C/C++ example for Get_rflex_invvarm1

 

#include "stdafx.h"

#include "DllFunc.h"

#include <stdio.h>

 

Get_rflex_invvarm_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,j,k,ierr;

           double InvVarM1;

           double InvVarM2[3];

           double InvVarM3[9];

           double *InvVarN1;

           double *InvVarN2;

           double *InvVarN3;

           double *InvVarN4;

           double *InvVarN5;

           double *InvVarN6;

           int *SelectedModeIds;

 

           FILE* ForDebug;

 

           if(iflag)

           {

                     ForDebug=fopen("CprogramDebug.txt","w");

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

 

                     // RFLEX Information

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

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

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

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

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

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

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

 

                     // allocate memory

                     SelectedModeIds = new int[nmode];

                     InvVarN1 = new double[3*nmode];

                     InvVarN2 = new double[9*nmode];

                     InvVarN3 = new double[9*nmode];

                     InvVarN4 = new double[9*nmode*nmode];

                     InvVarN5 = new double[3*nmode];

                     InvVarN6 = new double[3*nmode*nmode];

 

                     // get Mode Ids (Selected modes)

                     get_rflex_modeid(ifbody,SelectedModeIds,&ierr);

 

                     // Call auxiliary functions (Get Invariant Variables)

                     get_rflex_invvarm1(ifbody,&InvVarM1,&ierr);

                     get_rflex_invvarm2(ifbody,InvVarM2,&ierr);

                     get_rflex_invvarm3(ifbody,InvVarM3,&ierr);

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

                     {

                                get_rflex_invvarn1(ifbody,SelectedModeIds[i],&(InvVarN1[3*i]),&ierr);

                                get_rflex_invvarn2(ifbody,SelectedModeIds[i],&(InvVarN2[9*i]),&ierr);

                                get_rflex_invvarn3(ifbody,SelectedModeIds[i],&(InvVarN3[9*i]),&ierr);

                                get_rflex_invvarn5(ifbody,SelectedModeIds[i],&(InvVarN5[3*i]),&ierr);

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

                                {

get_rflex_invvarn4(ifbody,SelectedModeIds[i],SelectedModeIds[j],&(InvVarN4[9*nmode*i+9*j]),&ierr);

get_rflex_invvarn6(ifbody,SelectedModeIds[i],SelectedModeIds[j],&(InvVarN6[3*nmode*i+3*j]),&ierr);

                                }

                     }

 

                     // Write Invariant variable M1

                     fprintf(ForDebug,"*** Invariant Variable M1\n");

                     fprintf(ForDebug," %20.10e \n", InvVarM1);

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

 

                     // Write Invariant variable M2

                     fprintf(ForDebug,"*** Invariant Variable M2\n");

                     fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarM2[0],InvVarM2[1],InvVarM2[2]);

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

 

                     // Write Invariant variable M3

                     fprintf(ForDebug,"*** Invariant Variable M3\n");

                     fprintf(ForDebug," %20.10e %20.10e %20.10e \n", nvVarM3[0],InvVarM3[1],InvVarM3[2]);

                     fprintf(ForDebug," %20.10e %20.10e %20.10e \n", nvVarM3[3],InvVarM3[4],InvVarM3[5]);

                     fprintf(ForDebug," %20.10e %20.10e %20.10e \n", nvVarM3[6],InvVarM3[7],InvVarM3[8]);

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

                    

                     // Write Invariant variable N1

                     fprintf(ForDebug,"*** Invariant Variable N1\n");

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

                     {

                                fprintf(ForDebug," Mode ID : %d (Selected mode)\n",SelectedModeIds[i]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN1[3*i+0],InvVarN1[3*i+1],InvVarN1[3*i+2]);

                     }

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

                    

                     // Write Invariant variable N2

                     fprintf(ForDebug,"*** Invariant Variable N2\n");

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

                     {

                                fprintf(ForDebug," Mode ID : %d (Selected mode)\n",SelectedModeIds[i]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN2[9*i+0],InvVarN2[9*i+1],InvVarN2[9*i+2]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN2[9*i+3],InvVarN2[9*i+4],InvVarN2[9*i+5]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN2[9*i+6],InvVarN2[9*i+7],InvVarN2[9*i+8]);

                     }

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

                    

                     // Write Invariant variable N3

                     fprintf(ForDebug,"*** Invariant Variable N3\n");

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

                     {

                                fprintf(ForDebug," Mode ID : %d (Selected mode)\n",SelectedModeIds[i]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN3[9*i+0],InvVarN3[9*i+1],InvVarN3[9*i+2]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN3[9*i+3],InvVarN3[9*i+4],InvVarN3[9*i+5]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN3[9*i+6],InvVarN3[9*i+7],InvVarN3[9*i+8]);

                     }

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

                    

                     // Write Invariant variable N4

                     fprintf(ForDebug,"*** Invariant Variable N4\n");

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

                     {

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

                                {

                                           fprintf(ForDebug," 1st Mode ID : %d / 2nd Mode ID : %d \n",SelectedModeIds[i],SelectedModeIds[j]);

                                           fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN4[9*nmode*i+9*j+0],InvVarN4[9*nmode*i+9*j+1]

,InvVarN4[9*nmode*i+9*j+2]);

                                           fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN4[9*nmode*i+9*j+3],InvVarN4[9*nmode*i+9*j+4

],InvVarN4[9*nmode*i+9*j+5]);

                                           fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN4[9*nmode*i+9*j+6],InvVarN4[9*nmode*i+9*j+7

],InvVarN4[9*nmode*i+9*j+8]);

                                }

                     }

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

                    

                     // Write Invariant variable N5

                     fprintf(ForDebug,"*** Invariant Variable N5\n");

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

                     {

                                fprintf(ForDebug," Mode ID : %d \n",SelectedModeIds[i]);

                                fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN5[3*i+0],InvVarN5[3*i+1],InvVarN5[3*i+2]);

                     }

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

                    

                     // Write Invariant variable N6

                     fprintf(ForDebug,"*** Invariant Variable N6\n");

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

                     {

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

                                {

                                           fprintf(ForDebug," 1st Mode ID : %d / 2nd Mode ID : %d \n",SelectedModeIds[i],SelectedModeIds[j]);

                                           fprintf(ForDebug," %20.10e %20.10e %20.10e \n", InvVarN6[3*nmode*i+3*j],InvVarN6[3*nmode*i+3*j+1],InvVarN6[3*nmode*i+3*j+2]);

                                }

                     }

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

 

                    

                     // Deallocate memory

                     delete [] SelectedModeIds;

                     delete [] InvVarN1;

                     delete [] InvVarN2;

                     delete [] InvVarN3;

                     delete [] InvVarN4;

                     delete [] InvVarN5;

                     delete [] InvVarN6;

 

                     fclose(ForDebug);

           }

 

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

           {

                     result[i] = 0.0;

           }

}