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.");
61 const std::string & name,
69 const std::string & name,
81 auto nl_solver = std::make_shared<mfem::NewtonSolver>(
getComm());
84 nl_solver->SetRelTol(0.0);
85 nl_solver->SetAbsTol(0.0);
86 nl_solver->SetMaxIter(1);
93 const std::string & name,
98 if (dynamic_cast<const MFEMIntegratedBC *>(mfem_bc_uo) !=
nullptr)
109 "' because there is no corresponding equation system.");
112 else if (dynamic_cast<const MFEMEssentialBC *>(mfem_bc_uo) !=
nullptr)
123 "' because there is no corresponding equation system.");
128 mooseError(
"Unsupported bc of type '", bc_name,
"' and name '",
name,
"' detected.");
136 "MFEM materials must be added through the 'FunctorMaterials' block and not 'Materials'");
141 const std::string & name,
145 getUserObject<MFEMFunctorMaterial>(
name);
150 const std::string & name,
163 const std::string & var_name,
172 const auto time_derivative_var_name =
173 getUserObject<MFEMVariable>(var_name).getTimeDerivativeName();
175 time_derivative_var_name);
182 const std::string & var_name,
185 if (var_type ==
"MFEMVariable")
201 MFEMVariable & mfem_variable = getUserObject<MFEMVariable>(var_name);
213 const std::string & var_name,
223 const std::string & name,
231 const std::string & name,
237 if (dynamic_cast<const MFEMKernel *>(kernel_uo) !=
nullptr)
248 "' because there is no corresponding equation system.");
253 mooseError(
"Unsupported kernel of type '", kernel_name,
"' and name '",
name,
"' detected.");
261 vec.Elem(0), vec.Size() > 1 ? vec.Elem(1) : 0., vec.Size() > 2 ? vec.Elem(2) : 0.);
267 if (type ==
"LevelSetOlssonVortex")
271 else if (type ==
"ParsedVectorFunction")
292 const std::vector<std::string>
SCALAR_FUNCS = {
"Axisymmetric2D3DSolutionFunction",
293 "BicubicSplineFunction",
294 "CoarsenedPiecewiseLinear",
299 "ParsedGradFunction",
303 "PiecewiseConstantFromCSV",
305 "PiecewiseLinearFromVectorPostprocessor",
306 "PiecewiseMultiInterpolation",
307 "PiecewiseMulticonstant",
311 "LevelSetOlssonBubble",
312 "LevelSetOlssonPlane",
313 "NearestReporterCoordinatesFunction",
314 "ParameterMeshFunction",
315 "ParsedOptimizationFunction",
318 "MultiControlDrumFunction",
319 "Grad2ParsedFunction",
320 "GradParsedFunction",
322 "ScaledAbsDifferenceDRLRewardFunction",
323 "CircularAreaHydraulicDiameterFunction",
324 "CosineHumpFunction",
325 "CosineTransitionFunction",
326 "CubicTransitionFunction",
327 "GeneralizedCircumference",
334 const std::string & name,
345 [&func](
const mfem::Vector & p, mfem::real_t t) -> mfem::real_t
354 [&func,
dim](
const mfem::Vector & p, mfem::real_t t, mfem::Vector & u)
357 for (
int i = 0; i <
dim; i++)
359 u[i] = vector_value(i);
363 else if (
"MFEMParsedFunction" !=
type)
367 " is scalar or vector; no MFEM coefficient object created.");
373 const std::string & name,
379 name, [&val](
const mfem::Vector &) -> mfem::real_t {
return val; });
393 std::string mfem_family;
396 switch (moose_fe_type.family)
398 case FEFamily::LAGRANGE:
402 case FEFamily::LAGRANGE_VEC:
406 case FEFamily::MONOMIAL:
410 case FEFamily::MONOMIAL_VEC:
415 mooseError(
"Unable to set MFEM FESpace for MOOSE variable");
421 const std::string fespace_name = mfem_family +
"_" +
422 std::to_string(
mesh().getMFEMParMesh().Dimension()) +
"D_P" +
423 std::to_string(moose_fe_type.order.get_order());
426 fespace_params.
set<std::string>(
"fec_name") = fespace_name;
427 fespace_params.
set<
int>(
"vdim") = mfem_vdim;
431 addFESpace(
"MFEMGenericFESpace", fespace_name, fespace_params);
434 mfem_variable_params.
set<UserObjectName>(
"fespace") = fespace_name;
436 return mfem_variable_params;
443 if (
mesh().shouldDisplace())
450 std::optional<std::reference_wrapper<mfem::ParGridFunction const>>
455 if (displacement_variable)
465 std::vector<VariableName>
475 "Please choose the MFEMMesh mesh type for an MFEMProblem\n");
487 const std::string & var_name,
493 MFEMSubMesh & mfem_submesh = getUserObject<MFEMSubMesh>(var_name);
499 const std::string & name,
508 std::shared_ptr<mfem::ParGridFunction>
516 const std::string & name,
520 getUserObject<MFEMInitialCondition>(
name);
526 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.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
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.
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)
void mooseWarning(Args &&... args) const
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...
void addTimeDerivativeAssociation(const std::string &var_name, const std::string &time_derivative_var_name)
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.
MPI_Comm getComm()
Return the MPI communicator associated with this FE problem's mesh.
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.
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.
Moose::MFEM::TimeDerivativeMap time_derivative_map
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