int TPZCheckGeom::CheckSideTransform(TPZGeoEl *gel, int sidefrom, int sideto){ int check = 0; int nsides = gel->NSides(); TPZIntPoints *integ = gel->CreateSideIntegrationRule(sidefrom,2); TPZTransform trans = gel->SideToSideTransform(sidefrom,sideto); TPZTransform trans1 = gel->SideToSideTransform(sidefrom,nsides-1); TPZTransform trans2 = gel->SideToSideTransform(sideto,nsides-1); int sidefromdim = gel->SideDimension(sidefrom); int sidetodim = gel->SideDimension(sideto); int geldim = gel->Dimension(); TPZVec<REAL> intpoint(sidefromdim); TPZVec<REAL> sidetopoint(sidetodim); TPZVec<REAL> elpoint1(geldim),elpoint2(geldim); TPZVec<REAL> x1(3),x2(3); int nintpoints = integ->NPoints(); int ip; REAL w; for(ip=0; ip<nintpoints; ip++) { integ->Point(ip,intpoint,w); trans.Apply(intpoint,sidetopoint); trans1.Apply(intpoint,elpoint1); trans2.Apply(sidetopoint,elpoint2); gel->X(elpoint1,x1); gel->X(elpoint2,x2); REAL dif = 0; int nx = x1.NElements(); int ix; for(ix=0; ix<nx; ix++) dif += (x1[ix]-x2[ix])*(x1[ix]-x2[ix]); if(dif > 1.e-6) { PZError << "TPZCheckGeom::CheckSideTransform sidefrom = "<< sidefrom << " sideto = " << sideto << " dif = " << dif << endl; gel->Print(); check = 1; } } delete integ; return check; }
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") }
// 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; } }
int TPZCheckGeom::CheckSubFatherTransform(TPZGeoEl *subel, int sidesub) { int check = 0; TPZGeoElSide father = subel->Father2(sidesub); if(!father.Exists()) return check; TPZIntPoints *integ = subel->CreateSideIntegrationRule(sidesub,2); int subsidedim = subel->SideDimension(sidesub); int subdim = subel->Dimension(); TPZTransform trans(subsidedim); trans = subel->BuildTransform2(sidesub,father.Element(),trans); int fathsidedim = father.Dimension(); int fathdim = father.Element()->Dimension(); int nsubsides = subel->NSides(); int nfathsides = father.Element()->NSides(); TPZTransform trans1 = subel->SideToSideTransform(sidesub,nsubsides-1); TPZTransform trans2 = father.Element()->SideToSideTransform(father.Side(),nfathsides-1); TPZVec<REAL> intpoint(subsidedim); TPZVec<REAL> sidetopoint(fathsidedim); TPZVec<REAL> elpoint1(subdim),elpoint2(fathdim); TPZVec<REAL> x1(3),x2(3); int nintpoints = integ->NPoints(); int ip; REAL w; for(ip=0; ip<nintpoints; ip++) { integ->Point(ip,intpoint,w); trans.Apply(intpoint,sidetopoint); trans1.Apply(intpoint,elpoint1); trans2.Apply(sidetopoint,elpoint2); subel->X(elpoint1,x1); father.Element()->X(elpoint2,x2); int otherfatherside = father.Element()->WhichSide(elpoint2); if(otherfatherside != father.Side()) { int son = subel->WhichSubel(); PZError << "TPZCheckGeom::CheckSubFatherTransform son " << son << " sidesub = "<< sidesub << " fathside = " << father.Side() << " otherfatherside = " << otherfatherside << endl; check=1; } REAL dif = 0; int nx = x1.NElements(); int ix; for(ix=0; ix<nx; ix++) dif += (x1[ix]-x2[ix])*(x1[ix]-x2[ix]); if(dif > 1.e-6) { int son = subel->WhichSubel(); PZError << "TPZCheckGeom::CheckSubFatherTransform son " << son << " sidesub = "<< sidesub << " fathside = " << father.Side() << " dif = " << dif << endl; // subel->Print(); check = 1; TPZTransform t = subel->ComputeParamTrans(father.Element(),father.Side(),sidesub); t.PrintInputForm(cout); cout << endl; trans.PrintInputForm(cout); cout << endl; check = 1; } } if(check == 0) { TPZTransform t = subel->ComputeParamTrans(father.Element(),father.Side(),sidesub); check = t.Compare(trans); if(check == 1){ int son = subel->WhichSubel(); PZError << "TPZCheckGeom::CheckSubFatherTransform son " << son << " sidesub = "<< sidesub << " fathside = " << father.Side() << endl; t.PrintInputForm(cout); cout << endl; trans.PrintInputForm(cout); cout << endl; } // compare t with trans } delete integ; return check; }