https://mooseframework.inl.gov
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 
41 void
42 MFEMEigenproblem::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 
77 void
79 {
81 
82  if (getProblemData().nonlinear_solver)
83  mooseError("MFEMEigenproblem does not support nonlinear solver '",
84  getProblemData().nonlinear_solver->name(),
85  "'.");
86 
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
virtual void resolveMFEMSolvers()
Construct recorded MFEM solvers in dependency order and select the problem driver solver(s)...
Definition: MFEMProblem.C:157
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.
Definition: MFEMProblem.C:392
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:271
NumericType _num_type
The numeric representation currently active for this problem.
Definition: MFEMProblem.h:402
registerMooseObject("MooseApp", MFEMEigenproblem)
static InputParameters validParams()
Return the input parameters used to construct an MFEM problem.
Definition: MFEMProblem.C:60
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &parameters) override
Override of MFEMProblem::addVariable.
MFEMEigenproblem(const InputParameters &params)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::shared_ptr< Moose::MFEM::LinearSolverBase > jacobian_solver
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.
virtual void resolveMFEMSolvers() override
Construct recorded MFEM solvers in dependency order and select the problem driver solver(s)...
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...
Definition: MooseBase.h:271
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...
std::string mode_separator
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 validateVariableNumericType(const std::string &var_type, const std::string &var_name) const
Verify that a primary variable&#39;s numeric type matches the problem&#39;s equation system.
Definition: MFEMProblem.C:358
Base class for eigensolvers.
static InputParameters validParams()