Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
output_force_torque_calculation.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2022, 2024 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
6#include <fstream>
7
8void
10 std::map<unsigned int, Tensor<1, 3>> force_on_walls,
11 std::map<unsigned int, Tensor<1, 3>> torque_on_walls)
12{
13 TableHandler table;
14
15 for (const auto &it : force_on_walls)
16 {
17 table.add_value("B_id", it.first);
18 table.add_value("Fx", force_on_walls[it.first][0]);
19 table.add_value("Fy", force_on_walls[it.first][1]);
20 table.add_value("Fz", force_on_walls[it.first][2]);
21 table.add_value("Tx", torque_on_walls[it.first][0]);
22 table.add_value("Ty", torque_on_walls[it.first][1]);
23 table.add_value("Tz", torque_on_walls[it.first][2]);
24 }
25 table.set_precision("Fx", 9);
26 table.set_precision("Fy", 9);
27 table.set_precision("Fz", 9);
28 table.set_precision("Tx", 9);
29 table.set_precision("Ty", 9);
30 table.set_precision("Tz", 9);
31
32 table.write_text(std::cout);
33}
34
35void
37 const std::string &filename,
38 const unsigned int output_frequency,
39 const std::vector<unsigned int> &boundary_index,
40 const double time_step,
41 DEM::dem_data_structures<3>::vector_on_boundary &forces_boundary_information,
42 DEM::dem_data_structures<3>::vector_on_boundary &torques_boundary_information)
43{
44 unsigned int this_mpi_process =
45 Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
46 unsigned int n_mpi_processes =
47 Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
48 for (unsigned int i = 0; i < boundary_index.size(); i++)
49 {
50 std::string filename_boundary_description =
51 std::to_string(boundary_index[i]);
52 std::string filename_output =
53 filename + "_boundary_" + filename_boundary_description;
54 if (this_mpi_process == i || (i + 1) > n_mpi_processes)
55 {
56 TableHandler table;
57
58 for (unsigned int j = 0; j < forces_boundary_information.size();
59 j += output_frequency)
60 {
61 table.add_value("Force x", forces_boundary_information[j][i][0]);
62 table.add_value("Force y", forces_boundary_information[j][i][1]);
63 table.add_value("Force z", forces_boundary_information[j][i][2]);
64 table.add_value("Torque x",
65 torques_boundary_information[j][i][0]);
66 table.add_value("Torque y",
67 torques_boundary_information[j][i][1]);
68 table.add_value("Torque z",
69 torques_boundary_information[j][i][2]);
70 table.add_value("Current time", j * time_step);
71 }
72
73 table.set_precision("Force x", 9);
74 table.set_precision("Force y", 9);
75 table.set_precision("Force z", 9);
76 table.set_precision("Torque x", 9);
77 table.set_precision("Torque y", 9);
78 table.set_precision("Torque z", 9);
79 table.set_precision("Current time", 9);
80
81 // output
82 std::ofstream out_file(filename_output);
83 table.write_text(out_file);
84 out_file.close();
85 }
86 }
87}
void write_forces_torques_output_locally(std::map< unsigned int, Tensor< 1, 3 > > force_on_walls, std::map< unsigned int, Tensor< 1, 3 > > torque_on_walls)
write_forces_torques_output_locally Writes the results of force and torque calculations in the termin...
void write_forces_torques_output_results(const std::string &filename, const unsigned int output_frequency, const std::vector< unsigned int > &boundary_index, const double time_step, DEM::dem_data_structures< 3 >::vector_on_boundary &forces_boundary_information, DEM::dem_data_structures< 3 >::vector_on_boundary &torques_boundary_information)
write_forces_torques_output_results Writes the results of force and torque calculations in a file,...
ankerl::unordered_dense::map< unsigned int, std::map< types::boundary_id, Tensor< 1, 3 > > > vector_on_boundary