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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4622 - (show annotations)
Fri Jan 17 04:55:41 2014 UTC (5 years, 3 months ago) by sshaw
File MIME type: text/plain
File size: 10100 byte(s)
Added dirac support to ripley, added interface for custom assemblers for ripleydomains (also added the custom assembler for 2D VTI waves), changed synthetic_VTI example to use the new, faster custom assembler

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_RECTANGLE_H__
17 #define __RIPLEY_RECTANGLE_H__
18
19 #include <ripley/RipleyDomain.h>
20
21 struct Paso_Connector;
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 public:
32
33 /**
34 \brief creates a rectangular mesh with n0 x n1 elements over the
35 rectangle [x0,x1] x [y0,y1].
36 \param n0,n1 number of elements in each dimension
37 \param x0,y0,x1,y1 coordinates of bottom-left and top-right corners
38 \param d0,d1 number of subdivisions in each dimension
39 */
40 Rectangle(int n0, int n1, double x0, double y0, double x1, double y1,
41 int d0=-1, int d1=-1,
42 const std::vector<double>& points = std::vector<double>(),
43 const std::vector<int>& tags = std::vector<int>(),
44 const std::map<std::string, int>& tagnamestonums =
45 std::map<std::string, int>());
46
47 /**
48 \brief
49 Destructor.
50 */
51 ~Rectangle();
52
53 /**
54 \brief
55 returns a description for this domain
56 */
57 virtual std::string getDescription() const;
58
59 /**
60 \brief equality operator
61 */
62 virtual bool operator==(const escript::AbstractDomain& other) const;
63
64 /**
65 \brief
66 dumps the mesh to a file with the given name
67 \param filename The name of the output file
68 */
69 void dump(const std::string& filename) const;
70
71 /**
72 */
73 virtual void readNcGrid(escript::Data& out, std::string filename,
74 std::string varname, const ReaderParameters& params) const;
75
76 /**
77 */
78 virtual void readBinaryGrid(escript::Data& out, std::string filename,
79 const ReaderParameters& params) 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 array of reference numbers for a function space type
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 fs_code, 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) 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 /**
172 * \brief
173 Returns a Data object filled with random data passed through filter.
174 */
175 escript::Data randomFill(long seed, const boost::python::tuple& filter) const;
176
177 /**
178 \brief
179 Sets the assembler to a custom/specific assembler.
180 */
181 virtual void setAssembler(std::string type, std::map<std::string, escript::Data> options);
182
183
184 protected:
185 virtual dim_t getNumNodes() const;
186 virtual dim_t getNumElements() const;
187 virtual dim_t getNumFaceElements() const;
188 virtual dim_t getNumDOF() const;
189 virtual dim_t insertNeighbourNodes(IndexVector& index, index_t node) const;
190 virtual void assembleCoordinates(escript::Data& arg) const;
191 virtual void assembleGradient(escript::Data& out, escript::Data& in) const;
192 virtual void assembleIntegrate(DoubleVector& integrals, escript::Data& arg) const;
193 virtual Paso_SystemMatrixPattern* getPattern(bool reducedRowOrder, bool reducedColOrder) const;
194 virtual void interpolateNodesOnElements(escript::Data& out,
195 escript::Data& in, bool reduced) const;
196 virtual void interpolateNodesOnFaces(escript::Data& out, escript::Data& in,
197 bool reduced) const;
198 virtual void nodesToDOF(escript::Data& out, escript::Data& in) const;
199 virtual void dofToNodes(escript::Data& out, escript::Data& in) const;
200 virtual int getDofOfNode(int node) const;
201
202 private:
203 void populateSampleIds();
204 void createPattern();
205 void addToMatrixAndRHS(Paso_SystemMatrix* S, escript::Data& F,
206 const DoubleVector& EM_S, const DoubleVector& EM_F,
207 bool addS, bool addF, int firstNode, int nEq=1, int nComp=1) const;
208
209 template<typename ValueType>
210 void readBinaryGridImpl(escript::Data& out, const std::string& filename,
211 const ReaderParameters& params) const;
212
213 template<typename ValueType>
214 void writeBinaryGridImpl(const escript::Data& in,
215 const std::string& filename, int byteOrder) const;
216
217 int findNode(double *coords) const;
218
219 /// total number of elements in each dimension
220 dim_t m_gNE[2];
221
222 /// origin of domain
223 double m_origin[2];
224
225 /// side lengths of domain
226 double m_length[2];
227
228 /// grid spacings / cell sizes of domain
229 double m_dx[2];
230
231 /// number of spatial subdivisions
232 dim_t m_NX[2];
233
234 /// number of elements for this rank in each dimension including shared
235 dim_t m_NE[2];
236
237 /// number of own elements for this rank in each dimension
238 dim_t m_ownNE[2];
239
240 /// number of nodes for this rank in each dimension
241 dim_t m_NN[2];
242
243 /// first node on this rank is at (offset0,offset1) in global mesh
244 dim_t m_offset[2];
245
246 /// number of face elements per edge (left, right, bottom, top)
247 int m_faceCount[4];
248
249 /// faceOffset[i]=-1 if face i is not an external face, otherwise it is
250 /// the index of that face (where i: 0=left, 1=right, 2=bottom, 3=top)
251 IndexVector m_faceOffset;
252
253 /// vector of sample reference identifiers
254 IndexVector m_dofId;
255 IndexVector m_nodeId;
256 IndexVector m_elementId;
257 IndexVector m_faceId;
258
259 // vector with first node id on each rank
260 IndexVector m_nodeDistribution;
261
262 // vector that maps each node to a DOF index (used for the coupler)
263 IndexVector m_dofMap;
264
265 // Paso connector used by the system matrix and to interpolate DOF to
266 // nodes
267 Paso_Connector* m_connector;
268
269 // the Paso System Matrix pattern
270 Paso_SystemMatrixPattern* m_pattern;
271
272 friend class DefaultAssembler2D;
273 friend class WaveAssembler2D;
274 };
275
276 ////////////////////////////// inline methods ////////////////////////////////
277 inline int Rectangle::getDofOfNode(int node) const {
278 return m_dofMap[node];
279 }
280
281 inline int Rectangle::getNumDataPointsGlobal() const
282 {
283 return (m_gNE[0]+1)*(m_gNE[1]+1);
284 }
285
286 inline double Rectangle::getLocalCoordinate(int index, int dim) const
287 {
288 EsysAssert((dim>=0 && dim<2), "'dim' out of bounds");
289 EsysAssert((index>=0 && index<m_NN[dim]), "'index' out of bounds");
290 return m_origin[dim]+m_dx[dim]*(m_offset[dim]+index);
291 }
292
293 inline boost::python::tuple Rectangle::getGridParameters() const
294 {
295 return boost::python::make_tuple(
296 boost::python::make_tuple(m_origin[0], m_origin[1]),
297 boost::python::make_tuple(m_dx[0], m_dx[1]),
298 boost::python::make_tuple(m_gNE[0], m_gNE[1]));
299 }
300
301 inline Paso_SystemMatrixPattern* Rectangle::getPattern(bool reducedRowOrder,
302 bool reducedColOrder) const
303 {
304 // TODO: reduced
305 return m_pattern;
306 }
307
308
309 //protected
310 inline dim_t Rectangle::getNumDOF() const
311 {
312 return (m_gNE[0]+1)/m_NX[0]*(m_gNE[1]+1)/m_NX[1];
313 }
314
315 //protected
316 inline dim_t Rectangle::getNumNodes() const
317 {
318 return m_NN[0]*m_NN[1];
319 }
320
321 //protected
322 inline dim_t Rectangle::getNumElements() const
323 {
324 return m_NE[0]*m_NE[1];
325 }
326
327 //protected
328 inline dim_t Rectangle::getNumFaceElements() const
329 {
330 return m_faceCount[0] + m_faceCount[1] + m_faceCount[2] + m_faceCount[3];
331 }
332
333
334 } // end of namespace ripley
335
336 #endif // __RIPLEY_RECTANGLE_H__
337

  ViewVC Help
Powered by ViewVC 1.1.26