https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Functions
TestFaceCenteredMapFunctor.C File Reference

Go to the source code of this file.

Classes

class  FictionalFaceCenteredMapFunctor< T, Map >
 

Functions

 TEST (FaceCenteredMapFunctorTest, testArgs)
 

Function Documentation

◆ TEST()

TEST ( FaceCenteredMapFunctorTest  ,
testArgs   
)

Definition at line 35 of file TestFaceCenteredMapFunctor.C.

36{
37 const char * argv[2] = {"foo", "\0"};
38
39 // First we create a simple mesh
40 auto app = Moose::createMooseApp("NavierStokesUnitApp", 1, (char **)argv);
41 auto * factory = &app->getFactory();
42 std::string mesh_type = "MeshGeneratorMesh";
43
44 std::shared_ptr<MeshGeneratorMesh> mesh;
45 {
46 InputParameters params = factory->getValidParams(mesh_type);
47 mesh = factory->create<MeshGeneratorMesh>(mesh_type, "moose_mesh", params);
48 }
49
50 app->actionWarehouse().mesh() = mesh;
51
52 {
53 std::unique_ptr<MeshBase> lm_mesh;
54 InputParameters params = factory->getValidParams("GeneratedMeshGenerator");
55 params.set<unsigned int>("nx") = 2;
56 params.set<unsigned int>("ny") = 2;
57 params.set<MooseEnum>("dim") = "2";
58 auto mesh_gen =
59 factory->create<GeneratedMeshGenerator>("GeneratedMeshGenerator", "mesh_gen", params);
60 lm_mesh = mesh_gen->generate();
61 mesh->setMeshBase(std::move(lm_mesh));
62 }
63
64 mesh->prepare();
65 MultiMooseEnum coord_type_enum("XYZ RZ RSPHERICAL", "XYZ");
66 mesh->setCoordSystem({}, coord_type_enum);
67 mesh->buildFiniteVolumeInfo();
68 mesh->computeFiniteVolumeCoords();
69 const auto & all_fi = mesh->allFaceInfo();
70
71 // We create a face-centered functor
73 "u");
74
75 // We fill up the functor with known values
76 for (auto & fi : all_fi)
77 {
78 const auto & face_center = fi.faceCentroid();
79 u[fi.id()] = RealVectorValue(
80 -sin(face_center(0)) * cos(face_center(1)), cos(face_center(0)) * sin(face_center(1)), 0);
81 }
82
83 // We check if the functor has the right face values
84 for (auto & fi : all_fi)
85 {
86 const auto & face_center = fi.faceCentroid();
87 const auto face_arg = Moose::FaceArg{
88 &fi, Moose::FV::LimiterType::CentralDifference, true, false, nullptr, nullptr};
89
90 const auto result = u(face_arg, Moose::currentState());
91
92 EXPECT_NEAR(result(0), -sin(face_center(0)) * cos(face_center(1)), 1e-14);
93 EXPECT_NEAR(result(1), cos(face_center(0)) * sin(face_center(1)), 1e-14);
94 EXPECT_EQ(result(2), 0);
95 }
96
97 // Next, we test for the error messages of not-implemented methods
98 // This is a lambda for testing errors when requesting a gradient evaluation
99 auto test_gradient = [&u](const auto & arg)
100 {
101 try
102 {
103 u.gradient(arg, Moose::currentState());
104 EXPECT_TRUE(false);
105 }
106 catch (std::runtime_error & e)
107 {
108 EXPECT_TRUE(std::string(e.what()).find("not implemented") != std::string::npos);
109 }
110 };
111
112 // This is a lambda for testing errors when requesting a regular evaluation with an unsupported
113 // argument
114 auto test_evaluate = [&u](const auto & arg)
115 {
116 try
117 {
118 u(arg, Moose::currentState());
119 EXPECT_TRUE(false);
120 }
121 catch (std::runtime_error & e)
122 {
123 EXPECT_TRUE(std::string(e.what()).find("not implemented") != std::string::npos);
124 }
125 };
126
127 // Arguments for the simple error checks, we use the first face and the corresponding
128 // owner element
129 QGauss qrule(1, CONSTANT);
130 const auto face_arg = Moose::FaceArg{
131 &all_fi[0], Moose::FV::LimiterType::CentralDifference, true, false, nullptr, nullptr};
132 const auto elem_arg = ElemArg{all_fi[0].elemPtr(), false};
133 const auto elem_qp_arg = ElemQpArg({all_fi[0].elemPtr(), 0, &qrule, Point(0)});
134 const auto elem_side_qp_arg = ElemSideQpArg({all_fi[0].elemPtr(), 0, 0, &qrule, Point(0)});
135 const auto elem_point_arg = ElemPointArg({all_fi[0].elemPtr(), Point(0), false});
136
137 test_gradient(elem_arg);
138 test_gradient(face_arg);
139
140 test_evaluate(elem_qp_arg);
141 test_evaluate(elem_side_qp_arg);
142 test_evaluate(elem_point_arg);
143
144 // Lastly, we check for errors when encountering faces with incorrect subdomains
146 unrestricted_error_test(*mesh, "not_restricted");
147 try
148 {
149 unrestricted_error_test(
150 FaceArg{&all_fi[2], LimiterType::CentralDifference, true, false, nullptr, nullptr},
152 EXPECT_TRUE(false);
153 }
154 catch (std::runtime_error & e)
155 {
156 EXPECT_TRUE(std::string(e.what()).find("not_restricted") != std::string::npos);
157 EXPECT_TRUE(std::string(e.what()).find("Make sure to fill") != std::string::npos);
158 }
159
161 restricted_error_test(*mesh, {1}, "is_restricted");
162 try
163 {
164 restricted_error_test(
165 FaceArg{&all_fi[2], LimiterType::CentralDifference, true, false, nullptr, nullptr},
167 EXPECT_TRUE(false);
168 }
169 catch (std::runtime_error & e)
170 {
171 EXPECT_TRUE(std::string(e.what()).find("is_restricted") != std::string::npos);
172 EXPECT_TRUE(std::string(e.what()).find("0") != std::string::npos);
173 EXPECT_TRUE(
174 std::string(e.what()).find(
175 "that subdomain id is not one of the subdomain ids the functor is restricted to") !=
176 std::string::npos);
177 }
178}
A functor whose evaluation relies on querying a map where the keys are face info ids and the values c...
T & set(const std::string &name, bool quiet_mode=false)
MeshBase & mesh
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cos(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cos
std::unique_ptr< MooseApp > createMooseApp(const std::string &default_app_type, int argc, char *argv[])
StateArg currentState()
VectorValue< Real > RealVectorValue