SpatialOps
Some natively supported field types

Goal of this example

This example will show all 16 Field types and illustrate how they are different.

Key Concepts

  1. This example also illustrates the different layouts of fields.
See also
Basics of field creation
Inferring field types
The Field Types module, which documents the field types and type inference tools in SpatialOps.

Example Code

examples/field_types.cpp

#include <spatialops/structured/Grid.h>
#include <iostream>
#include <iomanip>
#include <string>
using namespace SpatialOps;
using namespace std;
//==============================================================================
template<typename FieldT>
void driver( const string tag )
{
cout << tag << std::endl;
// Define the size and number of points in the domain
const IntVec fieldDim( 5, 5, 1 ); // 5 x 5 x 1 points
const DoubleVec domainLength( 5.0, 5.0, 5.0 ); // a cube of length 5.0
//----------------------------------------------------------------------------
// Create coordinate fields of type FieldT.
const bool bcx=true, bcy=true, bcz=true;
const IntVec bc(bcx,bcy,bcz);
const GhostData nghost(0);
const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bc,bc );
const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
FieldT x( window, bcInfo, nghost, NULL, InternalStorage );
FieldT y( window, bcInfo, nghost, NULL, InternalStorage );
FieldT z( window, bcInfo, nghost, NULL, InternalStorage );
//----------------------------------------------------------------------------
// Set coordinate fields.
const Grid grid( fieldDim, domainLength );
grid.set_coord<XDIR>(x);
grid.set_coord<YDIR>(y);
grid.set_coord<ZDIR>(z);
//----------------------------------------------------------------------------
// Print coordinates
cout << "x:" << std::endl; print_field( x, cout );
cout << "y:" << std::endl; print_field( y, cout );
cout << "z:" << std::endl; print_field( z, cout );
}
//==============================================================================
int main()
{
driver< SVolField>( "SVolField - volume field on the scalar volume" );
driver<SSurfXField>( "SSurfXField - x-surface field on the scalar volume" );
driver<SSurfYField>( "SSurfYField - y-surface field on the scalar volume" );
driver<SSurfZField>( "SSurfZField - z-surface field on the scalar volume" );
driver< XVolField>( "XVolField - volume field on the x-staggered volume" );
driver<XSurfXField>( "XSurfXField - x-surface field on the x-staggered volume" );
driver<XSurfYField>( "XSurfYField - y-surface field on the x-staggered volume" );
driver<XSurfZField>( "XSurfZField - z-surface field on the x-staggered volume" );
driver< YVolField>( "YVolField - volume field on the y-staggered volume" );
driver<YSurfXField>( "YSurfXField - x-surface field on the y-staggered volume" );
driver<YSurfYField>( "YSurfYField - y-surface field on the y-staggered volume" );
driver<YSurfZField>( "YSurfZField - z-surface field on the y-staggered volume" );
driver< ZVolField>( "ZVolField - volume field on the z-staggered volume" );
driver<ZSurfXField>( "ZSurfXField - x-surface field on the z-staggered volume" );
driver<ZSurfYField>( "ZSurfYField - y-surface field on the z-staggered volume" );
driver<ZSurfZField>( "ZSurfZField - z-surface field on the z-staggered volume" );
return 0;
}