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::addMFEMSolver(const std::string & type,
43  const std::string & name,
44  InputParameters & parameters)
45 {
47  addObject<Moose::MFEM::LinearSolverBase>(type, name, parameters).front();
48 
49  if (!std::dynamic_pointer_cast<Moose::MFEM::EigensolverBase>(getProblemData().jacobian_solver))
50  mooseError("The selected solver '" + name +
51  "' is not an eigensolver, but the problem is marked as an eigenproblem.");
52 }
53 
54 void
55 MFEMEigenproblem::addVariable(const std::string & var_type,
56  const std::string & var_name,
57  InputParameters & parameters)
58 {
59  // Reject names that would collide with the mode-suffix convention or with any
60  // already-registered eigenmode storage entry.
61  const auto num_modes = getParam<int>("num_modes");
62  const auto & sep = getProblemData().mode_separator;
63  if (getProblemData().gridfunctions.Has(var_name))
64  mooseError("MFEM variable '",
65  var_name,
66  "' clashes with an existing gridfunction (likely an eigenmode entry from another "
67  "variable). Choose a different variable name or set 'mode_separator' to a string "
68  "that avoids the clash.");
69 
70  for (int i = 0; i < num_modes; ++i)
71  {
72  const auto mode_name = var_name + sep + std::to_string(i);
73  if (getProblemData().gridfunctions.Has(mode_name))
74  mooseError("Eigenmode storage name '",
75  mode_name,
76  "' for variable '",
77  var_name,
78  "' clashes with an already-registered variable. Set 'mode_separator' to a "
79  "string that avoids the clash, or rename the conflicting variable.");
80  }
81 
82  addGridFunction(var_type, var_name, parameters);
83 
84  for (int i = 0; i < num_modes; ++i)
85  addGridFunction(var_type, var_name + sep + std::to_string(i), parameters);
86 }
87 
88 #endif
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:255
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:254
NumericType _num_type
The numeric representation currently active for this problem.
Definition: MFEMProblem.h:372
registerMooseObject("MooseApp", MFEMEigenproblem)
static InputParameters validParams()
Return the input parameters used to construct an MFEM problem.
Definition: MFEMProblem.C:31
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
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
virtual void addMFEMSolver(const std::string &user_object_name, const std::string &name, InputParameters &parameters) override
Method called in AddMFEMSolverAction which will create the solver.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93
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:281
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...
static InputParameters validParams()