From c877cdd8b874b3eb1a01be41f1c10db440458165 Mon Sep 17 00:00:00 2001 From: Simon Homes Date: Tue, 30 Jul 2024 10:55:50 +0200 Subject: [PATCH] Split into cpp and h files --- .../mixingrules/LorentzBerthelot.cpp | 19 ++++++++++ src/molecules/mixingrules/LorentzBerthelot.h | 25 ++++--------- src/molecules/mixingrules/MixingRuleBase.cpp | 30 +++++++++++++++ src/molecules/mixingrules/MixingRuleBase.h | 37 ++++--------------- 4 files changed, 63 insertions(+), 48 deletions(-) create mode 100644 src/molecules/mixingrules/LorentzBerthelot.cpp create mode 100644 src/molecules/mixingrules/MixingRuleBase.cpp diff --git a/src/molecules/mixingrules/LorentzBerthelot.cpp b/src/molecules/mixingrules/LorentzBerthelot.cpp new file mode 100644 index 0000000000..5d58532a58 --- /dev/null +++ b/src/molecules/mixingrules/LorentzBerthelot.cpp @@ -0,0 +1,19 @@ +#include "LorentzBerthelot.h" + +#include + +#include "MixingRuleBase.h" +#include "utils/Logger.h" +#include "utils/xmlfileUnits.h" + +void LorentzBerthelotMixingRule::readXML(const XMLfileUnits& xmlconfig) { + MixingRuleBase::readXML(xmlconfig); + double eta, xi; + xmlconfig.getNodeValue("eta", eta); + xmlconfig.getNodeValue("xi", xi); + _parameters = {eta, xi}; + Log::global_log->info() << "Mixing coefficients for components " + << this->getCid1()+1 << " + " << this->getCid2()+1 // +1 due to internal cid + << ": (eta, xi) = (" << _parameters.at(0) + << ", " << _parameters.at(1) << ")" << std::endl; +} diff --git a/src/molecules/mixingrules/LorentzBerthelot.h b/src/molecules/mixingrules/LorentzBerthelot.h index 23e5ac598b..5eb4f51004 100644 --- a/src/molecules/mixingrules/LorentzBerthelot.h +++ b/src/molecules/mixingrules/LorentzBerthelot.h @@ -1,25 +1,15 @@ #ifndef LORENTZBERTHELOT_H_ #define LORENTZBERTHELOT_H_ -#include "molecules/mixingrules/MixingRuleBase.h" +#include -#include "utils/Logger.h" -#include "utils/xmlfileUnits.h" +#include "MixingRuleBase.h" + +class XMLfileUnits; class LorentzBerthelotMixingRule : public MixingRuleBase { -public: - - void readXML(XMLfileUnits& xmlconfig) override { - MixingRuleBase::readXML(xmlconfig); - double eta, xi; - xmlconfig.getNodeValue("eta", eta); - xmlconfig.getNodeValue("xi", xi); - _parameters = {eta, xi}; - Log::global_log->info() << "Mixing coefficients for components " - << this->getCid1()+1 << " + " << this->getCid2()+1 // +1 due to internal cid - << ": (eta, xi) = (" << _parameters.at(0) - << ", " << _parameters.at(1) << ")" << std::endl; - } + public: + void readXML(const XMLfileUnits& xmlconfig) override; // _parameters of MixingRuleBase.cpp contains (eta, xi) in case of this mixing rule double getEta() const { return _parameters.at(0); } @@ -28,8 +18,7 @@ class LorentzBerthelotMixingRule : public MixingRuleBase { void setEta(double eta) { _parameters.at(0) = eta; } void setXi(double xi) { _parameters.at(1) = xi; } - std::string getType() const override { return "LB"; }; - + std::string getType() const override { return "LB"; } }; #endif /* LORENTZBERTHELOT_H_ */ diff --git a/src/molecules/mixingrules/MixingRuleBase.cpp b/src/molecules/mixingrules/MixingRuleBase.cpp new file mode 100644 index 0000000000..7214c58a8d --- /dev/null +++ b/src/molecules/mixingrules/MixingRuleBase.cpp @@ -0,0 +1,30 @@ +#include "MixingRuleBase.h" + +#include + +#include "utils/Logger.h" +#include "utils/mardyn_assert.h" +#include "utils/xmlfileUnits.h" + +void MixingRuleBase::readXML(const XMLfileUnits& xmlconfig) { + int cid1; + int cid2; + xmlconfig.getNodeValue("@cid1", cid1); + xmlconfig.getNodeValue("@cid2", cid2); + + if (cid1 == cid2) { + Log::global_log->error() << "Mixing rules: cid1 and cid2 must not be the same but are both " << cid1 << std::endl; + mardyn_exit(1); + } else if ((cid1 <= 0) or (cid2 <= 0)) { + Log::global_log->error() << "Mixing rules: cid1 and cid2 must be greater than zero" << std::endl; + mardyn_exit(1); + } else if (cid1 > cid2) { + // Symmetry for mixing rules is assumed + // cid1 must be less than cid2 + _cid1 = cid2 - 1; // component id - 1 to convert to internal format starting with 0 + _cid2 = cid1 - 1; + } else { + _cid1 = cid1 - 1; + _cid2 = cid2 - 1; + } +} diff --git a/src/molecules/mixingrules/MixingRuleBase.h b/src/molecules/mixingrules/MixingRuleBase.h index a3af7185ab..192d188a8f 100644 --- a/src/molecules/mixingrules/MixingRuleBase.h +++ b/src/molecules/mixingrules/MixingRuleBase.h @@ -2,36 +2,13 @@ #define MIXINGRULE_BASE_H_ #include +#include -#include "utils/Logger.h" -#include "utils/mardyn_assert.h" -#include "utils/xmlfileUnits.h" +class XMLfileUnits; class MixingRuleBase { -public: - - virtual void readXML(XMLfileUnits& xmlconfig) { - int cid1; - int cid2; - xmlconfig.getNodeValue("@cid1", cid1); - xmlconfig.getNodeValue("@cid2", cid2); - - if (cid1 == cid2) { - Log::global_log->error() << "Mixing rules: cid1 and cid2 must not be the same but are both " << cid1 << std::endl; - mardyn_exit(1); - } else if ((cid1 <= 0) or (cid2 <= 0)) { - Log::global_log->error() << "Mixing rules: cid1 and cid2 must be greater than zero" << std::endl; - mardyn_exit(1); - } else if (cid1 > cid2) { - // Symmetry for mixing rules is assumed - // cid1 must be less than cid2 - _cid1 = cid2 - 1; // component id - 1 to convert to internal format starting with 0 - _cid2 = cid1 - 1; - } else { - _cid1 = cid1 - 1; - _cid2 = cid2 - 1; - } - } + public: + virtual void readXML(const XMLfileUnits& xmlconfig); int getCid1() const { return _cid1; } int getCid2() const { return _cid2; } @@ -41,14 +18,14 @@ class MixingRuleBase { virtual std::string getType() const = 0; - const std::vector &getParameters() const { return _parameters; }; - void setParameters(std::vector params) { _parameters = params; }; + const std::vector &getParameters() const { return _parameters; } + void setParameters(std::vector params) { _parameters = params; } // Parameters of mixing rule // e.g. for LB it contains (eta, xi) std::vector _parameters {1.0, 1.0}; // default for eta, xi; -private: + private: // Internal cids starting with 0 int _cid1 {}; int _cid2 {};