Skip to content

Commit

Permalink
Merge pull request aurora-multiphysics#5 from aurora-multiphysics/Edw…
Browse files Browse the repository at this point in the history
…ardPalmer99/remove-hephaestus-dependency

Remove Hephaestus Dependency
  • Loading branch information
alexanderianblair authored Jul 11, 2024
2 parents d7277af + f1614b2 commit c0b090f
Show file tree
Hide file tree
Showing 29 changed files with 1,113 additions and 70 deletions.
10 changes: 5 additions & 5 deletions framework/include/mfem/bcs/MFEMBoundaryCondition.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "GeneralUserObject.h"
#include "boundary_conditions.hpp"
#include "gridfunctions.hpp"
#include "coefficients.hpp"
#include "boundary_conditions.h"
#include "gridfunctions.h"
#include "coefficients.h"
#include "Function.h"

class MFEMBoundaryCondition : public GeneralUserObject
Expand All @@ -14,7 +14,7 @@ class MFEMBoundaryCondition : public GeneralUserObject
MFEMBoundaryCondition(const InputParameters & parameters);
~MFEMBoundaryCondition() override {}

inline virtual std::shared_ptr<hephaestus::BoundaryCondition> getBC() const
inline virtual std::shared_ptr<platypus::BoundaryCondition> getBC() const
{
return _boundary_condition;
}
Expand All @@ -27,5 +27,5 @@ class MFEMBoundaryCondition : public GeneralUserObject
std::vector<BoundaryName> _boundary_names;
mfem::Array<int> bdr_attr;

std::shared_ptr<hephaestus::BoundaryCondition> _boundary_condition{nullptr};
std::shared_ptr<platypus::BoundaryCondition> _boundary_condition{nullptr};
};
2 changes: 1 addition & 1 deletion framework/include/mfem/bcs/MFEMScalarDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "MFEMBoundaryCondition.h"
#include "MFEMFunctionCoefficient.h"
#include "boundary_conditions.hpp"
#include "boundary_conditions.h"

class MFEMScalarDirichletBC : public MFEMBoundaryCondition
{
Expand Down
2 changes: 1 addition & 1 deletion framework/include/mfem/bcs/MFEMVectorDirichletBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "MFEMBoundaryCondition.h"
#include "MFEMVectorFunctionCoefficient.h"
#include "boundary_conditions.hpp"
#include "boundary_conditions.h"

class MFEMVectorDirichletBC : public MFEMBoundaryCondition
{
Expand Down
2 changes: 1 addition & 1 deletion framework/include/mfem/bcs/MFEMVectorNormalIntegratedBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "MFEMBoundaryCondition.h"
#include "MFEMVectorFunctionCoefficient.h"
#include "boundary_conditions.hpp"
#include "boundary_conditions.h"

class MFEMVectorNormalIntegratedBC : public MFEMBoundaryCondition
{
Expand Down
36 changes: 36 additions & 0 deletions framework/include/mfem/bcs/boundary_conditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
#include "essential_bcs.h"
#include "integrated_bcs.h"
#include "named_fields_map.h"
#include "robin_bcs.h"

namespace platypus
{

class BCMap : public platypus::NamedFieldsMap<platypus::BoundaryCondition>
{
public:
mfem::Array<int> GetEssentialBdrMarkers(const std::string & name_, mfem::Mesh * mesh_);

void ApplyEssentialBCs(const std::string & name_,
mfem::Array<int> & ess_tdof_list,
mfem::GridFunction & gridfunc,
mfem::Mesh * mesh_);

void ApplyEssentialBCs(const std::string & name_,
mfem::Array<int> & ess_tdof_list,
mfem::ParComplexGridFunction & gridfunc,
mfem::Mesh * mesh_);

void ApplyIntegratedBCs(const std::string & name_, mfem::LinearForm & lf, mfem::Mesh * mesh_);

void ApplyIntegratedBCs(const std::string & name_,
mfem::ParComplexLinearForm & clf,
mfem::Mesh * mesh_);

void ApplyIntegratedBCs(const std::string & name_,
mfem::ParSesquilinearForm & clf,
mfem::Mesh * mesh_);
};

} // namespace platypus
141 changes: 141 additions & 0 deletions framework/include/mfem/equation_systems/equation_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#pragma once
#include "../common/pfem_extras.hpp"
#include "inputs.h"
#include "kernel_base.h"
#include "named_fields_map.h"

namespace platypus
{

/*
Class to store weak form components (bilinear and linear forms, and optionally
mixed and nonlinear forms) and build methods
*/
class EquationSystem : public mfem::Operator
{
public:
using ParBilinearFormKernel = platypus::Kernel<mfem::ParBilinearForm>;
using ParLinearFormKernel = platypus::Kernel<mfem::ParLinearForm>;
using ParNonlinearFormKernel = platypus::Kernel<mfem::ParNonlinearForm>;
using ParMixedBilinearFormKernel = platypus::Kernel<mfem::ParMixedBilinearForm>;

EquationSystem() = default;
~EquationSystem() override;

// Test variables are associated with LinearForms,
// whereas trial variables are associated with gridfunctions.

// Names of all variables corresponding to gridfunctions. This may differ
// from test_var_names when time derivatives are present.
std::vector<std::string> _trial_var_names;
// Names of all test variables corresponding to linear forms in this equation
// system
std::vector<std::string> _test_var_names;
std::vector<mfem::ParFiniteElementSpace *> _test_pfespaces;

// Components of weak form. // Named according to test variable
platypus::NamedFieldsMap<mfem::ParBilinearForm> _blfs;
platypus::NamedFieldsMap<mfem::ParLinearForm> _lfs;
platypus::NamedFieldsMap<mfem::ParNonlinearForm> _nlfs;
platypus::NamedFieldsMap<platypus::NamedFieldsMap<mfem::ParMixedBilinearForm>>
_mblfs; // named according to trial variable

// add test variable to EquationSystem;
virtual void AddTestVariableNameIfMissing(const std::string & test_var_name);
virtual void AddTrialVariableNameIfMissing(const std::string & trial_var_name);

// Add kernels.
void AddKernel(const std::string & test_var_name,
std::shared_ptr<ParBilinearFormKernel> blf_kernel);

void AddKernel(const std::string & test_var_name, std::shared_ptr<ParLinearFormKernel> lf_kernel);

void AddKernel(const std::string & test_var_name,
std::shared_ptr<ParNonlinearFormKernel> nlf_kernel);

void AddKernel(const std::string & trial_var_name,
const std::string & test_var_name,
std::shared_ptr<ParMixedBilinearFormKernel> mblf_kernel);

virtual void ApplyBoundaryConditions(platypus::BCMap & bc_map);

// override to add kernels
virtual void AddKernels() {}

// Build forms
virtual void Init(platypus::GridFunctions & gridfunctions,
const platypus::FESpaces & fespaces,
platypus::BCMap & bc_map,
platypus::Coefficients & coefficients);
virtual void BuildLinearForms(platypus::BCMap & bc_map);
virtual void BuildBilinearForms();
virtual void BuildMixedBilinearForms();
virtual void BuildEquationSystem(platypus::BCMap & bc_map);

// Form linear system, with essential boundary conditions accounted for
virtual void FormLinearSystem(mfem::OperatorHandle & op,
mfem::BlockVector & trueX,
mfem::BlockVector & trueRHS);

// Build linear system, with essential boundary conditions accounted for
virtual void BuildJacobian(mfem::BlockVector & trueX, mfem::BlockVector & trueRHS);

/// Compute residual y = Mu
void Mult(const mfem::Vector & u, mfem::Vector & residual) const override;

/// Compute J = M + grad_H(u)
mfem::Operator & GetGradient(const mfem::Vector & u) const override;

// Update variable from solution vector after solve
virtual void RecoverFEMSolution(mfem::BlockVector & trueX,
platypus::GridFunctions & gridfunctions);

std::vector<mfem::Array<int>> _ess_tdof_lists;

protected:
bool VectorContainsName(const std::vector<std::string> & the_vector,
const std::string & name) const;

// gridfunctions for setting Dirichlet BCs
std::vector<std::unique_ptr<mfem::ParGridFunction>> _xs;

mfem::Array2D<mfem::HypreParMatrix *> _h_blocks;

// Arrays to store kernels to act on each component of weak form. Named
// according to test variable
platypus::NamedFieldsMap<std::vector<std::shared_ptr<ParBilinearFormKernel>>> _blf_kernels_map;

platypus::NamedFieldsMap<std::vector<std::shared_ptr<ParLinearFormKernel>>> _lf_kernels_map;

platypus::NamedFieldsMap<std::vector<std::shared_ptr<ParNonlinearFormKernel>>> _nlf_kernels_map;

platypus::NamedFieldsMap<
platypus::NamedFieldsMap<std::vector<std::shared_ptr<ParMixedBilinearFormKernel>>>>
_mblf_kernels_map_map;

mutable mfem::OperatorHandle _jacobian;
};

/*
Class to store weak form components for time dependent PDEs
*/
class TimeDependentEquationSystem : public EquationSystem
{
public:
TimeDependentEquationSystem();
~TimeDependentEquationSystem() override = default;

static std::string GetTimeDerivativeName(std::string name)
{
return std::string("d") + name + std::string("_dt");
}

void AddTrialVariableNameIfMissing(const std::string & trial_var_name) override;

virtual void SetTimeStep(double dt);
virtual void UpdateEquationSystem(platypus::BCMap & bc_map);
mfem::ConstantCoefficient _dt_coef; // Coefficient for timestep scaling
std::vector<std::string> _trial_var_time_derivative_names;
};

} // namespace platypus
3 changes: 0 additions & 3 deletions framework/include/mfem/fespaces/MFEMFESpace.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#pragma once

#include "GeneralUserObject.h"
#include "inputs.hpp"
#include "gridfunctions.hpp"

class MFEMFESpace : public GeneralUserObject
{
Expand Down
11 changes: 4 additions & 7 deletions framework/include/mfem/kernels/MFEMDiffusionKernel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "MFEMBilinearFormKernel.h"
#include "kernels.hpp"
#include "kernels.h"

class MFEMDiffusionKernel : public MFEMBilinearFormKernel
{
Expand All @@ -14,12 +14,9 @@ class MFEMDiffusionKernel : public MFEMBilinearFormKernel
virtual void initialize() override {}
virtual void finalize() override {}

std::shared_ptr<hephaestus::Kernel<mfem::ParBilinearForm>> getKernel() override
{
return _kernel;
}
std::shared_ptr<platypus::Kernel<mfem::ParBilinearForm>> getKernel() override { return _kernel; }

protected:
hephaestus::InputParameters _kernel_params;
std::shared_ptr<hephaestus::DiffusionKernel> _kernel{nullptr};
platypus::InputParameters _kernel_params;
std::shared_ptr<platypus::DiffusionKernel> _kernel{nullptr};
};
4 changes: 2 additions & 2 deletions framework/include/mfem/materials/MFEMMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "GeneralUserObject.h"
#include "MFEMCoefficient.h"
#include "coefficients.hpp"
#include "coefficients.h"

class MFEMMaterial : public GeneralUserObject
{
Expand All @@ -16,7 +16,7 @@ class MFEMMaterial : public GeneralUserObject
virtual void initialize() override {}
virtual void finalize() override {}

virtual void storeCoefficients(hephaestus::Subdomain & subdomain) {}
virtual void storeCoefficients(platypus::Subdomain & subdomain) {}

std::vector<SubdomainName> blocks;
};
25 changes: 11 additions & 14 deletions framework/include/mfem/problem/MFEMProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
#include "MFEMBilinearFormKernel.h"
#include "MFEMLinearFormKernel.h"
#include "MFEMFormulation.h"
#include "MFEMAuxSolver.h"
#include "MFEMDataCollection.h"
#include "MFEMFESpace.h"
#include "Function.h"
#include "MooseEnum.h"
#include "SystemBase.h"
#include "Transient.h"
#include "Steady.h"
#include "hephaestus.hpp"
#include "platypus.h"
#include "libmesh/string_to_enum.h"
#include "libmesh/point.h"

Expand Down Expand Up @@ -109,9 +108,7 @@ class MFEMProblem : public ExternalProblem
const std::string & name,
InputParameters & parameters) override;
/**
* Override of ExternalProblem::addAuxKernel. Uses ExternalProblem::addAuxKernel to create a
* GeneralUserObject representing the auxkernel in MOOSE, and creates corresponding MFEM auxsolver
* to be used in the MFEM solve.
* Override of ExternalProblem::addAuxKernel.
*/
void addAuxKernel(const std::string & kernel_name,
const std::string & name,
Expand Down Expand Up @@ -151,9 +148,9 @@ class MFEMProblem : public ExternalProblem
* builders.
*/
template <class T>
void addKernel(std::string var_name, std::shared_ptr<hephaestus::Kernel<T>> kernel)
void addKernel(std::string var_name, std::shared_ptr<platypus::Kernel<T>> kernel)
{
using namespace hephaestus;
using namespace platypus;

EquationSystemProblemBuilderInterface * eqn_system_problem_builder{nullptr};

Expand All @@ -173,13 +170,13 @@ class MFEMProblem : public ExternalProblem
std::string _formulation_name;
int _order;

hephaestus::Coefficients _coefficients;
hephaestus::InputParameters _solver_options;
hephaestus::Outputs _outputs;
hephaestus::InputParameters _exec_params;
platypus::Coefficients _coefficients;
platypus::InputParameters _solver_options;
platypus::Outputs _outputs;
platypus::InputParameters _exec_params;

std::shared_ptr<hephaestus::ProblemBuilder> mfem_problem_builder{nullptr};
std::shared_ptr<platypus::ProblemBuilder> mfem_problem_builder{nullptr};

std::unique_ptr<hephaestus::Problem> mfem_problem{nullptr};
std::unique_ptr<hephaestus::Executioner> executioner{nullptr};
std::unique_ptr<platypus::Problem> mfem_problem{nullptr};
std::unique_ptr<platypus::Executioner> executioner{nullptr};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include "problem_operator.h"
#include "problem_operator_interface.h"
#include "equation_system_interface.h"

namespace platypus
{
/// Steady-state problem operator with an equation system.
class EquationSystemProblemOperator : public ProblemOperator, public EquationSystemInterface
{
public:
EquationSystemProblemOperator(platypus::Problem &) = delete;

EquationSystemProblemOperator(platypus::Problem & problem,
std::unique_ptr<platypus::EquationSystem> equation_system)
: ProblemOperator(problem), _equation_system(std::move(equation_system))
{
}

void SetGridFunctions() override;
void Init(mfem::Vector & X) override;

~EquationSystemProblemOperator() override = default;

[[nodiscard]] platypus::EquationSystem * GetEquationSystem() const override
{
if (!_equation_system)
{
MFEM_ABORT("No equation system has been added to ProblemOperator.");
}

return _equation_system.get();
}

private:
std::unique_ptr<platypus::EquationSystem> _equation_system{nullptr};
};

} // namespace platypus
Loading

0 comments on commit c0b090f

Please sign in to comment.