SpatialOps
Inferring field types

Goal of this example

This example will show how to obtain related field types from an existing field or operator type. This is very useful for finite volume calculations where we want to obtain the type of x-face field given a volume field type, for example.

Key Concepts

  1. While new field types can be added to SpatialOps, a list of commonly used field types is provided in FVStaggeredFieldTypes.h. See also the Field Types module.
  2. To obtain the face types associated with a volume field type, use FaceTypes
    typedef FaceTypes<VolT>::XFace XFaceT;
    typedef FaceTypes<VolT>::YFace YFaceT;
    typedef FaceTypes<VolT>::ZFace ZFaceT;
  3. To obtain the volume field type associated with a given face type, use VolType
    typedef VolType<FaceT>::VolField VolT;
  4. Operator types can be used to infer field types:
    typedef OpType::SrcFieldT SrcT; // the type of field that OpType acts on
    typedef OpType::DestFieldT DestT; // the type of field that OpType produces
See also
Some natively supported field types
The Field Types module, which documents the field types and type inference tools in SpatialOps.
Fields and Meshes and Field type inference

Example Code

examples/field_type_inference.cpp

#include <spatialops/structured/FVStaggered.h> // field type definitions, etc.
#include <spatialops/SpatialOpsTools.h> // for is_same_type
#include <cassert>
using namespace SpatialOps;
int main()
{
//
// Field types associated with the non-staggered, cell-centered ("scalar") mesh
//
typedef FaceTypes<SVolField>::XFace XFaceT; // same as SSurfXField
typedef FaceTypes<SVolField>::YFace YFaceT; // same as SSurfYField
typedef FaceTypes<SVolField>::ZFace ZFaceT; // same as SSurfZField
assert(( is_same_type< XFaceT, SSurfXField >() ));
assert(( is_same_type< YFaceT, SSurfYField >() ));
assert(( is_same_type< ZFaceT, SSurfZField >() ));
//
// Field types associated with the x-staggered mesh
//
typedef FaceTypes<XVolField>::XFace XMeshXFaceT; // same as XSurfXField
typedef FaceTypes<XVolField>::YFace XMeshYFaceT; // same as XSurfYField
typedef FaceTypes<XVolField>::ZFace XMeshZFaceT; // same as XSurfZField
assert(( is_same_type< XMeshXFaceT, XSurfXField >() ));
assert(( is_same_type< XMeshYFaceT, XSurfYField >() ));
assert(( is_same_type< XMeshZFaceT, XSurfZField >() ));
//
// Field types associated with the y-staggered mesh
//
typedef FaceTypes<YVolField>::XFace YMeshXFaceT; // same as YSurfXField
typedef FaceTypes<YVolField>::YFace YMeshYFaceT; // same as YSurfYField
typedef FaceTypes<YVolField>::ZFace YMeshZFaceT; // same as YSurfZField
assert(( is_same_type< YMeshXFaceT, YSurfXField >() ));
assert(( is_same_type< YMeshYFaceT, YSurfYField >() ));
assert(( is_same_type< YMeshZFaceT, YSurfZField >() ));
//
// Field types associated with the z-staggered mesh
//
typedef FaceTypes<ZVolField>::XFace ZMeshXFaceT; // same as ZSurfXField
typedef FaceTypes<ZVolField>::YFace ZMeshYFaceT; // same as ZSurfYField
typedef FaceTypes<ZVolField>::ZFace ZMeshZFaceT; // same as ZSurfZField
assert(( is_same_type< ZMeshXFaceT, ZSurfXField >() ));
assert(( is_same_type< ZMeshYFaceT, ZSurfYField >() ));
assert(( is_same_type< ZMeshZFaceT, ZSurfZField >() ));
return 0;
}