void ISOP2P1::getMonitor() { /// 限制最大迭代步数. maxStep() = max_step; /// 同步网格. syncMesh(); FEMFunction<double, DIM> _u_h(fem_space_p); FEMFunction<double, DIM> _v_h(fem_space_p); Operator::L2Interpolate(v_h[0], _u_h); Operator::L2Interpolate(v_h[1], _v_h); FEMSpace<double, DIM>::ElementIterator the_element = fem_space_p.beginElement(); FEMSpace<double, DIM>::ElementIterator end_element = fem_space_p.endElement(); for (int i = 0; the_element != end_element; ++the_element) { double volume = the_element->templateElement().volume(); const QuadratureInfo<DIM>& quad_info = the_element->findQuadratureInfo(3); std::vector<double> jacobian = the_element->local_to_global_jacobian(quad_info.quadraturePoint()); int n_quadrature_point = quad_info.n_quadraturePoint(); std::vector<Point<DIM> > q_point = the_element->local_to_global(quad_info.quadraturePoint()); std::vector<std::vector<double> > basis_value = the_element->basis_function_value(q_point); std::vector<double> u_h_value = _u_h.value(q_point, *the_element); std::vector<double> v_h_value = _v_h.value(q_point, *the_element); std::vector<std::vector<double> > u_h_gradient = _u_h.gradient(q_point, *the_element); std::vector<std::vector<double> > v_h_gradient = _v_h.gradient(q_point, *the_element); float d = 0, area = 0, norm = 0; for (int l = 0; l < n_quadrature_point; ++l) { double Jxw = quad_info.weight(l) * jacobian[l] * volume; area += Jxw; norm += u_h_value[l] * u_h_value[l] + v_h_value[l] * v_h_value[l]; d += Jxw * (innerProduct(u_h_gradient[l], u_h_gradient[l])); } norm = 1.0 / (eps + sqrt(norm)); monitor(i++) = d / area; } std::cout << "max monitor=" << *std::max_element(monitor().begin(), monitor().end()) << "\tmin monitor=" << *std::min_element(monitor().begin(), monitor().end()) << std::endl; double max_monitor = *std::max_element(monitor().begin(), monitor().end()); smoothMonitor(2); for (int i = 0; i < n_geometry(2); ++i) monitor(i) = 1.0 / sqrt(1.0 + alpha * monitor(i)); };
double SubSystem::maxStep(Eigen::VectorXd &xdir) { return maxStep(plist, xdir); }
void CollisionRespone::ContactForceResponse(){ std::list<int> C,NC; int d=0; ReturnData sj; arma::fmat A,a,b,f(ActiveCollisionList.size(),1),df,da; f.zeros(); A=CalculateMatrixA(); b=CalculateMatrixB(); a=b; std::cout<<"here A\n"<<A<<"\n"; // std::cout<<"here a start\n"<<a<<"\n"; std::cout<<"start\n"; while(AllAccelerationZeroLess(a)){ while(1){ std::cout<<d<<" loop\n"; std::cout<<"a her\n"<<a; std::cout<<"f er her\n"<<f; df=fdirection(d,A,C); da=A*df; sj=maxStep(f,a,df,da,d,C,NC); f+=sj.s*df; a+=sj.s*da; //std::cout<<"loop\n"; //std::cout<<"here da\n"<<da<<"\n"; //std::cout<<"med s "<<sj.s<<"\n"; if(ValueInList(C,sj.j)){ C.remove(sj.j); NC.push_back(sj.j); } else if(ValueInList(NC,sj.j)){ NC.remove(sj.j); C.push_back(sj.j); } else{ C.push_back(sj.j); break; } } d++; //std::cout<<"\n"; } std::cout<<"a s**t her\n"<<a; std::cout<<"heres f\n"<<f<<"\n"; std::cout<<"s**t\n"; //std::cout<<"here a s**t\n"<<a<<"\n"; Vector2D r1,r2,n,sep; for(int i=0;i<ActiveCollisionList.size();i++){ //std::cout<<f(i,0)<<" applying to "<<ActiveCollisionList[i].obj1->parent->id<<" and "<<ActiveCollisionList[i].obj1->parent->id<<"\n"; r1=ActiveCollisionList[i].ContactPoint; r2=r1; r1-=ActiveCollisionList[i].obj1->getPosition(); r2-=ActiveCollisionList[i].obj2->getPosition(); n=ActiveCollisionList[i].CollisionAxis; if(ActiveCollisionList[i].axis_from==2){ n*=-1; } sep=ActiveCollisionList[i].SeperatingVector; //sep.null(); if(ActiveCollisionList[i].obj2->getMass()!=0){ sep/=2; ActiveCollisionList[i].obj1->HandleCollision(sep,f(i,0),r1,n); sep*=-1; ActiveCollisionList[i].obj2->HandleCollision(sep,-f(i,0),r2,n); } else{ ActiveCollisionList[i].obj1->HandleCollision(sep,f(i,0),r1,n); } } }