void elasticitySolver::solve() { //linearSystemFull<double> *lsys = new linearSystemFull<double>; #if defined(HAVE_TAUCS) linearSystemCSRTaucs<double> *lsys = new linearSystemCSRTaucs<double>; #elif defined(HAVE_PETSC) linearSystemPETSc<double> *lsys = new linearSystemPETSc<double>; #else linearSystemGmm<double> *lsys = new linearSystemGmm<double>; lsys->setNoisy(2); #endif assemble(lsys); lsys->systemSolve(); printf("-- done solving!\n"); GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); // printLinearSystem(lsys); double energ=0; for (unsigned int i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term,elasticFields[i].g->begin(),elasticFields[i].g->end(), Integ_Bulk,energ); } printf("elastic energy=%f\n",energ); }
void elasticitySolver::solve() { std::string sysname = "A"; if(pAssembler && pAssembler->getLinearSystem(sysname)) delete pAssembler->getLinearSystem(sysname); #if defined(HAVE_PETSC) linearSystemPETSc<double> *lsys = new linearSystemPETSc<double>; #elif defined(HAVE_GMM) linearSystemCSRGmm<double> *lsys = new linearSystemCSRGmm<double>; #else linearSystemFull<double> *lsys = new linearSystemFull<double>; #endif assemble(lsys); // printLinearSystem(lsys,pAssembler->sizeOfR()); lsys->systemSolve(); printf("-- done solving!\n"); double energ = 0; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for(std::size_t i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field, elasticFields[i]._e, elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), elasticFields[i].g->end(), Integ_Bulk, energ); } printf("elastic energy=%f\n", energ); }
PView *elasticitySolver::buildVonMisesView(const std::string postFileName) { std::cout << "build elastic view"<< std::endl; std::map<int, std::vector<double> > data; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for (unsigned int i = 0; i < elasticFields.size(); ++i) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); it != elasticFields[i].g->end(); ++it) { MElement *e=*it; double energ; IntPt *GP; int npts=Integ_Bulk.getIntPoints(e,&GP); Elastic_Energy_Term.get(e,npts,GP,energ); std::vector<double> vec; vec.push_back(energ); data[(*it)->getNum()]=vec; } } PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0); return pv; }
void elasticitySolver::postSolve() { GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); double energ=0; for (unsigned int i = 0; i < elasticFields.size(); i++) { SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); Assemble(Elastic_Energy_Term, elasticFields[i].g->begin(), elasticFields[i].g->end(), Integ_Bulk, energ); } printf("elastic energy=%f\n",energ); }
PView* elasticitySolver::buildStressesView (const std::string postFileName) { std::cout << "build stresses view"<< std::endl; std::map<int, std::vector<double> > data; GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for (unsigned int i = 0; i < elasticFields.size(); ++i) { double E = elasticFields[i]._E; double nu = elasticFields[i]._nu; SolverField<SVector3> Field(pAssembler, LagSpace); IsotropicElasticTerm Eterm(Field,elasticFields[i]._E,elasticFields[i]._nu); BilinearTermToScalarTerm Elastic_Energy_Term(Eterm); for (groupOfElements::elementContainer::const_iterator it = elasticFields[i].g->begin(); it != elasticFields[i].g->end(); ++it) { MElement *e=*it; int nbVertex = e->getNumVertices(); std::vector<SVector3> val(nbVertex); double valx[256]; double valy[256]; double valz[256]; for (int k = 0; k < nbVertex; k++){ MVertex *v = e->getVertex(k); MPoint p(v); Field.f(&p,0,0,0,val[k]); valx[k] =val[k](0); valy[k] =val[k](1); valz[k] =val[k](2); } double gradux[3]; double graduy[3]; double graduz[3]; double u=0.33, v=0.33, w=0.0; e->interpolateGrad(valx, u, v, w, gradux); e->interpolateGrad(valy, u, v, w, graduy); e->interpolateGrad(valz, u, v, w, graduz); double eps[6] = {gradux[0], graduy[1], graduz[2], 0.5 * (gradux[1] + graduy[0]), 0.5 * (gradux[2] + graduz[0]), 0.5 * (graduy[2] + graduz[1])}; double A = E / (1. + nu); double B = A * (nu / (1. - 2 * nu)); double trace = eps[0] + eps[1] + eps[2] ; double sxx = A * eps[0] + B * trace; double syy = A * eps[1] + B * trace; double szz = A * eps[2] + B * trace; double sxy = A * eps[3]; double sxz = A * eps[4]; double syz = A * eps[5]; std::vector<double> vec(9); vec[0]=sxx; vec[1]=sxy; vec[2]=sxz; vec[3]=sxy; vec[4]=syy; vec[5]=syz; vec[6]=sxz; vec[7]=syz; vec[8]=szz; data[e->getNum()]=vec; } } PView *pv = new PView (postFileName, "ElementData", pModel, data, 0.0); return pv; }
void elasticitySolver::assemble(linearSystem<double> *lsys) { if (pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // we first do all fixations. the behavior of the dofManager is to // give priority to fixations : when a dof is fixed, it cannot be // numbered afterwards // Dirichlet conditions for (unsigned int i = 0; i < allDirichlet.size(); i++) { FilterDofComponent filter(allDirichlet[i]._comp); FixNodalDofs(*LagSpace,allDirichlet[i].g->begin(),allDirichlet[i].g->end(), *pAssembler,*allDirichlet[i]._f,filter); } // LagrangeMultipliers for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); ++i) { NumberDofs(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), *pAssembler); } // Elastic Fields for (unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E != 0.) NumberDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), *pAssembler); } // Voids for (unsigned int i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._E == 0.) FixVoidNodalDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), *pAssembler); } // Neumann conditions GaussQuadrature Integ_Boundary(GaussQuadrature::Val); for (unsigned int i = 0; i < allNeumann.size(); i++) { LoadTerm<SVector3> Lterm(*LagSpace,*allNeumann[i]._f); Assemble(Lterm,*LagSpace,allNeumann[i].g->begin(),allNeumann[i].g->end(), Integ_Boundary,*pAssembler); } // Assemble cross term, laplace term and rhs term for LM GaussQuadrature Integ_LagrangeMult(GaussQuadrature::ValVal); GaussQuadrature Integ_Laplace(GaussQuadrature::GradGrad); for (unsigned int i = 0; i < LagrangeMultiplierFields.size(); i++) { LagrangeMultiplierTerm LagTerm(*LagSpace, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._d); Assemble(LagTerm, *LagSpace, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, *pAssembler); LaplaceTerm<double,double> LapTerm(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._tau); Assemble(LapTerm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Laplace, *pAssembler); LoadTerm<double> Lterm(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._f); Assemble(Lterm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble elastic term for GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for (unsigned int i = 0; i < elasticFields.size(); i++) { IsotropicElasticTerm Eterm(*LagSpace,elasticFields[i]._E,elasticFields[i]._nu); Assemble(Eterm,*LagSpace,elasticFields[i].g->begin(),elasticFields[i].g->end(), Integ_Bulk,*pAssembler); } /*for (int i=0;i<pAssembler->sizeOfR();i++){ for (int j=0;j<pAssembler->sizeOfR();j++){ double d;lsys->getFromMatrix(i,j,d); printf("%12.5E ",d); } double d;lsys->getFromRightHandSide(i,d); printf(" | %12.5E\n",d); }*/ printf("nDofs=%d\n",pAssembler->sizeOfR()); printf("nFixed=%d\n",pAssembler->sizeOfF()); }
void elasticitySolver::assemble(linearSystem<double> *lsys) { if(pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // we first do all fixations. the behavior of the dofManager is to // give priority to fixations : when a dof is fixed, it cannot be // numbered afterwards // Dirichlet conditions for(std::size_t i = 0; i < allDirichlet.size(); i++) { FilterDofComponent filter(allDirichlet[i]._comp); FixNodalDofs(*LagSpace, allDirichlet[i].g->begin(), allDirichlet[i].g->end(), *pAssembler, *allDirichlet[i]._f, filter); } // LagrangeMultipliers for(std::size_t i = 0; i < LagrangeMultiplierFields.size(); ++i) { std::size_t j = 0; for(; j < LagrangeMultiplierSpaces.size(); j++) if(LagrangeMultiplierSpaces[j]->getId() == LagrangeMultiplierFields[i]._tag) break; NumberDofs(*(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), *pAssembler); } // Elastic Fields for(std::size_t i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._e != 0.) NumberDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), *pAssembler); } // Voids for(std::size_t i = 0; i < elasticFields.size(); ++i) { if(elasticFields[i]._e == 0.) FixVoidNodalDofs(*LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), *pAssembler); } // Neumann conditions GaussQuadrature Integ_Boundary(GaussQuadrature::Val); for(std::size_t i = 0; i < allNeumann.size(); i++) { LoadTerm<SVector3> Lterm(*LagSpace, allNeumann[i]._f); Assemble(Lterm, *LagSpace, allNeumann[i].g->begin(), allNeumann[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble cross term, laplace term and rhs term for LM GaussQuadrature Integ_LagrangeMult(GaussQuadrature::ValVal); GaussQuadrature Integ_Laplace(GaussQuadrature::GradGrad); for(std::size_t i = 0; i < LagrangeMultiplierFields.size(); i++) { std::size_t j = 0; for(; j < LagrangeMultiplierSpaces.size(); j++) if(LagrangeMultiplierSpaces[j]->getId() == LagrangeMultiplierFields[i]._tag) break; printf("Lagrange Mult Lag\n"); LagrangeMultiplierTerm<SVector3> LagTerm(*LagSpace, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i]._d); Assemble(LagTerm, *LagSpace, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, *pAssembler); printf("Lagrange Mult Lap\n"); LaplaceTerm<double, double> LapTerm(*(LagrangeMultiplierSpaces[j]), -LagrangeMultiplierFields[i]._tau); Assemble(LapTerm, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Laplace, *pAssembler); printf("Lagrange Mult Load\n"); LoadTermOnBorder<double> Lterm(*(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i]._f); Assemble(Lterm, *(LagrangeMultiplierSpaces[j]), LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble elastic term for GaussQuadrature Integ_Bulk(GaussQuadrature::GradGrad); for(std::size_t i = 0; i < elasticFields.size(); i++) { printf("Elastic\n"); IsotropicElasticTerm Eterm(*LagSpace, elasticFields[i]._e, elasticFields[i]._nu); Assemble(Eterm, *LagSpace, elasticFields[i].g->begin(), elasticFields[i].g->end(), Integ_Bulk, *pAssembler); } printf("nDofs=%d\n", pAssembler->sizeOfR()); printf("nFixed=%d\n", pAssembler->sizeOfF()); }
void thermicSolver::assemble(linearSystem<double> *lsys) { if(pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // we first do all fixations. the behavior of the dofManager is to // give priority to fixations : when a dof is fixed, it cannot be // numbered afterwards // Dirichlet conditions for(std::size_t i = 0; i < allDirichlet.size(); i++) { FilterDofTrivial filter; FixNodalDofs(*LagSpace, allDirichlet[i].g->begin(), allDirichlet[i].g->end(), *pAssembler, *allDirichlet[i]._f, filter); } // LagrangeMultipliers for(std::size_t i = 0; i < LagrangeMultiplierFields.size(); ++i) { NumberDofs(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), *pAssembler); } // Thermic Fields for(std::size_t i = 0; i < thermicFields.size(); ++i) { NumberDofs(*LagSpace, thermicFields[i].g->begin(), thermicFields[i].g->end(), *pAssembler); } // Neumann conditions GaussQuadrature Integ_Boundary(GaussQuadrature::Val); for(std::size_t i = 0; i < allNeumann.size(); i++) { std::cout << "Neumann BC" << std::endl; LoadTerm<double> Lterm(*LagSpace, allNeumann[i]._f); Assemble(Lterm, *LagSpace, allNeumann[i].g->begin(), allNeumann[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble cross term, laplace term and rhs term for LM GaussQuadrature Integ_LagrangeMult(GaussQuadrature::ValVal); GaussQuadrature Integ_Laplace(GaussQuadrature::GradGrad); for(std::size_t i = 0; i < LagrangeMultiplierFields.size(); i++) { printf("Lagrange Mult Lag\n"); LagrangeMultiplierTerm<double> LagTerm(*LagSpace, *LagrangeMultiplierSpace, 1.); Assemble(LagTerm, *LagSpace, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_LagrangeMult, *pAssembler); printf("Lagrange Mult Lap\n"); LaplaceTerm<double, double> LapTerm(*LagrangeMultiplierSpace, -LagrangeMultiplierFields[i]._tau); Assemble(LapTerm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Laplace, *pAssembler); printf("Lagrange Mult Load\n"); LoadTermOnBorder<double> Lterm(*LagrangeMultiplierSpace, LagrangeMultiplierFields[i]._f); Assemble(Lterm, *LagrangeMultiplierSpace, LagrangeMultiplierFields[i].g->begin(), LagrangeMultiplierFields[i].g->end(), Integ_Boundary, *pAssembler); } // Assemble thermic term GaussQuadrature Integ_Bulk(GaussQuadrature::ValVal); for(std::size_t i = 0; i < thermicFields.size(); i++) { printf("Thermic Term\n"); LaplaceTerm<double, double> Tterm(*LagSpace, thermicFields[i]._k); Assemble(Tterm, *LagSpace, thermicFields[i].g->begin(), thermicFields[i].g->end(), Integ_Bulk, *pAssembler); } /*for (int i = 0;i<pAssembler->sizeOfR();i++){ for (int j = 0;j<pAssembler->sizeOfR();j++){ double d; lsys->getFromMatrix(i, j, d); printf("%g ", d); } double d; lsys->getFromRightHandSide(i, d); printf(" | %g\n", d); }*/ printf("nDofs=%d\n", pAssembler->sizeOfR()); printf("nFixed=%d\n", pAssembler->sizeOfF()); }