NeoPZ
TPZTriangleSphere.h
Go to the documentation of this file.
1 //
2 // TPZTriangleSphere.h
3 // PZ
4 //
5 // Created by Philippe Devloo on 3/21/14.
6 //
7 //
8 
9 #ifndef __PZ__TPZTriangleSphere__
10 #define __PZ__TPZTriangleSphere__
11 
12 #include <iostream>
13 #include "pzgeotriangle.h"
14 
15 namespace pzgeom {
16 
17  template <class GeomTriang = pzgeom::TPZGeoTriangle>
18  class TPZTriangleSphere : public GeomTriang
19  {
20  //int fNumWaves;
21 
23  REAL fR;
24 
25  public:
26  int ClassId() const override;
27 
29  TPZTriangleSphere(TPZVec<int64_t> &nodeindexes) : GeomTriang(nodeindexes), fXc(0.), fR(0.)
30  {
31  }
32 
34  TPZTriangleSphere() : GeomTriang(), fXc(0.), fR(0.)
35  {
36  }
37 
40  std::map<int64_t,int64_t> & gl2lcNdMap) : GeomTriang(cp,gl2lcNdMap), fXc(cp.fXc), fR(cp.fR)
41  {
42  }
43 
45  TPZTriangleSphere(const TPZTriangleSphere &cp) : GeomTriang(cp), fXc(cp.fXc), fR(cp.fR)
46  {
47  }
48 
50  TPZTriangleSphere(const TPZTriangleSphere &cp, TPZGeoMesh &) : GeomTriang(cp), fXc(cp.fXc), fR(cp.fR)
51  {
52  }
53 
55  {
56  GeomTriang::operator=(cp);
57  fR = cp.fR;
58  fXc = cp.fXc;
59  return *this;
60  }
61 
62 
63  void SetData(const REAL R, TPZVec<REAL> &Xc)
64  {
65 #ifdef PZDEBUG
66  if (Xc.size() != 3 || R == 0.0 ) {
67  DebugStop();
68  }
69 #endif
70  fXc = Xc;
71  fR = R;
72  }
73 
75  bool IsGeoBlendEl() const;
76 
78  static std::string TypeName() { return "TPZTriangleSphere";}
79 
80  static bool IsLinearMapping(int side)
81  {
82  return false;
83  }
84 
85  /* @brief Computes the coordinate of a point given in parameter space */
86  template<class T>
87  void X(TPZFMatrix<REAL> &cornerco,TPZVec<T> &loc,TPZVec<T> &result) const
88  {
89 // TPZFNMatrix<3*NNodes> coord(3,NNodes);
90 // CornerCoordinates(gel, coord);
91 // X(coord,loc,result);
92 
93 
94  TPZManVector<T,3> xqsi(3,0.); // will store (x,y,z) from (qsi,eta)
95  TPZManVector<T,3> XtminusXc(3,0.0); // will store (x,y,z)-xc
96  GeomTriang::X(cornerco,loc,xqsi);
98 
99  T NormValue = 0.0;
100 
101  for (int i = 0; i < 3; i++) {
102  XtminusXc[i] = xqsi[i] - Xc[i];
103  NormValue += XtminusXc[i]*XtminusXc[i];
104  }
105 
106 // XtminusXc[0,0)= xqsi[0] - Xc[0];
107 // XtminusXc(1,0)= xqsi[1] - Xc[1];
108 // XtminusXc(2,0)= xqsi[2] - Xc[2];
109 
110  NormValue = sqrt(NormValue);
111 
112  TPZManVector<T,3> Xsphere(3,0.0);
113  for(int i=0; i<3; i++)
114  {
115  result[i] = (fR/NormValue)*(XtminusXc[i])+ Xc[i];
116  }
117 // Xsphere[0] = (fR/NormValue)*(XtminusXc(0,0)+Xc[0]);
118 // Xsphere[1] = (fR/NormValue)*(XtminusXc(1,0)+Xc[1]);
119 // Xsphere[2] = (fR/NormValue)*(XtminusXc(2,0)+Xc[2]);
120 // result=Xsphere;
121 
122 
123  }
124 
125  template<class T>
127  {
128  TPZManVector<T,3> XTriangle(3,0.0);
129  TPZFNMatrix<9,T> GradOneoverNorm(3,1,0.0);
130  TPZFNMatrix<9,T> TensorXtGradX(3,2,0.0);
131  TPZFNMatrix<9,T> GradXtScaled(3,3,0.0);
132 
133  // TPZFNMatrix<3*NNodes> coord(3,NNodes);
134  // CornerCoordinates(gel, coord);
135 
136  GeomTriang::X(cornerco,par,XTriangle);
137  TPZFNMatrix<3,T> XtminusXc(3,1,0.0);
138  TPZVec<REAL> Xc= fXc;
139 
140  for (int i = 0; i < XTriangle.size(); i++)
141  { XtminusXc(i,0)= XTriangle[i] - Xc[i]; }
142  T NormValue = Norm(XtminusXc);
143 
144 
145  TPZFNMatrix<9,T> GradXt;
146  GeomTriang::GradX(cornerco,par,GradXt);
147 
148  GradOneoverNorm(0,0) = XtminusXc(0,0)*GradXt(0,0)+XtminusXc(1,0)*GradXt(1,0)+XtminusXc(2,0)*GradXt(2,0);
149  GradOneoverNorm(1,0) = XtminusXc(0,0)*GradXt(0,1)+XtminusXc(1,0)*GradXt(1,1)+XtminusXc(2,0)*GradXt(2,1);
150  T a = (NormValue*NormValue*NormValue);
151  T b = -fR/a;
152  GradOneoverNorm = b*GradOneoverNorm;
153 
154  TensorXtGradX(0,0)= XtminusXc(0,0)*GradOneoverNorm(0,0);
155  TensorXtGradX(0,1)= XtminusXc(0,0)*GradOneoverNorm(1,0);
156  TensorXtGradX(1,0)= XtminusXc(1,0)*GradOneoverNorm(0,0);
157  TensorXtGradX(1,1)= XtminusXc(1,0)*GradOneoverNorm(1,0);
158  TensorXtGradX(2,0)= XtminusXc(2,0)*GradOneoverNorm(0,0);
159  TensorXtGradX(2,1)= XtminusXc(2,0)*GradOneoverNorm(1,0);
160  a = fR/NormValue;
161  gradx=a*GradXt+TensorXtGradX;
162 
163  }
164 
165  /* @brief Computes the jacobian of the map between the master element and deformed element */
166 // void Jacobian(const TPZGeoEl &gel,TPZVec<REAL> &param,TPZFMatrix<REAL> &jacobian,TPZFMatrix<REAL> &axes,REAL &detjac,TPZFMatrix<REAL> &jacinv) const
167 // {
168 // TPZManVector<REAL,3> XTriangle(3,0.0);
169 // TPZFNMatrix<9,REAL> GradOneoverNorm(3,1,0.0);
170 // TPZFNMatrix<9,REAL> TensorXtGradX(3,2,0.0);
171 // TPZFNMatrix<9,REAL> GradXtScaled(3,3,0.0);
172 //
175 //
176 // GeomTriang::X(gel,param,XTriangle);
177 // TPZFMatrix<REAL> XtminusXc(3,1,0.0);
178 // TPZVec<REAL> Xc= fXc;
179 //
180 // for (int i = 0; i < XTriangle.size(); i++)
181 // { XtminusXc(i,0)= XTriangle[i] - Xc[i]; }
182 // REAL NormValue = Norm(XtminusXc);
183 //
184 // DebugStop();
186 // TPZFNMatrix<6> axest(3,2);
187 // axes.Transpose(&axest);
188 //
189 // TPZFNMatrix<9,REAL> GradXt;
190 // axest.Multiply(jacobian, GradXt);
191 //
192 // GradOneoverNorm(0,0) = XtminusXc(0,0)*GradXt(0,0)+XtminusXc(1,0)*GradXt(1,0)+XtminusXc(2,0)*GradXt(2,0);
193 // GradOneoverNorm(1,0) = XtminusXc(0,0)*GradXt(0,1)+XtminusXc(1,0)*GradXt(1,1)+XtminusXc(2,0)*GradXt(2,1);
194 // GradOneoverNorm = -(fR/(NormValue*NormValue*NormValue))*GradOneoverNorm;
195 //
196 // TensorXtGradX(0,0)= XtminusXc(0,0)*GradOneoverNorm(0,0);
197 // TensorXtGradX(0,1)= XtminusXc(0,0)*GradOneoverNorm(1,0);
198 // TensorXtGradX(1,0)= XtminusXc(1,0)*GradOneoverNorm(0,0);
199 // TensorXtGradX(1,1)= XtminusXc(1,0)*GradOneoverNorm(1,0);
200 // TensorXtGradX(2,0)= XtminusXc(2,0)*GradOneoverNorm(0,0);
201 // TensorXtGradX(2,1)= XtminusXc(2,0)*GradOneoverNorm(1,0);
202 //
203 // TPZFNMatrix<9,REAL> VecMatrix;
204 // VecMatrix=((fR/(NormValue))*GradXt)+TensorXtGradX;
205 //
206 //
207 //
208 // //-----
209 // /*
210 // TPZManVector<REAL,3> minx(3,0.),maxx(3,0.);
211 //
212 // int spacedim = coord.Rows();
213 //
214 // for (int j=0; j<spacedim; j++) { minx[j] = coord.GetVal(j,0); maxx[j] = coord.GetVal(j,0);}
215 //
216 // for(int i = 0; i < 3; i++) {
217 // for(int j = 0; j < spacedim; j++) {
218 // minx[j] = minx[j] < coord.GetVal(j,i) ? minx[j]:coord.GetVal(j,i);
219 // maxx[j] = maxx[j] > coord.GetVal(j,i) ? maxx[j]:coord.GetVal(j,i);
220 // }
221 // }
222 //
223 // REAL delx = 0.;
224 // for (int j=0; j<spacedim; j++) {
225 // delx = delx > (maxx[j]-minx[j]) ? delx : (maxx[j]-minx[j]);
226 // }
227 //
228 // VecMatrix *= 1./delx;
229 // */
230 // //-----
231 //
232 //
233 //
234 //
235 // VecMatrix.GramSchmidt(axest,jacobian);
236 // axest.Transpose(&axes);
237 // detjac = jacobian(0,0)*jacobian(1,1) - jacobian(1,0)*jacobian(0,1);
238 //
239 // if(IsZero(detjac))
240 // {
241 //
242 // detjac = ZeroTolerance();
243 // }
244 //
245 // jacinv(0,0) = jacobian(1,1)/detjac;
246 // jacinv(1,1) = jacobian(0,0)/detjac;
247 // jacinv(0,1) = -jacobian(0,1)/detjac;
248 // jacinv(1,0) = -jacobian(1,0)/detjac;
249 //
250 // /*
251 // // Left without the amplification for learning purposes
252 // jacobian *= delx;
253 // jacinv *= 1./delx;
254 // detjac *= (delx*delx);
255 // */
256 //
257 // }
258 
259  //void X(const TPZFMatrix<REAL> &nodes,TPZVec<REAL> &loc,TPZVec<REAL> &result) const;
260 
261 
262  // static TPZGeoEl *CreateBCGeoEl(TPZGeoEl *gel, int side,int bc);
263 
264  // /** @brief Creates a geometric element according to the type of the father element */
265  // static TPZGeoEl *CreateGeoElement(TPZGeoMesh &mesh, MElementType type,
266  // TPZVec<int64_t>& nodeindexes,
267  // int matid,
268  // int64_t& index);
269 
270  void Read(TPZStream& buf, void* context) override {
272  buf.Read(&fR,1);
273  }
274 
275  void Write(TPZStream &buf, int withclassid) const override
276  {
277  pzgeom::TPZGeoTriangle::Write(buf, withclassid);
278  buf.Write(&fR,1);
279  }
280 
281  static void InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size);
282 
283 
284 
285 
286  };
287 
288  template <class GeomTriang>
290  return Hash("TPZTriangleSphere") ^ GeomTriang::ClassId() << 1;
291  }
292 }
293 
294 #endif /* defined(__PZ__TPZTriangleSphere__) */
void Read(TPZStream &buf, void *context) override
read objects from the stream
static REAL cornerco[8][3]
void GradX(TPZFMatrix< REAL > &cornerco, TPZVec< T > &par, TPZFMatrix< T > &gradx) const
void X(TPZFMatrix< REAL > &cornerco, TPZVec< T > &loc, TPZVec< T > &result) const
void Write(TPZStream &buf, int withclassid) const override
bool IsGeoBlendEl() const
declare geometry as blended element
TPZTriangleSphere & operator=(const TPZTriangleSphere &cp)
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
static bool IsLinearMapping(int side)
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
TPZTriangleSphere(TPZVec< int64_t > &nodeindexes)
Constructor with list of nodes.
TPZTriangleSphere(const TPZTriangleSphere &cp, std::map< int64_t, int64_t > &gl2lcNdMap)
Constructor with node map.
int ClassId() const override
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
TPZTriangleSphere(const TPZTriangleSphere &cp)
Copy constructor.
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
TPZTriangleSphere(const TPZTriangleSphere &cp, TPZGeoMesh &)
Copy constructor.
void Read(TPZStream &buf, void *context) override
Creates a geometric element according to the type of the father element.
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Groups all classes which model the geometry.
Definition: pzgeopoint.cpp:18
static std::string TypeName()
Returns the type name of the element.
void SetData(const REAL R, TPZVec< REAL > &Xc)
static void InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec< REAL > &lowercorner, TPZVec< REAL > &size)
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
TPZTriangleSphere()
Empty constructor.