1 /*! 2 * \file mfront/src/CyranoInterfaceExceptions.cxx 3 * \brief This file implements the CyranoInterfaceExceptions class. 4 * \author Thomas Helfer 5 * \date 21 fév 2014 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<cstdlib> 15 #include<sstream> 16 #include<iostream> 17 18 #include "TFEL/Raise.hxx" 19 #include "MFront/Cyrano/CyranoInterfaceExceptions.hxx" 20 21 // fixing a bug on current glibc++ cygwin versions (19/08/2015) 22 #if defined __CYGWIN__ && (!defined _GLIBCXX_USE_C99) 23 #include<sstream> 24 namespace std{ 25 template<typename T> to_string(const T & v)26 std::string to_string(const T& v){ 27 std::ostringstream s; 28 s << v; 29 return s.str(); 30 } 31 } 32 #endif /* defined __CYGWIN__ && (!defined _GLIBCXX_USE_C99) */ 33 34 namespace cyrano{ 35 36 void throwUnMatchedNumberOfMaterialProperties(const std::string & b,const unsigned short n1,const CyranoInt n2)37 CyranoInterfaceExceptions::throwUnMatchedNumberOfMaterialProperties(const std::string& b, 38 const unsigned short n1, 39 const CyranoInt n2) 40 { 41 std::ostringstream msg; 42 msg << "CyranoInterfaceExceptions::throwUnMatchedNumberOfMaterialProperties : " 43 << "the number of material properties does not match. The behaviour '" 44 << b << "' requires " << n1 << " material properties, and " 45 << n2 << " material properties were declared"; 46 tfel::raise<CyranoException>(msg.str()); 47 } // end of throwUnMatchedNumberOfMaterialProperties 48 49 void throwUnMatchedNumberOfStateVariables(const std::string & b,const unsigned short n1,const CyranoInt n2)50 CyranoInterfaceExceptions::throwUnMatchedNumberOfStateVariables(const std::string& b, 51 const unsigned short n1, 52 const CyranoInt n2) 53 { 54 std::ostringstream msg; 55 msg << "CyranoInterfaceExceptions::throwUnMatchedNumberOfStateVariables : " 56 << "the number of internal state variables does not match. The behaviour '" 57 << b << "' requires " << n1 << " state variables, and " 58 << n2 << " state variables were declared"; 59 tfel::raise<CyranoException>(msg.str()); 60 } // end of throwUnMatchedNumberOfStateVariables 61 62 void treatCyranoException(const std::string & b,const CyranoException & e)63 CyranoInterfaceExceptions::treatCyranoException(const std::string& b, 64 const CyranoException& e) 65 { 66 std::cout << "The behaviour '" << b 67 << "' has thrown an CyranoException : " 68 << e.what() << std::endl; 69 } // end of treatCyranoException 70 71 void treatMaterialException(const std::string & b,const tfel::material::MaterialException & e)72 CyranoInterfaceExceptions::treatMaterialException(const std::string& b, 73 const tfel::material::MaterialException& e) 74 { 75 std::cout << "The behaviour '" << b 76 << "' has thrown an MaterialException : " 77 << e.what() << std::endl; 78 } // end of treatMaterialException 79 80 void treatTFELException(const std::string & b,const tfel::exception::TFELException & e)81 CyranoInterfaceExceptions::treatTFELException(const std::string& b, 82 const tfel::exception::TFELException& e) 83 { 84 std::cout << "The behaviour '" << b 85 << "' has thrown a generic tfel exception : " 86 << e.what() << std::endl; 87 } // end of treatTFELException 88 89 void treatStandardException(const std::string & b,const std::exception & e)90 CyranoInterfaceExceptions::treatStandardException(const std::string& b, 91 const std::exception& e) 92 { 93 std::cout << "The behaviour '" << b 94 << "' has thrown a generic standard exception : " 95 << e.what() << std::endl; 96 } // end of treatStandardException 97 98 void treatUnknownException(const std::string & b)99 CyranoInterfaceExceptions::treatUnknownException(const std::string& b) 100 { 101 std::cout << "The behaviour '" << b 102 << "' has thrown an unknown exception" << std::endl; 103 } // end of treatUnknownException 104 105 void throwNegativeTimeStepException(const std::string & b)106 CyranoInterfaceExceptions::throwNegativeTimeStepException(const std::string& b) 107 { 108 tfel::raise("CyranoInterfaceExceptions::throwNegativeTimeStepException: " 109 "negative time step detected for behaviour '"+b+"'"); 110 } // end of CyranoInterfaceExceptions::throwNegativeTimeStepException 111 112 void throwBehaviourIntegrationFailedException(const std::string & b)113 CyranoInterfaceExceptions::throwBehaviourIntegrationFailedException(const std::string& b) 114 { 115 tfel::raise<CyranoIntegrationFailed>("integration failed for behaviour '"+b+"'"); 116 } // end of CyranoInterfaceExceptions::throwBehaviourIntegrationFailedException 117 118 void throwMaximumNumberOfSubSteppingReachedException(const std::string & b)119 CyranoInterfaceExceptions::throwMaximumNumberOfSubSteppingReachedException(const std::string& b) 120 { 121 tfel::raise<CyranoIntegrationFailed>("maximum number of sub stepping reached " 122 "failed for behaviour '"+b+"'"); 123 } // end of CyranoInterfaceExceptions::throwMaximumNumberOfSubSteppingReachedException 124 125 void throwPlaneStressMaximumNumberOfIterationsReachedException(const std::string & b)126 CyranoInterfaceExceptions::throwPlaneStressMaximumNumberOfIterationsReachedException(const std::string& b) 127 { 128 tfel::raise<CyranoIntegrationFailed>("maximum number of iterations of " 129 "the plane stress algorithm " 130 "reached failed for behaviour '"+b+"'"); 131 } // end of CyranoInterfaceExceptions::throwPlaneStressMaximumNumberOfIterationsReachedException 132 checkNTENSValue(const CyranoInt NTENS,const unsigned short s)133 void CyranoInterfaceExceptions::checkNTENSValue(const CyranoInt NTENS, 134 const unsigned short s) 135 { 136 tfel::raise_if(NTENS!=s,"CyranoInterfaceExceptions::checkNTENSValue: " 137 "invalid value for the NTENS parameter " 138 "(got '"+std::to_string(NTENS)+"', expected '"+ 139 std::to_string(static_cast<unsigned int>(s))+"')"); 140 } // end of CyranoInterfaceExceptions::checkNTENSValue 141 displayInvalidModellingHypothesisErrorMessage()142 void CyranoInterfaceExceptions::displayInvalidModellingHypothesisErrorMessage() 143 { 144 std::cout << "CyranoInterfaceExceptions::displayInvalidModellingHypothesisErrorMessage : " 145 << "invalid value for the NDI parameter" << std::endl; 146 } 147 148 void throwInvalidBehaviourTypeAndModellingHypothesis(const std::string & h)149 CyranoInterfaceExceptions::throwInvalidBehaviourTypeAndModellingHypothesis(const std::string& h) 150 { 151 tfel::raise("CyranoInterfaceExceptions::throwInvalidBehaviourTypeAndModellingHypothesis : " 152 "behaviour can't be used in '"+h+"'"); 153 } // end of CyranoInterfaceExceptions::throwInvalidBehaviourTypeAndModellingHypothesis 154 155 void throwPredictionComputationFailedException(const std::string & b)156 CyranoInterfaceExceptions::throwPredictionComputationFailedException(const std::string& b) 157 { 158 tfel::raise("CyranoInterfaceExceptions::throwPredictionComputationFailedException: " 159 "prediction computation failed for behaviour '"+b+"'"); 160 } 161 162 void throwPredictionOperatorIsNotAvalaible(const std::string & b)163 CyranoInterfaceExceptions::throwPredictionOperatorIsNotAvalaible(const std::string& b) 164 { 165 tfel::raise("CyranoInterfaceExceptions::throwPredictionOperatorIsNotAvalaible: " 166 "behaviour '"+b+"' can't compute a prediction operator"); 167 } // end of CyranoInterfaceExceptions::throwBehaviourIntegrationFailedException 168 169 void throwConsistentTangentOperatorIsNotAvalaible(const std::string & b)170 CyranoInterfaceExceptions::throwConsistentTangentOperatorIsNotAvalaible(const std::string& b) 171 { 172 tfel::raise("CyranoInterfaceExceptions::throwConsistentTangentOperatorIsNotAvalaible: " 173 "behaviour '"+b+"' can't compute a consistent tangent operator"); 174 } // end of CyranoInterfaceExceptions::throwBehaviourIntegrationFailedException 175 176 void throwUnsupportedStressFreeExpansionException(const std::string & b)177 CyranoInterfaceExceptions::throwUnsupportedStressFreeExpansionException(const std::string& b) 178 { 179 tfel::raise("CyranoInterfaceExceptions::throwUnsupportedStressFreeExpansionException: " 180 "behaviour '"+b+"' can handle stress-free expansion " 181 "but the Cyrano interface can't"); 182 } // end of CyranoInterfaceExceptions::throwUnsupportedStressFreeExpansionException 183 throwThermalExpansionCoefficientShallBeNull(const std::string & b)184 void CyranoInterfaceExceptions::throwThermalExpansionCoefficientShallBeNull(const std::string& b) 185 { 186 tfel::raise("CyranoInterfaceExceptions::throwThermalExpansionCoefficientShallBeNull: " 187 "behaviour '"+b+"' handle thermal expansion, so the thermal expansion " 188 "declared in Cyrano must be null."); 189 } 190 throwInvalidDDSOEException(const std::string & b,const CyranoReal v)191 void CyranoInterfaceExceptions::throwInvalidDDSOEException(const std::string& b, 192 const CyranoReal v) 193 { 194 tfel::raise("CyranoInterfaceExceptions::throwInvalidDDSOEException : " 195 "an invalid value for the DDSOE parameter has been given " 196 "('"+std::to_string(v)+"') " 197 "to the behaviour '"+b+"'.\n" 198 "The following values are accepted:\n" 199 "-3 : compute the prediction tangent operator, no behaviour integration\n" 200 "-2 : compute the prediction secant operator, no behaviour integration\n" 201 "-1 : compute the prediction elastic operator, no behaviour integration\n" 202 " 0 : integrate the behaviour over the time step, no stiffness requested\n" 203 " 1 : integrate the behaviour over the time step, elastic stiffness requested\n" 204 " 2 : integrate the behaviour over the time step, secant operator requested\n" 205 " 3 : integrate the behaviour over the time step, tagent operator requested\n" 206 " 4 : integrate the behaviour over the time step, consistent tagent operator requested\n"); 207 } // end of CyranoInterfaceExceptions::throwInvalidDDSOEException 208 exe(const CyranoReal * const,const CyranoReal * const,const CyranoReal * const,const CyranoReal * const,const CyranoReal * const,const CyranoReal * const,const CyranoReal * const,const CyranoReal * const,const CyranoInt * const,const CyranoReal * const,const CyranoReal * const,CyranoReal * const,const CyranoInt * const,CyranoReal * const)209 void CyranoUnSupportedCaseHandler::exe(const CyranoReal *const , 210 const CyranoReal *const, 211 const CyranoReal *const, 212 const CyranoReal *const, 213 const CyranoReal *const, 214 const CyranoReal *const, 215 const CyranoReal *const, 216 const CyranoReal *const, 217 const CyranoInt *const, 218 const CyranoReal *const, 219 const CyranoReal *const, 220 CyranoReal *const, 221 const CyranoInt *const, 222 CyranoReal *const) 223 { 224 tfel::raise("CyranoUnSupportedCaseHandler::exe : " 225 "we fall in a case that the cyrano interface " 226 "is not able to handle."); 227 } // end of exe 228 229 } // end of namespace cyrano 230