void TPZQuadraticQuad::InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size) { TPZManVector<REAL,3> co(3),shift(3),scale(3); TPZManVector<int64_t,4> nodeindexes(NCornerNodes); for (int i=0; i<3; i++) { scale[i] = size[i]/3.; shift[i] = size[i]/2.+lowercorner[i]; } for (int i=0; i<NCornerNodes; i++) { ParametricDomainNodeCoord(i, co); co.Resize(3,0.); for (int j=0; j<3; j++) { co[j] = shift[j]+scale[j]*co[j]+(rand()*0.2/RAND_MAX)-0.1; } nodeindexes[i] = gmesh.NodeVec().AllocateNewElement(); gmesh.NodeVec()[nodeindexes[i]].Initialize(co, gmesh); } int64_t index; CreateGeoElement(gmesh, EQuadrilateral, nodeindexes, matid, index); TPZGeoEl *gel = gmesh.Element(index); int nsides = gel->NSides(); for (int is=0; is<nsides; is++) { gel->SetSideDefined(is); } gel = TPZChangeEl::ChangeToQuadratic(&gmesh, index); for (int node = gel->NCornerNodes(); node < gel->NNodes(); node++) { TPZManVector<REAL,3> co(3); gel->NodePtr(node)->GetCoordinates(co); for (int i=0; i<3; i++) { co[i] += (0.2*rand())/RAND_MAX - 0.1; } gel->NodePtr(node)->SetCoord(co); } }
void AdjustBoundary(TPZGeoMesh *gmesh) { int64_t nel = gmesh->NElements(); for (int64_t el = 0; el<nel; el++) { TPZGeoEl *gel = gmesh->Element(el); if (gel->Dimension() == 3 || gel->HasSubElement()) { continue; } TPZGeoElSide gelside(gel,gel->NSides()-1); TPZGeoElSide neighbour = gelside.Neighbour(); bool should_refine = false; int nsub = -1; int numneigh = 0; while (gelside != neighbour) { nsub = neighbour.Element()->NSideSubElements(neighbour.Side()); if (neighbour.Element()->HasSubElement() && nsub > 1) { should_refine = true; } numneigh++; neighbour = neighbour.Neighbour(); } if (should_refine == true) { TPZAutoPointer<TPZRefPattern> match = TPZRefPatternTools::PerfectMatchRefPattern(gel); if (!match) { DebugStop(); } gel->SetRefPattern(match); TPZStack<TPZGeoEl *> subels; gel->Divide(subels); } } }
/** * @brief transform in low order Raviar Tomas */ void TPZCreateApproximationSpace::UndoMakeRaviartTomas(TPZCompMesh &cmesh) { int numcell = cmesh.NElements(); int el; for (el = 0; el<numcell ; el++) { TPZCompEl *cel = cmesh.ElementVec()[el]; TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(cel); if (!intel) { continue; } TPZGeoEl *gel = intel->Reference(); int geldim = gel->Dimension(); int is; int nsides = gel->NSides(); for (is=0; is<nsides; is++) { if (gel->SideDimension(is) != geldim-1) { continue; } int nsconnects = intel->NSideConnects(is); // only interested in HDiv elements if (nsconnects != 1) { continue; } // int cindex = intel->SideConnectIndex(0, is); TPZConnect &c = intel->Connect(intel->SideConnectLocId(0,is)); if (c.HasDependency()) { c.RemoveDepend(); } } } cmesh.ExpandSolution(); cmesh.CleanUpUnconnectedNodes(); }
int TPZCheckGeom::CheckRefinement(TPZGeoEl *gel){ int check = 0; if(!gel || !gel->HasSubElement()) return check; int nsides = gel->NSides(); int is; for(is=0; is<nsides; is++) { TPZStack<TPZGeoElSide> subel; gel->GetSubElements2(is,subel); int nsub = subel.NElements(); int isub; for(isub=0; isub<nsub; isub++) { TPZGeoElSide fath = subel[isub].Father2(); int son = subel[isub].Element()->WhichSubel(); if(fath.Side() != is) { PZError << "TPZCheckGeom::CheckRefinement non corresponding subelement/sides son " << son << " sonside " << subel[isub].Side() << " fathside " << is << " fath2side " << fath.Side() << endl; gel->Print(); check = 1; } } } int nsub = gel->NSubElements(); for(is=0; is<nsub; is++) { TPZGeoEl *sub = gel->SubElement(is); int nsubsides = sub->NSides(); int iss; for(iss=0; iss<nsubsides; iss++) { check = (CheckSubFatherTransform(sub,iss) || check); } } return check; }
void LoadingRamp(REAL pseudo_t, TPZCompMesh * cmesh){ if (!cmesh) { DebugStop(); } TPZMaterial *mat = cmesh->FindMaterial(ERock); if (!mat) { DebugStop(); } /// Compute the footing lenght REAL footing_lenght = 0; { TPZGeoMesh * gmesh = cmesh->Reference(); if (!gmesh) { DebugStop(); } int n_el = gmesh ->NElements(); for (int iel = 0; iel < n_el; iel++) { TPZGeoEl * gel = gmesh->Element(iel); if (!gel) { DebugStop(); } if (gel->MaterialId() != ETopBC) { continue; } REAL gel_length = gel->SideArea(gel->NSides() - 1); footing_lenght += gel_length; } } /// Apply loading REAL max_uy = 100.0; REAL min_uy = 0.0; /// Compute current displacement // REAL uy = (footing_lenght*(max_uy - min_uy)*pseudo_t)/100.0; REAL uy = (footing_lenght*(max_uy - min_uy)*pseudo_t); /// Apply current displacement TPZFMatrix<STATE> val2(2,1,0.); val2(1,0) = -uy; TPZBndCond * bc_top = NULL; bc_top = dynamic_cast<TPZBndCond *> (cmesh->FindMaterial(ETopBC)); if (!bc_top || bc_top->Material() != mat) { DebugStop(); } else { bc_top->Val2() = val2; } }
void TPZMultiphysicsElement::CreateInterfaces() { //nao verifica-se caso o elemento de contorno //eh maior em tamanho que o interface associado //caso AdjustBoundaryElement nao for aplicado //a malha eh criada consistentemente TPZGeoEl *ref = Reference(); int nsides = ref->NSides(); int InterfaceDimension = Mesh()->Dimension() - 1; int side; nsides--;//last face for(side=nsides;side>=0;side--) { if(ref->SideDimension(side) != InterfaceDimension) continue; TPZCompElSide thisside(this,side); if(this->ExistsInterface(side)) { // cout << "TPZCompElDisc::CreateInterface inconsistent: interface already exists\n"; continue; } TPZStack<TPZCompElSide> highlist; thisside.HigherLevelElementList(highlist,0,1); //a interface se cria uma vez so quando existem ambos //elementos esquerdo e direito (compu tacionais) if(!highlist.NElements()) { this->CreateInterface(side);//s�tem iguais ou grande => pode criar a interface } else { int64_t ns = highlist.NElements(); int64_t is; for(is=0; is<ns; is++) {//existem pequenos ligados ao lado atual const int higheldim = highlist[is].Reference().Dimension(); if(higheldim != InterfaceDimension) continue; // TPZCompElDisc *del = dynamic_cast<TPZCompElDisc *> (highlist[is].Element()); // if(!del) continue; TPZCompEl *del = highlist[is].Element(); if(!del) continue; TPZCompElSide delside( del, highlist[is].Side() ); TPZMultiphysicsElement * delSp = dynamic_cast<TPZMultiphysicsElement *>(del); if (!delSp){ PZError << "\nERROR AT " << __PRETTY_FUNCTION__ << " - CASE NOT AVAILABLE\n"; return; } if ( delSp->ExistsInterface(highlist[is].Side()) ) { // cout << "TPZCompElDisc::CreateInterface inconsistent: interface already exists\n"; } else { delSp->CreateInterface(highlist[is].Side()); } } } } }
/** * @brief transform in low order Raviar Tomas */ void TPZCreateApproximationSpace::MakeRaviartTomas(TPZCompMesh &cmesh) { int numcell = cmesh.NElements(); int el; for (el = 0; el<numcell ; el++) { TPZCompEl *cel = cmesh.ElementVec()[el]; TPZInterpolationSpace *intel = dynamic_cast<TPZInterpolationSpace *>(cel); if (!intel) { continue; } intel->SetPreferredOrder(1); } cmesh.ExpandSolution(); for (el = 0; el<numcell ; el++) { TPZCompEl *cel = cmesh.ElementVec()[el]; TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(cel); if (!intel) { continue; } TPZGeoEl *gel = intel->Reference(); int geldim = gel->Dimension(); int is; int nsides = gel->NSides(); for (is=0; is<nsides; is++) { if (gel->SideDimension(is) != geldim-1) { continue; } int nsconnects = intel->NSideConnects(is); // only interested in HDiv elements if (nsconnects != 1) { continue; } int cindex = intel->SideConnectIndex(0, is); TPZConnect &c = intel->Connect(intel->SideConnectLocId(0,is)); if (c.HasDependency()) { continue; } int nshape = 1; int nstate = 1; int order = 0; int cindex2 = cmesh.AllocateNewConnect(nshape, nstate, order); // TPZConnect &c2 = cmesh.ConnectVec()[cindex]; TPZFNMatrix<2> depmat(2,1,1.); c.AddDependency(cindex, cindex2, depmat, 0, 0, 2, 1); } } cmesh.ExpandSolution(); }
TPZGeoEl *TPZQuadraticQuad::CreateBCGeoEl(TPZGeoEl *orig,int side,int bc) { int ns = orig->NSideNodes(side); TPZManVector<int64_t> nodeindices(ns); int in; for(in=0; in<ns; in++) { nodeindices[in] = orig->SideNodeIndex(side,in); } int64_t index; TPZGeoMesh *mesh = orig->Mesh(); MElementType type = orig->Type(side); TPZGeoEl *newel = mesh->CreateGeoBlendElement(type, nodeindices, bc, index); TPZGeoElSide me(orig,side); TPZGeoElSide newelside(newel,newel->NSides()-1); newelside.InsertConnectivity(me); // newel->Initialize(); return newel; }
void InsertBoundaryElements(TPZGeoMesh *gmesh) { REAL xplane = 1435; REAL yplane = 1161; REAL zplane = -1530; REAL ztop = 122.8; REAL minx = 0; REAL minz = 0; REAL maxz = 0; int64_t nel = gmesh->NElements(); for (int64_t el=0; el<nel; el++) { TPZGeoEl *gel = gmesh->Element(el); if (gel->HasSubElement()) { continue; } int nsides = gel->NSides(); for (int is=0; is<nsides; is++) { int bccreated = 999; TPZGeoElSide gelside(gel,is); if (gel->SideDimension(is) == 1) { TPZManVector<REAL,3> xcenter(3); gelside.CenterX(xcenter); if (xcenter[2] > maxz) { maxz = xcenter[2]; } if (fabs(xcenter[0]) < 1 && fabs(xcenter[2]-ztop) < 1) { bccreated = bcloadtop; TPZGeoElSide neighbour = gelside.Neighbour(); while (neighbour != gelside) { if (neighbour.Element()->MaterialId() == bcloadtop) { bccreated = 999; } neighbour = neighbour.Neighbour(); } if (bccreated == bcloadtop) { std::cout << "Added boundary bcloadtop xcenter = " << xcenter << std::endl; } } } if (gel->SideDimension(is) == 2) { TPZManVector<REAL,3> xcenter(3); gelside.CenterX(xcenter); if (xcenter[0] < minx) { minx = xcenter[0]; } if (xcenter[2] < minz) { minz = xcenter[2]; } if (fabs(xcenter[2] - zplane) < 1.) { bccreated = bcbottom; } if (fabs(fabs(xcenter[0])-xplane) < 1) { bccreated = bcsidex; } if (fabs(fabs(xcenter[1])-yplane) < 1) { bccreated = bcsidey; } if (fabs(xcenter[2]-ztop) <1) { bccreated = bctopsurface; } } if(bccreated != 999) { if (gelside.Dimension() == 2 && gelside.Neighbour() != gelside) { DebugStop();; } gel->CreateBCGeoEl(is, bccreated); } } } std::cout << "minx = " << minx << " minz = " << minz << " maxz " << maxz << std::endl; }
int main() { TPZManVector<REAL,3> x0(3,0.),x1(3,1.); x1[2] = 0.; TPZManVector<int,2> nelx(2,4); nelx[0] = 8; TPZGenGrid gengrid(nelx,x0,x1); gengrid.SetElementType(ETriangle); TPZGeoMesh *gmesh = new TPZGeoMesh; gmesh->SetDimension(2); gengrid.Read(gmesh); { std::ofstream out("gmesh.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh, out, true); } TPZExtendGridDimension extend(gmesh,0.5); extend.SetElType(1); TPZGeoMesh *gmesh3d = extend.ExtendedMesh(4); { std::ofstream out("gmesh3d.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true); } { int numel = nelx[1]; for(int el=0; el<numel; el++) { TPZManVector<int64_t, 3> nodes(2); nodes[0] = 2+(nelx[0]+1)*el+el; nodes[1] = 2+(nelx[0]+1)*(el+1)+1+el; int matid = 2; int64_t index; gmesh3d->CreateGeoElement(EOned, nodes, matid, index); } { std::ofstream out("gmesh3dbis.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true); } } gmesh3d->BuildConnectivity(); gRefDBase.InitializeRefPatterns(); std::set<int> matids; matids.insert(2); TPZRefPatternTools::RefineDirectional(gmesh3d, matids); { std::ofstream out("gmesh3dtris.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true); } { int64_t nel = gmesh3d->NElements(); for (int64_t el = 0; el<nel; el++) { TPZGeoEl *gel = gmesh3d->Element(el); if(gel->Father()) gel->SetMaterialId(3); } for (int64_t el = 0; el<nel; el++) { TPZGeoEl *gel = gmesh3d->Element(el); if(gel->Dimension() == 1) { for(int side=0; side < gel->NSides(); side++) { TPZGeoElSide gelside(gel,side); TPZGeoElSide neighbour(gelside.Neighbour()); while (neighbour != gelside) { if(neighbour.Element()->Father()) { neighbour.Element()->SetMaterialId(4); } neighbour = neighbour.Neighbour(); } } } } } { std::ofstream out("gmesh3dtris.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true); } return 0; }
int CompareShapeFunctions(TPZCompElSide celsideA, TPZCompElSide celsideB) { TPZGeoElSide gelsideA = celsideA.Reference(); TPZGeoElSide gelsideB = celsideB.Reference(); int sideA = gelsideA.Side(); int sideB = gelsideB.Side(); TPZCompEl *celA = celsideA.Element(); TPZCompEl *celB = celsideB.Element(); TPZMultiphysicsElement *MFcelA = dynamic_cast<TPZMultiphysicsElement *>(celA); TPZMultiphysicsElement *MFcelB = dynamic_cast<TPZMultiphysicsElement *>(celB); TPZInterpolatedElement *interA = dynamic_cast<TPZInterpolatedElement *>(MFcelA->Element(0)); TPZInterpolatedElement *interB = dynamic_cast<TPZInterpolatedElement *>(MFcelB->Element(0)); TPZMaterialData dataA; TPZMaterialData dataB; interA->InitMaterialData(dataA); interB->InitMaterialData(dataB); TPZTransform<> tr = gelsideA.NeighbourSideTransform(gelsideB); TPZGeoEl *gelA = gelsideA.Element(); TPZTransform<> trA = gelA->SideToSideTransform(gelsideA.Side(), gelA->NSides()-1); TPZGeoEl *gelB = gelsideB.Element(); TPZTransform<> trB = gelB->SideToSideTransform(gelsideB.Side(), gelB->NSides()-1); int dimensionA = gelA->Dimension(); int dimensionB = gelB->Dimension(); int nSideshapeA = interA->NSideShapeF(sideA); int nSideshapeB = interB->NSideShapeF(sideB); int is; int firstShapeA = 0; int firstShapeB = 0; for (is=0; is<sideA; is++) { firstShapeA += interA->NSideShapeF(is); } for (is=0; is<sideB; is++) { firstShapeB += interB->NSideShapeF(is); } TPZIntPoints *intrule = gelA->CreateSideIntegrationRule(gelsideA.Side(), 4); int nwrong = 0; int npoints = intrule->NPoints(); int ip; for (ip=0; ip<npoints; ip++) { TPZManVector<REAL,3> pointA(gelsideA.Dimension()),pointB(gelsideB.Dimension()), pointElA(gelA->Dimension()),pointElB(gelB->Dimension()); REAL weight; intrule->Point(ip, pointA, weight); int sidedim = gelsideA.Dimension(); TPZFNMatrix<9> jacobian(sidedim,sidedim),jacinv(sidedim,sidedim),axes(sidedim,3); REAL detjac; gelsideA.Jacobian(pointA, jacobian, jacinv, detjac, jacinv); TPZManVector<REAL,3> normal(3,0.), xA(3),xB(3); normal[0] = axes(0,1); normal[1] = -axes(0,0); tr.Apply(pointA, pointB); trA.Apply(pointA, pointElA); trB.Apply(pointB, pointElB); gelsideA.Element()->X(pointElA, xA); gelsideB.Element()->X(pointElB, xB); for (int i=0; i<3; i++) { if(fabs(xA[i]- xB[i])> 1.e-6) DebugStop(); } int nshapeA = 0, nshapeB = 0; interA->ComputeRequiredData(dataA, pointElA); interB->ComputeRequiredData(dataB, pointElB); nshapeA = dataA.phi.Rows(); nshapeB = dataB.phi.Rows(); if(nSideshapeA != nSideshapeB) DebugStop(); TPZManVector<REAL> shapesA(nSideshapeA), shapesB(nSideshapeB); int nwrongkeep(nwrong); int i,j; for(i=firstShapeA,j=firstShapeB; i<firstShapeA+nSideshapeA; i++,j++) { int Ashapeind = i; int Bshapeind = j; int Avecind = -1; int Bvecind = -1; // if A or B are boundary elements, their shapefunctions come in the right order if (dimensionA != sidedim) { Ashapeind = dataA.fVecShapeIndex[i].second; Avecind = dataA.fVecShapeIndex[i].first; } if (dimensionB != sidedim) { Bshapeind = dataB.fVecShapeIndex[j].second; Bvecind = dataB.fVecShapeIndex[j].first; } if (dimensionA != sidedim && dimensionB != sidedim) { // vefify that the normal component of the normal vector corresponds Avecind = dataA.fVecShapeIndex[i].first; Bvecind = dataB.fVecShapeIndex[j].first; REAL vecnormalA = dataA.fNormalVec(0,Avecind)*normal[0]+dataA.fNormalVec(1,Avecind)*normal[1]; REAL vecnormalB = dataB.fNormalVec(0,Bvecind)*normal[0]+dataB.fNormalVec(1,Bvecind)*normal[1]; if(fabs(vecnormalA-vecnormalB) > 1.e-6) { nwrong++; LOGPZ_ERROR(logger, "normal vectors aren't equal") } } shapesA[i-firstShapeA] = dataA.phi(Ashapeind,0); shapesB[j-firstShapeB] = dataB.phi(Bshapeind,0); REAL valA = dataA.phi(Ashapeind,0); REAL valB = dataB.phi(Bshapeind,0); REAL diff = valA-valB; REAL decision = fabs(diff)-1.e-6; if(decision > 0.) { nwrong ++; std::cout << "valA = " << valA << " valB = " << valB << " Avecind " << Avecind << " Bvecind " << Bvecind << " Ashapeind " << Ashapeind << " Bshapeind " << Bshapeind << " sideA " << sideA << " sideB " << sideB << std::endl; LOGPZ_ERROR(logger, "shape function values are different") }
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; }
TPZCompMesh *TPZAdaptMesh::CreateCompMesh (TPZCompMesh *mesh, //malha a refinar TPZVec<TPZGeoEl *> &gelstack, // TPZVec<int> &porders) { //Cria um ponteiro para a malha geom�trica de mesh TPZGeoMesh *gmesh = mesh->Reference(); if(!gmesh) { cout << "TPZAdaptMesh::CreateCompMesh encountered no geometric mesh\n"; return 0; } //Reseta as refer�ncias do ponteiro para a malha geom�trica criada //e cria uma nova malha computacional baseada nesta malha geom�trica gmesh->ResetReference(); TPZCompMesh *cmesh = new TPZCompMesh(gmesh); // int nmat = mesh->MaterialVec().size(); // int m; //Cria um clone do vetor de materiais da malha mesh mesh->CopyMaterials(*cmesh); /* for(m=0; m<nmat; m++) { TPZMaterial * mat = mesh->MaterialVec()[m]; if(!mat) continue; mat->Clone(cmesh->MaterialVec()); } */ //Idenifica o vetor de elementos computacionais de mesh // TPZAdmChunkVector<TPZCompEl *> &elementvec = mesh->ElementVec(); int el,nelem = gelstack.NElements(); // cmesh->SetName("Antes PRefine"); // cmesh->Print(cout); for(el=0; el<nelem; el++) { //identifica os elementos geom�tricos passados em gelstack TPZGeoEl *gel = gelstack[el]; if(!gel) { cout << "TPZAdaptMesh::CreateCompMesh encountered an null element\n"; continue; } long celindex; //Cria um TPZIntel baseado no gel identificado TPZInterpolatedElement *csint; csint = dynamic_cast<TPZInterpolatedElement *> (cmesh->CreateCompEl(gel,celindex)); if(!csint) continue; //Refina em p o elemento criado // cmesh->SetName("depois criar elemento"); // cmesh->Print(cout); csint->PRefine(porders[el]); // cmesh->SetName("depois prefine no elemento"); // cmesh->Print(cout); } #ifndef CLONEBCTOO nelem = gmesh->NElements(); for (el=0; el<nelem; el++) { TPZGeoEl *gel = gmesh->ElementVec()[el]; if (!gel || gel->Reference()) { continue; } int matid = gel->MaterialId(); if (matid < 0) { TPZStack<TPZCompElSide> celstack; int ns = gel->NSides(); TPZGeoElSide gelside(gel,ns-1); gelside.HigherLevelCompElementList2(celstack, 1, 1); if (celstack.size()) { TPZStack<TPZGeoEl *> subels; gel->Divide(subels); } } } nelem = gmesh->NElements(); for (el=0; el<nelem; el++) { TPZGeoEl *gel = gmesh->ElementVec()[el]; if (!gel || gel->Reference()) { continue; } int matid = gel->MaterialId(); if (matid < 0) { TPZStack<TPZCompElSide> celstack; int ns = gel->NSides(); TPZGeoElSide gelside(gel,ns-1); gelside.EqualLevelCompElementList(celstack, 1, 0); if (celstack.size()) { long index; cmesh->CreateCompEl(gel, index); } } } #endif //Mais einh!! // cmesh->SetName("Antes Adjust"); // cmesh->Print(cout); cmesh->AdjustBoundaryElements(); // cmesh->SetName("Depois"); // cmesh->Print(cout); return cmesh; }
// 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; } }