| 1 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc |
| 2 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 3 |
#include <stk_io/FillMesh.hpp> |
| 4 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 5 |
#include <fstream> |
| 6 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 7 |
|
| 8 |
namespace |
| 9 |
{ |
| 10 |
|
| 11 |
using stk::unit_test_util::build_mesh; |
| 12 |
using stk::unit_test_util::build_mesh_no_simple_fields; |
| 13 |
|
| 14 |
class AttributesInFile : public stk::unit_test_util::MeshFixture |
| 15 |
{ |
| 16 |
protected: |
| 17 |
const std::string filename = "fileWithAttr.e"; |
| 18 |
|
| 19 |
void expect_ordered_attributes(const stk::io::StkMeshIoBroker &stkIo) |
| 20 |
{ |
| 21 |
const stk::mesh::Part *blockPart = get_meta().get_part("block_10"); |
| 22 |
ASSERT_NE(nullptr, blockPart); |
| 23 |
stk::mesh::FieldVector attrFields = stkIo.get_ordered_attribute_fields(blockPart); |
| 24 |
std::vector<std::string> expectedNames = {"area", "i1", "i2", "j", "orient", "offset"}; |
| 25 |
ASSERT_EQ(expectedNames.size(), attrFields.size()); |
| 26 |
for(size_t i=0; i<expectedNames.size(); i++) |
| 27 |
EXPECT_EQ(expectedNames[i], attrFields[i]->name()); |
| 28 |
} |
| 29 |
|
| 30 |
void read_and_write(const std::string &outputFilename) |
| 31 |
{ |
| 32 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 33 |
stk::io::StkMeshIoBroker stkIo(get_comm()); |
| 34 |
stk::io::fill_mesh_preexisting(stkIo, filename, get_bulk()); |
| 35 |
|
| 36 |
stk::io::StkMeshIoBroker outputStkIo(get_comm()); |
| 37 |
outputStkIo.set_bulk_data(get_bulk()); |
| 38 |
size_t outputFileIndex = outputStkIo.create_output_mesh(outputFilename, stk::io::WRITE_RESULTS); |
| 39 |
outputStkIo.set_attribute_field_ordering_stored_by_part_ordinal(stkIo.get_attribute_field_ordering_stored_by_part_ordinal()); |
| 40 |
outputStkIo.write_output_mesh(outputFileIndex); |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
TEST_F(AttributesInFile, reading_fieldsReturnedInOrder) |
| 45 |
{ |
| 46 |
if (!std::ifstream(filename)) { |
| 47 |
std::cout<<"file "<<filename<<" doesn't exist, skipping test."<<std::endl; |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if(stk::parallel_machine_size(get_comm()) == 1) |
| 52 |
{ |
| 53 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 54 |
stk::io::StkMeshIoBroker stkIo(get_comm()); |
| 55 |
stk::io::fill_mesh_preexisting(stkIo, filename, get_bulk()); |
| 56 |
|
| 57 |
expect_ordered_attributes(stkIo); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
TEST_F(AttributesInFile, readWriteRead_fieldsReturnedInOrder) |
| 62 |
{ |
| 63 |
if (!std::ifstream(filename)) { |
| 64 |
std::cout<<"file "<<filename<<" doesn't exist, skipping test."<<std::endl; |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
if(stk::parallel_machine_size(get_comm()) == 1) |
| 69 |
{ |
| 70 |
const std::string outputFilename = "fileWithAttrOut.e"; |
| 71 |
read_and_write(outputFilename); |
| 72 |
|
| 73 |
std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(get_comm()); |
| 74 |
|
| 75 |
stk::io::StkMeshIoBroker stkIo(get_comm()); |
| 76 |
stk::io::fill_mesh_preexisting(stkIo, outputFilename, *bulk); |
| 77 |
|
| 78 |
expect_ordered_attributes(stkIo); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
} |