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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6141 - (show annotations)
Wed Apr 6 03:51:30 2016 UTC (2 years, 8 months ago) by caltinay
File MIME type: text/plain
File size: 12472 byte(s)
more namespacing of defines.

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

  ViewVC Help
Powered by ViewVC 1.1.26