|
9 | 9 |
|
10 | 10 | #include "test_comm.h"
|
11 | 11 | #include "libmesh_cppunit.h"
|
| 12 | +#include "libmesh/enum_xdr_mode.h" |
12 | 13 |
|
13 | 14 |
|
14 | 15 | using namespace libMesh;
|
@@ -43,6 +44,9 @@ public:
|
43 | 44 |
|
44 | 45 | #if LIBMESH_DIM > 1
|
45 | 46 | CPPUNIT_TEST( test_subdomain_id_sets );
|
| 47 | + CPPUNIT_TEST( vectorMeshFuctionLagrange ); |
| 48 | + CPPUNIT_TEST( vectorMeshFuctionNedelec ); |
| 49 | + CPPUNIT_TEST( vectorMeshFuctionRaviartThomas ); |
46 | 50 | #endif
|
47 | 51 | #if LIBMESH_DIM > 2
|
48 | 52 | #ifdef LIBMESH_ENABLE_AMR
|
@@ -220,7 +224,141 @@ public:
|
220 | 224 | }
|
221 | 225 | }
|
222 | 226 | #endif // LIBMESH_ENABLE_AMR
|
223 |
| -}; |
224 | 227 |
|
| 228 | + // Tests the projection of Lagrange Vectors using MeshFunction |
| 229 | + void vectorMeshFuctionLagrange() |
| 230 | + { |
| 231 | + LOG_UNIT_TEST; |
| 232 | + |
| 233 | + // Reading mesh and solution infromation from XDA files |
| 234 | + ReplicatedMesh mesh(*TestCommWorld); |
| 235 | + mesh.read("solutions/lagrange_vec_solution_mesh.xda"); |
| 236 | + EquationSystems es(mesh); |
| 237 | + es.read("solutions/lagrange_vec_solution.xda", READ, |
| 238 | + EquationSystems::READ_HEADER | |
| 239 | + EquationSystems::READ_DATA | |
| 240 | + EquationSystems::READ_ADDITIONAL_DATA); |
| 241 | + es.update(); |
| 242 | + |
| 243 | + // Pulling the correct system and variable infromation from |
| 244 | + // the XDA files (the default system name is "nl0") |
| 245 | + System & sys = es.get_system<System>("nl0"); |
| 246 | + std::unique_ptr<NumericVector<Number>> mesh_function_vector = |
| 247 | + NumericVector<Number>::build(es.comm()); |
| 248 | + mesh_function_vector->init(sys.n_dofs(), false, SERIAL); |
| 249 | + sys.solution->localize(*mesh_function_vector); |
| 250 | + |
| 251 | + // Setting up libMesh::MeshFuction |
| 252 | + MeshFunction mesh_function(es, *mesh_function_vector, |
| 253 | + sys.get_dof_map(), 0); |
| 254 | + mesh_function.init(); |
| 255 | + |
| 256 | + // Defining input parameters for MeshFunction::operator() |
| 257 | + DenseVector<Gradient> output; |
| 258 | + const std::set<subdomain_id_type> * subdomain_ids = nullptr; |
| 259 | + const Point & p = Point(0.5, 0.5); |
| 260 | + |
| 261 | + // Suppling the Lagrange Vec value at center of mesh to output |
| 262 | + (mesh_function)(p, 0.0, output, subdomain_ids); |
| 263 | + |
| 264 | + // Expected value at center mesh |
| 265 | + Gradient output_expected = Gradient(0.100977281077292,0.201954562154583); |
| 266 | + |
| 267 | + LIBMESH_ASSERT_FP_EQUAL(output(0)(0), output_expected(0), |
| 268 | + TOLERANCE * TOLERANCE); |
| 269 | + LIBMESH_ASSERT_FP_EQUAL(output(0)(1), output_expected(1), |
| 270 | + TOLERANCE * TOLERANCE); |
| 271 | + } |
| 272 | + |
| 273 | + // Tests the projection of Nedelec Vectors using MeshFunction |
| 274 | + void vectorMeshFuctionNedelec() |
| 275 | + { |
| 276 | + LOG_UNIT_TEST; |
| 277 | + |
| 278 | + // Reading mesh and solution infromation from XDA files |
| 279 | + ReplicatedMesh mesh(*TestCommWorld); |
| 280 | + mesh.read("solutions/nedelec_one_solution_mesh.xda"); |
| 281 | + EquationSystems es(mesh); |
| 282 | + es.read("solutions/nedelec_one_solution.xda", READ, |
| 283 | + EquationSystems::READ_HEADER | |
| 284 | + EquationSystems::READ_DATA | |
| 285 | + EquationSystems::READ_ADDITIONAL_DATA); |
| 286 | + es.update(); |
| 287 | + |
| 288 | + // Pulling the correct system and variable infromation from |
| 289 | + // the XDA files (the default system name is "nl0") |
| 290 | + System & sys = es.get_system<System>("nl0"); |
| 291 | + std::unique_ptr<NumericVector<Number>> mesh_function_vector = |
| 292 | + NumericVector<Number>::build(es.comm()); |
| 293 | + mesh_function_vector->init(sys.n_dofs(), false, SERIAL); |
| 294 | + sys.solution->localize(*mesh_function_vector); |
| 295 | + |
| 296 | + // Setting up libMesh::MeshFuction |
| 297 | + MeshFunction mesh_function(es, *mesh_function_vector, |
| 298 | + sys.get_dof_map(), 0); |
| 299 | + mesh_function.init(); |
| 300 | + |
| 301 | + // Defining input parameters for MeshFunction::operator() |
| 302 | + DenseVector<Gradient> output; |
| 303 | + const std::set<subdomain_id_type> * subdomain_ids = nullptr; |
| 304 | + const Point & p = Point(0.5, 0.5); |
| 305 | + |
| 306 | + // Suppling the Nedelec One value at center of mesh to output |
| 307 | + (mesh_function)(p, 0.0, output, subdomain_ids); |
| 308 | + |
| 309 | + // Expected value at center mesh |
| 310 | + Gradient output_expected = Gradient(0.0949202883998996,-0.0949202883918033); |
| 311 | + |
| 312 | + LIBMESH_ASSERT_FP_EQUAL(output(0)(0), output_expected(0), |
| 313 | + TOLERANCE * TOLERANCE); |
| 314 | + LIBMESH_ASSERT_FP_EQUAL(output(0)(1), output_expected(1), |
| 315 | + TOLERANCE * TOLERANCE); |
| 316 | + } |
| 317 | + |
| 318 | + // Tests the projection of Raviart Thomas Vectors using MeshFunction |
| 319 | + void vectorMeshFuctionRaviartThomas() |
| 320 | + { |
| 321 | + LOG_UNIT_TEST; |
| 322 | + |
| 323 | + // Reading mesh and solution infromation from XDA files |
| 324 | + ReplicatedMesh mesh(*TestCommWorld); |
| 325 | + mesh.read("solutions/raviart_thomas_solution_mesh.xda"); |
| 326 | + EquationSystems es(mesh); |
| 327 | + es.read("solutions/raviart_thomas_solution.xda", READ, |
| 328 | + EquationSystems::READ_HEADER | |
| 329 | + EquationSystems::READ_DATA | |
| 330 | + EquationSystems::READ_ADDITIONAL_DATA); |
| 331 | + es.update(); |
| 332 | + |
| 333 | + // Pulling the correct system and variable infromation from |
| 334 | + // the XDA files (the default system name is "nl0") |
| 335 | + System & sys = es.get_system<System>("nl0"); |
| 336 | + std::unique_ptr<NumericVector<Number>> mesh_function_vector = |
| 337 | + NumericVector<Number>::build(es.comm()); |
| 338 | + mesh_function_vector->init(sys.n_dofs(), false, SERIAL); |
| 339 | + sys.solution->localize(*mesh_function_vector); |
| 340 | + |
| 341 | + // Setting up libMesh::MeshFuction |
| 342 | + MeshFunction mesh_function(es, *mesh_function_vector, |
| 343 | + sys.get_dof_map(), 0); |
| 344 | + mesh_function.init(); |
| 345 | + |
| 346 | + // Defining input parameters for MeshFunction::operator() |
| 347 | + DenseVector<Gradient> output; |
| 348 | + const std::set<subdomain_id_type> * subdomain_ids = nullptr; |
| 349 | + const Point & p = Point(0.5, 0.5); |
| 350 | + |
| 351 | + // Suppling the Raviart Thomas value at center of mesh to output |
| 352 | + (mesh_function)(p, 0.0, output, subdomain_ids); |
| 353 | + |
| 354 | + // Expected value at center mesh |
| 355 | + Gradient output_expected = Gradient(0.0772539939808116,-0.0772537479511396); |
| 356 | + |
| 357 | + LIBMESH_ASSERT_FP_EQUAL(output(0)(0), output_expected(0), |
| 358 | + TOLERANCE * TOLERANCE); |
| 359 | + LIBMESH_ASSERT_FP_EQUAL(output(0)(1), output_expected(1), |
| 360 | + TOLERANCE * TOLERANCE); |
| 361 | + } |
| 362 | +}; |
225 | 363 |
|
226 |
| -CPPUNIT_TEST_SUITE_REGISTRATION( MeshFunctionTest ); |
| 364 | +CPPUNIT_TEST_SUITE_REGISTRATION(MeshFunctionTest); |
0 commit comments