diff --git a/CMakeLists.txt b/CMakeLists.txt index fabbc83e56a72e49c311b6672131d4769ea5fcbf..77369d876b90e89761e33e8d12fca0547882fafc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ ## Contents: ## - definition of build options ## - compiler variables ( c++ standard, warnings etc. ) -## - Finding of service libraries. Required: none, Optional: Boost, MPI, FFTW3, METIS, OpenMesh, Python +## - Finding of service libraries. Required: none, Optional: MPI, FFTW3, METIS, OpenMesh, Python ## the include paths are set, and the libraries are added to variable SERVICE_LIBS ## - Subdirectory cmake lists are called ## -> src/ this folder contains all modules, each module (that contains c or cpp files) is linked to a @@ -704,53 +704,6 @@ if ( WALBERLA_BUILD_WITH_PYTHON ) endif() -############################################################################################################################ -## -## BOOST Libraries -## -############################################################################################################################# -set ( Boost_NO_BOOST_CMAKE ON) - -# This variable is necessary, if the CMAKE version used is not aware of a more recent boost version (keep this up to date!) -set ( Boost_ADDITIONAL_VERSIONS - "1.45" "1.45.0" "1.46" "1.46.0" "1.46.1" "1.47" "1.47.0" "1.48" "1.48.0" "1.49" "1.49.0" - "1.50" "1.50.0" "1.51" "1.51.0" "1.52" "1.52.0" "1.53" "1.53.0" "1.54" "1.54.0" "1.55" "1.55.0" - "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" "1.59" "1.59.0" "1.60" "1.60.0" "1.61" "1.61.0" "1.62" "1.62.0" "1.63" "1.63.0" - "1.64.0" "1.65.0" "1.65.1" "1.66.0" "1.67.0" "1.68.0" "1.69.0" "1.70.0" "1.71.0" "1.72.0" "1.73.0" "1.74.0") - -# if you defined BOOST_ROOT or BOOST_BASE in your environment use it here to find boost too -if ( NOT BOOST_ROOT ) - foreach ( var BOOST_ROOT BOOST_BASE ) - if ( NOT "$ENV{${var}}" STREQUAL "" ) - message ( STATUS "Use environment boost directory: $ENV{${var}}" ) - set ( BOOST_ROOT $ENV{${var}} CACHE INTERNAL "") - break ( ) - endif ( ) - endforeach ( ) -endif ( ) - -find_package ( Boost ) - -if ( Boost_FOUND ) - if(CMAKE_GENERATOR STREQUAL "Xcode") - # this is needed because the SYSTEM flag to include_directories does not work - add_flag ( CMAKE_CXX_FLAGS "-isystem ${Boost_INCLUDE_DIRS}" ) - else() - include_directories ( SYSTEM ${Boost_INCLUDE_DIRS} ) - endif() - add_definitions ( -DBOOST_ALL_NO_LIB ) # Disable Boost auto-linking (CMAKE does that for us...) - - set( WALBERLA_BUILD_WITH_BOOST TRUE CACHE INTERNAL "Build with Boost" ) -else( Boost_FOUND ) - set( WALBERLA_BUILD_WITH_BOOST FALSE CACHE INTERNAL "Build with Boost" ) -endif( Boost_FOUND ) - - -############################################################################################################################ - - - - ############################################################################################################################ ## diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f3a6dc20b97c034513391b21528648f51b394299..099e0b5732a9d5b112600d150162f728bf8dcb8f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -57,8 +57,6 @@ target_sources( core Hostname.h Macros.h MemoryUsage.h - MultiArrayIO.h - MultiArrayIO.impl.h NonCopyable.h NonCreateable.h OpenMP.h diff --git a/src/core/MultiArrayIO.h b/src/core/MultiArrayIO.h deleted file mode 100644 index 097fb1c99ff0a2879c3b44b3184cee3d5cdf3428..0000000000000000000000000000000000000000 --- a/src/core/MultiArrayIO.h +++ /dev/null @@ -1,65 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file MultiArrayIO.h -//! \ingroup config -//! \author Martin Bauer <martin.bauer@fau.de> -// -//====================================================================================================================== - -#pragma once - - -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning( disable : 4189 ) -# pragma warning( disable : 4100 ) -# pragma warning( disable : 4458 ) -# pragma warning( disable : 4459 ) -# pragma warning( disable : 4510 ) -# pragma warning( disable : 4610 ) -#endif //_MSC_VER - -#include <boost/multi_array.hpp> - -#ifdef _MSC_VER -# pragma warning(pop) -#endif //_MSC_VER - - -namespace boost { - - // 1D Arrays - template< typename T> - std::istream & operator>> ( std::istream & is, boost::multi_array<T,1> & arr ); - - template<typename T> - std::ostream & operator<< ( std::ostream & os, const boost::multi_array<T,1> & arr ); - - - - // 2D Arrays - template<typename T> - std::istream & operator>> ( std::istream & is, boost::multi_array<T,2> & arr ); - - template<typename T> - std::ostream & operator<< ( std::ostream & os, const boost::multi_array<T,2> & arr ); - - - -} // namespace walberla - - -#include "MultiArrayIO.impl.h" diff --git a/src/core/MultiArrayIO.impl.h b/src/core/MultiArrayIO.impl.h deleted file mode 100644 index c9e671654aeaaf1bca3eb8d957e6d19098bde137..0000000000000000000000000000000000000000 --- a/src/core/MultiArrayIO.impl.h +++ /dev/null @@ -1,231 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file MultiArrayIO.h -//! \ingroup config -//! \author Martin Bauer <martin.bauer@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "core/DataTypes.h" -#include "core/StringUtility.h" - -#include <cstddef> -#include <sstream> - -namespace boost { - -//=================================================================================================================== -// -// Helper Functions -// -//=================================================================================================================== - - -template<typename T> -bool parseArray1D( std::vector<T> & arr, std::istream & is, - const char openingBracket='[', - const char closingBracket=']', - const std::string & delimiter = ", \t\n" ) -{ - - is >> std::skipws; - - char bracket1; - if( !(is >> bracket1 ) || bracket1 != openingBracket ) - return false; - - std::string line; - if ( ! std::getline( is, line, closingBracket ) ) - return false; - - - std::vector<std::string> stringArr = walberla::string_split( line, delimiter ); - - arr.clear(); - arr.reserve( stringArr.size() ); - for( auto sArrIt =stringArr.begin(); sArrIt != stringArr.end(); ++sArrIt ) - { - if ( *sArrIt == "") continue; - - std::stringstream ss ( *sArrIt ); - T value; - ss >> value; - arr.push_back( value ); - } - return true; -} - - - -template<typename T > -bool parseArray2D( std::vector< std::vector<T> > & arr, std::istream & is, - const char openingBracket='[', - const char closingBracket=']', - const std::string & delimiter = ", \t\n" ) -{ - is >> std::skipws; - char bracket1; - if( !(is >> bracket1 ) || bracket1 != openingBracket ) - return false; - - do - { - arr.push_back( std::vector<T>() ); - if ( ! parseArray1D( arr.back(), is, openingBracket, closingBracket, delimiter ) ) - return false; - - while( delimiter.find( (char)( is.peek()) ) != std::string::npos ) - is.get(); - - if ( is.peek() == closingBracket ) { - is.get(); - return true; - } - - } while ( true ); - -} - - -//=================================================================================================================== -// -// IO Operators -// -//=================================================================================================================== - - -template<typename T> -std::istream & operator>> ( std::istream & is, boost::multi_array<T,1> & arr ) -{ - if ( !is ) return is; - - const std::istream::pos_type pos( is.tellg() ); - const std::istream::fmtflags oldFlags( is.flags() ); - - - std::vector< T > vec; - if ( ! parseArray1D( vec, is ) ) { - is.clear(); - is.seekg( pos ); - is.setstate( std::istream::failbit ); - is.flags( oldFlags ); - return is; - } - - auto rows = vec.size(); - if ( rows == 0 ) - return is; - - arr.resize( boost::extents[walberla::numeric_cast< boost::multi_array_types::index >(rows)] ); - - for( std::size_t r = 0; r < rows; ++r ) - arr[walberla::numeric_cast< boost::multi_array_types::index >(r)] = vec[r]; - - return is; -} - -template<typename T> -std::ostream & operator<< ( std::ostream & os, const boost::multi_array<T,1> & arr ) -{ - os << "[ "; - for( std::size_t c = 0; c < arr.size(); ++c ) - os << arr[walberla::numeric_cast< boost::multi_array_types::index >(c)] << ","; - os << "]"; - - return os; -} - - - - - - -template<typename T> -std::istream & operator>> ( std::istream & is, boost::multi_array<T,2> & arr ) -{ - if ( !is ) return is; - - const std::istream::pos_type pos( is.tellg() ); - const std::istream::fmtflags oldFlags( is.flags() ); - - - std::vector< std::vector<T> > vec2D; - if ( ! parseArray2D( vec2D, is ) ) { - is.clear(); - is.seekg( pos ); - is.setstate( std::istream::failbit ); - is.flags( oldFlags ); - return is; - } - - std::size_t rows = vec2D.size(); - if ( rows == 0 ) - return is; - - std::size_t cols = vec2D[0].size(); - for( std::size_t r = 0; r < rows; ++r ) - { - if ( vec2D[r].size() != cols ) - { - // non square vector - is.clear(); - is.seekg( pos ); - is.setstate( std::istream::failbit ); - is.flags( oldFlags ); - return is; - } - } - - arr.resize( boost::extents[ walberla::numeric_cast< boost::multi_array_types::index >(rows) ][ walberla::numeric_cast< boost::multi_array_types::index >(cols) ] ); - - for( std::size_t r = 0; r < rows; ++r ) - for( std::size_t c = 0; c < cols; ++c ) - arr[walberla::numeric_cast< boost::multi_array_types::index >(r)][walberla::numeric_cast< boost::multi_array_types::index >(c)] = vec2D[r][c]; - - - return is; -} - -template<typename T> -std::ostream & operator<< ( std::ostream & os, const boost::multi_array<T,2> & arr ) -{ - os << "[\n"; - - for( std::size_t r = 0; r < arr.size(); ++r ) - { - os << " [ "; - for( std::size_t c = 0; c < arr[walberla::numeric_cast< boost::multi_array_types::index >(r)].size(); ++c ) { - os << arr[walberla::numeric_cast< boost::multi_array_types::index >(r)][walberla::numeric_cast< boost::multi_array_types::index >(c)] << "\t"; - } - os << "] \n"; - } - os << "]"; - - return os; -} - - - - - - - - -} // namespace walberla - - diff --git a/src/core/math/CMakeLists.txt b/src/core/math/CMakeLists.txt index fc18eccf217cd3c2b13358cf5119c3db5f22a065..5f8733c9ae7fbcf9f8f31a50292e34c9b2c6495f 100644 --- a/src/core/math/CMakeLists.txt +++ b/src/core/math/CMakeLists.txt @@ -22,8 +22,6 @@ target_sources( core Parser.h ParserOMP.cpp ParserOMP.h - PhysicalCheck.cpp - PhysicalCheck.h Plane.h Primes.cpp Primes.h @@ -42,17 +40,4 @@ target_sources( core Vector2.h Vector3.h extern/exprtk.h - equation_system/Equation.cpp - equation_system/Equation.h - equation_system/EquationParser.cpp - equation_system/EquationParser.h - equation_system/EquationSystem.cpp - equation_system/EquationSystem.h - equation_system/FwdEquation.h - equation_system/FwdOperator.h - equation_system/FwdVariable.h - equation_system/Operator.cpp - equation_system/Operator.h - equation_system/Variable.cpp - equation_system/Variable.h ) diff --git a/src/core/math/PhysicalCheck.cpp b/src/core/math/PhysicalCheck.cpp deleted file mode 100644 index 7288961752c9ab84be7521e994200bfa7349f63a..0000000000000000000000000000000000000000 --- a/src/core/math/PhysicalCheck.cpp +++ /dev/null @@ -1,545 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file PhysicalCheck.cpp -//! \ingroup core -//! \author David Staubach <david.staubach@fau.de> -// -//====================================================================================================================== - -#include "waLBerlaDefinitions.h" -#ifdef WALBERLA_BUILD_WITH_BOOST - -#include "PhysicalCheck.h" -#include "core/Abort.h" -#include "core/logging/Logging.h" -#include "core/math/Parser.h" -#include "equation_system/EquationParser.h" - - -namespace walberla { -namespace math { - - PhysicalCheck::PhysicalCheck() : - solved_( false ) - {} - - PhysicalCheck::PhysicalCheck( const std::vector< std::string >& equations, const std::map< std::string, std::string >& unitParameterRelations, const std::vector<std::string>& constraints ) : - solved_( false ) - { - addEquations( equations ); - addUnitParameterRelations( unitParameterRelations ); - addConstraints( constraints ); - } - - PhysicalCheck::PhysicalCheck( const Config::BlockHandle& configBlock ) : - solved_( false ) - { - addBlock( configBlock ); - } - - void PhysicalCheck::addBlock( const Config::BlockHandle& configBlock ) - { - auto eqBlock = configBlock.getBlock( "Equations" ); - - if( eqBlock ) - { - std::vector< std::string > equations; - for( auto i=eqBlock.begin(); i!=eqBlock.end(); ++i ) - equations.push_back(i->second); - - addEquations( equations ); - } - - auto unitBlock = configBlock.getBlock( "Units" ); - - if ( unitBlock ) - { - std::map< std::string, std::string > unitParameterRelations; - for( auto i=unitBlock.begin(); i!=unitBlock.end(); ++i ) - unitParameterRelations.insert( - std::pair<std::string,std::string>(i->first,i->second)); - - - addUnitParameterRelations( unitParameterRelations ); - } - - auto constraintsBlock = configBlock.getBlock( "Constraints" ); - - if( constraintsBlock ) - { - std::vector<std::string> constraints; - for( auto i=constraintsBlock.begin(); i!=constraintsBlock.end(); ++i ) - constraints.push_back(i->second); - - addConstraints( constraints ); - } - } - - void PhysicalCheck::addEquations( const std::vector< std::string >& equations ) - { - EquationParser ep(es_); - size_t index = 0; - - solved_ = false; - - for (size_t i=0; i<equations.size(); ++i){ - index = 0; - es_.add( std::to_string(es_.getNumberOfEquations()+1), ep.parseEquation( equations[i], index ) ); - } - } - - void PhysicalCheck::addEquation( const std::string& equation ) - { - EquationParser ep(es_); - size_t index = 0; - - solved_ = false; - - es_.add( std::to_string(es_.getNumberOfEquations()+1), ep.parseEquation( equation, index ) ); - } - - void PhysicalCheck::addUnitParameterRelations( const std::map< std::string, std::string >& unitParameterRelations ) - { - // parse units and store unit as int - for( auto i=unitParameterRelations.begin(); i!=unitParameterRelations.end(); ++i ) - { -// unitParameterRelations_[i->first]["m"] = 0; -// unitParameterRelations_[i->first]["s"] = 0; -// unitParameterRelations_[i->first]["kg"] = 0; -// unitParameterRelations_[i->first]["A"] = 0; - - std::string unitString = i->second; - int factor = 1; - - for( size_t j=0; j<unitString.size(); ++j ) - { - if( unitString[j] == 'm' || unitString[j] == 's' || unitString[j] == 'A' ) - { - size_t index = j; - ++j; - - // make this work for exponents larger than 9 - if( j < unitString.size() && unitString[j] == '^' ) - { - ++j; - int expo = factor * std::atoi( &unitString[j] ); - if( !setVarUnit( i->first, unitString.substr(index,1), expo ) ) - WALBERLA_ABORT( "Error in PhysicalCheck::addUnitParameterRelations(). Non-unique description for unit '" << unitString[index] << "' for parameter '" << i->first << "'." ); - } - else - { - --j; - if( !setVarUnit( i->first, unitString.substr(index,1), factor ) ) - WALBERLA_ABORT( "Error in PhysicalCheck::addUnitParameterRelations(). Non-unique description for unit '" << unitString[index] << "' for parameter '" << i->first << "'." ); - } - } - else if( unitString[j] == 'k' ) - { - size_t index = j; - ++j;++j; - - if( j < unitString.size() && unitString[j] == '^' ) - { - ++j; - int expo = factor * std::atoi( &unitString[j] ); - if( !setVarUnit( i->first, unitString.substr(index,2), expo ) ) - WALBERLA_ABORT( "Error in PhysicalCheck::addUnitParameterRelations(). Non-unique description for unit 'kg' for parameter '" << i->first << "'."); - } - else - { - --j; - if( !setVarUnit( i->first, unitString.substr(index,2), factor ) ) - WALBERLA_ABORT( "Error in PhysicalCheck::addUnitParameterRelations(). Non-unique description for unit 'kg' for parameter '" << i->first << "'."); - } - } - else if( unitString[j] == '/') - factor = -1; - else - continue; // necessary to allow for units of the form: 1/s - } - - // add equation for the calculation between lattice and physical units - std::stringstream ss; - ss << "'" << i->first << "_L' = '" << i->first << "'"<< getParametrizationTerm(i->first); - addEquation( ss.str() ); - } - } - - std::string PhysicalCheck::getParametrizationTerm( const std::string& varName ) - { - std::map<std::string,int> parametrizationTerm; - - parametrizationTerm["dx"] = - unitParameterRelations_[varName]["m"] - 3*unitParameterRelations_[varName]["kg"] - 5*unitParameterRelations_[varName]["A"]; - parametrizationTerm["dt"] = - unitParameterRelations_[varName]["s"] + 3*unitParameterRelations_[varName]["A"]; - parametrizationTerm["rho"] = - unitParameterRelations_[varName]["kg"] - unitParameterRelations_[varName]["A"]; - - std::stringstream num; - std::stringstream denom; - for( auto i=parametrizationTerm.begin(); i!=parametrizationTerm.end(); ++i ) - { - if( i->second == 0 ) - continue; - - if( i->second < 0 ) - { - if( !denom.str().empty() ) - denom << " * "; - denom << i->first; - } - else - { - num << " * " << i->first; - } - - if( i->second < -1 ) - denom << " ^ " << std::abs( i->second ); - else if( i->second > 1 ) - num << " ^ " << i->second; - } - - if( num.str().empty() && denom.str().empty() ) - return std::string(); - - if( denom.str().empty() ) - { - num << " *"; - return num.str(); - } - - if( num.str().empty() ) - num << " * 1"; - - num << " / ( "; - num << denom.str() << " )"; - return num.str(); - } - - void PhysicalCheck::addConstraints( const std::vector<std::string>& constraints ) - { - for( auto i=constraints.begin(); i!=constraints.end(); ++i ) - constraints_.push_back( *i ); - } - - void PhysicalCheck::completeConfig( const shared_ptr<Config>& config ) - { - auto globalBlock = config->getWritableGlobalBlock(); - - std::map<std::string,double> symbolTable; - getVarMap(symbolTable); - - completeBlock( globalBlock, symbolTable ); - } - - void PhysicalCheck::completeBlock( Config::Block& configBlock, const std::map<std::string,double>& symbolTable ) - { - if( configBlock.getKey() == "Physical_Check" ) - return; - - // traverse all parameters in the current block - for( auto param=configBlock.begin(); param!=configBlock.end(); ++param ) - { - // check for "'" in the string and erase if present - std::string expression(param->second); - if( expression[0] == '\'' ) - { - expression.erase( std::remove(expression.begin(), expression.end(), '\''), expression.end() ); - - FunctionParser funcParser; - try - { - // hand the expression over to the FunctionParser - funcParser.parse(expression); - } - catch( std::exception& ) - { - WALBERLA_ABORT( "BadSyntaxException when completing Config-File. Block: " << configBlock.getKey()<< ", Parameter: "<< param->first ); - } - - double result=0; - try - { - result = funcParser.evaluate(symbolTable); - } - catch( std::exception& ) - { - WALBERLA_ABORT( "UnknownSymbolException when completing Config-File. Block: " << configBlock.getKey() ); - } - - // set the current parameter to the evaluated result in the current block - std::ostringstream os; - os << std::setprecision(16) << result; - configBlock.setParameter( param->first, os.str() ); - - // check for the equality of the parameter and the result - double val = configBlock.getParameter<double>( param->first ); - if( !floatIsEqual( val, result ) ) - WALBERLA_ABORT( "Error in PhysicalCheck::completeBlock(). Failure when trying to complete Block: " << configBlock.getKey() ); - } - } - - // recursive call of the inner blocks within the current block - std::vector<Config::Block*> innerBlocks; - configBlock.getWritableBlocks( innerBlocks ); - - for( auto innerBlock=innerBlocks.begin();innerBlock!=innerBlocks.end();++innerBlock ) - completeBlock( **innerBlock, symbolTable ); - } - - bool PhysicalCheck::isDefined( const std::string& varName ) - { - if( !solved_ ) - solve(); - - return es_.isVarDefined( varName ); - } - - double PhysicalCheck::getVarValue( const std::string& varName ) - { - if( !isDefined(varName) ) - { - WALBERLA_ABORT( "Error in PhysicalCheck::getVarValue(). Variable not found: " << varName ); - return 0; - } - - return es_.getVarValue(varName); - } - - std::string PhysicalCheck::getVarUnit( const std::string& varName ) - { - if( !isDefined(varName) ) - { - WALBERLA_ABORT( "Error in PhysicalCheck::getVarUnit(). Variable not found: " << varName ); - return std::string(); - } - - std::stringstream num; - std::stringstream denom; - for( auto i=unitParameterRelations_[varName].begin(); i!=unitParameterRelations_[varName].end(); ++i ) - { - if( i->second == 0 ) - continue; - - if( i->second < 0 ) - denom << i->first; - else - num << i->first; - - if( i->second < -1 ) - denom << '^' << std::abs( i->second ); - else if( i->second > 1 ) - num << '^' << i->second; - } - - if( num.str().empty() && denom.str().empty() ) - return std::string(); - - if( denom.str().empty() ) - return num.str(); - - if( num.str().empty() ) - num << 1; - - num << '/'; - num << denom.str(); - return num.str(); - } - - bool PhysicalCheck::setVarUnit( const std::string& varName, const std::string& unit, const int expo ) - { - if( unitParameterRelations_[varName][unit] != 0 ) - return false; - - unitParameterRelations_[varName][unit] = expo; - return true; - } - - void PhysicalCheck::getVarMap( std::map<std::string,double>& varMap ) - { - if( !solved_ ) - solve(); - - es_.getVarMap( varMap ); - } - - void PhysicalCheck::solve() - { - if( !es_.solve() ) - WALBERLA_ABORT( "Error in PhysicalCheck::solve(). System of equations is not solvable." ); - - solved_ = true; - WALBERLA_LOG_INFO( "System of equations has been solved successfully.\n" << es_.writeVariables() ); - - if( checkConstraints() ) - WALBERLA_LOG_INFO( "All constraints are fulfilled." ); - } - - bool PhysicalCheck::checkConstraints() - { - enum Operator{ LOWER, LOWER_EQUAL, GREATER, GREATER_EQUAL, UNEQUAL, INVALID }; - - std::map<std::string,double> symbolTable; - getVarMap( symbolTable ); - - for( auto i=constraints_.begin(); i!=constraints_.end(); ++i ) - { - std::string constraintString( *i ); - - Operator op = INVALID; - uint_t lenLHS = 0; - uint_t startRHS = 0; - - // parse constraint and search for operator <,>,<=,>=,!= - for( uint_t j=0; j<constraintString.size(); ++j ) - { - switch( constraintString[j] ) - { - case '<': - lenLHS = j; - if( constraintString[j+1] == '=' ) - { - op = LOWER_EQUAL; - startRHS = j+2; - } - else - { - op = LOWER; - startRHS = j+1; - } - break; - case '>': - lenLHS = j; - if( constraintString[j+1] == '=' ) - { - op = GREATER_EQUAL; - startRHS = j+2; - } - else - { - op = GREATER; - startRHS = j+1; - } - break; - case '!': - if( constraintString[j+1] == '=' ) - { - op = UNEQUAL; - lenLHS = j; - startRHS = j+2; - } - else - WALBERLA_ABORT( "Error in PhysicalCheck::checkConstraints(). Invalid operator '!'." ); - break; - default: - break; - } - } - - if ( op == INVALID ) - WALBERLA_ABORT( "Error in PhysicalCheck::checkConstraints(): No Operator found in " << constraintString ); - - // use the FunctionParser to parse and solve the lhs and the rhs, respectively - std::string lhs = constraintString.substr( 0, lenLHS ); - std::string rhs = constraintString.substr( startRHS, constraintString.size()-startRHS ); - - FunctionParser funcParser; - try - { - funcParser.parse(lhs); - } - catch( std::exception& ) - { - WALBERLA_ABORT( "BadSyntaxException when checking constraints. Constraint: '" << lhs << "'" ); - } - - double resultLHS=0; - try - { - resultLHS = funcParser.evaluate(symbolTable); - } - catch( std::exception& ) - { - WALBERLA_ABORT( "UnknownSymbolException when checking constraints. Constraint: '" << lhs << "'" ); - } - - try - { - funcParser.parse(rhs); - } - catch( std::exception& ) - { - WALBERLA_ABORT( "BadSyntaxException when checking constraints. Constraint: '" << rhs << "'" ); - } - - double resultRHS=0; - try - { - resultRHS = funcParser.evaluate(symbolTable); - } - catch( std::exception& ) - { - WALBERLA_ABORT( "UnknownSymbolException when checking constraints. Constraint: '" << rhs << "'" ); - } - - switch( op ) - { - case LOWER: - if( !(resultLHS < resultRHS) ) - WALBERLA_ABORT( "Constraint '" << constraintString << "' failed." ); - break; - case LOWER_EQUAL: - if( !(resultLHS <= resultRHS) ) - WALBERLA_ABORT( "Constraint '" << constraintString << "' failed." ); - break; - case GREATER: - if( !(resultLHS > resultRHS) ) - WALBERLA_ABORT( "Constraint '" << constraintString << "' failed." ); - break; - case GREATER_EQUAL: - if( !(resultLHS >= resultRHS) ) - WALBERLA_ABORT( "Constraint '" << constraintString << "' failed." ); - break; - case UNEQUAL: - if( floatIsEqual(resultLHS,resultRHS) ) - WALBERLA_ABORT( "Constraint '" << constraintString << "' failed." ); - break; - default: - WALBERLA_ABORT( "Error in PhysicalCheck::checkConstraints(). Entered unreachable code." ); - break; - } - } - - return true; - } - - void PhysicalCheck::writeUnitParameterRelations() - { - std::stringstream ss; - ss << "Unit-Parameter-Relations:" << std::endl; - for( auto i=unitParameterRelations_.begin(); i!=unitParameterRelations_.end(); ++i ) - { - ss << i->first << " (" << getVarUnit(i->first) << ")" << std::endl; - } - } - - std::ostream& operator<<( std::ostream& os, PhysicalCheck& pc ) - { - return os << pc.es_; - } - -} // namespace math -} // namespace walberla - -#endif diff --git a/src/core/math/PhysicalCheck.h b/src/core/math/PhysicalCheck.h deleted file mode 100644 index 857b292f404f96b2bec8fed07ed036963afefea4..0000000000000000000000000000000000000000 --- a/src/core/math/PhysicalCheck.h +++ /dev/null @@ -1,138 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file PhysicalCheck.h -//! \ingroup core -//! \author David Staubach <david.staubach@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "core/config/Config.h" -#include "equation_system/EquationSystem.h" - -#include <map> -#include <string> -#include <vector> - - -namespace walberla { -namespace math { - - //=================================================================================================================== - // - // CLASS DEFINITION - // - //=================================================================================================================== - - //******************************************************************************************************************* - /*!\brief Wrapper class to check for physical properties and correctness of given input parameters - * - * This class serves as an interface between the given parameters in an input file and the - * math module classes that solve the equations and expressions of interest. - * It can be created either by passing a vector of equations, a map of unit-parameter relations and - * a vector of constraints, or by passing a BlockHandle to the input file. - * - * The blocks for the PhysicalCheck in the input file are bound to the following layout: - * - * Physical_Check { - * Equations { - * eq0 parameter1 = 23; - * eq1 parameter2 = 42; - * - * eq2 var1 = parameter1 + cos(parameter2); - * eq3 var2 = parameter2 - 23; - * } - * Units { - * parameter1 m; - * parameter2 m^2/s; - * } - * Constraints { - * co0 var1 > 20; - * co1 var1 <= 30; - * co2 var2 != var1; - * } - * } - * - * Geometry { - * BoundaryConditionXYZ { - * velocity 'parameter1'; - * pressure 'var1 * 29.9'; - * } - * - * BoundaryConditionABC { - * velocity 'parameter1'; - * } - * } - */ - class PhysicalCheck - { - public: - - //**Constructors***************************************************************************** - PhysicalCheck(); - PhysicalCheck( const std::vector<std::string>& equations, const std::map< std::string, std::string >& unitParameterRelations, const std::vector<std::string>& constraints ); - PhysicalCheck( const Config::BlockHandle& configBlock ); - - //**Utility functions************************************************************************ - /*! \name Utility functions */ - //@{ - void addBlock ( const Config::BlockHandle& configBlock ); - void addEquations ( const std::vector<std::string>& equations ); - void addUnitParameterRelations ( const std::map< std::string, std::string >& unitParameterRelations ); - void addConstraints ( const std::vector<std::string>& constraints ); - void completeConfig ( const shared_ptr<Config>& config ); - //@} - //**************************************************************************************************************** - - //**Get functions**************************************************************************** - /*! \name Get functions */ - //@{ - bool isDefined ( const std::string& varName ); - double getVarValue( const std::string& varName ); - //@} - //**************************************************************************************************************** - - //**Output functions************************************************************************* - /*! \name Output functions */ - //@{ - friend std::ostream& operator<<( std::ostream& os, PhysicalCheck& pc ); - //@} - //**************************************************************************************************************** - private: - //**Private functions to setup data layout from the given input file************************* - /*! \name Private functions */ - //@{ - void addEquation ( const std::string& equation ); - std::string getParametrizationTerm ( const std::string& varName ); - void solve (); - bool checkConstraints (); - void completeBlock ( Config::Block& configBlock, const std::map<std::string,double>& symbolTable ); - std::string getVarUnit ( const std::string& varName ); - bool setVarUnit ( const std::string& varName, const std::string& unit, const int expo ); - void getVarMap ( std::map<std::string,double>& varMap ); - void writeUnitParameterRelations (); - //@} - //**************************************************************************************************************** - - EquationSystem es_; - std::map<std::string, std::map<std::string, int> > unitParameterRelations_; - std::vector<std::string> constraints_; - bool solved_; - }; - -} // namespace math -} // namespace walberla diff --git a/src/core/math/all.h b/src/core/math/all.h index 0d5c22ad7d8b0f11e5887e47712ee0e36dcc9fdb..a1c1c9e1bc38113246d5a0c11e2a41baad0e2a83 100644 --- a/src/core/math/all.h +++ b/src/core/math/all.h @@ -36,9 +36,6 @@ #include "Matrix3.h" #include "Parser.h" #include "ParserOMP.h" -#ifdef WALBERLA_BUILD_WITH_BOOST -#include "PhysicalCheck.h" -#endif #include "Plane.h" #include "Primes.h" #include "Random.h" @@ -48,5 +45,3 @@ #include "Utility.h" #include "Vector2.h" #include "Vector3.h" - -#include "equation_system/all.h" diff --git a/src/core/math/equation_system/Equation.cpp b/src/core/math/equation_system/Equation.cpp deleted file mode 100644 index 96717ca97ae89dca49dc9730448a264fd08fc969..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/Equation.cpp +++ /dev/null @@ -1,261 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Equation.cpp -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#include "Equation.h" -#include "Operator.h" -#include "Variable.h" - -#include <algorithm> -#include <cmath> -#include <memory> - - -namespace walberla { -namespace math { - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // NODE - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Node::Node( const double value ) : nodeType_(NT_CONSTANT), value_(value ), opType_(OP_NO ) {} - Node::Node( const VarPtr& var ) : nodeType_(NT_VARIABLE), value_(FP_NAN), opType_(OP_NO ), var_(var) {} - Node::Node( OpType& opType ) : nodeType_(NT_OPERATOR), value_(FP_NAN), opType_(opType) {} - - void Node::setVar( const VarPtr& var ){ var_ = var; } - - void Node::collectVariables( VarMap& varMap ){ - switch (nodeType_) - { - case NT_CONSTANT: - break; - case NT_VARIABLE: - if ( varMap.find( var_->getName() ) == varMap.end() ) - varMap[var_->getName()] = var_; - break; - case NT_OPERATOR: - left_->collectVariables ( varMap ); - right_->collectVariables( varMap ); - break; - default: - WALBERLA_ABORT( "No correct node type" ); - break; - } - } - - uint_t Node::countUnknownVariables(){ - switch (nodeType_) - { - case NT_CONSTANT: - return 0; - case NT_VARIABLE: - return var_->valid() ? 0 : 1; - case NT_OPERATOR: - return left_->countUnknownVariables() + right_->countUnknownVariables(); - default: - WALBERLA_ABORT( "No correct node type" ); - return 0; // has no effect - break; - } - } - - double Node::compute(){ - switch (nodeType_) - { - case NT_CONSTANT: - return value_; - case NT_VARIABLE: - return var_->getValue(); - case NT_OPERATOR: - return opType_(left_->compute(), right_->compute()); - default: - WALBERLA_ABORT( "No correct node type" ); - return 0; // has no effect - break; - } - } - - bool Node::findUnknownVariable(){ - switch (nodeType_) - { - case NT_CONSTANT: - return false; - case NT_VARIABLE: - return !var_->valid(); - case NT_OPERATOR: - if(left_->findUnknownVariable()){ - nodeDir_ = ND_LEFT; - return true; - } - if(right_->findUnknownVariable()){ - nodeDir_ = ND_RIGHT; - return true; - } - return false; - default: - WALBERLA_ABORT( "No correct node type" ); - return false; // has no effect - break; - } - } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // EQUATION - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Equation::Equation( const NodePtr& root) : root_ (root) - { - root_->collectVariables( varMap_ ); - } - - bool Equation::evaluate(){ - if (!isEvaluatable()) - WALBERLA_ABORT( "Equation is not evaluatable" ); - - double left = root_->left_->compute(); - double right = root_->right_->compute(); - - if ( std::isnan(left) && std::isnan(right) ){ - //WALBERLA_LOG_WARNING( "WARNING: Both values are NAN -> return true" ); - return true; - } else if ( std::isinf(left) && std::isinf(right) ){ - //WALBERLA_LOG_WARNING( "WARNING: Both values are INF -> return true" ); - return true; - } - - const double border = std::max( - std::fabs(left/2e12 + right/2e12), - std::fabs(left/2e12 - right/2e12) ); - - return std::fabs( left - right ) < std::max( border, std::numeric_limits<double>::epsilon() ); - } - - VarPtr Equation::compute(){ - if (!isComputable()) - WALBERLA_ABORT( "Equation is not computable" ); - - sort(); - - root_->left_->var_->setValue( root_->right_->compute() ); - - return root_->left_->var_; - } - - - void Equation::sort(){ - if ( root_->right_->findUnknownVariable() ) - root_->flip(); - else - root_->left_->findUnknownVariable(); - - while( root_->left_->nodeType_ == NT_OPERATOR ){ - if ( root_->left_->opType_ == OP_PLUS ) - { - rotate( (root_->left_->nodeDir_ == ND_RIGHT), OP_MINUS, OP_MINUS ); - } - else if ( root_->left_->opType_ == OP_MINUS ) - { - rotate( false, OP_PLUS, OP_MINUS ); - } - else if ( root_->left_->opType_ == OP_MULT ) - { - rotate( (root_->left_->nodeDir_ == ND_RIGHT), OP_DIV, OP_DIV ); - } - else if ( root_->left_->opType_ == OP_DIV ) - { - rotate( false, OP_MULT, OP_DIV ); - } - else if ( root_->left_->opType_ == OP_PROD ) - { - //rotate( (root_->left_->nodeDir_ == ND_RIGHT), OP_ROOT, OP_LOG ); - rotate( (root_->left_->nodeDir_ == ND_RIGHT), OP_PROD, OP_LOG ); - } - else if ( root_->left_->opType_ == OP_LOG ) - { - //rotate( (root_->left_->nodeDir_ == ND_LEFT), OP_PROD, OP_ROOT ); - rotate( (root_->left_->nodeDir_ == ND_LEFT), OP_PROD, OP_PROD ); - } - //else if ( root_->left_->opType_ == OP_ROOT ) - //{ - // rotate( false, OP_PROD, OP_LOG ); - //} - else - WALBERLA_ABORT( "Unknown operator" ); - } - } - - void Equation::rotate(bool flip, OpType& leftOp, OpType& rightOp){ - NodePtr newNode; - if ( root_->left_->nodeDir_ == ND_LEFT ){ - newNode = std::make_shared<Node>( leftOp ); - if (flip){ - newNode->left_ = root_->left_->right_; - newNode->right_ = root_->right_; - } else { - newNode->right_ = root_->left_->right_; - newNode->left_ = root_->right_; - } - root_->left_ = root_->left_->left_; - } else { - newNode = std::make_shared<Node>( rightOp ); - if (flip){ - newNode->right_ = root_->left_->left_; - newNode->left_ = root_->right_; - } else { - newNode->left_ = root_->left_->left_; - newNode->right_ = root_->right_; - } - root_->left_ = root_->left_->right_; - } - root_->right_ = newNode; - } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // OUTPUT - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - std::ostream& operator<<( std::ostream& os, const Node & node ){ - switch (node.nodeType_) - { - case NT_CONSTANT: - os << node.value_; - break; - case NT_VARIABLE: - os << node.var_->getName(); - break; - case NT_OPERATOR: - if (node.opType_ == OP_EQUAL) - os << *node.left_ << node.opType_ << *node.right_; - else if( node.opType_ == OP_LOG ) - os << "log(" << *node.left_ << ", " << *node.right_ << ")"; - else - os << "(" << *node.left_ << node.opType_ << *node.right_ << ")"; - break; - default: - WALBERLA_ABORT( "No correct node type" ); - break; - } - return os; - } - - std::ostream& operator<<( std::ostream& os, const Equation & eq ){ - return os << *eq.root_; - } - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/Equation.h b/src/core/math/equation_system/Equation.h deleted file mode 100644 index 3ccbb14f7ef2ca2842222878448e44c10e3e7dfd..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/Equation.h +++ /dev/null @@ -1,113 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Equation.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "FwdEquation.h" -#include "FwdOperator.h" -#include "FwdVariable.h" -#include "core/Abort.h" - - -namespace walberla { -namespace math { - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // NODE - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class Node - { - friend class Equation; - - private: - const NodeType nodeType_; - const double value_; - NodeDir nodeDir_; - OpType& opType_; - - VarPtr var_; - NodePtr left_; - NodePtr right_; - - public: - Node( const double value ); - Node( const VarPtr& var ); - Node( OpType& opType ); - private: - Node& operator=( const Node& ){ return *this; } - - public: - friend std::ostream& operator<<( std::ostream& os, const Node & node ); - - private: - uint_t countUnknownVariables(); - bool findUnknownVariable(); - - void collectVariables( VarMap& varMap ); - - void flip(){ left_.swap(right_); } - - public: - double compute(); - - NodePtr& left () { return left_; } - NodePtr& right() { return right_; } - - void setVar( const VarPtr& var ); - void setOp ( OpType& opType ); - }; - // end class Node - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // EQUATION - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class Equation - { - public: - NodePtr root_; - VarMap varMap_; - - public: - Equation( const NodePtr& root ); - - private: - uint_t countUnknownVariables(){ return uint_c( root_->countUnknownVariables() ); } - - public: - friend std::ostream& operator<<( std::ostream& os, const Equation & eq ); - - bool isComputable() { return countUnknownVariables() == 1; } - bool isEvaluatable() { return countUnknownVariables() == 0; } - - bool evaluate(); - VarPtr compute(); - - private: - void sort(); - void rotate(bool flip, OpType& leftOp, OpType& rightOp); - - public: - const VarMap& getVarMap() { return varMap_; } - }; - // end class Equation - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/EquationParser.cpp b/src/core/math/equation_system/EquationParser.cpp deleted file mode 100644 index d5bdb0aafa54228fcecc356c9d24f877a65f5d80..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/EquationParser.cpp +++ /dev/null @@ -1,347 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file EquationParser.cpp -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#include "waLBerlaDefinitions.h" -#ifdef WALBERLA_BUILD_WITH_BOOST - -#include "Equation.h" -#include "EquationParser.h" -#include "Operator.h" -#include "Variable.h" -#include "core/math/Constants.h" -#include "core/StringUtility.h" - -#include <memory> - - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// PARSE UTIL -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#define THROW(msg, str, index) {\ - std::stringstream ss;\ - ss << (msg) << " -> [" << (str) << "] at [" << (index) << "]";\ - throw std::runtime_error( ss.str() );\ -} - -namespace walberla { -namespace math { - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// PARSE NUMBER -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -bool EquationParser::checkNumber( const std::string& str, size_t& index ) const -{ - if(str[index] == '+' || str[index] == '-') - return isdigit(str[index+1]) != int(0); - return isdigit(str[index]) != int(0); -} - -NodePtr EquationParser::parseNumber( const std::string& str, size_t& index ) const -{ - size_t start = index; - double value; - - if(str[index] == '+' || str[index] == '-') - ++index; - - if( isdigit(str[index]) == int(0) ) - THROW( "No number found", str, index ); - - while( isdigit(str[++index]) ); - - // numbers are allowed to end with a '.' - if ( str[index] == '.' ) - while( isdigit(str[++index]) != int(0) ); - - if ( str[index] == 'e' || str[index] == 'E' ){ - ++index; - size_t estart = index; - if( str[index] == '+' || str[index] == '-' ) - ++index; - if( isdigit(str[index]) == int(0) ) - THROW( "Number ends with 'e'", str, index ); - while( isdigit(str[++index]) != int(0) ); - - value = std::stod( str.substr(start, estart-start-1) ) * - pow(10.0, std::stoi( str.substr(estart, index-estart) ) ); - } else { - value = std::stod( str.substr(start, index-start) ); - } - - return std::make_shared<Node>( value ); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// PARSE NT_VARIABLE -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -bool EquationParser::checkVariable( const std::string& str, size_t& index ) const -{ - if(str[index] == '+' || str[index] == '-') - return (isalpha(str[index+1]) != int(0)) || (str[index+1] == '\''); - return (isalpha(str[index]) != int(0)) || (str[index] == '\''); -} - -NodePtr EquationParser::parseVariable( const std::string& str, size_t& index ) const -{ - bool sign = false; - if(str[index] == '+' || str[index] == '-'){ - sign = str[index] == '-'; - ++index; - } - - // variables can start with a ' - bool marked = (str[index] == '\''); - if ( marked ) - ++index; - - if ( isalpha(str[index]) == int(0) ) - THROW( "Variable name has to start with a letter", str, index ); - - size_t start = index; - size_t len; - - for ( - len=1, ++index; - (isalpha(str[index]) != int(0)) || (isdigit(str[index]) != int(0)) || str[index] == '_'; - ++len, ++index ); - - if ( marked ) - { - if (str[index] == '\'' ){ - ++index; - } else { - THROW( "Variable declaration has to end with '", str, index ); - } - } - - std::string name = str.substr(start, len); - - VarPtr varPtr; - if ( es_.varMap_.find(name) != es_.varMap_.end() ){ - varPtr = es_.varMap_[name]; - } else { - varPtr = std::make_shared<Var>( name ); - es_.varMap_[name] = varPtr; - } - - NodePtr nodePtr; - if (sign){ - nodePtr.reset( new Node(OP_MULT) ); - nodePtr->left().reset( new Node( -1) ); - nodePtr->right().reset( new Node(varPtr) ); - } else { - nodePtr.reset( new Node(varPtr) ); - } - return nodePtr; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// PARSE FUNCTION -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -bool EquationParser::checkFunction( const std::string& str, size_t& index ) const -{ - return (str.substr(index, 4) == "exp(") || - (str.substr(index, 3) == "ln(") || - (str.substr(index, 5) == "sqrt("); -} - -NodePtr EquationParser::parseFunction( const std::string& str, size_t& index ) const -{ - OpFunction opFunc; - if ( str.substr(index, 4) == "exp(" ){ - opFunc = OP_FUNC_EXP; - index += 4; - } else if ( str.substr(index, 3) == "ln(" ){ - opFunc = OP_FUNC_LN; - index += 3; - } else if ( str.substr(index, 5) == "sqrt(" ){ - opFunc = OP_FUNC_SQRT; - index += 5; - } else { - THROW( "Found no function", str, index ); - } - NodePtr nodePtr = parseExpression(str, index); - if ( ! (str[index] == ')') ) - THROW( "Found no enclosing parenthesis", str, index ); - ++index; - - NodePtr funcPtr; - - switch(opFunc) - { - case OP_FUNC_EXP: - funcPtr = std::make_shared<Node>( OP_PROD ); - funcPtr->left() = std::make_shared<Node>( math::e ); - funcPtr->right() = nodePtr; - return funcPtr; - case OP_FUNC_LN: - funcPtr = std::make_shared<Node>( OP_LOG ); - funcPtr->right() = std::make_shared<Node>( math::e ); - funcPtr->left() = nodePtr; - return funcPtr; - case OP_FUNC_SQRT: - funcPtr = std::make_shared<Node>( OP_PROD ); - funcPtr->left() = nodePtr; - funcPtr->right() = std::make_shared<Node>( 0.5 ); - return funcPtr; - default: - WALBERLA_ABORT( "Function not yet defined" ); - break; - } - return funcPtr; // has no effect -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// PARSE EXPRESSION -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//********************************************************************************************************************** -/*! -* Parses a given term inside the current expression -* -* Goal: creating a binary tree node for the corresponding term -* -* \param str string representation of the term -* \param index index of the current term within the equation -*/ -//********************************************************************************************************************** -NodePtr EquationParser::parseTerm( const std::string& str, size_t& index ) const -{ - NodePtr nodePtr; - - // check for the type of the current term - if ( str[index] == '(' ){ - nodePtr = parseExpression(str, ++index); - if ( ! (str[index] == ')') ) - THROW( "Found no enclosing parenthesis", str, index ); - ++index; - } else if ( checkFunction(str, index) ) { - nodePtr = parseFunction(str, index); - } else if ( checkVariable(str, index) ) { - nodePtr = parseVariable(str, index); - } else if ( checkNumber(str, index) ) { - nodePtr = parseNumber(str, index); - } else { - THROW( "Found no parenthesis, variable or number", str, index ); - } - return nodePtr; -} - -//********************************************************************************************************************** -/*! -* Parses a given expression inside the current Equation -* -* Goal: modeling the current expression in binary tree format -* -* \param str string representation of the expression -* \param index index of the current term within the equation -*/ -//********************************************************************************************************************** -NodePtr EquationParser::parseExpression( const std::string& str, size_t& index ) const -{ - NodePtr leftPtr = parseTerm(str, index); - - // index has been shifted to next term by parseTerm function - size_t indexFstOp = index; - if ( str[index] == '=' || str.size() == index || str[index] == ')'){ - return leftPtr; - } else if ( isop(str[index]) ){ - ++index; - } else { - THROW( "Found no operator or equal", str, index ); - } - - NodePtr rightPtr; - bool run = true; - do { - rightPtr = parseTerm(str, index); - - size_t indexSndOp = index; - if ( str[index] == '=' || str.size() == index || str[index] == ')'){ - NodePtr nodePtr ( new Node (getOp(str[indexFstOp])) ); - nodePtr->left() = leftPtr; - nodePtr->right() = rightPtr; - return nodePtr; - } else if ( isop(str[index]) ){ - ++index; - } else { - THROW( "Found no operator or equal", str, index ); - } - - OpType& opFst = getOp(str[indexFstOp]); - OpType& opSnd = getOp(str[indexSndOp]); - - if (opFst >= opSnd){ - NodePtr nodePtr ( new Node (getOp(str[indexFstOp])) ); - nodePtr->left() = leftPtr; - nodePtr->right() = rightPtr; - leftPtr = nodePtr; - indexFstOp = indexSndOp; - } else { - break; - } - } while ( run ); - - index = indexFstOp+1; - rightPtr = parseExpression(str, index); - - NodePtr nodePtr ( new Node (getOp(str[indexFstOp])) ); - nodePtr->left() = leftPtr; - nodePtr->right() = rightPtr; - return nodePtr; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// PARSE EQUATION -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//********************************************************************************************************************** -/*! -* Parses a given Equation and constructs a binary tree as representation -* -* Goal: Equation is modeled in a binary tree format to be solved later on -* -* \param str string representation of the equation -* \param index index of the current term (is always zero here) -*/ -//********************************************************************************************************************** -EquationPtr EquationParser::parseEquation( const std::string& str, size_t& index ) -{ - // removing leading and trailing spaces of input string - std::string trimmedStr = string_trim_copy(str); - // removing spaces inside the trimmed string - trimmedStr.erase(std::remove(trimmedStr.begin(), trimmedStr.end(), ' '), trimmedStr.end()); - NodePtr leftPtr = parseExpression(trimmedStr, index); - if ( ! (trimmedStr[index] == '=') ) - THROW( "Found no equal sign in equation", str, index ); - ++index; - - NodePtr rightPtr = parseExpression(trimmedStr, index); - - NodePtr nodePtr ( new Node (OP_EQUAL) ); - nodePtr->left() = leftPtr; - nodePtr->right() = rightPtr; - - return std::make_shared<Equation>( nodePtr ); -} - -} // namespace math -} // namespace walberla - -#endif \ No newline at end of file diff --git a/src/core/math/equation_system/EquationParser.h b/src/core/math/equation_system/EquationParser.h deleted file mode 100644 index e32287be8926f996fbb60073bd43eadf8b5d2506..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/EquationParser.h +++ /dev/null @@ -1,82 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file EquationParser.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "EquationSystem.h" -#include "core/logging/Logging.h" - -#include <sstream> - -namespace walberla { -namespace math { - - class EquationParser - { - private: - EquationSystem& es_; - - public: - EquationParser( EquationSystem& es) : es_(es) { } - - private: - EquationParser& operator=( const EquationParser& ) { return *this; } - - private: - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // PARSE NUMBER - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - bool checkNumber( const std::string& str, size_t& index ) const; - NodePtr parseNumber( const std::string& str, size_t& index ) const; - - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // PARSE NT_VARIABLE - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - bool checkVariable( const std::string& str, size_t& index ) const; - NodePtr parseVariable( const std::string& str, size_t& index ) const; - - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // PARSE FUNCTION - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - enum OpFunction{ - OP_FUNC_EXP, - OP_FUNC_LN, - OP_FUNC_SQRT - }; - - bool checkFunction( const std::string& str, size_t& index ) const; - NodePtr parseFunction( const std::string& str, size_t& index ) const; - - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // PARSE EXPRESSION - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - NodePtr parseTerm ( const std::string& str, size_t& index ) const; - NodePtr parseExpression( const std::string& str, size_t& index ) const; - - public: - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // PARSE EQUATION - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - EquationPtr parseEquation( const std::string& str, size_t& index ); - }; - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/EquationSystem.cpp b/src/core/math/equation_system/EquationSystem.cpp deleted file mode 100644 index ef68ac88aff3e89d6af02890fdfb31c2ab405162..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/EquationSystem.cpp +++ /dev/null @@ -1,206 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file EquationSystem.cpp -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#include "waLBerlaDefinitions.h" -#ifdef WALBERLA_BUILD_WITH_BOOST - -#include "Equation.h" -#include "EquationSystem.h" -#include "Variable.h" -#include "core/Abort.h" -#include "core/debug/Debug.h" -#include "core/logging/Logging.h" - - -#ifdef _MSC_VER -#pragma warning ( push, 1 ) -#pragma warning ( disable: 4701 ) -#endif - -#include <boost/graph/adjacency_list_io.hpp> -#include <boost/graph/max_cardinality_matching.hpp> - -#ifdef _MSC_VER -#pragma warning ( pop ) -#endif - -namespace walberla { -namespace math { - -void EquationSystem::add(const std::string& key, const EquationPtr& eq) -{ - if ( eqMap_.find(key) != eqMap_.end() ) - WALBERLA_ABORT( "Equation already exists" ); - - eqMap_[key] = eq; - eqVertices_[key] = boost::add_vertex(eqGraph_); - - for(VarMapIt it = eq->getVarMap().begin(); it != eq->getVarMap().end(); ++it) - { - if ( varVertices_.find(it->first) == varVertices_.end() ) - { - varVertices_[it->first] = boost::add_vertex(eqGraph_); - } - boost::add_edge(eqVertices_[key], varVertices_[it->first], eqGraph_); - } -} - -void EquationSystem::clear( ) -{ - eqMap_.clear(); - varMap_.clear(); -} - -void EquationSystem::remove(const std::string& key) -{ - eqMap_.erase(key); -} - -void EquationSystem::match() -{ - std::cout << "\nEquation Nodes:\n"; - for(EqMapIt it = eqMap_.begin(); it != eqMap_.end(); ++it) - { - //std::cout << *it->second << "\n"; - WALBERLA_LOG_RESULT( *it->second ); - } - - std::cout << "\nVariable Nodes:\n"; - for(VarMapIt it = varMap_.begin(); it != varMap_.end(); ++it) - { - //std::cout << *it->second << "\n"; - WALBERLA_LOG_RESULT( *it->second ); - } - - //std::cout << "\nInput Graph:\n" << boost::write( eqGraph_ ); - WALBERLA_LOG_RESULT( "\nInput Graph:\n" << boost::write( eqGraph_ ) ); - - std::vector<EqGraph::vertex_descriptor> mate( boost::num_vertices(eqGraph_) ); - WALBERLA_ASSERT( boost::checked_edmonds_maximum_cardinality_matching(eqGraph_, &mate[0]) ); - - WALBERLA_LOG_RESULT( "Maximum matching:" ); - EqGraph::vertex_iterator vi; - EqGraph::vertex_iterator vi_end; - for(boost::tie(vi,vi_end) = vertices(eqGraph_); vi != vi_end; ++vi) - if (mate[*vi] != boost::graph_traits<EqGraph>::null_vertex() && *vi < mate[*vi]) - //std::cout << "{" << *vi << ", " << mate[*vi] << "}" << std::endl; - WALBERLA_LOG_RESULT( "{" << *vi << ", " << mate[*vi] << "}" ); -} - -bool EquationSystem::solve() -{ - bool change = true; - while(change){ - change = false; - EqMapIt it = eqMap_.begin(); - for ( ; it != eqMap_.end(); ++it ){ - EquationPtr eq = it->second; - if (eq->isComputable()){ - VarPtr varPtr = eq->compute(); - change = true; - } else if (eq->isEvaluatable()){ - //eq->evaluate(); - if (!eq->evaluate()) - //std::cout << "Equation is not evaluatable! " << *eq << " -> " << eq->root_->left()->compute() << "!=" << eq->root_->right()->compute() << std::endl; - WALBERLA_ABORT( "Equation is not evaluatable! " << *eq << " -> " << eq->root_->left()->compute() << "!=" << eq->root_->right()->compute() ); - /*} else { - //std::cout << "Equation '" << *eq << "' is neither computable nor evaluatable!" << std::endl; - WALBERLA_LOG_RESULT( "Equation '" << *eq << "' is neither computable nor evaluatable!" );*/ - } - } - } - - /*for ( VarMapIt it = varMap_.begin(); it != varMap_.end(); ++it ){ - //std::cout << *it->second << std::endl; - WALBERLA_LOG_RESULT( *it->second ); - }*/ - bool evaluatable = true; - EqMapIt it = eqMap_.begin(); - for ( ; it != eqMap_.end(); ++it ){ - EquationPtr eq = it->second; - if ( !eq->isEvaluatable() || !eq->evaluate()){ - evaluatable = false; - //std::cout << "Equation is not evaluatable! " << *eq << " -> " << eq->root_->left()->compute() << "!=" << eq->root_->right()->compute() << std::endl; - //WALBERLA_LOG_RESULT( "Equation is not evaluatable! " << *eq << " -> " << eq->root_->left()->compute() << "!=" << eq->root_->right()->compute() ); - } - } - /*if (evaluatable) - //std::cout << "All Equations are evaluatable!" << std::endl; - WALBERLA_LOG_RESULT( "All Equations are evaluatable!" );*/ - - return evaluatable; -} - -bool EquationSystem::isVarDefined( const std::string& var ) const -{ - return varMap_.find(var) != varMap_.end(); -} - -double EquationSystem::getVarValue( const std::string& var ) const -{ - return varMap_.find(var)->second->getValue(); -} - -void EquationSystem::getVarMap( std::map<std::string,double>& varMap ) const -{ - for( auto it = varMap_.begin(); it != varMap_.end(); ++it ) - { - varMap.insert( std::pair<std::string,double>(it->first,it->second->getValue()) ); - } -} - -size_t EquationSystem::getNumberOfEquations() const -{ - return eqMap_.size(); -} - -std::string EquationSystem::writeEquations() const -{ - std::stringstream ss; - ss << "Equations to solve:" << std::endl; - for( auto it = eqMap_.begin(); it != eqMap_.end(); ++it ) - { - ss << *it->second << std::endl; - } - return ss.str(); -} - -std::string EquationSystem::writeVariables() const -{ - std::stringstream ss; - ss << "Solution for each variable:" << std::endl; - for( auto it = varMap_.begin(); it != varMap_.end(); ++it ) - { - ss << *it->second << std::endl; - } - return ss.str(); -} - -std::ostream& operator<<( std::ostream& os, EquationSystem& es ) -{ - os << es.writeEquations() << es.writeVariables(); - return os; -} - -} // namespace math -} // namespace walberla - -#endif diff --git a/src/core/math/equation_system/EquationSystem.h b/src/core/math/equation_system/EquationSystem.h deleted file mode 100644 index 82d17a0f79a552aa4d2b1cf13c575484909baf1e..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/EquationSystem.h +++ /dev/null @@ -1,127 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file EquationSystem.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "FwdEquation.h" -#include "FwdVariable.h" - -#include <map> -#include <string> -#include <vector> - - -#ifdef _MSC_VER -#pragma warning ( push, 1 ) -#endif -#include <boost/graph/adjacency_list.hpp> -#ifdef _MSC_VER -#pragma warning ( pop ) -#endif - - -namespace walberla { -namespace math { - - //=================================================================================================================== - // - // CLASS DEFINITION - // - //=================================================================================================================== - - //******************************************************************************************************************* - /*!\brief Wrapper class to handle and solve an equation system, e.g. given by the equations - * in an input file - * \author Matthias Markl - * - * This class handles and solves the equations given in an input file in terms of a triangular - * equation system. In order to do so, it employs boost-graphs to organize the equations in data structures. - * Furthermore, equations and the variables that are solved for are hold in map-structures and can be - * operated on from outside. - * - * The equations need to be given in the following form (e.g.): - * - * "'c' = 'dx_L' / 'dt_L'" - */ - class EquationSystem - { - private: - // forward declaration of EquationParser class - friend class EquationParser; - - using EqGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>; - - using EqVertexMap = std::map<std::string, EqGraph::vertex_descriptor>; - using VarVertexMap = std::map<std::string, EqGraph::vertex_descriptor>; - - using EqVertexMapIt = std::map<std::string, EqGraph::vertex_descriptor>::const_iterator; - using VarVertexMapIt = std::map<std::string, EqGraph::vertex_descriptor>::const_iterator; - - using EqMap = std::map<std::string, EquationPtr>; - using EqMapIt = std::map<std::string, EquationPtr>::const_iterator; - - EqMap eqMap_; - EqGraph eqGraph_; - EqVertexMap eqVertices_; - - VarMap varMap_; - VarVertexMap varVertices_; - public: - - //**Get functions**************************************************************************** - /*! \name Get functions */ - //@{ - const EquationPtr& get (const std::string& key) { return eqMap_[key]; } - bool isVarDefined ( const std::string& var ) const; - double getVarValue ( const std::string& var ) const; - void getVarMap ( std::map<std::string,double>& varMap ) const; - size_t getNumberOfEquations () const; - //@} - //**************************************************************************************************************** - - //**Output functions************************************************************************* - /*! \name Output functions */ - //@{ - std::string writeEquations() const; - std::string writeVariables() const; - friend std::ostream& operator<<( std::ostream& os, EquationSystem& es ); - //@} - //**************************************************************************************************************** - - //**Utility functions************************************************************************ - /*! \name Utility functions */ - //@{ - void add(const std::string& key, const EquationPtr& eq); - void remove(const std::string& key); - bool solve(); - void match(); - void clear(); - //void push(); - //void pop(); - //@} - //**************************************************************************************************************** - - }; - - using EquationSystemPtr = shared_ptr<EquationSystem>; - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/FwdEquation.h b/src/core/math/equation_system/FwdEquation.h deleted file mode 100644 index 21fbb523cd241c52d51f60fb6fd3f13c0ca136cf..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/FwdEquation.h +++ /dev/null @@ -1,53 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file FwdEquation.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include <memory> - - -namespace walberla { -namespace math { - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // NODE - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - enum NodeType { - NT_OPERATOR, - NT_CONSTANT, - NT_VARIABLE - }; - - enum NodeDir { - ND_LEFT, - ND_RIGHT - }; - - class Node; - using NodePtr = std::shared_ptr<Node>; - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // EQUATION - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class Equation; - using EquationPtr = std::shared_ptr<Equation>; - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/FwdOperator.h b/src/core/math/equation_system/FwdOperator.h deleted file mode 100644 index 062f371cc3eba90cab5aacb9ccdd92e18b290132..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/FwdOperator.h +++ /dev/null @@ -1,55 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file FwdOperator.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include <map> - - -namespace walberla { -namespace math { - class OpType; - class OpNo; - class OpPlus; - class OpMinus; - class OpMult; - class OpDiv; - class OpProd; - class OpRoot; - class OpLog; - - // no valid operators - extern OpNo OP_NO; - extern OpNo OP_EQUAL; - - // operators - extern OpPlus OP_PLUS; - extern OpMinus OP_MINUS; - extern OpMult OP_MULT; - extern OpDiv OP_DIV; - extern OpProd OP_PROD; - - // functions - extern OpLog OP_LOG; - extern OpRoot OP_ROOT; - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/FwdVariable.h b/src/core/math/equation_system/FwdVariable.h deleted file mode 100644 index bb9e8edf550f014eb01aa904eee6aa1c697c9727..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/FwdVariable.h +++ /dev/null @@ -1,42 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file FwdVariable.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include <memory> -#include <map> -#include <string> - - -namespace walberla { -namespace math { - - extern double NAN_VAL; - - class Var; - - using VarPtr = std::shared_ptr<Var>; - - using VarMap = std::map<std::string, VarPtr>; - using VarMapIt = std::map<std::string, VarPtr>::const_iterator; - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/Operator.cpp b/src/core/math/equation_system/Operator.cpp deleted file mode 100644 index 86c062fc71509325f6520894e98ddd87894bdc44..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/Operator.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Operator.cpp -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#include "Operator.h" - - -namespace walberla { -namespace math { - - // no valid operators - OpNo OP_NO ( 'n', "no op", 0u ); - OpNo OP_EQUAL( '=', "equal", 0u ); - - // operators - OpPlus OP_PLUS ( '+', "plus", 10u ); - OpMinus OP_MINUS( '-', "minus", 10u ); - OpMult OP_MULT ( '*', "mult", 30u ); - OpDiv OP_DIV ( '/', "div", 30u ); - OpProd OP_PROD ( '^', "prod", 40u ); - - // functions - OpLog OP_LOG ( '$', "log", 50u ); - //OpRoot OP_ROOT ( '%', "root", 50u ); - - - int isop( const char c ) - { - return - ( OP_PLUS == c || - OP_MINUS == c || - OP_MULT == c || - OP_DIV == c || - OP_PROD == c ) ? c : 0; - } - - OpType& getOp ( const char c ) - { - if (OP_PLUS == c) return OP_PLUS; - if (OP_MINUS == c) return OP_MINUS; - if (OP_MULT == c) return OP_MULT; - if (OP_DIV == c) return OP_DIV; - if (OP_PROD == c) return OP_PROD; - WALBERLA_ABORT( "Found no operator" ); - return OP_NO; // has no effect - } - - std::ostream& operator<<( std::ostream& os, const OpType & type ){ - if( type == '$' ) - return os << type.name_; - return os << type.sign_; - } - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/Operator.h b/src/core/math/equation_system/Operator.h deleted file mode 100644 index e9a6a75e1ed50196b285212e1b5bed3ddfec4649..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/Operator.h +++ /dev/null @@ -1,129 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Operator.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "FwdOperator.h" -#include "core/Abort.h" - -#include <cmath> -#include <string> - - -namespace walberla { -namespace math { - - class OpType - { - private: - const char sign_; - const std::string name_; - const unsigned int strength_; - - public: - OpType( const char& sign, const std::string& n, const unsigned int strength ) : - sign_(sign), name_(n), strength_(strength) {} - - virtual ~OpType() = default; - - private: - OpType& operator=( const OpType& ){ return *this; } - - public: - bool operator==( const OpType & type ) const { return sign_ == type.sign_; } - bool operator==( const char & c ) const { return sign_ == c; } - - bool operator<( const OpType & type ) const { return strength_ < type.strength_; } - bool operator>( const OpType & type ) const { return strength_ > type.strength_; } - bool operator<=( const OpType & type ) const { return strength_ <= type.strength_; } - bool operator>=( const OpType & type ) const { return strength_ >= type.strength_; } - - virtual double operator() ( const double&, const double& ) = 0; - - friend std::ostream& operator<<( std::ostream& os, const OpType & type ); - - public: - const std::string & getName() const { return name_; } - }; - - class OpNo : public OpType{ - public: - OpNo( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double &, const double & ) override { WALBERLA_ABORT( "NO OPERATION" ); return 0; } - }; - - class OpPlus : public OpType{ - public: - OpPlus( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {}; - double operator() ( const double & a, const double & b ) override { return a + b; } - }; - - class OpMinus : public OpType{ - public: - OpMinus( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double & a, const double & b ) override { return a - b; } - }; - - class OpMult : public OpType{ - public: - OpMult( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double & a, const double & b ) override { return a * b; } - }; - - class OpDiv : public OpType{ - public: - OpDiv( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double & a, const double & b ) override { return a / b; } - }; - - class OpProd : public OpType{ - public: - OpProd( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double & a, const double & b ) override { return pow( a, b ); } - }; - - class OpRoot : public OpType{ - public: - OpRoot( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double & a, const double & b ) override { return pow( a, 1/b ); } - }; - - class OpLog : public OpType{ - public: - OpLog( const char& sign, const std::string& name, const unsigned int strength ) : - OpType( sign, name, strength ) {} - double operator() ( const double & a, const double & b ) override { return log10(a) / log10(b); } - }; - - - int isop( const char c ); - - OpType& getOp ( const char c ); - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/Variable.cpp b/src/core/math/equation_system/Variable.cpp deleted file mode 100644 index fcfd72f9a76751a20f57ef6a896a08e00228e85d..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/Variable.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Variable.cpp -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#include "Variable.h" - -#include <cmath> -#include <sstream> - - -namespace walberla { -namespace math { - - Var::Var ( const std::string& name ) : - name_ (name), - valid_ (false), - value_ (FP_NAN) - {} - - void Var::setValue( const double value ){ - value_ = value; - valid_ = !std::isnan( value ); - } - - bool Var::operator==( const Var& var) const { - return name_ == var.name_; - } - - std::ostream& operator<<( std::ostream& os, const Var & var ){ - return os << var.name_ << " = " << var.value_; - } - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/Variable.h b/src/core/math/equation_system/Variable.h deleted file mode 100644 index f80f19d5f9723e48d83c7e23d3c00df141d116de..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/Variable.h +++ /dev/null @@ -1,60 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Variable.h -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#pragma once - -#include "FwdVariable.h" - - -namespace walberla { -namespace math { - - class Var - { - private: - const std::string name_; - - bool valid_; - double value_; - - public: - Var ( const std::string& name ); - private: - Var& operator=( const Var& ){ return *this; } - - public: - bool operator==( const Var& var) const; - - public: - bool valid() const { return valid_; } - double getValue() const { return value_; } - const std::string& getName() const { return name_; } - - public: - void setValue( const double value ); - - public: - friend std::ostream& operator<<( std::ostream& os, const Var & var ); - }; - // end class Var - -} // namespace math -} // namespace walberla diff --git a/src/core/math/equation_system/all.h b/src/core/math/equation_system/all.h deleted file mode 100644 index 5c3cc61ed82ebd39c635b37d4f92bb51e5f19f3c..0000000000000000000000000000000000000000 --- a/src/core/math/equation_system/all.h +++ /dev/null @@ -1,31 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file all.h -//! \ingroup core -//! \author Florian Schornbaum <florian.schornbaum@fau.de> -//! \brief Collective header file for module core -// -//====================================================================================================================== - -#pragma once - -#include "Equation.h" -#ifdef WALBERLA_BUILD_WITH_BOOST -#include "EquationParser.h" -#include "EquationSystem.h" -#endif -#include "Operator.h" -#include "Variable.h" \ No newline at end of file diff --git a/src/waLBerlaDefinitions.in.h b/src/waLBerlaDefinitions.in.h index 3676dcd942011ea90850f8667f50eae94af0d468..3fddd25444efca07d819a2ce553331c7b96841b7 100644 --- a/src/waLBerlaDefinitions.in.h +++ b/src/waLBerlaDefinitions.in.h @@ -22,7 +22,6 @@ // External libraries -#cmakedefine WALBERLA_BUILD_WITH_BOOST #cmakedefine WALBERLA_BUILD_WITH_MPI #cmakedefine WALBERLA_BUILD_WITH_OPENMP #cmakedefine WALBERLA_BUILD_WITH_METIS diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 788e8f3ba206dea078a20dd9a3525a92d914be66..46b98eb48c90884feda14e4dde15341b4b5f3687 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -21,11 +21,6 @@ waLBerla_execute_test( NAME CellIntervalTest ) waLBerla_compile_test( FILES config/ConfigTest.cpp ) waLBerla_execute_test( NAME ConfigTest COMMAND $<TARGET_FILE:ConfigTest> ${CMAKE_CURRENT_SOURCE_DIR}/config/ConfigTest.dat ) -if( WALBERLA_BUILD_WITH_BOOST ) - waLBerla_compile_test( FILES config/MultiArrayIOTest.cpp ) - waLBerla_execute_test( NAME MultiArrayIOTest COMMAND $<TARGET_FILE:MultiArrayIOTest> ) -endif( WALBERLA_BUILD_WITH_BOOST ) - ######### # debug # ######### @@ -81,26 +76,10 @@ waLBerla_execute_test( NAME Matrix3Test ) waLBerla_compile_test( FILES math/GenericAABBTest.cpp DEPENDS stencil domain_decomposition ) waLBerla_execute_test( NAME GenericAABBTest ) -if( WALBERLA_BUILD_WITH_BOOST ) - waLBerla_compile_test( FILES math/PhysicalCheckTest.cpp DEPENDS stencil ) - waLBerla_execute_test( NAME PhysicalCheckTest - COMMAND $<TARGET_FILE:PhysicalCheckTest> ${CMAKE_CURRENT_SOURCE_DIR}/math/PhysicalCheckTestInput.prm - DEPENDS_ON_TARGETS PhysicalCheckTest ) -endif( WALBERLA_BUILD_WITH_BOOST ) - waLBerla_compile_test( FILES math/FastInvSqrtTest.cpp ) waLBerla_execute_test( NAME FastInvSqrtTest ) -######################## -# math/equation_system # -######################## - -if( WALBERLA_BUILD_WITH_BOOST ) - waLBerla_compile_test( FILES math/equation_system/EquationSolverTest.cpp ) - waLBerla_execute_test( NAME EquationSolverTest ) -endif( WALBERLA_BUILD_WITH_BOOST ) - ####### # mpi # ####### diff --git a/tests/core/config/MultiArrayIOTest.cpp b/tests/core/config/MultiArrayIOTest.cpp deleted file mode 100644 index 515b1071b12a12f8ea93838d44253d6a3c557e89..0000000000000000000000000000000000000000 --- a/tests/core/config/MultiArrayIOTest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file MultiArrayIOTest.h -//! \author Martin Bauer <martin.bauer@fau.de> -// -//====================================================================================================================== - - -#include "core/MultiArrayIO.h" -#include "core/debug/TestSubsystem.h" -#include "core/Environment.h" - -#include <sstream> -#include <iostream> - -using namespace walberla; - - -int main( int argc, char ** argv ) -{ - debug::enterTestMode(); - walberla::Environment walberlaEnv( argc, argv ); - - using namespace std; - - string test1 = "[[ 0.2 0.24 0.2 0.17]\n[ 0.24 0.2 0.2 0.2 ]\n\t[ 0.2 0.2 0.2 0.2 ]\n[ 0.17 0.2 0.2 0.2 ]]"; - stringstream ss1 ( test1 ); - //string betweenBrackets; - //WALBERLA_CHECK( readContentBetweenBrackets( ss1, betweenBrackets ) ); - //cout << betweenBrackets; - - boost::multi_array<real_t,2> arr1; - bool res = !( ss1 >> arr1 ).fail(); - WALBERLA_CHECK( res ); - cout << arr1 << endl; - - - string test2 = " [1 2 3,4,5,6,7 ]"; - stringstream ss2 ( test2 ); - - boost::multi_array<real_t,1> arr2; - bool res2 = !(ss2 >> arr2).fail() ; - WALBERLA_CHECK( res2 ); - cout << arr2 << endl; - - - return 0; -} \ No newline at end of file diff --git a/tests/core/math/PhysicalCheckTest.cpp b/tests/core/math/PhysicalCheckTest.cpp deleted file mode 100644 index d92517723561bff7dfe590450ad8d771c2531136..0000000000000000000000000000000000000000 --- a/tests/core/math/PhysicalCheckTest.cpp +++ /dev/null @@ -1,102 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file PhysicalCheckTest.cpp -//! \ingroup core -//! \author David Staubach <david.staubach@fau.de> -// -//====================================================================================================================== - -#include "core/Abort.h" -#include "core/DataTypes.h" -#include "core/Environment.h" -#include "core/debug/TestSubsystem.h" -#include "core/logging/Logging.h" -#include "core/math/PhysicalCheck.h" - -#include <iostream> -#include <string> -#include <vector> - - -using namespace walberla; -using namespace walberla::math; - - -int testPhysicalCheck1( shared_ptr<Config> & config ) -{ - Config::BlockHandle pcConfigBlock = config->getBlock( "Physical_Check" ); - - if( !pcConfigBlock ) - WALBERLA_ABORT( "You have to specify a \"Physical_Check\" block in the configuration file!" ); - - PhysicalCheck pc( pcConfigBlock ); - - WALBERLA_CHECK( pc.isDefined(std::string("parameter1")) ); - WALBERLA_CHECK( pc.isDefined(std::string("parameter2")) ); - WALBERLA_CHECK( pc.isDefined(std::string("var1")) ); - WALBERLA_CHECK( pc.isDefined(std::string("var2")) ); - // TODO: further checks - - // Check for functionality is within the function - pc.completeConfig( config ); - - return 0; -} - -int testPhysicalCheck2( shared_ptr<Config> & config ) -{ - Config::BlockHandle pcConfigBlock = config->getBlock( "Physical_Check" ); - - if( !pcConfigBlock ) - WALBERLA_ABORT( "You have to specify a \"Physical_Check\" block in the configuration file!" ); - - PhysicalCheck pc; - - pc.addBlock(pcConfigBlock); - - WALBERLA_CHECK( pc.isDefined(std::string("parameter1")) ); - WALBERLA_CHECK( pc.isDefined(std::string("parameter2")) ); - WALBERLA_CHECK( pc.isDefined(std::string("var1")) ); - WALBERLA_CHECK( pc.isDefined(std::string("var2")) ); - // TODO: further checks - - // Check for functionality is within the function - pc.completeConfig( config ); - - return 0; -} - -int main( int argc, char** argv ) -{ - walberla::Environment env( argc, argv ); - - debug::enterTestMode(); - - try { - shared_ptr<Config> config = env.config(); - - int value; - value = testPhysicalCheck1( config ); - - value = testPhysicalCheck2( config ); - - return value; - } - catch( std::exception & e ) - { - WALBERLA_LOG_INFO( "Unhandled exception raised: " << e.what() ); - } -} diff --git a/tests/core/math/PhysicalCheckTestInput.prm b/tests/core/math/PhysicalCheckTestInput.prm deleted file mode 100644 index d93526bcedab10fdacfd65d948aa4e6961b65b56..0000000000000000000000000000000000000000 --- a/tests/core/math/PhysicalCheckTestInput.prm +++ /dev/null @@ -1,48 +0,0 @@ -//GlobalState FZYX,SRTD3Q19LevelBased; -//SRTD3Q19LevelBased, MRTD3Q19OriginalLevelBased, MRTD3Q19ExtendedLevelBased - -Physical_Check { - - Equations { - eq0 parameter1 = 23; - eq1 parameter2 = 42; - eq2 parameter3 = -11; - - eq3 var1 = parameter1 + sqrt(parameter2); - eq4 var2 = parameter2 - ln(23); - eq5 var3 = parameter3 * exp(var2); - - eq6 dx = 2; - eq7 dt = 1; - eq8 rho = 3; - } - - Units { - parameter1 m; - parameter2 m^2/s; - parameter3 1/Akg; - } - - Constraints { - co0 var1 > 20; - co2 var3 <= -209; - co3 parameter1 >= 23; - co5 parameter2 < parameter1*2; - } -} - -Geometry { - BoundaryConditionXYZ { - velocity 'parameter1'; - pressure 'var1 * 29.9'; - - BoundaryConditionZYX { - pressureIN 'parameter3'; - pressureOUT 'var3-var2'; - } - } - - BoundaryConditionABC { - velocity 'parameter1'; - } -} diff --git a/tests/core/math/equation_system/EquationSolverTest.cpp b/tests/core/math/equation_system/EquationSolverTest.cpp deleted file mode 100644 index e711d04f8300e746ce14d922d7103c3afe3b0670..0000000000000000000000000000000000000000 --- a/tests/core/math/equation_system/EquationSolverTest.cpp +++ /dev/null @@ -1,203 +0,0 @@ -//====================================================================================================================== -// -// This file is part of waLBerla. waLBerla is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// waLBerla is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file EquationSolverTest.cpp -//! \ingroup core -//! \author Matthias Markl <matthias.markl@fau.de> -// -//====================================================================================================================== - -#include "core/DataTypes.h" -#include "core/debug/TestSubsystem.h" -#include "core/logging/Logging.h" -#include "core/mpi/Environment.h" -#include "core/math/equation_system/EquationParser.h" -#include "core/math/equation_system/EquationSystem.h" - -#include <iostream> -#include <string> -#include <vector> - - -using namespace walberla; -using namespace walberla::math; - -/* -int directInput(){ - EquationSystem es; - EquationParser ep(es); - - std::string str; - uint_t index = 0; - - std::cout << "\nWrite equations to solve without any blank!\nTo quit enter 'exit'\nTo clear all known variable enter 'clear'"<< std::endl; - - bool run = true; - do { - std::cin >> str; - index = 0; - if ( strcmp(str.c_str(),"exit") == 0 ) - return 0; - if ( strcmp(str.c_str(),"clear") == 0 ){ - std::cout << "Clear known variables and equations" << std::endl; - es.clear(); - continue; - } - try { - EquationPtr eqPtr = ep.parseEquation(str, index); - es.add(str, eqPtr); - std::cout << "Convert '" << str << "' to '" << (*eqPtr) << "'" << std::endl; - if (eqPtr->isComputable()){ - VarPtr varPtr = eqPtr->compute(); - std::cout << "Equation is computable: " << varPtr->name() << "=" << varPtr->value() << std::endl; - } else if (eqPtr->isEvaluatable()){ - std::cout << "Equation is evaluatable: " << (eqPtr->evaluate() ? "true" : "false") << std::endl; - } else { - std::cout << "Equation is neither computable nor evaluatable!" << std::endl; - } - } catch (std::runtime_error re) { - std::cerr << re.what() << std::endl; - } - } while (run); - return 0; -} - */ - - -int equationInput(){ - std::vector<std::string> eqStringList; - - //// Parameters - eqStringList.emplace_back("dt = 2e-7"); - eqStringList.emplace_back("dx = 5e-6"); - eqStringList.emplace_back("eta = 0.0001"); - eqStringList.emplace_back("omega = 1.95"); - eqStringList.emplace_back("rho = 1000"); - - //// LBM Equations - eqStringList.emplace_back("'rho_L' = 1.0"); - eqStringList.emplace_back("'dt_L' = 1.0"); - eqStringList.emplace_back("'dx_L' = 1.0"); - eqStringList.emplace_back("'c' = 'dx_L' / 'dt_L'"); - eqStringList.emplace_back("'nu' = 'eta' / 'rho'"); - eqStringList.emplace_back("'nu_L' = 'eta_L' / 'rho_L'"); - eqStringList.emplace_back("'dt' = ( 0.1 * 'dx' ) / 'maxOcurringPhysVel'"); - eqStringList.emplace_back("'cs' = ( 1.0 / ( 3.0 ^ 0.5 ) ) * 'c'"); - eqStringList.emplace_back("'omega' = 1.0 / 'tau'"); - eqStringList.emplace_back("'nu_L' = ( 'cs' ^ 2.0 ) * ( 'tau' - ( 0.5 * 'dt_L' ) )"); - /* - // Unsolvable: - // Parameters - eqStringList.push_back( "nu = 3.50E-006"); - eqStringList.push_back( "omega = 1.99"); - eqStringList.push_back( "rho = 1000"); - eqStringList.push_back( "maxOcurringPhysVel = 0.10"); - - - // LBM Equations - eqStringList.push_back( "'rho_L' = 1.0"); - eqStringList.push_back( "'dt_L' = 1.0"); - eqStringList.push_back( "'dx_L' = 1.0"); - eqStringList.push_back( "'c' = 'dx_L' / 'dt_L'"); - eqStringList.push_back( "'nu' = 'eta' / 'rho'"); - eqStringList.push_back( "'nu_L' = 'eta_L' / 'rho_L'"); - eqStringList.push_back( "'dt' = ( 0.1 * 'dx' ) / 'maxOcurringPhysVel'"); - eqStringList.push_back( "'cs' = ( 1.0 / ( 3.0 ^ 0.5 ) ) * 'c'"); - eqStringList.push_back( "'omega' = 1.0 / 'tau'"); - eqStringList.push_back( "'nu_L' = ( 'cs' ^ 2.0 ) * ( 'tau' - ( 0.5 * 'dt_L' ) )"); - eqStringList.push_back( "'nu_L' = (nu * dt) / dx^2"); - */ - - EquationSystem es; - EquationParser ep(es); - size_t index = 0; - size_t number = 0; - - for (size_t i=0; i<eqStringList.size(); ++i){ - index = 0; - es.add( std::to_string(++number), ep.parseEquation( eqStringList[i], index ) ); - } - - WALBERLA_CHECK( es.solve() ); - //es.match(); - WALBERLA_LOG_RESULT( es ); - return 0; -} - -int unitTest(double v) -{ - std::string s = std::to_string( v ); - - std::vector<std::string> eqStringList; - eqStringList.push_back( "a = " + s ); - eqStringList.push_back( "a + 3 = " + s + " + 3" ); - eqStringList.push_back( "3 + a = 3 + " + s + "" ); - eqStringList.push_back( "a - 3 = " + s + " - 3" ); - eqStringList.push_back( "3 - a = 3 - " + s + "" ); - eqStringList.push_back( "a * 3 = " + s + " * 3" ); - eqStringList.push_back( "3 * a = 3 * " + s + "" ); - eqStringList.push_back( "a / 3 = " + s + " / 3" ); - eqStringList.push_back( "3 / a = 3 / " + s + "" ); - eqStringList.push_back( "a ^ 3 = " + s + " ^ 3" ); - eqStringList.push_back( "3 ^ a = 3 ^ " + s + "" ); - eqStringList.push_back( "sqrt(a) = sqrt(" + s + ")" ); - eqStringList.push_back( "exp(a) = exp(" + s + ")" ); - eqStringList.push_back( "ln(a) = ln(" + s + ")" ); - - EquationSystem es; - EquationParser ep(es); - uint_t index = 0; - - for (uint_t i=0; i<eqStringList.size(); ++i){ - index = 0; - es.add( eqStringList[i], ep.parseEquation( eqStringList[i], index ) ); - } - WALBERLA_CHECK( es.solve() ); - - return 0; -} - -int unitTests(unsigned int count){ - srand( static_cast<unsigned int>(time(nullptr)) ); - - double values[] = {0.0, 1.0, 1e-15, 1e+15}; - unsigned int size = 4; - - int test = 0; - for (unsigned int i=0; i<size && test == 0; ++i){ - test = unitTest( values[i] ); - } - - for (unsigned int i=0; i<count && test == 0; ++i){ - double value = double(rand()) / RAND_MAX; - int exp = rand() / ( RAND_MAX / 30 ) - 14; - test = unitTest( pow( value, exp ) ); - } - - return test; -} - -int main( int argc, char** argv ) -{ - debug::enterTestMode(); - - mpi::Environment mpiEnv( argc, argv ); - - int value; - //value = unitTests(100); - value = equationInput(); - //value = directInput(); - return value; -}