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

Generated by: LCOV version 1.14