Example #1
0
void SetNewProblem()
{
	const unsigned int nprob = 2;
	static unsigned int iprob = 0;

	static int id_val_bc0=0, id_val_bc1=0, id_val_bc2=0;
	
	if( iprob == 0 ){	// 2次元問題の設定
		Cad::CCadObj2D cad_2d;
		{	// 形を作る
            std::vector<Com::CVector2D> vec_ary;
            vec_ary.push_back( Com::CVector2D(-0.5,-0.5) );
            vec_ary.push_back( Com::CVector2D( 0.5,-0.5) );
            vec_ary.push_back( Com::CVector2D( 0.5, 0.5) );
            vec_ary.push_back( Com::CVector2D(-0.5, 0.5) );
			cad_2d.AddPolygon( vec_ary );
            cad_2d.AddVertex(Cad::LOOP,1,Com::CVector2D(0.0,0.0));
		}
		world.Clear();
		const unsigned int id_base = world.AddMesh( Msh::CMesher2D(cad_2d,0.05) );
		const Fem::Field::CIDConvEAMshCad& conv = world.GetIDConverter(id_base);

		unsigned int id_field_rot = world.MakeField_FieldElemDim(id_base,2,VECTOR2,VALUE,CORNER);
		unsigned int id_field_deflect = world.MakeField_FieldElemDim(id_base,2,SCALAR,VALUE,CORNER);

		Fem::Ls::CLinearSystem_Field ls;
		LsSol::CPreconditioner_ILU prec;
		ls.AddPattern_Field(id_field_deflect,world);
		ls.AddPattern_Field(id_field_rot,id_field_deflect,world);
		prec.SetLinearSystem(ls.m_ls);

		unsigned int id_field_rot_fix0 = world.GetPartialField(id_field_rot,conv.GetIdEA_fromCad(2,Cad::EDGE));
		unsigned int id_field_rot_fix1 = world.GetPartialField(id_field_rot,conv.GetIdEA_fromCad(4,Cad::EDGE));
		ls.SetFixedBoundaryCondition_Field(id_field_rot_fix0,world);
		ls.SetFixedBoundaryCondition_Field(id_field_rot_fix1,world);

		unsigned int id_field_def_fix0 = world.GetPartialField(id_field_deflect,conv.GetIdEA_fromCad(2,Cad::EDGE));
		unsigned int id_field_def_fix1 = world.GetPartialField(id_field_deflect,conv.GetIdEA_fromCad(4,Cad::EDGE));
    Fem::Field::SetFieldValue_Constant(id_field_rot_fix1,1,Fem::Field::VALUE,world, -1);
    
		ls.SetFixedBoundaryCondition_Field(id_field_def_fix0,world);
		ls.SetFixedBoundaryCondition_Field(id_field_def_fix1,world);    
    
		ls.InitializeMarge();
		Fem::Eqn::AddLinearSystem_DKT2D_Static(ls,world,id_field_deflect,id_field_rot);
		double res = ls.FinalizeMarge();
		prec.SetValue(ls.m_ls);

		std::cout << "Residual : " << res << std::endl;
		{
			double tol = 1.0e-6;
			unsigned int iter = 10000;
			LsSol::Solve_CG(tol,iter,ls);
//			Fem::Sol::Solve_PCG(tol,iter,ls,prec);
			std::cout << iter << " " << tol << std::endl;
		}
		ls.UpdateValueOfField(id_field_deflect,world,VALUE);
		ls.UpdateValueOfField(id_field_rot,world,VALUE);

		drawer_ary.Clear();
	//	drawer_ary.PushBack( new View::CDrawerVector(id_field_rot,world) );
		drawer_ary.PushBack( new View::CDrawerFace(id_field_deflect,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_deflect,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_deflect,true,world) );
    camera.Fit( drawer_ary.GetBoundingBox(camera.GetRotMatrix3() ) );
	}
	else if( iprob == 1 ){
		Msh::CMesher2D msh;
		msh.ReadFromFile_GiDMsh("../input_file/rect_tri.msh");
		world.Clear();
		const unsigned int id_base = world.AddMesh( msh );

		unsigned int id_field_rot = world.MakeField_FieldElemDim(id_base,2,  VECTOR2,VALUE,CORNER);
		unsigned int id_field_deflect = world.MakeField_FieldElemDim(id_base,2,  SCALAR,VALUE,CORNER);

		unsigned int id_field_rot_fix0 = world.GetPartialField(id_field_rot,3);
		unsigned int id_field_rot_fix1 = world.GetPartialField(id_field_rot,4);
		unsigned int id_field_def_fix0 = world.GetPartialField(id_field_deflect,3);
		unsigned int id_field_def_fix1 = world.GetPartialField(id_field_deflect,4);
    
    Fem::Field::SetFieldValue_Constant(id_field_def_fix1,0,Fem::Field::VALUE,world, -3);    

		Fem::Ls::CLinearSystem_Field ls;
		LsSol::CPreconditioner_ILU prec;
		ls.AddPattern_Field(id_field_deflect,world);
		ls.AddPattern_Field(id_field_rot,id_field_deflect,world);
		prec.SetLinearSystem(ls.m_ls);

		ls.SetFixedBoundaryCondition_Field(id_field_rot_fix0,world);
		ls.SetFixedBoundaryCondition_Field(id_field_rot_fix1,world);
		ls.SetFixedBoundaryCondition_Field(id_field_def_fix0,world);
		ls.SetFixedBoundaryCondition_Field(id_field_def_fix1,world);
		ls.InitializeMarge();
		Fem::Eqn::AddLinearSystem_DKT2D_Static(ls,world,id_field_deflect,id_field_rot);
		double res = ls.FinalizeMarge();
		prec.SetValue(ls.m_ls);

		std::cout << "Residual : " << res << std::endl;
		{
			double tol = 1.0e-6;
			unsigned int iter = 10000;
			LsSol::Solve_CG(tol,iter,ls);
//			Fem::Sol::Solve_PCG(tol,iter,ls,prec);
			std::cout << iter << " " << tol << std::endl;
		}
		ls.UpdateValueOfField(id_field_deflect,world,VALUE);
		ls.UpdateValueOfField(id_field_rot,world,VALUE);

		drawer_ary.Clear();
	//	drawer_ary.PushBack( new View::CDrawerVector(id_field_rot,world) );
		drawer_ary.PushBack( new View::CDrawerFace(id_field_deflect,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_deflect,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_deflect,true,world) );
    camera.Fit( drawer_ary.GetBoundingBox(camera.GetRotMatrix3() ) );    
	}

	iprob++;
	if( iprob == nprob ) iprob=0;
}
Example #2
0
void SetNewProblem()
{
	const unsigned int nprob = 9;	// 問題数
	static unsigned int iprob = 0;

	if( iprob == 0 )
	{
		Cad::CCadObj2D cad_2d;
 		{	// 形を作る
			std::vector<Com::CVector2D> vec_ary;
			vec_ary.push_back( Com::CVector2D(0.0,0.0) );
			vec_ary.push_back( Com::CVector2D(5.0,0.0) );
			vec_ary.push_back( Com::CVector2D(5.0,1.0) );
			vec_ary.push_back( Com::CVector2D(0.0,1.0) );
			cad_2d.AddPolygon( vec_ary );
		}
		Msh::CMesh3D_Extrude msh_3d;
		msh_3d.Extrude( Msh::CMesher2D(cad_2d,0.4), 1.0, 0.4 );	// 突き出しによって3次元メッシュを作る
		world.Clear();
		id_base = world.AddMesh( msh_3d );
        const CIDConvEAMshCad& conv = world.GetIDConverter(id_base);
		solid.SetDomain_Field(id_base,world);
		solid.SetYoungPoisson(250, 0.3);	// ヤング率とポアソン比の設定
//		solid.SetGeometricalNonLinear();	// 幾何学的非線形性を考慮する
		solid.UnSetGeometricalNonLinear();
		solid.SetStationary();
        dt = 0.1;
        solid.SetTimeIntegrationParameter(dt,0.6);
//		solid.SetSaveStiffMat();

//		unsigned int id_field_bc0 = solid.AddFixElemAry(7,world);
		unsigned int id_field_bc1 = solid.AddFixElemAry(conv.GetIdEA_fromCad(2,Cad::EDGE,2),world);
    field_value_setter = Fem::Field::CFieldValueSetter(id_field_bc1,world);
    field_value_setter.SetMathExp("sin(5*sin(0.1*t))", 1,Fem::Field::VALUE, world);	// bc1_fieldのy座標に単振動を追加
    field_value_setter.SetMathExp("cos(5*sin(0.1*t))", 2,Fem::Field::VALUE, world);	// bc1_fieldのy座標に単振動を追加
		// 描画オブジェクトの登録
		drawer_ary.Clear();
		id_field_disp = solid.GetIdField_Disp();
		drawer_ary.PushBack( new View::CDrawerFace(id_field_disp,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_disp,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_disp,true ,world) );
    camera.Fit( drawer_ary.GetBoundingBox(camera.GetRotMatrix3()) );            
	}
	else if( iprob == 1 ){
		solid.UnSetStationary();
		solid.UnSetGeometricalNonLinear();	// 幾何学的非線形性を考慮しない
		solid.UnSetSaveStiffMat();			// 全剛性行列を保存する.
	}
	else if( iprob == 2 ){
		solid.SetGeometricalNonLinear();
	}
	else if( iprob == 3 ){
        const CIDConvEAMshCad& conv = world.GetIDConverter(id_base);
		unsigned int id_field_bc0 = solid.AddFixElemAry(conv.GetIdEA_fromCad(4,Cad::EDGE,2),world);
		solid.SetStationary();
	}
	else if( iprob == 4 ){
		solid.UnSetStationary();
	}
	else if( iprob == 5 )
	{
		Msh::CMesher3D mesh_3d;
		mesh_3d.ReadFromFile_GiDMsh("../input_file/cylinder_tet.msh");
		world.Clear();
		id_base = world.AddMesh( mesh_3d );
		solid.SetDomain_Field(id_base,world);
		solid.SetYoungPoisson(200, 0.43);	// ヤング率とポアソン比の設定
		solid.UnSetGeometricalNonLinear();	// 幾何学的非線形性を考慮する.
		solid.UnSetStationary();
		solid.UnSetSaveStiffMat();
		unsigned int id_field_bc0 = solid.AddFixElemAry(3,world);
		unsigned int id_field_bc1 = solid.AddFixElemAry(4,world);
    field_value_setter = Fem::Field::CFieldValueSetter(id_field_bc1,world);
    field_value_setter.SetMathExp("5*sin(2*t)^2", 0,Fem::Field::VALUE, world);	// bc1_fieldのy座標に単振動を追加
		// 描画オブジェクトの登録
		drawer_ary.Clear();
		id_field_disp = solid.GetIdField_Disp();
		drawer_ary.PushBack( new View::CDrawerFace(id_field_disp,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_disp,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_disp,true ,world) );
    camera.Fit( drawer_ary.GetBoundingBox(camera.GetRotMatrix3()) );            
	}
	else if( iprob == 6 ){
		solid.SetStationary();
	}
	else if( iprob == 7 ){
		Msh::CMesher2D mesh_2d;
		mesh_2d.ReadFromFile_GiDMsh("../input_file/rect_quad.msh");
		Msh::CMesh3D_Extrude mesh_3d;
		mesh_3d.Extrude(mesh_2d, 5.0, 0.5 );
        world.Clear();
		id_base = world.AddMesh(mesh_3d);
        const CIDConvEAMshCad& conv = world.GetIDConverter(id_base);
		solid.SetDomain_Field(id_base,world);
		solid.SetYoungPoisson(100, 0.3);	// ヤング率とポアソン比の設定
		solid.UnSetSaveStiffMat();
		solid.UnSetStationary();
        dt = 0.1;
        solid.SetTimeIntegrationParameter(dt,0.52);
//		solid.SetGeometricalNonLinear();	// 幾何学的非線形性を考慮する.
		solid.UnSetGeometricalNonLinear();	// 幾何学的非線形性を考慮する.
		unsigned int id_field_bc0 = solid.AddFixElemAry(conv.GetIdEA_fromMshExtrude(1,1),world);
		unsigned int id_field_bc1 = solid.AddFixElemAry(conv.GetIdEA_fromMshExtrude(3,2),world);
    field_value_setter = Fem::Field::CFieldValueSetter(id_field_bc1,world);
    field_value_setter.SetMathExp("2*sin(t)", 0,Fem::Field::VALUE, world);	// bc1_fieldのy座標に単振動を追加
		// 描画オブジェクトの登録
		drawer_ary.Clear();
		id_field_disp = solid.GetIdField_Disp();
		drawer_ary.PushBack( new View::CDrawerFace(id_field_disp,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_disp,false,world) );
		drawer_ary.PushBack( new View::CDrawerEdge(id_field_disp,true ,world) );
    camera.Fit( drawer_ary.GetBoundingBox(camera.GetRotMatrix3()) );            
	}
	else if( iprob == 8 ){
		solid.UnSetGeometricalNonLinear();	// 幾何学的非線形性を考慮しない
		solid.SetStationary();
	}

	iprob++;
	if( iprob == nprob ){
		iprob = 0;
	}
}