NeoPZ
pzdxmesh.cpp
Go to the documentation of this file.
1 
6 #include "pzdxmesh.h"
7 #include "pzcmesh.h"
8 #include "pzcompel.h"
9 #include "pzintel.h"
10 #include "pzgraphel.h"
11 #include "pztrigraph.h"
12 #include "pzgraphnode.h"
13 #include "TPZMaterial.h"
14 #include "pzfmatrix.h"
15 #include "pzgeoel.h"
16 
17 using namespace std;
18 
19 TPZDXGraphMesh::TPZDXGraphMesh(TPZCompMesh *cmesh, int dimension, const std::set<int> & matids, const TPZVec<std::string> &scalarnames, const TPZVec<std::string> &vecnames) :
20 TPZGraphMesh(cmesh,dimension,matids,scalarnames,vecnames) {
21  fNextDataField = 1;
22  fStyle = EDXStyle;
23  // int index = 0;
24  TPZCompEl *ce = FindFirstInterpolatedElement(cmesh,dimension);
25  fElementType = "noname";
26  if(ce) {
27  int type = ce->Type();
28  if(type == EOned) fElementType = "lines";
29  if(type == ETriangle) fElementType = "triangles";
30  if(type == EQuadrilateral) fElementType = "quads";
31  if(type == ECube) fElementType = "cubes";
32  if(type == EPrisma) fElementType = "cubes";
33  TPZGeoEl *gel = ce->Reference();
34  if( type == EDiscontinuous || (type == EAgglomerate && gel) ){
35  int nnodes = gel->NNodes();
36  if(nnodes==4 && dimension==2) fElementType = "quads";
37  if(nnodes==3 && dimension==2) fElementType = "triangles";
38  if(dimension==3) fElementType = "cubes";
39  }
40  }
41  fNumCases = 0;
42  fNumConnectObjects[0] = 1;
43  fNumConnectObjects[1] = 1;
44  fNumConnectObjects[2] = 1;
45  fNormalObject = 0;
46 
47  for(int i = 0; i < 8; i++) fElConnectivityObject[i] = -1;
48 
49 }
50 
52 TPZGraphMesh(cmesh,dim,graph->fMaterialIds,graph->ScalarNames(),graph->VecNames()) {
54  fStyle = EDXStyle;
55  fElementType = "noname";
56  fElementType[0] = '\0';
57  fElementType = graph->fElementType;
58  fNumCases = graph->fNumCases;
59  int i;
60  for(i=0;i<3;i++) {
61  fNumConnectObjects[i] = 1;
62  fFirstFieldValues[i] = graph->fFirstFieldValues[i];
63  }
64  for(;i<8;i++) fNumConnectObjects[i] = 0;
65  fTimes = graph->fTimes;
66  fFileName = graph->fFileName;
68  graph->fOutFile.close();
70  fOutFile.open(fFileName.c_str());
71 
72  for(int i = 0; i < 8; i++) fElConnectivityObject[i] = -1;
73 
74 }
75 
77  Close();
78 }
79 
81  if(fElementType == "noname") return 0;
82  if(fElementType == "lines") return 2;
83  if(fElementType == "triangles") return 3;
84  if(fElementType == "quads") return 4;
85  if(fElementType == "cubes") return 8;
86  return -1;
87 }
88 
90  return fElementType;
91 }
92 
93 void TPZDXGraphMesh::DrawMesh(int numcases) {
94 
95  std::set<int> matids = MaterialIds();
96  if(matids.size() == 0) {
97  cout << "TPZMVGraphMesh no material found\n";
98  return;
99  }
100  set<int>::iterator iter = matids.begin();
101  TPZMaterial * matp = fCompMesh->FindMaterial(*iter);
102  int dim = matp->Dimension();
103  int dim1 = dim-1;
105  int firsttype[4] = {1,2,4,0}, lasttype[4] = {2,4,5,0};
106  int numnod[] = {0,2,4,3,8};
107  std::string elname[] = {"noname","lines","quads","triangles","cubes"};
108  int object = fNextDataField;
109  fNodePosObject[dim1] = object;
110  int64_t nn = NPoints();
111 
112  //field nodes / positions
113  (fOutFile) << "object " << object << " class array type float rank 1 shape 3 items "
114  << nn << " data follows"<< endl;
115  DrawNodes();
116  (fOutFile) << "attribute \"dep\" string \"positions\"" << endl;
117  (fOutFile) << "#" << endl;
118  object++;
119 
120  fNormalObject = -1;
121 
122  // field connectivity
123  int it;
124  for(it=firsttype[dim1]; it<lasttype[dim1]; it++) {
125  MElementType type = eltypes[it];
126  int64_t nel = NElements(type);
127  if(nel) {
128 
129  fElConnectivityObject[type] = object;
130  (fOutFile) << "object " << object << " class array type int rank 1 shape "
131  << numnod[it];
132  (fOutFile) << " items "
133  << NElements(type) << " data follows"<<endl;
134  object++;
135  DrawConnectivity(type);
136 
137  (fOutFile) << "attribute \"element type\" string ";
138  (fOutFile) << "\"" << elname[it] << "\"" << endl;
139  (fOutFile) << "attribute \"ref\" string \"positions\"" << endl;
140  (fOutFile) << "#" << endl;
141  } else {
142  fElConnectivityObject[type] = 0;
143  }
144  }
145  fNumCases = numcases;
146  fNextDataField = object;
147 }
148 
149 void TPZDXGraphMesh::DrawSolution(int step, REAL time) {
150 
151  std::set<int> matids = MaterialIds();
152  if(matids.size() == 0) {
153  cout << "TPZMVGraphMesh no material found\n";
154  return;
155  }
156  set<int>::iterator iter = matids.begin();
157  TPZMaterial * matp = fCompMesh->FindMaterial(*iter);
158  int64_t i,nel;
159  if(!matp) return;
160  int dim = matp->Dimension();
161  int dim1 = dim-1;
162 
163  int numscal = fScalarNames.NElements();
164  int numvec = fVecNames.NElements();
165  TPZVec<int> scalind(0);
166  TPZVec<int> vecind(0);
167  scalind.Resize(numscal);
168  vecind.Resize(numvec);
169  scalind.Fill(-1);
170  vecind.Fill(-1);
171  int n;
172  for(n=0; n<numscal; n++) {
173  scalind[n] = matp->VariableIndex( fScalarNames[n]);
174  }
175  for(n=0; n<numvec; n++) {
176  vecind[n] = matp->VariableIndex( fVecNames[n]);
177  }
179  fTimes.Push(time);
180  cout << "TPZDXGraphMesh.DrawSolution step = " << step << " time = " << time << endl;
181  int64_t numpoints = NPoints();
182  TPZVec<int> scal(1);
183  for(n=0; n<numscal; n++) {
184  (fOutFile) << "object " << fNextDataField << " class array type float rank 0 items "
185  << numpoints << " data follows " << endl;
186  scal[0] = scalind[n];
187  nel = fNodeMap.NElements();
188  for(i=0;i<nel;i++) {
189  TPZGraphNode *np = &fNodeMap[i];
190  if(np) np->DrawSolution(scal, fStyle);
191  }
192  (fOutFile) << "attribute \"dep\" string \"positions\"" << endl;
193  (fOutFile) << "#" << endl;
194  fNextDataField ++;
195 
196 
197  //+++++ Cubes
198  if(dim == 3 && (NNodes() == 8 || NNodes() == 6)) {
199  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
200  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
201  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
202  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[ECube] << endl;
203  (fOutFile) << "attribute \"name\" string \"" << (std::string) fScalarNames[n]
204  << step << (0) << "\"" << endl;
205  (fOutFile) << "#" << endl;
206  fNextDataField ++;
207  }
208 
209  if(dim == 2 && (NNodes() == 4 || NNodes() == 3)) {
210  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
211  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
212  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
213  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[EQuadrilateral] << endl;
214  (fOutFile) << "attribute \"name\" string \"" << (std::string) fScalarNames[n]; (fOutFile).flush();
215  (fOutFile) << step; (fOutFile).flush();
216  (fOutFile) << (0); (fOutFile).flush();
217  (fOutFile) << "\""; (fOutFile).flush();
218  (fOutFile) << endl; (fOutFile).flush();
219  (fOutFile) << "#" << endl; (fOutFile).flush();
220  fNextDataField ++;
221  }
222  if(dim == 1) {
223  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
224  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
225  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
226  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[EOned] << endl;
227  if(fNormalObject > 0) (fOutFile) << "component \"normals\" value " << fNormalObject << endl;
228  (fOutFile) << "attribute \"name\" string \"" << (std::string) fScalarNames[n]
229  << step << (0) << "\"" << endl;
230  (fOutFile) << "#" << endl;
231  fNextDataField ++;
232  }
233  }
234  TPZVec<int> vec(1);
235  for(n=0; n<numvec; n++) {
236  (fOutFile) << "object " << fNextDataField << " class array type float rank 1 shape " <<
237  matp->NSolutionVariables(vecind[n]) << " items "
238  << numpoints << " data follows " << endl;
239  vec[0] = vecind[n];
240  nel = fNodeMap.NElements();
241  for(i=0;i<nel;i++) {
242  TPZGraphNode *np = &fNodeMap[i];
243  if(np) np->DrawSolution(vec, fStyle);
244  }
245  (fOutFile) << "attribute \"dep\" string \"positions\"" << endl;
246  (fOutFile) << "#" << endl;
247  fNextDataField ++;
248  //+++++ Cubes
249  if(dim == 3 && fElConnectivityObject[ECube]) {
250  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
251  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
252  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
253  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[ECube] << endl;
254  (fOutFile) << "attribute \"name\" string \"" << (std::string) fVecNames[n]
255  << step << (0) << "\"" << endl;
256  (fOutFile) << "#" << endl;
257  fNextDataField ++;
258  }
259  //|\|\|\|\|\|\|\|\|\|\|
260  if(dim == 2 && fElConnectivityObject[EQuadrilateral]) {
261  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
262  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
263  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
264  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[EQuadrilateral] << endl;
265  (fOutFile) << "attribute \"name\" string \"" << (std::string) fVecNames[n]
266  << step << (0) << "\"" << endl;
267  (fOutFile) << "#" << endl;
268  fNextDataField ++;
269  }
270  if(dim == 2 && fElConnectivityObject[ETriangle]) {
271  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
272  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
273  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
274  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[ETriangle] << endl;
275  (fOutFile) << "attribute \"name\" string \"" << (std::string) fVecNames[n]
276  << step << (1) << "\"" << endl;
277  (fOutFile) << "#" << endl;
278  fNextDataField ++;
279  }
280  if(dim == 1) {
281  (fOutFile) << "object " << (fNextDataField) << " class field" << endl;
282  (fOutFile) << "component \"data\" value " << (fNextDataField-1) << endl;
283  (fOutFile) << "component \"positions\" value " << fNodePosObject[dim1] << endl;
284  (fOutFile) << "component \"connections\" value " << fElConnectivityObject[EOned] << endl;
285  (fOutFile) << "attribute \"name\" string \"" << (std::string) fVecNames[n]
286  << step << (0) << "\"" << endl;
287  (fOutFile) << "#" << endl;
288  fNextDataField ++;
289  }
290  }
291 }
292 
293 
295 
296  int n;
297  int dim = fDimension;
298  int dim1 = dim-1;
300  int numscal = fScalarNames.NElements();
301  int numvec = fVecNames.NElements();
302  int ist;
303  TPZStack<int> &FVR = fFirstFieldValues[dim1];
304  cout << "DxMesh finalizing\n";
305  for(n=0; n<numscal; n++) {
306  (fOutFile) << "object \"" << fScalarNames[n] << "\" class series" << endl;
307  for(ist =0; ist<fNumCases; ist++) {
308  int icon;
309  for(icon=0; icon< fNumConnectObjects[dim1]; icon++) {
310  int64_t FVRval = FVR[ist]+icon;
311  (fOutFile) << "member " << ist << " position " << (fTimes)[ist]
312  << " value " << FVRval << endl;
313  }
314  fFirstFieldValues[dim1][ist] += 1+fNumConnectObjects[dim1];
315  }
316  (fOutFile) << "#" << endl;
317  }
318  for(n=0; n<numvec; n++) {
319  (fOutFile) << "object \"" << fVecNames[n] << "\" class series" << endl;
320  for(ist =0; ist<fNumCases; ist++) {
321  int icon;
322  for(icon=0; icon< fNumConnectObjects[dim1]; icon++) {
323  int64_t FVRval = FVR[ist]+icon;
324  (fOutFile) << "member " << ist << " position " << (fTimes)[ist]
325  << " value " << FVRval << endl;
326  }
327  fFirstFieldValues[dim1][ist] += 1+fNumConnectObjects[dim1];
328  }
329  (fOutFile) << "#" << endl;
330  }
331  (fOutFile) << "object \"ALL\" class group\n";
332  for(n=0; n<numscal; n++) {
333  (fOutFile) << "member \"" << fScalarNames[n] << "\" value \"" << fScalarNames[n] << '\"' << endl;
334  }
335  for(n=0; n<numvec; n++) {
336  (fOutFile) << "member \"" << fVecNames[n] << "\" value \"" << fVecNames[n] << '\"' << endl;
337  }
338  (fOutFile) << "end\n";
339  fNumCases = 0;
340  fNumConnectObjects[0] = 1;
341  fNumConnectObjects[1] = 1;
342  fNumConnectObjects[2] = 1;
343  fNormalObject = 0;
344  fTimes.Resize(0);
348  fNextDataField = 1;
349 
350 }
351 
352 
354 {
355  std::set<int> matids = MaterialIds();
356  if(matids.size() == 0) {
357  cout << "TPZMVGraphMesh no material found\n";
358  return;
359  }
360  set<int>::iterator iter = matids.begin();
361  TPZMaterial * matp = fCompMesh->FindMaterial(*iter);
362  int64_t i,varind;
363  varind = matp->VariableIndex(var);
364  TPZVec<int> vec(1);
365  (fOutFile) << "object " << fNextDataField << " class array type float rank 1 shape " <<
366  matp->NSolutionVariables(varind) << " items " << NPoints() << " data follows " << endl;
367  vec[0] = varind;
368  int64_t nel = fCompMesh->ConnectVec().NElements();
369  for(i=0;i<nel;i++) {
370  TPZGraphNode n = fNodeMap[i];
371  n.DrawSolution(vec,fStyle);
372  }
373  (fOutFile) << "attribute \"dep\" string \"positions\"" << endl;
374  (fOutFile) << "#" << endl;
375  (fOutFile) << "object " << (fNextDataField+1) << " class field" << endl;
376  (fOutFile) << "component \"data\" value " << fNextDataField << endl;
377  (fOutFile) << "attribute \"name\" string \"" << var << fNextDataField <<
378  "\"" << endl;
379  (fOutFile) << "#" << endl;
380  fNextDataField += 2;
381 
382 }
383 
385 {
386  /*
387  Pix i = fCompMesh->MaterialVec().first();
388  TPZMaterial *matp = (TPZMaterial *) fCompMesh->MaterialVec().contents(i);
389  (fOutFile) << "object " << fNextDataField << " class array type float rank 1 shape " <<
390  matp->NumVariables() << " items "
391  << NPoints() << " data follows " << endl;
392  i = fConnectVec.first();
393  while(i) {
394  TGraphNode *n = (TGraphNode *) fConnectVec.contents(i);
395  n->DrawSolution(bl,fStyle);
396  fConnectVec.next(i);
397  }
398  (fOutFile) << "attribute \"dep\" string \"positions\"" << endl;
399  (fOutFile) << "#" << endl;
400  (fOutFile) << "object " << (fNextDataField+1) << " class field" << endl;
401  (fOutFile) << "component \"data\" value " << fNextDataField << endl;
402  (fOutFile) << "component \"positions\" value " << fNodeCoField << endl;
403  (fOutFile) << "component \"connections\" value " << fConnectField << endl;
404  (fOutFile) << "attribute \"name\" string \"" << fNextDataField <<
405  "\"" << endl;
406  (fOutFile) << "#" << endl;
407  fNextDataField += 2;
408  */
409 }
410 
411 void TPZDXGraphMesh::DrawNormals(int numnorm) {
412  int i;
413  for(i=0; i<numnorm; i++) {
414  (fOutFile) << "0. 1. 0." << endl;
415  }
416 }
417 
418 void TPZDXGraphMesh::SetFileName(const std::string &filename)
419 {
420  TPZGraphMesh::SetFileName(filename);
421  fOutFile.open(filename.c_str());
422 }
423 
Represents a graphical mesh used for post processing purposes. Post processing.
Definition: pzgraphmesh.h:34
virtual void SetFileName(const std::string &filename)
Sets the name of the output file.
Definition: pzdxmesh.cpp:418
filename
Definition: stats.py:82
int fNormalObject
Definition: pzdxmesh.h:23
virtual MElementType Type()
Return the type of the element.
Definition: pzcompel.cpp:195
TPZVec< std::string > fScalarNames
Vectors of the variables names (scalar, vectorial, and tensorial)
Definition: pzgraphmesh.h:127
void DrawSolution(int solutionid, TPZDrawStyle st=EDXStyle)
Draw solution on the current connect for solutionid variable.
Definition: pzgraphnode.cpp:89
Implements the interface of the graphmesh to the OpenDX graphics package. Post processing.
Definition: pzdxmesh.h:17
clarg::argInt dimension("-d", "Matrices dimension M x M", 1000)
virtual void DrawConnectivity(MElementType type)
Draw the connectivity information.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
std::string fFileName
Definition: pzgraphmesh.h:125
TPZVec< std::string > VecNames()
Return vectorial variable names.
Definition: pzgraphmesh.h:146
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
virtual int Dimension() const =0
Returns the integrable dimension of the material.
Contains the TPZGraphEl class which implements the graphical one-, two- and three-dimensional element...
Contains the TPZGraphNode class which implements the graphical node.
int64_t NElements() const
Access method to query the number of elements of the vector.
TPZCompEl * FindFirstInterpolatedElement(TPZCompMesh *mesh, int dimension)
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
std::set< int > MaterialIds()
Get material ids.
std::string fElementType
Definition: pzdxmesh.h:27
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
virtual void DrawNodes()
Draw the graphical nodes information.
int fNextDataField
Definition: pzdxmesh.h:19
Definition: TPZDrawStyle.h:12
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
TPZStack< int > fFirstFieldValues[3]
Definition: pzdxmesh.h:25
int fDimension
Dimension of the graphical mesh.
Definition: pzgraphmesh.h:115
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
virtual ~TPZDXGraphMesh()
Default destructor.
Definition: pzdxmesh.cpp:76
virtual void DrawSolution(TPZBlock< REAL > &Sol)
Draw solution as dx file.
Definition: pzdxmesh.cpp:384
TPZDrawStyle fStyle
Style of the graphical file.
Definition: pzgraphmesh.h:123
void DrawNormals(int numnormals)
Definition: pzdxmesh.cpp:411
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
Contains TPZMatrixclass which implements full matrix (using column major representation).
int fNumConnectObjects[8]
Definition: pzdxmesh.h:20
TPZMaterial * FindMaterial(int id)
Find the material with identity id.
Definition: pzcmesh.cpp:297
Contains the TPZGraphElT class which implements the graphical triangular element. ...
int fElConnectivityObject[8]
Definition: pzdxmesh.h:21
TPZVec< std::string > fVecNames
Definition: pzgraphmesh.h:127
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...
std::ofstream fOutFile
Definition: pzgraphmesh.h:124
virtual void DrawMesh(int numcases)
Draw mesh as dx file.
Definition: pzdxmesh.cpp:93
virtual void SetFileName(const std::string &filename)
Sets the filename to output of graph.
virtual int NNodes() const =0
Returns the number of nodes of the element.
TPZAdmChunkVector< TPZGraphNode > fNodeMap
Vector of graphical nodes (connects)
Definition: pzgraphmesh.h:119
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
virtual int NSolutionVariables(int var)
Returns the number of variables associated with the variable indexed by var.
Implements block matrices. Matrix utility.
MElementType
Define the element types.
Definition: pzeltype.h:52
TPZVec< std::string > ScalarNames()
Return scalar variable names.
Definition: pzgraphmesh.h:140
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
Definition: pzeltype.h:61
int NNodes()
Number of nodes.
Definition: pzdxmesh.cpp:80
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
int64_t NElements(MElementType type)
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
TPZCompMesh * fCompMesh
Computational mesh associated.
Definition: pzgraphmesh.h:109
int fNodePosObject[8]
Definition: pzdxmesh.h:22
std::set< int > fMaterialIds
Set of material ids being post-processed.
Definition: pzgraphmesh.h:113
Contains the TPZDXGraphMesh class which implements the interface of the graphmesh to the OpenDX graph...
Definition: pzeltype.h:55
int64_t NPoints()
Number of points to drawing, depending on the resolution.
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
To export a graphical node. Post processing.
Definition: pzgraphnode.h:24
TPZStack< REAL > fTimes
Definition: pzdxmesh.h:24
TPZDXGraphMesh(TPZCompMesh *mesh, int dimension, const std::set< int > &matids, const TPZVec< std::string > &scalarnames, const TPZVec< std::string > &vecnames)
Constructor for output in DX format.
Definition: pzdxmesh.cpp:19
std::string ElementName()
Definition: pzdxmesh.cpp:89