6#include <deal.II/dofs/dof_renumbering.h>
8#include <deal.II/fe/fe_simplex_p.h>
10#include <deal.II/lac/solver_control.h>
11#include <deal.II/lac/sparsity_tools.h>
12#include <deal.II/lac/trilinos_solver.h>
14#include <deal.II/meshworker/mesh_loop.h>
16#include <deal.II/numerics/error_estimator.h>
17#include <deal.II/numerics/vector_tools.h>
27 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
29 std::shared_ptr<SimulationControl> p_simulation_control)
36 TimerOutput::wall_times)
42 .reinitialization_method.sharpening.threshold)
44 p_simulation_parameters.post_processing.isocontour_bounding_boxes
54 .get_number_of_fluids()));
58 .reinitialization_method.reinitialization_method_type ==
61 UnsupportedReinitialization());
65 .reinitialization_method.reinitialization_method_type !=
68 UnsupportedReinitializationWithSimplex());
71 this->simulation_parameters.post_processing.calculate_mass_conservation)
74 <<
"Warning: DG-CLS and the geometric surface and volume computations are not compatible. Only the global volume will be monitored."
81 fe = std::make_shared<FE_SimplexP<dim>>(
83 mapping = std::make_shared<MappingFE<dim>>(*fe);
86 std::make_shared<QGaussSimplex<dim - 1>>(
fe->degree + 1);
93 fe = std::make_shared<FE_DGQ<dim>>(
98 fe = std::make_shared<FE_Q<dim>>(
102 mapping = std::make_shared<MappingQ<dim>>(std::max(
fe->degree, uint(1)));
112 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
123 SolutionTransfer<dim, GlobalVectorType>(*this->dof_handler));
131 .sharpening.interface_sharpness < 1.0)
133 <<
"Warning: interface sharpness values smaller than 1 smooth the interface instead of sharpening it."
135 <<
"The interface sharpness value should be set between 1 and 2"
148 .geometric_interface_reinitialization.enable ||
150 ->cls_initial_condition_smoothing ==
164 .reinitialization_method.geometric_interface_reinitialization
165 .max_reinitialization_distance,
169 .reinitialization_method.verbosity);
173 .reinitialization_method.geometric_interface_reinitialization);
193 "The SDIRK scheme is not yet supported for this physics"));
217 this->simulation_parameters.multiphysics.cls_parameters));
248 const DoFHandler<dim> &dof_handler_fd =
255 *this->cell_quadrature,
256 *this->face_quadrature,
258 dof_handler_fd.get_fe());
261 this->dof_handler->end(),
267 this->cell_quadrature->size()));
277 const DoFHandler<dim> &dof_handler_fluid =
284 *this->cell_quadrature,
285 *this->face_quadrature,
287 dof_handler_fluid.get_fe());
290 this->cell_quadrature->size());
295 const auto cell_worker =
296 [&](
const typename DoFHandler<dim>::active_cell_iterator &cell,
302 const auto boundary_worker =
303 [&]([[maybe_unused]]
const typename DoFHandler<dim>::active_cell_iterator
305 [[maybe_unused]]
const unsigned int &face_no,
309 const auto face_worker =
310 [&](
const typename DoFHandler<dim>::active_cell_iterator &cell,
311 const unsigned int &face_no,
312 const unsigned int &sub_face_no,
313 const typename DoFHandler<dim>::active_cell_iterator &neigh_cell,
314 const unsigned int &neigh_face_no,
315 const unsigned int &neigh_sub_face_no,
318 scratch_data.reinit_internal_face(cell,
329 auto ©_data_face = copy_data.
face_data.back();
330 copy_data_face.face_matrix.reinit(scratch_data.n_interface_dofs,
331 scratch_data.n_interface_dofs);
332 copy_data_face.joint_dof_indices =
333 scratch_data.fe_interface_values_cls.get_interface_dof_indices();
337 typename DoFHandler<dim>::active_cell_iterator velocity_cell(
338 &(*
triangulation), cell->level(), cell->index(), &dof_handler_fluid);
353 for (
const auto &cdf : copy_data.
face_data)
355 constraints_used.distribute_local_to_global(cdf.face_matrix,
356 cdf.joint_dof_indices,
361 MeshWorker::mesh_loop(this->
dof_handler->begin_active(),
362 this->dof_handler->end(),
367 MeshWorker::assemble_own_cells |
368 MeshWorker::assemble_boundary_faces |
369 MeshWorker::assemble_own_interior_faces_once |
370 MeshWorker::assemble_ghost_faces_both,
379 const typename DoFHandler<dim>::active_cell_iterator &cell,
384 if (!cell->is_locally_owned())
389 const DoFHandler<dim> &dof_handler_fd =
392 typename DoFHandler<dim>::active_cell_iterator velocity_cell(
393 &(*this->
triangulation), cell->level(), cell->index(), &dof_handler_fd);
401 average_velocity_profile &&
402 !this->simulation_parameters.multiphysics.fluid_dynamics &&
404 this->simulation_parameters.post_processing
405 .initial_time_for_average_velocities)
413 this->simulation_parameters.ale);
422 this->simulation_parameters.ale);
431 average_velocity_profile &&
432 !this->simulation_parameters.multiphysics.fluid_dynamics &&
434 this->simulation_parameters.post_processing
435 .initial_time_for_average_velocities)
441 this->simulation_parameters.ale);
449 this->simulation_parameters.ale);
457 assembler->assemble_matrix(scratch_data, copy_data);
472 constraints_used.distribute_local_to_global(copy_data.
local_matrix,
474 this->system_matrix);
498 const DoFHandler<dim> &dof_handler_fd =
505 *this->cell_quadrature,
506 *this->face_quadrature,
508 dof_handler_fd.get_fe());
511 this->dof_handler->end(),
517 this->cell_quadrature->size()));
519 this->
system_rhs.compress(VectorOperation::add);
526 const DoFHandler<dim> &dof_handler_fluid =
533 *this->cell_quadrature,
534 *this->face_quadrature,
536 dof_handler_fluid.get_fe());
539 this->cell_quadrature->size());
541 const auto cell_worker =
542 [&](
const typename DoFHandler<dim>::active_cell_iterator &cell,
548 const auto boundary_worker =
549 [&]([[maybe_unused]]
const typename DoFHandler<dim>::active_cell_iterator
551 [[maybe_unused]]
const unsigned int &face_no,
555 const auto face_worker =
556 [&](
const typename DoFHandler<dim>::active_cell_iterator &cell,
557 const unsigned int &face_no,
558 const unsigned int &sub_face_no,
559 const typename DoFHandler<dim>::active_cell_iterator &neigh_cell,
560 const unsigned int &neigh_face_no,
561 const unsigned int &neigh_sub_face_no,
566 scratch_data.reinit_internal_face(cell,
575 auto ©_data_face = copy_data.
face_data.back();
576 copy_data_face.joint_dof_indices =
577 scratch_data.fe_interface_values_cls.get_interface_dof_indices();
578 copy_data_face.face_rhs.reinit(scratch_data.n_interface_dofs);
582 const DoFHandler<dim> &dof_handler_fluid =
585 typename DoFHandler<dim>::active_cell_iterator velocity_cell(
586 &(*
triangulation), cell->level(), cell->index(), &dof_handler_fluid);
599 for (
const auto &cdf : c.face_data)
601 constraints_used.distribute_local_to_global(cdf.face_rhs,
602 cdf.joint_dof_indices,
607 MeshWorker::mesh_loop(this->
dof_handler->begin_active(),
608 this->dof_handler->end(),
613 MeshWorker::assemble_own_cells |
614 MeshWorker::assemble_boundary_faces |
615 MeshWorker::assemble_own_interior_faces_once |
616 MeshWorker::assemble_ghost_faces_both,
624 const typename DoFHandler<dim>::active_cell_iterator &cell,
629 if (!cell->is_locally_owned())
634 const DoFHandler<dim> &dof_handler_fd =
637 typename DoFHandler<dim>::active_cell_iterator velocity_cell(
638 &(*this->
triangulation), cell->level(), cell->index(), &dof_handler_fd);
646 average_velocity_profile &&
647 !this->simulation_parameters.multiphysics.fluid_dynamics &&
649 this->simulation_parameters.post_processing
650 .initial_time_for_average_velocities)
658 this->simulation_parameters.ale);
667 this->simulation_parameters.ale);
676 average_velocity_profile &&
677 !this->simulation_parameters.multiphysics.fluid_dynamics &&
679 this->simulation_parameters.post_processing
680 .initial_time_for_average_velocities)
686 this->simulation_parameters.ale);
694 this->simulation_parameters.ale);
702 assembler->assemble_rhs(scratch_data, copy_data);
717 constraints_used.distribute_local_to_global(copy_data.
local_rhs,
723std::vector<OutputStruct<dim, GlobalVectorType>>
726 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
727 std::vector<std::string> solution_names(1,
"phase");
728 std::vector<DataComponentInterpretation::DataComponentInterpretation>
729 solution_component_interpretation(
730 1, DataComponentInterpretation::component_is_scalar);
733 solution_output_structs.emplace_back(
738 solution_component_interpretation);
741 std::vector<std::string> filtered_solution_names(1,
"filtered_phase");
742 std::vector<DataComponentInterpretation::DataComponentInterpretation>
743 filtered_solution_component_interpretation(
744 1, DataComponentInterpretation::component_is_scalar);
745 solution_output_structs.emplace_back(
749 filtered_solution_names,
750 filtered_solution_component_interpretation);
754 if ((cls_parameters.surface_tension_force.enable &&
755 cls_parameters.surface_tension_force.output_cls_auxiliary_fields) ||
756 cls_parameters.reinitialization_method
757 .pde_based_interface_reinitialization.enable)
759 std::vector<DataComponentInterpretation::DataComponentInterpretation>
760 projected_phase_indicator_gradient_component_interpretation(
761 dim, DataComponentInterpretation::component_is_scalar);
762 for (
int i = 0; i < dim; ++i)
763 projected_phase_indicator_gradient_component_interpretation[i] =
764 DataComponentInterpretation::component_is_part_of_vector;
766 std::vector<std::string> phase_gradient_projection_name(
767 dim,
"phase_indicator_gradient");
768 solution_output_structs.emplace_back(
772 this->cls_subequations_interface->get_solution(
774 phase_gradient_projection_name,
775 projected_phase_indicator_gradient_component_interpretation);
777 if (cls_parameters.surface_tension_force.enable &&
778 cls_parameters.surface_tension_force.output_cls_auxiliary_fields)
780 solution_output_structs.emplace_back(
784 this->cls_subequations_interface->get_solution(
786 std::vector<std::string>(1,
"curvature"),
788 DataComponentInterpretation::DataComponentInterpretation>(
789 1, DataComponentInterpretation::component_is_scalar));
794 .geometric_interface_reinitialization.enable)
798 .reinitialization_method.frequency !=
812 solution_output_structs.push_back(output_struct);
815 "interface_reconstruction_" +
817 this->simulation_parameters.simulation_control.output_folder,
821 return solution_output_structs;
828 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
830 FEValues<dim> fe_values_cls(*this->
mapping,
833 update_values | update_quadrature_points |
837 std::vector<double> phase_exact_solution(n_q_points);
838 std::vector<double> phase_values(n_q_points);
845 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
847 if (cell->is_locally_owned())
849 fe_values_cls.reinit(cell);
854 exact_solution.value_list(fe_values_cls.get_quadrature_points(),
855 phase_exact_solution);
857 for (
unsigned int q = 0; q < n_q_points; q++)
859 double sim = phase_values[q];
860 double exact = phase_exact_solution[q];
861 l2error += (sim - exact) * (sim - exact) * fe_values_cls.JxW(q);
865 l2error = Utilities::MPI::sum(l2error, mpi_communicator);
870template <
typename VectorType>
871std::pair<Tensor<1, dim>, Tensor<1, dim>>
876 const MPI_Comm mpi_communicator = this->
triangulation->get_mpi_communicator();
878 FEValues<dim> fe_values_cls(*this->
mapping,
881 update_values | update_quadrature_points |
884 std::shared_ptr<ConservativeLevelSetFilterBase>
filter =
888 const DoFHandler<dim> &dof_handler_fd =
891 FEValues<dim> fe_values_fd(*this->
mapping,
892 dof_handler_fd.get_fe(),
893 *this->cell_quadrature,
897 std::vector<double> phase_values(n_q_points);
898 std::vector<Tensor<1, dim>> velocity_values(n_q_points);
899 std::vector<Point<dim>> quadrature_locations(n_q_points);
901 const FEValuesExtractors::Vector
velocity(0);
903 Tensor<1, dim> barycenter_location;
904 Tensor<1, dim> barycenter_velocity;
908 std::map<field, std::vector<double>> fields;
910 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
912 if (cell->is_locally_owned())
914 fe_values_cls.reinit(cell);
915 quadrature_locations = fe_values_cls.get_quadrature_points();
916 fe_values_cls.get_function_values(solution, phase_values);
919 typename DoFHandler<dim>::active_cell_iterator cell_fd(
925 fe_values_fd.reinit(cell_fd);
926 fe_values_fd[
velocity].get_function_values(solution_fd,
929 for (
unsigned int q = 0; q < n_q_points; q++)
931 const double JxW = fe_values_cls.JxW(q);
932 const double filtered_phase_value =
933 filter->filter_phase(phase_values[q]);
935 volume += (filtered_phase_value)*JxW;
936 barycenter_location +=
937 (filtered_phase_value)*quadrature_locations[q] * JxW;
938 barycenter_velocity +=
939 (filtered_phase_value)*velocity_values[q] * JxW;
944 volume = Utilities::MPI::sum(volume, mpi_communicator);
945 barycenter_location =
946 Utilities::MPI::sum(barycenter_location, mpi_communicator) / volume;
947 barycenter_velocity =
948 Utilities::MPI::sum(barycenter_velocity, mpi_communicator) / volume;
950 return std::pair<Tensor<1, dim>, Tensor<1, dim>>(barycenter_location,
951 barycenter_velocity);
954template std::pair<Tensor<1, 2>, Tensor<1, 2>>
960template std::pair<Tensor<1, 3>, Tensor<1, 3>>
965template std::pair<Tensor<1, 2>, Tensor<1, 2>>
971template std::pair<Tensor<1, 3>, Tensor<1, 3>>
978template <
typename VectorType>
985 const MPI_Comm mpi_communicator = this->
triangulation->get_mpi_communicator();
987 FEValues<dim> fe_values_cls(*this->
mapping,
990 update_values | update_JxW_values);
992 const DoFHandler<dim> &dof_handler_fd =
994 QGauss<dim> quadrature_formula(dof_handler_fd.get_fe().degree + 1);
996 FEValues<dim> fe_values_fd(*this->
mapping,
997 dof_handler_fd.get_fe(),
1001 const FEValuesExtractors::Scalar
pressure(dim);
1004 std::vector<double> phase_values(n_q_points);
1005 std::vector<double> density_0(n_q_points);
1006 std::vector<double> density_1(n_q_points);
1007 std::vector<double> pressure_values(n_q_points);
1013 const auto density_models =
1015 .get_density_vector();
1016 std::map<field, std::vector<double>> fields;
1020 for (
const auto &cell_cls : this->
dof_handler->active_cell_iterators())
1022 if (cell_cls->is_locally_owned())
1024 fe_values_cls.reinit(cell_cls);
1025 fe_values_cls.get_function_values(solution, phase_values);
1031 typename DoFHandler<dim>::active_cell_iterator cell_fd(
1037 fe_values_fd.reinit(cell_fd);
1038 fe_values_fd[
pressure].get_function_values(current_solution_fd,
1043 density_models[0]->vector_value(fields, density_0);
1044 density_models[1]->vector_value(fields, density_1);
1046 for (
unsigned int q = 0; q < n_q_points; q++)
1048 switch (monitored_fluid)
1053 fe_values_cls.JxW(q) * (1 - phase_values[q]);
1055 (1 - phase_values[q]) *
1062 fe_values_cls.JxW(q) * phase_values[q];
1064 fe_values_cls.JxW(q) * phase_values[q] * density_1[q];
1068 throw std::runtime_error(
1069 "Unsupported number of fluids (>2)");
1082template <
typename VectorType>
1089 const MPI_Comm mpi_communicator = this->
triangulation->get_mpi_communicator();
1091 FEValues<dim> fe_values_cls(*this->
mapping,
1094 update_values | update_JxW_values);
1096 const DoFHandler<dim> &dof_handler_fd =
1099 FEValues<dim> fe_values_fd(*this->
mapping,
1100 dof_handler_fd.get_fe(),
1101 *this->cell_quadrature,
1104 const FEValuesExtractors::Vector
velocity(0);
1105 const FEValuesExtractors::Scalar
pressure(dim);
1108 std::vector<double> phase_values(n_q_points);
1109 std::vector<double> density_0(n_q_points);
1110 std::vector<double> density_1(n_q_points);
1111 std::vector<double> pressure_values(n_q_points);
1112 std::vector<Tensor<1, dim>> velocity_values(n_q_points);
1114 Tensor<1, dim> total_momentum;
1117 const auto density_models =
1119 .get_density_vector();
1120 std::map<field, std::vector<double>> fields;
1124 for (
const auto &cell_cls : this->
dof_handler->active_cell_iterators())
1126 if (cell_cls->is_locally_owned())
1128 fe_values_cls.reinit(cell_cls);
1129 fe_values_cls.get_function_values(solution, phase_values);
1132 typename DoFHandler<dim>::active_cell_iterator cell_fd(
1137 fe_values_fd.reinit(cell_fd);
1139 fe_values_fd[
velocity].get_function_values(current_solution_fd,
1145 fe_values_fd[
pressure].get_function_values(current_solution_fd,
1153 density_models[0]->vector_value(fields, density_0);
1154 density_models[1]->vector_value(fields, density_1);
1156 for (
unsigned int q = 0; q < n_q_points; q++)
1158 switch (monitored_fluid)
1162 total_momentum += fe_values_cls.JxW(q) *
1163 (1 - phase_values[q]) *
1164 velocity_values[q] * density_0[q];
1169 total_momentum += fe_values_cls.JxW(q) * phase_values[q] *
1170 velocity_values[q] * density_1[q];
1174 throw std::runtime_error(
1175 "Unsupported number of fluids (>2)");
1181 total_momentum = Utilities::MPI::sum(total_momentum, mpi_communicator);
1183 return total_momentum;
1189 const bool pressure_dependent,
1190 const bool temperature_dependent)
1193 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
1196 FEValues<dim> fe_values_cls(*this->
mapping,
1199 update_quadrature_points | update_JxW_values);
1203 const DoFHandler<dim> *dof_handler_fd =
nullptr;
1204 const DoFHandler<dim> *dof_handler_ht =
nullptr;
1207 std::unique_ptr<FEValues<dim>> fe_values_fd;
1208 std::unique_ptr<FEValues<dim>> fe_values_ht;
1215 const FEValuesExtractors::Scalar
pressure(dim);
1218 std::vector<double> density_0(n_q_points);
1219 std::vector<double> density_1(n_q_points);
1220 std::vector<double> pressure_values(n_q_points);
1221 std::vector<double> surface_tension(n_q_points);
1222 std::vector<double> temperature_values(n_q_points);
1225 if (pressure_dependent)
1229 fe_values_fd = std::make_unique<FEValues<dim>>(*this->
mapping,
1230 dof_handler_fd->get_fe(),
1233 current_solution_fd =
1238 if (temperature_dependent)
1241 fe_values_ht = std::make_unique<FEValues<dim>>(*this->
mapping,
1242 dof_handler_ht->get_fe(),
1245 current_solution_ht =
1249 std::map<field, std::vector<double>> fields;
1250 const auto density_models =
1252 .get_density_vector();
1253 std::shared_ptr<SurfaceTensionModel> surface_tension_model =
1255 .get_surface_tension();
1262 double capillary_time_step_constraint = std::numeric_limits<double>::max();
1265 const unsigned int degree = this->
dof_handler->get_fe().degree;
1268 for (
const auto &cell_cls : this->
dof_handler->active_cell_iterators())
1270 if (cell_cls->is_locally_owned())
1272 fe_values_cls.reinit(cell_cls);
1274 if (pressure_dependent)
1277 typename DoFHandler<dim>::active_cell_iterator cell_fd(
1283 fe_values_fd->reinit(cell_fd);
1284 (*fe_values_fd)[
pressure].get_function_values(
1285 *current_solution_fd, pressure_values);
1289 if (temperature_dependent)
1292 typename DoFHandler<dim>::active_cell_iterator cell_ht(
1298 fe_values_ht->reinit(cell_ht);
1299 fe_values_ht->get_function_values(*current_solution_ht,
1300 temperature_values);
1305 density_models[0]->vector_value(fields, density_0);
1306 density_models[1]->vector_value(fields, density_1);
1307 surface_tension_model->vector_value(fields, surface_tension);
1310 double cell_measure =
1315 for (
unsigned int q = 0; q < n_q_points; q++)
1317 double density_average = 0.5 * (density_0[q] + density_1[q]);
1318 double surface_tension_q =
1319 std::max(surface_tension[q], 1e-16);
1320 double denominator_inv = 1 / (numbers::PI * surface_tension_q);
1323 double new_capillary_time_step_constraint =
1324 std::sqrt(density_average * Utilities::fixed_power<3>(h) *
1328 capillary_time_step_constraint =
1329 std::min(new_capillary_time_step_constraint,
1330 capillary_time_step_constraint);
1336 return Utilities::MPI::min(capillary_time_step_constraint, mpi_communicator);
1343 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
1344 unsigned int this_mpi_process(
1345 Utilities::MPI::this_mpi_process(mpi_communicator));
1347 if (this_mpi_process == 0 &&
1353 this->
error_table.omit_column_from_convergence_rate_evaluation(
"cells");
1355 this->
error_table.omit_column_from_convergence_rate_evaluation(
"time");
1357 this->
error_table.set_scientific(
"error_phase",
true);
1366 this->
pcout << std::defaultfloat;
1368 this->
pcout << std::scientific;
1387 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
1388 unsigned int this_mpi_process(
1389 Utilities::MPI::this_mpi_process(mpi_communicator));
1406 this->
error_table.add_value(
"error_phase", phase_error);
1407 this->
error_table.set_scientific(
"error_phase",
true);
1409 if (this_mpi_process == 0)
1411 std::string filename =
1415 std::ofstream output(filename.c_str());
1422 this->
pcout <<
"L2 error phase : " << phase_error << std::endl;
1429 "Calculate mass conservation");
1430 const std::vector<Parameters::FluidIndicator> fluid_indicators = {
1434 const unsigned int n_fluids =
1436 .get_number_of_fluids();
1439 std::string volume_column_name;
1440 std::string mass_column_name;
1442 std::string geometric_volume_column_name;
1443 std::string area_column_name;
1446 std::vector<std::string> dependent_column_names;
1447 dependent_column_names.reserve(n_fluids * 2 + 1);
1448 std::vector<double> volumes_masses_momentum_and_sharpening_threshold;
1449 volumes_masses_momentum_and_sharpening_threshold.reserve(n_fluids * 2 +
1452 if (this_mpi_process == 0)
1470 double geometric_volume_outside, geometric_volume_inside, surface;
1476 std::tie(geometric_volume_outside, surface) =
1481 const double global_volume =
1483 geometric_volume_inside = global_volume - geometric_volume_outside;
1486 for (
unsigned int i = 0; i < n_fluids; i++)
1492 fluid_indicators[i]);
1495 const Tensor<1, dim> momentum =
1499 fluid_indicators[i]);
1501 if (this_mpi_process == 0)
1503 std::string fluid_id(
"");
1507 fluid_id =
"fluid_1";
1509 else if (fluid_indicators[i] ==
1512 fluid_id =
"fluid_0";
1515 std::vector<std::string> momentum_names(
1516 {
"momentum-x_" + fluid_id,
"momentum-y_" + fluid_id});
1517 if constexpr (dim == 3)
1518 momentum_names.emplace_back(
"momentum-z_" + fluid_id);
1520 if constexpr (dim == 2)
1522 volume_column_name =
"surface_" + fluid_id;
1523 mass_column_name =
"mass_per_length_" + fluid_id;
1524 geometric_volume_column_name =
1525 "geometric_surface_" + fluid_id;
1526 area_column_name =
"length_" + fluid_id;
1528 else if constexpr (dim == 3)
1530 volume_column_name =
"volume_" + fluid_id;
1531 mass_column_name =
"mass_" + fluid_id;
1532 geometric_volume_column_name =
"geometric_volume_" + fluid_id;
1533 area_column_name =
"surface_" + fluid_id;
1548 if (fluid_id ==
"fluid_1")
1551 geometric_volume_column_name, geometric_volume_inside);
1553 geometric_volume_column_name,
true);
1555 geometric_volume_column_name,
1561 geometric_volume_column_name, geometric_volume_outside);
1563 geometric_volume_column_name,
true);
1565 geometric_volume_column_name,
1589 for (
int d = 0; d < dim; ++d)
1603 dependent_column_names.emplace_back(volume_column_name);
1607 dependent_column_names.emplace_back(
1608 geometric_volume_column_name);
1611 dependent_column_names.emplace_back(mass_column_name);
1614 dependent_column_names.emplace_back(area_column_name);
1616 volumes_masses_momentum_and_sharpening_threshold.emplace_back(
1620 if (fluid_id ==
"fluid_1")
1621 volumes_masses_momentum_and_sharpening_threshold
1622 .emplace_back(geometric_volume_inside);
1624 volumes_masses_momentum_and_sharpening_threshold
1625 .emplace_back(geometric_volume_outside);
1627 volumes_masses_momentum_and_sharpening_threshold.emplace_back(
1632 volumes_masses_momentum_and_sharpening_threshold
1633 .emplace_back(surface);
1635 for (
int d = 0; d < dim; ++d)
1637 dependent_column_names.emplace_back(momentum_names[d]);
1638 volumes_masses_momentum_and_sharpening_threshold
1639 .emplace_back(momentum[d]);
1645 if (this_mpi_process == 0)
1652 this->simulation_parameters.post_processing.output_frequency ==
1656 std::string filename =
1659 .mass_conservation_output_name +
1661 std::ofstream output(filename.c_str());
1669 volumes_masses_momentum_and_sharpening_threshold.emplace_back(
1671 dependent_column_names.emplace_back(
"sharpening_threshold");
1675 std::vector<std::vector<double>>
1676 volumes_masses_and_sharpening_thresholds;
1677 volumes_masses_and_sharpening_thresholds.emplace_back(
1678 volumes_masses_momentum_and_sharpening_threshold);
1681 std::string independent_column_name =
"time";
1682 std::vector<double> time = {
1687 independent_column_name,
1688 volumes_masses_and_sharpening_thresholds,
1689 dependent_column_names,
1693 std::cout << std::endl;
1698 table.write_text(std::cout);
1706 std::pair<Tensor<1, dim>, Tensor<1, dim>> position_and_velocity;
1707 std::pair<Tensor<1, dim>, Tensor<1, dim>> position_and_velocity_geo;
1716 average_velocity_profile &&
1717 !this->simulation_parameters.multiphysics.fluid_dynamics &&
1719 this->simulation_parameters.post_processing
1720 .initial_time_for_average_velocities)
1729 position_and_velocity =
1741 average_velocity_profile &&
1742 !this->simulation_parameters.multiphysics.fluid_dynamics &&
1744 this->simulation_parameters.post_processing
1745 .initial_time_for_average_velocities)
1747 position_and_velocity =
1754 position_and_velocity =
1759 const DoFHandler<dim> &dof_handler_fd =
1762 const Mapping<dim> &mapping_fd =
1771 dof_handler_fd.get_fe(),
1776 if (this_mpi_process == 0)
1781 std::cout << std::endl;
1782 std::string independent_column_names =
"time";
1784 std::vector<std::string> dependent_column_names;
1785 dependent_column_names.emplace_back(
"x_cls");
1786 dependent_column_names.emplace_back(
"y_cls");
1787 if constexpr (dim == 3)
1788 dependent_column_names.emplace_back(
"z_cls");
1789 dependent_column_names.emplace_back(
"vx_cls");
1790 dependent_column_names.emplace_back(
"vy_cls");
1791 if constexpr (dim == 3)
1792 dependent_column_names.emplace_back(
"vz_cls");
1794 dependent_column_names.emplace_back(
"x_cls_geo");
1795 dependent_column_names.emplace_back(
"y_cls_geo");
1796 if constexpr (dim == 3)
1797 dependent_column_names.emplace_back(
"z_cls_geo");
1798 dependent_column_names.emplace_back(
"vx_cls_geo");
1799 dependent_column_names.emplace_back(
"vy_cls_geo");
1800 if constexpr (dim == 3)
1801 dependent_column_names.emplace_back(
"vz_cls_geo");
1803 std::vector<Tensor<1, dim>> position_vector{
1804 position_and_velocity.first};
1805 std::vector<Tensor<1, dim>> velocity_vector{
1806 position_and_velocity.second};
1808 std::vector<Tensor<1, dim>> position_vector_geo{
1809 position_and_velocity_geo.first};
1810 std::vector<Tensor<1, dim>> velocity_vector_geo{
1811 position_and_velocity_geo.second};
1813 std::vector<std::vector<Tensor<1, dim>>>
1814 position_and_velocity_vectors{position_vector,
1816 position_vector_geo,
1817 velocity_vector_geo};
1819 std::vector<double> time = {
1824 independent_column_names,
1825 position_and_velocity_vectors,
1826 dependent_column_names,
1831 table.write_text(std::cout);
1841 position_and_velocity.first[0]);
1847 position_and_velocity.first[1]);
1852 if constexpr (dim == 3)
1855 position_and_velocity.first[2]);
1862 position_and_velocity.second[0]);
1868 position_and_velocity.second[1]);
1873 if constexpr (dim == 3)
1876 position_and_velocity.second[2]);
1883 position_and_velocity_geo.first[0]);
1889 position_and_velocity_geo.first[1]);
1894 if constexpr (dim == 3)
1897 "z_cls_geo", position_and_velocity_geo.first[2]);
1904 position_and_velocity_geo.second[0]);
1910 position_and_velocity_geo.second[1]);
1915 if constexpr (dim == 3)
1918 "vz_cls_geo", position_and_velocity_geo.second[2]);
1925 this->simulation_parameters.post_processing.output_frequency ==
1929 std::string filename =
1932 .barycenter_output_name +
1934 std::ofstream output(filename.c_str());
1946 "Compute bounding values of phase isocontours");
1950 .ids_and_isocontours_per_variable,
1952 *this->present_solution,
1953 this->simulation_control->get_current_time(),
1954 this->simulation_parameters.post_processing.verbosity,
1956 this->phase_indicator_isocontour_bounding_values_tables);
1959 this->simulation_parameters.post_processing.output_frequency ==
1963 this->simulation_parameters.simulation_control.output_folder,
1965 this->simulation_parameters.post_processing.isocontour_bounding_boxes
1966 .ids_and_isocontours_per_variable,
1967 this->phase_indicator_isocontour_bounding_values_tables);
1979 this->simulation_parameters.multiphysics.cls_parameters
1980 .surface_tension_force.enable &&
1981 this->simulation_parameters.simulation_control
1982 .adapt_with_capillary_time_step_ratio)
1989 this->simulation_parameters.physical_properties_manager
1999 this->
pcout << std::defaultfloat;
2001 this->
pcout << std::scientific;
2012 auto cls_parameters =
2015 if (cls_parameters.reinitialization_method.sharpening.enable)
2019 this->simulation_parameters.multiphysics.cls_parameters
2020 .reinitialization_method.frequency ==
2030 .pde_based_interface_reinitialization.enable &&
2033 .reinitialization_method.frequency ==
2039 .geometric_interface_reinitialization.enable &&
2042 .reinitialization_method.frequency ==
2069 this->
pcout <<
"Sharpening interface at step "
2074 .reinitialization_method.sharpening.type ==
2080 this->
pcout <<
" Adapting the sharpening threshold" << std::endl;
2088 this->
pcout <<
" ... final sharpening is : "
2097 .reinitialization_method.sharpening.threshold;
2112 .reinitialization_method.sharpening.threshold_max_deviation;
2115 .reinitialization_method.sharpening.threshold_max_deviation;
2118 const double mass_deviation_tol =
2120 .reinitialization_method.sharpening.tolerance *
2122 const unsigned int max_iterations =
2124 .reinitialization_method.sharpening.max_iterations;
2128 .reinitialization_method.sharpening.monitored_fluid;
2130 unsigned int nb_search_ite = 0;
2135 double mass_deviation_avg = 0.;
2146 st_avg = (st_min + st_max) / 2.;
2154 <<
" ... step " << nb_search_ite
2155 <<
" of the search algorithm, min, avg, max mass deviation is : "
2156 << mass_deviation_min <<
" " << mass_deviation_avg <<
" "
2157 << mass_deviation_max << std::endl;
2160 if (mass_deviation_avg * mass_deviation_min < 0)
2163 mass_deviation_max = mass_deviation_avg;
2168 mass_deviation_min = mass_deviation_avg;
2171 while (std::abs(mass_deviation_avg) > mass_deviation_tol &&
2172 nb_search_ite < max_iterations);
2177 if (std::abs(mass_deviation_avg) > mass_deviation_tol)
2179 double mass_deviation_endpoint = 0.;
2180 double st_tested = 0;
2181 if (st_min == st_avg)
2183 else if (st_max == st_avg)
2186 mass_deviation_endpoint =
2191 if (std::abs(mass_deviation_endpoint) > std::abs(mass_deviation_avg))
2197 if (std::abs(mass_deviation_endpoint) > mass_deviation_tol)
2200 <<
" WARNING: Maximum number of iterations (" << nb_search_ite
2201 <<
") reached in the " << std::endl
2202 <<
" adaptive sharpening threshold algorithm, remaining error"
2204 <<
" on mass conservation is: "
2208 <<
" Consider increasing the sharpening threshold range or the "
2210 <<
" number of iterations to reach the mass conservation tolerance."
2219 this->
pcout <<
" ... search algorithm took : " << nb_search_ite
2220 <<
" step(s) " << std::endl
2221 <<
" ... error on mass conservation reached: "
2253 return mass_deviation;
2261 const bool sharpen_previous_solutions)
2265 if (sharpen_previous_solutions)
2275 if (sharpen_previous_solutions)
2288 if (sharpen_previous_solutions)
2311 FEValues<dim> fe_values_phase_indicator(*this->
mapping,
2314 update_values | update_JxW_values |
2317 const unsigned int dofs_per_cell = this->
fe->dofs_per_cell;
2320 FullMatrix<double> local_matrix_phase_indicator(dofs_per_cell, dofs_per_cell);
2321 Vector<double> local_rhs_phase_indicator(dofs_per_cell);
2322 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
2324 std::vector<double> phi_phase_indicator(dofs_per_cell);
2325 std::vector<Tensor<1, dim>> phi_phase_indicator_gradient(dofs_per_cell);
2327 std::vector<double> phase_values(n_q_points);
2334 double cell_measure;
2336 const double phase_indicator_diffusion_factor =
2338 ->projection_step_diffusion_factor;
2340 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
2342 if (cell->is_locally_owned())
2344 fe_values_phase_indicator.reinit(cell);
2348 fe_values_phase_indicator.get_JxW_values());
2351 local_matrix_phase_indicator = 0;
2352 local_rhs_phase_indicator = 0;
2355 fe_values_phase_indicator.get_function_values(solution, phase_values);
2357 double color_function = 0.0;
2358 for (
unsigned int q = 0; q < n_q_points; ++q)
2361 phase_values[q] * fe_values_phase_indicator.JxW(q);
2364 color_function /= cell_measure;
2366 for (
unsigned int q = 0; q < n_q_points; ++q)
2368 for (
unsigned int k = 0; k < dofs_per_cell; ++k)
2370 phi_phase_indicator[k] =
2371 fe_values_phase_indicator.shape_value(k, q);
2372 phi_phase_indicator_gradient[k] =
2373 fe_values_phase_indicator.shape_grad(k, q);
2376 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
2379 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
2381 local_matrix_phase_indicator(i, j) +=
2382 (phi_phase_indicator[j] * phi_phase_indicator[i] +
2383 phase_indicator_diffusion_factor * h * h *
2384 scalar_product(phi_phase_indicator_gradient[i],
2385 phi_phase_indicator_gradient[j])) *
2386 fe_values_phase_indicator.JxW(q);
2390 local_rhs_phase_indicator(i) +=
2391 phi_phase_indicator[i] * color_function *
2392 fe_values_phase_indicator.JxW(q);
2396 cell->get_dof_indices(local_dof_indices);
2398 local_matrix_phase_indicator,
2399 local_rhs_phase_indicator,
2416 const double linear_solver_tolerance = 1e-13;
2421 SolverControl solver_control(
2423 linear_solver_tolerance,
2427 TrilinosWrappers::SolverCG solver(solver_control);
2429 const unsigned int ilu_fill =
2432 const double ilu_atol =
2435 const double ilu_rtol =
2439 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
2440 ilu_fill, ilu_atol, ilu_rtol, 0);
2445 preconditionerOptions);
2447 completely_distributed_phase_indicator_solution,
2454 this->
pcout <<
" -Iterative solver (phase indicator) took : "
2455 << solver_control.last_step() <<
" steps " << std::endl;
2459 completely_distributed_phase_indicator_solution);
2460 solution = completely_distributed_phase_indicator_solution;
2483 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
2514 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
2516 dealii::Vector<float> &estimated_error_per_cell)
2521 ivar.second.error_estimator ==
2524 "Only the Kelly error estimator is currently implemented for the "
2525 "<phase> CLS field."));
2528 ComponentMask phase_mask =
2529 fe->component_mask(FEValuesExtractors::Scalar(0));
2537 dealii::Vector<float> &estimated_error_per_cell,
2538 const ComponentMask &component_mask)
2540 KellyErrorEstimator<dim>::estimate(
2544 typename std::map<types::boundary_id,
const Function<dim, double> *>(),
2546 estimated_error_per_cell,
2551std::vector<OutputStructTableHandler>
2554 std::vector<OutputStructTableHandler> table_output_structs;
2556 std::string prefix =
2558 std::string suffix =
".checkpoint";
2561 table_output_structs.emplace_back(
2567 table_output_structs.emplace_back(
2571 .mass_conservation_output_name +
2575 table_output_structs.emplace_back(
2592 for (
auto it = begin; it != end; ++it, ++i)
2595 const std::string &isocontour_output_name =
2596 it->second.second.output_name;
2598 table_output_structs.emplace_back(
2600 prefix + isocontour_output_name + suffix);
2604 return table_output_structs;
2611 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
2613 std::vector<const GlobalVectorType *> sol_set_transfer;
2616 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
2621 sol_set_transfer.emplace_back(&previous_solution);
2627 const std::vector<OutputStructTableHandler> &table_output_structs =
2636 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
2639 this->
pcout <<
"Reading CLS checkpoint" << std::endl;
2641 std::vector<GlobalVectorType *> input_vectors(1 + previous_solutions_size);
2644 input_vectors[0] = &distributed_system;
2647 std::vector<GlobalVectorType> distributed_previous_solutions;
2648 distributed_previous_solutions.reserve(previous_solutions_size);
2649 for (
unsigned int i = 0; i < previous_solutions_size; ++i)
2651 distributed_previous_solutions.emplace_back(
2653 input_vectors[i + 1] = &distributed_previous_solutions[i];
2659 for (
unsigned int i = 0; i < previous_solutions_size; ++i)
2669 std::vector<OutputStructTableHandler> table_output_structs =
2674 .reinitialization_method.sharpening.type ==
2681 this->simulation_parameters.multiphysics.cls_parameters
2682 .reinitialization_method.sharpening.monitored_fluid);
2695 auto mpi_communicator =
triangulation->get_mpi_communicator();
2701 DoFRenumbering::Cuthill_McKee(*this->
dof_handler);
2706 DoFTools::extract_locally_relevant_dofs(*this->
dof_handler);
2744 DoFTools::make_flux_sparsity_pattern(*this->
dof_handler,
2751 DoFTools::make_sparsity_pattern(*this->
dof_handler,
2757 SparsityTools::distribute_sparsity_pattern(dsp,
2799 this->
pcout <<
" Number of CLS degrees of freedom: "
2809 this->previous_solutions);
2812 .geometric_interface_reinitialization.enable)
2834 for (
auto const &[
id, type] :
2857 DoFTools::make_hanging_node_constraints(*this->
dof_handler,
2860 for (
auto const &[
id, type] :
2865 VectorTools::interpolate_boundary_values(
2868 Functions::ZeroFunction<dim>(),
2873 const auto &periodic_boundary =
2875 .periodic_boundaries.at(
id);
2876 DoFTools::make_periodicity_constraints(*this->
dof_handler,
2878 periodic_boundary.neighbor_id,
2879 periodic_boundary.direction,
2880 this->zero_constraints);
2896 DoFTools::make_hanging_node_constraints(*this->
dof_handler,
2899 for (
auto const &[
id, type] :
2904 VectorTools::interpolate_boundary_values(
2908 .phase_indicator.at(
id),
2913 const auto &periodic_boundary =
2915 .periodic_boundaries.at(
id);
2916 DoFTools::make_periodicity_constraints(
2919 periodic_boundary.neighbor_id,
2920 periodic_boundary.direction,
2933 VectorTools::interpolate(*this->
mapping,
2936 this->newton_update);
2942 ->cls_initial_condition_smoothing ==
2947 ->cls_initial_condition_smoothing ==
2954 .reinitialization_method.sharpening.type ==
2961 this->simulation_parameters.multiphysics.cls_parameters
2962 .reinitialization_method.sharpening.monitored_fluid);
2972 .output_cls_auxiliary_fields) ||
2974 .pde_based_interface_reinitialization.enable)
2987 .pde_based_interface_reinitialization.enable &&
2989 .pde_based_interface_reinitialization.output_reinitialization_steps)
2991 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
2992 const std::string folder =
2994 "/pde-based-reinitialization-steps-output/";
2998 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
3000 if (stat(folder.c_str(), &buffer) != 0)
3014 this->simulation_parameters.multiphysics.cls_parameters
3015 .surface_tension_force.enable &&
3016 this->simulation_parameters.simulation_control
3017 .adapt_with_capillary_time_step_ratio)
3024 this->simulation_parameters.physical_properties_manager
3029 ->limit_initial_time_step_with_capillary_time_step_constraint();
3042 const unsigned int ilu_fill =
3044 const double ilu_atol =
3046 const double ilu_rtol =
3048 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
3049 ilu_fill, ilu_atol, ilu_rtol, 0);
3063 std::vector<std::vector<bool>> constant_modes;
3065 ComponentMask components(1,
true);
3067 DoFTools::extract_constant_modes(*this->
dof_handler, components);
3071 const bool elliptic =
false;
3072 bool higher_order_elements =
false;
3073 if (this->
fe->degree > 1)
3074 higher_order_elements =
true;
3075 const unsigned int n_cycles =
3077 const bool w_cycle =
3079 const double aggregation_threshold =
3081 .amg_aggregation_threshold;
3082 const unsigned int smoother_sweeps =
3084 const unsigned int smoother_overlap =
3086 const bool output_details =
false;
3087 const char *smoother_type =
"ILU";
3088 const char *coarse_type =
"ILU";
3089 TrilinosWrappers::PreconditionAMG::AdditionalData preconditionerOptions(
3091 higher_order_elements,
3094 aggregation_threshold,
3102 Teuchos::ParameterList parameter_ml;
3103 std::unique_ptr<Epetra_MultiVector> distributed_constant_modes;
3104 preconditionerOptions.set_parameters(parameter_ml,
3105 distributed_constant_modes,
3107 const double ilu_fill =
3109 const double ilu_atol =
3111 const double ilu_rtol =
3113 parameter_ml.set(
"smoother: ifpack level-of-fill", ilu_fill);
3114 parameter_ml.set(
"smoother: ifpack absolute threshold", ilu_atol);
3115 parameter_ml.set(
"smoother: ifpack relative threshold", ilu_rtol);
3117 parameter_ml.set(
"coarse: ifpack level-of-fill", ilu_fill);
3118 parameter_ml.set(
"coarse: ifpack absolute threshold", ilu_atol);
3119 parameter_ml.set(
"coarse: ifpack relative threshold", ilu_rtol);
3131 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
3133 const AffineConstraints<double> &constraints_used = this->
zero_constraints;
3135 const double absolute_residual =
3137 const double relative_residual =
3141 const double current_residual = this->
system_rhs.l2_norm() / rescale_metric;
3142 const double linear_solver_tolerance =
3143 std::max(relative_residual * current_residual, absolute_residual);
3144 const double non_rescaled_linear_solver_tolerance =
3145 linear_solver_tolerance * rescale_metric;
3150 this->
pcout <<
" -Tolerance of iterative solver is : "
3151 << linear_solver_tolerance << std::endl;
3157 SolverControl solver_control(
3159 non_rescaled_linear_solver_tolerance,
3163 TrilinosWrappers::SolverGMRES::AdditionalData solver_parameters(
3167 TrilinosWrappers::SolverGMRES solver(solver_control, solver_parameters);
3169 const auto preconditioner_type =
3176 completely_distributed_solution,
3180 else if (preconditioner_type ==
3185 completely_distributed_solution,
3193 "This linear solver does not support this preconditioner. Only <ilu> and <amg> preconditioners are supported."));
3198 this->
pcout <<
" -Iterative solver took : " << solver_control.last_step()
3199 <<
" steps to reach a residual norm of "
3200 << solver_control.last_value() / rescale_metric << std::endl;
3204 constraints_used.distribute(completely_distributed_solution);
3218 const double penalty_parameter = 100;
3231 std::vector<bool> dof_touched(this->
dof_handler->n_dofs(),
false);
3233 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
3235 if (cell->is_locally_owned())
3237 for (
unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
3240 Assert(this->
dof_handler->get_fe().dofs_per_cell ==
3241 GeometryInfo<dim>::vertices_per_cell,
3242 ExcNotImplemented());
3243 const unsigned int dof_index = cell->vertex_dof_index(v, 0);
3246 const double solution_value =
3248 if (lambda(dof_index) +
3259 lambda(dof_index) = 0;
3261 else if (lambda(dof_index) +
3273 lambda(dof_index) = 0;
3290 const double interface_sharpness =
3292 .reinitialization_method.sharpening.interface_sharpness;
3294 FEValues<dim> fe_values_cls(*this->
mapping,
3297 update_values | update_JxW_values);
3299 const unsigned int dofs_per_cell = this->
fe->dofs_per_cell;
3301 FullMatrix<double> local_matrix_phase_indicator(dofs_per_cell, dofs_per_cell);
3302 Vector<double> local_rhs_phase_indicator(dofs_per_cell);
3303 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
3304 std::vector<double> phi_phase(dofs_per_cell);
3306 std::vector<double> phase_values(n_q_points);
3311 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
3313 if (cell->is_locally_owned())
3315 fe_values_cls.reinit(cell);
3317 local_matrix_phase_indicator = 0;
3318 local_rhs_phase_indicator = 0;
3320 fe_values_cls.get_function_values(solution, phase_values);
3322 for (
unsigned int q = 0; q < n_q_points; ++q)
3324 auto phase_value = phase_values[q];
3327 for (
unsigned int k = 0; k < dofs_per_cell; ++k)
3329 phi_phase[k] = fe_values_cls.shape_value(k, q);
3331 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
3334 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
3336 local_matrix_phase_indicator(i, j) +=
3337 (phi_phase[j] * phi_phase[i]) * fe_values_cls.JxW(q);
3346 local_rhs_phase_indicator(i) +=
3348 (1. - interface_sharpness)) *
3349 std::pow(phase_value, interface_sharpness) *
3350 phi_phase[i] * fe_values_cls.JxW(q);
3353 local_rhs_phase_indicator(i) +=
3356 (1. - interface_sharpness)) *
3357 std::pow((1. - phase_value), interface_sharpness)) *
3358 phi_phase[i] * fe_values_cls.JxW(q);
3363 cell->get_dof_indices(local_dof_indices);
3365 local_matrix_phase_indicator,
3366 local_rhs_phase_indicator,
3383 const double linear_solver_tolerance = 1e-15;
3386 .reinitialization_method.verbosity ==
3389 this->
pcout <<
" -Tolerance of iterative solver is : "
3390 << linear_solver_tolerance << std::endl;
3397 SolverControl solver_control(
3399 linear_solver_tolerance,
3403 TrilinosWrappers::SolverCG solver(solver_control);
3408 const unsigned int ilu_fill =
3411 const double ilu_atol =
3414 const double ilu_rtol =
3418 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
3419 ilu_fill, ilu_atol, ilu_rtol, 0);
3422 std::make_shared<TrilinosWrappers::PreconditionILU>();
3425 preconditionerOptions);
3428 completely_distributed_phase_indicator_solution,
3433 .reinitialization_method.verbosity ==
3436 this->
pcout <<
" -Iterative solver took : " << solver_control.last_step()
3437 <<
" steps " << std::endl;
3441 completely_distributed_phase_indicator_solution);
3442 solution = completely_distributed_phase_indicator_solution;
3448 TrilinosWrappers::SparseMatrix &mass_matrix)
3452 FEValues<dim> fe_values_cls(*this->
fe,
3454 update_values | update_JxW_values);
3457 const unsigned int dofs_per_cell = this->
fe->dofs_per_cell;
3458 const unsigned int n_q_points = quadrature_formula.size();
3459 FullMatrix<double> cell_matrix(dofs_per_cell, dofs_per_cell);
3460 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
3461 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
3463 if (cell->is_locally_owned())
3465 fe_values_cls.reinit(cell);
3467 for (
unsigned int q = 0; q < n_q_points; ++q)
3468 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
3469 cell_matrix(i, i) +=
3470 (fe_values_cls.shape_value(i, q) *
3471 fe_values_cls.shape_value(i, q) * fe_values_cls.JxW(q));
3472 cell->get_dof_indices(local_dof_indices);
3474 cell_matrix, local_dof_indices, mass_matrix);
3487 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
3490 filtered_solution_owned = original_solution;
3500 filtered_solution_owned[p] =
3501 filter->filter_phase(filtered_solution_owned[p]);
3508 this->
pcout <<
"Filtered phase values: " << std::endl;
3511 this->
pcout << filtered_phase << std::endl;
3520 TimerOutput::Scope t(this->
computing_timer,
"PDE-based reinitialization");
3525 .reinitialization_method.frequency > 1)
3527 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
3544 FETools::interpolate(
3547 this->cls_subequations_interface->get_solution(
3550 this->nonzero_constraints,
3551 previous_reinitialized_solution_owned);
3567 FETools::interpolate(
3570 this->cls_subequations_interface->get_solution(
3573 this->nonzero_constraints,
3574 this->local_evaluation_point);
3584 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
3590 const double phase = solution[p];
3591 level_set_owned[p] = (-2.0 *
phase + 1.0);
3596 level_set_solution = level_set_owned;
3605 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
3611 const double signed_dist = level_set_solution[p];
3617 phase_indicator_solution = solution_owned;
3624 TimerOutput::Scope t(this->
computing_timer,
"Geometric reinitialization");
3630 this->
pcout <<
"In redistanciation of the previous solution ..."
3634 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
3656 this->nonzero_constraints,
3657 previous_level_set_owned);
3660 previous_level_set = previous_level_set_owned;
3668 this->
pcout <<
"In redistanciation of the present solution ..."
3681 this->nonzero_constraints,
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
AuxiliaryPhysics(const Parameters::NonLinearSolver non_linear_solver_parameters)
Class that assembles the transient time arising from BDF time integration for the CLS equation....
Class that assembles the core of the CLS solver. According to the following weak form: with an SUPG ...
Assemble the Discontinuity-Capturing Directional Dissipation (DCDD) stabilization term for the CLS ph...
Class that assembles the core (cells) of the CLS equation for DG elements. This class assembles the w...
Store the information required by the assembly procedure for a CLS free surface equation....
void reinit(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType ¤t_solution, const std::vector< VectorType > &previous_solutions)
Reinitialize the content of the scratch.
void reinit_velocity(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType ¤t_solution, const std::vector< VectorType > &previous_solutions, const Parameters::ALE< dim > &ale)
Reinitialize the velocity, calculated by the Fluid Dynamics.
static std::shared_ptr< ConservativeLevelSetFilterBase > model_cast(const Parameters::CLS_PhaseFilter &phase_filter_parameters)
Instantiate and return a pointer to a ConservativeLevelSetFilterBase object by casting it to the prop...
const SimulationParameters< dim > & simulation_parameters
GlobalVectorType system_rhs_phase_indicator
void compute_error_estimate(const std::pair< const Variable, Parameters::MultipleAdaptationParameters > &ivar, dealii::Vector< float > &estimated_error_per_cell) override
Compute the error estimator for mesh refinement.
TableHandler table_monitoring_cls
double find_sharpening_threshold()
Find the sharpening threshold to ensure mass conservation of the fluid monitored, as given in the prm...
TableHandler table_barycenter
GlobalVectorType nodal_phase_indicator_owned
std::shared_ptr< GlobalVectorType > filtered_solution
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
void percolate_time_vectors() override
Carry out the operations required to rearrange the values of the previous solution at the end of a ti...
void assemble_mass_matrix(TrilinosWrappers::SparseMatrix &mass_matrix)
Assembles a mass_matrix which is used in update_solution_and_constraints function to limit the phase ...
void assemble_system_rhs() override
Assemble the rhs associated with the solver.
ConvergenceTable error_table
void compute_level_set_from_phase_indicator(const GlobalVectorType &solution, GlobalVectorType &level_set_solution)
Compute level-set field from the phase indicator field using an inverse tanh-based transformation.
void assemble_projection_phase_indicator(GlobalVectorType &solution)
Assembles the matrix and rhs for calculation of a smooth phase indicator using a projection.
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
void setup_amg()
Set up the AMG preconditioner stored in amg_preconditioner.
const double phase_lower_bound
double sharpening_threshold
void assemble_system_matrix_dg()
Assemble the matrix associated with the solver when DG elements are used.
virtual void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, CLSScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local rhs for a given cell.
std::shared_ptr< SimulationControl > simulation_control
TrilinosWrappers::SparseMatrix system_matrix
GlobalVectorType newton_update
void solve_interface_sharpening(GlobalVectorType &solution)
Solves the assembled system to sharpen the interface. The linear_solver_tolerance is hardcoded = 1e-1...
virtual void copy_local_rhs_to_global_rhs(const StabilizedMethodsCopyData ©_data)
Copy local cell rhs information to global rhs.
ConservativeLevelSet(MultiphysicsInterface< dim > *multiphysics_interface, const SimulationParameters< dim > &p_simulation_parameters, const std::shared_ptr< parallel::DistributedTriangulationBase< dim > > &p_triangulation, std::shared_ptr< SimulationControl > p_simulation_control)
CLS - Base constructor.
void modify_solution() override
Carry out modifications on the auxiliary physic solution.
void solve_projection_phase_indicator(GlobalVectorType &solution)
Solves smooth phase indicator system.
std::shared_ptr< CLSSubequationsInterface< dim > > cls_subequations_interface
void update_boundary_conditions() override
Update non zero constraints if the boundary is time dependent.
void smooth_phase_indicator(GlobalVectorType &solution)
Carries out the smoothing phase indicator with a projection step (to avoid a staircase interface).
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
void update_solution_and_constraints(GlobalVectorType &solution)
Limit the phase indicators between 0 and 1. This is necessary before interface sharpening....
void postprocess(bool first_iteration) override
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
std::vector< OutputStructTableHandler > gather_tables() override
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for t...
void pre_mesh_adaptation() override
pre_mesh_adaption Prepares the auxiliary physics variables for a mesh refinement/coarsening
std::shared_ptr< CLSAssemblerSIPG< dim > > inner_face_assembler
void assemble_system_rhs_cg()
Assemble the rhs associated with the solver when CG elements are used.
std::shared_ptr< DoFHandler< dim > > dof_handler
MultiphysicsInterface< dim > * multiphysics
TrilinosWrappers::SparseMatrix system_matrix_phase_indicator
std::vector< std::shared_ptr< CLSAssemblerBase< dim > > > assemblers
void compute_kelly(dealii::Vector< float > &estimated_error_per_cell, const ComponentMask &component_mask)
Compute the Kelly error estimator on the phase variable for mesh refinement. See : https://www....
virtual void copy_local_matrix_to_global_matrix(const StabilizedMethodsCopyData ©_data)
Copy local cell information to global matrix.
GlobalVectorType local_evaluation_point
void finish_simulation() override
Carry out the operations required to finish a simulation correctly.
void define_zero_constraints()
defined the zero constraints used to solve the problem.
double calculate_L2_error()
Calculates the L2 error of the solution.
std::shared_ptr< ConservativeLevelSetFilterBase > filter
void setup_ilu()
Set up the ILU preconditioner stored in ilu_preconditioner.
double compute_capillary_time_step_constraint(const bool pressure_dependent, const bool temperature_dependent)
Computes the capillary time-step constraint.
void write_checkpoint() override
Prepares auxiliary physics to write checkpoint.
const double phase_upper_bound
void sharpen_interface(GlobalVectorType &solution, const double sharpening_threshold, const bool sharpen_previous_solutions)
Carries out interface sharpening. It is called in the modify solution function.
GlobalVectorType complete_system_rhs_phase_indicator
GlobalVectorType level_set
std::shared_ptr< FiniteElement< dim > > fe
void assemble_system_matrix_cg()
Assemble the matrix associated with the solver when CG elements are used.
AffineConstraints< double > zero_constraints
void compute_phase_indicator_from_level_set(const GlobalVectorType &level_set_solution, GlobalVectorType &phase_indicator_solution)
Compute the phase indicator field from level-set field using a tanh-based transformation.
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
AffineConstraints< double > nonzero_constraints
std::shared_ptr< SignedDistanceTransformationBase > signed_distance_transformation
GlobalVectorType system_rhs
virtual void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, CLSScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local matrix for a given cell.
void set_initial_conditions() override
Sets-up the initial conditions associated with the physics. Generally, physics only support imposing ...
TrilinosWrappers::SparseMatrix mass_matrix_phase_indicator
void solve_linear_system() override
Call for the solution of the linear system of equation using a strategy appropriate to the auxiliary ...
void reinitialize_interface_with_geometric_method()
Reinitialize the interface between fluids using the geometric approach.
double calculate_mass_deviation(const Parameters::FluidIndicator monitored_fluid, const double sharpening_threshold)
Calculate the mass deviation of the monitored fluid, between the current iteration and the mass at fi...
TrilinosWrappers::SparseMatrix complete_system_matrix_phase_indicator
TimerOutput computing_timer
IndexSet locally_owned_dofs
void define_non_zero_constraints()
defined the non zero constraints used to solve the problem.
void calculate_volume_and_mass(const GlobalVectorType &solution, const VectorType ¤t_solution_fd, const Parameters::FluidIndicator monitored_fluid)
Calculates the volume and mass for a given fluid phase. Used for conservation monitoring.
void assemble_system_matrix() override
Assembles the matrix associated with the solver.
std::vector< SolutionTransfer< dim, GlobalVectorType > > previous_solutions_transfer
virtual void setup_assemblers()
sets up the vector of assembler functions
Tensor< 1, dim > calculate_momentum(const GlobalVectorType &solution, const VectorType ¤t_solution_fd, const Parameters::FluidIndicator monitored_fluid)
Calculates the momentum for a given fluid phase. Used for conservation monitoring.
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
void output_per_iteration_timer() override
Output the per iteration wallclock times.
std::shared_ptr< InterfaceTools::SignedDistanceSolver< dim, GlobalVectorType > > signed_distance_solver
void post_mesh_adaptation() override
post_mesh_adaption Interpolates the auxiliary physics variables to the new mesh
void handle_interface_sharpening()
Carries out interface sharpening. It is called in the modify solution function. Launches sharpen_inte...
void apply_phase_filter(const GlobalVectorType &original_solution, GlobalVectorType &filtered_solution)
Apply filter on phase indicator values.
GlobalVectorType evaluation_point
void setup_dofs() override
Sets-up the DofHandler and the degree of freedom associated with the physics.
void read_checkpoint() override
Set solution vector of Auxiliary Physics using checkpoint.
void assemble_rhs()
Call for the assembly of the right-hand side.
std::pair< Tensor< 1, dim >, Tensor< 1, dim > > calculate_barycenter(const GlobalVectorType &solution, const VectorType ¤t_solution_fd)
Calculates the barycenter of the fluid and its velocity.
void assemble_L2_projection_interface_sharpening(GlobalVectorType &solution, const double sharpening_threshold)
Assemble the system for interface sharpening.
virtual std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Gather and return vector of output structs that are particular to some applications.
std::shared_ptr< Mapping< dim > > mapping
IndexSet locally_relevant_dofs
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
double mass_first_iteration
void reinitialize_interface_with_pde_based_method()
Reinitialize the interface between fluids using the PDE-based approach.
std::shared_ptr< TrilinosWrappers::PreconditionAMG > amg_preconditioner
AMG preconditioner used by the iterative linear solver of the main conservative level set system.
std::vector< TableHandler > phase_indicator_isocontour_bounding_values_tables
Vector of tables containing evolution of phase indicator isocontour bounding values.
std::shared_ptr< GlobalVectorType > present_solution
AffineConstraints< double > bounding_constraints
void reinit_face_velocity_with_adequate_solution(const typename DoFHandler< dim >::active_cell_iterator &velocity_cell, const unsigned int &face_no, CLSScratchData< dim > &scratch_data)
Helper function to reinit the face velocity with the adequate solution. This prevents code duplicatio...
void assemble_system_rhs_dg()
Assemble the rhs associated with the solver when DG elements are used.
std::shared_ptr< Quadrature< dim > > cell_quadrature
PhysicsSolverStrategy< GlobalVectorType > * physics_solving_strategy
Responsible for storing the information calculated using the discontinuous galerkin (DG) assembly of ...
std::vector< CopyDataFace > face_data
Class responsible for storing the information calculated using the assembly of stabilized scalar equa...
Vector< double > local_rhs
FullMatrix< double > local_matrix
void reset()
Resets the cell_matrix, cell_rhs, strong_residual and strong_jacobian to zero.
std::vector< types::global_dof_index > local_dof_indices
@ curvature_projection
CLS curvature L2 projection.
@ pde_based_interface_reinitialization
CLS PDE-based interface reinitialization.
@ phase_gradient_projection
CLS phase indicator gradient L2 projection.
double compute_cell_measure_with_JxW(const std::vector< double > &JxW_values)
Computes the area (2D) or volume (3D) of the cell by integrating 1 over the cell, by summing JxW valu...
TableHandler make_table_scalars_tensors(const std::vector< T > &independent_values, const std::string &independent_column_name, const std::vector< Tensor< 1, dim > > &dependent_vector, const std::vector< std::string > &dependent_column_names, const unsigned int display_precision, const bool display_scientific_notation=false)
Generate a table from a vector of scalars (independent variable) and a vector of Tensor<1,...
void create_output_folder(const std::string &dirname)
Creates the simulation output folder.
TableHandler make_table_scalars_vectors(const std::vector< T > &independent_values, const std::string &independent_column_name, const std::vector< std::vector< double > > &dependent_vector, const std::vector< std::string > &dependent_column_names, const unsigned int display_precision, const bool display_scientific_notation=false)
Generate a table from a vector of scalars (independent variable) and a vector of vectors of scalars (...
void delete_output_folder(const std::string &dirname)
Delete the output folder and its content.
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.
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...
double compute_cell_diameter(const double cell_measure, const unsigned int fe_degree)
Computes equivalent cell diameter by comparing the area to a disk (2D) or the volume to a sphere (3D)...
void deserialize_tables_vector(std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Deserializes all the TableHandler objects in table_output_structs.
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
@ phase
Phase indicator scalar field from CLS.
@ velocity
Velocity vector field from fluid dynamics.
@ pressure
Pressure scalar field from fluid dynamics.
PhysicsID
Unique identifiers for each physics module in Lethe.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
@ heat_transfer
Heat transfer (Temperature).
FluidDynamicsInitialConditionType
FluidIndicator
Class to account for different fluid indicators. This is used for multiphase simulations in PostProce...
void set_field_vector(const field &id, const std::vector< double > &data, std::map< field, std::vector< double > > &fields)
std::pair< double, double > calculate_L2_error(const DoFHandler< dim > &dof_handler, const VectorType &evaluation_point, const Function< dim > *exact_solution, const Quadrature< dim > &quadrature_formula, const Mapping< dim > &mapping)
Calculates the L2 norm of the error on velocity and pressure.
Struct containing information about the solution output. It is used to pass all the information requi...
@ amg
Algebraic Multigrid.
@ ilu
Incomplete LU Factorization.
GlobalVectorType VectorType
bool time_stepping_is_bdf(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the bdf family.
bool time_stepping_is_sdirk(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the sdirk family.
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
dealii::TrilinosWrappers::MPI::BlockVector GlobalBlockVectorType