SpatialOps
field_types.cpp
Go to the documentation of this file.
1 
51 #include <spatialops/structured/Grid.h>
53 
54 #include <iostream>
55 #include <iomanip>
56 #include <string>
57 
58 using namespace SpatialOps;
59 using namespace std;
60 
61 //==============================================================================
62 
63 template<typename FieldT>
64 void driver( const string tag )
65 {
66  cout << tag << std::endl;
67 
68  // Define the size and number of points in the domain
69  const IntVec fieldDim( 5, 5, 1 ); // 5 x 5 x 1 points
70  const DoubleVec domainLength( 5.0, 5.0, 5.0 ); // a cube of length 5.0
71 
72  //----------------------------------------------------------------------------
73  // Create coordinate fields of type FieldT.
74  const bool bcx=true, bcy=true, bcz=true;
75  const IntVec bc(bcx,bcy,bcz);
76  const GhostData nghost(0);
77  const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bc,bc );
78  const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
79 
80  FieldT x( window, bcInfo, nghost, NULL, InternalStorage );
81  FieldT y( window, bcInfo, nghost, NULL, InternalStorage );
82  FieldT z( window, bcInfo, nghost, NULL, InternalStorage );
83 
84  //----------------------------------------------------------------------------
85  // Set coordinate fields.
86  const Grid grid( fieldDim, domainLength );
87  grid.set_coord<XDIR>(x);
88  grid.set_coord<YDIR>(y);
89  grid.set_coord<ZDIR>(z);
90 
91  //----------------------------------------------------------------------------
92  // Print coordinates
93  cout << "x:" << std::endl; print_field( x, cout );
94  cout << "y:" << std::endl; print_field( y, cout );
95  cout << "z:" << std::endl; print_field( z, cout );
96 }
97 
98 //==============================================================================
99 
100 int main()
101 {
102  driver< SVolField>( "SVolField - volume field on the scalar volume" );
103  driver<SSurfXField>( "SSurfXField - x-surface field on the scalar volume" );
104  driver<SSurfYField>( "SSurfYField - y-surface field on the scalar volume" );
105  driver<SSurfZField>( "SSurfZField - z-surface field on the scalar volume" );
106 
107  driver< XVolField>( "XVolField - volume field on the x-staggered volume" );
108  driver<XSurfXField>( "XSurfXField - x-surface field on the x-staggered volume" );
109  driver<XSurfYField>( "XSurfYField - y-surface field on the x-staggered volume" );
110  driver<XSurfZField>( "XSurfZField - z-surface field on the x-staggered volume" );
111 
112  driver< YVolField>( "YVolField - volume field on the y-staggered volume" );
113  driver<YSurfXField>( "YSurfXField - x-surface field on the y-staggered volume" );
114  driver<YSurfYField>( "YSurfYField - y-surface field on the y-staggered volume" );
115  driver<YSurfZField>( "YSurfZField - z-surface field on the y-staggered volume" );
116 
117  driver< ZVolField>( "ZVolField - volume field on the z-staggered volume" );
118  driver<ZSurfXField>( "ZSurfXField - x-surface field on the z-staggered volume" );
119  driver<ZSurfYField>( "ZSurfYField - y-surface field on the z-staggered volume" );
120  driver<ZSurfZField>( "ZSurfZField - z-surface field on the z-staggered volume" );
121 
122  return 0;
123 }
Provides tools to index into a sub-block of memory.
Definition: MemoryWindow.h:63
MemoryWindow get_window_with_ghost(const IntVec &localDim, const GhostData &ghost, const BoundaryCellInfo &bc)
Obtain the memory window for a field on a patch that is a single, contiguous memory block...
Definition: MemoryWindow.h:314
void print_field(const Field &f, std::ostream &os, const bool addFormat=false)
print the values of a field (and ghost cells) to standard output
Definition: FieldHelper.h:281
STL namespace.
Provides a simple interface to set coordinate fields.
Definition: Grid.h:36
Holds information about the number of ghost cells on each side of the domain.
Definition: GhostData.h:54
Defines a type for the x-direction.
Defines a type for the y-direction.
Defines a type for the z-direction.
Provides information about boundary cells for various fields.