Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
solid_base.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/solid_base.h>
5#include <core/utilities.h>
6
7#include <deal.II/base/bounding_box.h>
8#include <deal.II/base/point.h>
9#include <deal.II/base/quadrature_lib.h>
10
11#include <deal.II/distributed/fully_distributed_tria.h>
12
13#include <deal.II/dofs/dof_tools.h>
14
15#include <deal.II/fe/fe_simplex_p.h>
16#include <deal.II/fe/fe_system.h>
17#include <deal.II/fe/fe_values.h>
18#include <deal.II/fe/mapping.h>
19
20#include <deal.II/grid/filtered_iterator.h>
21#include <deal.II/grid/grid_generator.h>
22#include <deal.II/grid/grid_in.h>
23#include <deal.II/grid/grid_tools.h>
24
25#include <deal.II/numerics/solution_transfer.h>
26#include <deal.II/numerics/vector_tools.h>
27
28#include <deal.II/particles/data_out.h>
29
30#include <boost/archive/text_iarchive.hpp>
31#include <boost/archive/text_oarchive.hpp>
32
33#include <fstream>
34
35
36
37template <int dim, int spacedim>
40 const std::shared_ptr<parallel::DistributedTriangulationBase<spacedim>>
42 const std::shared_ptr<Mapping<spacedim>> &fluid_mapping)
43 : mpi_communicator(MPI_COMM_WORLD)
48 , param(param)
49 , velocity(&param->solid_velocity)
50 , temperature(&param->solid_temperature)
51{
52 if (param->solid_mesh.simplex)
53 {
54 // for simplex meshes
55 fe = std::make_shared<FE_SimplexP<dim, spacedim>>(1);
56 solid_mapping = std::make_shared<MappingFE<dim, spacedim>>(*fe);
57 quadrature =
58 std::make_shared<QGaussSimplex<dim>>(param->number_quadrature_points);
59 solid_tria = std::make_shared<
60 parallel::fullydistributed::Triangulation<dim, spacedim>>(
61 this->mpi_communicator);
62
63 displacement_fe =
64 std::make_shared<FESystem<dim, spacedim>>(FE_SimplexP<dim, spacedim>(1),
65 spacedim);
66 }
67 else
68 {
69 // Usual case, for quad/hex meshes
70 fe = std::make_shared<FE_Q<dim, spacedim>>(1);
71 solid_mapping = std::make_shared<MappingQGeneric<dim, spacedim>>(1);
72 quadrature =
73 std::make_shared<QGauss<dim>>(param->number_quadrature_points);
74 solid_tria =
75 std::make_shared<parallel::distributed::Triangulation<dim, spacedim>>(
76 mpi_communicator,
77 typename Triangulation<dim, spacedim>::MeshSmoothing(
78 Triangulation<dim, spacedim>::smoothing_on_refinement |
79 Triangulation<dim, spacedim>::smoothing_on_coarsening));
80
81 displacement_fe =
82 std::make_shared<FESystem<dim, spacedim>>(FE_Q<dim, spacedim>(1),
83 spacedim);
84 }
85
86 // Dof handler associated with particles
87 solid_dh.clear();
88 solid_dh.reinit(*this->solid_tria);
89
90 // Dof handler associated with mesh displacement
91 displacement_dh.clear();
92 displacement_dh.reinit(*this->solid_tria);
93}
94
95template <int dim, int spacedim>
96void
98{
99 // initial_setup is called if the simulation is not a restarted one
100 // Set-up of Nitsche triangulation, then particles (order important)
101 setup_triangulation(false);
104}
105
106
107
108template <int dim, int spacedim>
109void
111{
112 if (param->solid_mesh.type == Parameters::Mesh<spacedim>::Type::gmsh)
113 {
114 // The mesh file is checked here, before the branch below, so that every
115 // rank raises the same error. The simplex branch reads the file from
116 // within a lambda that is only run by the root of each group of
117 // processes, and a check placed there would leave the other ranks
118 // waiting.
119 check_file_exists(param->solid_mesh.file_name,
120 "gmsh mesh file of the solid object, given by "
121 "'subsection mesh' - 'set file name'");
122
123 if (param->solid_mesh.simplex)
124 {
125 auto comm = solid_tria->get_mpi_communicator();
126 std::string file_name = param->solid_mesh.file_name;
127
128 auto construction_data = TriangulationDescription::Utilities::
129 create_description_from_triangulation_in_groups<dim, spacedim>(
130 [file_name](dealii::Triangulation<dim, spacedim> &basetria) {
131 GridIn<dim, spacedim> grid_in;
132 grid_in.attach_triangulation(basetria);
133 std::ifstream input_file(file_name);
134
135 grid_in.read_msh(input_file);
136 },
137 [](dealii::Triangulation<dim, spacedim> &basetria,
138 const MPI_Comm comm,
139 const unsigned int /*group_size*/) {
140 GridTools::partition_triangulation(
141 Utilities::MPI::n_mpi_processes(comm), basetria);
142 },
143 comm,
144 Utilities::MPI::n_mpi_processes(comm) /* group size */,
145 dealii::Triangulation<dim, spacedim>::none);
146
147 solid_tria->create_triangulation(construction_data);
148 }
149 else
150 { // Grid creation
151 GridIn<dim, spacedim> grid_in;
152 // Attach triangulation to the grid
153 grid_in.attach_triangulation(*solid_tria);
154 // Read input gmsh file
155 std::ifstream input_file(param->solid_mesh.file_name);
156 grid_in.read_msh(input_file);
157 }
158 }
159 else if (param->solid_mesh.type == Parameters::Mesh<spacedim>::Type::dealii)
160 {
161 if (param->solid_mesh.simplex)
162 { // TODO Using dealii generated meshes with simplices in Nitsche solver
163 // generates and error. "boundary_id !=
164 // numbers::internal_face_boundary_id"
165 Triangulation<dim, spacedim> temporary_quad_triangulation;
166 GridGenerator::generate_from_name_and_arguments(
167 temporary_quad_triangulation,
168 param->solid_mesh.grid_type,
169 param->solid_mesh.grid_arguments);
170
171 // initial refinement
172 const int initial_refinement = param->solid_mesh.initial_refinement;
173 temporary_quad_triangulation.refine_global(initial_refinement);
174 // flatten the triangulation
175 Triangulation<dim, spacedim> flat_temp_quad_triangulation;
176 GridGenerator::flatten_triangulation(temporary_quad_triangulation,
177 flat_temp_quad_triangulation);
178
179 Triangulation<dim, spacedim> temporary_tri_triangulation(
180 Triangulation<dim, spacedim>::limit_level_difference_at_vertices);
181 GridGenerator::convert_hypercube_to_simplex_mesh(
182 flat_temp_quad_triangulation, temporary_tri_triangulation);
183
184 GridTools::partition_triangulation_zorder(
185 Utilities::MPI::n_mpi_processes(solid_tria->get_mpi_communicator()),
186 temporary_tri_triangulation);
187 GridTools::partition_multigrid_levels(temporary_tri_triangulation);
188
189 // extract relevant information from distributed triangulation
190 auto construction_data = TriangulationDescription::Utilities::
191 create_description_from_triangulation(
192 temporary_tri_triangulation,
193 solid_tria->get_mpi_communicator(),
194 TriangulationDescription::Settings::
195 construct_multigrid_hierarchy);
196 solid_tria->create_triangulation(construction_data);
197 }
198 else
199 { // deal.ii creates grid and attaches the solid triangulation
200 GridGenerator::generate_from_name_and_arguments(
201 *solid_tria,
202 param->solid_mesh.grid_type,
203 param->solid_mesh.grid_arguments);
204 }
205 }
206 else
207 throw std::runtime_error(
208 "Unsupported mesh type - solid mesh will not be created");
209
210 // Rotate the triangulation
211 rotate_grid(param->solid_mesh.rotation_angle,
212 param->solid_mesh.rotation_axis);
213
214 // Translate the triangulation
215 translate_grid(param->solid_mesh.translation);
216 // Refine the solid triangulation to its initial size
217 // NB: solid_tria should not be refined if loaded from a restart file
218 // afterwards
219 if (!restart)
220 {
221 if (param->solid_mesh.simplex)
222 {
223 // Simplex triangulation refinement isn't possible yet
224 }
225 else
226 {
227 solid_tria->refine_global(param->solid_mesh.initial_refinement);
228 }
229 solid_dh.distribute_dofs(*fe);
230 }
231}
232
233template <int dim, int spacedim>
234void
236 const double angle,
237 [[maybe_unused]] const Tensor<1, spacedim> &axis)
238{
239 if constexpr (spacedim == 2)
240 GridTools::rotate(angle, *solid_tria);
241 else
242 GridTools::rotate(axis, angle, *solid_tria);
243}
244
245template <int dim, int spacedim>
246void
247SolidBase<dim, spacedim>::translate_grid(const Tensor<1, spacedim> &translation)
248{
249 GridTools::shift(translation, *solid_tria);
250}
251
252template <int dim, int spacedim>
253void
254SolidBase<dim, spacedim>::load_triangulation(const std::string &filename_tria)
255{
256 // Load solid triangulation from given file
257 // Currently we only load the triangulation without loading the particles,
258 // this is an issue that needs to be addressed in a near future.
259 try
260 {
261 solid_tria->load(filename_tria.c_str());
262 }
263 catch (...)
264 {
265 AssertThrow(false,
266 ExcMessage("Cannot open snapshot mesh file or read the "
267 "solid triangulation stored there."));
268 }
269
270 // Initialize dof handler for solid
271 solid_dh.distribute_dofs(*fe);
272}
273
274template <int dim, int spacedim>
275void
277{
278 unsigned int n_properties = (dim == 2 && spacedim == 3) ? 1 + spacedim : 1;
279
281 std::make_shared<Particles::ParticleHandler<spacedim>>();
282
283 // Put the proper triangulation and mapping for more general cases
284 solid_particle_handler->initialize(*fluid_tria, *fluid_mapping, n_properties);
285}
286
287template <int dim, int spacedim>
288void
290{
292
293 // Initialize FEValues
294 std::vector<Point<spacedim>> quadrature_points_vec;
295 quadrature_points_vec.reserve(quadrature->size() *
296 solid_tria->n_locally_owned_active_cells());
297 unsigned int n_properties = (dim == 2 && spacedim == 3) ? 1 + spacedim : 1;
298
299 std::vector<std::vector<double>> properties;
300 properties.reserve(quadrature->size() *
301 solid_tria->n_locally_owned_active_cells() * n_properties);
302
303 UpdateFlags update_flags = update_JxW_values | update_quadrature_points;
304 if (dim == 2 && spacedim == 3)
305 update_flags = update_flags | update_normal_vectors;
306
307 FEValues<dim, spacedim> fe_v(*solid_mapping, *fe, *quadrature, update_flags);
308
309 // Fill quadrature points vector and properties, used to fill
310 // solid_particle_handler
311 for (const auto &cell : solid_dh.active_cell_iterators())
312 if (cell->is_locally_owned())
313 {
314 fe_v.reinit(cell);
315 const auto &points = fe_v.get_quadrature_points();
316 const auto &JxW = fe_v.get_JxW_values();
317 if (dim == 2 && spacedim == 3)
318 {
319 const auto &normal_vectors = fe_v.get_normal_vectors();
320 for (unsigned int q = 0; q < points.size(); ++q)
321 {
322 quadrature_points_vec.emplace_back(points[q]);
323 std::vector<double> prop_i = {JxW[q],
324 normal_vectors[q][0],
325 normal_vectors[q][1]};
326 if (spacedim == 3)
327 prop_i.push_back(normal_vectors[q][2]);
328 properties.emplace_back(prop_i);
329 }
330 }
331 else
332 {
333 for (unsigned int q = 0; q < points.size(); ++q)
334 {
335 quadrature_points_vec.emplace_back(points[q]);
336 std::vector<double> prop_i = {JxW[q]};
337 properties.emplace_back(prop_i);
338 }
339 }
340 }
341
342 // Compute fluid bounding box
343 std::vector<std::vector<BoundingBox<spacedim>>> global_fluid_bounding_boxes;
344
345 // Use the more general boost rtree bounding boxes
346 std::vector<BoundingBox<spacedim>> all_boxes;
347 all_boxes.reserve(fluid_tria->n_locally_owned_active_cells());
348 for (const auto &cell : fluid_tria->active_cell_iterators())
349 if (cell->is_locally_owned())
350 all_boxes.emplace_back(cell->bounding_box());
351 const auto tree = pack_rtree(all_boxes);
352 const auto local_boxes = extract_rtree_level(
353 tree, std::max(int(log10(fluid_tria->n_locally_owned_active_cells())), 1));
354
355 global_fluid_bounding_boxes =
356 Utilities::MPI::all_gather(mpi_communicator, local_boxes);
357
358 // Fill solid particle handler
359 solid_particle_handler->insert_global_particles(quadrature_points_vec,
360 global_fluid_bounding_boxes,
361 properties);
362
363 // Number of particles used to assess that no particle is lost
365}
366
367template <int dim, int spacedim>
368void
369SolidBase<dim, spacedim>::load_particles(const std::string &filename_part)
370{
371 // Setup particles handler
373
374 // Gather particle serialization information
375 check_file_exists(filename_part,
376 "checkpoint file of the solid particles, given by "
377 "'subsection restart' - 'set filename'");
378 std::ifstream input(filename_part.c_str());
379
380 std::string buffer;
381 std::getline(input, buffer);
382 std::istringstream iss(buffer);
383 boost::archive::text_iarchive ia(iss, boost::archive::no_header);
384
386
388}
389
390template <int dim, int spacedim>
391DoFHandler<dim, spacedim> &
396
397template <int dim, int spacedim>
398DoFHandler<dim, spacedim> &
403
404
405template <int dim, int spacedim>
412
413template <int dim, int spacedim>
414std::shared_ptr<Particles::ParticleHandler<spacedim>> &
419
420template <int dim, int spacedim>
421std::shared_ptr<parallel::DistributedTriangulationBase<dim, spacedim>>
426
427template <int dim, int spacedim>
428Function<spacedim> *
433template <int dim, int spacedim>
434Function<spacedim> *
439
440template <int dim, int spacedim>
441void
443{
444 temperature->set_time(time);
445}
446
447template <int dim, int spacedim>
448void
450 double initial_time)
451{
452 const unsigned int sub_particles_iterations = param->particles_sub_iterations;
453 AssertThrow(sub_particles_iterations >= 1,
454 ExcMessage("Sub particles iterations must be 1 or larger"));
455
456
457
458 double sub_iteration_relaxation = 1. / sub_particles_iterations;
459 time_step = time_step * sub_iteration_relaxation;
460 // Particle sub iterations divide the time step in a number of "sub
461 // iterations". This allows the solver to use a larger CFL without
462 // necessitating the use of the more complex particle location detection
463 // approaches. The number of sub particles iterations must be chosen so that
464 // the time_step / sub_particles_iterations * velocity / cell size is smaller
465 // than unity
466 for (unsigned int it = 0; it < sub_particles_iterations; ++it)
467 {
468 for (auto particle = solid_particle_handler->begin();
469 particle != solid_particle_handler->end();
470 ++particle)
471 {
472 // Calculate the next position of the particle using the RK4
473 // time integration scheme
474 // x(t+dt) = x(t) + 1/6 (k1+2*k2+2*k3+k4)
475 // k1 = dt * v(t,x(t))
476 // k2 = dt * v(t+0.5*dt,x+k1/2)
477 // k3 = dt * v(t+0.5*dt,x+k2/2)
478 // k4 = dt * vt(t+dt,x+k3)
479 // The four stages (1 to 4) are built successively
480 // For each stage, the time of the function must be "reset"
481 // to ensure adequate evaluation of the RK4 scheme.
482 // See https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods for
483 // more details
484
485 Point<spacedim> particle_location = particle->get_location();
486
487 Tensor<1, spacedim> k1;
488 velocity->set_time(initial_time);
489 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
490 k1[comp_i] = velocity->value(particle_location, comp_i);
491
492 Point<spacedim> p1 = particle_location + time_step / 2 * k1;
493 Tensor<1, spacedim> k2;
494 velocity->set_time(initial_time + time_step / 2);
495 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
496 k2[comp_i] = velocity->value(p1, comp_i);
497
498 Point<spacedim> p2 = particle_location + time_step / 2 * k2;
499 Tensor<1, spacedim> k3;
500 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
501 k3[comp_i] = velocity->value(p2, comp_i);
502
503 Point<spacedim> p3 = particle_location + time_step * k3;
504 Tensor<1, spacedim> k4;
505 velocity->set_time(initial_time + time_step);
506 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
507 k4[comp_i] = velocity->value(p3, comp_i);
508
509 particle_location += time_step / 6 * (k1 + 2 * k2 + 2 * k3 + k4);
510 particle->set_location(particle_location);
511 }
512 solid_particle_handler->sort_particles_into_subdomains_and_cells();
513 initial_time += time_step;
514 }
515
517 solid_particle_handler->n_global_particles())
518 {
519 if (this_mpi_process == 0)
520 {
521 std::cout << "Warning - Nitsche Particles have been lost"
522 << std::endl;
523 std::cout << "Initial number of particles : "
524 << initial_number_of_particles << std::endl;
525 std::cout << "Current number of particles : "
526 << solid_particle_handler->n_global_particles()
527 << std::endl;
528 std::cout << "Try increasing the number of particles sub iterations"
529 << std::endl;
530
531 // Stops the simulation if particles have been lost
532 // Future improvement would be to dynamically increase the number of
533 // particles subiteration if particles have been lost
534 if (param->stop_particles_lost)
535 {
536 std::cerr
537 << std::endl
538 << std::endl
539 << "----------------------------------------------------"
540 << std::endl;
541 std::cerr
542 << "Exception on processing: " << std::endl
543 << "Nitsche Particles have been lost" << std::endl
544 << "Aborting!" << std::endl
545 << "----------------------------------------------------"
546 << std::endl;
547 std::exit(1);
548 }
549 }
550 }
551}
552
553template <int dim, int spacedim>
554void
556 const double initial_time)
557{
558 // First we calculate the displacement that the solid triangulation
559 // will feel during this iteration.
560 // Then, we apply this displacement to the triangulation
561 const unsigned int dofs_per_cell = displacement_fe->dofs_per_cell;
562 const std::vector<bool> locally_owned_vertices =
563 GridTools::get_locally_owned_vertices(*this->solid_tria);
564 std::vector<bool> vertex_moved(this->solid_tria->n_vertices(), false);
565 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
566
567
568 for (const auto &cell : displacement_dh.active_cell_iterators())
569 {
570 if (cell->is_locally_owned())
571 {
572 for (unsigned int vertex = 0;
573 vertex < cell->reference_cell().n_vertices();
574 ++vertex)
575 {
576 // Calculate the next position of the particle using the RK4
577 // time integration scheme
578 // x(t+dt) = x(t) + 1/6 (k1+2*k2+2*k3+k4)
579 // k1 = dt * v(t,x(t))
580 // k2 = dt * v(t+0.5*dt,x+k1/2)
581 // k3 = dt * v(t+0.5*dt,x+k2/2)
582 // k4 = dt * vt(t+dt,x+k3)
583 // The four stages (1 to 4) are built successively
584 // For each stage, the time of the function must be "reset"
585 // to ensure adequate evaluation of the RK4 scheme.
586 // See https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
587 // for more details
588
589 const auto dof_index = cell->vertex_dof_index(vertex, 0);
590 Point<spacedim> &vertex_position = cell->vertex(vertex);
591 const unsigned global_vertex_no = cell->vertex_index(vertex);
592 if (vertex_moved[global_vertex_no] ||
593 !locally_owned_vertices[global_vertex_no])
594 continue;
595
596 Tensor<1, spacedim> k1;
597 velocity->set_time(initial_time);
598 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
599 k1[comp_i] = velocity->value(vertex_position, comp_i);
600
601 Point<spacedim> p1 = vertex_position + time_step / 2 * k1;
602 Tensor<1, spacedim> k2;
603 velocity->set_time(initial_time + time_step / 2);
604 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
605 k2[comp_i] = velocity->value(p1, comp_i);
606
607 Point<spacedim> p2 = vertex_position + time_step / 2 * k2;
608 Tensor<1, spacedim> k3;
609 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
610 k3[comp_i] = velocity->value(p2, comp_i);
611
612 Point<spacedim> p3 = vertex_position + time_step * k3;
613 Tensor<1, spacedim> k4;
614 velocity->set_time(initial_time + time_step);
615 for (int comp_i = 0; comp_i < spacedim; ++comp_i)
616 k4[comp_i] = velocity->value(p3, comp_i);
617
618 auto vertex_displacement =
619 time_step / 6 * (k1 + 2 * k2 + 2 * k3 + k4);
620
621 vertex_position += vertex_displacement;
622
623 for (int d = 0; d < spacedim; ++d)
624 displacement[dof_index + d] =
625 displacement[dof_index + d] + vertex_displacement[d];
626
627 vertex_moved[global_vertex_no] = true;
628 }
629 }
630 }
631 this->solid_tria->communicate_locally_moved_vertices(locally_owned_vertices);
632}
633
634
635template <int dim, int spacedim>
636void
638{
639 const unsigned int dofs_per_cell = displacement_fe->dofs_per_cell;
640 std::set<unsigned int> dof_vertex_displaced;
641 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
642
643 for (const auto &cell : displacement_dh.active_cell_iterators())
644 {
645 if (cell->is_locally_owned())
646 {
647 for (unsigned int vertex = 0;
648 vertex < cell->reference_cell().n_vertices();
649 ++vertex)
650 {
651 if (!dof_vertex_displaced.contains(cell->vertex_index(vertex)))
652 {
653 const auto dof_index = cell->vertex_dof_index(vertex, 0);
654 Point<spacedim> &vertex_position = cell->vertex(vertex);
655
656 for (int d = 0; d < spacedim; ++d)
657 {
658 vertex_position[d] = vertex_position[d] +
659 displacement_relevant[dof_index + d];
660 }
661
662 dof_vertex_displaced.insert(cell->vertex_index(vertex));
663 }
664 }
665 }
666 }
667}
668
669template <int dim, int spacedim>
670void
672{
673 std::map<int, Particles::ParticleIterator<spacedim>> local_particles;
674 for (auto particle = solid_particle_handler->begin();
675 particle != solid_particle_handler->end();
676 ++particle)
677 {
678 local_particles.insert({particle->get_id(), particle});
679 }
680
681 for (auto &iterator : local_particles)
682 {
683 unsigned int id = iterator.first;
684 auto particle = iterator.second;
685 auto particle_location = particle->get_location();
686
687 std::cout << std::fixed << std::setprecision(0) << id << " "
688 << std::setprecision(2) << particle_location << std::endl;
689 }
690}
691
692
693template <int dim, int spacedim>
694void
696{
697 // First, manage the serialization of the particle information.
698 // The particles are attached to the background triangulation and not
699 // the solid triangulation. Consequently, they only need to be prepared
700 // for serialization and will be serialized when the background triangulation
701 // itself is serialized by the main solver.
702 std::string prefix_particles = prefix + "_particles";
703 std::ostringstream oss;
704 boost::archive::text_oarchive oa(oss, boost::archive::no_header);
705 oa << *(this->solid_particle_handler);
706
707 // Write additional particle information for deserialization
708 std::string particle_filename = prefix + ".particles";
709 std::ofstream output(particle_filename.c_str());
710 output << oss.str() << std::endl;
711
712 // Prepare particle handler for serialization
713 this->solid_particle_handler->prepare_for_serialization();
714
715 // Prepare serialization of the solid triangulation which is
716 // only used for visualization purposes
717 SolutionTransfer<dim, GlobalVectorType, spacedim> system_trans_vectors(
718 this->displacement_dh);
719
720 std::vector<const GlobalVectorType *> sol_set_transfer;
722 sol_set_transfer.push_back(&displacement_relevant);
723
724 system_trans_vectors.prepare_for_serialization(sol_set_transfer);
725
726 std::string triangulationName = prefix + ".triangulation";
727 this->solid_tria.get()->save(prefix + ".triangulation");
728}
729
730template <int dim, int spacedim>
731void
733{
734 // Setup an un-refined triangulation before loading if we have a fully
735 // distributed triangulation. If we have a fully distributed triangulation,
736 // nothing should be done to setup the triangulation since it will be fully
737 // generated during the restart process.
738 if (!param->solid_mesh.simplex)
740
741 // Read the triangulation from the checkpoint
742 const std::string filename = prefix + ".triangulation";
743 try
744 {
745 this->solid_tria->load(filename.c_str());
746 }
747 catch (...)
748 {
749 AssertThrow(false,
750 ExcMessage("Cannot open snapshot mesh file or read the "
751 "triangulation stored there."));
752 }
753
754 // Setup dof-handler for solid and displacement
755 solid_dh.distribute_dofs(*fe);
757
758 // Read displacement vector
759 std::vector<GlobalVectorType *> x_system(1);
760 x_system[0] = &(displacement);
761
762 SolutionTransfer<dim, GlobalVectorType, spacedim> system_trans_vectors(
763 this->displacement_dh);
764
765 system_trans_vectors.deserialize(x_system);
767
768 // Reset triangulation position using displacement vector if is not a simplex
769 // triangulation fullydistributed::triangulation store their displacement when
770 // they are saved wheras distributed::triangulation do not.
771 if (!param->solid_mesh.simplex)
773
774 // Gather particle serialization information and deserialize them
775 std::string particle_filename = prefix + ".particles";
776 check_file_exists(particle_filename,
777 "checkpoint file of the solid particles, given by "
778 "'subsection restart' - 'set filename'");
779 std::ifstream input(particle_filename.c_str());
780
781 std::string buffer;
782 std::getline(input, buffer);
783 std::istringstream iss(buffer);
784 boost::archive::text_iarchive ia(iss, boost::archive::no_header);
785
786
787 // At this stage, the pointer for the particle handler has not been allocated
788 // it thus needs to be done by calling the setup
789 // TODO, this function should be called in the constructor
791 ia >> *(this->solid_particle_handler);
792
793 this->solid_particle_handler->deserialize();
794
795 // Number of particles is reset to the number of particles in the
796 // solid_particle_handler after deserialization
798}
799
800
801template <int dim, int spacedim>
802void
804{
805 displacement_dh.distribute_dofs(*this->displacement_fe);
806 locally_owned_dofs = displacement_dh.locally_owned_dofs();
808 DoFTools::extract_locally_relevant_dofs(displacement_dh);
809
814
815 displacement = 0;
816}
817
818
819// Pre-compile the 2D, 3D and the 2D in 3D versions with the types that can
820// occur
821template class SolidBase<2>;
822template class SolidBase<3>;
823template class SolidBase<2, 3>;
Parameters for a single solid object used with the Nitsche immersed boundary method.
std::shared_ptr< Particles::ParticleHandler< spacedim > > & get_solid_particle_handler()
DoFHandler< dim, spacedim > solid_dh
Definition solid_base.h:222
DoFHandler< dim, spacedim > & get_solid_dof_handler()
std::shared_ptr< parallel::DistributedTriangulationBase< dim, spacedim > > solid_tria
Definition solid_base.h:220
void load_particles(const std::string &filename_part)
Loads a particle handler in the fluid triangulation domain that holds the particles of the solid acco...
DoFHandler< dim, spacedim > & get_displacement_dof_handler()
void move_solid_triangulation(double time_step, double initial_time)
Moves the vertices of the solid triangulation. This function uses an Runge-Kutta 4 explicit time inte...
void translate_grid(const Tensor< 1, spacedim > &translate)
Translate the grid. In spacedim=2, the third component is ignore.
const unsigned int this_mpi_process
Definition solid_base.h:217
void update_temperature_time(double time)
Updates the time in the function used to describe the solid temperature.
void load_triangulation(const std::string &filename_tria)
Loads a solid triangulation from a restart file.
std::shared_ptr< Quadrature< dim > > quadrature
Definition solid_base.h:229
void setup_triangulation(const bool restart)
Generates a solid triangulation from a dealii or gmsh mesh.
const unsigned int n_mpi_processes
Definition solid_base.h:216
GlobalVectorType displacement
Definition solid_base.h:234
GlobalVectorType & get_displacement_vector()
std::shared_ptr< Mapping< spacedim > > fluid_mapping
Definition solid_base.h:228
Function< spacedim > * temperature
Definition solid_base.h:241
void initial_setup()
Manages solid triangulation and particles setup.
Definition solid_base.cc:97
std::shared_ptr< Particles::ParticleHandler< spacedim > > solid_particle_handler
Definition solid_base.h:223
std::shared_ptr< Parameters::NitscheObject< spacedim > > & param
Definition solid_base.h:238
void move_solid_triangulation_with_displacement()
Moves the dofs of the solid_triangulation by using the displacement vector. This is only use to move ...
DoFHandler< dim, spacedim > displacement_dh
Definition solid_base.h:232
std::shared_ptr< parallel::DistributedTriangulationBase< spacedim > > fluid_tria
Definition solid_base.h:221
SolidBase(std::shared_ptr< Parameters::NitscheObject< spacedim > > &param, const std::shared_ptr< parallel::DistributedTriangulationBase< spacedim > > &fluid_tria, const std::shared_ptr< Mapping< spacedim > > &fluid_mapping)
Definition solid_base.cc:38
GlobalVectorType displacement_relevant
Definition solid_base.h:235
IndexSet locally_owned_dofs
Definition solid_base.h:212
std::shared_ptr< parallel::DistributedTriangulationBase< dim, spacedim > > get_solid_triangulation()
Function< spacedim > * get_solid_velocity()
void read_checkpoint(const std::string &prefix_name)
read solid base triangulation checkpoint
void setup_displacement()
Sets-up particles with particle handler, in the fluid triangulation domain that holds the particles o...
std::shared_ptr< FiniteElement< dim, spacedim > > fe
Definition solid_base.h:225
MPI_Comm mpi_communicator
Definition solid_base.h:215
std::shared_ptr< Mapping< dim, spacedim > > solid_mapping
Definition solid_base.h:227
Function< spacedim > * get_solid_temperature()
IndexSet locally_relevant_dofs
Definition solid_base.h:213
std::shared_ptr< FESystem< dim, spacedim > > displacement_fe
Definition solid_base.h:233
void setup_particles()
Sets-up particles with particle handler, in the fluid triangulation domain that holds the particles o...
Function< spacedim > * velocity
Definition solid_base.h:240
void write_checkpoint(const std::string &prefix_name)
write solid base triangulation checkpoint
void setup_particles_handler()
Creates a particle handler in the fluid triangulation domain.
unsigned int initial_number_of_particles
Definition solid_base.h:243
void integrate_velocity(double time_step, double initial_time)
Updates particle positions in solid_particle_handler by integrating velocity using an explicit Runge-...
void print_particle_positions()
prints the positions of the particles
void rotate_grid(const double angle, const Tensor< 1, spacedim > &axis)
Rotates the grid by a given angle around an axis.
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...
Definition utilities.cc:225
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17