|
| 1 | +#include <gtest/gtest.h> |
| 2 | +#include <limits> |
| 3 | + |
| 4 | +#include <stk_util/parallel/Parallel.hpp> |
| 5 | +#include <stk_mesh/base/MetaData.hpp> |
| 6 | +#include <stk_mesh/base/BulkData.hpp> |
| 7 | +#include <stk_mesh/base/Bucket.hpp> |
| 8 | +#include <stk_mesh/base/CoordinateSystems.hpp> |
| 9 | +#include <stk_mesh/base/FieldBase.hpp> |
| 10 | +#include <stk_mesh/base/Field.hpp> |
| 11 | +#include <stk_mesh/base/GetEntities.hpp> |
| 12 | + |
| 13 | +#include "UnitTestUtils.h" |
| 14 | + |
| 15 | +namespace { |
| 16 | +
|
| 17 | +unsigned count_locally_owned_elems(const stk::mesh::BulkData& bulk) |
| 18 | +{ |
| 19 | + return stk::mesh::count_selected_entities(bulk.mesh_meta_data().locally_owned_part(), |
| 20 | + bulk.buckets(stk::topology::ELEM_RANK)); |
| 21 | +} |
| 22 | + |
| 23 | +void verify_elems_are_unit_cubes(const stk::mesh::BulkData& bulk) |
| 24 | +{ |
| 25 | + typedef stk::mesh::Field<double,stk::mesh::Cartesian> CoordFieldType; |
| 26 | + CoordFieldType* coordField = bulk.mesh_meta_data().get_field<CoordFieldType>(stk::topology::NODE_RANK, "coordinates"); |
| 27 | + EXPECT_TRUE(coordField != nullptr); |
| 28 | + |
| 29 | + stk::mesh::EntityVector elems; |
| 30 | + stk::mesh::get_entities(bulk, stk::topology::ELEM_RANK, elems); |
| 31 | + |
| 32 | + const double tolerance = std::numeric_limits<double>::epsilon(); |
| 33 | + |
| 34 | + for(stk::mesh::Entity elem : elems) { |
| 35 | + double minX = 999.99, minY = 999.99, minZ = 999.99; |
| 36 | + double maxX = 0, maxY = 0, maxZ = 0; |
| 37 | + const stk::mesh::Entity* nodes = bulk.begin_nodes(elem); |
| 38 | + unsigned numNodes = bulk.num_nodes(elem); |
| 39 | + for(unsigned i=0; i<numNodes; ++i) { |
| 40 | + double* nodeCoords = stk::mesh::field_data(*coordField, nodes[i]); |
| 41 | + minX = std::min(minX, nodeCoords[0]); |
| 42 | + minY = std::min(minY, nodeCoords[1]); |
| 43 | + minZ = std::min(minZ, nodeCoords[2]); |
| 44 | + maxX = std::max(maxX, nodeCoords[0]); |
| 45 | + maxY = std::max(maxY, nodeCoords[1]); |
| 46 | + maxZ = std::max(maxZ, nodeCoords[2]); |
| 47 | + } |
| 48 | + |
| 49 | + EXPECT_NEAR(1.0, (maxX-minX), tolerance); |
| 50 | + EXPECT_NEAR(1.0, (maxY-minY), tolerance); |
| 51 | + EXPECT_NEAR(1.0, (maxZ-minZ), tolerance); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +}//namespace |
| 56 | + |
| 57 | +TEST(Basic, CheckCoords1Elem) |
| 58 | +{ |
| 59 | + stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 60 | + |
| 61 | + unsigned spatialDimension = 3; |
| 62 | + stk::mesh::MetaData meta(spatialDimension); |
| 63 | + stk::mesh::BulkData bulk(meta, comm); |
| 64 | + |
| 65 | + unit_test_utils::fill_mesh_1_elem_per_proc_hex8(bulk); |
| 66 | + |
| 67 | + EXPECT_EQ(1u, count_locally_owned_elems(bulk)); |
| 68 | + |
| 69 | + verify_elems_are_unit_cubes(bulk); |
| 70 | +} |
| 71 | + |
0 commit comments