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"
15
17
20{
22 params.addClassDescription("Problem type for building and solving a finite element eigenproblem "
23 "using the MFEM finite element library.");
24 params.addParam<int>("num_modes", 1, "Set the number of lowest eigenmodes to compute.");
25 params.addParam<std::string>(
26 "mode_separator",
27 "_",
28 "Separator string inserted between a variable name and its eigenmode index when "
29 "registering the gridfunction that stores the corresponding eigenvector.");
30 params.addParam<MFEMScalarCoefficientName>(
31 "rhs_coefficient",
32 "1.",
33 "Name of the coefficient to scale the right-hand side of the eigenproblem equation by.");
34 params.addParam<MFEMMatrixCoefficientName>("rhs_matrix_coefficient",
35 "Name of the matrix coefficient to scale the "
36 "right-hand side of the eigenproblem equation by.");
37
38 return params;
39}
40
42{
43 getProblemData().mode_separator = getParam<std::string>("mode_separator");
45 mooseError("Complex numbers are not currently supported for eigenproblems.");
46
47 if (isParamSetByUser("rhs_matrix_coefficient") && isParamSetByUser("rhs_coefficient"))
48 paramError("rhs_coefficient",
49 "Only one of 'rhs_coefficient' and 'rhs_matrix_coefficient' may be set to a "
50 "non-default value.");
51}
52
55{
56 if (isParamSetByUser("rhs_matrix_coefficient"))
58 getParam<MFEMMatrixCoefficientName>("rhs_matrix_coefficient"));
60 getParam<MFEMScalarCoefficientName>("rhs_coefficient"));
61}
62
63void
64MFEMEigenproblem::addVariable(const std::string & var_type,
65 const std::string & var_name,
66 InputParameters & parameters)
67{
68 validateVariableNumericType(var_type, var_name);
69
70 // Reject names that would collide with the mode-suffix convention or with any
71 // already-registered eigenmode storage entry.
72 const auto num_modes = getParam<int>("num_modes");
73 const auto & sep = getProblemData().mode_separator;
74 if (getProblemData().gridfunctions.Has(var_name))
75 mooseError("MFEM variable '",
76 var_name,
77 "' clashes with an existing gridfunction (likely an eigenmode entry from another "
78 "variable). Choose a different variable name or set 'mode_separator' to a string "
79 "that avoids the clash.");
80
81 for (int i = 0; i < num_modes; ++i)
82 {
83 const auto mode_name = var_name + sep + std::to_string(i);
84 if (getProblemData().gridfunctions.Has(mode_name))
85 mooseError("Eigenmode storage name '",
86 mode_name,
87 "' for variable '",
88 var_name,
89 "' clashes with an already-registered variable. Set 'mode_separator' to a "
90 "string that avoids the clash, or rename the conflicting variable.");
91 }
92
93 addGridFunction(var_type, var_name, parameters);
94
95 for (int i = 0; i < num_modes; ++i)
96 addGridFunction(var_type, var_name + sep + std::to_string(i), parameters);
97}
98
99void
101{
103
104 if (getProblemData().nonlinear_solver)
105 mooseError("MFEMEigenproblem does not support nonlinear solver '",
106 getProblemData().nonlinear_solver->name(),
107 "'.");
108
109 if (getProblemData().jacobian_solver &&
110 !std::dynamic_pointer_cast<Moose::MFEM::EigensolverBase>(getProblemData().jacobian_solver))
111 mooseError("The selected solver '",
112 getProblemData().jacobian_solver->name(),
113 "' is not an eigensolver, but the problem is marked as an eigenproblem.");
114}
115
116#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
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).
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)
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:60
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 ...
std::variant< mfem::Coefficient *, mfem::MatrixCoefficient * > EigenRHSCoefficient
Scalar or matrix coefficient scaling the eigenproblem right-hand side.
std::string mode_separator