void TPZMaterialTest3D::Errors( TPZVec<REAL> &/*x*/,TPZVec<REAL> &u,TPZFMatrix<REAL> &dudx, TPZFMatrix<REAL> &axes, TPZVec<REAL> &/*flux*/,TPZVec<REAL> & u_exact, TPZFMatrix<REAL> &du_exact,TPZVec<REAL> &values) { //TPZVec<REAL> sol(1),dsol(3); TPZManVector<REAL> sol(1),dsol(3); Solution(u,dudx,axes,1,sol); Solution(u,dudx,axes,2,dsol); if(dudx.Rows()<3) { REAL dx = du_exact(0,0)*axes(0,0)+du_exact(1,0)*axes(0,1); REAL dy = du_exact(0,0)*axes(1,0)+du_exact(1,0)*axes(1,1); REAL parc1 = fabs(dx-dudx(0,0)); REAL parc2 = fabs(dy-dudx(1,0)); //Norma L2 values[1] = pow(fabs(u[0] - u_exact[0]),(REAL)2.0); //seminorma values[2] = pow(parc1,(REAL)2.)+pow(parc2,(REAL)2.); //Norma Energia values[0] = values[1]+values[2]; return; } //values[1] : eror em norma L2 values[1] = pow(sol[0] - u_exact[0],(REAL)2.0); //values[2] : erro em semi norma H1 values[2] = pow(dsol[0] - du_exact(0,0),(REAL)2.0); if(dudx.Rows()>1) values[2] += pow(dsol[1] - du_exact(1,0),(REAL)2.0); if(dudx.Rows()>2) values[2] += pow(dsol[2] - du_exact(2,0),(REAL)2.0); //values[0] : erro em norma H1 <=> norma Energia values[0] = values[1]+values[2]; }
/** * @brief Computes a contribution to the stiffness matrix and load vector at one integration point to multiphysics simulation * @param data [in] * @param dataleft [in] * @param dataright [in] * @param weight [in] * @param ek [out] is the stiffness matrix * @param ef [out] is the load vector * @since June 5, 2012 */ void TPZLagrangeMultiplier::ContributeInterface(TPZMaterialData &data, TPZVec<TPZMaterialData> &dataleft, TPZVec<TPZMaterialData> &dataright, REAL weight, TPZFMatrix<STATE> &ek, TPZFMatrix<STATE> &ef) { TPZFMatrix<REAL> *phiLPtr = 0, *phiRPtr = 0; for (int i=0; i<dataleft.size(); i++) { if (dataleft[i].phi.Rows() != 0) { phiLPtr = &dataleft[i].phi; break; } } for (int i=0; i<dataright.size(); i++) { if (dataright[i].phi.Rows() != 0) { phiRPtr = &dataright[i].phi; break; } } if(!phiLPtr || !phiRPtr) { DebugStop(); } TPZFMatrix<REAL> &phiL = *phiLPtr; TPZFMatrix<REAL> &phiR = *phiRPtr; int nrowl = phiL.Rows(); int nrowr = phiR.Rows(); static int count = 0; if((nrowl+nrowr)*fNStateVariables != ek.Rows() && count < 20) { std::cout<<"ek.Rows() "<< ek.Rows()<< " nrowl " << nrowl << " nrowr " << nrowr << " may give wrong result " << std::endl; count++; } int secondblock = ek.Rows()-phiR.Rows()*fNStateVariables; int il,jl,ir,jr; // 3) phi_I_left, phi_J_right for(il=0; il<nrowl; il++) { for(jr=0; jr<nrowr; jr++) { for (int ist=0; ist<fNStateVariables; ist++) { ek(fNStateVariables*il+ist,fNStateVariables*jr+ist+secondblock) += weight * fMultiplier * (phiL(il) * phiR(jr)); } } } // // 4) phi_I_right, phi_J_left for(ir=0; ir<nrowr; ir++) { for(jl=0; jl<nrowl; jl++) { for (int ist=0; ist<fNStateVariables; ist++) { ek(ir*fNStateVariables+ist+secondblock,jl*fNStateVariables+ist) += weight * fMultiplier * (phiR(ir) * phiL(jl)); } } } }
void TPZEulerConsLawDEP::ContributeBC(TPZMaterialData &data,REAL weight, TPZFMatrix &ek,TPZFMatrix &ef,TPZBndCond &bc) { TPZFMatrix dphi = data.dphix; TPZFMatrix dphiL = data.dphixl; TPZFMatrix dphiR = data.dphixr; TPZFMatrix phi = data.phi; TPZFMatrix phiL = data.phil; TPZFMatrix phiR = data.phir; TPZManVector<REAL,3> normal = data.normal; TPZManVector<REAL,3> x = data.x; // int POrder=data.p; // int LeftPOrder=data.leftp; // int RightPOrder=data.rightp; TPZVec<REAL> sol=data.sol; TPZVec<REAL> solL=data.soll; TPZVec<REAL> solR=data.solr; TPZFMatrix dsol=data.dsol; TPZFMatrix dsolL=data.dsoll; TPZFMatrix dsolR=data.dsolr; // REAL faceSize=data.HSize; int phr = phi.Rows(); short in,jn,i,j; int nstate = NStateVariables(); REAL v2[5];//m�imo nstate for(i=0;i<nstate;i++) v2[i] = bc.Val2()(i,0); switch (bc.Type()) { case 0 :// Dirichlet condition for(in = 0 ; in < phr; in++) { for(i = 0 ; i < nstate; i++) ef(in*nstate+i,0) += gBigNumber * weight * v2[i] * phi(in,0); for (jn = 0 ; jn < phr; jn++) { for(i = 0 ; i < nstate; i++) ek(in*nstate+i,jn*nstate+i) += gBigNumber * weight * phi(in,0) * phi(jn,0); } } break; case 1 :// Neumann condition for(in = 0 ; in < phi.Rows(); in++) { for(i = 0 ; i < nstate; i++) ef(in*nstate+i,0) += v2[i] * phi(in,0) * weight; } break; case 2 :// condi�o mista for(in = 0 ; in < phi.Rows(); in++) { for(i = 0 ; i < nstate; i++) ef(in*nstate+i, 0) += weight * v2[i] * phi(in, 0); for (jn = 0 ; jn < phi.Rows(); jn++) { for(i = 0 ; i < nstate; i++) for(j = 0 ; j < nstate; j++) ek(in*nstate+i,jn*nstate+j) += weight * bc.Val1()(i,j) * phi(in,0) * phi(jn,0); } } } }
void TPZBiharmonic::Solution(TPZVec<REAL> &Sol,TPZFMatrix<REAL> &DSol,TPZFMatrix<REAL> &/*axes*/, int var,TPZVec<REAL> &Solout){ if(var == 0 || var == 1) Solout[0] = Sol[0];//function if(var == 2) { Solout.Resize(DSol.Rows()); int id; for(id=0 ; id < DSol.Rows(); id++) { Solout[id] = DSol(id,0);//derivate } } }
void TPZMaterialTest::ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix<STATE> &ek, TPZFMatrix<STATE> &ef, TPZBndCond &bc) { TPZFMatrix<REAL> &phi = data.phi; if(bc.Material() != this) { PZError << "TPZMat1dLin.apply_bc warning : this material didn't create the boundary condition!\n"; } if(bc.Type() < 0 && bc.Type() > 2){ PZError << "TPZMat1dLin.aplybc, unknown boundary condition type :" << bc.Type() << " boundary condition ignored\n"; } int numdof = NStateVariables(); int numnod = ek.Rows()/numdof; int r = numdof; int idf,jdf,in,jn; switch(bc.Type()) { case 0: for(in=0 ; in<numnod ; ++in){ for(idf = 0;idf<r;idf++) { (ef)(in*r+idf,0) += gBigNumber*phi(in,0)*bc.Val2()(idf,0)*weight; } for(jn=0 ; jn<numnod ; ++jn) { for(idf = 0;idf<r;idf++) { ek(in*r+idf,jn*r+idf) += gBigNumber*phi(in,0)*phi(jn,0)*weight; } } } break; case 1: for(in=0 ; in<numnod ; ++in){ for(idf = 0;idf<r;idf++) { (ef)(in*r+idf,0) += phi(in,0)*bc.Val2()(idf,0)*weight; } } break; case 2: for(in=0 ; in<numnod ; ++in){ for(idf = 0;idf<r;idf++) { (ef)(in*r+idf,0) += phi(in,0)*bc.Val2()(idf,0)*weight; } for(jn=0 ; jn<numnod ; ++jn) { for(idf = 0;idf<r;idf++) { for(jdf = 0;jdf<r;jdf++) { ek(in*r+idf,jn*r+jdf) += bc.Val1()(idf,jdf)*phi(in,0)*phi(jn,0)*weight; } } } }//fim switch } }
inline void TPZQuadraticQuad::GradX(const TPZFMatrix<REAL> &nodes,TPZVec<T> &loc, TPZFMatrix<T> &gradx){ gradx.Resize(3,2); gradx.Zero(); int nrow = nodes.Rows(); int ncol = nodes.Cols(); #ifdef PZDEBUG if(nrow != 3 || ncol != 8){ std::cout << "Objects of incompatible lengths, gradient cannot be computed." << std::endl; std::cout << "nodes matrix must be 3x8." << std::endl; DebugStop(); } #endif TPZFNMatrix<3,T> phi(NNodes,1); TPZFNMatrix<6,T> dphi(2,NNodes); TShape(loc,phi,dphi); for(int i = 0; i < NNodes; i++) { for(int j = 0; j < 3; j++) { gradx(j,0) += nodes.GetVal(j,i)*dphi(0,i); gradx(j,1) += nodes.GetVal(j,i)*dphi(1,i); } } }
void TPZStructMatrixCS::Assemble(TPZFMatrix<STATE> & rhs,TPZAutoPointer<TPZGuiInterface> guiInterface){ ass_rhs.start(); if(fEquationFilter.IsActive()) { int64_t neqcondense = fEquationFilter.NActiveEquations(); int64_t neqexpand = fEquationFilter.NEqExpand(); if(rhs.Rows() != neqexpand || Norm(rhs) != 0.) { DebugStop(); } TPZFMatrix<STATE> rhsloc(neqcondense,1,0.); if(this->fNumThreads) { this->MultiThread_Assemble(rhsloc,guiInterface); } else { this->Serial_Assemble(rhsloc,guiInterface); } fEquationFilter.Scatter(rhsloc,rhs); } else { if(this->fNumThreads){ this->MultiThread_Assemble(rhs,guiInterface); } else{ this->Serial_Assemble(rhs,guiInterface); } } ass_rhs.stop(); }
/** * @brief It computes a contribution to stiffness matrix and load vector at one integration point * @param data [in] * @param dataleft [in] * @param dataright [in] * @param weight [in] * @param ek [out] is the stiffness matrix * @param ef [out] is the load vector * @since April 16, 2007 */ void TPZLagrangeMultiplier::ContributeInterface(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight, TPZFMatrix<STATE> &ek, TPZFMatrix<STATE> &ef) { // TPZFMatrix<REAL> &dphiLdAxes = dataleft.dphix; // TPZFMatrix<REAL> &dphiRdAxes = dataright.dphix; TPZFMatrix<REAL> &phiL = dataleft.phi; TPZFMatrix<REAL> &phiR = dataright.phi; // TPZFNMatrix<660> dphiL, dphiR; // TPZAxesTools<REAL>::Axes2XYZ(dphiLdAxes, dphiL, dataleft.axes); // TPZAxesTools<REAL>::Axes2XYZ(dphiRdAxes, dphiR, dataright.axes); int nrowl = phiL.Rows(); int nrowr = phiR.Rows(); #ifdef PZDEBUG if(phiL.Rows()*fNStateVariables+phiR.Rows()*fNStateVariables != ek.Rows()) { DebugStop(); } #endif int secondblock = ek.Rows()-phiR.Rows()*fNStateVariables; int il,jl,ir,jr; // 3) phi_I_left, phi_J_right for(il=0; il<nrowl; il++) { for(jr=0; jr<nrowr; jr++) { for (int ist=0; ist<fNStateVariables; ist++) { ek(fNStateVariables*il+ist,fNStateVariables*jr+ist+secondblock) += weight * fMultiplier * (phiL(il) * phiR(jr)); } } } // // 4) phi_I_right, phi_J_left for(ir=0; ir<nrowr; ir++) { for(jl=0; jl<nrowl; jl++) { for (int ist=0; ist<fNStateVariables; ist++) { ek(ir*fNStateVariables+ist+secondblock,jl*fNStateVariables+ist) += weight * fMultiplier * (phiR(ir) * phiL(jl)); } } } }
void TPZMaterialTest3D::Solution(TPZVec<REAL> &Sol,TPZFMatrix<REAL> &DSol, TPZFMatrix<REAL> &axes,int var,TPZVec<REAL> &Solout) { if(var == 0 || var == 1) Solout[0] = Sol[0];//function else if(var == 2) { Solout[0] = DSol(0,0);//derivate Solout[1] = DSol(1,0);//derivate if(DSol.Rows()>2) Solout[2] = DSol(2,0);//derivate } else TPZMaterial::Solution(Sol,DSol,axes,var,Solout); }
REAL TPZIncNavierStokesKEps::Dot(TPZFMatrix<REAL> &A, TPZFMatrix<REAL> &B){ REAL sum = 0.; int i, j, rows, cols; rows = A.Rows(); cols = A.Cols(); for(i = 0; i < rows; i++){ for(j = 0; j < cols; j++){ sum += A(i,j) * B(i,j); } } return sum; }
/** This function creates a Visualization Tool Kit (VTK) file that allow to visualization of the value of a matrix passed as parameter */ void VisualMatrixVTK(TPZFMatrix<REAL> & matrix, const std::string &outfilename) { const int nelx = matrix.Cols(); const int nely = matrix.Rows(); const int neltotal = nelx * nely; int i,j; ofstream out(outfilename.c_str()); out << "# vtk DataFile Version 3.0\n"; out << "Generated by PZ\n"; out << "ASCII\n"; out << "DATASET RECTILINEAR_GRID\n"; out << "DIMENSIONS " << (nelx+1) << " " << (nely+1) << " 1\n"; out << "X_COORDINATES " << nelx+1 << " float\n"; for (i=0; i<=nelx; i++) { out << i << " "; } out << std::endl; out << "Y_COORDINATES " << nely+1 << " float\n"; for (j=0; j<=nely; j++) { out << j << " "; } out << std::endl; out << "Z_COORDINATES " << 1 << " float\n0.\n"; out << "CELL_DATA " << nelx*nely << std::endl; out << "SCALARS mat_value float 1\n"; out << "LOOKUP_TABLE default\n"; const REAL *elem = &matrix(0,0); for (i=0; i<neltotal; i++) { out << *(elem+i) << std::endl; } /* # vtk DataFile Version 3.0 Cube example ASCII DATASET RECTILINEAR_GRID DIMENSIONS 3 3 1 X_COORDINATES 3 float 0. 1. 2. Y_COORDINATES 3 float 0. 1. 2. Z_COORDINATES 1 float 0. CELL_DATA 4 SCALARS toto float 1 LOOKUP_TABLE default 1 2 3 4 */ }
void TPZGeoTriangle::X(TPZFMatrix<REAL> & coord, TPZVec<REAL> & loc,TPZVec<REAL> &result) { REAL spacephi[3],spacedphi[6]; TPZFMatrix<REAL> phi(3,1,spacephi,3); TPZFMatrix<REAL> dphi(2,3,spacedphi,6); Shape(loc,phi,dphi); int space = coord.Rows(); for(int i = 0; i < space; i++) { result[i] = 0.0; for(int j = 0; j < 3; j++) result[i] += phi(j,0)*coord(i,j); } }
void TPZDohrMatrix<TVar,TSubStruct>::MultAddTBB(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z, const TVar alpha,const TVar beta,const int opt) const { #ifdef USING_TBB if ((!opt && this->Cols() != x.Rows()) || this->Rows() != x.Rows()) this->Error( "Operator* <matrixs with incompatible dimensions>" ); if(x.Cols() != y.Cols() || x.Cols() != z.Cols() || x.Rows() != y.Rows() || x.Rows() != z.Rows()) { this->Error ("TPZFMatrix::MultiplyAdd incompatible dimensions\n"); } this->PrepareZ(y,z,beta,opt); unsigned int nglob = fGlobal.size(); TPZAutoPointer<TPZDohrAssembleList<TVar> > assemblelist = new TPZDohrAssembleList<TVar>(nglob,z,this->fAssembly); ParallelAssembleTaskMatrix<TVar,TSubStruct> multwork(x,alpha,fAssembly,assemblelist); typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator iter; int isub=0; for (iter=fGlobal.begin(); iter!=fGlobal.end(); iter++,isub++) { TPZDohrThreadMultData<TSubStruct> data(isub,*iter); multwork.addWorkItem(data); } TPZVec<pthread_t> AllThreads(1); multwork.run_parallel_for(pzenviroment.fSubstructurePartitioner); PZ_PTHREAD_CREATE(&AllThreads[0], 0, TPZDohrAssembleList<TVar>::Assemble, assemblelist.operator->(), __FUNCTION__); void *result; PZ_PTHREAD_JOIN(AllThreads[0], &result, __FUNCTION__); #endif }
void TPZQuadraticQuad::X(const TPZFMatrix<REAL> &nodes,TPZVec<T> &loc,TPZVec<T> &x){ TPZFNMatrix<4,T> phi(NNodes,1); TPZFNMatrix<8,T> dphi(2,NNodes); TShape(loc,phi,dphi); int space = nodes.Rows(); for(int i = 0; i < space; i++) { x[i] = 0.0; for(int j = 0; j < NNodes; j++) { x[i] += phi(j,0)*nodes.GetVal(i,j); } } }
/** This function creates a Data Explorer file that allow to visualization of the value of a matrix passed as parameter */ void VisualMatrixDX(TPZFMatrix<REAL> & matrix, const std::string &outfilename) { const int nelx = matrix.Cols(); const int nely = matrix.Rows(); const int neltotal = nelx * nely; int i,j; ofstream out(outfilename.c_str()); out << "# Graphical Visualization of Matrix." << endl; out << "# Positions as the indexes of the matrix, beginning by column." << endl; out << "# The number of elements in x direction correspond to the number of the columns of the matrix." << endl; out << "# The number of elements in y direction correspond to the number of the rows of the matrix." << endl; out << "object 1 class gridpositions counts " << nelx+1 << " " << nely +1 << endl; out << "origin 0. 0." << endl; out << "delta 1. 0." << endl; out << "delta 0. 1." << endl; out << "attribute \"dep\" string \"positions\"" << endl; out << endl; out << "object 2 class gridconnections counts " << nelx+1 << " " << nely +1 << endl; out << "attribute \"element type\" string \"quads\"" << endl; out << "attribute \"ref\" string \"positions\"" << endl; out.precision(5); out << "object 3 class array type float rank 0 items " << neltotal << " data follows" << endl; for (i = 0; i < nelx; i++) { for(j=0; j< nely ; j++) out << matrix(i,j) << endl; } out << "attribute \"dep\" string \"connections\" " << endl; out << endl; out << "object 4 class field" << endl; out << "component \"data\" value 3" << endl; out << "component \"positions\" value 1" << endl; out << "component \"connections\" value 2" << endl; out << "attribute \"name\" string \"Matrix\"" << endl; out << endl; out << "end" << endl; out.close(); cout << "Data Explorer file " << outfilename << " was created with success!\n"; }
void TPZErrorIndicator::Sort(TPZFMatrix &error, TPZFMatrix &perm) { int i,j,k; int imin = 0; int imax = error.Rows(); perm.Resize(imax,error.Cols()); for (i=0;i<imax;i++) for (j=0;j<error.Cols();j++) perm(i,j) = i; for(i=imin; i<imax; i++) { for(j=i+1; j<imax; j++) { for (k=0;k<error.Cols();k++){ if(error((int)perm(i,k)) < error((int)perm(j,k))) { int kp = (int) perm(i,k); perm(i,k) = perm(j,k); perm(j,k) = kp; } } } } }
void TPZSkylMatrix<TVar>::MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z, const TVar alpha,const TVar beta ,const int opt,const int stride ) const { // Computes z = beta * y + alpha * opt(this)*x // z and x cannot overlap in memory if ((!opt && this->Cols()*stride != x.Rows()) || this->Rows()*stride != x.Rows()) TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__," <matrixs with incompatible dimensions>" ); if(z.Rows() != x.Rows() || z.Cols() != x.Cols()) z.Redim(x.Rows(),x.Cols()); if(x.Cols() != y.Cols() || x.Cols() != z.Cols() || x.Rows() != y.Rows() || x.Rows() != z.Rows()) { cout << "x.Cols = " << x.Cols() << " y.Cols()"<< y.Cols() << " z.Cols() " << z.Cols() << " x.Rows() " << x.Rows() << " y.Rows() "<< y.Rows() << " z.Rows() "<< z.Rows() << endl; TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__," incompatible dimensions\n"); } this->PrepareZ(y,z,beta,opt,stride); int rows = this->Rows(); int xcols = x.Cols(); int ic, r; for (ic = 0; ic < xcols; ic++) { for( r = 0 ; r < rows ; r++ ) { int offset = Size(r); TVar val = 0.; const TVar *p = &x.g((r-offset+1)*stride,ic); TVar *diag = fElem[r] + offset-1; TVar *diaglast = fElem[r]; while( diag > diaglast ) { val += *diag-- * *p; p += stride; } if( diag == diaglast ) val += *diag * *p; z(r*stride,ic) += val*alpha; TVar *zp = &z((r-offset+1)*stride,ic); val = x.g(r*stride,ic); diag = fElem[r] + offset-1; while( diag > diaglast ) { *zp += alpha * *diag-- * val; zp += stride; } } } }
void TPZGeoTriangle::Jacobian(TPZFMatrix<REAL> & coord, TPZVec<REAL> ¶m,TPZFMatrix<REAL> &jacobian,TPZFMatrix<REAL> &axes,REAL &detjac,TPZFMatrix<REAL> &jacinv) { int spacedim = coord.Rows(); jacobian.Resize(2,2); axes.Resize(2,3); jacinv.Resize(2,2); TPZFNMatrix<3> phi(3,1); TPZFNMatrix<6> dphi(2,3),axest(3,2); jacobian.Zero(); Shape(param,phi,dphi); TPZFNMatrix<6> VecMatrix(3,2,0.); for(int i = 0; i < 3; i++) { for(int j = 0; j < spacedim; j++) { VecMatrix(j,0) += coord(j,i)*dphi(0,i); VecMatrix(j,1) += coord(j,i)*dphi(1,i); } } VecMatrix.GramSchmidt(axest,jacobian); axest.Transpose(&axes); detjac = jacobian(0,0)*jacobian(1,1)-jacobian(1,0)*jacobian(0,1); if(IsZero(detjac)) { std::stringstream sout; sout << "Singular Jacobian " << detjac; LOGPZ_ERROR(logger, sout.str()) detjac = ZeroTolerance(); } if(detjac) { jacinv(0,0) = jacobian(1,1)/detjac; jacinv(1,1) = jacobian(0,0)/detjac; jacinv(0,1) = -jacobian(0,1)/detjac; jacinv(1,0) = -jacobian(1,0)/detjac; } else { jacinv.Zero(); } }
void TPZMixedDarcyFlow::ContributeBC(TPZVec<TPZMaterialData> &datavec,REAL weight,TPZFMatrix<STATE> &ef,TPZBndCond &bc){ TPZFMatrix<STATE> ekfake(ef.Rows(),ef.Rows(),0.0); this->ContributeBC(datavec, weight, ekfake, ef, bc); }
void TPZTransform::SetMatrix(TPZFMatrix<REAL> &mult, TPZFMatrix<REAL> &sum) { fRow = mult.Rows(); fCol = mult.Cols(); fMult = mult; fSum = sum; }
void TPZMaterial::ContributeBC(TPZMaterialData &data, REAL weight, TPZFMatrix<REAL> &ef, TPZBndCond &bc){ TPZFMatrix<REAL> fakeek(ef.Rows(), ef.Rows(), 0.); this->ContributeBC(data, weight, fakeek, ef, bc); }
void TPZMaterial::Contribute(TPZMaterialData &data, REAL weight, TPZFMatrix<REAL> &ef){ TPZFMatrix<REAL> fakeek(ef.Rows(), ef.Rows(), 0.); this->Contribute(data, weight, fakeek, ef); }
void TPZArtDiff::PrepareFastestDiff(TPZFMatrix<REAL> &jacinv, TPZVec<STATE> &sol, TPZFMatrix<STATE> &dsol, TPZFMatrix<REAL> &phi, TPZFMatrix<REAL> &dphi, TPZVec<TPZVec<STATE> > & TauDiv, TPZVec<TPZDiffMatrix<STATE> > & dTauDiv) { #ifdef _TFAD typedef TFad<dim+2, REAL> TFADREALdim; #endif #ifdef _FAD typedef Fad<REAL> TFADREALdim; #endif #ifdef _TINYFAD typedef TinyFad<dim+2, REAL> TFADREALdim; #endif const int nstate = sol.NElements(); const int nshape = phi.Rows(); TPZVec<TFADREALdim > FADsol(nstate); TPZVec<TPZDiffMatrix<TFADREALdim> > FADAi(dim); TPZVec<TPZDiffMatrix<REAL> > Ai(dim); TPZVec<TPZDiffMatrix<TFADREALdim> > FADTau(dim); TPZVec<TPZDiffMatrix<STATE> > Tau(dim); TPZVec<TPZVec<TFADREALdim> > FADTauDiv(dim); TFADREALdim temp; int i, j, k, l; for(i = 0; i < nstate; i++) { FADsol[i] = sol[i]; FADsol[i].diff(i, nstate); } TPZEulerConsLaw::JacobFlux(fGamma, dim, FADsol, FADAi); ComputeTau(dim, jacinv, FADsol, FADAi, FADTau); for( k = 0; k < dim; k++) { Tau[k].Redim(nstate, nstate); Ai [k].Redim(nstate, nstate); for(i = 0; i < nstate; i++) for( j = 0; j < nstate; j++) { Tau[k](i,j) = FADTau[k](i,j).val(); Ai [k](i,j) = FADAi [k](i,j).val(); } } TPZVec<STATE> Div; TPZDiffMatrix<STATE> dDiv; //Computing the divergent with derivatives Divergent(dsol, phi, dphi, FADAi, Div, &dDiv); TauDiv. Resize(dim); dTauDiv.Resize(dim); //Computing Tau * Div and DTau * Div for(k=0;k<dim;k++) { TauDiv [k].Resize(nstate); dTauDiv[k].Redim(nstate, nstate); //FADTau[k].Multiply(Div, FADTauDiv[k]); FADTauDiv[k].Resize(nstate); for(i = 0; i < nstate; i++) { temp = 0.; for(j = 0; j < nstate; j++) temp += FADTau[k](i,j) * ((REAL)Div[j]); FADTauDiv[k][i] = temp; }// // copying data using REAL dTauDiv[k].Redim(nstate, nstate * nshape); for(i = 0; i < nstate; i++) { TauDiv[k][i] = FADTauDiv[k][i].val(); for(j = 0; j < nstate; j++) { for(l = 0; l < nshape; l++) dTauDiv[k](i,l * nstate + j) = FADTauDiv[k][i].dx/*fastAccessDx*/(j) * phi(l,0); } } } TPZDiffMatrix<STATE> TaudDiv_k; // temporary storage for(k = 0; k < dim; k++) { Tau[k].Multiply(dDiv, TaudDiv_k); dTauDiv[k].Add(TaudDiv_k, 1.); } //Computing DTauDiv = DTau * Div + Tau * DDiv }
/** @brief Computing operator for the parallel for. */ void operator()(const blocked_range<size_t>& range) const { for(size_t i=range.begin(); i!=range.end(); ++i ) { TPZDohrThreadMultData<TSubStruct> runner = mWorkItems[i]; TPZFMatrix<TVar> xlocal; fAssembly->Extract(runner.fisub,*(fInput),xlocal); TPZAutoPointer<TPZDohrAssembleItem<TVar> > assembleItem = new TPZDohrAssembleItem<TVar>(runner.fisub,xlocal.Rows(),xlocal.Cols()); runner.fSub->ContributeKULocal(fAlpha,xlocal,assembleItem->fAssembleData); fAssemblyStructure->AddItem(assembleItem); } }
void *TPZDohrThreadMultList<TVar,TSubStruct>::ThreadWork(void *ptr) { TPZDohrThreadMultList<TVar,TSubStruct> *myptr = (TPZDohrThreadMultList<TVar,TSubStruct> *) ptr; TPZDohrThreadMultData<TSubStruct> runner = myptr->PopItem(); while (runner.IsValid()) { TPZFMatrix<TVar> xlocal; myptr->fAssembly->Extract(runner.fisub,*(myptr->fInput),xlocal); TPZAutoPointer<TPZDohrAssembleItem<TVar> > assembleItem = new TPZDohrAssembleItem<TVar>(runner.fisub,xlocal.Rows(),xlocal.Cols()); runner.fSub->ContributeKULocal(myptr->fAlpha,xlocal,assembleItem->fAssembleData); myptr->fAssemblyStructure->AddItem(assembleItem); runner = myptr->PopItem(); } return ptr; }
void TPZDohrMatrix<TVar,TSubStruct>::MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z, const TVar alpha,const TVar beta,const int opt) const { #ifdef USING_TBB MultAddTBB(x, y, z, alpha, beta, opt); return; #endif TPZfTime mult; if ((!opt && this->Cols() != x.Rows()) || this->Rows() != x.Rows()) this->Error( "Operator* <matrixs with incompatible dimensions>" ); if(x.Cols() != y.Cols() || x.Cols() != z.Cols() || x.Rows() != y.Rows() || x.Rows() != z.Rows()) { this->Error ("TPZFMatrix::MultiplyAdd incompatible dimensions\n"); } this->PrepareZ(y,z,beta,opt); typename SubsList::const_iterator iter; int isub = 0; if (fNumThreads == 0) { for (iter=fGlobal.begin();iter!=fGlobal.end();iter++,isub++) { if(0) { TPZPersistenceManager::OpenWrite("dohr.txt"); TPZPersistenceManager::WriteToFile(fAssembly.operator ->()); TPZPersistenceManager::WriteToFile(&x); TPZAutoPointer<TSubStruct> point(*iter); TPZPersistenceManager::WriteToFile(point.operator ->()); TPZPersistenceManager::CloseWrite(); } TPZFMatrix<TVar> xlocal,zlocal; fAssembly->Extract(isub,x,xlocal); zlocal.Redim(xlocal.Rows(),xlocal.Cols()); (*iter)->ContributeKULocal(alpha,xlocal,zlocal); fAssembly->Assemble(isub,zlocal,z); // z.Print("Resultado intermediario"); } } else { unsigned int nglob = fGlobal.size(); TPZAutoPointer<TPZDohrAssembleList<TVar> > assemblelist = new TPZDohrAssembleList<TVar>(nglob,z,this->fAssembly); TPZDohrThreadMultList<TVar,TSubStruct> multwork(x,alpha,fAssembly,assemblelist); typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator iter; int isub=0; for (iter=fGlobal.begin(); iter!=fGlobal.end(); iter++,isub++) { TPZDohrThreadMultData<TSubStruct> data(isub,*iter); multwork.AddItem(data); } TPZVec<pthread_t> AllThreads(fNumThreads+1); int i; for (i=0; i<fNumThreads; i++) { PZ_PTHREAD_CREATE(&AllThreads[i+1], 0, (TPZDohrThreadMultList<TVar,TSubStruct>::ThreadWork), &multwork, __FUNCTION__); } //sleep(1); PZ_PTHREAD_CREATE(&AllThreads[0], 0, TPZDohrAssembleList<TVar>::Assemble, assemblelist.operator->(), __FUNCTION__); for (i=0; i<fNumThreads+1; i++) { void *result; PZ_PTHREAD_JOIN(AllThreads[i], &result, __FUNCTION__); } } tempo.fMultiply.Push(mult.ReturnTimeDouble()); }
void TPZDiscontinuousGalerkin::ContributeBCInterface(TPZMaterialData &data, TPZMaterialData &dataleft, REAL weight, TPZFMatrix<REAL> &ef,TPZBndCond &bc){ TPZFMatrix<REAL> fakeek(ef.Rows(), ef.Rows(), 0.); this->ContributeBCInterface(data, dataleft, weight, fakeek, ef, bc); }
void TPZEulerConsLawDEP::Contribute(TPZMaterialData &data, REAL weight,TPZFMatrix &ef) { TPZFMatrix dphi = data.dphix; TPZFMatrix dphiL = data.dphixl; TPZFMatrix dphiR = data.dphixr; TPZFMatrix phi = data.phi; TPZFMatrix phiL = data.phil; TPZFMatrix phiR = data.phir; TPZManVector<REAL,3> normal = data.normal; TPZManVector<REAL,3> x = data.x; // int POrder=data.p; // int LeftPOrder=data.leftp; // int RightPOrder=data.rightp; TPZVec<REAL> sol=data.sol; TPZVec<REAL> solL=data.soll; TPZVec<REAL> solR=data.solr; TPZFMatrix dsol=data.dsol; TPZFMatrix dsolL=data.dsoll; TPZFMatrix dsolR=data.dsolr; // REAL faceSize=data.HSize; int phr = phi.Rows();// phi(in, 0) = phi_in , dphi(i,jn) = dphi_jn/dxi int i,nstate = NStateVariables();//3, 4 ou 5 if(fForcingFunction) { //na 2a itera�o deve-se ter fForcingFunction = 0 TPZManVector<REAL> res(nstate); fForcingFunction(x,res); for(i=0;i<nstate;i++) sol[i] = res[i]; } int dim = dphi.Rows();//dx, dy ou dz if(Dimension() != dim) PZError << "TPZEulerConsLawDEP::Contribute dimension error, dimension = " << dim << endl; //neste passo �calculada (�x/�,�y/�,�z/�) (no construtor) TPZDiffusionConsLaw diffusion(sol,fGamma,dim,fArtificialDiffusion); TPZVec<REAL> Fx(nstate),Fy(nstate),Fz(nstate); Flux(sol,Fx,Fy,Fz); TPZVec<REAL> gradphi(3,0.); TPZFMatrix Tx(nstate,nstate),Ty(nstate,nstate),Tz(nstate,nstate); TPZFMatrix DF1(nstate,nstate),DF2(nstate,nstate),DF3(nstate,nstate); diffusion.Tau(Tx,Ty,Tz); TPZFMatrix Trx(nstate,nstate),Try(nstate,nstate),Trz(nstate,nstate); Tx.Transpose(&Trx); Ty.Transpose(&Try); Tz.Transpose(&Trz); diffusion.GradientOfTheFlow(DF1,DF2,DF3); REAL timestep = TimeStep(); //REAL delta = diffusion.Delta(); //if(fDelta!= 0.) delta = diffusion.DeltaOtimo(); TPZFMatrix divF(nstate,1),prodpoint(nstate,nstate); TPZVec<REAL> sum1(nstate,0.),sum2(nstate,0.); for( int in = 0; in < phr; in++ ) { // w * Un for(i=0;i<nstate;i++) sum1[i] = phi(in, 0) * sol[i]; // grad(w) . F for(i=0;i<nstate;i++){ if(dim>0) sum2[i] = Fx[i] * dphi(0,in); if(dim>1) sum2[i] += Fy[i] * dphi(1,in); if(dim>2) sum2[i] += Fz[i] * dphi(2,in); } //EF : w * Un + deltaT * (grad(w) . F) for(i=0;i<nstate;i++) ef(in * nstate + i, 0) += weight * (sum1[i] + timestep * sum2[i]); }//in }
void TPZStepSolver<TVar>::Solve(const TPZFMatrix<TVar> &F, TPZFMatrix<TVar> &result, TPZFMatrix<TVar> *residual){ if(!this->Matrix()) { cout << "TPZMatrixSolver::Solve called without a matrix pointer\n"; DebugStop(); } TPZAutoPointer<TPZMatrix<TVar> > mat = this->Matrix(); // update the matrix to which the preconditioner refers if(fPrecond) { fPrecond->UpdateFrom(this->Matrix()); } if(result.Rows() != mat->Rows() || result.Cols() != F.Cols()) { result.Redim(mat->Rows(),F.Cols()); } if(this->fScratch.Rows() != result.Rows() || this->fScratch.Cols() != result.Cols()) { this->fScratch.Redim(result.Rows(),result.Cols()); } TVar tol = fTol; int numiterations = fNumIterations; switch(fSolver) { case TPZStepSolver::ENoSolver: default: cout << "TPZMatrixSolver::Solve called without initialized solver, Jacobi used\n"; SetJacobi(1,0.,0); case TPZStepSolver::EJacobi: // cout << "fScratch dimension " << fScratch.Rows() << ' ' << fScratch.Cols() << endl; mat->SolveJacobi(numiterations,F,result,residual,this->fScratch,tol,fFromCurrent); break; case TPZStepSolver::ESOR: mat->SolveSOR(numiterations,F,result,residual,this->fScratch,fOverRelax,tol,fFromCurrent); break; case TPZStepSolver::ESSOR: mat->SolveSSOR(numiterations,F,result,residual,this->fScratch,fOverRelax,tol,fFromCurrent); break; case TPZStepSolver::ECG: mat->SolveCG(numiterations,*fPrecond,F,result,residual,tol,fFromCurrent); #ifdef LOG4CXX { std::stringstream sout; sout << "Number of equations " << mat->Rows() << std::endl; sout << "Number of CG iterations " << numiterations << " tol = " << tol; LOGPZ_DEBUG(logger,sout.str().c_str()); } #endif break; case TPZStepSolver::EGMRES: { TPZFMatrix<TVar> H(fNumVectors+1,fNumVectors+1,0.); mat->SolveGMRES(numiterations,*fPrecond,H,fNumVectors,F,result,residual,tol,fFromCurrent); if(numiterations == fNumIterations || tol >= fTol) { std::cout << "GMRes tolerance was not achieved : numiter " << numiterations << " tol " << tol << endl; } #ifdef LOG4CXX { std::stringstream sout; sout << "Number of GMRES iterations " << numiterations << " tol = " << tol; LOGPZ_DEBUG(logger,sout.str().c_str()); } #endif } break; case TPZStepSolver::EBICGSTAB: mat->SolveBICGStab(numiterations, *fPrecond, F, result,residual,tol,fFromCurrent); if(numiterations == fNumIterations || tol >= fTol) { std::cout << "BiCGStab tolerance was not achieved : numiter " << numiterations << " tol " << tol << endl; } #ifdef LOG4CXX { std::stringstream sout; sout << "Number of BiCGStab iterations " << numiterations << " tol = " << tol; LOGPZ_DEBUG(logger,sout.str().c_str()); } #endif break; case TPZStepSolver::EDirect: result = F; mat->SolveDirect(result,fDecompose,fSingular); if(residual) residual->Redim(F.Rows(),F.Cols()); break; case TPZStepSolver::EMultiply: mat->Multiply(F,result); if(residual) mat->Residual(result,F,*residual); } }
void TPZGeoTriangle::VecHdiv(TPZFMatrix<REAL> & coord, TPZFMatrix<REAL> & fNormalVec,TPZVec<int> &fVectorSide) { if(coord.Rows()!=3) { cout<< "Erro na dimens�o das linhas de coord"<< endl; } if(coord.Cols()!=3) { cout<< "Erro na dimens�o das colunas de coord"<< endl; } TPZVec<REAL> p1(3), p2(3), p3(3),result(3); for(int j=0; j<3; j++) { p1[j]=coord(j,0); p2[j]=coord(j,1); p3[j]=coord(j,2); } fNormalVec.Resize(14, 3); fVectorSide.Resize(14); int count=0; //primeira face for(int j=0; j<3; j++) //v0 { fNormalVec(0,j) = coord(j,0)- coord(j,2); } fVectorSide[count]=0; count++; for(int j=0; j<3; j++) //v1 { fNormalVec(1,j) = coord(j,1)- coord(j,2); } fVectorSide[count]=1; count++; //v2 ComputeNormal(p1,p2,p3,result); fNormalVec(2,0) = -result[0]; fNormalVec(2,1) = -result[1]; fNormalVec(2,2) = -result[2]; fVectorSide[count]=3; count++; //segunda face for(int j=0; j<3; j++) //v3 { fNormalVec(3,j) = coord(j,1)- coord(j,0); } fVectorSide[count]=1; count++; for(int j=0; j<3; j++) //v4 { fNormalVec(4,j) = coord(j,2)- coord(j,0); } fVectorSide[count]=2; count++; //v5 ComputeNormal(p2,p3,p1,result); fNormalVec(5,0) = -result[0]; fNormalVec(5,1) = -result[1]; fNormalVec(5,2) = -result[2]; fVectorSide[count]=4; count++; //terceira face for(int j=0; j<3; j++) //v6 { fNormalVec(6,j) = coord(j,2)- coord(j,1); } fVectorSide[count]=2; count++; for(int j=0; j<3; j++) //v7 { fNormalVec(7,j) = coord(j,0)- coord(j,1); } fVectorSide[count]=0; count++; //v8 ComputeNormal(p3,p1,p2,result); fNormalVec(8,0) = -result[0]; fNormalVec(8,1) = -result[1]; fNormalVec(8,2) = -result[2]; fVectorSide[count]=5; count++; // internos tangentes for(int j=0; j<3; j++) //v9 { fNormalVec(9,j) = coord(j,1)- coord(j,0); } fVectorSide[count]=3; count++; for(int j=0; j<3; j++) //v10 { fNormalVec(10,j) = coord(j,2)- coord(j,1); } fVectorSide[count]=4; count++; for(int j=0; j<3; j++) //v11 { fNormalVec(11,j) = coord(j,0)- coord(j,2); } fVectorSide[count]=5; count++; //internos meio TPZVec<REAL> midle(3,0.); midle[0]=(1./3.)*(coord(0,2)+coord(0,0)+coord(0,1)); midle[1]=(1./3.)*(coord(1,2)+coord(1,0)+coord(1,1)); midle[2]=(1./3.)*(coord(2,2)+coord(2,0)+coord(2,1)); TPZFMatrix<REAL> jacobian; TPZFMatrix<REAL> axes; REAL detjac; TPZFMatrix<REAL> jacinv; Jacobian(coord,midle,jacobian,axes,detjac,jacinv); fNormalVec(12,0)=axes(0,0); fNormalVec(12,1)=axes(0,1); fNormalVec(12,2)=axes(0,2); fNormalVec(13,0)=axes(1,0); fNormalVec(13,1)=axes(1,1); fNormalVec(13,2)=axes(1,2); fVectorSide[count]=6; fVectorSide[count+1]=6; //normaliza��o for(int k=0; k<14; k++) { REAL temp=0.; temp=sqrt( fNormalVec(k,0)*fNormalVec(k,0) + fNormalVec(k,1)*fNormalVec(k,1) + fNormalVec(k,2)*fNormalVec(k,2)); fNormalVec(k,0) *=1./temp; fNormalVec(k,1) *=1./temp; } // produto normal == 1 for(int kk=0; kk<3; kk++) { REAL temp1=0.; REAL temp2=0.; temp1 = fNormalVec(kk*3,0)*fNormalVec(kk*3+2,0) + fNormalVec(kk*3,1)*fNormalVec(kk*3+2,1); temp2 = fNormalVec(kk*3+1,0)*fNormalVec(kk*3+2,0) + fNormalVec(kk*3+1,1)*fNormalVec(kk*3+2,1); fNormalVec(kk*3,0) *=1./temp1; fNormalVec(kk*3,1) *=1./temp1; fNormalVec(kk*3+1,0) *=1./temp2; fNormalVec(kk*3+1,1) *=1./temp2; } #ifdef LOG4CXX { std::stringstream sout; fNormalVec.Print("fNormalVec", sout); LOGPZ_DEBUG(logger,sout.str()) } #endif }