NeoPZ
pzgraphmesh.cpp
Go to the documentation of this file.
1 
6 #include "pzgraphmesh.h"
7 #include "pzcmesh.h"
8 #include "pzsubcmesh.h"
9 #include "pzintel.h"
10 #include "pzgmesh.h"
11 #include "pzcompel.h"
12 #include "pzgeoel.h"
13 #include "pzgraphel.h"
14 #include "pztrigraph.h"
15 #include "pzgraphnode.h"
16 #include "TPZMaterial.h"
17 #include "TPZCompElDisc.h"
18 
19 #ifndef STATE_COMPLEX
20  #include "TPZAgglomerateEl.h"
21 #endif
22 
23 using namespace std;
24 
25 TPZGraphMesh::TPZGraphMesh(TPZCompMesh *cm, int dimension, const std::set<int> & matids, const TPZVec<std::string> &scalarnames, const TPZVec<std::string> &vecnames) :
26  fCompMesh(cm), fDimension(dimension), fMaterialIds(matids), fScalarNames(scalarnames), fVecNames(vecnames), fTensorNames()
27 {
28  int64_t nel,i;
31  fNodeMap.Resize(0);
33 
35  TPZCompEl *ce;
36  nel = celvec.NElements();
37  for(i=0;i<nel;i++) {
38  ce = (TPZCompEl *) celvec[i];
39  if(!ce) continue;
40  ce->CreateGraphicalElement(*this, dimension);
41  }
42 
43 }
44 
45 TPZGraphMesh::TPZGraphMesh(TPZCompMesh *cm, int dimension, const std::set<int> & matids, const TPZVec<std::string> &scalarnames, const TPZVec<std::string> &vecnames, const TPZVec<std::string> &tensornames) :
46 fCompMesh(cm), fDimension(dimension), fMaterialIds(matids), fScalarNames(scalarnames), fVecNames(vecnames), fTensorNames(tensornames)
47 {
48  int64_t nel,i;
51  fNodeMap.Resize(0);
53 
55  TPZCompEl *ce;
56  nel = celvec.NElements();
57  for(i=0;i<nel;i++) {
58  ce = (TPZCompEl *) celvec[i];
59  if(!ce) continue;
60  ce->CreateGraphicalElement(*this, dimension);
61  }
62 
63 }
64 
66 {
67  int64_t nel = fElementList.NElements();
68  TPZGraphEl *el;
69  for(int64_t i=0;i<nel;i++) {
70  el = fElementList[i];
71  if(!el) continue;
72  if(el) delete el;
73  }
74 }
75 
77 
79 {
80 
81  int64_t nnod = fNodeMap.NElements();
82  for(int64_t index=0;index<nnod;index++) {
83  TPZGraphNode *node = &fNodeMap[index];
84  if(node && node->SequenceNumber() != -1 && node->SequenceNumber()==sid) return fNodeMap[index];
85  }
86  return gn;
87 }
88 
90 {
91  int64_t nelem = fElementList.NElements();
92  if(sid > nelem-1) {
93  cout << "TPZGraphMesh::FindNode, sid out of range sid = " << sid << endl;
94  return 0;
95  }
96  for(int64_t index=0;index<nelem;index++) {
97  TPZGraphEl *el = fElementList[index];
98  if(el && el->Id()==sid) return fElementList[index];
99  }
100  return NULL;
101 }
102 
103 
105 
107  if(!list) {
108  list->Resize(0);
109  }
110  return fElementList;
111 }
112 
114  return fNodeMap;
115 }
116 
118 
119  int64_t nnod = fNodeMap.NElements();
120  int64_t seq = 0;
121  for(int64_t i=0;i<nnod;i++) {
122  TPZGraphNode *n = &fNodeMap[i];
123  if(n) {
124  int numnod = n->NPoints();
125  n->SetPointNumber(seq);
126  seq += numnod;
127  }
128  }
129  int64_t el, nelem = fElementList.NElements();
130  int64_t firstel=0;
131  for(el=0; el<nelem; el++) {
132  TPZGraphEl *grel = fElementList[el];
133  if(!grel) continue;
134  grel->SetId(firstel);
135  firstel += grel->NElements();
136  }
137 }
138 
139 void TPZGraphMesh::SetFileName(const std::string &filename)
140 {
142  if(fOutFile.is_open())
143  {
144  fOutFile.close();
145  }
146 }
147 
149 {
150  int64_t nnod = fNodeMap.NElements();
151  for(int64_t i=0;i<nnod;i++) {
152  TPZGraphNode *n = &fNodeMap[i];
153  if(n) n->DrawCo(fStyle);
154  }
155 }
156 
157 void TPZGraphMesh::DrawMesh(int /*numcases*/){
158 }
159 
160 void TPZGraphMesh::DrawSolution(int /*step*/, REAL /*time*/){
161  cout << "TPZGraphMesh::DrawSolution called\n";
162 }
163 
165 {
168  if(!list) return;
169  int64_t nel = fElementList.NElements();
170  TPZGraphEl *e;
171  for(int64_t i=0;i<nel;i++) {
172  e = (TPZGraphEl *) fElementList[i];
173  if(e && e->Type() == type) e->Connectivity(fStyle);
174  }
175 }
176 
178  int64_t nn = 0;
179  int64_t i;
180  int64_t nnod = fNodeMap.NElements();
181  for(i=0;i<nnod;i++) {
182  TPZGraphNode *n = &fNodeMap[i];
183  if(n) nn += n->NPoints();
184  }
185  return nn;
186 }
187 
189 
190  int64_t numel = 0;
191  int64_t nel = fElementList.NElements();
192  for(int64_t j=0;j<nel;j++) {
193  TPZGraphEl *el = (TPZGraphEl *) fElementList[j];
194  if(el->Type() == type) numel += el->NElements();
195  }
196  return numel;
197 }
198 
199 void TPZGraphMesh::Print(ostream &out) {
200 
201  int64_t i;
202  int64_t nnod = fNodeMap.NElements();
203  for(i=0;i<nnod;i++) {
204  TPZGraphNode *nod = &fNodeMap[i];
205  if(nod) nod->Print(out);
206  }
207  int64_t nel = fElementList.NElements();
208  for(i=0;i<nel;i++) {
209  TPZGraphEl *el = (TPZGraphEl *) fElementList[i];
210  if(el) el->Print(out);
211  }
212 }
213 
214 void TPZGraphMesh::SetNames(const TPZVec<std::string>&scalarnames, const TPZVec<std::string>&vecnames) {
215  fScalarNames = scalarnames;
216  fVecNames = vecnames;
217  fTensorNames.resize(0);
218 }
219 
220 void TPZGraphMesh::SetNames(const TPZVec<std::string>&scalarnames, const TPZVec<std::string>&vecnames, const TPZVec<std::string>& tensornames) {
221  fScalarNames = scalarnames;
222  fVecNames = vecnames;
223  fTensorNames = tensornames;
224 }
225 
226 
227 void TPZGraphMesh::SetMaterialIds(const std::set<int> & matids){
228  SetCompMesh(fCompMesh, matids);
229 }
230 
232  return fMaterialIds;
233 }
234 
236  return fMaterialIds.find(matid) != fMaterialIds.end();
237 }
238 
239 void TPZGraphMesh::SetCompMesh(TPZCompMesh *mesh, const std::set<int> & matids){
240  if(fCompMesh == mesh && matids == fMaterialIds) return;
241  int64_t i;
242  fCompMesh = mesh;
243  fMaterialIds = matids;
244  int64_t nel = fElementList.NElements();
245  TPZGraphEl *el;
246  for(i=0;i<nel;i++) {
247  el = fElementList[i];
248  if(!el) continue;
249  if(el) delete el;
250  }
251  fElementList.Resize(0);
252  fNodeMap.Resize(0);
254  TPZCompEl *ce;
255  nel = celvec.NElements();
256  for(i=0;i<nel;i++) {
257  ce = (TPZCompEl *) celvec[i];
258  if(ce) ce->CreateGraphicalElement(*this, fDimension);
259  }
260 }
261 
263  int64_t nel = mesh->NElements();
264  TPZCompEl *cel;
265  int64_t iel;
266  for(iel=0; iel<nel; iel++) {
267  cel = mesh->ElementVec()[iel];
268  if(!cel) continue;
269  int type = cel->Type();
270  if(type == EAgglomerate){
271 #ifndef STATE_COMPLEX
272  if(!cel->Reference()) continue;
273  TPZAgglomerateElement *agg = dynamic_cast<TPZAgglomerateElement *>(cel);
274  if(agg && agg->Dimension() == dim) return agg;
275 #else
276  DebugStop();
277 #endif
278  }
279  if(type == EDiscontinuous){
280  TPZCompElDisc *disc = dynamic_cast<TPZCompElDisc *>(cel);
281  if(disc && disc->Reference()->Dimension() == dim) return disc;
282  }
283  TPZCompEl *intel = dynamic_cast<TPZInterpolatedElement *>(cel);
284  if(intel && intel->Reference()->Dimension() == dim) return intel;
285  TPZSubCompMesh *subcmesh = dynamic_cast<TPZSubCompMesh *> (cel);
286  if(subcmesh) {
287  intel = FindFirstInterpolatedElement(subcmesh,dim);
288  if(intel) return intel;
289  }
290  }
291  return 0;
292 }
293 
295  return Hash("TPZGraphMesh");
296 }
297 
298 void TPZGraphMesh::Read(TPZStream& buf, void* context) {
300  fGeoMesh = dynamic_cast<TPZGeoMesh *>(TPZPersistenceManager::GetInstance(&buf));
301  TPZManVector<int> mat_ids;
302  buf.Read(mat_ids);
303  for (auto matid: mat_ids) {
304  fMaterialIds.insert(matid);
305  }
306  buf.Write(&fDimension);
307  buf.Read(&fDimension);
309  fNodeMap.Read(buf, context);
310  buf.Read(&fResolution);
311  int fStyleInt;
312  buf.Read(&fStyleInt);
313  fStyle = TPZDrawStyle(fStyleInt);
314  buf.Read(&fFileName);
315  this->SetFileName(fFileName);
316  buf.Read(fScalarNames);
317  buf.Read(fVecNames);
318  buf.Read(fTensorNames);
319 }
320 
321 void TPZGraphMesh::Write(TPZStream& buf, int withclassid) const {
324  TPZManVector<int> mat_ids(fMaterialIds.size());
325  auto it = fMaterialIds.begin();
326  for (int i = 0; i < fMaterialIds.size(); i++, it++ ) {
327  mat_ids[i] = *it;
328  }
329  buf.Write(mat_ids);
330  buf.Write(&fDimension);
332  fNodeMap.Write(buf, withclassid);
333  buf.Write(&fResolution);
334  int fStyleInt = as_integer(fStyle);
335  buf.Write(&fStyleInt);
336  buf.Write(&fFileName);
337  buf.Write(fScalarNames);
338  buf.Write(fVecNames);
339  buf.Write(fTensorNames);
340 }
TPZGraphMesh(TPZCompMesh *cm, int dimension, const std::set< int > &matids, const TPZVec< std::string > &scalarnames, const TPZVec< std::string > &vecnames)
Constructor for graphical mesh.
Definition: pzgraphmesh.cpp:25
int64_t NElements() const
Number of computational elements allocated.
Definition: pzcmesh.h:169
bool Material_Is_PostProcessed(int matid)
Return a directive if the material id is being postprocessed.
void Print(std::ostream &out)
const int64_t numel
Number of elements to test.
Definition: pzsubcmesh.cpp:47
filename
Definition: stats.py:82
virtual MElementType Type()
Return the type of the element.
Definition: pzcompel.cpp:195
int ClassId() const override
Define the class id associated with the class.
TPZVec< std::string > fScalarNames
Vectors of the variables names (scalar, vectorial, and tensorial)
Definition: pzgraphmesh.h:127
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
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...
void WritePointers(const TPZVec< TPZAutoPointer< T >> &vec)
Definition: TPZStream.h:214
std::string fFileName
Definition: pzgraphmesh.h:125
std::underlying_type< Enumeration >::type as_integer(const Enumeration value)
Definition: pzreal.h:37
int64_t Id()
Get the Id of the graphical element.
Definition: pzgraphel.h:42
Contains the TPZGraphEl class which implements the graphical one-, two- and three-dimensional element...
Contains the TPZGraphNode class which implements the graphical node.
virtual void CreateGraphicalElement(TPZGraphMesh &graphmesh, int dimension)
Creates corresponding graphical element(s) if the dimension matches graphical elements are used to ge...
Definition: pzcompel.h:785
clarg::argInt cm("-cm", "clean memory before execution", 512)
int64_t NElements() const
Access method to query the number of elements of the vector.
Implements a chunk vector with free store administration. Utility.
Definition: TPZStream.h:39
TPZGeoMesh * fGeoMesh
Geometric mesh related.
Definition: pzgraphmesh.h:111
TPZGraphEl * FindElement(int64_t sid)
Definition: pzgraphmesh.cpp:89
void Print(std::ostream &out)
Print object attributes.
TPZCompEl * FindFirstInterpolatedElement(TPZCompMesh *mesh, int dimension)
static TPZSavable * GetInstance(const int64_t &objId)
void ReadPointers(TPZVec< TPZAutoPointer< T >> &vec)
Definition: TPZStream.h:305
int Dimension() const override
It returns dimension from the elements.
static TPZGraphNode gn
Definition: pzgraphmesh.cpp:76
virtual int NElements()=0
std::set< int > MaterialIds()
Get material ids.
virtual void DrawNodes()
Draw the graphical nodes information.
void SetMaterialIds(const std::set< int > &matids)
Set material ids.
TPZAdmChunkVector< TPZGraphEl * > & ElementList()
Vector of the graphical elements.
virtual void SequenceNodes()
void Read(TPZStream &buf, void *context) override
read objects from the stream
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...
int fDimension
Dimension of the graphical mesh.
Definition: pzgraphmesh.h:115
void SetPointNumber(int64_t num)
Definition: pzgraphnode.cpp:65
TPZDrawStyle fStyle
Style of the graphical file.
Definition: pzgraphmesh.h:123
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
Contains declaration of.
Implements a group of computational elements as a mesh and an element. Computational Mesh...
Definition: pzsubcmesh.h:36
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
virtual void SetCompMesh(TPZCompMesh *mesh, const std::set< int > &matids)
Sets the computational mesh to associate.
virtual void DrawMesh(int numcases)
Draw the graphical mesh.
int64_t SequenceNumber()
Definition: pzgraphnode.h:38
Contains the TPZGraphElT class which implements the graphical triangular element. ...
TPZAdmChunkVector< TPZGraphNode > & NodeMap()
Vector of the graphical nodes.
Contains the TPZGraphMesh class which represents a graphical mesh used for post processing purposes...
TPZVec< std::string > fVecNames
Definition: pzgraphmesh.h:127
Contains declaration of TPZCompelDisc class which implements a computational element for discontinuou...
Contains declaration of TPZCompMesh class which is a repository for computational elements...
std::ofstream fOutFile
Definition: pzgraphmesh.h:124
void CompactDataStructure(CompactScheme type=CompactScheme::ALWAYS)
Sets the method to compact the data structure based on the.
Definition: pzadmchunk.h:222
void SetId(int64_t id)
Set graphical element id.
Definition: pzgraphel.h:54
int fResolution
Resolution of the graphical object.
Definition: pzgraphmesh.h:121
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual void Connectivity(TPZDrawStyle st=EDXStyle)=0
Set dx style for connectivity information.
virtual void SetFileName(const std::string &filename)
Sets the filename to output of graph.
void SetNames(const TPZVec< std::string > &scalarnames, const TPZVec< std::string > &vecnames)
Set names with scalar and vector variable names.
Contains declaration of TPZSubCompMesh class which implements a group of computational elements as a ...
TPZAdmChunkVector< TPZGraphNode > fNodeMap
Vector of graphical nodes (connects)
Definition: pzgraphmesh.h:119
virtual int Dimension() const =0
Returns the dimension of the element.
void Print(std::ostream &out)
Print the information of the graphical element.
Definition: pzgraphel.cpp:170
virtual void DrawSolution(int step, REAL time)
Draw solution depending on the resolution.
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
void DrawCo(TPZDrawStyle st=EDXStyle)
Draw coordinates of the graphical node.
Definition: pzgraphnode.cpp:84
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
MElementType
Define the element types.
Definition: pzeltype.h:52
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
TPZVec< std::string > fTensorNames
Definition: pzgraphmesh.h:127
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
Abstract class to graphical one-, two- and three-dimensional element. Post processing.
Definition: pzgraphel.h:23
int64_t NElements(MElementType type)
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
TPZCompMesh * fCompMesh
Computational mesh associated.
Definition: pzgraphmesh.h:109
std::set< int > fMaterialIds
Set of material ids being post-processed.
Definition: pzgraphmesh.h:113
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
This class implements a discontinuous element (for use with discontinuous Galerkin). Computational Element.
Definition: TPZCompElDisc.h:35
virtual MElementType Type()=0
Get the type of the graphical element.
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzadmchunk.h:118
virtual ~TPZGraphMesh(void)
Default destructor.
Definition: pzgraphmesh.cpp:65
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
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
TPZDrawStyle
Definition: TPZDrawStyle.h:12
Implements computational element based on an interpolation space. Computational Element.
Definition: pzintel.h:27
TPZGraphNode & FindNode(int64_t side)
Find graphical node (connect)
Definition: pzgraphmesh.cpp:78
Implements an agglomerated discontinuous element. Computational Element.
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
TPZAdmChunkVector< TPZGraphEl * > fElementList
Vector of graphical elements.
Definition: pzgraphmesh.h:117
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzadmchunk.h:132