https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMEigenproblem.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 "MFEMEigenproblem.h"
13#include "MFEMVariable.h"
14#include "MFEMEigensolverBase.h"
16
18
21{
23 params.addClassDescription("Problem type for building and solving a finite element eigenproblem "
24 "using the MFEM finite element library.");
25 params.addParam<int>("num_modes", 1, "Set the number of lowest eigenmodes to compute.");
26 params.addParam<std::string>(
27 "mode_separator",
28 "_",
29 "Separator string inserted between a variable name and its eigenmode index when "
30 "registering the gridfunction that stores the corresponding eigenvector.");
31 params.addParam<MFEMScalarCoefficientName>(
32 "rhs_coefficient",
33 "1.",
34 "Name of the coefficient to scale the right-hand side of the eigenproblem equation by.");
35 params.addParam<MFEMMatrixCoefficientName>("rhs_matrix_coefficient",
36 "Name of the matrix coefficient to scale the "
37 "right-hand side of the eigenproblem equation by.");
38
39 return params;
40}
41
43{
44 getProblemData().mode_separator = getParam<std::string>("mode_separator");
46 mooseError("Complex numbers are not currently supported for eigenproblems.");
47
48 if (isParamSetByUser("rhs_matrix_coefficient") && isParamSetByUser("rhs_coefficient"))
49 paramError("rhs_coefficient",
50 "Only one of 'rhs_coefficient' and 'rhs_matrix_coefficient' may be set to a "
51 "non-default value.");
52}
53
56{
57 if (isParamSetByUser("rhs_matrix_coefficient"))
59 getParam<MFEMMatrixCoefficientName>("rhs_matrix_coefficient"));
61 getParam<MFEMScalarCoefficientName>("rhs_coefficient"));
62}
63
64void
65MFEMEigenproblem::addVariable(const std::string & var_type,
66 const std::string & var_name,
67 InputParameters & parameters)
68{
69 validateVariableNumericType(var_type, var_name);
70
71 // Reject names that would collide with the mode-suffix convention or with any
72 // already-registered eigenmode storage entry.
73 const auto num_modes = getParam<int>("num_modes");
74 const auto & sep = getProblemData().mode_separator;
75 if (getProblemData().gridfunctions.Has(var_name))
76 mooseError("MFEM variable '",
77 var_name,
78 "' clashes with an existing gridfunction (likely an eigenmode entry from another "
79 "variable). Choose a different variable name or set 'mode_separator' to a string "
80 "that avoids the clash.");
81
82 for (int i = 0; i < num_modes; ++i)
83 {
84 const auto mode_name = var_name + sep + std::to_string(i);
85 if (getProblemData().gridfunctions.Has(mode_name))
86 mooseError("Eigenmode storage name '",
87 mode_name,
88 "' for variable '",
89 var_name,
90 "' clashes with an already-registered variable. Set 'mode_separator' to a "
91 "string that avoids the clash, or rename the conflicting variable.");
92 }
93
94 addGridFunction(var_type, var_name, parameters);
95
96 for (int i = 0; i < num_modes; ++i)
97 addGridFunction(var_type, var_name + sep + std::to_string(i), parameters);
98}
99
100void
102{
104
105 if (getProblemData().nonlinear_solver)
106 mooseError("MFEMEigenproblem does not support nonlinear solver '",
107 getProblemData().nonlinear_solver->name(),
108 "'.");
109
110 if (getProblemData().jacobian_solver &&
111 !std::dynamic_pointer_cast<Moose::MFEM::EigensolverBase>(getProblemData().jacobian_solver))
112 mooseError("The selected solver '",
113 getProblemData().jacobian_solver->name(),
114 "' is not an eigensolver, but the problem is marked as an eigenproblem.");
115}
116
117std::shared_ptr<MFEMWeakFormBase>
119{
121 mooseError("Complex MFEM eigenproblems are not currently supported. Please set the Problem "
122 "numeric type to 'real'.");
123
124 InputParameters parameters = _factory.getValidParams("MFEMEigenproblemWeakForm");
125 return addObject<MFEMWeakFormBase>("MFEMEigenproblemWeakForm", "__DefaultWeakForm", parameters)
126 .front();
127}
128
129std::shared_ptr<MFEMProblemComposer>
131{
132 InputParameters params = _factory.getValidParams("MFEMEigenWeakFormProblemComposer");
133 return addObject<MFEMProblemComposer>(
134 "MFEMEigenWeakFormProblemComposer", "__DefaultWeakFormProblemComposer", params)
135 .front();
136}
137
138#endif
registerMooseObject("MooseApp", MFEMEigenproblem)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
virtual void resolveMFEMSolvers() override
Construct recorded MFEM solvers in dependency order and select the problem driver solver(s).
virtual std::shared_ptr< MFEMProblemComposer > addDefaultProblemComposer() override
Add default problem composer if none has been added by the user.
static InputParameters validParams()
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters) override
Override of MFEMProblem::addVariable.
Moose::MFEM::EigenRHSCoefficient getRHSCoefficient()
Returns the coefficient used to scale the right-hand side of the eigenproblem equation.
MFEMEigenproblem(const InputParameters &params)
virtual std::shared_ptr< MFEMWeakFormBase > addDefaultWeakForm() override
Add default weak form if none has been added by the user.
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.
void validateVariableNumericType(const std::string &var_type, const std::string &var_name) const
Verify that a primary variable's numeric type matches the problem's equation system.
static InputParameters validParams()
Return the input parameters used to construct an MFEM problem.
Definition MFEMProblem.C:62
NumericType getNumericType() const
Retrieve the numeric type of the problem.
void addGridFunction(const std::string &var_type, const std::string &var_name, InputParameters &parameters)
Adds one MFEM GridFunction to be used in the MFEM solve.
NumericType _num_type
The numeric representation currently active for this problem.
virtual void resolveMFEMSolvers()
Construct recorded MFEM solvers in dependency order and select the problem driver solver(s).
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
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
mfem::MatrixCoefficient & getMatrixCoefficient(const std::string &name)
Return scalar coefficient with the given name.
mfem::Coefficient & getScalarCoefficient(const std::string &name)
Return a scalar coefficient with the given name or, if that doesn't exist, try interpreting the name ...
Factory & _factory
The Factory for building objects.
std::variant< mfem::Coefficient *, mfem::MatrixCoefficient * > EigenRHSCoefficient
Scalar or matrix coefficient scaling the eigenproblem right-hand side.
std::string mode_separator