BasicMeshes.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23  \ *---------------------------------------------------------------------------*/
24 
25 #ifndef __BASICMESHES_HH
26 #define __BASICMESHES_HH
27 
28 #include "BasicShapes.hpp"
29 #include <memory>
30 
31 namespace mimmo{
32 
45 
46 protected:
47  std::unique_ptr<BasicShape> m_shape;
48  double m_dx;
49  double m_dy;
50  double m_dz;
51  int m_nx;
52  int m_ny;
53  int m_nz;
61  bool m_setorigin;
62  bool m_setspan;
64  bool m_setRefSys;
65  bool m_isBuild;
66 private:
67  //list of temp members
68  darray3E m_origin_temp;
69  darray3E m_span_temp;
70  darray3E m_inflimits_temp;
71  dmatrix33E m_refsystem_temp;
72  ShapeType m_shapetype_temp;
74 public:
75  //Building stuffs
76  UStructMesh();
77  virtual ~UStructMesh();
78 
79  // Copy constructor & assignment operators
80  UStructMesh(const UStructMesh & other);
82 
83  void swap(UStructMesh & x) noexcept;
84 
85  //get-set methods
86  const BasicShape* getShape() const;
89  darray3E getSpan();
99 
100  std::array<CoordType,3> getCoordType();
101 
104 
105  darray3E getLocalCCell(int);
106  darray3E getLocalCCell(int, int, int);
107  darray3E getLocalPoint(int);
108  darray3E getLocalPoint(int, int, int);
110  darray3E getGlobalCCell(int, int, int);
112  darray3E getGlobalPoint(int, int, int);
113 
115  ivector1D getCellNeighs(int, int, int);
116 
121 
122  void setOrigin(darray3E origin);
123  void setSpan(double, double, double);
124  void setSpan(darray3E span);
125  void setInfLimits(double val, int dir);
126  void setInfLimits(darray3E val);
127 
129  void setRefSystem(int, darray3E);
130  void setRefSystem(dmatrix33E);
131 
132  void setDimension(ivector1D dim);
133  void setDimension(iarray3E dim);
134 
135  void setShape(ShapeType type = ShapeType::CUBE);
136  void setShape(int itype = 0);
137  void setShape(const BasicShape *);
138 
139  void setCoordType(CoordType,int);
140  void setCoordTypex(CoordType);
141  void setCoordTypey(CoordType);
142  void setCoordTypez(CoordType);
143 
144  void setCoordType(std::array<CoordType,3>);
145 
146  void setMesh(darray3E & origin, darray3E & span, ShapeType, iarray3E & dimensions);
147  void setMesh(darray3E & origin, darray3E & span, ShapeType, dvector1D & spacing);
148  void setMesh(BasicShape *, iarray3E & dimensions);
149  void setMesh(BasicShape *, dvector1D & spacing);
150 
151  //generic manteinance of the mesh
152  void clearMesh();
153 
154  //functionalities
155  void locateCellByPoint(darray3E & point, int &i, int &j, int &k);
156  void locateCellByPoint(dvector1D & point, int &i, int &j, int &k);
157  int accessCellIndex(int i, int j, int k);
158  void accessCellIndex(int N_, int &i, int &j, int &k);
159  int accessPointIndex(int i, int j, int k);
160  void accessPointIndex(int N_, int &i, int &j, int &k);
161 
162  darray3E transfToGlobal( darray3E & point);
164  dvecarr3E transfToGlobal( dvecarr3E & list_points);
165  darray3E transfToLocal( darray3E & point);
167  dvecarr3E transfToLocal( dvecarr3E & list_points);
168 
169  // interpolators
170  double interpolateCellData(darray3E & point, dvector1D & celldata);
171  int interpolateCellData(darray3E & point, ivector1D & celldata);
172  darray3E interpolateCellData(darray3E & point, dvecarr3E & celldata);
173 
174  double interpolatePointData(darray3E & point, dvector1D & pointdata);
175  int interpolatePointData(darray3E & point, ivector1D & pointdata);
176  darray3E interpolatePointData(darray3E & point, dvecarr3E & pointdata);
177 
178  //plotting
179  void plotCloud( std::string & , std::string, int , bool, const ivector1D & labels, dvecarr3E * extPoints=nullptr);
180  void plotCloudScalar(std::string, std::string , int, bool, dvector1D & data);
181  void plotGrid(std::string &, std::string , int, bool, const ivector1D & labels, dvecarr3E * extPoints=nullptr);
182  void plotGridScalar(std::string, std::string , int, bool, dvector1D & data);
183 
184  void execute();
185  bool isBuilt();
186 
187  virtual bool build();
188 
189 protected:
190  //internal maintenance of the mesh
191  void resizeMesh();
192  void destroyNodalStructure();
193  void reshapeNodalStructure();
194 
195 };
196 
197 
204 inline int UStructMesh::accessPointIndex(int i, int j, int k){
205  int index = (m_ny+1) * (m_nz+1) * i + (m_nz+1) * j + k;
206  return(index);
207 };
208 
209 };
210 
211 #endif //__BASICMESHES_HH
CoordType getCoordTypey()
Abstract Interface class for Elementary Shape Representation.
Definition: BasicShapes.hpp:91
void setCoordTypey(CoordType)
void plotCloudScalar(std::string, std::string, int, bool, dvector1D &data)
darray3E getLocalSpan()
std::array< int, 3 > iarray3E
darray3E getLocalCCell(int)
darray3E getGlobalCCell(int)
void setDimension(ivector1D dim)
dvecarr3E getGlobalCellCentroids()
darray3E getGlobalPoint(int)
virtual bool build()
darray3E getLocalPoint(int)
CoordType
Specify type of conditions to distribute NURBS nodes in a given coordinate of the shape.
Definition: BasicShapes.hpp:49
void setRefSystem(darray3E, darray3E, darray3E)
int accessCellIndex(int i, int j, int k)
dvecarr3E getLocalCellCentroids()
void setCoordTypez(CoordType)
ivector1D getCellNeighs(int)
std::vector< darray3E > dvecarr3E
void setCoordType(CoordType, int)
void locateCellByPoint(darray3E &point, int &i, int &j, int &k)
std::unique_ptr< BasicShape > m_shape
Definition: BasicMeshes.hpp:47
void setOrigin(darray3E origin)
int accessPointIndex(int i, int j, int k)
const BasicShape * getShape() const
CoordType getCoordTypex()
void setShape(ShapeType type=ShapeType::CUBE)
std::array< CoordType, 3 > getCoordType()
std::vector< int > ivector1D
std::array< darray3E, 3 > dmatrix33E
void setMesh(darray3E &origin, darray3E &span, ShapeType, iarray3E &dimensions)
dvecarr3E getLocalCoords()
darray3E transfToLocal(darray3E &point)
std::vector< double > dvector1D
darray3E getSpacing()
darray3E transfToGlobal(darray3E &point)
virtual ~UStructMesh()
Definition: BasicMeshes.cpp:56
darray3E getScaling()
iarray3E getDimension()
void plotGridScalar(std::string, std::string, int, bool, dvector1D &data)
ShapeType
Identifies the type of elemental shape supported by BasicShape class.
Definition: BasicShapes.hpp:38
double interpolateCellData(darray3E &point, dvector1D &celldata)
double interpolatePointData(darray3E &point, dvector1D &pointdata)
void setCoordTypex(CoordType)
void plotCloud(std::string &, std::string, int, bool, const ivector1D &labels, dvecarr3E *extPoints=nullptr)
ShapeType getShapeType()
Class for 3D uniform structured mesh.
Definition: BasicMeshes.hpp:44
std::array< double, 3 > darray3E
void setSpan(double, double, double)
UStructMesh & operator=(UStructMesh other)
void swap(UStructMesh &x) noexcept
dvecarr3E getGlobalCoords()
darray3E getOrigin()
darray3E getInfLimits()
void plotGrid(std::string &, std::string, int, bool, const ivector1D &labels, dvecarr3E *extPoints=nullptr)
void setInfLimits(double val, int dir)
dmatrix33E getRefSystem()
CoordType getCoordTypez()