Skip to content

Commit 2b5b82d

Browse files
committed
Refactor {get,has}MFEMObject() to avoid dealing w/ system names (idaholab#32781)
1 parent a5a619e commit 2b5b82d

18 files changed

Lines changed: 58 additions & 83 deletions

File tree

framework/include/base/TheWarehouse.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,13 @@ class TheWarehouse
490490
results.clear();
491491
results.reserve(objs.size());
492492
for (auto & obj : objs)
493-
{
494-
mooseAssert(obj, "Null object");
495-
auto cast_obj = dynamic_cast<T *>(obj);
496-
if (obj)
497-
mooseAssert(cast_obj,
498-
"Queried object " + obj->typeAndName() + " has incompatible c++ type with " +
499-
MooseUtils::prettyCppType<T>());
500-
mooseAssert(std::find(results.begin(), results.end(), cast_obj) == results.end(),
501-
"Duplicate object");
502-
if (show_all || obj->enabled())
503-
results.push_back(cast_obj);
504-
}
493+
if (auto cast_obj = dynamic_cast<T *>(obj))
494+
{
495+
mooseAssert(std::find(results.begin(), results.end(), cast_obj) == results.end(),
496+
"Duplicate object");
497+
if (show_all || obj->enabled())
498+
results.push_back(cast_obj);
499+
}
505500
return results;
506501
}
507502

framework/include/mfem/problem/MFEMProblem.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,16 @@ class MFEMProblem : public ExternalProblem
343343
}
344344

345345
/**
346-
* Retrieve an MFEM object from the warehouse by system and name.
346+
* Retrieve an MFEM object from the warehouse by type and name.
347347
*/
348348
template <typename T>
349-
T & getMFEMObject(const std::string & system,
350-
const std::string & name,
351-
const THREAD_ID tid = 0) const;
349+
T & getMFEMObject(const std::string & name, const THREAD_ID tid = 0) const;
352350

353351
/**
354-
* Determine whether an MFEM object with the supplied system and name exists.
352+
* Determine whether an MFEM object with the supplied type and name exists.
355353
*/
356-
bool hasMFEMObject(const std::string & system, const std::string & name) const;
354+
template <typename T>
355+
bool hasMFEMObject(const std::string & name, const THREAD_ID tid = 0) const;
357356

358357
/**
359358
* Enumerates the supported numeric representations for MFEM variables and operators.
@@ -378,21 +377,33 @@ class MFEMProblem : public ExternalProblem
378377

379378
template <typename T>
380379
T &
381-
MFEMProblem::getMFEMObject(const std::string & system,
382-
const std::string & name,
383-
const THREAD_ID tid) const
380+
MFEMProblem::getMFEMObject(const std::string & name, const THREAD_ID tid) const
384381
{
385382
std::vector<T *> objs;
386383
theWarehouse()
387384
.query()
388-
.condition<AttribSystem>(system)
385+
.condition<AttribSystem>("MFEMObject")
389386
.condition<AttribThread>(tid)
390387
.condition<AttribName>(name)
391388
.queryInto(objs);
392389
if (objs.empty())
393-
mooseError("Unable to find MFEM object with system '" + system + "' and name '" + name + "'");
390+
mooseError("No MFEM object '" + name + "' of type '" + MooseUtils::prettyCppType<T>() + "'");
394391
mooseAssert(objs.size() == 1, "Shouldn't find more than one object with given system and name");
395392
return *(objs[0]);
396393
}
397394

395+
template <typename T>
396+
bool
397+
MFEMProblem::hasMFEMObject(const std::string & name, const THREAD_ID tid) const
398+
{
399+
std::vector<T *> objs;
400+
theWarehouse()
401+
.query()
402+
.condition<AttribSystem>("MFEMObject")
403+
.condition<AttribThread>(tid)
404+
.condition<AttribName>(name)
405+
.queryInto(objs);
406+
return !objs.empty();
407+
}
408+
398409
#endif

framework/src/mfem/base/MFEMObject.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ MFEMObject::validParams()
2222
params += VectorPostprocessorInterface::validParams();
2323
params += ReporterInterface::validParams();
2424
params.addClassDescription("Base class for MFEM objects backed directly by MooseObject.");
25+
params.registerSystemAttributeName("MFEMObject");
2526
return params;
2627
}
2728

framework/src/mfem/bcs/MFEMBoundaryCondition.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ MFEMBoundaryCondition::validParams()
2323

2424
params.addClassDescription("Base class for applying boundary conditions to MFEM problems.");
2525
params.registerBase("BoundaryCondition");
26-
params.registerSystemAttributeName("BoundaryCondition");
2726
params.addParam<VariableName>("variable", "Variable on which to apply the boundary condition");
2827
return params;
2928
}

framework/src/mfem/fespaces/MFEMFESpace.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ MFEMFESpace::validParams()
1717
{
1818
InputParameters params = MFEMObject::validParams();
1919
params.registerBase("MFEMFESpace");
20-
params.registerSystemAttributeName("MFEMFESpace");
2120
MooseEnum ordering("NODES VDIM", "VDIM", false);
2221
params.addParam<MooseEnum>("ordering", ordering, "Ordering style to use for vector DoFs.");
2322
params.addParam<int>("vdim", 1, "The number of degrees of freedom per basis function.");

framework/src/mfem/functormaterials/MFEMFunctorMaterial.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ MFEMFunctorMaterial::validParams()
2222
params.addClassDescription(
2323
"Base class for declaration of material properties to add to MFEM problems.");
2424
params.registerBase("FunctorMaterial");
25-
params.registerSystemAttributeName("FunctorMaterial");
2625
params.addPrivateParam<bool>("_neighbor", false);
2726
params.addPrivateParam<bool>("_interface", false);
2827
return params;

framework/src/mfem/indicators/MFEMIndicator.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ MFEMIndicator::validParams()
1717
{
1818
InputParameters params = MFEMObject::validParams();
1919
params.registerBase("Indicator");
20-
params.registerSystemAttributeName("Indicator");
2120

2221
params.addRequiredParam<VariableName>("variable", "Variable to perform amr with");
2322
params.addRequiredParam<std::string>("kernel", "Kernel to perform amr with");

framework/src/mfem/indicators/MFEML2ZienkiewiczZhuIndicator.C

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,20 @@ MFEML2ZienkiewiczZhuIndicator::MFEML2ZienkiewiczZhuIndicator(const InputParamete
3131
if (isParamSetByUser("flux_fespace"))
3232
{
3333
// fetch the flux_fespace from the object system
34-
auto object_ptr =
35-
getMFEMProblem()
36-
.getMFEMObject<MFEMFESpace>("MFEMFESpace", getParam<MFEMFESpaceName>("flux_fespace"))
37-
.getSharedPtr();
34+
auto object_ptr = getMFEMProblem()
35+
.getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("flux_fespace"))
36+
.getSharedPtr();
3837
auto fespace_ptr = std::dynamic_pointer_cast<const MFEMFESpace>(object_ptr);
3938
_flux_fes = fespace_ptr->getFESpace();
4039
}
4140

4241
if (isParamSetByUser("smooth_flux_fespace"))
4342
{
4443
// fetch the smooth_flux_fespace from the object system
45-
auto object_ptr = getMFEMProblem()
46-
.getMFEMObject<MFEMFESpace>(
47-
"MFEMFESpace", getParam<MFEMFESpaceName>("smooth_flux_fespace"))
48-
.getSharedPtr();
44+
auto object_ptr =
45+
getMFEMProblem()
46+
.getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("smooth_flux_fespace"))
47+
.getSharedPtr();
4948
auto fespace_ptr = std::dynamic_pointer_cast<const MFEMFESpace>(object_ptr);
5049
_smooth_flux_fes = fespace_ptr->getFESpace();
5150
}
@@ -55,7 +54,7 @@ void
5554
MFEML2ZienkiewiczZhuIndicator::createEstimator()
5655
{
5756
// fetch the kernel first so we can build an auxiliary blf integrator
58-
MFEMKernel & kernel = getMFEMProblem().getMFEMObject<MFEMKernel>("Kernel", _kernel_name);
57+
MFEMKernel & kernel = getMFEMProblem().getMFEMObject<MFEMKernel>(_kernel_name);
5958
_integ = std::unique_ptr<mfem::BilinearFormIntegrator>(kernel.createBFIntegrator());
6059

6160
// Next, we need to check that this integrator is supported by mfem::L2ZienkiewiczZhuEstimator

framework/src/mfem/kernels/MFEMKernel.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ MFEMKernel::validParams()
2121
InputParameters params = MFEMObject::validParams();
2222
params += MFEMBlockRestrictable::validParams();
2323
params.registerBase("Kernel");
24-
params.registerSystemAttributeName("Kernel");
2524
params.addParam<VariableName>("variable",
2625
"Variable labelling the weak form this kernel is added to");
2726
return params;

framework/src/mfem/markers/MFEMRefinementMarker.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ MFEMRefinementMarker::validParams()
1919
{
2020
InputParameters params = MFEMObject::validParams();
2121
params.registerBase("Marker");
22-
params.registerSystemAttributeName("Marker");
2322

2423
params.addRequiredParam<std::string>("indicator", "Estimator to use");
2524
params.addRangeCheckedParam<Real>("threshold",
@@ -49,7 +48,7 @@ void
4948
MFEMRefinementMarker::initialSetup()
5049
{
5150
// fetch const ref to the estimator
52-
_estimator = &getMFEMProblem().getMFEMObject<MFEMIndicator>("Indicator", _estimator_name);
51+
_estimator = &getMFEMProblem().getMFEMObject<MFEMIndicator>(_estimator_name);
5352

5453
// Check if p-refinement is supported by the fespace supplied with the variable
5554
if (_max_p_level and !_estimator->getFESpace().PRefinementSupported())

0 commit comments

Comments
 (0)