diff --git a/src/problem/MFEMProblem.C b/src/problem/MFEMProblem.C index 7f80f5c..456831d 100644 --- a/src/problem/MFEMProblem.C +++ b/src/problem/MFEMProblem.C @@ -293,9 +293,9 @@ MFEMProblem::addFunction(const std::string & type, } else { - mooseWarning("Could not identify whether function time ", + mooseWarning("Could not identify whether function ", type, - "is scalar or vector; no MFEM coefficient object created."); + " is scalar or vector; no MFEM coefficient object created."); } } diff --git a/unit/src/FunctionTest.C b/unit/src/FunctionTest.C new file mode 100644 index 0000000..3609c40 --- /dev/null +++ b/unit/src/FunctionTest.C @@ -0,0 +1,78 @@ +#include "MFEMObjectUnitTest.h" + +class FunctionTest : public MFEMObjectUnitTest +{ +public: + mfem::IsoparametricTransformation fe_transform; + mfem::IntegrationPoint point; + FunctionTest() : MFEMObjectUnitTest("PlatypusApp") + { + point.Init(3); + point.Set3(0., 0., 0.); + fe_transform.SetIdentityTransformation(mfem::Geometry::CUBE); + } +}; + +/** + * Test MFEMProblem::getScalarFunctionCoefficient works as it should. + */ +TEST_F(FunctionTest, GetScalarFunctionCoefficient) +{ + // Build required kernel inputs + InputParameters func_params1 = _factory.getValidParams("ParsedFunction"); + func_params1.set("expression") = "1."; + _mfem_problem->addFunction("ParsedFunction", "coef1", func_params1); + _mfem_problem->getFunction("coef1").initialSetup(); + std::shared_ptr coef = _mfem_problem->getScalarFunctionCoefficient("coef1"); + EXPECT_EQ(coef->Eval(fe_transform, point), 1); + + EXPECT_THROW(_mfem_problem->getVectorFunctionCoefficient("coef1"), std::runtime_error); + EXPECT_THROW(_mfem_problem->getScalarFunctionCoefficient("coef2"), std::runtime_error); +} + +/** + * Test MFEMProblem::getVectorFunctionCoefficient works as it should. + */ +TEST_F(FunctionTest, GetVectorFunctionCoefficient) +{ + // Build required kernel inputs + InputParameters func_params1 = _factory.getValidParams("ParsedVectorFunction"); + func_params1.set("expression_x") = "1."; + func_params1.set("expression_y") = "2."; + func_params1.set("expression_z") = "3."; + _mfem_problem->addFunction("ParsedVectorFunction", "vec_coef1", func_params1); + _mfem_problem->getFunction("vec_coef1").initialSetup(); + std::shared_ptr coef = + _mfem_problem->getVectorFunctionCoefficient("vec_coef1"); + mfem::Vector vec; + coef->Eval(vec, fe_transform, point); + EXPECT_EQ(vec[0], 1.); + EXPECT_EQ(vec[1], 2.); + EXPECT_EQ(vec[2], 3.); + + EXPECT_THROW(_mfem_problem->getVectorFunctionCoefficient("vec_coef2"), std::runtime_error); + EXPECT_THROW(_mfem_problem->getScalarFunctionCoefficient("vec_coef1"), std::runtime_error); +} + +/** + * Test MFEMProblem::addFunction when unkown function type is used. + */ +TEST_F(FunctionTest, AddUnknownFunction) +{ + InputParameters func_params1 = _factory.getValidParams("ParsedFunction"); + func_params1.set("expression") = "1."; + _mfem_problem->addFunction("ParsedFunction", "coef1", func_params1); + InputParameters func_params2 = _factory.getValidParams("ParsedFunction"); + func_params2.set("expression") = "x*y"; + _mfem_problem->addFunction("ParsedFunction", "coef2", func_params2); + InputParameters func_params3 = _factory.getValidParams("LinearCombinationFunction"); + func_params3.set>("functions") = {"coef1", "coef2"}; + func_params3.set>("w") = {1., 2.}; + _mfem_problem->addFunction("LinearCombinationFunction", "coef3", func_params3); + _mfem_problem->getFunction("coef1").initialSetup(); + _mfem_problem->getFunction("coef2").initialSetup(); + _mfem_problem->getFunction("coef3").initialSetup(); + + EXPECT_THROW(_mfem_problem->getScalarFunctionCoefficient("coef3"), std::runtime_error); + EXPECT_THROW(_mfem_problem->getVectorFunctionCoefficient("coef3"), std::runtime_error); +}