Exemplo n.º 1
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")
            }
Exemplo n.º 2
0
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;
	
}