[Common] Switch parser from Exprtk to muParser

parent b4759d4b
......@@ -20,6 +20,7 @@ image: $DUNE_ENV_IMAGE
before_script:
- cd /opt/dune
- apt-get install -y libmuparser-dev # TODO: remove before merging w/ master
stages:
- setup
......
[submodule "plugins/vendor/spdlog"]
path = plugins/vendor/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "plugins/vendor/exprtk"]
path = plugins/vendor/exprtk
url = https://github.com/ArashPartow/exprtk.git
......@@ -74,7 +74,7 @@ by CI tests.
| SuperLU | 5.2 |
| [yaml-cpp](https://github.com/jbeder/yaml-cpp) | >= 5.2.0 |
| [spdlog](https://github.com/gabime/spdlog) | 1.1.0 | Included as Git Submodule
| [exprtk](https://github.com/ArashPartow/exprtk.git) | master | Included as Git Submodule
| [muparser](http://beltoforion.de/article.php?a=muparser) | master |
| [dune-common](https://gitlab.dune-project.org/core/dune-common) | releases/2.6
| [dune-geometry](https://gitlab.dune-project.org/core/dune-geometry) | releases/2.6
| [dune-grid](https://gitlab.dune-project.org/core/dune-grid) | releases/2.6
......
......@@ -9,6 +9,7 @@ FIND_PACKAGE (FFTW REQUIRED)
FIND_PACKAGE (SuperLU REQUIRED)
FIND_PACKAGE (MPI REQUIRED)
find_package (yaml-cpp 0.5.2 REQUIRED)
FIND_PACKAGE (muParser REQUIRED)
FIND_PACKAGE (METIS)
FIND_PACKAGE (ParMETIS)
......
# - Find the muParser library
#
# Usage:
# find_package(muParser [REQUIRED] [QUIET] )
#
# It sets the following variables:
# MUPARSER_FOUND ... true if muParser is found on the system
# MUPARSER_LIBRARIES ... full path to muParser library
# MUPARSER_INCLUDES ... muParser include directory
#
set(MUPARSER_DIR "" CACHE PATH "An optional hint to a muParser installation")
if(MUPARSER_DIR STREQUAL "")
set(MUPARSER_DIR "$ENV{MUPARSER_DIR}")
endif()
find_library(MUPARSER_LIBRARY
NAMES muparser muparserd
HINTS ${MUPARSER_DIR}/lib
PATH_SUFFIXES lib${LIB_SUFFIX} lib64 lib
)
find_path(MUPARSER_INCLUDE_DIR
muParserDef.h
HINTS ${MUPARSER_DIR}
PATH_SUFFIXES include
)
find_package_handle_standard_args(MUPARSER
DEFAULT_MSG
MUPARSER_LIBRARY MUPARSER_INCLUDE_DIR)
if (MUPARSER_FOUND)
set(MUPARSER_LIBRARIES ${MUPARSER_LIBRARY} )
set(MUPARSER_INCLUDEs ${MUPARSER_INCLUDE_DIR} )
endif()
mark_as_advanced(MUPARSER_INCLUDE_DIR MUPARSER_LIBRARY)
\ No newline at end of file
......@@ -26,6 +26,7 @@ RUN apt-get clean && apt-get update && apt-get install -y \
libsuperlu-dev \
libxft-dev \
libyaml-cpp-dev \
libmuparser-dev \
locales \
python3-dev \
python3-pip \
......
......@@ -12,5 +12,4 @@ install(FILES
util.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/dorie/common)
add_subdirectory("impl")
add_subdirectory("initial_condition")
\ No newline at end of file
add_library(dorie-common STATIC math_parser.cc)
\ No newline at end of file
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/common/fvector.hh>
#include <dune/dorie/common/math_parser.hh>
#include <cstdio>
#include <string>
namespace Dune {
namespace Dorie {
// template class parser<double>;
// template class expression<double>;
// template class symbol_table<double>;
template class MathParser<FieldVector<double,3>,FieldVector<double,1>>;
template class MathParser<FieldVector<double,2>,FieldVector<double,1>>;
} // namespace Dorie
} // namespace Dune
\ No newline at end of file
......@@ -7,7 +7,8 @@
#include <dune/common/parametertree.hh>
#include <dune/dorie/common/initial_condition/initial_condition.hh>
#include <dune/dorie/common/math_parser.hh>
#include <muParser.h>
namespace Dune {
namespace Dorie {
......@@ -41,8 +42,14 @@ public:
*/
InitialConditionAnalytic (const GV& gv, const std::string& equation_str)
: Base(gv)
, _parser(equation_str,_x_global)
{}
{
_parser.DefineVar("x", &_x_global[0]);
_parser.DefineVar("y", &_x_global[1]);
if constexpr (dim == 3)
_parser.DefineVar("z", &_x_global[2]);
_parser.SetExpr(equation_str);
}
~InitialConditionAnalytic() override {};
......@@ -56,12 +63,12 @@ public:
typename Traits::RangeType& y) const override
{
_x_global = e.geometry().global(x);
y = _parser.evaluate();
y = _parser.Eval();
}
private:
mutable Domain _x_global;
MathParser<typename Traits::DomainType,typename Traits::RangeType> _parser;
mu::Parser _parser;
};
}
......
#ifndef DUNE_DORIE_MATH_PARSER_HH
#define DUNE_DORIE_MATH_PARSER_HH
#include <string>
#include <plugins/vendor/exprtk/exprtk.hpp>
#include <dune/common/exceptions.hh>
namespace Dune {
namespace Dorie {
/**
* @brief Initial conditions
* @tparam T BaseTraits
* @tparam m dimension of the Range type
*/
template<class Domain, class Range>
class MathParser
{
private:
using DF = typename Domain::value_type;
static constexpr int dim = Domain::dimension;
using SymbolTable = exprtk::symbol_table<DF>;
using Expression = exprtk::expression<DF>;
using Parser = exprtk::parser<DF>;
public:
/// Initial Condition Class Constructor. Reads initial condition parameters
/** \throw Dune::IOError BC File Type not supported
*/
MathParser (const std::string& equation_str, Domain& x_global)
{
SymbolTable symbol_table;
symbol_table.add_variable("x",x_global[0]);
symbol_table.add_variable("y",x_global[1]);
if constexpr (dim == 3)
symbol_table.add_variable("z",x_global[2]);
_expression.register_symbol_table(symbol_table);
Parser parser;
if (!parser.compile(equation_str,_expression))
DUNE_THROW(IOError,"Unexpected error with math expression!");
}
/// Evaluate the initial condition at certain position
/** \param y
* \param x Position in local element coordinates
* \param e Element enitity
*/
inline Range evaluate () const
{
return _expression.value();
}
private:
Expression _expression;
};
}
}
#endif // DUNE_DORIE_MATH_PARSER_HH
......@@ -13,7 +13,5 @@ add_library(dorie-richards STATIC
sim_ug_3_3.cc)
target_link_libraries(dorie-richards
PUBLIC
dorie-common
spdlog
PUBLIC spdlog
)
\ No newline at end of file
......@@ -46,4 +46,3 @@ updates. See the list below for the current setup.
| Software | Checkout | Branch? |
| -------- | -------- | ------- |
| spdlog | `v1.1.0` | No |
| exprtk | master | No |
Subproject commit d38dc142762e05eebfd161b7cbe290409e64ea9e
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment