SpatialOps
stencil_type_inference.cpp
Go to the documentation of this file.
1 
71 #include <spatialops/structured/FVStaggered.h> // defines field and operator types for structured meshes
72 #include <spatialops/SpatialOpsTools.h> // for is_same_type
73 
74 #include <cassert>
75 
76 using namespace SpatialOps;
77 
78 int main()
79 {
80  //----------------------------------------------------------------------------
81  // Illustrate type inference to obtain various operator types from a given
82  // volume field type. If an invalid "volume" field is provided, a compiler
83  // error will result.
84  typedef BasicOpTypes<SVolField>::GradX GradX; // x-derivative operator type
85  typedef BasicOpTypes<SVolField>::GradY GradY; // y-derivative operator type
86  typedef BasicOpTypes<SVolField>::GradZ GradZ; // z-derivative operator type
87 
88  typedef BasicOpTypes<SVolField>::InterpC2FX InterpX; // x-interpolant operator type
89  typedef BasicOpTypes<SVolField>::InterpC2FY InterpY; // y-interpolant operator type
90  typedef BasicOpTypes<SVolField>::InterpC2FZ InterpZ; // z-interpolant operator type
91 
92  typedef BasicOpTypes<SVolField>::DivX DivX; // x-divergence operator
93  typedef BasicOpTypes<SVolField>::DivY DivY; // y-divergence operator
94  typedef BasicOpTypes<SVolField>::DivZ DivZ; // z-divergence operator
95 
96 
97  //----------------------------------------------------------------------------
98  // Illustrate more general way to obtain operator types using OperatorTypeBuilder
99  // Here, we use the operation we want to accomplish (e.g., Interpolant) as
100  // well as the source and destination field types to obtain the operator type
101  // of interest. If no such operator has been defined, a compiler error will result.
105 
106  assert(( is_same_type< InterpX,InterpX2 >() ));
107  assert(( is_same_type< GradX, GradX2 >() ));
108  assert(( is_same_type< DivX, DivX2 >() ));
109 
110 
111  //----------------------------------------------------------------------------
112  // Operators define the types of fields that they operate on (source field types)
113  // as well as the type of field that they produce (destination field type)
114  assert(( is_same_type< InterpX::SrcFieldType, SVolField >() ));
115  assert(( is_same_type< InterpX::DestFieldType, SSurfXField>() ));
116 
117  assert(( is_same_type< DivY::SrcFieldType, SSurfYField>() ));
118  assert(( is_same_type< DivY::DestFieldType, SVolField >() ));
119 
120 
121  //----------------------------------------------------------------------------
122  // The examples above were dealing with the cell-centered mesh (with field types
123  // SVolField, SSurfXField, etc.) but we can also apply type inference for the
124  // staggered meshes.
125  typedef BasicOpTypes<XVolField>::GradX XVolGradX;
126  typedef BasicOpTypes<XVolField>::DivX XVolDivX;
127 
128  assert(( is_same_type< XVolGradX::DestFieldType, XVolDivX::SrcFieldType>() ));
129 
130  return 0;
131 }
Provides typedefs for common operator types on a given volume.
Builds operator types from field types and operator type descriptors.