SpatialOps
3D_Laplacian.h
Go to the documentation of this file.
1 
66 
67 
68 // Here FieldT is a generic field that is assumed to live on a volume.
69 //
70 // Valid input field types:
71 // ------------------------
72 // SVolField - cell-centered (scalar) volume field
73 // XVolField - x-staggered volume field (x-velocity/momentum)
74 // YVolField - y-staggered volume field (y-velocity/momentum)
75 // ZVolField - z-staggered volume field (z-velocity/momentum)
76 //
77 // Inputs:
78 // -------
79 // opDB - the OperatorDatabase that holds all operators
80 // src - the source field (to apply the Laplacian to)
81 //
82 // Output:
83 // -------
84 // dest - the destination field (result of Laplacian applied to src)
85 //
86 template< typename FieldT >
87 void
88 calculate_laplacian_3D( const SpatialOps::OperatorDatabase& opDB,
89  const FieldT& src,
90  FieldT& dest )
91 {
92  using namespace SpatialOps;
93 
94  //---------------------------------------------------------------------------
95  // Infer operator types for the 3D laplacian
96  // If this function is used with a field type that is not a volume field
97  // then compiler errors result due to invalid type inference for operators.
98  typedef typename BasicOpTypes< FieldT >::GradX GradX;
99  typedef typename BasicOpTypes< FieldT >::GradY GradY;
100  typedef typename BasicOpTypes< FieldT >::GradZ GradZ;
101 
102  typedef typename BasicOpTypes< FieldT >::DivX DivX;
103  typedef typename BasicOpTypes< FieldT >::DivY DivY;
104  typedef typename BasicOpTypes< FieldT >::DivZ DivZ;
105 
106 
107  //---------------------------------------------------------------------------
108  // obtain the appropriate operators from the operator database
109  // The OperatorDatabase is simply a container for operators that
110  // provides access by type.
111  GradX& gradX = *opDB.retrieve_operator<GradX>();
112  GradY& gradY = *opDB.retrieve_operator<GradY>();
113  GradZ& gradZ = *opDB.retrieve_operator<GradZ>();
114 
115  DivX& divX = *opDB.retrieve_operator<DivX >();
116  DivY& divY = *opDB.retrieve_operator<DivY >();
117  DivZ& divZ = *opDB.retrieve_operator<DivZ >();
118 
119 
120  //---------------------------------------------------------------------------
121  // Finally, perform the calculation. This is the easy part!
122  // Note that this will run on multicore and GPU!
123  dest <<= divX( gradX( src ) )
124  + divY( gradY( src ) )
125  + divZ( gradZ( src ) );
126 }
OpT * retrieve_operator(const int id=-1) const
Retrieve an operator of the requested type.
Provides typedefs for common operator types on a given volume.
Provides a database to hold operators of any type.