Simbody
|
00001 #ifndef SimTK_SIMMATH_COMMON_H_ 00002 #define SimTK_SIMMATH_COMMON_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * SimTK Core: SimTK Simmath(tm) * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK Core biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org. * 00011 * * 00012 * Portions copyright (c) 2006-10 Stanford University and the Authors. * 00013 * Authors: Jack Middleton * 00014 * Contributors: Michael Sherman * 00015 * * 00016 * Permission is hereby granted, free of charge, to any person obtaining a * 00017 * copy of this software and associated documentation files (the "Software"), * 00018 * to deal in the Software without restriction, including without limitation * 00019 * the rights to use, copy, modify, merge, publish, distribute, sublicense, * 00020 * and/or sell copies of the Software, and to permit persons to whom the * 00021 * Software is furnished to do so, subject to the following conditions: * 00022 * * 00023 * The above copyright notice and this permission notice shall be included in * 00024 * all copies or substantial portions of the Software. * 00025 * * 00026 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 00027 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 00028 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 00029 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 00030 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 00031 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * 00032 * USE OR OTHER DEALINGS IN THE SOFTWARE. * 00033 * -------------------------------------------------------------------------- */ 00034 00040 #include "SimTKcommon.h" 00041 00042 /* Shared libraries are messy in Visual Studio. We have to distinguish three 00043 * cases: 00044 * (1) this header is being used to build the simmath shared library (dllexport) 00045 * (2) this header is being used by a *client* of the simmath shared 00046 * library (dllimport) 00047 * (3) we are building the simmath static library, or the client is 00048 * being compiled with the expectation of linking with the 00049 * simmath static library (nothing special needed) 00050 * In the CMake script for building this library, we define one of the symbols 00051 * SIMMATH_BUILDING_{SHARED|STATIC}_LIBRARY 00052 * Client code normally has no special symbol defined, in which case we'll 00053 * assume it wants to use the shared library. However, if the client defines 00054 * the symbol SimTK_USE_STATIC_LIBRARIES we'll suppress the dllimport so 00055 * that the client code can be linked with static libraries. Note that 00056 * the client symbol is not library dependent, while the library symbols 00057 * affect only the simmath library, meaning that other libraries can 00058 * be clients of this one. However, we are assuming all-static or all-shared. 00059 */ 00060 00061 #ifdef _WIN32 00062 #if defined(SimTK_SIMMATH_BUILDING_SHARED_LIBRARY) 00063 #define SimTK_SIMMATH_EXPORT __declspec(dllexport) 00064 #elif defined(SimTK_SIMMATH_BUILDING_STATIC_LIBRARY) || defined(SimTK_USE_STATIC_LIBRARIES) 00065 #define SimTK_SIMMATH_EXPORT 00066 #else 00067 /* i.e., a client of a shared library */ 00068 #define SimTK_SIMMATH_EXPORT __declspec(dllimport) 00069 #endif 00070 #else 00071 /* Linux, Mac */ 00072 #define SimTK_SIMMATH_EXPORT 00073 #endif 00074 00075 00076 // Every SimTK Core library must provide these two routines, with the library 00077 // name appearing after the "version_" and "about_". 00078 extern "C" { 00079 SimTK_SIMMATH_EXPORT void SimTK_version_simmath(int* major, int* minor, int* build); 00080 SimTK_SIMMATH_EXPORT void SimTK_about_simmath(const char* key, int maxlen, char* value); 00081 } 00082 00083 00084 00085 const static double POSITIVE_INF = 2e19; 00086 const static double NEGATIVE_INF = -2e19; 00087 00088 namespace SimTK { 00089 00090 00091 namespace Exception { 00092 00093 class OptimizerFailed : public Base { 00094 public: 00095 OptimizerFailed( const char * fn, int ln, String msg) : Base(fn, ln) 00096 { 00097 setMessage("Optimizer failed: " + msg ); 00098 } 00099 private: 00100 }; 00101 00102 class UnrecognizedParameter : public Base { 00103 public: 00104 UnrecognizedParameter( const char * fn, int ln, String msg) : Base(fn, ln) 00105 { 00106 setMessage("Unrecognized Parameter: " + msg ); 00107 } 00108 private: 00109 }; 00110 00111 class IllegalLapackArg : public Base { 00112 public: 00113 IllegalLapackArg( const char *fn, int ln, const char *lapackRoutine, 00114 int argNum ) : Base(fn, ln) 00115 { 00116 char buf[1024]; 00117 00118 sprintf(buf, "SimTK internal error: %s called with an illegal value to arguement #%d \n Please report this to SimTK", 00119 lapackRoutine, argNum ); 00120 setMessage(String(buf)); 00121 00122 } 00123 private: 00124 }; 00125 class IncorrectArrayLength : public Base { 00126 public: 00127 IncorrectArrayLength( const char *fn, int ln, const char *valueName, int length, 00128 const char *paramName, int paramValue, const char *where) : Base(fn, ln) 00129 { 00130 char buf[1024]; 00131 00132 sprintf(buf, "Incorrect array length in %s : %s is %d and must equal %s which is %d", 00133 where, valueName, length, paramName, paramValue ); 00134 setMessage(String(buf)); 00135 00136 } 00137 private: 00138 }; 00139 00140 class SingularMatrix : public Base { 00141 public: 00142 SingularMatrix( const char *fn, int ln, int index, 00143 const char *where) : Base(fn, ln) 00144 { 00145 char buf[1024]; 00146 00147 sprintf(buf, "%s failed because index %d in matrix was singular and factorization failed", 00148 where, index ); 00149 setMessage(String(buf)); 00150 00151 } 00152 private: 00153 }; 00154 00155 class ConvergedFailed : public Base { 00156 public: 00157 ConvergedFailed( const char *fn, int ln, const char *algorithm, 00158 const char *where) : Base(fn, ln) 00159 { 00160 char buf[1024]; 00161 00162 sprintf(buf, "%s failed because %s failed to converge", where, algorithm ); 00163 setMessage(String(buf)); 00164 00165 } 00166 private: 00167 }; 00168 00169 class NotPositiveDefinite : public Base { 00170 public: 00171 NotPositiveDefinite( const char *fn, int ln, int index, 00172 const char *where) : Base(fn, ln) 00173 { 00174 char buf[1024]; 00175 00176 sprintf(buf, "%s failed because index %d in matrix was not positive definite and factorization failed ", 00177 where, index ); 00178 setMessage(String(buf)); 00179 00180 } 00181 private: 00182 }; 00183 } // namespace Exception 00184 00185 } // namespace SimTK 00186 00187 #endif // SimTK_SIMMATH_COMMON_H_