Skip to content

Commit

Permalink
Merge pull request #26 from aurora-multiphysics/alexanderianblair/MFE…
Browse files Browse the repository at this point in the history
…MSolversAndPreconditioners

Enable user specification of solvers and preconditioners
  • Loading branch information
alexanderianblair authored Sep 3, 2024
2 parents 21c8d76 + c29f6a8 commit a21fd94
Show file tree
Hide file tree
Showing 31 changed files with 4,205 additions and 3,725 deletions.
20 changes: 20 additions & 0 deletions include/actions/AddMFEMPreconditionerAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "MooseObjectAction.h"

/**
* This class allows us to have a section of the input file like the following
* specifying the solver to use and the solve options.
*
* [Preconditioner]
* []
*/
class AddMFEMPreconditionerAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddMFEMPreconditionerAction(const InputParameters & parameters);

void act() override;
};
20 changes: 20 additions & 0 deletions include/actions/AddMFEMSolverAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "MooseObjectAction.h"

/**
* This class allows us to have a section of the input file like the following
* specifying the solver to use and the solve options.
*
* [Solver]
* []
*/
class AddMFEMSolverAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddMFEMSolverAction(const InputParameters & parameters);

void act() override;
};
15 changes: 15 additions & 0 deletions include/problem/MFEMProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "MFEMFormulation.h"
#include "MFEMDataCollection.h"
#include "MFEMFESpace.h"
#include "MFEMSolverBase.h"
#include "Function.h"
#include "MooseEnum.h"
#include "SystemBase.h"
Expand Down Expand Up @@ -112,6 +113,20 @@ class MFEMProblem : public ExternalProblem
const std::string & name,
InputParameters & parameters) override;

/**
* Method called in AddMFEMPreconditionerAction which will create the solver.
*/
void addMFEMPreconditioner(const std::string & user_object_name,
const std::string & name,
InputParameters & parameters);

/**
* Method called in AddMFEMSolverAction which will create the solver.
*/
void addMFEMSolver(const std::string & user_object_name,
const std::string & name,
InputParameters & parameters);

/**
* Method used to get an mfem FEC depending on the variable family specified in the input file.
* This method is used in addAuxVariable to help create the MFEM grid function that corresponds to
Expand Down
19 changes: 0 additions & 19 deletions include/problem_builders/problem_builder_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ class ProblemBuilder
virtual ~ProblemBuilder() = default;

void SetMesh(std::shared_ptr<mfem::ParMesh> pmesh);
void SetFESpaces(platypus::FESpaces & fespaces);
void SetGridFunctions(platypus::GridFunctions & gridfunctions);
void SetBoundaryConditions(platypus::BCMap & bc_map);
void SetOutputs(platypus::Outputs & outputs);
void SetSolverOptions(platypus::InputParameters & solver_options);
void SetJacobianPreconditioner(std::shared_ptr<mfem::Solver> preconditioner);
void SetJacobianSolver(std::shared_ptr<mfem::Solver> solver);
void SetCoefficients(platypus::Coefficients & coefficients);
void SetDevice(const std::string & dev);

Expand All @@ -79,8 +72,6 @@ class ProblemBuilder
virtual void RegisterCoefficients() = 0;

virtual void SetOperatorGridFunctions() = 0;
virtual void ConstructJacobianPreconditioner();
virtual void ConstructJacobianSolver();
virtual void ConstructNonlinearSolver();
virtual void ConstructOperator() = 0;
virtual void ConstructState() = 0;
Expand Down Expand Up @@ -128,16 +119,6 @@ class ProblemBuilder
int _k_dim;
};

/// Called in @a ConstructJacobianSolver. This will create a solver of the chosen type and use the user's input
/// parameters if they have been provided.
void ConstructJacobianSolverWithOptions(SolverType type,
SolverParams default_params = {
._tolerance = 1e-16,
._abs_tolerance = 1e-16,
._max_iteration = 1000,
._print_level = 2, // GetGlobalPrintLevel(),
._k_dim = 10});

/// Overridden in derived classes.
[[nodiscard]] virtual platypus::Problem * GetProblem() const = 0;

Expand Down
1 change: 0 additions & 1 deletion include/problem_operators/problem_operator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "../common/pfem_extras.hpp"
#include "hephaestus_solvers.h"
#include "problem_builder_base.h"
#include "problem_operator_interface.h"

Expand Down
1 change: 0 additions & 1 deletion include/problem_operators/time_domain_problem_operator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "../common/pfem_extras.hpp"
#include "hephaestus_solvers.h"
#include "problem_builder_base.h"
#include "problem_operator_interface.h"

Expand Down
24 changes: 24 additions & 0 deletions include/solvers/MFEMHypreAMS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include "MFEMSolverBase.h"
#include "MFEMFESpace.h"

/**
* Wrapper for mfem::HypreAMS solver.
*/
class MFEMHypreAMS : public MFEMSolverBase
{
public:
static InputParameters validParams();

MFEMHypreAMS(const InputParameters &);

/// Returns a shared pointer to the instance of the Solver derived-class.
std::shared_ptr<mfem::Solver> getSolver() const override { return _preconditioner; }

protected:
void constructSolver(const InputParameters & parameters) override;

private:
const MFEMFESpace & _mfem_fespace;
std::shared_ptr<mfem::HypreAMS> _preconditioner{nullptr};
};
24 changes: 24 additions & 0 deletions include/solvers/MFEMHypreBoomerAMG.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include "MFEMSolverBase.h"
#include "mfem.hpp"
#include <memory>

/**
* Wrapper for mfem::HypreBoomerAMG solver.
*/
class MFEMHypreBoomerAMG : public MFEMSolverBase
{
public:
static InputParameters validParams();

MFEMHypreBoomerAMG(const InputParameters &);

/// Returns a shared pointer to the instance of the Solver derived-class.
std::shared_ptr<mfem::Solver> getSolver() const override { return _solver; }

protected:
void constructSolver(const InputParameters & parameters) override;

private:
std::shared_ptr<mfem::HypreBoomerAMG> _solver{nullptr};
};
24 changes: 24 additions & 0 deletions include/solvers/MFEMHypreFGMRES.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include "MFEMSolverBase.h"
#include "mfem.hpp"
#include <memory>

/**
* Wrapper for mfem::HypreFGMRES solver.
*/
class MFEMHypreFGMRES : public MFEMSolverBase
{
public:
static InputParameters validParams();

MFEMHypreFGMRES(const InputParameters & parameters);

std::shared_ptr<mfem::Solver> getSolver() const override { return _solver; }

protected:
void constructSolver(const InputParameters & parameters) override;

private:
std::shared_ptr<mfem::Solver> _preconditioner{nullptr};
std::shared_ptr<mfem::HypreFGMRES> _solver{nullptr};
};
26 changes: 26 additions & 0 deletions include/solvers/MFEMHypreGMRES.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "MFEMSolverBase.h"
#include "MFEMHypreBoomerAMG.h"
#include "mfem.hpp"
#include <memory>

/**
* Wrapper for mfem::HypreGMRES solver.
*/
class MFEMHypreGMRES : public MFEMSolverBase
{
public:
static InputParameters validParams();

MFEMHypreGMRES(const InputParameters &);

/// Returns a shared pointer to the instance of the Solver derived-class.
std::shared_ptr<mfem::Solver> getSolver() const override { return _solver; }

protected:
void constructSolver(const InputParameters & parameters) override;

private:
std::shared_ptr<mfem::Solver> _preconditioner{nullptr};
std::shared_ptr<mfem::HypreGMRES> _solver{nullptr};
};
25 changes: 25 additions & 0 deletions include/solvers/MFEMHyprePCG.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include "MFEMSolverBase.h"
#include "mfem.hpp"
#include <memory>

/**
* Wrapper for mfem::HyprePCG solver.
*/
class MFEMHyprePCG : public MFEMSolverBase
{
public:
static InputParameters validParams();

MFEMHyprePCG(const InputParameters & parameters);

/// Returns a shared pointer to the instance of the Solver derived-class.
std::shared_ptr<mfem::Solver> getSolver() const override { return _solver; }

protected:
void constructSolver(const InputParameters & parameters) override;

private:
std::shared_ptr<mfem::Solver> _preconditioner{nullptr};
std::shared_ptr<mfem::HyprePCG> _solver{nullptr};
};
22 changes: 22 additions & 0 deletions include/solvers/MFEMSolverBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include "MFEMGeneralUserObject.h"
#include "mfem.hpp"
#include <memory>

/**
* Base class for wrapping mfem::Solver-derived classes.
*/
class MFEMSolverBase : public MFEMGeneralUserObject
{
public:
static InputParameters validParams();

MFEMSolverBase(const InputParameters & parameters);

/// Returns a shared pointer to the instance of the Solver derived-class.
virtual std::shared_ptr<mfem::Solver> getSolver() const = 0;

protected:
/// Override in derived classes to construct and set the solver options.
virtual void constructSolver(const InputParameters & parameters) = 0;
};
46 changes: 46 additions & 0 deletions include/solvers/MFEMSuperLU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once
#include "MFEMSolverBase.h"
#include "mfem.hpp"
#include <memory>

namespace platypus
{

/**
* Wrapper for mfem::SuperLU solver that creates a SuperLURowLocMatrix from the operator
* when set.
*/
class SuperLUSolver : public mfem::SuperLUSolver
{
public:
SuperLUSolver(MPI_Comm comm, int npdep = 1) : mfem::SuperLUSolver(comm, npdep){};
void SetOperator(const mfem::Operator & op) override
{
_a_superlu = std::make_unique<mfem::SuperLURowLocMatrix>(op);
mfem::SuperLUSolver::SetOperator(*_a_superlu.get());
}

private:
std::unique_ptr<mfem::SuperLURowLocMatrix> _a_superlu{nullptr};
};
} // namespace platypus

/**
* Wrapper for mfem::HyprePCG solver.
*/
class MFEMSuperLU : public MFEMSolverBase
{
public:
static InputParameters validParams();

MFEMSuperLU(const InputParameters & parameters);

/// Returns a shared pointer to the instance of the Solver derived-class.
std::shared_ptr<mfem::Solver> getSolver() const override { return _solver; }

protected:
void constructSolver(const InputParameters & parameters) override;

private:
std::shared_ptr<platypus::SuperLUSolver> _solver{nullptr};
};
Loading

0 comments on commit a21fd94

Please sign in to comment.