Exemplo n.º 1
0
void ReadSolution(ifstream &arq, TPZVec<REAL> &sol, TPZCompMesh *cmesh, int &nstate, TPZVec<int> &dimstate){

  int i,j,totaldim=0;
  for(i=0;i<nstate;i++) totaldim += dimstate[i];
  TPZVec<REAL> pt(3,0.);
  TPZVec<REAL> coord(3,0.);
  TPZVec<REAL> auxsol(totaldim,0.);

  int iter = 0;
  int nel = cmesh->NElements();
  int solsize = totaldim * nel;
  sol.Resize(solsize);
  sol.Fill(0.);

  for(i=0; i<nel; i++){
    TPZCompEl *el = cmesh->ElementVec()[i];
    if (!el) continue;
    el->Reference()->CenterPoint(el->Reference()->NSides()-1,pt);
    el->Reference()->X(pt,coord);
    EvaluateSolution(coord,auxsol);
    for (j=0;j<totaldim;j++){
      sol[iter] = auxsol[j];
      iter++;
    }
  }
}
Exemplo n.º 2
0
void TPZMGAnalysis::MeshError(TPZCompMesh *fine, TPZCompMesh *coarse, TPZVec<REAL> &ervec,
							  void (*f)(TPZVec<REAL> &loc, TPZVec<REAL> &val, TPZFMatrix<REAL> &deriv),TPZVec<REAL> &truervec){
	coarse->Reference()->ResetReference();
	coarse->LoadReferences();
	int dim = fine->MaterialVec().begin()->second->Dimension();
	ervec.Resize(coarse->NElements());
	if(f) {
		truervec.Resize(coarse->NElements());
		truervec.Fill(0.,0);
	}
	ervec.Fill(0.,0);
	TPZCompEl *cel;
	TPZAdmChunkVector<TPZCompEl *> &elementvec = fine->ElementVec();
	int numel = elementvec.NElements();
	int el;
	for(el=0; el<numel; el++) {
		cel = elementvec[el];
		if (!cel) continue;
		TPZInterpolatedElement *cint = dynamic_cast<TPZInterpolatedElement *> (cel);
		if(!cint) continue;
		int ncon = cint->NConnects();
		TPZGeoElSide gelside(cint->Reference(),ncon-1);
		if(gelside.Dimension() != dim) continue;
		TPZGeoElSide gellarge(gelside);
		while(!gellarge.Reference().Exists() && gellarge.Father2().Exists()) gellarge = gellarge.Father2();
		if(!gellarge.Reference().Exists()) {
			cout << "TPZMGAnalsysis::BuildTransferMatrix element " << el << " found no corresponding element\n";
			continue;
		}
		TPZCompElSide cellargeside = gellarge.Reference();
		TPZCompEl *cellarge = cellargeside.Element();
		TPZInterpolatedElement *cintlarge = (TPZInterpolatedElement *) cellarge;
		TPZTransform transform(gelside.Dimension(),gellarge.Dimension());
		gelside.SideTransform3(gellarge,transform);
		int index = cellarge->Index();
		REAL truerror = 0.;
		ervec[index] += ElementError(cint,cintlarge,transform,f,truerror);
		if(f) truervec[index]  += truerror;
	}
}
Exemplo n.º 3
0
void TPZArtDiff::ODotOperator(TPZVec<REAL> &dphi, TPZVec<TPZVec<T> > &TauDiv, TPZVec<T> &Result){
	
	int dim = TauDiv.NElements();
	int size = dphi.NElements();
	int neq = TauDiv[0].NElements();
	if(size<1 || size>3){
		PZError << "TPZArtDiff::PointOperator: error data size";
	}
	
	Result.Resize(neq);
	Result.Fill(REAL(0.));
	
	int i, k;
	for(k=0;k<dim;k++)
		for(i=0;i<neq;i++)Result[i] += TauDiv[k][i] * dphi[k];
}
Exemplo n.º 4
0
void TPZMatPoissonD3::ErrorsHdiv(TPZMaterialData &data,TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values){
    
    values.Fill(0.0);
    TPZVec<STATE> sol(1),dsol(3),div(1);
//    if(data.numberdualfunctions) Solution(data,2,sol);//pressao
    Solution(data,1,dsol);//fluxo
    //Solution(data,14,div);//divergente
    
#ifdef LOG4CXX
//    if(logger->isDebugEnabled()){
//        std::stringstream sout;
//        sout<< "\n";
//        sout << " Pto  " << data.x << std::endl;
//        sout<< " pressao exata " <<u_exact <<std::endl;
//        sout<< " pressao aprox " <<sol <<std::endl;
//        sout<< " ---- "<<std::endl;
//        sout<< " fluxo exato " <<du_exact(0,0)<<", " << du_exact(1,0)<<std::endl;
//        sout<< " fluxo aprox " <<dsol<<std::endl;
//        sout<< " ---- "<<std::endl;
//        if(du_exact.Rows()>fDim) sout<< " div exato " <<du_exact(2,0)<<std::endl;
//        sout<< " div aprox " <<div<<std::endl;
//        LOGPZ_DEBUG(logger,sout.str())
//    }
#endif
    
    
//    //values[0] : pressure error using L2 norm
//    if(data.numberdualfunctions){
//        REAL diffP = abs(u_exact[0]-sol[0]);
//        values[0]  = diffP*diffP;
//    }
    //values[1] : flux error using L2 norm
    for(int id=0; id<fDim; id++) {
        REAL diffFlux = abs(dsol[id] - du_exact(id,0));
        values[1]  += diffFlux*diffFlux;
    }
//    if(du_exact.Rows()>3){
//        //values[2] : divergence using L2 norm
//        REAL diffDiv = abs(div[0] - du_exact(2,0));
//        values[2]=diffDiv*diffDiv;
//        //values[3] : Hdiv norm => values[1]+values[2];
//        values[3]= values[1]+values[2];
//    }
}
Exemplo n.º 5
0
void TPZArtDiff::Divergent(TPZFMatrix<STATE> &dsol,
						   TPZFMatrix<REAL> & dphi,
						   TPZVec<TPZDiffMatrix<STATE> > & Ai,
						   TPZVec<STATE> & Div,
						   TPZDiffMatrix<STATE> * dDiv)
{
	int nstate = Ai[0].Cols();
	int dim = nstate - 2;
	int nshape = dphi.Cols();
	Div.Resize(nstate);
	Div.Fill(0.);
	
	int i, j, k;
	
	// computing the divergent:
	// A.du/dx + B.du/dy + C.du/dz
	for(k=0;k<dim;k++)
		for(i=0;i<nstate; i++)
			for(j=0;j<nstate;j++)
			{
				Div[i]+=Ai[k](i,j)*dsol(k,j);
			}
	
	if(!dDiv)return;
	// computing an approximation to the divergent derivative:
	
	// dDiv/dUj ~= A.d2U/dUidx + B.d2U/dUidy + C.d2U/dUidz
	dDiv->Redim(nstate, nstate * nshape);
	int l;
	REAL buff;
	for(l=0;l<nshape;l++)
		for(j=0;j<nstate;j++)
			for(i=0;i<nstate; i++)
			{
				buff =0.;
				for(k=0;k<dim;k++)
				{
					buff+=Ai[k](i,j)*dphi(k,l);
				}
				dDiv->operator()(i,j+l*nstate)=buff;
			}
	
}
Exemplo n.º 6
0
void TPZPrimalPoisson::Errors(TPZVec<REAL> &x,TPZVec<STATE> &u,TPZFMatrix<STATE> &du, TPZFMatrix<REAL> &axes, TPZVec<STATE> &flux,TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &error){
    
    error.Fill(0.0);
    //  q = - grad (p)
    du *= -1.0;
    
    /** @brief   error[0] : primal error using L2 norm */
    STATE p_error = u[0] - u_exact[0];
    error[0]  = p_error*p_error;

    /** @brief   error[1] : dual error using L2 norm */
    for(int i = 0; i < this->Dimension(); i++) {
        STATE d_error = du(i,0) - du_exact(i,0);
        error[1]  += d_error*d_error;
    }
    
    /** @brief   error[2] : H1 error norm */
    error[2]= error[1];
    
}
Exemplo n.º 7
0
void TPZMatPoissonD3::Errors(TPZVec<REAL> &x,TPZVec<STATE> &u,
							 TPZFMatrix<STATE> &dudx, TPZFMatrix<REAL> &axes, TPZVec<STATE> &/*flux*/,
							 TPZVec<STATE> &u_exact,TPZFMatrix<STATE> &du_exact,TPZVec<REAL> &values) {
	
    values.Resize(NEvalErrors());
    values.Fill(0.0);
    
    TPZManVector<STATE> sol(1),dsol(3,0.);
    Solution(u,dudx,axes,2,sol);
    Solution(u,dudx,axes,1,dsol);
    int id;
    //values[1] : eror em norma L2
    REAL  diff = fabs(sol[0] - u_exact[0]);
    values[1]  = diff*diff;
    //values[2] : erro em semi norma H1
    values[2] = 0.;
    for(id=0; id<fDim; id++) {
        diff = fabs(dsol[id] - du_exact(id,0));
        values[2]  += abs(fK)*diff*diff;
    }
    //values[0] : erro em norma H1 <=> norma Energia
    values[0]  = values[1]+values[2];
}