17 #include "libmesh/string_to_enum.h" 28 params.
addClassDescription(
"Problem type for building and solving finite element problem using" 29 " the MFEM finite element library.");
61 if (mfem_exec_ptr !=
nullptr)
67 mooseError(
"Executioner used that is not currently supported by MFEMProblem");
73 const std::string & name,
81 const std::string & name,
96 nl_solver->SetRelTol(0.0);
97 nl_solver->SetAbsTol(0.0);
98 nl_solver->SetMaxIter(1);
105 const std::string & name,
110 if (dynamic_cast<const MFEMIntegratedBC *>(mfem_bc_uo) !=
nullptr)
121 "' because there is no corresponding equation system.");
124 else if (dynamic_cast<const MFEMEssentialBC *>(mfem_bc_uo) !=
nullptr)
135 "' because there is no corresponding equation system.");
140 mooseError(
"Unsupported bc of type '", bc_name,
"' and name '",
name,
"' detected.");
148 "MFEM materials must be added through the 'FunctorMaterials' block and not 'Materials'");
153 const std::string & name,
157 getUserObject<MFEMFunctorMaterial>(
name);
162 const std::string & name,
175 const std::string & var_name,
190 const std::string & var_name,
193 if (var_type ==
"MFEMVariable")
209 MFEMVariable & mfem_variable = getUserObject<MFEMVariable>(var_name);
221 const std::string & var_name,
230 const std::string & name,
238 const std::string & name,
244 if (dynamic_cast<const MFEMKernel *>(kernel_uo) !=
nullptr)
255 "' because there is no corresponding equation system.");
260 mooseError(
"Unsupported kernel of type '", kernel_name,
"' and name '",
name,
"' detected.");
268 vec.Elem(0), vec.Size() > 1 ? vec.Elem(1) : 0., vec.Size() > 2 ? vec.Elem(2) : 0.);
274 if (type ==
"LevelSetOlssonVortex")
278 else if (type ==
"ParsedVectorFunction")
299 const std::vector<std::string>
SCALAR_FUNCS = {
"Axisymmetric2D3DSolutionFunction",
300 "BicubicSplineFunction",
301 "CoarsenedPiecewiseLinear",
306 "ParsedGradFunction",
310 "PiecewiseConstantFromCSV",
312 "PiecewiseLinearFromVectorPostprocessor",
313 "PiecewiseMultiInterpolation",
314 "PiecewiseMulticonstant",
318 "LevelSetOlssonBubble",
319 "LevelSetOlssonPlane",
320 "NearestReporterCoordinatesFunction",
321 "ParameterMeshFunction",
322 "ParsedOptimizationFunction",
325 "MultiControlDrumFunction",
326 "Grad2ParsedFunction",
327 "GradParsedFunction",
329 "ScaledAbsDifferenceDRLRewardFunction",
330 "CircularAreaHydraulicDiameterFunction",
331 "CosineHumpFunction",
332 "CosineTransitionFunction",
333 "CubicTransitionFunction",
334 "GeneralizedCircumference",
341 const std::string & name,
352 [&func](
const mfem::Vector & p,
double t) -> mfem::real_t
361 [&func,
dim](
const mfem::Vector & p,
double t, mfem::Vector & u)
364 for (
int i = 0; i <
dim; i++)
366 u[i] = vector_value(i);
374 " is scalar or vector; no MFEM coefficient object created.");
380 const std::string & name,
387 name, [&val](
const mfem::Vector &, double) -> mfem::real_t {
return val; });
401 std::string mfem_family;
404 switch (moose_fe_type.family)
406 case FEFamily::LAGRANGE:
410 case FEFamily::LAGRANGE_VEC:
414 case FEFamily::MONOMIAL:
418 case FEFamily::MONOMIAL_VEC:
423 mooseError(
"Unable to set MFEM FESpace for MOOSE variable");
429 const std::string fespace_name = mfem_family +
"_" +
430 std::to_string(
mesh().getMFEMParMesh().Dimension()) +
"D_P" +
431 std::to_string(moose_fe_type.order.get_order());
434 fespace_params.
set<std::string>(
"fec_name") = fespace_name;
435 fespace_params.
set<
int>(
"vdim") = mfem_vdim;
439 addFESpace(
"MFEMGenericFESpace", fespace_name, fespace_params);
442 mfem_variable_params.
set<UserObjectName>(
"fespace") = fespace_name;
444 return mfem_variable_params;
451 if (
mesh().shouldDisplace())
458 std::optional<std::reference_wrapper<mfem::ParGridFunction const>>
463 if (displacement_variable)
473 std::vector<VariableName>
483 "Please choose the MFEMMesh mesh type for an MFEMProblem\n");
495 const std::string & var_name,
501 MFEMSubMesh & mfem_submesh = getUserObject<MFEMSubMesh>(var_name);
507 const std::string & name,
510 if (
parameters.
get<std::string>(
"_moose_base") ==
"MFEMSubMeshTransfer")
516 std::shared_ptr<mfem::ParGridFunction>
524 const std::string & name,
528 getUserObject<MFEMInitialCondition>(
name);
534 mooseAssert(solver_sys_num == 0,
"No support for multi-system with MFEM right now");
std::shared_ptr< mfem::ParMesh > pmesh
void addGridFunction(const std::string &var_type, const std::string &var_name, InputParameters ¶meters)
Adds one MFEM GridFunction to be used in the MFEM solve.
void addMFEMPreconditioner(const std::string &user_object_name, const std::string &name, InputParameters ¶meters)
Method called in AddMFEMPreconditionerAction which will create the solver.
virtual void addTransfer(const std::string &transfer_name, const std::string &name, InputParameters ¶meters)
Add a Transfer to the problem.
Factory & _factory
The Factory for building objects.
virtual void constructProblemOperator()=0
Virtual method to construct the ProblemOperator. Call for default problems.
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
const std::vector< std::string > SCALAR_FUNCS
std::shared_ptr< mfem::ParGridFunction > getGridFunction(const std::string &name)
void addPostprocessor(const std::string &type, const std::string &name, InputParameters ¶meters) override
Override of ExternalProblem::addPostprocessor.
std::optional< std::reference_wrapper< std::string const > > getMeshDisplacementVariable() const
Returns an optional reference to displacement variable name.
void addFunction(const std::string &type, const std::string &name, InputParameters ¶meters) override
Override of ExternalProblem::addFunction.
InputParameters addMFEMFESpaceFromMOOSEVariable(InputParameters &moosevar_params)
Method used to get an mfem FEC depending on the variable family specified in the input file...
static InputParameters validParams()
virtual MFEMMesh & mesh() override
Overwritten mesh() method from base MooseMesh to retrieve the correct mesh type, in this case MFEMMes...
registerMooseObject("MooseApp", MFEMProblem)
void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶meters) override
Override of ExternalProblem::addVariable.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
static InputParameters validParams()
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
std::string solverTypeString(unsigned int solver_sys_num) override
Return solver type as a human readable string.
void initProblemOperator()
Initialise the required ProblemOperator used in the Executioner to solve the problem.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
std::shared_ptr< MooseObject > getSharedPtr()
Get another shared pointer to this object that has the same ownership group.
int vectorFunctionDim(const std::string &type, const InputParameters ¶meters)
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
void displaceMesh()
Displace the mesh, if mesh displacement is enabled.
MFEMProblemData _problem_data
virtual const std::string & name() const
Get the name of the class.
Moose::MFEM::FESpaces fespaces
Moose::MFEM::SubMeshes submeshes
void addSubMesh(const std::string &user_object_name, const std::string &name, InputParameters ¶meters)
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
std::string GetTimeDerivativeName(std::string name)
Constructs and stores an mfem::ParGridFunction object.
void addMFEMNonlinearSolver()
Add the nonlinear solver to the system.
Moose::MFEM::FECollections fecs
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
virtual void addPostprocessor(const std::string &pp_name, const std::string &name, InputParameters ¶meters)
std::shared_ptr< mfem::FiniteElementCollection > getFEC() const
Returns a shared pointer to the constructed fec.
virtual bool isScalar() const =0
mfem::Coefficient & declareScalar(const std::string &name, const std::string &existing_or_literal)
Declare an alias to an existing scalar coefficient or, if it does not exist, try interpreting the nam...
T * Get(const std::string &field_name) const
Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer...
Base class for construction of a mfem::ParSubMesh object.
mfem::VectorCoefficient & declareVector(const std::string &name, const std::string &existing_or_literal)
Declare an alias to an existing vector coefficientor or, if it does not exist, try interpreting the n...
virtual void addFunction(const std::string &type, const std::string &name, InputParameters ¶meters)
Real PostprocessorValue
various MOOSE typedefs
Moose::MFEM::CoefficientManager & getCoefficients()
Method to get the PropertyManager object for storing material properties and converting them to MFEM ...
void addMaterial(const std::string &material_name, const std::string &name, InputParameters ¶meters) override
virtual void initialSetup() override
const std::string & type() const
Get the type of this class.
void initialSetup() override
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void setMesh()
Set the mesh used by MFEM.
virtual const SystemBase & systemBaseAuxiliary() const override
Return the auxiliary system object as a base class reference.
void addMFEMSolver(const std::string &user_object_name, const std::string &name, InputParameters ¶meters)
Method called in AddMFEMSolverAction which will create the solver.
void addAuxKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters) override
Override of ExternalProblem::addAuxKernel.
MooseApp & _app
The MOOSE application this is associated with.
const MFEMFESpace & getFESpace() const
Returns a reference to the fespace used by the gridfunction.
std::shared_ptr< mfem::ParSubMesh > getSubMesh()
Returns a shared pointer to the constructed fespace.
std::shared_ptr< mfem::ParMesh > getMFEMParMeshPtr()
Copy a shared_ptr to the mfem::ParMesh object.
std::shared_ptr< mfem::ParGridFunction > getGridFunction() const
Returns a shared pointer to the constructed gridfunction.
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name, std::size_t t_index=0) const
Get a read-only reference to the value associated with a Postprocessor that exists.
std::shared_ptr< Moose::MFEM::EquationSystem > eqn_system
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Constructs and stores an mfem::ParFiniteElementSpace object.
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶ms)
Canonical method for adding a non-linear variable.
std::shared_ptr< mfem::NewtonSolver > nonlinear_solver
void addFESpace(const std::string &user_object_name, const std::string &name, InputParameters ¶meters)
Add an MFEM FESpace to the problem.
void Register(const std::string &field_name, FieldArgs &&... args)
Construct new field with name field_name and register.
MFEMProblem(const InputParameters ¶ms)
void displace(mfem::GridFunction const &displacement)
Displace the nodes of the mesh by the given displacement.
void addFunctorMaterial(const std::string &material_name, const std::string &name, InputParameters ¶meters) override
libMesh::Point pointFromMFEMVector(const mfem::Vector &vec)
virtual std::vector< VariableName > getAuxVariableNames()
Returns all the variable names from the auxiliary system base.
virtual std::vector< std::shared_ptr< UserObject > > addUserObject(const std::string &user_object_name, const std::string &name, InputParameters ¶meters)
void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters ¶meters) override
const std::vector< std::string > VECTOR_FUNCS
Base class for wrapping mfem::Solver-derived classes.
virtual MooseMesh & mesh() override
const std::vector< VariableName > & getVariableNames() const
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
std::shared_ptr< mfem::ParFiniteElementSpace > getFESpace() const
Returns a shared pointer to the constructed fespace.
void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters) override
Override of ExternalProblem::addKernel.
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
Get the user object by its name.
virtual bool isTransient() const override
std::optional< std::reference_wrapper< mfem::ParGridFunction const > > getMeshDisplacementGridFunction()
Returns optional reference to the displacement GridFunction to apply to nodes.
Moose::MFEM::GridFunctions gridfunctions
void addAuxVariable(const std::string &var_type, const std::string &var_name, InputParameters ¶meters) override
Override of ExternalProblem::addAuxVariable.
Base class for user-specific data.
std::shared_ptr< MFEMSolverBase > jacobian_solver
std::string prettyCppType(const std::string &cpp_type)
void addTransfer(const std::string &transfer_name, const std::string &name, InputParameters ¶meters) override
Add transfers between MultiApps and/or MFEM SubMeshes.
void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters ¶meters) override