LCOV - code coverage report
Current view: top level - src/mfem/problem - MFEMEigenproblem.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 26 31 83.9 %
Date: 2026-05-29 20:35:17 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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          52 :   getProblemData().jacobian_solver = addObject<MFEMSolverBase>(type, name, parameters).front();
      47             : 
      48          26 :   if (!std::dynamic_pointer_cast<MFEMEigensolverBase>(getProblemData().jacobian_solver))
      49           0 :     mooseError("The selected solver '" + name +
      50             :                "' is not an eigensolver, but the problem is marked as an eigenproblem.");
      51          26 : }
      52             : 
      53             : void
      54          26 : MFEMEigenproblem::addVariable(const std::string & var_type,
      55             :                               const std::string & var_name,
      56             :                               InputParameters & parameters)
      57             : {
      58             :   // Reject names that would collide with the mode-suffix convention or with any
      59             :   // already-registered eigenmode storage entry.
      60          52 :   const auto num_modes = getParam<int>("num_modes");
      61          26 :   const auto & sep = getProblemData().mode_separator;
      62          26 :   if (getProblemData().gridfunctions.Has(var_name))
      63           0 :     mooseError("MFEM variable '",
      64             :                var_name,
      65             :                "' clashes with an existing gridfunction (likely an eigenmode entry from another "
      66             :                "variable). Choose a different variable name or set 'mode_separator' to a string "
      67             :                "that avoids the clash.");
      68             : 
      69         156 :   for (int i = 0; i < num_modes; ++i)
      70             :   {
      71         130 :     const auto mode_name = var_name + sep + std::to_string(i);
      72         130 :     if (getProblemData().gridfunctions.Has(mode_name))
      73           0 :       mooseError("Eigenmode storage name '",
      74             :                  mode_name,
      75             :                  "' for variable '",
      76             :                  var_name,
      77             :                  "' clashes with an already-registered variable. Set 'mode_separator' to a "
      78             :                  "string that avoids the clash, or rename the conflicting variable.");
      79         130 :   }
      80             : 
      81          26 :   addGridFunction(var_type, var_name, parameters);
      82             : 
      83         156 :   for (int i = 0; i < num_modes; ++i)
      84         130 :     addGridFunction(var_type, var_name + sep + std::to_string(i), parameters);
      85          26 : }
      86             : 
      87             : #endif

Generated by: LCOV version 1.14