Skip to content

Commit 4ab301d

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

10 files changed

Lines changed: 47 additions & 60 deletions

File tree

framework/include/mfem/problem/MFEMProblem.h

Lines changed: 20 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,31 @@ 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)
389385
.condition<AttribThread>(tid)
390386
.condition<AttribName>(name)
391387
.queryInto(objs);
392388
if (objs.empty())
393-
mooseError("Unable to find MFEM object with system '" + system + "' and name '" + name + "'");
389+
mooseError("Unable to find MFEM object with name '" + name + "'");
394390
mooseAssert(objs.size() == 1, "Shouldn't find more than one object with given system and name");
395391
return *(objs[0]);
396392
}
397393

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

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/markers/MFEMRefinementMarker.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void
4949
MFEMRefinementMarker::initialSetup()
5050
{
5151
// fetch const ref to the estimator
52-
_estimator = &getMFEMProblem().getMFEMObject<MFEMIndicator>("Indicator", _estimator_name);
52+
_estimator = &getMFEMProblem().getMFEMObject<MFEMIndicator>(_estimator_name);
5353

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

framework/src/mfem/problem/MFEMProblem.C

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ MFEMProblem::addVariable(const std::string & var_type,
235235
if (isTransient())
236236
{
237237
const auto time_derivative_var_name =
238-
getMFEMObject<MFEMVariable>("MooseVariableBase", var_name).getTimeDerivativeName();
238+
getMFEMObject<MFEMVariable>(var_name).getTimeDerivativeName();
239239
getProblemData().time_derivative_map.addTimeDerivativeAssociation(var_name,
240240
time_derivative_var_name);
241241
addGridFunction(var_type, time_derivative_var_name, parameters);
@@ -269,8 +269,7 @@ MFEMProblem::addGridFunction(const std::string & var_type,
269269
// Register gridfunction.
270270
if (var_type == "MFEMComplexVariable")
271271
{
272-
MFEMComplexVariable & mfem_variable =
273-
getMFEMObject<MFEMComplexVariable>("MooseVariableBase", var_name);
272+
MFEMComplexVariable & mfem_variable = getMFEMObject<MFEMComplexVariable>(var_name);
274273
getProblemData().cmplx_gridfunctions.Register(var_name, mfem_variable.getComplexGridFunction());
275274
if (mfem_variable.getFESpace().isScalar())
276275
{
@@ -289,7 +288,7 @@ MFEMProblem::addGridFunction(const std::string & var_type,
289288
}
290289
else // must be real, but may have been set up indirectly from a MOOSE variable
291290
{
292-
MFEMVariable & mfem_variable = getMFEMObject<MFEMVariable>("MooseVariableBase", var_name);
291+
MFEMVariable & mfem_variable = getMFEMObject<MFEMVariable>(var_name);
293292
getProblemData().gridfunctions.Register(var_name, mfem_variable.getGridFunction());
294293
if (mfem_variable.getFESpace().isScalar())
295294
getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
@@ -355,7 +354,7 @@ MFEMProblem::addRealComponentToKernel(const std::string & kernel_name,
355354
InputParameters & parameters)
356355
{
357356
auto parent_ptr = std::dynamic_pointer_cast<MFEMComplexKernel>(
358-
getMFEMObject<MFEMComplexKernel>("Kernel", name).getSharedPtr());
357+
getMFEMObject<MFEMComplexKernel>(name).getSharedPtr());
359358
parameters.set<VariableName>("variable") = parent_ptr->getParam<VariableName>("variable");
360359
auto kernel_ptr = addObject<MFEMKernel>(kernel_name, name + "_real", parameters).front();
361360
parent_ptr->setRealKernel(kernel_ptr);
@@ -367,7 +366,7 @@ MFEMProblem::addImagComponentToKernel(const std::string & kernel_name,
367366
InputParameters & parameters)
368367
{
369368
auto parent_ptr = std::dynamic_pointer_cast<MFEMComplexKernel>(
370-
getMFEMObject<MFEMComplexKernel>("Kernel", name).getSharedPtr());
369+
getMFEMObject<MFEMComplexKernel>(name).getSharedPtr());
371370
parameters.set<VariableName>("variable") = parent_ptr->getParam<VariableName>("variable");
372371
auto kernel_ptr = addObject<MFEMKernel>(kernel_name, name + "_imag", parameters).front();
373372
parent_ptr->setImagKernel(kernel_ptr);
@@ -379,7 +378,7 @@ MFEMProblem::addRealComponentToBC(const std::string & kernel_name,
379378
InputParameters & parameters)
380379
{
381380
auto parent_ptr = std::dynamic_pointer_cast<MFEMComplexIntegratedBC>(
382-
getMFEMObject<MFEMComplexIntegratedBC>("BoundaryCondition", name).getSharedPtr());
381+
getMFEMObject<MFEMComplexIntegratedBC>(name).getSharedPtr());
383382
parameters.set<VariableName>("variable") = parent_ptr->getParam<VariableName>("variable");
384383
parameters.set<std::vector<BoundaryName>>("boundary") =
385384
parent_ptr->getParam<std::vector<BoundaryName>>("boundary");
@@ -394,7 +393,7 @@ MFEMProblem::addImagComponentToBC(const std::string & kernel_name,
394393
InputParameters & parameters)
395394
{
396395
auto parent_ptr = std::dynamic_pointer_cast<MFEMComplexIntegratedBC>(
397-
getMFEMObject<MFEMComplexIntegratedBC>("BoundaryCondition", name).getSharedPtr());
396+
getMFEMObject<MFEMComplexIntegratedBC>(name).getSharedPtr());
398397
parameters.set<VariableName>("variable") = parent_ptr->getParam<VariableName>("variable");
399398
parameters.set<std::vector<BoundaryName>>("boundary") =
400399
parent_ptr->getParam<std::vector<BoundaryName>>("boundary");
@@ -594,10 +593,8 @@ MFEMProblem::addMFEMFESpaceFromMOOSEVariable(InputParameters & parameters)
594593
fespace_params.set<std::string>("fec_name") = fespace_name;
595594
fespace_params.set<int>("vdim") = mfem_vdim;
596595

597-
if (!hasMFEMObject("MFEMFESpace", fespace_name)) // Create the fespace (implicit).
598-
{
596+
if (!hasMFEMObject<MFEMFESpace>(fespace_name)) // Create the fespace (implicit).
599597
addFESpace("MFEMGenericFESpace", fespace_name, fespace_params);
600-
}
601598

602599
mfem_variable_params.set<MFEMFESpaceName>("fespace") = fespace_name;
603600

@@ -756,17 +753,4 @@ MFEMProblem::solverTypeString(const unsigned int libmesh_dbg_var(solver_sys_num)
756753
return MooseUtils::prettyCppType(getProblemData().jacobian_solver.get());
757754
}
758755

759-
bool
760-
MFEMProblem::hasMFEMObject(const std::string & system, const std::string & name) const
761-
{
762-
std::vector<MooseObject *> objs;
763-
theWarehouse()
764-
.query()
765-
.condition<AttribSystem>(system)
766-
.condition<AttribThread>(0)
767-
.condition<AttribName>(name)
768-
.queryInto(objs);
769-
return !objs.empty();
770-
}
771-
772756
#endif

framework/src/mfem/solvers/MFEMHypreADS.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ MFEMHypreADS::validParams()
2828

2929
MFEMHypreADS::MFEMHypreADS(const InputParameters & parameters)
3030
: MFEMSolverBase(parameters),
31-
_mfem_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
32-
getParam<MFEMFESpaceName>("fespace")))
31+
_mfem_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("fespace")))
3332
{
3433
constructSolver();
3534
}

framework/src/mfem/solvers/MFEMHypreAMS.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ MFEMHypreAMS::validParams()
3232

3333
MFEMHypreAMS::MFEMHypreAMS(const InputParameters & parameters)
3434
: MFEMSolverBase(parameters),
35-
_mfem_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
36-
getParam<MFEMFESpaceName>("fespace")))
35+
_mfem_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("fespace")))
3736
{
3837
constructSolver();
3938
}

framework/src/mfem/solvers/MFEMHypreBoomerAMG.C

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ MFEMHypreBoomerAMG::validParams()
3535

3636
MFEMHypreBoomerAMG::MFEMHypreBoomerAMG(const InputParameters & parameters)
3737
: MFEMSolverBase(parameters),
38-
_mfem_fespace(
39-
isParamSetByUser("fespace")
40-
? getMFEMProblem()
41-
.getMFEMObject<MFEMFESpace>("MFEMFESpace", getParam<MFEMFESpaceName>("fespace"))
42-
.getFESpace()
43-
: nullptr)
38+
_mfem_fespace(isParamSetByUser("fespace")
39+
? getMFEMProblem()
40+
.getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("fespace"))
41+
.getFESpace()
42+
: nullptr)
4443
{
4544
constructSolver();
4645
}

framework/src/mfem/solvers/MFEMSolverBase.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ MFEMSolverBase::setPreconditioner(T & solver)
4141
if (!_preconditioner)
4242
_preconditioner =
4343
&const_cast<MFEMSolverBase &>(getMFEMProblem().getMFEMObject<MFEMSolverBase>(
44-
"MFEMSolverBase", getParam<MFEMSolverName>("preconditioner")));
44+
getParam<MFEMSolverName>("preconditioner")));
4545

4646
auto & mfem_pre = _preconditioner->getSolver();
4747
if constexpr (std::is_base_of_v<mfem::HypreSolver, T>)

framework/src/mfem/variables/MFEMComplexVariable.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ MFEMComplexVariable::validParams()
2424

2525
MFEMComplexVariable::MFEMComplexVariable(const InputParameters & parameters)
2626
: MFEMObject(parameters),
27-
_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
28-
getParam<MFEMFESpaceName>("fespace"))),
27+
_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("fespace"))),
2928
_cmplx_gridfunction(buildComplexGridFunction())
3029
{
3130
*_cmplx_gridfunction = 0.0;

framework/src/mfem/variables/MFEMVariable.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ MFEMVariable::validParams()
3636

3737
MFEMVariable::MFEMVariable(const InputParameters & parameters)
3838
: MFEMObject(parameters),
39-
_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
40-
getParam<MFEMFESpaceName>("fespace"))),
39+
_fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>(getParam<MFEMFESpaceName>("fespace"))),
4140
_gridfunction(buildGridFunction()),
4241
_time_derivative_name(
4342
isParamValid("time_derivative")

0 commit comments

Comments
 (0)