Skip to content

Commit

Permalink
Separate the MAP++ API from the internal MAP++ data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
sanguinariojoe committed Aug 28, 2024
1 parent 2b877b4 commit 973f55d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 69 deletions.
3 changes: 1 addition & 2 deletions modules/map/src/mapapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
****************************************************************/


#include "mapapi.h"
#include "map.h"
#include "maperror.h"
#include "MAP_Types.h"
#include "mapapi.h"
#include "lineroutines.h"
#include "freedata.h"
#include "mapinit.h"
Expand Down
156 changes: 89 additions & 67 deletions modules/map/src/mapapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
#define _MAPAPI_H


// MAP_EXTERNCALL
#include "mapsys.h"
// MAP_ERROR_CODE
#include "maperror.h"


// Some redefinitions from MAP_Types.h, so the API does not need to exposes the
// internal data structures.
typedef struct MAP_InputType* MAP_Input_t;
typedef struct MAP_ParameterType* MAP_Parameter_t;
typedef struct MAP_ContinuousStateType* MAP_ContinuousState_t;
typedef struct MAP_DiscreteStateType* MAP_DiscreteState_t;
typedef struct MAP_ConstraintStateType* MAP_ConstraintState_t;
typedef struct MAP_OtherStateType* MAP_OtherState_t;
typedef struct MAP_OutputType* MAP_Output_t;
typedef struct MAP_InitOutputType* MAP_InitOutput_t;
typedef struct MAP_InitInputType* MAP_InitInput_t;
// Same with map.h
typedef struct InitializationData_t* MAP_InitializationData_t;
typedef struct Domain_t* MAP_Domain_t;


/**
* @brief Initalizes all MAP base types (including some internal state)
* @details The idea is to set variables to zero and null to prevent seg-faults in the case of
Expand All @@ -34,25 +56,25 @@
* @see map_init()
* @return Size of CableLibrary structure
*/
MAP_EXTERNCALL void map_initialize_msqs_base(MAP_InputType_t* u_type, MAP_ParameterType_t* p_type, MAP_ContinuousStateType_t* x_type, MAP_ConstraintStateType_t* z_type, MAP_OtherStateType_t* other_type, MAP_OutputType_t* y_type, MAP_InitOutputType_t* io_type);
MAP_EXTERNCALL void map_initialize_msqs_base(MAP_Input_t u_type, MAP_Parameter_t p_type, MAP_ContinuousState_t x_type, MAP_ConstraintState_t z_type, MAP_OtherState_t other_type, MAP_Output_t y_type, MAP_InitOutput_t io_type);


MAP_EXTERNCALL void set_init_to_null(MAP_InitInputType_t* init_type, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_add_cable_library_input_text(MAP_InitInputType_t* init_type);
MAP_EXTERNCALL void map_add_node_input_text(MAP_InitInputType_t* init_type);
MAP_EXTERNCALL void map_add_line_input_text(MAP_InitInputType_t* init_type);
MAP_EXTERNCALL void map_add_options_input_text(MAP_InitInputType_t* init_type);
MAP_EXTERNCALL double* map_plot_x_array(MAP_OtherStateType_t* other_type, int i, int num_points, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double* map_plot_y_array(MAP_OtherStateType_t* other_type, int i, int num_points, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double* map_plot_z_array(MAP_OtherStateType_t* other_type, int i, int num_points, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void set_init_to_null(MAP_InitInput_t init_type, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_add_cable_library_input_text(MAP_InitInput_t init_type);
MAP_EXTERNCALL void map_add_node_input_text(MAP_InitInput_t init_type);
MAP_EXTERNCALL void map_add_line_input_text(MAP_InitInput_t init_type);
MAP_EXTERNCALL void map_add_options_input_text(MAP_InitInput_t init_type);
MAP_EXTERNCALL double* map_plot_x_array(MAP_OtherState_t other_type, int i, int num_points, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double* map_plot_y_array(MAP_OtherState_t other_type, int i, int num_points, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double* map_plot_z_array(MAP_OtherState_t other_type, int i, int num_points, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_plot_array_free(double* array) ;
MAP_EXTERNCALL double map_residual_function_length(MAP_OtherStateType_t* other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_residual_function_height(MAP_OtherStateType_t* other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dxdh(MAP_OtherStateType_t* other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dxdv(MAP_OtherStateType_t* other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dzdh(MAP_OtherStateType_t* other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dzdv(MAP_OtherStateType_t* other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL int map_size_lines(MAP_OtherStateType_t* other_type, MAP_ERROR_CODE* ierr, char* map_msg);
MAP_EXTERNCALL double map_residual_function_length(MAP_OtherState_t other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_residual_function_height(MAP_OtherState_t other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dxdh(MAP_OtherState_t other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dxdv(MAP_OtherState_t other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dzdh(MAP_OtherState_t other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL double map_jacobian_dzdv(MAP_OtherState_t other_type, int i, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL int map_size_lines(MAP_OtherState_t other_type, MAP_ERROR_CODE* ierr, char* map_msg);


/**
Expand All @@ -63,7 +85,7 @@ MAP_EXTERNCALL int map_size_lines(MAP_OtherStateType_t* other_type, MAP_ERROR_CO
* @return MAP_SAFE if it completes successfully
* @see {@link map_init()}
*/
MAP_EXTERNCALL int free_init_data (InitializationData* init, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL int free_init_data (MAP_InitializationData_t init, char* map_msg, MAP_ERROR_CODE* ierr);

/**
* @brief Set the water depth. Should be called before {@link map_init()}
Expand All @@ -87,7 +109,7 @@ MAP_EXTERNCALL int free_init_data (InitializationData* init, char* map_msg, MAP_
* CALL mapextern_set_depth(p%C_obj, depth)
* @endcode
*/
MAP_EXTERNCALL void map_set_sea_depth(MAP_ParameterType_t* p_type, const double depth);
MAP_EXTERNCALL void map_set_sea_depth(MAP_Parameter_t p_type, const double depth);


/**
Expand All @@ -112,7 +134,7 @@ MAP_EXTERNCALL void map_set_sea_depth(MAP_ParameterType_t* p_type, const double
* CALL mapextern_set_density(p%C_obj, rho)
* @endcode
*/
MAP_EXTERNCALL void map_set_sea_density(MAP_ParameterType_t* p_type, const double rho);
MAP_EXTERNCALL void map_set_sea_density(MAP_Parameter_t p_type, const double rho);


/**
Expand All @@ -137,7 +159,7 @@ MAP_EXTERNCALL void map_set_sea_density(MAP_ParameterType_t* p_type, const doubl
* CALL mapextern_map_set_gravity(p%C_obj, g)
* @endcode
*/
MAP_EXTERNCALL void map_set_gravity(MAP_ParameterType_t* p_type, const double gravity);
MAP_EXTERNCALL void map_set_gravity(MAP_Parameter_t p_type, const double gravity);


/**
Expand All @@ -151,7 +173,7 @@ MAP_EXTERNCALL void map_set_gravity(MAP_ParameterType_t* p_type, const double gr
* @param ierr, error code
* @see
*/
MAP_EXTERNCALL void map_get_fairlead_force_2d(double* H, double* V, MAP_OtherStateType_t* other_type, int index, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_get_fairlead_force_2d(double* H, double* V, MAP_OtherState_t other_type, int index, char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -166,7 +188,7 @@ MAP_EXTERNCALL void map_get_fairlead_force_2d(double* H, double* V, MAP_OtherSta
* @param ierr, error code
* @see
*/
MAP_EXTERNCALL void map_get_fairlead_force_3d(double* fx, double* fy, double* fz, MAP_OtherStateType_t* other_type, int index, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_get_fairlead_force_3d(double* fx, double* fy, double* fz, MAP_OtherState_t other_type, int index, char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -192,13 +214,13 @@ MAP_EXTERNCALL void map_get_fairlead_force_3d(double* fx, double* fy, double* fz
* global |
* local
*/
MAP_EXTERNCALL void map_offset_vessel(MAP_OtherStateType_t* other_type, MAP_InputType_t* u_type, double x, double y, double z, double phi, double the, double psi, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_offset_vessel(MAP_OtherState_t other_type, MAP_Input_t u_type, double x, double y, double z, double phi, double the, double psi, char* map_msg, MAP_ERROR_CODE* ierr);


/**
* lib.linearize_matrix.argtypes = [MapInput_Type, MapData_Type, MapOutnput_Type, c_double, c_char_p, POINTER(c_int)]
*/
MAP_EXTERNCALL double** map_linearize_matrix(MAP_InputType_t* u_type, MAP_ParameterType_t* p_type, MAP_OtherStateType_t* other_type, MAP_OutputType_t* y_type, MAP_ConstraintStateType_t* z_type, double epsilon, MAP_ERROR_CODE* ierr, char* map_msg);
MAP_EXTERNCALL double** map_linearize_matrix(MAP_Input_t u_type, MAP_Parameter_t p_type, MAP_OtherState_t other_type, MAP_Output_t y_type, MAP_ConstraintState_t z_type, double epsilon, MAP_ERROR_CODE* ierr, char* map_msg);


/**
Expand All @@ -209,7 +231,7 @@ MAP_EXTERNCALL void map_free_linearize_matrix(double** array);
/**
* lib.map_f_op.argtypes = [MapInput_Type, MapData_Type, MapOutnput_Type, c_double, c_char_p, POINTER(c_int)]
*/
MAP_EXTERNCALL double* map_f_op(MAP_InputType_t* u_type, MAP_ParameterType_t* p_type, MAP_OtherStateType_t* other_type, MAP_OutputType_t* y_type, MAP_ConstraintStateType_t* z_type, MAP_ERROR_CODE* ierr, char* map_msg);
MAP_EXTERNCALL double* map_f_op(MAP_Input_t u_type, MAP_Parameter_t p_type, MAP_OtherState_t other_type, MAP_Output_t y_type, MAP_ConstraintState_t z_type, MAP_ERROR_CODE* ierr, char* map_msg);

/**
* lib.map_free_f_op.argtypes = [POINTER(c_double)]
Expand All @@ -232,15 +254,15 @@ MAP_EXTERNCALL void map_free_f_op(double* array);
* @param ierr error code
* @param map_msg error string
*/
MAP_EXTERNCALL void map_init(MAP_InitInputType_t* init_type,
MAP_InputType_t* u_type,
MAP_ParameterType_t* p_type,
MAP_ContinuousStateType_t* x_type,
MAP_DiscreteStateType_t* xd_type,
MAP_ConstraintStateType_t* z_type,
MAP_OtherStateType_t* other_type,
MAP_OutputType_t* y_type,
MAP_InitOutputType_t* ioType,
MAP_EXTERNCALL void map_init(MAP_InitInput_t init_type,
MAP_Input_t u_type,
MAP_Parameter_t p_type,
MAP_ContinuousState_t x_type,
MAP_DiscreteState_t xd_type,
MAP_ConstraintState_t z_type,
MAP_OtherState_t other_type,
MAP_Output_t y_type,
MAP_InitOutput_t ioType,
MAP_ERROR_CODE* ierr,
char* map_msg);

Expand Down Expand Up @@ -270,12 +292,12 @@ MAP_EXTERNCALL void map_init(MAP_InitInputType_t* init_type,
*/
MAP_EXTERNCALL void map_update_states(float t,
int interval,
MAP_InputType_t* u_type,
MAP_ParameterType_t* p_type,
MAP_ContinuousStateType_t* x_type,
MAP_DiscreteStateType_t* xd_type,
MAP_ConstraintStateType_t* z_type,
MAP_OtherStateType_t* other_type,
MAP_Input_t u_type,
MAP_Parameter_t p_type,
MAP_ContinuousState_t x_type,
MAP_DiscreteState_t xd_type,
MAP_ConstraintState_t z_type,
MAP_OtherState_t other_type,
MAP_ERROR_CODE* ierr,
char* map_msg);

Expand All @@ -296,13 +318,13 @@ MAP_EXTERNCALL void map_update_states(float t,
* @see {@link map_update_states()}
*/
MAP_EXTERNCALL void map_calc_output(float t,
MAP_InputType_t* u_type,
MAP_ParameterType_t* p_type,
MAP_ContinuousStateType_t* x_type,
MAP_DiscreteStateType_t* xd_type,
MAP_ConstraintStateType_t* z_type,
MAP_OtherStateType_t* other_type,
MAP_OutputType_t* y_type,
MAP_Input_t u_type,
MAP_Parameter_t p_type,
MAP_ContinuousState_t x_type,
MAP_DiscreteState_t xd_type,
MAP_ConstraintState_t z_type,
MAP_OtherState_t other_type,
MAP_Output_t y_type,
MAP_ERROR_CODE* ierr,
char* map_msg);

Expand All @@ -320,13 +342,13 @@ MAP_EXTERNCALL void map_calc_output(float t,
* @param map_msg error string
* @see {@link map_update_states()}
*/
MAP_EXTERNCALL void map_end(MAP_InputType_t* u_type,
MAP_ParameterType_t* p_type,
MAP_ContinuousStateType_t* x_type,
MAP_DiscreteStateType_t* xd_type,
MAP_ConstraintStateType_t* z_type,
MAP_OtherStateType_t* other_type,
MAP_OutputType_t* y_type,
MAP_EXTERNCALL void map_end(MAP_Input_t u_type,
MAP_Parameter_t p_type,
MAP_ContinuousState_t x_type,
MAP_DiscreteState_t xd_type,
MAP_ConstraintState_t z_type,
MAP_OtherState_t other_type,
MAP_Output_t y_type,
MAP_ERROR_CODE* ierr,
char* map_msg);

Expand Down Expand Up @@ -357,7 +379,7 @@ MAP_EXTERNCALL void map_end(MAP_InputType_t* u_type,
* @endcode
* @todo: need to free summary_file_name. This is done in delete_all_init_data(...), should be called in Fortran routines
*/
MAP_EXTERNCALL void map_set_summary_file_name(MAP_InitInputType_t* init_type, char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL void map_set_summary_file_name(MAP_InitInput_t init_type, char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand Down Expand Up @@ -390,7 +412,7 @@ MAP_EXTERNCALL void map_set_summary_file_name(MAP_InitInputType_t* init_type, ch
* @endcode
* @todo this should raise and error when count!=n
*/
MAP_EXTERNCALL void map_get_header_string(int* n, char** str_array, MAP_OtherStateType_t* other_type);
MAP_EXTERNCALL void map_get_header_string(int* n, char** str_array, MAP_OtherState_t other_type);


/**
Expand Down Expand Up @@ -421,7 +443,7 @@ MAP_EXTERNCALL void map_get_header_string(int* n, char** str_array, MAP_OtherSta
* @endcode
* @todo this should raise and error when count!=n
*/
MAP_EXTERNCALL void map_get_unit_string(int* n, char** str_array ,MAP_OtherStateType_t* other_type);
MAP_EXTERNCALL void map_get_unit_string(int* n, char** str_array ,MAP_OtherState_t other_type);


/**
Expand All @@ -438,7 +460,7 @@ MAP_EXTERNCALL void map_get_unit_string(int* n, char** str_array ,MAP_OtherState
* @param ierr, error code
* @return instance of the packed initialization strings (different from the FAST-required derived types)
*/
MAP_EXTERNCALL InitializationData* MAP_InitInput_Create(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_InitializationData_t MAP_InitInput_Create(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -453,7 +475,7 @@ MAP_EXTERNCALL InitializationData* MAP_InitInput_Create(char* map_msg, MAP_ERROR
* @param ierr, error code
* @return initialization input type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_InitInputType_t* map_create_init_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_InitInput_t map_create_init_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -470,7 +492,7 @@ MAP_EXTERNCALL MAP_InitInputType_t* map_create_init_type(char* map_msg, MAP_ERRO
* @see map_create_other_type()
* @return instance of the interal model struct (different from the FAST-required derived types)
*/
MAP_EXTERNCALL Domain* MAP_OtherState_Create(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_Domain_t MAP_OtherState_Create(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -482,7 +504,7 @@ MAP_EXTERNCALL Domain* MAP_OtherState_Create(char* map_msg, MAP_ERROR_CODE* ierr
* @param ierr, error code
* @return other state type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_OtherStateType_t* map_create_other_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_OtherState_t map_create_other_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -496,7 +518,7 @@ MAP_EXTERNCALL MAP_OtherStateType_t* map_create_other_type(char* map_msg, MAP_ER
* @param ierr, error code
* @return initialization output type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_InitOutputType_t* map_create_initout_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_InitOutput_t map_create_initout_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -510,7 +532,7 @@ MAP_EXTERNCALL MAP_InitOutputType_t* map_create_initout_type(char* map_msg, MAP_
* @param ierr, error code
* @return input type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_InputType_t* map_create_input_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_Input_t map_create_input_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -524,7 +546,7 @@ MAP_EXTERNCALL MAP_InputType_t* map_create_input_type(char* map_msg, MAP_ERROR_C
* @param ierr, error code
* @return parameter type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_ParameterType_t* map_create_parameter_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_Parameter_t map_create_parameter_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -538,7 +560,7 @@ MAP_EXTERNCALL MAP_ParameterType_t* map_create_parameter_type(char* map_msg, MAP
* @param ierr, error code
* @return constraint type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_ConstraintStateType_t* map_create_constraint_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_ConstraintState_t map_create_constraint_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -552,7 +574,7 @@ MAP_EXTERNCALL MAP_ConstraintStateType_t* map_create_constraint_type(char* map_m
* @param ierr, error code
* @return output type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_OutputType_t* map_create_output_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_Output_t map_create_output_type(char* map_msg, MAP_ERROR_CODE* ierr);


/**
Expand All @@ -563,7 +585,7 @@ MAP_EXTERNCALL MAP_OutputType_t* map_create_output_type(char* map_msg, MAP_ERROR
* @param ierr, error code
* @return continuous type (equivalent C binding struct)
*/
MAP_EXTERNCALL MAP_ContinuousStateType_t* map_create_continuous_type(char* map_msg, MAP_ERROR_CODE* ierr);
MAP_EXTERNCALL MAP_ContinuousState_t map_create_continuous_type(char* map_msg, MAP_ERROR_CODE* ierr);


#endif /* _MAPAPI_H */

0 comments on commit 973f55d

Please sign in to comment.