From ed03a672a7ca7b599e1b1d030bbd638510736815 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Fri, 15 Dec 2023 00:40:54 +0000 Subject: [PATCH 1/2] Add Coefficients that return the value of a function of an MFEM variable or its reciprocal --- ...peratureDependentConductivityCoefficient.h | 24 +++++++++++++ ...MFEMVariableDependentFunctionCoefficient.h | 24 +++++++++++++ ...peratureDependentConductivityCoefficient.C | 35 +++++++++++++++++++ ...MFEMVariableDependentFunctionCoefficient.C | 33 +++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 include/coefficients/MFEMTemperatureDependentConductivityCoefficient.h create mode 100644 include/coefficients/MFEMVariableDependentFunctionCoefficient.h create mode 100644 src/coefficients/MFEMTemperatureDependentConductivityCoefficient.C create mode 100644 src/coefficients/MFEMVariableDependentFunctionCoefficient.C diff --git a/include/coefficients/MFEMTemperatureDependentConductivityCoefficient.h b/include/coefficients/MFEMTemperatureDependentConductivityCoefficient.h new file mode 100644 index 00000000..70daf6aa --- /dev/null +++ b/include/coefficients/MFEMTemperatureDependentConductivityCoefficient.h @@ -0,0 +1,24 @@ +#pragma once +#include "MFEMCoefficient.h" +#include "auxsolvers.hpp" + +class MFEMTemperatureDependentConductivityCoefficient : public MFEMCoefficient, + public hephaestus::CoupledCoefficient +{ +public: + static InputParameters validParams(); + + MFEMTemperatureDependentConductivityCoefficient(const InputParameters & parameters); + virtual ~MFEMTemperatureDependentConductivityCoefficient(); + + virtual void execute() override{}; + virtual void initialize() override{}; + virtual void finalize() override{}; + + double Eval(mfem::ElementTransformation & trans, const mfem::IntegrationPoint & ip) override; + + virtual mfem::Coefficient * getCoefficient() override { return this; }; + +private: + const Function & _func; +}; diff --git a/include/coefficients/MFEMVariableDependentFunctionCoefficient.h b/include/coefficients/MFEMVariableDependentFunctionCoefficient.h new file mode 100644 index 00000000..3fb7cee2 --- /dev/null +++ b/include/coefficients/MFEMVariableDependentFunctionCoefficient.h @@ -0,0 +1,24 @@ +#pragma once +#include "MFEMCoefficient.h" +#include "auxsolvers.hpp" + +class MFEMVariableDependentFunctionCoefficient : public MFEMCoefficient, + public hephaestus::CoupledCoefficient +{ +public: + static InputParameters validParams(); + + MFEMVariableDependentFunctionCoefficient(const InputParameters & parameters); + virtual ~MFEMVariableDependentFunctionCoefficient(); + + virtual void execute() override{}; + virtual void initialize() override{}; + virtual void finalize() override{}; + + double Eval(mfem::ElementTransformation & trans, const mfem::IntegrationPoint & ip) override; + + virtual mfem::Coefficient * getCoefficient() override { return this; }; + +private: + const Function & _func; +}; diff --git a/src/coefficients/MFEMTemperatureDependentConductivityCoefficient.C b/src/coefficients/MFEMTemperatureDependentConductivityCoefficient.C new file mode 100644 index 00000000..91577d7d --- /dev/null +++ b/src/coefficients/MFEMTemperatureDependentConductivityCoefficient.C @@ -0,0 +1,35 @@ +#include "MFEMTemperatureDependentConductivityCoefficient.h" + +registerMooseObject("ApolloApp", MFEMTemperatureDependentConductivityCoefficient); + +InputParameters +MFEMTemperatureDependentConductivityCoefficient::validParams() +{ + InputParameters params = MFEMCoefficient::validParams(); + params.addParam( + "resistivity_function", 1.0, "The resistivity of the material as a function of temperature"); + params.addParam("temperature_variable", + "The MFEMVariable describing the temperature of the material."); + return params; +} + +MFEMTemperatureDependentConductivityCoefficient::MFEMTemperatureDependentConductivityCoefficient( + const InputParameters & parameters) + : MFEMCoefficient(parameters), + hephaestus::CoupledCoefficient(hephaestus::InputParameters( + {{"CoupledVariableName", getParam("temperature_variable")}})), + _func(getFunction("resistivity_function")) +{ +} + +double +MFEMTemperatureDependentConductivityCoefficient::Eval(mfem::ElementTransformation & trans, + const mfem::IntegrationPoint & ip) +{ + auto gf_value{hephaestus::CoupledCoefficient::Eval(trans, ip)}; + return 1.0 / _func.value(gf_value); +}; + +MFEMTemperatureDependentConductivityCoefficient::~MFEMTemperatureDependentConductivityCoefficient() +{ +} diff --git a/src/coefficients/MFEMVariableDependentFunctionCoefficient.C b/src/coefficients/MFEMVariableDependentFunctionCoefficient.C new file mode 100644 index 00000000..f826b995 --- /dev/null +++ b/src/coefficients/MFEMVariableDependentFunctionCoefficient.C @@ -0,0 +1,33 @@ +#include "MFEMVariableDependentFunctionCoefficient.h" + +registerMooseObject("ApolloApp", MFEMVariableDependentFunctionCoefficient); + +InputParameters +MFEMVariableDependentFunctionCoefficient::validParams() +{ + InputParameters params = MFEMCoefficient::validParams(); + params.addParam( + "function", 1, "The function acting on the MFEM variable to return the coefficient"); + + params.addParam("coupled_variable", "The MFEMVariable the coefficient depends on."); + return params; +} + +MFEMVariableDependentFunctionCoefficient::MFEMVariableDependentFunctionCoefficient( + const InputParameters & parameters) + : MFEMCoefficient(parameters), + hephaestus::CoupledCoefficient(hephaestus::InputParameters( + {{"CoupledVariableName", getParam("coupled_variable")}})), + _func(getFunction("function")) +{ +} + +double +MFEMVariableDependentFunctionCoefficient::Eval(mfem::ElementTransformation & trans, + const mfem::IntegrationPoint & ip) +{ + auto gf_value{hephaestus::CoupledCoefficient::Eval(trans, ip)}; + return _func.value(gf_value); +}; + +MFEMVariableDependentFunctionCoefficient::~MFEMVariableDependentFunctionCoefficient() {} From d1f0554181a9199e2ff0e9389b2edd72cfb11a18 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Fri, 15 Dec 2023 02:54:23 +0000 Subject: [PATCH 2/2] Add variables as a prerequisite for mfem_coefficients build in order to avoid issues when building variable dependent coefficients --- src/base/ApolloApp.C | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/base/ApolloApp.C b/src/base/ApolloApp.C index 14bdb0a9..b5956cc7 100644 --- a/src/base/ApolloApp.C +++ b/src/base/ApolloApp.C @@ -38,6 +38,8 @@ associateSyntaxInner(Syntax & syntax, ActionFactory & /*action_factory*/) registerMooseObjectTask("add_mfem_coefficients", MFEMCoefficient, false); registerSyntaxTask("AddCoefficientAction", "Coefficients/*", "add_mfem_coefficients"); addTaskDependency("add_material", "add_mfem_coefficients"); + addTaskDependency("add_mfem_coefficients", "add_variable"); + addTaskDependency("add_mfem_coefficients", "add_aux_variable"); // add vector coefficients registerMooseObjectTask("add_mfem_vector_coefficients", MFEMVectorCoefficient, false);