From 6a4c7c3229ec07847daf9aaae9c48246f0d034c7 Mon Sep 17 00:00:00 2001 From: George Dan Miron <44091914+gdmiron@users.noreply.github.com> Date: Thu, 13 Jan 2022 12:37:00 +0100 Subject: [PATCH] Added ChemicalFun library (#31) * Moved implementation to ChemicalFun * chemicalfun to environment file * fix link to chemicalfun * fix forward declaration * fix for MSVC build * disabled build on mingw, issue with linking to chemicalfun which is compiled with MSVC * v0.3.9 Co-authored-by: svetad Co-authored-by: G. Dan Miron --- CMakeLists.txt | 2 +- Resources/fun-hubclient-config-win.json | 8 +- Resources/fun-hubclient-config.json | 8 +- ThermoFun/CMakeLists.txt | 4 + ThermoFun/Common/formuladata.cpp | 449 ------------------------ ThermoFun/Common/formuladata.h | 336 ------------------ ThermoFun/Common/formulaparser.cpp | 360 ------------------- ThermoFun/Common/formulaparser.h | 167 --------- ThermoFun/Database.cpp | 52 ++- ThermoFun/Database.h | 11 + ThermoFun/Element.cpp | 35 ++ ThermoFun/Element.h | 10 + ThermoFun/Reaction.cpp | 2 + ThermoFun/ThermoEngine.cpp | 4 +- ThermoFun/ThermoFun.pri | 8 +- azure-pipelines.yml | 54 +-- ci/pipelines/installVS.bat | 2 +- cmake/modules/ThermoFunFindDeps.cmake | 6 + environment.devenv.yml | 1 + tests/interfaceTest/interfaceTest.pro | 2 + tests/interfaceTest/src/main.cpp | 2 +- 21 files changed, 155 insertions(+), 1368 deletions(-) delete mode 100644 ThermoFun/Common/formuladata.cpp delete mode 100644 ThermoFun/Common/formuladata.h delete mode 100644 ThermoFun/Common/formulaparser.cpp delete mode 100644 ThermoFun/Common/formulaparser.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9534c36a..14e1dda3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9) # Set the name of the project -project(ThermoFun VERSION 0.3.8 LANGUAGES CXX) +project(ThermoFun VERSION 0.3.9 LANGUAGES CXX) # Set the cmake module path of the project set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") diff --git a/Resources/fun-hubclient-config-win.json b/Resources/fun-hubclient-config-win.json index 788e3134..cddf8f19 100644 --- a/Resources/fun-hubclient-config-win.json +++ b/Resources/fun-hubclient-config-win.json @@ -1,5 +1,5 @@ { - "jsonio" : { + "arangodb" : { "UseArangoDBInstance" : "ArangoDBRemote", "UseVelocypackPut" : true, "UseVelocypackGet" : true, @@ -25,6 +25,9 @@ "DBRootUser" : "", "DBRootPassword" : "" } + }, + "jsonio" : { + }, "jsonui" : { "CurrentDBConnection" : "ArangoDBRemote", @@ -32,7 +35,8 @@ "CanEdit_id" : false, "KeepExpanded" : true, "ShowComments" : true, - "ShowEnumNames" : true + "ShowEnumNames" : true, + "CanEditDocPages" : false }, "common" : { "UserHomeDirectoryPath" : "C:/", diff --git a/Resources/fun-hubclient-config.json b/Resources/fun-hubclient-config.json index be53386b..10c09733 100644 --- a/Resources/fun-hubclient-config.json +++ b/Resources/fun-hubclient-config.json @@ -1,5 +1,5 @@ { - "jsonio" : { + "arangodb" : { "UseArangoDBInstance" : "ArangoDBRemote", "UseVelocypackPut" : true, "UseVelocypackGet" : true, @@ -25,6 +25,9 @@ "DBRootUser" : "", "DBRootPassword" : "" } + }, + "jsonio" : { + }, "jsonui" : { "CurrentDBConnection" : "ArangoDBRemote", @@ -32,7 +35,8 @@ "CanEdit_id" : false, "KeepExpanded" : true, "ShowComments" : true, - "ShowEnumNames" : true + "ShowEnumNames" : true, + "CanEditDocPages" : false }, "common" : { "UserHomeDirectoryPath" : "~", diff --git a/ThermoFun/CMakeLists.txt b/ThermoFun/CMakeLists.txt index 9cfc2137..d7833ed8 100644 --- a/ThermoFun/CMakeLists.txt +++ b/ThermoFun/CMakeLists.txt @@ -28,6 +28,10 @@ add_library(ThermoFun ${HEADER_FILES} ${SOURCE_FILES}) # Add aliases for ThermoFun shared and static libraries add_library(ThermoFun::ThermoFun ALIAS ThermoFun) +if(ChemicalFun_FOUND) + target_link_libraries(ThermoFun PUBLIC ChemicalFun::ChemicalFun) +endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") #link_directories("/usr/local/lib") else() diff --git a/ThermoFun/Common/formuladata.cpp b/ThermoFun/Common/formuladata.cpp deleted file mode 100644 index c6b320ba..00000000 --- a/ThermoFun/Common/formuladata.cpp +++ /dev/null @@ -1,449 +0,0 @@ -#include -#include "formuladata.h" -#include "formulaparser.h" -#include "Element.h" -#include "Exception.h" -// JSON -#include - -using json = nlohmann::json; - -using namespace std; - -namespace ThermoFun { -using ElementsMap = std::map; -const short SHORT_EMPTY_ = -32768; - -DBElementsData ChemicalFormula::dbElements= DBElementsData(); -//vector ChemicalFormula::queryFields = -//{ -// "_id", -// "_type", -// "_label", -// "properties.symbol", -// "properties.class_" , -// "properties.isotope_mass", -// "properties.atomic_mass.values.0", -// "properties.entropy.values.0", -// "properties.heat_capacity.values.0", -// "properties.volume.values.0", -// "properties.valences.0", -// "properties.number", -// "properties.name" -//}; - -// Construct key from elements document values -ElementKey::ElementKey(const std::string& asymbol, const string &aclass_, const std::string& aisotope ): - symbol(asymbol) -{ - json j = json::parse(aclass_); - isotope = 0; - if( !aisotope.empty() ) - isotope = stoi(aisotope); - class_ = stoi(j.begin().key()); -} - -void ElementKey::classIsotopeFrom(const string& typeline) -{ - class_ = 0; // ElementClass::ELEMENT schema.enumdef->getId( "ELEMENT" ); - isotope = 0; - - if( typeline == CHARGE_CLASS ) - class_ = 4; // ElementClass::CHARGE schema.enumdef->getId( "CHARGE" ); - else - if( typeline == NOISOTOPE_CLASS || typeline == "v" ) - { - - } - else -// if( jsonio::is( isotope, typeline.c_str()) ) -// class_ = 1; // ElementClass::ISOTOPE schema.enumdef->getId( "ISOTOPE" ); -// else - isotope = 0; - //cout << typeline << " class_ " << class_ << " isotope " << isotope << endl; - -} - -string ElementKey::formulaKey() const -{ - string _key= symbol; - if( class_ != 0 ) - _key+= "|" + to_string(class_); - if( isotope != 0 ) - _key+= "|" + to_string(isotope); - - return _key; -} - -// Reads data from JsonDom (fromm real record) -void ElementKey::fromElementNode( const std::string& element ) -{ - json j = json::parse(element); - - if (j.contains("symbol")) - symbol = j["symbol"].get(); - else - funError("Undefined symbol.", "Element ", __LINE__, __FILE__ ); - if (j.contains("isotope_mass")) - isotope = j["isotope_mass"].get(); - else - isotope = 0; - if (j.contains("class_")) - class_ = stoi(j["class_"].begin().key()); - else - class_ = 0; -} - -bool operator <( const ElementKey& iEl, const ElementKey& iEr) -{ - if( iEl.symbol < iEr.symbol ) - return true; - if(iEl.symbol == iEr.symbol ) - { - if( iEl.class_ < iEr.class_ ) - return true; - else - if( iEl.class_ == iEr.class_ ) - return ( iEl.isotope < iEr.isotope ); - } - return false; -} - -bool operator >( const ElementKey& iEl, const ElementKey& iEr) -{ - if( iEl.symbol > iEr.symbol ) - return true; - if(iEl.symbol == iEr.symbol ) - { - if( iEl.class_ > iEr.class_ ) - return true; - else - if( iEl.class_ == iEr.class_ ) - return ( iEl.isotope > iEr.isotope ); - } - return false; -} - -bool operator ==( const ElementKey& iEl, const ElementKey& iEr) -{ - return (iEl.symbol == iEr.symbol) && - (iEl.class_ == iEr.class_) && - (iEl.isotope == iEr.isotope) ; -} - -bool operator !=( const ElementKey& iEl, const ElementKey& iEr) -{ - return !(iEl==iEr); -} - -//------------------------------------------------------------- - -void FormulaToken::setFormula( const string& aformula ) -{ - clear(); - formula = aformula; - formula.erase(std::remove(formula.begin(), formula.end(), '\"'), formula.end()); - ChemicalFormulaParser formparser; - list icterms = formparser.parse( formula ); - unpack( icterms ); - aZ = calculateCharge(); -} - - -// unpack list of terms to data -void FormulaToken::unpack( list& itt_ ) -{ - list::iterator itr; - itr = itt_.begin(); - while( itr != itt_.end() ) - { - ElementKey key( itr->ick, itr->ick_iso ); - - if( itr->val == SHORT_EMPTY_ ) - { auto itrdb = ChemicalFormula::getDBElements().find(key); - if( itrdb != ChemicalFormula::getDBElements().end() ) - itr->val = itrdb->second.valence; - } - datamap.push_back( FormulaValues( key, itr->stoich, itr->val )); - elements.insert(key); - if (elements_map.find(key) != elements_map.end()) - elements_map.at(key) += itr->stoich; - else - elements_map.insert(pair(key,itr->stoich)); -// coefficients.push_back(itr->stoich); - itr++; - } -} - -double FormulaToken::calculateCharge() -{ - double Zz=0.0; - auto itr = datamap.begin(); - while( itr != datamap.end() ) - { - if( itr->key.Class() != 4 /*CHARGE*/ && - itr->valence != SHORT_EMPTY_ ) - Zz += itr->stoichCoef * itr->valence; - itr++; - } - return Zz; -} - - -void FormulaToken::clear() -{ - datamap.clear(); - elements.clear(); - elements_map.clear(); - aZ = 0.; -} - - -bool FormulaToken::checkElements( const string& aformula ) -{ - string notPresent = testElements( aformula ); - return notPresent.empty(); -} - -void FormulaToken::exeptionCheckElements( const string& subreacKey, const string& aformula ) -{ - string notPresent = testElements( aformula ); - if( !notPresent.empty() ) - { - string msg = "Invalid Elements: "; - msg += notPresent; - msg += "\n in formula in record: \n"; - msg += subreacKey; - funError("Invalid symbol", msg, __LINE__, __FILE__); - } -} - -// Test all IComps in DB -string FormulaToken::testElements( const string& aformula ) -{ - string notPresent = ""; - setFormula( aformula ); - - auto itr = datamap.begin(); - while( itr != datamap.end() ) - { - if( ChemicalFormula::getDBElements().find(itr->key) == - ChemicalFormula::getDBElements().end() ) - notPresent += itr->key.Symbol() + ";"; - itr++; - } - return notPresent; -} - -void FormulaToken::calcFormulaProperites( FormulaProperites& propert ) -{ - double Sc; - int valence; - propert.formula = formula; - propert.charge = propert.atomic_mass = 0.0; - propert.elemental_entropy = propert.atoms_formula_unit = 0.0; - - auto itr = datamap.begin(); - while( itr != datamap.end() ) - { - auto itrdb = ChemicalFormula::getDBElements().find(itr->key); - if( itrdb == ChemicalFormula::getDBElements().end() ) - funError("Invalid symbol", itr->key.Symbol(), __LINE__, __FILE__); - - Sc = itr->stoichCoef; - propert.atoms_formula_unit += Sc; - propert.atomic_mass += Sc * itrdb->second.atomic_mass; - propert.elemental_entropy += Sc * itrdb->second.entropy; - - valence = itr->valence; - if( valence == SHORT_EMPTY_ ) - valence = itrdb->second.valence; - if( itr->key.Class() != 4 /*CHARGE*/ ) - propert.charge += Sc * valence; - - itr++; - } -} - - -// Get a row of stoichiometry matrix -vector FormulaToken::makeStoichiometryRowOld( const vector& sysElemens ) -{ - double ai = 0; - vector rowA; - - auto itel = sysElemens.begin(); - while( itel != sysElemens.end() ) - { - ai=0.; - const ElementKey& elkey = *itel; - if( elements.find(elkey) != elements.end() ) - { - for(unsigned int ii=0; iikey ) - { - double Zzval = itr->stoichCoef; - - if( fabs( (aZ - Zzval) ) > 1e-6 ) - { - string str = "In the formula: "; - str += formula + "\n calculated charge: "; - str += to_string(aZ) + " != " + to_string(Zzval); - //aSC[ii] = aZ; // KD 03.01.04 - temporary workaround (adsorption) - funError("Charge imbalance", str, __LINE__, __FILE__); - } - break; - } - } -} - - -//------------------------------------------ - -vector ChemicalFormula::elementsRow() -{ - vector row; - auto itr =dbElements.begin(); - - while( itr != dbElements.end() ) - row.push_back( ElementKey(itr++->first) ); - return row; -} - -map ChemicalFormula::extractElements_map( const vector& formulalist ) -{ - map elements_map; - FormulaToken formula(""); - - for(unsigned int ii=0; ii ChemicalFormula::extractElements( const vector& formulalist ) -{ - set elements; - FormulaToken formula(""); - - for(unsigned int ii=0; ii ChemicalFormula::calcThermo( const vector& formulalist ) -{ - vector thermo; - FormulaToken formula(""); - FormulaProperites val; - - for(unsigned int ii=0; ii> ChemicalFormula::calcStoichiometryMatrixOld( const vector& formulalist ) -{ - vector> matrA; - vector sysElemens = elementsRow(); - FormulaToken formula(""); - - for(unsigned int ii=0; ii Element -{ - Element e; - auto itrdb = ChemicalFormula::getDBElements().find(elementKey); - if (itrdb == ChemicalFormula::getDBElements().end()) - funError("Invalid symbol", elementKey.Symbol(), __LINE__, __FILE__); - - e.setClass(elementKey.Class()); - e.setIsotopeMass(elementKey.Isotope()); - e.setSymbol(elementKey.Symbol()); - e.setName(itrdb->second.name); - e.setMolarMass(itrdb->second.atomic_mass); - e.setEntropy(itrdb->second.entropy); - e.setHeatCapacity(itrdb->second.heat_capacity); - e.setVolume(itrdb->second.volume); - e.setValence(itrdb->second.valence); - e.setNumber(itrdb->second.number); - - return e; -} - - -} diff --git a/ThermoFun/Common/formuladata.h b/ThermoFun/Common/formuladata.h deleted file mode 100644 index 5cb337cf..00000000 --- a/ThermoFun/Common/formuladata.h +++ /dev/null @@ -1,336 +0,0 @@ -#ifndef FORMULADATA_H -#define FORMULADATA_H - -#include -#include -#include -#include "formulaparser.h" - -namespace ThermoFun { - -class Element; - -const std::map elements_valences = { - {"Ac", 3}, - {"Ag", 1}, - {"Al", 3}, - {"Ar", 0}, - {"Am", 3}, - {"As", 5}, - {"Au", 1}, - {"B", 3}, - {"Ba", 2}, - {"Be", 2}, - {"Bi", 3}, - {"Br", -1}, - {"C", 4}, - {"Ca", 2}, - {"Cd", 2}, - {"Ce", 3}, - {"Cf", 3}, - {"Cit", -3}, - {"Cl", -1}, - {"Co", 2}, - {"Cr", 3}, - {"Cm", 3}, - {"Cs", 1}, - {"Cu", 2}, - {"Dy", 3}, - {"Edta", -4}, - {"Er", 3}, - {"Eu", 3}, - {"F", -1}, - {"Fr", 1}, - {"Fe", 2}, - {"Ga", 3}, - {"Gd", 3}, - {"Ge", 4}, - {"H", 1}, - {"He", 0}, - {"Hf", 4}, - {"Hg", 2}, - {"Ho", 3}, - {"I", -1}, - {"In", 3}, - {"Isa", -4}, - {"Ir", 4}, - {"K", 1}, - {"Kr", 0}, - {"La", 3}, - {"Li", 1}, - {"Lu", 3}, - {"Mg", 2}, - {"Mn", 2}, - {"Mo", 6}, - {"N", 5}, - {"N_atm", 0}, - {"Na", 1}, - {"Nb", 5}, - {"Nd", 3}, - {"Ne", 0}, - {"Ni", 2}, - {"Np", 6}, - {"O", -2}, - {"Os", 4}, - {"Ox", -2}, - {"P", 5}, - {"Pa", 5}, - {"Pb", 2}, - {"Pd", 2}, - {"Po", 4}, - {"Pu", 6}, - {"Pr", 3}, - {"Pm", 3}, - {"Pt", 2}, - {"Ra", 2}, - {"Rb", 1}, - {"Re", 4}, - {"Rh", 2}, - {"Rn", 0}, - {"Ru", 2}, - {"S", 6}, - {"Sb", 3}, - {"Sc", 3}, - {"Se", 4}, - {"Si", 4}, - {"Sm", 3}, - {"Sn", 2}, - {"Sr", 2}, - {"Ta", 5}, - {"Tb", 3}, - {"Tc", 7}, - {"Te", 6}, - {"Th", 4}, - {"Ti", 4}, - {"Tl", 1}, - {"Tm", 3}, - {"U", 6}, - {"V", 5}, - {"W", 6}, - {"Xe", 0}, - {"Y", 3}, - {"Yb", 3}, - {"Zn", 2}, - {"Zr", 4}, - {"Zz", 0} -}; - - -/// Key fields of Element vertex -class ElementKey -{ - - std::string symbol; - int class_; - int isotope; - - void classIsotopeFrom(const std::string& line ); - -public: - -// static int index_from_map(std::string map); - - /// Construct key from elements JSON document string - ElementKey( const std::string& element ) - { - fromElementNode(element); - } - - /// Construct key from elements document fields values - ElementKey( const std::string& asymbol, const std::string& aclass_, const std::string& aisotope ); - - /// Constructor - ElementKey( const std::string& asymbol, int aclass /*ELEMENT*/, int aisotope ): - symbol(asymbol), class_(aclass), isotope(aisotope) - { } - - /// Construct key from formula parser - ElementKey( const std::string& asymbol, const std::string& typeline ): - symbol(asymbol) - { classIsotopeFrom(typeline); } - - - const std::string& Symbol() const - { - return symbol; - } - - int Class() const - { - return class_; - } - - int Isotope() const - { - return isotope; - } - - /// Generate subset of formula - std::string formulaKey() const; - - /// ElementKey from element record - void fromElementNode( const std::string& element ); - - friend bool operator <( const ElementKey&, const ElementKey& ); - friend bool operator >( const ElementKey&, const ElementKey& ); - friend bool operator==( const ElementKey&, const ElementKey& ); - friend bool operator!=( const ElementKey&, const ElementKey& ); - -}; - -auto elementKeyToElement(ElementKey elementKey) -> Element; - -/// Elements values, loaded from Database -struct ElementValues -{ - std::string recid; // Record id - double atomic_mass; // "Atomic (molar) mass, g/atom (g/mole)" - double entropy; // "Atomic entropy S0 at standard state, J/mole/K" - double heat_capacity; // "Atomic heat capacity Cp0 at standard state, J/mole/K" - double volume; // "Atomic volume V0 at standard state, cm3/mole" - int valence; // "Default valence number (charge) in compounds" - int number; // "Index in Periodical (Mendeleev's) table" - std::string name; - // ... -}; - -/// Loading from Database a map of element symbol, -/// valence, entropy and other -using DBElementsData = std::map; - -/// Values extracted from chemical formulae -struct FormulaValues -{ - ElementKey key; - int valence; - double stoichCoef; - - FormulaValues( const ElementKey& akey, double astoichCoef, int avalence ): - key(akey), valence(avalence), stoichCoef(astoichCoef) - { } -}; - -/// Values calculated from formula -/// vectors of molar masses, entropies and charges of substances. -struct FormulaProperites -{ - std::string formula; - double charge; - double atomic_mass; - double elemental_entropy; - double atoms_formula_unit; -}; - -/// Internal parsed data -using FormulaElementsData = std::vector; - -/// Description of disassembled formula token -class FormulaToken -{ - std::string formula; - FormulaElementsData datamap; ///< List of tokens - std::map elements_map; - std::set elements; ///< Set of existed elements -// std::map mapElementsCoeff; ///< Map of elements symbols and coefficients - double aZ; ///< Calculated charge in Mol - -protected: - - void clear(); - void unpack( std::list& itt_ ); - -public: - - FormulaToken( const std::string& aformula ):aZ(0) - { - setFormula(aformula); - } - - ~FormulaToken(){} - - //--- Selectors - - void setFormula( const std::string& aformula ); - const std::string& getFormula() const - { - return formula; - } - - double calculateCharge(); - double charge() const - { - return aZ; - } - - //--- Value manipulation - - /// Return true if all elements from formula present into system - bool checkElements( const std::string& aformula ); - /// Throw exeption if in formula have element not present into system - void exeptionCheckElements( const std::string& subreacKey, const std::string& aformula ); - /// Build list of elements not present into system - std::string testElements( const std::string& aformula ); - - /// Calculate charge, molar mass, elemental entropy, atoms per formula unit - /// from chemical formulae - void calcFormulaProperites( FormulaProperites& propert ); - - /// Get a row of stoichiometry matrix from the unpacked formula, - /// sysElemens - list of element keys - std::vector makeStoichiometryRowOld(const std::vector& sysElemens ); -// Eigen::VectorXd makeStoichiometryRow(const vector& sysElemens ); - - /// Throw exeption if charge imbalance - void exeptionCargeImbalance(); - - /// Get of existed elements - const std::map& getElements_map() const - { return elements_map; } - const std::set& getElements() const - { return elements; } - -// const std::vector& getCoefficients() const -// { return coefficients; } - -}; - -class ChemicalFormula -{ - - /// Loading from database elements - static DBElementsData dbElements; - static std::vector queryFields; - static void addOneElement(Element element); - - public: - - static ElementValues undefinedProperites; - - static const DBElementsData& getDBElements() - { - return dbElements; - } - - static void setDBElements(std::map elements ); - static std::vector elementsRow(); - static std::map extractElements_map( const std::vector& formulalist ); - static std::set extractElements( const std::vector& formulalist ); - static FormulaProperites calcThermo( const std::string formula_ ); - static std::vector calcThermo( const std::vector& formulalist ); - static std::vector> calcStoichiometryMatrixOld( const std::vector& formulalist ); -// static Eigen::MatrixXd calcStoichiometryMatrix( const vector& formulalist ); - - static const ElementValues& elementProperites( const ElementKey& elementKey ) - { - auto itr = dbElements.find(elementKey); - if( itr == dbElements.end() ) - return undefinedProperites; - else - return itr->second; - } - -}; - -} - -#endif // FORMULADATA_H diff --git a/ThermoFun/Common/formulaparser.cpp b/ThermoFun/Common/formulaparser.cpp deleted file mode 100644 index d2207044..00000000 --- a/ThermoFun/Common/formulaparser.cpp +++ /dev/null @@ -1,360 +0,0 @@ -#include "formulaparser.h" -#include "Exception.h" -namespace ThermoFun { - -const int MAXICNAME = 10; -const char* NOISOTOPE_CLASS ="n"; -const char* CHARGE_CLASS ="z"; -const char* CHARGE_NAME ="Zz"; -const short SHORT_EMPTY_ = -32768; - - -void BaseParser::xblanc( std::string& str ) -{ - if(str.empty()) - return; - size_t ti = str.find_first_not_of(" \n\t\r"); - if( ti == std::string::npos ) - str = ""; - else - str = str.substr(ti); -} - - -// ::= -void BaseParser::getReal( double& valReal, std::string& parsedstr ) -{ - xblanc( parsedstr ); - if( parsedstr.empty() ) - return; - - if( isdigit( parsedstr[0] ) || parsedstr[0]=='.' || parsedstr[0]=='e' ) - { - std::string::size_type sz; - valReal = stod(parsedstr,&sz); - parsedstr = parsedstr.substr(sz); - } -// std::cout << parsedstr << endl; -} - -// -------------------------------------------------------------- - -ChemicalFormulaParser::~ChemicalFormulaParser() -{} - -//add component to sorted list -void ChemicalFormulaParser::icadd( std::list& itt_, ICTERM& it ) -{ - int iRet; - std::list::iterator itr; - itr = itt_.begin(); - - // test for setting element before - while( itr != itt_.end() ) - { - iRet = ictcomp( itr, it.ick, it.val ); - if( iRet == 0 )// ic find - { - itr->stoich += it.stoich; - return; - } - if( iRet > 0 ) - break; - itr++; - } - itt_.insert( itr, ICTERM( it ) ); -} - -void ChemicalFormulaParser::icadd( std::list& itt_, const char *icn, - const char *iso, int val, double csto ) -{ - ICTERM term( icn, iso, val, csto ); - icadd( itt_, term ); -} - -int ChemicalFormulaParser::ictcomp( std::list::iterator& itr, std::string& ick, int val ) -{ - if( itr->ick < ick ) return(-1); - if( itr->ick > ick ) return(1); - if( itr->val < val ) return(-1); - if( itr->val > val ) return(1); - return(0); -} - -//get ::= | - std::list ChemicalFormulaParser::parse( const std::string& aformula ) -{ - formula = aformula; - charge = ""; - std::list newtt; - - scanCharge(); - - // cout << formula.c_str() << charge.c_str() << endl; - std::string term = formula; - scanFterm( newtt, term, '\0'); - - // added charge item - if( !charge.empty() ) - addCharge( newtt ); - - // TEST OUTPUT - //cout << "Formula " << form_str << " ZZ " << charge_str << endl; - // for( std::size_t ii=0; ii& tt ) - { - double cha = 1.0; - int sign = 1; - double aZ = 0.0; - std::string chan = charge; - //char *chan = (char *)charge_str.c_str(); - - switch( chan[0] ) - { - case CHARGE_NUL: break; - case CHARGE_MINUS: sign = -1; - case CHARGE_PLUS: - chan = chan.substr(1); - getReal( cha, chan ); - aZ = cha * sign; - break; - default: break; - } - icadd( tt, CHARGE_NAME, CHARGE_CLASS, 1, aZ ); - } - - //get ::= | - // ::= | < elem_st_coef> - void ChemicalFormulaParser::scanFterm( std::list& itt_, std::string& startPos, char endSimb ) - { - //char *cur_ = startPos; - double st_coef; - std::list elt_; - std::list::iterator ite; - - while( startPos[0] != endSimb && !startPos.empty()) // list of < elem_st_coef> - { - // get element - elt_.clear(); - - scanElem( elt_, startPos ); - - if( !startPos.empty() ) - { - // get elem_st_coef - st_coef = 1.; - getReal( st_coef, startPos ); - ite = elt_.begin(); - while( ite != elt_.end() ) - { ite->stoich *= st_coef; - ite++; - } - } - - // added elements list to top level elements - ite = elt_.begin(); - while( ite != elt_.end() ) - { - icadd( itt_, *ite ); - ite++; - } - xblanc( startPos ); - if( startPos.empty() ) - return; - } - } - - //get ::= () | [] | - // | - // | - // | - void ChemicalFormulaParser::scanElem( std::list& itt_, std::string& startPos ) - { - xblanc( startPos ); - if( startPos.empty() ) - return; - - switch( startPos[0] ) - { - - case LBRACKET1: startPos = startPos.substr(1); - scanFterm( itt_, startPos, RBRACKET1 ); - funErrorIf(startPos[0]!=RBRACKET1, "Formula", "Must be )", __LINE__, __FILE__ ); - startPos = startPos.substr(1); - break; - case LBRACKET2: startPos = startPos.substr(1); - scanFterm( itt_, startPos, RBRACKET2 ); - funErrorIf(startPos[0]!=RBRACKET2, "Formula", "Must be ]", __LINE__, __FILE__ ); - startPos = startPos.substr(1); - break; - case LBRACKET3: startPos = startPos.substr(1); - scanFterm( itt_, startPos, RBRACKET3 ); - funErrorIf(startPos[0]!=RBRACKET3, "Formula", "Must be }", __LINE__, __FILE__ ); - startPos = startPos.substr(1); - break; - case PSUR_L_PLUS: startPos = startPos.substr(1); - break; - case 'V': if( startPos[1] == 'a' ) // Va - ignore vacancy - { startPos = startPos.substr(2); - break; - } // else goto default - other - default: // - { - std::string isotop = std::string(NOISOTOPE_CLASS); - std::string icName = ""; - int val = SHORT_EMPTY_; - - scanIsotope( isotop, startPos); - scanICsymb( icName, startPos); - scanValence( val, startPos); - icadd( itt_, icName.c_str(), isotop.c_str(), val, 1. ); - break; - } - } - } - - - // get ::= |-| \ |+| \ || - // ::= - void ChemicalFormulaParser::scanValence( int& val, std::string& cur) - { - xblanc( cur ); - if( cur.empty() ) - return; - - if( cur[0] != B_VALENT ) // next token no valence - return; - - cur = cur.substr(1); - if(cur.empty()) - funError("Valence", "Term valence scan error", __LINE__, __FILE__ ); - - size_t ti = cur.find_first_of(B_VALENT); - if( ti >= 3 || ti==std::string::npos ) - funError("Valence", "Term valence scan error", __LINE__, __FILE__ ); - - if( !sscanf( cur.c_str(), " %d", &val )) - funError("Valence","Integer number scan error", __LINE__, __FILE__ ); - cur = cur.substr(ti+1); - } - - // /3/H2/18/O isotopic form of water. - // get ::= // - void ChemicalFormulaParser::scanIsotope( std::string& isotop, std::string& cur) - { - xblanc( cur ); - if( cur.empty() ) - return; - - if( cur[0] != B_ISOTOPE ) // next token no isotop - return; - - cur = cur.substr(1); - if(cur.empty()) - funError("Isotope","Term isotope scan error", __LINE__, __FILE__ ); - - size_t ti = cur.find_first_of(B_ISOTOPE); - if( ti >= MAXICNAME || ti==std::string::npos ) - funError("Isotope","Term isotope scan error", __LINE__, __FILE__ ); - - isotop = std::string( cur, 0, ti ); // test please - cur = cur.substr(ti+1); - } - - // ::= \ \ _ - void ChemicalFormulaParser::scanICsymb( std::string& icName, std::string& cur) - { - std::size_t i=1; - - xblanc( cur ); - if( cur.empty() ) - return; - - if( !iscapl( cur[0] )) - funError("Fromula Parser"," A symbol of element expected here!", __LINE__, __FILE__ ); - - for( i=1; i<=MAXICNAME+2; i++ ) - if( !islowl( cur[i])) - break; - funErrorIf(i>=MAXICNAME, "Fromula Parser","IC Symbol scan error", __LINE__, __FILE__ ); - - icName = std::string( cur, 0, i ); // strncpy( ic, aFa.cur, len ); - cur = cur.substr(i); - } - - //------------------------------------------------------------------ - - MoityParser::~MoityParser() - {} - - // ::= : | : - // ::= | - // ::= {} | {} | Va - int MoityParser::parse( const std::string& aformula, std::vector& moit_ ) - { - formula = aformula; - std::string cur_ = formula; - size_t endmoi; - std::string moiName; - double nj; // moiety-site occupancy. - moit_.clear(); - - nSites = 0; - while( !cur_.empty() ) // list of {}< elem_st_coef> - { - switch( cur_[0]) - { case PSUR_L_PLUS: nSites++; - cur_ = cur_.substr(1); - continue; - case LBRACKET3: { - cur_ = cur_.substr(1); - if( cur_.empty() ) - funError("scanMoiety","Must be }", __LINE__, __FILE__ ); - endmoi = cur_.find_first_of( RBRACKET3 ); - if( endmoi == std::string::npos ) - funError("scanMoiety","Must be }", __LINE__, __FILE__ ); - moiName = std::string( cur_, 0, endmoi ); - // moiName = std::string( cur_, 0, endmoi-1 ); - cur_ = cur_.substr(endmoi+1); - nj = 1.; - getReal( nj, cur_ ); - moit_.push_back( MOITERM(moiName.c_str(), nSites, nj )); - break; - } - case 'V': if( cur_[1] == 'a' ) // Va vacancy - { - cur_ = cur_.substr(2); //Va - nj = 1.; - getReal( nj, cur_ ); - moit_.push_back( MOITERM("Va", nSites, nj )); - break; - } - // else other symbol - default: cur_ = cur_.substr(1); - break; - } - } - return nSites; - } - -} diff --git a/ThermoFun/Common/formulaparser.h b/ThermoFun/Common/formulaparser.h deleted file mode 100644 index e1f7833b..00000000 --- a/ThermoFun/Common/formulaparser.h +++ /dev/null @@ -1,167 +0,0 @@ -//------------------------------------------------------------------- -// $Id: formula-parser.h 1373 2009-07-22 12:25:22Z gems $ -// -// Declaration of TFormula - gems chemical formulas parser -// -// Rewritten from C to C++ by S.Dmytriyeva -// Copyright (C) 1995-2016 D.Kulik, S.Dmytriyeva -// -// This file is part of a GEM-Selektor library for thermodynamic -// modelling by Gibbs energy minimization -// -// This file may be distributed under the terms of GEMS4 Development -// Quality Assurance Licence (GEMS4.QAL) -// -// See http://gems.web.psi.ch/ for more information -// E-mail: gems2.support@psi.ch -//------------------------------------------------------------------- -// -#ifndef FORMULAPARSER_H -#define FORMULAPARSER_H - -#include -#include -#include - -namespace ThermoFun { - -extern const char* NOISOTOPE_CLASS; -extern const char* CHARGE_CLASS; -extern const char* CHARGE_NAME; - - -class BaseParser // stack for analyzing formula -{ - -protected: - - enum BRACKETS - { - LBRACKET1 ='(', RBRACKET1 =')', - LBRACKET2 ='[', RBRACKET2 =']', - LBRACKET3 ='{', RBRACKET3 ='}', - B_ISOTOPE = '/', B_VALENT ='|', - PSUR_L_PLUS =':' - }; - - /// Is capital letter - inline bool iscapl( char ch ) - { - return( (ch>='A' && ch<='Z') || ch=='$' ); - } - /// Is lowercase letter - inline bool islowl( char ch ) - { - return( (ch>='a' && ch<='z') || ch == '_' ); - } - - /// Skip escape sequences (" \n\t\r") - virtual void xblanc( std::string& str ); - - /// Read next real from string - virtual void getReal( double& real, std::string& cur); - -public: - - BaseParser(){} - virtual ~BaseParser(){} - -}; - -/// Description of parsed element -struct ICTERM -{ - std::string ick; - std::string ick_iso; - int val; // valence IC - double stoich; // stoich. coef. - - ICTERM( const char* aIck, const char* aIso, int aVal, double aStoc ): - ick(aIck), ick_iso(aIso), val(aVal), stoich(aStoc) - {} - ICTERM( const ICTERM& data ): - val(data.val), stoich(data.stoich) - { - ick = data.ick; - ick_iso = data.ick_iso; - } -}; - -/// Parser for Chemical Formula -class ChemicalFormulaParser : public BaseParser -{ - std::string formula; - std::string charge; - - const char* CHARGE_TOK ="+-@"; - - enum CHARGE_FIELD - { - CHARGE_NUL ='@', - CHARGE_PLUS ='+', - CHARGE_MINUS ='-' - }; - -protected: - - void icadd( std::list& itt_, const char *icn, - const char *iso, int val, double csto ); - void icadd( std::list& itt_, ICTERM& it ); - int ictcomp( std::list::iterator& it, std::string& ick, int val ); - void addCharge(std::list& tt); - void scanCharge(); - void scanFterm( std::list& itt_, std::string& startPos, char endSimb ); - void scanElem( std::list& itt_, std::string& cur ); - void scanValence( int& val, std::string& cur); - void scanIsotope( std::string& isotop, std::string& cur); - void scanICsymb( std::string& icName, std::string& cur); - -public: - - ChemicalFormulaParser(){} - ~ChemicalFormulaParser(); - - std::list parse( const std::string& formula ); - -}; - - -/// Description of Moiety element -struct MOITERM -{ - std::string name; - int site; // sublattice site - double nj; // moiety-site occupancy. - - MOITERM( const char* aName, int aSite, double aNj ): - site(aSite), nj(aNj) - { - name = "{" + std::string(aName) + "}" + std::to_string(site); - } - - MOITERM( const MOITERM& data ): - site(data.site), nj(data.nj) - { - name = data.name; - } -}; - - -/// Parser for Moity -class MoityParser : public BaseParser -{ - std::string formula; - int nSites; // number of sites in formula - -public: - - MoityParser(){} - ~MoityParser(); - - int parse( const std::string& aformula, std::vector& moit_ ); - -}; - -} - -#endif // FORMULAPARSER_H diff --git a/ThermoFun/Database.cpp b/ThermoFun/Database.cpp index 4d47c50f..cb62c50c 100644 --- a/ThermoFun/Database.cpp +++ b/ThermoFun/Database.cpp @@ -1,8 +1,8 @@ -#include "Database.h" +#include "Database.h" // ThermoFun includes +#include "ChemicalFun/FormulaParser/ChemicalData.h" #include "Common/Exception.h" -#include "Common/formuladata.h" #include "Common/ParseJsonToData.h" #include "Substance.h" #include "Reaction.h" @@ -35,6 +35,8 @@ struct Database::Impl /// The map of all elements in the database ElementsMap elements_map; + /// Downloaded elements data for formula parser + ChemicalFun::DBElements all_elements; //char type_ = jsonio::FileTypes::Undef_; Impl() @@ -46,14 +48,14 @@ struct Database::Impl //type_ = file.Type(); fromFile( filename ); if (elements_map.size()>0) - ChemicalFormula::setDBElements( elements_map ); + setDBElements( elements_map ); } Impl(vector jsons, std::string _label) { fromJSONs(jsons, _label); if (elements_map.size()>0) - ChemicalFormula::setDBElements( elements_map ); + setDBElements( elements_map ); } template @@ -66,6 +68,25 @@ struct Database::Impl return collection; } + auto setDBElements(ElementsMap elements ) -> void + { + std::cout << "Database::setDBElements() elements " << elements_map.size() << std::endl; + ChemicalFun::ElementValues eldata; + for (auto& e : elements) + { + auto elkey = e.second.toElementKey(eldata); + all_elements.addElement(elkey, eldata); + } + } + + auto elementKeyToElement(ChemicalFun::ElementKey elementKey) -> Element + { + auto itrdb = all_elements.elements().find(elementKey); + if (itrdb == all_elements.elements().end()) + funError("Invalid symbol", elementKey.Symbol(), __LINE__, __FILE__); + return Element(elementKey, itrdb->second); + } + auto addElement(const Element& element) -> void { elements_map.insert({element.symbol(), element}); @@ -346,7 +367,7 @@ auto Database::appendData(std::string filename) -> void auto elements_number = pimpl->mapElements().size(); pimpl->fromFile(filename); if (elements_number != pimpl->mapElements().size()) - ChemicalFormula::setDBElements(pimpl->mapElements()); + pimpl->setDBElements(pimpl->mapElements()); } auto Database::appendData(vector jsonRecords, std::string _label = "unknown label") -> void @@ -354,7 +375,7 @@ auto Database::appendData(vector jsonRecords, std::string _label = "unkn auto elements_number = pimpl->mapElements().size(); pimpl->fromJSONs(jsonRecords, _label); if (elements_number != pimpl->mapElements().size()) - ChemicalFormula::setDBElements(pimpl->mapElements()); + pimpl->setDBElements(pimpl->mapElements()); } auto Database::addElement(const Element& element) -> void @@ -510,24 +531,25 @@ auto Database::containsReaction(std::string symbol) const -> bool auto Database::parseSubstanceFormula(std::string formula_) const -> std::map { - std::set elements; std::map map; - FormulaToken formula(""); - - formula.setFormula(formula_); + ChemicalFun::FormulaToken formula(formula_); + // ??? Do we need props, do not save + auto props = formula.properties(pimpl->all_elements.elements()); - FormulaProperites props; - formula.calcFormulaProperites(props); - - for (auto element : formula.getElements_map()) + for (const auto& element : formula.getStoichCoefficients()) { - Element e = elementKeyToElement(element.first); + Element e = pimpl->elementKeyToElement(element.first); map[e] = element.second; } return map; } +auto Database::elementalEntropyFormula(std::string formula) const -> double +{ + ChemicalFun::FormulaProperties prop = pimpl->all_elements.formulasProperties(formula); + return prop.elemental_entropy; +} } // namespace ThermoFun diff --git a/ThermoFun/Database.h b/ThermoFun/Database.h index 1b9e9cd9..2f7034b8 100644 --- a/ThermoFun/Database.h +++ b/ThermoFun/Database.h @@ -7,6 +7,12 @@ #include #include +namespace ChemicalFun +{ +class ElementKey; +struct ElementValues; +} + namespace ThermoFun { // Forward declarations @@ -177,6 +183,11 @@ class Database /// @return map of Elements and coefficients auto parseSubstanceFormula(std::string formula) const -> std::map; + /// Pareses a given substance formula present in the database + /// @param formula + /// @return elemental entropy + auto elementalEntropyFormula(std::string formula) const -> double; + private: struct Impl; diff --git a/ThermoFun/Element.cpp b/ThermoFun/Element.cpp index c6a53936..a6bbb61a 100644 --- a/ThermoFun/Element.cpp +++ b/ThermoFun/Element.cpp @@ -1,4 +1,5 @@ #include "Element.h" +#include "ChemicalFun/FormulaParser/ChemicalData.h" #include "Common/ParseJsonToData.h" namespace ThermoFun { @@ -55,6 +56,22 @@ Element::Element(const Element& other) : pimpl(new Impl(*other.pimpl)) {} +Element::Element(const ChemicalFun::ElementKey &elKey, + const ChemicalFun::ElementValues &elValues) +: pimpl(new Impl()) +{ + setClass(elKey.Class()); + setIsotopeMass(elKey.Isotope()); + setSymbol(elKey.Symbol()); + setName(elValues.name); + setMolarMass(elValues.atomic_mass); + setEntropy(elValues.entropy); + setHeatCapacity(elValues.heat_capacity); + setVolume(elValues.volume); + setValence(elValues.valence); + setNumber(elValues.number); +} + Element::~Element() {} @@ -174,6 +191,24 @@ auto Element::jsonString() const -> std::string return pimpl->jString; } +ChemicalFun::ElementKey Element::toElementKey(ChemicalFun::ElementValues &eldata) +{ + // eldata.recid =; + eldata.atomic_mass = molarMass(); + eldata.entropy = entropy(); + eldata.heat_capacity = heatCapacity(); + eldata.volume = volume(); + if(valence()==777) + { + setValence(ChemicalFun::DBElements::defaultValence(symbol())); + } + eldata.valence = valence(); + eldata.number = number(); + eldata.name = symbol(); // was e.name(); + + return ChemicalFun::ElementKey(symbol(), class_(), isotopeMass() ); +} + auto operator<(const Element& lhs, const Element& rhs) -> bool { if (lhs.symbol() < rhs.symbol()) diff --git a/ThermoFun/Element.h b/ThermoFun/Element.h index 0d602f6e..521fc7ed 100644 --- a/ThermoFun/Element.h +++ b/ThermoFun/Element.h @@ -5,6 +5,12 @@ #include #include +namespace ChemicalFun +{ +class ElementKey; +struct ElementValues; +} + namespace ThermoFun { /// A type used to define a chemical element and its attributes @@ -20,6 +26,8 @@ class Element /// Construct a copy of an Element instance Element(const Element& other); + /// Construct from internal elements database + Element(const ChemicalFun::ElementKey& elKey, const ChemicalFun::ElementValues& values ); /// Assign an Element instance to this instance auto operator=(Element other) -> Element&; @@ -98,6 +106,8 @@ class Element */ auto jsonString() const -> std::string; + auto toElementKey(ChemicalFun::ElementValues& eldata) -> ChemicalFun::ElementKey; + private: struct Impl; diff --git a/ThermoFun/Reaction.cpp b/ThermoFun/Reaction.cpp index 9d126391..e12f0343 100644 --- a/ThermoFun/Reaction.cpp +++ b/ThermoFun/Reaction.cpp @@ -475,6 +475,8 @@ auto Reaction::calc_logK_fT_coefficients() -> vd auto Hr = ref_prop.reaction_enthalpy; auto Cpr = ref_prop.reaction_heat_capacity_cp; + K_fT_Coeff[0] = ref_prop.log_equilibrium_constant.val; + switch( method_T ) { // calculation 2- and 3-term param approximation case MethodCorrT_Thrift::type::CTM_DKR: // 3-term extrap. from Franck-Marshall density model diff --git a/ThermoFun/ThermoEngine.cpp b/ThermoFun/ThermoEngine.cpp index ab21249c..9300ce7d 100644 --- a/ThermoFun/ThermoEngine.cpp +++ b/ThermoFun/ThermoEngine.cpp @@ -1,6 +1,5 @@ // ThermoFun includes #include "Common/Exception.h" -#include "Common/formuladata.h" #include "ThermoEngine.h" #include "Database.h" #include "Reaction.h" @@ -137,8 +136,7 @@ struct ThermoEngine::Impl auto toBermanBrown(ThermoPropertiesSubstance &tps, const Substance &subst) -> void { const auto Tr = subst.referenceT(); - FormulaProperites prop = ThermoFun::ChemicalFormula::calcThermo(subst.formula()); - const auto entropyElements = prop.elemental_entropy; + const auto entropyElements = database.elementalEntropyFormula(subst.formula()); tps.gibbs_energy -= (Tr * entropyElements); } diff --git a/ThermoFun/ThermoFun.pri b/ThermoFun/ThermoFun.pri index 868ec82e..aee34565 100644 --- a/ThermoFun/ThermoFun.pri +++ b/ThermoFun/ThermoFun.pri @@ -3,8 +3,8 @@ $$PWD/Common/ThermoScalar.hpp \ $$PWD/Common/ScalarTypes.hpp \ $$PWD/Common/Units.hpp \ - $$PWD/Common/formuladata.h \ - $$PWD/Common/formulaparser.h \ +# $$PWD/Common/formuladata.h \ +# $$PWD/Common/formulaparser.h \ # ThermoFun $$PWD/Substances/Solute/SoluteAnderson91.h \ $$PWD/Substances/Solute/SoluteHollandPowell98.h \ @@ -78,8 +78,8 @@ SOURCES += $$PWD/Database.cpp \ $$PWD/Common/ParseJsonToData.cpp \ $$PWD/Common/Units.cpp \ - $$PWD/Common/formuladata.cpp \ - $$PWD/Common/formulaparser.cpp \ +# $$PWD/Common/formuladata.cpp \ +# $$PWD/Common/formulaparser.cpp \ # ThermoFun $$PWD/Element.cpp \ $$PWD/GlobalFunctions.cpp \ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 97282168..0e617a9a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -26,37 +26,37 @@ jobs: inputs: filePath: 'ci/pipelines/install/install-osx.sh' -- job: win64 - pool: - vmImage: 'windows-2019' - strategy: - matrix: - Python37: - python.version: '3.7' +# - job: win64 +# pool: +# vmImage: 'windows-2019' +# strategy: +# matrix: +# Python37: +# python.version: '3.7' - steps: - - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - displayName: Add conda to PATH +# steps: +# - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" +# displayName: Add conda to PATH - - script: | - conda config --system --set always_yes yes --set changeps1 no - conda config --system --append channels conda-forge - conda install -n base conda-devenv - conda update -q conda - conda info -a - conda devenv - call activate thermofun - displayName: Create Anaconda environment +# - script: | +# conda config --system --set always_yes yes --set changeps1 no +# conda config --system --append channels conda-forge +# conda install -n base conda-devenv +# conda update -q conda +# conda info -a +# conda devenv +# call activate thermofun +# displayName: Create Anaconda environment - - task: BatchScript@1 - inputs: - filename: 'ci/pipelines/install.bat' +# - task: BatchScript@1 +# inputs: +# filename: 'ci/pipelines/install.bat' - - script: | - call activate thermofun - conda list - call python -c "import thermofun" - displayName: Test +# - script: | +# call activate thermofun +# conda list +# call python -c "import thermofun" +# displayName: Test - job: win64_VS pool: diff --git a/ci/pipelines/installVS.bat b/ci/pipelines/installVS.bat index 6ee5a32d..c333552d 100644 --- a/ci/pipelines/installVS.bat +++ b/ci/pipelines/installVS.bat @@ -22,4 +22,4 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary echo "Configuring..." cmake -G"Visual Studio 16 2019" -DTHERMOFUN_PYTHON_INSTALL_PREFIX:PATH="%CONDA_PREFIX%" -A x64 -S . -B build echo "Building..." -cmake --build build --config %CONFIGURATION% --target install \ No newline at end of file +cmake --build build --target install \ No newline at end of file diff --git a/cmake/modules/ThermoFunFindDeps.cmake b/cmake/modules/ThermoFunFindDeps.cmake index 4320f23a..06d29fbe 100644 --- a/cmake/modules/ThermoFunFindDeps.cmake +++ b/cmake/modules/ThermoFunFindDeps.cmake @@ -12,3 +12,9 @@ if(TFUN_BUILD_PYTHON) message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") endif() endif() + + +find_package(ChemicalFun REQUIRED) +if(NOT ChemicalFun_FOUND) + message(FATAL_ERROR "ChemicalFun library not found") +endif() diff --git a/environment.devenv.yml b/environment.devenv.yml index d123fd6d..27bb2f3b 100644 --- a/environment.devenv.yml +++ b/environment.devenv.yml @@ -11,6 +11,7 @@ dependencies: - ccache # [unix] - pybind11 - nlohmann_json + - chemicalfun - python={{ python_version }} - pytest - pip: diff --git a/tests/interfaceTest/interfaceTest.pro b/tests/interfaceTest/interfaceTest.pro index bea32cae..01177ab9 100644 --- a/tests/interfaceTest/interfaceTest.pro +++ b/tests/interfaceTest/interfaceTest.pro @@ -32,6 +32,8 @@ OBJECTS_DIR = obj # Define the directory where the gui, third-party libs, resources are located BUILD_DIR = $$OUT_PWD/.. +LIBS += -lChemicalFun + INCLUDEPATH += "/usr/local/include" DEPENDPATH += "/usr/local/include" LIBPATH += "/usr/local/lib/" diff --git a/tests/interfaceTest/src/main.cpp b/tests/interfaceTest/src/main.cpp index 32c2d887..12fab8b6 100644 --- a/tests/interfaceTest/src/main.cpp +++ b/tests/interfaceTest/src/main.cpp @@ -1,5 +1,5 @@ #include "ThermoFun.h" -#include "ThermoFun/Common/formuladata.h" +#include "ChemicalFun/FormulaParser.h" #include "GlobalVariables.h" //#include "ThermoFun/Common/ThermoScalar.hpp" using namespace std;