NeoPZ
pzvtkmesh.cpp
Go to the documentation of this file.
1 
6 #include <sstream>
7 #include "pzvtkmesh.h"
8 #include "pzcmesh.h"
9 #include "TPZMaterial.h"
10 #include "pzgraphnode.h"
11 #include "pzgraphel.h"
12 
13 using namespace std;
14 
15 
17 TPZGraphMesh(cmesh, dimension, graph->fMaterialIds, graph->ScalarNames(),graph->VecNames(), graph->TensorNames()) {
18  fNumCases = graph->fNumCases;
19  fNumSteps = graph->fNumSteps;
20  fStyle = EVTKStyle;
21 }
22 
23 TPZVTKGraphMesh::TPZVTKGraphMesh(TPZCompMesh *cmesh, int dimension, const std::set<int> & matids, const TPZVec<std::string> &scalnames, const TPZVec<std::string> &vecnames, const TPZVec<std::string> &tensnames): TPZGraphMesh(cmesh, dimension, matids,scalnames,vecnames,tensnames) {
24  fNumCases = 0;
25  fNumSteps = 0;
26  fStyle = EVTKStyle;
27  fVecNames = vecnames;
28  fScalarNames = scalnames;
29  fTensorNames = tensnames;
30 }
31 
32 void TPZVTKGraphMesh::DrawMesh(int numcases) {
33 
34  fNumCases = numcases;
35  fNumSteps = 0;
36 }
37 
38 void TPZVTKGraphMesh::DrawSolution(int step, REAL time){
39 
40  std::set<int> matid = MaterialIds();
41  std::set<int> matids = MaterialIds();
42  if(matids.size() == 0) {
43  cout << "TPZMVGraphMesh no material found\n";
44  return;
45  }
46  set<int>::iterator it = matids.begin();
47  TPZMaterial * matp = fCompMesh->FindMaterial(*it);
48  if(fOutFile.is_open())
49  {
50  fOutFile.close();
51  }
52  int n;
53  {
54  std::stringstream sout;
55  sout << fFileName.substr(0,fFileName.size()-4) << ".scal_vec." << step << ".vtk";
56  fOutFile.open(sout.str().c_str());
57  }
58  (fOutFile) << "# vtk DataFile Version 3.0" << endl;
59  (fOutFile) << "Arquivo gerado por PZ" << endl;
60  (fOutFile) << "ASCII\n" << endl;
61  (fOutFile) << "DATASET UNSTRUCTURED_GRID" << endl;
62  DrawNodes();
64  int numscal = fScalarNames.NElements();
65  int numvec = fVecNames.NElements();
66  int numtens = fTensorNames.NElements();
67  if(numscal || numvec)(fOutFile) << "POINT_DATA " << NPoints() << endl;
68  if(numscal)
69  {
70  TPZManVector<int> scalind(0);
71  scalind.Fill(-1,0,numscal);
72  scalind.Resize(numscal);
73  for(n=0; n<numscal; n++) {
74  scalind[n] = matp->VariableIndex( fScalarNames[n]);
75  if (scalind[n] == -1) {
76  std::cout << fScalarNames[n] << " not recognized as post processing name\n";
77  }
78  }
79  for(n=0; n<numscal; n++)
80  {
81  if (scalind[n] != -1)
82  {
83  (fOutFile) << "SCALARS " << fScalarNames[n] << " float" << endl << "LOOKUP_TABLE default\n";
84  int64_t nnod = fNodeMap.NElements(),i;
85  for(i=0;i<nnod;i++) {
86  TPZGraphNode *node = &fNodeMap[i];
87  if(node) node->DrawSolution(scalind[n], EVTKStyle);
88  }
89  (fOutFile) << std::endl;
90  }
91  }
92  }
93  if(numvec)
94  {
95  TPZManVector<int> vecind(0);
96  vecind.Resize(numvec);
97  vecind.Fill(-1,0,numvec);
98  for(n=0; n<numvec; n++) {
99  vecind[n] = matp->VariableIndex(fVecNames[n]);
100  if(vecind[n] == -1)
101  {
102  std::cout << "Post processing vector name " << fVecNames[n] << " not found\n";
103 
104  }
105  }
106  for(n=0; n<numvec; n++)
107  {
108  if(vecind[n] != -1)
109  {
110  (fOutFile) << "VECTORS " << fVecNames[n] << " float" << std::endl;
111  int64_t nnod = fNodeMap.NElements(), i;
112  for(i=0;i<nnod;i++) {
113  TPZGraphNode *node = &fNodeMap[i];
114  if(node) node->DrawSolution(vecind[n], EVTKStyle);
115  }
116  (fOutFile) << std::endl;
117  }
118  }
119  }
120  if(numtens)
121  {
122  TPZVec<int> tensind(0);
123  tensind.Resize(numtens);
124  tensind.Fill(-1,0,numtens);
125  for(n=0; n<numtens; n++) {
126  tensind[n] = matp->VariableIndex(fTensorNames[n]);
127  if(tensind[n] == -1)
128  {
129  std::cout << "Post processing name " << fTensorNames[n] << " not found\n";
130  DebugStop();
131  }
132  }
133  for(n=0; n<numtens; n++)
134  {
135  (fOutFile) << "TENSORS " << fTensorNames[n] << " float" << std::endl;
136  int64_t nnod = fNodeMap.NElements(), i;
137  for(i=0;i<nnod;i++) {
138  TPZGraphNode *node = &fNodeMap[i];
139  if(node) node->DrawSolution(tensind[n], EVTKStyle);
140  }
141  (fOutFile) << std::endl;
142  }
143  }
144  fOutFile.close();
145  fNumSteps++;
146 }
147 
148 
151 }
152 
154 
155  int64_t nn = 0L;
156  int64_t nnod = fNodeMap.NElements();
157  int64_t i;
158  for(i=0;i<nnod;i++) {
159  TPZGraphNode *n = &fNodeMap[i];
160  if(n) nn += n->NPoints();
161  }
162  (fOutFile) << "POINTS ";
163  (fOutFile) << nn << " float" << endl;
164 
165  for(i=0;i<nnod;i++) {
166  TPZGraphNode *n = &fNodeMap[i];
167  if(n) n->DrawCo(EVTKStyle);
168  }
169 }
170 
172 
173  int64_t nel = fElementList.NElements();
174  if(!nel) return;
175  TPZGraphEl *el = (TPZGraphEl *) fElementList[0];
176  (fOutFile) << std::endl;
177  (fOutFile) << "CELLS ";
178  int64_t nelem = 0;
179  int64_t nint = 0;
180  int64_t i;
181  for(i=0;i<nel;i++) {
182  el = (TPZGraphEl *) fElementList[i];
183  if(el)
184  {
185  nelem += el->NElements();
186  nint += (el->NNodes() + 1) * el->NElements();
187  }
188  }
189  (fOutFile) << nelem << " " << nint << std::endl;
190  for(i=0;i<nel;i++) {
191  el = (TPZGraphEl *) fElementList[i];
192  if(el) el->Connectivity(EVTKStyle);
193  }
194  (fOutFile) << std::endl;
195  (fOutFile) << "CELL_TYPES " << nelem << std::endl;
196  for(i=0;i<nel;i++) {
197  el = (TPZGraphEl *) fElementList[i];
198  if(el)
199  {
200  int64_t j, nElPerEl = el->NElements();
201  for(j = 0; j < nElPerEl; j++)(fOutFile) << el->ExportType(EVTKStyle) << std::endl;
202  }
203  }
204  (fOutFile) << std::endl;
205 }
206 
208  cout << "TPZMVGraphMesh::DrawSolution not Implemented\n";
209 }
210 
211 void TPZVTKGraphMesh::DrawSolution(char * /*var = 0*/) {
212  cout << "TPZMVGraphMesh::DrawSolution not Implemented\n";
213 }
Represents a graphical mesh used for post processing purposes. Post processing.
Definition: pzgraphmesh.h:34
TPZVTKGraphMesh(TPZCompMesh *cmesh, int dimension, const std::set< int > &matids, const TPZVec< std::string > &scalnames, const TPZVec< std::string > &vecnames, const TPZVec< std::string > &tensnames)
Constructor for graphical mesh using VTK format with tensor variables.
Definition: pzvtkmesh.cpp:23
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
virtual void DrawConnectivity(MElementType type)
Draw the connectivity information.
Definition: pzvtkmesh.cpp:171
clarg::argInt dimension("-d", "Matrices dimension M x M", 1000)
Contains the TPZVTKGraphMesh class which implements the graphical mesh to VTK environment.
std::string fFileName
Definition: pzgraphmesh.h:125
virtual int VariableIndex(const std::string &name)
Returns the variable index associated with the name.
To export a graphical mesh to VTK environment. Post processing.
Definition: pzvtkmesh.h:19
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.
virtual void DrawNodes()
Draw the graphical nodes information.
Definition: pzvtkmesh.cpp:153
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
virtual int NElements()=0
std::set< int > MaterialIds()
Get material ids.
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
virtual void SequenceNodes()
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
TPZDrawStyle fStyle
Style of the graphical file.
Definition: pzgraphmesh.h:123
virtual int NNodes()=0
Number of corner nodes (geometric information)
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Definition: TPZDrawStyle.h:12
TPZMaterial * FindMaterial(int id)
Find the material with identity id.
Definition: pzcmesh.cpp:297
TPZVec< std::string > fVecNames
Definition: pzgraphmesh.h:127
Contains declaration of TPZCompMesh class which is a repository for computational elements...
std::ofstream fOutFile
Definition: pzgraphmesh.h:124
virtual void SequenceNodes()
Definition: pzvtkmesh.cpp:149
virtual void Connectivity(TPZDrawStyle st=EDXStyle)=0
Set dx style for connectivity information.
virtual void DrawSolution(int step, REAL time)
Draw solution depending on the resolution.
Definition: pzvtkmesh.cpp:38
virtual void DrawMesh(int numcases)
Draw the graphical mesh.
Definition: pzvtkmesh.cpp:32
TPZAdmChunkVector< TPZGraphNode > fNodeMap
Vector of graphical nodes (connects)
Definition: pzgraphmesh.h:119
void DrawCo(TPZDrawStyle st=EDXStyle)
Draw coordinates of the graphical node.
Definition: pzgraphnode.cpp:84
Implements block matrices. Matrix utility.
MElementType
Define the element types.
Definition: pzeltype.h:52
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
Definition: pzeltype.h:61
virtual int ExportType(TPZDrawStyle st)=0
Sets the style to export (format)
TPZVec< std::string > fTensorNames
Definition: pzgraphmesh.h:127
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
Abstract class to graphical one-, two- and three-dimensional element. Post processing.
Definition: pzgraphel.h:23
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
int64_t NPoints()
Number of points to drawing, depending on the resolution.
To export a graphical node. Post processing.
Definition: pzgraphnode.h:24
TPZAdmChunkVector< TPZGraphEl * > fElementList
Vector of graphical elements.
Definition: pzgraphmesh.h:117