12#include <deal.II/base/work_stream.h>
14#include <deal.II/dofs/dof_renumbering.h>
15#include <deal.II/dofs/dof_tools.h>
17#include <deal.II/fe/mapping.h>
18#include <deal.II/fe/mapping_q.h>
20#include <deal.II/grid/grid_tools.h>
22#include <deal.II/lac/affine_constraints.h>
23#include <deal.II/lac/dynamic_sparsity_pattern.h>
24#include <deal.II/lac/solver_control.h>
25#include <deal.II/lac/sparsity_tools.h>
26#include <deal.II/lac/trilinos_precondition.h>
27#include <deal.II/lac/trilinos_solver.h>
29#include <deal.II/numerics/error_estimator.h>
30#include <deal.II/numerics/vector_tools.h>
39 "The SDIRK scheme is not yet supported for this physics"));
62 (this->simulation_parameters.multiphysics.cahn_hilliard_parameters
64 this->simulation_parameters.multiphysics.cahn_hilliard_parameters
67 this->simulation_parameters.cahn_hilliard_boundary_conditions));
74 (this->simulation_parameters.multiphysics.cahn_hilliard_parameters
76 this->simulation_parameters.multiphysics.cahn_hilliard_parameters
79 this->simulation_parameters.cahn_hilliard_boundary_conditions));
86 (this->simulation_parameters.multiphysics.cahn_hilliard_parameters
88 this->simulation_parameters.multiphysics.cahn_hilliard_parameters
102 const DoFHandler<dim> &dof_handler_fluid =
108 *this->cell_quadrature,
110 dof_handler_fluid.get_fe(),
111 *this->face_quadrature);
114 this->dof_handler->end(),
120 this->cell_quadrature->size()));
128 const typename DoFHandler<dim>::active_cell_iterator &cell,
144 const DoFHandler<dim> &dof_handler_fluid =
147 typename DoFHandler<dim>::active_cell_iterator velocity_cell(
148 &(*
triangulation), cell->level(), cell->index(), &dof_handler_fluid);
155 this->simulation_parameters.ale);
162 this->simulation_parameters.ale);
170 assembler->assemble_matrix(scratch_data, copy_data);
185 constraints_used.distribute_local_to_global(copy_data.
local_matrix,
199 const DoFHandler<dim> &dof_handler_fluid =
205 *this->cell_quadrature,
207 dof_handler_fluid.get_fe(),
208 *this->face_quadrature);
211 this->dof_handler->end(),
217 this->cell_quadrature->size()));
219 this->
system_rhs.compress(VectorOperation::add);
225 const typename DoFHandler<dim>::active_cell_iterator &cell,
241 const DoFHandler<dim> &dof_handler_fluid =
244 typename DoFHandler<dim>::active_cell_iterator velocity_cell(
245 &(*
triangulation), cell->level(), cell->index(), &dof_handler_fluid);
252 this->simulation_parameters.ale);
259 this->simulation_parameters.ale);
267 assembler->assemble_rhs(scratch_data, copy_data);
282 constraints_used.distribute_local_to_global(copy_data.
local_rhs,
288std::vector<OutputStruct<dim, GlobalVectorType>>
291 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
294 std::vector<std::string> solution_names;
295 solution_names.emplace_back(
"phase_order");
296 solution_names.emplace_back(
"chemical_potential");
298 std::vector<DataComponentInterpretation::DataComponentInterpretation>
299 data_component_interpretation(
300 2, DataComponentInterpretation::component_is_scalar);
302 solution_output_structs.emplace_back(
307 data_component_interpretation);
309 std::vector<std::string> solution_names_filtered;
310 solution_names_filtered.emplace_back(
"phase_order_filtered");
311 solution_names_filtered.emplace_back(
"chemical_potential_filtered");
314 solution_output_structs.emplace_back(
318 solution_names_filtered,
319 data_component_interpretation);
321 return solution_output_structs;
325std::pair<double, double>
328 auto mpi_communicator =
triangulation->get_mpi_communicator();
330 FEValues<dim> fe_values(*this->
mapping,
333 update_values | update_gradients |
334 update_quadrature_points | update_JxW_values);
336 const FEValuesExtractors::Scalar phase_order(0);
337 const FEValuesExtractors::Scalar chemical_potential(1);
340 std::vector<Vector<double>> q_exactSol(n_q_points, Vector<double>(2));
342 std::vector<double> local_phase_order_values(n_q_points);
343 std::vector<double> local_chemical_potential_values(n_q_points);
345 auto &exact_solution =
349 double l2_error_phase_order = 0.;
350 double l2_error_chemical_potential = 0.;
352 for (
const auto &cell :
dof_handler->active_cell_iterators())
354 if (cell->is_locally_owned())
356 fe_values.reinit(cell);
358 local_phase_order_values);
359 fe_values[chemical_potential].get_function_values(
363 exact_solution.vector_value_list(fe_values.get_quadrature_points(),
366 for (
unsigned int q = 0; q < n_q_points; q++)
370 double phase_order_sim = local_phase_order_values[q];
371 double phase_order_exact = q_exactSol[q][0];
373 l2_error_phase_order += (phase_order_sim - phase_order_exact) *
374 (phase_order_sim - phase_order_exact) *
377 double chemical_potential_sim =
378 local_chemical_potential_values[q];
379 double chemical_potential_exact = q_exactSol[q][1];
381 l2_error_chemical_potential +=
382 (chemical_potential_sim - chemical_potential_exact) *
383 (chemical_potential_sim - chemical_potential_exact) *
388 l2_error_phase_order =
389 Utilities::MPI::sum(l2_error_phase_order, mpi_communicator);
390 l2_error_chemical_potential =
391 Utilities::MPI::sum(l2_error_chemical_potential, mpi_communicator);
393 return std::make_pair(std::sqrt(l2_error_phase_order),
394 std::sqrt(l2_error_chemical_potential));
402 auto mpi_communicator =
triangulation->get_mpi_communicator();
404 FEValues<dim> fe_values(*
mapping,
407 update_values | update_gradients |
408 update_quadrature_points | update_JxW_values);
410 const FEValuesExtractors::Scalar phase_order(0);
413 std::vector<double> local_phase_order_values(n_q_points);
414 std::vector<Tensor<1, dim>> local_phase_order_gradients(n_q_points);
417 double max_phase_value(std::numeric_limits<double>::min());
418 double min_phase_value(std::numeric_limits<double>::max());
423 for (
const auto &cell :
dof_handler->active_cell_iterators())
425 if (cell->is_locally_owned())
427 fe_values.reinit(cell);
429 local_phase_order_values);
430 fe_values[phase_order].get_function_gradients(
432 for (
unsigned int q = 0; q < n_q_points; q++)
434 integral += local_phase_order_values[q] * fe_values.JxW(q);
436 std::max(local_phase_order_values[q], max_phase_value);
438 std::min(local_phase_order_values[q], min_phase_value);
440 (1 + local_phase_order_values[q]) * 0.5 * fe_values.JxW(q);
442 (1 - local_phase_order_values[q]) * 0.5 * fe_values.JxW(q);
447 min_phase_value = Utilities::MPI::min(min_phase_value, mpi_communicator);
448 max_phase_value = Utilities::MPI::max(max_phase_value, mpi_communicator);
450 integral = Utilities::MPI::sum(integral, mpi_communicator);
451 volume_0 = Utilities::MPI::sum(volume_0, mpi_communicator);
452 volume_1 = Utilities::MPI::sum(volume_1, mpi_communicator);
455 double phase_average = integral / global_volume;
463 this->
pcout <<
"Min: " << min_phase_value << std::endl;
464 this->
pcout <<
"Max: " << max_phase_value << std::endl;
465 this->
pcout <<
"Average: " << phase_average << std::endl;
466 this->
pcout <<
"Integral: " << integral << std::endl;
467 this->
pcout <<
"Volume phase 0: " << volume_0 << std::endl;
468 this->
pcout <<
"Volume phase 1: " << volume_1 << std::endl;
491 auto mpi_communicator =
triangulation->get_mpi_communicator();
493 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
495 std::string filename =
498 std::ofstream output(filename.c_str());
508 auto mpi_communicator =
triangulation->get_mpi_communicator();
510 FEValues<dim> fe_values(*
mapping,
513 update_values | update_gradients |
514 update_quadrature_points | update_JxW_values);
516 const FEValuesExtractors::Scalar phase_order(0);
519 std::vector<double> local_phase_order_values(n_q_points);
520 std::vector<Tensor<1, dim>> local_phase_order_gradients(n_q_points);
522 double bulk_energy(0.);
523 double interface_energy(0.);
524 double total_energy(0.);
533 for (
const auto &cell :
dof_handler->active_cell_iterators())
535 if (cell->is_locally_owned())
537 fe_values.reinit(cell);
539 local_phase_order_values);
540 fe_values[phase_order].get_function_gradients(
542 for (
unsigned int q = 0; q < n_q_points; q++)
544 bulk_energy += (1 - local_phase_order_values[q] *
545 local_phase_order_values[q]) *
546 (1 - local_phase_order_values[q] *
547 local_phase_order_values[q]) *
549 interface_energy += epsilon * epsilon * 0.5 *
550 (local_phase_order_gradients[q] *
551 local_phase_order_gradients[q]) *
557 bulk_energy = Utilities::MPI::sum(bulk_energy, mpi_communicator);
558 interface_energy = Utilities::MPI::sum(interface_energy, mpi_communicator);
559 total_energy = bulk_energy + interface_energy;
575 this->
pcout <<
"Bulk energy: " << bulk_energy << std::endl;
576 this->
pcout <<
"Interface energy: " << interface_energy << std::endl;
577 this->
pcout <<
"Total energy: " << total_energy << std::endl;
585 auto mpi_communicator =
triangulation->get_mpi_communicator();
587 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
589 std::string filename =
592 std::ofstream output(filename.c_str());
606 auto mpi_communicator =
triangulation->get_mpi_communicator();
607 unsigned int this_mpi_process(
608 Utilities::MPI::this_mpi_process(mpi_communicator));
610 if (this_mpi_process == 0 &&
614 error_table.omit_column_from_convergence_rate_evaluation(
"cells");
620 ConvergenceTable::reduction_rate_log2);
622 error_table.set_scientific(
"error_phase_order",
true);
625 error_table.set_scientific(
"error_chemical_potential",
true);
626 error_table.set_precision(
"error_chemical_potential",
634 this->
pcout << std::defaultfloat;
636 this->
pcout << std::scientific;
646 (*previous_solutions)[i] = (*previous_solutions)[i - 1];
663 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
664 unsigned int this_mpi_process(
665 Utilities::MPI::this_mpi_process(mpi_communicator));
675 error_table.add_value(
"error_phase_order", phase_order_error);
676 error_table.add_value(
"error_chemical_potential", potential_error);
678 error_table.set_scientific(
"error_phase_order",
true);
679 error_table.set_scientific(
"error_chemical_potential",
true);
681 if (this_mpi_process == 0)
683 std::string filename =
686 "_cahn_hilliard.dat";
687 std::ofstream output(filename.c_str());
694 this->
pcout <<
"L2 error phase order: " << phase_order_error
696 this->
pcout <<
"L2 error chemical potential: " << potential_error
704 double epsilon = GridTools::minimal_cell_diameter(*
triangulation);
706 this->
pcout <<
"Epsilon value: " << epsilon << std::endl;
713 this->simulation_parameters.post_processing.output_frequency ==
723 this->simulation_parameters.post_processing.output_frequency ==
733 std::pair<Tensor<1, dim>, Tensor<1, dim>> position_and_velocity;
741 average_velocity_profile &&
742 !this->simulation_parameters.multiphysics.fluid_dynamics &&
744 this->simulation_parameters.post_processing
745 .initial_time_for_average_velocities)
754 position_and_velocity =
766 average_velocity_profile &&
767 !this->simulation_parameters.multiphysics.fluid_dynamics &&
769 this->simulation_parameters.post_processing
770 .initial_time_for_average_velocities)
772 position_and_velocity =
779 position_and_velocity =
785 if (this_mpi_process == 0)
790 std::cout << std::endl;
791 std::string independent_column_names =
"time";
793 std::vector<std::string> dependent_column_names;
794 dependent_column_names.emplace_back(
"x_cahn_hilliard");
795 dependent_column_names.emplace_back(
"y_cahn_hilliard");
796 if constexpr (dim == 3)
797 dependent_column_names.emplace_back(
"z_cahn_hilliard");
798 dependent_column_names.emplace_back(
"vx_cahn_hilliard");
799 dependent_column_names.emplace_back(
"vy_cahn_hilliard");
800 if constexpr (dim == 3)
801 dependent_column_names.emplace_back(
"vz_cahn_hilliard");
803 std::vector<Tensor<1, dim>> position_vector{
804 position_and_velocity.first};
805 std::vector<Tensor<1, dim>> velocity_vector{
806 position_and_velocity.second};
808 std::vector<std::vector<Tensor<1, dim>>>
809 position_and_velocity_vectors{position_vector, velocity_vector};
811 std::vector<double> time = {
816 independent_column_names,
817 position_and_velocity_vectors,
818 dependent_column_names,
824 table.write_text(std::cout);
831 position_and_velocity.first[0]);
833 position_and_velocity.first[1]);
834 if constexpr (dim == 3)
836 position_and_velocity.first[2]);
839 position_and_velocity.second[0]);
841 position_and_velocity.second[1]);
842 if constexpr (dim == 3)
844 position_and_velocity.second[2]);
848 this->simulation_parameters.post_processing.output_frequency ==
852 std::string filename =
855 .barycenter_output_name +
857 std::ofstream output(filename.c_str());
870 this->
pcout << std::defaultfloat;
872 this->
pcout << std::scientific;
893 auto mpi_communicator =
triangulation->get_mpi_communicator();
914 (*previous_solutions)[i] = tmp_previous_solution;
921 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
923 dealii::Vector<float> &estimated_error_per_cell)
928 ivar.second.error_estimator ==
931 "Only the Kelly error estimator is currently implemented for the "
932 "<phase_cahn-hilliard> field."));
934 ComponentMask phase_mask =
935 fe->component_mask(FEValuesExtractors::Scalar(0));
941 ivar.second.error_estimator ==
944 "Only the Kelly error estimator is currently implemented for the "
945 "<chemical_potential_cahn-hilliard> field."));
946 ComponentMask chemical_potential_mask =
947 fe->component_mask(FEValuesExtractors::Scalar(1));
948 compute_kelly(estimated_error_per_cell, chemical_potential_mask);
956 dealii::Vector<float> &estimated_error_per_cell,
957 const ComponentMask &component_mask)
959 KellyErrorEstimator<dim>::estimate(
963 typename std::map<types::boundary_id,
const Function<dim, double> *>(),
965 estimated_error_per_cell,
970std::vector<OutputStructTableHandler>
973 std::vector<OutputStructTableHandler> table_output_structs;
977 std::string suffix =
".checkpoint";
980 table_output_structs.emplace_back(
986 table_output_structs.emplace_back(
992 table_output_structs.emplace_back(
999 table_output_structs.emplace_back(
1005 return table_output_structs;
1012 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
1013 std::vector<const GlobalVectorType *> sol_set_transfer;
1016 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
1021 sol_set_transfer.emplace_back(&previous_solution);
1027 const std::vector<OutputStructTableHandler> &table_output_structs =
1036 auto mpi_communicator =
triangulation->get_mpi_communicator();
1037 this->
pcout <<
"Reading Cahn Hilliard checkpoint" << std::endl;
1041 input_vectors[0] = &distributed_system;
1044 std::vector<GlobalVectorType> distributed_previous_solutions;
1048 distributed_previous_solutions.emplace_back(
1050 input_vectors[i + 1] = &distributed_previous_solutions[i];
1058 (*previous_solutions)[i] = distributed_previous_solutions[i];
1063 std::vector<OutputStructTableHandler> table_output_structs =
1076 DoFRenumbering::Cuthill_McKee(*this->
dof_handler);
1078 auto mpi_communicator =
triangulation->get_mpi_communicator();
1108 DoFTools::make_hanging_node_constraints(*this->
dof_handler,
1111 for (
auto const &[
id, type] :
1114 ComponentMask mask(2,
true);
1122 VectorTools::interpolate_boundary_values(
1134 const auto &periodic_boundary =
1136 .periodic_boundaries.at(
id);
1137 DoFTools::make_periodicity_constraints(
1140 periodic_boundary.neighbor_id,
1141 periodic_boundary.direction,
1151 DoFTools::make_hanging_node_constraints(*this->
dof_handler,
1154 for (
auto const &[
id, type] :
1159 VectorTools::interpolate_boundary_values(
1162 Functions::ZeroFunction<dim>(2),
1167 const auto &periodic_boundary =
1169 .periodic_boundaries.at(
id);
1170 DoFTools::make_periodicity_constraints(
1173 periodic_boundary.neighbor_id,
1174 periodic_boundary.direction,
1184 DoFTools::make_sparsity_pattern(*this->
dof_handler,
1189 SparsityTools::distribute_sparsity_pattern(dsp,
1198 this->
pcout <<
" Number of Cahn-Hilliard degrees of freedom: "
1209 this->previous_solutions);
1222 DoFTools::make_hanging_node_constraints(*this->
dof_handler,
1225 for (
auto const &[
id, type] :
1228 ComponentMask mask(2,
true);
1238 ->phi.set_time(time);
1240 VectorTools::interpolate_boundary_values(
1252 const auto &periodic_boundary =
1254 .periodic_boundaries.at(
id);
1255 DoFTools::make_periodicity_constraints(*this->
dof_handler,
1257 periodic_boundary.neighbor_id,
1258 periodic_boundary.direction,
1273 const FEValuesExtractors::Scalar phase_order(0);
1274 const FEValuesExtractors::Scalar potential(1);
1276 VectorTools::interpolate(
1281 fe->component_mask(phase_order));
1285 VectorTools::interpolate(
1290 fe->component_mask(potential));
1304 const unsigned int ilu_fill =
static_cast<unsigned int>(
1307 const double ilu_atol =
1310 const double ilu_rtol =
1313 TrilinosWrappers::PreconditionILU::AdditionalData preconditionerOptions(
1314 ilu_fill, ilu_atol, ilu_rtol, 0);
1330 std::vector<std::vector<bool>> constant_modes;
1332 ComponentMask components(2,
true);
1334 DoFTools::extract_constant_modes(*this->
dof_handler, components);
1338 const bool elliptic =
false;
1341 const bool higher_order_elements =
1345 const unsigned int n_cycles =
1348 const bool w_cycle =
1351 const double aggregation_threshold =
1353 .amg_aggregation_threshold;
1354 const unsigned int smoother_sweeps =
1356 .amg_smoother_sweeps;
1357 const unsigned int smoother_overlap =
1359 .amg_smoother_overlap;
1360 const bool output_details =
false;
1361 const char *smoother_type =
"ILU";
1362 const char *coarse_type =
"ILU";
1363 TrilinosWrappers::PreconditionAMG::AdditionalData preconditionerOptions(
1365 higher_order_elements,
1368 aggregation_threshold,
1376 Teuchos::ParameterList parameter_ml;
1377 std::unique_ptr<Epetra_MultiVector> distributed_constant_modes;
1378 preconditionerOptions.set_parameters(parameter_ml,
1379 distributed_constant_modes,
1381 const double ilu_fill =
1383 .amg_precond_ilu_fill;
1384 const double ilu_atol =
1386 .amg_precond_ilu_atol;
1387 const double ilu_rtol =
1389 .amg_precond_ilu_rtol;
1390 parameter_ml.set(
"smoother: ifpack level-of-fill", ilu_fill);
1391 parameter_ml.set(
"smoother: ifpack absolute threshold", ilu_atol);
1392 parameter_ml.set(
"smoother: ifpack relative threshold", ilu_rtol);
1394 parameter_ml.set(
"coarse: ifpack level-of-fill", ilu_fill);
1395 parameter_ml.set(
"coarse: ifpack absolute threshold", ilu_atol);
1396 parameter_ml.set(
"coarse: ifpack relative threshold", ilu_rtol);
1408 auto mpi_communicator =
triangulation->get_mpi_communicator();
1410 const AffineConstraints<double> &constraints_used = this->
zero_constraints;
1412 const double absolute_residual =
1415 const double relative_residual =
1420 const double current_residual =
system_rhs.l2_norm() / rescale_metric;
1421 const double linear_solver_tolerance =
1422 std::max(relative_residual * current_residual, absolute_residual);
1426 this->
pcout <<
" -Tolerance of iterative solver is : "
1427 << linear_solver_tolerance << std::endl;
1429 const double non_rescaled_linear_solver_tolerance =
1430 linear_solver_tolerance * rescale_metric;
1438 non_rescaled_linear_solver_tolerance,
1442 TrilinosWrappers::SolverGMRES::AdditionalData solver_parameters(
1445 .max_krylov_vectors);
1448 TrilinosWrappers::SolverGMRES solver(solver_control, solver_parameters);
1450 const auto preconditioner_type =
1458 completely_distributed_solution,
1462 else if (preconditioner_type ==
1467 completely_distributed_solution,
1475 "This linear solver does not support this preconditioner. Only <ilu> and <amg> preconditioners are supported."));
1480 this->
pcout <<
" -Iterative solver took : " << solver_control.last_step()
1481 <<
" steps to reach a residual norm of "
1482 << solver_control.last_value() / rescale_metric << std::endl;
1485 constraints_used.distribute(completely_distributed_solution);
1490template <
typename VectorType>
1491std::pair<Tensor<1, dim>, Tensor<1, dim>>
1495 const MPI_Comm mpi_communicator = this->
triangulation->get_mpi_communicator();
1497 FEValues<dim> fe_values_cahn_hilliard(*this->
mapping,
1500 update_values | update_gradients |
1501 update_quadrature_points |
1503 std::shared_ptr<CahnHilliardFilterBase>
filter =
1508 const DoFHandler<dim> &dof_handler_fd =
1511 FEValues<dim> fe_values_fd(*this->
mapping,
1512 dof_handler_fd.get_fe(),
1513 *this->cell_quadrature,
1517 std::vector<double> phase_cahn_hilliard_values(n_q_points);
1518 std::vector<Tensor<1, dim>> phase_cahn_hilliard_gradients(n_q_points);
1519 std::vector<Tensor<1, dim>> velocity_values(n_q_points);
1520 std::vector<Point<dim>> quadrature_locations(n_q_points);
1522 const FEValuesExtractors::Vector
velocity(0);
1523 const FEValuesExtractors::Scalar phase_order(0);
1525 Tensor<1, dim> barycenter_location;
1526 Tensor<1, dim> barycenter_velocity;
1530 std::map<field, std::vector<double>> fields;
1532 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
1534 if (cell->is_locally_owned())
1536 fe_values_cahn_hilliard.reinit(cell);
1537 quadrature_locations =
1538 fe_values_cahn_hilliard.get_quadrature_points();
1539 fe_values_cahn_hilliard[phase_order].get_function_values(
1540 solution, phase_cahn_hilliard_values);
1541 fe_values_cahn_hilliard[phase_order].get_function_gradients(
1542 solution, phase_cahn_hilliard_gradients);
1545 typename DoFHandler<dim>::active_cell_iterator cell_fd(
1551 fe_values_fd.reinit(cell_fd);
1552 fe_values_fd[
velocity].get_function_values(solution_fd,
1555 for (
unsigned int q = 0; q < n_q_points; q++)
1557 const double JxW = fe_values_cahn_hilliard.JxW(q);
1558 const double phase_values = phase_cahn_hilliard_values[q];
1562 volume += (1 - phase_values) * 0.5 * JxW;
1563 barycenter_location +=
1564 (1 - phase_values) * 0.5 * quadrature_locations[q] * JxW;
1565 barycenter_velocity +=
1566 (1 - phase_values) * 0.5 * velocity_values[q] * JxW;
1571 volume = Utilities::MPI::sum(volume, mpi_communicator);
1572 barycenter_location =
1573 Utilities::MPI::sum(barycenter_location, mpi_communicator) / volume;
1574 barycenter_velocity =
1575 Utilities::MPI::sum(barycenter_velocity, mpi_communicator) / volume;
1577 return std::pair<Tensor<1, dim>, Tensor<1, dim>>(barycenter_location,
1578 barycenter_velocity);
1585 auto mpi_communicator = this->
triangulation->get_mpi_communicator();
1587 FEValues<dim> fe_values(*
mapping,
1590 update_values | update_gradients |
1591 update_quadrature_points | update_JxW_values);
1600 std::unordered_set<unsigned int> filtered_cell_list;
1602 const unsigned int dofs_per_cell = this->
fe->dofs_per_cell;
1603 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1610 for (
const auto &cell : this->
dof_handler->active_cell_iterators())
1612 if (cell->is_locally_owned())
1614 cell->get_dof_indices(local_dof_indices);
1616 for (
unsigned int p = 0; p < local_dof_indices.size(); ++p)
1622 auto component_index =
fe->system_to_component_index(p).first;
1625 if (component_index == 0)
1628 filtered_cell_list.find(local_dof_indices[p]);
1629 if (iterator == filtered_cell_list.end())
1631 filtered_cell_list.insert(local_dof_indices[p]);
1632 filtered_solution_owned[local_dof_indices[p]] =
1634 filtered_solution_owned[local_dof_indices[p]]);
1647 this->
pcout <<
"Filtered phase values: " << std::endl;
1650 this->
pcout << filtered_phase << std::endl;
1659 auto mpi_communicator =
triangulation->get_mpi_communicator();
1661 FEValuesExtractors::Scalar phase_order(0);
1662 FEValuesExtractors::Scalar chemical_potential(1);
1664 ComponentMask phase_order_mask =
fe->component_mask(phase_order);
1665 ComponentMask chemical_potential_mask =
1666 fe->component_mask(chemical_potential);
1668 const std::vector<IndexSet> index_set_phase_order =
1669 DoFTools::locally_owned_dofs_per_component(*
dof_handler, phase_order_mask);
1670 const std::vector<IndexSet> index_set_chemical_potential =
1671 DoFTools::locally_owned_dofs_per_component(*
dof_handler,
1672 chemical_potential_mask);
1674 double local_sum = 0.0;
1675 double local_max = std::numeric_limits<double>::lowest();
1678 for (
const auto &j : index_set_phase_order[0])
1681 local_sum += dof_newton_update * dof_newton_update;
1682 local_max = std::max(local_max, std::abs(dof_newton_update));
1686 double global_phase_order_l2_norm =
1687 std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator));
1688 double global_phase_order_linfty_norm =
1689 Utilities::MPI::max(local_max, mpi_communicator);
1692 local_max = std::numeric_limits<double>::lowest();
1694 for (
const auto &j : index_set_chemical_potential[0])
1697 local_sum += dof_newton_update * dof_newton_update;
1698 local_max = std::max(local_max, std::abs(dof_newton_update));
1701 double global_chemical_potential_l2_norm =
1702 std::sqrt(Utilities::MPI::sum(local_sum, mpi_communicator));
1703 double global_chemical_potential_linfty_norm =
1704 Utilities::MPI::max(local_max, mpi_communicator);
1706 this->
pcout <<
"\n\t ||dphi||_L2 = " << std::setw(6)
1707 << global_phase_order_l2_norm << std::setw(6)
1708 <<
"\t ||dphi||_Linfty = " << global_phase_order_linfty_norm
1710 this->
pcout <<
"\t ||deta||_L2 = " << std::setw(6)
1711 << global_chemical_potential_l2_norm << std::setw(6)
1712 <<
"\t ||deta||_Linfty = "
1713 << global_chemical_potential_linfty_norm << std::endl;
1716template std::pair<Tensor<1, 2>, Tensor<1, 2>>
1721template std::pair<Tensor<1, 3>, Tensor<1, 3>>
1726template std::pair<Tensor<1, 2>, Tensor<1, 2>>
1732template std::pair<Tensor<1, 3>, Tensor<1, 3>>
Class that assembles the transient time arising from BDF time integration for the Cahn-Hilliard equat...
Class that assembles the core of the Cahn-Hilliard equation : .
Class that assembles the boundary condition that allows a free angle of contact, thus adding a degree...
static std::shared_ptr< CahnHilliardFilterBase > model_cast(const Parameters::CahnHilliard &cahn_hilliard_parameters)
Instantiate and return a pointer to a CahnHilliardFilterBase object by casting it to the proper child...
Class that implements a boundary conditions for the Cahn-Hilliard equation where the phase and chemic...
Class that stores the information required by the assembly procedure for the Cahn-Hilliard equations....
void calculate_physical_properties()
Calculates the physical properties that may be required by the Cahn-Hilliard problem....
void reinit_velocity(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType ¤t_solution, const Parameters::ALE< dim > &ale)
void reinit(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType ¤t_solution, const std::vector< VectorType > &previous_solutions, Function< dim > *source_function)
Reinitializes the content of the scratch.
void apply_phase_filter()
Applies filter on phase fraction values.
std::vector< OutputStructTableHandler > gather_tables() override
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for t...
virtual void setup_assemblers()
sets up the vector of assembler functions
std::shared_ptr< TrilinosWrappers::PreconditionAMG > amg_preconditioner
AMG preconditioner used by the iterative linear solver.
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
std::shared_ptr< DoFHandler< dim > > dof_handler
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
ILU preconditioner used by the iterative linear solver.
TrilinosWrappers::SparseMatrix system_matrix
TableHandler barycenter_table
GlobalVectorType newton_update
void solve_linear_system() override
Call for the solution of the linear system of equation using a strategy appropriate to the auxiliary ...
TimerOutput computing_timer
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
void finish_simulation() override
Carry out the operations required to finish a simulation correctly.
virtual void copy_local_matrix_to_global_matrix(const StabilizedMethodsCopyData ©_data)
Copy local cell information to global matrix.
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....
IndexSet locally_relevant_dofs
std::vector< std::shared_ptr< CahnHilliardAssemblerBase< dim > > > assemblers
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
void setup_amg()
Set up the AMG preconditioner stored in amg_preconditioner.
IndexSet locally_owned_dofs
std::shared_ptr< GlobalVectorType > filtered_solution
std::shared_ptr< FESystem< dim > > fe
void setup_dofs() override
Sets-up the DofHandler and the degree of freedom associated with the physics.
void assemble_system_matrix() override
Assembles the matrix associated with the solver.
void modify_solution() override
Carry out modifications on the auxiliary physic solution.
void setup_ilu()
Set up the ILU preconditioner stored in ilu_preconditioner.
std::shared_ptr< SimulationControl > simulation_control
GlobalVectorType system_rhs
void write_phase_statistics()
Writes the phase statistics to an output file.
virtual void copy_local_rhs_to_global_rhs(const StabilizedMethodsCopyData ©_data)
Copy local cell rhs information to global rhs.
TableHandler phase_energy_table
MultiphysicsInterface< dim > * multiphysics
GlobalVectorType local_evaluation_point
GlobalVectorType evaluation_point
std::pair< Tensor< 1, dim >, Tensor< 1, dim > > calculate_barycenter(const GlobalVectorType &solution, const VectorType ¤t_solution_fd)
Calculates the barycenter of fluid 1 and its velocity.
std::shared_ptr< CahnHilliardFilterBase > filter
AffineConstraints< double > nonzero_constraints
void post_mesh_adaptation() override
post_mesh_adaption Interpolates the auxiliary physics variables to the new mesh
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
void read_checkpoint() override
Allows Cahn-Hilliard physics to set-up solution vector from checkpoint file;.
void write_checkpoint() override
Prepares Cahn-Hilliard to write checkpoint.
void assemble_system_rhs() override
Assemble the rhs associated with the solver.
std::vector< SolutionTransfer< dim, GlobalVectorType > > previous_solutions_transfer
std::shared_ptr< Quadrature< dim > > cell_quadrature
std::shared_ptr< Mapping< dim > > mapping
AffineConstraints< double > zero_constraints
void write_phase_energy()
virtual void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, CahnHilliardScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local rhs for a given cell.
void percolate_time_vectors() override
Rearrange vector solution correctly for transient simulations.
void calculate_phase_statistics()
Calculate phase statistics for monitoring purposes.
ConvergenceTable error_table
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
std::shared_ptr< GlobalVectorType > present_solution
void set_initial_conditions() override
Sets-up the initial conditions associated with the physics. Generally, physics only support imposing ...
const SimulationParameters< dim > & simulation_parameters
void postprocess(bool first_iteration) override
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
void calculate_phase_energy()
Calculate the phase energies : bulk energy, interface energy and total energy.
void output_per_iteration_timer() override
Output the per iteration wallclock times.
TableHandler statistics_table
virtual void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, CahnHilliardScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local matrix for a given cell.
std::pair< double, double > calculate_L2_error()
Calculates the L2 error of the solution.
void update_boundary_conditions() override
Update non zero constraints if the boundary is time-dependent.
void pre_mesh_adaptation() override
pre_mesh_adaption Prepares the auxiliary physics variables for a mesh refinement/coarsening
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.
std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Gather and return vector of output structs that are particular to some applications.
void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
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
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 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...
void deserialize_tables_vector(std::vector< OutputStructTableHandler > &table_output_structs, const MPI_Comm mpi_communicator)
Deserializes all the TableHandler objects in table_output_structs.
@ chemical_potential_cahn_hilliard
Chemical potential scalar field from Cahn Hilliard.
@ phase_cahn_hilliard
Phase order scalar field from Cahn Hilliard.
@ velocity
Velocity vector field from fluid dynamics.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
@ cahn_hilliard
Cahn-Hilliard (Phase indicator, Potential).
FluidDynamicsInitialConditionType
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