Use CellDataTransfer in MechanicalPhysics#477
Conversation
There was a problem hiding this comment.
Code Review
This pull request integrates mesh adaptation for cell data within the MechanicalPhysics class by utilizing the ClosestQuadPointAdaptation utility. Feedback highlights a critical logic error where the adaptation logic fails to account for multiple data components (e.g., stress and back stress) packed into the cell vectors, which could result in incorrect data transfer or crashes. Furthermore, suggestions were made to pass lambda parameters by constant reference to optimize performance during mesh refinement and coarsening.
87a817c to
2150267
Compare
| * Object used for interpolating to and from the closest quadrature point in | ||
| * the cell data transfer object. | ||
| */ | ||
| adamantine::ClosestQuadPointAdaptation<dim, dim, std::vector<double>> |
There was a problem hiding this comment.
| adamantine::ClosestQuadPointAdaptation<dim, dim, std::vector<double>> | |
| ClosestQuadPointAdaptation<dim, dim, std::vector<double>> |
Is this the last thing missing to support AMR? If yes, then we need a test for it. |
Any suggestions? We are already hitting this path in the thermoelastic integration test case but apparently the output hasn't changed. |
|
The thermoelastic integration tests do not refine the mesh ( |
|
Seeing For some reason we are losing degrees of freedoms when enabling more refinements until none after left. |
|
There is an option to coarsen the mesh: coarsen_after_beam but it should be false by default. |
|
The issue isn't that we are coarsening but that fewer and fewer cells are enabled for the mechanical part. Printing the cells on refinement and the number of DoFs for |
|
With diff --git a/application/adamantine.hh b/application/adamantine.hh
index 75782b0..d09cb8c 100644
--- a/application/adamantine.hh
+++ b/application/adamantine.hh
@@ -437,6 +437,7 @@ void refine_and_transfer(
#endif
// Execute the refinement
triangulation.execute_coarsening_and_refinement();
+ std::cout << "n_cells: " << triangulation.n_cells() << std::endl;
#ifdef ADAMANTINE_WITH_CALIPER
CALI_MARK_END("refine triangulation");
#endif
@@ -1186,6 +1187,7 @@ run(MPI_Comm const &communicator, boost::property_tree::ptree const &database,
const_cast<dealii::Triangulation<dim> &>(
thermal_physics->get_dof_handler().get_triangulation()));
triangulation.execute_coarsening_and_refinement();
+ std::cout << "n_cells: " << triangulation.n_cells() << std::endl;
#ifdef ADAMANTINE_WITH_CALIPER
CALI_MARK_END("refine triangulation");
#endif
@@ -2102,6 +2104,7 @@ run_ensemble(MPI_Comm const &global_communicator,
dof_handler.get_triangulation()));
triangulation.execute_coarsening_and_refinement();
+ std::cout << "n_cells: " << triangulation.n_cells() << std::endl;
#ifdef ADAMANTINE_WITH_CALIPER
CALI_MARK_END("refine triangulation");
#endif
diff --git a/source/MechanicalPhysics.cc b/source/MechanicalPhysics.cc
index 88c9943..bee7ffa 100644
--- a/source/MechanicalPhysics.cc
+++ b/source/MechanicalPhysics.cc
@@ -66,6 +66,8 @@ MechanicalPhysics<dim, n_materials, p_order, MaterialStates, MemorySpaceType>::
// material.
unsigned int n_active_cells =
_dof_handler.get_triangulation().n_active_cells();
+ unsigned int solid_cells = 0;
+ unsigned int liquid_cells = 0;
for (auto const &cell :
dealii::filter_iterators(_dof_handler.active_cell_iterators(),
dealii::IteratorFilters::LocallyOwnedCell()))
@@ -74,12 +76,15 @@ MechanicalPhysics<dim, n_materials, p_order, MaterialStates, MemorySpaceType>::
cell, MaterialStates::State::solid) > 0.99)
{
cell->set_active_fe_index(0);
+ ++solid_cells;
}
else
{
cell->set_active_fe_index(1);
+ ++liquid_cells;
}
}
+ std::cout << "active_cells: " << n_active_cells << " solid: " << solid_cells << " liquid: " << liquid_cells << std::endl;
// Create the mechanical operator
_mechanical_operator =
@@ -121,6 +126,7 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
_dof_handler.distribute_dofs(_fe_collection);
dealii::IndexSet locally_relevant_dofs =
dealii::DoFTools::extract_locally_relevant_dofs(_dof_handler);
+ std::cout << "Total DoFs: " << locally_relevant_dofs.size() << " Local DoFs: " << locally_relevant_dofs.n_elements() << std::endl;
dealii::IndexSet locally_owned_dofs = _dof_handler.locally_owned_dofs();
_affine_constraints.reinit(locally_owned_dofs, locally_relevant_dofs);
dealii::DoFTools::make_hanging_node_constraints(_dof_handler,
@@ -350,6 +356,11 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
}
}
+ unsigned int n_active_cells =
+ _dof_handler.get_triangulation().n_active_cells();
+ unsigned int solid_cells = 0;
+ unsigned int liquid_cells = 0;
+
// Now we can update the fe indices and the plastic variables.
for (auto const &cell : _dof_handler.active_cell_iterators())
{
@@ -387,7 +398,11 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
std::vector<dealii::SymmetricTensor<2, dim>>(n_quad_pts));
cell->set_active_fe_index(updated_fe_index);
- rebuild_matrix = true;
+ if (updated_fe_index == 0)
+ ++solid_cells;
+ else
+ ++liquid_cells;
+ rebuild_matrix = true;
}
}
else
@@ -399,6 +414,7 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
// The cell is liquid. We don't need to save the plastic variables.
cell->set_active_fe_index(1);
+ ++liquid_cells;
tmp_plastic_internal_variable.push_back(std::vector<double>(
n_quad_pts, std::numeric_limits<double>::signaling_NaN()));
tmp_stress.push_back(
@@ -419,6 +435,8 @@ void MechanicalPhysics<dim, n_materials, p_order, MaterialStates,
++cell_id;
}
+ std::cout << "active_cells: " << n_active_cells << " solid: " << solid_cells << " liquid: " << liquid_cells << std::endl;
+
// Check if we need to rebuild the matrix
rebuild_matrix =
dealii::Utilities::MPI::logical_or(rebuild_matrix,
diff --git a/source/ThermalPhysics.templates.hh b/source/ThermalPhysics.templates.hh
index ed64f85..9b5d8db 100644
--- a/source/ThermalPhysics.templates.hh
+++ b/source/ThermalPhysics.templates.hh
@@ -515,6 +515,7 @@ void ThermalPhysics<dim, n_materials, p_order, fe_degree, MaterialStates,
dealii::IndexSet locally_relevant_dofs =
dealii::DoFTools::extract_locally_relevant_dofs(_dof_handler);
dealii::IndexSet locally_owned_dofs = _dof_handler.locally_owned_dofs();
+ std::cout << "Thermal Total DoFs: " << locally_relevant_dofs.size() << " Local DoFs: " << locally_relevant_dofs.n_elements() << std::endl;
_affine_constraints.reinit(locally_owned_dofs, locally_relevant_dofs);
dealii::DoFTools::make_hanging_node_constraints(_dof_handler,
_affine_constraints);the output shows that more and more cells get liquified. |
b681fc1 to
180c24e
Compare
We might want to add another test case.