int SubStructure(TPZAutoPointer<TPZCompMesh> cmesh, REAL height) { int nelem = cmesh->NElements(); TPZManVector<int> subindex(nelem,-1); int iel; int nsub = 0; for (iel=0; iel<nelem; iel++) { TPZCompEl *cel = cmesh->ElementVec()[iel]; if (!cel) { continue; } TPZGeoEl *gel = cel->Reference(); if (!gel) { continue; } int nsides = gel->NSides(); TPZManVector<REAL> center(gel->Dimension(),0.), xco(3,0.); gel->CenterPoint(nsides-1,center); gel->X(center,xco); REAL z = xco[2]; int floor = (int) z/height; nsub = (floor+1) > nsub ? (floor+1) : nsub; subindex[iel] = floor; } #ifdef DEBUG { TPZGeoMesh *gmesh = cmesh->Reference(); int nelgeo = gmesh->NElements(); TPZVec<int> domaincolor(nelgeo,-999); int cel; int nel = cmesh->NElements(); for (cel=0; cel<nel; cel++) { TPZCompEl *compel = cmesh->ElementVec()[cel]; if(!compel) continue; TPZGeoEl *gel = compel->Reference(); if (!gel) { continue; } domaincolor[gel->Index()] = subindex[cel]; } ofstream vtkfile("partition.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh, vtkfile, domaincolor); } #endif int isub; TPZManVector<TPZSubCompMesh *> submeshes(nsub,0); for (isub=0; isub<nsub; isub++) { int index; std::cout << '^'; std::cout.flush(); submeshes[isub] = new TPZSubCompMesh(cmesh,index); if (index < subindex.NElements()) { subindex[index] = -1; } } for (iel=0; iel<nelem; iel++) { int domindex = subindex[iel]; if (domindex >= 0) { TPZCompEl *cel = cmesh->ElementVec()[iel]; if (!cel) { continue; } submeshes[domindex]->TransferElement(cmesh.operator->(),iel); } } cmesh->ComputeNodElCon(); for (isub=0; isub<nsub; isub++) { submeshes[isub]->MakeAllInternal(); std::cout << '*'; std::cout.flush(); } cmesh->ComputeNodElCon(); cmesh->CleanUpUnconnectedNodes(); return nsub; }
// 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; } }