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 GhostData nghost(0);
76  const BoundaryCellInfo bcInfo = BoundaryCellInfo::build<FieldT>( bcx, bcy, bcz );
77  const MemoryWindow window( get_window_with_ghost( fieldDim, nghost, bcInfo ) );
78 
79  FieldT x( window, bcInfo, nghost, NULL, InternalStorage );
80  FieldT y( window, bcInfo, nghost, NULL, InternalStorage );
81  FieldT z( window, bcInfo, nghost, NULL, InternalStorage );
82 
83  //----------------------------------------------------------------------------
84  // Set coordinate fields.
85  const Grid grid( fieldDim, domainLength );
86  grid.set_coord<XDIR>(x);
87  grid.set_coord<YDIR>(y);
88  grid.set_coord<ZDIR>(z);
89 
90  //----------------------------------------------------------------------------
91  // Print coordinates
92  cout << "x:" << std::endl; print_field( x, cout );
93  cout << "y:" << std::endl; print_field( y, cout );
94  cout << "z:" << std::endl; print_field( z, cout );
95 }
96 
97 //==============================================================================
98 
99 int main()
100 {
101  driver< SVolField>( "SVolField - volume field on the scalar volume" );
102  driver<SSurfXField>( "SSurfXField - x-surface field on the scalar volume" );
103  driver<SSurfYField>( "SSurfYField - y-surface field on the scalar volume" );
104  driver<SSurfZField>( "SSurfZField - z-surface field on the scalar volume" );
105 
106  driver< XVolField>( "XVolField - volume field on the x-staggered volume" );
107  driver<XSurfXField>( "XSurfXField - x-surface field on the x-staggered volume" );
108  driver<XSurfYField>( "XSurfYField - y-surface field on the x-staggered volume" );
109  driver<XSurfZField>( "XSurfZField - z-surface field on the x-staggered volume" );
110 
111  driver< YVolField>( "YVolField - volume field on the y-staggered volume" );
112  driver<YSurfXField>( "YSurfXField - x-surface field on the y-staggered volume" );
113  driver<YSurfYField>( "YSurfYField - y-surface field on the y-staggered volume" );
114  driver<YSurfZField>( "YSurfZField - z-surface field on the y-staggered volume" );
115 
116  driver< ZVolField>( "ZVolField - volume field on the z-staggered volume" );
117  driver<ZSurfXField>( "ZSurfXField - x-surface field on the z-staggered volume" );
118  driver<ZSurfYField>( "ZSurfYField - y-surface field on the z-staggered volume" );
119  driver<ZSurfZField>( "ZSurfZField - z-surface field on the z-staggered volume" );
120 
121  return 0;
122 }
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.