Line data Source code
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 : 16 : registerMooseObject("MooseApp", MFEMEigenproblem); 17 : 18 : InputParameters 19 2150 : MFEMEigenproblem::validParams() 20 : { 21 2150 : InputParameters params = MFEMProblem::validParams(); 22 4300 : params.addClassDescription("Problem type for building and solving a finite element eigenproblem " 23 : "using the MFEM finite element library."); 24 8600 : params.addParam<int>("num_modes", 1, "Set the number of lowest eigenmodes to compute."); 25 6450 : 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 2150 : return params; 32 0 : } 33 : 34 26 : MFEMEigenproblem::MFEMEigenproblem(const InputParameters & params) : MFEMProblem(params) 35 : { 36 52 : getProblemData().mode_separator = getParam<std::string>("mode_separator"); 37 26 : if (_num_type == NumericType::COMPLEX) 38 0 : mooseError("Complex numbers are not currently supported for eigenproblems."); 39 26 : } 40 : 41 : void 42 26 : MFEMEigenproblem::addMFEMSolver(const std::string & type, 43 : const std::string & name, 44 : InputParameters & parameters) 45 : { 46 26 : getProblemData().jacobian_solver = 47 78 : addObject<Moose::MFEM::LinearSolverBase>(type, name, parameters).front(); 48 : 49 26 : if (!std::dynamic_pointer_cast<Moose::MFEM::EigensolverBase>(getProblemData().jacobian_solver)) 50 0 : mooseError("The selected solver '" + name + 51 : "' is not an eigensolver, but the problem is marked as an eigenproblem."); 52 26 : } 53 : 54 : void 55 26 : 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 52 : const auto num_modes = getParam<int>("num_modes"); 62 26 : const auto & sep = getProblemData().mode_separator; 63 26 : if (getProblemData().gridfunctions.Has(var_name)) 64 0 : 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 156 : for (int i = 0; i < num_modes; ++i) 71 : { 72 130 : const auto mode_name = var_name + sep + std::to_string(i); 73 130 : if (getProblemData().gridfunctions.Has(mode_name)) 74 0 : 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 130 : } 81 : 82 26 : addGridFunction(var_type, var_name, parameters); 83 : 84 156 : for (int i = 0; i < num_modes; ++i) 85 130 : addGridFunction(var_type, var_name + sep + std::to_string(i), parameters); 86 26 : } 87 : 88 : #endif