LCOV - code coverage report
Current view: top level - include/mfem/problem - MFEMProblem.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 3501bd Lines: 4 6 66.7 %
Date: 2025-09-04 20:01:23 Functions: 5 7 71.4 %
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             : #pragma once
      13             : #include "ExternalProblem.h"
      14             : #include "MFEMProblemData.h"
      15             : #include "MFEMMesh.h"
      16             : 
      17             : class MFEMProblem : public ExternalProblem
      18             : {
      19             : public:
      20             :   static InputParameters validParams();
      21             : 
      22             :   MFEMProblem(const InputParameters & params);
      23         882 :   virtual ~MFEMProblem() {}
      24             : 
      25             :   virtual void initialSetup() override;
      26           0 :   virtual void externalSolve() override {}
      27           0 :   virtual void syncSolutions(Direction) override {}
      28             : 
      29             :   /**
      30             :    * Overwritten mesh() method from base MooseMesh to retrieve the correct mesh type, in this case
      31             :    * MFEMMesh.
      32             :    */
      33             :   virtual MFEMMesh & mesh() override;
      34             :   virtual const MFEMMesh & mesh() const override;
      35             :   using ExternalProblem::mesh;
      36             : 
      37             :   /**
      38             :    * Returns all the variable names from the auxiliary system base. This is helpful in the
      39             :    * syncSolutions() method when transferring variable data.
      40             :    */
      41             :   virtual std::vector<VariableName> getAuxVariableNames();
      42             : 
      43             :   void addBoundaryCondition(const std::string & bc_name,
      44             :                             const std::string & name,
      45             :                             InputParameters & parameters) override;
      46             : 
      47             :   void addMaterial(const std::string & material_name,
      48             :                    const std::string & name,
      49             :                    InputParameters & parameters) override;
      50             : 
      51             :   void addFunctorMaterial(const std::string & material_name,
      52             :                           const std::string & name,
      53             :                           InputParameters & parameters) override;
      54             : 
      55             :   /**
      56             :    * Add an MFEM FESpace to the problem.
      57             :    */
      58             :   void addFESpace(const std::string & user_object_name,
      59             :                   const std::string & name,
      60             :                   InputParameters & parameters);
      61             :   /**
      62             :    * Set the device to use to solve the FE problem.
      63             :    */
      64             :   void setDevice();
      65             : 
      66             :   /**
      67             :    * Set the mesh used by MFEM.
      68             :    */
      69             :   void setMesh();
      70             : 
      71             :   /**
      72             :    * Add an MFEM SubMesh to the problem.
      73             :    */
      74             :   void addSubMesh(const std::string & user_object_name,
      75             :                   const std::string & name,
      76             :                   InputParameters & parameters);
      77             : 
      78             :   /**
      79             :    * Add transfers between MultiApps and/or MFEM SubMeshes.
      80             :    */
      81             :   void addTransfer(const std::string & transfer_name,
      82             :                    const std::string & name,
      83             :                    InputParameters & parameters) override;
      84             :   /**
      85             :    * Override of ExternalProblem::addVariable. Sets a
      86             :    * MFEM grid function (and time derivative, for transient problems) to be used in the MFEM solve.
      87             :    */
      88             :   void addVariable(const std::string & var_type,
      89             :                    const std::string & var_name,
      90             :                    InputParameters & parameters) override;
      91             : 
      92             :   /**
      93             :    * Adds one MFEM GridFunction to be used in the MFEM solve.
      94             :    */
      95             :   void addGridFunction(const std::string & var_type,
      96             :                        const std::string & var_name,
      97             :                        InputParameters & parameters);
      98             : 
      99             :   using ExternalProblem::addAuxVariable;
     100             :   /**
     101             :    * Override of ExternalProblem::addAuxVariable. Sets a
     102             :    * MFEM grid function to be used in the MFEM solve.
     103             :    */
     104             :   void addAuxVariable(const std::string & var_type,
     105             :                       const std::string & var_name,
     106             :                       InputParameters & parameters) override;
     107             : 
     108             :   /**
     109             :    * Override of ExternalProblem::addKernel. Uses ExternalProblem::addKernel to create a
     110             :    * MFEMGeneralUserObject representing the kernel in MOOSE, and creates corresponding MFEM kernel
     111             :    * to be used in the MFEM solve.
     112             :    */
     113             :   void addKernel(const std::string & kernel_name,
     114             :                  const std::string & name,
     115             :                  InputParameters & parameters) override;
     116             : 
     117             :   /**
     118             :    * Override of ExternalProblem::addAuxKernel. Uses ExternalProblem::addAuxKernel to create a
     119             :    * MFEMGeneralUserObject representing the kernel in MOOSE, and creates corresponding MFEM kernel
     120             :    * to be used in the MFEM solve.
     121             :    */
     122             :   void addAuxKernel(const std::string & kernel_name,
     123             :                     const std::string & name,
     124             :                     InputParameters & parameters) override;
     125             : 
     126             :   /**
     127             :    * Override of ExternalProblem::addFunction. Uses ExternalProblem::addFunction to create a
     128             :    * MFEMGeneralUserObject representing the function in MOOSE, and creates a corresponding
     129             :    * MFEM Coefficient or VectorCoefficient object.
     130             :    */
     131             :   void addFunction(const std::string & type,
     132             :                    const std::string & name,
     133             :                    InputParameters & parameters) override;
     134             : 
     135             :   void addInitialCondition(const std::string & ic_name,
     136             :                            const std::string & name,
     137             :                            InputParameters & parameters) override;
     138             : 
     139             :   /**
     140             :    * Override of ExternalProblem::addPostprocessor. In addition to
     141             :    * creating the postprocessor object, it will create a coefficient
     142             :    * that will hold its value.
     143             :    */
     144             :   void addPostprocessor(const std::string & type,
     145             :                         const std::string & name,
     146             :                         InputParameters & parameters) override;
     147             : 
     148             :   /**
     149             :    * Method called in AddMFEMPreconditionerAction which will create the solver.
     150             :    */
     151             :   void addMFEMPreconditioner(const std::string & user_object_name,
     152             :                              const std::string & name,
     153             :                              InputParameters & parameters);
     154             : 
     155             :   /**
     156             :    * Method called in AddMFEMSolverAction which will create the solver.
     157             :    */
     158             :   void addMFEMSolver(const std::string & user_object_name,
     159             :                      const std::string & name,
     160             :                      InputParameters & parameters);
     161             : 
     162             :   /**
     163             :    * Add the nonlinear solver to the system. TODO: allow user to specify solver options,
     164             :    * similar to the linear solvers.
     165             :    */
     166             :   void addMFEMNonlinearSolver();
     167             : 
     168             :   /**
     169             :    * Method used to get an mfem FEC depending on the variable family specified in the input file.
     170             :    * This method is used in addAuxVariable to help create the MFEM grid function that corresponds to
     171             :    * a given MOOSE aux-variable.
     172             :    */
     173             :   InputParameters addMFEMFESpaceFromMOOSEVariable(InputParameters & moosevar_params);
     174             : 
     175             :   /**
     176             :    * Method to get the PropertyManager object for storing material
     177             :    * properties and converting them to MFEM coefficients. This is used
     178             :    * by Material and Kernel classes (among others).
     179             :    */
     180        2047 :   Moose::MFEM::CoefficientManager & getCoefficients() { return _problem_data.coefficients; }
     181             : 
     182             :   /**
     183             :    * Method to get the current MFEMProblemData object storing the
     184             :    * current data specifying the FE problem.
     185             :    */
     186        8143 :   MFEMProblemData & getProblemData() { return _problem_data; }
     187             : 
     188             :   /**
     189             :    * Displace the mesh, if mesh displacement is enabled.
     190             :    */
     191             :   void displaceMesh();
     192             : 
     193             :   /**
     194             :    * Returns optional reference to the displacement GridFunction to apply to nodes.
     195             :    */
     196             :   std::optional<std::reference_wrapper<mfem::ParGridFunction const>>
     197             :   getMeshDisplacementGridFunction();
     198             : 
     199         622 :   Moose::FEBackend feBackend() const override { return Moose::FEBackend::MFEM; }
     200             : 
     201             :   std::string solverTypeString(unsigned int solver_sys_num) override;
     202             : 
     203             :   /**
     204             :    * @returns a shared pointer to an MFEM parallel grid function
     205             :    */
     206             :   std::shared_ptr<mfem::ParGridFunction> getGridFunction(const std::string & name);
     207             : 
     208             : protected:
     209             :   MFEMProblemData _problem_data;
     210             : };
     211             : 
     212             : #endif

Generated by: LCOV version 1.14