1 /*!
2 * \file mfront/src/CastemInterfaceExceptions.cxx
3 * \brief This file implements the CastemInterfaceExceptions class.
4 * \author Thomas Helfer
5 * \date 12/12/2011
6 * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7 * reserved.
8 * This project is publicly released under either the GNU GPL Licence
9 * or the CECILL-A licence. A copy of thoses licences are delivered
10 * with the sources of TFEL. CEA or EDF may also distribute this
11 * project under specific licensing conditions.
12 */
13
14 #include <cstring>
15 #include <cstdlib>
16 #include <sstream>
17 #include <iostream>
18
19 #include "TFEL/Raise.hxx"
20 #include "MFront/Castem/CastemInterfaceExceptions.hxx"
21
22 // fixing a bug on current glibc++ cygwin versions (19/08/2015)
23 #if defined __CYGWIN__ && (!defined _GLIBCXX_USE_C99)
24 #include <sstream>
25 namespace std {
26 template <typename T>
to_string(const T & v)27 std::string to_string(const T& v) {
28 std::ostringstream s;
29 s << v;
30 return s.str();
31 }
32 }
33 #endif /* defined __CYGWIN__ && (!defined _GLIBCXX_USE_C99) */
34
getDisplayErrorMessageFlag()35 static bool getDisplayErrorMessageFlag(){
36 const auto* e = ::getenv("CASTEM_DISPLAY_ERROR_MESSAGE");
37 if (e == nullptr) {
38 return true;
39 }
40 return ::strcmp(e, "true") == 0;
41 }
42
displayErrorMessage()43 static bool displayErrorMessage() {
44 static bool b = getDisplayErrorMessageFlag();
45 return b;
46 } // end of displayErrorMessage
47
48 namespace castem {
49
50
throwUnMatchedNumberOfMaterialProperties(const std::string & b,const unsigned short n1,const CastemInt n2)51 void CastemInterfaceExceptions::throwUnMatchedNumberOfMaterialProperties(
52 const std::string& b, const unsigned short n1, const CastemInt n2) {
53 std::ostringstream msg;
54 msg << "CastemInterfaceExceptions::"
55 "throwUnMatchedNumberOfMaterialProperties : "
56 << "the number of material properties does not match. The behaviour '"
57 << b << "' requires " << n1 << " material properties, and " << n2
58 << " material properties were declared";
59 tfel::raise<CastemException>(msg.str());
60 } // end of throwUnMatchedNumberOfMaterialProperties
61
throwUnMatchedNumberOfStateVariables(const std::string & b,const unsigned short n1,const CastemInt n2)62 void CastemInterfaceExceptions::throwUnMatchedNumberOfStateVariables(
63 const std::string& b, const unsigned short n1, const CastemInt n2) {
64 std::ostringstream msg;
65 msg << "CastemInterfaceExceptions::throwUnMatchedNumberOfStateVariables : "
66 << "the number of internal state variables does not match. The "
67 "behaviour '"
68 << b << "' requires " << n1 << " state variables, and " << n2
69 << " state variables were declared";
70 tfel::raise<CastemException>(msg.str());
71 } // end of throwUnMatchedNumberOfStateVariables
72
treatCastemException(const std::string & b,const CastemException & e)73 void CastemInterfaceExceptions::treatCastemException(
74 const std::string& b, const CastemException& e) {
75 if (displayErrorMessage()) {
76 std::cout << "The behaviour '" << b
77 << "' has thrown an CastemException : " << e.what()
78 << std::endl;
79 }
80 } // end of treatCastemException
81
treatMaterialException(const std::string & b,const tfel::material::MaterialException & e)82 void CastemInterfaceExceptions::treatMaterialException(
83 const std::string& b, const tfel::material::MaterialException& e) {
84 if (displayErrorMessage()) {
85 std::cout << "The behaviour '" << b
86 << "' has thrown an MaterialException : " << e.what()
87 << std::endl;
88 }
89 } // end of treatMaterialException
90
treatTFELException(const std::string & b,const tfel::exception::TFELException & e)91 void CastemInterfaceExceptions::treatTFELException(
92 const std::string& b, const tfel::exception::TFELException& e) {
93 if (displayErrorMessage()) {
94 std::cout << "The behaviour '" << b
95 << "' has thrown a generic tfel exception : " << e.what()
96 << std::endl;
97 }
98 } // end of treatTFELException
99
treatStandardException(const std::string & b,const std::exception & e)100 void CastemInterfaceExceptions::treatStandardException(
101 const std::string& b, const std::exception& e) {
102 if (displayErrorMessage()) {
103 std::cout << "The behaviour '" << b
104 << "' has thrown a generic standard exception : " << e.what()
105 << std::endl;
106 }
107 } // end of treatStandardException
108
treatUnknownException(const std::string & b)109 void CastemInterfaceExceptions::treatUnknownException(const std::string& b) {
110 if (displayErrorMessage()) {
111 std::cout << "The behaviour '" << b << "' has thrown an unknown exception"
112 << std::endl;
113 }
114 } // end of treatUnknownException
115
throwNegativeTimeStepException(const std::string & b)116 void CastemInterfaceExceptions::throwNegativeTimeStepException(
117 const std::string& b) {
118 tfel::raise(
119 "CastemInterfaceExceptions::throwNegativeTimeStepException: "
120 "negative time step detected for behaviour '" +
121 b + "'");
122 } // end of CastemInterfaceExceptions::throwNegativeTimeStepException
123
throwBehaviourIntegrationFailedException(const std::string & b)124 void CastemInterfaceExceptions::throwBehaviourIntegrationFailedException(
125 const std::string& b) {
126 tfel::raise<CastemIntegrationFailed>("integration failed for behaviour '" +
127 b + "'");
128 } // end of
129 // CastemInterfaceExceptions::throwBehaviourIntegrationFailedException
130
131 void
throwMaximumNumberOfSubSteppingReachedException(const std::string & b)132 CastemInterfaceExceptions::throwMaximumNumberOfSubSteppingReachedException(
133 const std::string& b) {
134 tfel::raise<CastemIntegrationFailed>(
135 "maximum number of sub stepping reached failed for behaviour '" + b +
136 "'");
137 } // end of
138 // CastemInterfaceExceptions::throwMaximumNumberOfSubSteppingReachedException
139
140 void CastemInterfaceExceptions::
throwPlaneStressMaximumNumberOfIterationsReachedException(const std::string & b)141 throwPlaneStressMaximumNumberOfIterationsReachedException(
142 const std::string& b) {
143 tfel::raise<CastemIntegrationFailed>(
144 "maximum number of iterations of the plane stress algorithm "
145 "reached failed for behaviour '" +
146 b + "'");
147 } // end of
148 // CastemInterfaceExceptions::throwPlaneStressMaximumNumberOfIterationsReachedException
149
checkNTENSValue(const CastemInt NTENS,const unsigned short s)150 void CastemInterfaceExceptions::checkNTENSValue(const CastemInt NTENS,
151 const unsigned short s) {
152 if (NTENS != s) {
153 tfel::raise(
154 "CastemInterfaceExceptions::checkNTENSValue : "
155 "invalid value for the NTENS parameter "
156 "(got '" +
157 std::to_string(NTENS) +
158 "', "
159 "expected '" +
160 std::to_string(static_cast<unsigned int>(s)) + "')");
161 }
162 } // end of CastemInterfaceExceptions::checkNTENSValue
163
164 void
displayInvalidModellingHypothesisErrorMessage()165 CastemInterfaceExceptions::displayInvalidModellingHypothesisErrorMessage() {
166 if (displayErrorMessage()) {
167 std::cout << "CastemInterfaceExceptions::"
168 "displayInvalidModellingHypothesisErrorMessage : "
169 << "invalid value for the NDI parameter" << std::endl;
170 }
171 }
172
173 void
throwInvalidBehaviourTypeAndModellingHypothesis(const CastemBehaviourType,const std::string & h)174 CastemInterfaceExceptions::throwInvalidBehaviourTypeAndModellingHypothesis(
175 const CastemBehaviourType, const std::string& h) {
176 tfel::raise(
177 "CastemInterfaceExceptions::"
178 "throwInvalidBehaviourTypeAndModellingHypothesis: "
179 "behaviour can't be used in '" +
180 h + "'");
181 } // end of
182 // CastemInterfaceExceptions::throwInvalidBehaviourTypeAndModellingHypothesis
183
throwPredictionComputationFailedException(const std::string & b)184 void CastemInterfaceExceptions::throwPredictionComputationFailedException(
185 const std::string& b) {
186 tfel::raise(
187 "CastemInterfaceExceptions::throwPredictionComputationFailedException: "
188 "prediction computation failed for behaviour '" +
189 b + "'");
190 }
191
throwPredictionOperatorIsNotAvalaible(const std::string & b)192 void CastemInterfaceExceptions::throwPredictionOperatorIsNotAvalaible(
193 const std::string& b) {
194 tfel::raise(
195 "CastemInterfaceExceptions::throwPredictionOperatorIsNotAvalaible: "
196 "behaviour '" +
197 b + "' can't compute a prediction operator");
198 } // end of
199 // CastemInterfaceExceptions::throwBehaviourIntegrationFailedException
200
throwConsistentTangentOperatorIsNotAvalaible(const std::string & b)201 void CastemInterfaceExceptions::throwConsistentTangentOperatorIsNotAvalaible(
202 const std::string& b) {
203 tfel::raise(
204 "CastemInterfaceExceptions::"
205 "throwConsistentTangentOperatorIsNotAvalaible: "
206 "behaviour '" +
207 b + "' can't compute a consistent tangent operator");
208 } // end of
209 // CastemInterfaceExceptions::throwBehaviourIntegrationFailedException
210
throwUnsupportedStressFreeExpansionException(const std::string & b)211 void CastemInterfaceExceptions::throwUnsupportedStressFreeExpansionException(
212 const std::string& b) {
213 tfel::raise(
214 "CastemInterfaceExceptions::"
215 "throwUnsupportedStressFreeExpansionException: "
216 "behaviour '" +
217 b +
218 "' can handle stress-free expansion "
219 "but the Castem interface can't");
220 } // end of
221 // CastemInterfaceExceptions::throwUnsupportedStressFreeExpansionException
222
throwThermalExpansionCoefficientShallBeNull(const std::string & b)223 void CastemInterfaceExceptions::throwThermalExpansionCoefficientShallBeNull(
224 const std::string& b) {
225 tfel::raise(
226 "CastemInterfaceExceptions::"
227 "throwThermalExpansionCoefficientShallBeNull: "
228 "behaviour '" +
229 b +
230 "' handle thermal expansion, so "
231 "the thermal expansion declared in Castem must be null.");
232 }
233
234 void CastemInterfaceExceptions::
throwTangentOperatorNotAvailableThroughGenericPlaneStressHandler(const std::string &)235 throwTangentOperatorNotAvailableThroughGenericPlaneStressHandler(
236 const std::string&) {
237 tfel::raise(
238 "tangent operator is not available in the "
239 "generic plane stress handler");
240 }
241
throwInvalidDDSDDEException(const std::string & b,const CastemReal v)242 void CastemInterfaceExceptions::throwInvalidDDSDDEException(
243 const std::string& b, const CastemReal v) {
244 tfel::raise(
245 "CastemInterfaceExceptions::throwInvalidDDSDDEException : "
246 "an invalid value for the DDSDDE parameter has been given "
247 "('" +
248 std::to_string(v) +
249 "')"
250 " to the behaviour '" +
251 b +
252 "'.\n"
253 "The following values are accepted:\n"
254 "-3 : compute the prediction tangent operator, no behaviour "
255 "integration\n"
256 "-2 : compute the prediction secant operator, no behaviour "
257 "integration\n"
258 "-1 : compute the prediction elastic operator, no behaviour "
259 "integration\n"
260 " 0 : integrate the behaviour over the time step, no stiffness "
261 "requested\n"
262 " 1 : integrate the behaviour over the time step, elastic stiffness "
263 "requested\n"
264 " 2 : integrate the behaviour over the time step, secant operator "
265 "requested\n"
266 " 3 : integrate the behaviour over the time step, tagent operator "
267 "requested\n"
268 " 4 : integrate the behaviour over the time step, consistent tagent "
269 "operator requested");
270 } // end of CastemInterfaceExceptions::throwInvalidDDSDDEException
271
exe(const CastemReal * const,const CastemReal * const,CastemReal * const,const CastemReal * const,const CastemReal * const,const CastemReal * const,const CastemReal * const,const CastemReal * const,const CastemInt * const,const CastemReal * const,const CastemReal * const,CastemReal * const,const CastemInt * const,CastemReal * const,const StressFreeExpansionHandler &)272 void CastemUnSupportedCaseHandler::exe(const CastemReal* const,
273 const CastemReal* const,
274 CastemReal* const,
275 const CastemReal* const,
276 const CastemReal* const,
277 const CastemReal* const,
278 const CastemReal* const,
279 const CastemReal* const,
280 const CastemInt* const,
281 const CastemReal* const,
282 const CastemReal* const,
283 CastemReal* const,
284 const CastemInt* const,
285 CastemReal* const,
286 const StressFreeExpansionHandler&) {
287 tfel::raise(
288 "CastemUnSupportedCaseHandler::exe : "
289 "we fall in a case that the castem interface "
290 "is not able to handle.");
291 } // end of exe
292
293 } // end of namespace castem
294