/// calcula a contribuicao para a matriz de rigidez void TPBrSteamFlux::CalcStiff(TPZVec<REAL> &leftstate, TPZVec<REAL> &rightstate, TPZVec<REAL> &interfacestate, REAL delx, REAL area, REAL delt, TPZFMatrix<REAL> &ek, TPZFMatrix<REAL> &ef) { const int totaleq = 2*TPBrCellConservation::NumCellEq+TPBrSteamFlux::NumFluxEq; TPZManVector<TFad<totaleq,REAL> , TPBrCellConservation::NumCellEq> leftcellfad(TPBrCellConservation::NumCellEq),rightcellfad(TPBrCellConservation::NumCellEq); TPZManVector<TFad<totaleq,REAL> , TPBrSteamFlux::NumFluxEq> interfacefad(TPBrSteamFlux::NumFluxEq); TPBrCellConservation::Initialize<totaleq>(leftstate,leftcellfad,0); TPBrSteamFlux::Initialize<totaleq>(interfacestate,interfacefad,TPBrCellConservation::NumCellEq); TPBrCellConservation::Initialize<totaleq>(rightstate,rightcellfad,TPBrCellConservation::NumCellEq+TPBrSteamFlux::NumFluxEq); TPZManVector<TFad<totaleq,REAL> , NumFluxEq> cellresidualfad(NumFluxEq); FluxResidual(leftcellfad, rightcellfad, interfacefad, delx, area, delt, cellresidualfad ); ek.Redim(NumFluxEq, totaleq); ef.Redim(NumFluxEq, 1); int i,j; for (i=0; i<NumFluxEq; i++) { ef(i,0) = cellresidualfad[i].val(); for (j=0; j<totaleq; j++) { ek(i,j) = cellresidualfad[i].d(j); } } #ifdef LOG4CXX { std::stringstream sout; ek.Print("Flux stiffness",sout); LOGPZ_DEBUG(logger,sout.str()) } #endif }
void TPZMatRed<TVar,TSideMatrix>::SetF(const TPZFMatrix<TVar> & F) { int64_t FCols=F.Cols(),c,r,r1; fF0.Redim(fDim0,FCols); fF1.Redim(fDim1,FCols); for(c=0; c<FCols; c++){ r1=0; for(r=0; r<fDim0; r++){ fF0.PutVal( r,c,F.GetVal(r,c) ) ; } //aqui r=fDim0 for( ;r<fDim0+fDim1; r++){ fF1.PutVal( r1++,c,F.GetVal(r,c) ); } } #ifdef LOG4CXX if (logger->isDebugEnabled()) { std::stringstream sout; F.Print("F Input",sout); fF0.Print("fF0 Initialized",sout); fF1.Print("fF1 Initialized",sout); LOGPZ_DEBUG(logger, sout.str()) }
/// calcula a contribuicao para a matriz de rigidez das equacoes de entrada void TPBrSteamFlux::InletCalcStiff(TPZVec<REAL> &rightstate, TPZVec<REAL> &interfacestate, REAL delx, REAL area, REAL delt, TPZFMatrix<REAL> &ek, TPZFMatrix<REAL> &ef) { const int totaleq = NumInletVars+NumFluxEq+TPBrCellConservation::NumCellEq; // TPZManVector<TFad<totaleq,REAL> , NumInletVars> inletfad(NumInletVars); TPZManVector<TFad<totaleq,REAL> , TPBrSteamFlux::NumFluxEq+TPBrSteamFlux::NumInletVars> interfacefad(TPBrSteamFlux::NumFluxEq+TPBrSteamFlux::NumInletVars); TPZManVector<TFad<totaleq,REAL> , TPBrCellConservation::NumCellEq> rightcellfad(TPBrCellConservation::NumCellEq); //TPBrSteamFlux::InitializeInlet<totaleq>(inletstate,inletfad,0); TPBrSteamFlux::InitializeInlet<totaleq>(interfacestate,interfacefad,0); TPBrCellConservation::Initialize<totaleq>(rightstate,rightcellfad,NumInletVars+TPBrSteamFlux::NumFluxEq); #ifdef LOG4CXX { std::stringstream sout; sout << "before calling inlet flux residual\n"; // sout << "inletfad " << inletfad << std::endl; sout << "interfacefad " << interfacefad << std::endl; sout << "rightcellfad " << rightcellfad << std::endl; LOGPZ_DEBUG(logger,sout.str()) } #endif TPZManVector<TFad<totaleq,REAL> , NumFluxEq+NumInletVars> cellresidualfad(NumFluxEq+NumInletVars); InletFluxResidual(rightcellfad, interfacefad, delx, area, delt, cellresidualfad ); #ifdef LOG4CXX { std::stringstream sout; sout << "cellresidual " << cellresidualfad; LOGPZ_DEBUG(logger, sout.str()) } #endif ek.Redim(NumFluxEq+NumInletVars, totaleq); ef.Redim(NumFluxEq+NumInletVars, 1); int i,j; for (i=0; i<NumFluxEq+NumInletVars; i++) { ef(i,0) = cellresidualfad[i].val(); for (j=0; j<totaleq; j++) { ek(i,j) = cellresidualfad[i].d(j); } } #ifdef LOG4CXX { std::stringstream sout; ek.Print("Inlet stiffness",sout); LOGPZ_DEBUG(logger,sout.str()) } #endif }
void TPZDarcyAnalysis::PrintLS(TPZAnalysis *an) { TPZAutoPointer< TPZMatrix<REAL> > KGlobal; TPZFMatrix<STATE> FGlobal; KGlobal = an->Solver().Matrix(); FGlobal = an->Rhs(); #ifdef PZDEBUG #ifdef LOG4CXX if(logger->isDebugEnabled()) { std::stringstream sout; KGlobal->Print("KGlobal = ", sout,EMathematicaInput); FGlobal.Print("FGlobal = ", sout,EMathematicaInput); LOGPZ_DEBUG(logger,sout.str()) }
void TPZFrontNonSym::main() { int i, j; /** * Populates data structure */ int matsize=6; TPZFMatrix<REAL> TestMatrix(matsize,matsize); for(i=0;i<matsize;i++) { for(j=i;j<matsize;j++) { int random = rand(); double rnd = (random*matsize)/0x7fff; TestMatrix(i,j)=rnd; TestMatrix(j,i)=TestMatrix(i,j); if(i==j) TestMatrix(i,j)=6000.; } } TPZFMatrix<REAL> Prova; Prova=TestMatrix; // Prova.Decompose_Cholesky(); Prova.Print("TPZFMatrix<REAL> Cholesky"); TPZFrontNonSym TestFront(matsize); TPZVec<int> DestIndex(matsize); for(i=0;i<matsize;i++) DestIndex[i]=i; TestFront.SymbolicAddKel(DestIndex); TestFront.SymbolicDecomposeEquations(0,matsize-1); std::string OutFile; OutFile = "TPZFrontNonSymTest.txt"; ofstream output(OutFile.c_str(),ios::app); TestFront.Compress(); TestFront.AllocData(); TestFront.AddKel(TestMatrix, DestIndex); TPZEqnArray Result; /*TestFront.DecomposeEquations(0,0,Result); TestFront.Print(OutFile, output); ofstream outeqn("TestEQNArray.txt",ios::app); Result.Print("TestEQNArray.txt",outeqn); TestFront.Compress(); TestFront.Print(OutFile, output); */ TestFront.DecomposeEquations(0,matsize-1,Result); ofstream outeqn("TestEQNArray.txt",ios::app); Result.Print("TestEQNArray.txt",outeqn); TPZFMatrix<REAL> Load(matsize); for(i=0;i<matsize;i++) { int random = rand(); double rnd = (random*matsize)/0x7fff; Load(i,0)=rnd; } TPZFMatrix<REAL> Load_2(matsize); Load_2=Load; // Prova.Subst_Forward(&Load); // Prova.Subst_Backward(&Load); DecomposeType decType = ECholesky; Prova.SolveDirect(Load, decType); Load.Print(); //TestFront.Print(OutFile, output); Result.EqnForward(Load_2, decType); Result.EqnBackward(Load_2, decType); Load_2.Print("Eqn"); }
void TPZMaterialCoupling::ContributeInterface2(TPZMaterialData &data, TPZMaterialData &dataleft, TPZMaterialData &dataright, REAL weight,TPZFMatrix<REAL> &ek,TPZFMatrix<REAL> &ef){ // TPZFMatrix<REAL> &dphixL = dataleft.dphix; TPZFMatrix<REAL> &phixL = dataleft.phi; TPZFMatrix<REAL> &phixR = dataright.phi; int numvec=dataright.fVecShapeIndex.NElements(); int nrowR=phixR.Rows();//funcao a direita Hdiv int nrowL=phixL.Rows();//Funcao a esquerda H1 int numdual = dataright.numberdualfunctions; std::cout << "numero de funcoes de Hdiv( direita ) " << nrowR<<std::endl; std::cout << "numero de funcoes de de pressao(direita) " << numdual<<std::endl; std::cout << "numero de funcoes de H1 (esquerda ) " << nrowL<<std::endl; #ifdef LOG4CXX { std::stringstream sout; sout << "numero de funcoes de Hdiv( direita ) " << nrowR<<std::endl; sout << "numero de funcoes de de pressao(direita) " << numdual<<std::endl; sout << "numero de funcoes de H1 (esquerda ) " << nrowL<<std::endl; LOGPZ_DEBUG(logger, sout.str().c_str()); } #endif /* for(int ir=0; ir<nrowL; ir++) { for(int jl=0; jl<nrowL; jl++) { REAL prod1 = phixL(ir)* phixL(jl); } } */ for(int ir=0; ir<nrowR-1; ir++) { // int ivecind = dataright.fVecShapeIndex[ir].first; int ishapeind = dataright.fVecShapeIndex[ir].second; for(int jl=0; jl<nrowL; jl++) { REAL prod1 = phixR(ishapeind,0)* phixL(jl); #ifdef LOG4CXX { std::stringstream sout; sout << "produto das phis " << prod1<<std::endl; LOGPZ_DEBUG(logger, sout.str().c_str()); } #endif ek(ir,numvec+jl) += weight * prod1; ek(numvec+jl,ir) += weight *(-prod1); } } #ifdef LOG4CXX { std::stringstream sout; ek.Print("Matriz de Acoplamento",sout); LOGPZ_DEBUG(logger, sout.str().c_str()); } #endif }
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 }
void TPZMaterialTest::Flux(TPZVec<REAL> &x, TPZVec<STATE> &Sol, TPZFMatrix<STATE> &DSol, TPZFMatrix<REAL> &axes, TPZVec<STATE> &flux) { if(fabs(axes(2,0)) >= 1.e-6 || fabs(axes(2,1)) >= 1.e-6) { cout << "TPZMaterialTest::Flux only serves for xy configuration\n"; axes.Print("axes"); } }
int main1(int argc, char *argv[]) { #ifdef LOG4CXX InitializePZLOG(); #endif TPZTimer total; total.start(); std::cout << "COMECA O TEMPO"<< std::endl; int dimension = 3; int dim = 2; int maxlevel = 5; int sublevel = 3; int plevel = 1; TPZPairStructMatrix::gNumThreads = 20; int numthreads = 20; // tempo.fNumthreads = numthreads; // alimenta timeTemp com o numero de threads TPZGeoMesh *gmesh = 0; { TPZCompEl::SetgOrder(plevel); TPZAutoPointer<TPZCompMesh> cmesh; if(0) { TPZGenSubStruct sub(dim,maxlevel,sublevel); cmesh = sub.GenerateMesh(); cmesh->SetDimModel(dim); gmesh = cmesh->Reference(); } else { dim = 3; if (1) // Predio Viscoso { int dimension = 3; gmesh = MalhaPredio(); cmesh = new TPZCompMesh(gmesh); cmesh->SetDimModel(3); cmesh->SetDefaultOrder(plevel); cmesh->SetAllCreateFunctionsContinuousWithMem(dimension); InsertViscoElasticity(cmesh); cmesh->AutoBuild(); } else // Cubo Viscoso { int dimension = 3; gmesh = MalhaCubo(); cmesh = new TPZCompMesh(gmesh); cmesh->SetDimModel(3); cmesh->SetDefaultOrder(plevel); cmesh->SetAllCreateFunctionsContinuousWithMem(dimension); InsertViscoElasticityCubo(cmesh); cmesh->AutoBuild(); } } std::cout << "Numero de equacoes " << cmesh->NEquations() << std::endl; int numthread_assemble = 20; int numthread_decompose = 20; TPZAutoPointer<TPZCompMesh> cmeshauto(cmesh); TPZDohrStructMatrix dohrstruct(cmeshauto); dohrstruct.IdentifyExternalConnectIndexes(); std::cout << "Substructuring the mesh\n"; // TPZfTime timetosub; // init of timer //REAL height = Height(gmesh); //int nsubstruct = SubStructure(cmesh, height/2); dohrstruct.SubStructure(16); // tempo.ft0sub = timetosub.ReturnTimeDouble(); // end of timer // std::cout << tempo.ft0sub << std::endl; // sub.SubStructure(); //Teste Skyline /* TPZSkylineStructMatrix skyl(cmesh); TPZFMatrix<REAL> rhsfake(cmesh->NEquations(),1,0); int numsubmesh = cmesh->NElements(); TPZAutoPointer<TPZGuiInterface> fakegui = new TPZGuiInterface; int nel = cmesh->NElements(); for (int iel = 0 ; iel < nel ; iel++) { TPZSubCompMesh *subcompmesh = dynamic_cast<TPZSubCompMesh*>(cmesh->ElementVec()[iel]); if(subcompmesh) { subcompmesh->SetAnalysisSkyline(0,0,fakegui); } } TPZMatrix<REAL> *stiff2 = skyl.CreateAssemble(rhsfake, fakegui,numthread_assemble,numthread_decompose); */ #ifdef LOG4CXX { std::stringstream str; cmesh->Print(str); LOGPZ_DEBUG(logger,str.str()); } #endif dohrstruct.SetNumThreads(numthreads); TPZAutoPointer<TPZGuiInterface> gui; TPZFMatrix<STATE> rhs(cmesh->NEquations(),1,0.); TPZMatrix<STATE> *matptr = dohrstruct.Create(); dohrstruct.Assemble(*matptr,rhs,gui,numthread_assemble,numthread_decompose); TPZAutoPointer<TPZMatrix<STATE> > dohr = matptr; TPZAutoPointer<TPZMatrix<STATE> > precond = dohrstruct.Preconditioner(); { std::ofstream out("DohrCerta2.txt"); TPZFMatrix<REAL> Subtract(dohr->Rows(),dohr->Rows()), unitary(dohr->Rows(),dohr->Rows()); unitary.Identity(); TPZFMatrix<REAL> result; dohr->Multiply(unitary, result); result.Print("DohrCerta2", out); } /* #ifdef LOG4CXX { std::ofstream out("DohrErrada.txt"), outRhsCerto("RhsSkyl.txt"), outRhsErrado("RhsDohrmann.txt"); TPZFMatrix<REAL> Subtract(dohr->Rows(),dohr->Rows()), unitary(dohr->Rows(),dohr->Rows()); unitary.Identity(); TPZFMatrix<REAL> result; dohr->Multiply(unitary, result); std::ofstream out2("Dohr_Certa.txt"); result.Print("DohrCerta",out2); for (int i = 0 ; i < dohr->Rows(); i++) { for (int j = 0 ; j < dohr->Rows(); j++) { double temp = result(i,j) - stiff2->Get(i,j); if (temp < 1e-10) { temp = 0; } Subtract(i,j) = temp; } } std::stringstream str; result.Print("DohrmannErrada", out); stiff2->Print("Skyl",out); Subtract.Print("Subtract", out); rhsfake.Print("RhsSkyl", outRhsCerto); rhs.Print("RhsDohrmann", outRhsErrado); LOGPZ_DEBUG(logger,str.str()); } #endif */ int neq = dohr->Rows(); TPZFMatrix<STATE> diag(neq,1,0.), produto(neq,1); std::cout << "Numero de equacoes " << neq << std::endl; TPZStepSolver<STATE> pre(precond); pre.SetMultiply(); TPZStepSolver<STATE> cg(dohr); // void SetCG(const int numiterations,const TPZMatrixSolver &pre,const STATE tol,const int FromCurrent); cg.SetCG(500,pre,5.e-6,0); cg.Solve(rhs,diag); diag.Print("diag"); TPZDohrMatrix<STATE,TPZDohrSubstructCondense<STATE> > *dohrptr = dynamic_cast<TPZDohrMatrix<STATE,TPZDohrSubstructCondense<STATE> > *> (dohr.operator->()); if (!dohrptr) { DebugStop(); } dohrptr->AddInternalSolution(diag); TPZMaterial * mat = cmeshauto->FindMaterial(1); int nstate = mat->NStateVariables(); int nscal = 0, nvec = 0; if(nstate ==1) { nscal = 1; } else { nvec = 1; } TPZManVector<std::string> scalnames(nscal),vecnames(nvec); if(nscal == 1) { scalnames[0]="state"; } else { vecnames[0] = "state"; } //cmeshauto->Solution().Print(); std::string postprocessname("ugabuga.vtk"); TPZVTKGraphMesh vtkmesh(cmesh.operator->(),dim,mat,scalnames,vecnames); vtkmesh.SetFileName(postprocessname); vtkmesh.SetResolution(0); int numcases = 1; // Iteracoes de tempo int istep = 0, nsteps = 80; vtkmesh.DrawMesh(numcases); vtkmesh.DrawSolution(istep, 1.); typedef std::list<TPZAutoPointer<TPZDohrSubstructCondense<STATE> > > subtype; const subtype &sublist = dohrptr->SubStructures(); subtype::const_iterator it = sublist.begin(); int subcount=0; while (it != sublist.end()) { TPZFMatrix<STATE> subext,subu; dohrptr->fAssembly->Extract(subcount,diag,subext); (*it)->UGlobal(subext,subu); TPZCompMesh *submesh = SubMesh(cmeshauto, subcount); submesh->LoadSolution(subu); subu.Print(); std::map<int ,TPZMaterial * > materialmap(submesh->MaterialVec()); std::map<int ,TPZMaterial * >::iterator itmat; for (itmat = materialmap.begin(); itmat != materialmap.end() ; itmat++) { TPZMaterial * mat = itmat->second; TPZViscoelastic *vmat = dynamic_cast< TPZViscoelastic *> (mat); if(vmat) { vmat->SetUpdateMem(); } } subcount++; it++; } /* #ifdef LOG4CXX { std::stringstream sout; diag.Print("Resultado do processo iterativo",sout); LOGPZ_INFO(loggernathan,sout.str()) } #endif */ //ViscoElastico vtkmesh.DrawMesh(numcases); vtkmesh.DrawSolution(istep+1, 1.); std::cout << "To seguindo!!!" << std::endl; for (istep = 2 ; istep < nsteps ; istep++) { TPZAutoPointer<TPZGuiInterface> guifake; dohrstruct.Assemble(rhs, guifake); cg.Solve(rhs,diag); dohrptr->AddInternalSolution(diag); // Colocando a solucao na malha typedef std::list<TPZAutoPointer<TPZDohrSubstructCondense<STATE> > > subtype; const subtype &sublist = dohrptr->SubStructures(); subtype::const_iterator it = sublist.begin(); int subcount=0; while (it != sublist.end()) { TPZFMatrix<STATE> subext,subu; dohrptr->fAssembly->Extract(subcount,diag,subext); (*it)->UGlobal(subext,subu); TPZCompMesh *submesh = SubMesh(cmeshauto, subcount); submesh->LoadSolution(subu); subcount++; it++; } vtkmesh.DrawMesh(numcases); vtkmesh.DrawSolution(istep, 1.); } } total.stop(); std::cout << "TEMPO = " << total.seconds() << std::endl; delete gmesh; return EXIT_SUCCESS; }
void SolveSystemTransient(REAL deltaT,REAL maxTime, TPZAnalysis *NonLinearAn, TPZCompMesh* CMesh) { TPZFMatrix<STATE> Patn; TPZFMatrix<STATE> PatnMinusOne; // { // TPZBFileStream load; // load.OpenRead("MultiphaseSaturationSol.bin"); // SolutiontoLoad.Read(load,0); // meshvec[2]->LoadSolution(SolutiontoLoad); // TPZBuildMultiphysicsMesh::TransferFromMeshes(meshvec, mphysics); // } std::string OutPutFile = "WaveSolution"; TPZMaterial *mat1 = CMesh->FindMaterial(1); TPZLinearWave * material1 = dynamic_cast<TPZLinearWave *>(mat1); // TPZMultiphase * material2 = dynamic_cast<TPZMultiphase *>(mat2); material1->SetTimeStep(deltaT); // Starting Newton Iterations TPZFMatrix<STATE> DeltaX = CMesh->Solution(); TPZFMatrix<STATE> Uatn = CMesh->Solution(); TPZFMatrix<STATE> Uatk = CMesh->Solution(); REAL TimeValue = 0.0; REAL Tolerance = 1.0e-7; int cent = 0; int MaxIterations = 50; TimeValue = cent*deltaT; REAL NormValue =1.0; bool StopCriteria = false; TPZFMatrix<STATE> RhsAtnMinusOne, RhsAtn, RhsAtnPlusOne, Residual; std::string outputfile; outputfile = OutPutFile; std::stringstream outputfiletemp; outputfiletemp << outputfile << ".vtk"; std::string plotfile = outputfiletemp.str(); PosProcess(material1->Dimension(),*NonLinearAn,outputfile,2); std::cout << " Starting the time computations. " << std::endl; while (TimeValue < maxTime) { material1->SetMinusOneState(); CMesh->LoadSolution(PatnMinusOne); NonLinearAn->AssembleResidual(); RhsAtnMinusOne = NonLinearAn->Rhs(); material1->SetNState(); CMesh->LoadSolution(Patn); NonLinearAn->AssembleResidual(); RhsAtn = NonLinearAn->Rhs(); material1->SetPlusOneState(); CMesh->LoadSolution(Patn); NonLinearAn->Assemble(); RhsAtnPlusOne = NonLinearAn->Rhs(); Residual= RhsAtnMinusOne + RhsAtn + RhsAtnPlusOne; NormValue = Norm(Residual); int iterations= 0; while (NormValue > Tolerance) { Residual*=-1.0; NonLinearAn->Rhs()=Residual; NonLinearAn->Solve(); DeltaX = NonLinearAn->Solution(); Uatk = (Uatn + DeltaX); CMesh->LoadSolution(Uatn + DeltaX); #ifdef LOG4CXX if(logdata->isDebugEnabled()) { std::stringstream sout; sout.precision(20); Residual.Print(sout); Uatk.Print(sout); LOGPZ_DEBUG(logdata,sout.str()); } #endif material1->SetPlusOneState(); NonLinearAn->Assemble(); RhsAtnPlusOne = NonLinearAn->Rhs(); Residual= RhsAtnMinusOne + RhsAtn + RhsAtnPlusOne; NormValue = Norm(Residual); #ifdef LOG4CXX if(logdata->isDebugEnabled()) { std::stringstream sout; sout.precision(15); Uatk.Print(sout); Residual.Print("Res = ",sout,EMathematicaInput); LOGPZ_DEBUG(logdata,sout.str()); } #endif iterations++; std::cout << " Newton's Iteration = : " << iterations << " L2 norm = : " << NormValue << std::endl; if (iterations == MaxIterations) { StopCriteria = true; std::cout << " Time Step number = : " << iterations << "\n Exceed max iterations numbers = : " << MaxIterations << std::endl; break; } Uatn = Uatk; } outputfile = OutPutFile; std::stringstream outputfiletemp; outputfiletemp << outputfile << ".vtk"; std::string plotfile = outputfiletemp.str(); PosProcess(material1->Dimension(),*NonLinearAn,outputfile,2); if (StopCriteria) { std::cout << " Newton's Iteration = : " << iterations << " L2 norm = : " << NormValue << std::endl; break; } cent++; TimeValue = cent*deltaT; std::cout << " Time Step : " << cent << " Time : " << TimeValue << std::endl; PatnMinusOne = Patn; Patn = Uatk; } }