Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes regarding component ID #319

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Adsorption/Generator/adsorption.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<lattice system="cubic" centering="face"/>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate>
<x>0</x>
<y>0</y>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<lattice system="cubic" centering="face"/>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate>
<x>0</x>
<y>0</y>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<lattice system="cubic" centering="face"/>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate>
<x>0</x>
<y>0</y>
Expand Down
2 changes: 1 addition & 1 deletion examples/DropletCoalescence/liq/config_1_generateLiq.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/DropletCoalescence/vap/config_3_generateVap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/Evaporation/stationary/sim01/run01/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</lattice>
<basis>
<site>
<componentid>1</componentid>
<componentid>2</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</lattice>
<basis>
<site>
<componentid>1</componentid>
<componentid>2</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/Injection/liq/sim02/run01/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/Injection/nemd/sim01/run01/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</lattice>
<basis>
<site>
<componentid>2</componentid>
<componentid>3</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/Injection/nemd/sim02/run01/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</lattice>
<basis>
<site>
<componentid>2</componentid>
<componentid>3</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
4 changes: 2 additions & 2 deletions examples/KDD-vectorization-tuner/one-component/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand All @@ -58,7 +58,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
4 changes: 2 additions & 2 deletions examples/KDD-vectorization-tuner/two-components/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</lattice>
<basis>
<site>
<componentid>1</componentid>
<componentid>2</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand All @@ -58,7 +58,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/Mamico-couette/ls1configNoCP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
2 changes: 1 addition & 1 deletion examples/SpinodalDecomposition/config_1_genGrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
4 changes: 2 additions & 2 deletions examples/adios/write/config_mix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand All @@ -102,7 +102,7 @@
</lattice>
<basis>
<site>
<componentid>1</componentid>
<componentid>2</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
4 changes: 2 additions & 2 deletions examples/general-plugins/CavityWriter/CavityWriterTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ It detects the less dense space around the dense drop as a cavity.
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand All @@ -92,7 +92,7 @@ It detects the less dense space around the dense drop as a cavity.
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand All @@ -82,7 +82,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</lattice>
<basis>
<site>
<componentid>0</componentid>
<componentid>1</componentid>
<coordinate> <x>0.5</x> <y>0.5</y> <z>0.5</z> </coordinate>
</site>
</basis>
Expand Down
21 changes: 17 additions & 4 deletions src/ensemble/EnsembleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,29 @@ void Ensemble::readXML(XMLfileUnits& xmlconfig) {
Log::global_log->fatal() << "No components found. Please verify that you have input them correctly." << std::endl;
Simulation::exit(96123);
}
_components.resize(numComponents);
// Initialize _components vector using components with ID=0
_components.resize(numComponents, Component(0));
XMLfile::Query::const_iterator componentIter;
std::string oldpath = xmlconfig.getcurrentnodepath();
for(componentIter = query.begin(); componentIter; componentIter++) {
xmlconfig.changecurrentnode(componentIter);
unsigned int cid = 0;
xmlconfig.getNodeValue("@id", cid);
_components[cid - 1].readXML(xmlconfig);
_componentnamesToIds[_components[cid - 1].getName()] = cid - 1;
Log::global_log->debug() << _components[cid - 1].getName() << " --> " << cid - 1 << std::endl;
// Check if cid in valid range
if ((cid < 1) || (cid > numComponents)) {
Log::global_log->error() << "Specified componentid is invalid. Valid range: 1 <= componentid <= " << numComponents << std::endl;
Simulation::exit(1);
}
// Check if cid was not set before
if (_components[cid - 1].ID() == 0) {
// Add component
_components[cid - 1].readXML(xmlconfig);
_componentnamesToIds[_components[cid - 1].getName()] = cid - 1;
Log::global_log->debug() << _components[cid - 1].getName() << " --> " << cid - 1 << std::endl;
} else {
Log::global_log->error() << "Component " << cid << " was already added! ID might be set twice in <components>" << std::endl;
Simulation::exit(1);
}
}
xmlconfig.changecurrentnode(oldpath);

Expand Down
13 changes: 11 additions & 2 deletions src/utils/generator/Basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ void Basis::readXML(XMLfileUnits& xmlconfig) {
XMLfile::Query query = xmlconfig.query("site");
Ensemble* ensemble = _simulation.getEnsemble();
std::string oldpath = xmlconfig.getcurrentnodepath();
const size_t numComps = ensemble->getComponents()->size();
for(auto siteIter = query.begin(); siteIter; siteIter++) {
Molecule molecule;
xmlconfig.changecurrentnode(siteIter);
int componentid;
xmlconfig.getNodeValue("componentid", componentid);
molecule.setComponent(ensemble->getComponent(componentid));
if (xmlconfig.getNodeValue("componentid", componentid)) {
if ((componentid < 1) || (componentid > numComps)) {
Log::global_log->error() << "[Basis] Specified componentid is invalid. Valid range: 1 <= componentid <= " << numComps << std::endl;
Simulation::exit(1);
}
} else {
Log::global_log->error() << "[Basis] No componentid specified. Set <componentid>!" << std::endl;
Simulation::exit(1);
}
molecule.setComponent(ensemble->getComponent(componentid - 1)); // Internally stored in vector starting at index 0
Comment on lines +23 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of code should go in the ensemble->getComponent method and not here.

Copy link
Contributor Author

@HomesGH HomesGH Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I fully understand your intention.
The actual bug fix is changing
ensemble->getComponent(componentid) to ensemble->getComponent(componentid - 1)
since getComponent uses the "internal" ID (starting with 0).

I added the checks to validate the user input via the xml file. This must be done here to print meaningful error messages.

A basic check in the getComponent method is already kind of (only with Debug build) implemented:

Component* getComponent(int cid) {
mardyn_assert(cid < static_cast<int>(_components.size()));
return &_components.at(cid);
}

But this will print a more generic, not user-friendly error message.

double r[3];
Coordinate3D sitePosition(xmlconfig, "coordinate");
sitePosition.get(r);
Expand Down
Loading