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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5119 - (show annotations)
Wed Aug 20 04:10:01 2014 UTC (4 years, 10 months ago) by caltinay
File MIME type: text/plain
File size: 10853 byte(s)
Separated pattern generation from connector generation in ripley Brick
to allow using alternative System Matrices.

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

  ViewVC Help
Powered by ViewVC 1.1.26