Organize model functions and prototypes. Refs #338

This commit is contained in:
John M. Penn 2016-11-17 16:04:07 -06:00
parent ecc7ac4fc3
commit 9ac0f64f10
15 changed files with 157 additions and 208 deletions

View File

@ -3,7 +3,6 @@ PURPOSE:
(This S_define works with the RUN_analytic input file)
LIBRARY DEPENDENCIES:
(
(cannon/gravity/src/cannon_default_data.c)
(cannon/gravity/src/cannon_init.c)
(cannon/gravity/src/cannon_analytic.c)
)

View File

@ -3,16 +3,14 @@ PURPOSE:
(This S_define is used with RUN_integ input file)
LIBRARY DEPENDENCIES:
(
(cannon/gravity/src/cannon_default_data.c)
(cannon/gravity/src/cannon_init.c)
(cannon/gravity/src/cannon_deriv.c)
(cannon/gravity/src/cannon_numeric.c)
(cannon/gravity/src/cannon_ec_integ.c)
)
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "cannon/gravity/include/cannon.h"
##include "cannon/gravity/include/cannon_eulercromer.h"
class CannonSimObject : public Trick::SimObject {

View File

@ -3,11 +3,8 @@ PURPOSE:
(Cannon Numeric)
LIBRARY DEPENDENCIES:
(
(cannon/gravity/src/cannon_default_data.c)
(cannon/gravity/src/cannon_init.c)
(cannon/gravity/src/cannon_deriv.c)
(cannon/gravity/src/cannon_integ.c)
(cannon/gravity/src/cannon_impact.c)
(cannon/gravity/src/cannon_numeric.c)
)
*************************************************************/

View File

@ -2,7 +2,6 @@
/*************************************************************************
PURPOSE: (Represent the state and initial conditions of a cannonball)
**************************************************************************/
#ifndef CANNON_H
#define CANNON_H
#include "sim_services/Integrator/include/regula_falsi.h"
@ -11,28 +10,37 @@ PURPOSE: (Represent the state and initial conditions of a cannonball)
typedef struct {
double vel0[2] ; /* *i m Init velocity of cannonball */
double pos0[2] ; /* *i m Init position of cannonball */
double init_speed ; /* *i m/s Init barrel speed */
double init_angle ; /* *i rad Angle of cannon */
double vel0[2] ; /* *i m Init velocity of cannonball */
double pos0[2] ; /* *i m Init position of cannonball */
double init_speed ; /* *i m/s Init barrel speed */
double init_angle ; /* *i rad Angle of cannon */
double acc[2] ; /* m/s2 xy-acceleration */
double vel[2] ; /* m/s xy-velocity */
double pos[2] ; /* m xy-position */
double acc[2] ; /* m/s2 xy-acceleration */
double vel[2] ; /* m/s xy-velocity */
double pos[2] ; /* m xy-position */
double time; /* s Model time */
double timeRate; /* -- Model time per Sim time. */
/* =1.0 when cannon ball in flight. =0.0 otherwise. */
double time; /* s Model time */
double timeRate; /* -- Model time per Sim time. */
/* =1.0 when cannon ball in flight. =0.0 otherwise. */
int impact ; /* -- Has impact occured? */
double impactTime; /* s Time of Impact */
int impact ; /* -- Has impact occured? */
double impactTime; /* s Time of Impact */
/* Impact */
REGULA_FALSI rf ; /* -- Dynamic event params for impact */
/* Impact */
REGULA_FALSI rf ; /* -- Dynamic event params for impact */
/* Communication Connection */
TCDevice connection ; /* -- Socket connection for sending position */
/* Communication Connection */
TCDevice connection ; /* -- Socket connection for sending position */
} CANNON ;
#ifdef __cplusplus
extern "C" {
#endif
int cannon_default_data(CANNON*) ;
int cannon_init(CANNON*) ;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -4,7 +4,7 @@ PURPOSE: ( Cannon Analytic Model )
#ifndef CANNON_ANALYTIC_H
#define CANNON_ANALYTIC_H
#include "cannon_common.h"
#include "cannon.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,18 +0,0 @@
/*************************************************************************
PURPOSE: ( Cannon Analytic Model )
**************************************************************************/
#ifndef CANNON_COMMON_H
#define CANNON_COMMON_H
#include "cannon.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_default_data(CANNON*) ;
int cannon_init(CANNON*) ;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -6,12 +6,11 @@ PURPOSE: ( Cannonball EulerCromer Model )
#ifndef CANNON_EULERCROMER_H
#define CANNON_EULERCROMER_H
#include "cannon_common.h"
#include "cannon_numeric.h"
#ifdef __cplusplus
extern "C" {
#endif
int cannon_deriv(CANNON*) ;
int cannon_ec_integ(CANNON*) ;
#ifdef __cplusplus
}

View File

@ -6,7 +6,7 @@ PURPOSE: ( Cannonball Numeric Model )
#ifndef CANNON_NUMERIC_H
#define CANNON_NUMERIC_H
#include "cannon_common.h"
#include "cannon.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,12 +1,12 @@
/*****************************************************************************
PURPOSE: ( Analytical Cannon )
PURPOSE: ( Analytical Cannon )
*****************************************************************************/
#include <stdio.h>
#include <math.h>
#include "../include/cannon.h"
#include "../include/cannon_analytic.h"
int cannon_analytic( CANNON* C ) {
int cannon_analytic( CANNON* C )
{
C->acc[0] = 0.00;
C->acc[1] = -9.81 ;
C->vel[0] = C->vel0[0] + C->acc[0] * C->time ;
@ -25,12 +25,6 @@ int cannon_analytic( CANNON* C )
}
}
/*
* Increment time by the time delta associated with this job
* Note that the 0.01 matches the frequency of this job
* as specified in the S_define.
*/
C->time += 0.01 ;
return 0 ;
C->time += 0.01 ; /* This should match rate of the job in the S_define. */
return 0 ;
}

View File

@ -1,43 +0,0 @@
/******************************* TRICK HEADER ****************************
PURPOSE: (Set the default data values)
LIBRARY_DEPENDENCY: ((cannon_default_data.o))
*************************************************************************/
/* Model Include files */
#include "../include/cannon.h"
#include "sim_services/include/Flag.h"
int cannon_default_data( CANNON* C ) {
const double PI = 3.1415926535;
C->acc[0] = 0.0;
C->acc[1] = -9.81;
C->init_angle = PI/6 ;
C->init_speed = 50.0 ;
C->pos0[0] = 0.0 ;
C->pos0[1] = 0.0 ;
C->impactTime = 0.0 ;
C->time = 0.0 ;
/*
* Regula falsi dynamic event impact setup
*/
#define MY_BIG_TGO 10000
C->rf.lower_set = No ;
C->rf.upper_set = No ;
C->rf.iterations = 0 ;
C->rf.fires = 0 ;
C->rf.x_lower = MY_BIG_TGO ;
C->rf.t_lower = MY_BIG_TGO ;
C->rf.x_upper = MY_BIG_TGO ;
C->rf.t_upper = MY_BIG_TGO ;
C->rf.delta_time = MY_BIG_TGO ;
C->rf.error_tol = 1.0e-9 ;
C->rf.mode = Decreasing ;
C->impact = 0 ;
return(0) ;
}

View File

@ -1,14 +0,0 @@
/*****************************************************************************
PURPOSE: ( Try Trick integration )
*****************************************************************************/
#include "../include/cannon.h"
int cannon_deriv( CANNON* C ) {
if (!C->impact) {
C->acc[0] = 0.00 ;
C->acc[1] = -9.81 ;
C->timeRate = 1.00;
}
return 0 ;
}

View File

@ -1,34 +0,0 @@
/*****************************************************************************
PURPOSE: ( Dynamic Event to determine cannonball impact time. )
*****************************************************************************/
#include <stdio.h>
#include "../include/cannon.h"
#include "sim_services/Integrator/include/integrator_c_intf.h"
double cannon_impact( CANNON* C ) {
double tgo ;
double now ;
/* Set error function --- how far ball is above ground */
C->rf.error = C->pos[1] ;
now = get_integ_time() ;
tgo = regula_falsi( now, &(C->rf) ) ;
if (tgo == 0.0) {
/* Cannonball hits dirt and goes BOOM. */
C->impact = 1 ;
now = get_integ_time() ;
reset_regula_falsi( now, &(C->rf) ) ;
C->vel[0] = 0.0 ; C->vel[1] = 0.0 ;
C->acc[0] = 0.0 ; C->acc[1] = 0.0 ;
C->impactTime = C->time;
fprintf(stderr, "\n\nIMPACT: SimTime = %.9f, ModelTime = %.9f, pos = %.9f\n\n", now, C->impactTime, C->pos[0] ) ;
}
return ( tgo ) ;
}

View File

@ -1,20 +1,60 @@
/*****************************************************************************
PURPOSE: (Initialize the cannonball)
*****************************************************************************/
/******************************* TRICK HEADER ****************************
PURPOSE: (Set the initial data values)
*************************************************************************/
/* Model Include files */
#include <math.h>
#include "../include/cannon_common.h"
#include "../include/cannon.h"
#include "sim_services/include/Flag.h"
int cannon_init( CANNON* C) {
/* default data job */
int cannon_default_data( CANNON* C ) {
C->vel0[0] = C->init_speed*cos(C->init_angle);
C->vel0[1] = C->init_speed*sin(C->init_angle);
const double PI = 3.1415926535;
C->vel[0] = C->vel0[0] ;
C->vel[1] = C->vel0[1] ;
C->acc[0] = 0.0;
C->acc[1] = -9.81;
C->init_angle = PI/6 ;
C->init_speed = 50.0 ;
C->pos0[0] = 0.0 ;
C->pos0[1] = 0.0 ;
C->impactTime = 0.0;
C->impact = 0.0;
C->time = 0.0 ;
return 0 ;
C->impact = 0 ;
C->impactTime = 0.0 ;
/*
* Regula falsi dynamic event impact setup
*/
#define MY_BIG_TGO 10000
C->rf.lower_set = No ;
C->rf.upper_set = No ;
C->rf.iterations = 0 ;
C->rf.fires = 0 ;
C->rf.x_lower = MY_BIG_TGO ;
C->rf.t_lower = MY_BIG_TGO ;
C->rf.x_upper = MY_BIG_TGO ;
C->rf.t_upper = MY_BIG_TGO ;
C->rf.delta_time = MY_BIG_TGO ;
C->rf.error_tol = 1.0e-9 ;
C->rf.mode = Decreasing ;
return(0) ;
}
/* initialization job */
int cannon_init( CANNON* C) {
C->vel0[0] = C->init_speed*cos(C->init_angle);
C->vel0[1] = C->init_speed*sin(C->init_angle);
C->vel[0] = C->vel0[0] ;
C->vel[1] = C->vel0[1] ;
C->impactTime = 0.0;
C->impact = 0.0;
return 0 ;
}

View File

@ -1,46 +0,0 @@
/*****************************************************************************
PURPOSE: ( Integration Job for SIM_cannon_numeric )
*****************************************************************************/
#include "../include/cannon.h"
#include "sim_services/Integrator/include/integrator_c_intf.h"
int cannon_integ( CANNON* C ) {
int ipass;
/* LOAD THE POSITION AND VELOCITY STATES */
load_state(
&C->pos[0] ,
&C->pos[1] ,
&C->vel[0] ,
&C->vel[1] ,
&C->time ,
NULL
);
/* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
load_deriv(
&C->vel[0] ,
&C->vel[1] ,
&C->acc[0] ,
&C->acc[1] ,
&C->timeRate ,
NULL
);
/* CALL THE TRICK INTEGRATION SERVICE */
ipass = integrate();
/* UNLOAD THE NEW POSITION AND VELOCITY STATES */
unload_state(
&C->pos[0] ,
&C->pos[1] ,
&C->vel[0] ,
&C->vel[1] ,
&C->time ,
NULL
);
/* RETURN */
return( ipass );
}

View File

@ -0,0 +1,69 @@
/*****************************************************************************
PURPOSE: ( Numeric integration for SIM_cannon_numeric )
*****************************************************************************/
#include <stdio.h>
#include "../include/cannon_numeric.h"
#include "sim_services/Integrator/include/integrator_c_intf.h"
/* The cannonball sim's derivative job */
int cannon_deriv( CANNON* C ) {
if (!C->impact) {
C->acc[0] = 0.00 ;
C->acc[1] = -9.81 ;
C->timeRate = 1.00;
}
return 0 ;
}
/* The cannonball sim's integration job */
int cannon_integ( CANNON* C ) {
int ipass;
/* LOAD THE POSITION AND VELOCITY STATES */
load_state(
&C->pos[0], &C->pos[1] ,
&C->vel[0], &C->vel[1] ,
&C->time,
NULL
);
/* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
load_deriv(
&C->vel[0], &C->vel[1] ,
&C->acc[0], &C->acc[1] ,
&C->timeRate,
NULL
);
/* CALL THE TRICK INTEGRATION SERVICE */
ipass = integrate();
/* UNLOAD THE NEW POSITION AND VELOCITY STATES */
unload_state(
&C->pos[0], &C->pos[1] ,
&C->vel[0], &C->vel[1] ,
&C->time,
NULL
);
/* RETURN */
return( ipass );
}
/* The cannonball sim's dynamic job */
double cannon_impact( CANNON* C ) {
double tgo ;
double now ;
/* Set error function --- how far ball is above ground */
C->rf.error = C->pos[1] ;
now = get_integ_time() ;
tgo = regula_falsi( now, &(C->rf) ) ;
if (tgo == 0.0) {
C->impact = 1 ;
now = get_integ_time() ;
reset_regula_falsi( now, &(C->rf) ) ;
C->vel[0] = 0.0 ; C->vel[1] = 0.0 ;
C->acc[0] = 0.0 ; C->acc[1] = 0.0 ;
C->impactTime = C->time;
fprintf(stderr, "\n\nIMPACT: SimTime = %.9f, ModelTime = %.9f, pos = %.9f\n\n", now, C->impactTime, C->pos[0] ) ;
}
return ( tgo ) ;
}