| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc |
| 36 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 37 |
#include <stk_mesh/base/MeshBuilder.hpp> |
| 38 |
#include <stk_mesh/base/FEMHelpers.hpp> // for declare_element |
| 39 |
#include <stk_mesh/base/Field.hpp> // for Field |
| 40 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, put_field, etc |
| 41 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 42 |
#include "stk_mesh/base/FieldBase.hpp" // for field_scalars_per_entity, etc |
| 43 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 44 |
#include "stk_io/IossBridge.hpp" |
| 45 |
#include "stk_unit_test_utils/TextMesh.hpp" |
| 46 |
|
| 47 |
namespace { |
| 48 |
|
| 49 |
//BEGINUseAdvancedFields |
| 50 |
TEST(stkMeshHowTo, useAdvancedFields) |
| 51 |
{ |
| 52 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); } |
| 53 |
|
| 54 |
const unsigned spatialDimension = 3; |
| 55 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 56 |
builder.set_spatial_dimension(spatialDimension); |
| 57 |
std::unique_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 58 |
stk::mesh::MetaData& metaData = bulkPtr->mesh_meta_data(); |
| 59 |
|
| 60 |
typedef stk::mesh::Field<double> DoubleField; |
| 61 |
DoubleField& tensorField = metaData.declare_field<double>(stk::topology::ELEM_RANK, "tensor"); |
| 62 |
DoubleField& variableSizeField = metaData.declare_field<double>(stk::topology::ELEM_RANK, "variableSizeField"); |
| 63 |
|
| 64 |
stk::mesh::Part &tetPart = metaData.declare_part_with_topology("tetElementPart", stk::topology::TET_4); |
| 65 |
stk::mesh::Part &hexPart = metaData.declare_part_with_topology("hexElementPart", stk::topology::HEX_8); |
| 66 |
|
| 67 |
const int numTensorValues = 9; |
| 68 |
const int numCopies = 2; |
| 69 |
double initialTensorValue[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 70 |
11, 12, 13, 14, 15, 16, 17, 18, 19}; |
| 71 |
stk::mesh::put_field_on_mesh(tensorField, metaData.universal_part(), numTensorValues, numCopies, initialTensorValue); |
| 72 |
stk::io::set_field_output_type(tensorField, stk::io::FieldOutputType::FULL_TENSOR_36); |
| 73 |
|
| 74 |
const int numVectorValues = 3; |
| 75 |
double initialVectorValue[] = {1, 2, 3, 11, 12, 13}; |
| 76 |
stk::mesh::put_field_on_mesh(variableSizeField, tetPart, numVectorValues, initialVectorValue); |
| 77 |
stk::mesh::put_field_on_mesh(variableSizeField, hexPart, numVectorValues, numCopies, initialVectorValue); |
| 78 |
stk::io::set_field_output_type(variableSizeField, stk::io::FieldOutputType::VECTOR_3D); |
| 79 |
|
| 80 |
std::string meshSpec = "0,1,TET_4, 1,2,3,4, tetElementPart\n" |
| 81 |
"0,2,HEX_8, 5,6,7,8,9,10,11,12, hexElementPart"; |
| 82 |
stk::unit_test_util::setup_text_mesh(*bulkPtr, meshSpec); |
| 83 |
|
| 84 |
stk::mesh::Entity tetElem = bulkPtr->get_entity(stk::topology::ELEM_RANK, 1); |
| 85 |
stk::mesh::Entity hexElem = bulkPtr->get_entity(stk::topology::ELEM_RANK, 2); |
| 86 |
|
| 87 |
const int tensorScalarsPerTet = stk::mesh::field_scalars_per_entity(tensorField, tetElem); |
| 88 |
const int tensorScalarsPerHex = stk::mesh::field_scalars_per_entity(tensorField, hexElem); |
| 89 |
EXPECT_EQ(tensorScalarsPerTet, numTensorValues*numCopies); |
| 90 |
EXPECT_EQ(tensorScalarsPerHex, numTensorValues*numCopies); |
| 91 |
|
| 92 |
const int tensorExtent0PerTet = stk::mesh::field_extent0_per_entity(tensorField, tetElem); |
| 93 |
const int tensorExtent0PerHex = stk::mesh::field_extent0_per_entity(tensorField, hexElem); |
| 94 |
EXPECT_EQ(tensorExtent0PerTet, numTensorValues); |
| 95 |
EXPECT_EQ(tensorExtent0PerHex, numTensorValues); |
| 96 |
|
| 97 |
const int tensorExtent1PerTet = stk::mesh::field_extent1_per_entity(tensorField, tetElem); |
| 98 |
const int tensorExtent1PerHex = stk::mesh::field_extent1_per_entity(tensorField, hexElem); |
| 99 |
EXPECT_EQ(tensorExtent1PerTet, numCopies); |
| 100 |
EXPECT_EQ(tensorExtent1PerHex, numCopies); |
| 101 |
|
| 102 |
double* tensorData = stk::mesh::field_data(tensorField, hexElem); |
| 103 |
for (int i = 0; i < tensorScalarsPerHex; ++i) { |
| 104 |
EXPECT_EQ(initialTensorValue[i], tensorData[i]); |
| 105 |
} |
| 106 |
|
| 107 |
const int vectorScalarsPerTet = stk::mesh::field_scalars_per_entity(variableSizeField, tetElem); |
| 108 |
const int vectorScalarsPerHex = stk::mesh::field_scalars_per_entity(variableSizeField, hexElem); |
| 109 |
EXPECT_EQ(vectorScalarsPerTet, numVectorValues); |
| 110 |
EXPECT_EQ(vectorScalarsPerHex, numVectorValues*numCopies); |
| 111 |
|
| 112 |
const int vectorExtent0PerTet = stk::mesh::field_extent0_per_entity(variableSizeField, tetElem); |
| 113 |
const int vectorExtent0PerHex = stk::mesh::field_extent0_per_entity(variableSizeField, hexElem); |
| 114 |
EXPECT_EQ(vectorExtent0PerTet, numVectorValues); |
| 115 |
EXPECT_EQ(vectorExtent0PerHex, numVectorValues); |
| 116 |
|
| 117 |
const int vectorExtent1PerTet = stk::mesh::field_extent1_per_entity(variableSizeField, tetElem); |
| 118 |
const int vectorExtent1PerHex = stk::mesh::field_extent1_per_entity(variableSizeField, hexElem); |
| 119 |
EXPECT_EQ(vectorExtent1PerTet, 1); |
| 120 |
EXPECT_EQ(vectorExtent1PerHex, numCopies); |
| 121 |
|
| 122 |
double* vectorTetData = stk::mesh::field_data(variableSizeField, tetElem); |
| 123 |
for (int i = 0; i < vectorScalarsPerTet; ++i) { |
| 124 |
EXPECT_EQ(initialVectorValue[i], vectorTetData[i]); |
| 125 |
} |
| 126 |
|
| 127 |
double* vectorHexData = stk::mesh::field_data(variableSizeField, hexElem); |
| 128 |
for (int i = 0; i < vectorScalarsPerHex; ++i) { |
| 129 |
EXPECT_EQ(initialVectorValue[i], vectorHexData[i]); |
| 130 |
} |
| 131 |
} |
| 132 |
//ENDUseAdvancedFields |
| 133 |
|
| 134 |
} |