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
31 return params;
32}
33
35{
36 getProblemData().mode_separator = getParam<std::string>("mode_separator");
38 mooseError("Complex numbers are not currently supported for eigenproblems.");
39}
40
41void
42MFEMEigenproblem::addVariable(const std::string & var_type,
43 const std::string & var_name,
44 InputParameters & parameters)
45{
46 validateVariableNumericType(var_type, var_name);
47
48 // Reject names that would collide with the mode-suffix convention or with any
49 // already-registered eigenmode storage entry.
50 const auto num_modes = getParam<int>("num_modes");
51 const auto & sep = getProblemData().mode_separator;
52 if (getProblemData().gridfunctions.Has(var_name))
53 mooseError("MFEM variable '",
54 var_name,
55 "' clashes with an existing gridfunction (likely an eigenmode entry from another "
56 "variable). Choose a different variable name or set 'mode_separator' to a string "
57 "that avoids the clash.");
58
59 for (int i = 0; i < num_modes; ++i)
60 {
61 const auto mode_name = var_name + sep + std::to_string(i);
62 if (getProblemData().gridfunctions.Has(mode_name))
63 mooseError("Eigenmode storage name '",
64 mode_name,
65 "' for variable '",
66 var_name,
67 "' clashes with an already-registered variable. Set 'mode_separator' to a "
68 "string that avoids the clash, or rename the conflicting variable.");
69 }
70
71 addGridFunction(var_type, var_name, parameters);
72
73 for (int i = 0; i < num_modes; ++i)
74 addGridFunction(var_type, var_name + sep + std::to_string(i), parameters);
75}
76
77void
79{
81
82 if (getProblemData().nonlinear_solver)
83 mooseError("MFEMEigenproblem does not support nonlinear solver '",
84 getProblemData().nonlinear_solver->name(),
85 "'.");
86
87 if (getProblemData().jacobian_solver &&
88 !std::dynamic_pointer_cast<Moose::MFEM::EigensolverBase>(getProblemData().jacobian_solver))
89 mooseError("The selected solver '",
90 getProblemData().jacobian_solver->name(),
91 "' is not an eigensolver, but the problem is marked as an eigenproblem.");
92}
93
94#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.
MFEMEigenproblem(const InputParameters &params)
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
std::string mode_separator