diff --git a/AMDiS/AMDiSConfig.cmake.in b/AMDiS/AMDiSConfig.cmake.in index 0a8c9ced09b05e4479a2e96688c13d8693ad4519..e8dc99d5ef122cd2e80ad916eaa63ba82be12c85 100644 --- a/AMDiS/AMDiSConfig.cmake.in +++ b/AMDiS/AMDiSConfig.cmake.in @@ -41,7 +41,7 @@ find_library(_AMDIS_LIB amdis PATHS ${AMDIS_LIBRARY_DIR} ${AMDIS_DIR}/../../lib/ if(_AMDIS_LIB) get_filename_component(AMDIS_LIBRARY_DIR ${_AMDIS_LIB} PATH CACHE) set(AMDIS_LIBRARY_DIRS ${AMDIS_LIBRARY_DIR}) - set(AMDIS_LIBRARIES "${_AMDIS_LIB};${AMDIS_LIBRARY_DIR}/libcompositeFEM.so;${AMDIS_LIBRARY_DIR}/libreinit.so" CACHE STRING "amdis libraries") + set(AMDIS_LIBRARIES "${_AMDIS_LIB};${AMDIS_LIBRARY_DIR}/libcompositeFEM.so;${AMDIS_LIBRARY_DIR}/libreinit.so;${AMDIS_LIBRARY_DIR}/libmuparser.so" CACHE STRING "amdis libraries") else() message(ERROR "could not detect the AMDiS library directory. Please set the variable AMDIS_LIBRARY_DIR to the directory containg the AMDiS library") endif() @@ -129,6 +129,7 @@ endif(AMDiS_NEED_UMFPACK) #add directories for reinit list(APPEND AMDIS_INCLUDE_DIRS ${AMDIS_INCLUDE_DIR}/reinit) list(APPEND AMDIS_INCLUDE_DIRS ${AMDIS_INCLUDE_DIR}/compositeFEM) +list(APPEND AMDIS_INCLUDE_DIRS ${AMDIS_INCLUDE_DIR}/muparser) if(${AMDIS_FIND_COMPONENTS} MATCHES umfpack ) if( NOT AMDiS_NEED_UMFPACK ) diff --git a/AMDiS/CMakeLists.txt b/AMDiS/CMakeLists.txt index cdadf256d00190ef97abbd5456f064d59979bec7..7c10f956c6d676fec684e823afab4e2f3bff7095 100644 --- a/AMDiS/CMakeLists.txt +++ b/AMDiS/CMakeLists.txt @@ -336,6 +336,12 @@ set(REINIT_SOURCE_DIR ${SOURCE_DIR}/reinit) file(GLOB REINIT_SRC ${REINIT_SOURCE_DIR}/*.cc) include_directories(${REINIT_SOURCE_DIR}) + +#muparser includes +set(MUPARSER_SOURCE_DIR ${AMDiS_SOURCE_DIR}/lib/muparser_v134) +file(GLOB MUPARSER_SRC ${MUPARSER_SOURCE_DIR}/src/*.cpp) +list(APPEND AMDiS_INCLUDE_DIRS ${MUPARSER_SOURCE_DIR}/include) + #mtl4 includes list(APPEND AMDiS_INCLUDE_DIRS ${MTL_INCLUDE_DIR}) #include_directories(${MTL_INCLUDE_DIR}) @@ -346,6 +352,7 @@ include_directories(${AMDiS_INCLUDE_DIRS}) add_library(amdis SHARED ${AMDIS_SRC} ${PARALLEL_DOMAIN_AMDIS_SRC}) add_library(compositeFEM SHARED ${COMPOSITE_FEM_SRC}) add_library(reinit SHARED ${REINIT_SRC}) +add_library(muparser SHARED ${MUPARSER_SRC}) #target_link_libraries(compositeFEM amdis) #target_link_libraries(reinit amdis) list(APPEND AMDiS_LIBS amdis ${Boost_LIBRARIES}) @@ -406,8 +413,13 @@ INSTALL(FILES ${HEADERS} DESTINATION include/amdis/compositeFEM) list(APPEND deb_add_dirs "include/amdis/compositeFEM") +FILE(GLOB HEADERS "${MUPARSER_SOURCE_DIR}/include/*.h") +INSTALL(FILES ${HEADERS} + DESTINATION include/amdis/muparser) +list(APPEND deb_add_dirs "include/amdis/muparser") + list(APPEND deb_add_dirs "lib/amdis") -install(TARGETS amdis compositeFEM reinit +install(TARGETS amdis compositeFEM reinit muparser LIBRARY DESTINATION lib/amdis/ ) configure_file(${AMDiS_SOURCE_DIR}/AMDiSConfig.cmake.in diff --git a/AMDiS/src/Initfile.h b/AMDiS/src/Initfile.h index 6347e02f303f702f5999ff8ba90026672ab05509..552f607b2d14f256bdce34a70e44c07718d0bbf3 100644 --- a/AMDiS/src/Initfile.h +++ b/AMDiS/src/Initfile.h @@ -15,8 +15,12 @@ #include <boost/algorithm/string/trim.hpp> #include <boost/lexical_cast.hpp> +#include <boost/numeric/conversion/cast.hpp> + #include <boost/type_traits.hpp> +// a parser for arithmetic expressions +#include "muParser.h" namespace AMDiS { @@ -43,7 +47,18 @@ namespace AMDiS { WrongValueFormat(std::string value): std::runtime_error(std::string("cannot convert '") + value + std::string("' into <")+ name(T())+">" ) {} - + }; + template< typename T > + struct BadArithmeticExpression : std::runtime_error { + static std::string name(int ) { return "int"; } + static std::string name(bool ) { return "bool"; } + static std::string name(double ) { return "double"; } + static std::string name(unsigned int ) { return "unsigned int"; } + template< typename G > + static std::string name(G ) { return std::string(typeid(G).name()); } + + BadArithmeticExpression(std::string m, std::string value): std::runtime_error(std::string("cannot evaluate expression '") + value + std::string("' into <")+ name(T())+">\nParser message: '" + m + "'" ) + {} }; /// trim std::string @@ -125,11 +140,22 @@ namespace AMDiS { typename boost::disable_if< boost::is_enum< T > >::type* p2 = NULL ) { using boost::lexical_cast; + using boost::numeric_cast; + mu::Parser parser; + + parser.DefineConst(_T("M_PI"), m_pi); + parser.DefineConst(_T("M_E"), m_e); try { - value = lexical_cast< T >(trim(valStr)); - }catch(boost::bad_lexical_cast e) { + parser.SetExpr(valStr); +// value = lexical_cast< T >(trim(valStr)); + value= numeric_cast< T >(parser.Eval()); + } catch(boost::bad_lexical_cast e) { + throw WrongValueFormat< T >(valStr); + } catch(boost::bad_numeric_cast e) { throw WrongValueFormat< T >(valStr); + } catch (mu::Parser::exception_type &e) { + throw BadArithmeticExpression< T >(e.GetMsg(), valStr); } } diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 4315c6b5ac24b1cf672d187c6500426491951b21..1ed9525b96e42470a68229a64249758ea6ad3b4d 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -1,6 +1,7 @@ project("amdis_demo") cmake_minimum_required(VERSION 2.8) +set(AMDIS_DIR /u/spraetor/amdis-trunk/AMDiS_seq/share/amdis) #find_package(AMDIS REQUIRED COMPONENTS umfpack ) find_package(AMDIS REQUIRED)