8#include <deal.II/base/point.h>
10#include <deal.II/fe/fe_q.h>
11#include <deal.II/fe/fe_simplex_p.h>
12#include <deal.II/fe/fe_system.h>
14#include <deal.II/grid/grid_generator.h>
15#include <deal.II/grid/grid_in.h>
16#include <deal.II/grid/grid_tools.h>
18#include <deal.II/numerics/data_out.h>
19#include <deal.II/numerics/vector_tools.h>
23template <
int dim,
int spacedim>
26 const unsigned int id)
39 if (
param->solid_mesh.simplex)
42 fe = std::make_shared<FE_SimplexP<dim, spacedim>>(1);
43 solid_mapping = std::make_shared<MappingFE<dim, spacedim>>(*fe);
44 solid_tria = std::make_shared<Triangulation<dim, spacedim>>();
47 std::make_shared<FESystem<dim, spacedim>>(FE_SimplexP<dim, spacedim>(1),
53 fe = std::make_shared<FE_Q<dim, spacedim>>(1);
54 solid_mapping = std::make_shared<MappingQGeneric<dim, spacedim>>(1);
55 solid_tria = std::make_shared<Triangulation<dim, spacedim>>(
56 typename Triangulation<dim, spacedim>::MeshSmoothing(
57 Triangulation<dim, spacedim>::smoothing_on_refinement |
58 Triangulation<dim, spacedim>::smoothing_on_coarsening));
61 std::make_shared<FESystem<dim, spacedim>>(FE_Q<dim, spacedim>(1),
72 if constexpr (dim == 2)
75 if (
param->solid_mesh.simplex)
80template <
int dim,
int spacedim>
82 std::pair<typename Triangulation<spacedim>::active_cell_iterator,
83 typename Triangulation<dim, spacedim>::active_cell_iterator>>
85 const parallel::TriangulationBase<spacedim> &background_tr)
88 std::pair<typename Triangulation<spacedim>::active_cell_iterator,
89 typename Triangulation<dim, spacedim>::active_cell_iterator>>
92 if constexpr (dim == 2)
98 auto temporary_solid_cell =
solid_tria->begin();
99 std::vector<Point<spacedim>> triangle(temporary_solid_cell->n_vertices());
102 for (
const auto &background_cell : background_tr.active_cell_iterators())
105 if (background_cell->is_locally_owned())
108 const double bg_cell_length = background_cell->diameter();
111 Point<spacedim> bg_cell_center = background_cell->center();
114 for (
auto &solid_cell :
solid_tria->active_cell_iterators())
117 for (
unsigned int v = 0; v < solid_cell->n_vertices(); ++v)
119 triangle[v] = solid_cell->vertex(v);
123 const double distance =
125 triangle, bg_cell_center);
127 if (distance < bg_cell_length)
129 mapped_solid.push_back(
130 std::make_pair(background_cell, solid_cell));
136 else if constexpr (dim == 3)
138 throw std::runtime_error(
139 "Solid volumes are not yet implemented in Lethe. Please, remove the whole \"solid volumes\" subsection from your parameter file.");
150template <
int dim,
int spacedim>
162template <
int dim,
int spacedim>
169 "gmsh mesh file of the solid object, given by "
170 "'subsection mesh' - 'set file name'");
173 GridIn<dim, spacedim> grid_in;
177 std::ifstream input_file(
param->solid_mesh.file_name);
179 grid_in.read_msh(input_file);
181 else if (
param->solid_mesh.type ==
184 if (
param->solid_mesh.simplex)
186 Triangulation<dim, spacedim> temporary_quad_triangulation;
187 GridGenerator::generate_from_name_and_arguments(
188 temporary_quad_triangulation,
189 param->solid_mesh.grid_type,
190 param->solid_mesh.grid_arguments);
193 const int initial_refinement =
param->solid_mesh.initial_refinement;
194 temporary_quad_triangulation.refine_global(initial_refinement);
196 Triangulation<dim, spacedim> flat_temp_quad_triangulation;
197 GridGenerator::flatten_triangulation(temporary_quad_triangulation,
198 flat_temp_quad_triangulation);
200 GridGenerator::convert_hypercube_to_simplex_mesh(
205 GridGenerator::generate_from_name_and_arguments(
207 param->solid_mesh.grid_type,
208 param->solid_mesh.grid_arguments);
212 throw std::runtime_error(
214 "Unsupported mesh type - solid mesh will not be created");
218 param->solid_mesh.rotation_axis);
228 if (
param->solid_mesh.simplex)
240template <
int dim,
int spacedim>
241DoFHandler<dim, spacedim> &
248template <
int dim,
int spacedim>
255template <
int dim,
int spacedim>
262template <
int dim,
int spacedim>
263std::shared_ptr<Triangulation<dim, spacedim>>
269template <
int dim,
int spacedim>
273 [[maybe_unused]]
const Tensor<1, spacedim> &axis)
275 if constexpr (spacedim == 2)
281template <
int dim,
int spacedim>
284 const Tensor<1, spacedim> &translation)
289template <
int dim,
int spacedim>
301template <
int dim,
int spacedim>
304 const double initial_time)
310 const std::vector<bool> locally_owned_vertices =
311 GridTools::get_locally_owned_vertices(*this->
solid_tria);
312 std::vector<bool> vertex_moved(this->
solid_tria->n_vertices(),
false);
313 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
318 for (
int comp_i = 0; comp_i < spacedim; ++comp_i)
328 if (cell->is_locally_owned())
330 for (
unsigned int vertex = 0;
331 vertex < cell->reference_cell().n_vertices();
334 const auto dof_index = cell->vertex_dof_index(vertex, 0);
335 Point<spacedim> &vertex_position = cell->vertex(vertex);
336 const unsigned global_vertex_no = cell->vertex_index(vertex);
337 if (vertex_moved[global_vertex_no] ||
338 !locally_owned_vertices[global_vertex_no])
341 Tensor<1, spacedim> distance_vector =
344 Tensor<1, spacedim> local_velocity =
346 if constexpr (spacedim == 2)
353 if constexpr (spacedim == 3)
359 auto vertex_displacement = time_step * local_velocity;
361 vertex_position += vertex_displacement;
363 for (
int d = 0; d < spacedim; ++d)
368 vertex_displacement[d];
371 vertex_moved[global_vertex_no] =
true;
380template <
int dim,
int spacedim>
385 std::set<unsigned int> dof_vertex_displaced;
386 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
390 if (cell->is_locally_owned())
392 for (
unsigned int vertex = 0;
393 vertex < cell->reference_cell().n_vertices();
396 if (!dof_vertex_displaced.contains(cell->vertex_index(vertex)))
398 const auto dof_index = cell->vertex_dof_index(vertex, 0);
399 Point<spacedim> &vertex_position = cell->vertex(vertex);
401 for (
int d = 0; d < spacedim; ++d)
407 dof_vertex_displaced.insert(cell->vertex_index(vertex));
414template <
int dim,
int spacedim>
422 std::set<unsigned int> dof_vertex_displaced;
423 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
428 for (
unsigned int vertex = 0;
429 vertex < cell->reference_cell().n_vertices();
432 if (!dof_vertex_displaced.contains(cell->vertex_index(vertex)))
434 const auto dof_index = cell->vertex_dof_index(vertex, 0);
435 Point<spacedim> &vertex_position = cell->vertex(vertex);
437 for (
int d = 0; d < spacedim; ++d)
442 dof_vertex_displaced.insert(cell->vertex_index(vertex));
449template <
int dim,
int spacedim>
452 const std::shared_ptr<SimulationControl> &simulation_control)
457 DataOut<dim, spacedim> data_out;
461 std::vector<std::string> displacement_names(spacedim,
"displacement");
462 std::vector<DataComponentInterpretation::DataComponentInterpretation>
463 data_component_interpretation(
464 spacedim, DataComponentInterpretation::component_is_part_of_vector);
468 DataOut<dim, spacedim>::type_dof_data,
469 data_component_interpretation);
473 std::vector<std::string> displacement_names(spacedim,
474 "displacement_since_mapped");
475 std::vector<DataComponentInterpretation::DataComponentInterpretation>
476 data_component_interpretation(
477 spacedim, DataComponentInterpretation::component_is_part_of_vector);
481 DataOut<dim, spacedim>::type_dof_data,
482 data_component_interpretation);
485 data_out.build_patches();
487 const std::string folder = simulation_control->get_output_path();
488 const std::string solution_name = [&] {
489 if constexpr (dim == 1)
491 return simulation_control->get_output_name() +
".solid_line." +
492 Utilities::int_to_string(
id, 2);
494 if constexpr (dim == 2)
496 return simulation_control->get_output_name() +
".solid_surface." +
497 Utilities::int_to_string(
id, 2);
499 if constexpr (dim == 3)
501 return simulation_control->get_output_name() +
".solid_volume." +
502 Utilities::int_to_string(
id, 2);
505 const unsigned int iter = simulation_control->get_iteration_number();
506 const double time = simulation_control->get_current_time();
507 const unsigned int group_files = simulation_control->get_group_files();
519template <
int dim,
int spacedim>
525 std::string file_name =
526 prefix +
".solid_object." + Utilities::int_to_string(
id, 2) +
".dof";
527 std::ofstream ofs(file_name);
528 boost::archive::text_oarchive oa(ofs);
534 std::string file_name = prefix +
".solid_object." +
535 Utilities::int_to_string(
id, 2) +
".displacement";
536 std::ofstream ofs(file_name);
537 boost::archive::text_oarchive oa(ofs);
542 pvdhandler.save(prefix +
".solid_object." + Utilities::int_to_string(
id, 2));
545template <
int dim,
int spacedim>
552 std::string file_name =
553 prefix +
".solid_object." + Utilities::int_to_string(
id, 2) +
".dof";
555 "checkpoint file of the degrees of freedom of the solid "
556 "object, given by 'subsection restart' - 'set filename'");
557 std::ifstream ifs(file_name);
558 boost::archive::text_iarchive ia(ifs);
563 std::string file_name = prefix +
".solid_object." +
564 Utilities::int_to_string(
id, 2) +
".displacement";
566 "checkpoint file of the displacement of the solid "
567 "object, given by 'subsection restart' - 'set filename'");
568 std::ifstream ifs(file_name);
569 boost::archive::text_iarchive ia(ifs);
574 pvdhandler.read(prefix +
".solid_object." + Utilities::int_to_string(
id, 2));
581template <
int dim,
int spacedim>
593template <
int dim,
int spacedim>
600 std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>>
605 for (
const auto &main_cell :
solid_tria->active_cell_iterators())
608 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>
609 es_main_cell, vs_main_cell;
612 const unsigned int n_vertices_main_cell = main_cell->n_vertices();
615 std::vector<unsigned int> main_cell_vertex_indices;
616 main_cell_vertex_indices.reserve(n_vertices_main_cell);
617 for (
unsigned int v = 0; v < n_vertices_main_cell; ++v)
618 main_cell_vertex_indices.push_back(main_cell->vertex_index(v));
622 auto neighboring_cells =
627 for (
const auto &neigh_cell : neighboring_cells)
630 if (neigh_cell == main_cell)
635 unsigned int n_sharing_vertices = 0;
638 const unsigned int n_vertices_neigh_cell = neigh_cell->n_vertices();
640 for (
unsigned int v = 0; v < n_vertices_neigh_cell; ++v)
642 unsigned int neigh_cell_vertex_index =
643 neigh_cell->vertex_index(v);
644 if (std::ranges::find(main_cell_vertex_indices,
645 neigh_cell_vertex_index) !=
646 main_cell_vertex_indices.end())
647 n_sharing_vertices++;
650 if (n_sharing_vertices == 1)
651 vs_main_cell.push_back(neigh_cell);
653 es_main_cell.push_back(neigh_cell);
655 es_neighbors.insert(std::make_pair(main_cell, es_main_cell));
656 vs_neighbors.insert(std::make_pair(main_cell, vs_main_cell));
Parameters for a single rigid solid object used in DEM simulations.
std::shared_ptr< Function< spacedim > > angular_velocity
void setup_containers()
Builds the neighboring cells information for each cell of the solid object. These containers store fo...
const unsigned int n_mpi_processes
Tensor< 1, 3 > current_angular_velocity
std::shared_ptr< Triangulation< dim, spacedim > > solid_tria
void setup_dof_handler()
Set-ups the displacement vector to store the motion of the triangulation.
MPI_Comm mpi_communicator
void write_output_results(const std::shared_ptr< SimulationControl > &simulation_control)
Write the output file of the solid object triangulation.
std::shared_ptr< Parameters::RigidSolidObject< dim, spacedim > > & param
double current_solid_temperature
std::shared_ptr< FESystem< dim, spacedim > > displacement_fe
triangulation_cell_neighbors_map vs_neighbors
Vector< double > displacement_since_mapped
std::shared_ptr< Triangulation< dim, spacedim > > get_triangulation()
Returns the shared pointer to the solid object triangulation.
Tensor< 1, spacedim > current_translational_velocity
triangulation_cell_neighbors_map es_neighbors
void move_solid_triangulation(double time_step, double initial_time)
Moves the vertices of the solid triangulation. This function uses explicitEuler scheme time integrato...
void initial_setup()
Manages solid triangulation setup.
void reset_displacement_monitoring()
Reset displacements since intersection for contact detection.
void read_checkpoint(const std::string &prefix_name)
read solid base triangulation checkpoint and replaces the triangulation at the location where it was ...
DoFHandler< dim, spacedim > displacement_dh
void rotate_grid(const double angle, const Tensor< 1, spacedim > &axis)
Rotates the grid by a given angle around an axis.
void write_checkpoint(const std::string &prefix_name)
write solid base triangulation checkpoint
std::shared_ptr< Function< spacedim > > translational_velocity
Vector< double > displacement
DoFHandler< dim, spacedim > & get_dof_handler()
Returns the dof_handler associated with the displacement of the solid object.
void update_solid_temperature(const double initial_time)
Update the temperature of the solid object, which is a function of time.
double get_max_displacement_since_mapped() const
Calculates the max displacement of the solid object. The max displacement is defined as the L^\infty ...
Parameters::SolidObjectThermalBoundaryType thermal_boundary_type
std::vector< std::pair< typename Triangulation< spacedim >::active_cell_iterator, typename Triangulation< dim, spacedim >::active_cell_iterator > > map_solid_in_background_triangulation(const parallel::TriangulationBase< spacedim > &background_tr)
Maps the solid object in the background triangulation.
void translate_grid(const Tensor< 1, spacedim > &translate)
Translate the grid. In spacedim=2, the third component is ignored.
std::shared_ptr< Function< spacedim > > solid_temperature
const unsigned int this_mpi_process
void move_solid_triangulation_with_displacement()
Moves the vertices of the solid triangulation using the displacement vector. This is mostly used when...
Point< spacedim > center_of_rotation
void displace_solid_triangulation()
Moves the dofs of the solid_triangulation by using the displacement vector. This is only used to move...
void setup_triangulation(const bool restart)
Generates a solid triangulation from a dealii or gmsh mesh.
SerialSolid(std::shared_ptr< Parameters::RigidSolidObject< dim, spacedim > > ¶m, unsigned int id)
Vector< double > & get_displacement_vector()
Returns the displacement vector of all the vertices of the solid object.
void check_file_exists(const std::string &file_name, const std::string &file_description)
Verify that a file that Lethe must read exists and can be opened, and raise an error stated in the us...
@ adiabatic
No heat flux through the solid boundary.
void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface< dim, spacedim > &data_out, const std::string &folder, const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, const MPI_Comm &mpi_communicator, const unsigned int digits=5)
Output the data out to "group_files" vtu files, with a pvtu file and a pvd to store the timing This f...