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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (4 years, 11 months ago) by caltinay
File MIME type: text/plain
File size: 11143 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

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

  ViewVC Help
Powered by ViewVC 1.1.26