C/C++ example for Get_rflex_macc

 

#include "stdafx.h"

#include "DllFunc.h"

#include <stdio.h>

 

Get_rflex_mcoor_API void __cdecl modal_force

           (int id, double time, double upar[], int npar, int ifbody, double pos[12],

           double vel[6], double acc[6], int nmode, int nnode, int nModalLoad, double *ModalLoads,

           int jflag, int iflag, double *result)

{

           using namespace rd_syscall;

           // Parameter Information

           //     id: MFORCE ID (Input)

           //   time: Simulation time of RD/Solver (Input)

           //   upar: Parameters defined by user (Input)

           //   npar: Number of user parameters (Input)

           //   ifbody : RFLEX body seq ID (Input)

           //   pos : Position(1~3) and Orientation matrix (4~12) w.r.t Ground.InertiaMarker (Input)

           //   vel : Velocity vector w.r.t. Ground.InertiaMarker (Input)

           //   acc : Acceleration vector w.r.t Ground.InertiaMarker (Input)

           //   nmode : No of selected mode (Input)

           //   nnode : No of node (Input)

           //   nModalLoad : No of selected modal load cases (Input)

           //   ModalLoads : Modal-force vector (Input, size : [(6+nmode) x nModalLoad] )

           //   jflag: When RD/Solver evaluates a Jacobian, the flag is true. (Input)

           //   iflag: When RD/Solver initializes arrays, the flag is true. (Input)

           //   result: Returned modal froce vector (Output, Size : [6+nmode] )

 

           int i,ierr;

           double *MC=NULL; // Modal coordinate

           double *MVel=NULL; // Modal velocity

           double *MAcc=NULL; // Modal acceleration

           int *SelectedModeIds=NULL;

           static int Wflag=0;

           static double settime=-0.1;

 

           FILE* MCwrite;

 

           if(iflag)

           {

                     MCwrite=fopen("ModalCoordinate_C.txt","w");

                     fprintf(MCwrite,"*** C program \n");

 

                     // RFLEX Information

                     fprintf(MCwrite,"*** RFLEX Information\n");

                     fprintf(MCwrite,"    RFLEX body seq. Id = %d\n",ifbody);

                     fprintf(MCwrite,"    No. selected mode = %d\n",nmode);

                     fprintf(MCwrite,"    No. Modal Load Case = %d\n",nModalLoad);

                     fprintf(MCwrite,"    No. Node(Grid) = %d\n",nnode);

                     fprintf(MCwrite,"    No. User Parameter (USUB) = %d\n",npar);

                     fprintf(MCwrite,"\n\n");

 

// selected mode information

                     SelectedModeIds = new int[nmode];

                     get_rflex_modeid(ifbody,SelectedModeIds,&ierr);

 

                     fprintf(MCwrite,"*** Modal Coordinate and Velocity and Acceleration\n");

                     fprintf(MCwrite," Time ");

                     for(i=0;i<nmode;i++)

                                fprintf(MCwrite," MC%d ",SelectedModeIds[i]);

                    

                     for(i=0;i<nmode;i++)

                                fprintf(MCwrite," MV%d ",SelectedModeIds[i]);

                    

                     for(i=0;i<nmode;i++)

                                fprintf(MCwrite," MA%d ",SelectedModeIds[i]);

fprintf(MCwrite,"\n");

 

                     fclose(MCwrite);

 

           }

 

           MCwrite=fopen("ModalCoordinate_C.txt","a+");

 

           for(i=0;i<6+nmode;i++)

           {

                     result[i] = 0.0;

           }

 

           if(!jflag && !iflag)

           {

                     Wflag++;

                     if(Wflag == 2 && settime == time) // Final caclulation for Report

                     {

                                // allocated memory 

                                MC = new double[nmode];

                                MVel = new double[nmode];

                                MAcc = new double[nmode];

 

                                get_rflex_mcoor(ifbody,MC,&ierr);

                                get_rflex_mvel(ifbody,MVel,&ierr);

                                get_rflex_macc(ifbody,MAcc,&ierr);

 

                                fprintf(MCwrite," %20.10e ",time);

                                for(i=0;i<nmode;i++)

                                {

                                           fprintf(MCwrite," %20.10e ",MC[i]);

                                }

                                for(i=0;i<nmode;i++)

                                {

                                           fprintf(MCwrite," %20.10e ",MVel[i]);

                                }

                                for(i=0;i<nmode;i++)

                                {

                                           fprintf(MCwrite," %20.10e ",MAcc[i]);

                                }

                                fprintf(MCwrite,"\n");

 

 

                                // deallocate memory

                                delete [] MC;

                                delete [] MVel;

                                delete [] MAcc;

                     }

                     settime = time;                  

           }

           if(jflag) Wflag = 0;

 

           fclose(MCwrite);

 

}