void Solve ( TPZAnalysis &an ){ TPZCompMesh *malha = an.Mesh(); //TPZBandStructMatrix mat(malha); //TPZSkylineStructMatrix mat(malha);// requer decomposição simétrica, não pode ser LU! //TPZBlockDiagonalStructMatrix mat(malha);//ok! //TPZFrontStructMatrix<TPZFrontNonSym> mat ( malha );// não funciona com método iterativo TPZFStructMatrix mat( malha );// ok! matriz estrutural cheia //TPZSpStructMatrix mat( malha );//matriz estrutural esparsa (???? NÃO FUNCIONOU !!!!!!!!!!) TPZStepSolver<STATE> solv; solv.SetDirect ( ELU );//ECholesky);// ELU , ELDLt , // cout << "ELDLt " << endl; an.SetSolver ( solv ); an.SetStructuralMatrix ( mat ); cout << endl; an.Solution().Redim ( 0,0 ); cout << "Assemble " << endl; an.Assemble(); // std::ofstream fileout("rigidez.txt"); // an.Solver().Matrix()->Print("Rigidez", fileout, EMathematicaInput); // an.Solve(); // cout << endl; // cout << "No equacoes = " << malha->NEquations() << endl; }
void SolveSyst(TPZAnalysis &an, TPZCompMesh *Cmesh) { TPZSkylineStructMatrix full(Cmesh); an.SetStructuralMatrix(full); TPZStepSolver<STATE> step; step.SetDirect(ELDLt); //step.SetDirect(ELU); an.SetSolver(step); an.Run(); }
void TPZAnalysis::Solve() { int numeq = fCompMesh->NEquations(); if(fRhs.Rows() != numeq ) return; TPZFMatrix<REAL> residual(fRhs); TPZFMatrix<REAL> delu(numeq,1,0.); /* if(fSolution.Rows() != numeq) { fSolution.Redim(numeq,1); } else { fSolver->Matrix()->Residual(fSolution,fRhs,residual); }*/ // REAL normres = Norm(residual); // cout << "TPZAnalysis::Solve residual : " << normres << " neq " << numeq << endl; #ifdef LOG4CXX_KEEP { std::stringstream sout; sout << "Residual norm " << Norm(residual) << std::endl; residual.Print("Residual",sout); LOGPZ_DEBUG(logger,sout.str()) } #endif fSolver->Solve(residual, delu); #ifdef LOG4CXX { std::stringstream sout; TPZStepSolver<REAL> *step = dynamic_cast<TPZStepSolver<REAL> *> (fSolver); if(!step) DebugStop(); int nsing = step->Singular().size(); sout << "Number of singular equations " << nsing; std::list<int>::iterator it = step->Singular().begin(); if(nsing) sout << "\nSingular modes "; while(it != step->Singular().end()) { sout << *it << " "; it++; } if(nsing) sout << std::endl; LOGPZ_WARN(logger,sout.str()) } #endif #ifdef LOG4CXX_KEEP { std::stringstream sout; sout << "Solution norm " << Norm(delu) << std::endl; delu.Print("delu",sout); LOGPZ_DEBUG(logger,sout.str()) } #endif fSolution = delu; fCompMesh->LoadSolution(fSolution); }
TPZAnalysis * Analysis(TPZCompMesh * cmesh, int n_threads){ TPZAnalysis * analysis = new TPZAnalysis(cmesh,true); // TPZSkylineStructMatrix matrix(cmesh); // TPZSymetricSpStructMatrix matrix(cmesh); TPZSpStructMatrix matrix(cmesh); TPZStepSolver<STATE> step; step.SetDirect(ELU); matrix.SetNumThreads(n_threads); analysis->SetStructuralMatrix(matrix); analysis->SetSolver(step); return analysis; }
void TPZMulticamadaOrthotropic::ComputeSolution(std::ostream &out,int print){ TPZAnalysis an(fCompMesh); TPZSkylineStructMatrix skyl(fCompMesh); an.SetStructuralMatrix(skyl); TPZStepSolver<REAL> solve; solve.SetDirect(ELDLt); an.SetSolver(solve); an.Solution().Zero(); an.Run(); if(print) an.Print("* PRINT ANALISYS *",out); }
void TPZMulticamadaOrthotropic::ComputeSolution(TPZMaterial *mat,std::ofstream &out,int numiter){ TPZAnalysis an(fCompMesh); TPZSkylineStructMatrix skyl(fCompMesh); an.SetStructuralMatrix(skyl); TPZStepSolver<REAL> solve; solve.SetDirect(ELDLt); an.SetSolver(solve); an.Solution().Zero(); TPZVec<std::string> scalar(3),vector(0); scalar[0] = "SigX"; scalar[1] = "SigY"; scalar[2] = "TauXY"; TPZCompMesh *cmesh = an.Mesh(); int dim = mat->Dimension(); TPZDXGraphMesh graph(cmesh,dim,mat,scalar,vector); cout << "\nmain::ComputeSolution out file : MultCam.dx\n"; graph.SetFileName("MultCam.dx"); int resolution = 0; graph.SetResolution(resolution); graph.DrawMesh(dim); int iter = 0,draw=0; an.Solution().Zero(); an.Run(); ComputeCenterForces(); PrintCenterForces(out); PrintTensors(out); cout << "Iteracao = " << ++iter << endl; an.LoadSolution(); REAL time = 0.0; graph.DrawSolution(draw++,time); while(iter < numiter) { an.Solution().Zero(); an.Run(); ComputeCenterForces(); PrintCenterForces(out); PrintTensors(out); an.LoadSolution(); time += 0.1; graph.DrawSolution(draw++,time); cout << "Iteracao = " << ++iter << endl; } out.flush(); an.LoadSolution(); }
void TPZAnalysis::AnimateRun(int num_iter, int steps, TPZVec<std::string> &scalnames, TPZVec<std::string> &vecnames, const std::string &plotfile) { Assemble(); int numeq = fCompMesh->NEquations(); if(fRhs.Rows() != numeq ) return; TPZFMatrix<REAL> residual(fRhs); int dim = HighestDimension(); TPZAutoPointer<TPZMaterial> mat = 0; std::map<int, TPZAutoPointer<TPZMaterial> >::iterator matit; for(matit = fCompMesh->MaterialVec().begin(); matit != fCompMesh->MaterialVec().end(); matit++) { TPZBndCond *bc = dynamic_cast<TPZBndCond *>(matit->second.operator->()); if(bc) continue; if( matit->second->Dimension() == dim) { mat = matit->second; break; } } if(!mat) { std::cout << __PRETTY_FUNCTION__ << " no material found " << std::endl; LOGPZ_ERROR(logger, " no material found"); return; } TPZDXGraphMesh gg(fCompMesh,dim,mat,scalnames,vecnames) ; // TPZV3DGrafGrid gg(fCompMesh) ; gg.SetFileName(plotfile); gg.SetResolution(0); gg.DrawMesh(num_iter); int i; for(i=1; i<=num_iter;i+=steps){ TPZStepSolver<REAL> sol; sol.ShareMatrix(Solver()); sol.SetJacobi(i,0.,0); SetSolver(sol); // Solver().SetNumIterations(i); fSolver->Solve(fRhs, fSolution); fCompMesh->LoadSolution(fSolution); gg.DrawSolution(i-1,0); } }
void SolveSyst(TPZAnalysis &an, TPZCompMesh *fCmesh, int numthreads) { //TPZBandStructMatrix full(fCmesh); TPZSkylineStructMatrix full(fCmesh); //caso simetrico full.SetNumThreads(numthreads); an.SetStructuralMatrix(full); TPZStepSolver<STATE> step; step.SetDirect(ELDLt); //caso simetrico //step.SetDirect(ELU); an.SetSolver(step); an.Run(); //Saida de Dados: solucao e grafico no VT // ofstream file("Solutout"); // an.Solution().Print("solution", file); //Solution visualization on Paraview (VTK) }
void Run(int PolynomialOrder, int Href, std::string GeoGridFile, int div) { int pOrder = PolynomialOrder; TPZReadGIDGrid myreader; TPZGeoMesh * gmesh = myreader.GeometricGIDMesh(GeoGridFile); { // Print Geometrical Base Mesh std::ofstream arg1("BaseGeoMesh.txt"); gmesh->Print(arg1); std::ofstream file1("BaseGeoMesh.vtk"); // In this option true -> let you use shrink paraview filter // PrintGMeshVTK(gmesh,file1); TPZVTKGeoMesh::PrintGMeshVTK(gmesh,file1, true); } // Modifying Geometric Mesh RefinamentoUniforme(gmesh, Href); { // Print Geometrical refined Base Mesh std::ofstream arg1("RefineGeoMesh.txt"); gmesh->Print(arg1); std::ofstream file1("RefineGeoMesh.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh,file1, true); } TPZCompMesh * cmesh = ComputationalMesh(gmesh,PolynomialOrder); TPZAnalysis *MyAnalysis = new TPZAnalysis(cmesh); TPZSkylineStructMatrix strskyl(cmesh); MyAnalysis->SetStructuralMatrix(strskyl); TPZStepSolver<STATE> direct; direct.SetDirect(ELDLt); MyAnalysis->SetSolver(direct); REAL deltaT = 0.5; REAL maxTime = 10.0; SolveSystemTransient(deltaT, maxTime, MyAnalysis,cmesh); // MyAnalysis->Run(); // std::string plotfile("MyProblemSolution.vtk"); // PosProcess(myreader.fProblemDimension,*MyAnalysis, plotfile, div); }
void SolveSist(TPZAnalysis &an, TPZCompMesh *fCmesh) { // Symmetric case TPZSkylineStructMatrix full(fCmesh); an.SetStructuralMatrix(full); an.Solution().Zero(); TPZStepSolver<REAL> step; step.SetDirect(ELDLt); an.SetSolver(step); an.Run(); // Nonsymmetric case // TPZBandStructMatrix full(fCmesh); // an.SetStructuralMatrix(full); // TPZStepSolver step; // step.SetDirect(ELU); // an.SetSolver(step); // an.Run(); }
void ResolverSistema(TPZAnalysis &an, TPZCompMesh *fCmesh, bool symmetric_matrix) { if(symmetric_matrix ==true){ TPZSkylineStructMatrix skmat(fCmesh); an.SetStructuralMatrix(skmat); TPZStepSolver<STATE> direct; direct.SetDirect(ELDLt); an.SetSolver(direct); } else{ TPZBandStructMatrix bdmat(fCmesh); an.SetStructuralMatrix(bdmat); TPZStepSolver<STATE> direct; direct.SetDirect(ELU); an.SetSolver(direct); } an.Run(); //Saida de Dados: solucao txt ofstream file("Solution.out"); an.Solution().Print("solution", file); }
int main(/*int argc, char *argv[]*/) { InitializePZLOG(); gRefDBase.InitializeUniformRefPattern(EOned); gRefDBase.InitializeUniformRefPattern(EQuadrilateral); gRefDBase.InitializeUniformRefPattern(ETriangle); int p =1; int ndiv = 1; TPZGeoMesh *gmesh = GMesh(false, 1, 1); UniformRefine( gmesh,ndiv); ofstream filegmesh1("gmes.txt"); gmesh->Print(filegmesh1); TPZCompMesh *cmesh1 = MeshH1(gmesh, p, 2,true);//malha para y(estado) ofstream filemesh1("malhaY.txt"); cmesh1->Print(filemesh1); TPZCompMesh *cmesh2 = MeshL2(gmesh, p, 2);//malha para controle(u) ofstream filemesh2("malhaU.txt"); cmesh2->Print(filemesh2); TPZCompMesh *cmesh3 = MeshH1(gmesh, p, 2,false);//malha para mult.lagrange(p) ofstream filemesh3("malhaP.txt"); cmesh3->Print(filemesh3); TPZManVector<TPZCompMesh *,3> meshvec(3); meshvec[0] = cmesh1; meshvec[1] = cmesh2; meshvec[2] = cmesh3; TPZCompMesh * mphysics = MalhaMultifisicaOpt(meshvec, gmesh); ofstream filemesh4("malhaMulti.txt"); mphysics->Print(filemesh4); //Resolver problema TPZAnalysis analysis(mphysics,false); //TPZParFrontStructMatrix<TPZFrontSym<STATE> > strmat(mphysics); //strmat.SetDecomposeType(ELDLt); TPZSkylineStructMatrix strmat(mphysics); //strmat.SetNumThreads(6); analysis.SetStructuralMatrix(strmat); TPZStepSolver<STATE> step; step.SetDirect(ELDLt); //caso simetrico analysis.SetSolver(step); analysis.Assemble(); analysis.Solve(); std::ofstream out("SolOpt.txt"); analysis.Solution().Print("Solucao",out); //Post-Process TPZBuildMultiphysicsMesh::TransferFromMultiPhysics(meshvec, mphysics); TPZManVector<std::string,10> scalnames(4), vecnames(0); scalnames[0] = "State"; scalnames[1] = "Control"; scalnames[2]="LagrangeMult"; scalnames[3]="ExactState"; std::stringstream name; name << "Solution_Opt" <<ndiv<< ".vtk"; std::string paraviewfile(name.str()); analysis.DefineGraphMesh(2,scalnames,vecnames,paraviewfile); analysis.PostProcess(0); //visualizar matriz no vtk // TPZFMatrix<REAL> vismat(100,100); // mphysics->ComputeFillIn(100,vismat); // VisualMatrixVTK(vismat,"matrixstruct.vtk"); return EXIT_SUCCESS; }
void TPZDarcyAnalysis::Run() { std::string dirname = PZSOURCEDIR; // gRefDBase.InitializeUniformRefPattern(EOned); // gRefDBase.InitializeUniformRefPattern(EQuadrilateral); // gRefDBase.InitializeUniformRefPattern(ETriangle); // gRefDBase.InitializeUniformRefPattern(ECube); #ifdef PZDEBUG #ifdef LOG4CXX std::string FileName = dirname; FileName = dirname + "/Projects/DarcyflowHdiv3D/"; FileName += "DarcyFlowLog3D.cfg"; InitializePZLOG(FileName); #endif #endif // Reading mesh std::string GridFileName; GridFileName = dirname + "/Projects/DarcyflowHdiv3D/"; GridFileName += "SingleLayer.dump"; //GridFileName += "MixLayer.dump"; //GridFileName += "BatatacoarseQ.dump"; //GridFileName += "QUAD4.dump"; if(fLayers[0]->GetIsGIDGeometry()) { ReadGeoMesh(GridFileName); } else { int nx = 2; int ny = 2; int nz = 2; Geometry(nx,ny,nz); // CreatedGeoMesh(); } REAL deg = 0.0; int hcont = 0; RotateGeomesh(deg * M_PI/180.0); this->UniformRefinement(fSimulationData->GetHrefinement()); std::set<int> matidstoRef; // matidstoRef.insert(2); // matidstoRef.insert(3); // matidstoRef.insert(4); matidstoRef.insert(3); matidstoRef.insert(5); this->UniformRefinement(hcont, matidstoRef); this->PrintGeoMesh(); int q = fSimulationData->Getqorder(); int p = fSimulationData->Getporder(); int s = 0; // if (fSimulationData->GetIsH1approx()) if (false) { // CmeshH1(p); } else { CreateMultiphysicsMesh(q,p,s); // CreateInterfaces(); } // Analysis bool mustOptimizeBandwidth = true; TPZAnalysis *an = new TPZAnalysis(fcmeshdarcy,mustOptimizeBandwidth); int numofThreads = 0; bool IsDirecSolver = fSimulationData->GetIsDirect(); if (IsDirecSolver) { if (fSimulationData->GetIsBroyden()) { TPZFStructMatrix fullMatrix(fcmeshdarcy); TPZStepSolver<STATE> step; fullMatrix.SetNumThreads(numofThreads); step.SetDirect(ELU); an->SetStructuralMatrix(fullMatrix); an->SetSolver(step); } else{ TPZSkylineNSymStructMatrix skylnsym(fcmeshdarcy); TPZStepSolver<STATE> step; skylnsym.SetNumThreads(numofThreads); step.SetDirect(ELU); an->SetStructuralMatrix(skylnsym); an->SetSolver(step); } } else { if (fSimulationData->GetIsBroyden()) { TPZFStructMatrix fullMatrix(fcmeshdarcy); fullMatrix.SetNumThreads(numofThreads); TPZAutoPointer<TPZMatrix<STATE> > fullMatrixa = fullMatrix.Create(); TPZAutoPointer<TPZMatrix<STATE> > fullMatrixaClone = fullMatrixa->Clone(); TPZStepSolver<STATE> *stepre = new TPZStepSolver<STATE>(fullMatrixaClone); TPZStepSolver<STATE> *stepGMRES = new TPZStepSolver<STATE>(fullMatrixa); TPZStepSolver<STATE> *stepGC = new TPZStepSolver<STATE>(fullMatrixa); stepre->SetDirect(ELU); stepre->SetReferenceMatrix(fullMatrixa); stepGMRES->SetGMRES(10, 20, *stepre, 1.0e-10, 0); stepGC->SetCG(10, *stepre, 1.0e-10, 0); if (fSimulationData->GetIsCG()) { an->SetSolver(*stepGC); } else{ an->SetSolver(*stepGMRES); } } else{ TPZSkylineNSymStructMatrix skylnsym(fcmeshdarcy); skylnsym.SetNumThreads(numofThreads); TPZAutoPointer<TPZMatrix<STATE> > skylnsyma = skylnsym.Create(); TPZAutoPointer<TPZMatrix<STATE> > skylnsymaClone = skylnsyma->Clone(); TPZStepSolver<STATE> *stepre = new TPZStepSolver<STATE>(skylnsymaClone); TPZStepSolver<STATE> *stepGMRES = new TPZStepSolver<STATE>(skylnsyma); TPZStepSolver<STATE> *stepGC = new TPZStepSolver<STATE>(skylnsyma); stepre->SetDirect(ELU); stepre->SetReferenceMatrix(skylnsyma); stepGMRES->SetGMRES(10, 20, *stepre, 1.0e-10, 0); stepGC->SetCG(10, *stepre, 1.0e-10, 0); if (fSimulationData->GetIsCG()) { an->SetSolver(*stepGC); } else{ an->SetSolver(*stepGMRES); } } } this->InitializeSolution(an); this->TimeForward(an); }
int main(int argc, char *argv[]) { InitializePZLOG(); gRefDBase.InitializeUniformRefPattern(EOned); gRefDBase.InitializeUniformRefPattern(EQuadrilateral); gRefDBase.InitializeUniformRefPattern(ETriangle); ofstream saidaerros("ErroMDP.txt"); saidaerros << "\nCalculo do Erro\n"; int h= 0; int p=0, pr; int dim = 1; fc = 0.1; fk = 0.0001; saidaerros.precision(8); for(p=1; p<2; p++) { pr = p+3; saidaerros << "\n"; saidaerros << "Ordens p = " << p << " and Ordens pr = " << pr <<"\n"; for(h=7; h<8; h++) { saidaerros << "\nRefinamento: h = "<< h <<"\n"; //if(dim>1){ //TPZAutoPointer<TPZGeoMesh> gmesh; TPZGeoMesh *gmesh; if(dim>1){ gmesh = MalhaGeom(1.,1.,false); TPZVec<int> dims(dim,dim); if(dim>1) dims[0]=1; int nref = h; RefinamentoUniforme(gmesh, nref, dims); }else gmesh = MalhaGeom1D(3.,h); ofstream arg("gmesh.txt"); gmesh->Print(arg); TPZCompMesh * cmesh1; TPZCompMesh * cmesh2; if(dim>1){ cmesh1 = CompMesh(gmesh,pr); cmesh2 = CompMesh(gmesh,p); }else{ cmesh1 = CompMesh1D(gmesh,pr); cmesh2 = CompMesh1D(gmesh,p); } // Criando a malha computacional multifísica //malha multifisica TPZVec<TPZCompMesh *> meshvec(2); meshvec[0] = cmesh1; meshvec[1] = cmesh2; TPZCompMesh * mphysics; if(dim>1){ mphysics = MalhaMDP(meshvec,gmesh); }else mphysics = MalhaMDP1D(meshvec,gmesh); //analysis TPZAnalysis an(mphysics,false); TPZStepSolver<STATE> step; //TPZBandStructMatrix bst(mphysics); //TPZFStructMatrix bst(mphysics); TPZSkylineNSymStructMatrix bst(mphysics); an.SetStructuralMatrix(bst); //bst.SetNumThreads(8); step.SetDirect(ELU); an.SetSolver(step); an.Assemble(); an.Solve(); TPZBuildMultiphysicsMesh::TransferFromMultiPhysics(meshvec, mphysics); std::string plotfile("result.vtk"); TPZStack<std::string> scalnames,vecnames; scalnames.Push("Solution"); scalnames.Push("ExactSolution"); scalnames.Push("OptimalTestFunction"); an.DefineGraphMesh(mphysics->Dimension(), scalnames, vecnames, plotfile); an.PostProcess(0,dim); saidaerros<<"\n\nErro da simulacao MDP para a pressao"; // TPZVec<REAL> erros(3); // TPZAnalysis an2(cmesh2); // an2.SetExact(*SolSuave); // an2.PostProcessError(erros, saidaerros); ErrorH1(cmesh2, saidaerros); mphysics->CleanUp(); gmesh->CleanUp(); delete mphysics; } } return EXIT_SUCCESS; }
int mainfem(int argc, char *argv[]) { //InitializePZLOG(); gRefDBase.InitializeUniformRefPattern(EOned); gRefDBase.InitializeUniformRefPattern(EQuadrilateral); gRefDBase.InitializeUniformRefPattern(ETriangle); ofstream saidaerros("ErroProjecaoSemiH1.txt"); saidaerros << "\nCalculo do Erro\n"; int h= 0; int p=0; saidaerros.precision(16); for(p=1; p<5; p++) { saidaerros << "\n"; saidaerros << "Ordens p = " << p <<"\n"; for(h=0; h<6; h++) { saidaerros << "\nRefinamento: h = "<< h <<"\n"; //TPZGeoMesh * gmesh = MalhaGeom(1.,1.,false); TPZAutoPointer<TPZGeoMesh> gmesh = MalhaGeom(1.,1.,false); TPZVec<int> dims(2,0); dims[0]=1; dims[1]=2; int nref = h; RefinamentoUniforme(gmesh, nref, dims); TPZCompMesh * cmesh = CompMesh(gmesh.operator->(),p); //analysis TPZAnalysis an(cmesh,false); TPZSkylineStructMatrix skyl(cmesh); an.SetStructuralMatrix(skyl); TPZStepSolver<STATE> step; step.SetDirect(ELDLt); an.SetSolver(step); an.Assemble(); an.Solve(); // std::string plotfile("result.vtk"); // TPZStack<std::string> scalnames,vecnames; // scalnames.Push("Solution"); // scalnames.Push("ExactPressure"); // an.DefineGraphMesh(cmesh->Dimension(), scalnames, vecnames, plotfile); // an.PostProcess(0,2); // TPZVec<REAL> erros(3); // an.SetExact(*SolSuave); // an.PostProcessError(erros,saidaerros); ErrorH1(cmesh, saidaerros); cmesh->CleanUp(); gmesh->CleanUp(); delete cmesh; } } return EXIT_SUCCESS; }
int mainDPG(int argc, char *argv[]) { // InitializePZLOG(); gRefDBase.InitializeUniformRefPattern(EOned); gRefDBase.InitializeUniformRefPattern(EQuadrilateral); gRefDBase.InitializeUniformRefPattern(ETriangle); ofstream saidaerros("ErroMDP-mhm.txt"); saidaerros << "\nCalculo do Erro\n"; saidaerros.precision(16); for(int p=1; p<5; p++){ saidaerros << "\n"; saidaerros << "Ordens P: p_fine = "<<p+2 <<", p_coarse = " << p <<", p_interface = " << p-1 <<"\n"; for(int h=0; h<5; h++){ saidaerros << "\nRefinamento: h = "<< h <<"\n"; TPZAutoPointer<TPZGeoMesh> gmesh = MalhaGeom(1.,1.,false); // ofstream arg0("gmesh0.txt"); // gmesh->Print(arg0); //-------- construindo malha coarse ---------- //1 refinamento uniforme TPZVec<int> dims(2,0); dims[0]=1; dims[1]=2; int nref = h; RefinamentoUniforme(gmesh, nref, dims); // ofstream arg1("gmesh1.txt"); // gmesh->Print(arg1); //index dos elementos da malha coarse std::set<int64_t> coarseindex; GetElIndexCoarseMesh(gmesh, coarseindex); // std::set<int64_t>::iterator it; // for (it=coarseindex.begin(); it!=coarseindex.end(); ++it) // std::cout << ' ' << *it; // std::cout << "\n"; TPZAutoPointer<TPZGeoMesh> gmesh2 = new TPZGeoMesh(gmesh); dims.Resize(1, 0); dims[0]=2; nref = 0; RefinamentoUniforme(gmesh2, nref, dims); // ofstream arg2("gmesh2.txt"); // gmesh2->Print(arg2); //-------------------------------------------------- TPZDPGMeshControl dpgmesh(gmesh2,coarseindex); int porder = p; dpgmesh.SetMatIds(matfinermesh, matcoarsemesh, matskeletonmesh); dpgmesh.SetPOrderMeshes(porder+2, porder, porder-1); TPZCompMesh &corsemesh = dpgmesh.PressureCoarseMesh(); InsertMaterialObjects(corsemesh); TPZMHMeshControl &mhm = dpgmesh.MHMControl(); bool useDPGPhil=false; bool useMDP=true; InsertMaterialObjectsMHM(mhm.CMesh(),useDPGPhil,useMDP); //refinar malha fina // mhm.SetLagrangeAveragePressure(true); // mhm.CreateCoarseInterfaces(matskeletonmesh); // mhm.BuildComputationalMesh(); // TPZVec<TPZCompMesh *> meshvec; // mhm.GetMeshVec(meshvec); // TPZCompMesh *finemesh = meshvec[0]; // finemesh->Reference()->ResetReference(); // finemesh->LoadReferences(); // TPZBuildMultiphysicsMesh::UniformRefineCompMesh(finemesh,1,false); // ofstream arg3("gmesh3.txt"); // gmesh2->Print(arg3); // ofstream arg4("cmeshfine.txt"); // finemesh->Print(arg4); dpgmesh.BuildComputationalMesh(); TPZAnalysis an(mhm.CMesh(),false); TPZStepSolver<STATE> step; if(useMDP) { TPZSkylineNSymStructMatrix bst(mhm.CMesh().operator->()); //TPZBandStructMatrix bst(mhm.CMesh().operator->()); an.SetStructuralMatrix(bst); bst.SetNumThreads(8); step.SetDirect(ELU); }else{ TPZSkylineStructMatrix skyl(mhm.CMesh()); an.SetStructuralMatrix(skyl); skyl.SetNumThreads(8); step.SetDirect(ELDLt); } an.SetSolver(step); an.Assemble(); //an.Run(); an.Solve(); // std::string plotfile("result.vtk"); // TPZStack<std::string> scalnames,vecnames; // scalnames.Push("Solution"); // scalnames.Push("ExactSolution"); // scalnames.Push("ErrorEstimatorDPG"); // an.DefineGraphMesh(mhm.CMesh()->Dimension(), scalnames, vecnames, plotfile); // an.PostProcess(0,2); //calculo do erro TPZVec<TPZCompMesh *> meshvec; dpgmesh.GetMeshVec(meshvec); int NEq1 = mhm.CMesh()->NEquations(); int NEq2 =meshvec[3]->NEquations(); saidaerros << "\nNumero Equacoes: Malha Multifisica = "<< NEq1 <<" e Malha coarse = "<< NEq2 <<"\n"; TPZBuildMultiphysicsMesh::TransferFromMultiPhysics(meshvec, mhm.CMesh().operator->()); TPZVec<REAL> erros(3); TPZAnalysis an_coarse(meshvec[3],false); an_coarse.SetExact(*SolSuave); an_coarse.PostProcessError(erros,saidaerros); //ErrorH1(meshvec[3], saidaerros); mhm.CMesh().operator->()->CleanUp(); meshvec[0]->CleanUp(); meshvec[1]->CleanUp(); meshvec[2]->CleanUp(); meshvec[3]->CleanUp(); gmesh.operator->()->CleanUp(); gmesh2.operator->()->CleanUp(); } } return EXIT_SUCCESS; }
TPZMatrixSolver<REAL> *TPZAnalysis::BuildPreconditioner(EPrecond preconditioner, bool overlap) { if(!fSolver || !fSolver->Matrix()) { #ifndef BORLAND cout << __FUNCTION__ << " called with uninitialized stiffness matrix\n"; #else cout << "TPZMatrixSolver *TPZAnalysis::BuildPreconditioner" << " called with uninitialized stiffness matrix\n"; #endif } if(preconditioner == EJacobi) { } else { TPZNodesetCompute nodeset; TPZStack<int> elementgraph,elementgraphindex; // fCompMesh->ComputeElGraph(elementgraph,elementgraphindex); int nindep = fCompMesh->NIndependentConnects(); int neq = fCompMesh->NEquations(); fCompMesh->ComputeElGraph(elementgraph,elementgraphindex); int nel = elementgraphindex.NElements()-1; TPZMetis renum(nel,nindep); //nodeset.Print(file,elementgraphindex,elementgraph); renum.ConvertGraph(elementgraph,elementgraphindex,nodeset.Nodegraph(),nodeset.Nodegraphindex()); // cout << "nodegraphindex " << nodeset.Nodegraphindex() << endl; // cout << "nodegraph " << nodeset.Nodegraph() << endl; nodeset.AnalyseGraph(); //nodeset.Print(file); TPZStack<int> blockgraph,blockgraphindex; switch(preconditioner) { case EJacobi: return 0; case EBlockJacobi: nodeset.BuildNodeGraph(blockgraph,blockgraphindex); break; case EElement: nodeset.BuildElementGraph(blockgraph,blockgraphindex); break; case ENodeCentered: nodeset.BuildVertexGraph(blockgraph,blockgraphindex); break; } TPZStack<int> expblockgraph,expblockgraphindex; nodeset.ExpandGraph(blockgraph,blockgraphindex,fCompMesh->Block(),expblockgraph,expblockgraphindex); #ifdef LOG4CXX #ifdef DEBUG2 std::map<int,int> blocksizes; int i; int totalsize; for(i=0; i< expblockgraphindex.NElements()-1;i++) { int bls = expblockgraphindex[i+1]-expblockgraphindex[i]; blocksizes[bls]++; totalsize += bls*bls; } std::map<int,int>::iterator it; std::stringstream sout; sout << __PRETTY_FUNCTION__ << " total size of allocation " << totalsize << std::endl; for(it=blocksizes.begin(); it != blocksizes.end(); it++) { sout << "block size " << (*it).first << " number of blocks " << (*it).second << std::endl; } LOGPZ_DEBUG(logger,sout.str().c_str()); #endif #endif if(overlap && !(preconditioner == EBlockJacobi)) { TPZSparseBlockDiagonal<REAL> *sp = new TPZSparseBlockDiagonal<REAL>(expblockgraph,expblockgraphindex,neq); TPZStepSolver<REAL> *step = new TPZStepSolver<REAL>(sp); step->SetDirect(ELU); step->SetReferenceMatrix(fSolver->Matrix()); return step; } else if (overlap) { TPZBlockDiagonalStructMatrix blstr(fCompMesh); TPZBlockDiagonal<REAL> *sp = new TPZBlockDiagonal<REAL>(); blstr.AssembleBlockDiagonal(*sp); // std::ofstream out("Direct assembly"); // sp->Print("Directly assembled",out); /* int numbl = sp->NumberofBlocks(); int ib,i,j; for(ib=numbl-1; ib>=0; ib--) { for(i=0; i<3; i++) { for(j=0; j<3; j++) { if(i!=j) (*sp)(3*ib+i,3*ib+j) = 0.; } } } */ TPZStepSolver<REAL> *step = new TPZStepSolver<REAL>(sp); step->SetDirect(ELU); return step; } else { TPZVec<int> blockcolor; int numcolors = nodeset.ColorGraph(expblockgraph,expblockgraphindex,neq,blockcolor); return BuildSequenceSolver(expblockgraph,expblockgraphindex,neq,numcolors,blockcolor); } } return 0; }
void TPZMGAnalysis::Solve() { if(fMeshes.NElements() == 1) { TPZAnalysis::Solve(); if(fSolvers.NElements() == 0) { fSolvers.Push((TPZMatrixSolver<REAL> *) fSolver->Clone()); } if(fPrecondition.NElements() == 0) { fPrecondition.Push(0); } if(fSolutions.NElements() == 0) { fSolutions.Push(new TPZFMatrix<REAL>(fSolution)); } else { int nsol = fSolutions.NElements(); *(fSolutions[nsol-1]) = fSolution; } return; } int numeq = fCompMesh->NEquations(); if(fRhs.Rows() != numeq ) return; int nsolvers = fSolvers.NElements(); TPZFMatrix<REAL> residual(fRhs); TPZFMatrix<REAL> delu(numeq,1,0.); TPZMatrixSolver<REAL> *solve = dynamic_cast<TPZMatrixSolver<REAL> *> (fSolvers[nsolvers-1]); if(fSolution.Rows() != numeq) { fSolution.Redim(numeq,1); } else { solve->Matrix()->Residual(fSolution,fRhs,residual); } REAL normrhs = Norm(fRhs); REAL normres = Norm(residual); if(normrhs*1.e-6 >= normres) { cout << "TPZMGAnalysis::Solve no need for iterations normrhs = " << normrhs << " normres = " << normres << endl; if(fSolutions.NElements() < fMeshes.NElements()) { fSolutions.Push(new TPZFMatrix<REAL>(fSolution)); } else { int nsol = fSolutions.NElements(); *(fSolutions[nsol-1]) = fSolution; } return ; } // REAL tol = 1.e-6*normrhs/normres; // if(numeq > 1500) { // fIterative->SetCG(200,*fPrecond,tol,0); // } else { // fIterative->SetDirect(ELDLt); // } TPZStepSolver<REAL> *stepsolve = dynamic_cast<TPZStepSolver<REAL> *> (solve); if(stepsolve) stepsolve->SetTolerance(1.e-6*normrhs/normres); cout << "TPZMGAnalysis::Run res : " << Norm(residual) << " neq " << numeq << endl; solve->Solve(residual, delu); fSolution += delu; fCompMesh->LoadSolution(fSolution); if(fSolutions.NElements() < fMeshes.NElements()) { fSolutions.Push(new TPZFMatrix<REAL>(fSolution)); } else { int nsol = fSolutions.NElements(); *(fSolutions[nsol-1]) = fSolution; } }
void SolveSist(TPZAnalysis *an, TPZCompMesh *Cmesh) { // TPZParFrontStructMatrix<TPZFrontSym<STATE> > strmat(Cmesh); TPZSkylineStructMatrix strmat(Cmesh); // TPZSymetricSpStructMatrix strmat(Cmesh); strmat.SetNumThreads(8); an->SetStructuralMatrix(strmat); int64_t neq = Cmesh->NEquations(); if(neq > 20000) { std::cout << "Entering Assemble Equations\n"; std::cout.flush(); } #ifdef USING_BOOST boost::posix_time::ptime t1 = boost::posix_time::microsec_clock::local_time(); #endif TPZStepSolver<STATE> step; step.SetDirect(ECholesky); an->SetSolver(step); an->Assemble(); // std::ofstream andrade("../Andrade.mtx"); // andrade.precision(16); // an->Solver().Matrix()->Print("Andrade",andrade,EMatrixMarket); // std::cout << "Leaving Assemble\n"; #ifdef USING_BOOST boost::posix_time::ptime t2 = boost::posix_time::microsec_clock::local_time(); #endif //#define NONO #ifdef NONO step.SetMatrix(an->Solver().Matrix()); TPZAutoPointer<TPZMatrix<STATE> > matrix = an->Solver().Matrix(); TPZSkylMatrix<STATE> *skylmat = dynamic_cast<TPZSkylMatrix<STATE> *>(matrix.operator->()); TPZSkylMatrix<float> * floatmat = new TPZSkylMatrix<float>; floatmat->CopyFrom(*skylmat); floatmat->Decompose_Cholesky(); TPZSkylMatrix<STATE> *floatdec = new TPZSkylMatrix<STATE>; floatdec->CopyFrom(*floatmat); TPZStepSolver<STATE> stepfloat; stepfloat.SetMatrix(floatdec); stepfloat.SetDirect(ECholesky); step.SetCG(10, stepfloat, 1.e-6, 0); an->SetSolver(step); #endif if(neq > 20000) { std::cout << "Entering Solve\n"; std::cout.flush(); } an->Solve(); #ifdef USING_BOOST boost::posix_time::ptime t3 = boost::posix_time::microsec_clock::local_time(); std::cout << "Time for assembly " << t2-t1 << " Time for solving " << t3-t2 << std::endl; #endif }
void TPZAnalysisError::hp_Adaptive_Mesh_Design(std::ostream &out,REAL &CurrentEtaAdmissible) { int64_t iter = 0;//iteracao atual cout << "\n\nIteration 1\n"; out << "\n Iteration 1\n"; Run(out);//solucao malha inicial TPZManVector<REAL,3> errors(3); errors.Fill(0.0); TPZVec<REAL> flux(0); bool store_error = false; fNIterations--; while(iter++ < fNIterations) { arq << "\n iter = " << iter << endl; CurrentEtaAdmissible = pow(fEtaAdmissible,sqrt((REAL)(iter*1./(fNIterations*1.))));//error admissivel corrigido // Print data PlotLocal(iter,CurrentEtaAdmissible,out); //if more norms than 3 are available, the pzvec is resized in the material error method Mesh()->EvaluateError(fExact,store_error, errors); if (errors.NElements() < 3) { PZError << endl << "TPZAnalysisError::hp_Adaptive_Mesh_Design - At least 3 norms are expected." << endl; exit (-1); } out << " - Error Energy Norm : " << errors[0] << endl; out << " - FE Sol Energy Norm : " << errors[1] << endl; out << " - Ex Sol Energy Norm : " << errors[2] << endl; for(int ier = 3; ier < errors.NElements(); ier++) out << "Other norms : " << errors[ier] << endl; out << " - Eta Admissible : " << CurrentEtaAdmissible << endl; // out << " - Eta Reached : " << true_error/exactnorm << endl; out << " - Eta Reached : " << errors[0]/errors[2] << endl; //Code isn't place to chat //#warning Philippe, nao entendo nada!!!!! //<!> //#warning De fato Thiago, voce tem razao out << " - Number of D.O.F. : " << fCompMesh->NEquations() << endl; out.flush(); HPAdapt(CurrentEtaAdmissible,out);//processa os restantes elementos ; (nadmerror) Mesh()->AdjustBoundaryElements(); OptimizeBandwidth(); TPZSkylineStructMatrix skystr(fCompMesh); SetStructuralMatrix(skystr); TPZStepSolver<STATE> sol; sol.ShareMatrix(Solver()); sol.SetDirect(ECholesky);//ECholesky SetSolver(sol); cout << "\n\nIteration " << (iter+1) << endl; out << "\n Iteration " << (iter+1) << endl; Run(out); } //Code isn't place to chat //#warning Philippe, nao parece igual acima ?? //<!> //#warning Olhar aqui //<!> errors.Resize(3); errors.Fill(0.0); PlotLocal(iter,CurrentEtaAdmissible,out); Mesh()->EvaluateError(fExact,store_error, errors); if (errors.NElements() < 3) { PZError << endl << "TPZAnalysisError::hp_Adaptive_Mesh_Design - At least 3 norms are expected." << endl; exit (-1); } out << " - Error Energy Norm : " << errors[0] << endl; out << " - FE Sol Energy Norm : " << errors[1] << endl; out << " - Ex Sol Energy Norm : " << errors[2] << endl; for(int ier = 3; ier < errors.NElements(); ier++) out << "Other norms : " << errors[ier] << endl; out << " - Eta Admissible : " << CurrentEtaAdmissible << endl; // out << " - Eta Reached : " << true_error/exactnorm << endl; <!> out << " - Eta Reached : " << errors[0]/errors[2] << endl; out << " - Number of D.O.F. : " << fCompMesh->NEquations() << endl; out.flush(); }