NeoPZ
input.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2014 by: *
3  * Gilvan Vieira (gilvandsv@gmail.com) *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ******************************************************************************/
20 
21 #include "tpzdohrsubstruct.h"
22 #include "tpzdohrmatrix.h"
23 #include "tpzdohrprecond.h"
24 #include "pzdohrstructmatrix.h"
25 #include "pzstepsolver.h"
26 #include "pzcompel.h"
27 #include "pzgeoelbc.h"
28 #include "pzelast3d.h"
29 #include "pzbndcond.h"
30 #include "tpzdohrassembly.h"
31 #include "pzlog.h"
32 #include "tpzgensubstruct.h"
33 #include "tpzpairstructmatrix.h"
34 #include "pzviscoelastic.h"
35 #include "TPZTimer.h"
36 #include "TPZVTKGeoMesh.h"
37 #include "pzgeotetrahedra.h"
38 #include "pzskylstrmatrix.h"
39 #include "pzskylmat.h"
40 #include "tpzarc3d.h"
41 #include "tpzdohrmatrix.h"
42 #include "pzvtkmesh.h"
43 #include "pzlog.h"
44 
45 #include <string>
46 
47 using namespace std;
48 
49 namespace Input {
51  void SetPointBC(TPZGeoMesh *gr, TPZVec<REAL> &x, int bc)
52  {
53  // look for an element/corner node whose distance is close to start
54  TPZGeoNode *gn1 = gr->FindNode(x);
55  int64_t iel;
56  int64_t nelem = gr->ElementVec().NElements();
57  TPZGeoEl *gel;
58  for (iel = 0; iel<nelem; iel++) {
59  gel = gr->ElementVec()[iel];
60  if(!gel) continue;
61  int nc = gel->NCornerNodes();
62  int c;
63  for (c=0; c<nc; c++) {
64  TPZGeoNode *gn = gel->NodePtr(c);
65  if (gn == gn1) {
66  break;
67  }
68  }
69  if (c<nc) {
70  TPZGeoElBC(gel, c, bc);
71  return;
72  }
73  }
74  }
75 
77  {
78  mesh->SetDimModel(3);
79  int nummat = 1, neumann = 1, mixed = 2;
80  // int dirichlet = 0;
81  int dir1 = -1, dir2 = -2, dir3 = -3, neumann1 = -4., neumann2 = -5; //, dirp2 = -6;
82  TPZManVector<STATE> force(3,0.);
83  //force[1] = 0.;
84 
85  STATE ElaE = 1000., poissonE = 0.2; //, poissonV = 0.1, ElaV = 100.;
86 
87  STATE lambdaV = 0, muV = 0, alpha = 0, deltaT = 0;
88  lambdaV = 11.3636;
89  muV = 45.4545;
90  alpha = 1.;
91  deltaT = 0.01;
92 
93  //TPZViscoelastic *viscoelast = new TPZViscoelastic(nummat);
94  //viscoelast->SetMaterialDataHooke(ElaE, poissonE, ElaV, poissonV, alpha, deltaT, force);
95  //TPZViscoelastic *viscoelast = new TPZViscoelastic(nummat, ElaE, poissonE, lambdaV, muV, alphaT, force);
96  TPZElasticity3D *viscoelast = new TPZElasticity3D(nummat, ElaE, poissonE, force);
97 
98  TPZFNMatrix<6> qsi(6,1,0.);
99  //viscoelast->SetDefaultMem(qsi); //elast
100  //int index = viscoelast->PushMemItem(); //elast
101  TPZMaterial * viscoelastauto(viscoelast);
102  mesh->InsertMaterialObject(viscoelastauto);
103 
104  // Neumann em x = 1;
105  TPZFMatrix<STATE> val1(3,3,0.),val2(3,1,0.);
106  val2(0,0) = 1.;
107  TPZBndCond *bc4 = viscoelast->CreateBC(viscoelastauto, neumann1, neumann, val1, val2);
108  TPZMaterial * bcauto4(bc4);
109  mesh->InsertMaterialObject(bcauto4);
110 
111  // Neumann em x = -1;
112  val2(0,0) = -1.;
113  TPZBndCond *bc5 = viscoelast->CreateBC(viscoelastauto, neumann2, neumann, val1, val2);
114  TPZMaterial * bcauto5(bc5);
115  mesh->InsertMaterialObject(bcauto5);
116 
117  val2.Zero();
118  // Dirichlet em -1 -1 -1 xyz;
119  val1(0,0) = 1e4;
120  val1(1,1) = 1e4;
121  val1(2,2) = 1e4;
122  TPZBndCond *bc1 = viscoelast->CreateBC(viscoelastauto, dir1, mixed, val1, val2);
123  TPZMaterial * bcauto1(bc1);
124  mesh->InsertMaterialObject(bcauto1);
125 
126  // Dirichlet em 1 -1 -1 yz;
127  val1(0,0) = 0.;
128  val1(1,1) = 1e4;
129  val1(2,2) = 1e4;
130  TPZBndCond *bc2 = viscoelast->CreateBC(viscoelastauto, dir2, mixed, val1, val2);
131  TPZMaterial * bcauto2(bc2);
132  mesh->InsertMaterialObject(bcauto2);
133 
134  // Dirichlet em 1 1 -1 z;
135  val1(0,0) = 0.;
136  val1(1,1) = 0.;
137  val1(2,2) = 1e4;
138  TPZBndCond *bc3 = viscoelast->CreateBC(viscoelastauto, dir3, mixed, val1, val2);
139  TPZMaterial * bcauto3(bc3);
140  mesh->InsertMaterialObject(bcauto3);
141 
142  }
143 
144  TPZGeoMesh *MalhaCubo(string FileName)
145  {
146  int numnodes=-1;
147  int numelements=-1;
148 
149  {
150  bool countnodes = false;
151  bool countelements = false;
152 
153  ifstream read (FileName.c_str());
154 
155  while(read)
156  {
157  char buf[1024];
158  read.getline(buf, 1024);
159  std::string str(buf);
160  if(str == "Coordinates") countnodes = true;
161  if(str == "end coordinates") countnodes = false;
162  if(countnodes) numnodes++;
163 
164  if(str == "Elements") countelements = true;
165  if(str == "end elements") countelements = false;
166  if(countelements) numelements++;
167  }
168  }
169 
170  TPZGeoMesh * gMesh = new TPZGeoMesh;
171 
172  gMesh -> NodeVec().Resize(numnodes);
173 
174  TPZManVector <int64_t> TopolTetra(4);
175 
176  const int Qnodes = numnodes;
177  TPZVec <TPZGeoNode> Node(Qnodes);
178 
179  //setting nodes coords
180  int64_t nodeId = 0, elementId = 0, matElId = 1;
181 
182  ifstream read;
183  read.open(FileName.c_str());
184 
185  double nodecoordX , nodecoordY , nodecoordZ ;
186 
187  char buf[1024];
188  read.getline(buf, 1024);
189  read.getline(buf, 1024);
190  std::string str(buf);
191  int in;
192  for(in=0; in<numnodes; in++)
193  {
194  read >> nodeId;
195  read >> nodecoordX;
196  read >> nodecoordY;
197  read >> nodecoordZ;
198  Node[nodeId-1].SetNodeId(nodeId);
199  Node[nodeId-1].SetCoord(0,nodecoordX);
200  Node[nodeId-1].SetCoord(1,nodecoordY);
201  Node[nodeId-1].SetCoord(2,nodecoordZ);
202  gMesh->NodeVec()[nodeId-1] = Node[nodeId-1];
203  }
204 
205  {
206  read.close();
207  read.open(FileName.c_str());
208 
209  int l , m = numnodes+5;
210  for(l=0; l<m; l++)
211  {
212  read.getline(buf, 1024);
213  }
214 
215 
216  int el;
217  int neumann1 = -4, neumann2 = -5;
218  //std::set<int> ncoordz; //jeitoCaju
219  for(el=0; el<numelements; el++)
220  {
221  read >> elementId;
222  read >> TopolTetra[0]; //node 1
223  read >> TopolTetra[1]; //node 2
224  read >> TopolTetra[2]; //node 3
225  read >> TopolTetra[3]; //node 4
226 
227  // O GID comeca com 1 na contagem dos nodes, e nao zero como no PZ, assim o node 1 na verdade é o node 0
228  TopolTetra[0]--;
229  TopolTetra[1]--;
230  TopolTetra[2]--;
231  TopolTetra[3]--;
232 
233  int64_t index = el;
234 
235  new TPZGeoElRefPattern< pzgeom::TPZGeoTetrahedra> (index, TopolTetra, matElId, *gMesh);
236  }
237 
238  gMesh->BuildConnectivity();
239 
240  // Colocando as condicoes de contorno
241  for(el=0; el<numelements; el++)
242  {
243  TPZManVector <TPZGeoNode,4> Nodefinder(4);
244  TPZManVector <REAL,3> nodecoord(3);
245  TPZGeoEl *tetra = gMesh->ElementVec()[el];
246 
247  // na face x = 1
248  TPZVec<int64_t> ncoordzVec(0); int64_t sizeOfVec = 0;
249  for (int i = 0; i < 4; i++)
250  {
251  int pos = tetra->NodeIndex(i);
252  Nodefinder[i] = gMesh->NodeVec()[pos];
253  Nodefinder[i].GetCoordinates(nodecoord);
254  if (nodecoord[0] == 1.)
255  {
256  sizeOfVec++;
257  ncoordzVec.Resize(sizeOfVec);
258  ncoordzVec[sizeOfVec-1] = pos;
259  }
260  }
261  if(ncoordzVec.NElements() == 3)
262  {
263  int lado = tetra->WhichSide(ncoordzVec);
264  TPZGeoElSide tetraSide(tetra, lado);
265  TPZGeoElBC(tetraSide,neumann1);
266  }
267 
268  // Na face x = -1
269  ncoordzVec.Resize(0);
270  sizeOfVec = 0;
271  for (int i = 0; i < 4; i++)
272  {
273  int pos = tetra->NodeIndex(i);
274  Nodefinder[i] = gMesh->NodeVec()[pos];
275 
276  Nodefinder[i].GetCoordinates(nodecoord);
277  if (nodecoord[0] == -1.)
278  {
279  sizeOfVec++;
280  ncoordzVec.Resize(sizeOfVec);
281  ncoordzVec[sizeOfVec-1] = pos;
282  }
283  }
284  if(ncoordzVec.NElements() == 3)
285  {
286  int lado = tetra->WhichSide(ncoordzVec);
287  TPZGeoElSide tetraSide(tetra, lado);
288  TPZGeoElBC(tetraSide,neumann2);
289  }
290 
291  }
292 
293  TPZVec <REAL> xyz(3,-1.), yz(3,-1.), z(3,1.);
294  yz[0] = 1.;
295  z[2] = -1;
296  int bcidxyz = -1, bcidyz = -2, bcidz = -3;
297  SetPointBC(gMesh, xyz, bcidxyz);
298  SetPointBC(gMesh, yz, bcidyz);
299  SetPointBC(gMesh, z, bcidz);
300 
301  }
302 
303  return gMesh;
304  }
305 
307  {
308  TPZGeoMesh *gmesh = 0;
309 
311 
312  gmesh = MalhaCubo(filename);
313  cmesh = new TPZCompMesh(gmesh);
314  cmesh->SetDimModel(3);
315  InsertElasticityCubo(cmesh);
316  cmesh->SetDefaultOrder(plevel);
317  cmesh->AutoBuild();
318 
319  // Gerando a matriz
320  TPZAnalysis an(cmesh);
321  TPZSkylineStructMatrix skyl(cmesh);
322  an.SetStructuralMatrix(skyl);
323  TPZStepSolver<REAL> step;
324  step.SetDirect(ECholesky);
325  an.SetSolver(step);
326  an.Assemble();
328  skylmat1 = an.Solver().Matrix();
329 
330  return skylmat1;
331  // TPZSkylMatrix<REAL> *orig = dynamic_cast<TPZSkylMatrix<REAL> *> (skylmat1.operator->());
332  //
333  // return orig;
334  }
335 
336 }
337 
338 
filename
Definition: stats.py:82
TPZGeoNode * NodePtr(int i) const
Returns a pointer to the ith node of the element.
Definition: pzgeoel.cpp:2566
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
void SetStructuralMatrix(TPZAutoPointer< TPZStructMatrix > strmatrix)
Set structural matrix as auto pointer for analysis.
Definition: pzanalysis.cpp:82
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
clarg::argBool bc("-bc", "binary checkpoints", false)
Timing class. Absolutely copied from GNU time. Take a look at
Contains the TPZDohrSubstruct class which implements sub structure matrices using Dohrman algorithm...
Contains the TPZVTKGraphMesh class which implements the graphical mesh to VTK environment.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Defines step solvers class. Solver.
Definition: pzmganalysis.h:17
void SetSolver(TPZMatrixSolver< STATE > &solver)
Set solver matrix.
virtual int NCornerNodes() const =0
Returns the number of corner nodes of the element.
This class implements a 3D isotropic elasticity material.
Definition: pzelast3d.h:21
Contains the TPZDohrMatrix class which implements a matrix divided into substructures. Also contains the TPZDohrThreadMultData and TPZDohrThreadMultList structs.
virtual void Assemble()
Assemble the stiffness matrix and load vector.
Definition: pzanalysis.cpp:304
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
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.
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...
Contains the TPZDohrAssembly class which implements assembling using Dohrmann algorithm.
TPZMatrixSolver< STATE > & Solver()
Get the solver matrix.
Definition: pzanalysis.h:367
static TPZGraphNode gn
Definition: pzgraphmesh.cpp:76
int WhichSide(TPZVec< int64_t > &SideNodeIds)
Returns the side number which is connected to the SideNodes returns -1 if no side is found...
Definition: pzgeoel.cpp:165
Implements a skyline storage format. A Skyline matrix is symmetric so square. Matrix.
Definition: pzskylmat.h:394
Contains the TPZDohrStructMatrix class which implements structural matrix divided in sub structures...
const int bc3
Definition: main.cpp:88
TPZGeoNode * FindNode(TPZVec< REAL > &co)
Returns the nearest node to the coordinate. This method is VERY INEFFICIENT.
Definition: pzgmesh.cpp:419
Contains the TPZElasticity3D class which implements a 3D isotropic elasticity material.
const int bc4
Definition: main.cpp:89
void SetDefaultOrder(int order)
Definition: pzcmesh.h:403
Implements SkyLine Structural Matrices. Structural Matrix.
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
clarg::argInt plevel("-p", "plevel", 1)
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
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
Contains the TPZGenSubStruct class which is an interface to "feed" the datastructure of the Dohrmann ...
Implements the sequence of actions to perform a finite element analysis. Analysis.
Definition: pzanalysis.h:32
Implements a generic geometric element which is refined according to a generic refinement pattern...
Definition: pzgmesh.h:35
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
Contains the TPZGeoTetrahedra class which implements the geometry of a tetrahedral element...
def read(filename)
Definition: stats.py:13
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
Contains the TPZSkylineStructMatrix class which implements SkyLine Structural Matrices.
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
Contains the TPZDohrPrecond class which implements a matrix which computes the preconditioner develop...
virtual void AutoBuild(const std::set< int > *MaterialIDs)
Creates the computational elements, and the degree of freedom nodes.
Definition: pzcmesh.cpp:308
Contains the TPZPairStructMatrix class.
Contains TPZSkyline class which implements a skyline storage format.
void SetDimModel(int dim)
Set de dimension of the domain of the problem.
Definition: pzcmesh.h:139
Structure to help the construction of geometric elements along side of a given geometric element...
Definition: pzgeoelbc.h:21
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
TPZGeoMesh * MalhaCubo(string FileName)
Definition: input.h:144
virtual TPZBndCond * CreateBC(TPZMaterial *reference, int id, int typ, TPZFMatrix< STATE > &val1, TPZFMatrix< STATE > &val2)
Creates an object TPZBndCond derived of TPZMaterial.
int InsertMaterialObject(TPZMaterial *mat)
Insert a material object in the datastructure.
Definition: pzcmesh.cpp:287
Contains the TPZArc3D class which implements three dimensional arc.
Implements a geometric node in the pz environment. Geometry.
Definition: pzgnode.h:31
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
const int bc1
Definition: main.cpp:86
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
void SetPointBC(TPZGeoMesh *gr, TPZVec< REAL > &x, int bc)
Generate a boundary geometric element at the indicated node.
Definition: input.h:51
TPZAutoPointer< TPZMatrix< TVar > > Matrix() const
Returns a pointer to TPZMatrix<>
Definition: pzsolve.h:138
Contains TPZStepSolver class which defines step solvers class.
const int bc2
Definition: main.cpp:87
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
TPZAutoPointer< TPZMatrix< REAL > > CreateCuboSkyMatrix(string filename, int plevel)
Definition: input.h:306
void SetDirect(const DecomposeType decomp)
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
Contains the TPZVTKGeoMesh class which implements the graphical mesh to VTK environment to geometric ...
Definition: input.h:49
void InsertElasticityCubo(TPZAutoPointer< TPZCompMesh > mesh)
Definition: input.h:76
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
TPZAdmChunkVector< TPZGeoEl * > & ElementVec()
Methods for handling pzlists.
Definition: pzgmesh.h:138