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

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

  ViewVC Help
Powered by ViewVC 1.1.26