NeoPZ
TPZRefLinear.cpp
Go to the documentation of this file.
1 
5 #include "TPZRefLinear.h"
6 #include "pzshapelinear.h"
7 #include "TPZGeoLinear.h"
8 #include "TPZGeoElement.h"
9 #include "pzgeoel.h"
10 #include "pzgmesh.h"
11 
12 using namespace pzshape;
13 using namespace std;
14 
15 namespace pzrefine {
16  static int InNeigh[2][1][3] = {
17  {{1,1,0}},{{0,0,1}}
18  };
19 
20  static int CornerSons[2][2] = {
21  {0,2},{2,1}
22  };
23 
24  static int MidSideNodes[1][2] = {
25  {0,1}
26  };
27 
28  static REAL MidCoord[1][1] = { {0.} };
29 
30  static int subeldata[3][3][2] =
31  {
32  {{0,0}},/*side=0 { isub0{0,1},isub1{0,1} }*/
33  {{1,1}},/*side=1*/
34  {{0,2},{0,1},{1,2}}/*side=2*/
35  // {{0,1},{0,2},{1,2}}/*side=2*/
36  };
37 
38  static int nsubeldata[3] = {1,1,3};
39 
40  static REAL buildt[2][3][2][1] = {//por colunas
41  /*S0*/
42  {/*0*/{{0.},{-1.}},
43  /*1*/{{0.},{0.}},
44  /*2*/{{.5},{-.5}}
45  },
46  /*S1*/
47  {/*0*/{{0.},{0.}},
48  /*1*/{{0.},{1.}},
49  /*2*/{{.5},{.5}}
50  }
51  };
52 
53  static int fatherside[2][3] = {
54  {0,2,2},{2,1,2}
55  };
56 
57 
58  void TPZRefLinear::Divide(TPZGeoEl *geo,TPZVec<TPZGeoEl *> &SubElVec) {
59 
60  int i;
61  if(geo->HasSubElement()) {
62  SubElVec.Resize(NSubEl);
63  for(i=0;i<NSubEl;i++) SubElVec[i] = geo->SubElement(i);
64  return;//If exist fSubEl return this sons
65  }
66  int j,sub,matid=geo->MaterialId();
67  int64_t index;
68  int np[TPZShapeLinear::NSides];//guarda conectividades dos 8 subelementos
69 
70  for(j=0;j<TPZShapeLinear::NCornerNodes;j++) np[j] = geo->NodeIndex(j);
71  for(sub=TPZShapeLinear::NCornerNodes;sub<TPZShapeLinear::NSides;sub++) {
72  NewMidSideNode(geo,sub,index);
73  np[sub] = index;
74  }
75  // creating new subelements
76  for(i=0;i<TPZShapeLinear::NCornerNodes;i++) {
77  TPZManVector<int64_t> cornerindexes(TPZShapeLinear::NCornerNodes);
78  for(int j=0;j<TPZShapeLinear::NCornerNodes;j++) cornerindexes[j] = np[CornerSons[i][j]];
79  int64_t index;
80  TPZGeoEl *subel = geo->Mesh()->CreateGeoElement(EOned,cornerindexes,matid,index);
81  geo->SetSubElement(i , subel);
82  }
83 
84  SubElVec.Resize(NSubEl);
85  for(sub=0;sub<NSubEl;sub++) {
86  SubElVec[sub] = geo->SubElement(sub);
87  SubElVec[sub]->SetFather(geo);
88  SubElVec[sub]->SetFatherIndex(geo->Index());
89  }
90  for(i=0;i<NSubEl;i++) {//conectividades entre os filhos : viz interna
91  for(j=0;j<1;j++) { //lado do subel numero do filho viz. lado do viz.
92  geo->SubElement(i)->SetNeighbour(InNeigh[i][j][0],TPZGeoElSide(geo->SubElement(InNeigh[i][j][1]),InNeigh[i][j][2]));
93  }
94  }
95 
97 
98  }
99  void TPZRefLinear::MidSideNodeIndex(const TPZGeoEl *gel,int side,int64_t &index){
100  index = -1;
101  if(side<0 || side>TPZShapeLinear::NSides-1) {
102  PZError << "TPZRefCube::MidSideNodeIndex. Bad parameter side = " << side << endl;
103  return;
104  }
105  //sides 0 a 7
106  if(side<TPZShapeLinear::NCornerNodes) {//o nó medio do lado 0 é o 0 etc.
107  index = (gel)->NodeIndex(side);
108  return;
109  }
110  //o nó medio da face é o centro e o nó medio do centro é o centro
111  //como nó de algum filho se este existir
112  //caso tenha filhos é o canto de algum filho, se não tiver filhos retorna -1
113  if(gel->HasSubElement()) {
115  index=(gel->SubElement(MidSideNodes[side][0]))->NodeIndex(MidSideNodes[side][1]);
116  }
117  }
118  void TPZRefLinear::NewMidSideNode(TPZGeoEl *gel,int side,int64_t &index) {
119 
120  MidSideNodeIndex(gel,side,index);
121  if(index < 0) {
122  TPZGeoElSide gelside = gel->Neighbour(side);
123  if(gelside.Element()) {
124  while(gelside.Element() != gel) {
125  gelside.Element()->MidSideNodeIndex(gelside.Side(),index);
126  if(index!=-1) return;
127  gelside = gelside.Neighbour();
128  }
129  }
130  TPZVec<REAL> par(3,0.);
131  TPZVec<REAL> coord(3,0.);
132  if(side < TPZShapeLinear::NCornerNodes) {
133  index = gel->NodeIndex(side);
134  return;
135  }
136  //aqui side = 8 a 26
137  side-=TPZShapeLinear::NCornerNodes;//0,1,..,18
138  par[0] = MidCoord[side][0];
139  gel->X(par,coord);
140  index = gel->Mesh()->NodeVec().AllocateNewElement();
141  gel->Mesh()->NodeVec()[index].Initialize(coord,*gel->Mesh());
142  }
143 
144  }
145 
146  void TPZRefLinear::GetSubElements(const TPZGeoEl *father,int side, TPZStack<TPZGeoElSide> &subel) {
147 // subel.Resize(0);
148  if(side<0 || side>TPZShapeLinear::NSides || !father->HasSubElement()){
149  PZError << "TPZRefCube::GetSubelements2 called with error arguments\n";
150  return;
151  }
152  int nsub = NSideSubElements(side);//nsubeldata[side];
153  for(int i=0;i<nsub;i++)
154  subel.Push(TPZGeoElSide(father->SubElement(subeldata[side][i][0]),subeldata[side][i][1]));
155 
156  }
157  int TPZRefLinear::NSideSubElements(int side) {
158  if(side<0 || side>TPZShapeLinear::NSides-1){
159  PZError << "TPZRefCube::NSideSubelements2 called with error arguments\n";
160  return -1;
161  }
162  return nsubeldata[side];
163 
164  }
165 
166  TPZTransform<> TPZRefLinear::GetTransform(int side,int whichsubel) {
167  if(side<0 || side>TPZShapeLinear::NSides-1){
168  PZError << "TPZRefLinear::GetTransform side out of range or father null\n";
169  return TPZTransform<>(0,0);
170  }
171  int smalldim = TPZShapeLinear::SideDimension(side);
172  int fatherside = FatherSide(side,whichsubel);
173  int largedim = TPZShapeLinear::SideDimension(fatherside);
174  TPZTransform<> trans(largedim,smalldim);
175  int i,j;
176  for(i=0; i<largedim; i++) {
177  for(j=0; j<smalldim; j++) {
178  trans.Mult()(i,j) = buildt[whichsubel][side][j][i];
179  }
180  trans.Sum() (i,0) = buildt[whichsubel][side][1][i];
181  }
182  return trans;
183 
184  }
185 
186  int TPZRefLinear::FatherSide(int side,int whichsubel) {
187  if(side<0 || side>TPZShapeLinear::NSides-1){
188  PZError << "TPZRefCube::Father2 called error" << endl;
189  return -1;
190  }
191  return fatherside[whichsubel][side];
192 
193  }
194 
195  int TPZRefLinear::ClassId() const{
196  return Hash("TPZRefLinear");
197  }
198 };
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
int MaterialId() const
Returns the material index of the element.
Definition: pzgeoel.h:250
virtual TPZGeoEl * CreateGeoElement(MElementType type, TPZVec< int64_t > &cornerindexes, int matid, int64_t &index, int reftype=1)
Generic method for creating a geometric element. Putting this method centrally facilitates the modifi...
Definition: pzgmesh.cpp:1296
virtual void SetNeighbour(int side, const TPZGeoElSide &neighbour)=0
Fill in the data structure for the neighbouring information.
clarg::argInt nsub("-nsub", "number of substructs", 4)
static int SideDimension(int side)
Returns the dimension of the side.
Definition: tpzline.cpp:245
groups all classes dedicated to the computation of shape functions
Definition: pzshapeextend.h:16
const TPZFMatrix< T > & Mult() const
Definition: pztrnsform.h:64
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
TPZGeoElSide Neighbour() const
Definition: pzgeoel.h:754
TPZGeoMesh * Mesh() const
Returns the mesh to which the element belongs.
Definition: pzgeoel.h:220
virtual int64_t NodeIndex(int i) const =0
Returns the index of the ith node the index is the location of the node in the nodevector of the mesh...
static int CornerSons[2][2]
Contains TPZShapeLinear class which implements the shape functions of a linear one-dimensional elemen...
static int nsubeldata[3]
virtual TPZGeoEl * SubElement(int is) const =0
Returns a pointer to the subelement is.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
static int MidSideNodes[1][2]
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
static int InNeigh[2][1][3]
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
int64_t Index() const
Returns the index of the element within the element vector of the mesh.
Definition: pzgeoel.h:730
static int fatherside[2][3]
static int subeldata[3][3][2]
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
const TPZFMatrix< T > & Sum() const
Definition: pztrnsform.h:66
Groups all classes which model the h refinement These classes are used as template arguments of...
Definition: pzrefpoint.cpp:15
virtual TPZGeoElSide Neighbour(int side)=0
Returns a pointer to the neighbour and the neighbourside along side of the current element...
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual void SetSubElement(int i, TPZGeoEl *gel)=0
Sets the subelement of index i.
virtual int HasSubElement() const =0
Return 1 if the element has subelements.
TPZGeoEl * Element() const
Definition: pzgeoelside.h:162
virtual void X(TPZVec< REAL > &qsi, TPZVec< REAL > &result) const =0
Return the coordinate in real space of the point coordinate in the master element space...
This class implements a stack object. Utility.
Definition: pzcheckmesh.h:14
int Side() const
Definition: pzgeoelside.h:169
Contains the TPZRefLinear class which implements the uniform refinement of a geometric linear element...
static REAL MidCoord[1][1]
Implements an affine transformation between points in parameter space. Topology Utility.
Definition: pzmganalysis.h:14
static REAL buildt[2][3][2][1]
Contains declaration of TPZGeoElement class which implements a generic geometric element with a unifo...
Definition: pzeltype.h:55
virtual void SetSubElementConnectivities()
Initializes the external connectivities of the subelements.
Definition: pzgeoel.cpp:563
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
virtual void MidSideNodeIndex(int side, int64_t &index) const =0
Returns the midside node index along a side of the element.