Skip to content

Commit

Permalink
Split into cpp and h files
Browse files Browse the repository at this point in the history
  • Loading branch information
HomesGH committed Jul 30, 2024
1 parent c4103f5 commit c877cdd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 48 deletions.
19 changes: 19 additions & 0 deletions src/molecules/mixingrules/LorentzBerthelot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "LorentzBerthelot.h"

#include <ostream>

#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;
}
25 changes: 7 additions & 18 deletions src/molecules/mixingrules/LorentzBerthelot.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#ifndef LORENTZBERTHELOT_H_
#define LORENTZBERTHELOT_H_

#include "molecules/mixingrules/MixingRuleBase.h"
#include <string>

#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); }
Expand All @@ -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_ */
30 changes: 30 additions & 0 deletions src/molecules/mixingrules/MixingRuleBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "MixingRuleBase.h"

#include <ostream>

#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;
}
}
37 changes: 7 additions & 30 deletions src/molecules/mixingrules/MixingRuleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,13 @@
#define MIXINGRULE_BASE_H_

#include <string>
#include <vector>

#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; }
Expand All @@ -41,14 +18,14 @@ class MixingRuleBase {

virtual std::string getType() const = 0;

const std::vector<double> &getParameters() const { return _parameters; };
void setParameters(std::vector<double> params) { _parameters = params; };
const std::vector<double> &getParameters() const { return _parameters; }
void setParameters(std::vector<double> params) { _parameters = params; }

// Parameters of mixing rule
// e.g. for LB it contains (eta, xi)
std::vector<double> _parameters {1.0, 1.0}; // default for eta, xi;

private:
private:
// Internal cids starting with 0
int _cid1 {};
int _cid2 {};
Expand Down

0 comments on commit c877cdd

Please sign in to comment.