NeoPZ
pzpargrid.cpp
Go to the documentation of this file.
1 
6 #include "pzpargrid.h"
7 #include "pzcmesh.h"
8 #include "pzgmesh.h"
9 
10 #include "pzgnode.h"
11 #include "pzgeoel.h"
12 #include "pzgeoelbc.h"
13 
14 #include "pzvec.h"
15 #include "pzstack.h"
16 
17 using namespace std;
18 
19 TPZGenPartialGrid::TPZGenPartialGrid(TPZVec<int> &nx, TPZVec<int> &rangex, TPZVec<int> &rangey, TPZVec<REAL> &x0,TPZVec<REAL> &x1) : fNx(nx), fX0(x0), fX1(x1),
20 fDelx(2)
21 {
22  fDelx[0] = (x1[0]-x0[0])/(nx[0]);
23  fDelx[1] = (x1[1]-x0[1])/(nx[1]);
24  fNumNodes= (nx[0]+1)*(nx[1]+1);
25  fElementType = 0;
26  fRangex = rangex;
27  fRangey = rangey;
28 }
29 
31 
32 }
33 
34 int64_t TPZGenPartialGrid::NodeIndex(int x, int y){
35  return y*(fNx[0]+1)+x;
36 }
37 
38 int64_t TPZGenPartialGrid::ElementIndex(int x, int y) {
39  return y*fNx[0]+x;
40 }
41 
42 short
44 
45  TPZVec<REAL> coor(2,0.);
46  int i,j;
47  int64_t index;
48 
49  if(grid.NodeVec().NElements() < fNumNodes) grid.NodeVec().Resize(fNumNodes);
50  for(i=fRangex[0]; i<fRangex[1]+1; i++) {
51  for(j = fRangey[0]; j<fRangey[1]+1; j++) {
52  index = NodeIndex(i,j);
53  Coord(index,coor);
54  grid.NodeVec()[index].Initialize(coor,grid);
55  }
56  }
57  //
58  //numbering the nodes
59  //
60  // create the geometric elements (retangular)
61 
62  TPZVec<int64_t> nos(4);
63  for(i=fRangex[0]; i<fRangex[1]; i++) {
64  for(j=fRangey[0]; j<fRangey[1]; j++) {
65  index = ElementIndex(i,j);
66  ElementConnectivity(index,nos);
67  if(fElementType == 0) {
68  int64_t index;
69  grid.CreateGeoElement(EQuadrilateral,nos,1,index);
70  } else {
71  int64_t index;
72  grid.CreateGeoElement(ETriangle,nos,1,index);
73  nos[1] = nos[2];
74  nos[2] = nos[3];
75  grid.CreateGeoElement(ETriangle,nos,1,index);
76  }
77  }
78  }
79  grid.BuildConnectivity();
80  return 0;
81 
82 }
83 
85  int ix = i%(fNx[0]+1);
86  int iy = i/(fNx[0]+1);
87  coor[0] = fX0[0]+fDelx[0]*ix;
88  coor[1] = fX0[1]+fDelx[1]*iy;
89 }
90 
91 void TPZGenPartialGrid::ElementConnectivity(int64_t i, TPZVec<int64_t> &rectangle_nodes){
92  int xel = i%(fNx[0]);
93  int yel = i/(fNx[0]);
94  rectangle_nodes[0] = yel*(fNx[0]+1)+xel;
95  rectangle_nodes[1] = yel*(fNx[0]+1)+xel+1;
96  rectangle_nodes[2] = (yel+1)*(fNx[0]+1)+xel+1;
97  rectangle_nodes[3] = (yel+1)*(fNx[0]+1)+xel;
98 }
99 
100 void TPZGenPartialGrid::Print( char *name , ostream &out )
101 {
102 
103  out<<"\n"<<name<<"\n";
104  out << "Number of divisions " << fNx[0] << ' ' << fNx[1] << endl;
105  out << "Corner Coordinates " << endl << fX0[0] << ' ' << fX0[1] << endl;
106  out << fX1[0] << ' ' << fX1[1] << endl;
107 
108 }
109 
110 void TPZGenPartialGrid::SetBC(TPZGeoMesh &g, int side, int bc) {
111  if(side == 0 && fRangey[0] != 0) return;
112  if(side == 1 && fRangex[1] != fNx[0]) return;
113  if(side == 2 && fRangey[1] != fNx[1]) return;
114  if(side == 3 && fRangex[0] != 0) return;
115  TPZStack<TPZGeoEl*> ElementVec;
116  TPZStack<int> Sides;
117  TPZVec<int64_t> cornernodes(4);
118  cornernodes[0] = NodeIndex(fRangex[0],fRangey[0]);
119  cornernodes[1] = NodeIndex(fRangex[1],fRangey[0]);
120  cornernodes[2] = NodeIndex(fRangex[1],fRangey[1]);
121  cornernodes[3] = NodeIndex(fRangex[0],fRangey[1]);
122  g.GetBoundaryElements(cornernodes[side],cornernodes[(side+1)%4],ElementVec, Sides);
123  int64_t numel = ElementVec.NElements();
124  for(int64_t el=0; el<numel; el++) {
125  TPZGeoEl *gel = (TPZGeoEl *) ElementVec[el];
126  if(gel) {
127  TPZGeoElBC(gel,Sides[el],bc);
128  }
129  }
130 }
131 
void Print(char *name=NULL, std::ostream &out=std::cout)
Definition: pzpargrid.cpp:100
const int64_t numel
Number of elements to test.
Definition: pzsubcmesh.cpp:47
TPZVec< REAL > fDelx
Definition: pzpargrid.h:59
clarg::argBool bc("-bc", "binary checkpoints", false)
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
Contains declaration of TPZGeoNode class which defines a geometrical node.
TPZVec< int > fRangey
Definition: pzpargrid.h:58
Templated vector implementation.
Contains the TPZGenPartialGrid class which implements the generation of a geometric grid...
Contains declaration of TPZGeoElBC class, it is a structure to help the construction of geometric ele...
int64_t NElements() const
Access method to query the number of elements of the vector.
void Resize(const int newsize)
Increase the size of the chunk vector.
Definition: pzadmchunk.h:280
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
void Coord(int i, TPZVec< REAL > &coord)
Definition: pzpargrid.cpp:84
short Read(TPZGeoMesh &malha)
Definition: pzpargrid.cpp:43
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
TPZVec< REAL > fX0
Definition: pzpargrid.h:59
Contains declaration of TPZCompMesh class which is a repository for computational elements...
void SetBC(TPZGeoMesh &gr, int side, int bc)
Definition: pzpargrid.cpp:110
A simple stack.
TPZVec< int > fRangex
Definition: pzpargrid.h:58
Structure to help the construction of geometric elements along side of a given geometric element...
Definition: pzgeoelbc.h:21
void GetBoundaryElements(int64_t IndexNodeFrom, int64_t IndexNodeTo, TPZStack< TPZGeoEl *> &ElementVec, TPZStack< int > &Sides)
GetBoundaryElements returns all elements beweeen NodFrom and NodTo counterclock wise this method uses...
Definition: pzgmesh.cpp:238
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
TPZVec< REAL > fX1
Definition: pzpargrid.h:59
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
This class implements a stack object. Utility.
Definition: pzcheckmesh.h:14
TPZGenPartialGrid(TPZVec< int > &nx, TPZVec< int > &rangex, TPZVec< int > &rangey, TPZVec< REAL > &x0, TPZVec< REAL > &x1)
Definition: pzpargrid.cpp:19
TPZVec< int > fNx
Definition: pzpargrid.h:57
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
int64_t NodeIndex(int i, int j)
Definition: pzpargrid.cpp:34
int64_t ElementIndex(int i, int j)
Definition: pzpargrid.cpp:38
int64_t fNumNodes
Definition: pzpargrid.h:60
void ElementConnectivity(int64_t iel, TPZVec< int64_t > &nodes)
Definition: pzpargrid.cpp:91