Skip to content

Commit

Permalink
Use RedistributeProperties when needed
Browse files Browse the repository at this point in the history
This is enough to solve idaholab#4532 for me.  With these changes we should no
longer be automatically using workarounds instead.  I'll fix up the
regression tests where we were manually using workarounds too.
  • Loading branch information
roystgnr committed Apr 4, 2023
1 parent e098a26 commit 75cc63b
Showing 1 changed file with 58 additions and 25 deletions.
83 changes: 58 additions & 25 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
#include "BoundaryNodeIntegrityCheckThread.h"
#include "BoundaryElemIntegrityCheckThread.h"
#include "NodalBCBase.h"
#include "RedistributeProperties.h"

#include "libmesh/exodusII_io.h"
#include "libmesh/quadrature.h"
Expand Down Expand Up @@ -746,6 +747,53 @@ FEProblemBase::initialSetup()
}
}

// Set up stateful material property redistribution, if we suspect
// it may be necessary later.
#ifdef LIBMESH_ENABLE_AMR
if ((_adaptivity.isOn() || _num_grid_steps) &&
(_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
_neighbor_material_props.hasStatefulProperties()))
{
// Even on a serialized Mesh, we don't keep our material
// properties serialized, so we'll rely on the callback to
// redistribute() to redistribute properties at the same time
// libMesh is redistributing elements.
auto add_redistributer =
[this](MooseMesh & mesh, const std::string & redistributer_name, bool use_displaced_mesh)
{
InputParameters redistribute_params = RedistributeProperties::validParams();
redistribute_params.set<MooseApp *>("_moose_app") = &_app;
redistribute_params.set<std::string>("for_whom") = this->name();
redistribute_params.set<MooseMesh *>("mesh") = &mesh;
redistribute_params.set<Moose::RelationshipManagerType>("rm_type") =
Moose::RelationshipManagerType::GEOMETRIC;
redistribute_params.set<bool>("use_displaced_mesh") = use_displaced_mesh;

std::shared_ptr<RedistributeProperties> redistributer =
_factory.create<RedistributeProperties>(
"RedistributeProperties", redistributer_name, redistribute_params);

if (_material_props.hasStatefulProperties())
redistributer->addMaterialPropertyStorage(_material_data, _material_props);

if (_bnd_material_props.hasStatefulProperties())
redistributer->addMaterialPropertyStorage(_bnd_material_data, _bnd_material_props);

if (_neighbor_material_props.hasStatefulProperties())
redistributer->addMaterialPropertyStorage(_neighbor_material_data,
_neighbor_material_props);

mesh.getMesh().add_ghosting_functor(redistributer);
};

add_redistributer(_mesh, "mesh_property_redistributer", false);
if (_displaced_problem)
add_redistributer(_displaced_problem->mesh(), "displaced_mesh_property_redistributer", true);
}
#endif // LIBMESH_ENABLE_AMR

// Restart/recovery code

if (_app.isRecovering() && (_app.isUltimateMaster() || _force_restart))
{
if (_app.getRestartRecoverFileSuffix() == "cpa")
Expand Down Expand Up @@ -6945,13 +6993,14 @@ FEProblemBase::meshChangedHelper(bool intermediate_change)

reinitBecauseOfGhostingOrNewGeomObjects(/*mortar_changed=*/true);

// We need to create new storage for the new elements and copy stateful properties from the old
// elements.
// We need to create new storage for newly active elements, and copy
// stateful properties from the old elements.
if (_has_initialized_stateful &&
(_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties()))
{
// Prolong properties onto newly refined elements' children
{
ProjectMaterialProperties pmp(true,
ProjectMaterialProperties pmp(/* refine = */ true,
*this,
_material_data,
_bnd_material_data,
Expand All @@ -6968,11 +7017,13 @@ FEProblemBase::meshChangedHelper(bool intermediate_change)
{
_material_props.eraseProperty(elem);
_bnd_material_props.eraseProperty(elem);
_neighbor_material_props.eraseProperty(elem);
}
}

// Restrict properties onto newly coarsened elements
{
ProjectMaterialProperties pmp(false,
ProjectMaterialProperties pmp(/* refine = */ false,
*this,
_material_data,
_bnd_material_data,
Expand All @@ -6988,6 +7039,7 @@ FEProblemBase::meshChangedHelper(bool intermediate_change)
{
_material_props.eraseProperty(child);
_bnd_material_props.eraseProperty(child);
_neighbor_material_props.eraseProperty(child);
}
}
}
Expand Down Expand Up @@ -7045,27 +7097,8 @@ FEProblemBase::checkProblemIntegrity()
(_material_props.hasStatefulProperties() || _bnd_material_props.hasStatefulProperties() ||
_neighbor_material_props.hasStatefulProperties()))
{
_console << "Using EXPERIMENTAL Stateful Material Property projection with Adaptivity!\n";

if (n_processors() > 1)
{
if (_mesh.uniformRefineLevel() > 0 && _mesh.getMesh().skip_partitioning() == false)
mooseError("This simulation is using uniform refinement on the mesh, with stateful "
"properties and adaptivity. "
"You must skip partitioning to run this case:\nMesh/skip_partitioning=true");

_console << "\nWarning! Mesh re-partitioning is disabled while using stateful material "
"properties! This can lead to large load imbalances and degraded "
"performance!!\n\n";
_mesh.getMesh().skip_partitioning(true);

_mesh.errorIfDistributedMesh("StatefulMaterials + Adaptivity");

if (_displaced_problem)
_displaced_problem->mesh().getMesh().skip_partitioning(true);
}

_console << std::flush;
_console << "Using EXPERIMENTAL Stateful Material Property projection with Adaptivity!\n"
<< std::flush;
}
#endif

Expand Down

0 comments on commit 75cc63b

Please sign in to comment.