Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
force_chains_visualization.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
7
8#include <deal.II/grid/grid_out.h>
9#include <deal.II/grid/tria.h>
10
11#include <deal.II/numerics/data_out.h>
12
13#include <cmath>
14#include <fstream>
15
16using namespace DEM;
17using namespace Parameters::Lagrangian;
18
19template <int dim,
20 typename PropertiesIndex,
22 RollingResistanceMethod rolling_friction_model>
25 contact_model,
26 rolling_friction_model>::
27 ParticlesForceChains(const DEMSolverParameters<dim> &dem_parameters)
29 PropertiesIndex,
30 contact_model,
31 rolling_friction_model>(dem_parameters)
32{}
33
34template <int dim,
35 typename PropertiesIndex,
37 RollingResistanceMethod rolling_friction_model>
38void
40 PropertiesIndex,
41 contact_model,
42 rolling_friction_model>::
43 multi_general_cell(Triangulation<1, 3> &tria,
44 const std::vector<Point<3>> &vertices)
45{
46 const unsigned int n_cells = vertices.size() / 2;
47 std::vector<CellData<1>> cells(n_cells, CellData<1>());
48 for (unsigned int i = 0; i < n_cells; ++i)
49 {
50 cells[i].vertices[0] = 2 * i;
51 cells[i].vertices[1] = 2 * i + 1;
52 cells[i].material_id = 0;
53 };
54 tria.create_triangulation(vertices, cells, SubCellData());
55}
56
57template <
58 int dim,
59 typename PropertiesIndex,
62void
64 PropertiesIndex,
65 force_model,
66 rolling_friction_model>::
67 calculate_force_chains(
69 &local_adjacent_particles,
71 &ghost_adjacent_particles,
72 std::vector<Point<3>> &vertices,
73 std::vector<double> &normal_forces_vector)
74{
75 // Looping over local_adjacent_particles values with iterator
76 // adjacent_particles_list
77 for (auto &&adjacent_particles_list :
78 local_adjacent_particles | boost::adaptors::map_values)
79 {
81 adjacent_particles_list, vertices, normal_forces_vector);
82 }
83
84 // Calculate force for local-ghost particle pairs
85 for (auto &&adjacent_particles_list :
86 ghost_adjacent_particles | boost::adaptors::map_values)
87 {
89 adjacent_particles_list, vertices, normal_forces_vector);
90 }
91}
92
93template <int dim,
94 typename PropertiesIndex,
96 RollingResistanceMethod rolling_friction_model>
97void
99 PropertiesIndex,
100 contact_model,
101 rolling_friction_model>::
102 write_force_chains(const DEMSolverParameters<dim> &dem_parameters,
103 PVDHandler &pvd_handler,
104 MPI_Comm mpi_communicator,
105 const std::string folder,
106 const unsigned int iter,
107 const double time,
109 &local_adjacent_particles,
111 &ghost_adjacent_particles)
112{
113 // Creating containers
114 std::vector<Point<3>> vertices = {Point<3>(), Point<3>()};
115 std::vector<double> normal_forces_vector = {0.};
116
117 this->calculate_force_chains(local_adjacent_particles,
118 ghost_adjacent_particles,
119 vertices,
120 normal_forces_vector);
121
122 Triangulation<1, 3> triangulation;
123 multi_general_cell(triangulation, vertices);
124 DoFHandler<1, 3> force_dh(triangulation);
125 DataOut<1, 3> data_out;
126 data_out.attach_dof_handler(force_dh);
127
128 Vector<double> force_values(triangulation.n_active_cells());
129 for (unsigned int i = 0; i < force_values.size(); ++i)
130 {
131 force_values[i] = normal_forces_vector[i];
132 }
133 data_out.add_data_vector(force_values, "force");
134 data_out.build_patches();
135
136 const std::string file_prefix =
137 dem_parameters.simulation_control.output_name + "-force_chains";
138 const std::string face_filename =
139 (folder + file_prefix + "." + Utilities::int_to_string(iter, 5) + ".vtu");
140 data_out.write_vtu_in_parallel(face_filename.c_str(), mpi_communicator);
141
142 std::vector<std::string> filenames;
143 filenames.push_back(file_prefix + "." + Utilities::int_to_string(iter, 5) +
144 ".vtu");
145
146 std::string pvtu_filename =
147 (file_prefix + "." + Utilities::int_to_string(iter, 5) + ".pvtu");
148
149 std::string pvtu_filename_with_folder = folder + pvtu_filename;
150 std::ofstream master_output(pvtu_filename_with_folder.c_str());
151
152 data_out.write_pvtu_record(master_output, filenames);
153
154 std::string pvdPrefix = (folder + file_prefix + ".pvd");
155 pvd_handler.append(time, pvtu_filename);
156 std::ofstream pvd_output(pvdPrefix.c_str());
157 DataOutBase::write_pvd_record(pvd_output, pvd_handler.times_and_names);
158}
159//// DEM::SolverType::dem
160// No resistance
161template class ParticlesForceChains<2,
165template class ParticlesForceChains<3,
169template class ParticlesForceChains<2,
173template class ParticlesForceChains<3,
177template class ParticlesForceChains<
178 2,
182template class ParticlesForceChains<
183 3,
187template class ParticlesForceChains<
188 2,
192template class ParticlesForceChains<
193 3,
197template class ParticlesForceChains<
198 2,
202template class ParticlesForceChains<
203 3,
207template class ParticlesForceChains<2,
211template class ParticlesForceChains<3,
215
216// Constant resistance
217template class ParticlesForceChains<2,
221template class ParticlesForceChains<3,
225template class ParticlesForceChains<2,
229template class ParticlesForceChains<3,
233template class ParticlesForceChains<
234 2,
238template class ParticlesForceChains<
239 3,
243template class ParticlesForceChains<
244 2,
248template class ParticlesForceChains<
249 3,
253template class ParticlesForceChains<
254 2,
258template class ParticlesForceChains<
259 3,
263template class ParticlesForceChains<2,
267template class ParticlesForceChains<3,
271
272// Viscous resistance
273template class ParticlesForceChains<2,
277template class ParticlesForceChains<3,
281template class ParticlesForceChains<2,
285template class ParticlesForceChains<3,
289template class ParticlesForceChains<
290 2,
294template class ParticlesForceChains<
295 3,
299template class ParticlesForceChains<
300 2,
304template class ParticlesForceChains<
305 3,
309template class ParticlesForceChains<
310 2,
314template class ParticlesForceChains<
315 3,
319template class ParticlesForceChains<2,
323template class ParticlesForceChains<3,
327
328// EPSD resistance
329template class ParticlesForceChains<2,
333template class ParticlesForceChains<3,
337template class ParticlesForceChains<2,
341template class ParticlesForceChains<3,
345template class ParticlesForceChains<
346 2,
350template class ParticlesForceChains<
351 3,
355template class ParticlesForceChains<
356 2,
360template class ParticlesForceChains<
361 3,
365template class ParticlesForceChains<
366 2,
370template class ParticlesForceChains<
371 3,
375template class ParticlesForceChains<2,
379template class ParticlesForceChains<3,
383
384
385//// DEM::CFDDEMProperties::PropertiesIndex
386// No resistance
387template class ParticlesForceChains<2,
391template class ParticlesForceChains<3,
395template class ParticlesForceChains<2,
399template class ParticlesForceChains<3,
403template class ParticlesForceChains<
404 2,
408template class ParticlesForceChains<
409 3,
413template class ParticlesForceChains<
414 2,
418template class ParticlesForceChains<
419 3,
423template class ParticlesForceChains<
424 2,
428template class ParticlesForceChains<
429 3,
433template class ParticlesForceChains<2,
437template class ParticlesForceChains<3,
441
442// Constant resistance
443template class ParticlesForceChains<2,
447template class ParticlesForceChains<3,
451template class ParticlesForceChains<2,
455template class ParticlesForceChains<3,
459template class ParticlesForceChains<
460 2,
464template class ParticlesForceChains<
465 3,
469template class ParticlesForceChains<
470 2,
474template class ParticlesForceChains<
475 3,
479template class ParticlesForceChains<
480 2,
484template class ParticlesForceChains<
485 3,
489template class ParticlesForceChains<2,
493template class ParticlesForceChains<3,
497
498// Viscous resistance
499template class ParticlesForceChains<2,
503template class ParticlesForceChains<3,
507template class ParticlesForceChains<2,
511template class ParticlesForceChains<3,
515template class ParticlesForceChains<
516 2,
520template class ParticlesForceChains<
521 3,
525template class ParticlesForceChains<
526 2,
530template class ParticlesForceChains<
531 3,
535template class ParticlesForceChains<
536 2,
540template class ParticlesForceChains<
541 3,
545template class ParticlesForceChains<2,
549template class ParticlesForceChains<3,
553
554// EPSD resistance
555template class ParticlesForceChains<2,
559template class ParticlesForceChains<3,
563template class ParticlesForceChains<2,
567template class ParticlesForceChains<3,
571template class ParticlesForceChains<
572 2,
576template class ParticlesForceChains<
577 3,
581template class ParticlesForceChains<
582 2,
586template class ParticlesForceChains<
587 3,
591template class ParticlesForceChains<
592 2,
596template class ParticlesForceChains<
597 3,
601template class ParticlesForceChains<2,
605template class ParticlesForceChains<3,
609
610//// DEM::SolverType::dem_mp
611// No resistance
612template class ParticlesForceChains<2,
616
617template class ParticlesForceChains<3,
621
622template class ParticlesForceChains<2,
626
627template class ParticlesForceChains<3,
631
632template class ParticlesForceChains<
633 2,
637
638template class ParticlesForceChains<
639 3,
643
644template class ParticlesForceChains<
645 2,
649
650template class ParticlesForceChains<
651 3,
655
656template class ParticlesForceChains<
657 2,
661
662template class ParticlesForceChains<
663 3,
667
668template class ParticlesForceChains<2,
672
673template class ParticlesForceChains<3,
677
678// Constant resistance
679template class ParticlesForceChains<2,
683
684template class ParticlesForceChains<3,
688
689template class ParticlesForceChains<2,
693
694template class ParticlesForceChains<3,
698
699template class ParticlesForceChains<
700 2,
704
705template class ParticlesForceChains<
706 3,
710
711template class ParticlesForceChains<
712 2,
716
717template class ParticlesForceChains<
718 3,
722
723template class ParticlesForceChains<
724 2,
728
729template class ParticlesForceChains<
730 3,
734
735template class ParticlesForceChains<2,
739
740template class ParticlesForceChains<3,
744
745// Viscous resistance
746template class ParticlesForceChains<2,
750
751template class ParticlesForceChains<3,
755
756template class ParticlesForceChains<2,
760
761template class ParticlesForceChains<3,
765
766template class ParticlesForceChains<
767 2,
771
772template class ParticlesForceChains<
773 3,
777
778template class ParticlesForceChains<
779 2,
783
784template class ParticlesForceChains<
785 3,
789
790template class ParticlesForceChains<
791 2,
795
796template class ParticlesForceChains<
797 3,
801
802template class ParticlesForceChains<2,
806
807template class ParticlesForceChains<3,
811
812// EPSD resistance
813template class ParticlesForceChains<2,
817
818template class ParticlesForceChains<3,
822
823template class ParticlesForceChains<2,
827
828template class ParticlesForceChains<3,
832
833template class ParticlesForceChains<
834 2,
838
839template class ParticlesForceChains<
840 3,
844
845template class ParticlesForceChains<
846 2,
850
851template class ParticlesForceChains<
852 3,
856
857template class ParticlesForceChains<
858 2,
862
863template class ParticlesForceChains<
864 3,
868
869template class ParticlesForceChains<2,
873
874template class ParticlesForceChains<3,
878
879//// DEM::CFDDEMMPProperties::PropertiesIndex
880// No resistance
881template class ParticlesForceChains<2,
885template class ParticlesForceChains<3,
889template class ParticlesForceChains<2,
893template class ParticlesForceChains<3,
897template class ParticlesForceChains<
898 2,
902template class ParticlesForceChains<
903 3,
907template class ParticlesForceChains<
908 2,
912template class ParticlesForceChains<
913 3,
917template class ParticlesForceChains<
918 2,
922template class ParticlesForceChains<
923 3,
927template class ParticlesForceChains<2,
931template class ParticlesForceChains<3,
935// Constant resistance
936template class ParticlesForceChains<2,
940template class ParticlesForceChains<3,
944template class ParticlesForceChains<2,
948template class ParticlesForceChains<3,
952template class ParticlesForceChains<
953 2,
957template class ParticlesForceChains<
958 3,
962template class ParticlesForceChains<
963 2,
967template class ParticlesForceChains<
968 3,
972template class ParticlesForceChains<
973 2,
977template class ParticlesForceChains<
978 3,
982template class ParticlesForceChains<2,
986template class ParticlesForceChains<3,
990// Viscous resistance
991template class ParticlesForceChains<2,
995template class ParticlesForceChains<3,
999template class ParticlesForceChains<2,
1003template class ParticlesForceChains<3,
1007template class ParticlesForceChains<
1008 2,
1012template class ParticlesForceChains<
1013 3,
1017template class ParticlesForceChains<
1018 2,
1022template class ParticlesForceChains<
1023 3,
1027template class ParticlesForceChains<
1028 2,
1032template class ParticlesForceChains<
1033 3,
1037template class ParticlesForceChains<2,
1041template class ParticlesForceChains<3,
1045// EPSD resistance
1046template class ParticlesForceChains<2,
1050template class ParticlesForceChains<3,
1054template class ParticlesForceChains<2,
1058template class ParticlesForceChains<3,
1062template class ParticlesForceChains<
1063 2,
1067template class ParticlesForceChains<
1068 3,
1072template class ParticlesForceChains<
1073 2,
1077template class ParticlesForceChains<
1078 3,
1082template class ParticlesForceChains<
1083 2,
1087template class ParticlesForceChains<
1088 3,
1092template class ParticlesForceChains<2,
1096template class ParticlesForceChains<3,
Handles all the parameters declared in the parameter handler file.
Parameters::SimulationControl simulation_control
The PVDHandler class manages the storage of the information required to write pvd file....
Definition pvd_handler.h:17
std::vector< std::pair< double, std::string > > times_and_names
Definition pvd_handler.h:43
void append(double time, const std::string &pvtu_filename)
Definition pvd_handler.h:36
Class that carries out the calculation of particle-particle contact force and the visualization of fo...
void multi_general_cell(Triangulation< 1, 3 > &tria, const std::vector< Point< 3 > > &vertices)
Create a triangulation with a unique cell (represented by a line) for each normal force between two p...
void execute_contact_calculation(ContactInfoContainer &adjacent_particles_list, std::vector< Point< 3 > > &vertices, std::vector< double > &normal_forces_vector)
Execute the contact calculation step for the particle-particle contact only for local-local and local...
void calculate_force_chains(typename dem_data_structures< dim >::adjacent_particle_pairs &local_adjacent_particles, typename dem_data_structures< dim >::adjacent_particle_pairs &ghost_adjacent_particles, std::vector< Point< 3 > > &vertices, std::vector< double > &normal_forces_vector) override
Calculate normal forces between all touching particles with ParticleParticleContactForce class' metho...
PropertiesIndex
Particle property indices for CFD-DEM multiphysics simulations.
PropertiesIndex
Particle property indices for CFD-DEM simulations.
PropertiesIndex
Particle property indices for DEM multiphysics simulations.
PropertiesIndex
Particle property indices for pure DEM simulations.
This namespace defines all the data containers and required operations on these containers for the DE...
ParticleParticleContactForceModel
Contact force model for particle-particle interactions.
@ hertz_JKR
Hertz model with Johnson-Kendall-Roberts cohesive force.
@ hertz_mindlin_limit_overlap
Hertz-Mindlin model with a limitation on tangential overlap.
@ hertz_mindlin_limit_force
Hertz-Mindlin model with a limitation on tangential force.
RollingResistanceMethod
Method used to compute the rolling resistance torque.
@ epsd
Elastic-plastic spring-dashpot.
@ viscous
Viscous rolling resistance.
@ constant
Constant rolling resistance.
@ none
No rolling resistance.
Parameter structures for Lagrangian (DEM) particle simulations.
ankerl::unordered_dense::map< types::particle_index, adjacent_particle_pairs_value > adjacent_particle_pairs