https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMVariable.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
12#include "MFEMVariable.h"
13#include "MFEMProblem.h"
14#include "MFEMFESpace.h"
16#include "MooseVariableBase.h"
18
20
23{
25 // Create user-facing 'boundary' input for restricting inheriting object to boundaries.
26 params.addParam<MFEMFESpaceName>("fespace",
27 "The finite element space this variable is defined on.");
28 params.addParam<std::string>(
29 "fespace_hierarchy",
30 "Name of a MFEMFESpaceHierarchy the variable lives on its finest level. "
31 "Mutually exclusive with 'fespace'.");
32 // Require moose variable parameters (not used!)
35 "Class for adding MFEM variables to the problem (`mfem::ParGridFunction`s).");
36 params.registerBase("MooseVariableBase");
37 params.registerSystemAttributeName("MooseVariableBase");
38 params.addParam<VariableName>(
39 "time_derivative",
40 "Optional name to assign to the time derivative of the variable in transient problems.");
41 return params;
42}
43
45 : MFEMObject(parameters),
46 _time_derivative_name(
47 isParamValid("time_derivative")
48 ? getParam<VariableName>("time_derivative")
49 : VariableName(
50 getMFEMProblem().getProblemData().time_derivative_map.createTimeDerivativeName(
51 name())))
52{
53 const bool has_fespace = isParamSetByUser("fespace");
54 const bool has_hierarchy = isParamSetByUser("fespace_hierarchy");
55
56 if (has_fespace && has_hierarchy)
57 paramError("fespace_hierarchy", "Cannot specify both 'fespace' and 'fespace_hierarchy'.");
58 if (!has_fespace && !has_hierarchy)
59 paramError("fespace", "Either 'fespace' or 'fespace_hierarchy' must be provided.");
60
61 if (has_fespace)
62 {
63 const auto & fespace = getMFEMProblem().getMFEMObject<MFEMFESpace>(
64 "MFEMFESpace", getParam<MFEMFESpaceName>("fespace"));
65 _par_fespace = fespace.getFESpace();
66 _is_scalar = fespace.isScalar();
67 }
68 else
69 {
70 const auto & hierarchy_name = getParam<std::string>("fespace_hierarchy");
71 const auto & hierarchy = getMFEMProblem().getMFEMObject<MFEMFESpaceHierarchy>(
72 "MFEMFESpaceHierarchy", hierarchy_name);
74 _is_scalar = hierarchy.isScalar();
75 }
76
78 *_gridfunction = 0.0;
79}
80
81const std::shared_ptr<mfem::ParGridFunction>
83{
84 return std::make_shared<mfem::ParGridFunction>(_par_fespace.get());
85}
86
87void
89{
90 const int cont_type = _par_fespace->FEColl()->GetContType();
91 if (_is_scalar)
92 {
93 getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
94 name(), getGridFunction().get());
95 // If gradient is well-defined on this variable, create auxiliary coefficient
96 if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
97 {
98 getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
99 name() + "_grad", getGridFunction().get());
101 name() + "_grad_mag",
103 }
104 }
105 else
106 {
107 getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
108 name(), getGridFunction().get());
111 // If curl is well-defined on this variable, create auxiliary coefficient
112 if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
113 cont_type == mfem::FiniteElementCollection::CONTINUOUS)
114 {
115 getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
116 name() + "_curl", getGridFunction().get());
118 name() + "_curl_mag",
120 }
121 // If divergence is well-defined on this variable, create auxiliary coefficient
122 if (cont_type == mfem::FiniteElementCollection::NORMAL ||
123 cont_type == mfem::FiniteElementCollection::CONTINUOUS)
124 getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
125 name() + "_div", getGridFunction().get());
126 }
127}
128
129#endif
registerMooseObject("MooseApp", MFEMVariable)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Builds and owns a mfem::ParFiniteElementSpaceHierarchy from a base FESpace by applying a sequence of ...
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition MFEMFESpace.h:21
std::shared_ptr< mfem::ParFiniteElementSpace > getFESpace() const
Returns a shared pointer to the constructed fespace.
Definition MFEMFESpace.h:36
Thin base for MFEM objects backed directly by MooseObject instead of UserObject.
Definition MFEMObject.h:30
static InputParameters validParams()
Declare the common parameters required by MFEM MooseObject-backed classes.
Definition MFEMObject.C:17
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
Moose::MFEM::CoefficientManager & getCoefficients()
Method to get the PropertyManager object for storing material properties and converting them to MFEM ...
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem.
T & getMFEMObject(const std::string &system, const std::string &name, const THREAD_ID tid=0) const
Retrieve an MFEM object from the warehouse by system and name.
Constructs and stores an mfem::ParGridFunction object.
std::shared_ptr< mfem::ParGridFunction > _gridfunction
Stores the constructed gridfunction.
const std::shared_ptr< mfem::ParGridFunction > buildGridFunction()
Constructs the gridfunction.
std::shared_ptr< mfem::ParFiniteElementSpace > _par_fespace
The underlying MFEM FESpace - always populated regardless of which parameter was used.
std::shared_ptr< mfem::ParGridFunction > getGridFunction() const
Returns a shared pointer to the constructed gridfunction.
void declareCoefficients()
Declare default coefficients associated with this gridfunction.
MFEMVariable(const InputParameters &parameters)
static InputParameters validParams()
Scalar coefficient that evaluates the magnitude of a vector coefficient.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
Definition MooseBase.h:205
static InputParameters validParams()
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...
mfem::VectorCoefficient & getVectorCoefficient(const std::string &name)
Return a vector coefficient with the given name or, if that doesn't exists, try interpreting the name...
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...
std::shared_ptr< T > GetShared(const std::string &field_name) const
Returns a shared pointer to the field. This is guaranteed to return a non-null shared pointer.
Moose::MFEM::FESpaces fespaces