10 #ifdef MOOSE_MFEM_ENABLED 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.");
59 const std::string & name,
67 const std::string & name,
82 nl_solver->SetRelTol(0.0);
83 nl_solver->SetAbsTol(0.0);
84 nl_solver->SetMaxIter(1);
91 const std::string & name,
96 if (dynamic_cast<const MFEMIntegratedBC *>(mfem_bc_uo) !=
nullptr)
107 "' because there is no corresponding equation system.");
110 else if (dynamic_cast<const MFEMEssentialBC *>(mfem_bc_uo) !=
nullptr)
121 "' because there is no corresponding equation system.");
126 mooseError(
"Unsupported bc of type '", bc_name,
"' and name '",
name,
"' detected.");
134 "MFEM materials must be added through the 'FunctorMaterials' block and not 'Materials'");
139 const std::string & name,
143 getUserObject<MFEMFunctorMaterial>(
name);
148 const std::string & name,
161 const std::string & var_name,
174 const std::string & var_name,
177 if (var_type ==
"MFEMVariable")
193 MFEMVariable & mfem_variable = getUserObject<MFEMVariable>(var_name);
205 const std::string & var_name,
215 const std::string & name,
223 const std::string & name,
229 if (dynamic_cast<const MFEMKernel *>(kernel_uo) !=
nullptr)
240 "' because there is no corresponding equation system.");
245 mooseError(
"Unsupported kernel of type '", kernel_name,
"' and name '",
name,
"' detected.");
253 vec.Elem(0), vec.Size() > 1 ? vec.Elem(1) : 0., vec.Size() > 2 ? vec.Elem(2) : 0.);
259 if (type ==
"LevelSetOlssonVortex")
263 else if (type ==
"ParsedVectorFunction")
284 const std::vector<std::string>
SCALAR_FUNCS = {
"Axisymmetric2D3DSolutionFunction",
285 "BicubicSplineFunction",
286 "CoarsenedPiecewiseLinear",
291 "ParsedGradFunction",
295 "PiecewiseConstantFromCSV",
297 "PiecewiseLinearFromVectorPostprocessor",
298 "PiecewiseMultiInterpolation",
299 "PiecewiseMulticonstant",
303 "LevelSetOlssonBubble",
304 "LevelSetOlssonPlane",
305 "NearestReporterCoordinatesFunction",
306 "ParameterMeshFunction",
307 "ParsedOptimizationFunction",
310 "MultiControlDrumFunction",
311 "Grad2ParsedFunction",
312 "GradParsedFunction",
314 "ScaledAbsDifferenceDRLRewardFunction",
315 "CircularAreaHydraulicDiameterFunction",
316 "CosineHumpFunction",
317 "CosineTransitionFunction",
318 "CubicTransitionFunction",
319 "GeneralizedCircumference",
326 const std::string & name,
337 [&func](
const mfem::Vector & p,
double t) -> mfem::real_t
346 [&func,
dim](
const mfem::Vector & p,
double t, mfem::Vector & u)
349 for (
int i = 0; i <
dim; i++)
351 u[i] = vector_value(i);
359 " is scalar or vector; no MFEM coefficient object created.");
365 const std::string & name,
372 name, [&val](
const mfem::Vector &, double) -> mfem::real_t {
return val; });
386 std::string mfem_family;
389 switch (moose_fe_type.family)
391 case FEFamily::LAGRANGE:
395 case FEFamily::LAGRANGE_VEC:
399 case FEFamily::MONOMIAL:
403 case FEFamily::MONOMIAL_VEC:
408 mooseError(
"Unable to set MFEM FESpace for MOOSE variable");
414 const std::string fespace_name = mfem_family +
"_" +
415 std::to_string(
mesh().getMFEMParMesh().Dimension()) +
"D_P" +
416 std::to_string(moose_fe_type.order.get_order());
419 fespace_params.
set<std::string>(
"fec_name") = fespace_name;
420 fespace_params.
set<
int>(
"vdim") = mfem_vdim;
424 addFESpace(
"MFEMGenericFESpace", fespace_name, fespace_params);
427 mfem_variable_params.
set<UserObjectName>(
"fespace") = fespace_name;
429 return mfem_variable_params;
436 if (
mesh().shouldDisplace())
443 std::optional<std::reference_wrapper<mfem::ParGridFunction const>>
448 if (displacement_variable)
458 std::vector<VariableName>
468 "Please choose the MFEMMesh mesh type for an MFEMProblem\n");
480 const std::string & var_name,
486 MFEMSubMesh & mfem_submesh = getUserObject<MFEMSubMesh>(var_name);
492 const std::string & name,
501 std::shared_ptr<mfem::ParGridFunction>
509 const std::string & name,
513 getUserObject<MFEMInitialCondition>(
name);
519 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.
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...
const InputParameters & parameters() const
Get the parameters of the object.
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.
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
Moose::MFEM::FESpaces fespaces
Moose::MFEM::SubMeshes submeshes
void addSubMesh(const std::string &user_object_name, const std::string &name, InputParameters ¶meters)
Add an MFEM SubMesh to the problem.
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.
const std::string & name() const
Get the name of the class.
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.
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
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)
MFEMMesh inherits a MOOSE mesh class which allows us to work with other MOOSE objects.
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.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
virtual MooseMesh & mesh() override
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
const std::vector< VariableName > & getVariableNames() const
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
Class to construct an MFEM integrator to apply to the equation system.
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