From 557739cab8e2a46fd9950ff8d312bd6309672407 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Thu, 31 Oct 2024 18:39:49 +0000 Subject: [PATCH 01/24] Removed references to Platypus coefficient classes --- include/actions/AddCoefficientAction.h | 20 -------------- include/actions/AddVectorCoefficientAction.h | 20 -------------- include/coefficients/MFEMCoefficient.h | 21 --------------- .../coefficients/MFEMConstantCoefficient.h | 18 ------------- .../coefficients/MFEMFunctionCoefficient.h | 16 ------------ include/coefficients/MFEMVectorCoefficient.h | 20 -------------- .../MFEMVectorConstantCoefficient.h | 20 -------------- .../MFEMVectorFunctionCoefficient.h | 19 -------------- src/actions/AddCoefficientAction.C | 24 ----------------- src/actions/AddVectorCoefficientAction.C | 24 ----------------- src/coefficients/MFEMCoefficient.C | 24 ----------------- src/coefficients/MFEMConstantCoefficient.C | 21 --------------- src/coefficients/MFEMFunctionCoefficient.C | 20 -------------- src/coefficients/MFEMVectorCoefficient.C | 18 ------------- .../MFEMVectorConstantCoefficient.C | 26 ------------------- .../MFEMVectorFunctionCoefficient.C | 21 --------------- 16 files changed, 332 deletions(-) delete mode 100644 include/actions/AddCoefficientAction.h delete mode 100644 include/actions/AddVectorCoefficientAction.h delete mode 100644 include/coefficients/MFEMCoefficient.h delete mode 100644 include/coefficients/MFEMConstantCoefficient.h delete mode 100644 include/coefficients/MFEMFunctionCoefficient.h delete mode 100644 include/coefficients/MFEMVectorCoefficient.h delete mode 100644 include/coefficients/MFEMVectorConstantCoefficient.h delete mode 100644 include/coefficients/MFEMVectorFunctionCoefficient.h delete mode 100644 src/actions/AddCoefficientAction.C delete mode 100644 src/actions/AddVectorCoefficientAction.C delete mode 100644 src/coefficients/MFEMCoefficient.C delete mode 100644 src/coefficients/MFEMConstantCoefficient.C delete mode 100644 src/coefficients/MFEMFunctionCoefficient.C delete mode 100644 src/coefficients/MFEMVectorCoefficient.C delete mode 100644 src/coefficients/MFEMVectorConstantCoefficient.C delete mode 100644 src/coefficients/MFEMVectorFunctionCoefficient.C diff --git a/include/actions/AddCoefficientAction.h b/include/actions/AddCoefficientAction.h deleted file mode 100644 index 21b113f5..00000000 --- a/include/actions/AddCoefficientAction.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "MooseObjectAction.h" -#include "MFEMProblem.h" -/** - * This class allows us to have a section of the input file like the - * following to add MFEM coefficients to the problem. - * - * [Coefficients] - * [] - */ -class AddCoefficientAction : public MooseObjectAction -{ -public: - static InputParameters validParams(); - - AddCoefficientAction(const InputParameters & parameters); - - virtual void act() override; -}; diff --git a/include/actions/AddVectorCoefficientAction.h b/include/actions/AddVectorCoefficientAction.h deleted file mode 100644 index 978ce573..00000000 --- a/include/actions/AddVectorCoefficientAction.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "MooseObjectAction.h" -#include "MFEMProblem.h" -/** - * This class allows us to have a section of the input file like the - * following to add MFEM coefficients to the problem. - * - * [Coefficients] - * [] - */ -class AddVectorCoefficientAction : public MooseObjectAction -{ -public: - static InputParameters validParams(); - - AddVectorCoefficientAction(const InputParameters & parameters); - - virtual void act() override; -}; diff --git a/include/coefficients/MFEMCoefficient.h b/include/coefficients/MFEMCoefficient.h deleted file mode 100644 index 4ff530be..00000000 --- a/include/coefficients/MFEMCoefficient.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include "MFEMGeneralUserObject.h" -#include "Function.h" - -libMesh::Point PointFromMFEMVector(const mfem::Vector & vec); - -class MFEMCoefficient : public MFEMGeneralUserObject -{ -public: - static InputParameters validParams(); - - MFEMCoefficient(const InputParameters & parameters); - virtual ~MFEMCoefficient(); - - virtual std::shared_ptr getCoefficient() const - { - mooseError("Base class MFEMCoefficient cannot return a valid Coefficient. Use a child class."); - } -}; diff --git a/include/coefficients/MFEMConstantCoefficient.h b/include/coefficients/MFEMConstantCoefficient.h deleted file mode 100644 index ced3ac83..00000000 --- a/include/coefficients/MFEMConstantCoefficient.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "MFEMCoefficient.h" -#include "MFEMContainers.h" - -class MFEMConstantCoefficient : public MFEMCoefficient -{ -public: - static InputParameters validParams(); - - MFEMConstantCoefficient(const InputParameters & parameters); - virtual ~MFEMConstantCoefficient(); - - std::shared_ptr getCoefficient() const override { return coefficient; } - -private: - std::shared_ptr coefficient{nullptr}; -}; diff --git a/include/coefficients/MFEMFunctionCoefficient.h b/include/coefficients/MFEMFunctionCoefficient.h deleted file mode 100644 index 204b6ab5..00000000 --- a/include/coefficients/MFEMFunctionCoefficient.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include "MFEMCoefficient.h" - -class MFEMFunctionCoefficient : public MFEMCoefficient -{ -public: - static InputParameters validParams(); - - MFEMFunctionCoefficient(const InputParameters & parameters); - virtual ~MFEMFunctionCoefficient(); - - std::shared_ptr getCoefficient() const override { return _coefficient; }; - -private: - std::shared_ptr _coefficient{nullptr}; -}; diff --git a/include/coefficients/MFEMVectorCoefficient.h b/include/coefficients/MFEMVectorCoefficient.h deleted file mode 100644 index 4a568638..00000000 --- a/include/coefficients/MFEMVectorCoefficient.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include "MFEMGeneralUserObject.h" -#include "Function.h" - -class MFEMVectorCoefficient : public MFEMGeneralUserObject -{ -public: - static InputParameters validParams(); - - MFEMVectorCoefficient(const InputParameters & parameters); - virtual ~MFEMVectorCoefficient(); - - virtual std::shared_ptr getVectorCoefficient() const - { - mooseError("Base class MFEMVectorCoefficient cannot return a valid VectorCoefficient. Use a " - "child class."); - } -}; diff --git a/include/coefficients/MFEMVectorConstantCoefficient.h b/include/coefficients/MFEMVectorConstantCoefficient.h deleted file mode 100644 index d87d279d..00000000 --- a/include/coefficients/MFEMVectorConstantCoefficient.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "MFEMVectorCoefficient.h" - -class MFEMVectorConstantCoefficient : public MFEMVectorCoefficient -{ -public: - static InputParameters validParams(); - - MFEMVectorConstantCoefficient(const InputParameters & parameters); - virtual ~MFEMVectorConstantCoefficient(); - - virtual std::shared_ptr getVectorCoefficient() const override - { - return _vector_coefficient; - } - -private: - const mfem::Vector _vector; - std::shared_ptr _vector_coefficient{nullptr}; -}; diff --git a/include/coefficients/MFEMVectorFunctionCoefficient.h b/include/coefficients/MFEMVectorFunctionCoefficient.h deleted file mode 100644 index 4b3389f7..00000000 --- a/include/coefficients/MFEMVectorFunctionCoefficient.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "MFEMVectorCoefficient.h" - -class MFEMVectorFunctionCoefficient : public MFEMVectorCoefficient -{ -public: - static InputParameters validParams(); - - MFEMVectorFunctionCoefficient(const InputParameters & parameters); - virtual ~MFEMVectorFunctionCoefficient(); - - std::shared_ptr getVectorCoefficient() const override - { - return _vector_coefficient; - } - -private: - std::shared_ptr _vector_coefficient{nullptr}; -}; diff --git a/src/actions/AddCoefficientAction.C b/src/actions/AddCoefficientAction.C deleted file mode 100644 index 2af5c381..00000000 --- a/src/actions/AddCoefficientAction.C +++ /dev/null @@ -1,24 +0,0 @@ -#include "AddCoefficientAction.h" - -registerMooseAction("PlatypusApp", AddCoefficientAction, "add_mfem_coefficients"); - -InputParameters -AddCoefficientAction::validParams() -{ - InputParameters params = MooseObjectAction::validParams(); - params.addClassDescription("Add a MFEM Coefficient object to the simulation."); - return params; -} - -AddCoefficientAction::AddCoefficientAction(const InputParameters & parameters) - : MooseObjectAction(parameters) -{ -} - -void -AddCoefficientAction::act() -{ - MFEMProblem * mfem_problem = dynamic_cast(_problem.get()); - if (mfem_problem) - mfem_problem->addCoefficient(_type, _name, _moose_object_pars); -} diff --git a/src/actions/AddVectorCoefficientAction.C b/src/actions/AddVectorCoefficientAction.C deleted file mode 100644 index 6abea3d7..00000000 --- a/src/actions/AddVectorCoefficientAction.C +++ /dev/null @@ -1,24 +0,0 @@ -#include "AddVectorCoefficientAction.h" - -registerMooseAction("PlatypusApp", AddVectorCoefficientAction, "add_mfem_coefficients"); - -InputParameters -AddVectorCoefficientAction::validParams() -{ - InputParameters params = MooseObjectAction::validParams(); - params.addClassDescription("Add a MFEM VectorCoefficient object to the simulation."); - return params; -} - -AddVectorCoefficientAction::AddVectorCoefficientAction(const InputParameters & parameters) - : MooseObjectAction(parameters) -{ -} - -void -AddVectorCoefficientAction::act() -{ - MFEMProblem * mfem_problem = dynamic_cast(_problem.get()); - if (mfem_problem) - mfem_problem->addVectorCoefficient(_type, _name, _moose_object_pars); -} diff --git a/src/coefficients/MFEMCoefficient.C b/src/coefficients/MFEMCoefficient.C deleted file mode 100644 index c05f285a..00000000 --- a/src/coefficients/MFEMCoefficient.C +++ /dev/null @@ -1,24 +0,0 @@ -#include "MFEMCoefficient.h" - -registerMooseObject("PlatypusApp", MFEMCoefficient); - -libMesh::Point -PointFromMFEMVector(const mfem::Vector & vec) -{ - return libMesh::Point(vec.Elem(0), vec.Elem(1), vec.Elem(2)); -} - -InputParameters -MFEMCoefficient::validParams() -{ - InputParameters params = MFEMGeneralUserObject::validParams(); - params.registerBase("MFEMCoefficient"); - return params; -} - -MFEMCoefficient::MFEMCoefficient(const InputParameters & parameters) - : MFEMGeneralUserObject(parameters) -{ -} - -MFEMCoefficient::~MFEMCoefficient() {} diff --git a/src/coefficients/MFEMConstantCoefficient.C b/src/coefficients/MFEMConstantCoefficient.C deleted file mode 100644 index 3bb68cdd..00000000 --- a/src/coefficients/MFEMConstantCoefficient.C +++ /dev/null @@ -1,21 +0,0 @@ -#include "MFEMConstantCoefficient.h" -#include "MFEMProblem.h" - -registerMooseObject("PlatypusApp", MFEMConstantCoefficient); - -InputParameters -MFEMConstantCoefficient::validParams() -{ - InputParameters params = MFEMCoefficient::validParams(); - params.addRequiredParam("value", "Value for the ConstantCoefficient"); - return params; -} - -MFEMConstantCoefficient::MFEMConstantCoefficient(const InputParameters & parameters) - : MFEMCoefficient(parameters), - coefficient{getMFEMProblem().getProblemData()._scalar_manager.make( - getParam("value"))} -{ -} - -MFEMConstantCoefficient::~MFEMConstantCoefficient() {} diff --git a/src/coefficients/MFEMFunctionCoefficient.C b/src/coefficients/MFEMFunctionCoefficient.C deleted file mode 100644 index 160a4dea..00000000 --- a/src/coefficients/MFEMFunctionCoefficient.C +++ /dev/null @@ -1,20 +0,0 @@ -#include "MFEMFunctionCoefficient.h" -#include "MFEMProblem.h" - -registerMooseObject("PlatypusApp", MFEMFunctionCoefficient); - -InputParameters -MFEMFunctionCoefficient::validParams() -{ - InputParameters params = MFEMCoefficient::validParams(); - params.addParam("function", 0, "The function to associated with the Dirichlet BC"); - return params; -} - -MFEMFunctionCoefficient::MFEMFunctionCoefficient(const InputParameters & parameters) - : MFEMCoefficient(parameters), - _coefficient(getMFEMProblem().getScalarFunctionCoefficient(getParam("function"))) -{ -} - -MFEMFunctionCoefficient::~MFEMFunctionCoefficient() {} diff --git a/src/coefficients/MFEMVectorCoefficient.C b/src/coefficients/MFEMVectorCoefficient.C deleted file mode 100644 index a89c432e..00000000 --- a/src/coefficients/MFEMVectorCoefficient.C +++ /dev/null @@ -1,18 +0,0 @@ -#include "MFEMVectorCoefficient.h" - -registerMooseObject("PlatypusApp", MFEMVectorCoefficient); - -InputParameters -MFEMVectorCoefficient::validParams() -{ - InputParameters params = MFEMGeneralUserObject::validParams(); - params.registerBase("MFEMVectorCoefficient"); - return params; -} - -MFEMVectorCoefficient::MFEMVectorCoefficient(const InputParameters & parameters) - : MFEMGeneralUserObject(parameters) -{ -} - -MFEMVectorCoefficient::~MFEMVectorCoefficient() {} diff --git a/src/coefficients/MFEMVectorConstantCoefficient.C b/src/coefficients/MFEMVectorConstantCoefficient.C deleted file mode 100644 index 3640b44e..00000000 --- a/src/coefficients/MFEMVectorConstantCoefficient.C +++ /dev/null @@ -1,26 +0,0 @@ -#include "MFEMVectorConstantCoefficient.h" -#include "MFEMProblem.h" - -registerMooseObject("PlatypusApp", MFEMVectorConstantCoefficient); - -InputParameters -MFEMVectorConstantCoefficient::validParams() -{ - InputParameters params = MFEMVectorCoefficient::validParams(); - params.addRequiredParam("value_x", "x component of the VectorConstantCoefficient"); - params.addRequiredParam("value_y", "y component of the VectorConstantCoefficient"); - params.addRequiredParam("value_z", "z component of the VectorConstantCoefficient"); - return params; -} - -MFEMVectorConstantCoefficient::MFEMVectorConstantCoefficient(const InputParameters & parameters) - : MFEMVectorCoefficient(parameters), - _vector( - {getParam("value_x"), getParam("value_y"), getParam("value_z")}), - _vector_coefficient{ - getMFEMProblem().getProblemData()._vector_manager.make( - _vector)} -{ -} - -MFEMVectorConstantCoefficient::~MFEMVectorConstantCoefficient() {} diff --git a/src/coefficients/MFEMVectorFunctionCoefficient.C b/src/coefficients/MFEMVectorFunctionCoefficient.C deleted file mode 100644 index 7de1e428..00000000 --- a/src/coefficients/MFEMVectorFunctionCoefficient.C +++ /dev/null @@ -1,21 +0,0 @@ -#include "MFEMVectorFunctionCoefficient.h" -#include "MFEMProblem.h" - -registerMooseObject("PlatypusApp", MFEMVectorFunctionCoefficient); - -InputParameters -MFEMVectorFunctionCoefficient::validParams() -{ - InputParameters params = MFEMVectorCoefficient::validParams(); - params.addParam("function", 0, "The function to associated with the Dirichlet BC"); - return params; -} - -MFEMVectorFunctionCoefficient::MFEMVectorFunctionCoefficient(const InputParameters & parameters) - : MFEMVectorCoefficient(parameters), - _vector_coefficient( - getMFEMProblem().getVectorFunctionCoefficient(getParam("function"))) -{ -} - -MFEMVectorFunctionCoefficient::~MFEMVectorFunctionCoefficient() {} From c753682bfe819ba6570b017eab3709a568fa1733 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 4 Nov 2024 17:26:59 +0000 Subject: [PATCH 02/24] Fixed failing tests to use new BCs --- test/tests/outputs/datacollections.i | 26 ++----------------- .../variables/mfem_variables_from_moose.i | 26 ++----------------- unit/src/MFEMIntegratedBCTest.C | 24 ++++++++--------- 3 files changed, 15 insertions(+), 61 deletions(-) diff --git a/test/tests/outputs/datacollections.i b/test/tests/outputs/datacollections.i index c70b5c73..6d02f6b3 100644 --- a/test/tests/outputs/datacollections.i +++ b/test/tests/outputs/datacollections.i @@ -23,29 +23,18 @@ [] [] -[Functions] - [value_bottom] - type = ParsedFunction - expression = 1.0 - [] - [value_top] - type = ParsedFunction - expression = 0.0 - [] -[] - [BCs] [bottom] type = MFEMScalarDirichletBC variable = diffused boundary = '1' - coefficient = BottomValue + value = 1.0 [] [low_terminal] type = MFEMScalarDirichletBC variable = diffused boundary = '2' - coefficient = TopValue + value = 0.0 [] [] @@ -57,17 +46,6 @@ [] [] -[Coefficients] - [TopValue] - type = MFEMFunctionCoefficient - function = value_top - [] - [BottomValue] - type = MFEMFunctionCoefficient - function = value_bottom - [] -[] - [Kernels] [diff] type = MFEMDiffusionKernel diff --git a/test/tests/variables/mfem_variables_from_moose.i b/test/tests/variables/mfem_variables_from_moose.i index 6ba30e76..e7fd9911 100644 --- a/test/tests/variables/mfem_variables_from_moose.i +++ b/test/tests/variables/mfem_variables_from_moose.i @@ -30,29 +30,18 @@ [] [] -[Functions] - [value_bottom] - type = ParsedFunction - expression = 1.0 - [] - [value_top] - type = ParsedFunction - expression = 0.0 - [] -[] - [BCs] [bottom] type = MFEMScalarDirichletBC variable = scalar_var boundary = '1' - coefficient = BottomValue + value = 1.0 [] [low_terminal] type = MFEMScalarDirichletBC variable = scalar_var boundary = '2' - coefficient = TopValue + value = 0.0 [] [] @@ -64,17 +53,6 @@ [] [] -[Coefficients] - [TopValue] - type = MFEMFunctionCoefficient - function = value_top - [] - [BottomValue] - type = MFEMFunctionCoefficient - function = value_bottom - [] -[] - [Kernels] [diff] type = MFEMDiffusionKernel diff --git a/unit/src/MFEMIntegratedBCTest.C b/unit/src/MFEMIntegratedBCTest.C index 50faa151..630f2c03 100644 --- a/unit/src/MFEMIntegratedBCTest.C +++ b/unit/src/MFEMIntegratedBCTest.C @@ -13,16 +13,10 @@ public: */ TEST_F(MFEMIntegratedBCTest, MFEMVectorNormalIntegratedBC) { - // Build required kernel inputs - InputParameters vec_coef_params = _factory.getValidParams("MFEMGenericConstantVectorMaterial"); - vec_coef_params.set>("prop_names") = {"vec_coef1"}; - vec_coef_params.set>("prop_values") = {1.0, 2.0, 3.0}; - _mfem_problem->addMaterial("MFEMGenericConstantVectorMaterial", "material1", vec_coef_params); - // Construct boundary condition InputParameters bc_params = _factory.getValidParams("MFEMVectorNormalIntegratedBC"); bc_params.set("variable") = "test_variable_name"; - bc_params.set("vector_coefficient") = "vec_coef1"; + bc_params.set>("values") = {1., 2., 3.}; bc_params.set>("boundary") = {"1"}; MFEMVectorNormalIntegratedBC & integrated_bc = addObject("MFEMVectorNormalIntegratedBC", "bc1", bc_params); @@ -44,16 +38,20 @@ TEST_F(MFEMIntegratedBCTest, MFEMVectorNormalIntegratedBC) TEST_F(MFEMIntegratedBCTest, MFEMConvectiveHeatFluxBC) { // Build required kernel inputs - InputParameters coef_params = _factory.getValidParams("MFEMGenericConstantMaterial"); - coef_params.set>("prop_names") = {"htc", "Tinf"}; - coef_params.set>("prop_values") = {1.0, 3.0}; - _mfem_problem->addMaterial("MFEMGenericConstantMaterial", "material1", coef_params); + InputParameters htc_params = _factory.getValidParams("ParsedFunction"); + htc_params.set("expression") = "1.0"; + _mfem_problem->addFunction("ParsedFunction", "htc", htc_params); + _mfem_problem->getFunction("htc").initialSetup(); + InputParameters Tinf_params = _factory.getValidParams("ParsedFunction"); + Tinf_params.set("expression") = "3.0"; + _mfem_problem->addFunction("ParsedFunction", "Tinf", Tinf_params); + _mfem_problem->getFunction("Tinf").initialSetup(); // Construct boundary condition InputParameters bc_params = _factory.getValidParams("MFEMConvectiveHeatFluxBC"); bc_params.set("variable") = "test_variable_name"; - bc_params.set("heat_transfer_coefficient") = "htc"; - bc_params.set("T_infinity") = "Tinf"; + bc_params.set("heat_transfer_coefficient") = "htc"; + bc_params.set("T_infinity") = "Tinf"; bc_params.set>("boundary") = {"1"}; MFEMConvectiveHeatFluxBC & integrated_bc = addObject("MFEMConvectiveHeatFluxBC", "bc1", bc_params); From 11098c28d4945acf99d377b693387e774ba4706c Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Tue, 5 Nov 2024 11:56:17 +0000 Subject: [PATCH 03/24] Stop trying to register actions to add coefficients --- src/base/PlatypusApp.C | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/base/PlatypusApp.C b/src/base/PlatypusApp.C index 0bd90620..c509c84c 100644 --- a/src/base/PlatypusApp.C +++ b/src/base/PlatypusApp.C @@ -32,20 +32,6 @@ associateSyntaxInner(Syntax & syntax, ActionFactory & /*action_factory*/) addTaskDependency("add_elemental_field_variable", "add_mfem_problem_operator"); addTaskDependency("add_kernel", "add_mfem_problem_operator"); - // add coefficients - 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"); - addTaskDependency("add_mfem_coefficients", "add_ic"); - - // add vector coefficients - registerMooseObjectTask("add_mfem_vector_coefficients", MFEMVectorCoefficient, false); - registerSyntaxTask( - "AddVectorCoefficientAction", "VectorCoefficients/*", "add_mfem_vector_coefficients"); - addTaskDependency("add_material", "add_mfem_vector_coefficients"); - // add FESpaces registerMooseObjectTask("add_mfem_fespaces", MFEMFESpace, false); appendMooseObjectTask("add_mfem_fespaces", MFEMFECollection); From e9156093983bdcad9d0bbee03ed8efde424255b6 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Tue, 5 Nov 2024 13:24:23 +0000 Subject: [PATCH 04/24] Added tests for new integrated BCs --- unit/src/MFEMIntegratedBCTest.C | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/unit/src/MFEMIntegratedBCTest.C b/unit/src/MFEMIntegratedBCTest.C index f042e26c..4aec25ea 100644 --- a/unit/src/MFEMIntegratedBCTest.C +++ b/unit/src/MFEMIntegratedBCTest.C @@ -1,6 +1,8 @@ #include "MFEMObjectUnitTest.h" #include "MFEMVectorBoundaryIntegratedBC.h" #include "MFEMVectorNormalIntegratedBC.h" +#include "MFEMVectorFunctionBoundaryIntegratedBC.h" +#include "MFEMVectorFunctionNormalIntegratedBC.h" #include "MFEMConvectiveHeatFluxBC.h" class MFEMIntegratedBCTest : public MFEMObjectUnitTest @@ -33,6 +35,36 @@ TEST_F(MFEMIntegratedBCTest, MFEMVectorNormalIntegratedBC) delete blf_integrator; } +/** + * Test MFEMVectorNormalIntegratedBC creates an mfem::BoundaryNormalLFIntegrator successfully. + */ +TEST_F(MFEMIntegratedBCTest, MFEMVectorFunctionNormalIntegratedBC) +{ + // Construct boundary condition + InputParameters func_params = _factory.getValidParams("ParsedVectorFunction"); + func_params.set("expression_x") = "x + y"; + func_params.set("expression_y") = "x + y + 1"; + func_params.set("expression_z") = "x + y + 2"; + _mfem_problem->addFunction("ParsedVectorFunction", "func1", func_params); + InputParameters bc_params = _factory.getValidParams("MFEMVectorFunctionNormalIntegratedBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set("function") = "func1"; + bc_params.set>("boundary") = {"1"}; + MFEMVectorFunctionNormalIntegratedBC & integrated_bc = + addObject( + "MFEMVectorFunctionNormalIntegratedBC", "bc1", bc_params); + + // Test MFEMVectorNormalIntegratedBC returns an integrator of the expected type + auto lf_integrator = + dynamic_cast(integrated_bc.createLinearFormIntegrator()); + ASSERT_NE(lf_integrator, nullptr); + delete lf_integrator; + + auto blf_integrator = integrated_bc.createBilinearFormIntegrator(); + ASSERT_EQ(blf_integrator, nullptr); + delete blf_integrator; +} + /** * Test MFEMConvectiveHeatFluxBC creates the expected mfem::BoundaryIntegrators successfully. */ @@ -90,3 +122,31 @@ TEST_F(MFEMIntegratedBCTest, MFEMVectorBoundaryIntegratedBC) ASSERT_EQ(blf_integrator, nullptr); delete blf_integrator; } + +TEST_F(MFEMIntegratedBCTest, MFEMVectorFunctionBoundaryIntegratedBC) +{ + // Build required BC inputs + + // Construct boundary condition + InputParameters func_params = _factory.getValidParams("ParsedVectorFunction"); + func_params.set("expression_x") = "x + y"; + func_params.set("expression_y") = "x + y + 1"; + func_params.set("expression_z") = "x + y + 2"; + _mfem_problem->addFunction("ParsedVectorFunction", "func1", func_params); + InputParameters bc_params = _factory.getValidParams("MFEMVectorFunctionBoundaryIntegratedBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set>("boundary") = {"1"}; + bc_params.set("function") = "func1"; + auto & bc = addObject( + "MFEMVectorFunctionBoundaryIntegratedBC", "bc1", bc_params); + + // Test MFEMVectorBoundaryIntegratedBC returns an integrator of the expected type + auto lf_integrator = + dynamic_cast(bc.createLinearFormIntegrator()); + ASSERT_NE(lf_integrator, nullptr); + delete lf_integrator; + + auto blf_integrator = bc.createBilinearFormIntegrator(); + ASSERT_EQ(blf_integrator, nullptr); + delete blf_integrator; +} From 9391d2c55cbfb40744b0e56b8d7b61720a4a976d Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Wed, 6 Nov 2024 10:35:13 +0000 Subject: [PATCH 05/24] Add tests for Dirichlet boundaries --- unit/src/MFEMEssentialBCTest.C | 157 ++++++++++++++++++++++++++++++++ unit/src/MFEMIntegratedBCTest.C | 6 +- 2 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 unit/src/MFEMEssentialBCTest.C diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C new file mode 100644 index 00000000..94a3723b --- /dev/null +++ b/unit/src/MFEMEssentialBCTest.C @@ -0,0 +1,157 @@ +#include "MFEMObjectUnitTest.h" +#include "MFEMScalarDirichletBC.h" +#include "MFEMScalarFunctionDirichletBC.h" +#include "MFEMVectorDirichletBC.h" +#include "MFEMVectorFunctionDirichletBC.h" +#include "MFEMVectorTangentialDirichletBC.h" +#include "MFEMVectorFunctionTangentialDirichletBC.h" + +class MFEMEssentialBCTest : public MFEMObjectUnitTest +{ +public: + mfem::LinearFECollection _fec; + mfem::FiniteElementSpace _fes; + mfem::GridFunction _gridfunc; + + MFEMEssentialBCTest() + : MFEMObjectUnitTest("PlatypusApp"), + _fec(), + _fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), &_fec), + _gridfunc(&_fes) + { + InputParameters func_params = _factory.getValidParams("ParsedFunction"); + func_params.set("expression") = "x + y"; + _mfem_problem->addFunction("ParsedFunction", "func1", func_params); + _mfem_problem->getFunction("func1").initialSetup(); + InputParameters vecfunc_params = _factory.getValidParams("ParsedVectorFunction"); + vecfunc_params.set("expression_x") = "x + y"; + vecfunc_params.set("expression_y") = "x + y + 1"; + vecfunc_params.set("expression_z") = "x + y + 2"; + _mfem_problem->addFunction("ParsedVectorFunction", "func2", vecfunc_params); + _mfem_problem->getFunction("func2").initialSetup(); + } +}; + +/** + * Test MFEMScalarDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMScalarDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMScalarDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set("value") = 1.; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = addObject("MFEMScalarDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // FIXME: We should actually check this applies the right boundary values... +} + +/** + * Test MFEMScalarFunctionDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMScalarFunctionDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMScalarFunctionDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set("function") = "func1"; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = + addObject("MFEMScalarFunctionDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // FIXME: We should actually check this applies the right boundary values... +} + +/** + * Test MFEMVectorDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMVectorDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set>("values") = {1., 2., 3.}; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = addObject("MFEMVectorDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // FIXME: We should actually check this applies the right boundary values... +} + +/** + * Test MFEMVectorFunctionDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMVectorFunctionDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set("function") = "func2"; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = + addObject("MFEMVectorFunctionDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // FIXME: We should actually check this applies the right boundary values... +} + +/** + * Test MFEMVectorTangentialDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMVectorTangentialDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set>("values") = {1., 2., 3.}; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = addObject( + "MFEMVectorTangentialDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // FIXME: We should actually check this applies the right boundary values... +} + +/** + * Test MFEMVectorFunctionDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMVectorFunctionTangentialDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set("function") = "func2"; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = addObject( + "MFEMVectorFunctionTangentialDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // FIXME: We should actually check this applies the right boundary values... +} diff --git a/unit/src/MFEMIntegratedBCTest.C b/unit/src/MFEMIntegratedBCTest.C index 4aec25ea..83db3ce8 100644 --- a/unit/src/MFEMIntegratedBCTest.C +++ b/unit/src/MFEMIntegratedBCTest.C @@ -102,8 +102,6 @@ TEST_F(MFEMIntegratedBCTest, MFEMConvectiveHeatFluxBC) TEST_F(MFEMIntegratedBCTest, MFEMVectorBoundaryIntegratedBC) { - // Build required BC inputs - // Construct boundary condition InputParameters bc_params = _factory.getValidParams("MFEMVectorBoundaryIntegratedBC"); bc_params.set("variable") = "test_variable_name"; @@ -126,13 +124,13 @@ TEST_F(MFEMIntegratedBCTest, MFEMVectorBoundaryIntegratedBC) TEST_F(MFEMIntegratedBCTest, MFEMVectorFunctionBoundaryIntegratedBC) { // Build required BC inputs - - // Construct boundary condition InputParameters func_params = _factory.getValidParams("ParsedVectorFunction"); func_params.set("expression_x") = "x + y"; func_params.set("expression_y") = "x + y + 1"; func_params.set("expression_z") = "x + y + 2"; _mfem_problem->addFunction("ParsedVectorFunction", "func1", func_params); + + // Construct boundary condition InputParameters bc_params = _factory.getValidParams("MFEMVectorFunctionBoundaryIntegratedBC"); bc_params.set("variable") = "test_variable_name"; bc_params.set>("boundary") = {"1"}; From 3de4386f593064c8976e01e17b80b2aa170ea99e Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Fri, 8 Nov 2024 14:05:40 +0000 Subject: [PATCH 06/24] Fixed segfaults for vector BC tests --- unit/src/MFEMEssentialBCTest.C | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 94a3723b..f4ce9b70 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -1,3 +1,4 @@ +#include "mfem-common.hpp" #include "MFEMObjectUnitTest.h" #include "MFEMScalarDirichletBC.h" #include "MFEMScalarFunctionDirichletBC.h" @@ -9,15 +10,16 @@ class MFEMEssentialBCTest : public MFEMObjectUnitTest { public: - mfem::LinearFECollection _fec; - mfem::FiniteElementSpace _fes; - mfem::GridFunction _gridfunc; + mfem::common::H1_FESpace _scalar_fes; + mfem::common::ND_FESpace _vector_fes; + mfem::GridFunction _scalar_gridfunc, _vector_gridfunc; MFEMEssentialBCTest() : MFEMObjectUnitTest("PlatypusApp"), - _fec(), - _fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), &_fec), - _gridfunc(&_fes) + _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), + _vector_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), + _scalar_gridfunc(&_scalar_fes), + _vector_gridfunc(&_vector_fes) { InputParameters func_params = _factory.getValidParams("ParsedFunction"); func_params.set("expression") = "x + y"; @@ -48,7 +50,7 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // FIXME: We should actually check this applies the right boundary values... } @@ -69,7 +71,7 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarFunctionDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // FIXME: We should actually check this applies the right boundary values... } @@ -89,7 +91,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // FIXME: We should actually check this applies the right boundary values... } @@ -110,7 +112,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // FIXME: We should actually check this applies the right boundary values... } @@ -131,7 +133,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // FIXME: We should actually check this applies the right boundary values... } @@ -152,6 +154,6 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // FIXME: We should actually check this applies the right boundary values... } From c7d23749de05815f6b893724566ec8119f8e280d Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Fri, 15 Nov 2024 17:11:32 +0000 Subject: [PATCH 07/24] Add an example test for checking MFEMScalarDirichletBC has set the gridfunction values on the boundary. --- unit/src/MFEMEssentialBCTest.C | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index f4ce9b70..2741e578 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -51,7 +51,15 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarDirichletBC) // Test applying the BC essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - // FIXME: We should actually check this applies the right boundary values... + + // Check the correct boundary values have been applied + mfem::Array ess_vdofs_list, ess_vdofs_marker; + _scalar_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker); + _scalar_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); + for (auto ess_dof : ess_vdofs_list) + { + EXPECT_EQ(_scalar_gridfunc[ess_dof], bc_params.get("value")); + } } /** @@ -72,6 +80,8 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarFunctionDirichletBC) // Test applying the BC essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + // FIXME: We should actually check this applies the right boundary values... } From 1c6eef37c6691a992665b082322f9de787e7bb67 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Fri, 15 Nov 2024 17:14:23 +0000 Subject: [PATCH 08/24] Remove duplicated check on the test variable name in MFEMEssentialBCTest.MFEMScalarFunctionDirichletBC --- unit/src/MFEMEssentialBCTest.C | 2 -- 1 file changed, 2 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 2741e578..ee34df81 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -80,8 +80,6 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarFunctionDirichletBC) // Test applying the BC essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); - // FIXME: We should actually check this applies the right boundary values... } From d85c883b0e97ab0f768d782cce1f8a32358c12b4 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Wed, 11 Dec 2024 14:45:20 +0000 Subject: [PATCH 09/24] Added first attempt to test Vector BCs --- unit/src/MFEMEssentialBCTest.C | 38 +++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index ee34df81..455c369c 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -11,13 +11,16 @@ class MFEMEssentialBCTest : public MFEMObjectUnitTest { public: mfem::common::H1_FESpace _scalar_fes; - mfem::common::ND_FESpace _vector_fes; + // mfem::common::ND_FESpace _vector_fes; + mfem::common::H1_FESpace _vector_fes; mfem::GridFunction _scalar_gridfunc, _vector_gridfunc; MFEMEssentialBCTest() : MFEMObjectUnitTest("PlatypusApp"), _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), - _vector_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), + // _vector_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), + _vector_fes( + _mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, mfem::BasisType::GaussLobatto, 3), _scalar_gridfunc(&_scalar_fes), _vector_gridfunc(&_vector_fes) { @@ -56,9 +59,10 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarDirichletBC) mfem::Array ess_vdofs_list, ess_vdofs_marker; _scalar_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker); _scalar_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); + const Real expected = bc_params.get("value"); for (auto ess_dof : ess_vdofs_list) { - EXPECT_EQ(_scalar_gridfunc[ess_dof], bc_params.get("value")); + EXPECT_EQ(_scalar_gridfunc[ess_dof], expected); } } @@ -100,7 +104,19 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) // Test applying the BC essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - // FIXME: We should actually check this applies the right boundary values... + // Check the correct boundary values have been applied + mfem::Array ess_vdofs_list, ess_vdofs_marker; + const std::vector expected = bc_params.get>("values"); + for (int i = 0; i < 3; i++) + { + _vector_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker, i); + _vector_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); + for (auto ess_dof : ess_vdofs_list) + { + std::cout << "Index: " << ess_dof << std::endl; + EXPECT_EQ(_vector_gridfunc[ess_dof], expected[i]); + } + } } /** @@ -142,7 +158,19 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) // Test applying the BC essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - // FIXME: We should actually check this applies the right boundary values... + // Check the correct boundary values have been applied + mfem::Array ess_vdofs_list, ess_vdofs_marker; + const std::vector expected = bc_params.get>("values"); + for (int i = 0; i < 3; i++) + { + _vector_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker, i); + _vector_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); + for (auto ess_dof : ess_vdofs_list) + { + std::cout << "Index: " << ess_dof << std::endl; + EXPECT_EQ(_vector_gridfunc[ess_dof], expected[i]); + } + } } /** From e50ddf24b56cebbd1deb957feab5e4493c16bc1a Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Wed, 11 Dec 2024 15:36:57 +0000 Subject: [PATCH 10/24] Added docs and a function version of vector normal Dirichlet BC --- .../source/bcs/MFEMScalarDirichletBC.md | 2 +- .../bcs/MFEMScalarFunctionDirichletBC.C | 24 +++++++++++++++++++ .../bcs/MFEMVectorBoundaryIntegratedBC.md | 2 +- .../source/bcs/MFEMVectorDirichletBC.md | 2 +- .../source/bcs/MFEMVectorDirichletBCBase.md | 3 ++- .../MFEMVectorFunctionBoundaryIntegratedBC.md | 22 +++++++++++++++++ .../bcs/MFEMVectorFunctionDirichletBC.md | 20 ++++++++++++++++ .../bcs/MFEMVectorFunctionDirichletBCBase.md | 11 +++++++++ .../MFEMVectorFunctionNormalDirichletBC.md | 21 ++++++++++++++++ .../MFEMVectorFunctionNormalIntegratedBC.md | 21 ++++++++++++++++ ...MFEMVectorFunctionTangentialDirichletBC.md | 21 ++++++++++++++++ .../source/bcs/MFEMVectorNormalDirichletBC.md | 5 ++-- .../bcs/MFEMVectorNormalIntegratedBC.md | 2 +- .../bcs/MFEMVectorTangentialDirichletBC.md | 5 ++-- 14 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C create mode 100644 doc/content/source/bcs/MFEMVectorFunctionBoundaryIntegratedBC.md create mode 100644 doc/content/source/bcs/MFEMVectorFunctionDirichletBC.md create mode 100644 doc/content/source/bcs/MFEMVectorFunctionDirichletBCBase.md create mode 100644 doc/content/source/bcs/MFEMVectorFunctionNormalDirichletBC.md create mode 100644 doc/content/source/bcs/MFEMVectorFunctionNormalIntegratedBC.md create mode 100644 doc/content/source/bcs/MFEMVectorFunctionTangentialDirichletBC.md diff --git a/doc/content/source/bcs/MFEMScalarDirichletBC.md b/doc/content/source/bcs/MFEMScalarDirichletBC.md index 8d34e109..81b8bc63 100644 --- a/doc/content/source/bcs/MFEMScalarDirichletBC.md +++ b/doc/content/source/bcs/MFEMScalarDirichletBC.md @@ -7,7 +7,7 @@ ## Overview Boundary condition for enforcing an essential (Dirichlet) condition on a scalar variable on the -boundary, fixing its values to the input scalar coefficient on the boundary. +boundary, fixing its values to the input on the boundary. ## Example Input File Syntax diff --git a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C new file mode 100644 index 00000000..cc509772 --- /dev/null +++ b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C @@ -0,0 +1,24 @@ +#MFEMScalarFunctionDirichletBC + +## Summary + +!syntax description /BCs/MFEMScalarFunctionDirichletBC + +## Overview + +Boundary condition for enforcing an essential (Dirichlet) +condition on a scalar variable on the boundary, + fixing its values to the input scalar function on the boundary. + + ##Example Input File Syntax + + !syntax parameters / + BCs / + MFEMScalarFunctionDirichletBC + + !syntax inputs / + BCs / + MFEMScalarFunctionDirichletBC + + !syntax children / + BCs / MFEMScalarFunctionDirichletBC diff --git a/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md b/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md index 22e3aca1..dd04b33e 100644 --- a/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md +++ b/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md @@ -11,7 +11,7 @@ Adds the boundary integrator for integrating the linear form !equation (\vec f, \vec v)_{\partial\Omega} \,\,\, \forall \vec v \in V -where $v \in \vec H^1$ and $\vec f$ is a vector coefficient of the same dimension. +where $v \in \vec H^1$ and $\vec f$ is a constant vector of the same dimension. ## Example Input File Syntax diff --git a/doc/content/source/bcs/MFEMVectorDirichletBC.md b/doc/content/source/bcs/MFEMVectorDirichletBC.md index 1a8e92fb..ca16cbb4 100644 --- a/doc/content/source/bcs/MFEMVectorDirichletBC.md +++ b/doc/content/source/bcs/MFEMVectorDirichletBC.md @@ -7,7 +7,7 @@ ## Overview Boundary condition for enforcing an essential (Dirichlet) boundary condition on all components of a -vector $H^1$ conforming variable on the boundary. +vector $H^1$ conforming variable on the boundary. The boundary value is constant in space and time. ## Example Input File Syntax diff --git a/doc/content/source/bcs/MFEMVectorDirichletBCBase.md b/doc/content/source/bcs/MFEMVectorDirichletBCBase.md index b46d1a93..6a2939cf 100644 --- a/doc/content/source/bcs/MFEMVectorDirichletBCBase.md +++ b/doc/content/source/bcs/MFEMVectorDirichletBCBase.md @@ -8,4 +8,5 @@ Base class for objects applying essential boundary conditions on vector variable Classes deriving from `MFEMVectorDirichletBCBase` are used for the application of Dirichlet-like BCs that remove degrees of freedom from vector variables in the problem on the specified boundary. These are commonly used when -strongly constraining the values a solution may take on boundaries. +strongly constraining the values a solution may take on boundaries. The imposed values are uniform in space and constant +in time. diff --git a/doc/content/source/bcs/MFEMVectorFunctionBoundaryIntegratedBC.md b/doc/content/source/bcs/MFEMVectorFunctionBoundaryIntegratedBC.md new file mode 100644 index 00000000..3e581f8e --- /dev/null +++ b/doc/content/source/bcs/MFEMVectorFunctionBoundaryIntegratedBC.md @@ -0,0 +1,22 @@ +# MFEMVectorFunctionBoundaryIntegratedBC + +## Summary + +!syntax description /BCs/MFEMVectorFunctionBoundaryIntegratedBC + +## Overview + +Adds the boundary integrator for integrating the linear form + +!equation +(\vec f, \vec v)_{\partial\Omega} \,\,\, \forall \vec v \in V + +where $v \in \vec H^1$ and $\vec f$ is a vector function of the same dimension. + +## Example Input File Syntax + +!syntax parameters /BCs/MFEMVectorFunctionBoundaryIntegratedBC + +!syntax inputs /BCs/MFEMVectorFunctionBoundaryIntegratedBC + +!syntax children /BCs/MFEMVectorFunctionBoundaryIntegratedBC diff --git a/doc/content/source/bcs/MFEMVectorFunctionDirichletBC.md b/doc/content/source/bcs/MFEMVectorFunctionDirichletBC.md new file mode 100644 index 00000000..c755682f --- /dev/null +++ b/doc/content/source/bcs/MFEMVectorFunctionDirichletBC.md @@ -0,0 +1,20 @@ +# MFEMVectorFunctionDirichletBC + +## Summary + +!syntax description /BCs/MFEMVectorFunctionDirichletBC + +## Overview + +Boundary condition for enforcing an essential (Dirichlet) boundary condition on all components of a +vector $H^1$ conforming variable on the boundary. The boundary value is a function of space and/or time. + +## Example Input File Syntax + +!listing test/tests/kernels/linearelasticity.i block=BCs + +!syntax parameters /BCs/MFEMVectorFunctionDirichletBC + +!syntax inputs /BCs/MFEMVectorFunctionDirichletBC + +!syntax children /BCs/MFEMVectorFunctionDirichletBC diff --git a/doc/content/source/bcs/MFEMVectorFunctionDirichletBCBase.md b/doc/content/source/bcs/MFEMVectorFunctionDirichletBCBase.md new file mode 100644 index 00000000..7d9221ed --- /dev/null +++ b/doc/content/source/bcs/MFEMVectorFunctionDirichletBCBase.md @@ -0,0 +1,11 @@ +# MFEMVectorFunctionDirichletBCBase + +## Summary + +Base class for objects applying essential boundary conditions on vector variables in an MFEM FE problem. + +## Overview + +Classes deriving from `MFEMVectorFunctionDirichletBCBase` are used for the application of Dirichlet-like BCs that +remove degrees of freedom from vector variables in the problem on the specified boundary. These are commonly used when +strongly constraining the values a solution may take on boundaries. The imposed values may vary in space and/or time. diff --git a/doc/content/source/bcs/MFEMVectorFunctionNormalDirichletBC.md b/doc/content/source/bcs/MFEMVectorFunctionNormalDirichletBC.md new file mode 100644 index 00000000..fc30dfb4 --- /dev/null +++ b/doc/content/source/bcs/MFEMVectorFunctionNormalDirichletBC.md @@ -0,0 +1,21 @@ +# MFEMVectorFunctionNormalDirichletBC + +## Summary + +!syntax description /BCs/MFEMVectorFunctionNormalDirichletBC + +## Overview + +Boundary condition for enforcing an essential (Dirichlet) boundary condition on the normal +components of a $H(\mathrm{div})$ conforming vector FE at a boundary. The imposed value is +a function of space and/or time. + +## Example Input File Syntax + +!listing test/tests/kernels/graddiv.i block=BCs + +!syntax parameters /BCs/MFEMVectorFunctionNormalDirichletBC + +!syntax inputs /BCs/MFEMVectorFunctionNormalDirichletBC + +!syntax children /BCs/MFEMVectorFunctionNormalDirichletBC diff --git a/doc/content/source/bcs/MFEMVectorFunctionNormalIntegratedBC.md b/doc/content/source/bcs/MFEMVectorFunctionNormalIntegratedBC.md new file mode 100644 index 00000000..7c5a584f --- /dev/null +++ b/doc/content/source/bcs/MFEMVectorFunctionNormalIntegratedBC.md @@ -0,0 +1,21 @@ +# MFEMVectorFunctionNormalIntegratedBC + +## Summary + +!syntax description /BCs/MFEMVectorFunctionNormalIntegratedBC + +## Overview + +Adds the boundary integrator for integrating the linear form + +!equation +(\vec f \cdot \hat n, v)_{\partial\Omega} \,\,\, \forall v \in V + +where $v \in H^1$, $\vec f$ is a vector function, and $\hat n$ is the outward facing unit normal +vector on the boundary. + +!syntax parameters /BCs/MFEMVectorFunctionNormalIntegratedBC + +!syntax inputs /BCs/MFEMVectorFunctionNormalIntegratedBC + +!syntax children /BCs/MFEMVectorFunctionNormalIntegratedBC diff --git a/doc/content/source/bcs/MFEMVectorFunctionTangentialDirichletBC.md b/doc/content/source/bcs/MFEMVectorFunctionTangentialDirichletBC.md new file mode 100644 index 00000000..bf283281 --- /dev/null +++ b/doc/content/source/bcs/MFEMVectorFunctionTangentialDirichletBC.md @@ -0,0 +1,21 @@ +# MFEMVectorFunctionTangentialDirichletBC + +## Summary + +!syntax description /BCs/MFEMVectorFunctionTangentialDirichletBC + +## Overview + +Boundary condition for enforcing an essential (Dirichlet) boundary condition on the tangential +components of a $H(\mathrm{curl})$ conforming vector FE at a boundary. The boundary value is +a function of space and/or time. + +## Example Input File Syntax + +!listing test/tests/kernels/curlcurl.i block=BCs + +!syntax parameters /BCs/MFEMVectorFunctionTangentialDirichletBC + +!syntax inputs /BCs/MFEMVectorFunctionTangentialDirichletBC + +!syntax children /BCs/MFEMVectorFunctionTangentialDirichletBC diff --git a/doc/content/source/bcs/MFEMVectorNormalDirichletBC.md b/doc/content/source/bcs/MFEMVectorNormalDirichletBC.md index 317bb642..8baf0e48 100644 --- a/doc/content/source/bcs/MFEMVectorNormalDirichletBC.md +++ b/doc/content/source/bcs/MFEMVectorNormalDirichletBC.md @@ -7,12 +7,11 @@ ## Overview Boundary condition for enforcing an essential (Dirichlet) boundary condition on the normal -components of a $H(\mathrm{div})$ conforming vector FE at a boundary. +components of a $H(\mathrm{div})$ conforming vector FE at a boundary. The imposed value is +constant in space and time. ## Example Input File Syntax -!listing test/tests/kernels/graddiv.i block=BCs - !syntax parameters /BCs/MFEMVectorNormalDirichletBC !syntax inputs /BCs/MFEMVectorNormalDirichletBC diff --git a/doc/content/source/bcs/MFEMVectorNormalIntegratedBC.md b/doc/content/source/bcs/MFEMVectorNormalIntegratedBC.md index eb3a97d5..2be8a43b 100644 --- a/doc/content/source/bcs/MFEMVectorNormalIntegratedBC.md +++ b/doc/content/source/bcs/MFEMVectorNormalIntegratedBC.md @@ -11,7 +11,7 @@ Adds the boundary integrator for integrating the linear form !equation (\vec f \cdot \hat n, v)_{\partial\Omega} \,\,\, \forall v \in V -where $v \in H^1$, $\vec f$ is a vector coefficient, and $\hat n$ is the outward facing unit normal +where $v \in H^1$, $\vec f$ is a vector value, and $\hat n$ is the outward facing unit normal vector on the boundary. !syntax parameters /BCs/MFEMVectorNormalIntegratedBC diff --git a/doc/content/source/bcs/MFEMVectorTangentialDirichletBC.md b/doc/content/source/bcs/MFEMVectorTangentialDirichletBC.md index 8ef1f967..6d10093c 100644 --- a/doc/content/source/bcs/MFEMVectorTangentialDirichletBC.md +++ b/doc/content/source/bcs/MFEMVectorTangentialDirichletBC.md @@ -7,12 +7,11 @@ ## Overview Boundary condition for enforcing an essential (Dirichlet) boundary condition on the tangential -components of a $H(\mathrm{curl})$ conforming vector FE at a boundary. +components of a $H(\mathrm{curl})$ conforming vector FE at a boundary. The boundary value is +constant in space and time. ## Example Input File Syntax -!listing test/tests/kernels/curlcurl.i block=BCs - !syntax parameters /BCs/MFEMVectorTangentialDirichletBC !syntax inputs /BCs/MFEMVectorTangentialDirichletBC From 681df353478a774f2eab11ca810d66f1b42a8daa Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Wed, 11 Dec 2024 18:50:37 +0000 Subject: [PATCH 11/24] Fixed compile bug in normal dirichlet BCs --- unit/src/MFEMEssentialBCTest.C | 1 - 1 file changed, 1 deletion(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 455c369c..9f6e7d57 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -113,7 +113,6 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) _vector_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); for (auto ess_dof : ess_vdofs_list) { - std::cout << "Index: " << ess_dof << std::endl; EXPECT_EQ(_vector_gridfunc[ess_dof], expected[i]); } } From 019a43df01203f6d503fb76ba46db9682d28a9b5 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Fri, 13 Dec 2024 19:29:03 +0000 Subject: [PATCH 12/24] Rewrote how I check BCs, but still broken for some of them --- unit/src/MFEMEssentialBCTest.C | 261 ++++++++++++++++++++++++++++----- 1 file changed, 223 insertions(+), 38 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 9f6e7d57..8ef5e76d 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -4,6 +4,8 @@ #include "MFEMScalarFunctionDirichletBC.h" #include "MFEMVectorDirichletBC.h" #include "MFEMVectorFunctionDirichletBC.h" +#include "MFEMVectorNormalDirichletBC.h" +#include "MFEMVectorFunctionNormalDirichletBC.h" #include "MFEMVectorTangentialDirichletBC.h" #include "MFEMVectorFunctionTangentialDirichletBC.h" @@ -11,18 +13,22 @@ class MFEMEssentialBCTest : public MFEMObjectUnitTest { public: mfem::common::H1_FESpace _scalar_fes; - // mfem::common::ND_FESpace _vector_fes; + // mfem::common::ND_FESpace _vector_fes; mfem::common::H1_FESpace _vector_fes; mfem::GridFunction _scalar_gridfunc, _vector_gridfunc; + mfem::ConstantCoefficient _scalar_zero; + mfem::VectorConstantCoefficient _vector_zero; MFEMEssentialBCTest() : MFEMObjectUnitTest("PlatypusApp"), _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), - // _vector_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), + //_vector_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), _vector_fes( _mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, mfem::BasisType::GaussLobatto, 3), _scalar_gridfunc(&_scalar_fes), - _vector_gridfunc(&_vector_fes) + _vector_gridfunc(&_vector_fes), + _scalar_zero(0.), + _vector_zero(mfem::Vector({0., 0., 0.})) { InputParameters func_params = _factory.getValidParams("ParsedFunction"); func_params.set("expression") = "x + y"; @@ -34,6 +40,42 @@ public: vecfunc_params.set("expression_z") = "x + y + 2"; _mfem_problem->addFunction("ParsedVectorFunction", "func2", vecfunc_params); _mfem_problem->getFunction("func2").initialSetup(); + _scalar_gridfunc.ProjectCoefficient(_scalar_zero); + _vector_gridfunc.ProjectCoefficient(_vector_zero); + } + + void check_boundary(int bound, + std::function error_func, + double tolerance) + { + for (int be = 0; be < _mfem_mesh_ptr->getMFEMParMeshPtr()->GetNBE(); be++) + { + mfem::Element * elem = _mfem_mesh_ptr->getMFEMParMeshPtr()->GetBdrElement(be); + if (elem->GetAttribute() != 1) + continue; + mfem::ElementTransformation * transform = + _mfem_mesh_ptr->getMFEMParMeshPtr()->GetBdrElementTransformation(be); + const mfem::FiniteElement * fe = _scalar_fes.GetBE(be); + const mfem::IntegrationRule & ir = + mfem::IntRules.Get(fe->GetGeomType(), 2 * fe->GetOrder() + 2); + double total_error = 0.0; + for (int j = 0; j < ir.GetNPoints(); j++) + { + const mfem::IntegrationPoint point = ir.IntPoint(j); + transform->SetIntPoint(&point); + const double error = error_func(transform, point); + total_error += error * error; + } + EXPECT_LT(total_error, tolerance); + } + } + + mfem::Vector calc_normal(mfem::ElementTransformation * transform) const + { + mfem::Vector normal(3); + mfem::CalcOrtho(transform->Jacobian(), normal); + return normal; } }; @@ -56,14 +98,13 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarDirichletBC) essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::Array ess_vdofs_list, ess_vdofs_marker; - _scalar_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker); - _scalar_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); - const Real expected = bc_params.get("value"); - for (auto ess_dof : ess_vdofs_list) - { - EXPECT_EQ(_scalar_gridfunc[ess_dof], expected); - } + mfem::GridFunctionCoefficient scalar_variable(&_scalar_gridfunc); + check_boundary( + 1, + [&scalar_variable](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { return scalar_variable.Eval(*transform, point) - 1.; }, + 1e-8); } /** @@ -84,7 +125,17 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarFunctionDirichletBC) // Test applying the BC essential_bc.ApplyBC(_scalar_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - // FIXME: We should actually check this applies the right boundary values... + + // Check the correct boundary values have been applied + mfem::GridFunctionCoefficient scalar_variable(&_scalar_gridfunc); + std::shared_ptr expected = + _mfem_problem->getScalarFunctionCoefficient("func1"); + check_boundary( + 1, + [&scalar_variable, expected](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { return scalar_variable.Eval(*transform, point) - expected->Eval(*transform, point); }, + 1e-8); } /** @@ -104,18 +155,21 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) // Test applying the BC essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + // Check the correct boundary values have been applied - mfem::Array ess_vdofs_list, ess_vdofs_marker; - const std::vector expected = bc_params.get>("values"); - for (int i = 0; i < 3; i++) - { - _vector_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker, i); - _vector_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); - for (auto ess_dof : ess_vdofs_list) - { - EXPECT_EQ(_vector_gridfunc[ess_dof], expected[i]); - } - } + mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::Vector expected({1., 2., 3.}); + check_boundary( + 1, + [&variable, &expected](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { + mfem::Vector actual(3); + variable.Eval(actual, *transform, point); + actual -= expected; + return actual.Norml2(); + }, + 1e-8); } /** @@ -136,7 +190,101 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionDirichletBC) // Test applying the BC essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - // FIXME: We should actually check this applies the right boundary values... + + // Check the correct boundary values have been applied + mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + std::shared_ptr function = + _mfem_problem->getVectorFunctionCoefficient("func2"); + check_boundary( + 1, + [&variable, &function](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { + mfem::Vector actual(3), expected(3); + variable.Eval(actual, *transform, point); + function->Eval(expected, *transform, point); + actual -= expected; + return actual.Norml2(); + }, + 1e-8); +} + +/** + * Test MFEMVectorNormalDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMVectorNormalDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMVectorNormalDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set>("values") = {1., 2., 3.}; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = + addObject("MFEMVectorNormalDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + + // Check the correct boundary values have been applied + mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::Vector assigned_val({1., 2., 3.}); + check_boundary( + 1, + [this, &variable, &assigned_val](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { + mfem::Vector actual(3), expected(3), normal = calc_normal(transform); + variable.Eval(actual, *transform, point); + std::cout << "[" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" << std::endl; + // Project the assigned BC val into the direction of the normal + expected = normal; + expected *= (assigned_val * normal) / (normal * normal); + actual -= expected; + // (actual - expected) should be perpendicular to the normal and have a dot product of 0. + return actual.Norml2(); + }, + 1e-8); +} + +/** + * Test MFEMVectorFunctionNormalDirichletBC can be constructed and applied successfully + */ +TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionNormalDirichletBC) +{ + // Construct boundary condition + InputParameters bc_params = _factory.getValidParams("MFEMVectorFunctionNormalDirichletBC"); + bc_params.set("variable") = "test_variable_name"; + bc_params.set("function") = "func2"; + bc_params.set>("boundary") = {"1"}; + auto & essential_bc = addObject( + "MFEMVectorFunctionNormalDirichletBC", "bc1", bc_params); + + EXPECT_EQ(essential_bc.getTrialVariableName(), "test_variable_name"); + EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); + + // Test applying the BC + essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + + // Check the correct boundary values have been applied + mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + std::shared_ptr function = + _mfem_problem->getVectorFunctionCoefficient("func2"); + check_boundary( + 1, + [this, &variable, &function](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { + mfem::Vector actual(3), expected(3), normal = calc_normal(transform); + variable.Eval(actual, *transform, point); + function->Eval(expected, *transform, point); + actual -= expected; + // (actual - expected) should be perpendicular to the normal and have a dot product of 0. + return normal[0] * actual[0] + normal[1] * actual[1] + normal[2] * actual[2]; + }, + 1e-8); } /** @@ -158,22 +306,33 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) // Test applying the BC essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::Array ess_vdofs_list, ess_vdofs_marker; - const std::vector expected = bc_params.get>("values"); - for (int i = 0; i < 3; i++) - { - _vector_fes.GetEssentialVDofs(essential_bc._bdr_markers, ess_vdofs_marker, i); - _vector_fes.MarkerToList(ess_vdofs_marker, ess_vdofs_list); - for (auto ess_dof : ess_vdofs_list) - { - std::cout << "Index: " << ess_dof << std::endl; - EXPECT_EQ(_vector_gridfunc[ess_dof], expected[i]); - } - } + mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::Vector expected({1., 2., 3.}); + check_boundary( + 1, + [this, &variable, &expected](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { + mfem::Vector actual(3), normal = calc_normal(transform), cross_prod(3); + variable.Eval(actual, *transform, point); + std::cout << "Normal [" << normal[0] << ", " << normal[1] << ", " << normal[2] << "]" + << std::endl; + std::cout << "Actual [" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" + << std::endl; + std::cout << "Expected [" << expected[0] << ", " << expected[1] << ", " << expected[2] + << "]" << std::endl; + actual -= expected; + // (actual - expected) should be parallel to the normal and have a cross product of 0. + cross_prod = normal[1] * actual[2] - normal[2] * actual[1]; + cross_prod = normal[2] * actual[0] - normal[0] * actual[2]; + cross_prod = normal[0] * actual[1] - normal[1] * actual[0]; + return cross_prod.Norml2(); + }, + 1e-8); } /** - * Test MFEMVectorFunctionDirichletBC can be constructed and applied successfully + * Test MFEMVectorFunctionTangentialDirichletBC can be constructed and applied successfully */ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) { @@ -190,5 +349,31 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) // Test applying the BC essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); - // FIXME: We should actually check this applies the right boundary values... + + // Check the correct boundary values have been applied + mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + std::shared_ptr function = + _mfem_problem->getVectorFunctionCoefficient("func2"); + check_boundary( + 1, + [this, &variable, &function](mfem::ElementTransformation * transform, + const mfem::IntegrationPoint & point) + { + mfem::Vector actual(3), expected(3), normal = calc_normal(transform), cross_prod(3); + variable.Eval(actual, *transform, point); + function->Eval(expected, *transform, point); + std::cout << "Normal [" << normal[0] << ", " << normal[1] << ", " << normal[2] << "]" + << std::endl; + std::cout << "Actual [" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" + << std::endl; + std::cout << "Expected [" << expected[0] << ", " << expected[1] << ", " << expected[2] + << "]" << std::endl; + actual -= expected; + // (actual - expected) should be parallel to the normal and have a cross product of 0. + cross_prod = normal[1] * actual[2] - normal[2] * actual[1]; + cross_prod = normal[2] * actual[0] - normal[0] * actual[2]; + cross_prod = normal[0] * actual[1] - normal[1] * actual[0]; + return cross_prod.Norml2(); + }, + 1e-8); } From 78417d5180558f5d39972cab026b8bda243728e0 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Mon, 16 Dec 2024 11:08:48 +0000 Subject: [PATCH 13/24] Fix failing build of test --- unit/src/MFEMEssentialBCTest.C | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 8ef5e76d..90343525 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -13,20 +13,27 @@ class MFEMEssentialBCTest : public MFEMObjectUnitTest { public: mfem::common::H1_FESpace _scalar_fes; - // mfem::common::ND_FESpace _vector_fes; - mfem::common::H1_FESpace _vector_fes; - mfem::GridFunction _scalar_gridfunc, _vector_gridfunc; + // mfem::common::ND_FESpace _vector_h1_fes; + mfem::common::H1_FESpace _vector_h1_fes; + mfem::common::ND_FESpace _vector_hcurl_fes; + mfem::common::RT_FESpace _vector_hdiv_fes; + mfem::GridFunction _scalar_gridfunc, _vector_h1_gridfunc, _vector_hcurl_gridfunc, + _vector_hdiv_gridfunc; mfem::ConstantCoefficient _scalar_zero; mfem::VectorConstantCoefficient _vector_zero; MFEMEssentialBCTest() : MFEMObjectUnitTest("PlatypusApp"), _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), - //_vector_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), - _vector_fes( + //_vector_h1_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), + _vector_h1_fes( _mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, mfem::BasisType::GaussLobatto, 3), + _vector_hcurl_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), + _vector_hdiv_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), _scalar_gridfunc(&_scalar_fes), - _vector_gridfunc(&_vector_fes), + _vector_h1_gridfunc(&_vector_h1_fes), + _vector_hcurl_gridfunc(&_vector_hcurl_fes), + _vector_hdiv_gridfunc(&_vector_hdiv_fes), _scalar_zero(0.), _vector_zero(mfem::Vector({0., 0., 0.})) { @@ -41,7 +48,7 @@ public: _mfem_problem->addFunction("ParsedVectorFunction", "func2", vecfunc_params); _mfem_problem->getFunction("func2").initialSetup(); _scalar_gridfunc.ProjectCoefficient(_scalar_zero); - _vector_gridfunc.ProjectCoefficient(_vector_zero); + _vector_h1_gridfunc.ProjectCoefficient(_vector_zero); } void check_boundary(int bound, @@ -154,10 +161,10 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_h1_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_h1_gridfunc); mfem::Vector expected({1., 2., 3.}); check_boundary( 1, @@ -189,10 +196,10 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_h1_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_h1_gridfunc); std::shared_ptr function = _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( @@ -226,10 +233,10 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorNormalDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_h1_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_h1_gridfunc); mfem::Vector assigned_val({1., 2., 3.}); check_boundary( 1, @@ -266,10 +273,10 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionNormalDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_h1_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_h1_gridfunc); std::shared_ptr function = _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( @@ -304,9 +311,9 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_hcurl_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_hcurl_gridfunc); mfem::Vector expected({1., 2., 3.}); check_boundary( 1, @@ -348,10 +355,10 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_hcurl_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_hcurl_gridfunc); std::shared_ptr function = _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( From a1481a88e6e1ce6158f98888408c45e6ae2116ed Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 16 Dec 2024 17:25:30 +0000 Subject: [PATCH 14/24] Removed coefficient action documentation --- .../source/actions/AddCoefficientAction.md | 16 ---------------- .../actions/AddVectorCoefficientAction.md | 17 ----------------- 2 files changed, 33 deletions(-) delete mode 100644 doc/content/source/actions/AddCoefficientAction.md delete mode 100644 doc/content/source/actions/AddVectorCoefficientAction.md diff --git a/doc/content/source/actions/AddCoefficientAction.md b/doc/content/source/actions/AddCoefficientAction.md deleted file mode 100644 index c2a9fa20..00000000 --- a/doc/content/source/actions/AddCoefficientAction.md +++ /dev/null @@ -1,16 +0,0 @@ -# AddCoefficientAction - -## Summary - -!syntax description /Coefficients/AddCoefficientAction - -## Overview - -Action called to add an MFEM coefficient to the problem, parsing content inside a `Coefficients` -block in the user input. Only has an effect if the `Problem` type is set to [`MFEMProblem`](source/problem/MFEMProblem.md). - -## Example Input File Syntax - -!listing test/tests/kernels/heatconduction.i block=Problem Functions Coefficients - -!syntax parameters /Coefficients/AddCoefficientAction diff --git a/doc/content/source/actions/AddVectorCoefficientAction.md b/doc/content/source/actions/AddVectorCoefficientAction.md deleted file mode 100644 index fef1bc87..00000000 --- a/doc/content/source/actions/AddVectorCoefficientAction.md +++ /dev/null @@ -1,17 +0,0 @@ -# AddVectorCoefficientAction - -## Summary - -!syntax description /VectorCoefficients/AddVectorCoefficientAction - -## Overview - -Action called to add an MFEM vector coefficient to the problem, parsing content inside a `VectorCoefficients` -block in the user input. Only has an effect if the `Problem` type is set to -[`MFEMProblem`](source/problem/MFEMProblem.md). - -## Example Input File Syntax - -!listing test/tests/kernels/curlcurl.i block=Problem Functions Coefficients - -!syntax parameters /VectorCoefficients/AddVectorCoefficientAction From a0cdedbca85f17f796f9facfa95afc8974f3ad44 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Mon, 16 Dec 2024 18:07:26 +0000 Subject: [PATCH 15/24] Fix broken MFEMEssentialBCTests for constant function calls --- unit/src/MFEMEssentialBCTest.C | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 90343525..a62c3f5e 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -42,16 +42,19 @@ public: _mfem_problem->addFunction("ParsedFunction", "func1", func_params); _mfem_problem->getFunction("func1").initialSetup(); InputParameters vecfunc_params = _factory.getValidParams("ParsedVectorFunction"); - vecfunc_params.set("expression_x") = "x + y"; - vecfunc_params.set("expression_y") = "x + y + 1"; - vecfunc_params.set("expression_z") = "x + y + 2"; + vecfunc_params.set("expression_x") = "3"; + vecfunc_params.set("expression_y") = "4"; + vecfunc_params.set("expression_z") = "5"; _mfem_problem->addFunction("ParsedVectorFunction", "func2", vecfunc_params); _mfem_problem->getFunction("func2").initialSetup(); _scalar_gridfunc.ProjectCoefficient(_scalar_zero); _vector_h1_gridfunc.ProjectCoefficient(_vector_zero); + _vector_hcurl_gridfunc.ProjectCoefficient(_vector_zero); + _vector_hdiv_gridfunc.ProjectCoefficient(_vector_zero); } void check_boundary(int bound, + mfem::FiniteElementSpace & fespace, std::function error_func, double tolerance) @@ -63,7 +66,7 @@ public: continue; mfem::ElementTransformation * transform = _mfem_mesh_ptr->getMFEMParMeshPtr()->GetBdrElementTransformation(be); - const mfem::FiniteElement * fe = _scalar_fes.GetBE(be); + const mfem::FiniteElement * fe = fespace.GetBE(be); const mfem::IntegrationRule & ir = mfem::IntRules.Get(fe->GetGeomType(), 2 * fe->GetOrder() + 2); double total_error = 0.0; @@ -108,6 +111,7 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarDirichletBC) mfem::GridFunctionCoefficient scalar_variable(&_scalar_gridfunc); check_boundary( 1, + _scalar_fes, [&scalar_variable](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { return scalar_variable.Eval(*transform, point) - 1.; }, @@ -139,6 +143,7 @@ TEST_F(MFEMEssentialBCTest, MFEMScalarFunctionDirichletBC) _mfem_problem->getScalarFunctionCoefficient("func1"); check_boundary( 1, + _scalar_fes, [&scalar_variable, expected](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { return scalar_variable.Eval(*transform, point) - expected->Eval(*transform, point); }, @@ -168,6 +173,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) mfem::Vector expected({1., 2., 3.}); check_boundary( 1, + _scalar_fes, [&variable, &expected](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { @@ -204,6 +210,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionDirichletBC) _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( 1, + _scalar_fes, [&variable, &function](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { @@ -233,25 +240,24 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorNormalDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_h1_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_hdiv_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_h1_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_hdiv_gridfunc); mfem::Vector assigned_val({1., 2., 3.}); check_boundary( 1, + _vector_hdiv_fes, [this, &variable, &assigned_val](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { mfem::Vector actual(3), expected(3), normal = calc_normal(transform); variable.Eval(actual, *transform, point); std::cout << "[" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" << std::endl; - // Project the assigned BC val into the direction of the normal - expected = normal; - expected *= (assigned_val * normal) / (normal * normal); + expected = assigned_val; actual -= expected; // (actual - expected) should be perpendicular to the normal and have a dot product of 0. - return actual.Norml2(); + return normal[0] * actual[0] + normal[1] * actual[1] + normal[2] * actual[2]; }, 1e-8); } @@ -273,14 +279,15 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionNormalDirichletBC) EXPECT_EQ(essential_bc.getTestVariableName(), "test_variable_name"); // Test applying the BC - essential_bc.ApplyBC(_vector_h1_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); + essential_bc.ApplyBC(_vector_hdiv_gridfunc, _mfem_mesh_ptr->getMFEMParMeshPtr().get()); // Check the correct boundary values have been applied - mfem::VectorGridFunctionCoefficient variable(&_vector_h1_gridfunc); + mfem::VectorGridFunctionCoefficient variable(&_vector_hdiv_gridfunc); std::shared_ptr function = _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( 1, + _vector_hdiv_fes, [this, &variable, &function](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { @@ -317,6 +324,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) mfem::Vector expected({1., 2., 3.}); check_boundary( 1, + _vector_hcurl_fes, [this, &variable, &expected](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { @@ -363,6 +371,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( 1, + _vector_hcurl_fes, [this, &variable, &function](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { From 61551395e2c9c060c3a98ed398862806d8442c78 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 16 Dec 2024 21:47:58 +0000 Subject: [PATCH 16/24] Fixed up BC for graddiv test and added missing documentation --- .../bcs/MFEMScalarFunctionDirichletBC.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md diff --git a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md new file mode 100644 index 00000000..3713f789 --- /dev/null +++ b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md @@ -0,0 +1,21 @@ +# MFEMScalarFunctionDirichletBC + +## Summary + +!syntax description /BCs/MFEMScalarFunctionDirichletBC + +## Overview + +Boundary condition for enforcing an essential (Dirichlet) condition on +a scalar variable on the boundary, fixing its values to the input +scalar function on the boundary. + +## Example Input File Syntax + +!listing test/tests/kernels/graddiv.i block=BCs + +!syntax parameters/BCs/MFEMScalarFunctionDirichletBC + +!syntax inputs/BCs/MFEMScalarFunctionDirichletBC + +!syntax children/BCs/MFEMScalarFunctionDirichletBC From 1e7d545cd62153b5a7b96475798996af5886f7bc Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 16 Dec 2024 22:20:44 +0000 Subject: [PATCH 17/24] Fix most of the problems with Essential BCs --- .../bcs/MFEMScalarFunctionDirichletBC.md | 6 ++--- unit/src/MFEMEssentialBCTest.C | 25 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md index 3713f789..5f7626a9 100644 --- a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md +++ b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md @@ -14,8 +14,8 @@ scalar function on the boundary. !listing test/tests/kernels/graddiv.i block=BCs -!syntax parameters/BCs/MFEMScalarFunctionDirichletBC +!syntax parameters /BCs/MFEMScalarFunctionDirichletBC -!syntax inputs/BCs/MFEMScalarFunctionDirichletBC +!syntax inputs /BCs/MFEMScalarFunctionDirichletBC -!syntax children/BCs/MFEMScalarFunctionDirichletBC +!syntax children /BCs/MFEMScalarFunctionDirichletBC diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index a62c3f5e..851bdb9d 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -13,7 +13,6 @@ class MFEMEssentialBCTest : public MFEMObjectUnitTest { public: mfem::common::H1_FESpace _scalar_fes; - // mfem::common::ND_FESpace _vector_h1_fes; mfem::common::H1_FESpace _vector_h1_fes; mfem::common::ND_FESpace _vector_hcurl_fes; mfem::common::RT_FESpace _vector_hdiv_fes; @@ -25,7 +24,6 @@ public: MFEMEssentialBCTest() : MFEMObjectUnitTest("PlatypusApp"), _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), - //_vector_h1_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, 3), _vector_h1_fes( _mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, mfem::BasisType::GaussLobatto, 3), _vector_hcurl_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), @@ -42,9 +40,9 @@ public: _mfem_problem->addFunction("ParsedFunction", "func1", func_params); _mfem_problem->getFunction("func1").initialSetup(); InputParameters vecfunc_params = _factory.getValidParams("ParsedVectorFunction"); - vecfunc_params.set("expression_x") = "3"; - vecfunc_params.set("expression_y") = "4"; - vecfunc_params.set("expression_z") = "5"; + vecfunc_params.set("expression_x") = "x + y"; + vecfunc_params.set("expression_y") = "x + y + 1"; + vecfunc_params.set("expression_z") = "x + y + 2"; _mfem_problem->addFunction("ParsedVectorFunction", "func2", vecfunc_params); _mfem_problem->getFunction("func2").initialSetup(); _scalar_gridfunc.ProjectCoefficient(_scalar_zero); @@ -173,7 +171,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorDirichletBC) mfem::Vector expected({1., 2., 3.}); check_boundary( 1, - _scalar_fes, + _vector_h1_fes, [&variable, &expected](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { @@ -210,7 +208,7 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionDirichletBC) _mfem_problem->getVectorFunctionCoefficient("func2"); check_boundary( 1, - _scalar_fes, + _vector_h1_fes, [&variable, &function](mfem::ElementTransformation * transform, const mfem::IntegrationPoint & point) { @@ -253,7 +251,6 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorNormalDirichletBC) { mfem::Vector actual(3), expected(3), normal = calc_normal(transform); variable.Eval(actual, *transform, point); - std::cout << "[" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" << std::endl; expected = assigned_val; actual -= expected; // (actual - expected) should be perpendicular to the normal and have a dot product of 0. @@ -294,6 +291,12 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionNormalDirichletBC) mfem::Vector actual(3), expected(3), normal = calc_normal(transform); variable.Eval(actual, *transform, point); function->Eval(expected, *transform, point); + std::cout << "Normal [" << normal[0] << ", " << normal[1] << ", " << normal[2] << "]" + << std::endl; + std::cout << "Actual [" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" + << std::endl; + std::cout << "Expected [" << expected[0] << ", " << expected[1] << ", " << expected[2] + << "]" << std::endl; actual -= expected; // (actual - expected) should be perpendicular to the normal and have a dot product of 0. return normal[0] * actual[0] + normal[1] * actual[1] + normal[2] * actual[2]; @@ -330,12 +333,6 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorTangentialDirichletBC) { mfem::Vector actual(3), normal = calc_normal(transform), cross_prod(3); variable.Eval(actual, *transform, point); - std::cout << "Normal [" << normal[0] << ", " << normal[1] << ", " << normal[2] << "]" - << std::endl; - std::cout << "Actual [" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" - << std::endl; - std::cout << "Expected [" << expected[0] << ", " << expected[1] << ", " << expected[2] - << "]" << std::endl; actual -= expected; // (actual - expected) should be parallel to the normal and have a cross product of 0. cross_prod = normal[1] * actual[2] - normal[2] * actual[1]; From 174d2e5a263ce3816c5dcfee4ef2392e527ec4bc Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 16 Dec 2024 22:29:50 +0000 Subject: [PATCH 18/24] Still trying to fix graddiv --- doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md index 5f7626a9..eef43fb4 100644 --- a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md +++ b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.md @@ -12,8 +12,6 @@ scalar function on the boundary. ## Example Input File Syntax -!listing test/tests/kernels/graddiv.i block=BCs - !syntax parameters /BCs/MFEMScalarFunctionDirichletBC !syntax inputs /BCs/MFEMScalarFunctionDirichletBC From 81438c1ee36cf16102c4c5cee82da3e41fd2280d Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 16 Dec 2024 23:40:15 +0000 Subject: [PATCH 19/24] Use second-order basis functions for norm and tangent BCs --- unit/src/MFEMEssentialBCTest.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 851bdb9d..536b05e2 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -26,8 +26,8 @@ public: _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), _vector_h1_fes( _mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, mfem::BasisType::GaussLobatto, 3), - _vector_hcurl_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), - _vector_hdiv_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), + _vector_hcurl_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 2, 3, 3), + _vector_hdiv_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 2, 3, 3), _scalar_gridfunc(&_scalar_fes), _vector_h1_gridfunc(&_vector_h1_fes), _vector_hcurl_gridfunc(&_vector_hcurl_fes), From 29c4f0c3c6b1c8841e84f0eb48a24a79320380ba Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Mon, 16 Dec 2024 23:51:28 +0000 Subject: [PATCH 20/24] Removed debugging print statements --- unit/src/MFEMEssentialBCTest.C | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 536b05e2..9f2c2775 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -291,12 +291,6 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionNormalDirichletBC) mfem::Vector actual(3), expected(3), normal = calc_normal(transform); variable.Eval(actual, *transform, point); function->Eval(expected, *transform, point); - std::cout << "Normal [" << normal[0] << ", " << normal[1] << ", " << normal[2] << "]" - << std::endl; - std::cout << "Actual [" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" - << std::endl; - std::cout << "Expected [" << expected[0] << ", " << expected[1] << ", " << expected[2] - << "]" << std::endl; actual -= expected; // (actual - expected) should be perpendicular to the normal and have a dot product of 0. return normal[0] * actual[0] + normal[1] * actual[1] + normal[2] * actual[2]; @@ -375,12 +369,6 @@ TEST_F(MFEMEssentialBCTest, MFEMVectorFunctionTangentialDirichletBC) mfem::Vector actual(3), expected(3), normal = calc_normal(transform), cross_prod(3); variable.Eval(actual, *transform, point); function->Eval(expected, *transform, point); - std::cout << "Normal [" << normal[0] << ", " << normal[1] << ", " << normal[2] << "]" - << std::endl; - std::cout << "Actual [" << actual[0] << ", " << actual[1] << ", " << actual[2] << "]" - << std::endl; - std::cout << "Expected [" << expected[0] << ", " << expected[1] << ", " << expected[2] - << "]" << std::endl; actual -= expected; // (actual - expected) should be parallel to the normal and have a cross product of 0. cross_prod = normal[1] * actual[2] - normal[2] * actual[1]; From 27246e70739893371087a2ee02db9e8ac10a4a65 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Tue, 17 Dec 2024 10:47:20 +0000 Subject: [PATCH 21/24] Update unit/src/MFEMEssentialBCTest.C Co-authored-by: Alexander Blair <35571481+alexanderianblair@users.noreply.github.com> --- unit/src/MFEMEssentialBCTest.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit/src/MFEMEssentialBCTest.C b/unit/src/MFEMEssentialBCTest.C index 9f2c2775..43934cd3 100644 --- a/unit/src/MFEMEssentialBCTest.C +++ b/unit/src/MFEMEssentialBCTest.C @@ -26,8 +26,8 @@ public: _scalar_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3), _vector_h1_fes( _mfem_mesh_ptr->getMFEMParMeshPtr().get(), 1, 3, mfem::BasisType::GaussLobatto, 3), - _vector_hcurl_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 2, 3, 3), - _vector_hdiv_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 2, 3, 3), + _vector_hcurl_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 2, 3), + _vector_hdiv_fes(_mfem_mesh_ptr->getMFEMParMeshPtr().get(), 2, 3), _scalar_gridfunc(&_scalar_fes), _vector_h1_gridfunc(&_vector_h1_fes), _vector_hcurl_gridfunc(&_vector_hcurl_fes), From b58100e09089e29cb9ceec3b675bd386d782babf Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Tue, 17 Dec 2024 10:47:55 +0000 Subject: [PATCH 22/24] Update doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C Co-authored-by: Alexander Blair <35571481+alexanderianblair@users.noreply.github.com> --- .../source/bcs/MFEMScalarFunctionDirichletBC.C | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C index cc509772..2c5fd00a 100644 --- a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C +++ b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C @@ -8,17 +8,12 @@ Boundary condition for enforcing an essential (Dirichlet) condition on a scalar variable on the boundary, - fixing its values to the input scalar function on the boundary. +fixing its values to the input scalar function on the boundary. - ##Example Input File Syntax +##Example Input File Syntax - !syntax parameters / - BCs / - MFEMScalarFunctionDirichletBC +!syntax parameters /BCs/MFEMScalarFunctionDirichletBC - !syntax inputs / - BCs / - MFEMScalarFunctionDirichletBC +!syntax inputs /BCs/MFEMScalarFunctionDirichletBC - !syntax children / - BCs / MFEMScalarFunctionDirichletBC +!syntax children /BCs/MFEMScalarFunctionDirichletBC From 8a91f59f763e1ce1fd298328c4e8f6dc675225a5 Mon Sep 17 00:00:00 2001 From: Chris MacMackin Date: Tue, 17 Dec 2024 10:48:19 +0000 Subject: [PATCH 23/24] Update doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md Co-authored-by: Alexander Blair <35571481+alexanderianblair@users.noreply.github.com> --- doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md b/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md index dd04b33e..6f914a9b 100644 --- a/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md +++ b/doc/content/source/bcs/MFEMVectorBoundaryIntegratedBC.md @@ -11,7 +11,7 @@ Adds the boundary integrator for integrating the linear form !equation (\vec f, \vec v)_{\partial\Omega} \,\,\, \forall \vec v \in V -where $v \in \vec H^1$ and $\vec f$ is a constant vector of the same dimension. +where $\vec v \in \vec H^1$ and $\vec f$ is a constant vector of the same dimension. ## Example Input File Syntax From f80586ab06030d05e02015a74a703ad877bbeac8 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Tue, 17 Dec 2024 12:37:50 +0000 Subject: [PATCH 24/24] Remove duplicated documentation file with incorrect file extension for MFEMScalarFunctionDirichletBC --- .../bcs/MFEMScalarFunctionDirichletBC.C | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C diff --git a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C b/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C deleted file mode 100644 index 2c5fd00a..00000000 --- a/doc/content/source/bcs/MFEMScalarFunctionDirichletBC.C +++ /dev/null @@ -1,19 +0,0 @@ -#MFEMScalarFunctionDirichletBC - -## Summary - -!syntax description /BCs/MFEMScalarFunctionDirichletBC - -## Overview - -Boundary condition for enforcing an essential (Dirichlet) -condition on a scalar variable on the boundary, -fixing its values to the input scalar function on the boundary. - -##Example Input File Syntax - -!syntax parameters /BCs/MFEMScalarFunctionDirichletBC - -!syntax inputs /BCs/MFEMScalarFunctionDirichletBC - -!syntax children /BCs/MFEMScalarFunctionDirichletBC