pc
Subscriber

/* Replace "dll.h" with the name of your header */
#include "user_force.h"
#include
#include
#include

DLLIMPORT void USER_FORCE(int* Mode , int I_Control[100] , float R_Control[100] ,
                           int* Nstruc , float* Time , float* TimeStep , int* Stage ,
                           float Position[][6] , float Velocity[][6] , float Cog[][3] ,
                           float Force[][6] , float Addmass[][6][6] , int* ErrorFlag)
 
//
// *** Visual C++ Template
// -----------------------
//
// 1. Uses stdcall calling convention
// 2. Routine name MUST be in upper case
// 3. All parameters are passed as pointers
//
// Input Parameter Description:
//
// Mode int*       - 0  = Initialisation. This routine is called once with mode 0
//                        before the simulation. All parameters are as described
//                        below except for STAGE, which is undefined. FORCES and
//                        ADDMAS are assumed undefined on exit.
//                        IERR if set to > 0 on exit will cause
//                        the simulation to stop.
//
//                   1  = Called during the simulation. FORCE/ADDMAS output expected.
//
//                   99 = Termination. This routine is called once with mode 99
//                        at the end of the simulation.
//
// I_Control[100]  - User-defined integer control parameters input in .DAT file.
// (int*)
//
// R_Control[100]  - User-defined real control parameters input in .DAT file.
// (float*)
//
// Nstruc int*     - Number of structures in the the simulation
//
// Time float*     - The current time (see Stage below)
//
// Timestep float* - The current timestep
//
// Stage int*      - The stage of the integration scheme. AQWA time integration is
//                   based on a 2-stage predictor corrector method. This routine is
//                   therefore called twice at each timestep, once with STAGE=1 and
//                   once with STAGE=2. On stage 2 the position and velocity are
//                   predictions of the position and velocity at TIME. e.g. if the
//                   initial time is 0.0 and the step 1.0 seconds then calls are as
//                   follows for the 1st 2 integration steps:
//
//                   CALL USER_FORCE(.....,TIME=0.0,TIMESTEP=1,STAGE=1 ...)
//                   CALL USER_FORCE(.....,TIME=1.0,TIMESTEP=1,STAGE=2 ...)
//                   CALL USER_FORCE(.....,TIME=1.0,TIMESTEP=2,STAGE=1 ...)
//                   CALL USER_FORCE(.....,TIME=2.0,TIMESTEP=2,STAGE=2 ...)
//
// Cog[Nstruc][3]  - Position of the Centre of Gravity in the Definition axes.
//
// Position[Nstruc][6] - Position of the structure in the FRA - angles in radians
// (float*)
//
// Velocity[Nstruc][6] - Velocity of the structure in the FRA
// (float*)              angular velocity in rad/s
//
//
// Output Parameter Description:
//
// Force[Nstruc,6] - Force on the Centre of gravity of the structure. NB: these
// (float)           forces are applied in the Fixed Reference axis e.g.
//                   the surge(X) force is ALWAYS IN THE SAME DIRECTION i.e. in
//                   the direction of the X fixed reference axis.
//
// Addmass[Nstruc,6,6]
// (float)         - Added mass matrix for each structure. As the value of the
//                   acceleration is dependent on FORCES, this matrix may be used
//                   to apply inertia type forces to the structure. This mass
//                   will be added to the total added mass of the structure at each
//                   timestep at each stage.
//
// Errorflag int*  - Error flag. The program will abort at any time if this
//                   error flag is non-zero. The values of the error flag will
//                   be output in the abort message.
               
{
    // DECLARATION SECTION
    /*indices*/
    int i, j;                // indices for controlling loops
    /* External additional forces*/
    float F_ext[6];
    float F_gyro[6];                          // Gyroscopic Moments (forces will be zero)
    
    for (i = 0; i<6; i++){
        F_ext[i] = 0;
        F_gyro[i] = 0;
    }

    int struc = 0;                // Only one structure
    
    /* Inputs from AQUA*/
    float Ir = 12 , omega=50 ;            // Rotor inertia
    float I_rOmega_r[3];    // Rotor second mass moment of inertia in kg m^2
   

        
//------------------------------------------------------------------------
// MODE#0 - Initialise any summing variables/open/create files.
//          This mode is executed once before the simulation begins.
//------------------------------------------------------------------------

    if ( *Mode == 0 )
    {
    }

//------------------------------------------------------------------------
// MODE#1 - On-going - calculation of forces/mass
//------------------------------------------------------------------------

    else if ( *Mode == 1 )
    {
        for ( struc = 0 ; struc < *Nstruc ; struc++ )
        {                        
             // Gyroscopic effect calculations
            
                I_rOmega_r[0] = 0;
                I_rOmega_r[1] = 0; 
                I_rOmega_r[2] = Ir*omega;
            
            // Gyroscopic effect module
            for (j = 0; j <3; j++){
                F_gyro[j] = 0;
                F_gyro[j+3] = 0;
            }
                                                    
            // dot product of Velocity with I_rOmega_r
            F_gyro[3] = Velocity[struc][4] * I_rOmega_r[2] - Velocity[struc][5] * I_rOmega_r[1]; 
            F_gyro[4] = Velocity[struc][5] * I_rOmega_r[0] - Velocity[struc][3] * I_rOmega_r[2]; 
            F_gyro[5] = Velocity[struc][3] * I_rOmega_r[1] - Velocity[struc][4] * I_rOmega_r[0];
            
            
            
            //  Sum of all external force
            for ( i =0 ; i < 6 ; i++ )
            {
                F_ext[i] = F_gyro[i]    
            }

            
            for ( i = 0 ; i < 6 ; i++ )
            {
                Force[struc][i] += F_ext[i]; 
                
                for ( j = 0 ; j < 6 ; j++ )
                {
                    Addmass[struc][i][j] += 0.0;
                }
            }
        }
        *ErrorFlag = 0;
    }

//------------------------------------------------------------------------
// MODE#99 - Termination - Output/print any summaries required/Close Files
//           This mode is executed once at the end of the simulation
//------------------------------------------------------------------------

    else if ( *Mode == 99 )
    {
    }

//------------------------------------------------------------------------
// MODE# ERROR - OUTPUT ERROR MESSAGE
//------------------------------------------------------------------------

    else
    {
    }
    return;

}
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
    switch(fdwReason)
    {
        case DLL_PROCESS_ATTACH:
        {
            break;
        }
        case DLL_PROCESS_DETACH:
        {
            break;
        }
        case DLL_THREAD_ATTACH:
        {
            break;
        }
        case DLL_THREAD_DETACH:
        {
            break;
        }
    }
    
    /* Return TRUE on success, FALSE on failure */
    return TRUE;
}