TPZDXGraphMesh::TPZDXGraphMesh(TPZCompMesh *cmesh, int dimension, TPZAutoPointer<TPZMaterial> mat, const TPZVec<std::string> &scalarnames, const TPZVec<std::string> &vecnames) : TPZGraphMesh(cmesh,dimension,mat) { SetNames(scalarnames,vecnames); fNextDataField = 1; fStyle = EDXStyle; // int index = 0; TPZCompEl *ce = FindFirstInterpolatedElement(cmesh,dimension); fElementType = "noname"; if(ce) { int type = ce->Type(); if(type == EOned) fElementType = "lines"; if(type == ETriangle) fElementType = "triangles"; if(type == EQuadrilateral) fElementType = "quads"; if(type == ECube) fElementType = "cubes"; if(type == EPrisma) fElementType = "cubes"; TPZGeoEl *gel = ce->Reference(); if( type == EDiscontinuous || (type == EAgglomerate && gel) ){ int nnodes = gel->NNodes(); if(nnodes==4 && dimension==2) fElementType = "quads"; if(nnodes==3 && dimension==2) fElementType = "triangles"; if(dimension==3) fElementType = "cubes"; } } fNumCases = 0; fNumConnectObjects[0] = 1; fNumConnectObjects[1] = 1; fNumConnectObjects[2] = 1; fNormalObject = 0; for(int i = 0; i < 8; i++) fElConnectivityObject[i] = -1; }
TPZCompEl *TPZGraphMesh::FindFirstInterpolatedElement(TPZCompMesh *mesh, int dim) { int64_t nel = mesh->NElements(); TPZCompEl *cel; int64_t iel; for(iel=0; iel<nel; iel++) { cel = mesh->ElementVec()[iel]; if(!cel) continue; int type = cel->Type(); if(type == EAgglomerate){ #ifndef STATE_COMPLEX if(!cel->Reference()) continue; TPZAgglomerateElement *agg = dynamic_cast<TPZAgglomerateElement *>(cel); if(agg && agg->Dimension() == dim) return agg; #else DebugStop(); #endif } if(type == EDiscontinuous){ TPZCompElDisc *disc = dynamic_cast<TPZCompElDisc *>(cel); if(disc && disc->Reference()->Dimension() == dim) return disc; } TPZCompEl *intel = dynamic_cast<TPZInterpolatedElement *>(cel); if(intel && intel->Reference()->Dimension() == dim) return intel; TPZSubCompMesh *subcmesh = dynamic_cast<TPZSubCompMesh *> (cel); if(subcmesh) { intel = FindFirstInterpolatedElement(subcmesh,dim); if(intel) return intel; } } return 0; }
// Output as Mathematica format void OutputMathematica(std::ofstream &outMath,int var,int pointsByElement,TPZCompMesh *cmesh) { int i, j, k, nnodes; int nelem = cmesh->ElementVec().NElements(); int dim = cmesh->Dimension(); // Dimension of the model REAL w; if(var-1 < 0) var = 1; // Map to store the points and values map<REAL,TPZVec<REAL> > Graph; TPZVec<REAL> tograph(4,0.); map<TPZVec<REAL>,REAL> Graphics; for(i=0;i<nelem;i++) { TPZCompEl *cel = cmesh->ElementVec()[i]; TPZGeoEl *gel = cel->Reference(); TPZInterpolationSpace * sp = dynamic_cast <TPZInterpolationSpace*>(cel); int nstates = cel->Material()->NStateVariables(); // If var is higher than nstates of the element, go to next element if(var > nstates) continue; TPZVec<REAL> qsi(3,0.), sol(nstates,0.), outfem(3,0.); nnodes = gel->NNodes(); if(pointsByElement < nnodes) pointsByElement = nnodes; for(j=0;j<gel->NNodes();j++) { // Get corners points to compute solution on gel->CenterPoint(j,qsi); sp->Solution(qsi,0,sol); cel->Reference()->X(qsi,outfem); // Jointed point coordinates and solution value on for(k=0;k<3;k++) tograph[k] = outfem[k]; tograph[k] = sol[var-1]; Graph.insert(pair<REAL,TPZVec<REAL> >(outfem[0],tograph)); Graphics.insert(pair<TPZVec<REAL>,REAL>(outfem,sol[var-1])); // If cel is point gets one point value if(cel->Type() == EPoint) { break; } } // If cel is point gets one point value if(cel->Type() == EPoint) continue; // Print another points using integration points TPZIntPoints *rule = NULL; int order = 1, npoints = 0; while(pointsByElement-(npoints+nnodes) > 0) { if(rule) delete rule; // Cleaning unnecessary allocation int nsides = gel->NSides(); // Get the integration rule to compute internal points to print, not to print rule = gel->CreateSideIntegrationRule(nsides-1,order); if(!rule) break; npoints = rule->NPoints(); order += 2; } for(j=0;j<npoints;j++) { // Get integration points to get internal points rule->Point(j,qsi,w); sp->Solution(qsi,0,sol); cel->Reference()->X(qsi,outfem); // Jointed point coordinates and solution value on for(k=0;k<3;k++) tograph[k] = outfem[k]; tograph[k] = sol[var-1]; Graph.insert(pair<REAL,TPZVec<REAL> >(outfem[0],tograph)); Graphics.insert(pair<TPZVec<REAL>,REAL>(outfem,sol[var-1])); } } // Printing the points and values into the Mathematica file outMath << "Saida = { "; // Formatting output outMath << fixed << setprecision(10); if(dim<2) { map<REAL,TPZVec<REAL> >::iterator it; for(it=Graph.begin();it!=Graph.end();it++) { if(it!=Graph.begin()) outMath << ","; outMath << "{"; for(j=0;j<dim;j++) outMath << (*it).second[j] << ","; outMath << (*it).second[3] << "}"; } outMath << "};" << std::endl; // Choose Mathematica command depending on model dimension outMath << "ListPlot[Saida,Joined->True]"<< endl; } else { map<TPZVec<REAL>,REAL>::iterator it; for(it=Graphics.begin();it!=Graphics.end();it++) { if(it!=Graphics.begin()) outMath << ","; outMath << "{"; for(j=0;j<dim;j++) outMath << (*it).first[j] << ","; outMath << (*it).second << "}"; } outMath << "};" << std::endl; outMath << "ListPlot3D[Saida]"<< endl; } }