NeoPZ
TPBSpStructMatrix.cpp
Go to the documentation of this file.
1 
6 #include "TPBSpStructMatrix.h"
7 #include "TPZSpStructMatrix.h"
8 #include "pzstrmatrix.h"
9 
10 #include "pzgeoelbc.h"
11 #include "pzgmesh.h"
12 #include "pzcmesh.h"
13 
14 #include "pzanalysis.h"
15 #include "pzsolve.h"
16 #include "pzstepsolver.h"
17 
18 #include "pzdxmesh.h"
19 #include <fstream>
20 #include "pzelmat.h"
21 #include "pzysmp.h"
22 
23 #include "pzbndcond.h"
24 #include "pzmetis.h"
25 
26 
27 using namespace std;
28 
29 #ifndef STATE_COMPLEX
30 #include "pzmat2dlin.h"
31 
33 
34  int refine=5;
35  int order=5;
36 
37  TPZGeoMesh gmesh;
38  TPZCompMesh cmesh(&gmesh);
39  double coordstore[4][3] = {{0.,0.,0.},{1.,0.,0.},{1.,1.,0.},
40  {0.,1.,0.}};
41 
42  int i,j;
43  TPZVec<REAL> coord(3,0.);
44  for(i=0; i<4; i++) {
45  // initializar as coordenadas do no em um vetor
46  for (j=0; j<3; j++) coord[j] = coordstore[i][j];
47 
48  // identificar um espa� no vetor onde podemos armazenar
49  // este vetor
50  gmesh.NodeVec ().AllocateNewElement ();
51 
52  // initializar os dados do n�
53  gmesh.NodeVec ()[i].Initialize (i,coord,gmesh);
54  }
55  int el;
56  TPZGeoEl *gel;
57  for(el=0; el<1; el++) {
58 
59  // initializar os indices dos n�
60  TPZVec<int64_t> indices(4);
61  for(i=0; i<4; i++) indices[i] = i;
62  // O proprio construtor vai inserir o elemento na malha
63  int64_t index;
64  gel = gmesh.CreateGeoElement(EQuadrilateral, indices,1,index);
65  }
66  gmesh.BuildConnectivity ();
67 
68  TPZVec<TPZGeoEl *> subel;
69  //gel->Divide(subel);
70 
71 
72 
73  cout << "Refinement ";
74  cin >> refine;
75  cout << endl;
76 
77  DebugStop();
78 // UniformRefine(refine,gmesh);
79 
80 
81  TPZGeoElBC gelbc(gel,4,-4);
82  TPZMat2dLin *meumat = new TPZMat2dLin(1);
83  TPZFMatrix<STATE> xk(1,1,1.),xc(1,2,0.),xf(1,1,1.);
84  meumat->SetMaterial (xk,xc,xf);
85  TPZMaterial * meumatptr(meumat);
86  cmesh.InsertMaterialObject(meumatptr);
87 
88  TPZFMatrix<STATE> val1(1,1,0.),val2(1,1,0.);
89  TPZMaterial * bnd = meumat->CreateBC (meumatptr,-4,0,val1,val2);
90 
91  cmesh.InsertMaterialObject(bnd);
92 
93 
94 
95  cout << "Interpolation order ";
96  cin >> order;
97  cout << endl;
98 
99  // TPZCompEl::gOrder = order;
100  cmesh.SetDefaultOrder(order);
101 
102  cmesh.AutoBuild();
103  // cmesh.AdjustBoundaryElements();
104  cmesh.InitializeBlock();
105 
106  ofstream output("outputPar.dat");
107  // ofstream output2("outputNon.dat");
108  //cmesh.Print(output);
109  TPZAnalysis an(&cmesh,true,output);
110  // TPZAnalysis an2(&cmesh,output);
111 
112  TPZVec<int> numelconnected(cmesh.NEquations(),0);
113  int64_t ic;
114  //cout << "Nmero de Equa�es -> " << cmesh.NEquations() << endl;
115  //cout.flush();
116 
117  ofstream out("cmeshBlock_out.txt");
118  // cmesh.Print(out);
119  // cmesh.Block().Print("Block",out);
120  for(ic=0; ic<cmesh.ConnectVec().NElements(); ic++) {
121  TPZConnect &cn = cmesh.ConnectVec()[ic];
122  if(cn.HasDependency()) continue;
123  int64_t seqn = cn.SequenceNumber();
124  if(seqn < 0) continue;
125  int64_t firsteq = cmesh.Block().Position(seqn);
126  int64_t lasteq = firsteq+cmesh.Block().Size(seqn);
127  int64_t ind;
128  int temp = cmesh.ConnectVec()[ic].NElConnected();
129  for(ind=firsteq;ind<lasteq;ind++) {
130  numelconnected[ind] = temp;//cmesh.ConnectVec()[ic].NElConnected();
131  }
132  }
133  // //cout << "nequations " << numelconnected.NElements();
134  // for(ic=0;ic<numelconnected.NElements(); ic++) //cout << numelconnected[ic] <<' ';
135  // //cout << endl;
136  // //cout.flush();
137 
138  // TPZFrontMatrix<TPZFileEqnStorage, TPZFrontNonSym> *mat = new TPZFrontMatrix<TPZFileEqnStorage, TPZFrontNonSym>(cmesh.NEquations());
139  //TPZFrontMatrix<TPZStackEqnStorage, TPZFrontNonSym> *mat = new TPZFrontMatrix<TPZStackEqnStorage, TPZFrontNonSym>(cmesh.NEquations());
140  //TPZFrontMatrix<TPZStackEqnStorage> *mat = new TPZFrontMatrix<TPZStackEqnStorage>(cmesh.NEquations());
141 
142  //TPZParFrontStructMatrix<TPZFrontSym> mat(&cmesh);
143  TPBSpStructMatrix mat(&cmesh);
144 
145  // TPZFStructMatrix mat2(&cmesh);
146  // mat->SetNumElConnected(numelconnected);
147  //mat = CreateAssemble();
148 
149  //int threads=3;
150  //cout << "Number of Threads ";
151  //cin >> threads;
152  //cout << endl;
153 
154  //mat.SetNumberOfThreads(threads);
155  //mat.SetNumberOfThreads(1);
156 
157  an.SetStructuralMatrix(mat);
158  // an2.SetStructuralMatrix(mat2);
159 
161  // sol.SetDirect(ELU);
162  sol.SetDirect(ECholesky);
163  // TPZStepSolver sol2;
164  // sol2.SetDirect(ECholesky);
165  // sol.SetDirect(ELU);
166 
167 
168  an.SetSolver(sol);
169  // an2.SetSolver(sol2);
170  // mat->SetNumElConnected(numelconnected);
171  // mat->SetFileName("longhin.bin");
172  // an.Solver().SetDirect(ELU);
173  // mat->FinishWriting();
174  // mat->SetFileName('r',"longhin.bin");
175  // //cout << "******************************************************************************************************AQUI 1" << endl;
176  an.Run(output);
177  //an.Print("solution of frontal solver", output);
178  // //cout << "******************************************************************************************************AQUI 2" << endl;
179  // an2.Run(output2);
180  // an2.Print("solution of frontal solver", output2);
181  /*
182  TPZVec<char *> scalnames(1);
183  scalnames[0] = "state";
184 
185  TPZVec<char *> vecnames(0);
186 
187  TPZDXGraphMesh graph(&cmesh,2,meumat,vecnames,scalnames);
188  ofstream *dxout = new ofstream("poisson.dx");
189  graph.SetOutFile(*dxout);
190  graph.SetResolution(0);
191 
192  //an.DefineGraphMesh(2, scalnames, vecnames, plotfile);
193  //an.Print("FEM SOLUTION ",output);
194  //an.PostProcess(1);
195  int istep = 0,numstep=1;
196 
197  graph.DrawMesh(numstep+1);
198  graph.DrawSolution(0,0);
199 
200  TPZAnalysis an2(&cmesh,output);
201  TPZFMatrix<STATE> *full = new TPZFMatrix(cmesh.NEquations(),cmesh.NEquations(),0.);
202  an2.SetMatrix(full);
203  an2.Solver().SetDirect(ELU);
204  an2.Run(output);
205  an2.Print("solution of full matrix", output);
206 
207  // full->Print("full decomposed matrix");
208  */
209  output.flush();
210  cout.flush();
211  return 0;
212 
213 }
214 
215 #endif
216 
218  return new TPBSpStructMatrix(*this);
219 }
221  int64_t neq = fMesh->NEquations();
222  if(fMesh->FatherMesh()) {
223  cout << "TPZSpStructMatrix should not be called with CreateAssemble for a substructure mesh\n";
224  return new TPZFYsmpMatrix<STATE>(0,0);
225  }
226  TPZMatrix<STATE> *stiff = Create();//new TPZFYsmpMatrix(neq,neq);
227  rhs.Redim(neq,1);
228  //stiff->Print("Stiffness TPZFYsmpMatrix :: CreateAssemble()");
229  Assemble(*stiff,rhs, guiInterface);
230  //stiff->Print("Stiffness TPZFYsmpMatrix :: CreateAssemble()");
231  return stiff;
232 }
234  //checked
235 
236  int64_t neq = fEquationFilter.NActiveEquations();
237  TPZFYsmpMatrix<STATE> * mat = new TPZFYsmpMatrix<STATE>(neq,neq);
238 
240  // TPZVec<int> elorder(fMesh->NEquations(),0);
241 
242 
246  TPZStack<int64_t> elgraph;
247  TPZVec<int64_t> elgraphindex;
248  // int nnodes = 0;
249  fMesh->ComputeElGraph(elgraph,elgraphindex);
251  TPZMetis metis;
252  metis.SetElementsNodes(elgraphindex.NElements() -1 ,fMesh->NIndependentConnects());
253  metis.SetElementGraph(elgraph,elgraphindex);
254 
255  TPZManVector<int64_t> nodegraph;
256  TPZManVector<int64_t> nodegraphindex;
261  metis.ConvertGraph(elgraph,elgraphindex,nodegraph,nodegraphindex);
263  int64_t i;
264  int64_t nblock = nodegraphindex.NElements()-1;
265  int64_t totalvar = 0;
266  int64_t totaleq = 0;
267  for(i=0;i<nblock;i++){
268  int64_t iblsize = fMesh->Block().Size(i);
269  int64_t iblpos = fMesh->Block().Position(i);
270  int64_t numactive = fEquationFilter.NumActive(iblpos, iblpos+iblsize);
271  if (!numactive) {
272  continue;
273  }
274  if (numactive != iblsize) {
275  DebugStop();
276  }
277  totaleq += iblsize;
278  int64_t icfirst = nodegraphindex[i];
279  int64_t iclast = nodegraphindex[i+1];
280  int64_t j;
281  //longhin
282  totalvar+=iblsize*iblsize;
283  for(j=icfirst;j<iclast;j++) {
284  int64_t col = nodegraph[j];
285  int64_t colsize = fMesh->Block().Size(col);
286  int64_t colpos = fMesh->Block().Position(col);
287  int64_t numactive = fEquationFilter.NumActive(colpos, colpos+colsize);
288  if (!numactive) {
289  continue;
290  }
291  totalvar += iblsize*colsize;
292  }
293  }
294 
295  int64_t ieq = 0;
296  int64_t pos = 0;
297 
298  nblock=fMesh->NIndependentConnects();
299 
300  int64_t * Eq = new int64_t[totaleq+1];
301  int64_t * EqCol = new int64_t[totalvar/2];
302  STATE * EqValue = new STATE[totalvar/2];
303  for(i=0;i<nblock;i++){
304  int64_t iblsize = fMesh->Block().Size(i);
305  int64_t iblpos = fMesh->Block().Position(i);
306  int64_t numactive = fEquationFilter.NumActive(iblpos, iblpos+iblsize);
307  if (!numactive) {
308  continue;
309  }
310  int64_t ibleq;
311  for(ibleq=0; ibleq<iblsize; ibleq++) {
312  Eq[ieq] = pos;
313  if(ieq%2) {
314  ieq++;
315  continue;
316  }
317  int64_t colsize = fMesh->Block().Size(i);
318  int64_t colpos = fMesh->Block().Position(i);
319  int64_t jbleq;
320  for(jbleq=0; jbleq<colsize; jbleq++) {
322  EqCol[pos] = -1;//colpos;
323  EqValue[pos] = 0.;
324  colpos++;
325  pos++;
326  }
327 
328  int64_t icfirst = nodegraphindex[i];
329  int64_t iclast = nodegraphindex[i+1];
330  int64_t j;
331  for(j=icfirst;j<iclast;j++) {
332  int64_t col = nodegraph[j];
333  colsize = fMesh->Block().Size(col);
334  colpos = fMesh->Block().Position(col);
335  int64_t numactive = fEquationFilter.NumActive(colpos, colpos+colsize);
336  if (!numactive) {
337  continue;
338  }
339  for(jbleq=0; jbleq<colsize; jbleq++) {
340  EqCol[pos] = -1;//colpos;
341  EqValue[pos] = 0.;
342  colpos++;
343  pos++;
344  }
345  }
346  ieq++;
347  }
348  }
349  Eq[ieq] = pos;
350  /* for(i=0;i<totalvar;i++){
351  if(i<totaleq+1){
352  cout << i << " " << Eq[i] << " "<< EqCol[i] << " " << EqValue[i] << endl;
353  }else{
354  cout << i << " " << " "<< EqCol[i] << " " << EqValue[i] << endl;
355  }
356  }
357  */
358  mat->SetData(Eq,EqCol,EqValue);
359  return mat;
360 }
362 TPZSpStructMatrix(mesh)
363 {
364 }
365 
367  return Hash("TPBSpStructMatrix") ^ TPZSpStructMatrix::ClassId() << 1;
368 }
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
Contains TPZAnalysis class which implements the sequence of actions to perform a finite element analy...
int Position(const int block_diagonal) const
Returns the position of first element block dependent on matrix diagonal.
Definition: pzblock.h:177
void SetElementGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex)
This method declares the element graph to the object.
Represents a set of shape functions associated with a computational element/side. Computational Eleme...
Definition: pzconnect.h:30
void SetStructuralMatrix(TPZAutoPointer< TPZStructMatrix > strmatrix)
Set structural matrix as auto pointer for analysis.
Definition: pzanalysis.cpp:82
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
Implements renumbering for elements of a mesh. Utility.
Definition: pzmetis.h:17
void ConvertGraph(TPZVec< int64_t > &elgraph, TPZVec< int64_t > &elgraphindex, TPZManVector< int64_t > &nodegraph, TPZManVector< int64_t > &nodegraphindex)
Will convert an element graph defined by elgraph and elgraphindex into a node graph defined by nodegr...
int64_t NEquations()
This computes the number of equations associated with non-restrained nodes.
Definition: pzcmesh.cpp:721
Defines step solvers class. Solver.
Definition: pzmganalysis.h:17
void SetSolver(TPZMatrixSolver< STATE > &solver)
Set solver matrix.
Implements a non symmetric sparse matrix (Yale Sparse Matrix Storage). Matrix.
Definition: pzysmp.h:45
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 void SetData(int64_t *IA, int64_t *JA, TVar *A)
Pass the data to the class.
Definition: pzysmp.h:232
virtual TPZStructMatrix * Clone() override
Contains the TPZStructMatrixOR class which responsible for a interface among Matrix and Finite Elemen...
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface) override
void SetDefaultOrder(int order)
Definition: pzcmesh.h:403
int ClassId() const override
Define the class id associated with the class.
Refines geometrical mesh (all the elements) num times.
Definition: pzstrmatrix.h:35
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
Contains the TPZSpStructMatrix class which implements sparse structural matrices. ...
virtual TPZMatrix< STATE > * Create() override
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
int64_t SequenceNumber() const
Returns the Sequence number of the connect object.
Definition: pzconnect.h:158
Implements the sequence of actions to perform a finite element analysis. Analysis.
Definition: pzanalysis.h:32
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
void SetElementsNodes(int64_t NElements, int64_t NNodes)
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
virtual void AutoBuild(const std::set< int > *MaterialIDs)
Creates the computational elements, and the degree of freedom nodes.
Definition: pzcmesh.cpp:308
int HasDependency() const
Returns whether exist dependecy information.
Definition: pzconnect.h:292
Contains the TPZFYsmpMatrix class which implements a non symmetric sparse matrix. ...
const TPZBlock< STATE > & Block() const
Access the block structure of the solution vector.
Definition: pzcmesh.h:213
Contains the TPZMat2dLin class which implements a bi-dimensional linear problem.
TPZAdmChunkVector< TPZConnect > & ConnectVec()
Return a reference to the connect pointers vector.
Definition: pzcmesh.h:198
Contains declaration of TPZCompMesh class which is a repository for computational elements...
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
void SetMaterial(TPZFMatrix< STATE > &xkin, TPZFMatrix< STATE > &xcin, TPZFMatrix< STATE > &xfin)
Definition: pzmat2dlin.h:44
virtual void Run(std::ostream &out=std::cout)
Calls the appropriate sequence of methods to build a solution or a time stepping sequence.
Definition: pzanalysis.cpp:920
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
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
virtual TPZBndCond * CreateBC(TPZMaterial *reference, int id, int typ, TPZFMatrix< STATE > &val1, TPZFMatrix< STATE > &val2)
Creates an object TPZBndCond derived of TPZMaterial.
Contains the TPBSpStructMatrix class which assembles on the pair equations.
int InsertMaterialObject(TPZMaterial *mat)
Insert a material object in the datastructure.
Definition: pzcmesh.cpp:287
TPBSpStructMatrix(TPZCompMesh *)
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
Implements a bi-dimensional linear problem.
Definition: pzmat2dlin.h:22
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int Size(const int block_diagonal) const
Returns block dimension.
Definition: pzblock.h:171
Contains TPZSolver class which defines a abstract class of solvers which will be used by matrix class...
Assembles only the pair equations. Structural Matrix.
Contains TPZStepSolver class which defines step solvers class.
Implements Sparse Structural Matrices. Structural Matrix.
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
void SetDirect(const DecomposeType decomp)
Contains the TPZDXGraphMesh class which implements the interface of the graphmesh to the OpenDX graph...
void InitializeBlock()
Resequence the block object, remove unconnected connect objects and reset the dimension of the soluti...
Definition: pzcmesh.cpp:391
Contains TPZMetis class which implements the renumbering for elements of a mesh to minimize the band...
int ClassId() const override
Define the class id associated with the class.