/[escript]/trunk/ripley/src/Brick.h
ViewVC logotype

Contents of /trunk/ripley/src/Brick.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4357 - (show annotations)
Thu Apr 11 06:07:14 2013 UTC (6 years, 5 months ago) by caltinay
File MIME type: text/plain
File size: 11182 byte(s)
templated writeBinaryGrid and a bit of cleanup.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16 #ifndef __RIPLEY_BRICK_H__
17 #define __RIPLEY_BRICK_H__
18
19 #include <ripley/RipleyDomain.h>
20
21 struct Paso_Connector;
22
23 namespace ripley {
24
25 /**
26 \brief
27 Brick is the 3-dimensional implementation of a RipleyDomain.
28 */
29 class RIPLEY_DLL_API Brick: public RipleyDomain
30 {
31 public:
32
33 /**
34 \brief creates a hexagonal mesh with n0 x n1 x n2 elements over the
35 brick [x0,x1] x [y0,y1] x [z0,z1].
36 \param n0,n1,n2 number of elements in each dimension
37 \param x0,y0,z0,x1,y1,z1 coordinates of corner nodes of the brick
38 \param d0,d1,d2 number of subdivisions in each dimension
39 */
40 Brick(int n0, int n1, int n2, double x0, double y0, double z0, double x1,
41 double y1, double z1, int d0=-1, int d1=-1, int d2=-1);
42
43 /**
44 \brief
45 Destructor.
46 */
47 ~Brick();
48
49 /**
50 \brief
51 returns a description for this domain
52 */
53 virtual std::string getDescription() const;
54
55 /**
56 \brief equality operator
57 */
58 virtual bool operator==(const escript::AbstractDomain& other) const;
59
60 /**
61 \brief
62 dumps the mesh to a file with the given name
63 \param filename The name of the output file
64 */
65 void dump(const std::string& filename) const;
66
67 /**
68 */
69 virtual void readBinaryGrid(escript::Data& out, std::string filename,
70 const std::vector<int>& first,
71 const std::vector<int>& numValues,
72 const std::vector<int>& multiplier) const;
73
74 /**
75 */
76 virtual void readNcGrid(escript::Data& out, std::string filename,
77 std::string varname, const std::vector<int>& first,
78 const std::vector<int>& numValues,
79 const std::vector<int>& multiplier) const;
80
81 /**
82 */
83 virtual void writeBinaryGrid(const escript::Data& in,
84 std::string filename,
85 int byteOrder, int dataType) const;
86
87 /**
88 \brief
89 returns the reference number of the given sample number
90 \param fsType The function space type
91 */
92 const int* borrowSampleReferenceIDs(int fsType) const;
93
94 /**
95 \brief
96 returns true if this rank owns the sample id.
97 */
98 virtual bool ownSample(int fsType, index_t id) const;
99
100 /**
101 \brief
102 copies the surface normals at data points into out. The actual function
103 space to be considered is defined by out. out has to be defined on this
104 domain.
105 */
106 virtual void setToNormal(escript::Data& out) const;
107
108 /**
109 \brief
110 copies the size of samples into out. The actual function space to be
111 considered is defined by out. out has to be defined on this domain.
112 */
113 virtual void setToSize(escript::Data& out) const;
114
115 /**
116 \brief
117 returns the number of data points summed across all MPI processes
118 */
119 virtual int getNumDataPointsGlobal() const;
120
121 /**
122 \brief
123 writes information about the mesh to standard output
124 \param full whether to print additional data
125 */
126 virtual void Print_Mesh_Info(const bool full=false) const;
127
128 /**
129 \brief
130 returns the number of nodes per MPI rank in each dimension
131 */
132 virtual const int* getNumNodesPerDim() const { return m_NN; }
133
134 /**
135 \brief
136 returns the number of elements per MPI rank in each dimension
137 */
138 virtual const int* getNumElementsPerDim() const { return m_NE; }
139
140 /**
141 \brief
142 returns the number of face elements in the order
143 (left,right,bottom,top,front,back) on current MPI rank
144 */
145 virtual const int* getNumFacesPerBoundary() const { return m_faceCount; }
146
147 /**
148 \brief
149 returns the node distribution vector
150 */
151 virtual IndexVector getNodeDistribution() const { return m_nodeDistribution; }
152
153 /**
154 \brief
155 returns the number of spatial subdivisions in each dimension
156 */
157 virtual const int* getNumSubdivisionsPerDim() const { return m_NX; }
158
159 /**
160 \brief
161 returns the index'th coordinate value in given dimension for this rank
162 */
163 virtual double getLocalCoordinate(int index, int dim) const;
164
165 /**
166 \brief
167 returns the tuple (origin, spacing, number_of_elements)
168 */
169 virtual boost::python::tuple getGridParameters() const;
170
171 protected:
172 virtual dim_t getNumNodes() const;
173 virtual dim_t getNumElements() const;
174 virtual dim_t getNumFaceElements() const;
175 virtual dim_t getNumDOF() const;
176 virtual dim_t insertNeighbourNodes(IndexVector& index, index_t node) const;
177 virtual void assembleCoordinates(escript::Data& arg) const;
178 virtual void assembleGradient(escript::Data& out, escript::Data& in) const;
179 virtual void assembleIntegrate(DoubleVector& integrals, escript::Data& arg) const;
180 virtual void assemblePDESingle(Paso_SystemMatrix* mat, escript::Data& rhs,
181 const escript::Data& A, const escript::Data& B,
182 const escript::Data& C, const escript::Data& D,
183 const escript::Data& X, const escript::Data& Y) const;
184 virtual void assemblePDEBoundarySingle(Paso_SystemMatrix* mat,
185 escript::Data& rhs, const escript::Data& d,
186 const escript::Data& y) const;
187 virtual void assemblePDESingleReduced(Paso_SystemMatrix* mat,
188 escript::Data& rhs, const escript::Data& A, const escript::Data& B,
189 const escript::Data& C, const escript::Data& D,
190 const escript::Data& X, const escript::Data& Y) const;
191 virtual void assemblePDEBoundarySingleReduced(Paso_SystemMatrix* mat,
192 escript::Data& rhs, const escript::Data& d,
193 const escript::Data& y) const;
194 virtual void assemblePDESystem(Paso_SystemMatrix* mat, escript::Data& rhs,
195 const escript::Data& A, const escript::Data& B,
196 const escript::Data& C, const escript::Data& D,
197 const escript::Data& X, const escript::Data& Y) const;
198 virtual void assemblePDEBoundarySystem(Paso_SystemMatrix* mat,
199 escript::Data& rhs, const escript::Data& d,
200 const escript::Data& y) const;
201 virtual void assemblePDESystemReduced(Paso_SystemMatrix* mat,
202 escript::Data& rhs, const escript::Data& A, const escript::Data& B,
203 const escript::Data& C, const escript::Data& D,
204 const escript::Data& X, const escript::Data& Y) const;
205 virtual void assemblePDEBoundarySystemReduced(Paso_SystemMatrix* mat,
206 escript::Data& rhs, const escript::Data& d,
207 const escript::Data& y) const;
208 virtual Paso_SystemMatrixPattern* getPattern(bool reducedRowOrder, bool reducedColOrder) const;
209 virtual void interpolateNodesOnElements(escript::Data& out,
210 escript::Data& in, bool reduced) const;
211 virtual void interpolateNodesOnFaces(escript::Data& out, escript::Data& in,
212 bool reduced) const;
213 virtual void nodesToDOF(escript::Data& out, escript::Data& in) const;
214 virtual void dofToNodes(escript::Data& out, escript::Data& in) const;
215
216 private:
217 void populateSampleIds();
218 void createPattern();
219 void addToMatrixAndRHS(Paso_SystemMatrix* S, escript::Data& F,
220 const DoubleVector& EM_S, const DoubleVector& EM_F,
221 bool addS, bool addF, index_t firstNode, dim_t nEq=1, dim_t nComp=1) const;
222 template<typename ValueType>
223 void writeBinaryGridImpl(const escript::Data& in,
224 const std::string& filename, int byteOrder) const;
225
226
227 /// total number of elements in each dimension
228 dim_t m_gNE[3];
229
230 /// origin of domain
231 double m_origin[3];
232
233 /// side lengths of domain
234 double m_length[3];
235
236 /// grid spacings / cell sizes of domain
237 double m_dx[3];
238
239 /// number of spatial subdivisions
240 int m_NX[3];
241
242 /// number of elements for this rank in each dimension including shared
243 dim_t m_NE[3];
244
245 /// number of own elements for this rank in each dimension
246 dim_t m_ownNE[3];
247
248 /// number of nodes for this rank in each dimension
249 dim_t m_NN[3];
250
251 /// first node on this rank is at (offset0,offset1,offset2) in global mesh
252 dim_t m_offset[3];
253
254 /// number of face elements per edge (left, right, bottom, top, front, back)
255 int m_faceCount[6];
256
257 /// faceOffset[i]=-1 if face i is not an external face, otherwise it is
258 /// the index of that face (where i: 0=left, 1=right, 2=bottom, 3=top,
259 /// 4=front, 5=back)
260 IndexVector m_faceOffset;
261
262 /// vector of sample reference identifiers
263 IndexVector m_dofId;
264 IndexVector m_nodeId;
265 IndexVector m_elementId;
266 IndexVector m_faceId;
267
268 // vector with first node id on each rank
269 IndexVector m_nodeDistribution;
270
271 // vector that maps each node to a DOF index (used for the coupler)
272 IndexVector m_dofMap;
273
274 // Paso connector used by the system matrix and to interpolate DOF to
275 // nodes
276 Paso_Connector* m_connector;
277
278 // the Paso System Matrix pattern
279 Paso_SystemMatrixPattern* m_pattern;
280 };
281
282 ////////////////////////////// inline methods ////////////////////////////////
283
284 inline int Brick::getNumDataPointsGlobal() const
285 {
286 return (m_gNE[0]+1)*(m_gNE[1]+1)*(m_gNE[2]+1);
287 }
288
289 inline double Brick::getLocalCoordinate(int index, int dim) const
290 {
291 EsysAssert((dim>=0 && dim<3), "'dim' out of bounds");
292 EsysAssert((index>=0 && index<m_NN[dim]), "'index' out of bounds");
293 return m_origin[dim]+m_dx[dim]*(m_offset[dim]+index);
294 }
295
296 inline boost::python::tuple Brick::getGridParameters() const
297 {
298 return boost::python::make_tuple(
299 boost::python::make_tuple(m_origin[0], m_origin[1], m_origin[2]),
300 boost::python::make_tuple(m_dx[0], m_dx[1], m_dx[2]),
301 boost::python::make_tuple(m_gNE[0], m_gNE[1], m_gNE[2]));
302 }
303
304 inline Paso_SystemMatrixPattern* Brick::getPattern(bool reducedRowOrder,
305 bool reducedColOrder) const
306 {
307 // TODO: reduced
308 return m_pattern;
309 }
310
311
312 //protected
313 inline dim_t Brick::getNumDOF() const
314 {
315 return (m_gNE[0]+1)/m_NX[0]*(m_gNE[1]+1)/m_NX[1]*(m_gNE[2]+1)/m_NX[2];
316 }
317
318 //protected
319 inline dim_t Brick::getNumNodes() const
320 {
321 return m_NN[0]*m_NN[1]*m_NN[2];
322 }
323
324 //protected
325 inline dim_t Brick::getNumElements() const
326 {
327 return m_NE[0]*m_NE[1]*m_NE[2];
328 }
329
330 //protected
331 inline dim_t Brick::getNumFaceElements() const
332 {
333 return m_faceCount[0] + m_faceCount[1] + m_faceCount[2]
334 + m_faceCount[3] + m_faceCount[4] + m_faceCount[5];
335 }
336
337 } // end of namespace ripley
338
339 #endif // __RIPLEY_BRICK_H__
340

  ViewVC Help
Powered by ViewVC 1.1.26