-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for getting MFEM coefficients for functions
- Loading branch information
1 parent
8fd7148
commit cd2f2e8
Showing
2 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<std::string>("expression") = "1."; | ||
_mfem_problem->addFunction("ParsedFunction", "coef1", func_params1); | ||
_mfem_problem->getFunction("coef1").initialSetup(); | ||
std::shared_ptr<mfem::Coefficient> 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<std::string>("expression_x") = "1."; | ||
func_params1.set<std::string>("expression_y") = "2."; | ||
func_params1.set<std::string>("expression_z") = "3."; | ||
_mfem_problem->addFunction("ParsedVectorFunction", "vec_coef1", func_params1); | ||
_mfem_problem->getFunction("vec_coef1").initialSetup(); | ||
std::shared_ptr<mfem::VectorCoefficient> 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<std::string>("expression") = "1."; | ||
_mfem_problem->addFunction("ParsedFunction", "coef1", func_params1); | ||
InputParameters func_params2 = _factory.getValidParams("ParsedFunction"); | ||
func_params2.set<std::string>("expression") = "x*y"; | ||
_mfem_problem->addFunction("ParsedFunction", "coef2", func_params2); | ||
InputParameters func_params3 = _factory.getValidParams("LinearCombinationFunction"); | ||
func_params3.set<std::vector<FunctionName>>("functions") = {"coef1", "coef2"}; | ||
func_params3.set<std::vector<double>>("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); | ||
} |