Skip to content

Commit

Permalink
Revert "Converted to the new STK simple_fields workflow (#1233)" (#1234)
Browse files Browse the repository at this point in the history
This reverts commit 8e8f4d5.
  • Loading branch information
jrood-nrel authored Jan 5, 2024
1 parent 70e576b commit 69e080b
Show file tree
Hide file tree
Showing 226 changed files with 2,633 additions and 2,679 deletions.
43 changes: 22 additions & 21 deletions docs/source/theory/codeAbstractions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ elemental, nodal, face and edge of desired size.
const int numStates = realm_.number_of_states();
// declare it
density_ = &(metaData_.declare_field<double>(stk::topology::NODE_RANK,
"density", numStates));
density_
= &(metaData_.declare_field<ScalarFieldType>(stk::topology::NODE_RANK,
"density", numStates));
// put it on this part
stk::mesh::put_field_on_mesh(*density_, *part, nullptr);
stk::mesh::put_field(*density_, *part);
}
:math:`\bullet` edge field registration:
Expand All @@ -276,11 +277,9 @@ elemental, nodal, face and edge of desired size.
{
const int nDim = metaData_.spatial_dimension();
edgeAreaVec_
= &(metaData_.declare_field<double>(stk::topology::EDGE_RANK,
"edge_area_vector"));
stk::mesh::put_field_on_mesh(*edgeAreaVec_, *part, nDim, nullptr);
stk::io::set_field_output_type(*edgeAreaVec_,
stk::io::FieldOutputType::VECTOR_3D);
= &(metaData_.declare_field<VectorFieldType>(stk::topology::EDGE_RANK,
"edge_area_vector"));
stk::mesh::put_field(*edgeAreaVec_, *part, nDim);
}
:math:`\bullet` side/face field registration:
Expand All @@ -298,10 +297,9 @@ elemental, nodal, face and edge of desired size.
stk::topology::rank_t sideRank
= static_cast<stk::topology::rank_t>(metaData_.side_rank());
GenericFieldType *wallFrictionVelocityBip
= &(metaData_.declare_field<double>
= &(metaData_.declare_field<GenericFieldType>
(sideRank, "wall_friction_velocity_bip"));
stk::mesh::put_field_on_mesh(*wallFrictionVelocityBip, *part, numIp,
nullptr);
stk::mesh::put_field(*wallFrictionVelocityBip, *part, numIp);
}
}
Expand All @@ -319,21 +317,23 @@ addition to the field template type,
.. code-block:: c++
VectorFieldType *velocityRTM
= metaData_.get_field<double>(stk::topology::NODE_RANK, "velocity");
= metaData_.get_field<VectorFieldType>(stk::topology::NODE_RANK,
"velocity");
ScalarFieldType *density
= metaData_.get_field<double>(stk::topology::NODE_RANK, "density");}
= metaData_.get_field<ScalarFieldType>(stk::topology::NODE_RANK,
"density");}
VectorFieldType *edgeAreaVec
= metaData_.get_field<double>(stk::topology::EDGE_RANK,
"edge_area_vector");
= metaData_.get_field<VectorFieldType>(stk::topology::EDGE_RANK,
"edge_area_vector");
GenericFieldType *massFlowRate
= metaData_.get_field<double>(stk::topology::ELEMENT_RANK,
"mass_flow_rate_scs");
GenericFieldType *massFlowRate
= metaData_.get_field<GenericFieldType>(stk::topology::ELEMENT_RANK,
"mass_flow_rate_scs");
GenericFieldType *wallFrictionVelocityBip_
= metaData_.get_field<double>(metaData_.side_rank(),
"wall_friction_velocity_bip");
= metaData_.get_field<GenericFieldType>(metaData_.side_rank(),
"wall_friction_velocity_bip");
State
~~~~~
Expand All @@ -346,7 +346,8 @@ extracted,
.. code-block:: c++
ScalarFieldType *density
= metaData_.get_field<double>(stk::topology::NODE_RANK, "density");
= metaData_.get_field<ScalarFieldType>(stk::topology::NODE_RANK,
"density");
densityNm1_ = &(density->field_of_state(stk::mesh::StateNM1));
densityN_ = &(density->field_of_state(stk::mesh::StateN));
densityNp1_ = &(density->field_of_state(stk::mesh::StateNP1));
Expand Down
62 changes: 33 additions & 29 deletions include/FieldDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,30 @@
namespace sierra {
namespace nalu {

enum class FieldLayout { SCALAR, VECTOR, TENSOR, ARRAY };

template <typename T, FieldLayout Layout = FieldLayout::SCALAR>
template <typename T>
struct FieldDefinition
{
using DataType = T;
using FieldType = T;
const stk::topology::rank_t rank;
const int num_states{1};
const int num_components{1};
const FieldLayout layout{Layout};
};

using FieldDefScalar = FieldDefinition<double>;
using FieldDefVector = FieldDefinition<double, FieldLayout::VECTOR>;
using FieldDefTensor = FieldDefinition<double, FieldLayout::TENSOR>;
using FieldDefGeneric = FieldDefinition<double, FieldLayout::ARRAY>;
using FieldDefGenericInt = FieldDefinition<int, FieldLayout::ARRAY>;
using FieldDefTpetraId = FieldDefinition<TpetIdType>;
using FieldDefLocalId = FieldDefinition<LocalId>;
using FieldDefGlobalId = FieldDefinition<stk::mesh::EntityId>;
using FieldDefHypreId = FieldDefinition<HypreIntType>;
using FieldDefScalarInt = FieldDefinition<int>;
using FieldDefScalar = FieldDefinition<ScalarFieldType>;
using FieldDefVector = FieldDefinition<VectorFieldType>;
using FieldDefTensor = FieldDefinition<TensorFieldType>;
using FieldDefGeneric = FieldDefinition<GenericFieldType>;
using FieldDefGenericInt = FieldDefinition<GenericIntFieldType>;
using FieldDefTpetraId = FieldDefinition<TpetIDFieldType>;
using FieldDefLocalId = FieldDefinition<LocalIdFieldType>;
using FieldDefGlobalId = FieldDefinition<GlobalIdFieldType>;
using FieldDefHypreId = FieldDefinition<HypreIDFieldType>;
using FieldDefScalarInt = FieldDefinition<ScalarIntFieldType>;

// Type redundancy can occur between HypreId and ScalarInt
// which will break std::variant
using FieldDefTypes = std::conditional<
std::is_same_v<int, HypreIntType>,
std::is_same_v<ScalarIntFieldType, HypreIDFieldType>,
std::variant<
FieldDefScalar,
FieldDefVector,
Expand All @@ -64,22 +61,29 @@ using FieldDefTypes = std::conditional<
FieldDefScalarInt,
FieldDefHypreId>>::type;

// Trouble!
using FieldPointerTypes = std::conditional<
std::is_same_v<int, HypreIntType>,
std::is_same_v<ScalarIntFieldType, HypreIDFieldType>,
std::variant<
stk::mesh::Field<double>*,
stk::mesh::Field<int>*,
stk::mesh::Field<LocalId>*,
stk::mesh::Field<stk::mesh::EntityId>*,
stk::mesh::Field<TpetIdType>*>,
ScalarFieldType*,
VectorFieldType*,
TensorFieldType*,
GenericFieldType*,
GenericIntFieldType*,
TpetIDFieldType*,
LocalIdFieldType*,
GlobalIdFieldType*,
ScalarIntFieldType*>,
std::variant<
stk::mesh::Field<double>*,
stk::mesh::Field<int>*,
stk::mesh::Field<LocalId>*,
stk::mesh::Field<stk::mesh::EntityId>*,
stk::mesh::Field<TpetIdType>*,
stk::mesh::Field<HypreIntType>*>>::type;
ScalarFieldType*,
VectorFieldType*,
TensorFieldType*,
GenericFieldType*,
GenericIntFieldType*,
TpetIDFieldType*,
LocalIdFieldType*,
GlobalIdFieldType*,
ScalarIntFieldType*,
HypreIDFieldType*>>::type;

} // namespace nalu
} // namespace sierra
Expand Down
22 changes: 13 additions & 9 deletions include/FieldManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FieldManager
/// ScalarFieldType* and so on.
///
template <typename T>
stk::mesh::Field<T>* register_field(
T* register_field(
const std::string& name,
const stk::mesh::PartVector& parts,
const void* init_val = nullptr,
Expand Down Expand Up @@ -86,26 +86,28 @@ class FieldManager
stk::mesh::FieldState state = stk::mesh::FieldState::StateNone)
{
register_field(name, parts, numStates, numComponents, init_val);
return get_field_ptr<GenericFieldType::value_type>(name, state);
return get_field_ptr<GenericFieldType>(name, state);
}

// Return a field by the given name and of type T, the template parameter.
// This function will throw if the named field is not of the type
// specified by the template parameter: ScalarFieldType, VectorFieldType,
// ScalarIntFieldType, GlobalIdFieldType,....
template <typename T>
stk::mesh::Field<T>* get_field_ptr(
T* get_field_ptr(
const std::string& name,
stk::mesh::FieldState state = stk::mesh::FieldState::StateNone) const
{
FieldDefTypes fieldDef =
FieldRegistry::query(numDimensions_, numStates_, name);
FieldPointerTypes pointerSet = std::visit(
[&](auto def) -> FieldPointerTypes {
return &meta_.get_field<T>(def.rank, name)->field_of_state(state);
return &meta_
.get_field<typename decltype(def)::FieldType>(def.rank, name)
->field_of_state(state);
},
fieldDef);
return std::get<stk::mesh::Field<T>*>(pointerSet);
return std::get<T*>(pointerSet);
}

/// Register a field with the option to override default parameters that
Expand Down Expand Up @@ -137,7 +139,9 @@ class FieldManager
FieldRegistry::query(numDimensions_, numStates_, name);
const stk::mesh::FieldBase& stkField = std::visit(
[&](auto def) -> stk::mesh::FieldBase& {
return meta_.get_field<T>(def.rank, name)->field_of_state(state);
return meta_
.get_field<typename decltype(def)::FieldType>(def.rank, name)
->field_of_state(state);
},
fieldDef);
stk::mesh::NgpField<T>& tmp = stk::mesh::get_updated_ngp_field<T>(stkField);
Expand All @@ -150,16 +154,16 @@ class FieldManager
std::string name,
stk::mesh::FieldState state = stk::mesh::FieldState::StateNone) const
{
return MakeSmartField<tags::DEVICE, ACCESS>().template operator()(
return MakeSmartField<tags::DEVICE, ACCESS>().template operator()<T>(
get_ngp_field_ptr<T>(name, state));
}

template <typename T, typename ACCESS>
SmartField<stk::mesh::Field<T>, tags::LEGACY, ACCESS> get_legacy_smart_field(
SmartField<T, tags::LEGACY, ACCESS> get_legacy_smart_field(
std::string name,
stk::mesh::FieldState state = stk::mesh::FieldState::StateNone) const
{
return MakeSmartField<tags::LEGACY, ACCESS>().template operator()(
return MakeSmartField<tags::LEGACY, ACCESS>().template operator()<T>(
get_field_ptr<T>(name, state));
}
};
Expand Down
44 changes: 25 additions & 19 deletions include/FieldTypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define FieldTypeDef_h

#include <stk_mesh/base/FieldBase.hpp>
#include <stk_mesh/base/CoordinateSystems.hpp>
#include <stk_mesh/base/Ngp.hpp>
#include <stk_mesh/base/NgpField.hpp>

Expand All @@ -26,38 +27,43 @@
namespace sierra {
namespace nalu {

using ScalarFieldType = stk::mesh::Field<double>;
using GlobalIdFieldType = stk::mesh::Field<stk::mesh::EntityId>;
using ScalarIntFieldType = stk::mesh::Field<int>;
using NGPDoubleFieldType = stk::mesh::NgpField<double>;
using NGPGlobalIdFieldType = stk::mesh::NgpField<stk::mesh::EntityId>;
using NGPScalarIntFieldType = stk::mesh::NgpField<int>;
// define scalar field typedef
typedef stk::mesh::Field<double> ScalarFieldType;
typedef stk::mesh::Field<stk::mesh::EntityId> GlobalIdFieldType;
typedef stk::mesh::Field<int> ScalarIntFieldType;
typedef stk::mesh::NgpField<double> NGPDoubleFieldType;
typedef stk::mesh::NgpField<stk::mesh::EntityId> NGPGlobalIdFieldType;
typedef stk::mesh::NgpField<int> NGPScalarIntFieldType;

using VectorFieldType = stk::mesh::Field<double>;
using TensorFieldType = stk::mesh::Field<double>;
// define vector field typedef; however, what is the value of Cartesian?
typedef stk::mesh::Field<double, stk::mesh::Cartesian> VectorFieldType;
typedef stk::mesh::Field<double, stk::mesh::FullTensor> TensorFieldType;

using GenericFieldType = stk::mesh::Field<double>;
// define generic
typedef stk::mesh::Field<double, stk::mesh::SimpleArrayTag> GenericFieldType;

using GenericIntFieldType = stk::mesh::Field<int>;
typedef stk::mesh::Field<int, stk::mesh::SimpleArrayTag> GenericIntFieldType;

using LocalId = unsigned;
using LocalIdFieldType = stk::mesh::Field<LocalId>;
// field type for local ids
typedef unsigned LocalId;
typedef stk::mesh::Field<LocalId> LocalIdFieldType;

// Hypre Integer types
#ifdef NALU_USES_HYPRE
using HypreIntType = HYPRE_Int;
typedef HYPRE_Int HypreIntType;
#else
using HypreIntType = int;
typedef int HypreIntType;
#endif

#ifdef NALU_USES_TRILINOS_SOLVERS
using TpetIdType = Tpetra::Details::DefaultTypes::global_ordinal_type;
typedef stk::mesh::Field<Tpetra::Details::DefaultTypes::global_ordinal_type>
TpetIDFieldType;
#else
using TpetIdType = int64_t;
typedef stk::mesh::Field<int64_t> TpetIDFieldType;
#endif

using TpetIDFieldType = stk::mesh::Field<TpetIdType>;
using HypreIDFieldType = stk::mesh::Field<HypreIntType>;
using NGPHypreIDFieldType = stk::mesh::NgpField<HypreIntType>;
typedef stk::mesh::Field<HypreIntType> HypreIDFieldType;
typedef stk::mesh::NgpField<HypreIntType> NGPHypreIDFieldType;

} // namespace nalu
} // namespace sierra
Expand Down
1 change: 1 addition & 0 deletions include/MatrixFreeHeatCondEquationSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Kokkos_Array.hpp"

#include "stk_mesh/base/Ngp.hpp"
#include "stk_mesh/base/CoordinateSystems.hpp"

#include "Realm.h"

Expand Down
1 change: 1 addition & 0 deletions include/ProjectedNodalGradientEquationSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <NaluParsedTypes.h>

#include <stk_mesh/base/FieldBase.hpp>
#include <stk_mesh/base/CoordinateSystems.hpp>

namespace stk {
struct topology;
Expand Down
5 changes: 2 additions & 3 deletions include/SmartField.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,9 @@ struct MakeSmartField<LEGACY, ACCESS>
{
// use pointer since that is the common access type for stk::mesh::Field<T>
template <typename T>
SmartField<stk::mesh::Field<T>, LEGACY, ACCESS>
operator()(stk::mesh::Field<T>* field)
SmartField<T, LEGACY, ACCESS> operator()(T* field)
{
return SmartField<stk::mesh::Field<T>, LEGACY, ACCESS>(*field);
return SmartField<T, LEGACY, ACCESS>(*field);
}
};

Expand Down
Loading

0 comments on commit 69e080b

Please sign in to comment.