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