1 /*! 2 * \file mfront/src/MFrontMaterialPropertyInterface.cxx 3 * \brief 4 * \author Thomas Helfer 5 * \date 06 mai 2008 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<sstream> 15 #include<stdexcept> 16 #include<algorithm> 17 #include"TFEL/Raise.hxx" 18 #include"TFEL/Config/GetInstallPath.hxx" 19 #include"MFront/DSLUtilities.hxx" 20 #include"MFront/MFrontUtilities.hxx" 21 #include"MFront/MFrontHeader.hxx" 22 #include"MFront/TargetsDescription.hxx" 23 #include"MFront/MaterialPropertyDescription.hxx" 24 #include"MFront/MFrontMaterialPropertyInterface.hxx" 25 26 namespace mfront 27 { 28 getName()29 std::string MFrontMaterialPropertyInterface::getName() 30 { 31 return "mfront"; 32 } 33 34 MFrontMaterialPropertyInterface::MFrontMaterialPropertyInterface() = default; 35 36 std::pair<bool,tfel::utilities::CxxTokenizer::TokensContainer::const_iterator> treatKeyword(const std::string & k,const std::vector<std::string> & i,tokens_iterator current,const tokens_iterator)37 MFrontMaterialPropertyInterface::treatKeyword(const std::string& k, 38 const std::vector<std::string>& i, 39 tokens_iterator current, 40 const tokens_iterator) 41 { 42 tfel::raise_if(std::find(i.begin(),i.end(),"mfront")!=i.end(), 43 "MFrontMaterialPropertyInterface::treatKeyword: " 44 "unsupported key '"+k+"'"); 45 return {false,current}; 46 } // end of treatKeyword 47 48 void getTargetsDescription(TargetsDescription & d,const MaterialPropertyDescription & mpd) const49 MFrontMaterialPropertyInterface::getTargetsDescription(TargetsDescription& d, 50 const MaterialPropertyDescription& mpd) const 51 { 52 const auto lib = "MFrontMaterialLaw"; 53 const auto name = this->getSrcFileName(mpd.material,mpd.className); 54 const auto f = mpd.material.empty() ? mpd.className : mpd.material+"_"+mpd.className; 55 const auto header = this->getHeaderFileName(mpd.material,mpd.className); 56 const auto tfel_config = tfel::getTFELConfigExecutableName(); 57 insert_if(d[lib].cppflags, 58 "$(shell "+tfel_config+" --cppflags --compiler-flags)"); 59 insert_if(d[lib].include_directories, 60 "$(shell "+tfel_config+" --include-path)"); 61 if(!header.empty()){ 62 insert_if(d.headers,header+".hxx"); 63 } 64 insert_if(d[lib].sources,name+".cxx"); 65 #if !((defined _WIN32) && (defined _MSC_VER)) 66 insert_if(d[lib].link_libraries,"m"); 67 #endif /* !((defined _WIN32) && (defined _MSC_VER)) */ 68 insert_if(d[lib].epts,{f,f+"_checkBounds"}); 69 } // end of MFrontMaterialPropertyInterface::getTargetsDescription 70 71 std::string getHeaderFileName(const std::string & material,const std::string & className) const72 MFrontMaterialPropertyInterface::getHeaderFileName(const std::string& material, 73 const std::string& className) const 74 { 75 if(material.empty()){ 76 return className+"-mfront"; 77 } 78 return material+"_"+className+"-mfront"; 79 } // end of MFrontMaterialPropertyInterface::getHeaderFileName 80 81 std::string getSrcFileName(const std::string & material,const std::string & className) const82 MFrontMaterialPropertyInterface::getSrcFileName(const std::string& material, 83 const std::string& className) const 84 { 85 if(material.empty()){ 86 return className+"-mfront"; 87 } 88 return material+"_"+className+"-mfront"; 89 } // end of MFrontMaterialPropertyInterface::getSrcFileName 90 writeBeginHeaderNamespace(std::ostream & os) const91 void MFrontMaterialPropertyInterface::writeBeginHeaderNamespace(std::ostream& os) const 92 { 93 os << "namespace mfront{\n\n"; 94 } // end of MFrontMaterialPropertyInterface::writeBeginHeaderNamespace 95 writeEndHeaderNamespace(std::ostream & os) const96 void MFrontMaterialPropertyInterface::writeEndHeaderNamespace(std::ostream& os) const 97 { 98 os << "} // end of namespace mfront\n\n"; 99 } // end of MFrontMaterialPropertyInterface::writeEndHeaderNamespace() 100 writeBeginSrcNamespace(std::ostream & os) const101 void MFrontMaterialPropertyInterface::writeBeginSrcNamespace(std::ostream& os) const 102 { 103 os << "namespace mfront{\n"; 104 } // end of MFrontMaterialPropertyInterface::writeBeginSrcNamespace 105 writeEndSrcNamespace(std::ostream & os) const106 void MFrontMaterialPropertyInterface::writeEndSrcNamespace(std::ostream& os) const 107 { 108 os << "} // end of namespace mfront\n"; 109 } // end of MFrontMaterialPropertyInterface::writeEndSrcNamespace() 110 111 std::string getFunctionName(const MaterialPropertyDescription & mpd) const112 MFrontMaterialPropertyInterface::getFunctionName(const MaterialPropertyDescription& mpd) const 113 { 114 const auto material = mpd.material; 115 const auto law = mpd.className; 116 return material.empty() ? law : material+'_'+law; 117 } // end of MFrontMaterialPropertyInterface::getFunctionName 118 requiresCheckBoundsFunction() const119 bool MFrontMaterialPropertyInterface::requiresCheckBoundsFunction() const 120 { 121 return true; 122 } 123 124 std::string getCheckBoundsFunctionName(const MaterialPropertyDescription & mpd) const125 MFrontMaterialPropertyInterface::getCheckBoundsFunctionName(const MaterialPropertyDescription& mpd) const 126 { 127 return this->getFunctionName(mpd)+"_checkBounds"; 128 } // end of MFrontMaterialPropertyInterface::getCheckBoundsFunctionName 129 writeEntryPointSymbol(std::ostream &,const MaterialPropertyDescription &) const130 void MFrontMaterialPropertyInterface::writeEntryPointSymbol(std::ostream&, 131 const MaterialPropertyDescription&) const 132 {} // end of MFrontMaterialPropertyInterface::writeEntryPointSymbol 133 writeTFELVersionSymbol(std::ostream &,const MaterialPropertyDescription &) const134 void MFrontMaterialPropertyInterface::writeTFELVersionSymbol(std::ostream&, 135 const MaterialPropertyDescription&) const 136 {} // end of MFrontMaterialPropertyInterface::writeTFELVersionSymbol 137 writeMaterialSymbol(std::ostream &,const MaterialPropertyDescription &) const138 void MFrontMaterialPropertyInterface::writeMaterialSymbol(std::ostream&, 139 const MaterialPropertyDescription&) const 140 {} // end of MFrontMaterialPropertyInterface::writeMaterialSymbol 141 writeInterfaceSymbol(std::ostream &,const MaterialPropertyDescription &) const142 void MFrontMaterialPropertyInterface::writeInterfaceSymbol(std::ostream&, 143 const MaterialPropertyDescription&) const 144 {} // end of MFrontMaterialPropertyInterface::writeInterfaceSymbol 145 writeMaterialKnowledgeTypeSymbol(std::ostream &,const MaterialPropertyDescription &) const146 void MFrontMaterialPropertyInterface::writeMaterialKnowledgeTypeSymbol(std::ostream&, 147 const MaterialPropertyDescription&) const 148 {} // end of MFrontMaterialPropertyInterface::writeEntryPointSymbol 149 150 MFrontMaterialPropertyInterface::~MFrontMaterialPropertyInterface() = default; 151 152 } // end of namespace mfront 153