escript  Revision_
speckley/src/Rectangle.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 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-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 #ifndef __SPECKLEY_RECTANGLE_H__
19 #define __SPECKLEY_RECTANGLE_H__
20 
21 #include <speckley/SpeckleyDomain.h>
22 
23 namespace speckley {
24 
25 #ifdef USE_RIPLEY
26 class RipleyCoupler; //forward declaration of coupler to avoid circles
27 #endif
28 
34 {
35 public:
36 
44  Rectangle(int order, dim_t n0, dim_t n1, double x0, double y0,
45  double x1, double y1, int d0=-1, int d1=-1,
46  const std::vector<double>& points = std::vector<double>(),
47  const std::vector<int>& tags = std::vector<int>(),
48  const TagMap& tagnamestonums = TagMap(),
50  );
51 
56  ~Rectangle();
57 
62  virtual std::string getDescription() const;
63 
67  virtual bool operator==(const escript::AbstractDomain& other) const;
68 
74  virtual void write(const std::string& filename) const;
75 
81  void dump(const std::string& filename) const;
82 
85  virtual void readNcGrid(escript::Data& out, std::string filename,
86  std::string varname, const ReaderParameters& params) const;
87 
90  virtual void readBinaryGrid(escript::Data& out, std::string filename,
91  const ReaderParameters& params) const;
92 
95  virtual void readBinaryGridFromZipped(escript::Data& out,
96  std::string filename, const ReaderParameters& params) const;
97 
100  virtual void writeBinaryGrid(const escript::Data& in,
101  std::string filename,
102  int byteOrder, int dataType) const;
103 
109  const dim_t* borrowSampleReferenceIDs(int fsType) const;
110 
115  virtual bool ownSample(int fs_code, index_t id) const;
116 
123  virtual void setToNormal(escript::Data& out) const;
124 
130  virtual void setToSize(escript::Data& out) const;
131 
136  virtual dim_t getNumDataPointsGlobal() const;
137 
143  virtual void Print_Mesh_Info(const bool full=false) const;
144 
149  virtual const dim_t* getNumNodesPerDim() const { return m_NN; }
150 
155  virtual const dim_t* getNumElementsPerDim() const { return m_NE; }
156 
162  virtual const dim_t* getNumFacesPerBoundary() const { return m_faceCount; }
163 
168  virtual IndexVector getNodeDistribution() const { return m_nodeDistribution; }
169 
174  virtual const int* getNumSubdivisionsPerDim() const { return m_NX; }
175 
180  virtual double getLocalCoordinate(index_t index, int dim) const;
181 
186  virtual boost::python::tuple getGridParameters() const;
187 
193  const escript::FunctionSpace& what, long seed, const boost::python::tuple& filter) const;
194 
199  virtual Assembler_ptr createAssembler(std::string type,
200  const DataMap& options) const;
201 
207  virtual void interpolateAcross(escript::Data& target,
208  const escript::Data& source) const;
209 
214  virtual bool probeInterpolationAcross(int, const escript::AbstractDomain&,
215  int) const;
216 
221  const double *getLength() const { return m_length; }
222 
223 protected:
224  virtual dim_t getNumNodes() const;
225  virtual dim_t getNumElements() const;
226  virtual dim_t getNumDOF() const;
227 #ifdef ESYS_MPI
228  virtual void balanceNeighbours(escript::Data& data, bool average) const;
229 #endif
230  virtual void assembleCoordinates(escript::Data& arg) const;
231  virtual void assembleGradient(escript::Data& out,
232  const escript::Data& in) const;
233  virtual void assembleIntegrate(std::vector<real_t>& integrals,
234  const escript::Data& arg) const;
235  virtual void assembleIntegrate(std::vector<cplx_t>& integrals,
236  const escript::Data& arg) const;
237  virtual void interpolateNodesOnElements(escript::Data& out,
238  const escript::Data& in,
239  bool reduced) const;
240  virtual void interpolateElementsOnNodes(escript::Data& out,
241  const escript::Data& in) const;
242  virtual dim_t getDofOfNode(dim_t node) const;
243  virtual void reduceElements(escript::Data& out, const escript::Data& in) const;
244 
245 private:
246  template<typename Scalar>
247  void gradient_order2(escript::Data&, const escript::Data&) const;
248  template<typename Scalar>
249  void gradient_order3(escript::Data&, const escript::Data&) const;
250  template<typename Scalar>
251  void gradient_order4(escript::Data&, const escript::Data&) const;
252  template<typename Scalar>
253  void gradient_order5(escript::Data&, const escript::Data&) const;
254  template<typename Scalar>
255  void gradient_order6(escript::Data&, const escript::Data&) const;
256  template<typename Scalar>
257  void gradient_order7(escript::Data&, const escript::Data&) const;
258  template<typename Scalar>
259  void gradient_order8(escript::Data&, const escript::Data&) const;
260  template<typename Scalar>
261  void gradient_order9(escript::Data&, const escript::Data&) const;
262  template<typename Scalar>
263  void gradient_order10(escript::Data&, const escript::Data&) const;
264 
265  template<typename Scalar>
266  void reduction_order2(const escript::Data&, escript::Data&) const;
267  template<typename Scalar>
268  void reduction_order3(const escript::Data&, escript::Data&) const;
269  template<typename Scalar>
270  void reduction_order4(const escript::Data&, escript::Data&) const;
271  template<typename Scalar>
272  void reduction_order5(const escript::Data&, escript::Data&) const;
273  template<typename Scalar>
274  void reduction_order6(const escript::Data&, escript::Data&) const;
275  template<typename Scalar>
276  void reduction_order7(const escript::Data&, escript::Data&) const;
277  template<typename Scalar>
278  void reduction_order8(const escript::Data&, escript::Data&) const;
279  template<typename Scalar>
280  void reduction_order9(const escript::Data&, escript::Data&) const;
281  template<typename Scalar>
282  void reduction_order10(const escript::Data&, escript::Data&) const;
283 
284  template<typename Scalar>
285  void integral_order2(std::vector<Scalar>&, const escript::Data&) const;
286  template<typename Scalar>
287  void integral_order3(std::vector<Scalar>&, const escript::Data&) const;
288  template<typename Scalar>
289  void integral_order4(std::vector<Scalar>&, const escript::Data&) const;
290  template<typename Scalar>
291  void integral_order5(std::vector<Scalar>&, const escript::Data&) const;
292  template<typename Scalar>
293  void integral_order6(std::vector<Scalar>&, const escript::Data&) const;
294  template<typename Scalar>
295  void integral_order7(std::vector<Scalar>&, const escript::Data&) const;
296  template<typename Scalar>
297  void integral_order8(std::vector<Scalar>&, const escript::Data&) const;
298  template<typename Scalar>
299  void integral_order9(std::vector<Scalar>&, const escript::Data&) const;
300  template<typename Scalar>
301  void integral_order10(std::vector<Scalar>&, const escript::Data&) const;
302 
303  template<typename Scalar>
304  void assembleIntegrateWorker(std::vector<Scalar>& integrals,
305  const escript::Data& arg) const;
306 
307  template<typename Scalar>
308  void interpolateNodesOnElementsWorker(escript::Data& out,
309  const escript::Data& in,
310  bool reduced) const;
311 
312  template<typename Scalar>
313  void interpolateElementsOnNodesWorker(escript::Data& out,
314  const escript::Data& in) const;
315 
316 #ifdef ESYS_MPI
317  template<typename Scalar>
318  void balanceNeighboursWorker(escript::Data& data, bool average) const;
319 
320  /* \brief
321  Sums the values across MPI overlaps
322  */
323  template<typename Scalar>
324  void shareCorners(escript::Data& out, int rx, int ry) const;
325  /* \brief
326  Sums the values across MPI overlaps
327  */
328  template<typename Scalar>
329  void shareSides(escript::Data& out, int rx, int ry) const;
330 
331  /* \brief
332  Sums the values across MPI overlaps
333  */
334  template<typename Scalar>
335  void shareVertical(escript::Data& out, int rx, int ry) const;
336 #endif
337 
338  /* \brief
339  interpolates the non-corner point values of an element
340  from the corner values
341  */
342  void interpolateFromCorners(escript::Data& out) const;
343 
344  void populateSampleIds();
345 
346  template<typename ValueType>
347  void readBinaryGridImpl(escript::Data& out, const std::string& filename,
348  const ReaderParameters& params) const;
349 
350 #ifdef ESYS_HAVE_BOOST_IO
351  template<typename ValueType>
352  void readBinaryGridZippedImpl(escript::Data& out,
353  const std::string& filename, const ReaderParameters& params) const;
354 #endif
355 
356  template<typename ValueType>
357  void writeBinaryGridImpl(const escript::Data& in,
358  const std::string& filename, int byteOrder) const;
359 
360  dim_t findNode(const double *coords) const;
361 
363  dim_t m_gNE[2];
364 
366  double m_origin[2];
367 
369  double m_length[2];
370 
372  double m_dx[2];
373 
375  int m_NX[2];
376 
378  dim_t m_NE[2];
379 
381  dim_t m_NN[2];
382 
384  dim_t m_offset[2];
385 
387  dim_t m_faceCount[4];
388 
393 
394  // vector with first node id on each rank
396 
397 #ifdef USE_RIPLEY
398  mutable RipleyCoupler *coupler;
399 #endif
400 
401  friend class DefaultAssembler2D;
402  friend class WaveAssembler2D;
403 };
404 
407 {
408  return m_nodeId[node];
409 }
410 
412 {
413  return (m_gNE[0]*m_order+1)*(m_gNE[1]*m_order+1);
414 }
415 
416 inline double Rectangle::getLocalCoordinate(index_t index, int dim) const
417 {
418  ESYS_ASSERT(dim>=0 && dim<2, "'dim' out of bounds");
419  ESYS_ASSERT(index>=0 && index<m_NN[dim], "'index' out of bounds");
420  return m_origin[dim] //origin
421  + m_dx[dim]*(m_offset[dim] + index/m_order //elements
422  + point_locations[m_order-2][index%m_order]); //quads
423 }
424 
425 inline boost::python::tuple Rectangle::getGridParameters() const
426 {
427  return boost::python::make_tuple(
428  boost::python::make_tuple(m_origin[0], m_origin[1]),
429  boost::python::make_tuple(m_dx[0], m_dx[1]),
430  boost::python::make_tuple(m_gNE[0], m_gNE[1]));
431 }
432 
433 //protected
435 {
436  return getNumNodes();
437 }
438 
439 //protected
441 {
442  return m_NN[0] * m_NN[1];
443 }
444 
445 //protected
447 {
448  return m_NE[0]*m_NE[1];
449 }
450 
451 } // end of namespace speckley
452 
453 #endif // __SPECKLEY_RECTANGLE_H__
454 
speckley::TagMap
std::map< std::string, int > TagMap
Definition: Speckley.h:46
speckley::Rectangle::getNumNodesPerDim
virtual const dim_t * getNumNodesPerDim() const
returns the number of nodes per MPI rank in each dimension
Definition: speckley/src/Rectangle.h:149
speckley::readNcGrid
escript::Data readNcGrid(std::string filename, std::string varname, escript::FunctionSpace fs, const object &pyShape, double fill, const object &pyFirst, const object &pyNum, const object &pyMultiplier, const object &pyReverse)
Definition: speckleycpp.cpp:115
speckley::SpeckleyDomain::m_order
int m_order
element order (will be m_order + 1 quad points in each axis)
Definition: speckley/src/SpeckleyDomain.h:755
speckley::Rectangle::getNumSubdivisionsPerDim
virtual const int * getNumSubdivisionsPerDim() const
returns the number of spatial subdivisions in each dimension
Definition: speckley/src/Rectangle.h:174
speckley::Rectangle::m_nodeDistribution
IndexVector m_nodeDistribution
Definition: speckley/src/Rectangle.h:395
speckley::Rectangle::m_elementId
IndexVector m_elementId
Definition: speckley/src/Rectangle.h:392
speckley::readBinaryGridFromZipped
escript::Data readBinaryGridFromZipped(std::string filename, escript::FunctionSpace fs, const object &pyShape, double fill, int byteOrder, int dataType, const object &pyFirst, const object &pyNum, const object &pyMultiplier, const object &pyReverse)
Definition: speckleycpp.cpp:86
speckley::Rectangle::getDofOfNode
virtual dim_t getDofOfNode(dim_t node) const
Definition: speckley/src/Rectangle.h:406
speckley::Rectangle::getNumDOF
virtual dim_t getNumDOF() const
returns the number of degrees of freedom per MPI rank
Definition: speckley/src/Rectangle.h:434
escript::FunctionSpace
Definition: FunctionSpace.h:36
speckley::DefaultAssembler2D
Definition: speckley/src/DefaultAssembler2D.h:26
speckley::probeInterpolationAcross
bool probeInterpolationAcross(int fsType_source, const escript::AbstractDomain &domain, int fsType_target, int dim)
Definition: CrossDomainCoupler.cpp:32
speckley
Definition: AbstractAssembler.cpp:19
speckley::Rectangle::getNumNodes
virtual dim_t getNumNodes() const
returns the number of nodes per MPI rank
Definition: speckley/src/Rectangle.h:440
speckley::readBinaryGrid
escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs, const object &pyShape, double fill, int byteOrder, int dataType, const object &pyFirst, const object &pyNum, const object &pyMultiplier, const object &pyReverse)
Definition: speckleycpp.cpp:61
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:64
speckley::Rectangle::m_NN
dim_t m_NN[2]
number of nodes for this rank in each dimension
Definition: speckley/src/Rectangle.h:381
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
speckley::Rectangle::getNodeDistribution
virtual IndexVector getNodeDistribution() const
returns the node distribution vector
Definition: speckley/src/Rectangle.h:168
speckley::Rectangle::m_gNE
dim_t m_gNE[2]
total number of elements in each dimension
Definition: speckley/src/Rectangle.h:363
speckley::WaveAssembler2D
Definition: speckley/src/WaveAssembler2D.h:26
speckley::Rectangle::randomFill
virtual escript::Data randomFill(const escript::DataTypes::ShapeType &shape, const escript::FunctionSpace &what, long seed, const boost::python::tuple &filter) const
Returns a Data object filled with random data passed through filter.
speckley::Rectangle::getLocalCoordinate
virtual double getLocalCoordinate(index_t index, int dim) const
returns the index'th coordinate value in given dimension for this rank
Definition: speckley/src/Rectangle.h:416
speckley::Rectangle::getNumFacesPerBoundary
virtual const dim_t * getNumFacesPerBoundary() const
returns the number of face elements in the order (left,right,bottom,top) on current MPI rank
Definition: speckley/src/Rectangle.h:162
speckley::SpeckleyDomain
SpeckleyDomain extends the AbstractContinuousDomain interface for the Speckley library and is the bas...
Definition: speckley/src/SpeckleyDomain.h:86
speckley::Rectangle::getLength
const double * getLength() const
returns the lengths of the domain
Definition: speckley/src/Rectangle.h:221
speckley::Rectangle::m_dx
double m_dx[2]
grid spacings / cell sizes of domain
Definition: speckley/src/Rectangle.h:372
speckley::Rectangle
Rectangle is the 2-dimensional implementation of a SpeckleyDomain.
Definition: speckley/src/Rectangle.h:34
speckley::RipleyCoupler
Definition: CrossDomainCoupler.h:29
speckley::Rectangle::getNumDataPointsGlobal
virtual dim_t getNumDataPointsGlobal() const
returns the number of data points summed across all MPI processes
Definition: speckley/src/Rectangle.h:411
escript::SubWorld_ptr
boost::shared_ptr< SubWorld > SubWorld_ptr
Definition: SubWorld.h:147
speckley::Rectangle::getNumElements
virtual dim_t getNumElements() const
returns the number of elements per MPI rank
Definition: speckley/src/Rectangle.h:446
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
speckley::Rectangle::m_origin
double m_origin[2]
origin of domain
Definition: speckley/src/Rectangle.h:366
speckley::Rectangle::m_nodeId
IndexVector m_nodeId
Definition: speckley/src/Rectangle.h:391
speckley::Rectangle::getGridParameters
virtual boost::python::tuple getGridParameters() const
returns the tuple (origin, spacing, number_of_elements)
Definition: speckley/src/Rectangle.h:425
speckley::ReaderParameters
Structure that wraps parameters for the grid reading routines.
Definition: speckley/src/SpeckleyDomain.h:53
escript::AbstractDomain
Base class for all escript domains.
Definition: AbstractDomain.h:51
speckley::Rectangle::m_NE
dim_t m_NE[2]
number of elements for this rank in each dimension including shared
Definition: speckley/src/Rectangle.h:378
speckley::IndexVector
std::vector< index_t > IndexVector
Definition: Speckley.h:44
speckley::Rectangle::m_dofId
IndexVector m_dofId
vector of sample reference identifiers
Definition: speckley/src/Rectangle.h:390
Speckley_DLL_API
#define Speckley_DLL_API
Definition: speckley/src/system_dep.h:23
speckley::Rectangle::m_offset
dim_t m_offset[2]
first node on this rank is at (offset0,offset1) in global mesh
Definition: speckley/src/Rectangle.h:384
speckley::Rectangle::getNumElementsPerDim
virtual const dim_t * getNumElementsPerDim() const
returns the number of elements per MPI rank in each dimension
Definition: speckley/src/Rectangle.h:155
speckley::DataMap
std::map< std::string, escript::Data > DataMap
Definition: speckley/src/domainhelpers.h:25
ESYS_ASSERT
#define ESYS_ASSERT(a, b)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false.
Definition: Assert.h:79
speckley::point_locations
const double point_locations[][11]
Definition: Speckley.h:71