Simbody 3.9
Loading...
Searching...
No Matches
SimTKmath/include/simmath/internal/common.h
Go to the documentation of this file.
1#ifndef SimTK_SIMMATH_COMMON_H_
2#define SimTK_SIMMATH_COMMON_H_
3
4/* -------------------------------------------------------------------------- *
5 * Simbody(tm): SimTKmath *
6 * -------------------------------------------------------------------------- *
7 * This is part of the SimTK biosimulation toolkit originating from *
8 * Simbios, the NIH National Center for Physics-Based Simulation of *
9 * Biological Structures at Stanford, funded under the NIH Roadmap for *
10 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11 * *
12 * Portions copyright (c) 2006-12 Stanford University and the Authors. *
13 * Authors: Jack Middleton *
14 * Contributors: Michael Sherman *
15 * *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17 * not use this file except in compliance with the License. You may obtain a *
18 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19 * *
20 * Unless required by applicable law or agreed to in writing, software *
21 * distributed under the License is distributed on an "AS IS" BASIS, *
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23 * See the License for the specific language governing permissions and *
24 * limitations under the License. *
25 * -------------------------------------------------------------------------- */
26
32#include "SimTKcommon.h"
33
34/* Shared libraries are messy in Visual Studio. We have to distinguish three
35 * cases:
36 * (1) this header is being used to build the simmath shared library (dllexport)
37 * (2) this header is being used by a *client* of the simmath shared
38 * library (dllimport)
39 * (3) we are building the simmath static library, or the client is
40 * being compiled with the expectation of linking with the
41 * simmath static library (nothing special needed)
42 * In the CMake script for building this library, we define one of the symbols
43 * SIMMATH_BUILDING_{SHARED|STATIC}_LIBRARY
44 * Client code normally has no special symbol defined, in which case we'll
45 * assume it wants to use the shared library. However, if the client defines
46 * the symbol SimTK_USE_STATIC_LIBRARIES we'll suppress the dllimport so
47 * that the client code can be linked with static libraries. Note that
48 * the client symbol is not library dependent, while the library symbols
49 * affect only the simmath library, meaning that other libraries can
50 * be clients of this one. However, we are assuming all-static or all-shared.
51*/
52
53#if defined(_WIN32) && defined(_MSC_VER)
54 #if defined(SimTK_SIMMATH_BUILDING_SHARED_LIBRARY)
55 #define SimTK_SIMMATH_EXPORT __declspec(dllexport)
56 #elif defined(SimTK_SIMMATH_BUILDING_STATIC_LIBRARY) || defined(SimTK_USE_STATIC_LIBRARIES)
57 #define SimTK_SIMMATH_EXPORT
58 #else
59 /* i.e., a client of a shared library */
60 #define SimTK_SIMMATH_EXPORT __declspec(dllimport)
61 #endif
62#else
63 /* Linux, Mac, MinGW */
64 #define SimTK_SIMMATH_EXPORT
65#endif
66
67
68// Every SimTK Core library must provide these two routines, with the library
69// name appearing after the "version_" and "about_".
70extern "C" {
71 SimTK_SIMMATH_EXPORT void SimTK_version_simmath(int* major, int* minor, int* build);
72 SimTK_SIMMATH_EXPORT void SimTK_about_simmath(const char* key, int maxlen, char* value);
73}
74
75
76
77const static double POSITIVE_INF = 2e19;
78const static double NEGATIVE_INF = -2e19;
79
80namespace SimTK {
81
82namespace Exception {
83
84#ifdef _MSC_VER
85#pragma warning(push)
86#pragma warning(disable:4996) // don't warn about sprintf, etc.
87#endif
88
89class OptimizerFailed : public Base {
90public:
91 OptimizerFailed( const char * fn, int ln, String msg) : Base(fn, ln)
92 {
93 setMessage("Optimizer failed: " + msg );
94 }
95private:
96};
97
99public:
100 UnrecognizedParameter( const char * fn, int ln, String msg) : Base(fn, ln)
101 {
102 setMessage("Unrecognized Parameter: " + msg );
103 }
104private:
105};
106
107class IllegalLapackArg : public Base {
108public:
109 IllegalLapackArg( const char *fn, int ln, const char *lapackRoutine,
110 int info ) : Base(fn, ln)
111 {
112 const int n = 1024;
113 char buf[n];
114
115 snprintf(buf, n, "SimTK internal error: %s called with an illegal value to"
116 " argument #%d.\nPlease report this at SimTK.org.",
117 lapackRoutine, -info );
118 setMessage(String(buf));
119
120 }
121private:
122};
124public:
125 IncorrectArrayLength( const char *fn, int ln, const char *valueName, int length,
126 const char *paramName, int paramValue, const char *where) : Base(fn, ln)
127 {
128 const int n = 1024;
129 char buf[1024];
130
131 snprintf(buf, n, "Incorrect array length in %s : %s is %d and must equal %s which is %d",
132 where, valueName, length, paramName, paramValue );
133 setMessage(String(buf));
134
135 }
136private:
137};
138
139class SingularMatrix : public Base {
140public:
141 SingularMatrix( const char *fn, int ln, int index,
142 const char *where) : Base(fn, ln)
143 {
144 const int n = 1024;
145 char buf[n];
146
147 snprintf(buf, n, "%s failed because index %d in matrix was singular and factorization failed",
148 where, index );
149 setMessage(String(buf));
150
151 }
152private:
153};
154
155class ConvergedFailed : public Base {
156public:
157 ConvergedFailed( const char *fn, int ln, const char *algorithm,
158 const char *where) : Base(fn, ln)
159 {
160 const int n = 1024;
161 char buf[n];
162
163 snprintf(buf, n, "%s failed because %s failed to converge", where, algorithm );
164 setMessage(String(buf));
165
166 }
167private:
168};
169
170class NotPositiveDefinite : public Base {
171public:
172 NotPositiveDefinite( const char *fn, int ln, int index,
173 const char *where) : Base(fn, ln)
174 {
175 const int n = 1024;
176 char buf[n];
177
178 snprintf(buf, n, "%s failed because index %d in matrix was not positive definite and factorization failed ",
179 where, index );
180 setMessage(String(buf));
181
182 }
183private:
184};
185
186#ifdef _MSC_VER
187#pragma warning(pop)
188#endif
189
190} // namespace Exception
191
192} // namespace SimTK
193
194#endif // SimTK_SIMMATH_COMMON_H_
Includes internal headers providing declarations for the basic SimTK Core classes,...
static const double NEGATIVE_INF
Definition SimTKmath/include/simmath/internal/common.h:78
void SimTK_about_simmath(const char *key, int maxlen, char *value)
#define SimTK_SIMMATH_EXPORT
Definition SimTKmath/include/simmath/internal/common.h:64
static const double POSITIVE_INF
Definition SimTKmath/include/simmath/internal/common.h:77
void SimTK_version_simmath(int *major, int *minor, int *build)
Definition Exception.h:46
void setMessage(const std::string &msgin)
Definition Exception.h:57
Definition SimTKmath/include/simmath/internal/common.h:155
ConvergedFailed(const char *fn, int ln, const char *algorithm, const char *where)
Definition SimTKmath/include/simmath/internal/common.h:157
Definition SimTKmath/include/simmath/internal/common.h:107
IllegalLapackArg(const char *fn, int ln, const char *lapackRoutine, int info)
Definition SimTKmath/include/simmath/internal/common.h:109
Definition SimTKmath/include/simmath/internal/common.h:123
IncorrectArrayLength(const char *fn, int ln, const char *valueName, int length, const char *paramName, int paramValue, const char *where)
Definition SimTKmath/include/simmath/internal/common.h:125
Definition SimTKmath/include/simmath/internal/common.h:170
NotPositiveDefinite(const char *fn, int ln, int index, const char *where)
Definition SimTKmath/include/simmath/internal/common.h:172
Definition SimTKmath/include/simmath/internal/common.h:89
OptimizerFailed(const char *fn, int ln, String msg)
Definition SimTKmath/include/simmath/internal/common.h:91
Definition SimTKmath/include/simmath/internal/common.h:139
SingularMatrix(const char *fn, int ln, int index, const char *where)
Definition SimTKmath/include/simmath/internal/common.h:141
Definition SimTKmath/include/simmath/internal/common.h:98
UnrecognizedParameter(const char *fn, int ln, String msg)
Definition SimTKmath/include/simmath/internal/common.h:100
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition String.h:64
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37