Commit 088a8c4a authored by Olivier Lantsoght's avatar Olivier Lantsoght 🏁
Browse files

Merge branch 'better_errors_child' into 'dev'

Better errors handling

See merge request robotran/mbsysc!391
parents ca1f5f73 9fce2ae8
## Changes for next release ## Changes for next release
* To be defined * To be defined
* [C][Python] error handling is enhanced, with new error names and proper closing of the functions for all modules, except Real-time in dirdyn
* [C] All user models are printed with the `mbs_print_data` function * [C] All user models are printed with the `mbs_print_data` function
* [C] New function `print_d_vec_0_format` allowing to set the format of the vector values. * [C] New function `print_d_vec_0_format` allowing to set the format of the vector values.
* [C] New function to compute matrix product between matrices of specified shape: `doublematrix_product_0`. * [C] New function to compute matrix product between matrices of specified shape: `doublematrix_product_0`.
* [C] LPK functions new error catched with code `-#16`; Documentation fixed. * [C] LPK functions new error catched with code `-#16`; Documentation fixed.
* [C] Some functions that my be called by users have return status (<0 in case of error):
* Look Up Table: `mbs_lut_2D_alloc()`, `mbs_lut_res_alloc()`, `mbs_lut_res_load_file()`;
* Useful functions: `read_dmat_0()`
* [Py] User vector outputs are now available in the MbsDirdyn results field. * [Py] User vector outputs are now available in the MbsDirdyn results field.
* [Py] Using C symbolic library and Python user is possible even with external forces. * [Py] Using C symbolic library and Python user is possible even with external forces.
* [Py] Adding missing fields in MbsData. * [Py] Adding missing fields in MbsData.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "mbs_load_libraries.h" #include "mbs_load_libraries.h"
#include "mbs_path.h" #include "mbs_path.h"
#include "mbs_message.h" #include "mbs_message.h"
#include "mbs_errors_names.h"
#include "mbs_project_interface.h" #include "mbs_project_interface.h"
...@@ -177,7 +178,7 @@ int mbs_load_symbolic_functions(MbsData* mbs_data, const char* symbolicLib_path, ...@@ -177,7 +178,7 @@ int mbs_load_symbolic_functions(MbsData* mbs_data, const char* symbolicLib_path,
mbs_msg(">>LOAD>> Error in mbs_load_symbolic_functions, unable to load symbolic library.\n"); mbs_msg(">>LOAD>> Error in mbs_load_symbolic_functions, unable to load symbolic library.\n");
mbs_msg(" Library path: %s\n", lib_fullpath); mbs_msg(" Library path: %s\n", lib_fullpath);
free(lib_fullpath); free(lib_fullpath);
return -8; return _MBS_ERR_LOW_FILES;
} }
mbs_data->fct.symb.mbs_link = (mbs_link_ptr)mbs_load_function(symbLibInfo, "mbs_link"); mbs_data->fct.symb.mbs_link = (mbs_link_ptr)mbs_load_function(symbLibInfo, "mbs_link");
...@@ -221,7 +222,7 @@ int mbs_load_user_functions(MbsData* mbs_data, const char* userfctLib_path, cons ...@@ -221,7 +222,7 @@ int mbs_load_user_functions(MbsData* mbs_data, const char* userfctLib_path, cons
mbs_msg(">>LOAD>> Error in mbs_load_user_functions, unable to load user library.\n"); mbs_msg(">>LOAD>> Error in mbs_load_user_functions, unable to load user library.\n");
mbs_msg(" Library path: %s\n", lib_fullpath); mbs_msg(" Library path: %s\n", lib_fullpath);
free(lib_fullpath); free(lib_fullpath);
return -8; return _MBS_ERR_LOW_FILES;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "mbs_path.h" #include "mbs_path.h"
#include "mbs_message.h" #include "mbs_message.h"
#include "mbs_check.h" #include "mbs_check.h"
#include "mbs_errors_names.h"
#include <string.h> #include <string.h>
...@@ -38,6 +38,10 @@ MbsData* mbs_load(const char* mbs_filename, const char* build_path) ...@@ -38,6 +38,10 @@ MbsData* mbs_load(const char* mbs_filename, const char* build_path)
loader = mbs_new_loader(); loader = mbs_new_loader();
mbs_data = mbs_load_with_loader(mbs_filename, build_path, loader); mbs_data = mbs_load_with_loader(mbs_filename, build_path, loader);
mbs_delete_loader(loader); mbs_delete_loader(loader);
if (mbs_data == NULL)
{
mbs_error_msg("in mbs_load !! \n");
}
return mbs_data; return mbs_data;
} }
...@@ -61,7 +65,7 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path, ...@@ -61,7 +65,7 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path,
mbs_infos = mbs_info_reader(mbs_filename); mbs_infos = mbs_info_reader(mbs_filename);
if (!mbs_infos){ if (!mbs_infos){
mbs_msg(">>LOAD>> unable to create MbsInfo.\n"); mbs_msg(">>LOAD>> unable to create MbsInfo.\n");
mbs_error_msg("[%d] in mbs_load_with_loader !! \n", -909); mbs_msg("[%d] in mbs_load_with_loader !! \n", _MBS_ERR_MOD_LOAD + _MBS_ERR_LOW_FILES);
return NULL; return NULL;
} }
} }
...@@ -83,7 +87,7 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path, ...@@ -83,7 +87,7 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path,
{ {
mbs_msg(">>LOAD>> build_path is not defined \n"); mbs_msg(">>LOAD>> build_path is not defined \n");
mbs_msg("\n>>LOAD>> Check your files names and paths \n\n"); mbs_msg("\n>>LOAD>> Check your files names and paths \n\n");
mbs_error_msg("[%d] in mbs_load_with_loader !! \n", -910); mbs_msg("[%d] in mbs_load_with_loader !! \n", _MBS_ERR_MOD_LOAD +_MBS_ERR_LOW_FILES);
free(symbolicLib_name); free(symbolicLib_name);
free(symbolicLib_path); free(symbolicLib_path);
free(userfctLib_name); free(userfctLib_name);
...@@ -154,14 +158,30 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path, ...@@ -154,14 +158,30 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path,
mbs_data = mbs_new_data(); mbs_data = mbs_new_data();
mbs_data->project_path = (char*)malloc(sizeof(char)*(strlen(mbs_filename) + 100)); mbs_data->project_path = (char*)malloc(sizeof(char)*(strlen(mbs_filename) + 100));
find_project_path(mbs_filename, mbs_data->project_path); err = find_project_path(mbs_filename, mbs_data->project_path);
if (err <0)
{
free(symbolicLib_name);
free(symbolicLib_path);
free(userfctLib_name);
free(userfctLib_path);
if (!custom_mbs_info) {
mbs_delete_infos(mbs_infos);
}
mbs_msg("\n>>LOAD>> find_project_path \n\n");
mbs_msg("[%d] in mbs_load_with_loader !! \n", _MBS_ERR_MOD_LOAD + err);
mbs_delete_data(mbs_data);
return NULL;
}
// if we call project and user function pointer, init them // if we call project and user function pointer, init them
#ifdef PRJ_FCT_PTR #ifdef PRJ_FCT_PTR
if (opts->load_symb_user!=LOAD_NONE) { if (opts->load_symb_user!=LOAD_NONE) {
err = mbs_load_symbolic_functions(mbs_data, symbolicLib_path, symbolicLib_name); err = mbs_load_symbolic_functions(mbs_data, symbolicLib_path, symbolicLib_name);
if (err < 0){ if (err < 0){
mbs_error_msg("[%d] in mbs_load_with_loader !! \n", -900 + err); mbs_msg("[%d] in mbs_load_with_loader !! \n", _MBS_ERR_MOD_LOAD + err);
free(symbolicLib_name); free(symbolicLib_name);
free(symbolicLib_path); free(symbolicLib_path);
free(userfctLib_name); free(userfctLib_name);
...@@ -180,7 +200,7 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path, ...@@ -180,7 +200,7 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path,
if(opts->load_symb_user==LOAD_ALL) { if(opts->load_symb_user==LOAD_ALL) {
err = mbs_load_user_functions(mbs_data, userfctLib_path, userfctLib_name); err = mbs_load_user_functions(mbs_data, userfctLib_path, userfctLib_name);
if (err < 0){ if (err < 0){
mbs_error_msg("[%d] in mbs_load_with_loader !! \n", -900 + err); mbs_msg("[%d] in mbs_load_with_loader !! \n", _MBS_ERR_MOD_LOAD + err);
free(symbolicLib_name); free(symbolicLib_name);
free(symbolicLib_path); free(symbolicLib_path);
free(userfctLib_name); free(userfctLib_name);
...@@ -204,6 +224,21 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path, ...@@ -204,6 +224,21 @@ MbsData* mbs_load_with_loader(const char* mbs_filename, const char* build_path,
#endif #endif
mbs_data = mbs_info_to_data(mbs_infos, mbs_data); mbs_data = mbs_info_to_data(mbs_infos, mbs_data);
if (mbs_data == NULL)
{
free(symbolicLib_name);
free(symbolicLib_path);
free(userfctLib_name);
free(userfctLib_path);
if (!custom_mbs_info) {
mbs_delete_infos(mbs_infos);
}
mbs_msg("\n>>LOAD>> mbs_info_to_data \n\n");
mbs_msg("[%d] in mbs_load_with_loader !! \n", _MBS_ERR_MOD_LOAD + _MBS_ERR_LOW_FILES);
return NULL;
}
mbs_data->mbs_filename = (char*)malloc(1 + strlen(mbs_filename)); mbs_data->mbs_filename = (char*)malloc(1 + strlen(mbs_filename));
strcpy(mbs_data->mbs_filename, mbs_filename); strcpy(mbs_data->mbs_filename, mbs_filename);
...@@ -710,8 +745,8 @@ MbsData* mbs_info_to_data(MbsInfos* mbs_infos, MbsData* s) ...@@ -710,8 +745,8 @@ MbsData* mbs_info_to_data(MbsInfos* mbs_infos, MbsData* s)
{ {
mbs_msg(">>LOAD>> Error while fetching user_model number \n"); mbs_msg(">>LOAD>> Error while fetching user_model number \n");
mbs_msg("\n>>LOAD>> Please Re-generated your user_model Files !!! \n\n"); mbs_msg("\n>>LOAD>> Please Re-generated your user_model Files !!! \n\n");
mbs_error_msg("[%d] in mbs_load_with_loader \n", -900); mbs_msg("[%d] in mbs_load_with_loader \n", _MBS_ERR_MOD_LOAD);
exit(1); return NULL;
} }
free_ivec_1(user_model_list_c); free_ivec_1(user_model_list_c);
free_ivec_1(user_model_list_mbs); free_ivec_1(user_model_list_mbs);
...@@ -762,8 +797,8 @@ MbsData* mbs_info_to_data(MbsInfos* mbs_infos, MbsData* s) ...@@ -762,8 +797,8 @@ MbsData* mbs_info_to_data(MbsInfos* mbs_infos, MbsData* s)
{ {
mbs_msg(">>LOAD>> Error while fetching user_IO number \n"); mbs_msg(">>LOAD>> Error while fetching user_IO number \n");
mbs_msg("\n>>LOAD>> Please Re-generated your user_IO Files !!! \n\n"); mbs_msg("\n>>LOAD>> Please Re-generated your user_IO Files !!! \n\n");
mbs_error_msg("[%d] in mbs_load_with_loader \n", -900); mbs_msg("[%d] in mbs_load_with_loader \n", _MBS_ERR_MOD_LOAD);
exit(1); return NULL;
} }
if (s->n_user_IO) { if (s->n_user_IO) {
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include "mbs_xml_binder_private.h" #include "mbs_xml_binder_private.h"
#include "mbs_message.h" #include "mbs_message.h"
#include "mbs_errors_names.h"
///////////////////////////////////////// /////////////////////////////////////////
/// GET functions /////////////////////// /// GET functions ///////////////////////
...@@ -1449,9 +1451,8 @@ int mbs_info_mbsDescR7_binder(MbsInfos *mbs_infos, xmlNodePtr node, int mission) ...@@ -1449,9 +1451,8 @@ int mbs_info_mbsDescR7_binder(MbsInfos *mbs_infos, xmlNodePtr node, int mission)
mbs_msg(">>LOAD>> Error during xmlParseFile function \n"); mbs_msg(">>LOAD>> Error during xmlParseFile function \n");
mbs_msg(">>LOAD>> MDS_mbs_reader : Empty XML document\n"); mbs_msg(">>LOAD>> MDS_mbs_reader : Empty XML document\n");
mbs_msg(">>LOAD>> Check your files names and paths \n\n"); mbs_msg(">>LOAD>> Check your files names and paths \n\n");
mbs_error_msg("[%d] in MDS_mbs_reader !! \n", -909); mbs_msg("[%d] in MDS_mbs_reader !! \n", _MBS_ERR_LOW_FILES);
exit(1); return _MBS_ERR_LOW_FILES;
return 0;
} }
cur_node = node->children; cur_node = node->children;
...@@ -1747,6 +1748,7 @@ int mbs_info_init_and_binder(MbsInfos *mbs_infos, const char *mbs_xml_name, int ...@@ -1747,6 +1748,7 @@ int mbs_info_init_and_binder(MbsInfos *mbs_infos, const char *mbs_xml_name, int
{ {
xmlDocPtr doc; xmlDocPtr doc;
xmlNodePtr root; xmlNodePtr root;
int err = 0;
// xml document opening // xml document opening
xmlKeepBlanksDefault(0); // Ignore les noeuds texte composant la mise en forme xmlKeepBlanksDefault(0); // Ignore les noeuds texte composant la mise en forme
...@@ -1755,22 +1757,29 @@ int mbs_info_init_and_binder(MbsInfos *mbs_infos, const char *mbs_xml_name, int ...@@ -1755,22 +1757,29 @@ int mbs_info_init_and_binder(MbsInfos *mbs_infos, const char *mbs_xml_name, int
mbs_msg(">>LOAD>> Error during xmlParseFile function \n"); mbs_msg(">>LOAD>> Error during xmlParseFile function \n");
mbs_msg(">>LOAD>> mbs_info_init_and_binder : Invalid XML document\n"); mbs_msg(">>LOAD>> mbs_info_init_and_binder : Invalid XML document\n");
mbs_msg(">>LOAD>> Check your files names and paths \n\n"); mbs_msg(">>LOAD>> Check your files names and paths \n\n");
mbs_error_msg("[%d] in mbs_info_init_and_binder !! \n", -909); mbs_msg("[%d] in mbs_info_init_and_binder !! \n", _MBS_ERR_LOW_FILES);
return -1; return _MBS_ERR_LOW_FILES;
} }
// getting the root // getting the root
root = xmlDocGetRootElement(doc); root = xmlDocGetRootElement(doc);
if (root == NULL) { if (root == NULL) {
xmlFreeDoc(doc);
mbs_msg(">>LOAD>> Error during xmlParseFile function \n"); mbs_msg(">>LOAD>> Error during xmlParseFile function \n");
mbs_msg(">>LOAD>> mbs_info_init_and_binder : Empty XML document\n"); mbs_msg(">>LOAD>> mbs_info_init_and_binder : Empty XML document\n");
mbs_msg(">>LOAD>> Check your files names and paths \n\n"); mbs_msg(">>LOAD>> Check your files names and paths \n\n");
mbs_error_msg("[%d] in mbs_info_init_and_binder !! \n", -909); mbs_msg("[%d] in mbs_info_init_and_binder !! \n", _MBS_ERR_LOW_FILES);
return -1; xmlFreeDoc(doc);
xmlCleanupParser();
return _MBS_ERR_LOW_FILES;
} }
mbs_info_mbsDescR7_binder(mbs_infos, root, mission); err = mbs_info_mbsDescR7_binder(mbs_infos, root, mission);
if (err < 0)
{
mbs_msg(">>LOAD>> Error during mbs_info_mbsDescR7_binder function \n");
xmlFreeDoc(doc);
xmlCleanupParser();
return err;
}
if (mission == MBS_INFO_UPDATER) if (mission == MBS_INFO_UPDATER)
{ {
xmlSaveFormatFile("updated_prject.mbs", doc, 1); xmlSaveFormatFile("updated_prject.mbs", doc, 1);
...@@ -1810,7 +1819,7 @@ int mbs_info_updater(MbsInfos *mbs_infos, const char *mbs_xml_name) ...@@ -1810,7 +1819,7 @@ int mbs_info_updater(MbsInfos *mbs_infos, const char *mbs_xml_name)
err = mbs_info_init_and_binder(mbs_infos, mbs_xml_name, MBS_INFO_UPDATER); err = mbs_info_init_and_binder(mbs_infos, mbs_xml_name, MBS_INFO_UPDATER);
if (err < 0){ if (err < 0){
mbs_msg(">>LOAD>> Error during function mbs_info_updater.\n"); mbs_msg(">>LOAD>> Error during function mbs_info_updater.\n");
return -1; return err;
} }
return MBS_INFO_SUCCESS; return MBS_INFO_SUCCESS;
......
...@@ -24,6 +24,15 @@ ...@@ -24,6 +24,15 @@
int dirdynared(MbsAux *mbs_aux,MbsData *s); int dirdynared(MbsAux *mbs_aux,MbsData *s);
/**
* \brief Compute the required forces ont the actuated joints in a configuration
*
* \param[in,out] mbs_aux the local computation structure, where the result is stored in the variable Mr.
* \param[in,out] s the MbsData of the system, where q(iqv),qd(iqv) and qdd(iqv) are updated.
*
* \return Error status, <0 in case of failure.
*/
int invdynared(MbsAux *mbs_aux, MbsData *s); int invdynared(MbsAux *mbs_aux, MbsData *s);
/** /**
...@@ -31,8 +40,8 @@ int invdynared(MbsAux *mbs_aux, MbsData *s); ...@@ -31,8 +40,8 @@ int invdynared(MbsAux *mbs_aux, MbsData *s);
* necessary for * necessary for
* - the state space representation (computation of A) and then the modal analysis. * - the state space representation (computation of A) and then the modal analysis.
* *
* \p[in,out] mbs_aux the local computation structure, where the result is stored in the variable Mr. * \param[in,out] mbs_aux the local computation structure, where the result is stored in the variable Mr.
* \p[in,out] s the MbsData of the system, where q(iqv),qd(iqv) and qdd(iqv) are updated. * \param[in,out] s the MbsData of the system, where q(iqv),qd(iqv) and qdd(iqv) are updated.
*/ */
int mbs_Mred(MbsAux *mbs_aux, MbsData *s); int mbs_Mred(MbsAux *mbs_aux, MbsData *s);
...@@ -42,20 +51,24 @@ int mbs_Mred(MbsAux *mbs_aux, MbsData *s); ...@@ -42,20 +51,24 @@ int mbs_Mred(MbsAux *mbs_aux, MbsData *s);
* - equilibrium (even with non zero acceleration) * - equilibrium (even with non zero acceleration)
* - linearization of MBS: obtention of Gr Kr around a given configuration (*) [not necessarely an equilibrium] * - linearization of MBS: obtention of Gr Kr around a given configuration (*) [not necessarely an equilibrium]
* *
* \p[in,out] mbs_aux the local computation structure, where the result Rred is stored. * \param[in,out] mbs_aux the local computation structure, where the result Rred is stored.
* \p[in,out] s the MbsData of the system, where q(iqv),qd(iqv) and qdd(iqv) are updated. * \param[in,out] s the MbsData of the system, where q(iqv),qd(iqv) and qdd(iqv) are updated.
*
* \return Error status, <0 in case of failure.
*/ */
int mbs_Rred(MbsAux *mbs_aux, MbsData *s); int mbs_Rred(MbsAux *mbs_aux, MbsData *s);
/** /**
* \brief Compute the residual force on independant joints and required force in driven joints.. * \brief Compute the residual force on independant joints and required force in driven joints.
* *
* This function is the computationnal core of Rred and Invdynared computations. * This function is the computationnal core of Rred and Invdynared computations.
* This function assumes that all independent joints and all driven joints are * This function assumes that all independent joints and all driven joints are
* up-to-date (coordinates, velocities and accelerations). * up-to-date (coordinates, velocities and accelerations).
* *
* \p[in,out] mbs_aux the local computation structure, where the result Rred and Qc are stored. * \param[in,out] mbs_aux the local computation structure, where the result Rred and Qc are stored.
* \p[in,out] s the MbsData of the system, where q[qv], qd[qv], qdd[qv] and Qc are updated. * \param[in,out] s the MbsData of the system, where q[qv], qd[qv], qdd[qv] and Qc are updated.
*
* \return Error status, <0 in case of failure.
*/ */
int mbs_Rred_core(MbsAux *mbs_aux, MbsData *s); int mbs_Rred_core(MbsAux *mbs_aux, MbsData *s);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
// //
// //
#include "mbs_errors_names.h"
#include "MBSfun.h" #include "MBSfun.h"
#include "math.h" #include "math.h"
#include "nrfct.h" #include "nrfct.h"
...@@ -26,6 +27,7 @@ int mbs_Rred(MbsAux *mbs_aux, MbsData *s) ...@@ -26,6 +27,7 @@ int mbs_Rred(MbsAux *mbs_aux, MbsData *s)
} }
err = mbs_Rred_core(mbs_aux, s); err = mbs_Rred_core(mbs_aux, s);
return err; return err;
} }
...@@ -115,8 +117,10 @@ int mbs_Rred_core(MbsAux *mbs_aux, MbsData *s) { ...@@ -115,8 +117,10 @@ int mbs_Rred_core(MbsAux *mbs_aux, MbsData *s) {
{ {
if (isnan(mbs_aux->Rred[i])) if (isnan(mbs_aux->Rred[i]))
{ {
err = _MBS_ERR_MID_RRED + _MBS_ERR_LOW_NAN;
mbs_msg("\t >RRED> Rred[%d] is Not a number (Nan) \n", s->qu[i]); mbs_msg("\t >RRED> Rred[%d] is Not a number (Nan) \n", s->qu[i]);
return -87; return(err);
} }
} }
...@@ -139,11 +143,13 @@ int mbs_Rred_core(MbsAux *mbs_aux, MbsData *s) { ...@@ -139,11 +143,13 @@ int mbs_Rred_core(MbsAux *mbs_aux, MbsData *s) {
} }
} }
// compute lambda // compute lambda
ludcmp(mbs_aux->Jvt, s->nqv, mbs_aux->ind_Jvt, &d); err = ludcmp(mbs_aux->Jvt, s->nqv, mbs_aux->ind_Jvt, &d);
if (err < 0) // Error management if (err < 0) // Error management
{ {
err += _MBS_ERR_MID_RRED;
mbs_msg("\t >RRED> Error in Rred during LU decomposition of Jv matrix for lambda computation\n"); mbs_msg("\t >RRED> Error in Rred during LU decomposition of Jv matrix for lambda computation\n");
return (-80 + err); return (err);
} }
lubksb(mbs_aux->Jvt, s->nqv, mbs_aux->ind_Jvt, mbs_aux->Jvtlambda); lubksb(mbs_aux->Jvt, s->nqv, mbs_aux->ind_Jvt, mbs_aux->Jvtlambda);
......
...@@ -47,7 +47,7 @@ MbsAux * initMbsAux(MbsData *s) ...@@ -47,7 +47,7 @@ MbsAux * initMbsAux(MbsData *s)
if (nquc != njoint - Ncons) if (nquc != njoint - Ncons)
{ {
mbs_error_msg("nquc (%d) != njoint-Ncons (%d-%d=%d)", nquc, njoint, Ncons, njoint - Ncons); mbs_error_msg("nquc (%d) != njoint-Ncons (%d-%d=%d)", nquc, njoint, Ncons, njoint - Ncons);
exit(1); exit(EXIT_FAILURE);
} }
#endif #endif
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
// 01/10/2008 : JFC : Bug n°40 // 01/10/2008 : JFC : Bug n°40
// //
#include "mbs_errors_names.h"
#include "MBSfun.h" #include "MBSfun.h"
#include "nrfct.h" #include "nrfct.h"
#include "mbs_project_interface.h" #include "mbs_project_interface.h"
...@@ -39,18 +40,23 @@ int mbs_close_geo(MbsData *s, MbsAux *mbs_aux) ...@@ -39,18 +40,23 @@ int mbs_close_geo(MbsData *s, MbsAux *mbs_aux)
{ {
err = mbs_step_close_geo(s, mbs_aux); err = mbs_step_close_geo(s, mbs_aux);
if (err < 0) { if (err < 0) {
err += _MBS_ERR_MID_CLOSE_GEO;
mbs_msg("\t \t >CLOSE GEO> Error in mbs_close_geo during a NR iteration \n"); mbs_msg("\t \t >CLOSE GEO> Error in mbs_close_geo during a NR iteration \n");
return -50 + err; return err;
} }
} }
if (iter >= mbs_aux->MAX_NR_ITER) // Error management if (iter >= mbs_aux->MAX_NR_ITER) // Error management
{ {
err = _MBS_ERR_MID_CLOSE_GEO;
mbs_msg("\t \t >CLOSE GEO> Impossible to close the geometry after %d iterations \n", iter); mbs_msg("\t \t >CLOSE GEO> Impossible to close the geometry after %d iterations \n", iter);
if (mbs_aux->close_anim) { if (mbs_aux->close_anim) {
mbs_anim_close_geo(s, mbs_aux); mbs_anim_close_geo(s, mbs_aux);
} }
return -50;
return err;
} }
return iter; return iter;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "set_output.h" #include "set_output.h"
#include "MBSfun.h" #include "MBSfun.h"
#include "mbs_check.h" #include "mbs_check.h"
#include "mbs_errors_names.h"
#include "mbs_message.h" #include "mbs_message.h"
...@@ -161,22 +162,36 @@ int mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data) ...@@ -161,22 +162,36 @@ int mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
// - - - - - - - - - - - - - - // - - - - - - - - - - - - - -
err = mbs_dirdyn_init(dd, mbs_data); err = mbs_dirdyn_init(dd, mbs_data);
if (err < 0){ if (err < 0){
return -1; // Freeing the buffers, without error catching
mbs_dirdyn_finish(dd, mbs_data);
mbs_error_msg("[%d] in mbs_run_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
} }
// 2. Run the simulation // 2. Run the simulation
// - - - - - - - - - - - // - - - - - - - - - - -
err = mbs_dirdyn_loop(dd, mbs_data); err = mbs_dirdyn_loop(dd, mbs_data);
if (err < 0){ if (err < 0){
return -1; // Freeing the buffers, without error catching
mbs_dirdyn_finish(dd, mbs_data);
mbs_error_msg("[%d] in mbs_run_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
} }
// 3. Finish the simulation // 3. Finish the simulation
// - - - - - - - - - - - - // - - - - - - - - - - - -
mbs_dirdyn_finish(dd, mbs_data); err = mbs_dirdyn_finish(dd, mbs_data);
if (err < 0) {
mbs_error_msg("[%d] in mbs_run_dirdyn !! \n", _MBS_ERR_MOD_DIRDYN + err);
return _MBS_ERR_MOD_DIRDYN + err;
}
if (dd->options->verbose)
{
mbs_msg("\n>>DIRDYN>> Direct dynamics analysis finished.\n");
}
return 0; return err;
} }