Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cfd_dem_coupling_matrix_free.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/grids.h>
7#include <core/utilities.h>
8
11
21#include <dem/utilities.h>
26
27#include <boost/archive/text_iarchive.hpp>
28#include <boost/archive/text_oarchive.hpp>
29
30#include <filesystem>
31#include <fstream>
32#include <ranges>
33
34// Constructor for the class CFD-DEM class
35template <int dim, typename PropertiesIndex>
40
41template <int dim, typename PropertiesIndex>
42void
44{
46 setup_distributions(dem_parameters.lagrangian_physical_properties,
49 Utilities::MPI::this_mpi_process(this->mpi_communicator),
50 this->pcout);
51
53 std::pow(dem_parameters.model_parameters.neighborhood_threshold *
55 2);
56}
57
58template <int dim, typename PropertiesIndex>
59void
61{
63
64 // Initialize DEM Parameters
65 dem_parameters.lagrangian_physical_properties =
66 this->cfd_dem_simulation_parameters.dem_parameters
67 .lagrangian_physical_properties;
68 g = dem_parameters.lagrangian_physical_properties.g;
69 dem_parameters.boundary_conditions =
70 this->cfd_dem_simulation_parameters.dem_parameters.boundary_conditions;
71 dem_parameters.insertion_info =
72 this->cfd_dem_simulation_parameters.dem_parameters.insertion_info;
73 dem_parameters.floating_walls =
74 this->cfd_dem_simulation_parameters.dem_parameters.floating_walls;
75 dem_parameters.model_parameters =
76 this->cfd_dem_simulation_parameters.dem_parameters.model_parameters;
77 dem_parameters.simulation_control =
78 this->cfd_dem_simulation_parameters.dem_parameters.simulation_control;
79 dem_parameters.post_processing =
80 this->cfd_dem_simulation_parameters.dem_parameters.post_processing;
81 dem_parameters.mesh = this->cfd_dem_simulation_parameters.dem_parameters.mesh;
82 dem_parameters.restart =
83 this->cfd_dem_simulation_parameters.dem_parameters.restart;
85 dem_parameters.lagrangian_physical_properties.particle_type_number);
86
87 const auto parallel_triangulation =
88 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
89 &*this->triangulation);
90
91 // Setup load balancing parameters
92 load_balancing.set_parameters(dem_parameters.model_parameters);
93 load_balancing.copy_references(this->simulation_control,
94 *parallel_triangulation,
95 this->particle_handler,
97
98 // Attach the correct functions to the signals inside the triangulation
99 load_balancing.connect_weight_signals();
100
101 if (dem_parameters.model_parameters.sparse_particle_contacts)
102 {
103 dem_action_manager->set_sparse_contacts_enabled();
104 sparse_contacts_object.set_parameters(
105 dem_parameters.model_parameters.granular_temperature_threshold,
106 dem_parameters.model_parameters.solid_fraction_threshold,
107 dem_parameters.model_parameters.advect_particles);
108 }
109
111
112 // Calculate the Rayleigh critical time step ratio
113 rayleigh_time_step = DBL_MAX;
114
115 for (unsigned int i = 0;
116 i < dem_parameters.lagrangian_physical_properties.particle_type_number;
117 ++i)
118 {
119 const double youngs_modulus =
120 dem_parameters.lagrangian_physical_properties
121 .youngs_modulus_particle[i];
122 const double poisson_ratio =
123 dem_parameters.lagrangian_physical_properties.poisson_ratio_particle[i];
124 const double density =
125 dem_parameters.lagrangian_physical_properties.density_particle[i];
126 const double shear_modulus =
127 youngs_modulus / (2.0 * (1.0 + poisson_ratio));
128 const double min_diameter =
129 size_distribution_object_container.at(i)->find_min_diameter();
130
132 std::min(M_PI_2 * min_diameter * sqrt(density / shear_modulus) /
133 (0.1631 * poisson_ratio + 0.8766),
135 }
136
137 // Create a first instance of the DEM sub simulation control
138 dem_simulation_control = std::make_shared<SubSimulationControlDEM>(
139 this->cfd_dem_simulation_parameters.cfd_dem.dem_iteration_control,
140 this->simulation_control->get_time_step(),
141 this->cfd_dem_simulation_parameters.cfd_dem.coupling_frequency,
143 this->cfd_dem_simulation_parameters.cfd_dem.fraction_of_rayleigh_time);
145
146 // Check if there are periodic boundaries
147 if (!dem_parameters.boundary_conditions.periodic_boundaries.empty())
148 {
149 dem_action_manager->set_periodic_boundaries_enabled();
150
151 periodic_boundaries_object.set_periodic_boundaries_information(
152 dem_parameters.boundary_conditions.periodic_boundaries);
153 }
154
157 *parallel_triangulation,
160
161 // Initialize the total contact list counter
165 this->cfd_dem_simulation_parameters.dem_parameters);
166
167 // Initialize the contact search counter
169}
170
171template <int dim, typename PropertiesIndex>
172std::shared_ptr<Integrator<dim, PropertiesIndex>>
174{
175 using namespace Parameters::Lagrangian;
176 typename ModelParameters<dim>::IntegrationMethod integration_method =
177 dem_parameters.model_parameters.integration_method;
178
179 switch (integration_method)
180 {
182 return std::make_shared<
185 return std::make_shared<
187 default:
188 throw(std::runtime_error("Invalid integration method."));
189 }
190}
191
192template <int dim, typename PropertiesIndex>
193void
195{
196 this->pcout << "Initializing DEM parameters" << std::endl;
197
198 const auto parallel_triangulation =
199 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
200 &*this->triangulation);
201
202 // Set up the local and ghost cells (if ASC enabled)
203 sparse_contacts_object.update_local_and_ghost_cell_set(
204 *this->particle_projector.dof_handler);
205
208 this->cfd_dem_simulation_parameters.dem_parameters);
209
210 // Set the temperature of the walls of the grid for the first DEM iteration.
213 this->cfd_dem_simulation_parameters.dem_parameters.boundary_conditions,
214 this->simulation_control->get_current_time());
215
216 // Finding the smallest contact search frequency criterion between (smallest
217 // cell size - largest particle radius) and (security factor * (blob diameter
218 // - 1) * the largest particle radius). This value is used in
219 // find_contact_detection_frequency function
221 std::min((GridTools::minimal_cell_diameter(*this->triangulation) -
223 (dem_parameters.model_parameters.dynamic_contact_search_factor *
224 (dem_parameters.model_parameters.neighborhood_threshold - 1) *
226
227 // Remap periodic cells (if PBC enabled)
228 periodic_boundaries_object.map_periodic_cells(
229 *parallel_triangulation, periodic_boundaries_cells_information);
230
231 // Set the periodic offset per direction to the contact manager for
232 // periodic contact detection (if PBC enabled)
233 contact_manager.set_periodic_offset_per_direction(
234 periodic_boundaries_object.get_periodic_offset_per_direction());
235
236 // Set the periodic offsets of the periodic boundary pairs for other classes
237 for (const auto &pb_id :
238 periodic_boundaries_object.get_periodic_boundaries() | std::views::keys)
239 {
240 particle_particle_contact_force_object->set_periodic_offset(
241 periodic_boundaries_object.get_periodic_offset_distance(pb_id), pb_id);
242 }
243
244
245 // Find cell neighbors
246 contact_manager.execute_cell_neighbors_search(
247 *parallel_triangulation, periodic_boundaries_cells_information);
248
249 // Find boundary cells with faces
251 *parallel_triangulation,
252 dem_parameters.floating_walls,
253 dem_parameters.boundary_conditions.outlet_boundaries,
254 this->cfd_dem_simulation_parameters.cfd_parameters.mesh
255 .check_for_diamond_cells,
256 this->cfd_dem_simulation_parameters.cfd_parameters.mesh
257 .expand_particle_wall_contact_search,
258 this->pcout);
259
261
262 // Remap periodic nodes after setup of dofs (If ASC and PBC)
263 if (dem_action_manager->check_periodic_boundaries_enabled() &&
264 dem_action_manager->check_sparse_contacts_enabled())
265 {
266 sparse_contacts_object.map_periodic_nodes(
267 this->particle_projector.void_fraction_constraints);
268 }
269
270
271
272 this->pcout << "Finished initializing DEM parameters" << std::endl
273 << "DEM time step is "
274 << this->dem_simulation_control->get_time_step() << " s"
275 << std::endl;
276}
277
278template <int dim, typename PropertiesIndex>
279void
281{
282 this->pcout << "Reading DEM checkpoint" << std::endl;
283
284 std::string prefix =
285 this->cfd_dem_simulation_parameters.void_fraction->dem_file_name;
286
287 // Load checkpoint controller
288 std::string checkpoint_controller_object_filename =
289 prefix + ".checkpoint_controller";
290 check_file_exists(checkpoint_controller_object_filename,
291 "checkpoint file of the checkpoint controller, given by "
292 "'subsection void fraction' - 'set dem file name'");
293 std::ifstream iss_checkpoint_controller_obj(
294 checkpoint_controller_object_filename);
295 boost::archive::text_iarchive ia_checkpoint_controller_obj(
296 iss_checkpoint_controller_obj, boost::archive::no_header);
297
298 unsigned int checkpoint_id;
299 ia_checkpoint_controller_obj >> checkpoint_id;
300
301 // New prefix for the remaining files
302 prefix = prefix + "_" + Utilities::int_to_string(checkpoint_id);
303
304 // Gather particle serialization information
305 std::string particle_filename = prefix + ".particles";
306 check_file_exists(particle_filename,
307 "checkpoint file of the particles, given by "
308 "'subsection void fraction' - 'set dem file name'");
309 std::ifstream input(particle_filename.c_str());
310
311 std::string buffer;
312 std::getline(input, buffer);
313 std::istringstream iss(buffer);
314 boost::archive::text_iarchive ia(iss, boost::archive::no_header);
315
316 // Create a temporary particle_handler with the DEM properties of the
317 // simulation this one is restarted from
318 using DEMPropertiesIndex =
320
321 Particles::ParticleHandler<dim> temporary_particle_handler(
322 *this->triangulation,
323 this->particle_mapping,
324 DEMPropertiesIndex::n_properties);
325
326 ia >> temporary_particle_handler;
327
328 const std::string filename = prefix + ".triangulation";
329 check_file_exists(filename,
330 "checkpoint file of the triangulation, given by "
331 "'subsection void fraction' - 'set dem file name'");
332
333 if (auto parallel_triangulation =
334 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
335 &*this->triangulation))
336 {
337 try
338 {
339 parallel_triangulation->load(filename.c_str());
340
341 // Deserialize particles have the triangulation has been read
342 temporary_particle_handler.deserialize();
343 }
344 catch (...)
345 {
346 AssertThrow(false,
347 ExcMessage("Cannot open snapshot mesh file or read the"
348 "triangulation stored there."));
349 }
350
351 // Fill the existing particle handler using the temporary one
352 // This is done during the dynamic cast for the convert_particle_handler
353 // function which requires a parallel::distributed::triangulation
355 *parallel_triangulation,
356 temporary_particle_handler,
357 this->particle_handler);
358 }
359 else
360 {
361 throw std::runtime_error(
362 "VANS equations currently do not support triangulations other than parallel::distributed");
363 }
364
365 this->pcout << "Finished reading DEM checkpoint" << std::endl
366 << this->particle_handler.n_global_particles()
367 << " particles are in the simulation" << std::endl;
368
370}
371
372template <int dim, typename PropertiesIndex>
373std::vector<OutputStructTableHandler>
375{
376 std::vector<OutputStructTableHandler> table_output_structs;
377
378 const Parameters::PostProcessing<dim> post_processing =
379 this->simulation_parameters.post_processing;
380 std::string prefix =
381 this->simulation_parameters.simulation_control.output_folder;
382 std::string suffix = ".checkpoint";
383 if (post_processing.calculate_phase_volumes)
384 table_output_structs.emplace_back(
386 prefix + post_processing.phase_volumes_output_name + suffix);
387 return table_output_structs;
388}
389
390template <int dim, typename PropertiesIndex>
391void
393{
394 using VectorType = LinearAlgebra::distributed::Vector<double>;
395
396 TimerOutput::Scope timer(this->computing_timer, "Write checkpoint");
397
398 std::string prefix =
399 this->simulation_parameters.simulation_control.output_folder +
400 this->simulation_parameters.restart_parameters.filename;
401 std::string prefix_particles = prefix + "_particles";
402 std::string prefix_grid = prefix + "_lagrangian_postprocessing";
403
404 // Register the particles for serialization (all ranks)
405 this->particle_handler.prepare_for_serialization();
406
407 // This only needs to be done by rank 0.
408 if (Utilities::MPI::this_mpi_process(this->mpi_communicator) == 0)
409 {
410 this->simulation_control->save(prefix);
411 this->pvdhandler.save(prefix);
412 particles_pvdhandler.save(prefix_particles);
413
414 if (this->dem_parameters.post_processing
415 .lagrangian_post_processing_enabled)
416 grid_pvdhandler.save(prefix_grid);
417
418 if (this->simulation_parameters.flow_control.enable_flow_control)
419 this->flow_control.save(prefix);
420
421 // Serialize the global particle counters
422 std::ostringstream oss_particle_handler;
423 boost::archive::text_oarchive oa_particle_handler(
424 oss_particle_handler, boost::archive::no_header);
425 oa_particle_handler << this->particle_handler;
426
427 // Write additional particle information for deserialization
428 std::string particle_filename = prefix + ".particles";
429 std::ofstream output(particle_filename.c_str());
430 output << oss_particle_handler.str() << std::endl;
431
432 // Prepare the insertion object for checkpointing
433 std::string insertion_object_filename = prefix + ".insertion_object";
434 std::ofstream oss_insertion_obj(insertion_object_filename);
435 boost::archive::text_oarchive oa_insertion_obj(oss_insertion_obj,
436 boost::archive::no_header);
437 insertion_object->serialize(oa_insertion_obj);
438 }
439
440 std::vector<const VectorType *> sol_set_transfer;
441 sol_set_transfer.push_back(&(*this->present_solution));
442 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
443 {
444 sol_set_transfer.push_back(&(*this->previous_solutions)[i]);
445 }
446
448 {
449 std::vector<const VectorType *> av_set_transfer =
450 this->average_velocities->save(prefix);
451
452 // Insert average velocities vectors into the set transfer vector
453 sol_set_transfer.insert(sol_set_transfer.end(),
454 av_set_transfer.begin(),
455 av_set_transfer.end());
456 }
457
458 // Prepare for Serialization
459 SolutionTransfer<dim, VectorType> system_trans_vectors(*this->dof_handler);
460 system_trans_vectors.prepare_for_serialization(sol_set_transfer);
461
462 // Void Fraction
463 std::vector<const VectorType *> vf_set_transfer;
464 vf_set_transfer.push_back(&this->particle_projector.void_fraction_solution);
465 for (unsigned int i = 0;
466 i < this->particle_projector.void_fraction_previous_solution.size();
467 ++i)
468 {
469 vf_set_transfer.push_back(
470 &this->particle_projector.void_fraction_previous_solution[i]);
471 }
472
473 this->multiphysics->write_checkpoint();
474
475 // Prepare for Serialization
476 SolutionTransfer<dim, VectorType> vf_system_trans_vectors(
477 *this->particle_projector.dof_handler);
478 vf_system_trans_vectors.prepare_for_serialization(vf_set_transfer);
479
480 if (auto parallel_triangulation =
481 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
482 &*this->triangulation))
483 {
484 parallel_triangulation->save(prefix + ".triangulation");
485 }
486 // Serialize all post-processing tables that are currently used
487 // Serialize the post-processing tables that are additional in this solver
488 const std::vector<OutputStructTableHandler> &table_output_structs_add =
489 this->gather_tables();
490 serialize_tables_vector(table_output_structs_add, this->mpi_communicator);
491 // Serialize the default post-processing tables that are members of
492 // NavierStokesBase
493 const std::vector<OutputStructTableHandler> &table_output_structs =
495 serialize_tables_vector(table_output_structs, this->mpi_communicator);
496}
497
498template <int dim, typename PropertiesIndex>
499void
501{
502 TimerOutput::Scope timer(this->computing_timer, "Read checkpoint");
503 using VectorType = LinearAlgebra::distributed::Vector<double>;
504 std::string prefix =
505 this->simulation_parameters.simulation_control.output_folder +
506 this->simulation_parameters.restart_parameters.filename;
507 std::string prefix_particles = prefix + "_particles";
508 std::string prefix_grid = prefix + "_lagrangian_postprocessing";
509
510 this->simulation_control->read(prefix);
511 this->pvdhandler.read(prefix);
512 particles_pvdhandler.read(prefix_particles);
513
514 if (this->dem_parameters.post_processing.lagrangian_post_processing_enabled)
515 {
516 grid_pvdhandler.read(prefix_grid);
517 }
518
519 // Gather particle serialization information
520 std::string particle_filename = prefix + ".particles";
521 check_file_exists(particle_filename,
522 "checkpoint file of the particles, given by "
523 "'subsection restart' - 'set filename'");
524 std::ifstream input(particle_filename.c_str());
525
526 std::string buffer;
527 std::getline(input, buffer);
528 std::istringstream iss(buffer);
529 boost::archive::text_iarchive ia(iss, boost::archive::no_header);
530
531 ia >> this->particle_handler;
532
533 // Load the insertion object. Checkpoints written before the insertion object
534 // was checkpointed in CFD-DEM simulations do not contain this file. In that
535 // case, the insertion object keeps the state it was initialized with.
536 std::string insertion_object_filename = prefix + ".insertion_object";
537 if (std::filesystem::exists(insertion_object_filename))
538 {
539 std::ifstream iss_insertion_obj(insertion_object_filename);
540 boost::archive::text_iarchive ia_insertion_obj(iss_insertion_obj,
541 boost::archive::no_header);
542 insertion_object->deserialize(ia_insertion_obj);
543 }
544
545 const std::string filename = prefix + ".triangulation";
546 check_file_exists(filename,
547 "checkpoint file of the triangulation, given by "
548 "'subsection restart' - 'set filename'");
549
550 try
551 {
552 if (auto parallel_triangulation =
553 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
554 this->triangulation.get()))
555 parallel_triangulation->load(filename.c_str());
556 }
557 catch (...)
558 {
559 AssertThrow(false,
560 ExcMessage("Cannot open snapshot mesh file or read the "
561 "triangulation stored there."));
562 }
563
564 this->setup_dofs();
565
566 // TODO BB
567 // Remap periodic nodes after setup of dofs
568 if (dem_action_manager->check_periodic_boundaries_enabled() &&
569 dem_action_manager->check_sparse_contacts_enabled())
570 {
571 sparse_contacts_object.map_periodic_nodes(
572 this->particle_projector.void_fraction_constraints);
573 }
574
575 // Velocity Vectors
576 std::vector<VectorType *> x_system(1 + this->previous_solutions->size());
577
578 VectorType distributed_system(this->locally_owned_dofs,
580 this->mpi_communicator);
581
582 x_system[0] = &(distributed_system);
583
584 std::vector<VectorType> distributed_previous_solutions;
585
586 distributed_previous_solutions.reserve(this->previous_solutions->size());
587
588 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
589 {
590 distributed_previous_solutions.emplace_back(
593 this->mpi_communicator));
594 x_system[i + 1] = &distributed_previous_solutions[i];
595 }
596
597 SolutionTransfer<dim, VectorType> system_trans_vectors(*this->dof_handler);
598
600 {
601 std::vector<VectorType *> sum_vectors =
602 this->average_velocities->read(prefix);
603
604 x_system.insert(x_system.end(), sum_vectors.begin(), sum_vectors.end());
605 }
606
607 system_trans_vectors.deserialize(x_system);
608
609 *this->present_solution = distributed_system;
610 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
611 {
612 (*this->previous_solutions)[i] = distributed_previous_solutions[i];
613 }
614
616
617 // The deserialized vectors only carry valid locally owned entries; their
618 // ghost values are stale. The particle-fluid force/drag projection evaluates
619 // the fluid solution at particle locations on the first restarted step
620 // (before any Newton solve refreshes the ghosts) and therefore reads these
621 // ghost values directly. Refresh them here so that the restarted step matches
622 // a continuous run, where present_solution and previous_solutions are always
623 // left ghosted after a solve.
624 this->present_solution->update_ghost_values();
625 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
626 (*this->previous_solutions)[i].update_ghost_values();
627
628 // Void Fraction Vectors
629 std::vector<VectorType *> vf_system(
630 1 + this->particle_projector.previous_void_fraction->size());
631
632 VectorType vf_distributed_system(
633 this->particle_projector.locally_owned_dofs,
634 this->particle_projector.locally_relevant_dofs,
635 this->mpi_communicator);
636
637 vf_system[0] = &(vf_distributed_system);
638
639 std::vector<VectorType> vf_distributed_previous_solutions;
640
641 vf_distributed_previous_solutions.reserve(
642 this->particle_projector.previous_void_fraction->size());
643
644 for (unsigned int i = 0;
645 i < this->particle_projector.previous_void_fraction->size();
646 ++i)
647 {
648 vf_distributed_previous_solutions.emplace_back(
649 VectorType(this->particle_projector.locally_owned_dofs,
650 this->particle_projector.locally_relevant_dofs,
651 this->mpi_communicator));
652 vf_system[i + 1] = &vf_distributed_previous_solutions[i];
653 }
654
655 SolutionTransfer<dim, VectorType> vf_system_trans_vectors(
656 *this->particle_projector.dof_handler);
657
658 vf_system_trans_vectors.deserialize(vf_system);
659
660 this->particle_projector.void_fraction_solution = vf_distributed_system;
661
662#ifndef LETHE_USE_LDV
663 // We also wish the Trilinos solution to be updated.
665 this->particle_projector.void_fraction_locally_owned,
666 this->particle_projector.void_fraction_solution);
667
668 *this->particle_projector.void_fraction_locally_relevant =
669 this->particle_projector.void_fraction_locally_owned;
670#endif
671
672 for (unsigned int i = 0;
673 i < this->particle_projector.previous_void_fraction->size();
674 ++i)
675 {
676 this->particle_projector.void_fraction_previous_solution[i] =
677 vf_distributed_previous_solutions[i];
678
679#ifndef LETHE_USE_LDV
680 // We also wish the Trilinos solution to be updated.
682 this->particle_projector.void_fraction_locally_owned,
683 this->particle_projector.void_fraction_previous_solution[i]);
684 this->particle_projector.previous_void_fraction->at(i) =
685 this->particle_projector.void_fraction_locally_owned;
686#endif
687 }
688
689 // As for the fluid solution vectors above, the deserialized void fraction
690 // vectors only carry valid locally owned entries; their ghost values are
691 // stale. This is not felt on the restarted step itself, since the void
692 // fraction time derivative is assembled with add(), which only touches
693 // locally owned entries. It is felt at the *end* of the step: percolation
694 // copies void_fraction_previous_solution[0] into [1], propagating the stale
695 // ghosts, and the next write_checkpoint packs the vectors with
696 // SolutionTransfer, which reads ghost values to serialize the dofs of
697 // locally owned cells that sit on a subdomain boundary. The checkpoint would
698 // then store wrong void fractions on those dofs. Since the BDF time
699 // derivative of the void fraction is a small difference of large terms
700 // (the coefficients scale as 1/dt and cancel for a constant field), such
701 // errors do not stay small: they inject a spurious source in the continuity
702 // equation that grows with the number of subdomain boundaries and compounds
703 // over successive restarts. Refresh the ghosts here to keep the invariant
704 // that these vectors are always ghosted outside of a solve.
705 this->particle_projector.void_fraction_solution.update_ghost_values();
706 for (unsigned int i = 0;
707 i < this->particle_projector.void_fraction_previous_solution.size();
708 ++i)
709 this->particle_projector.void_fraction_previous_solution[i]
710 .update_ghost_values();
711
712 if (this->simulation_parameters.flow_control.enable_flow_control)
713 {
714 this->flow_control.read(prefix);
715 }
716 this->multiphysics->read_checkpoint();
717
718 // Deserialize particles have the triangulation has been read
719 this->particle_handler.deserialize();
720
721 // Deserialize all post-processing tables that are currently used
722 // Deserialize the post-processing tables that are particular to this solver
723 std::vector<OutputStructTableHandler> table_output_structs_add =
724 this->gather_tables();
725 deserialize_tables_vector(table_output_structs_add, this->mpi_communicator);
726
727 // Deserialize the default post-processing tables that are members of
728 // NavierStokesBase
729 std::vector<OutputStructTableHandler> table_output_structs =
731 deserialize_tables_vector(table_output_structs, this->mpi_communicator);
732
733 // Force a resort of the particles and exchange the ghost particles
734 // to ensure the cache to update the ghost particles is correctly
735 // built.
736 this->particle_handler.sort_particles_into_subdomains_and_cells();
737 this->particle_handler.exchange_ghost_particles(true);
738}
739
740template <int dim, typename PropertiesIndex>
741void
743 unsigned int counter)
744{
745 // Use namespace and alias to make the code more readable
746 using namespace Parameters::Lagrangian;
748 dem_parameters.model_parameters;
749
750 switch (model_parameters.contact_detection_method)
751 {
753 {
754 if ((counter % model_parameters.contact_detection_frequency) == 0)
755 dem_action_manager->contact_detection_step();
756 break;
757 }
759 {
760 double dt =
761 this->simulation_control->get_time_step() /
762 this->cfd_dem_simulation_parameters.cfd_dem.coupling_frequency;
763
765 this->particle_handler,
766 dt,
768 this->mpi_communicator,
770 break;
771 }
772 default:
773 break;
774 }
775}
776
777
778
779template <int dim, typename PropertiesIndex>
780void
782{
783 load_balancing.check_load_balance_iteration();
784
785 // If not a load balance iteration, exit the function
786 if (!dem_action_manager->check_load_balance())
787 return;
788
789 using VectorType = LinearAlgebra::distributed::Vector<double>;
790
791 // First prepare the solution of the VANS equations for the transfer
792 std::vector<const VectorType *> sol_set_transfer;
793 sol_set_transfer.push_back(&(*this->present_solution));
794 this->present_solution->update_ghost_values();
795 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
796 {
797 (*this->previous_solutions)[i].update_ghost_values();
798 sol_set_transfer.push_back(&(*this->previous_solutions)[i]);
799 }
800
801 // Prepare for Serialization
802 SolutionTransfer<dim, VectorType> system_trans_vectors(*this->dof_handler);
803 system_trans_vectors.prepare_for_coarsening_and_refinement(sol_set_transfer);
804
805 // The time-averaged velocity accumulators live on the fluid dof handler and
806 // must be transferred to the new partition as well. Otherwise the setup_dofs
807 // below resets them to zero while the total averaging time keeps spanning
808 // the whole averaging window, which makes the average velocity and the
809 // Reynolds stresses decay towards zero at every load balance.
811 this->average_velocities->prepare_for_mesh_adaptation();
812
813 // Now do the same process for the void fraction
814 // Void Fraction
815 std::vector<const VectorType *> vf_set_transfer;
816 vf_set_transfer.push_back(&this->particle_projector.void_fraction_solution);
817 this->particle_projector.void_fraction_solution.update_ghost_values();
818
819 for (unsigned int i = 0;
820 i < this->particle_projector.void_fraction_previous_solution.size();
821 ++i)
822 {
823 this->particle_projector.void_fraction_previous_solution[i]
824 .update_ghost_values();
825 vf_set_transfer.push_back(
826 &this->particle_projector.void_fraction_previous_solution[i]);
827 }
828
829 // Prepare for Serialization
830 SolutionTransfer<dim, VectorType> vf_system_trans_vectors(
831 *this->particle_projector.dof_handler);
832 vf_system_trans_vectors.prepare_for_coarsening_and_refinement(
833 vf_set_transfer);
834
835 // Let's now prepare the particle handler for the load balancing
836 // Prepare particle handle for serialization
837 this->particle_handler.prepare_for_coarsening_and_refinement();
838
839 this->pcout << "-->Repartitioning triangulation" << std::endl;
840
841 const auto parallel_triangulation =
842 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
843 &*this->triangulation);
844
845 parallel_triangulation->repartition();
846
847 // If PBC are enabled remap periodic cells
848 periodic_boundaries_object.map_periodic_cells(
849 *parallel_triangulation, periodic_boundaries_cells_information);
850
851 // Update cell neighbors
852 contact_manager.update_cell_neighbors(*parallel_triangulation,
854
856 *parallel_triangulation,
857 dem_parameters.floating_walls,
858 dem_parameters.boundary_conditions.outlet_boundaries,
859 this->cfd_dem_simulation_parameters.cfd_parameters.mesh
860 .check_for_diamond_cells,
861 this->cfd_dem_simulation_parameters.cfd_parameters.mesh
862 .expand_particle_wall_contact_search,
863 this->pcout);
864
865 const auto average_minimum_maximum_cells =
866 Utilities::MPI::min_max_avg(parallel_triangulation->n_active_cells(),
867 this->mpi_communicator);
868
869 const auto average_minimum_maximum_particles = Utilities::MPI::min_max_avg(
870 this->particle_handler.n_locally_owned_particles(), this->mpi_communicator);
871
872 this->pcout << "Load balance finished" << std::endl;
873 this->pcout
874 << "Average, minimum and maximum number of particles on the processors are "
875 << average_minimum_maximum_particles.avg << " , "
876 << average_minimum_maximum_particles.min << " and "
877 << average_minimum_maximum_particles.max << std::endl;
878 this->pcout
879 << "Minimum and maximum number of cells owned by the processors are "
880 << average_minimum_maximum_cells.min << " and "
881 << average_minimum_maximum_cells.max << std::endl;
882
883 this->pcout << "Setup DOFs" << std::endl;
884 this->setup_dofs();
885
886 // Remap periodic nodes after setup of dofs
887 if (dem_action_manager->check_periodic_boundaries_enabled() &&
888 dem_action_manager->check_sparse_contacts_enabled())
889 {
890 sparse_contacts_object.map_periodic_nodes(
891 this->particle_projector.void_fraction_constraints);
892 }
893
894 // Velocity Vectors
895 std::vector<VectorType *> x_system(1 + this->previous_solutions->size());
896
897 VectorType distributed_system(this->locally_owned_dofs,
899 this->mpi_communicator);
900
901
902 x_system[0] = &(distributed_system);
903
904 std::vector<VectorType> distributed_previous_solutions;
905
906 distributed_previous_solutions.reserve(this->previous_solutions->size());
907
908 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
909 {
910 distributed_previous_solutions.emplace_back(
913 this->mpi_communicator));
914 x_system[i + 1] = &distributed_previous_solutions[i];
915 }
916
917 system_trans_vectors.interpolate(x_system);
918
919 distributed_system.update_ghost_values();
920 *this->present_solution = distributed_system;
921
922 for (unsigned int i = 0; i < this->previous_solutions->size(); ++i)
923 {
924 distributed_previous_solutions[i].update_ghost_values();
925 (*this->previous_solutions)[i] = distributed_previous_solutions[i];
926 }
927
928 // Restore the time-averaged velocity accumulators on the new partition. This
929 // also reevaluates the average velocity and the Reynolds stresses from the
930 // transferred sums.
932 this->average_velocities->post_mesh_adaptation();
933
934 x_system.clear();
935
936 // Void Fraction Vectors
937 std::vector<VectorType *> vf_system(
938 1 + this->particle_projector.previous_void_fraction->size());
939
940 VectorType vf_distributed_system(
941 this->particle_projector.locally_owned_dofs,
942 this->particle_projector.locally_relevant_dofs,
943 this->mpi_communicator);
944
945 vf_system[0] = &(vf_distributed_system);
946
947 std::vector<VectorType> vf_distributed_previous_solutions;
948
949 vf_distributed_previous_solutions.reserve(
950 this->particle_projector.previous_void_fraction->size());
951
952 for (unsigned int i = 0;
953 i < this->particle_projector.previous_void_fraction->size();
954 ++i)
955 {
956 vf_distributed_previous_solutions.emplace_back(
957 VectorType(this->particle_projector.locally_owned_dofs,
958 this->particle_projector.locally_relevant_dofs,
959 this->mpi_communicator));
960 vf_system[i + 1] = &vf_distributed_previous_solutions[i];
961 }
962
963 vf_system_trans_vectors.interpolate(vf_system);
964
965 // Refresh the ghost values of the freshly interpolated void fraction vectors,
966 // exactly as is done for the fluid vectors above. interpolate() only fills
967 // locally owned entries, leaving stale ghosts. If these are not refreshed,
968 // the stale ghosts are later propagated by percolate_void_fraction (which
969 // copies whole vectors) and, when a checkpoint is written on a load balance
970 // step, packed into the checkpoint by prepare_for_serialization (which reads
971 // ghost values to serialize the dofs of locally owned cells sitting on a
972 // subdomain boundary). This would store wrong void fractions on those dofs
973 // and, since the BDF void fraction time derivative amplifies them by ~1/dt,
974 // cause an abnormally high residual on the restarted step.
975 vf_distributed_system.update_ghost_values();
976
977 // Store the interpolated void fraction before converting it to a Trilinos
978 // vector, otherwise the conversion below would pick up the stale (post
979 // setup_dofs, zeroed) content of void_fraction_solution instead of the
980 // freshly interpolated field.
981 this->particle_projector.void_fraction_solution = vf_distributed_system;
982
983#ifndef LETHE_USE_LDV
984 // We also wish the Trilinos solution to be updated.
986 this->particle_projector.void_fraction_locally_owned,
987 this->particle_projector.void_fraction_solution);
988
989 *this->particle_projector.void_fraction_locally_relevant =
990 this->particle_projector.void_fraction_locally_owned;
991#endif
992
993 for (unsigned int i = 0;
994 i < this->particle_projector.previous_void_fraction->size();
995 ++i)
996 {
997 // Refresh the ghost values before storing, for the same reason as the
998 // void_fraction_solution above: interpolate() leaves stale ghosts, which
999 // would otherwise be propagated by percolation and serialized into the
1000 // checkpoint on a load balance step.
1001 vf_distributed_previous_solutions[i].update_ghost_values();
1002
1003 this->particle_projector.void_fraction_previous_solution[i] =
1004 vf_distributed_previous_solutions[i];
1005
1006#ifndef LETHE_USE_LDV
1007 // We also wish the Trilinos solution to be updated.
1009 this->particle_projector.void_fraction_locally_owned,
1010 this->particle_projector.void_fraction_previous_solution[i]);
1011 this->particle_projector.previous_void_fraction->at(i) =
1012 this->particle_projector.void_fraction_locally_owned;
1013#endif
1014 }
1015
1016 vf_system.clear();
1017
1018 // Unpack particle handler after load balancing step
1019 this->particle_handler.unpack_after_coarsening_and_refinement();
1020}
1021
1022template <int dim, typename PropertiesIndex>
1023void
1025{
1026 /// Reference to torque vector from contact outcomes
1027 std::vector<Tensor<1, 3>> &torque = contact_outcome.torque;
1028
1029 /// Reference to force vector from contact outcomes
1030 std::vector<Tensor<1, 3>> &force = contact_outcome.force;
1031
1032 for (auto particle = this->particle_handler.begin();
1033 particle != this->particle_handler.end();
1034 ++particle)
1035 {
1036 auto particle_properties = particle->get_properties();
1037
1038 types::particle_index particle_id = particle->get_local_index();
1039
1040 force[particle_id][0] +=
1041 particle_properties[PropertiesIndex::fem_force_two_way_coupling_x] +
1042 particle_properties[PropertiesIndex::fem_force_one_way_coupling_x] +
1043 particle_properties[PropertiesIndex::fem_drag_x];
1044 force[particle_id][1] +=
1045 particle_properties[PropertiesIndex::fem_force_two_way_coupling_y] +
1046 particle_properties[PropertiesIndex::fem_force_one_way_coupling_y] +
1047 particle_properties[PropertiesIndex::fem_drag_y];
1048 force[particle_id][2] +=
1049 particle_properties[PropertiesIndex::fem_force_two_way_coupling_z] +
1050 particle_properties[PropertiesIndex::fem_force_one_way_coupling_z] +
1051 particle_properties[PropertiesIndex::fem_drag_z];
1052 torque[particle_id][0] +=
1053 particle_properties[PropertiesIndex::fem_torque_x];
1054 torque[particle_id][1] +=
1055 particle_properties[PropertiesIndex::fem_torque_y];
1056 torque[particle_id][2] +=
1057 particle_properties[PropertiesIndex::fem_torque_z];
1058 }
1059}
1060
1061template <int dim, typename PropertiesIndex>
1062void
1064{
1065 // If the insertion frequency is set to 0, then no particles are going
1066 // to be inserted in the CFD-DEM simulation and the function returns
1067 if (dem_parameters.insertion_info.insertion_frequency == 0)
1068 return;
1069
1070 const auto parallel_triangulation =
1071 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
1072 &*this->triangulation);
1073 if ((this->simulation_control->get_iteration_number() %
1074 dem_parameters.insertion_info.insertion_frequency) == 1 ||
1075 this->simulation_control->get_iteration_number() == 1)
1076 {
1077 insertion_object->insert(this->particle_handler,
1078 *parallel_triangulation,
1080
1081 dem_action_manager->particle_insertion_step();
1082
1083 // Sort particles after insertion
1085 }
1086}
1087
1088template <int dim, typename PropertiesIndex>
1089void
1091{
1092 const double dem_time_step = this->dem_simulation_control->get_time_step();
1093
1094 // Particle-wall contact force
1095 particle_wall_contact_force_object->calculate_particle_wall_contact(
1096 contact_manager.get_particle_wall_in_contact(),
1097 dem_time_step,
1099
1100 // Particle-floating wall contact force
1101 if (dem_parameters.floating_walls.floating_walls_number > 0)
1102 {
1103 particle_wall_contact_force_object->calculate_particle_wall_contact(
1104 contact_manager.get_particle_floating_wall_in_contact(),
1105 dem_time_step,
1107 }
1108
1110 .calculate_particle_point_contact_force(
1111 &contact_manager.get_particle_points_in_contact(),
1112 dem_parameters.lagrangian_physical_properties,
1113 contact_outcome.force);
1114
1115 if constexpr (dim == 3)
1116 {
1118 .calculate_particle_line_contact_force(
1119 &contact_manager.get_particle_lines_in_contact(),
1120 dem_parameters.lagrangian_physical_properties,
1121 contact_outcome.force);
1122 }
1123}
1124
1125template <int dim, typename PropertiesIndex>
1126void
1128{
1129 const std::string folder = dem_parameters.simulation_control.output_folder;
1130 const std::string particles_solution_name =
1131 dem_parameters.simulation_control.output_name + "_particles";
1132 const unsigned int iter = this->simulation_control->get_iteration_number();
1133 const double time = this->simulation_control->get_current_time();
1134 const unsigned int group_files =
1135 dem_parameters.simulation_control.group_files;
1136
1137 // Write particles
1138 Visualization<dim, PropertiesIndex> particle_data_out;
1139 particle_data_out.build_patches(this->particle_handler,
1140 properties_class.get_properties_name());
1141
1143 particle_data_out,
1144 folder,
1145 particles_solution_name,
1146 time,
1147 iter,
1148 group_files,
1149 this->mpi_communicator);
1150}
1151
1152
1153template <int dim, typename PropertiesIndex>
1154void
1156{
1157 const auto this_mpi_process =
1158 Utilities::MPI::this_mpi_process(this->mpi_communicator);
1159 // Update statistics on contact list
1160 double number_of_list_built_since_last_log =
1162 contact_list.max =
1163 std::max(number_of_list_built_since_last_log, contact_list.max);
1164 contact_list.min =
1165 std::min(number_of_list_built_since_last_log, contact_list.min);
1167 contact_list.average = contact_list.total /
1168 (this->simulation_control->get_iteration_number()) *
1169 this->simulation_control->get_log_frequency();
1170
1171 // Calculate statistics on the particles
1173 dim,
1174 PropertiesIndex,
1176 this->particle_handler, this->mpi_communicator);
1178 dim,
1179 PropertiesIndex,
1181 this->particle_handler, this->mpi_communicator);
1184 PropertiesIndex,
1186 this->particle_handler, this->mpi_communicator);
1189 PropertiesIndex,
1191 this->particle_handler, this->mpi_communicator);
1192
1193 if (this_mpi_process == 0)
1194 {
1195 TableHandler report;
1196
1197 std::vector<std::string> column_names{
1198 "Variable", "Min", "Max", "Average", "Total"};
1199
1200 for (const std::string &column_name : column_names)
1201 report.declare_column(column_name);
1202
1203 add_statistics_to_table_handler("Contact list generation",
1205 report);
1206 add_statistics_to_table_handler("Velocity magnitude", velocity, report);
1207 add_statistics_to_table_handler("Angular velocity magnitude",
1208 omega,
1209 report);
1210 add_statistics_to_table_handler("Translational kinetic energy",
1212 report);
1213 add_statistics_to_table_handler("Rotational kinetic energy",
1215 report);
1216
1217 // Only for Min, Max, Average and Total columns
1218 for (unsigned int i = 1; i < column_names.size(); ++i)
1219 {
1220 report.set_scientific(column_names[i], true);
1221 report.set_precision(column_names[i],
1222 this->simulation_control->get_log_precision());
1223 }
1224
1225 announce_string(this->pcout, "Particle statistics");
1226 report.write_text(std::cout, dealii::TableHandler::org_mode_table);
1227 }
1228
1229 if (dem_parameters.post_processing.lagrangian_post_processing_enabled &&
1230 this->simulation_control->is_output_iteration())
1231 {
1232 const auto parallel_triangulation =
1233 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
1234 &*this->triangulation);
1235
1237 *parallel_triangulation,
1239 *this->dof_handler,
1240 this->particle_handler,
1242 this->simulation_control->get_current_time(),
1243 this->simulation_control->get_iteration_number(),
1244 this->mpi_communicator,
1246 }
1247}
1248
1249template <int dim, typename PropertiesIndex>
1250void
1252{
1253 this->FluidDynamicsMatrixFree<dim>::postprocess_fd(first_iteration);
1254
1255 // Visualization
1256 if (this->simulation_control->is_output_iteration())
1257 {
1259 }
1260 if (!first_iteration)
1261 {
1262 this->pcout
1263 << "---------------------------------------------------------------"
1264 << std::endl;
1265 }
1266}
1267
1268template <int dim, typename PropertiesIndex>
1269void
1271{
1272 // Calculate total volume of fluid and solid
1273 if (this->simulation_parameters.post_processing.calculate_phase_volumes)
1274 {
1275 TimerOutput::Scope t(this->computing_timer, "total_volume_calculation");
1276 double total_volume_fluid, total_volume_particles;
1277 std::tie(total_volume_fluid, total_volume_particles) =
1279 *this->particle_projector.dof_handler,
1280 *this->particle_projector.void_fraction_locally_relevant,
1281 *this->cell_quadrature,
1282 *this->mapping);
1283 this->table_phase_volumes.add_value(
1284 "time", this->simulation_control->get_current_time());
1285 this->table_phase_volumes.add_value("total-volume-fluid",
1286 total_volume_fluid);
1287 this->table_phase_volumes.add_value("total-volume-particles",
1288 total_volume_particles);
1289 if (this->simulation_parameters.post_processing.verbosity ==
1291 {
1292 this->pcout << "Total volume of fluid: "
1293 << this->simulation_parameters.physical_properties_manager
1294 .get_density_scale() *
1295 total_volume_fluid
1296 << " m^3" << std::endl;
1297 this->pcout << "Total volume of particles: "
1298 << this->simulation_parameters.physical_properties_manager
1299 .get_density_scale() *
1300 total_volume_particles
1301 << " m^3" << std::endl;
1302 }
1303
1304 // Output pressure drop to a text file from processor 0
1305 if ((this->simulation_control->get_iteration_number() %
1306 this->simulation_parameters.post_processing.output_frequency ==
1307 0) &&
1308 this->this_mpi_process == 0)
1309 {
1310 std::string filename =
1311 this->simulation_parameters.simulation_control.output_folder +
1312 this->simulation_parameters.post_processing
1313 .phase_volumes_output_name +
1314 ".dat";
1315 std::ofstream output(filename.c_str());
1316 table_phase_volumes.set_precision("time", 12);
1317 table_phase_volumes.set_precision("total-volume-fluid", 12);
1318 table_phase_volumes.set_precision("total-volume-particles", 12);
1319 this->table_phase_volumes.write_text(output);
1320 }
1321 }
1322}
1323
1324
1325template <int dim, typename PropertiesIndex>
1326void
1328{
1329 if (this->simulation_parameters.flow_control.enable_flow_control &&
1330 this->simulation_parameters.simulation_control.method !=
1332 {
1333 // Calculate the average velocity according to the void fraction
1334 unsigned int flow_direction =
1335 this->simulation_parameters.flow_control.flow_direction;
1336 double average_velocity = calculate_average_velocity(
1337 *this->dof_handler,
1338 *this->particle_projector.dof_handler,
1339 *this->present_solution,
1340 this->particle_projector.void_fraction_solution,
1341 flow_direction,
1342 *this->cell_quadrature,
1343 *this->mapping);
1344
1345 // Calculate the beta force for fluid
1346 this->flow_control.calculate_beta(
1347 average_velocity,
1348 this->simulation_control->get_time_step(),
1349 this->simulation_control->get_iteration_number());
1350
1351 Tensor<1, 3> beta_particle;
1352 if (this->simulation_parameters.flow_control.enable_beta_particle)
1353 {
1354 // Calculate the beta for particles and add it to force tensor g
1355 AssertThrow(
1356 dem_parameters.lagrangian_physical_properties
1357 .particle_type_number == 1,
1358 ExcMessage(std::string(
1359 "Beta force calculation for particles is not implemented for multiple particle types.")));
1360
1361 double fluid_density =
1362 this->simulation_parameters.physical_properties_manager
1363 .get_density_scale();
1364 double particle_density =
1365 dem_parameters.lagrangian_physical_properties.density_particle[0];
1366 beta_particle =
1367 this->flow_control.get_beta_particles(fluid_density,
1368 particle_density);
1369 g = dem_parameters.lagrangian_physical_properties.g + beta_particle;
1370 }
1371
1372 // Showing results
1373 if (this->simulation_parameters.flow_control.verbosity ==
1375 this->simulation_control->get_iteration_number() > 0 &&
1376 this->this_mpi_process == 0)
1377 {
1378 announce_string(this->pcout, "Flow control summary");
1379 this->pcout << "Fluid space-average velocity: " << average_velocity
1380 << std::endl;
1381 this->pcout << "Fluid beta force: "
1382 << this->flow_control.get_beta()[flow_direction]
1383 << std::endl;
1384 this->pcout << "Particle beta force: "
1385 << beta_particle[flow_direction] << std::endl;
1386 }
1387 }
1388}
1389
1390
1391template <int dim, typename PropertiesIndex>
1392inline void
1395{
1396 this->particle_handler.sort_particles_into_subdomains_and_cells();
1397
1398 // Exchange ghost particles
1399 this->particle_handler.exchange_ghost_particles(true);
1400
1401 // Resize the displacement, force and torque containers only if the particles
1402 // have changed subdomains
1403 if (dem_action_manager->check_resize_containers())
1404 {
1405 unsigned int number_of_particles =
1406 this->particle_handler.get_max_local_particle_index();
1407 // Resize displacement container
1408 displacement.resize(number_of_particles);
1409 // Resize outcome containers
1410 contact_outcome.resize_interaction_containers(number_of_particles);
1411 MOI.resize(number_of_particles);
1412
1413 // Updating moment of inertia container
1414 for (auto &particle : this->particle_handler)
1415 {
1416 auto particle_properties = particle.get_properties();
1417 MOI[particle.get_local_index()] =
1418 0.1 * particle_properties[PropertiesIndex::mass] *
1419 particle_properties[PropertiesIndex::dp] *
1420 particle_properties[PropertiesIndex::dp];
1421 }
1422 }
1423
1424 // Always reset the displacement values since we are doing a search detection
1425 std::ranges::fill(displacement, 0.);
1426}
1427
1428template <int dim, typename PropertiesIndex>
1429void
1431{
1432 const unsigned int counter = this->dem_simulation_control->get_iteration();
1433 const double dem_time_step = this->dem_simulation_control->get_time_step();
1434
1435 // dem_contact_build carries out the particle-particle and particle-wall
1436 // broad and fine searches, sort_particles_into_subdomains_and_cells, and
1437 // exchange_ghost
1439
1440 // Particle-particle contact force
1441 particle_particle_contact_force_object->calculate_particle_particle_contact(
1442 contact_manager.get_local_adjacent_particles(),
1443 contact_manager.get_ghost_adjacent_particles(),
1444 contact_manager.get_local_local_periodic_adjacent_particles(),
1445 contact_manager.get_local_ghost_periodic_adjacent_particles(),
1446 contact_manager.get_ghost_local_periodic_adjacent_particles(),
1447 dem_time_step,
1449
1450 // Particles-walls contact force:
1452
1453 // Integration of the temperature of the particles for the multiphysic DEM.
1454 // The heat source is zero since the fluid does not exchange heat with the
1455 // particles yet.
1457 {
1459 this->particle_handler,
1460 dem_time_step,
1461 contact_outcome.heat_transfer_rate,
1462 std::vector<double>(contact_outcome.force.size()));
1463
1464 // Update the temperature of the walls of the grid for the next DEM
1465 // iteration. The counter first iteration starts at 1 so the time is given
1466 // by the previous time (of the cfd) plus the counter times the DEM time
1467 // step.
1469 this->cfd_dem_simulation_parameters.dem_parameters.boundary_conditions,
1470 this->simulation_control->get_previous_time() +
1471 counter * dem_time_step);
1472 }
1473
1474 // Add fluid-particle interaction force to the force container
1476
1477 // The cell average velocities and accelerations are updated
1478 // from the fully computed forces at step 0, but we do not use the
1479 // mobility status to disabled contacts at this step. The reason
1480 // is that the current mobility status are computed for the last
1481 // DEM time step (from the last CFD time step) are the force of
1482 // the fluid may have significantly changed the particulate
1483 // agitation.
1484 // Update the cell average velocities and accelerations
1485 sparse_contacts_object.update_average_velocities_acceleration(
1486 this->particle_handler, g, contact_outcome.force, dem_time_step);
1487
1488 // Integration correction step (after force calculation).
1489 // Since the velocities are synchronized with the positions at the end of
1490 // every CFD time step (see synchronize_particle_velocities), the first DEM
1491 // sub-iteration of every CFD time step is an opening step, which lets the
1492 // scheme restart its staggering if it has one.
1493 if (this->dem_simulation_control->is_first_iteration())
1494 {
1495 integrator_object->integrate_start(this->particle_handler,
1496 g,
1497 dem_time_step,
1498 contact_outcome.torque,
1499 contact_outcome.force,
1500 MOI);
1501 }
1502 else
1503 {
1504 const auto parallel_triangulation =
1505 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
1506 &*this->triangulation);
1507 integrator_object->integrate(this->particle_handler,
1508 g,
1509 dem_time_step,
1510 contact_outcome.torque,
1511 contact_outcome.force,
1512 MOI,
1513 *parallel_triangulation,
1515 }
1516
1517 auto dem_current_time =
1518 (this->simulation_control->get_current_time()) + (dem_time_step * counter);
1519
1520 // Log the contact statistics if the parameter is enabled
1521 if (dem_parameters.post_processing.particle_wall_collision_statistics)
1522 {
1525 contact_manager.get_particle_wall_in_contact(),
1526 dem_current_time,
1529 }
1530
1531 dem_action_manager->reset_triggers();
1532}
1533
1534template <int dim, typename PropertiesIndex>
1535void
1537{
1538 const double dem_time_step = this->dem_simulation_control->get_time_step();
1539
1540 // The particles have reached their final position for this CFD time step, but
1541 // their velocities are still lagging by half a DEM time step. The forces are
1542 // re-evaluated at this final position so that the closing half velocity step
1543 // can be applied. No contact search is carried out: the contact lists built
1544 // at the last DEM sub-iteration are exactly as valid here as they are for any
1545 // sub-iteration that does not trigger a search, and only the ghost particles
1546 // need to be updated.
1547 this->particle_handler.update_ghost_particles();
1548
1549 // Particle-particle contact force
1550 particle_particle_contact_force_object->calculate_particle_particle_contact(
1551 contact_manager.get_local_adjacent_particles(),
1552 contact_manager.get_ghost_adjacent_particles(),
1553 contact_manager.get_local_local_periodic_adjacent_particles(),
1554 contact_manager.get_local_ghost_periodic_adjacent_particles(),
1555 contact_manager.get_ghost_local_periodic_adjacent_particles(),
1556 dem_time_step,
1558
1559 // Particles-walls contact force
1561
1562 // The heat transfer rate accumulated by the contact force objects is
1563 // discarded. The temperature is not integrated by the closing half step,
1564 // since it is not staggered and has already been advanced to the final time
1565 // by the last DEM sub-iteration. Leaving the container filled would leak
1566 // this heat transfer rate into the temperature integration of the next CFD
1567 // time step, which would then be counted twice.
1569 std::ranges::fill(contact_outcome.heat_transfer_rate, 0.);
1570
1571 // Add fluid-particle interaction force to the force container
1573
1574 const auto parallel_triangulation =
1575 dynamic_cast<parallel::distributed::Triangulation<dim> *>(
1576 &*this->triangulation);
1577 integrator_object->integrate_end(this->particle_handler,
1578 g,
1579 dem_time_step,
1580 contact_outcome.torque,
1581 contact_outcome.force,
1582 MOI,
1583 *parallel_triangulation,
1585
1586 dem_action_manager->reset_triggers();
1587}
1588
1589template <int dim, typename PropertiesIndex>
1590void
1592{
1593 const unsigned int counter = this->dem_simulation_control->get_iteration();
1594 // If this is not the last DEM iteration before the next CFD iteration, check
1595 // if a contact detection step is necessary
1596 if (!this->dem_simulation_control->is_last_iteration())
1598
1599 // Otherwise, force a contact search at the last DEM iteration before a CFD
1600 // iteration to ensure that the particles are adequately located before
1601 // calculating the coupling between particle and fluid.
1602 else
1603 dem_action_manager->last_dem_of_cfddem_iteration_step();
1604
1605 // Sort particles in cells
1606 if (dem_action_manager->check_contact_search())
1607 {
1608 this->pcout << "DEM contact search at dem step " << counter << std::endl;
1610
1611 // Execute periodic boundaries (if PBC enabled)
1612 periodic_boundaries_object.execute_particles_displacement(
1614
1615 // Sort particles into subdomains and cells and reset the vectors that
1616 // the local particle if is their index
1618
1619 // Identify the mobility status of particles (if ASC enabled)
1620 sparse_contacts_object.identify_mobility_status(
1621 *this->particle_projector.dof_handler,
1622 this->particle_handler,
1623 (*this->triangulation).n_active_cells(),
1624 this->mpi_communicator);
1625
1626 // Execute broad search by filling containers of particle-particle
1627 // contact pair candidates and containers of particle-wall
1628 // contact pair candidates
1629 contact_manager.execute_particle_particle_broad_search(
1631
1632 contact_manager.execute_particle_wall_broad_search(
1633 this->particle_handler,
1636 dem_parameters.floating_walls,
1637 this->simulation_control->get_current_time(),
1639
1640 // Update contacts, remove replicates and add new contact pairs
1641 // to the contact containers when particles are exchanged between
1642 // processors
1643 contact_manager.update_contacts();
1644
1645 // Updates the iterators to particles in local-local contact
1646 // containers
1647 contact_manager.update_local_particles_in_cells(this->particle_handler);
1648
1649 // Execute fine search by updating particle-particle contact
1650 // containers regards the neighborhood threshold
1651 contact_manager.execute_particle_particle_fine_search(
1653
1654 // Execute fine search by updating particle-wall contact containers
1655 // regards the neighborhood threshold
1656 contact_manager.execute_particle_wall_fine_search(
1657 dem_parameters.floating_walls,
1658 this->simulation_control->get_current_time(),
1660 }
1661 else
1662 {
1663 this->particle_handler.update_ghost_particles();
1664 }
1665}
1666
1667template <int dim, typename PropertiesIndex>
1668void
1670{
1671 this->computing_timer.enter_subsection("Read mesh, manifolds and particles");
1672
1674 *this->triangulation,
1675 this->cfd_dem_simulation_parameters.cfd_parameters.mesh,
1676 this->cfd_dem_simulation_parameters.cfd_parameters.manifolds_parameters,
1677 this->cfd_dem_simulation_parameters.cfd_parameters.restart_parameters
1678 .restart ||
1679 this->cfd_dem_simulation_parameters.void_fraction->read_dem,
1680 this->cfd_dem_simulation_parameters.cfd_parameters.boundary_conditions
1681 .periodic_boundaries);
1682
1684
1685 // Reading DEM start file information
1686 if (this->cfd_dem_simulation_parameters.void_fraction->read_dem == true &&
1687 !this->cfd_dem_simulation_parameters.cfd_parameters.restart_parameters
1688 .restart)
1689 read_dem();
1690
1691 this->computing_timer.leave_subsection("Read mesh, manifolds and particles");
1692
1693 this->setup_dofs();
1694
1696 this->cfd_dem_simulation_parameters.cfd_parameters.initial_condition->type,
1697 this->cfd_dem_simulation_parameters.cfd_parameters.restart_parameters
1698 .restart);
1699
1702 this->pcout,
1703 this->mpi_communicator);
1704
1705 if (this->cfd_dem_simulation_parameters.void_fraction->output_qcm)
1706 {
1707 this->particle_projector.write_qcm_quadrature_points(
1708 this->cfd_dem_simulation_parameters.cfd_parameters.simulation_control
1709 .output_folder,
1710 "qcm_quadrature_points",
1711 this->cfd_dem_simulation_parameters.cfd_parameters.simulation_control
1712 .group_files);
1713 }
1714
1715 // Only needed if other physics apart from fluid dynamics are enabled.
1716 if (this->multiphysics->get_active_physics().size() > 1)
1718
1719 if (this->cfd_dem_simulation_parameters.cfd_parameters.restart_parameters
1720 .restart)
1721 dem_action_manager->restart_simulation();
1722
1723 // Initialize the DEM parameters and generate the ghost particles
1725
1726 // Calculate first instance of void fraction and of the projected particle
1727 // temperature once particles are set up
1728 if (!dem_action_manager->check_restart_simulation())
1729 {
1730 this->particle_projector.initialize_void_fraction(
1731 this->simulation_control->get_current_time());
1732 this->particle_projector.calculate_particle_temperature_projection();
1733 }
1734
1735 // Output the solution after initializing the void fraction
1736 if (!this->cfd_dem_simulation_parameters.cfd_parameters.restart_parameters
1737 .restart)
1738 {
1739 this->postprocess_fd(true);
1740 this->multiphysics->postprocess(true);
1741 if (this->simulation_control->is_output_iteration())
1743 }
1744
1745 while (this->simulation_control->integrate())
1746 {
1747 this->simulation_control->print_progression(this->pcout);
1748
1749 // We allow the physics to update their boundary conditions
1750 // according to their own parameters
1752 this->multiphysics->update_boundary_conditions();
1753
1754 // Insert particle if needed
1756
1757 this->dynamic_flow_control();
1758
1759 if (!this->simulation_control->is_at_start())
1760 {
1761 this->refine_mesh();
1762 }
1763
1764 // We calculate the void fraction and the particle-fluid interaction using
1765 // the particle projector.
1766 this->particle_projector.calculate_void_fraction(
1767 this->simulation_control->get_current_time());
1768
1769 // Project the particle temperature onto the fluid mesh (thermal CFD-DEM
1770 // simulations only), so that the other physics see the particle
1771 // temperature of the current time step
1772 this->particle_projector.calculate_particle_temperature_projection();
1773
1774 if (time_stepping_is_bdf(this->simulation_control->get_assembly_method()))
1775 {
1776 this->computing_timer.enter_subsection("Calculate time derivatives");
1777
1779 this->time_derivative_previous_solutions.update_ghost_values();
1780 this->system_operator->evaluate_time_derivative_previous_solutions(
1783 this->computing_timer.leave_subsection("Calculate time derivatives");
1784
1785 this->computing_timer.enter_subsection("Calculate flow controller");
1786 if (this->simulation_parameters.flow_control.enable_flow_control)
1787 this->system_operator->update_beta_force(
1788 this->flow_control.get_beta());
1789 this->computing_timer.leave_subsection("Calculate flow controller");
1790 }
1791
1792
1793 this->computing_timer.enter_subsection(
1794 "Calculate particle-fluid forces projection");
1795 this->particle_projector.calculate_particle_fluid_forces_projection(
1796 this->cfd_dem_simulation_parameters.cfd_dem,
1797 *this->dof_handler,
1798 *this->present_solution,
1799 *this->previous_solutions,
1800 this->cfd_dem_simulation_parameters.dem_parameters
1801 .lagrangian_physical_properties.g,
1803 this->simulation_control,
1804 this->simulation_parameters.physical_properties_manager,
1805 *this->fe,
1806 *this->cell_quadrature,
1807 *this->mapping,
1808 *this->face_quadrature));
1809 this->computing_timer.leave_subsection(
1810 "Calculate particle-fluid forces projection");
1811
1812
1813 // The base matrix-free operator is not aware of the various VANS
1814 // coupling terms. We must do a cast here to ensure that the operator is
1815 // of the right type.
1816 if (auto mf_operator = dynamic_cast<VANSOperator<dim, double> *>(
1817 this->system_operator.get()))
1818 {
1819 this->computing_timer.enter_subsection(
1820 "Prepare MF operator for VANS");
1821
1822 mf_operator->compute_void_fraction(
1823 *this->particle_projector.dof_handler,
1824 this->particle_projector.void_fraction_solution,
1825 this->time_derivative_void_fraction);
1826
1827 mf_operator->compute_particle_fluid_interaction(
1828 *this->particle_projector.fluid_force_on_particles_two_way_coupling
1829 .dof_handler,
1830 this->particle_projector.fluid_force_on_particles_two_way_coupling
1831 .particle_field_solution,
1832 *this->particle_projector.fluid_drag_on_particles.dof_handler,
1833 this->particle_projector.fluid_drag_on_particles
1834 .particle_field_solution,
1835 *this->particle_projector.particle_velocity.dof_handler,
1836 this->particle_projector.particle_velocity.particle_field_solution,
1837 *this->particle_projector.momentum_transfer_coefficient.dof_handler,
1838 this->particle_projector.momentum_transfer_coefficient
1839 .particle_field_solution);
1840
1841 this->computing_timer.leave_subsection(
1842 "Prepare MF operator for VANS");
1843 }
1844
1845 this->iterate();
1846
1847 // DEM iterations
1848 {
1849 announce_string(this->pcout, "DEM");
1850 TimerOutput::Scope t(this->computing_timer, "DEM_Iterator");
1851
1852 // Make alias reference to improve readability
1853 const auto &cfd_dem_prm = this->cfd_dem_simulation_parameters.cfd_dem;
1854
1855 // Create a simulation control object for the dem iterations
1856 dem_simulation_control = std::make_shared<SubSimulationControlDEM>(
1857 cfd_dem_prm.dem_iteration_control,
1858 this->simulation_control->get_time_step(),
1859 cfd_dem_prm.coupling_frequency,
1861 cfd_dem_prm.fraction_of_rayleigh_time);
1862
1863 // First DEM iteration of the CFD iteration
1864 dem_action_manager->first_dem_of_cfddem_iteration_step();
1865
1866 // Load balancing if needed
1867 load_balance();
1868
1869 // Update DEM time step when the simulation uses adaptive time-stepping
1870 if (this->simulation_control->is_adaptive_time_stepping())
1872
1874 while (dem_simulation_control->iterate())
1875 {
1876 // dem_iterator carries out the particle-particle and
1877 // particle_wall force calculations, integration and
1878 // update_ghost
1879 dem_iterator();
1880 }
1881
1882 // Closing step of the integration scheme. It brings the velocities of
1883 // the particles to the end of the CFD time step, at which their
1884 // positions already are.
1886
1887 this->pcout << "Finished " << dem_simulation_control->get_iteration()
1888 << " DEM iterations" << std::endl;
1889 }
1890
1892
1893 this->postprocess(false);
1894 this->postprocess_cfd_dem();
1895 this->finish_time_step_fd();
1896
1897 if (this->cfd_dem_simulation_parameters.cfd_dem.particle_statistics)
1899 }
1900
1901 // Write particle-wall collision statistics file if enabled
1902 // if (dem_parameters.post_processing.particle_wall_collision_statistics)
1903 // write_collision_stats(dem_parameters,
1904 // collision_event_log,
1905 // this->mpi_communicator);
1907 this->print_mg_setup_times();
1908
1909 this->finish_simulation();
1910}
1911
1912// Pre-compile the 2D and 3D CFD-DEM matrix-free solver
Solver class for coupled Computational Fluid Dynamics and Discrete Element Method (CFD-DEM) simulatio...
void particle_wall_contact_force()
Calculate contact forces between particles and walls.
double smallest_contact_search_criterion
Smallest criterion used for contact search algorithms.
void write_checkpoint() override
Write CFD-DEM simulation checkpoint files.
unsigned int contact_search_counter
Counter for contact searches performed in the current CFD iteration.
void postprocess_fd(bool first_iteration) override
Perform fluid dynamics post-processing after each iteration.
PVDHandler particles_pvdhandler
PVD handler for particle visualization output.
DEM::dem_data_structures< dim >::periodic_boundaries_cells_info periodic_boundaries_cells_information
Information about cells involved in periodic boundary conditions.
ParticleInteractionOutcomes< PropertiesIndex > contact_outcome
Container for particle interaction outcomes (forces and torques).
void read_dem() override
Read DEM restart files from a previous simulation.
std::shared_ptr< ParticleParticleContactForceBase< dim, PropertiesIndex > > particle_particle_contact_force_object
Contact force model for particle-particle interactions.
void add_fluid_particle_interaction()
Calculate and add fluid-particle interaction forces and torques.
void set_initial_condition(const Parameters::FluidDynamicsInitialConditionType initial_condition_type, const bool restart=false) override
Set the initial condition. The version in this class does not output the solution,...
double rayleigh_time_step
Rayleigh time step.
std::vector< double > MOI
Moment of inertia values for all particles.
void postprocess_cfd_dem()
Perform CFD-DEM coupled post-processing after each iteration.
void load_balance()
Check if load balancing is required and perform it if necessary.
std::shared_ptr< SubSimulationControlDEM > dem_simulation_control
DEMSolverParameters< dim > dem_parameters
DEM simulation parameters container.
dem_data_structures< dim >::solid_surfaces_mesh_information solid_surfaces_mesh_info
Mesh information for solid surfaces in contact with particles.
void report_rayleigh_time_ratio()
Reports the ratio between the DEM time step and the Rayleigh time.
double maximum_particle_diameter
Maximum diameter among all particles in the simulation.
std::vector< double > displacement
Displacement vector for particle motion calculations.
AdaptiveSparseContacts< dim, PropertiesIndex > sparse_contacts_object
Object for handling adaptive sparse contact detection algorithms.
void read_checkpoint() override
Read CFD-DEM simulation checkpoint files.
void dynamic_flow_control() override
Calculate dynamic flow control accounting for void fraction.
std::vector< std::shared_ptr< Distribution > > size_distribution_object_container
Container for particle size distribution objects.
std::shared_ptr< Insertion< dim, PropertiesIndex > > insertion_object
Particle insertion method handler.
double neighborhood_threshold_squared
Squared threshold distance for neighborhood particle detection.
statistics contact_list
Statistics container for timing and contact list information.
void solve() override
Engine of the CFD-DEM solver. Calls all the necessary functions to set parameters,...
unsigned int contact_search_total_number
Total number of contact searches since simulation start.
void setup_distribution_type()
Initialize the particle size distribution and related parameters.
void report_particle_statistics()
Calculate and report particle statistics to the terminal.
PeriodicBoundariesManipulator< dim > periodic_boundaries_object
Handler for periodic boundary condition manipulations.
void insert_particles()
Check if particles need to be inserted and perform insertion.
void synchronize_particle_velocities()
Carry out the closing half velocity step of a staggered integration scheme at the end of the DEM sub-...
std::shared_ptr< Integrator< dim, PropertiesIndex > > integrator_object
Time integration scheme for particle motion equations.
void dem_setup_parameters()
Set up the various parameters related to the DEM simulation.
void check_contact_detection_method(unsigned int counter)
Check if contact detection is required and execute it if necessary.
void sort_particles_into_subdomains_and_cells()
Sort particles into subdomains and cells for efficient processing.
DEMContactManager< dim, PropertiesIndex > contact_manager
LagrangianLoadBalancing< dim, PropertiesIndex > load_balancing
Load balancing handler for distributing particles across MPI processes.
CFDDEMMatrixFree(CFDDEMSimulationParameters< dim > &param)
Constructor for the CFD-DEM matrix-free solver.
DEMActionManager * dem_action_manager
Pointer to DEM action manager for handling DEM-specific operations.
OngoingCollisionLog< dim > ongoing_collision_log
Object to store ongoing collision information.
CompletedCollisionLog< dim > collision_event_log
Object to store completed collision events.
ParticlePointLineForce< dim, PropertiesIndex > particle_point_line_contact_force_object
Handler for point and line contact forces between particles.
std::vector< OutputStructTableHandler > gather_tables() override
Gather TableHandler objects for serialization during checkpointing.
void dem_iterator()
Execute a DEM time step.
std::shared_ptr< ParticleWallContactForceBase< dim, PropertiesIndex > > particle_wall_contact_force_object
Contact force model for particle-wall interactions.
void initialize_dem_parameters()
Initialize fundamental DEM simulation parameters.
BoundaryCellsInformation< dim > boundary_cell_object
Information about boundary cells for contact detection.
Tensor< 1, 3 > g
Gravitational acceleration vector.
std::shared_ptr< Integrator< dim, PropertiesIndex > > set_integrator_type()
Set up the time integration method for particle motion.
PVDHandler grid_pvdhandler
PVD handler for grid visualization output.
DEM::ParticleProperties< dim, PropertiesIndex > properties_class
Particle properties handler for DEM simulation.
void dem_contact_build()
Perform contact detection and build contact lists.
void write_dem_output_results()
Write DEM simulation results to output files.
static DEMActionManager * get_action_manager()
Getter of the unique instance of the DEMActionManager.
Implementation of a classical explicit euler scheme for the integration of the particle motion....
void print_mg_setup_times()
Prints the setup times for the geometric multigrid preconditioner.
VectorType time_derivative_previous_solutions
Vector to store the time derivatives of the previous solutions at the end of each time step for time-...
virtual void update_multiphysics_time_average_solution() override
Update the average velocity field solution in the multiphyscics interface.
std::shared_ptr< NavierStokesOperatorBase< dim, double > > system_operator
Matrix-free operator in used for all the matrix-vector multiplications calls (vmult).
void calculate_time_derivative_previous_solutions()
Calculate and store time derivatives of previous solutions according to time-stepping scheme to use t...
LinearAlgebra::distributed::Vector< double > VectorType
void evaluate_time_derivative_void_fraction()
Evaluate the time derivative of the void fraction. This evaluates the time-derivative as a solution v...
virtual void finish_time_step_fd()
Finish the time step and manage the end of the time step for the void fraction.
ParticleProjector< dim, PropertiesIndex > particle_projector
CFDDEMSimulationParameters< dim > cfd_dem_simulation_parameters
Simulation parameters for CFD-DEM simulations.
void setup_dofs() override
Setup the degree of freedom of the flow solver and the degrees of freedom and constraints for the voi...
FluidDynamicsVANSMatrixFree(CFDDEMSimulationParameters< dim > &param)
Constructor that sets the finite element degree and system operator according to simulation parameter...
Particles::ParticleHandler< dim, dim > particle_handler
Particle-handler used to store particles in CFD-DEM simulations.
MappingQGeneric< dim > particle_mapping
Mapping used for the particles.
void write_output_results(const LinearAlgebra::distributed::Vector< double > &solution)
virtual std::vector< OutputStructTableHandler > gather_tables()
Returns a vector of references to TableHandler objects that needs to be serialized/ deserialized for ...
std::shared_ptr< LinearAlgebra::distributed::Vector< double > > present_solution
std::shared_ptr< std::vector< LinearAlgebra::distributed::Vector< double > > > previous_solutions
std::shared_ptr< AverageVelocities< dim, LinearAlgebra::distributed::Vector< double >, IndexSet > > average_velocities
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
Numerical model parameters for DEM simulations.
enum Parameters::Lagrangian::ModelParameters::ContactDetectionMethod contact_detection_method
IntegrationMethod
Time integration method for particle motion.
unsigned int contact_detection_frequency
Frequency of particle-particle and particle-wall contact detection.
Postprocessing - Defines the parameters for the post-processing. In Lethe, post-processing implies th...
std::string phase_volumes_output_name
prefix for the total volume output in cfd-dem simulation
Implements the matrix-free operator for the VANS equations.
Implementation of a classical velocity verlet scheme for the integration of the particle motion....
Building patches of particle properties for visualization. This function is taken from Aspect and dea...
void build_patches(Particles::ParticleHandler< dim > &particle_handler, const std::vector< std::pair< std::string, int > > &properties)
Build the patches of properties of particles for visualization.
A simple container for storing basic statistical values.
Definition utilities.h:56
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
void serialize_tables_vector(const std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Serializes all the TableHandler objects in table_output_structs.
Definition utilities.h:602
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
void add_statistics_to_table_handler(const std::string &variable, const statistics &stats, TableHandler &table)
Add statistical values to a TableHandler.
Definition utilities.h:97
void deserialize_tables_vector(std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Deserializes all the TableHandler objects in table_output_structs.
Definition utilities.h:624
void report_cell_size_to_particle_diameter_ratio(const parallel::DistributedTriangulationBase< dim > &triangulation, const double maximum_particle_diameter, const ConditionalOStream &pcout, const MPI_Comm &mpi_communicator)
Reports the ratio between the minimum cell size and the maximum particle diameter.
Definition utilities.h:35
void setup_distributions(const LagrangianPhysicalProperties &lpp, std::vector< std::shared_ptr< Distribution > > &size_distribution_object_container, double &maximum_particle_diameter, const unsigned int mpi_process_id, const ConditionalOStream &pcout)
void find_particle_contact_detection_step(Particles::ParticleHandler< dim > &particle_handler, const double dt, const double smallest_contact_search_criterion, MPI_Comm &mpi_communicator, std::vector< double > &displacement, const bool parallel_update=true)
Find steps for dynamic contact search for particle-particle contacts.
void read_mesh_and_manifolds(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries)
Completely sets up a mesh and its manifolds.
Definition grids.cc:447
void write_post_processing_results(const parallel::distributed::Triangulation< dim > &triangulation, PVDHandler &grid_pvdhandler, const DoFHandler< dim > &background_dh, const Particles::ParticleHandler< dim > &particle_handler, const DEMSolverParameters< dim > &dem_parameters, const double current_time, const unsigned int step_number, const MPI_Comm &mpi_communicator, AdaptiveSparseContacts< dim, PropertiesIndex > &sparse_contacts_object)
Carries out writing the cell data of the domain.
void log_collision_data(const DEMSolverParameters< dim > &parameters, typename DEM::dem_data_structures< dim >::particle_wall_in_contact &particle_wall_pairs_in_contact, const double current_time, OngoingCollisionLog< dim > &ongoing_collision_log, CompletedCollisionLog< dim > &collision_event_log)
Logs the particle-wall contact statistics.
void integrate_temperature(Particles::ParticleHandler< dim > &particle_handler, const double dt, std::vector< double > &heat_transfer_rate, const std::vector< double > &heat_source)
Implementation of an explicit euler time-stepping scheme for the integration of the particles' temper...
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.
std::conditional_t< has_thermal_properties< PropertiesIndex >, DEMMPProperties::PropertiesIndex, DEMProperties::PropertiesIndex > matching_dem_properties_index
The pure DEM index set matching a given index set.
statistics calculate_granular_statistics(const Particles::ParticleHandler< dim > &particle_handler, const MPI_Comm &mpi_communicator)
Calculate statistics on a DEM ParticleHandler. At the moment, the following statistics are supported:
void convert_particle_handler(const parallel::distributed::Triangulation< dim > &triangulation, const Particles::ParticleHandler< dim > &ph_in, Particles::ParticleHandler< dim > &ph_out)
Converts an input particle handler with a given set of input properties into an output particle handl...
void set_wall_temperature_time(const Parameters::Lagrangian::BCDEM &boundary_conditions, const double time)
Set the time of the temperature functions of the walls of the grid with a temperature boundary condit...
double calculate_average_velocity(const DoFHandler< dim > &dof_handler, const VectorType &present_solution, const unsigned int &boundary_id, const Quadrature< dim - 1 > &face_quadrature_formula, const Mapping< dim > &mapping)
calculate_average_velocity. This function calculates average velocity from the volumetric flow rate a...
std::pair< double, double > calculate_fluid_and_particle_volumes(const DoFHandler< dim > &void_fraction_dof_handler, const VectorType &present_void_fraction_solution, const Quadrature< dim > &quadrature_formula, const Mapping< dim > &mapping)
This function calculates total volume of fluid and total volume of particles in cfd-dem simulation.
std::shared_ptr< Insertion< dim, PropertiesIndex > > set_insertion_type(std::vector< std::shared_ptr< Distribution > > &size_distribution_object_container, parallel::distributed::Triangulation< dim > &triangulation, DEMSolverParameters< dim > &dem_parameters, const double &maximum_particle_diameter)
Set up the particle insertion method for the simulation. Creates and configures the appropriate inser...
std::shared_ptr< ParticleParticleContactForceBase< dim, PropertiesIndex > > set_particle_particle_contact_force_model(const DEMSolverParameters< dim > &dem_parameters)
Return the particle-particle contact force model based on the spring-dashpot model and the rolling re...
std::shared_ptr< ParticleWallContactForceBase< dim, PropertiesIndex > > set_particle_wall_contact_force_model(const DEMSolverParameters< dim > &dem_parameters)
Return the particle-wall contact force model based on the spring-dashpot model and the rolling resist...
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...
Controls smaller simulation blocks within simulations.
GlobalVectorType VectorType
bool time_stepping_is_bdf(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the bdf family.
void convert_vector_dealii_to_trilinos(dealii::TrilinosWrappers::MPI::Vector &out, const dealii::LinearAlgebra::distributed::Vector< number > &in)
Helper function that allows to convert deal.II vectors to Trilinos vectors.
Definition vector.h:39