Ejemplo n.º 1
0
void ReferenceFrame2D::GetElementData(ElementDataContainer& edc) 		//fill in all element data
{
	Body2D::GetElementData(edc);

	//IVector FFRFelements; //elements connected to ReferenceFrame
	//SearchTree searchtree; //for optimized node fill
	//TArray<Node*> nodes;
	//int resortconstraint;  //activates resorting of the DOF of the reference frame into the constraint part
	//int isACRS;  //absolute coordinates reduced strain --> the frame rotation and translation is not taken into account in GetPos2D() etc.


	ElementData ed;
	SetElemDataIVector(edc, FFRFelements, "FFRF_elements");

	ed.SetBool(draw_frame, "Draw_Frame"); edc.Add(ed);
}
int Generate_Model_ANCFCable2D_contact(MBS* mbs)
{
    ElementDataContainer* edc = mbs->GetModelDataContainer();

    int nel = edc->TreeGetInt("Geometry.n_fibers");
    double sx = edc->TreeGetDouble("Geometry.length");
    double sy = edc->TreeGetDouble("Geometry.width");
    int nx = edc->TreeGetInt("Geometry.nx");
    int ny = edc->TreeGetInt("Geometry.ny");

    double rho = edc->TreeGetDouble("Geometry.rho");
    double Em = edc->TreeGetDouble("Geometry.Em");
    double nu = edc->TreeGetDouble("Geometry.nu");

    double box_x = edc->TreeGetDouble("Geometry.box_x");
    double box_y = edc->TreeGetDouble("Geometry.box_y");
    int nbox_x = edc->TreeGetInt("Geometry.nres_x");
    int nbox_y = edc->TreeGetInt("Geometry.nres_y");

    Vector3D size(sx,sy,1.0);
    double cdim = sy/2;
    double wi = 1;	//width of GeomLine2D elements (in pts/pixel)

    //===============================2D fibers=========================================

    ANCFCable2D cable(mbs);
    Vector xc1(4);
    Vector xc2(4);
    double phi = -MY_PI/4.;
    xc1(1)=0.5*sx*cos(phi+MY_PI);
    xc1(2)=0.5*sx*sin(phi+MY_PI);
    xc1(3)=cos(phi);
    xc1(4)=sin(phi);
    xc2(1)=xc1(1)+sx*cos(phi);
    xc2(2)=xc1(2)+sx*sin(phi);
    xc2(3)=cos(phi);
    xc2(4)=sin(phi);

    //Material m1(mbs,rho,Em,nu);
    //int mat1 = mbs->AddMaterial(&m1);

    cable.SetANCFCable2D(xc1, xc2, rho, Em, size, Vector3D(0.,0.7,0.));
    //cable.SetANCFCable2D(xc1, xc2, vcenter, vcenter, n1, n2, rho, Em, size, Vector3D(0.,0.7,0.));
    int nr = mbs->AddElement(&cable);

    MBSLoad grav;
    grav.SetBodyLoad(-9.81*rho,2);
    mbs->GetElement(nr).AddLoad(grav);

    //MBSSensor force_x(mbs,TMBSSensor(TSElement+TSDOF),idx1,1); //measure force via Lagrange multiplier
    //force_x.SetSensorName(mystr("Node_")+mystr(i)+mystr("_force_x"));
    //mbs->AddSensor(&force_x);

    TArray<Vector2D> points;
    double dx = sx/nx;
    double dy = sy/ny;

    for(int i=0; i<nx; ++i)
        points.Add(Vector2D(-0.5*sx+i*dx,-0.5*sy));
    for(int i=0; i<ny; ++i)
        points.Add(Vector2D(0.5*sx,-0.5*sy+i*dy));
    for(int i=0; i<nx; ++i)
        points.Add(Vector2D(0.5*sx-i*dx,0.5*sy));
    for(int i=0; i<=ny; ++i)
        points.Add(Vector2D(-0.5*sx,0.5*sy-i*dy));

    //mbs->GetElement(nr).SetAltShape(1);

    ////sensors for nodal positions and velocities
    //MBSSensor s1(mbs,TMBSSensor(TSElement+TSplanar+TSPos+TSX),nr,Vector3D(-0.5*size.X(),0.,0.));
    //s1.SetSensorName(mystr("Node_")+mystr(i)+mystr("_x"));
    //mbs->AddSensor(&s1);

    //sensors
    //field variables not available?
    //{
    //	FieldVariableElementSensor s1(mbs);
    //	s1.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.));
    //	s1.SetSensorName(mystr("cable")+mystr("_x"));
    //	mbs->AddSensor(&s1);

    //	FieldVariableElementSensor s2(mbs);
    //	s2.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.));
    //	s2.SetSensorName(mystr("cable")+mystr("_y"));
    //	mbs->AddSensor(&s2);

    //	FieldVariableElementSensor s3(mbs);
    //	s3.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.));
    //	s3.SetSensorName(mystr("cable")+mystr("_vx"));
    //	mbs->AddSensor(&s3);

    //	FieldVariableElementSensor s4(mbs);
    //	s4.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.));
    //	s4.SetSensorName(mystr("cable")+mystr("_vy"));
    //	mbs->AddSensor(&s4);
    //}

    //contact
    Vector3D contactcol(0.5,0,0.5);
    int slaveNODEmode = 0; //if NODEmode = 1, then use locnodenumbers, if NODEmode==0 then use loccoords
    double bordersize = 0.25*sy; //additional search radius for master and slave segments/nodes
    GeneralContact2D gc(mbs, slaveNODEmode, bordersize, Vector3D(0.0005,0,0), contactcol);
    gc.SetContactMode(0); //0 for Hertzian contact with restitution coefficient
    gc.SetIsLagrange(0);
    double friccoeff = 0.2;
    gc.SetFriction(1, edc->TreeGetDouble("Geometry.friction_coeff"));
    gc.SetContactParams(edc->TreeGetDouble("Geometry.restitution_coeff"),1); //coefficient of restitution, Hertzian contact parameter
    gc.SetContactMaxDist(0.5*sy); //max penetration; if exceeded, it is treated as if there where no contact
    gc.SetSearchTreeDim(20,20);
    double cstiff = edc->TreeGetDouble("Geometry.contact_stiffness");
    int bodyind = 1;

    for(int i=1; i<points.Length(); ++i)
    {
        gc.AddSlaveNode(nr, points(i), cstiff, bodyind);
    }

    if(edc->TreeGetInt("Geometry.mutual_contact"))
    {
        for(int i=1; i<points.Length(); ++i)
        {
            gc.AddMasterSegment(nr,points(i),points(i+1),bodyind); //be careful with orientation of master segments
        }
    }

    //===============================rigid body====================================
    {
        Vector x0i(6);
        x0i(1)=0.;
        x0i(2)=0.25*box_y;
        x0i(3)=0.;
        x0i(4)=0.;
        x0i(5)=0.;
        x0i(6)=0.;
        double r0=0.3*sx;
        Vector3D sizei(r0,r0,1.);
        Vector3D coli(1.,0.,0.);
        Rigid2D testbody(mbs,x0i,rho,sizei,coli);
        int nr = mbs->AddElement(&testbody);
        //MBSLoad load;
        //load.SetForceVector2D(Vector2D(1e-4,2e-4),Vector2D(0.));
        mbs->GetElement(nr).AddLoad(grav);

        TArray<Vector2D> points;
        int ni = 32;
        for(int j=0; j<=ni; ++j)
            points.Add(Vector2D( r0*cos(2*MY_PI/ni*j), r0*sin(2*MY_PI/ni*j) ));


        //for better visualization of rotation
        GeomLine2D c1(mbs,nr,Vector2D(0.,-0.5*r0),Vector2D(0.,0.5*r0),Vector3D(1.,0.,0.));
        GeomLine2D c2(mbs,nr,Vector2D(-0.5*r0,0.),Vector2D(0.5*r0,0.),Vector3D(1.,0.,0.));
        c1.SetDrawParam(Vector3D(2*wi, 10., 0.));
        c2.SetDrawParam(Vector3D(2*wi, 10., 0.));
        mbs->GetElement(nr).Add(c1);
        mbs->GetElement(nr).Add(c2);

        mbs->GetElement(nr).SetAltShape(1);

        //sensors
        //{
        //	FieldVariableElementSensor s1(mbs);
        //	s1.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.));
        //	s1.SetSensorName(mystr("rigid")+mystr("_x"));
        //	mbs->AddSensor(&s1);

        //	FieldVariableElementSensor s2(mbs);
        //	s2.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_position,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.));
        //	s2.SetSensorName(mystr("rigid")+mystr("_y"));
        //	mbs->AddSensor(&s2);

        //	FieldVariableElementSensor s3(mbs);
        //	s3.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_x),Vector2D(0.));
        //	s3.SetSensorName(mystr("rigid")+mystr("_vx"));
        //	mbs->AddSensor(&s3);

        //	FieldVariableElementSensor s4(mbs);
        //	s4.SetFVESPos2D(nr,FieldVariableDescriptor(FieldVariableDescriptor::FieldVariableType::FVT_velocity,FieldVariableDescriptor::FieldVariableComponentIndex::FVCI_y),Vector2D(0.));
        //	s4.SetSensorName(mystr("rigid")+mystr("_vy"));
        //	mbs->AddSensor(&s4);
        //}

        ////lock rotation
        //if(edc->TreeGetInt("Geometry.lock_rigid_body_rotation"))
        //{
        //	CoordConstraint cc1(mbs, nr, 3, cdim);
        //	mbs->AddElement(&cc1);
        //}

        //contact
        bodyind = 2;
        for(int i=1; i<=points.Length(); ++i)
        {
            gc.AddSlaveNode(nr, points(i), cstiff, bodyind);
        }

        if(edc->TreeGetInt("Geometry.mutual_contact"))
        {
            for(int i=1; i<points.Length(); ++i)
            {
                gc.AddMasterSegment(nr,points(i),points(i+1),bodyind); //be careful with orientation of master segments
                GeomLine2D c1(mbs,nr,points(i),points(i+1),Vector3D(1.,0.,0.));
                c1.SetDrawParam(Vector3D(2*wi, 10., 0.));
                mbs->GetElement(nr).Add(c1);
            }
        }

    }

    //===============================frame=========================================

    points.Flush();
    dx = box_x/nbox_x;
    dy = box_y/nbox_y;

    for(int i=0; i<nbox_x; ++i)
        points.Add(Vector2D(-0.5*box_x+i*dx,-0.5*box_y));
    for(int i=0; i<nbox_y; ++i)
        points.Add(Vector2D(0.5*box_x,-0.5*box_y+i*dy));
    for(int i=0; i<nbox_x; ++i)
        points.Add(Vector2D(0.5*box_x-i*dx,0.5*box_y));
    for(int i=0; i<=nbox_y; ++i)
        points.Add(Vector2D(-0.5*box_x,0.5*box_y-i*dy));

    //contact
    bodyind = 0; //must be 0 for mbs
    for(int i=1; i<points.Length(); ++i)
    {
        gc.AddMasterSegment(0,points(i+1),points(i), bodyind); //be careful with orientation of master segments
        GeomLine2D c1(mbs,0,points(i+1),points(i),Vector3D(0.,0.,0.));
        c1.SetDrawParam(Vector3D(2*wi, 10., 0.));
        mbs->Add(c1);
    }

    //finish contact
    gc.FinishContactDefinition();
    mbs->AddElement(&gc);

    mbs->Assemble();

    return 1;
};
void Sensitivity::Init()
{
	mbs->OpenFiles(0); //open files already here, do not append
	ElementDataContainer* edc = mbs->GetMBS_EDC_Options();

	mystr method = edc->TreeGetString("SolverOptions.Sensitivity.method");

	// choose type of analysis
	if(method.Compare(mystr("Forward")))
	{
		type_diff = 1;  //  1 ... df/dx =~ (f(x+dx)-f(x))/dx        forward differentiation
	}
	else if(method.Compare(mystr("Backward")))
	{
		type_diff = -1; // -1 ... df/dx =~ (f(x)-f(x-dx))/dx        backward differentiation
	}
	else
	{
		type_diff = 0;  //  0 ... df/dx =~ (f(x+dx/2)-f(x-dx/2))/dx central differentiation		
	}
	
	// get parameter names
	if(edc->TreeGetInt("SolverOptions.Sensitivity.use_optimization_parameters"))
	{
		number_of_params = edc->TreeGetInt("SolverOptions.Optimization.Parameters.number_of_params");
		for (int col=1; col <= number_of_params; col++)
		{
			mystr str =	edc->TreeGetString(mystr("SolverOptions.Optimization.Parameters.param_name")+mystr(col));
			param_names(col) = new mystr(str);
		}	
	}
	else
	{
		number_of_params = edc->TreeGetInt("SolverOptions.Sensitivity.Parameters.number_of_params");
		for (int col=1; col <= number_of_params; col++)
		{
			mystr str =	edc->TreeGetString(mystr("SolverOptions.Sensitivity.Parameters.param_name")+mystr(col));
			param_names(col) = new mystr(str);
		}
	}

	abs_diff_val = edc->TreeGetDouble("SolverOptions.Sensitivity.num_diff_parameter_absolute");
	rel_diff_val = edc->TreeGetDouble("SolverOptions.Sensitivity.num_diff_parameter_relative");

	NCompSensors = 0; // sensor with computation value (case use_final_sensor_values == 0)

	for(int i = 1; i<=mbs->NSensors();i++)
	{
		mystr str =	"";		
		if(mbs->GetMBS_EDC_Options()->TreeGetInt("SolverOptions.Sensitivity.use_final_sensor_values",0))
		{
			str = mbs->GetSensor(i).GetSensorName();
			sensor_names(i) = new mystr(str); // store names for header
		}
		else
		{
			if(mbs->GetSensor(i).HasSensorProcessingEvaluationData())
			{
				str = mbs->GetSensor(i).GetSensorName();
				NCompSensors++;
				sensor_names(NCompSensors) = new mystr(str); // store names for header
			}
		}	
	}	

	mbs->SolParFile() << GetHeaderString(); // write header into output file (use sensor_names and parameter_names)

}
Ejemplo n.º 4
0
void MathFunction::GetElementData(ElementDataContainer& edc) 		//fill in all element data
{
    ElementData ed;

    //structure of ElementData:
    //Mathfunction
    //{
    //  piecewise_mode = 0/1/2     %modus for piecewise interpolation: -1=not piecewise==>use parsed function, 0=constant, 1=linear, 2=quadratic
    //  piecewise_points = [ ... ] %supporting points (e.g. time or place) for piecewise interpolation
    //  piecewise_values = [ ... ] %values at supporting points
    //  piecewise_diff_values = [ ... ] %differential values at supporting points - for quadratic interpolation
    //  parsed_function = " ... " %string representing parsed function, e.g. "A*sin(omega*t)"
    //  parsed_function_parameter = " ... " %string representing parameter of parsed function, e.g. "t"
    //  user_defined_function = yes %not editable, hard-coded userdefined function!
    //}
    int piecewise_mode = -1;

    //if (funcmode == TMFpiecewiseconst || funcmode == TMFpiecewiselinear || funcmode == TMFpiecewisequad)
    //{
    //}
    if (funcmode == TMFpiecewiseconst)
    {
        piecewise_mode = 0;
    }
    else if (funcmode == TMFpiecewiselinear)
    {
        piecewise_mode = 1;
    }
    else if (funcmode == TMFpiecewisequad)
    {
        piecewise_mode = 2;
    }
    ed.SetInt(piecewise_mode, "piecewise_mode", -1, 2);
    ed.SetToolTipText("modus for piecewise interpolation: -1=not piecewise, 0=constant, 1=linear, 2=quadratic");
    edc.Add(ed);
    ed.SetVector(vectime.GetVecPtr(), vectime.Length(), "piecewise_points");
    ed.SetVariableLength();
    ed.SetToolTipText("supporting points (e.g. time or place) for piecewise interpolation");
    edc.Add(ed);
    ed.SetVector(valX.GetVecPtr(), valX.Length(), "piecewise_values");
    ed.SetVariableLength();
    ed.SetToolTipText("values at supporting points");
    edc.Add(ed);
    ed.SetVector(valY.GetVecPtr(), valY.Length(), "piecewise_diff_values");
    ed.SetVariableLength();
    ed.SetToolTipText("differential values at supporting points - for quadratic interpolation");
    edc.Add(ed);


    if (funcmode == TMFexpression)
    {
        ed.SetText(parsedFunctionExpression.c_str(), "parsed_function");
        ed.SetToolTipText("string representing parsed function, e.g. 'A*sin(omega*t)'");
        edc.Add(ed);
        ed.SetText(parsedFunctionVariables.c_str(), "parsed_function_parameter");
        ed.SetToolTipText("string representing parameter of parsed function, e.g. 't'");
        edc.Add(ed);
    }
    else
    {
        //initialize with zero strings:
        ed.SetText("", "parsed_function");
        ed.SetToolTipText("string representing parsed function, e.g. 'A*sin(omega*t)'");
        edc.Add(ed);
        ed.SetText("", "parsed_function_parameter");
        ed.SetToolTipText("string representing parameter of parsed function, e.g. 't'");
        edc.Add(ed);
    }

    if (funcmode == TMFuserdefined)
    {
        ed.SetBool(1,"user_defined_function");
        ed.SetLocked(1);
        ed.SetToolTipText("not editable, hard-coded userdefined function!");
        edc.Add(ed);
    }
}