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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (19 months, 1 week ago) by jfenwick
File MIME type: text/plain
File size: 13097 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 caltinay 3691
2 jfenwick 3981 /*****************************************************************************
3 caltinay 3691 *
4 jfenwick 6651 * Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 caltinay 3691 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 caltinay 3691 *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 *
15     *****************************************************************************/
16 caltinay 3691
17     #ifndef __RIPLEY_RECTANGLE_H__
18     #define __RIPLEY_RECTANGLE_H__
19    
20     #include <ripley/RipleyDomain.h>
21    
22     namespace ripley {
23    
24     /**
25     \brief
26     Rectangle is the 2-dimensional implementation of a RipleyDomain.
27     */
28 caltinay 3915 class RIPLEY_DLL_API Rectangle: public RipleyDomain
29 caltinay 3691 {
30 caltinay 6338 template<class Scalar> friend class DefaultAssembler2D;
31 caltinay 5119 friend class WaveAssembler2D;
32     friend class LameAssembler2D;
33 caltinay 3691 public:
34    
35     /**
36     \brief creates a rectangular mesh with n0 x n1 elements over the
37 caltinay 3781 rectangle [x0,x1] x [y0,y1].
38 caltinay 3691 \param n0,n1 number of elements in each dimension
39 caltinay 3781 \param x0,y0,x1,y1 coordinates of bottom-left and top-right corners
40 caltinay 3691 \param d0,d1 number of subdivisions in each dimension
41     */
42 caltinay 5187 Rectangle(dim_t n0, dim_t n1, double x0, double y0, double x1, double y1,
43 sshaw 4622 int d0=-1, int d1=-1,
44     const std::vector<double>& points = std::vector<double>(),
45     const std::vector<int>& tags = std::vector<int>(),
46 caltinay 5148 const TagMap& tagnamestonums = TagMap(),
47 jfenwick 4934 escript::SubWorld_ptr w=escript::SubWorld_ptr()
48     );
49 caltinay 3691
50     /**
51     \brief
52     Destructor.
53     */
54     ~Rectangle();
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 caltinay 5121 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 caltinay 3691 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 caltinay 3971 */
83 caltinay 4013 virtual void readNcGrid(escript::Data& out, std::string filename,
84 caltinay 4618 std::string varname, const ReaderParameters& params) const;
85 caltinay 4013
86     /**
87 caltinay 4334 */
88 caltinay 4495 virtual void readBinaryGrid(escript::Data& out, std::string filename,
89 caltinay 4618 const ReaderParameters& params) const;
90 caltinay 6141
91 sshaw 4738 /**
92     */
93     virtual void readBinaryGridFromZipped(escript::Data& out, std::string filename,
94 sshaw 4765 const ReaderParameters& params) const;
95 caltinay 4495
96     /**
97     */
98 caltinay 4334 virtual void writeBinaryGrid(const escript::Data& in,
99 caltinay 4357 std::string filename,
100     int byteOrder, int dataType) const;
101 caltinay 4334
102     /**
103 caltinay 3691 \brief
104     returns the array of reference numbers for a function space type
105     \param fsType The function space type
106     */
107 caltinay 5187 const dim_t* borrowSampleReferenceIDs(int fsType) const;
108 caltinay 3691
109     /**
110     \brief
111     returns true if this rank owns the sample id.
112     */
113 caltinay 5532 virtual bool ownSample(int fsType, index_t id) const;
114 caltinay 3691
115     /**
116     \brief
117 caltinay 3722 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 caltinay 3760 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 caltinay 3691 returns the number of data points summed across all MPI processes
133     */
134 caltinay 5187 virtual dim_t getNumDataPointsGlobal() const;
135 caltinay 3691
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 caltinay 3697 /**
144     \brief
145     returns the number of nodes per MPI rank in each dimension
146     */
147 caltinay 5187 virtual const dim_t* getNumNodesPerDim() const { return m_NN; }
148 caltinay 3697
149     /**
150     \brief
151     returns the number of elements per MPI rank in each dimension
152     */
153 caltinay 5187 virtual const dim_t* getNumElementsPerDim() const { return m_NE; }
154 caltinay 3697
155     /**
156     \brief
157     returns the number of face elements in the order
158 caltinay 4334 (left,right,bottom,top) on current MPI rank
159 caltinay 3697 */
160 caltinay 5187 virtual const dim_t* getNumFacesPerBoundary() const { return m_faceCount; }
161 caltinay 3697
162     /**
163     \brief
164     returns the node distribution vector
165     */
166     virtual IndexVector getNodeDistribution() const { return m_nodeDistribution; }
167    
168     /**
169     \brief
170 caltinay 3766 returns the number of spatial subdivisions in each dimension
171     */
172 caltinay 4334 virtual const int* getNumSubdivisionsPerDim() const { return m_NX; }
173 caltinay 3766
174     /**
175     \brief
176 caltinay 4334 returns the index'th coordinate value in given dimension for this rank
177 caltinay 3697 */
178 caltinay 5187 virtual double getLocalCoordinate(index_t index, int dim) const;
179 caltinay 3697
180 caltinay 4340 /**
181     \brief
182     returns the tuple (origin, spacing, number_of_elements)
183     */
184     virtual boost::python::tuple getGridParameters() const;
185 sshaw 4622
186 jfenwick 4521 /**
187     * \brief
188 caltinay 5532 returns a Data object filled with random data passed through filter.
189 jfenwick 4521 */
190 jfenwick 4687 virtual escript::Data randomFill(const escript::DataTypes::ShapeType& shape,
191 caltinay 5532 const escript::FunctionSpace& what, long seed,
192     const boost::python::tuple& filter) const;
193 jfenwick 4687
194 sshaw 4622 /**
195     \brief
196 caltinay 5532 creates and returns an assembler of the requested type.
197 sshaw 4622 */
198 sshaw 4943 virtual Assembler_ptr createAssembler(std::string type,
199 caltinay 5114 const DataMap& options) const;
200 sshaw 4622
201 sshaw 5226 /**
202     \brief
203     returns the lengths of the domain
204     */
205     const double *getLength() const { return m_length; }
206 sshaw 4622
207 sshaw 5226 /**
208     \brief
209     returns the lengths of an element
210     */
211     const double *getElementLength() const { return m_dx; }
212    
213 caltinay 5532 /**
214     \brief
215     returns a vector of rank numbers where vec[i]=n means that rank n
216     'owns' element/face element i.
217     */
218     virtual RankVector getOwnerVector(int fsType) const;
219    
220 caltinay 3691 protected:
221 caltinay 4334 virtual dim_t getNumNodes() const;
222     virtual dim_t getNumElements() const;
223 caltinay 3756 virtual dim_t getNumFaceElements() const;
224 caltinay 3750 virtual dim_t getNumDOF() const;
225 sshaw 5540 virtual dim_t getNumDOFInAxis(unsigned axis) const;
226     virtual index_t getFirstInDim(unsigned axis) const;
227    
228 caltinay 5209 virtual IndexVector getDiagonalIndices(bool upperOnly) const;
229 caltinay 3691 virtual void assembleCoordinates(escript::Data& arg) const;
230 caltinay 4626 virtual void assembleGradient(escript::Data& out,
231     const escript::Data& in) const;
232 caltinay 6473 virtual void assembleIntegrate(std::vector<real_t>& integrals,
233 caltinay 4626 const escript::Data& arg) const;
234 caltinay 6473 virtual void assembleIntegrate(std::vector<cplx_t>& integrals,
235     const escript::Data& arg) const;
236 caltinay 6169 virtual std::vector<IndexVector> getConnections(bool includeShared=false) const;
237 caltinay 6119
238 caltinay 6144 #ifdef ESYS_HAVE_TRILINOS
239 caltinay 6119 virtual esys_trilinos::const_TrilinosGraph_ptr getTrilinosGraph() const;
240     #endif
241    
242 caltinay 6169 #ifdef ESYS_HAVE_PASO
243 caltinay 5118 virtual paso::SystemMatrixPattern_ptr getPasoMatrixPattern(
244     bool reducedRowOrder, bool reducedColOrder) const;
245 caltinay 6169 #endif
246 caltinay 3711 virtual void interpolateNodesOnElements(escript::Data& out,
247 jfenwick 6426 const escript::Data& in, bool reduced) const;
248 caltinay 4626 virtual void interpolateNodesOnFaces(escript::Data& out,
249     const escript::Data& in,
250 caltinay 3711 bool reduced) const;
251 jfenwick 6426
252 caltinay 4626 virtual void nodesToDOF(escript::Data& out, const escript::Data& in) const;
253 caltinay 5187 virtual dim_t getDofOfNode(dim_t node) const;
254 caltinay 3691
255 sshaw 5540 virtual void populateSampleIds();
256     virtual void populateDofMap();
257 caltinay 6338
258     template<typename Scalar>
259 caltinay 6422 void assembleGradientImpl(escript::Data& out,
260     const escript::Data& in) const;
261    
262     template<typename Scalar>
263 caltinay 6338 void addToMatrixAndRHS(escript::AbstractSystemMatrix* S, escript::Data& F,
264     const std::vector<Scalar>& EM_S, const std::vector<Scalar>& EM_F,
265 caltinay 5187 bool addS, bool addF, index_t firstNode, int nEq=1, int nComp=1) const;
266 caltinay 4495
267 caltinay 4357 template<typename ValueType>
268 caltinay 4495 void readBinaryGridImpl(escript::Data& out, const std::string& filename,
269 caltinay 4618 const ReaderParameters& params) const;
270 caltinay 4495
271 caltinay 6141 #ifdef ESYS_HAVE_BOOST_IO
272 caltinay 4495 template<typename ValueType>
273 sshaw 4765 void readBinaryGridZippedImpl(escript::Data& out,
274     const std::string& filename, const ReaderParameters& params) const;
275 caltinay 6141 #endif
276 sshaw 4765
277     template<typename ValueType>
278 caltinay 4357 void writeBinaryGridImpl(const escript::Data& in,
279     const std::string& filename, int byteOrder) const;
280 caltinay 3691
281 sshaw 5540 virtual dim_t findNode(const double *coords) const;
282 sshaw 4622
283 jfenwick 4687
284     escript::Data randomFillWorker(const escript::DataTypes::ShapeType& shape,
285     long seed, const boost::python::tuple& filter) const;
286    
287 caltinay 3691 /// total number of elements in each dimension
288 caltinay 4334 dim_t m_gNE[2];
289 caltinay 3691
290 caltinay 4334 /// origin of domain
291     double m_origin[2];
292 caltinay 3781
293 caltinay 3691 /// side lengths of domain
294 caltinay 4334 double m_length[2];
295 caltinay 3691
296 caltinay 4334 /// grid spacings / cell sizes of domain
297     double m_dx[2];
298    
299 caltinay 3691 /// number of spatial subdivisions
300 caltinay 5187 int m_NX[2];
301 caltinay 3691
302 caltinay 3764 /// number of elements for this rank in each dimension including shared
303 caltinay 4334 dim_t m_NE[2];
304 caltinay 3691
305 caltinay 3764 /// number of own elements for this rank in each dimension
306 caltinay 4334 dim_t m_ownNE[2];
307 caltinay 3764
308 caltinay 3691 /// number of nodes for this rank in each dimension
309 caltinay 4334 dim_t m_NN[2];
310 caltinay 3691
311     /// first node on this rank is at (offset0,offset1) in global mesh
312 caltinay 4334 dim_t m_offset[2];
313 caltinay 3691
314 caltinay 4334 /// number of face elements per edge (left, right, bottom, top)
315 caltinay 5187 dim_t m_faceCount[4];
316 caltinay 4334
317 caltinay 3704 /// faceOffset[i]=-1 if face i is not an external face, otherwise it is
318     /// the index of that face (where i: 0=left, 1=right, 2=bottom, 3=top)
319     IndexVector m_faceOffset;
320    
321 caltinay 3691 /// vector of sample reference identifiers
322 caltinay 3750 IndexVector m_dofId;
323 caltinay 3691 IndexVector m_nodeId;
324     IndexVector m_elementId;
325     IndexVector m_faceId;
326 caltinay 3697
327     // vector with first node id on each rank
328     IndexVector m_nodeDistribution;
329 caltinay 3752
330 caltinay 3756 // vector that maps each node to a DOF index (used for the coupler)
331     IndexVector m_dofMap;
332    
333 caltinay 6169 #ifdef ESYS_HAVE_PASO
334 caltinay 3756 // the Paso System Matrix pattern
335 caltinay 5118 mutable paso::SystemMatrixPattern_ptr m_pattern;
336 caltinay 6166 #endif
337 caltinay 6119
338 caltinay 6144 #ifdef ESYS_HAVE_TRILINOS
339 caltinay 6119 /// Trilinos graph structure, cached for efficiency
340     mutable esys_trilinos::const_TrilinosGraph_ptr m_graph;
341     #endif
342 jfenwick 6426 private:
343 caltinay 6473 template<typename Scalar>
344     void assembleIntegrateImpl(std::vector<Scalar>& integrals, const escript::Data& arg) const;
345    
346 jfenwick 6426 template <typename S>
347     void interpolateNodesOnElementsWorker(escript::Data& out,
348     const escript::Data& in, bool reduced, S sentinel) const;
349     template <typename S>
350     void interpolateNodesOnFacesWorker(escript::Data& out,
351     const escript::Data& in,
352     bool reduced, S sentinel) const;
353 caltinay 3691 };
354    
355 caltinay 4334 ////////////////////////////// inline methods ////////////////////////////////
356 caltinay 5187 inline dim_t Rectangle::getDofOfNode(dim_t node) const
357     {
358 sshaw 4622 return m_dofMap[node];
359     }
360 caltinay 4334
361 caltinay 5187 inline dim_t Rectangle::getNumDataPointsGlobal() const
362 caltinay 4334 {
363     return (m_gNE[0]+1)*(m_gNE[1]+1);
364     }
365    
366 caltinay 5187 inline double Rectangle::getLocalCoordinate(index_t index, int dim) const
367 caltinay 4334 {
368 caltinay 6067 ESYS_ASSERT(dim>=0 && dim<2, "'dim' out of bounds");
369     ESYS_ASSERT(index>=0 && index<m_NN[dim], "'index' out of bounds");
370 caltinay 4334 return m_origin[dim]+m_dx[dim]*(m_offset[dim]+index);
371     }
372    
373 caltinay 4340 inline boost::python::tuple Rectangle::getGridParameters() const
374     {
375     return boost::python::make_tuple(
376     boost::python::make_tuple(m_origin[0], m_origin[1]),
377     boost::python::make_tuple(m_dx[0], m_dx[1]),
378     boost::python::make_tuple(m_gNE[0], m_gNE[1]));
379     }
380    
381 caltinay 4334 //protected
382     inline dim_t Rectangle::getNumDOF() const
383     {
384     return (m_gNE[0]+1)/m_NX[0]*(m_gNE[1]+1)/m_NX[1];
385     }
386    
387     //protected
388 sshaw 5540 inline dim_t Rectangle::getNumDOFInAxis(unsigned axis) const
389     {
390 caltinay 6067 ESYS_ASSERT(axis < m_numDim, "Invalid axis");
391 sshaw 5540 return (m_gNE[axis]+1)/m_NX[axis];
392     }
393    
394     //protected
395 caltinay 4334 inline dim_t Rectangle::getNumNodes() const
396     {
397     return m_NN[0]*m_NN[1];
398     }
399    
400     //protected
401     inline dim_t Rectangle::getNumElements() const
402     {
403     return m_NE[0]*m_NE[1];
404     }
405    
406     //protected
407     inline dim_t Rectangle::getNumFaceElements() const
408     {
409     return m_faceCount[0] + m_faceCount[1] + m_faceCount[2] + m_faceCount[3];
410     }
411    
412 sshaw 5540 //protected
413     inline index_t Rectangle::getFirstInDim(unsigned axis) const
414     {
415     return m_offset[axis] == 0 ? 0 : 1;
416     }
417 caltinay 4334
418 caltinay 3691 } // end of namespace ripley
419    
420     #endif // __RIPLEY_RECTANGLE_H__
421    

  ViewVC Help
Powered by ViewVC 1.1.26