From 766e5622294b7332b68f66b162f4e359fcf1d994 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 15 Mar 2023 13:43:57 +0100 Subject: [PATCH 01/94] small ancient bug fix --- src/Simulation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index c96310caaa..871ffac5e3 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -976,7 +976,7 @@ void Simulation::simulate() { //loopTimer->set_sync(true); //global_simulation->timers()->setSyncTimer("SIMULATION_LOOP", true); #ifdef WITH_PAPI - const char *papi_event_list[] = { "PAPI_TOT_CYC", "PAPI_TOT_INS" /*, "PAPI_VEC_DP", "PAPI_L2_DCM", "PAPI_L2_ICM", "PAPI_L1_ICM", "PAPI_DP_OPS", "PAPI_VEC_INS" }; */ + const char *papi_event_list[] = { "PAPI_TOT_CYC", "PAPI_TOT_INS" };/*, "PAPI_VEC_DP", "PAPI_L2_DCM", "PAPI_L2_ICM", "PAPI_L1_ICM", "PAPI_DP_OPS", "PAPI_VEC_INS" }; */ int num_papi_events = sizeof(papi_event_list) / sizeof(papi_event_list[0]); loopTimer->add_papi_counters(num_papi_events, (char**) papi_event_list); #endif From a64a78e3918a817593ba542a7863c4bd42040ce6 Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 24 Mar 2023 15:29:44 +0100 Subject: [PATCH 02/94] initial utils added --- src/parallel/boundaries/BoundaryType.h | 16 +++++++ src/parallel/boundaries/BoundaryUtils.cpp | 58 +++++++++++++++++++++++ src/parallel/boundaries/BoundaryUtils.h | 29 ++++++++++++ src/parallel/boundaries/DimensionType.h | 19 ++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/parallel/boundaries/BoundaryType.h create mode 100644 src/parallel/boundaries/BoundaryUtils.cpp create mode 100644 src/parallel/boundaries/BoundaryUtils.h create mode 100644 src/parallel/boundaries/DimensionType.h diff --git a/src/parallel/boundaries/BoundaryType.h b/src/parallel/boundaries/BoundaryType.h new file mode 100644 index 0000000000..84c64aa53a --- /dev/null +++ b/src/parallel/boundaries/BoundaryType.h @@ -0,0 +1,16 @@ +/* + * BoundaryType.h + * + * Created on: 24 March 2023 + * Author: amartyads + */ + +#pragma once + +enum class BoundaryType +{ + PERIODIC, + OUTFLOW, + REFLECTING, + ERROR +}; \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp new file mode 100644 index 0000000000..294c5c3397 --- /dev/null +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -0,0 +1,58 @@ +/* + * BoundaryUtils.cpp + * + * Created on: 24 March 2023 + * Author: amartyads + */ + +#include + +#include "BoundaryUtils.h" +#include "utils/Logger.h" + +BoundaryUtils::BoundaryUtils() : boundaries{ + {DimensionType::POSX, BoundaryType::PERIODIC}, {DimensionType::POSY, BoundaryType::PERIODIC}, + {DimensionType::POSZ, BoundaryType::PERIODIC}, {DimensionType::NEGX, BoundaryType::PERIODIC}, + {DimensionType::NEGY, BoundaryType::PERIODIC}, {DimensionType::NEGZ, BoundaryType::PERIODIC} + } {} + +BoundaryType BoundaryUtils::getBoundary(std::string dimension) +{ + DimensionType convertedDimension = convertStringToDimension(dimension); + if (convertedDimension == DimensionType::ERROR) + return BoundaryType::ERROR; + return boundaries[convertedDimension]; +} + +void BoundaryUtils::setBoundary(std::string dimension, BoundaryType value) +{ + DimensionType convertedDimension = convertStringToDimension(dimension); + if (convertedDimension == DimensionType::ERROR) + return; + boundaries[convertedDimension] = value; +} + +BoundaryType BoundaryUtils::getBoundary(DimensionType dimension) { return BoundaryType(); } + +void BoundaryUtils::setBoundary(DimensionType dimension, BoundaryType value) {} + +DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) +{ + if(std::find(permissibleDimensions.begin(),permissibleDimensions.end(),dimension) == permissibleDimensions.end()) + { + Log::global_log->error() << "Invalid dimension passed for boundary check" << std::endl; + return DimensionType::ERROR; + } + if(dimension == "+x") + return DimensionType::POSX; + if(dimension == "+y") + return DimensionType::POSY; + if(dimension == "+z") + return DimensionType::POSZ; + if(dimension == "-x") + return DimensionType::NEGX; + if(dimension == "-y") + return DimensionType::NEGY; + //if(dimension == "-z") + return DimensionType::NEGZ; +} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h new file mode 100644 index 0000000000..eab0df21f5 --- /dev/null +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -0,0 +1,29 @@ +/* + * BoundaryUtils.h + * + * Created on: 24 March 2023 + * Author: amartyads + */ + +#pragma once + +#include +#include +#include +#include "BoundaryType.h" +#include "DimensionType.h" + +class BoundaryUtils +{ +public: + BoundaryUtils(); + BoundaryType getBoundary(std::string dimension); + void setBoundary(std::string dimension, BoundaryType value); + BoundaryType getBoundary(DimensionType dimension); + void setBoundary(DimensionType dimension, BoundaryType value); + DimensionType convertStringToDimension(std::string dimension); + +private: + std::map boundaries; + const std::vector permissibleDimensions = {"+x", "-x", "+y", "-y", "+z", "-z"}; +}; \ No newline at end of file diff --git a/src/parallel/boundaries/DimensionType.h b/src/parallel/boundaries/DimensionType.h new file mode 100644 index 0000000000..1e8280e3e8 --- /dev/null +++ b/src/parallel/boundaries/DimensionType.h @@ -0,0 +1,19 @@ +/* + * DimensionType.h + * + * Created on: 24 March 2023 + * Author: amartyads + */ + +#pragma once + +enum class DimensionType +{ + POSX, + NEGX, + POSY, + NEGY, + POSZ, + NEGZ, + ERROR +}; \ No newline at end of file From ecb6245894f79cb1722a47c72227b7583ebe7093 Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 24 Mar 2023 15:37:23 +0100 Subject: [PATCH 03/94] added const, finished methods --- src/parallel/boundaries/BoundaryUtils.cpp | 24 ++++++++++++++--------- src/parallel/boundaries/BoundaryUtils.h | 6 +++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 294c5c3397..8efc888921 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -13,30 +13,36 @@ BoundaryUtils::BoundaryUtils() : boundaries{ {DimensionType::POSX, BoundaryType::PERIODIC}, {DimensionType::POSY, BoundaryType::PERIODIC}, {DimensionType::POSZ, BoundaryType::PERIODIC}, {DimensionType::NEGX, BoundaryType::PERIODIC}, - {DimensionType::NEGY, BoundaryType::PERIODIC}, {DimensionType::NEGZ, BoundaryType::PERIODIC} + {DimensionType::NEGY, BoundaryType::PERIODIC}, {DimensionType::NEGZ, BoundaryType::PERIODIC}, + {DimensionType::ERROR, BoundaryType::ERROR} } {} -BoundaryType BoundaryUtils::getBoundary(std::string dimension) +BoundaryType BoundaryUtils::getBoundary(std::string dimension) const { DimensionType convertedDimension = convertStringToDimension(dimension); - if (convertedDimension == DimensionType::ERROR) - return BoundaryType::ERROR; - return boundaries[convertedDimension]; + return boundaries.at(convertedDimension); } void BoundaryUtils::setBoundary(std::string dimension, BoundaryType value) { DimensionType convertedDimension = convertStringToDimension(dimension); - if (convertedDimension == DimensionType::ERROR) + if(convertedDimension == DimensionType::ERROR) return; boundaries[convertedDimension] = value; } -BoundaryType BoundaryUtils::getBoundary(DimensionType dimension) { return BoundaryType(); } +BoundaryType BoundaryUtils::getBoundary(DimensionType dimension) const +{ + return boundaries.at(dimension); +} -void BoundaryUtils::setBoundary(DimensionType dimension, BoundaryType value) {} +void BoundaryUtils::setBoundary(DimensionType dimension, BoundaryType value) +{ + if(dimension != DimensionType::ERROR) + boundaries[dimension] = value; +} -DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) +DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) const { if(std::find(permissibleDimensions.begin(),permissibleDimensions.end(),dimension) == permissibleDimensions.end()) { diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index eab0df21f5..28acb748b0 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -17,11 +17,11 @@ class BoundaryUtils { public: BoundaryUtils(); - BoundaryType getBoundary(std::string dimension); + BoundaryType getBoundary(std::string dimension) const; void setBoundary(std::string dimension, BoundaryType value); - BoundaryType getBoundary(DimensionType dimension); + BoundaryType getBoundary(DimensionType dimension) const; void setBoundary(DimensionType dimension, BoundaryType value); - DimensionType convertStringToDimension(std::string dimension); + DimensionType convertStringToDimension(std::string dimension) const; private: std::map boundaries; From e772fc43b404eb31529fe856042e557c589104d7 Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 24 Mar 2023 16:07:54 +0100 Subject: [PATCH 04/94] rename --- .../{BoundaryUtils.cpp => BoundaryHandler.cpp} | 16 ++++++++-------- .../{BoundaryUtils.h => BoundaryHandler.h} | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) rename src/parallel/boundaries/{BoundaryUtils.cpp => BoundaryHandler.cpp} (75%) rename src/parallel/boundaries/{BoundaryUtils.h => BoundaryHandler.h} (91%) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryHandler.cpp similarity index 75% rename from src/parallel/boundaries/BoundaryUtils.cpp rename to src/parallel/boundaries/BoundaryHandler.cpp index 8efc888921..9c8948ff3f 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -1,5 +1,5 @@ /* - * BoundaryUtils.cpp + * BoundaryHandler.cpp * * Created on: 24 March 2023 * Author: amartyads @@ -7,23 +7,23 @@ #include -#include "BoundaryUtils.h" +#include "BoundaryHandler.h" #include "utils/Logger.h" -BoundaryUtils::BoundaryUtils() : boundaries{ +BoundaryHandler::BoundaryHandler() : boundaries{ {DimensionType::POSX, BoundaryType::PERIODIC}, {DimensionType::POSY, BoundaryType::PERIODIC}, {DimensionType::POSZ, BoundaryType::PERIODIC}, {DimensionType::NEGX, BoundaryType::PERIODIC}, {DimensionType::NEGY, BoundaryType::PERIODIC}, {DimensionType::NEGZ, BoundaryType::PERIODIC}, {DimensionType::ERROR, BoundaryType::ERROR} } {} -BoundaryType BoundaryUtils::getBoundary(std::string dimension) const +BoundaryType BoundaryHandler::getBoundary(std::string dimension) const { DimensionType convertedDimension = convertStringToDimension(dimension); return boundaries.at(convertedDimension); } -void BoundaryUtils::setBoundary(std::string dimension, BoundaryType value) +void BoundaryHandler::setBoundary(std::string dimension, BoundaryType value) { DimensionType convertedDimension = convertStringToDimension(dimension); if(convertedDimension == DimensionType::ERROR) @@ -31,18 +31,18 @@ void BoundaryUtils::setBoundary(std::string dimension, BoundaryType value) boundaries[convertedDimension] = value; } -BoundaryType BoundaryUtils::getBoundary(DimensionType dimension) const +BoundaryType BoundaryHandler::getBoundary(DimensionType dimension) const { return boundaries.at(dimension); } -void BoundaryUtils::setBoundary(DimensionType dimension, BoundaryType value) +void BoundaryHandler::setBoundary(DimensionType dimension, BoundaryType value) { if(dimension != DimensionType::ERROR) boundaries[dimension] = value; } -DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) const +DimensionType BoundaryHandler::convertStringToDimension(std::string dimension) const { if(std::find(permissibleDimensions.begin(),permissibleDimensions.end(),dimension) == permissibleDimensions.end()) { diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryHandler.h similarity index 91% rename from src/parallel/boundaries/BoundaryUtils.h rename to src/parallel/boundaries/BoundaryHandler.h index 28acb748b0..fef428cd3e 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -1,5 +1,5 @@ /* - * BoundaryUtils.h + * BoundaryHandler.h * * Created on: 24 March 2023 * Author: amartyads @@ -13,10 +13,10 @@ #include "BoundaryType.h" #include "DimensionType.h" -class BoundaryUtils +class BoundaryHandler { public: - BoundaryUtils(); + BoundaryHandler(); BoundaryType getBoundary(std::string dimension) const; void setBoundary(std::string dimension, BoundaryType value); BoundaryType getBoundary(DimensionType dimension) const; From 4bd1be4dd24fa6d2ee7986057b831d9f2da28520 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 27 Mar 2023 10:53:03 +0200 Subject: [PATCH 05/94] moved functions to utils --- src/parallel/boundaries/BoundaryHandler.cpp | 26 +---- src/parallel/boundaries/BoundaryHandler.h | 2 - src/parallel/boundaries/BoundaryUtils.cpp | 119 ++++++++++++++++++++ src/parallel/boundaries/BoundaryUtils.h | 23 ++++ 4 files changed, 145 insertions(+), 25 deletions(-) create mode 100644 src/parallel/boundaries/BoundaryUtils.cpp create mode 100644 src/parallel/boundaries/BoundaryUtils.h diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 9c8948ff3f..c0dcabf32e 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -8,6 +8,7 @@ #include #include "BoundaryHandler.h" +#include "BoundaryUtils.h" #include "utils/Logger.h" BoundaryHandler::BoundaryHandler() : boundaries{ @@ -19,13 +20,13 @@ BoundaryHandler::BoundaryHandler() : boundaries{ BoundaryType BoundaryHandler::getBoundary(std::string dimension) const { - DimensionType convertedDimension = convertStringToDimension(dimension); + DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); return boundaries.at(convertedDimension); } void BoundaryHandler::setBoundary(std::string dimension, BoundaryType value) { - DimensionType convertedDimension = convertStringToDimension(dimension); + DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); if(convertedDimension == DimensionType::ERROR) return; boundaries[convertedDimension] = value; @@ -41,24 +42,3 @@ void BoundaryHandler::setBoundary(DimensionType dimension, BoundaryType value) if(dimension != DimensionType::ERROR) boundaries[dimension] = value; } - -DimensionType BoundaryHandler::convertStringToDimension(std::string dimension) const -{ - if(std::find(permissibleDimensions.begin(),permissibleDimensions.end(),dimension) == permissibleDimensions.end()) - { - Log::global_log->error() << "Invalid dimension passed for boundary check" << std::endl; - return DimensionType::ERROR; - } - if(dimension == "+x") - return DimensionType::POSX; - if(dimension == "+y") - return DimensionType::POSY; - if(dimension == "+z") - return DimensionType::POSZ; - if(dimension == "-x") - return DimensionType::NEGX; - if(dimension == "-y") - return DimensionType::NEGY; - //if(dimension == "-z") - return DimensionType::NEGZ; -} diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index fef428cd3e..e7b622a542 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -21,9 +21,7 @@ class BoundaryHandler void setBoundary(std::string dimension, BoundaryType value); BoundaryType getBoundary(DimensionType dimension) const; void setBoundary(DimensionType dimension, BoundaryType value); - DimensionType convertStringToDimension(std::string dimension) const; private: std::map boundaries; - const std::vector permissibleDimensions = {"+x", "-x", "+y", "-y", "+z", "-z"}; }; \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp new file mode 100644 index 0000000000..490873c6c4 --- /dev/null +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -0,0 +1,119 @@ +#include +#include + + +#include "BoundaryUtils.h" +#include "utils/Logger.h" + +bool BoundaryUtils::checkIfDimensionStringPermissible(std::string dimension) +{ + return std::find(permissibleDimensionsString.begin(),permissibleDimensionsString.end(),dimension) == permissibleDimensionsString.end(); +} + +bool BoundaryUtils::checkIfDimensionNumericPermissible(int dim) +{ + return (dim >= -3 && dim <= 3 && dim != 0); +} + +DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) { + if(checkIfDimensionStringPermissible(dimension)) + { + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + return DimensionType::ERROR; + } + if(dimension == "+x") + return DimensionType::POSX; + if(dimension == "+y") + return DimensionType::POSY; + if(dimension == "+z") + return DimensionType::POSZ; + if(dimension == "-x") + return DimensionType::NEGX; + if(dimension == "-y") + return DimensionType::NEGY; + //if(dimension == "-z") + return DimensionType::NEGZ; +} + +DimensionType BoundaryUtils::convertNumericToDimension(int dim) +{ + if(checkIfDimensionNumericPermissible(dim)) + { + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + return DimensionType::ERROR; + } + switch(findSign(dim)) + { + case -1: + switch(dim) + { + case 1: return DimensionType::NEGX; + case 2: return DimensionType::NEGY; + default: return DimensionType::NEGZ; //case 3 + + } + case 1: + switch(dim) + { + case 1: return DimensionType::POSX; + case 2: return DimensionType::POSY; + default: return DimensionType::POSZ; //case 3 + } + } +} + +std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) +{ + switch (dimension) + { + case DimensionType::POSX: + return "+x"; + + case DimensionType::POSY: + return "+y"; + + case DimensionType::POSZ: + return "+z"; + + case DimensionType::NEGX: + return "-x"; + + case DimensionType::NEGY: + return "-y"; + + case DimensionType::NEGZ: + return "-z"; + + default: + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + return "error"; + } +} + +int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) +{ + switch (dimension) + { + case DimensionType::POSX: + return 1; + + case DimensionType::POSY: + return 2; + + case DimensionType::POSZ: + return 3; + + case DimensionType::NEGX: + return -1; + + case DimensionType::NEGY: + return -2; + + case DimensionType::NEGZ: + return -3; + + default: + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + return 0; + } +} \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h new file mode 100644 index 0000000000..6ff6512cc4 --- /dev/null +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -0,0 +1,23 @@ + +#include +#include + +#include "BoundaryType.h" +#include "DimensionType.h" + +namespace BoundaryUtils +{ + static const std::vector permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; + static const std::vector permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; + + static bool checkIfDimensionStringPermissible(std::string dimension); + static bool checkIfDimensionNumericPermissible(int dim); + + static DimensionType convertStringToDimension(std::string dimension); + static DimensionType convertNumericToDimension(int dim); + + static std::string convertDimensionToString(DimensionType dimension); + static int convertDimensionToNumeric(DimensionType dimension); + + static int findSign(int n) { return n < 0 ? -1 : 1; } +} \ No newline at end of file From 34250aef5cec1529aa6532caa75a97cbcb3aaf0a Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 28 Mar 2023 23:26:15 +0200 Subject: [PATCH 06/94] more utils --- .gitignore | 3 ++- src/parallel/boundaries/BoundaryUtils.cpp | 13 ++++++++++++- src/parallel/boundaries/BoundaryUtils.h | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2da8a8d09e..fd4c88e8fc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ src/MarDyn_*.* *.a *.so doxygen_doc/ -__pycache__/ \ No newline at end of file +__pycache__/ +.vscode/ diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 490873c6c4..39ba7cbb2b 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -90,6 +90,11 @@ std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) } } +std::string BoundaryUtils::convertDimensionToStringAbs(DimensionType dimension) +{ + return convertDimensionToString(dimension).substr(1,1); +} + int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) { switch (dimension) @@ -116,4 +121,10 @@ int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; return 0; } -} \ No newline at end of file +} + +int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) +{ + int toReturn = convertDimensionToNumeric(dimension); + return findSign(toReturn) * toReturn; +} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 6ff6512cc4..7421b62762 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -5,6 +5,8 @@ #include "BoundaryType.h" #include "DimensionType.h" +#include "molecules/Molecule.h" + namespace BoundaryUtils { static const std::vector permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; @@ -17,7 +19,11 @@ namespace BoundaryUtils static DimensionType convertNumericToDimension(int dim); static std::string convertDimensionToString(DimensionType dimension); + static std::string convertDimensionToStringAbs(DimensionType dimension); static int convertDimensionToNumeric(DimensionType dimension); + static int convertDimensionToNumericAbs(DimensionType dimension); + + static int findSign(int n) { return n < 0 ? -1 : 1; } } \ No newline at end of file From 02b49d663aaa38eead57d83a52b4b3b7c01eb7c3 Mon Sep 17 00:00:00 2001 From: amartyads Date: Sun, 2 Apr 2023 23:28:55 +0200 Subject: [PATCH 07/94] files moved --- src/{parallel => ensemble}/boundaries/BoundaryHandler.cpp | 0 src/{parallel => ensemble}/boundaries/BoundaryHandler.h | 0 src/{parallel => ensemble}/boundaries/BoundaryType.h | 0 src/{parallel => ensemble}/boundaries/BoundaryUtils.cpp | 0 src/{parallel => ensemble}/boundaries/BoundaryUtils.h | 2 +- src/{parallel => ensemble}/boundaries/DimensionType.h | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename src/{parallel => ensemble}/boundaries/BoundaryHandler.cpp (100%) rename src/{parallel => ensemble}/boundaries/BoundaryHandler.h (100%) rename src/{parallel => ensemble}/boundaries/BoundaryType.h (100%) rename src/{parallel => ensemble}/boundaries/BoundaryUtils.cpp (100%) rename src/{parallel => ensemble}/boundaries/BoundaryUtils.h (93%) rename src/{parallel => ensemble}/boundaries/DimensionType.h (100%) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/ensemble/boundaries/BoundaryHandler.cpp similarity index 100% rename from src/parallel/boundaries/BoundaryHandler.cpp rename to src/ensemble/boundaries/BoundaryHandler.cpp diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/ensemble/boundaries/BoundaryHandler.h similarity index 100% rename from src/parallel/boundaries/BoundaryHandler.h rename to src/ensemble/boundaries/BoundaryHandler.h diff --git a/src/parallel/boundaries/BoundaryType.h b/src/ensemble/boundaries/BoundaryType.h similarity index 100% rename from src/parallel/boundaries/BoundaryType.h rename to src/ensemble/boundaries/BoundaryType.h diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/ensemble/boundaries/BoundaryUtils.cpp similarity index 100% rename from src/parallel/boundaries/BoundaryUtils.cpp rename to src/ensemble/boundaries/BoundaryUtils.cpp diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/ensemble/boundaries/BoundaryUtils.h similarity index 93% rename from src/parallel/boundaries/BoundaryUtils.h rename to src/ensemble/boundaries/BoundaryUtils.h index 7421b62762..d54dce2cca 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/ensemble/boundaries/BoundaryUtils.h @@ -25,5 +25,5 @@ namespace BoundaryUtils - static int findSign(int n) { return n < 0 ? -1 : 1; } + static inline int findSign(int n) { return n < 0 ? -1 : 1; } } \ No newline at end of file diff --git a/src/parallel/boundaries/DimensionType.h b/src/ensemble/boundaries/DimensionType.h similarity index 100% rename from src/parallel/boundaries/DimensionType.h rename to src/ensemble/boundaries/DimensionType.h From 59efed34238801d1baf49c12d74c777d42e72ef1 Mon Sep 17 00:00:00 2001 From: amartyads Date: Sun, 2 Apr 2023 23:41:51 +0200 Subject: [PATCH 08/94] additional util --- src/ensemble/boundaries/BoundaryUtils.cpp | 12 ++++++++++++ src/ensemble/boundaries/BoundaryUtils.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ensemble/boundaries/BoundaryUtils.cpp b/src/ensemble/boundaries/BoundaryUtils.cpp index 39ba7cbb2b..a1c44e98cd 100644 --- a/src/ensemble/boundaries/BoundaryUtils.cpp +++ b/src/ensemble/boundaries/BoundaryUtils.cpp @@ -128,3 +128,15 @@ int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) int toReturn = convertDimensionToNumeric(dimension); return findSign(toReturn) * toReturn; } + +BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) +{ + if(boundary == "periodic") + return BoundaryType::PERIODIC; + if(boundary == "reflecting" || boundary == "reflective") + return BoundaryType::REFLECTING; + if(boundary == "outflow") + return BoundaryType::OUTFLOW; + Log::global_log->error() << "Invalid boundary type passed. Check your input file!" << std::endl; + return BoundaryType::ERROR; +} \ No newline at end of file diff --git a/src/ensemble/boundaries/BoundaryUtils.h b/src/ensemble/boundaries/BoundaryUtils.h index d54dce2cca..6127d606f5 100644 --- a/src/ensemble/boundaries/BoundaryUtils.h +++ b/src/ensemble/boundaries/BoundaryUtils.h @@ -23,7 +23,7 @@ namespace BoundaryUtils static int convertDimensionToNumeric(DimensionType dimension); static int convertDimensionToNumericAbs(DimensionType dimension); - + static BoundaryType convertStringToBoundary(std::string boundary); static inline int findSign(int n) { return n < 0 ? -1 : 1; } } \ No newline at end of file From 319be032cb918e7cc2b48a220f49145962853d16 Mon Sep 17 00:00:00 2001 From: amartyads Date: Sun, 2 Apr 2023 23:42:29 +0200 Subject: [PATCH 09/94] files moved back --- src/{ensemble => parallel}/boundaries/BoundaryHandler.cpp | 0 src/{ensemble => parallel}/boundaries/BoundaryHandler.h | 0 src/{ensemble => parallel}/boundaries/BoundaryType.h | 0 src/{ensemble => parallel}/boundaries/BoundaryUtils.cpp | 0 src/{ensemble => parallel}/boundaries/BoundaryUtils.h | 0 src/{ensemble => parallel}/boundaries/DimensionType.h | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/{ensemble => parallel}/boundaries/BoundaryHandler.cpp (100%) rename src/{ensemble => parallel}/boundaries/BoundaryHandler.h (100%) rename src/{ensemble => parallel}/boundaries/BoundaryType.h (100%) rename src/{ensemble => parallel}/boundaries/BoundaryUtils.cpp (100%) rename src/{ensemble => parallel}/boundaries/BoundaryUtils.h (100%) rename src/{ensemble => parallel}/boundaries/DimensionType.h (100%) diff --git a/src/ensemble/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp similarity index 100% rename from src/ensemble/boundaries/BoundaryHandler.cpp rename to src/parallel/boundaries/BoundaryHandler.cpp diff --git a/src/ensemble/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h similarity index 100% rename from src/ensemble/boundaries/BoundaryHandler.h rename to src/parallel/boundaries/BoundaryHandler.h diff --git a/src/ensemble/boundaries/BoundaryType.h b/src/parallel/boundaries/BoundaryType.h similarity index 100% rename from src/ensemble/boundaries/BoundaryType.h rename to src/parallel/boundaries/BoundaryType.h diff --git a/src/ensemble/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp similarity index 100% rename from src/ensemble/boundaries/BoundaryUtils.cpp rename to src/parallel/boundaries/BoundaryUtils.cpp diff --git a/src/ensemble/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h similarity index 100% rename from src/ensemble/boundaries/BoundaryUtils.h rename to src/parallel/boundaries/BoundaryUtils.h diff --git a/src/ensemble/boundaries/DimensionType.h b/src/parallel/boundaries/DimensionType.h similarity index 100% rename from src/ensemble/boundaries/DimensionType.h rename to src/parallel/boundaries/DimensionType.h From b58a033b24f87eb2570cba6e096d2ef94d9e231d Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 3 Apr 2023 00:16:36 +0200 Subject: [PATCH 10/94] xml reading done --- src/Simulation.cpp | 24 +++++++++++++++++++++ src/parallel/DomainDecompBase.cpp | 4 ++++ src/parallel/DomainDecompBase.h | 8 +++++++ src/parallel/boundaries/BoundaryHandler.cpp | 11 ++++++++++ src/parallel/boundaries/BoundaryHandler.h | 1 + 5 files changed, 48 insertions(+) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 871ffac5e3..1b87c0f7bc 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -80,6 +80,8 @@ #include "bhfmm/FastMultipoleMethod.h" #include "bhfmm/cellProcessors/VectorizedLJP2PCellProcessor.h" +#include "parallel/boundaries/BoundaryUtils.h" + using Log::global_log; using namespace std; @@ -400,6 +402,28 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } _lastTraversalTimeHistory.setCapacity(timerForLoadAveragingLength); + if(xmlconfig.changecurrentnode("boundaries")) { + std::string tempBoundary; + xmlconfig.getNodeValue("boundaryType", tempBoundary); + //xmlconfig.getNodeValue("posx", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(tempBoundary)); + //xmlconfig.getNodeValue("posy", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(tempBoundary)); + //xmlconfig.getNodeValue("posz", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); + //xmlconfig.getNodeValue("negx", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(tempBoundary)); + //xmlconfig.getNodeValue("negy", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(tempBoundary)); + //xmlconfig.getNodeValue("negz", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); + + if (_domainDecomposition->hasInvalidBoundary()) { + global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; + exit(1); + } + } + xmlconfig.changecurrentnode(".."); } else { diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 67e2841d67..576fc74e43 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -25,6 +25,10 @@ DomainDecompBase::~DomainDecompBase() { void DomainDecompBase::readXML(XMLfileUnits& /* xmlconfig */) { } +void DomainDecompBase::setBoundaryType(DimensionType dimension, BoundaryType boundary) { + boundaryHandler.setBoundary(dimension, boundary); +} + void DomainDecompBase::addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer) { for (auto& molecule : invalidMolecules) { diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index acee357515..4d0e33d45b 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -16,6 +16,8 @@ #include "molecules/MoleculeForwardDeclaration.h" #include "utils/Logger.h" // is this used? +#include "boundaries/BoundaryHandler.h" + class Component; class Domain; class ParticleContainer; @@ -288,6 +290,10 @@ class DomainDecompBase: public MemoryProfilable { virtual void printCommunicationPartners(std::string filename) const {}; + void setBoundaryType(DimensionType dimension, BoundaryType boundary); + + bool hasInvalidBoundary() const { return boundaryHandler.hasInvalidBoundary();} + protected: void addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer); @@ -337,6 +343,8 @@ class DomainDecompBase: public MemoryProfilable { //! total number of processes in the simulation int _numProcs; + BoundaryHandler boundaryHandler; + private: CollectiveCommBase _collCommBase; int _sendLeavingAndCopiesSeparately = 0; diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index c0dcabf32e..aa84cfdaf3 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -42,3 +42,14 @@ void BoundaryHandler::setBoundary(DimensionType dimension, BoundaryType value) if(dimension != DimensionType::ERROR) boundaries[dimension] = value; } + +bool BoundaryHandler::hasInvalidBoundary() const +{ + return boundaries.at(DimensionType::POSX) == BoundaryType::ERROR || + boundaries.at(DimensionType::POSY) == BoundaryType::ERROR || + boundaries.at(DimensionType::POSZ) == BoundaryType::ERROR || + boundaries.at(DimensionType::NEGX) == BoundaryType::ERROR || + boundaries.at(DimensionType::NEGY) == BoundaryType::ERROR || + boundaries.at(DimensionType::NEGZ) == BoundaryType::ERROR; + +} \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index e7b622a542..35ab87e567 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -21,6 +21,7 @@ class BoundaryHandler void setBoundary(std::string dimension, BoundaryType value); BoundaryType getBoundary(DimensionType dimension) const; void setBoundary(DimensionType dimension, BoundaryType value); + bool hasInvalidBoundary() const; private: std::map boundaries; From 4d1a3d24a75a7dcae18357ddd0f544b249388fe4 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 3 Apr 2023 15:10:45 +0200 Subject: [PATCH 11/94] boundary condition initial skeleton --- src/Simulation.cpp | 13 ++++---- src/parallel/DomainDecompBase.cpp | 50 +++++++++++++++++++++++++++++++ src/parallel/DomainDecompBase.h | 2 ++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 1b87c0f7bc..a2c7b004be 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -405,17 +405,14 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { if(xmlconfig.changecurrentnode("boundaries")) { std::string tempBoundary; xmlconfig.getNodeValue("boundaryType", tempBoundary); - //xmlconfig.getNodeValue("posx", tempBoundary); + //xmlconfig.getNodeValue("x", tempBoundary); _domainDecomposition->setBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("posy", tempBoundary); - _domainDecomposition->setBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("posz", tempBoundary); - _domainDecomposition->setBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("negx", tempBoundary); _domainDecomposition->setBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("negy", tempBoundary); + //xmlconfig.getNodeValue("y", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("negz", tempBoundary); + //xmlconfig.getNodeValue("z", tempBoundary); + _domainDecomposition->setBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); if (_domainDecomposition->hasInvalidBoundary()) { diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 576fc74e43..b4b0123a14 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -14,6 +14,7 @@ #ifdef ENABLE_MPI #include #include "utils/MPI_Info_object.h" +#include "DomainDecompBase.h" #endif DomainDecompBase::DomainDecompBase() : _rank(0), _numProcs(1) { @@ -29,6 +30,55 @@ void DomainDecompBase::setBoundaryType(DimensionType dimension, BoundaryType bou boundaryHandler.setBoundary(dimension, boundary); } +void DomainDecompBase::processBoundaryConditions(ParticleContainer* moleculeContainer, Domain* domain) { + //find which walls to consider + double cutoff = moleculeContainer->getCutoff(); + double startRegion[3]{moleculeContainer->getBoundingBoxMin(0), + moleculeContainer->getBoundingBoxMin(1), + moleculeContainer->getBoundingBoxMin(2)}; + double endRegion[3]{moleculeContainer->getBoundingBoxMax(0), + moleculeContainer->getBoundingBoxMax(1), + moleculeContainer->getBoundingBoxMax(2)}; + + double globStartRegion[3]{getBoundingBoxMin(0, domain), + getBoundingBoxMin(1, domain), + getBoundingBoxMin(2, domain)}; + double globEndRegion[3]{getBoundingBoxMax(0, domain), + getBoundingBoxMax(1, domain), + getBoundingBoxMax(2, domain)}; + + std::map isOuterWall {{DimensionType::POSX, endRegion[0] == globEndRegion[0]}, + {DimensionType::NEGX, startRegion[0] == globStartRegion[0]}, + {DimensionType::POSY, endRegion[1] == globEndRegion[1]}, + {DimensionType::NEGY, startRegion[1] == globStartRegion[1]}, + {DimensionType::POSZ, endRegion[2] == globEndRegion[2]}, + {DimensionType::NEGZ, startRegion[2] == globStartRegion[2]}}; + + for (auto const& currentWall : isOuterWall) + { + if(!currentWall.second) + continue; + + switch(boundaryHandler.getBoundary(currentWall.first)) + { + case BoundaryType::PERIODIC: + //default behaviour + break; + + case BoundaryType::OUTFLOW: + //delete exiting particles + //remove from invalidparticles + break; + + case BoundaryType::REFLECTING: + break; + + default: + global_log->error() << "Boundary type error! Received type " << boundaryHandler.getBoundary(currentWall.first) << " not allowed!" << std::endl; + Simulation::exit(1); + } + } +} void DomainDecompBase::addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer) { for (auto& molecule : invalidMolecules) { diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index 4d0e33d45b..458e23b6ed 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -294,6 +294,8 @@ class DomainDecompBase: public MemoryProfilable { bool hasInvalidBoundary() const { return boundaryHandler.hasInvalidBoundary();} + void processBoundaryConditions(ParticleContainer* moleculeContainer, Domain* domain); + protected: void addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer); From 9266f878ce1121718a9b5834a0e85c518bcb32c3 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 4 Apr 2023 12:31:18 +0200 Subject: [PATCH 12/94] reflecting boundary done, untested --- .../ls1config.restart.dat | 31 ++++++++++ examples/simple-boundary-test/ls1config.xml | 62 +++++++++++++++++++ .../simple_checkpoint.inp | 32 ++++++++++ src/Simulation.cpp | 14 +++-- src/parallel/DomainDecompBase.cpp | 61 +++++++----------- src/parallel/DomainDecompBase.h | 3 +- src/parallel/boundaries/BoundaryHandler.cpp | 57 +++++++++++++++++ src/parallel/boundaries/BoundaryHandler.h | 5 ++ src/parallel/boundaries/BoundaryUtils.cpp | 46 +++++++++++++- src/parallel/boundaries/BoundaryUtils.h | 29 +++++---- 10 files changed, 283 insertions(+), 57 deletions(-) create mode 100644 examples/simple-boundary-test/ls1config.restart.dat create mode 100644 examples/simple-boundary-test/ls1config.xml create mode 100644 examples/simple-boundary-test/simple_checkpoint.inp diff --git a/examples/simple-boundary-test/ls1config.restart.dat b/examples/simple-boundary-test/ls1config.restart.dat new file mode 100644 index 0000000000..6a2eaf5f3f --- /dev/null +++ b/examples/simple-boundary-test/ls1config.restart.dat @@ -0,0 +1,31 @@ +mardyn trunk 20160512 +currentTime 5.000000000000000e-03 + Length 20 20 20 + Temperature 1.1 + NumberOfComponents 1 +1 0 0 0 0 +0 0 0 1 1 0.209810746 +0 0 0 +1e+10 + NumberOfMolecules 20 + MoleculeFormat ICRVQD +0 1 0.48603127897033637783 1.7794435968108754942 2.0227924682322138139 -1.7162766409929897105 1.8683918996070341123 -0.98456434350346022644 1 0 0 0 0 0 0 +1 1 1.6677144132331980231 0.25859408775764236577 1.5399333325166126851 0.15625509060396755578 1.3680691155123763103 0.0075202368310167012205 1 0 0 0 0 0 0 +2 1 1.5262378927374189441 1.5216082294268094 1.234856747197058402 0.88913102844128988345 0.099162118361529535959 -0.40708438540529612304 1 0 0 0 0 0 0 +3 1 1.1625533162733845405 2.2111768604675616778 0.13059190113262983401 -1.1933964438923811979 0.78092530601974929905 -1.3244124470944043104 1 0 0 0 0 0 0 +4 1 0.41334367801708188361 1.6995109620518646931 1.0668418688004606132 0.062109719212872407934 -0.78557062949754130621 -1.0976378108754849539 1 0 0 0 0 0 0 +5 1 0.65770345007752084587 0.59196795080797459665 1.9145963089956319347 -2.3617582323770536235 -0.91600979005842342318 0.68501446032528301444 1 0 0 0 0 0 0 +6 1 0.99622667537929843196 0.7392929454205859896 0.60969812749036444988 2.0209103733260689317 0.89837585959526122803 -0.70631748122506488041 1 0 0 0 0 0 0 +7 1 2.027328492637660684 0.65440934252588467412 0.51970378261626581917 0.48181202888830071407 -0.16392493695073473425 0.3431947333885322915 1 0 0 0 0 0 0 +8 1 1.6110619393430651858 1.1330702113548116738 2.1797121800639542855 1.3712824023646177363 2.1314929122719386001 2.1546162170900293731 1 0 0 0 0 0 0 +9 1 1.8838335913054302662 2.045198857482267929 2.1296014151485280763 -0.35127549368024091336 -0.51964852490068136337 -0.46559503330595947146 1 0 0 0 0 0 0 +10 1 2.3221196196709903425 2.3795093822947630535 1.0801855040189678459 0.65050748688470483305 -0.53891493799717871127 -0.63971620029506903737 1 0 0 0 0 0 0 +11 1 2.1851002203168206073 1.7046351084251787356 0.17877445783497525333 1.308606690806215056 -1.6109287639500093903 1.4111796504845324218 1 0 0 0 0 0 0 +12 1 0.15102235133673438949 0.10842108748820068753 0.78306635473720986873 0.36374847059148041062 0.22331691539781009515 1.4337552168580240952 1 0 0 0 0 0 0 +13 1 2.7378028356917614161 1.301510644170891462 0.96723024759923237337 -0.54776524033776707867 1.7993921407620585562 -2.6644334440552950305 1 0 0 0 0 0 0 +14 1 3.7458496665804013048 1.3844210574219317778 0.89645393033007536587 -0.80866903081109342555 0.90005320860011328588 -1.1749587939532963876 1 0 0 0 0 0 0 +15 1 4.2653476440444650919 0.43377482352582263925 0.93387624631555776755 -1.4329209659780199893 0.3393980985345660395 -0.056632979622997701996 1 0 0 0 0 0 0 +16 1 3.9851193402072158101 1.8649228102890285097 2.0319444568703191045 0.33464331734314711753 0.29967176433985404094 -0.76021915107732462857 1 0 0 0 0 0 0 +17 1 3.428878806578756322 1.9894165339375988744 0.24652197877382797664 -0.0035878903160999854258 -0.73487173402971572855 0.044228364692880849096 1 0 0 0 0 0 0 +18 1 3.0474575730585242717 0.32782274432827512856 0.78460113496888828077 -0.020236695636267433562 0.38597519143808084463 0.22165998336046152661 1 0 0 0 0 0 0 +19 1 3.4104955999544372958 0.9155617643481979151 1.7386275054408668606 -0.23677685282975227676 -0.13597725488048159614 -0.058470874344615619833 1 0 0 0 0 0 0 diff --git a/examples/simple-boundary-test/ls1config.xml b/examples/simple-boundary-test/ls1config.xml new file mode 100644 index 0000000000..5b7401cc9d --- /dev/null +++ b/examples/simple-boundary-test/ls1config.xml @@ -0,0 +1,62 @@ + + + + 0.34 + 39.948 + 120 + + + + 0.005 + + + 0 + 0 + + 200 + + + + 1.1 + + 20 + 20 + 20 + + + + + 0.0 0.0 0.0 + 1.0 + 1.0 + 1.0 + true + + + + + simple_checkpoint.inp + + + + + 22 1 + periodicreflectingoutflow + + + + + 2.2 + + + 1.0e+10 + + + + + vtkOutput + 1 + + + + diff --git a/examples/simple-boundary-test/simple_checkpoint.inp b/examples/simple-boundary-test/simple_checkpoint.inp new file mode 100644 index 0000000000..dc9632b574 --- /dev/null +++ b/examples/simple-boundary-test/simple_checkpoint.inp @@ -0,0 +1,32 @@ +mardyn trunk 20120726 +currentTime 0 +Length 20 20 20 +Temperature 1.1 +NumberOfComponents 1 +1 0 0 0 0 +0 0 0 1 1 1 0 +0 0 0 +1e+10 +NumberOfMolecules 20 +MoleculeFormat IRV +0 0.495023130681126800 1.769783381923575982 2.028459061539174435 -1.822950647035876726 1.933108883878859707 -1.247479613481441652 +1 1.666902289161833917 0.251548695399434363 1.539818418524745658 0.161786626031291930 1.405934354571577449 0.040477381848499375 +2 1.521644980017457405 1.521122184006463263 1.236726790577654445 0.917900648354828430 0.088832542456655561 -0.322355334716117325 +3 1.168739293122478928 2.207095133951280097 0.137498901779552762 -1.238237081130751926 0.824091951875207451 -1.393047606478275968 +4 0.413034045989151000 1.703482886840757882 1.071909164239454260 0.061052133396027539 -0.777952474274995032 -0.892174989916953098 +5 0.669926890252636409 0.596756192180819656 1.910988818406699430 -2.441868942606676196 -0.966112268211709035 0.735244244766940946 +6 0.985706008329942263 0.734732924753132011 0.613416822128000416 2.109936801929042094 0.892562783856633679 -0.756500545579516626 +7 2.024883837684851251 0.655224955884165072 0.517923501538259168 0.482343678913160712 -0.159269962164721030 0.356236835024475840 +8 1.603763777455249340 1.121356234421131859 2.168767437762714412 1.487629417187438241 2.445558985257139994 2.144651500768343766 +9 1.885850726602712690 2.048554252728604474 2.131951664636667410 -0.433649548613340874 -0.770578472330007203 -0.461386110163174823 +10 2.318740948078676478 2.382226451453307359 1.083495426816144525 0.678716993010245351 -0.528632663058676844 -0.661702674380576061 +11 2.178270331926622561 1.713016076999506643 0.171429381334559205 1.370070492693730158 -1.679782668506980547 1.468184943400678844 +12 0.149111661740284146 0.107249999693601050 0.775689695391597933 0.391452387594801832 0.240119875907177566 1.467340983915756514 +13 2.740437165984020762 1.292364430622112259 0.981165383835134741 -0.478637099342237027 1.789034980167728550 -2.806678834058749406 +14 3.750564619815982326 1.379364929250165517 0.902946608122211725 -1.037764094756559174 1.067623659752375831 -1.354150887333365194 +15 4.272720921989165532 0.432002065693436799 0.934187032815462115 -1.467508125738746561 0.358550665287694525 -0.065674309465818093 +16 3.983367130221580066 1.863344701744039433 2.035834014281116655 0.354638734151996371 0.321143357882705760 -0.769572589664034523 +17 3.428555648982378745 1.993724265656156458 0.245752545138458400 0.121685283873803327 -0.941923889757456001 0.239060361198430410 +18 3.047656038353257824 0.325743687754526556 0.783463768955406037 -0.058874143456041472 0.435127946587492986 0.226702582353335791 +19 3.411674504194637247 0.916158055315752895 1.739072582267308986 -0.226836548364954649 -0.093938776337105179 -0.124589539374959701 +20 3.530783156876641460 2.430364628092342105 1.251653022914280156 -0.502785611791367049 -2.307545880295731155 0.570935632592190045 diff --git a/src/Simulation.cpp b/src/Simulation.cpp index a2c7b004be..901e8d2313 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -404,14 +404,17 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { if(xmlconfig.changecurrentnode("boundaries")) { std::string tempBoundary; - xmlconfig.getNodeValue("boundaryType", tempBoundary); - //xmlconfig.getNodeValue("x", tempBoundary); + //xmlconfig.getNodeValue("boundaryType", tempBoundary); + xmlconfig.getNodeValue("x", tempBoundary); + global_log->info() << "x boundary " << tempBoundary << std::endl; _domainDecomposition->setBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("y", tempBoundary); + xmlconfig.getNodeValue("y", tempBoundary); + global_log->info() << "y boundary " << tempBoundary << std::endl; _domainDecomposition->setBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(tempBoundary)); - //xmlconfig.getNodeValue("z", tempBoundary); + xmlconfig.getNodeValue("z", tempBoundary); + global_log->info() << "z boundary " << tempBoundary << std::endl; _domainDecomposition->setBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); @@ -419,6 +422,7 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; exit(1); } + xmlconfig.changecurrentnode(".."); } xmlconfig.changecurrentnode(".."); @@ -1323,6 +1327,8 @@ void Simulation::updateParticleContainerAndDecomposition(double lastTraversalTim std::accumulate(_lastTraversalTimeHistory.begin(), _lastTraversalTimeHistory.end(), 0.) / _lastTraversalTimeHistory.size(); + _domainDecomposition->processBoundaryConditions(_moleculeContainer, _domain, _ensemble); + bool forceRebalancing = false; global_simulation->timers()->start("SIMULATION_MPI_OMP_COMMUNICATION"); _domainDecomposition->balanceAndExchange(averageLastTraversalTime, forceRebalancing, _moleculeContainer, diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index b4b0123a14..b118268d97 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -14,9 +14,10 @@ #ifdef ENABLE_MPI #include #include "utils/MPI_Info_object.h" -#include "DomainDecompBase.h" #endif +#include "boundaries/BoundaryUtils.h" + DomainDecompBase::DomainDecompBase() : _rank(0), _numProcs(1) { } @@ -30,23 +31,24 @@ void DomainDecompBase::setBoundaryType(DimensionType dimension, BoundaryType bou boundaryHandler.setBoundary(dimension, boundary); } -void DomainDecompBase::processBoundaryConditions(ParticleContainer* moleculeContainer, Domain* domain) { +void DomainDecompBase::processBoundaryConditions(Domain* domain, Ensemble* ensemble) { //find which walls to consider - double cutoff = moleculeContainer->getCutoff(); - double startRegion[3]{moleculeContainer->getBoundingBoxMin(0), - moleculeContainer->getBoundingBoxMin(1), - moleculeContainer->getBoundingBoxMin(2)}; - double endRegion[3]{moleculeContainer->getBoundingBoxMax(0), - moleculeContainer->getBoundingBoxMax(1), - moleculeContainer->getBoundingBoxMax(2)}; - - double globStartRegion[3]{getBoundingBoxMin(0, domain), - getBoundingBoxMin(1, domain), - getBoundingBoxMin(2, domain)}; - double globEndRegion[3]{getBoundingBoxMax(0, domain), - getBoundingBoxMax(1, domain), - getBoundingBoxMax(2, domain)}; + double startRegion[3], endRegion[3]; + for(int d = 0; d < 3; d++) { + startRegion[d] = getBoundingBoxMin(d, domain); + endRegion[d] = getBoundingBoxMax(d, domain); + } + + double* globStartRegion = ensemble->domain()->rmin(); + double* globEndRegion = ensemble->domain()->rmax(); + global_log->set_mpi_output_all(); + global_log->info() << "local: " << startRegion[0] << " " << startRegion[1] << " " << startRegion[2] << " " + << endRegion[0] << " " << endRegion[1] << " " << endRegion[2] << " " + << "global: " << globStartRegion[0] << " " << globStartRegion[1] << " " << globStartRegion[2] << " " + << globEndRegion[0] << " " << globEndRegion[1] << " " << globEndRegion[2] << " " << std::endl; + + std::map isOuterWall {{DimensionType::POSX, endRegion[0] == globEndRegion[0]}, {DimensionType::NEGX, startRegion[0] == globStartRegion[0]}, {DimensionType::POSY, endRegion[1] == globEndRegion[1]}, @@ -54,30 +56,11 @@ void DomainDecompBase::processBoundaryConditions(ParticleContainer* moleculeCont {DimensionType::POSZ, endRegion[2] == globEndRegion[2]}, {DimensionType::NEGZ, startRegion[2] == globStartRegion[2]}}; - for (auto const& currentWall : isOuterWall) - { - if(!currentWall.second) - continue; - switch(boundaryHandler.getBoundary(currentWall.first)) - { - case BoundaryType::PERIODIC: - //default behaviour - break; - - case BoundaryType::OUTFLOW: - //delete exiting particles - //remove from invalidparticles - break; - - case BoundaryType::REFLECTING: - break; - - default: - global_log->error() << "Boundary type error! Received type " << boundaryHandler.getBoundary(currentWall.first) << " not allowed!" << std::endl; - Simulation::exit(1); - } - } + boundaryHandler.setOuterWalls(isOuterWall); + boundaryHandler.processBoundaries(startRegion, endRegion); + + global_log->set_mpi_output_root(); } void DomainDecompBase::addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer) { diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index 458e23b6ed..e135849aca 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -17,6 +17,7 @@ #include "utils/Logger.h" // is this used? #include "boundaries/BoundaryHandler.h" +#include "ensemble/EnsembleBase.h" class Component; class Domain; @@ -294,7 +295,7 @@ class DomainDecompBase: public MemoryProfilable { bool hasInvalidBoundary() const { return boundaryHandler.hasInvalidBoundary();} - void processBoundaryConditions(ParticleContainer* moleculeContainer, Domain* domain); + void processBoundaryConditions(Domain* domain, Ensemble* _ensemble); protected: void addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index aa84cfdaf3..90ab0faf37 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -9,6 +9,10 @@ #include "BoundaryHandler.h" #include "BoundaryUtils.h" + +#include "Simulation.h" +#include "integrators/Integrator.h" + #include "utils/Logger.h" BoundaryHandler::BoundaryHandler() : boundaries{ @@ -52,4 +56,57 @@ bool BoundaryHandler::hasInvalidBoundary() const boundaries.at(DimensionType::NEGY) == BoundaryType::ERROR || boundaries.at(DimensionType::NEGZ) == BoundaryType::ERROR; +} + +bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) +{ + auto moleculeContainer = global_simulation->getMoleculeContainer(); + double timestepLength = (global_simulation->getIntegrator())->getTimestepLength(); + double cutoff = moleculeContainer->getCutoff(); + for (auto const& currentWall : isOuterWall) + { + global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; + if(!currentWall.second) + continue; + + switch(getBoundary(currentWall.first)) + { + case BoundaryType::PERIODIC: + //default behaviour + break; + + case BoundaryType::OUTFLOW: + //delete exiting particles + //remove from invalidparticles + + break; + + case BoundaryType::REFLECTING: + { + //create region + double curWallRegionBegin[3], curWallRegionEnd[3]; + bool successRegionSet = BoundaryUtils::setRegionToParams(startRegion, endRegion, currentWall.first, cutoff, curWallRegionBegin, curWallRegionEnd); + if (!successRegionSet) + { + global_log->error() << "Error while setting the region for boundary conditions " << std::endl; + Simulation::exit(1); + } + auto particlesInRegion = moleculeContainer->regionIterator(curWallRegionBegin, curWallRegionEnd, ParticleIterator::ONLY_INNER_AND_BOUNDARY); + for (auto it = particlesInRegion; it.isValid(); ++it) + { + Molecule curMolecule = *it; + if (BoundaryUtils::isMoleculeLeaving(curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength)) + { + int currentDim = BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); + double vel = it->v(currentDim); + it->setv(currentDim, -vel); + } + } + break; + } + default: + global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + Simulation::exit(1); + } + } } \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 35ab87e567..274c5743ef 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -13,6 +13,7 @@ #include "BoundaryType.h" #include "DimensionType.h" + class BoundaryHandler { public: @@ -23,6 +24,10 @@ class BoundaryHandler void setBoundary(DimensionType dimension, BoundaryType value); bool hasInvalidBoundary() const; + void setOuterWalls(std::map isOuterWallOth) {isOuterWall = isOuterWallOth;} + bool processBoundaries(double* startRegion, double* endRegion); + private: std::map boundaries; + std::map isOuterWall; }; \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index a1c44e98cd..5894fc83af 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -129,6 +129,11 @@ int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) return findSign(toReturn) * toReturn; } +int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) +{ + return convertDimensionToNumericAbs(dimension) - 1; +} + BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) { if(boundary == "periodic") @@ -139,4 +144,43 @@ BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) return BoundaryType::OUTFLOW; Log::global_log->error() << "Invalid boundary type passed. Check your input file!" << std::endl; return BoundaryType::ERROR; -} \ No newline at end of file +} + +bool BoundaryUtils::setRegionToParams(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, + double* returnRegionBegin, double* returnRegionEnd) +{ + for (int i = 0; i < 3; i++) + { + returnRegionBegin[i] = givenRegionBegin[i]; + returnRegionEnd[i] = givenRegionEnd[i]; + } + + int dimensionLS1 = convertDimensionToLS1Dims(dimension); + + switch (dimension) //can be done with findsign() too, but this is clearer + { + case DimensionType::POSX: + case DimensionType::POSY: + case DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1] - regionWidth; + break; + + case DimensionType::NEGX: + case DimensionType::NEGY: + case DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1] + regionWidth; + + default: + return false; + } + return true; +} + +bool BoundaryUtils::isMoleculeLeaving(Molecule molecule, double* regionBegin, double* regionEnd, + DimensionType dimension, double timestepLength) { + int ls1dim = convertDimensionToLS1Dims(dimension); + double newPos = molecule.r(ls1dim) + (timestepLength * molecule.v(ls1dim)); + if(newPos < regionBegin[ls1dim] || newPos > regionEnd[ls1dim]) + return true; + return false; +} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 6127d606f5..0a2a2fc3f3 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -9,21 +9,26 @@ namespace BoundaryUtils { - static const std::vector permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; - static const std::vector permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; + const std::vector permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; + const std::vector permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; - static bool checkIfDimensionStringPermissible(std::string dimension); - static bool checkIfDimensionNumericPermissible(int dim); + bool checkIfDimensionStringPermissible(std::string dimension); + bool checkIfDimensionNumericPermissible(int dim); - static DimensionType convertStringToDimension(std::string dimension); - static DimensionType convertNumericToDimension(int dim); + DimensionType convertStringToDimension(std::string dimension); + DimensionType convertNumericToDimension(int dim); - static std::string convertDimensionToString(DimensionType dimension); - static std::string convertDimensionToStringAbs(DimensionType dimension); - static int convertDimensionToNumeric(DimensionType dimension); - static int convertDimensionToNumericAbs(DimensionType dimension); + std::string convertDimensionToString(DimensionType dimension); + std::string convertDimensionToStringAbs(DimensionType dimension); + int convertDimensionToNumeric(DimensionType dimension); + int convertDimensionToNumericAbs(DimensionType dimension); + int convertDimensionToLS1Dims(DimensionType dimension); - static BoundaryType convertStringToBoundary(std::string boundary); + BoundaryType convertStringToBoundary(std::string boundary); - static inline int findSign(int n) { return n < 0 ? -1 : 1; } + bool setRegionToParams(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd); + bool isMoleculeLeaving(Molecule molecule, double* regionBegin, double* regionEnd, DimensionType dimension, double timestepLength); + + inline int findSign(int n) { return n < 0 ? -1 : 1; } + inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } } \ No newline at end of file From 837250fa4e7a46fc4d85bf63b4752407679693d9 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 4 Apr 2023 12:43:34 +0200 Subject: [PATCH 13/94] outflow done, not tested --- src/Simulation.cpp | 2 +- src/parallel/boundaries/BoundaryHandler.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 901e8d2313..d14e498f7d 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -1327,7 +1327,7 @@ void Simulation::updateParticleContainerAndDecomposition(double lastTraversalTim std::accumulate(_lastTraversalTimeHistory.begin(), _lastTraversalTimeHistory.end(), 0.) / _lastTraversalTimeHistory.size(); - _domainDecomposition->processBoundaryConditions(_moleculeContainer, _domain, _ensemble); + _domainDecomposition->processBoundaryConditions(_domain, _ensemble); bool forceRebalancing = false; global_simulation->timers()->start("SIMULATION_MPI_OMP_COMMUNICATION"); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 90ab0faf37..64f19c1ec2 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -76,11 +76,6 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) break; case BoundaryType::OUTFLOW: - //delete exiting particles - //remove from invalidparticles - - break; - case BoundaryType::REFLECTING: { //create region @@ -98,8 +93,15 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) if (BoundaryUtils::isMoleculeLeaving(curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength)) { int currentDim = BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); - double vel = it->v(currentDim); - it->setv(currentDim, -vel); + if(getBoundary(currentWall.first) == BoundaryType::REFLECTING) + { + double vel = it->v(currentDim); + it->setv(currentDim, -vel); + } + else + { + moleculeContainer->deleteMolecule(it, true); + } } } break; From 61d6e9166d8b51d63ab64d7fc0f4520775ef176a Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 4 Apr 2023 14:45:44 +0200 Subject: [PATCH 14/94] working wall detection, wrong paths (halos) --- .../ls1config.restart.dat | 31 ---------------- examples/simple-boundary-test/ls1config.xml | 12 +++---- .../simple_checkpoint.inp | 35 +++++++------------ src/parallel/boundaries/BoundaryHandler.cpp | 3 +- src/parallel/boundaries/BoundaryUtils.cpp | 1 + 5 files changed, 21 insertions(+), 61 deletions(-) delete mode 100644 examples/simple-boundary-test/ls1config.restart.dat diff --git a/examples/simple-boundary-test/ls1config.restart.dat b/examples/simple-boundary-test/ls1config.restart.dat deleted file mode 100644 index 6a2eaf5f3f..0000000000 --- a/examples/simple-boundary-test/ls1config.restart.dat +++ /dev/null @@ -1,31 +0,0 @@ -mardyn trunk 20160512 -currentTime 5.000000000000000e-03 - Length 20 20 20 - Temperature 1.1 - NumberOfComponents 1 -1 0 0 0 0 -0 0 0 1 1 0.209810746 -0 0 0 -1e+10 - NumberOfMolecules 20 - MoleculeFormat ICRVQD -0 1 0.48603127897033637783 1.7794435968108754942 2.0227924682322138139 -1.7162766409929897105 1.8683918996070341123 -0.98456434350346022644 1 0 0 0 0 0 0 -1 1 1.6677144132331980231 0.25859408775764236577 1.5399333325166126851 0.15625509060396755578 1.3680691155123763103 0.0075202368310167012205 1 0 0 0 0 0 0 -2 1 1.5262378927374189441 1.5216082294268094 1.234856747197058402 0.88913102844128988345 0.099162118361529535959 -0.40708438540529612304 1 0 0 0 0 0 0 -3 1 1.1625533162733845405 2.2111768604675616778 0.13059190113262983401 -1.1933964438923811979 0.78092530601974929905 -1.3244124470944043104 1 0 0 0 0 0 0 -4 1 0.41334367801708188361 1.6995109620518646931 1.0668418688004606132 0.062109719212872407934 -0.78557062949754130621 -1.0976378108754849539 1 0 0 0 0 0 0 -5 1 0.65770345007752084587 0.59196795080797459665 1.9145963089956319347 -2.3617582323770536235 -0.91600979005842342318 0.68501446032528301444 1 0 0 0 0 0 0 -6 1 0.99622667537929843196 0.7392929454205859896 0.60969812749036444988 2.0209103733260689317 0.89837585959526122803 -0.70631748122506488041 1 0 0 0 0 0 0 -7 1 2.027328492637660684 0.65440934252588467412 0.51970378261626581917 0.48181202888830071407 -0.16392493695073473425 0.3431947333885322915 1 0 0 0 0 0 0 -8 1 1.6110619393430651858 1.1330702113548116738 2.1797121800639542855 1.3712824023646177363 2.1314929122719386001 2.1546162170900293731 1 0 0 0 0 0 0 -9 1 1.8838335913054302662 2.045198857482267929 2.1296014151485280763 -0.35127549368024091336 -0.51964852490068136337 -0.46559503330595947146 1 0 0 0 0 0 0 -10 1 2.3221196196709903425 2.3795093822947630535 1.0801855040189678459 0.65050748688470483305 -0.53891493799717871127 -0.63971620029506903737 1 0 0 0 0 0 0 -11 1 2.1851002203168206073 1.7046351084251787356 0.17877445783497525333 1.308606690806215056 -1.6109287639500093903 1.4111796504845324218 1 0 0 0 0 0 0 -12 1 0.15102235133673438949 0.10842108748820068753 0.78306635473720986873 0.36374847059148041062 0.22331691539781009515 1.4337552168580240952 1 0 0 0 0 0 0 -13 1 2.7378028356917614161 1.301510644170891462 0.96723024759923237337 -0.54776524033776707867 1.7993921407620585562 -2.6644334440552950305 1 0 0 0 0 0 0 -14 1 3.7458496665804013048 1.3844210574219317778 0.89645393033007536587 -0.80866903081109342555 0.90005320860011328588 -1.1749587939532963876 1 0 0 0 0 0 0 -15 1 4.2653476440444650919 0.43377482352582263925 0.93387624631555776755 -1.4329209659780199893 0.3393980985345660395 -0.056632979622997701996 1 0 0 0 0 0 0 -16 1 3.9851193402072158101 1.8649228102890285097 2.0319444568703191045 0.33464331734314711753 0.29967176433985404094 -0.76021915107732462857 1 0 0 0 0 0 0 -17 1 3.428878806578756322 1.9894165339375988744 0.24652197877382797664 -0.0035878903160999854258 -0.73487173402971572855 0.044228364692880849096 1 0 0 0 0 0 0 -18 1 3.0474575730585242717 0.32782274432827512856 0.78460113496888828077 -0.020236695636267433562 0.38597519143808084463 0.22165998336046152661 1 0 0 0 0 0 0 -19 1 3.4104955999544372958 0.9155617643481979151 1.7386275054408668606 -0.23677685282975227676 -0.13597725488048159614 -0.058470874344615619833 1 0 0 0 0 0 0 diff --git a/examples/simple-boundary-test/ls1config.xml b/examples/simple-boundary-test/ls1config.xml index 5b7401cc9d..2ff015d7f8 100644 --- a/examples/simple-boundary-test/ls1config.xml +++ b/examples/simple-boundary-test/ls1config.xml @@ -13,15 +13,15 @@ 0 0 - 200 + 400 1.1 - 20 - 20 - 20 + 10 + 10 + 10 @@ -40,8 +40,8 @@ - 22 1 - periodicreflectingoutflow + 11 1 + reflectivereflectivereflective diff --git a/examples/simple-boundary-test/simple_checkpoint.inp b/examples/simple-boundary-test/simple_checkpoint.inp index dc9632b574..1da67c4a9c 100644 --- a/examples/simple-boundary-test/simple_checkpoint.inp +++ b/examples/simple-boundary-test/simple_checkpoint.inp @@ -1,32 +1,21 @@ mardyn trunk 20120726 currentTime 0 -Length 20 20 20 +Length 10 10 10 Temperature 1.1 NumberOfComponents 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1e+10 -NumberOfMolecules 20 +NumberOfMolecules 10 MoleculeFormat IRV -0 0.495023130681126800 1.769783381923575982 2.028459061539174435 -1.822950647035876726 1.933108883878859707 -1.247479613481441652 -1 1.666902289161833917 0.251548695399434363 1.539818418524745658 0.161786626031291930 1.405934354571577449 0.040477381848499375 -2 1.521644980017457405 1.521122184006463263 1.236726790577654445 0.917900648354828430 0.088832542456655561 -0.322355334716117325 -3 1.168739293122478928 2.207095133951280097 0.137498901779552762 -1.238237081130751926 0.824091951875207451 -1.393047606478275968 -4 0.413034045989151000 1.703482886840757882 1.071909164239454260 0.061052133396027539 -0.777952474274995032 -0.892174989916953098 -5 0.669926890252636409 0.596756192180819656 1.910988818406699430 -2.441868942606676196 -0.966112268211709035 0.735244244766940946 -6 0.985706008329942263 0.734732924753132011 0.613416822128000416 2.109936801929042094 0.892562783856633679 -0.756500545579516626 -7 2.024883837684851251 0.655224955884165072 0.517923501538259168 0.482343678913160712 -0.159269962164721030 0.356236835024475840 -8 1.603763777455249340 1.121356234421131859 2.168767437762714412 1.487629417187438241 2.445558985257139994 2.144651500768343766 -9 1.885850726602712690 2.048554252728604474 2.131951664636667410 -0.433649548613340874 -0.770578472330007203 -0.461386110163174823 -10 2.318740948078676478 2.382226451453307359 1.083495426816144525 0.678716993010245351 -0.528632663058676844 -0.661702674380576061 -11 2.178270331926622561 1.713016076999506643 0.171429381334559205 1.370070492693730158 -1.679782668506980547 1.468184943400678844 -12 0.149111661740284146 0.107249999693601050 0.775689695391597933 0.391452387594801832 0.240119875907177566 1.467340983915756514 -13 2.740437165984020762 1.292364430622112259 0.981165383835134741 -0.478637099342237027 1.789034980167728550 -2.806678834058749406 -14 3.750564619815982326 1.379364929250165517 0.902946608122211725 -1.037764094756559174 1.067623659752375831 -1.354150887333365194 -15 4.272720921989165532 0.432002065693436799 0.934187032815462115 -1.467508125738746561 0.358550665287694525 -0.065674309465818093 -16 3.983367130221580066 1.863344701744039433 2.035834014281116655 0.354638734151996371 0.321143357882705760 -0.769572589664034523 -17 3.428555648982378745 1.993724265656156458 0.245752545138458400 0.121685283873803327 -0.941923889757456001 0.239060361198430410 -18 3.047656038353257824 0.325743687754526556 0.783463768955406037 -0.058874143456041472 0.435127946587492986 0.226702582353335791 -19 3.411674504194637247 0.916158055315752895 1.739072582267308986 -0.226836548364954649 -0.093938776337105179 -0.124589539374959701 -20 3.530783156876641460 2.430364628092342105 1.251653022914280156 -0.502785611791367049 -2.307545880295731155 0.570935632592190045 +0 7.5 5 5 -3 0 0 +1 2.5 5 5 0 0 0 +2 2.5 7.5 5 0 0 0 +3 2.5 2.5 5 0 0 0 +4 2.5 5 2.5 0 0 0 +5 2.5 5 7.5 0 0 0 +6 2.5 7.5 7.5 0 0 0 +7 2.5 7.5 2.5 0 0 0 +8 2.5 2.5 7.5 0 0 0.69 +9 2.5 2.5 2.5 0 -1.1 -1 diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 64f19c1ec2..7822459d42 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -100,7 +100,7 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) } else { - moleculeContainer->deleteMolecule(it, true); + moleculeContainer->deleteMolecule(it, false); } } } @@ -111,4 +111,5 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) Simulation::exit(1); } } + return true; } \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 5894fc83af..698f269005 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -169,6 +169,7 @@ bool BoundaryUtils::setRegionToParams(double* givenRegionBegin, double* givenReg case DimensionType::NEGY: case DimensionType::NEGZ: returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1] + regionWidth; + break; default: return false; From 383495fda37dc9c15220dbf25f96d0d67cfc4618 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 5 Apr 2023 13:39:34 +0200 Subject: [PATCH 15/94] removed debug, tested for 8x8 --- examples/simple-boundary-test/ls1config.xml | 14 ++++++++++++-- src/parallel/DomainDecompBase.cpp | 8 ++++---- src/parallel/boundaries/BoundaryHandler.cpp | 4 ++-- src/parallel/boundaries/BoundaryUtils.cpp | 6 +++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/examples/simple-boundary-test/ls1config.xml b/examples/simple-boundary-test/ls1config.xml index 2ff015d7f8..7f05d09852 100644 --- a/examples/simple-boundary-test/ls1config.xml +++ b/examples/simple-boundary-test/ls1config.xml @@ -13,7 +13,7 @@ 0 0 - 400 + 800 @@ -40,7 +40,7 @@ - 11 1 + 22 2 reflectivereflectivereflective @@ -57,6 +57,16 @@ vtkOutput 1 + + diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index b118268d97..019d4f04f2 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -41,12 +41,12 @@ void DomainDecompBase::processBoundaryConditions(Domain* domain, Ensemble* ensem double* globStartRegion = ensemble->domain()->rmin(); double* globEndRegion = ensemble->domain()->rmax(); - global_log->set_mpi_output_all(); - global_log->info() << "local: " << startRegion[0] << " " << startRegion[1] << " " << startRegion[2] << " " + //global_log->set_mpi_output_all(); + /**global_log->info() << "local: " << startRegion[0] << " " << startRegion[1] << " " << startRegion[2] << " " << endRegion[0] << " " << endRegion[1] << " " << endRegion[2] << " " << "global: " << globStartRegion[0] << " " << globStartRegion[1] << " " << globStartRegion[2] << " " << globEndRegion[0] << " " << globEndRegion[1] << " " << globEndRegion[2] << " " << std::endl; - + **/ std::map isOuterWall {{DimensionType::POSX, endRegion[0] == globEndRegion[0]}, @@ -60,7 +60,7 @@ void DomainDecompBase::processBoundaryConditions(Domain* domain, Ensemble* ensem boundaryHandler.setOuterWalls(isOuterWall); boundaryHandler.processBoundaries(startRegion, endRegion); - global_log->set_mpi_output_root(); + //global_log->set_mpi_output_root(); } void DomainDecompBase::addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer) { diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 7822459d42..6f53eaecc8 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -60,12 +60,12 @@ bool BoundaryHandler::hasInvalidBoundary() const bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) { - auto moleculeContainer = global_simulation->getMoleculeContainer(); + auto moleculeContainer = global_simulation->getMoleculeContainer(); // :-( double timestepLength = (global_simulation->getIntegrator())->getTimestepLength(); double cutoff = moleculeContainer->getCutoff(); for (auto const& currentWall : isOuterWall) { - global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; + //global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; if(!currentWall.second) continue; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 698f269005..6e431db956 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -60,6 +60,7 @@ DimensionType BoundaryUtils::convertNumericToDimension(int dim) default: return DimensionType::POSZ; //case 3 } } + return DimensionType::ERROR; } std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) @@ -180,8 +181,11 @@ bool BoundaryUtils::setRegionToParams(double* givenRegionBegin, double* givenReg bool BoundaryUtils::isMoleculeLeaving(Molecule molecule, double* regionBegin, double* regionEnd, DimensionType dimension, double timestepLength) { int ls1dim = convertDimensionToLS1Dims(dimension); + int direction = findSign(dimension); double newPos = molecule.r(ls1dim) + (timestepLength * molecule.v(ls1dim)); - if(newPos < regionBegin[ls1dim] || newPos > regionEnd[ls1dim]) + if (newPos < regionBegin[ls1dim] && direction < 0) + return true; + if (newPos > regionEnd[ls1dim] && direction > 0) return true; return false; } From a78a2f4123e42ee0570895ea1eb493341c5ab08d Mon Sep 17 00:00:00 2001 From: amartyads Date: Sat, 15 Apr 2023 02:06:45 +0200 Subject: [PATCH 16/94] halo removal PoC --- src/Simulation.cpp | 2 + src/parallel/DomainDecompBase.cpp | 13 +++-- src/parallel/DomainDecompBase.h | 2 + src/parallel/boundaries/BoundaryHandler.cpp | 62 ++++++++++++++++++++- src/parallel/boundaries/BoundaryHandler.h | 2 + src/parallel/boundaries/BoundaryUtils.cpp | 34 ++++++++++- src/parallel/boundaries/BoundaryUtils.h | 3 +- 7 files changed, 111 insertions(+), 7 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index d14e498f7d..bc93331e3b 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -1077,6 +1077,8 @@ void Simulation::simulate() { decompositionTimer->stop(); + _domainDecomposition->removeNonPeriodicHalos(_domain); + // Force calculation and other pair interaction related computations global_log->debug() << "Traversing pairs" << endl; computationTimer->start(); diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 019d4f04f2..5b3ed526c2 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -34,10 +34,7 @@ void DomainDecompBase::setBoundaryType(DimensionType dimension, BoundaryType bou void DomainDecompBase::processBoundaryConditions(Domain* domain, Ensemble* ensemble) { //find which walls to consider double startRegion[3], endRegion[3]; - for(int d = 0; d < 3; d++) { - startRegion[d] = getBoundingBoxMin(d, domain); - endRegion[d] = getBoundingBoxMax(d, domain); - } + getBoundingBoxMinMax(domain, startRegion, endRegion); double* globStartRegion = ensemble->domain()->rmin(); double* globEndRegion = ensemble->domain()->rmax(); @@ -62,6 +59,14 @@ void DomainDecompBase::processBoundaryConditions(Domain* domain, Ensemble* ensem //global_log->set_mpi_output_root(); } + +void DomainDecompBase::removeNonPeriodicHalos(Domain* domain) +{ + double startRegion[3], endRegion[3]; + getBoundingBoxMinMax(domain, startRegion, endRegion); + boundaryHandler.removeHalos(startRegion, endRegion); +} + void DomainDecompBase::addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer) { for (auto& molecule : invalidMolecules) { diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index e135849aca..c0536742ba 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -297,6 +297,8 @@ class DomainDecompBase: public MemoryProfilable { void processBoundaryConditions(Domain* domain, Ensemble* _ensemble); + void removeNonPeriodicHalos(Domain* domain); + protected: void addLeavingMolecules(std::vector&& invalidMolecules, ParticleContainer* moleculeContainer); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 6f53eaecc8..3be1628b06 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -47,6 +47,23 @@ void BoundaryHandler::setBoundary(DimensionType dimension, BoundaryType value) boundaries[dimension] = value; } +BoundaryType BoundaryHandler::getBoundary(int dimension) const +{ + DimensionType toRet = DimensionType::ERROR; + switch(dimension) + { + case 0: + toRet = DimensionType::POSX; + break; + case 1: + toRet = DimensionType::POSY; + break; + default: //case 2: + toRet = DimensionType::POSZ; + } + return boundaries.at(toRet); +} + bool BoundaryHandler::hasInvalidBoundary() const { return boundaries.at(DimensionType::POSX) == BoundaryType::ERROR || @@ -80,7 +97,7 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) { //create region double curWallRegionBegin[3], curWallRegionEnd[3]; - bool successRegionSet = BoundaryUtils::setRegionToParams(startRegion, endRegion, currentWall.first, cutoff, curWallRegionBegin, curWallRegionEnd); + bool successRegionSet = BoundaryUtils::getInnerBuffer(startRegion, endRegion, currentWall.first, cutoff, curWallRegionBegin, curWallRegionEnd); if (!successRegionSet) { global_log->error() << "Error while setting the region for boundary conditions " << std::endl; @@ -112,4 +129,47 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) } } return true; +} + +void BoundaryHandler::removeHalos(double* startRegion, double* endRegion) +{ + auto moleculeContainer = global_simulation->getMoleculeContainer(); + double cutoff = moleculeContainer->getCutoff(); + for (auto const& currentWall : isOuterWall) + { + //global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; + if(!currentWall.second) //not an outer wall + continue; + + switch(getBoundary(currentWall.first)) + { + case BoundaryType::PERIODIC: + //default behaviour + break; + + case BoundaryType::OUTFLOW: + case BoundaryType::REFLECTING: + { + //create region + double curWallRegionBegin[3], curWallRegionEnd[3]; + bool successRegionSet = BoundaryUtils::getOuterBuffer(startRegion, endRegion, currentWall.first, cutoff, curWallRegionBegin, curWallRegionEnd); + if (!successRegionSet) + { + global_log->error() << "Error while setting the halo region for boundary conditions " << std::endl; + Simulation::exit(1); + } + auto particlesInRegion = moleculeContainer->regionIterator(curWallRegionBegin, curWallRegionEnd, ParticleIterator::ALL_CELLS); + for (auto it = particlesInRegion; it.isValid(); ++it) + { + global_log->info() << "Halo particle found " << std::endl; + moleculeContainer->deleteMolecule(it, false); + } + break; + } + default: + global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + Simulation::exit(1); + } + } + moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); } \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 274c5743ef..bdb56df524 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -22,10 +22,12 @@ class BoundaryHandler void setBoundary(std::string dimension, BoundaryType value); BoundaryType getBoundary(DimensionType dimension) const; void setBoundary(DimensionType dimension, BoundaryType value); + BoundaryType getBoundary(int dimension) const; bool hasInvalidBoundary() const; void setOuterWalls(std::map isOuterWallOth) {isOuterWall = isOuterWallOth;} bool processBoundaries(double* startRegion, double* endRegion); + void removeHalos(double* startRegion, double* endRegion); private: std::map boundaries; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 6e431db956..204c1e20d4 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -147,7 +147,7 @@ BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) return BoundaryType::ERROR; } -bool BoundaryUtils::setRegionToParams(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, +bool BoundaryUtils::getInnerBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd) { for (int i = 0; i < 3; i++) @@ -189,3 +189,35 @@ bool BoundaryUtils::isMoleculeLeaving(Molecule molecule, double* regionBegin, do return true; return false; } + +bool BoundaryUtils::getOuterBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, + double regionWidth, double* returnRegionBegin, double* returnRegionEnd) { + for (int i = 0; i < 3; i++) + { + returnRegionBegin[i] = givenRegionBegin[i]; + returnRegionEnd[i] = givenRegionEnd[i]; + } + + int dimensionLS1 = convertDimensionToLS1Dims(dimension); + + switch (dimension) //can be done with findsign() too, but this is clearer + { + case DimensionType::POSX: + case DimensionType::POSY: + case DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1] + regionWidth; + break; + + case DimensionType::NEGX: + case DimensionType::NEGY: + case DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1] - regionWidth; + break; + + default: + return false; + } + return true; +} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 0a2a2fc3f3..201a3ce181 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -26,8 +26,9 @@ namespace BoundaryUtils BoundaryType convertStringToBoundary(std::string boundary); - bool setRegionToParams(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd); + bool getInnerBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd); bool isMoleculeLeaving(Molecule molecule, double* regionBegin, double* regionEnd, DimensionType dimension, double timestepLength); + bool getOuterBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd); inline int findSign(int n) { return n < 0 ? -1 : 1; } inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } From c765df47672106fb92d747de6ca63f30aa5f67f7 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 17 Apr 2023 12:50:24 +0200 Subject: [PATCH 17/94] cleanup. modern arrays --- src/parallel/DomainDecompBase.cpp | 14 +++++++-- src/parallel/boundaries/BoundaryHandler.cpp | 34 ++++++++++----------- src/parallel/boundaries/BoundaryHandler.h | 5 +-- src/parallel/boundaries/BoundaryUtils.cpp | 32 +++++++++++++------ src/parallel/boundaries/BoundaryUtils.h | 12 +++++--- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 5b3ed526c2..d60fde29b9 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -55,7 +55,12 @@ void DomainDecompBase::processBoundaryConditions(Domain* domain, Ensemble* ensem boundaryHandler.setOuterWalls(isOuterWall); - boundaryHandler.processBoundaries(startRegion, endRegion); + + std::array modernStyleStartRegion, modernStyleEndRegion; + std::move(std::begin(startRegion), std::end(startRegion), modernStyleStartRegion.begin()); + std::move(std::begin(endRegion), std::end(endRegion), modernStyleEndRegion.begin()); + + boundaryHandler.processBoundaries(modernStyleStartRegion, modernStyleEndRegion); //global_log->set_mpi_output_root(); } @@ -64,7 +69,12 @@ void DomainDecompBase::removeNonPeriodicHalos(Domain* domain) { double startRegion[3], endRegion[3]; getBoundingBoxMinMax(domain, startRegion, endRegion); - boundaryHandler.removeHalos(startRegion, endRegion); + + std::array modernStyleStartRegion, modernStyleEndRegion; + std::move(std::begin(startRegion), std::end(startRegion), modernStyleStartRegion.begin()); + std::move(std::begin(endRegion), std::end(endRegion), modernStyleEndRegion.begin()); + + boundaryHandler.processBoundaries(modernStyleStartRegion, modernStyleEndRegion); } void DomainDecompBase::addLeavingMolecules(std::vector&& invalidMolecules, diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 3be1628b06..f01be86c79 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -75,7 +75,7 @@ bool BoundaryHandler::hasInvalidBoundary() const } -bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) +bool BoundaryHandler::processBoundaries(std::array startRegion, std::array endRegion) { auto moleculeContainer = global_simulation->getMoleculeContainer(); // :-( double timestepLength = (global_simulation->getIntegrator())->getTimestepLength(); @@ -96,14 +96,13 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) case BoundaryType::REFLECTING: { //create region - double curWallRegionBegin[3], curWallRegionEnd[3]; - bool successRegionSet = BoundaryUtils::getInnerBuffer(startRegion, endRegion, currentWall.first, cutoff, curWallRegionBegin, curWallRegionEnd); - if (!successRegionSet) - { - global_log->error() << "Error while setting the region for boundary conditions " << std::endl; - Simulation::exit(1); - } - auto particlesInRegion = moleculeContainer->regionIterator(curWallRegionBegin, curWallRegionEnd, ParticleIterator::ONLY_INNER_AND_BOUNDARY); + std::array curWallRegionBegin, curWallRegionEnd; + std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getInnerBuffer(startRegion, endRegion, currentWall.first, cutoff); + //conversion + const double cstylerbegin[] = {curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; + const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; + + auto particlesInRegion = moleculeContainer->regionIterator(cstylerbegin, cstylerend, ParticleIterator::ONLY_INNER_AND_BOUNDARY); for (auto it = particlesInRegion; it.isValid(); ++it) { Molecule curMolecule = *it; @@ -131,7 +130,7 @@ bool BoundaryHandler::processBoundaries(double* startRegion, double* endRegion) return true; } -void BoundaryHandler::removeHalos(double* startRegion, double* endRegion) +void BoundaryHandler::removeHalos(std::array startRegion, std::array endRegion) { auto moleculeContainer = global_simulation->getMoleculeContainer(); double cutoff = moleculeContainer->getCutoff(); @@ -151,14 +150,13 @@ void BoundaryHandler::removeHalos(double* startRegion, double* endRegion) case BoundaryType::REFLECTING: { //create region - double curWallRegionBegin[3], curWallRegionEnd[3]; - bool successRegionSet = BoundaryUtils::getOuterBuffer(startRegion, endRegion, currentWall.first, cutoff, curWallRegionBegin, curWallRegionEnd); - if (!successRegionSet) - { - global_log->error() << "Error while setting the halo region for boundary conditions " << std::endl; - Simulation::exit(1); - } - auto particlesInRegion = moleculeContainer->regionIterator(curWallRegionBegin, curWallRegionEnd, ParticleIterator::ALL_CELLS); + std::array curWallRegionBegin, curWallRegionEnd; + std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getInnerBuffer(startRegion, endRegion, currentWall.first, cutoff); + //conversion + const double cstylerbegin[] = {curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; + const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; + + auto particlesInRegion = moleculeContainer->regionIterator(cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); for (auto it = particlesInRegion; it.isValid(); ++it) { global_log->info() << "Halo particle found " << std::endl; diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index bdb56df524..1ae9dc77dc 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "BoundaryType.h" #include "DimensionType.h" @@ -26,8 +27,8 @@ class BoundaryHandler bool hasInvalidBoundary() const; void setOuterWalls(std::map isOuterWallOth) {isOuterWall = isOuterWallOth;} - bool processBoundaries(double* startRegion, double* endRegion); - void removeHalos(double* startRegion, double* endRegion); + bool processBoundaries(std::array startRegion, std::array endRegion); + void removeHalos(std::array startRegion, std::array endRegion); private: std::map boundaries; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 204c1e20d4..25659f00f2 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -3,6 +3,8 @@ #include "BoundaryUtils.h" + +#include "Simulation.h" #include "utils/Logger.h" bool BoundaryUtils::checkIfDimensionStringPermissible(std::string dimension) @@ -19,6 +21,7 @@ DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) { if(checkIfDimensionStringPermissible(dimension)) { Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Simulation::exit(1); return DimensionType::ERROR; } if(dimension == "+x") @@ -40,6 +43,7 @@ DimensionType BoundaryUtils::convertNumericToDimension(int dim) if(checkIfDimensionNumericPermissible(dim)) { Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Simulation::exit(1); return DimensionType::ERROR; } switch(findSign(dim)) @@ -59,6 +63,9 @@ DimensionType BoundaryUtils::convertNumericToDimension(int dim) case 2: return DimensionType::POSY; default: return DimensionType::POSZ; //case 3 } + default: //should never happen + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Simulation::exit(1); } return DimensionType::ERROR; } @@ -87,6 +94,7 @@ std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) default: Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Simulation::exit(1); return "error"; } } @@ -120,6 +128,7 @@ int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) default: Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Simulation::exit(1); return 0; } } @@ -147,9 +156,10 @@ BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) return BoundaryType::ERROR; } -bool BoundaryUtils::getInnerBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, - double* returnRegionBegin, double* returnRegionEnd) +std::tuple, std::array> BoundaryUtils::getInnerBuffer(const std::array givenRegionBegin, + const std::array givenRegionEnd, DimensionType dimension, double regionWidth) { + std::array returnRegionBegin, returnRegionEnd; for (int i = 0; i < 3; i++) { returnRegionBegin[i] = givenRegionBegin[i]; @@ -173,12 +183,13 @@ bool BoundaryUtils::getInnerBuffer(double* givenRegionBegin, double* givenRegion break; default: - return false; + Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; + Simulation::exit(1); } - return true; + return std::make_tuple(returnRegionBegin, returnRegionEnd); } -bool BoundaryUtils::isMoleculeLeaving(Molecule molecule, double* regionBegin, double* regionEnd, +bool BoundaryUtils::isMoleculeLeaving(const Molecule molecule, const std::array regionBegin, const std::array regionEnd, DimensionType dimension, double timestepLength) { int ls1dim = convertDimensionToLS1Dims(dimension); int direction = findSign(dimension); @@ -190,8 +201,10 @@ bool BoundaryUtils::isMoleculeLeaving(Molecule molecule, double* regionBegin, do return false; } -bool BoundaryUtils::getOuterBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, - double regionWidth, double* returnRegionBegin, double* returnRegionEnd) { +std::tuple, std::array> BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, + const std::array givenRegionEnd, DimensionType dimension, double regionWidth) +{ + std::array returnRegionBegin, returnRegionEnd; for (int i = 0; i < 3; i++) { returnRegionBegin[i] = givenRegionBegin[i]; @@ -217,7 +230,8 @@ bool BoundaryUtils::getOuterBuffer(double* givenRegionBegin, double* givenRegion break; default: - return false; + Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; + Simulation::exit(1); } - return true; + return std::make_tuple(returnRegionBegin, returnRegionEnd); } diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 201a3ce181..16ad38a98e 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -1,6 +1,8 @@ #include #include +#include +#include #include "BoundaryType.h" #include "DimensionType.h" @@ -9,8 +11,8 @@ namespace BoundaryUtils { - const std::vector permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; - const std::vector permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; + const std::array permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; + const std::array permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; bool checkIfDimensionStringPermissible(std::string dimension); bool checkIfDimensionNumericPermissible(int dim); @@ -26,9 +28,9 @@ namespace BoundaryUtils BoundaryType convertStringToBoundary(std::string boundary); - bool getInnerBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd); - bool isMoleculeLeaving(Molecule molecule, double* regionBegin, double* regionEnd, DimensionType dimension, double timestepLength); - bool getOuterBuffer(double* givenRegionBegin, double* givenRegionEnd, DimensionType dimension, double regionWidth, double* returnRegionBegin, double* returnRegionEnd); + std::tuple, std::array> getInnerBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double regionWidth); + bool isMoleculeLeaving(const Molecule molecule, const std::array regionBegin, const std::array regionEnd, DimensionType dimension, double timestepLength); + std::tuple, std::array> getOuterBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double regionWidth); inline int findSign(int n) { return n < 0 ? -1 : 1; } inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } From 2ae68314948bd2aca53382dd2bf032ebaa9ed85b Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 15 May 2023 14:22:32 +0200 Subject: [PATCH 18/94] bugfix --- examples/simple-boundary-test/ls1config.xml | 18 +++++++++++------- src/parallel/DomainDecompBase.cpp | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/simple-boundary-test/ls1config.xml b/examples/simple-boundary-test/ls1config.xml index 7f05d09852..fb880faeaa 100644 --- a/examples/simple-boundary-test/ls1config.xml +++ b/examples/simple-boundary-test/ls1config.xml @@ -40,10 +40,14 @@ - 22 2 - reflectivereflectivereflective + + + reflectiveoutflowreflective - + 2.2 @@ -53,15 +57,15 @@ - + + particles.bp BP4 1 - --> + 5 False + reflectiveoutflowreflective 1 diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index b29cfcbaf9..429088fde7 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -1,3 +1,10 @@ +/* + * BoundaryUtils.cpp + * + * Created on: 24 March 2023 + * Author: amartyads + */ + #include #include diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index f26757af68..b002eb5580 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -1,3 +1,9 @@ +/* + * BoundaryUtils.h + * + * Created on: 24 March 2023 + * Author: amartyads + */ #include #include From 2efb5b42e43fcb7f7ad222a3f57a392a752ca895 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 19 Jul 2023 17:14:11 +0200 Subject: [PATCH 27/94] option from previous PR --- examples/all-options.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/all-options.xml b/examples/all-options.xml index 241bed68a6..4abbdc5dd6 100644 --- a/examples/all-options.xml +++ b/examples/all-options.xml @@ -178,7 +178,8 @@ 0.0 0.0 0.0 - + + true From fbecbdeb233283f0c2ce407ea2548d69d172ad82 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 19 Jul 2023 17:22:58 +0200 Subject: [PATCH 28/94] some renames --- src/parallel/DomainDecompBase.cpp | 4 +-- src/parallel/boundaries/BoundaryHandler.cpp | 40 ++++++++++----------- src/parallel/boundaries/BoundaryHandler.h | 12 +++---- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 706ea0287d..39175c938f 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -28,7 +28,7 @@ void DomainDecompBase::readXML(XMLfileUnits& /* xmlconfig */) { } void DomainDecompBase::setGlobalBoundaryType(DimensionType dimension, BoundaryType boundary) { - _boundaryHandler.setBoundary(dimension, boundary); + _boundaryHandler.setGlobalWall(dimension, boundary); } void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble) { @@ -321,7 +321,7 @@ void DomainDecompBase::handleDomainLeavingParticlesDirect(const HaloRegion& halo void DomainDecompBase::populateHaloLayerWithCopies(unsigned dim, ParticleContainer* moleculeContainer) const { //reflecting and outflow boundaries do not expect halo particles - if(_boundaryHandler.getBoundary(dim) != BoundaryType::PERIODIC) + if(_boundaryHandler.getGlobalWall(dim) != BoundaryType::PERIODIC) return; double shiftMagnitude = moleculeContainer->getBoundingBoxMax(dim) - moleculeContainer->getBoundingBoxMin(dim); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index a25aa86efc..e9c0569d46 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -15,7 +15,7 @@ #include "utils/Logger.h" -BoundaryHandler::BoundaryHandler() : boundaries{ +BoundaryHandler::BoundaryHandler() : _boundaries{ {DimensionType::POSX, BoundaryType::PERIODIC}, {DimensionType::POSY, BoundaryType::PERIODIC}, {DimensionType::POSZ, BoundaryType::PERIODIC}, {DimensionType::NEGX, BoundaryType::PERIODIC}, {DimensionType::NEGY, BoundaryType::PERIODIC}, {DimensionType::NEGZ, BoundaryType::PERIODIC}, @@ -23,32 +23,32 @@ BoundaryHandler::BoundaryHandler() : boundaries{ } {} -BoundaryType BoundaryHandler::getBoundary(DimensionType dimension) const +BoundaryType BoundaryHandler::getGlobalWall(DimensionType dimension) const { - return boundaries.at(dimension); + return _boundaries.at(dimension); } -BoundaryType BoundaryHandler::getBoundary(std::string dimension) const +BoundaryType BoundaryHandler::getGlobalWall(std::string dimension) const { DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); - return getBoundary(convertedDimension); + return getGlobalWall(convertedDimension); } -BoundaryType BoundaryHandler::getBoundary(int dimension) const +BoundaryType BoundaryHandler::getGlobalWall(int dimension) const { - return getBoundary(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); + return getGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -void BoundaryHandler::setBoundary(DimensionType dimension, BoundaryType value) +void BoundaryHandler::setGlobalWall(DimensionType dimension, BoundaryType value) { if(dimension != DimensionType::ERROR) - boundaries[dimension] = value; + _boundaries[dimension] = value; } -void BoundaryHandler::setBoundary(std::string dimension, BoundaryType value) +void BoundaryHandler::setGlobalWall(std::string dimension, BoundaryType value) { DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); - setBoundary(convertedDimension, value); + setGlobalWall(convertedDimension, value); } void BoundaryHandler::setGlobalRegion(double* start, double* end) @@ -89,12 +89,12 @@ void BoundaryHandler::findOuterWallsInLocalRegion() bool BoundaryHandler::hasInvalidBoundary() const { - return boundaries.at(DimensionType::POSX) == BoundaryType::ERROR || - boundaries.at(DimensionType::POSY) == BoundaryType::ERROR || - boundaries.at(DimensionType::POSZ) == BoundaryType::ERROR || - boundaries.at(DimensionType::NEGX) == BoundaryType::ERROR || - boundaries.at(DimensionType::NEGY) == BoundaryType::ERROR || - boundaries.at(DimensionType::NEGZ) == BoundaryType::ERROR; + return _boundaries.at(DimensionType::POSX) == BoundaryType::ERROR || + _boundaries.at(DimensionType::POSY) == BoundaryType::ERROR || + _boundaries.at(DimensionType::POSZ) == BoundaryType::ERROR || + _boundaries.at(DimensionType::NEGX) == BoundaryType::ERROR || + _boundaries.at(DimensionType::NEGY) == BoundaryType::ERROR || + _boundaries.at(DimensionType::NEGZ) == BoundaryType::ERROR; } bool BoundaryHandler::isOuterWall(DimensionType dimension) const @@ -118,7 +118,7 @@ bool BoundaryHandler::processOuterWallLeavingParticles() if(!currentWall.second) continue; - switch(getBoundary(currentWall.first)) + switch(getGlobalWall(currentWall.first)) { case BoundaryType::PERIODIC: //default behaviour @@ -148,7 +148,7 @@ bool BoundaryHandler::processOuterWallLeavingParticles() if (BoundaryUtils::isMoleculeLeaving(curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength, nextStepVelAdjustment)) { //global_log->info() << "Boundary particle found leaving" << std::endl; - if(getBoundary(currentWall.first) == BoundaryType::REFLECTING) + if(getGlobalWall(currentWall.first) == BoundaryType::REFLECTING) { //global_log->info() << "Reflection particle found " << std::endl; double currentVel = it->v(currentDim); @@ -181,7 +181,7 @@ void BoundaryHandler::removeNonPeriodicHalos() if(!currentWall.second) //not an outer wall continue; - switch(getBoundary(currentWall.first)) + switch(getGlobalWall(currentWall.first)) { case BoundaryType::PERIODIC: //default behaviour diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 28f997b338..05a02ff9c8 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -19,11 +19,11 @@ class BoundaryHandler { public: BoundaryHandler(); - BoundaryType getBoundary(std::string dimension) const; - void setBoundary(std::string dimension, BoundaryType value); - BoundaryType getBoundary(DimensionType dimension) const; - void setBoundary(DimensionType dimension, BoundaryType value); - BoundaryType getBoundary(int dimension) const; + BoundaryType getGlobalWall(std::string dimension) const; + void setGlobalWall(std::string dimension, BoundaryType value); + BoundaryType getGlobalWall(DimensionType dimension) const; + void setGlobalWall(DimensionType dimension, BoundaryType value); + BoundaryType getGlobalWall(int dimension) const; bool hasInvalidBoundary() const; void setGlobalRegion(double* start, double* end); @@ -39,7 +39,7 @@ class BoundaryHandler void removeNonPeriodicHalos(); private: - std::map boundaries; + std::map _boundaries; std::map _isOuterWall; std::array _globalRegionStart, _globalRegionEnd; std::array _localRegionStart, _localRegionEnd; From 2c949326ff8a804a794a48e288e9f2cc51d68141 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 16 Aug 2023 15:08:30 +0200 Subject: [PATCH 29/94] added verlet skin to halo check region --- src/parallel/boundaries/BoundaryHandler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index e9c0569d46..b2a86ab1e5 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -174,7 +174,9 @@ bool BoundaryHandler::processOuterWallLeavingParticles() void BoundaryHandler::removeNonPeriodicHalos() { auto moleculeContainer = global_simulation->getMoleculeContainer(); - double buffers[] = {moleculeContainer->get_halo_L(0), moleculeContainer->get_halo_L(1), moleculeContainer->get_halo_L(2)}; + double buffers[] = {moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), + moleculeContainer->get_halo_L(1) + moleculeContainer->getSkin(), + moleculeContainer->get_halo_L(2) + moleculeContainer->getSkin()}; for (auto const& currentWall : _isOuterWall) { //global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; From eb964bd1eb464ddbd72eb3ea9c46e7753ec5ba0a Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 16 Aug 2023 15:44:15 +0200 Subject: [PATCH 30/94] cleanup --- src/parallel/DomainDecompBase.cpp | 6 ------ src/parallel/boundaries/BoundaryHandler.cpp | 10 ++-------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 39175c938f..3eba6e1624 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -38,12 +38,6 @@ void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* en double* globStartRegion = ensemble->domain()->rmin(); double* globEndRegion = ensemble->domain()->rmax(); - //global_log->set_mpi_output_all(); - /**global_log->info() << "local: " << startRegion[0] << " " << startRegion[1] << " " << startRegion[2] << " " - << endRegion[0] << " " << endRegion[1] << " " << endRegion[2] << " " - << "global: " << globStartRegion[0] << " " << globStartRegion[1] << " " << globStartRegion[2] << " " - << globEndRegion[0] << " " << globEndRegion[1] << " " << globEndRegion[2] << " " << std::endl; - **/ _boundaryHandler.setLocalRegion(startRegion, endRegion); _boundaryHandler.setGlobalRegion(globStartRegion, globEndRegion); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index b2a86ab1e5..e7c93c528d 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -114,8 +114,7 @@ bool BoundaryHandler::processOuterWallLeavingParticles() double cutoff = moleculeContainer->getCutoff(); for (auto const& currentWall : _isOuterWall) { - //global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; - if(!currentWall.second) + if(!currentWall.second) // not an outer wall continue; switch(getGlobalWall(currentWall.first)) @@ -147,16 +146,13 @@ bool BoundaryHandler::processOuterWallLeavingParticles() if (BoundaryUtils::isMoleculeLeaving(curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength, nextStepVelAdjustment)) { - //global_log->info() << "Boundary particle found leaving" << std::endl; if(getGlobalWall(currentWall.first) == BoundaryType::REFLECTING) { - //global_log->info() << "Reflection particle found " << std::endl; double currentVel = it->v(currentDim); it->setv(currentDim, -currentVel-nextStepVelAdjustment-nextStepVelAdjustment); } - else + else // outflow { - //global_log->info() << "Outflow particle found " << std::endl; moleculeContainer->deleteMolecule(it, false); } } @@ -179,7 +175,6 @@ void BoundaryHandler::removeNonPeriodicHalos() moleculeContainer->get_halo_L(2) + moleculeContainer->getSkin()}; for (auto const& currentWall : _isOuterWall) { - //global_log->info() << "wall number " << BoundaryUtils::convertDimensionToString(currentWall.first) << " : " << currentWall.second << std::endl; if(!currentWall.second) //not an outer wall continue; @@ -202,7 +197,6 @@ void BoundaryHandler::removeNonPeriodicHalos() auto particlesInRegion = moleculeContainer->regionIterator(cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); for (auto it = particlesInRegion; it.isValid(); ++it) { - //global_log->info() << "Halo particle found " << std::endl; moleculeContainer->deleteMolecule(it, false); } break; From 31e1e4819275f5fc20076758fa7da2f9ae4438e3 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 27 Sep 2023 12:24:35 +0200 Subject: [PATCH 31/94] do not enter loops if no non-periodic boundary --- src/parallel/DomainDecompBase.cpp | 8 +++++--- src/parallel/boundaries/BoundaryHandler.cpp | 10 ++++++++++ src/parallel/boundaries/BoundaryHandler.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 3eba6e1624..12cf26f396 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -44,12 +44,14 @@ void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* en _boundaryHandler.findOuterWallsInLocalRegion(); } -void DomainDecompBase::processBoundaryConditions() { - _boundaryHandler.processOuterWallLeavingParticles(); +void DomainDecompBase::processBoundaryConditions() { + if(_boundaryHandler.hasNonPeriodicBoundary()) + _boundaryHandler.processOuterWallLeavingParticles(); } void DomainDecompBase::removeNonPeriodicHalos() { - _boundaryHandler.removeNonPeriodicHalos(); + if(_boundaryHandler.hasNonPeriodicBoundary()) + _boundaryHandler.removeNonPeriodicHalos(); } void DomainDecompBase::addLeavingMolecules(std::vector& invalidMolecules, diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index e7c93c528d..7de7a8cfb2 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -97,6 +97,16 @@ bool BoundaryHandler::hasInvalidBoundary() const _boundaries.at(DimensionType::NEGZ) == BoundaryType::ERROR; } +bool BoundaryHandler::hasNonPeriodicBoundary() const +{ + return _boundaries.at(DimensionType::POSX) != BoundaryType::PERIODIC || + _boundaries.at(DimensionType::POSY) != BoundaryType::PERIODIC || + _boundaries.at(DimensionType::POSZ) != BoundaryType::PERIODIC || + _boundaries.at(DimensionType::NEGX) != BoundaryType::PERIODIC || + _boundaries.at(DimensionType::NEGY) != BoundaryType::PERIODIC || + _boundaries.at(DimensionType::NEGZ) != BoundaryType::PERIODIC; +} + bool BoundaryHandler::isOuterWall(DimensionType dimension) const { return _isOuterWall.at(dimension); diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 05a02ff9c8..d03982c636 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -25,6 +25,7 @@ class BoundaryHandler void setGlobalWall(DimensionType dimension, BoundaryType value); BoundaryType getGlobalWall(int dimension) const; bool hasInvalidBoundary() const; + bool hasNonPeriodicBoundary() const; void setGlobalRegion(double* start, double* end); void setLocalRegion(double* start, double* end); From 233c02d566c61f21b6011e5f70af4434e3e0494c Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 19 Feb 2024 16:31:34 +0100 Subject: [PATCH 32/94] boundary files should compile in serial --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f204718945..12e26f2b75 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,7 +17,8 @@ if(NOT ENABLE_MPI) # but include DomainDecompBase* and LoadCalc* list(FILTER MY_SRC_BACK INCLUDE REGEX "/parallel/") - list(FILTER MY_SRC_BACK INCLUDE REGEX "DomainDecompBase|LoadCalc|Zonal|ForceHelper") + + list(FILTER MY_SRC_BACK INCLUDE REGEX "boundaries/|DomainDecompBase|LoadCalc|Zonal|ForceHelper") list(APPEND MY_SRC ${MY_SRC_BACK}) else() if(NOT ENABLE_ALLLBL) From 8523df8b387b221b1d415298468743a315e86624 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 20 Feb 2024 12:28:27 +0100 Subject: [PATCH 33/94] added to comment --- src/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12e26f2b75..1aa8571844 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,9 +15,8 @@ if(NOT ENABLE_MPI) # exclude everything from parallel list(FILTER MY_SRC EXCLUDE REGEX "/parallel/") - # but include DomainDecompBase* and LoadCalc* + # but include DomainDecompBase*, LoadCalc* and Boundary utilities list(FILTER MY_SRC_BACK INCLUDE REGEX "/parallel/") - list(FILTER MY_SRC_BACK INCLUDE REGEX "boundaries/|DomainDecompBase|LoadCalc|Zonal|ForceHelper") list(APPEND MY_SRC ${MY_SRC_BACK}) else() From 0b89f6ecd32a8e335e82d61f5d18aec6025f4bee Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 21 Feb 2024 09:40:43 +0100 Subject: [PATCH 34/94] change to how fpic is enabled --- cmake/modules/mamico.cmake | 21 +++++++++------------ src/CMakeLists.txt | 4 +++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cmake/modules/mamico.cmake b/cmake/modules/mamico.cmake index 5d4a6ed549..6939b2c601 100644 --- a/cmake/modules/mamico.cmake +++ b/cmake/modules/mamico.cmake @@ -1,18 +1,15 @@ option(MAMICO_COUPLING "Couple with MaMiCo" OFF) if (MAMICO_COUPLING) - message(STATUS "MaMiCo coupling enabled. ls1 mardyn will compile as library. No executable will be created.") - set(MAMICO_COMPILE_DEFINITIONS MAMICO_COUPLING MDDim3) - option(MAMICO_ENABLE_FPIC "Enable -fPIC flag for MaMiCo python bindings" OFF) - set(MAMICO_SRC_DIR CACHE PATH "Root directory of the MaMiCo codebase") + message(STATUS "MaMiCo coupling enabled. ls1 mardyn will compile as library. No executable will be created.") + set(MAMICO_COMPILE_DEFINITIONS MAMICO_COUPLING MDDim3) + option(MAMICO_ENABLE_FPIC "Enable -fPIC flag for MaMiCo python bindings" OFF) + set(MAMICO_SRC_DIR CACHE PATH "Root directory of the MaMiCo codebase") if(NOT MAMICO_SRC_DIR) - message(FATAL_ERROR "MaMiCo source directory not specified.") - endif() - if(ENABLE_MPI) - set(MAMICO_MPI_DEFINITIONS MDCoupledParallel TarchParallel) - endif() - if(MAMICO_ENABLE_FPIC) - set(MAMICO_COMPILE_OPTIONS "${MAMICO_COMPILE_OPTIONS} -fPIC") - endif() + message(FATAL_ERROR "MaMiCo source directory not specified.") + endif() + if(ENABLE_MPI) + set(MAMICO_MPI_DEFINITIONS MDCoupledParallel TarchParallel) + endif() else() message(STATUS "MaMiCo coupling disabled.") endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1aa8571844..aed8c32eee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,9 @@ if (MAMICO_COUPLING) TARGET_COMPILE_DEFINITIONS(MarDyn PUBLIC ${MAMICO_COMPILE_DEFINITIONS} ${MAMICO_MPI_DEFINITIONS} ) - TARGET_COMPILE_OPTIONS(MarDyn PUBLIC ${MAMICO_COMPILE_OPTIONS}) + if(MAMICO_ENABLE_FPIC) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() else() ADD_EXECUTABLE(MarDyn ${MY_SRC} From 663745bb88c8f85d9df7abb55b32c74bb7dad03a Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 21 Feb 2024 09:57:56 +0100 Subject: [PATCH 35/94] bugfix --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aed8c32eee..c920774070 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,7 @@ if (MAMICO_COUPLING) ${MAMICO_COMPILE_DEFINITIONS} ${MAMICO_MPI_DEFINITIONS} ) if(MAMICO_ENABLE_FPIC) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) + SET_PROPERTY(TARGET MarDyn PROPERTY POSITION_INDEPENDENT_CODE ON) endif() else() ADD_EXECUTABLE(MarDyn From 6032ae49ad742f9bd595b7b83da38b6bb65b35a4 Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 23 Feb 2024 18:32:22 +0100 Subject: [PATCH 36/94] log namespacing --- src/Simulation.cpp | 8 ++++---- src/parallel/boundaries/BoundaryHandler.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 33947940b1..30e75e7b57 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -432,20 +432,20 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { std::string tempBoundary; //xmlconfig.getNodeValue("boundaryType", tempBoundary); xmlconfig.getNodeValue("x", tempBoundary); - global_log->info() << "x boundary " << tempBoundary << std::endl; + Log::global_log->info() << "x boundary " << tempBoundary << std::endl; _domainDecomposition->setGlobalBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(tempBoundary)); xmlconfig.getNodeValue("y", tempBoundary); - global_log->info() << "y boundary " << tempBoundary << std::endl; + Log::global_log->info() << "y boundary " << tempBoundary << std::endl; _domainDecomposition->setGlobalBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(tempBoundary)); xmlconfig.getNodeValue("z", tempBoundary); - global_log->info() << "z boundary " << tempBoundary << std::endl; + Log::global_log->info() << "z boundary " << tempBoundary << std::endl; _domainDecomposition->setGlobalBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); if (_domainDecomposition->hasInvalidBoundary()) { - global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; + Log::global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; exit(1); } _domainDecomposition->setLocalBoundariesFromGlobal(_domain, _ensemble); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 7de7a8cfb2..0c1b47a5c0 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -170,7 +170,7 @@ bool BoundaryHandler::processOuterWallLeavingParticles() break; } default: - global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; Simulation::exit(1); } } @@ -212,7 +212,7 @@ void BoundaryHandler::removeNonPeriodicHalos() break; } default: - global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; Simulation::exit(1); } } From 9235c87abe6995e7733d6f3ebf9d236d467afbb0 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 26 Feb 2024 11:17:43 +0100 Subject: [PATCH 37/94] changes to names to make plugin work, documentation, clangformat --- src/plugins/MamicoCoupling.cpp | 76 +++++------- src/plugins/MamicoCoupling.h | 215 ++++++++++++++++++--------------- 2 files changed, 150 insertions(+), 141 deletions(-) diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index 4bb5739eef..c7ce4c5711 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -1,64 +1,52 @@ #include "MamicoCoupling.h" #include "Domain.h" -void MamicoCoupling::readXML(XMLfileUnits& xmlconfig) -{ - return; -} +void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) { return; } -void MamicoCoupling::init(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, Domain* domain) -{ +void MamicoCoupling::init(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, Domain *domain) { #ifdef MAMICO_COUPLING - //code to print to log that plugin is initialised - Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; + // code to print to log that plugin is initialised + Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; #endif } -void MamicoCoupling::beforeEventNewTimestep(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, unsigned long simstep) -{ - -} +void MamicoCoupling::beforeEventNewTimestep( + ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, + unsigned long simstep) {} -void MamicoCoupling::beforeForces(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, unsigned long simstep) -{ +void MamicoCoupling::beforeForces(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, + unsigned long simstep) { #ifdef MAMICO_COUPLING - if(_couplingEnabled) - { - // This object should be set by MaMiCo after the plugins are created in the simulation readxml file - // Even though this method is called before the object is set, at this point the coupling switch is always off - _macroscopicCellService->processInnerMacroscopicCellAfterMDTimestep(); - _macroscopicCellService->distributeMass(simstep); - _macroscopicCellService->applyTemperatureToMolecules(simstep); + if (_couplingEnabled) { + // This object should be set by MaMiCo after the plugins are created in the + // simulation readxml file Even though this method is called before the + // object is set, at this point the coupling switch is always off + _couplingCellService->processInnerCouplingCellAfterMDTimestep(); + _couplingCellService->distributeMass(simstep); + _couplingCellService->applyTemperatureToMolecules(simstep); #ifndef MARDYN_AUTOPAS - particleContainer->deleteOuterParticles(); + particleContainer->deleteOuterParticles(); #endif - } + } #endif } -void MamicoCoupling::afterForces(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, unsigned long simstep) -{ +void MamicoCoupling::afterForces(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, + unsigned long simstep) { #ifdef MAMICO_COUPLING - if(_couplingEnabled) - { - _macroscopicCellService->distributeMomentum(simstep); - _macroscopicCellService->applyBoundaryForce(simstep); - } + if (_couplingEnabled) { + _couplingCellService->distributeMomentum(simstep); + _couplingCellService->applyBoundaryForce(simstep); + } #endif } -void MamicoCoupling::endStep(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, Domain* domain, unsigned long simstep) -{ +void MamicoCoupling::endStep(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, Domain *domain, + unsigned long simstep) {} -} - -void MamicoCoupling::finish(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, Domain* domain) -{ - -} +void MamicoCoupling::finish(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, Domain *domain) {} diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index c8a7c2f5c2..a8e921ced6 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -2,114 +2,135 @@ #include "PluginBase.h" #ifdef MAMICO_COUPLING -#include #include +#include #endif -/** @brief Allows execution of MaMiCo code to enable coupling with MaMiCo. - * - * When MaMiCo is coupled with any simulation software, it needs to control the simulation from both the outside and inside. - * From the outside, MaMiCo needs to be able to start and stop the simulation, and keep unique simulations distinct. - * From the inside, MaMiCo code needs to be executed at specific points within the same simulation step. This plugin enables the "inside" behaviour. - * - * MaMiCo coupling requires the MAMICO_COUPLING flag to be set, and the MAMICO_SRD_DIR flag to point to MaMiCo source files. With these enabled, ls1 compiles as a library. - * To make sure the program compiles and works with tests, the relevant MaMiCo portions for the code are put in #ifdef regions. - * - * */ - -class MamicoCoupling: public PluginBase { +/** + * Allows execution of MaMiCo code to enable coupling with MaMiCo. + * + * When MaMiCo is coupled with any simulation software, it needs to control the + * simulation from both the outside and inside. From the outside, MaMiCo needs + * to be able to start and stop the simulation, and keep unique simulations + * distinct. From the inside, MaMiCo code needs to be executed at specific + * points within the same simulation step. This plugin enables the "inside" + * behaviour. + * + * MaMiCo coupling requires the MAMICO_COUPLING flag to be set, and the + * MAMICO_SRD_DIR flag to point to MaMiCo source files. With these enabled, ls1 + * compiles as a library. To make sure the program compiles and works with + * tests, the relevant MaMiCo portions for the code are put in #ifdef regions. + */ + +class MamicoCoupling : public PluginBase { public: - MamicoCoupling() {} - virtual ~MamicoCoupling() {} - - /** @brief Prints to log that mamico coupling is initialized - * - * */ - void init(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, Domain* domain) override; - - - void readXML(XMLfileUnits& xmlconfig) override; - - void beforeEventNewTimestep( - ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, - unsigned long simstep - ) override; - - /** @brief Takes coupling steps such as particle insertion, to make sure they are accounted for before forces are calculated. - * - * Following steps are taken, if coupling is switched on: - * - Iterate over cells to average values like momentum and mass, to pass to macroscopic solvers - * - Distribute incoming mass from macroscopic solver by inserting perticles (if enabled) - * - Run the MaMiCo thermostat cell by cell - * - * The distributeMass method calls the updateParticleContainerAndDecomposition() function at the end, so we end up with a container with halo particles present. - * Hence a manual halo clearance is done to restore the state of the container. - * */ - void beforeForces( - ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, - unsigned long simstep - ) override; - - /** @brief Performs adjustments after force calculation - * - * Following steps are taken, if coupling is switched on: - * - Distribute incoming momentum among affected cells - * - Apply boundary force to molecules near microscopic domain boundary - * */ - void afterForces( - ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, - unsigned long simstep - ) override; - - void endStep( - ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, - Domain* domain, unsigned long simstep) override; - - void finish(ParticleContainer* particleContainer, - DomainDecompBase* domainDecomp, Domain* domain) override; - - std::string getPluginName() override { - return std::string("MamicoCoupling"); - } - - static PluginBase* createInstance() { return new MamicoCoupling(); } + MamicoCoupling() {} + virtual ~MamicoCoupling() {} + + /** + * Prints to log that mamico coupling is initialized + */ + void init(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, Domain *domain) override; + + void readXML(XMLfileUnits &xmlconfig) override; + + void beforeEventNewTimestep(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, + unsigned long simstep) override; + + /** + * Takes coupling steps such as particle insertion, to make sure they are + * accounted for before forces are calculated. + * + * Following steps are taken, if coupling is switched on: + * - Iterate over cells to average values like momentum and mass, to pass to + * macroscopic solvers + * - Distribute incoming mass from macroscopic solver by inserting perticles + * (if enabled) + * - Run the MaMiCo thermostat cell by cell + * + * The distributeMass method calls the + * updateParticleContainerAndDecomposition() function at the end, so we end up + * with a container with halo particles present. Hence a manual halo clearance + * is done to restore the state of the container. + */ + void beforeForces(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, + unsigned long simstep) override; + + /** + * Performs adjustments after force calculation + * + * Following steps are taken, if coupling is switched on: + * - Distribute incoming momentum among affected cells + * - Apply boundary force to molecules near microscopic domain boundary + */ + void afterForces(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, + unsigned long simstep) override; + + void endStep(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, Domain *domain, + unsigned long simstep) override; + + void finish(ParticleContainer *particleContainer, + DomainDecompBase *domainDecomp, Domain *domain) override; + + std::string getPluginName() override { return std::string("MamicoCoupling"); } + + static PluginBase *createInstance() { return new MamicoCoupling(); } #ifdef MAMICO_COUPLING -/** @brief Sets the macroscopicCellService object that controls the inner coupling logic. - * - * MaMiCo extracts the MamicoCoupling plugin object from the simulation object after initialization and uses this function to set the macroscopicCellCervice. - * The code for this object can be found in https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/MacroscopicCellService.cpph - * */ - void setMamicoMacroscopicCellService(coupling::services::MacroscopicCellService<3>* macroscopicCellService){ - _macroscopicCellService = static_cast*> - (macroscopicCellService); - } + /** + * Sets the macroscopicCellService object that controls the inner coupling + * logic. + * + * MaMiCo extracts the MamicoCoupling plugin object from the simulation object + * after initialization and uses this function to set the + * macroscopicCellCervice. The code for this object can be found in + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/MacroscopicCellService.cpph + */ + void setMamicoMacroscopicCellService( + coupling::services::CouplingCellService<3> *couplingCellService) { + _couplingCellService = + static_cast *>(couplingCellService); + } #endif -/** @brief Enables coupling logic, allowing coupling steps to run while simulation is running. - * - * Set from within MaMiCo, check https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, class LS1MDSimulation - * */ - void switchOnCoupling(){ _couplingEnabled = true; } - -/** @brief Disables coupling logic, not allowing coupling steps to run. Typically done when equilibrating the simulation initially. - * - * Set from within MaMiCo, check https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, class LS1MDSimulation - * */ - void switchOffCoupling(){ _couplingEnabled = false; } - -/** @brief Getter method for the coupling state. - * - * Not used currently, but may be used in future - * */ - bool getCouplingState() { return _couplingEnabled;} - + /** + * Enables coupling logic, allowing coupling steps to run while simulation is + * running. + * + * Set from within MaMiCo, check + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, + * class LS1MDSimulation + */ + void switchOnCoupling() { _couplingEnabled = true; } + + /** + * Disables coupling logic, not allowing coupling steps to run. Typically done + * when equilibrating the simulation initially. + * + * Set from within MaMiCo, check + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, + * class LS1MDSimulation + */ + void switchOffCoupling() { _couplingEnabled = false; } + + /** + * Getter method for the coupling state. + * + * Not used currently, but may be used in future + */ + bool getCouplingState() { return _couplingEnabled; } private: #ifdef MAMICO_COUPLING - coupling::services::MacroscopicCellServiceImpl* _macroscopicCellService; + coupling::services::CouplingCellServiceImpl + *_couplingCellService; #endif - bool _couplingEnabled = false; + bool _couplingEnabled = false; }; From a396b71aaba9dff3dd1b327e5ec4af1a191c3e11 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 26 Feb 2024 13:51:11 +0100 Subject: [PATCH 38/94] full plugin now optionally compiled --- src/plugins/MamicoCoupling.cpp | 13 ++++++------- src/plugins/MamicoCoupling.h | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index c7ce4c5711..80dc872e9a 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -1,3 +1,5 @@ +#ifdef MAMICO_COUPLING + #include "MamicoCoupling.h" #include "Domain.h" @@ -5,10 +7,9 @@ void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) { return; } void MamicoCoupling::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { -#ifdef MAMICO_COUPLING - // code to print to log that plugin is initialised + Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; -#endif + } void MamicoCoupling::beforeEventNewTimestep( @@ -18,7 +19,6 @@ void MamicoCoupling::beforeEventNewTimestep( void MamicoCoupling::beforeForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) { -#ifdef MAMICO_COUPLING if (_couplingEnabled) { // This object should be set by MaMiCo after the plugins are created in the // simulation readxml file Even though this method is called before the @@ -30,18 +30,15 @@ void MamicoCoupling::beforeForces(ParticleContainer *particleContainer, particleContainer->deleteOuterParticles(); #endif } -#endif } void MamicoCoupling::afterForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) { -#ifdef MAMICO_COUPLING if (_couplingEnabled) { _couplingCellService->distributeMomentum(simstep); _couplingCellService->applyBoundaryForce(simstep); } -#endif } void MamicoCoupling::endStep(ParticleContainer *particleContainer, @@ -50,3 +47,5 @@ void MamicoCoupling::endStep(ParticleContainer *particleContainer, void MamicoCoupling::finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) {} + +#endif diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index a8e921ced6..8bacdb2aba 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -1,10 +1,11 @@ +#ifdef MAMICO_COUPLING + #pragma once #include "PluginBase.h" -#ifdef MAMICO_COUPLING #include #include -#endif + /** * Allows execution of MaMiCo code to enable coupling with MaMiCo. @@ -29,11 +30,14 @@ class MamicoCoupling : public PluginBase { virtual ~MamicoCoupling() {} /** - * Prints to log that mamico coupling is initialized + * Currently only prints to log that mamico coupling is initialized */ void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override; + /* + * No XML tags defined for this plugin, so does nothing + */ void readXML(XMLfileUnits &xmlconfig) override; void beforeEventNewTimestep(ParticleContainer *particleContainer, @@ -81,8 +85,7 @@ class MamicoCoupling : public PluginBase { std::string getPluginName() override { return std::string("MamicoCoupling"); } static PluginBase *createInstance() { return new MamicoCoupling(); } - -#ifdef MAMICO_COUPLING + /** * Sets the macroscopicCellService object that controls the inner coupling * logic. @@ -90,15 +93,14 @@ class MamicoCoupling : public PluginBase { * MaMiCo extracts the MamicoCoupling plugin object from the simulation object * after initialization and uses this function to set the * macroscopicCellCervice. The code for this object can be found in - * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/MacroscopicCellService.cpph + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/CouplingCellService.cpph */ - void setMamicoMacroscopicCellService( + void setMamicoCouplingCellService( coupling::services::CouplingCellService<3> *couplingCellService) { _couplingCellService = static_cast *>(couplingCellService); } -#endif /** * Enables coupling logic, allowing coupling steps to run while simulation is @@ -128,9 +130,10 @@ class MamicoCoupling : public PluginBase { bool getCouplingState() { return _couplingEnabled; } private: -#ifdef MAMICO_COUPLING coupling::services::CouplingCellServiceImpl *_couplingCellService; -#endif + bool _couplingEnabled = false; }; + +#endif \ No newline at end of file From 4256464c80d5a6f58a602c4fd9632afe8160c1f4 Mon Sep 17 00:00:00 2001 From: Amartya Das Sharma Date: Mon, 26 Feb 2024 13:54:15 +0100 Subject: [PATCH 39/94] Apply Fabio's suggestions from code review Co-authored-by: FG-TUM --- src/plugins/MamicoCoupling.cpp | 2 +- src/plugins/MamicoCoupling.h | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index 80dc872e9a..b78a5e2420 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -3,7 +3,7 @@ #include "MamicoCoupling.h" #include "Domain.h" -void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) { return; } +void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) {} void MamicoCoupling::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index 8bacdb2aba..a57faba865 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -22,12 +22,11 @@ * compiles as a library. To make sure the program compiles and works with * tests, the relevant MaMiCo portions for the code are put in #ifdef regions. */ - class MamicoCoupling : public PluginBase { public: - MamicoCoupling() {} - virtual ~MamicoCoupling() {} + MamicoCoupling() = default; + ~MamicoCoupling() override = default; /** * Currently only prints to log that mamico coupling is initialized @@ -82,7 +81,7 @@ class MamicoCoupling : public PluginBase { void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override; - std::string getPluginName() override { return std::string("MamicoCoupling"); } + std::string getPluginName() override { return "MamicoCoupling"; } static PluginBase *createInstance() { return new MamicoCoupling(); } @@ -127,11 +126,11 @@ class MamicoCoupling : public PluginBase { * * Not used currently, but may be used in future */ - bool getCouplingState() { return _couplingEnabled; } + bool getCouplingState() const { return _couplingEnabled; } private: coupling::services::CouplingCellServiceImpl - *_couplingCellService; + *_couplingCellService = nullptr; bool _couplingEnabled = false; }; From 5bf619aba6d7d4c357cba06d42770bf138b95658 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 19 Mar 2024 11:20:29 +0100 Subject: [PATCH 40/94] move halo removal location --- src/Simulation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 30e75e7b57..67d9ae5dd6 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -1123,10 +1123,6 @@ void Simulation::simulateOneTimestep() global_simulation->timers()->stop("SIMULATION_DECOMPOSITION"); - global_simulation->timers()->start("SIMULATION_BOUNDARY_TREATMENT"); - _domainDecomposition->removeNonPeriodicHalos(); - global_simulation->timers()->stop("SIMULATION_BOUNDARY_TREATMENT"); - // Force calculation and other pair interaction related computations Log::global_log->debug() << "Traversing pairs" << std::endl; global_simulation->timers()->start("SIMULATION_COMPUTATION"); @@ -1407,6 +1403,10 @@ void Simulation::updateParticleContainerAndDecomposition(double lastTraversalTim _domain); global_simulation->timers()->stop("SIMULATION_MPI_OMP_COMMUNICATION"); + global_simulation->timers()->start("SIMULATION_BOUNDARY_TREATMENT"); + _domainDecomposition->removeNonPeriodicHalos(); + global_simulation->timers()->stop("SIMULATION_BOUNDARY_TREATMENT"); + // The cache of the molecules must be updated/build after the exchange process, // as the cache itself isn't transferred global_simulation->timers()->start("SIMULATION_UPDATE_CACHES"); From 1b8adfb92a52495ca0ad0a38b5079ebc56924e79 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 20 Mar 2024 10:35:14 +0100 Subject: [PATCH 41/94] bugfix, clearer function name --- src/parallel/boundaries/BoundaryUtils.cpp | 10 +++++----- src/parallel/boundaries/BoundaryUtils.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 429088fde7..59f08ad256 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -14,18 +14,18 @@ #include "Simulation.h" #include "utils/Logger.h" -bool BoundaryUtils::checkIfDimensionStringPermissible(std::string dimension) +bool BoundaryUtils::isDimensionStringPermissible(std::string dimension) { - return std::find(permissibleDimensionsString.begin(),permissibleDimensionsString.end(),dimension) == permissibleDimensionsString.end(); + return std::find(permissibleDimensionsString.begin(),permissibleDimensionsString.end(),dimension) != permissibleDimensionsString.end(); } -bool BoundaryUtils::checkIfDimensionNumericPermissible(int dim) +bool BoundaryUtils::isDimensionNumericPermissible(int dim) { return (dim >= -3 && dim <= 3 && dim != 0); } DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) { - if(checkIfDimensionStringPermissible(dimension)) + if(!isDimensionStringPermissible(dimension)) { Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; Simulation::exit(1); @@ -47,7 +47,7 @@ DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) { DimensionType BoundaryUtils::convertNumericToDimension(int dim) { - if(checkIfDimensionNumericPermissible(dim)) + if(!isDimensionNumericPermissible(dim)) { Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; Simulation::exit(1); diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index b002eb5580..a434f6ea4b 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -20,8 +20,8 @@ namespace BoundaryUtils const std::array permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; const std::array permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; - bool checkIfDimensionStringPermissible(std::string dimension); - bool checkIfDimensionNumericPermissible(int dim); + bool isDimensionStringPermissible(std::string dimension); + bool isDimensionNumericPermissible(int dim); DimensionType convertStringToDimension(std::string dimension); DimensionType convertNumericToDimension(int dim); From f4592dc83339c0fc296e7e335601edb5440215e9 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 20 Mar 2024 10:49:25 +0100 Subject: [PATCH 42/94] add check for overlappingp2p --- src/Simulation.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 67d9ae5dd6..e9a3e8d2e9 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -429,20 +429,30 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _lastTraversalTimeHistory.setCapacity(timerForLoadAveragingLength); if(xmlconfig.changecurrentnode("boundaries")) { - std::string tempBoundary; - //xmlconfig.getNodeValue("boundaryType", tempBoundary); - xmlconfig.getNodeValue("x", tempBoundary); - Log::global_log->info() << "x boundary " << tempBoundary << std::endl; - _domainDecomposition->setGlobalBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(tempBoundary)); - _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(tempBoundary)); - xmlconfig.getNodeValue("y", tempBoundary); - Log::global_log->info() << "y boundary " << tempBoundary << std::endl; - _domainDecomposition->setGlobalBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(tempBoundary)); - _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(tempBoundary)); - xmlconfig.getNodeValue("z", tempBoundary); - Log::global_log->info() << "z boundary " << tempBoundary << std::endl; - _domainDecomposition->setGlobalBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); - _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(tempBoundary)); + std::string xBoundary, yBoundary, zBoundary; + if(_overlappingP2P) + { + Log::global_log->info() << "Non-periodic boundaries not supported with overlappingP2P enabled! Defaulting to periodic boundaries" << std::endl; + xBoundary = yBoundary = zBoundary = "periodic"; + } + else + { + xmlconfig.getNodeValue("x", xBoundary); + xmlconfig.getNodeValue("y", yBoundary); + xmlconfig.getNodeValue("z", zBoundary); + } + + Log::global_log->info() << "x boundary " << xBoundary << std::endl; + _domainDecomposition->setGlobalBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(xBoundary)); + _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(xBoundary)); + + Log::global_log->info() << "y boundary " << yBoundary << std::endl; + _domainDecomposition->setGlobalBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(yBoundary)); + _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(yBoundary)); + + Log::global_log->info() << "z boundary " << zBoundary << std::endl; + _domainDecomposition->setGlobalBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(zBoundary)); + _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(zBoundary)); if (_domainDecomposition->hasInvalidBoundary()) { Log::global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; From e098a258d094bac2aef5fcf62e1219bff9fa1b99 Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 9 Aug 2024 10:38:13 +0200 Subject: [PATCH 43/94] comments by Christoph, static codecheck pass --- src/plugins/MamicoCoupling.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index a57faba865..a1e24c033f 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -28,9 +28,6 @@ class MamicoCoupling : public PluginBase { MamicoCoupling() = default; ~MamicoCoupling() override = default; - /** - * Currently only prints to log that mamico coupling is initialized - */ void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override; @@ -135,4 +132,4 @@ class MamicoCoupling : public PluginBase { bool _couplingEnabled = false; }; -#endif \ No newline at end of file +#endif From 53a9b47bd74ef835eeafd7333d8f3a9cebfe1d2e Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 9 Aug 2024 11:33:12 +0200 Subject: [PATCH 44/94] removed simulation::exit --- src/parallel/boundaries/BoundaryHandler.cpp | 4 ++-- src/parallel/boundaries/BoundaryUtils.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 0c1b47a5c0..163be47ae5 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -171,7 +171,7 @@ bool BoundaryHandler::processOuterWallLeavingParticles() } default: Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; - Simulation::exit(1); + mardyn_exit(1); } } return true; @@ -213,7 +213,7 @@ void BoundaryHandler::removeNonPeriodicHalos() } default: Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; - Simulation::exit(1); + mardyn_exit(1); } } #ifndef MARDYN_AUTOPAS diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 59f08ad256..6f9de0bd1d 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -28,7 +28,7 @@ DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) { if(!isDimensionStringPermissible(dimension)) { Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - Simulation::exit(1); + mardyn_exit(1); return DimensionType::ERROR; } if(dimension == "+x") @@ -50,7 +50,7 @@ DimensionType BoundaryUtils::convertNumericToDimension(int dim) if(!isDimensionNumericPermissible(dim)) { Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - Simulation::exit(1); + mardyn_exit(1); return DimensionType::ERROR; } switch(findSign(dim)) @@ -72,7 +72,7 @@ DimensionType BoundaryUtils::convertNumericToDimension(int dim) } default: //should never happen Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - Simulation::exit(1); + mardyn_exit(1); } return DimensionType::ERROR; } @@ -132,7 +132,7 @@ std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) default: Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - Simulation::exit(1); + mardyn_exit(1); return "error"; } } @@ -166,7 +166,7 @@ int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) default: Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - Simulation::exit(1); + mardyn_exit(1); return 0; } } @@ -222,7 +222,7 @@ std::tuple, std::array> BoundaryUtils::getInner default: Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; - Simulation::exit(1); + mardyn_exit(1); } return std::make_tuple(returnRegionBegin, returnRegionEnd); } @@ -278,7 +278,7 @@ std::tuple, std::array> BoundaryUtils::getOuterBu default: Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; - Simulation::exit(1); + mardyn_exit(1); } return std::make_tuple(returnRegionBegin, returnRegionEnd); } From 39a3a83f0725f910a5ea4c3c85772151794c60d5 Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 9 Aug 2024 12:26:54 +0200 Subject: [PATCH 45/94] clangformat --- src/plugins/MamicoCoupling.cpp | 2 -- src/plugins/MamicoCoupling.h | 7 +++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index b78a5e2420..1181ac7120 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -7,9 +7,7 @@ void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) {} void MamicoCoupling::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { - Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; - } void MamicoCoupling::beforeEventNewTimestep( diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index a1e24c033f..12195b295e 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -6,7 +6,6 @@ #include #include - /** * Allows execution of MaMiCo code to enable coupling with MaMiCo. * @@ -32,8 +31,8 @@ class MamicoCoupling : public PluginBase { DomainDecompBase *domainDecomp, Domain *domain) override; /* - * No XML tags defined for this plugin, so does nothing - */ + * No XML tags defined for this plugin, so does nothing + */ void readXML(XMLfileUnits &xmlconfig) override; void beforeEventNewTimestep(ParticleContainer *particleContainer, @@ -81,7 +80,7 @@ class MamicoCoupling : public PluginBase { std::string getPluginName() override { return "MamicoCoupling"; } static PluginBase *createInstance() { return new MamicoCoupling(); } - + /** * Sets the macroscopicCellService object that controls the inner coupling * logic. From 7d25c51fd1debc62a0a357dea6bfc1a6177d3fbd Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 9 Aug 2024 12:31:21 +0200 Subject: [PATCH 46/94] clangformat --- src/plugins/MamicoCoupling.cpp | 2 -- src/plugins/MamicoCoupling.h | 7 +++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index b78a5e2420..1181ac7120 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -7,9 +7,7 @@ void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) {} void MamicoCoupling::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { - Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; - } void MamicoCoupling::beforeEventNewTimestep( diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index a1e24c033f..12195b295e 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -6,7 +6,6 @@ #include #include - /** * Allows execution of MaMiCo code to enable coupling with MaMiCo. * @@ -32,8 +31,8 @@ class MamicoCoupling : public PluginBase { DomainDecompBase *domainDecomp, Domain *domain) override; /* - * No XML tags defined for this plugin, so does nothing - */ + * No XML tags defined for this plugin, so does nothing + */ void readXML(XMLfileUnits &xmlconfig) override; void beforeEventNewTimestep(ParticleContainer *particleContainer, @@ -81,7 +80,7 @@ class MamicoCoupling : public PluginBase { std::string getPluginName() override { return "MamicoCoupling"; } static PluginBase *createInstance() { return new MamicoCoupling(); } - + /** * Sets the macroscopicCellService object that controls the inner coupling * logic. From 5bc422df1c38071c0066f9ca750ff7774401812d Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 2 Sep 2024 16:15:24 +0200 Subject: [PATCH 47/94] move enums, remove files, clangformat --- src/Simulation.cpp | 12 +- src/parallel/DomainDecompBase.cpp | 4 +- src/parallel/DomainDecompBase.h | 2 +- src/parallel/boundaries/BoundaryHandler.cpp | 383 ++++++++------- src/parallel/boundaries/BoundaryHandler.h | 63 +-- src/parallel/boundaries/BoundaryType.h | 16 - src/parallel/boundaries/BoundaryUtils.cpp | 492 ++++++++++---------- src/parallel/boundaries/BoundaryUtils.h | 81 ++-- src/parallel/boundaries/DimensionType.h | 19 - 9 files changed, 547 insertions(+), 525 deletions(-) delete mode 100644 src/parallel/boundaries/BoundaryType.h delete mode 100644 src/parallel/boundaries/DimensionType.h diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 375da0f3ee..f0b74150c5 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -424,16 +424,16 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { } Log::global_log->info() << "x boundary " << xBoundary << std::endl; - _domainDecomposition->setGlobalBoundaryType(DimensionType::POSX, BoundaryUtils::convertStringToBoundary(xBoundary)); - _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(xBoundary)); + _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::POSX, BoundaryUtils::convertStringToBoundary(xBoundary)); + _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::NEGX, BoundaryUtils::convertStringToBoundary(xBoundary)); Log::global_log->info() << "y boundary " << yBoundary << std::endl; - _domainDecomposition->setGlobalBoundaryType(DimensionType::POSY, BoundaryUtils::convertStringToBoundary(yBoundary)); - _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(yBoundary)); + _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::POSY, BoundaryUtils::convertStringToBoundary(yBoundary)); + _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::NEGY, BoundaryUtils::convertStringToBoundary(yBoundary)); Log::global_log->info() << "z boundary " << zBoundary << std::endl; - _domainDecomposition->setGlobalBoundaryType(DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(zBoundary)); - _domainDecomposition->setGlobalBoundaryType(DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(zBoundary)); + _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::POSZ, BoundaryUtils::convertStringToBoundary(zBoundary)); + _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::NEGZ, BoundaryUtils::convertStringToBoundary(zBoundary)); if (_domainDecomposition->hasInvalidBoundary()) { Log::global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 17878f8537..e7d7b25fee 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -26,7 +26,7 @@ DomainDecompBase::~DomainDecompBase() { void DomainDecompBase::readXML(XMLfileUnits& /* xmlconfig */) { } -void DomainDecompBase::setGlobalBoundaryType(DimensionType dimension, BoundaryType boundary) { +void DomainDecompBase::setGlobalBoundaryType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary) { _boundaryHandler.setGlobalWall(dimension, boundary); } @@ -316,7 +316,7 @@ void DomainDecompBase::handleDomainLeavingParticlesDirect(const HaloRegion& halo void DomainDecompBase::populateHaloLayerWithCopies(unsigned dim, ParticleContainer* moleculeContainer) const { //reflecting and outflow boundaries do not expect halo particles - if(_boundaryHandler.getGlobalWall(dim) != BoundaryType::PERIODIC) + if(_boundaryHandler.getGlobalWall(dim) != BoundaryUtils::BoundaryType::PERIODIC) return; double shiftMagnitude = moleculeContainer->getBoundingBoxMax(dim) - moleculeContainer->getBoundingBoxMin(dim); diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index 3396be0a95..fc1132bf27 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -290,7 +290,7 @@ class DomainDecompBase: public MemoryProfilable { virtual void printCommunicationPartners(std::string filename) const {}; - void setGlobalBoundaryType(DimensionType dimension, BoundaryType boundary); + void setGlobalBoundaryType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary); void setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 163be47ae5..943d76e665 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -8,215 +8,244 @@ #include #include "BoundaryHandler.h" -#include "BoundaryUtils.h" #include "Simulation.h" #include "integrators/Integrator.h" -#include "utils/Logger.h" - -BoundaryHandler::BoundaryHandler() : _boundaries{ - {DimensionType::POSX, BoundaryType::PERIODIC}, {DimensionType::POSY, BoundaryType::PERIODIC}, - {DimensionType::POSZ, BoundaryType::PERIODIC}, {DimensionType::NEGX, BoundaryType::PERIODIC}, - {DimensionType::NEGY, BoundaryType::PERIODIC}, {DimensionType::NEGZ, BoundaryType::PERIODIC}, - {DimensionType::ERROR, BoundaryType::ERROR} - } {} - - -BoundaryType BoundaryHandler::getGlobalWall(DimensionType dimension) const -{ - return _boundaries.at(dimension); +#include "utils/Logger.h" + +BoundaryHandler::BoundaryHandler() + : _boundaries{{BoundaryUtils::DimensionType::POSX, + BoundaryUtils::BoundaryType::PERIODIC}, + {BoundaryUtils::DimensionType::POSY, + BoundaryUtils::BoundaryType::PERIODIC}, + {BoundaryUtils::DimensionType::POSZ, + BoundaryUtils::BoundaryType::PERIODIC}, + {BoundaryUtils::DimensionType::NEGX, + BoundaryUtils::BoundaryType::PERIODIC}, + {BoundaryUtils::DimensionType::NEGY, + BoundaryUtils::BoundaryType::PERIODIC}, + {BoundaryUtils::DimensionType::NEGZ, + BoundaryUtils::BoundaryType::PERIODIC}, + {BoundaryUtils::DimensionType::ERROR, + BoundaryUtils::BoundaryType::ERROR}} {} + +BoundaryUtils::BoundaryType +BoundaryHandler::getGlobalWall(BoundaryUtils::DimensionType dimension) const { + return _boundaries.at(dimension); } -BoundaryType BoundaryHandler::getGlobalWall(std::string dimension) const -{ - DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); - return getGlobalWall(convertedDimension); +BoundaryUtils::BoundaryType +BoundaryHandler::getGlobalWall(std::string dimension) const { + BoundaryUtils::DimensionType convertedDimension = + BoundaryUtils::convertStringToDimension(dimension); + return getGlobalWall(convertedDimension); } -BoundaryType BoundaryHandler::getGlobalWall(int dimension) const -{ - return getGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); +BoundaryUtils::BoundaryType +BoundaryHandler::getGlobalWall(int dimension) const { + return getGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -void BoundaryHandler::setGlobalWall(DimensionType dimension, BoundaryType value) -{ - if(dimension != DimensionType::ERROR) - _boundaries[dimension] = value; +void BoundaryHandler::setGlobalWall(BoundaryUtils::DimensionType dimension, + BoundaryUtils::BoundaryType value) { + if (dimension != BoundaryUtils::DimensionType::ERROR) + _boundaries[dimension] = value; } -void BoundaryHandler::setGlobalWall(std::string dimension, BoundaryType value) -{ - DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); - setGlobalWall(convertedDimension, value); +void BoundaryHandler::setGlobalWall(std::string dimension, + BoundaryUtils::BoundaryType value) { + BoundaryUtils::DimensionType convertedDimension = + BoundaryUtils::convertStringToDimension(dimension); + setGlobalWall(convertedDimension, value); } -void BoundaryHandler::setGlobalRegion(double* start, double* end) -{ - for(short int i = 0; i < 3; i++) { - _globalRegionStart[i] = start[i]; - _globalRegionEnd[i] = end[i]; - } +void BoundaryHandler::setGlobalRegion(double *start, double *end) { + for (short int i = 0; i < 3; i++) { + _globalRegionStart[i] = start[i]; + _globalRegionEnd[i] = end[i]; + } } -void BoundaryHandler::setLocalRegion(double* start, double* end) -{ - for(short int i = 0; i < 3; i++) { - _localRegionStart[i] = start[i]; - _localRegionEnd[i] = end[i]; - } +void BoundaryHandler::setLocalRegion(double *start, double *end) { + for (short int i = 0; i < 3; i++) { + _localRegionStart[i] = start[i]; + _localRegionEnd[i] = end[i]; + } } -void BoundaryHandler::setGlobalRegion(std::array start, std::array end) { - _globalRegionStart = start; - _globalRegionEnd = end; +void BoundaryHandler::setGlobalRegion(std::array start, + std::array end) { + _globalRegionStart = start; + _globalRegionEnd = end; } -void BoundaryHandler::setLocalRegion(std::array start, std::array end) { - _localRegionStart = start; - _localRegionEnd = end; +void BoundaryHandler::setLocalRegion(std::array start, + std::array end) { + _localRegionStart = start; + _localRegionEnd = end; } -void BoundaryHandler::findOuterWallsInLocalRegion() -{ - _isOuterWall[DimensionType::POSX] = (_localRegionEnd[0] == _globalRegionEnd[0]); - _isOuterWall[DimensionType::NEGX] = (_localRegionStart[0] == _globalRegionStart[0]); - _isOuterWall[DimensionType::POSY] = (_localRegionEnd[1] == _globalRegionEnd[1]); - _isOuterWall[DimensionType::NEGY] = (_localRegionStart[1] == _globalRegionStart[1]); - _isOuterWall[DimensionType::POSZ] = (_localRegionEnd[2] == _globalRegionEnd[2]); - _isOuterWall[DimensionType::NEGZ] = (_localRegionStart[2] == _globalRegionStart[2]); +void BoundaryHandler::findOuterWallsInLocalRegion() { + _isOuterWall[BoundaryUtils::DimensionType::POSX] = + (_localRegionEnd[0] == _globalRegionEnd[0]); + _isOuterWall[BoundaryUtils::DimensionType::NEGX] = + (_localRegionStart[0] == _globalRegionStart[0]); + _isOuterWall[BoundaryUtils::DimensionType::POSY] = + (_localRegionEnd[1] == _globalRegionEnd[1]); + _isOuterWall[BoundaryUtils::DimensionType::NEGY] = + (_localRegionStart[1] == _globalRegionStart[1]); + _isOuterWall[BoundaryUtils::DimensionType::POSZ] = + (_localRegionEnd[2] == _globalRegionEnd[2]); + _isOuterWall[BoundaryUtils::DimensionType::NEGZ] = + (_localRegionStart[2] == _globalRegionStart[2]); } -bool BoundaryHandler::hasInvalidBoundary() const -{ - return _boundaries.at(DimensionType::POSX) == BoundaryType::ERROR || - _boundaries.at(DimensionType::POSY) == BoundaryType::ERROR || - _boundaries.at(DimensionType::POSZ) == BoundaryType::ERROR || - _boundaries.at(DimensionType::NEGX) == BoundaryType::ERROR || - _boundaries.at(DimensionType::NEGY) == BoundaryType::ERROR || - _boundaries.at(DimensionType::NEGZ) == BoundaryType::ERROR; +bool BoundaryHandler::hasInvalidBoundary() const { + return _boundaries.at(BoundaryUtils::DimensionType::POSX) == + BoundaryUtils::BoundaryType::ERROR || + _boundaries.at(BoundaryUtils::DimensionType::POSY) == + BoundaryUtils::BoundaryType::ERROR || + _boundaries.at(BoundaryUtils::DimensionType::POSZ) == + BoundaryUtils::BoundaryType::ERROR || + _boundaries.at(BoundaryUtils::DimensionType::NEGX) == + BoundaryUtils::BoundaryType::ERROR || + _boundaries.at(BoundaryUtils::DimensionType::NEGY) == + BoundaryUtils::BoundaryType::ERROR || + _boundaries.at(BoundaryUtils::DimensionType::NEGZ) == + BoundaryUtils::BoundaryType::ERROR; } -bool BoundaryHandler::hasNonPeriodicBoundary() const -{ - return _boundaries.at(DimensionType::POSX) != BoundaryType::PERIODIC || - _boundaries.at(DimensionType::POSY) != BoundaryType::PERIODIC || - _boundaries.at(DimensionType::POSZ) != BoundaryType::PERIODIC || - _boundaries.at(DimensionType::NEGX) != BoundaryType::PERIODIC || - _boundaries.at(DimensionType::NEGY) != BoundaryType::PERIODIC || - _boundaries.at(DimensionType::NEGZ) != BoundaryType::PERIODIC; +bool BoundaryHandler::hasNonPeriodicBoundary() const { + return _boundaries.at(BoundaryUtils::DimensionType::POSX) != + BoundaryUtils::BoundaryType::PERIODIC || + _boundaries.at(BoundaryUtils::DimensionType::POSY) != + BoundaryUtils::BoundaryType::PERIODIC || + _boundaries.at(BoundaryUtils::DimensionType::POSZ) != + BoundaryUtils::BoundaryType::PERIODIC || + _boundaries.at(BoundaryUtils::DimensionType::NEGX) != + BoundaryUtils::BoundaryType::PERIODIC || + _boundaries.at(BoundaryUtils::DimensionType::NEGY) != + BoundaryUtils::BoundaryType::PERIODIC || + _boundaries.at(BoundaryUtils::DimensionType::NEGZ) != + BoundaryUtils::BoundaryType::PERIODIC; } -bool BoundaryHandler::isOuterWall(DimensionType dimension) const -{ - return _isOuterWall.at(dimension); +bool BoundaryHandler::isOuterWall( + BoundaryUtils::DimensionType dimension) const { + return _isOuterWall.at(dimension); } -bool BoundaryHandler::isOuterWall(int dimension) const -{ - return isOuterWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); +bool BoundaryHandler::isOuterWall(int dimension) const { + return isOuterWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -bool BoundaryHandler::processOuterWallLeavingParticles() -{ - auto moleculeContainer = global_simulation->getMoleculeContainer(); // :-( - double timestepLength = (global_simulation->getIntegrator())->getTimestepLength(); - double cutoff = moleculeContainer->getCutoff(); - for (auto const& currentWall : _isOuterWall) - { - if(!currentWall.second) // not an outer wall - continue; - - switch(getGlobalWall(currentWall.first)) - { - case BoundaryType::PERIODIC: - //default behaviour - break; - - case BoundaryType::OUTFLOW: - case BoundaryType::REFLECTING: - { - //create region - std::array curWallRegionBegin, curWallRegionEnd; - std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getInnerBuffer(_localRegionStart, _localRegionEnd, currentWall.first, cutoff); - //conversion - const double cstylerbegin[] = {curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; - const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; - - auto particlesInRegion = moleculeContainer->regionIterator(cstylerbegin, cstylerend, ParticleIterator::ONLY_INNER_AND_BOUNDARY); - for (auto it = particlesInRegion; it.isValid(); ++it) - { - Molecule curMolecule = *it; - - int currentDim = BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); - double halfTimestep = .5 * timestepLength; - double halfTimestepByMass = halfTimestep / it->mass(); - double force = it->F(currentDim); - double nextStepVelAdjustment = halfTimestepByMass * force; - - if (BoundaryUtils::isMoleculeLeaving(curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength, nextStepVelAdjustment)) - { - if(getGlobalWall(currentWall.first) == BoundaryType::REFLECTING) - { - double currentVel = it->v(currentDim); - it->setv(currentDim, -currentVel-nextStepVelAdjustment-nextStepVelAdjustment); - } - else // outflow - { - moleculeContainer->deleteMolecule(it, false); - } - } - } - break; - } - default: - Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; - mardyn_exit(1); - } - } - return true; +bool BoundaryHandler::processOuterWallLeavingParticles() { + auto moleculeContainer = global_simulation->getMoleculeContainer(); // :-( + double timestepLength = + (global_simulation->getIntegrator())->getTimestepLength(); + double cutoff = moleculeContainer->getCutoff(); + for (auto const ¤tWall : _isOuterWall) { + if (!currentWall.second) // not an outer wall + continue; + + switch (getGlobalWall(currentWall.first)) { + case BoundaryUtils::BoundaryType::PERIODIC: + // default behaviour + break; + + case BoundaryUtils::BoundaryType::OUTFLOW: + case BoundaryUtils::BoundaryType::REFLECTING: { + // create region + std::array curWallRegionBegin, curWallRegionEnd; + std::tie(curWallRegionBegin, curWallRegionEnd) = + BoundaryUtils::getInnerBuffer(_localRegionStart, _localRegionEnd, + currentWall.first, cutoff); + // conversion + const double cstylerbegin[] = { + curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; + const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], + curWallRegionEnd[2]}; + + auto particlesInRegion = moleculeContainer->regionIterator( + cstylerbegin, cstylerend, ParticleIterator::ONLY_INNER_AND_BOUNDARY); + for (auto it = particlesInRegion; it.isValid(); ++it) { + Molecule curMolecule = *it; + + int currentDim = + BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); + double halfTimestep = .5 * timestepLength; + double halfTimestepByMass = halfTimestep / it->mass(); + double force = it->F(currentDim); + double nextStepVelAdjustment = halfTimestepByMass * force; + + if (BoundaryUtils::isMoleculeLeaving( + curMolecule, curWallRegionBegin, curWallRegionEnd, + currentWall.first, timestepLength, nextStepVelAdjustment)) { + if (getGlobalWall(currentWall.first) == + BoundaryUtils::BoundaryType::REFLECTING) { + double currentVel = it->v(currentDim); + it->setv(currentDim, -currentVel - nextStepVelAdjustment - + nextStepVelAdjustment); + } else // outflow + { + moleculeContainer->deleteMolecule(it, false); + } + } + } + break; + } + default: + Log::global_log->error() + << "Boundary type error! Received type not allowed!" << std::endl; + mardyn_exit(1); + } + } + return true; } -void BoundaryHandler::removeNonPeriodicHalos() -{ - auto moleculeContainer = global_simulation->getMoleculeContainer(); - double buffers[] = {moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), - moleculeContainer->get_halo_L(1) + moleculeContainer->getSkin(), - moleculeContainer->get_halo_L(2) + moleculeContainer->getSkin()}; - for (auto const& currentWall : _isOuterWall) - { - if(!currentWall.second) //not an outer wall - continue; - - switch(getGlobalWall(currentWall.first)) - { - case BoundaryType::PERIODIC: - //default behaviour - break; - - case BoundaryType::OUTFLOW: - case BoundaryType::REFLECTING: - { - //create region - std::array curWallRegionBegin, curWallRegionEnd; - std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, currentWall.first, buffers); - //conversion - const double cstylerbegin[] = {curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; - const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; - - auto particlesInRegion = moleculeContainer->regionIterator(cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); - for (auto it = particlesInRegion; it.isValid(); ++it) - { - moleculeContainer->deleteMolecule(it, false); - } - break; - } - default: - Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; - mardyn_exit(1); - } - } - #ifndef MARDYN_AUTOPAS - moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); - #endif +void BoundaryHandler::removeNonPeriodicHalos() { + auto moleculeContainer = global_simulation->getMoleculeContainer(); + double buffers[] = { + moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), + moleculeContainer->get_halo_L(1) + moleculeContainer->getSkin(), + moleculeContainer->get_halo_L(2) + moleculeContainer->getSkin()}; + for (auto const ¤tWall : _isOuterWall) { + if (!currentWall.second) // not an outer wall + continue; + + switch (getGlobalWall(currentWall.first)) { + case BoundaryUtils::BoundaryType::PERIODIC: + // default behaviour + break; + + case BoundaryUtils::BoundaryType::OUTFLOW: + case BoundaryUtils::BoundaryType::REFLECTING: { + // create region + std::array curWallRegionBegin, curWallRegionEnd; + std::tie(curWallRegionBegin, curWallRegionEnd) = + BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, + currentWall.first, buffers); + // conversion + const double cstylerbegin[] = { + curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; + const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], + curWallRegionEnd[2]}; + + auto particlesInRegion = moleculeContainer->regionIterator( + cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); + for (auto it = particlesInRegion; it.isValid(); ++it) { + moleculeContainer->deleteMolecule(it, false); + } + break; + } + default: + Log::global_log->error() + << "Boundary type error! Received type not allowed!" << std::endl; + mardyn_exit(1); + } + } +#ifndef MARDYN_AUTOPAS + moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); +#endif } \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index d03982c636..5ced5be0b1 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -7,41 +7,42 @@ #pragma once +#include "BoundaryUtils.h" + +#include #include -#include #include -#include -#include "BoundaryType.h" -#include "DimensionType.h" - +#include -class BoundaryHandler -{ +class BoundaryHandler { public: - BoundaryHandler(); - BoundaryType getGlobalWall(std::string dimension) const; - void setGlobalWall(std::string dimension, BoundaryType value); - BoundaryType getGlobalWall(DimensionType dimension) const; - void setGlobalWall(DimensionType dimension, BoundaryType value); - BoundaryType getGlobalWall(int dimension) const; - bool hasInvalidBoundary() const; - bool hasNonPeriodicBoundary() const; - - void setGlobalRegion(double* start, double* end); - void setLocalRegion(double* start, double* end); - - void setGlobalRegion(std::array start, std::array end); - void setLocalRegion(std::array start, std::array end); - - void findOuterWallsInLocalRegion(); - bool isOuterWall(DimensionType dimension) const; - bool isOuterWall(int dimension) const; - bool processOuterWallLeavingParticles(); - void removeNonPeriodicHalos(); + BoundaryHandler(); + BoundaryUtils::BoundaryType getGlobalWall(std::string dimension) const; + void setGlobalWall(std::string dimension, BoundaryUtils::BoundaryType value); + BoundaryUtils::BoundaryType + getGlobalWall(BoundaryUtils::DimensionType dimension) const; + void setGlobalWall(BoundaryUtils::DimensionType dimension, + BoundaryUtils::BoundaryType value); + BoundaryUtils::BoundaryType getGlobalWall(int dimension) const; + bool hasInvalidBoundary() const; + bool hasNonPeriodicBoundary() const; + + void setGlobalRegion(double *start, double *end); + void setLocalRegion(double *start, double *end); + + void setGlobalRegion(std::array start, std::array end); + void setLocalRegion(std::array start, std::array end); + + void findOuterWallsInLocalRegion(); + bool isOuterWall(BoundaryUtils::DimensionType dimension) const; + bool isOuterWall(int dimension) const; + bool processOuterWallLeavingParticles(); + void removeNonPeriodicHalos(); private: - std::map _boundaries; - std::map _isOuterWall; - std::array _globalRegionStart, _globalRegionEnd; - std::array _localRegionStart, _localRegionEnd; + std::map + _boundaries; + std::map _isOuterWall; + std::array _globalRegionStart, _globalRegionEnd; + std::array _localRegionStart, _localRegionEnd; }; \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryType.h b/src/parallel/boundaries/BoundaryType.h deleted file mode 100644 index 84c64aa53a..0000000000 --- a/src/parallel/boundaries/BoundaryType.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * BoundaryType.h - * - * Created on: 24 March 2023 - * Author: amartyads - */ - -#pragma once - -enum class BoundaryType -{ - PERIODIC, - OUTFLOW, - REFLECTING, - ERROR -}; \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 6f9de0bd1d..1a6d724209 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -8,277 +8,289 @@ #include #include - #include "BoundaryUtils.h" #include "Simulation.h" #include "utils/Logger.h" -bool BoundaryUtils::isDimensionStringPermissible(std::string dimension) -{ - return std::find(permissibleDimensionsString.begin(),permissibleDimensionsString.end(),dimension) != permissibleDimensionsString.end(); +bool BoundaryUtils::isDimensionStringPermissible(std::string dimension) { + return std::find(permissibleDimensionsString.begin(), + permissibleDimensionsString.end(), + dimension) != permissibleDimensionsString.end(); } -bool BoundaryUtils::isDimensionNumericPermissible(int dim) -{ - return (dim >= -3 && dim <= 3 && dim != 0); +bool BoundaryUtils::isDimensionNumericPermissible(int dim) { + return (dim >= -3 && dim <= 3 && dim != 0); } -DimensionType BoundaryUtils::convertStringToDimension(std::string dimension) { - if(!isDimensionStringPermissible(dimension)) - { - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return DimensionType::ERROR; - } - if(dimension == "+x") - return DimensionType::POSX; - if(dimension == "+y") - return DimensionType::POSY; - if(dimension == "+z") - return DimensionType::POSZ; - if(dimension == "-x") - return DimensionType::NEGX; - if(dimension == "-y") - return DimensionType::NEGY; - //if(dimension == "-z") - return DimensionType::NEGZ; +BoundaryUtils::DimensionType +BoundaryUtils::convertStringToDimension(std::string dimension) { + if (!isDimensionStringPermissible(dimension)) { + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return DimensionType::ERROR; + } + if (dimension == "+x") + return DimensionType::POSX; + if (dimension == "+y") + return DimensionType::POSY; + if (dimension == "+z") + return DimensionType::POSZ; + if (dimension == "-x") + return DimensionType::NEGX; + if (dimension == "-y") + return DimensionType::NEGY; + // if(dimension == "-z") + return DimensionType::NEGZ; } -DimensionType BoundaryUtils::convertNumericToDimension(int dim) -{ - if(!isDimensionNumericPermissible(dim)) - { - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return DimensionType::ERROR; - } - switch(findSign(dim)) - { - case -1: - switch(dim) - { - case 1: return DimensionType::NEGX; - case 2: return DimensionType::NEGY; - default: return DimensionType::NEGZ; //case 3 - - } - case 1: - switch(dim) - { - case 1: return DimensionType::POSX; - case 2: return DimensionType::POSY; - default: return DimensionType::POSZ; //case 3 - } - default: //should never happen - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - } - return DimensionType::ERROR; +BoundaryUtils::DimensionType BoundaryUtils::convertNumericToDimension(int dim) { + if (!isDimensionNumericPermissible(dim)) { + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return DimensionType::ERROR; + } + switch (findSign(dim)) { + case -1: + switch (dim) { + case 1: + return DimensionType::NEGX; + case 2: + return DimensionType::NEGY; + default: + return DimensionType::NEGZ; // case 3 + } + case 1: + switch (dim) { + case 1: + return DimensionType::POSX; + case 2: + return DimensionType::POSY; + default: + return DimensionType::POSZ; // case 3 + } + default: // should never happen + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + } + return DimensionType::ERROR; } -DimensionType BoundaryUtils::convertLS1DimsToDimensionPos(int dim) -{ - DimensionType toRet = DimensionType::ERROR; - switch(dim) - { - case 0: - toRet = DimensionType::POSX; - break; - case 1: - toRet = DimensionType::POSY; - break; - default: //case 2: - toRet = DimensionType::POSZ; - } - return toRet; +BoundaryUtils::DimensionType +BoundaryUtils::convertLS1DimsToDimensionPos(int dim) { + DimensionType toRet = DimensionType::ERROR; + switch (dim) { + case 0: + toRet = DimensionType::POSX; + break; + case 1: + toRet = DimensionType::POSY; + break; + default: // case 2: + toRet = DimensionType::POSZ; + } + return toRet; } -std::vector BoundaryUtils::convertHaloOffsetToDimensionVector(int* offset) -{ - std::vector toRet; - for (int i = 0; i < 3; i++) - { - if(offset[i] != 0) - { - int numeric = (i+1) * offset[i]; - toRet.push_back(convertNumericToDimension(numeric)); - } - } - return toRet; +std::vector +BoundaryUtils::convertHaloOffsetToDimensionVector(int *offset) { + std::vector toRet; + for (int i = 0; i < 3; i++) { + if (offset[i] != 0) { + int numeric = (i + 1) * offset[i]; + toRet.push_back(convertNumericToDimension(numeric)); + } + } + return toRet; } -std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) -{ - switch (dimension) - { - case DimensionType::POSX: - return "+x"; - - case DimensionType::POSY: - return "+y"; - - case DimensionType::POSZ: - return "+z"; - - case DimensionType::NEGX: - return "-x"; - - case DimensionType::NEGY: - return "-y"; - - case DimensionType::NEGZ: - return "-z"; - - default: - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return "error"; - } +std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) { + switch (dimension) { + case DimensionType::POSX: + return "+x"; + + case DimensionType::POSY: + return "+y"; + + case DimensionType::POSZ: + return "+z"; + + case DimensionType::NEGX: + return "-x"; + + case DimensionType::NEGY: + return "-y"; + + case DimensionType::NEGZ: + return "-z"; + + default: + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return "error"; + } } -std::string BoundaryUtils::convertDimensionToStringAbs(DimensionType dimension) -{ - return convertDimensionToString(dimension).substr(1,1); +std::string +BoundaryUtils::convertDimensionToStringAbs(DimensionType dimension) { + return convertDimensionToString(dimension).substr(1, 1); } -int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) -{ - switch (dimension) - { - case DimensionType::POSX: - return 1; - - case DimensionType::POSY: - return 2; - - case DimensionType::POSZ: - return 3; - - case DimensionType::NEGX: - return -1; - - case DimensionType::NEGY: - return -2; - - case DimensionType::NEGZ: - return -3; - - default: - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return 0; - } +int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) { + switch (dimension) { + case DimensionType::POSX: + return 1; + + case DimensionType::POSY: + return 2; + + case DimensionType::POSZ: + return 3; + + case DimensionType::NEGX: + return -1; + + case DimensionType::NEGY: + return -2; + + case DimensionType::NEGZ: + return -3; + + default: + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return 0; + } } -int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) -{ - int toReturn = convertDimensionToNumeric(dimension); - return findSign(toReturn) * toReturn; +int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) { + int toReturn = convertDimensionToNumeric(dimension); + return findSign(toReturn) * toReturn; } -int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) -{ - return convertDimensionToNumericAbs(dimension) - 1; +int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { + return convertDimensionToNumericAbs(dimension) - 1; } -BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) -{ - if(boundary == "periodic") - return BoundaryType::PERIODIC; - if(boundary == "reflecting" || boundary == "reflective") - return BoundaryType::REFLECTING; - if(boundary == "outflow") - return BoundaryType::OUTFLOW; - Log::global_log->error() << "Invalid boundary type passed. Check your input file!" << std::endl; - return BoundaryType::ERROR; +BoundaryUtils::BoundaryType +BoundaryUtils::convertStringToBoundary(std::string boundary) { + if (boundary == "periodic") + return BoundaryType::PERIODIC; + if (boundary == "reflecting" || boundary == "reflective") + return BoundaryType::REFLECTING; + if (boundary == "outflow") + return BoundaryType::OUTFLOW; + Log::global_log->error() + << "Invalid boundary type passed. Check your input file!" << std::endl; + return BoundaryType::ERROR; } -std::tuple, std::array> BoundaryUtils::getInnerBuffer(const std::array givenRegionBegin, - const std::array givenRegionEnd, DimensionType dimension, double regionWidth) -{ - std::array returnRegionBegin, returnRegionEnd; - for (int i = 0; i < 3; i++) - { - returnRegionBegin[i] = givenRegionBegin[i]; - returnRegionEnd[i] = givenRegionEnd[i]; - } - - int dimensionLS1 = convertDimensionToLS1Dims(dimension); - - switch (dimension) //can be done with findsign() too, but this is clearer - { - case DimensionType::POSX: - case DimensionType::POSY: - case DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1] - regionWidth; - break; - - case DimensionType::NEGX: - case DimensionType::NEGY: - case DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1] + regionWidth; - break; - - default: - Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; - mardyn_exit(1); - } - return std::make_tuple(returnRegionBegin, returnRegionEnd); +std::tuple, std::array> +BoundaryUtils::getInnerBuffer(const std::array givenRegionBegin, + const std::array givenRegionEnd, + DimensionType dimension, double regionWidth) { + std::array returnRegionBegin, returnRegionEnd; + for (int i = 0; i < 3; i++) { + returnRegionBegin[i] = givenRegionBegin[i]; + returnRegionEnd[i] = givenRegionEnd[i]; + } + + int dimensionLS1 = convertDimensionToLS1Dims(dimension); + + switch (dimension) // can be done with findsign() too, but this is clearer + { + case DimensionType::POSX: + case DimensionType::POSY: + case DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = + returnRegionEnd[dimensionLS1] - regionWidth; + break; + + case DimensionType::NEGX: + case DimensionType::NEGY: + case DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = + returnRegionBegin[dimensionLS1] + regionWidth; + break; + + default: + Log::global_log->error() + << "Invalid dimension passed for inner buffer calculation" << std::endl; + mardyn_exit(1); + } + return std::make_tuple(returnRegionBegin, returnRegionEnd); } -bool BoundaryUtils::isMoleculeLeaving(const Molecule molecule, const std::array regionBegin, const std::array regionEnd, - DimensionType dimension, double timestepLength, double nextStepVelAdjustment) { - int ls1dim = convertDimensionToLS1Dims(dimension); - int direction = findSign(dimension); - double newPos = molecule.r(ls1dim) + (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); - if (newPos < regionBegin[ls1dim] && direction < 0) - return true; - if (newPos > regionEnd[ls1dim] && direction > 0) - return true; - return false; +bool BoundaryUtils::isMoleculeLeaving(const Molecule molecule, + const std::array regionBegin, + const std::array regionEnd, + DimensionType dimension, + double timestepLength, + double nextStepVelAdjustment) { + int ls1dim = convertDimensionToLS1Dims(dimension); + int direction = findSign(dimension); + double newPos = + molecule.r(ls1dim) + + (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); + if (newPos < regionBegin[ls1dim] && direction < 0) + return true; + if (newPos > regionEnd[ls1dim] && direction > 0) + return true; + return false; } -std::tuple, std::array> BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, - const std::array givenRegionEnd, DimensionType dimension, double* regionWidth) -{ - std::array returnRegionBegin, returnRegionEnd; - for (int i = 0; i < 3; i++) - { - returnRegionBegin[i] = givenRegionBegin[i]; - returnRegionEnd[i] = givenRegionEnd[i]; - } - - int dimensionLS1 = convertDimensionToLS1Dims(dimension); - - int extraDim1 = dimensionLS1 == 0 ? 1: 0; - int extraDim2 = dimensionLS1 == 2 ? 1: 2; - - returnRegionBegin[extraDim1] = returnRegionBegin[extraDim1] - regionWidth[extraDim1]; - returnRegionEnd[extraDim1] = returnRegionEnd[extraDim1] + regionWidth[extraDim1]; - - returnRegionBegin[extraDim2] = returnRegionBegin[extraDim2] - regionWidth[extraDim2]; - returnRegionEnd[extraDim2] = returnRegionEnd[extraDim2] + regionWidth[extraDim2]; - - switch (dimension) //can be done with findsign() too, but this is clearer - { - case DimensionType::POSX: - case DimensionType::POSY: - case DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; - returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1] + regionWidth[dimensionLS1]; - break; - - case DimensionType::NEGX: - case DimensionType::NEGY: - case DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; - returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1] - regionWidth[dimensionLS1]; - break; - - default: - Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; - mardyn_exit(1); - } - return std::make_tuple(returnRegionBegin, returnRegionEnd); +std::tuple, std::array> +BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, + const std::array givenRegionEnd, + DimensionType dimension, double *regionWidth) { + std::array returnRegionBegin, returnRegionEnd; + for (int i = 0; i < 3; i++) { + returnRegionBegin[i] = givenRegionBegin[i]; + returnRegionEnd[i] = givenRegionEnd[i]; + } + + int dimensionLS1 = convertDimensionToLS1Dims(dimension); + + int extraDim1 = dimensionLS1 == 0 ? 1 : 0; + int extraDim2 = dimensionLS1 == 2 ? 1 : 2; + + returnRegionBegin[extraDim1] = + returnRegionBegin[extraDim1] - regionWidth[extraDim1]; + returnRegionEnd[extraDim1] = + returnRegionEnd[extraDim1] + regionWidth[extraDim1]; + + returnRegionBegin[extraDim2] = + returnRegionBegin[extraDim2] - regionWidth[extraDim2]; + returnRegionEnd[extraDim2] = + returnRegionEnd[extraDim2] + regionWidth[extraDim2]; + + switch (dimension) // can be done with findsign() too, but this is clearer + { + case DimensionType::POSX: + case DimensionType::POSY: + case DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; + returnRegionEnd[dimensionLS1] = + returnRegionBegin[dimensionLS1] + regionWidth[dimensionLS1]; + break; + + case DimensionType::NEGX: + case DimensionType::NEGY: + case DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; + returnRegionBegin[dimensionLS1] = + returnRegionEnd[dimensionLS1] - regionWidth[dimensionLS1]; + break; + + default: + Log::global_log->error() + << "Invalid dimension passed for inner buffer calculation" << std::endl; + mardyn_exit(1); + } + return std::make_tuple(returnRegionBegin, returnRegionEnd); } diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index a434f6ea4b..ee415439df 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -5,41 +5,56 @@ * Author: amartyads */ -#include +#pragma once + +#include #include #include -#include - -#include "BoundaryType.h" -#include "DimensionType.h" +#include #include "molecules/Molecule.h" -namespace BoundaryUtils -{ - const std::array permissibleDimensionsString = {"+x", "+y", "+z", "-x", "-y", "-z"}; - const std::array permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; - - bool isDimensionStringPermissible(std::string dimension); - bool isDimensionNumericPermissible(int dim); - - DimensionType convertStringToDimension(std::string dimension); - DimensionType convertNumericToDimension(int dim); - DimensionType convertLS1DimsToDimensionPos(int dim); - std::vector convertHaloOffsetToDimensionVector(int* offset); - - std::string convertDimensionToString(DimensionType dimension); - std::string convertDimensionToStringAbs(DimensionType dimension); - int convertDimensionToNumeric(DimensionType dimension); - int convertDimensionToNumericAbs(DimensionType dimension); - int convertDimensionToLS1Dims(DimensionType dimension); - - BoundaryType convertStringToBoundary(std::string boundary); - - std::tuple, std::array> getInnerBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double regionWidth); - bool isMoleculeLeaving(const Molecule molecule, const std::array regionBegin, const std::array regionEnd, DimensionType dimension, double timestepLength, double nextStepVelAdjustment); - std::tuple, std::array> getOuterBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double* regionWidth); - - inline int findSign(int n) { return n < 0 ? -1 : 1; } - inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } -} \ No newline at end of file +namespace BoundaryUtils { + +enum class BoundaryType { PERIODIC, OUTFLOW, REFLECTING, ERROR }; +enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; + +const std::array permissibleDimensionsString = { + "+x", "+y", "+z", "-x", "-y", "-z"}; +const std::array permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; + +bool isDimensionStringPermissible(std::string dimension); +bool isDimensionNumericPermissible(int dim); + +DimensionType convertStringToDimension(std::string dimension); +DimensionType convertNumericToDimension(int dim); +DimensionType convertLS1DimsToDimensionPos(int dim); +std::vector convertHaloOffsetToDimensionVector(int *offset); + +std::string convertDimensionToString(DimensionType dimension); +std::string convertDimensionToStringAbs(DimensionType dimension); +int convertDimensionToNumeric(DimensionType dimension); +int convertDimensionToNumericAbs(DimensionType dimension); +int convertDimensionToLS1Dims(DimensionType dimension); + +BoundaryType convertStringToBoundary(std::string boundary); + +std::tuple, std::array> +getInnerBuffer(const std::array givenRegionBegin, + const std::array givenRegionEnd, + DimensionType dimension, double regionWidth); +bool isMoleculeLeaving(const Molecule molecule, + const std::array regionBegin, + const std::array regionEnd, + DimensionType dimension, double timestepLength, + double nextStepVelAdjustment); +std::tuple, std::array> +getOuterBuffer(const std::array givenRegionBegin, + const std::array givenRegionEnd, + DimensionType dimension, double *regionWidth); + +inline int findSign(int n) { return n < 0 ? -1 : 1; } +inline int findSign(DimensionType dimension) { + return findSign(convertDimensionToNumeric(dimension)); +} +} // namespace BoundaryUtils \ No newline at end of file diff --git a/src/parallel/boundaries/DimensionType.h b/src/parallel/boundaries/DimensionType.h deleted file mode 100644 index 1e8280e3e8..0000000000 --- a/src/parallel/boundaries/DimensionType.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * DimensionType.h - * - * Created on: 24 March 2023 - * Author: amartyads - */ - -#pragma once - -enum class DimensionType -{ - POSX, - NEGX, - POSY, - NEGY, - POSZ, - NEGZ, - ERROR -}; \ No newline at end of file From eac76570eef26f95743a4b04c9d3c2da86c272da Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 2 Sep 2024 16:51:23 +0200 Subject: [PATCH 48/94] some documentation in boundaryutils --- src/parallel/boundaries/BoundaryUtils.cpp | 17 ++++-- src/parallel/boundaries/BoundaryUtils.h | 65 +++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 1a6d724209..57be9f6046 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -204,18 +204,23 @@ BoundaryUtils::getInnerBuffer(const std::array givenRegionBegin, switch (dimension) // can be done with findsign() too, but this is clearer { + // in positive case, set the beginning to end-width, or whole domain if width + // too large case DimensionType::POSX: case DimensionType::POSY: case DimensionType::POSZ: returnRegionBegin[dimensionLS1] = - returnRegionEnd[dimensionLS1] - regionWidth; + std::max(returnRegionEnd[dimensionLS1] - regionWidth, + givenRegionBegin[dimensionLS1]); break; - + // in negative case, set the end to beginning+width, or whole domain if width + // too large case DimensionType::NEGX: case DimensionType::NEGY: case DimensionType::NEGZ: returnRegionEnd[dimensionLS1] = - returnRegionBegin[dimensionLS1] + regionWidth; + std::min(returnRegionBegin[dimensionLS1] + regionWidth, + givenRegionEnd[dimensionLS1]); break; default: @@ -256,9 +261,11 @@ BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, int dimensionLS1 = convertDimensionToLS1Dims(dimension); + // find the two dimensions that are not being considered int extraDim1 = dimensionLS1 == 0 ? 1 : 0; int extraDim2 = dimensionLS1 == 2 ? 1 : 2; + // extend the extra dimensions to cover all ghost areas returnRegionBegin[extraDim1] = returnRegionBegin[extraDim1] - regionWidth[extraDim1]; returnRegionEnd[extraDim1] = @@ -271,6 +278,8 @@ BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, switch (dimension) // can be done with findsign() too, but this is clearer { + // in positive case, move the box begin to edge of domain, and box end to + // beyond case DimensionType::POSX: case DimensionType::POSY: case DimensionType::POSZ: @@ -279,6 +288,8 @@ BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, returnRegionBegin[dimensionLS1] + regionWidth[dimensionLS1]; break; + // in negative case, move the box end to edge of domain, and box begin to + // beyond case DimensionType::NEGX: case DimensionType::NEGY: case DimensionType::NEGZ: diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index ee415439df..4288c45e4c 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -14,9 +14,33 @@ #include "molecules/Molecule.h" +/** + * Includes enums and helper functions for processing boundary conditions. + * + * Does not actually work on any molecule containers, hence can be used + * in a general sense for other calculations. + */ namespace BoundaryUtils { +/** + * enum storing the types of boundaries currently supported. + * + * The currently supported boundary types are + * PERIODIC - default behaviour, periodic boundaries + * OUTFLOW - molecules exiting the boundary are deleted + * REFLECTING - molecules exiting the boundary have their velocities + * reversed in the direction they are leaving + * ERROR - kept for sanity checks + * + * This can be extended if needed. + */ enum class BoundaryType { PERIODIC, OUTFLOW, REFLECTING, ERROR }; + +/** + * enum storing the axes and direction. + * + * This is fixed for 3D, and ERROR is included for sanity checks + */ enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; const std::array permissibleDimensionsString = { @@ -37,17 +61,58 @@ int convertDimensionToNumeric(DimensionType dimension); int convertDimensionToNumericAbs(DimensionType dimension); int convertDimensionToLS1Dims(DimensionType dimension); +/** + * Used to convert string read from the XML input file + */ BoundaryType convertStringToBoundary(std::string boundary); +/** + * When given a domain delimited by givenRegionBegin and givenRegionEnd + * and a DimensionType, and a requested regionWidth, this function + * returns a cropped box from the domain. This box is of size regionWidth + * in the dimension specified, and the size of the domain otherwise. + * + * E.g. if the dimension given is +x, and the regionWidth is 3, this function + * returns a box, which would contain every particle that is within 3 + * units from the +x boundary wall, in the original domain + * demarcated by givenRegion{begin,end}. + */ std::tuple, std::array> getInnerBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double regionWidth); + +/** + * Checks if a given molecule is leaving the given region in the next timestep, + * with added scalar velocity adjustment, but only in the given dimension. + * + * The molecule's position and velocity in the specified dimension is extracted + * from the molecule itself, and the next position is calculated using the + * velocity adjustment and the timestep length. + * + * When this function is called, it is usually expected that the forces have + * been updated for the current timestep and the positions and velocities + * aren't. Hence the nextStepVelAdjustment is provided to the caller function, + * so that it can handle the change in velocity due to forces. This is not done + * by the util function itself, to keep it as generic as possible. + */ bool isMoleculeLeaving(const Molecule molecule, const std::array regionBegin, const std::array regionEnd, DimensionType dimension, double timestepLength, double nextStepVelAdjustment); + +/** + * When given a domain delimited by givenRegionBegin and givenRegionEnd + * and a DimensionType, and a requested regionWidth, this function + * returns a box outside the domain. This box is of size regionWidth + * in the dimension specified, and the size of the domain plus regionwidth + * otherwise. + * + * E.g. if the dimension given is +x, and the regionWidth is 3, this function + * returns a box, which contains every ghost particle that is 3 units away + * from +x. + */ std::tuple, std::array> getOuterBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, From b1b0c0baeaa283da956441296aa51dbd041b856f Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 4 Sep 2024 16:05:51 +0200 Subject: [PATCH 49/94] no use of globsim object in boundary, fix for lost particles --- src/Simulation.cpp | 4 ++-- src/parallel/DomainDecompBase.cpp | 8 ++++---- src/parallel/DomainDecompBase.h | 4 ++-- src/parallel/boundaries/BoundaryHandler.cpp | 10 +++------- src/parallel/boundaries/BoundaryHandler.h | 5 +++-- src/parallel/boundaries/BoundaryUtils.cpp | 4 ++-- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index f0b74150c5..8faf5079a7 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -1077,7 +1077,7 @@ void Simulation::simulateOneTimestep() _ensemble->beforeEventNewTimestep(_moleculeContainer, _domainDecomposition, _simstep); global_simulation->timers()->start("SIMULATION_BOUNDARY_TREATMENT"); - _domainDecomposition->processBoundaryConditions(); + _domainDecomposition->processBoundaryConditions(_moleculeContainer, _integrator->getTimestepLength()); global_simulation->timers()->stop("SIMULATION_BOUNDARY_TREATMENT"); _integrator->eventNewTimestep(_moleculeContainer, _domain); @@ -1400,7 +1400,7 @@ void Simulation::updateParticleContainerAndDecomposition(double lastTraversalTim global_simulation->timers()->stop("SIMULATION_MPI_OMP_COMMUNICATION"); global_simulation->timers()->start("SIMULATION_BOUNDARY_TREATMENT"); - _domainDecomposition->removeNonPeriodicHalos(); + _domainDecomposition->removeNonPeriodicHalos(_moleculeContainer); global_simulation->timers()->stop("SIMULATION_BOUNDARY_TREATMENT"); // The cache of the molecules must be updated/build after the exchange process, diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index e7d7b25fee..a7149600f9 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -43,14 +43,14 @@ void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* en _boundaryHandler.findOuterWallsInLocalRegion(); } -void DomainDecompBase::processBoundaryConditions() { +void DomainDecompBase::processBoundaryConditions(ParticleContainer* moleculeContainer, double timestepLength) { if(_boundaryHandler.hasNonPeriodicBoundary()) - _boundaryHandler.processOuterWallLeavingParticles(); + _boundaryHandler.processOuterWallLeavingParticles(moleculeContainer, timestepLength); } -void DomainDecompBase::removeNonPeriodicHalos() { +void DomainDecompBase::removeNonPeriodicHalos(ParticleContainer* moleculeContainer) { if(_boundaryHandler.hasNonPeriodicBoundary()) - _boundaryHandler.removeNonPeriodicHalos(); + _boundaryHandler.removeNonPeriodicHalos(moleculeContainer); } void DomainDecompBase::addLeavingMolecules(std::vector& invalidMolecules, diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index fc1132bf27..49ddf5e556 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -296,9 +296,9 @@ class DomainDecompBase: public MemoryProfilable { bool hasInvalidBoundary() const { return _boundaryHandler.hasInvalidBoundary();} - void processBoundaryConditions(); + void processBoundaryConditions(ParticleContainer* moleculeContainer, double timestepLength); - void removeNonPeriodicHalos(); + void removeNonPeriodicHalos(ParticleContainer* moleculeContainer); protected: void addLeavingMolecules(std::vector& invalidMolecules, ParticleContainer* moleculeContainer); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 943d76e665..5cb770236f 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -140,10 +140,7 @@ bool BoundaryHandler::isOuterWall(int dimension) const { return isOuterWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -bool BoundaryHandler::processOuterWallLeavingParticles() { - auto moleculeContainer = global_simulation->getMoleculeContainer(); // :-( - double timestepLength = - (global_simulation->getIntegrator())->getTimestepLength(); +void BoundaryHandler::processOuterWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength) { double cutoff = moleculeContainer->getCutoff(); for (auto const ¤tWall : _isOuterWall) { if (!currentWall.second) // not an outer wall @@ -201,11 +198,9 @@ bool BoundaryHandler::processOuterWallLeavingParticles() { mardyn_exit(1); } } - return true; } -void BoundaryHandler::removeNonPeriodicHalos() { - auto moleculeContainer = global_simulation->getMoleculeContainer(); +void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer* moleculeContainer) { double buffers[] = { moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), moleculeContainer->get_halo_L(1) + moleculeContainer->getSkin(), @@ -235,6 +230,7 @@ void BoundaryHandler::removeNonPeriodicHalos() { auto particlesInRegion = moleculeContainer->regionIterator( cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); for (auto it = particlesInRegion; it.isValid(); ++it) { + moleculeContainer->deleteMolecule(it, false); } break; diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 5ced5be0b1..3cac703441 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -8,6 +8,7 @@ #pragma once #include "BoundaryUtils.h" +#include "particleContainer/ParticleContainer.h" #include #include @@ -36,8 +37,8 @@ class BoundaryHandler { void findOuterWallsInLocalRegion(); bool isOuterWall(BoundaryUtils::DimensionType dimension) const; bool isOuterWall(int dimension) const; - bool processOuterWallLeavingParticles(); - void removeNonPeriodicHalos(); + void processOuterWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength); + void removeNonPeriodicHalos(ParticleContainer* moleculeContainer); private: std::map diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 57be9f6046..081107e53b 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -242,9 +242,9 @@ bool BoundaryUtils::isMoleculeLeaving(const Molecule molecule, double newPos = molecule.r(ls1dim) + (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); - if (newPos < regionBegin[ls1dim] && direction < 0) + if (newPos <= regionBegin[ls1dim] && direction < 0) return true; - if (newPos > regionEnd[ls1dim] && direction > 0) + if (newPos >= regionEnd[ls1dim] && direction > 0) return true; return false; } From 6359485a70a9dd0dbe3d0a7ee5206c8df47d1ca0 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 4 Sep 2024 16:56:10 +0200 Subject: [PATCH 50/94] renames, documentation --- src/Simulation.cpp | 1 + src/parallel/DomainDecompBase.cpp | 4 +- src/parallel/DomainDecompBase.h | 5 ++ src/parallel/GeneralDomainDecomposition.cpp | 2 +- src/parallel/KDDecomposition.cpp | 2 +- src/parallel/boundaries/BoundaryHandler.cpp | 51 ++++++++----- src/parallel/boundaries/BoundaryHandler.h | 85 +++++++++++++++++++-- src/parallel/boundaries/BoundaryUtils.h | 17 ++++- 8 files changed, 133 insertions(+), 34 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 8faf5079a7..c62141a6c8 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -439,6 +439,7 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { Log::global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; exit(1); } + // go over all local boundaries, determine which are global _domainDecomposition->setLocalBoundariesFromGlobal(_domain, _ensemble); xmlconfig.changecurrentnode(".."); } diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index a7149600f9..c3162c8d4a 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -40,12 +40,12 @@ void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* en _boundaryHandler.setLocalRegion(startRegion, endRegion); _boundaryHandler.setGlobalRegion(globStartRegion, globEndRegion); - _boundaryHandler.findOuterWallsInLocalRegion(); + _boundaryHandler.findGlobalWallsInLocalRegion(); } void DomainDecompBase::processBoundaryConditions(ParticleContainer* moleculeContainer, double timestepLength) { if(_boundaryHandler.hasNonPeriodicBoundary()) - _boundaryHandler.processOuterWallLeavingParticles(moleculeContainer, timestepLength); + _boundaryHandler.processGlobalWallLeavingParticles(moleculeContainer, timestepLength); } void DomainDecompBase::removeNonPeriodicHalos(ParticleContainer* moleculeContainer) { diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index 49ddf5e556..68a29e005e 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -290,14 +290,19 @@ class DomainDecompBase: public MemoryProfilable { virtual void printCommunicationPartners(std::string filename) const {}; + /* Set the gloabl boundary type for the _boundaryHandler object. */ void setGlobalBoundaryType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary); + /* Find which boundaries of a subdomain are actually global boundaries, and update _boundaryHandler. */ void setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble); + /* Check if any of the global boundaries are invalid. */ bool hasInvalidBoundary() const { return _boundaryHandler.hasInvalidBoundary();} + /* Processes leaving particles according to the boundary coundition of the wall the particles would be leaving. */ void processBoundaryConditions(ParticleContainer* moleculeContainer, double timestepLength); + /* Delete all halo particles outside global boundas that are non-periodic. */ void removeNonPeriodicHalos(ParticleContainer* moleculeContainer); protected: diff --git a/src/parallel/GeneralDomainDecomposition.cpp b/src/parallel/GeneralDomainDecomposition.cpp index a11975e0b1..e5e3fd6eed 100644 --- a/src/parallel/GeneralDomainDecomposition.cpp +++ b/src/parallel/GeneralDomainDecomposition.cpp @@ -133,7 +133,7 @@ void GeneralDomainDecomposition::balanceAndExchange(double lastTraversalTime, bo } } _boundaryHandler.setLocalRegion(_boxMin,_boxMax); - _boundaryHandler.findOuterWallsInLocalRegion(); + _boundaryHandler.findGlobalWallsInLocalRegion(); } ++_steps; } diff --git a/src/parallel/KDDecomposition.cpp b/src/parallel/KDDecomposition.cpp index a44f520822..753be1eb75 100644 --- a/src/parallel/KDDecomposition.cpp +++ b/src/parallel/KDDecomposition.cpp @@ -331,7 +331,7 @@ void KDDecomposition::balanceAndExchange(double lastTraversalTime, bool forceReb double startRegion[3], endRegion[3]; getBoundingBoxMinMax(domain, startRegion, endRegion); _boundaryHandler.setLocalRegion(startRegion,endRegion); - _boundaryHandler.findOuterWallsInLocalRegion(); + _boundaryHandler.findGlobalWallsInLocalRegion(); } } diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 5cb770236f..9d46190832 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -86,18 +86,18 @@ void BoundaryHandler::setLocalRegion(std::array start, _localRegionEnd = end; } -void BoundaryHandler::findOuterWallsInLocalRegion() { - _isOuterWall[BoundaryUtils::DimensionType::POSX] = +void BoundaryHandler::findGlobalWallsInLocalRegion() { + _isGlobalWall[BoundaryUtils::DimensionType::POSX] = (_localRegionEnd[0] == _globalRegionEnd[0]); - _isOuterWall[BoundaryUtils::DimensionType::NEGX] = + _isGlobalWall[BoundaryUtils::DimensionType::NEGX] = (_localRegionStart[0] == _globalRegionStart[0]); - _isOuterWall[BoundaryUtils::DimensionType::POSY] = + _isGlobalWall[BoundaryUtils::DimensionType::POSY] = (_localRegionEnd[1] == _globalRegionEnd[1]); - _isOuterWall[BoundaryUtils::DimensionType::NEGY] = + _isGlobalWall[BoundaryUtils::DimensionType::NEGY] = (_localRegionStart[1] == _globalRegionStart[1]); - _isOuterWall[BoundaryUtils::DimensionType::POSZ] = + _isGlobalWall[BoundaryUtils::DimensionType::POSZ] = (_localRegionEnd[2] == _globalRegionEnd[2]); - _isOuterWall[BoundaryUtils::DimensionType::NEGZ] = + _isGlobalWall[BoundaryUtils::DimensionType::NEGZ] = (_localRegionStart[2] == _globalRegionStart[2]); } @@ -131,19 +131,19 @@ bool BoundaryHandler::hasNonPeriodicBoundary() const { BoundaryUtils::BoundaryType::PERIODIC; } -bool BoundaryHandler::isOuterWall( +bool BoundaryHandler::isGlobalWall( BoundaryUtils::DimensionType dimension) const { - return _isOuterWall.at(dimension); + return _isGlobalWall.at(dimension); } -bool BoundaryHandler::isOuterWall(int dimension) const { - return isOuterWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); +bool BoundaryHandler::isGlobalWall(int dimension) const { + return isGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -void BoundaryHandler::processOuterWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength) { +void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength) { double cutoff = moleculeContainer->getCutoff(); - for (auto const ¤tWall : _isOuterWall) { - if (!currentWall.second) // not an outer wall + for (auto const ¤tWall : _isGlobalWall) { + if (!currentWall.second) // not a global wall continue; switch (getGlobalWall(currentWall.first)) { @@ -153,7 +153,7 @@ void BoundaryHandler::processOuterWallLeavingParticles(ParticleContainer* molecu case BoundaryUtils::BoundaryType::OUTFLOW: case BoundaryUtils::BoundaryType::REFLECTING: { - // create region + // create region by using getInnerBuffer() std::array curWallRegionBegin, curWallRegionEnd; std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getInnerBuffer(_localRegionStart, _localRegionEnd, @@ -164,11 +164,15 @@ void BoundaryHandler::processOuterWallLeavingParticles(ParticleContainer* molecu const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; + // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( cstylerbegin, cstylerend, ParticleIterator::ONLY_INNER_AND_BOUNDARY); + + // iterate through all molecules for (auto it = particlesInRegion; it.isValid(); ++it) { Molecule curMolecule = *it; + // calculate the velocity adjustment from the leapfrog method int currentDim = BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); double halfTimestep = .5 * timestepLength; @@ -176,16 +180,19 @@ void BoundaryHandler::processOuterWallLeavingParticles(ParticleContainer* molecu double force = it->F(currentDim); double nextStepVelAdjustment = halfTimestepByMass * force; + // check if the molecule would leave the bounds if (BoundaryUtils::isMoleculeLeaving( curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength, nextStepVelAdjustment)) { if (getGlobalWall(currentWall.first) == BoundaryUtils::BoundaryType::REFLECTING) { double currentVel = it->v(currentDim); + // reflect the velocity, such that when the leapfrog integrator adds + // nextStepVelAdjustment in the next integration step, the final result + // ends up being currentVel+nextStepVelAdjustment in the negative direction of travel it->setv(currentDim, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); - } else // outflow - { + } else { // outflow, delete the particle if it would leave moleculeContainer->deleteMolecule(it, false); } } @@ -201,12 +208,13 @@ void BoundaryHandler::processOuterWallLeavingParticles(ParticleContainer* molecu } void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer* moleculeContainer) { + // get halo lengths in each dimension double buffers[] = { moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), moleculeContainer->get_halo_L(1) + moleculeContainer->getSkin(), moleculeContainer->get_halo_L(2) + moleculeContainer->getSkin()}; - for (auto const ¤tWall : _isOuterWall) { - if (!currentWall.second) // not an outer wall + for (auto const ¤tWall : _isGlobalWall) { + if (!currentWall.second) // not a global wall continue; switch (getGlobalWall(currentWall.first)) { @@ -216,7 +224,7 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer* moleculeContaine case BoundaryUtils::BoundaryType::OUTFLOW: case BoundaryUtils::BoundaryType::REFLECTING: { - // create region + // create region by using getOuterBuffer() std::array curWallRegionBegin, curWallRegionEnd; std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, @@ -227,10 +235,11 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer* moleculeContaine const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; + // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); for (auto it = particlesInRegion; it.isValid(); ++it) { - + // delete all halo particles moleculeContainer->deleteMolecule(it, false); } break; diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 3cac703441..5d87668708 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -15,35 +15,110 @@ #include #include +/** + * Class to handle boundary conditions, namely leaving and halo particles. + * + * The objects of this class store the local and global bounds of the subdomain in every process, + * and provide functions to deal with leaving particles, and delete halo particles. + * + * The internal walls of the subdomain, touching other subdomains are 'local' walls + * while the walls that are also the limits of the global domain are 'global' walls. + * + * Since the behaviour of 'local' walls are unchanged, they are assigned to 'PERIODIC'. + */ + class BoundaryHandler { public: BoundaryHandler(); + + /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType getGlobalWall(std::string dimension) const; + + /* Set the boundary type of a global wall for a particular dimension. */ void setGlobalWall(std::string dimension, BoundaryUtils::BoundaryType value); + + /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType getGlobalWall(BoundaryUtils::DimensionType dimension) const; + + /* Set the boundary type of a global wall for a particular dimension. */ void setGlobalWall(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); BoundaryUtils::BoundaryType getGlobalWall(int dimension) const; + + /* Check if any of the global boundaries are invalid. */ bool hasInvalidBoundary() const; + + /** + * Check if any of the global boundaries are non-periodic. + * + * This check helps bypass all boundary-related code if default behaviour (all periodic boundaries) is expected. + */ bool hasNonPeriodicBoundary() const; + /* Set bounds for local subdomain. */ void setGlobalRegion(double *start, double *end); + + /* Set bounds for global subdomain. */ void setLocalRegion(double *start, double *end); + /* Set bounds for local subdomain. */ void setGlobalRegion(std::array start, std::array end); + + /* Set bounds for global subdomain.*/ void setLocalRegion(std::array start, std::array end); - void findOuterWallsInLocalRegion(); - bool isOuterWall(BoundaryUtils::DimensionType dimension) const; - bool isOuterWall(int dimension) const; - void processOuterWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength); + /** + * Determine which walls in the local region are actually global walls. + * + * Should be called after changing global and local regions (typically after a rebalance). + */ + void findGlobalWallsInLocalRegion(); + + /* Check if the local wall in a particular dimension is actually a global wall. */ + bool isGlobalWall(BoundaryUtils::DimensionType dimension) const; + + /* Check if the local wall in a particular dimension is actually a global wall. */ + bool isGlobalWall(int dimension) const; + + /** + * Processes all particles that would leave the global domain. + * + * If a subdomain has no global walls, this function does nothing. + * For every global wall, the fucktion iterates through all particles that are one cutoff distance away + * from the wall. If these particles would leave the global box in the next simulation, the following is done: + * + * PERIODIC - nop (default behaviour). + * REFLECTING - The particle's velocity is reversed normal to the wall it's leaving. + * OUTFLOW - The particle is deleted. + */ + void processGlobalWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength); + + /** + * Processes all halo particles outside the global domain. + * + * If a subdomain has no global walls, this function does nothing. + * For every global wall, the fucktion iterates through all halo particles that are one cutoff distance away + * from the wall. The following is done for each particle: + * + * PERIODIC - nop (default behaviour). + * REFLECTING - The halo particle is deleted. + * OUTFLOW - The halo particle is deleted. + */ void removeNonPeriodicHalos(ParticleContainer* moleculeContainer); private: + +/* List of global boundary type per dimension. */ std::map _boundaries; - std::map _isOuterWall; + + /* Lookup table to check if a local wall is also global. */ + std::map _isGlobalWall; + + /* Global region start/end. */ std::array _globalRegionStart, _globalRegionEnd; + + /* Local region start/end. */ std::array _localRegionStart, _localRegionEnd; }; \ No newline at end of file diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 4288c45e4c..f6fd279096 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -38,16 +38,24 @@ enum class BoundaryType { PERIODIC, OUTFLOW, REFLECTING, ERROR }; /** * enum storing the axes and direction. + * + * The dimensions are POSX, NEGX, POSY, NEGY, POSZ and NEGZ. * - * This is fixed for 3D, and ERROR is included for sanity checks + * This is hardcoded for 3D, and ERROR is included for sanity checks. */ enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; +/* List of all allowed dimensions in string format. */ const std::array permissibleDimensionsString = { "+x", "+y", "+z", "-x", "-y", "-z"}; + +/* List of all allowed dimensions in int format. */ const std::array permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; +/* Check if a dimension is allowed. */ bool isDimensionStringPermissible(std::string dimension); + +/* Check if a dimension is allowed. */ bool isDimensionNumericPermissible(int dim); DimensionType convertStringToDimension(std::string dimension); @@ -61,9 +69,7 @@ int convertDimensionToNumeric(DimensionType dimension); int convertDimensionToNumericAbs(DimensionType dimension); int convertDimensionToLS1Dims(DimensionType dimension); -/** - * Used to convert string read from the XML input file - */ +/* Used to convert string read from the XML input file. */ BoundaryType convertStringToBoundary(std::string boundary); /** @@ -118,7 +124,10 @@ getOuterBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double *regionWidth); +/* Returns the sign of a number, used for determining direction from a dimension. */ inline int findSign(int n) { return n < 0 ? -1 : 1; } + +/* Returns the sign of a number, used for determining direction from a dimension. */ inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } From 6f7632a92a4679f1264beff3b8a62047aee0655f Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 4 Sep 2024 16:58:41 +0200 Subject: [PATCH 51/94] clangformat --- src/parallel/boundaries/BoundaryHandler.cpp | 11 ++-- src/parallel/boundaries/BoundaryHandler.h | 65 ++++++++++++--------- src/parallel/boundaries/BoundaryUtils.h | 8 ++- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 9d46190832..0db3ac74ca 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -140,7 +140,8 @@ bool BoundaryHandler::isGlobalWall(int dimension) const { return isGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength) { +void BoundaryHandler::processGlobalWallLeavingParticles( + ParticleContainer *moleculeContainer, double timestepLength) { double cutoff = moleculeContainer->getCutoff(); for (auto const ¤tWall : _isGlobalWall) { if (!currentWall.second) // not a global wall @@ -188,8 +189,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer* molec BoundaryUtils::BoundaryType::REFLECTING) { double currentVel = it->v(currentDim); // reflect the velocity, such that when the leapfrog integrator adds - // nextStepVelAdjustment in the next integration step, the final result - // ends up being currentVel+nextStepVelAdjustment in the negative direction of travel + // nextStepVelAdjustment in the next integration step, the final + // result ends up being currentVel+nextStepVelAdjustment in the + // negative direction of travel it->setv(currentDim, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); } else { // outflow, delete the particle if it would leave @@ -207,7 +209,8 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer* molec } } -void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer* moleculeContainer) { +void BoundaryHandler::removeNonPeriodicHalos( + ParticleContainer *moleculeContainer) { // get halo lengths in each dimension double buffers[] = { moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 5d87668708..ddd8a14b91 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -17,14 +17,17 @@ /** * Class to handle boundary conditions, namely leaving and halo particles. - * - * The objects of this class store the local and global bounds of the subdomain in every process, - * and provide functions to deal with leaving particles, and delete halo particles. - * - * The internal walls of the subdomain, touching other subdomains are 'local' walls - * while the walls that are also the limits of the global domain are 'global' walls. - * - * Since the behaviour of 'local' walls are unchanged, they are assigned to 'PERIODIC'. + * + * The objects of this class store the local and global bounds of the subdomain + * in every process, and provide functions to deal with leaving particles, and + * delete halo particles. + * + * The internal walls of the subdomain, touching other subdomains are 'local' + * walls while the walls that are also the limits of the global domain are + * 'global' walls. + * + * Since the behaviour of 'local' walls are unchanged, they are assigned to + * 'PERIODIC'. */ class BoundaryHandler { @@ -51,8 +54,9 @@ class BoundaryHandler { /** * Check if any of the global boundaries are non-periodic. - * - * This check helps bypass all boundary-related code if default behaviour (all periodic boundaries) is expected. + * + * This check helps bypass all boundary-related code if default behaviour + * (all periodic boundaries) is expected. */ bool hasNonPeriodicBoundary() const; @@ -70,46 +74,51 @@ class BoundaryHandler { /** * Determine which walls in the local region are actually global walls. - * - * Should be called after changing global and local regions (typically after a rebalance). + * + * Should be called after changing global and local regions (typically after a + * rebalance). */ void findGlobalWallsInLocalRegion(); - /* Check if the local wall in a particular dimension is actually a global wall. */ + /* Check if the local wall in a particular dimension is actually a global + * wall. */ bool isGlobalWall(BoundaryUtils::DimensionType dimension) const; - /* Check if the local wall in a particular dimension is actually a global wall. */ + /* Check if the local wall in a particular dimension is actually a global + * wall. */ bool isGlobalWall(int dimension) const; /** * Processes all particles that would leave the global domain. - * + * * If a subdomain has no global walls, this function does nothing. - * For every global wall, the fucktion iterates through all particles that are one cutoff distance away - * from the wall. If these particles would leave the global box in the next simulation, the following is done: - * + * For every global wall, the fucktion iterates through all particles that are + * one cutoff distance away from the wall. If these particles would leave the + * global box in the next simulation, the following is done: + * * PERIODIC - nop (default behaviour). - * REFLECTING - The particle's velocity is reversed normal to the wall it's leaving. - * OUTFLOW - The particle is deleted. + * REFLECTING - The particle's velocity is reversed normal to the wall it's + * leaving. OUTFLOW - The particle is deleted. */ - void processGlobalWallLeavingParticles(ParticleContainer* moleculeContainer, double timestepLength); + void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, + double timestepLength); /** * Processes all halo particles outside the global domain. - * + * * If a subdomain has no global walls, this function does nothing. - * For every global wall, the fucktion iterates through all halo particles that are one cutoff distance away - * from the wall. The following is done for each particle: - * + * For every global wall, the fucktion iterates through all halo particles + * that are one cutoff distance away from the wall. The following is done for + * each particle: + * * PERIODIC - nop (default behaviour). * REFLECTING - The halo particle is deleted. * OUTFLOW - The halo particle is deleted. */ - void removeNonPeriodicHalos(ParticleContainer* moleculeContainer); + void removeNonPeriodicHalos(ParticleContainer *moleculeContainer); private: - -/* List of global boundary type per dimension. */ + /* List of global boundary type per dimension. */ std::map _boundaries; diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index f6fd279096..e6bdbdd883 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -38,7 +38,7 @@ enum class BoundaryType { PERIODIC, OUTFLOW, REFLECTING, ERROR }; /** * enum storing the axes and direction. - * + * * The dimensions are POSX, NEGX, POSY, NEGY, POSZ and NEGZ. * * This is hardcoded for 3D, and ERROR is included for sanity checks. @@ -124,10 +124,12 @@ getOuterBuffer(const std::array givenRegionBegin, const std::array givenRegionEnd, DimensionType dimension, double *regionWidth); -/* Returns the sign of a number, used for determining direction from a dimension. */ +/* Returns the sign of a number, used for determining direction from a + * dimension. */ inline int findSign(int n) { return n < 0 ? -1 : 1; } -/* Returns the sign of a number, used for determining direction from a dimension. */ +/* Returns the sign of a number, used for determining direction from a + * dimension. */ inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } From c79562d9b207aba39e6d1e6265a8f1c2031d4bb6 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 10 Sep 2024 16:18:23 +0200 Subject: [PATCH 52/94] newlines for static code checker --- src/parallel/boundaries/BoundaryHandler.cpp | 2 +- src/parallel/boundaries/BoundaryHandler.h | 2 +- src/parallel/boundaries/BoundaryUtils.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 0db3ac74ca..4e3de41bb6 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -256,4 +256,4 @@ void BoundaryHandler::removeNonPeriodicHalos( #ifndef MARDYN_AUTOPAS moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); #endif -} \ No newline at end of file +} diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index ddd8a14b91..a6d4691647 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -130,4 +130,4 @@ class BoundaryHandler { /* Local region start/end. */ std::array _localRegionStart, _localRegionEnd; -}; \ No newline at end of file +}; diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index e6bdbdd883..abf0b0867a 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -133,4 +133,4 @@ inline int findSign(int n) { return n < 0 ? -1 : 1; } inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } -} // namespace BoundaryUtils \ No newline at end of file +} // namespace BoundaryUtils From 57fc6fd9edeba9a30f7dc5ac6183f20e7ea613a4 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 15:32:50 +0200 Subject: [PATCH 53/94] removed unused code that dealt with halo cells --- src/parallel/boundaries/BoundaryUtils.cpp | 13 +------------ src/parallel/boundaries/BoundaryUtils.h | 4 ---- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 081107e53b..a99d6ec257 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -20,6 +20,7 @@ bool BoundaryUtils::isDimensionStringPermissible(std::string dimension) { } bool BoundaryUtils::isDimensionNumericPermissible(int dim) { + // permissible dimensions are {-1, -2, -3, 1, 2, 3} return (dim >= -3 && dim <= 3 && dim != 0); } @@ -95,18 +96,6 @@ BoundaryUtils::convertLS1DimsToDimensionPos(int dim) { return toRet; } -std::vector -BoundaryUtils::convertHaloOffsetToDimensionVector(int *offset) { - std::vector toRet; - for (int i = 0; i < 3; i++) { - if (offset[i] != 0) { - int numeric = (i + 1) * offset[i]; - toRet.push_back(convertNumericToDimension(numeric)); - } - } - return toRet; -} - std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) { switch (dimension) { case DimensionType::POSX: diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index abf0b0867a..b0dcd8b8b0 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -49,9 +49,6 @@ enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; const std::array permissibleDimensionsString = { "+x", "+y", "+z", "-x", "-y", "-z"}; -/* List of all allowed dimensions in int format. */ -const std::array permissibleDimensionsInt = {-1, -2, -3, 1, 2, 3}; - /* Check if a dimension is allowed. */ bool isDimensionStringPermissible(std::string dimension); @@ -61,7 +58,6 @@ bool isDimensionNumericPermissible(int dim); DimensionType convertStringToDimension(std::string dimension); DimensionType convertNumericToDimension(int dim); DimensionType convertLS1DimsToDimensionPos(int dim); -std::vector convertHaloOffsetToDimensionVector(int *offset); std::string convertDimensionToString(DimensionType dimension); std::string convertDimensionToStringAbs(DimensionType dimension); From 3caeec9e834205f631dbeec48d6d7d90edea80ec Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 15:41:31 +0200 Subject: [PATCH 54/94] pass molecule by reference --- src/parallel/boundaries/BoundaryUtils.cpp | 2 +- src/parallel/boundaries/BoundaryUtils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index a99d6ec257..40b860ae1c 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -220,7 +220,7 @@ BoundaryUtils::getInnerBuffer(const std::array givenRegionBegin, return std::make_tuple(returnRegionBegin, returnRegionEnd); } -bool BoundaryUtils::isMoleculeLeaving(const Molecule molecule, +bool BoundaryUtils::isMoleculeLeaving(const Molecule &molecule, const std::array regionBegin, const std::array regionEnd, DimensionType dimension, diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index b0dcd8b8b0..b2d6918e5a 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -98,7 +98,7 @@ getInnerBuffer(const std::array givenRegionBegin, * so that it can handle the change in velocity due to forces. This is not done * by the util function itself, to keep it as generic as possible. */ -bool isMoleculeLeaving(const Molecule molecule, +bool isMoleculeLeaving(const Molecule &molecule, const std::array regionBegin, const std::array regionEnd, DimensionType dimension, double timestepLength, From e292e8f4f2fbde45b83c5963c83a8fea2acbe52c Mon Sep 17 00:00:00 2001 From: Amartya Das Sharma Date: Wed, 11 Sep 2024 16:37:14 +0200 Subject: [PATCH 55/94] Apply suggestions from code review Co-authored-by: Samuel Newcome <97889602+SamNewcome@users.noreply.github.com> --- src/parallel/DomainDecompBase.cpp | 4 +-- src/parallel/boundaries/BoundaryHandler.cpp | 19 ++++++------- src/parallel/boundaries/BoundaryHandler.h | 31 +++++++++++---------- src/parallel/boundaries/BoundaryUtils.cpp | 16 +++++------ src/parallel/boundaries/BoundaryUtils.h | 4 +-- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index c3162c8d4a..4207a2c4d7 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -35,8 +35,8 @@ void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* en double startRegion[3], endRegion[3]; getBoundingBoxMinMax(domain, startRegion, endRegion); - double* globStartRegion = ensemble->domain()->rmin(); - double* globEndRegion = ensemble->domain()->rmax(); + const double* globStartRegion = ensemble->domain()->rmin(); + const double* globEndRegion = ensemble->domain()->rmax(); _boundaryHandler.setLocalRegion(startRegion, endRegion); _boundaryHandler.setGlobalRegion(globStartRegion, globEndRegion); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 4e3de41bb6..58dbb7f298 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -173,13 +173,13 @@ void BoundaryHandler::processGlobalWallLeavingParticles( for (auto it = particlesInRegion; it.isValid(); ++it) { Molecule curMolecule = *it; - // calculate the velocity adjustment from the leapfrog method - int currentDim = + // Calculate the change in velocity, which the leapfrog method will apply in the next velocity update to the dimension of interest. + const int currentDim = BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); - double halfTimestep = .5 * timestepLength; - double halfTimestepByMass = halfTimestep / it->mass(); - double force = it->F(currentDim); - double nextStepVelAdjustment = halfTimestepByMass * force; + const double halfTimestep = .5 * timestepLength; + const double halfTimestepByMass = halfTimestep / it->mass(); + const double force = it->F(currentDim); + const double nextStepVelAdjustment = halfTimestepByMass * force; // check if the molecule would leave the bounds if (BoundaryUtils::isMoleculeLeaving( @@ -188,10 +188,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles( if (getGlobalWall(currentWall.first) == BoundaryUtils::BoundaryType::REFLECTING) { double currentVel = it->v(currentDim); - // reflect the velocity, such that when the leapfrog integrator adds - // nextStepVelAdjustment in the next integration step, the final - // result ends up being currentVel+nextStepVelAdjustment in the - // negative direction of travel + // change the velocity in the dimension of interest such that when the leapfrog integrator adds + // nextStepVelAdjustment in the next velocity update, the final + // result ends up being the intended, reversed velocity: -(currentVel+nextStepVelAdjustment) it->setv(currentDim, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); } else { // outflow, delete the particle if it would leave diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index a6d4691647..d965b101d8 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -35,21 +35,21 @@ class BoundaryHandler { BoundaryHandler(); /* Find the boundary type of a global wall for a particular dimension. */ - BoundaryUtils::BoundaryType getGlobalWall(std::string dimension) const; + BoundaryUtils::BoundaryType getGlobalWallType(std::string dimension) const; /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWall(std::string dimension, BoundaryUtils::BoundaryType value); + void setGlobalWallType(std::string dimension, BoundaryUtils::BoundaryType value); /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType - getGlobalWall(BoundaryUtils::DimensionType dimension) const; + getGlobalWallType(BoundaryUtils::DimensionType dimension) const; /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWall(BoundaryUtils::DimensionType dimension, + void setGlobalWallType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); - BoundaryUtils::BoundaryType getGlobalWall(int dimension) const; + BoundaryUtils::BoundaryType getGlobalWallType(int dimension) const; - /* Check if any of the global boundaries are invalid. */ + /* Check if any of the global boundaries have invalid types. */ bool hasInvalidBoundary() const; /** @@ -60,16 +60,16 @@ class BoundaryHandler { */ bool hasNonPeriodicBoundary() const; - /* Set bounds for local subdomain. */ + /* Set bounds for global subdomain. */ void setGlobalRegion(double *start, double *end); - /* Set bounds for global subdomain. */ + /* Set bounds for local subdomain. */ void setLocalRegion(double *start, double *end); - /* Set bounds for local subdomain. */ + /* Set bounds for global subdomain. */ void setGlobalRegion(std::array start, std::array end); - /* Set bounds for global subdomain.*/ + /* Set bounds for local subdomain.*/ void setLocalRegion(std::array start, std::array end); /** @@ -92,13 +92,14 @@ class BoundaryHandler { * Processes all particles that would leave the global domain. * * If a subdomain has no global walls, this function does nothing. - * For every global wall, the fucktion iterates through all particles that are - * one cutoff distance away from the wall. If these particles would leave the + * For every global wall, the function iterates through all particles that are + * within one cutoff distance away from the wall. If these particles would leave the * global box in the next simulation, the following is done: * * PERIODIC - nop (default behaviour). * REFLECTING - The particle's velocity is reversed normal to the wall it's - * leaving. OUTFLOW - The particle is deleted. + * leaving. + * OUTFLOW - The particle is deleted. */ void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, double timestepLength); @@ -107,8 +108,8 @@ class BoundaryHandler { * Processes all halo particles outside the global domain. * * If a subdomain has no global walls, this function does nothing. - * For every global wall, the fucktion iterates through all halo particles - * that are one cutoff distance away from the wall. The following is done for + * For every global wall, the function iterates through all halo particles + * that are within one cutoff distance away from the wall. The following is done for * each particle: * * PERIODIC - nop (default behaviour). diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 40b860ae1c..7601c57bfa 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -159,7 +159,7 @@ int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) { int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) { int toReturn = convertDimensionToNumeric(dimension); - return findSign(toReturn) * toReturn; + return std::abs(toReturn); } int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { @@ -189,7 +189,7 @@ BoundaryUtils::getInnerBuffer(const std::array givenRegionBegin, returnRegionEnd[i] = givenRegionEnd[i]; } - int dimensionLS1 = convertDimensionToLS1Dims(dimension); + const int dimensionLS1 = convertDimensionToLS1Dims(dimension); switch (dimension) // can be done with findsign() too, but this is clearer { @@ -226,9 +226,9 @@ bool BoundaryUtils::isMoleculeLeaving(const Molecule &molecule, DimensionType dimension, double timestepLength, double nextStepVelAdjustment) { - int ls1dim = convertDimensionToLS1Dims(dimension); - int direction = findSign(dimension); - double newPos = + const int ls1dim = convertDimensionToLS1Dims(dimension); + const int direction = findSign(dimension); + const double newPos = molecule.r(ls1dim) + (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); if (newPos <= regionBegin[ls1dim] && direction < 0) @@ -248,11 +248,11 @@ BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, returnRegionEnd[i] = givenRegionEnd[i]; } - int dimensionLS1 = convertDimensionToLS1Dims(dimension); + const int dimensionLS1 = convertDimensionToLS1Dims(dimension); // find the two dimensions that are not being considered - int extraDim1 = dimensionLS1 == 0 ? 1 : 0; - int extraDim2 = dimensionLS1 == 2 ? 1 : 2; + const int extraDim1 = dimensionLS1 == 0 ? 1 : 0; + const int extraDim2 = dimensionLS1 == 2 ? 1 : 2; // extend the extra dimensions to cover all ghost areas returnRegionBegin[extraDim1] = diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index b2d6918e5a..5d36642daf 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -26,7 +26,7 @@ namespace BoundaryUtils { * enum storing the types of boundaries currently supported. * * The currently supported boundary types are - * PERIODIC - default behaviour, periodic boundaries + * PERIODIC_OR_LOCAL - periodic boundaries or local boundaries: both of which use the default (communicate particle transfers with neighbours) behaviour * OUTFLOW - molecules exiting the boundary are deleted * REFLECTING - molecules exiting the boundary have their velocities * reversed in the direction they are leaving @@ -34,7 +34,7 @@ namespace BoundaryUtils { * * This can be extended if needed. */ -enum class BoundaryType { PERIODIC, OUTFLOW, REFLECTING, ERROR }; +enum class BoundaryType { PERIODIC_OR_LOCAL, OUTFLOW, REFLECTING, ERROR }; /** * enum storing the axes and direction. From c20a668bd2eec997f0f0f61419a2ef5ed7cb5d3e Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 16:48:05 +0200 Subject: [PATCH 56/94] replace PERIODIC in more places, documentation --- src/parallel/boundaries/BoundaryHandler.cpp | 67 +++++++++++---------- src/parallel/boundaries/BoundaryHandler.h | 29 +++++---- src/parallel/boundaries/BoundaryUtils.cpp | 2 +- src/parallel/boundaries/BoundaryUtils.h | 3 +- 4 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 58dbb7f298..b948aa95d8 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -16,48 +16,49 @@ BoundaryHandler::BoundaryHandler() : _boundaries{{BoundaryUtils::DimensionType::POSX, - BoundaryUtils::BoundaryType::PERIODIC}, + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, {BoundaryUtils::DimensionType::POSY, - BoundaryUtils::BoundaryType::PERIODIC}, + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, {BoundaryUtils::DimensionType::POSZ, - BoundaryUtils::BoundaryType::PERIODIC}, + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, {BoundaryUtils::DimensionType::NEGX, - BoundaryUtils::BoundaryType::PERIODIC}, + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, {BoundaryUtils::DimensionType::NEGY, - BoundaryUtils::BoundaryType::PERIODIC}, + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, {BoundaryUtils::DimensionType::NEGZ, - BoundaryUtils::BoundaryType::PERIODIC}, + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, {BoundaryUtils::DimensionType::ERROR, BoundaryUtils::BoundaryType::ERROR}} {} -BoundaryUtils::BoundaryType -BoundaryHandler::getGlobalWall(BoundaryUtils::DimensionType dimension) const { +BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType( + BoundaryUtils::DimensionType dimension) const { return _boundaries.at(dimension); } BoundaryUtils::BoundaryType -BoundaryHandler::getGlobalWall(std::string dimension) const { +BoundaryHandler::getGlobalWallType(std::string dimension) const { BoundaryUtils::DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); - return getGlobalWall(convertedDimension); + return getGlobalWallType(convertedDimension); } BoundaryUtils::BoundaryType -BoundaryHandler::getGlobalWall(int dimension) const { - return getGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); +BoundaryHandler::getGlobalWallType(int dimension) const { + return getGlobalWallType( + BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); } -void BoundaryHandler::setGlobalWall(BoundaryUtils::DimensionType dimension, - BoundaryUtils::BoundaryType value) { +void BoundaryHandler::setGlobalWallType(BoundaryUtils::DimensionType dimension, + BoundaryUtils::BoundaryType value) { if (dimension != BoundaryUtils::DimensionType::ERROR) _boundaries[dimension] = value; } -void BoundaryHandler::setGlobalWall(std::string dimension, - BoundaryUtils::BoundaryType value) { +void BoundaryHandler::setGlobalWallType(std::string dimension, + BoundaryUtils::BoundaryType value) { BoundaryUtils::DimensionType convertedDimension = BoundaryUtils::convertStringToDimension(dimension); - setGlobalWall(convertedDimension, value); + setGlobalWallType(convertedDimension, value); } void BoundaryHandler::setGlobalRegion(double *start, double *end) { @@ -118,17 +119,17 @@ bool BoundaryHandler::hasInvalidBoundary() const { bool BoundaryHandler::hasNonPeriodicBoundary() const { return _boundaries.at(BoundaryUtils::DimensionType::POSX) != - BoundaryUtils::BoundaryType::PERIODIC || + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || _boundaries.at(BoundaryUtils::DimensionType::POSY) != - BoundaryUtils::BoundaryType::PERIODIC || + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || _boundaries.at(BoundaryUtils::DimensionType::POSZ) != - BoundaryUtils::BoundaryType::PERIODIC || + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || _boundaries.at(BoundaryUtils::DimensionType::NEGX) != - BoundaryUtils::BoundaryType::PERIODIC || + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || _boundaries.at(BoundaryUtils::DimensionType::NEGY) != - BoundaryUtils::BoundaryType::PERIODIC || + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || _boundaries.at(BoundaryUtils::DimensionType::NEGZ) != - BoundaryUtils::BoundaryType::PERIODIC; + BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL; } bool BoundaryHandler::isGlobalWall( @@ -147,8 +148,8 @@ void BoundaryHandler::processGlobalWallLeavingParticles( if (!currentWall.second) // not a global wall continue; - switch (getGlobalWall(currentWall.first)) { - case BoundaryUtils::BoundaryType::PERIODIC: + switch (getGlobalWallType(currentWall.first)) { + case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: // default behaviour break; @@ -173,7 +174,8 @@ void BoundaryHandler::processGlobalWallLeavingParticles( for (auto it = particlesInRegion; it.isValid(); ++it) { Molecule curMolecule = *it; - // Calculate the change in velocity, which the leapfrog method will apply in the next velocity update to the dimension of interest. + // Calculate the change in velocity, which the leapfrog method will + // apply in the next velocity update to the dimension of interest. const int currentDim = BoundaryUtils::convertDimensionToLS1Dims(currentWall.first); const double halfTimestep = .5 * timestepLength; @@ -185,12 +187,13 @@ void BoundaryHandler::processGlobalWallLeavingParticles( if (BoundaryUtils::isMoleculeLeaving( curMolecule, curWallRegionBegin, curWallRegionEnd, currentWall.first, timestepLength, nextStepVelAdjustment)) { - if (getGlobalWall(currentWall.first) == + if (getGlobalWallType(currentWall.first) == BoundaryUtils::BoundaryType::REFLECTING) { double currentVel = it->v(currentDim); - // change the velocity in the dimension of interest such that when the leapfrog integrator adds - // nextStepVelAdjustment in the next velocity update, the final - // result ends up being the intended, reversed velocity: -(currentVel+nextStepVelAdjustment) + // change the velocity in the dimension of interest such that when + // the leapfrog integrator adds nextStepVelAdjustment in the next + // velocity update, the final result ends up being the intended, + // reversed velocity: -(currentVel+nextStepVelAdjustment) it->setv(currentDim, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); } else { // outflow, delete the particle if it would leave @@ -219,8 +222,8 @@ void BoundaryHandler::removeNonPeriodicHalos( if (!currentWall.second) // not a global wall continue; - switch (getGlobalWall(currentWall.first)) { - case BoundaryUtils::BoundaryType::PERIODIC: + switch (getGlobalWallType(currentWall.first)) { + case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: // default behaviour break; diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index d965b101d8..cd29bb3506 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -26,8 +26,9 @@ * walls while the walls that are also the limits of the global domain are * 'global' walls. * - * Since the behaviour of 'local' walls are unchanged, they are assigned to - * 'PERIODIC'. + * Since the behaviour of 'local' walls are unchanged (and is identical to the + * behaviour of global periodic walls), they are assigned to + * 'PERIODIC_OR_LOCAL'. */ class BoundaryHandler { @@ -38,7 +39,8 @@ class BoundaryHandler { BoundaryUtils::BoundaryType getGlobalWallType(std::string dimension) const; /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWallType(std::string dimension, BoundaryUtils::BoundaryType value); + void setGlobalWallType(std::string dimension, + BoundaryUtils::BoundaryType value); /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType @@ -46,7 +48,7 @@ class BoundaryHandler { /* Set the boundary type of a global wall for a particular dimension. */ void setGlobalWallType(BoundaryUtils::DimensionType dimension, - BoundaryUtils::BoundaryType value); + BoundaryUtils::BoundaryType value); BoundaryUtils::BoundaryType getGlobalWallType(int dimension) const; /* Check if any of the global boundaries have invalid types. */ @@ -93,12 +95,12 @@ class BoundaryHandler { * * If a subdomain has no global walls, this function does nothing. * For every global wall, the function iterates through all particles that are - * within one cutoff distance away from the wall. If these particles would leave the - * global box in the next simulation, the following is done: + * within one cutoff distance away from the wall. If these particles would + * leave the global box in the next simulation, the following is done: * - * PERIODIC - nop (default behaviour). + * PERIODIC_OR_LOCAL - No actions taken (default behaviour). * REFLECTING - The particle's velocity is reversed normal to the wall it's - * leaving. + * leaving. * OUTFLOW - The particle is deleted. */ void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, @@ -109,12 +111,13 @@ class BoundaryHandler { * * If a subdomain has no global walls, this function does nothing. * For every global wall, the function iterates through all halo particles - * that are within one cutoff distance away from the wall. The following is done for - * each particle: + * that are within one cutoff distance away from the wall. The following is + * done for each particle: * - * PERIODIC - nop (default behaviour). - * REFLECTING - The halo particle is deleted. - * OUTFLOW - The halo particle is deleted. + * PERIODIC_OR_LOCAL - No actions taken (default behaviour). + * REFLECTING / OUTFLOW - The halo particle is deleted, so that particles + * approaching the boundary do not decelerate due to influence from the halo + * particles, and preserve their velocities before being bounced/deleted */ void removeNonPeriodicHalos(ParticleContainer *moleculeContainer); diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 7601c57bfa..4e57bb8d89 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -169,7 +169,7 @@ int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(std::string boundary) { if (boundary == "periodic") - return BoundaryType::PERIODIC; + return BoundaryType::PERIODIC_OR_LOCAL; if (boundary == "reflecting" || boundary == "reflective") return BoundaryType::REFLECTING; if (boundary == "outflow") diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 5d36642daf..078e4a120d 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -26,7 +26,8 @@ namespace BoundaryUtils { * enum storing the types of boundaries currently supported. * * The currently supported boundary types are - * PERIODIC_OR_LOCAL - periodic boundaries or local boundaries: both of which use the default (communicate particle transfers with neighbours) behaviour + * PERIODIC_OR_LOCAL - periodic boundaries or local boundaries: both of which + * use the default (communicate particle transfers with neighbours) behaviour * OUTFLOW - molecules exiting the boundary are deleted * REFLECTING - molecules exiting the boundary have their velocities * reversed in the direction they are leaving From b133acbc24b5e4b689c17d74b4937ed70618b6dd Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 16:52:55 +0200 Subject: [PATCH 57/94] better variable names --- src/parallel/boundaries/BoundaryHandler.cpp | 23 ++++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index b948aa95d8..9b7d5decb4 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -160,15 +160,17 @@ void BoundaryHandler::processGlobalWallLeavingParticles( std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getInnerBuffer(_localRegionStart, _localRegionEnd, currentWall.first, cutoff); - // conversion - const double cstylerbegin[] = { + // convert the regions into c-style arrays, so that they can be passed to + // the region iterator + const double cStyleRegionBegin[] = { curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; - const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], - curWallRegionEnd[2]}; + const double cStyleRegionEnd[] = { + curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( - cstylerbegin, cstylerend, ParticleIterator::ONLY_INNER_AND_BOUNDARY); + cStyleRegionBegin, cStyleRegionEnd, + ParticleIterator::ONLY_INNER_AND_BOUNDARY); // iterate through all molecules for (auto it = particlesInRegion; it.isValid(); ++it) { @@ -234,15 +236,16 @@ void BoundaryHandler::removeNonPeriodicHalos( std::tie(curWallRegionBegin, curWallRegionEnd) = BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, currentWall.first, buffers); - // conversion - const double cstylerbegin[] = { + // convert the regions into c-style arrays, so that they can be passed to + // the region iterator + const double cStyleRegionBegin[] = { curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; - const double cstylerend[] = {curWallRegionEnd[0], curWallRegionEnd[1], - curWallRegionEnd[2]}; + const double cStyleRegionEnd[] = { + curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( - cstylerbegin, cstylerend, ParticleIterator::ALL_CELLS); + cStyleRegionBegin, cStyleRegionEnd, ParticleIterator::ALL_CELLS); for (auto it = particlesInRegion; it.isValid(); ++it) { // delete all halo particles moleculeContainer->deleteMolecule(it, false); From fe0dca708227733f34e161504c5d6eb78e2c8c1d Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 17:00:22 +0200 Subject: [PATCH 58/94] removed skin from halo buffer --- src/parallel/boundaries/BoundaryHandler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 9b7d5decb4..1ec2714928 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -216,10 +216,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles( void BoundaryHandler::removeNonPeriodicHalos( ParticleContainer *moleculeContainer) { // get halo lengths in each dimension - double buffers[] = { - moleculeContainer->get_halo_L(0) + moleculeContainer->getSkin(), - moleculeContainer->get_halo_L(1) + moleculeContainer->getSkin(), - moleculeContainer->get_halo_L(2) + moleculeContainer->getSkin()}; + double buffers[] = {moleculeContainer->get_halo_L(0), + moleculeContainer->get_halo_L(1), + moleculeContainer->get_halo_L(2)}; for (auto const ¤tWall : _isGlobalWall) { if (!currentWall.second) // not a global wall continue; From 2b1d448d58fe6ec9b6180f687a1d59e3c6fb6895 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 17:12:04 +0200 Subject: [PATCH 59/94] more documentation --- src/parallel/boundaries/BoundaryUtils.h | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 078e4a120d..9df3d3abe8 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -56,14 +56,44 @@ bool isDimensionStringPermissible(std::string dimension); /* Check if a dimension is allowed. */ bool isDimensionNumericPermissible(int dim); +/* Convert a string from permissibleDimensionsString into DimensionType */ DimensionType convertStringToDimension(std::string dimension); + +/* Convert a dimension from number to DimensionType, where x = +-1, y = +-2 and + * z = +-3 */ DimensionType convertNumericToDimension(int dim); + +/** + * Convert an LS1 internal dimension representation int to DimensionType, where + * x = 0, y = 1 and z = 2 Since this does not contain direction information, the + * positive direction is returned. + */ DimensionType convertLS1DimsToDimensionPos(int dim); +/* Convert a DimensionType into a string from permissibleDimensionsString */ std::string convertDimensionToString(DimensionType dimension); + +/** + * Convert a DimensionType into a string from permissibleDimensionsString, and + * remove directions Ex: POSX and NEGX both return "x" + */ std::string convertDimensionToStringAbs(DimensionType dimension); + +/* Convert a dimension from DimensionType to number, where x = +-1, y = +-2 and + * z = +-3 */ int convertDimensionToNumeric(DimensionType dimension); + +/** + * Convert a DimensionType into an int, and remove directions + * +x/-x returns 1, +y/-y returns 2, +z/-z returns 3 + */ int convertDimensionToNumericAbs(DimensionType dimension); + +/** + * Convert a DimensionType to LS1 internal dimension representation int, where x + * = 0, y = 1 and z = 2 Since this does not contain direction information, both + * POSX and NEGX return 0, for example. + */ int convertDimensionToLS1Dims(DimensionType dimension); /* Used to convert string read from the XML input file. */ From 147d8265f432cae9d7427ad3f371f0452015e5ed Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 18:30:07 +0200 Subject: [PATCH 60/94] added equality check for floats --- src/parallel/boundaries/BoundaryHandler.cpp | 12 ++++++------ src/parallel/boundaries/BoundaryUtils.h | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 1ec2714928..a064a90320 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -89,17 +89,17 @@ void BoundaryHandler::setLocalRegion(std::array start, void BoundaryHandler::findGlobalWallsInLocalRegion() { _isGlobalWall[BoundaryUtils::DimensionType::POSX] = - (_localRegionEnd[0] == _globalRegionEnd[0]); + BoundaryUtils::isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); _isGlobalWall[BoundaryUtils::DimensionType::NEGX] = - (_localRegionStart[0] == _globalRegionStart[0]); + BoundaryUtils::isNearRel(_localRegionStart[0], _globalRegionStart[0]); _isGlobalWall[BoundaryUtils::DimensionType::POSY] = - (_localRegionEnd[1] == _globalRegionEnd[1]); + BoundaryUtils::isNearRel(_localRegionEnd[1], _globalRegionEnd[1]); _isGlobalWall[BoundaryUtils::DimensionType::NEGY] = - (_localRegionStart[1] == _globalRegionStart[1]); + BoundaryUtils::isNearRel(_localRegionStart[1], _globalRegionStart[1]); _isGlobalWall[BoundaryUtils::DimensionType::POSZ] = - (_localRegionEnd[2] == _globalRegionEnd[2]); + BoundaryUtils::isNearRel(_localRegionEnd[2], _globalRegionEnd[2]); _isGlobalWall[BoundaryUtils::DimensionType::NEGZ] = - (_localRegionStart[2] == _globalRegionStart[2]); + BoundaryUtils::isNearRel(_localRegionStart[2], _globalRegionStart[2]); } bool BoundaryHandler::hasInvalidBoundary() const { diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 9df3d3abe8..f4ba38c646 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -160,4 +160,16 @@ inline int findSign(int n) { return n < 0 ? -1 : 1; } inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } + +/** + * Used for equality checks when comparing floats. + * + * Taken from AutoPas - src/autopas/utils/Math.h + */ +bool isNearRel(double a, double b, double maxRelativeDifference = 1e-9) { + const auto greaterNumber = std::max(std::abs(a), std::abs(b)); + const auto absoluteDifference = maxRelativeDifference * greaterNumber; + const auto diff = std::abs(a - b); + return diff <= absoluteDifference; +} } // namespace BoundaryUtils From 407998a8b439bd0c7002737995d4d306e56c8132 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 11 Sep 2024 18:56:07 +0200 Subject: [PATCH 61/94] compile errors fixed --- src/parallel/DomainDecompBase.cpp | 4 ++-- src/parallel/boundaries/BoundaryHandler.cpp | 4 ++-- src/parallel/boundaries/BoundaryHandler.h | 4 ++-- src/parallel/boundaries/BoundaryUtils.cpp | 8 ++++++++ src/parallel/boundaries/BoundaryUtils.h | 8 ++------ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 4207a2c4d7..0b07f18cec 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -27,7 +27,7 @@ void DomainDecompBase::readXML(XMLfileUnits& /* xmlconfig */) { } void DomainDecompBase::setGlobalBoundaryType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary) { - _boundaryHandler.setGlobalWall(dimension, boundary); + _boundaryHandler.setGlobalWallType(dimension, boundary); } void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble) { @@ -316,7 +316,7 @@ void DomainDecompBase::handleDomainLeavingParticlesDirect(const HaloRegion& halo void DomainDecompBase::populateHaloLayerWithCopies(unsigned dim, ParticleContainer* moleculeContainer) const { //reflecting and outflow boundaries do not expect halo particles - if(_boundaryHandler.getGlobalWall(dim) != BoundaryUtils::BoundaryType::PERIODIC) + if(_boundaryHandler.getGlobalWallType(dim) != BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL) return; double shiftMagnitude = moleculeContainer->getBoundingBoxMax(dim) - moleculeContainer->getBoundingBoxMin(dim); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index a064a90320..119486b9fa 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -61,14 +61,14 @@ void BoundaryHandler::setGlobalWallType(std::string dimension, setGlobalWallType(convertedDimension, value); } -void BoundaryHandler::setGlobalRegion(double *start, double *end) { +void BoundaryHandler::setGlobalRegion(const double *start, const double *end) { for (short int i = 0; i < 3; i++) { _globalRegionStart[i] = start[i]; _globalRegionEnd[i] = end[i]; } } -void BoundaryHandler::setLocalRegion(double *start, double *end) { +void BoundaryHandler::setLocalRegion(const double *start, const double *end) { for (short int i = 0; i < 3; i++) { _localRegionStart[i] = start[i]; _localRegionEnd[i] = end[i]; diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index cd29bb3506..915a3dd6c1 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -63,10 +63,10 @@ class BoundaryHandler { bool hasNonPeriodicBoundary() const; /* Set bounds for global subdomain. */ - void setGlobalRegion(double *start, double *end); + void setGlobalRegion(const double *start, const double *end); /* Set bounds for local subdomain. */ - void setLocalRegion(double *start, double *end); + void setLocalRegion(const double *start, const double *end); /* Set bounds for global subdomain. */ void setGlobalRegion(std::array start, std::array end); diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 4e57bb8d89..6a3ed02475 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -294,3 +294,11 @@ BoundaryUtils::getOuterBuffer(const std::array givenRegionBegin, } return std::make_tuple(returnRegionBegin, returnRegionEnd); } + +bool BoundaryUtils::isNearRel(double a, double b, + double maxRelativeDifference) { + const auto greaterNumber = std::max(std::abs(a), std::abs(b)); + const auto absoluteDifference = maxRelativeDifference * greaterNumber; + const auto diff = std::abs(a - b); + return diff <= absoluteDifference; +} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index f4ba38c646..1ba7f5c0b3 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -166,10 +166,6 @@ inline int findSign(DimensionType dimension) { * * Taken from AutoPas - src/autopas/utils/Math.h */ -bool isNearRel(double a, double b, double maxRelativeDifference = 1e-9) { - const auto greaterNumber = std::max(std::abs(a), std::abs(b)); - const auto absoluteDifference = maxRelativeDifference * greaterNumber; - const auto diff = std::abs(a - b); - return diff <= absoluteDifference; -} +bool isNearRel(double a, double b, double maxRelativeDifference = 1e-9); + } // namespace BoundaryUtils From 463799c60e32ba4e7cc62e642cde66d784540c09 Mon Sep 17 00:00:00 2001 From: Amartya Das Sharma Date: Thu, 12 Sep 2024 13:07:24 +0200 Subject: [PATCH 62/94] Apply suggestions from code review low hanging fruit 1, rest to follow Co-authored-by: FG-TUM --- examples/all-options.xml | 9 +++++++-- src/parallel/DomainDecompBase.cpp | 4 ++-- src/parallel/KDDecomposition.cpp | 4 ++-- src/parallel/boundaries/BoundaryHandler.cpp | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/all-options.xml b/examples/all-options.xml index 675af3291c..aabf2f7b4a 100644 --- a/examples/all-options.xml +++ b/examples/all-options.xml @@ -185,7 +185,7 @@ 0.0 0.0 0.0 - true + true @@ -197,7 +197,12 @@ False 5 False - reflectiveoutflowreflective + + + reflective + outflow + periodic + 5 False - + reflective outflow diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index c02cec0390..fb7276a8c3 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -219,7 +219,7 @@ void BoundaryHandler::removeNonPeriodicHalos( case BoundaryUtils::BoundaryType::REFLECTING: { // create region by using getOuterBuffer() std::array curWallRegionBegin, curWallRegionEnd; - std::tie(curWallRegionBegin, curWallRegionEnd) = + auto const [curWallRegionBegin, curWallRegionEnd] = BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, currentDim, buffers); // convert the regions into c-style arrays, so that they can be passed to diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index bb3e53fad6..508282341e 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -35,13 +35,6 @@ class BoundaryHandler { public: BoundaryHandler(); - /* Find the boundary type of a global wall for a particular dimension. */ - BoundaryUtils::BoundaryType getGlobalWallType(std::string dimension) const; - - /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWallType(std::string dimension, - BoundaryUtils::BoundaryType value); - /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType getGlobalWallType(BoundaryUtils::DimensionType dimension) const; From e849d34b277e896c2a85f8794326c25cd4d12b1f Mon Sep 17 00:00:00 2001 From: Amartya Das Sharma Date: Mon, 16 Sep 2024 14:57:38 +0200 Subject: [PATCH 75/94] Apply suggestions from code review Co-authored-by: FG-TUM --- src/parallel/boundaries/BoundaryHandler.cpp | 11 +---- src/parallel/boundaries/BoundaryUtils.cpp | 45 +++++++++------------ 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index fb7276a8c3..0322817238 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -146,16 +146,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles( const auto [curWallRegionBegin, curWallRegionEnd] = BoundaryUtils::getInnerBuffer(_localRegionStart, _localRegionEnd, currentDim, cutoff); - // convert the regions into c-style arrays, so that they can be passed to - // the region iterator - const double cStyleRegionBegin[] = { - curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; - const double cStyleRegionEnd[] = { - curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; - // grab an iterator from the converted coords - auto particlesInRegion = moleculeContainer->regionIterator( - cStyleRegionBegin, cStyleRegionEnd, + const auto particlesInRegion = moleculeContainer->regionIterator( + curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ONLY_INNER_AND_BOUNDARY); // iterate through all molecules diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 8f3b362d1d..2ed642b3e4 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -101,35 +101,28 @@ BoundaryUtils::convertDimensionToStringAbs(DimensionType dimension) { int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) { switch (dimension) { - case DimensionType::POSX: - return 1; - - case DimensionType::POSY: - return 2; - - case DimensionType::POSZ: - return 3; - - case DimensionType::NEGX: - return -1; - - case DimensionType::NEGY: - return -2; - - case DimensionType::NEGZ: - return -3; - - default: - Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return 0; + case DimensionType::POSX: + return 1; + case DimensionType::POSY: + return 2; + case DimensionType::POSZ: + return 3; + case DimensionType::NEGX: + return -1; + case DimensionType::NEGY: + return -2; + case DimensionType::NEGZ: + return -3; + default: + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return 0; } } int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) { - int toReturn = convertDimensionToNumeric(dimension); - return std::abs(toReturn); + return std::abs(convertDimensionToNumeric(dimension)); } int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { @@ -137,7 +130,7 @@ int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { } BoundaryUtils::BoundaryType -BoundaryUtils::convertStringToBoundary(std::string boundary) { +BoundaryUtils::convertStringToBoundary(const std::string &boundary) { if (boundary == "periodic") return BoundaryType::PERIODIC_OR_LOCAL; if (boundary == "reflecting" || boundary == "reflective") From fc81653c729fce10228dc4e1c54c40a0dbb3d66a Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 17 Sep 2024 11:16:06 +0200 Subject: [PATCH 76/94] moved boundary init, lambda, remove std::array setRegions --- src/parallel/DomainDecompBase.cpp | 5 +- src/parallel/boundaries/BoundaryHandler.cpp | 69 +++------------------ src/parallel/boundaries/BoundaryHandler.h | 18 +++--- src/parallel/boundaries/BoundaryUtils.h | 2 +- 4 files changed, 21 insertions(+), 73 deletions(-) diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index f63e2e67c9..54d144a887 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -32,9 +32,8 @@ void DomainDecompBase::setGlobalBoundaryType(BoundaryUtils::DimensionType dimens void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble) { //find which walls to consider - std::array startRegion{}, endRegion{}; - getBoundingBoxMinMax(domain, startRegion.data(), endRegion.data()); - + double startRegion[3], endRegion[3]; + getBoundingBoxMinMax(domain, startRegion, endRegion); const double* globStartRegion = ensemble->domain()->rmin(); const double* globEndRegion = ensemble->domain()->rmax(); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 0322817238..7207acaff2 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -14,22 +14,6 @@ #include "utils/Logger.h" -BoundaryHandler::BoundaryHandler() - : _boundaries{{BoundaryUtils::DimensionType::POSX, - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::POSY, - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::POSZ, - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::NEGX, - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::NEGY, - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::NEGZ, - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::ERROR, - BoundaryUtils::BoundaryType::ERROR}} {} - BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType( BoundaryUtils::DimensionType dimension) const { return _boundaries.at(dimension); @@ -61,18 +45,6 @@ void BoundaryHandler::setLocalRegion(const double *start, const double *end) { } } -void BoundaryHandler::setGlobalRegion(std::array start, - std::array end) { - _globalRegionStart = start; - _globalRegionEnd = end; -} - -void BoundaryHandler::setLocalRegion(std::array start, - std::array end) { - _localRegionStart = start; - _localRegionEnd = end; -} - void BoundaryHandler::updateGlobalWallLookupTable() { _isGlobalWall[BoundaryUtils::DimensionType::POSX] = BoundaryUtils::isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); @@ -89,33 +61,17 @@ void BoundaryHandler::updateGlobalWallLookupTable() { } bool BoundaryHandler::hasInvalidBoundary() const { - return _boundaries.at(BoundaryUtils::DimensionType::POSX) == - BoundaryUtils::BoundaryType::ERROR || - _boundaries.at(BoundaryUtils::DimensionType::POSY) == - BoundaryUtils::BoundaryType::ERROR || - _boundaries.at(BoundaryUtils::DimensionType::POSZ) == - BoundaryUtils::BoundaryType::ERROR || - _boundaries.at(BoundaryUtils::DimensionType::NEGX) == - BoundaryUtils::BoundaryType::ERROR || - _boundaries.at(BoundaryUtils::DimensionType::NEGY) == - BoundaryUtils::BoundaryType::ERROR || - _boundaries.at(BoundaryUtils::DimensionType::NEGZ) == - BoundaryUtils::BoundaryType::ERROR; + return std::any_of(_boundaries.begin(), _boundaries.end(),[](const auto &keyVal) { + const auto [dim, boundaryType] = keyVal; + return boundaryType == BoundaryUtils::BoundaryType::ERROR; + }); } bool BoundaryHandler::hasNonPeriodicBoundary() const { - return _boundaries.at(BoundaryUtils::DimensionType::POSX) != - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || - _boundaries.at(BoundaryUtils::DimensionType::POSY) != - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || - _boundaries.at(BoundaryUtils::DimensionType::POSZ) != - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || - _boundaries.at(BoundaryUtils::DimensionType::NEGX) != - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || - _boundaries.at(BoundaryUtils::DimensionType::NEGY) != - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL || - _boundaries.at(BoundaryUtils::DimensionType::NEGZ) != - BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL; + return std::any_of(_boundaries.begin(), _boundaries.end(),[](const auto &keyVal) { + const auto [dim, boundaryType] = keyVal; + return boundaryType == BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL; + }); } bool BoundaryHandler::isGlobalWall( @@ -211,20 +167,13 @@ void BoundaryHandler::removeNonPeriodicHalos( [[fallthrough]]; case BoundaryUtils::BoundaryType::REFLECTING: { // create region by using getOuterBuffer() - std::array curWallRegionBegin, curWallRegionEnd; auto const [curWallRegionBegin, curWallRegionEnd] = BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, currentDim, buffers); - // convert the regions into c-style arrays, so that they can be passed to - // the region iterator - const double cStyleRegionBegin[] = { - curWallRegionBegin[0], curWallRegionBegin[1], curWallRegionBegin[2]}; - const double cStyleRegionEnd[] = { - curWallRegionEnd[0], curWallRegionEnd[1], curWallRegionEnd[2]}; // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( - cStyleRegionBegin, cStyleRegionEnd, ParticleIterator::ALL_CELLS); + curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ALL_CELLS); for (auto it = particlesInRegion; it.isValid(); ++it) { // delete all halo particles moleculeContainer->deleteMolecule(it, false); diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 508282341e..6d921177a1 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -33,7 +33,7 @@ class BoundaryHandler { public: - BoundaryHandler(); + BoundaryHandler() = default; /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType @@ -42,6 +42,8 @@ class BoundaryHandler { /* Set the boundary type of a global wall for a particular dimension. */ void setGlobalWallType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); + + BoundaryUtils::BoundaryType getGlobalWallType(int dimension) const; /* Check if any of the global boundaries have invalid types. */ @@ -60,13 +62,6 @@ class BoundaryHandler { /* Set bounds for local subdomain. */ void setLocalRegion(const double *start, const double *end); - - /* Set bounds for global subdomain. */ - void setGlobalRegion(std::array start, std::array end); - - /* Set bounds for local subdomain.*/ - void setLocalRegion(std::array start, std::array end); - /** * Determine which walls in the local region are actually global walls. * @@ -117,7 +112,12 @@ class BoundaryHandler { private: /* List of global boundary type per dimension. */ std::map - _boundaries; + _boundaries {{BoundaryUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {BoundaryUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {BoundaryUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {BoundaryUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {BoundaryUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {BoundaryUtils::DimensionType::NEGZ,BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}}; /* Lookup table to check if a local wall is also global. */ std::map _isGlobalWall; diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 888935da49..81f3a52c68 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -90,7 +90,7 @@ int convertDimensionToNumericAbs(DimensionType dimension); int convertDimensionToLS1Dims(DimensionType dimension); /* Used to convert string read from the XML input file. */ -BoundaryType convertStringToBoundary(std::string boundary); +BoundaryType convertStringToBoundary(const std::string &boundary); std::string convertBoundaryToString(BoundaryType boundary); From 45930837822cae794eab6052a58374fb9b0dea51 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 17 Sep 2024 14:12:10 +0200 Subject: [PATCH 77/94] consts, removed molecule deref --- src/parallel/boundaries/BoundaryHandler.cpp | 30 ++++++++++++--------- src/parallel/boundaries/BoundaryHandler.h | 4 +-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 7207acaff2..12bae97da2 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -29,6 +29,11 @@ void BoundaryHandler::setGlobalWallType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType value) { if (dimension != BoundaryUtils::DimensionType::ERROR) _boundaries[dimension] = value; + else { + Log::global_log->error() + << "DimensionType::ERROR received in setGlobalWallType!!" << std::endl; + mardyn_exit(1); + } } void BoundaryHandler::setGlobalRegion(const double *start, const double *end) { @@ -84,7 +89,7 @@ bool BoundaryHandler::isGlobalWall(int dimension) const { } void BoundaryHandler::processGlobalWallLeavingParticles( - ParticleContainer *moleculeContainer, double timestepLength) { + ParticleContainer *moleculeContainer, double timestepLength) const { const auto cutoff = moleculeContainer->getCutoff(); for (auto const [currentDim, currentWallIsGlobalWall] : _isGlobalWall) { if (!currentWallIsGlobalWall) @@ -92,7 +97,8 @@ void BoundaryHandler::processGlobalWallLeavingParticles( switch (getGlobalWallType(currentDim)) { case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: - // default behaviour + // nothing changes from normal ls1 behaviour, so leaving particles not touched by BoundaryHandler and are processed by + // DomainDecompBase::handleDomainLeavingParticles() break; case BoundaryUtils::BoundaryType::OUTFLOW: @@ -108,33 +114,31 @@ void BoundaryHandler::processGlobalWallLeavingParticles( ParticleIterator::ONLY_INNER_AND_BOUNDARY); // iterate through all molecules - for (auto it = particlesInRegion; it.isValid(); ++it) { - Molecule curMolecule = *it; - + for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { // Calculate the change in velocity, which the leapfrog method will // apply in the next velocity update to the dimension of interest. const int currentDimInt = BoundaryUtils::convertDimensionToLS1Dims(currentDim); const double halfTimestep = .5 * timestepLength; - const double halfTimestepByMass = halfTimestep / it->mass(); - const double force = it->F(currentDimInt); + const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); + const double force = moleculeIter->F(currentDimInt); const double nextStepVelAdjustment = halfTimestepByMass * force; // check if the molecule would leave the bounds if (BoundaryUtils::isMoleculeLeaving( - curMolecule, curWallRegionBegin, curWallRegionEnd, currentDim, + *moleculeIter, curWallRegionBegin, curWallRegionEnd, currentDim, timestepLength, nextStepVelAdjustment)) { if (getGlobalWallType(currentDim) == BoundaryUtils::BoundaryType::REFLECTING) { - double currentVel = it->v(currentDimInt); + double currentVel = moleculeIter->v(currentDimInt); // change the velocity in the dimension of interest such that when // the leapfrog integrator adds nextStepVelAdjustment in the next // velocity update, the final result ends up being the intended, // reversed velocity: -(currentVel+nextStepVelAdjustment) - it->setv(currentDimInt, -currentVel - nextStepVelAdjustment - + moleculeIter->setv(currentDimInt, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); } else { // outflow, delete the particle if it would leave - moleculeContainer->deleteMolecule(it, false); + moleculeContainer->deleteMolecule(moleculeIter, false); } } } @@ -149,7 +153,7 @@ void BoundaryHandler::processGlobalWallLeavingParticles( } void BoundaryHandler::removeNonPeriodicHalos( - ParticleContainer *moleculeContainer) { + ParticleContainer *moleculeContainer) const { // get halo lengths in each dimension double buffers[] = {moleculeContainer->get_halo_L(0), moleculeContainer->get_halo_L(1), @@ -160,7 +164,7 @@ void BoundaryHandler::removeNonPeriodicHalos( switch (getGlobalWallType(currentDim)) { case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: - // default behaviour + // nothing changes from normal ls1 behaviour, so empty case, and halo particles left untouched break; case BoundaryUtils::BoundaryType::OUTFLOW: diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 6d921177a1..b4fd1e00db 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -92,7 +92,7 @@ class BoundaryHandler { * OUTFLOW - The particle is deleted. */ void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, - double timestepLength); + double timestepLength) const; /** * Processes all halo particles outside the global domain. @@ -107,7 +107,7 @@ class BoundaryHandler { * approaching the boundary do not decelerate due to influence from the halo * particles, and preserve their velocities before being bounced/deleted */ - void removeNonPeriodicHalos(ParticleContainer *moleculeContainer); + void removeNonPeriodicHalos(ParticleContainer *moleculeContainer) const; private: /* List of global boundary type per dimension. */ From 541a9f2933a033c88bb46b6ed69cfdf3fa19b321 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 17 Sep 2024 14:36:59 +0200 Subject: [PATCH 78/94] moved math to math.h, fixed array conversions --- src/parallel/GeneralDomainDecomposition.cpp | 2 +- src/parallel/KDDecomposition.cpp | 4 ++-- src/parallel/boundaries/BoundaryHandler.cpp | 19 ++++++++++--------- src/parallel/boundaries/BoundaryUtils.cpp | 8 -------- src/parallel/boundaries/BoundaryUtils.h | 7 ------- src/utils/Math.h | 20 +++++++++++++++++++- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/parallel/GeneralDomainDecomposition.cpp b/src/parallel/GeneralDomainDecomposition.cpp index d5af9f1cdd..2cbbf24573 100644 --- a/src/parallel/GeneralDomainDecomposition.cpp +++ b/src/parallel/GeneralDomainDecomposition.cpp @@ -132,7 +132,7 @@ void GeneralDomainDecomposition::balanceAndExchange(double lastTraversalTime, bo DomainDecompMPIBase::exchangeMoleculesMPI(moleculeContainer, domain, HALO_COPIES); } } - _boundaryHandler.setLocalRegion(_boxMin,_boxMax); + _boundaryHandler.setLocalRegion(_boxMin.data(),_boxMax.data()); _boundaryHandler.updateGlobalWallLookupTable(); } ++_steps; diff --git a/src/parallel/KDDecomposition.cpp b/src/parallel/KDDecomposition.cpp index 9c70c12d48..03fe4577a6 100644 --- a/src/parallel/KDDecomposition.cpp +++ b/src/parallel/KDDecomposition.cpp @@ -328,8 +328,8 @@ void KDDecomposition::balanceAndExchange(double lastTraversalTime, bool forceReb DomainDecompMPIBase::exchangeMoleculesMPI(moleculeContainer, domain, HALO_COPIES, true /*doHaloPositionCheck*/, removeRecvDuplicates); - std::array startRegion{}, endRegion{}; - getBoundingBoxMinMax(domain, startRegion.data(), endRegion.data()); + double startRegion[3], endRegion[3]; + getBoundingBoxMinMax(domain, startRegion, endRegion); _boundaryHandler.setLocalRegion(startRegion,endRegion); _boundaryHandler.updateGlobalWallLookupTable(); } diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 12bae97da2..d99a90a250 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -11,6 +11,7 @@ #include "Simulation.h" #include "integrators/Integrator.h" +#include "utils/Math.h" #include "utils/Logger.h" @@ -52,17 +53,17 @@ void BoundaryHandler::setLocalRegion(const double *start, const double *end) { void BoundaryHandler::updateGlobalWallLookupTable() { _isGlobalWall[BoundaryUtils::DimensionType::POSX] = - BoundaryUtils::isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); + isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); _isGlobalWall[BoundaryUtils::DimensionType::NEGX] = - BoundaryUtils::isNearRel(_localRegionStart[0], _globalRegionStart[0]); + isNearRel(_localRegionStart[0], _globalRegionStart[0]); _isGlobalWall[BoundaryUtils::DimensionType::POSY] = - BoundaryUtils::isNearRel(_localRegionEnd[1], _globalRegionEnd[1]); + isNearRel(_localRegionEnd[1], _globalRegionEnd[1]); _isGlobalWall[BoundaryUtils::DimensionType::NEGY] = - BoundaryUtils::isNearRel(_localRegionStart[1], _globalRegionStart[1]); + isNearRel(_localRegionStart[1], _globalRegionStart[1]); _isGlobalWall[BoundaryUtils::DimensionType::POSZ] = - BoundaryUtils::isNearRel(_localRegionEnd[2], _globalRegionEnd[2]); + isNearRel(_localRegionEnd[2], _globalRegionEnd[2]); _isGlobalWall[BoundaryUtils::DimensionType::NEGZ] = - BoundaryUtils::isNearRel(_localRegionStart[2], _globalRegionStart[2]); + isNearRel(_localRegionStart[2], _globalRegionStart[2]); } bool BoundaryHandler::hasInvalidBoundary() const { @@ -130,7 +131,7 @@ void BoundaryHandler::processGlobalWallLeavingParticles( timestepLength, nextStepVelAdjustment)) { if (getGlobalWallType(currentDim) == BoundaryUtils::BoundaryType::REFLECTING) { - double currentVel = moleculeIter->v(currentDimInt); + const double currentVel = moleculeIter->v(currentDimInt); // change the velocity in the dimension of interest such that when // the leapfrog integrator adds nextStepVelAdjustment in the next // velocity update, the final result ends up being the intended, @@ -178,9 +179,9 @@ void BoundaryHandler::removeNonPeriodicHalos( // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ALL_CELLS); - for (auto it = particlesInRegion; it.isValid(); ++it) { + for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { // delete all halo particles - moleculeContainer->deleteMolecule(it, false); + moleculeContainer->deleteMolecule(moleculeIter, false); } break; } diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 2ed642b3e4..8b202fc178 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -278,11 +278,3 @@ BoundaryUtils::getOuterBuffer(const std::array &givenRegionBegin, } return std::make_tuple(returnRegionBegin, returnRegionEnd); } - -bool BoundaryUtils::isNearRel(double a, double b, - double maxRelativeDifference) { - const auto greaterNumber = std::max(std::abs(a), std::abs(b)); - const auto absoluteDifference = maxRelativeDifference * greaterNumber; - const auto diff = std::abs(a - b); - return diff <= absoluteDifference; -} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 81f3a52c68..3c0ee1c501 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -156,11 +156,4 @@ inline int findSign(DimensionType dimension) { return findSign(convertDimensionToNumeric(dimension)); } -/** - * Used for equality checks when comparing floats. - * - * Taken from AutoPas - src/autopas/utils/Math.h - */ -bool isNearRel(double a, double b, double maxRelativeDifference = 1e-9); - } // namespace BoundaryUtils diff --git a/src/utils/Math.h b/src/utils/Math.h index b1a9a1c23d..4539f76ea1 100644 --- a/src/utils/Math.h +++ b/src/utils/Math.h @@ -50,5 +50,23 @@ inline void LinearRegression(const std::vector& x, const std::vector& y, beta2 = beta1 = 0.; } - +/** + * @brief Used for equality checks when comparing floats. + * + * Taken from AutoPas - src/autopas/utils/Math.h + * + * @param a + * @param b + * @param maxRelativeDifference optional, default value 1e-9 + * @return true + * @return false + */ +bool inline isNearRel(double a, double b, + double maxRelativeDifference = 1e-9) +{ + const auto greaterNumber = std::max(std::abs(a), std::abs(b)); + const auto absoluteDifference = maxRelativeDifference * greaterNumber; + const auto diff = std::abs(a - b); + return diff <= absoluteDifference; +} #endif /* MATH_H_ */ From dfd5c5793de22e949b881019564d74c18bdabc5e Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 17 Sep 2024 15:36:52 +0200 Subject: [PATCH 79/94] rename get_halo_L, buffers now c++ arrays --- src/parallel/boundaries/BoundaryHandler.cpp | 7 ++++--- src/parallel/boundaries/BoundaryUtils.cpp | 15 ++++++++++----- src/parallel/boundaries/BoundaryUtils.h | 6 ++---- src/particleContainer/AutoPasContainer.cpp | 2 +- src/particleContainer/AutoPasContainer.h | 2 +- src/particleContainer/LinkedCells.cpp | 2 +- src/particleContainer/LinkedCells.h | 2 +- src/particleContainer/ParticleContainer.h | 2 +- src/steereoCommands/sendCouplingMDCommand.cpp | 2 +- src/utils/Math.h | 3 +-- src/utils/generator/ReplicaFiller.cpp | 2 +- 11 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index d99a90a250..94f7bbc8cf 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -156,9 +156,10 @@ void BoundaryHandler::processGlobalWallLeavingParticles( void BoundaryHandler::removeNonPeriodicHalos( ParticleContainer *moleculeContainer) const { // get halo lengths in each dimension - double buffers[] = {moleculeContainer->get_halo_L(0), - moleculeContainer->get_halo_L(1), - moleculeContainer->get_halo_L(2)}; + const std::array buffers = { + moleculeContainer->getHaloWidthForDimension(0), + moleculeContainer->getHaloWidthForDimension(1), + moleculeContainer->getHaloWidthForDimension(2)}; for (auto const [currentDim, currentWallIsGlobalWall] : _isGlobalWall) { if (!currentWallIsGlobalWall) continue; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 8b202fc178..c9cf2a50b7 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "BoundaryUtils.h" @@ -21,7 +22,7 @@ bool BoundaryUtils::isDimensionNumericPermissible(int dim) { BoundaryUtils::DimensionType BoundaryUtils::convertNumericToDimension(int dim) { if (!isDimensionNumericPermissible(dim)) { Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; + << "Invalid dimension passed for enum conversion. Received value: " << dim << std::endl; mardyn_exit(1); return DimensionType::ERROR; } @@ -131,11 +132,14 @@ int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) { - if (boundary == "periodic") + std::string boundaryLowercase; + std::transform(boundary.begin(), boundary.end(), boundaryLowercase.begin(), + [](unsigned char c){ return std::tolower(c); }); + if (boundaryLowercase.find("per") != std::string::npos) return BoundaryType::PERIODIC_OR_LOCAL; - if (boundary == "reflecting" || boundary == "reflective") + if (boundaryLowercase.find("ref") != std::string::npos) return BoundaryType::REFLECTING; - if (boundary == "outflow") + if (boundaryLowercase.find("out") != std::string::npos) return BoundaryType::OUTFLOW; Log::global_log->error() << "Invalid boundary type passed to " @@ -225,7 +229,8 @@ bool BoundaryUtils::isMoleculeLeaving(const Molecule &molecule, std::tuple, std::array> BoundaryUtils::getOuterBuffer(const std::array &givenRegionBegin, const std::array &givenRegionEnd, - DimensionType dimension, double *regionWidth) { + DimensionType dimension, + const std::array ®ionWidth) { std::array returnRegionBegin = givenRegionBegin; std::array returnRegionEnd = givenRegionEnd; diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 3c0ee1c501..413ce91364 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -46,9 +46,6 @@ enum class BoundaryType { PERIODIC_OR_LOCAL, OUTFLOW, REFLECTING, ERROR }; */ enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; -/* Check if a dimension is allowed. */ -bool isDimensionStringPermissible(std::string dimension); - /* Check if a dimension is allowed. */ bool isDimensionNumericPermissible(int dim); @@ -144,7 +141,8 @@ bool isMoleculeLeaving(const Molecule &molecule, std::tuple, std::array> getOuterBuffer(const std::array &givenRegionBegin, const std::array &givenRegionEnd, - DimensionType dimension, double *regionWidth); + DimensionType dimension, + const std::array ®ionWidth); /* Returns the sign of a number, used for determining direction from a * dimension. */ diff --git a/src/particleContainer/AutoPasContainer.cpp b/src/particleContainer/AutoPasContainer.cpp index 0a9fa5a8c3..b324cba507 100644 --- a/src/particleContainer/AutoPasContainer.cpp +++ b/src/particleContainer/AutoPasContainer.cpp @@ -628,7 +628,7 @@ void AutoPasContainer::deleteOuterParticles() { } } -double AutoPasContainer::get_halo_L(int /*index*/) const { return _cutoff; } +double AutoPasContainer::getHaloWidthForDimension(int /*index*/) const { return _cutoff; } double AutoPasContainer::getCutoff() const { return _cutoff; } diff --git a/src/particleContainer/AutoPasContainer.h b/src/particleContainer/AutoPasContainer.h index 5167ba5818..ebdddf686c 100644 --- a/src/particleContainer/AutoPasContainer.h +++ b/src/particleContainer/AutoPasContainer.h @@ -89,7 +89,7 @@ class AutoPasContainer : public ParticleContainer { void deleteOuterParticles() override; - double get_halo_L(int index) const override; + double getHaloWidthForDimension(int index) const override; double getCutoff() const override; diff --git a/src/particleContainer/LinkedCells.cpp b/src/particleContainer/LinkedCells.cpp index d214872be7..67576d1bfe 100644 --- a/src/particleContainer/LinkedCells.cpp +++ b/src/particleContainer/LinkedCells.cpp @@ -626,7 +626,7 @@ void LinkedCells::deleteOuterParticles() { } } -double LinkedCells::get_halo_L(int index) const { +double LinkedCells::getHaloWidthForDimension(int index) const { return _haloLength[index]; } diff --git a/src/particleContainer/LinkedCells.h b/src/particleContainer/LinkedCells.h index a444fea3ae..add747275e 100644 --- a/src/particleContainer/LinkedCells.h +++ b/src/particleContainer/LinkedCells.h @@ -190,7 +190,7 @@ class LinkedCells : public ParticleContainer { //! @brief gets the width of the halo region in dimension index //! @todo remove this method, because a halo_L shouldn't be necessary for every ParticleContainer //! e.g. replace it by the cutoff-radius - double get_halo_L(int index) const override; + double getHaloWidthForDimension(int index) const override; double getCutoff() const override { return _cutoffRadius; } void setCutoff(double rc) override { _cutoffRadius = rc; } diff --git a/src/particleContainer/ParticleContainer.h b/src/particleContainer/ParticleContainer.h index eea8af21cc..012b68f2b3 100644 --- a/src/particleContainer/ParticleContainer.h +++ b/src/particleContainer/ParticleContainer.h @@ -192,7 +192,7 @@ class ParticleContainer: public MemoryProfilable { //! @brief returns the width of the halo stripe (for the given dimension index) //! @todo remove this method, because a halo_L shouldn't be necessary for every ParticleContainer //! e.g. replace it by the cutoff-radius - virtual double get_halo_L(int index) const = 0; + virtual double getHaloWidthForDimension(int index) const = 0; virtual double getCutoff() const = 0; diff --git a/src/steereoCommands/sendCouplingMDCommand.cpp b/src/steereoCommands/sendCouplingMDCommand.cpp index 1ee3ca5753..60966e40c7 100644 --- a/src/steereoCommands/sendCouplingMDCommand.cpp +++ b/src/steereoCommands/sendCouplingMDCommand.cpp @@ -97,7 +97,7 @@ ReturnType SendCouplingMDCommand::executeProcessing() double rmax = moleculeContainer->getBoundingBoxMax(dim); logger->debug() << "dim is " << dim << ", dir is " << dir << std::endl; - logger->debug() << "halo is " << moleculeContainer->get_halo_L(dim) << std::endl; + logger->debug() << "halo is " << moleculeContainer->getHaloWidthForDimension(dim) << std::endl; Molecule* currentMolecule; double low_limit = rmin; // particles below this limit have to be copied or moved to the lower process diff --git a/src/utils/Math.h b/src/utils/Math.h index 4539f76ea1..36c76f689e 100644 --- a/src/utils/Math.h +++ b/src/utils/Math.h @@ -61,8 +61,7 @@ inline void LinearRegression(const std::vector& x, const std::vector& y, * @return true * @return false */ -bool inline isNearRel(double a, double b, - double maxRelativeDifference = 1e-9) +bool inline isNearRel(double a, double b, double maxRelativeDifference = 1e-9) { const auto greaterNumber = std::max(std::abs(a), std::abs(b)); const auto absoluteDifference = maxRelativeDifference * greaterNumber; diff --git a/src/utils/generator/ReplicaFiller.cpp b/src/utils/generator/ReplicaFiller.cpp index f4767918cc..58dd7584fc 100644 --- a/src/utils/generator/ReplicaFiller.cpp +++ b/src/utils/generator/ReplicaFiller.cpp @@ -95,7 +95,7 @@ class ParticleContainerToBasisWrapper : public ParticleContainer { void deleteOuterParticles() override {} - double get_halo_L(int index) const override { return 0.0; } + double getHaloWidthForDimension(int index) const override { return 0.0; } double getCutoff() const override { return 0.0; } From 9cad8d9e9085f76b51bf056fbcb5fa154eef5183 Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 17 Sep 2024 15:39:49 +0200 Subject: [PATCH 80/94] renames ls1dim to ls1dimindex --- src/parallel/boundaries/BoundaryHandler.cpp | 6 +++--- src/parallel/boundaries/BoundaryUtils.cpp | 10 +++++----- src/parallel/boundaries/BoundaryUtils.h | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 94f7bbc8cf..c311088480 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -23,7 +23,7 @@ BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType( BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(int dimension) const { return getGlobalWallType( - BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); + BoundaryUtils::convertLS1DimIndexToEnumPos(dimension)); } void BoundaryHandler::setGlobalWallType(BoundaryUtils::DimensionType dimension, @@ -86,7 +86,7 @@ bool BoundaryHandler::isGlobalWall( } bool BoundaryHandler::isGlobalWall(int dimension) const { - return isGlobalWall(BoundaryUtils::convertLS1DimsToDimensionPos(dimension)); + return isGlobalWall(BoundaryUtils::convertLS1DimIndexToEnumPos(dimension)); } void BoundaryHandler::processGlobalWallLeavingParticles( @@ -119,7 +119,7 @@ void BoundaryHandler::processGlobalWallLeavingParticles( // Calculate the change in velocity, which the leapfrog method will // apply in the next velocity update to the dimension of interest. const int currentDimInt = - BoundaryUtils::convertDimensionToLS1Dims(currentDim); + BoundaryUtils::convertEnumToLS1DimIndex(currentDim); const double halfTimestep = .5 * timestepLength; const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); const double force = moleculeIter->F(currentDimInt); diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index c9cf2a50b7..d8461b1e6a 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -54,7 +54,7 @@ BoundaryUtils::DimensionType BoundaryUtils::convertNumericToDimension(int dim) { } BoundaryUtils::DimensionType -BoundaryUtils::convertLS1DimsToDimensionPos(int dim) { +BoundaryUtils::convertLS1DimIndexToEnumPos(int dim) { switch (dim) { case 0: return DimensionType::POSX; @@ -126,7 +126,7 @@ int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) { return std::abs(convertDimensionToNumeric(dimension)); } -int BoundaryUtils::convertDimensionToLS1Dims(DimensionType dimension) { +int BoundaryUtils::convertEnumToLS1DimIndex(DimensionType dimension) { return convertDimensionToNumericAbs(dimension) - 1; } @@ -175,7 +175,7 @@ BoundaryUtils::getInnerBuffer(const std::array &givenRegionBegin, std::array returnRegionBegin = givenRegionBegin; std::array returnRegionEnd = givenRegionBegin; - const int dimensionLS1 = convertDimensionToLS1Dims(dimension); + const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); switch (dimension) { // in positive case, set the beginning to end-width, or whole domain if width // too large @@ -214,7 +214,7 @@ bool BoundaryUtils::isMoleculeLeaving(const Molecule &molecule, DimensionType dimension, double timestepLength, double nextStepVelAdjustment) { - const int ls1dim = convertDimensionToLS1Dims(dimension); + const int ls1dim = convertEnumToLS1DimIndex(dimension); const int direction = findSign(dimension); const double newPos = molecule.r(ls1dim) + @@ -239,7 +239,7 @@ BoundaryUtils::getOuterBuffer(const std::array &givenRegionBegin, returnRegionEnd[i] = givenRegionEnd[i]; } - const int dimensionLS1 = convertDimensionToLS1Dims(dimension); + const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); // find the two dimensions that are not being considered const int extraDim1 = dimensionLS1 == 0 ? 1 : 0; diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 413ce91364..9ea85131c2 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -58,7 +58,7 @@ DimensionType convertNumericToDimension(int dim); * x = 0, y = 1 and z = 2 Since this does not contain direction information, the * positive direction is returned. */ -DimensionType convertLS1DimsToDimensionPos(int dim); +DimensionType convertLS1DimIndexToEnumPos(int dim); /* Convert a DimensionType into a string from permissibleDimensionsString */ std::string convertDimensionToString(DimensionType dimension); @@ -84,7 +84,7 @@ int convertDimensionToNumericAbs(DimensionType dimension); * = 0, y = 1 and z = 2 Since this does not contain direction information, both * POSX and NEGX return 0, for example. */ -int convertDimensionToLS1Dims(DimensionType dimension); +int convertEnumToLS1DimIndex(DimensionType dimension); /* Used to convert string read from the XML input file. */ BoundaryType convertStringToBoundary(const std::string &boundary); From a8ee7a1ca84aabd1a391e975b3fa721f27f37f05 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 18 Sep 2024 20:34:03 +0200 Subject: [PATCH 81/94] renamed "buffer", moved more math --- src/parallel/boundaries/BoundaryHandler.cpp | 12 ++++---- src/parallel/boundaries/BoundaryUtils.cpp | 32 +++++++-------------- src/parallel/boundaries/BoundaryUtils.h | 8 +++--- src/utils/Math.h | 11 ++++++- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index c311088480..afc5ce75c4 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -105,9 +105,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles( case BoundaryUtils::BoundaryType::OUTFLOW: [[fallthrough]]; case BoundaryUtils::BoundaryType::REFLECTING: { - // create region by using getInnerBuffer() + // create region by using getInnerRegionSlab() const auto [curWallRegionBegin, curWallRegionEnd] = - BoundaryUtils::getInnerBuffer(_localRegionStart, _localRegionEnd, + BoundaryUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, currentDim, cutoff); // grab an iterator from the converted coords const auto particlesInRegion = moleculeContainer->regionIterator( @@ -156,7 +156,7 @@ void BoundaryHandler::processGlobalWallLeavingParticles( void BoundaryHandler::removeNonPeriodicHalos( ParticleContainer *moleculeContainer) const { // get halo lengths in each dimension - const std::array buffers = { + const std::array haloWidths = { moleculeContainer->getHaloWidthForDimension(0), moleculeContainer->getHaloWidthForDimension(1), moleculeContainer->getHaloWidthForDimension(2)}; @@ -172,10 +172,10 @@ void BoundaryHandler::removeNonPeriodicHalos( case BoundaryUtils::BoundaryType::OUTFLOW: [[fallthrough]]; case BoundaryUtils::BoundaryType::REFLECTING: { - // create region by using getOuterBuffer() + // create region by using getOuterRegionSlab() auto const [curWallRegionBegin, curWallRegionEnd] = - BoundaryUtils::getOuterBuffer(_localRegionStart, _localRegionEnd, - currentDim, buffers); + BoundaryUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, + currentDim, haloWidths); // grab an iterator from the converted coords auto particlesInRegion = moleculeContainer->regionIterator( diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index d8461b1e6a..56320ec2db 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -26,31 +26,21 @@ BoundaryUtils::DimensionType BoundaryUtils::convertNumericToDimension(int dim) { mardyn_exit(1); return DimensionType::ERROR; } - switch (findSign(dim)) { - case -1: - switch (dim) { - case 1: - return DimensionType::NEGX; - case 2: - return DimensionType::NEGY; - default: - return DimensionType::NEGZ; // case 3 - } - case 1: - switch (dim) { + switch (dim) { case 1: return DimensionType::POSX; case 2: return DimensionType::POSY; - default: + case 3: return DimensionType::POSZ; // case 3 - } - default: // should never happen - Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); + case -1: + return DimensionType::NEGX; + case -2: + return DimensionType::NEGY; + case -3: + return DimensionType::NEGZ; } - return DimensionType::ERROR; + return DimensionType::ERROR; //warning suppression } BoundaryUtils::DimensionType @@ -168,7 +158,7 @@ std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { } std::tuple, std::array> -BoundaryUtils::getInnerBuffer(const std::array &givenRegionBegin, +BoundaryUtils::getInnerRegionSlab(const std::array &givenRegionBegin, const std::array &givenRegionEnd, DimensionType dimension, double regionWidth) { @@ -227,7 +217,7 @@ bool BoundaryUtils::isMoleculeLeaving(const Molecule &molecule, } std::tuple, std::array> -BoundaryUtils::getOuterBuffer(const std::array &givenRegionBegin, +BoundaryUtils::getOuterRegionSlab(const std::array &givenRegionBegin, const std::array &givenRegionEnd, DimensionType dimension, const std::array ®ionWidth) { diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 9ea85131c2..2f86c8f90f 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -12,6 +12,7 @@ #include #include +#include "utils/Math.h" #include "molecules/Molecule.h" /** @@ -103,7 +104,7 @@ std::string convertBoundaryToString(BoundaryType boundary); * demarcated by givenRegion{begin,end}. */ std::tuple, std::array> -getInnerBuffer(const std::array &givenRegionBegin, +getInnerRegionSlab(const std::array &givenRegionBegin, const std::array &givenRegionEnd, DimensionType dimension, double regionWidth); @@ -139,19 +140,18 @@ bool isMoleculeLeaving(const Molecule &molecule, * from +x. */ std::tuple, std::array> -getOuterBuffer(const std::array &givenRegionBegin, +getOuterRegionSlab(const std::array &givenRegionBegin, const std::array &givenRegionEnd, DimensionType dimension, const std::array ®ionWidth); /* Returns the sign of a number, used for determining direction from a * dimension. */ -inline int findSign(int n) { return n < 0 ? -1 : 1; } /* Returns the sign of a number, used for determining direction from a * dimension. */ inline int findSign(DimensionType dimension) { - return findSign(convertDimensionToNumeric(dimension)); + return ::findSign(convertDimensionToNumeric(dimension)); } } // namespace BoundaryUtils diff --git a/src/utils/Math.h b/src/utils/Math.h index 36c76f689e..e28b38ede4 100644 --- a/src/utils/Math.h +++ b/src/utils/Math.h @@ -51,7 +51,8 @@ inline void LinearRegression(const std::vector& x, const std::vector& y, } /** - * @brief Used for equality checks when comparing floats. + * @brief Check whether two floats are within some maximum relative difference. + * Used to check for equality while taking floating-point errors into account. * * Taken from AutoPas - src/autopas/utils/Math.h * @@ -68,4 +69,12 @@ bool inline isNearRel(double a, double b, double maxRelativeDifference = 1e-9) const auto diff = std::abs(a - b); return diff <= absoluteDifference; } + +/** + * @brief Find whether an int is positive or negative (zero is positive). + * + * @param n the number to be checked + * @return int -1 if the number is negative, and 1 otherwise + */ +inline short int findSign(int n) { return n < 0 ? -1 : 1; } #endif /* MATH_H_ */ From 1ab950bcc2d238b3c0acae154eb3ddca58fec575 Mon Sep 17 00:00:00 2001 From: amartyads Date: Wed, 18 Sep 2024 19:44:00 +0200 Subject: [PATCH 82/94] split utils file (separation of concerns) --- src/Simulation.cpp | 12 +- src/parallel/DomainDecompBase.cpp | 2 +- src/parallel/DomainDecompBase.h | 2 +- src/parallel/boundaries/BoundaryHandler.cpp | 36 ++-- src/parallel/boundaries/BoundaryHandler.h | 24 ++- src/parallel/boundaries/BoundaryUtils.cpp | 225 +------------------- src/parallel/boundaries/BoundaryUtils.h | 118 ---------- src/parallel/boundaries/DimensionUtils.cpp | 115 ++++++++++ src/parallel/boundaries/DimensionUtils.h | 70 ++++++ src/parallel/boundaries/RegionUtils.cpp | 126 +++++++++++ src/parallel/boundaries/RegionUtils.h | 69 ++++++ 11 files changed, 420 insertions(+), 379 deletions(-) create mode 100644 src/parallel/boundaries/DimensionUtils.cpp create mode 100644 src/parallel/boundaries/DimensionUtils.h create mode 100644 src/parallel/boundaries/RegionUtils.cpp create mode 100644 src/parallel/boundaries/RegionUtils.h diff --git a/src/Simulation.cpp b/src/Simulation.cpp index e5b245a5c5..c5e69276ce 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -417,12 +417,12 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { BoundaryUtils::BoundaryType xBoundary = BoundaryUtils::convertStringToBoundary(xBoundaryFromFile); BoundaryUtils::BoundaryType yBoundary = BoundaryUtils::convertStringToBoundary(yBoundaryFromFile); BoundaryUtils::BoundaryType zBoundary = BoundaryUtils::convertStringToBoundary(zBoundaryFromFile); - _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::POSX, xBoundary); - _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::NEGX, xBoundary); - _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::POSY, yBoundary); - _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::NEGY, yBoundary); - _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::POSZ, zBoundary); - _domainDecomposition->setGlobalBoundaryType(BoundaryUtils::DimensionType::NEGZ, zBoundary); + _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::POSX, xBoundary); + _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::NEGX, xBoundary); + _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::POSY, yBoundary); + _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::NEGY, yBoundary); + _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::POSZ, zBoundary); + _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::NEGZ, zBoundary); if (_domainDecomposition->hasInvalidBoundary()) { Log::global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; exit(1); diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 54d144a887..190e58c1a0 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -26,7 +26,7 @@ DomainDecompBase::~DomainDecompBase() { void DomainDecompBase::readXML(XMLfileUnits& /* xmlconfig */) { } -void DomainDecompBase::setGlobalBoundaryType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary) { +void DomainDecompBase::setGlobalBoundaryType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary) { _boundaryHandler.setGlobalWallType(dimension, boundary); } diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index bb227879f5..2f0f6cbf86 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -291,7 +291,7 @@ class DomainDecompBase: public MemoryProfilable { virtual void printCommunicationPartners(std::string filename) const {}; /* Set the global boundary type for the _boundaryHandler object. */ - void setGlobalBoundaryType(BoundaryUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary); + void setGlobalBoundaryType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType boundary); /* Find which boundaries of a subdomain are actually global boundaries, and update _boundaryHandler. */ void setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index afc5ce75c4..41422e3c6d 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -9,26 +9,26 @@ #include "BoundaryHandler.h" -#include "Simulation.h" #include "integrators/Integrator.h" -#include "utils/Math.h" +#include "utils/Math.h" +#include "utils/mardyn_assert.h" #include "utils/Logger.h" BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType( - BoundaryUtils::DimensionType dimension) const { + DimensionUtils::DimensionType dimension) const { return _boundaries.at(dimension); } BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(int dimension) const { return getGlobalWallType( - BoundaryUtils::convertLS1DimIndexToEnumPos(dimension)); + DimensionUtils::convertLS1DimIndexToEnumPositive(dimension)); } -void BoundaryHandler::setGlobalWallType(BoundaryUtils::DimensionType dimension, +void BoundaryHandler::setGlobalWallType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType value) { - if (dimension != BoundaryUtils::DimensionType::ERROR) + if (dimension != DimensionUtils::DimensionType::ERROR) _boundaries[dimension] = value; else { Log::global_log->error() @@ -52,17 +52,17 @@ void BoundaryHandler::setLocalRegion(const double *start, const double *end) { } void BoundaryHandler::updateGlobalWallLookupTable() { - _isGlobalWall[BoundaryUtils::DimensionType::POSX] = + _isGlobalWall[DimensionUtils::DimensionType::POSX] = isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); - _isGlobalWall[BoundaryUtils::DimensionType::NEGX] = + _isGlobalWall[DimensionUtils::DimensionType::NEGX] = isNearRel(_localRegionStart[0], _globalRegionStart[0]); - _isGlobalWall[BoundaryUtils::DimensionType::POSY] = + _isGlobalWall[DimensionUtils::DimensionType::POSY] = isNearRel(_localRegionEnd[1], _globalRegionEnd[1]); - _isGlobalWall[BoundaryUtils::DimensionType::NEGY] = + _isGlobalWall[DimensionUtils::DimensionType::NEGY] = isNearRel(_localRegionStart[1], _globalRegionStart[1]); - _isGlobalWall[BoundaryUtils::DimensionType::POSZ] = + _isGlobalWall[DimensionUtils::DimensionType::POSZ] = isNearRel(_localRegionEnd[2], _globalRegionEnd[2]); - _isGlobalWall[BoundaryUtils::DimensionType::NEGZ] = + _isGlobalWall[DimensionUtils::DimensionType::NEGZ] = isNearRel(_localRegionStart[2], _globalRegionStart[2]); } @@ -81,12 +81,12 @@ bool BoundaryHandler::hasNonPeriodicBoundary() const { } bool BoundaryHandler::isGlobalWall( - BoundaryUtils::DimensionType dimension) const { + DimensionUtils::DimensionType dimension) const { return _isGlobalWall.at(dimension); } bool BoundaryHandler::isGlobalWall(int dimension) const { - return isGlobalWall(BoundaryUtils::convertLS1DimIndexToEnumPos(dimension)); + return isGlobalWall(DimensionUtils::convertLS1DimIndexToEnumPositive(dimension)); } void BoundaryHandler::processGlobalWallLeavingParticles( @@ -107,7 +107,7 @@ void BoundaryHandler::processGlobalWallLeavingParticles( case BoundaryUtils::BoundaryType::REFLECTING: { // create region by using getInnerRegionSlab() const auto [curWallRegionBegin, curWallRegionEnd] = - BoundaryUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, + RegionUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, currentDim, cutoff); // grab an iterator from the converted coords const auto particlesInRegion = moleculeContainer->regionIterator( @@ -119,14 +119,14 @@ void BoundaryHandler::processGlobalWallLeavingParticles( // Calculate the change in velocity, which the leapfrog method will // apply in the next velocity update to the dimension of interest. const int currentDimInt = - BoundaryUtils::convertEnumToLS1DimIndex(currentDim); + DimensionUtils::convertEnumToLS1DimIndex(currentDim); const double halfTimestep = .5 * timestepLength; const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); const double force = moleculeIter->F(currentDimInt); const double nextStepVelAdjustment = halfTimestepByMass * force; // check if the molecule would leave the bounds - if (BoundaryUtils::isMoleculeLeaving( + if (RegionUtils::isMoleculeLeaving( *moleculeIter, curWallRegionBegin, curWallRegionEnd, currentDim, timestepLength, nextStepVelAdjustment)) { if (getGlobalWallType(currentDim) == @@ -174,7 +174,7 @@ void BoundaryHandler::removeNonPeriodicHalos( case BoundaryUtils::BoundaryType::REFLECTING: { // create region by using getOuterRegionSlab() auto const [curWallRegionBegin, curWallRegionEnd] = - BoundaryUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, + RegionUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, currentDim, haloWidths); // grab an iterator from the converted coords diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index b4fd1e00db..1e7c2cd761 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -7,7 +7,9 @@ #pragma once +#include "RegionUtils.h" #include "BoundaryUtils.h" +#include "DimensionUtils.h" #include "particleContainer/ParticleContainer.h" #include @@ -37,10 +39,10 @@ class BoundaryHandler { /* Find the boundary type of a global wall for a particular dimension. */ BoundaryUtils::BoundaryType - getGlobalWallType(BoundaryUtils::DimensionType dimension) const; + getGlobalWallType(DimensionUtils::DimensionType dimension) const; /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWallType(BoundaryUtils::DimensionType dimension, + void setGlobalWallType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); @@ -72,7 +74,7 @@ class BoundaryHandler { /* Check if the local wall in a particular dimension is actually a global * wall. */ - bool isGlobalWall(BoundaryUtils::DimensionType dimension) const; + bool isGlobalWall(DimensionUtils::DimensionType dimension) const; /* Check if the local wall in a particular dimension is actually a global * wall. */ @@ -111,16 +113,16 @@ class BoundaryHandler { private: /* List of global boundary type per dimension. */ - std::map - _boundaries {{BoundaryUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {BoundaryUtils::DimensionType::NEGZ,BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}}; + std::map + _boundaries {{DimensionUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::NEGZ,BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}}; /* Lookup table to check if a local wall is also global. */ - std::map _isGlobalWall; + std::map _isGlobalWall; /* Global region start/end. */ std::array _globalRegionStart, _globalRegionEnd; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 56320ec2db..1b4c0e5327 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -11,115 +11,9 @@ #include "BoundaryUtils.h" -#include "Simulation.h" +#include "utils/mardyn_assert.h" #include "utils/Logger.h" -bool BoundaryUtils::isDimensionNumericPermissible(int dim) { - // permissible dimensions are {-1, -2, -3, 1, 2, 3} - return (dim >= -3 && dim <= 3 && dim != 0); -} - -BoundaryUtils::DimensionType BoundaryUtils::convertNumericToDimension(int dim) { - if (!isDimensionNumericPermissible(dim)) { - Log::global_log->error() - << "Invalid dimension passed for enum conversion. Received value: " << dim << std::endl; - mardyn_exit(1); - return DimensionType::ERROR; - } - switch (dim) { - case 1: - return DimensionType::POSX; - case 2: - return DimensionType::POSY; - case 3: - return DimensionType::POSZ; // case 3 - case -1: - return DimensionType::NEGX; - case -2: - return DimensionType::NEGY; - case -3: - return DimensionType::NEGZ; - } - return DimensionType::ERROR; //warning suppression -} - -BoundaryUtils::DimensionType -BoundaryUtils::convertLS1DimIndexToEnumPos(int dim) { - switch (dim) { - case 0: - return DimensionType::POSX; - case 1: - return DimensionType::POSY; - case 2: - return DimensionType::POSZ; - default: - return DimensionType::ERROR; - } -} - -std::string BoundaryUtils::convertDimensionToString(DimensionType dimension) { - switch (dimension) { - case DimensionType::POSX: - return "+x"; - - case DimensionType::POSY: - return "+y"; - - case DimensionType::POSZ: - return "+z"; - - case DimensionType::NEGX: - return "-x"; - - case DimensionType::NEGY: - return "-y"; - - case DimensionType::NEGZ: - return "-z"; - - default: - Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return "error"; - } -} - -std::string -BoundaryUtils::convertDimensionToStringAbs(DimensionType dimension) { - return convertDimensionToString(dimension).substr(1, 1); -} - -int BoundaryUtils::convertDimensionToNumeric(DimensionType dimension) { - switch (dimension) { - case DimensionType::POSX: - return 1; - case DimensionType::POSY: - return 2; - case DimensionType::POSZ: - return 3; - case DimensionType::NEGX: - return -1; - case DimensionType::NEGY: - return -2; - case DimensionType::NEGZ: - return -3; - default: - Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return 0; - } -} - -int BoundaryUtils::convertDimensionToNumericAbs(DimensionType dimension) { - return std::abs(convertDimensionToNumeric(dimension)); -} - -int BoundaryUtils::convertEnumToLS1DimIndex(DimensionType dimension) { - return convertDimensionToNumericAbs(dimension) - 1; -} - BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) { std::string boundaryLowercase; @@ -156,120 +50,3 @@ std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { } return "error"; // warning suppression } - -std::tuple, std::array> -BoundaryUtils::getInnerRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionType dimension, double regionWidth) { - - std::array returnRegionBegin = givenRegionBegin; - std::array returnRegionEnd = givenRegionBegin; - - const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); - switch (dimension) { - // in positive case, set the beginning to end-width, or whole domain if width - // too large - case DimensionType::POSX: - [[fallthrough]]; - case DimensionType::POSY: - [[fallthrough]]; - case DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = - std::max(returnRegionEnd[dimensionLS1] - regionWidth, - givenRegionBegin[dimensionLS1]); - break; - // in negative case, set the end to beginning+width, or whole domain if width - // too large - case DimensionType::NEGX: - [[fallthrough]]; - case DimensionType::NEGY: - [[fallthrough]]; - case DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = - std::min(returnRegionBegin[dimensionLS1] + regionWidth, - givenRegionEnd[dimensionLS1]); - break; - - default: - Log::global_log->error() - << "Invalid dimension passed for inner buffer calculation\n"; - mardyn_exit(1); - } - return {returnRegionBegin, returnRegionEnd}; -} - -bool BoundaryUtils::isMoleculeLeaving(const Molecule &molecule, - const std::array ®ionBegin, - const std::array ®ionEnd, - DimensionType dimension, - double timestepLength, - double nextStepVelAdjustment) { - const int ls1dim = convertEnumToLS1DimIndex(dimension); - const int direction = findSign(dimension); - const double newPos = - molecule.r(ls1dim) + - (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); - if (newPos <= regionBegin[ls1dim] && direction < 0) - return true; - if (newPos >= regionEnd[ls1dim] && direction > 0) - return true; - return false; -} - -std::tuple, std::array> -BoundaryUtils::getOuterRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionType dimension, - const std::array ®ionWidth) { - std::array returnRegionBegin = givenRegionBegin; - std::array returnRegionEnd = givenRegionEnd; - - for (int i = 0; i < 3; i++) { - returnRegionBegin[i] = givenRegionBegin[i]; - returnRegionEnd[i] = givenRegionEnd[i]; - } - - const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); - - // find the two dimensions that are not being considered - const int extraDim1 = dimensionLS1 == 0 ? 1 : 0; - const int extraDim2 = dimensionLS1 == 2 ? 1 : 2; - - // extend the extra dimensions to cover all ghost areas - returnRegionBegin[extraDim1] -= regionWidth[extraDim1]; - returnRegionEnd[extraDim1] += regionWidth[extraDim1]; - - returnRegionBegin[extraDim2] -= regionWidth[extraDim2]; - returnRegionEnd[extraDim2] += regionWidth[extraDim2]; - - switch (dimension) // can be done with findsign() too, but this is clearer - { - // in positive case, move the box begin to edge of domain, and box end to - // beyond - case DimensionType::POSX: - [[fallthrough]]; - case DimensionType::POSY: - [[fallthrough]]; - case DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; - returnRegionEnd[dimensionLS1] += regionWidth[dimensionLS1]; - break; - - // in negative case, move the box end to edge of domain, and box begin to - // beyond - case DimensionType::NEGX: - [[fallthrough]]; - case DimensionType::NEGY: - [[fallthrough]]; - case DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; - returnRegionBegin[dimensionLS1] -= regionWidth[dimensionLS1]; - break; - - default: - Log::global_log->error() - << "Invalid dimension passed for inner buffer calculation" << std::endl; - mardyn_exit(1); - } - return std::make_tuple(returnRegionBegin, returnRegionEnd); -} diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index 2f86c8f90f..da0d9b4524 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -7,14 +7,7 @@ #pragma once -#include #include -#include -#include - -#include "utils/Math.h" -#include "molecules/Molecule.h" - /** * Includes enums and helper functions for processing boundary conditions. * @@ -38,120 +31,9 @@ namespace BoundaryUtils { */ enum class BoundaryType { PERIODIC_OR_LOCAL, OUTFLOW, REFLECTING, ERROR }; -/** - * enum storing the axes and direction. - * - * The dimensions are POSX, NEGX, POSY, NEGY, POSZ and NEGZ. - * - * This is hardcoded for 3D, and ERROR is included for sanity checks. - */ -enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; - -/* Check if a dimension is allowed. */ -bool isDimensionNumericPermissible(int dim); - -/* Convert a dimension from number to DimensionType, where x = +-1, y = +-2 and - * z = +-3 */ -DimensionType convertNumericToDimension(int dim); - -/** - * Convert an LS1 internal dimension representation int to DimensionType, where - * x = 0, y = 1 and z = 2 Since this does not contain direction information, the - * positive direction is returned. - */ -DimensionType convertLS1DimIndexToEnumPos(int dim); - -/* Convert a DimensionType into a string from permissibleDimensionsString */ -std::string convertDimensionToString(DimensionType dimension); - -/** - * Convert a DimensionType into a string from permissibleDimensionsString, and - * remove directions Ex: POSX and NEGX both return "x" - */ -std::string convertDimensionToStringAbs(DimensionType dimension); - -/* Convert a dimension from DimensionType to number, where x = +-1, y = +-2 and - * z = +-3 */ -int convertDimensionToNumeric(DimensionType dimension); - -/** - * Convert a DimensionType into an int, and remove directions - * +x/-x returns 1, +y/-y returns 2, +z/-z returns 3 - */ -int convertDimensionToNumericAbs(DimensionType dimension); - -/** - * Convert a DimensionType to LS1 internal dimension representation int, where x - * = 0, y = 1 and z = 2 Since this does not contain direction information, both - * POSX and NEGX return 0, for example. - */ -int convertEnumToLS1DimIndex(DimensionType dimension); - /* Used to convert string read from the XML input file. */ BoundaryType convertStringToBoundary(const std::string &boundary); std::string convertBoundaryToString(BoundaryType boundary); -/** - * When given a domain delimited by givenRegionBegin and givenRegionEnd - * and a DimensionType, and a requested regionWidth, this function - * returns a cropped box from the domain. This box is of size regionWidth - * in the dimension specified, and the size of the domain otherwise. - * - * E.g. if the dimension given is +x, and the regionWidth is 3, this function - * returns a box, which would contain every particle that is within 3 - * units from the +x boundary wall, in the original domain - * demarcated by givenRegion{begin,end}. - */ -std::tuple, std::array> -getInnerRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionType dimension, double regionWidth); - -/** - * Checks if a given molecule is leaving the given region in the next timestep, - * with added scalar velocity adjustment, but only in the given dimension. - * - * The molecule's position and velocity in the specified dimension is extracted - * from the molecule itself, and the next position is calculated using the - * velocity adjustment and the timestep length. - * - * When this function is called, it is usually expected that the forces have - * been updated for the current timestep and the positions and velocities - * aren't. Hence the nextStepVelAdjustment is provided to the caller function, - * so that it can handle the change in velocity due to forces. This is not done - * by the util function itself, to keep it as generic as possible. - */ -bool isMoleculeLeaving(const Molecule &molecule, - const std::array ®ionBegin, - const std::array ®ionEnd, - DimensionType dimension, double timestepLength, - double nextStepVelAdjustment); - -/** - * When given a domain delimited by givenRegionBegin and givenRegionEnd - * and a DimensionType, and a requested regionWidth, this function - * returns a box outside the domain. This box is of size regionWidth - * in the dimension specified, and the size of the domain plus regionwidth - * otherwise. - * - * E.g. if the dimension given is +x, and the regionWidth is 3, this function - * returns a box, which contains every ghost particle that is 3 units away - * from +x. - */ -std::tuple, std::array> -getOuterRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionType dimension, - const std::array ®ionWidth); - -/* Returns the sign of a number, used for determining direction from a - * dimension. */ - -/* Returns the sign of a number, used for determining direction from a - * dimension. */ -inline int findSign(DimensionType dimension) { - return ::findSign(convertDimensionToNumeric(dimension)); -} - } // namespace BoundaryUtils diff --git a/src/parallel/boundaries/DimensionUtils.cpp b/src/parallel/boundaries/DimensionUtils.cpp new file mode 100644 index 0000000000..de777cf601 --- /dev/null +++ b/src/parallel/boundaries/DimensionUtils.cpp @@ -0,0 +1,115 @@ +/* + * DimensionUtils.cpp + * + * Created on: 18 Sep 2024 + * Author: amartyads + */ + +#include "DimensionUtils.h" +#include "utils/Logger.h" +#include "utils/mardyn_assert.h" // for mardyn_exit() + +bool DimensionUtils::isDimensionNumericPermissible(int dim) { + // permissible dimensions are {-1, -2, -3, 1, 2, 3} + return (dim >= -3 && dim <= 3 && dim != 0); +} + +DimensionUtils::DimensionType DimensionUtils::convertNumericToDimension(int dim) { + if (!isDimensionNumericPermissible(dim)) { + Log::global_log->error() + << "Invalid dimension passed for enum conversion. Received value: " << dim << std::endl; + mardyn_exit(1); + return DimensionType::ERROR; + } + switch (dim) { + case 1: + return DimensionType::POSX; + case 2: + return DimensionType::POSY; + case 3: + return DimensionType::POSZ; + case -1: + return DimensionType::NEGX; + case -2: + return DimensionType::NEGY; + case -3: + return DimensionType::NEGZ; + } + return DimensionType::ERROR; //warning suppression +} + +DimensionUtils::DimensionType DimensionUtils::convertLS1DimIndexToEnumPositive(int dim) { + switch (dim) { + case 0: + return DimensionType::POSX; + case 1: + return DimensionType::POSY; + case 2: + return DimensionType::POSZ; + default: + return DimensionType::ERROR; + } +} + +std::string DimensionUtils::convertDimensionToString(DimensionType dimension) { + switch (dimension) { + case DimensionType::POSX: + return "+x"; + + case DimensionType::POSY: + return "+y"; + + case DimensionType::POSZ: + return "+z"; + + case DimensionType::NEGX: + return "-x"; + + case DimensionType::NEGY: + return "-y"; + + case DimensionType::NEGZ: + return "-z"; + + default: + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return "error"; + } +} + +std::string +DimensionUtils::convertDimensionToStringAbs(DimensionType dimension) { + return convertDimensionToString(dimension).substr(1, 1); +} + +int DimensionUtils::convertDimensionToNumeric(DimensionType dimension) { + switch (dimension) { + case DimensionType::POSX: + return 1; + case DimensionType::POSY: + return 2; + case DimensionType::POSZ: + return 3; + case DimensionType::NEGX: + return -1; + case DimensionType::NEGY: + return -2; + case DimensionType::NEGZ: + return -3; + default: + Log::global_log->error() + << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return 0; + } +} + +int DimensionUtils::convertDimensionToNumericAbs(DimensionType dimension) { + return std::abs(convertDimensionToNumeric(dimension)); +} + +int DimensionUtils::convertEnumToLS1DimIndex(DimensionType dimension) { + return convertDimensionToNumericAbs(dimension) - 1; +} \ No newline at end of file diff --git a/src/parallel/boundaries/DimensionUtils.h b/src/parallel/boundaries/DimensionUtils.h new file mode 100644 index 0000000000..88641eede2 --- /dev/null +++ b/src/parallel/boundaries/DimensionUtils.h @@ -0,0 +1,70 @@ +/* + * DimensionUtils.h + * + * Created on: 18 Sep 2024 + * Author: amartyads + */ + +#pragma once + +#include +#include "utils/Math.h" + +namespace DimensionUtils { +/** + * enum storing the axes and direction. + * + * The dimensions are POSX, NEGX, POSY, NEGY, POSZ and NEGZ. + * + * This is hardcoded for 3D, and ERROR is included for sanity checks. + */ +enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; + +/* Check if a dimension is allowed. */ +bool isDimensionNumericPermissible(int dim); + +/* Convert a dimension from number to DimensionType, where x = +-1, y = +-2 and + * z = +-3 */ +DimensionType convertNumericToDimension(int dim); + +/** + * Convert an LS1 internal dimension representation int to DimensionType, where + * x = 0, y = 1 and z = 2 Since this does not contain direction information, the + * positive direction is returned. + */ +DimensionType convertLS1DimIndexToEnumPositive(int dim); + +/* Convert a DimensionType into a string from permissibleDimensionsString */ +std::string convertDimensionToString(DimensionType dimension); + +/** + * Convert a DimensionType into a string from permissibleDimensionsString, and + * remove directions Ex: POSX and NEGX both return "x" + */ +std::string convertDimensionToStringAbs(DimensionType dimension); + +/* Convert a dimension from DimensionType to number, where x = +-1, y = +-2 and + * z = +-3 */ +int convertDimensionToNumeric(DimensionType dimension); + +/** + * Convert a DimensionType into an int, and remove directions + * +x/-x returns 1, +y/-y returns 2, +z/-z returns 3 + */ +int convertDimensionToNumericAbs(DimensionType dimension); + +/** + * Convert a DimensionType to LS1 internal dimension representation int, where x + * = 0, y = 1 and z = 2 Since this does not contain direction information, both + * POSX and NEGX return 0, for example. + */ +int convertEnumToLS1DimIndex(DimensionType dimension); + + +/* Returns the sign of a number, used for determining direction from a + * dimension. */ +inline int findSign(DimensionType dimension) { + return ::findSign(convertDimensionToNumeric(dimension)); +} + +} // namespace DimensionUtils \ No newline at end of file diff --git a/src/parallel/boundaries/RegionUtils.cpp b/src/parallel/boundaries/RegionUtils.cpp new file mode 100644 index 0000000000..365a4a7058 --- /dev/null +++ b/src/parallel/boundaries/RegionUtils.cpp @@ -0,0 +1,126 @@ +/* + * RegionUtils.cpp + * + * Created on: 18 Sep 2024 + * Author: amartyads + */ + +#include "RegionUtils.h" +#include "utils/mardyn_assert.h" //for mardyn_exit() + +std::tuple, std::array> +RegionUtils::getInnerRegionSlab(const std::array &givenRegionBegin, + const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, double regionWidth) { + + std::array returnRegionBegin = givenRegionBegin; + std::array returnRegionEnd = givenRegionBegin; + + const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); + switch (dimension) { + // in positive case, set the beginning to end-width, or whole domain if width + // too large + case DimensionUtils::DimensionType::POSX: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSY: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = + std::max(returnRegionEnd[dimensionLS1] - regionWidth, + givenRegionBegin[dimensionLS1]); + break; + // in negative case, set the end to beginning+width, or whole domain if width + // too large + case DimensionUtils::DimensionType::NEGX: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGY: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = + std::min(returnRegionBegin[dimensionLS1] + regionWidth, + givenRegionEnd[dimensionLS1]); + break; + + default: + Log::global_log->error() + << "Invalid dimension passed for inner buffer calculation\n"; + mardyn_exit(1); + } + return {returnRegionBegin, returnRegionEnd}; +} + +bool RegionUtils::isMoleculeLeaving(const Molecule &molecule, + const std::array ®ionBegin, + const std::array ®ionEnd, + DimensionUtils::DimensionType dimension, + double timestepLength, + double nextStepVelAdjustment) { + const int ls1dim = convertEnumToLS1DimIndex(dimension); + const int direction = findSign(dimension); + const double newPos = + molecule.r(ls1dim) + + (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); + if (newPos <= regionBegin[ls1dim] && direction < 0) + return true; + if (newPos >= regionEnd[ls1dim] && direction > 0) + return true; + return false; +} + +std::tuple, std::array> +RegionUtils::getOuterRegionSlab(const std::array &givenRegionBegin, + const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, + const std::array ®ionWidth) { + std::array returnRegionBegin = givenRegionBegin; + std::array returnRegionEnd = givenRegionEnd; + + for (int i = 0; i < 3; i++) { + returnRegionBegin[i] = givenRegionBegin[i]; + returnRegionEnd[i] = givenRegionEnd[i]; + } + + const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); + + // find the two dimensions that are not being considered + const int extraDim1 = dimensionLS1 == 0 ? 1 : 0; + const int extraDim2 = dimensionLS1 == 2 ? 1 : 2; + + // extend the extra dimensions to cover all ghost areas + returnRegionBegin[extraDim1] -= regionWidth[extraDim1]; + returnRegionEnd[extraDim1] += regionWidth[extraDim1]; + + returnRegionBegin[extraDim2] -= regionWidth[extraDim2]; + returnRegionEnd[extraDim2] += regionWidth[extraDim2]; + + switch (dimension) // can be done with findsign() too, but this is clearer + { + // in positive case, move the box begin to edge of domain, and box end to + // beyond + case DimensionUtils::DimensionType::POSX: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSY: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; + returnRegionEnd[dimensionLS1] += regionWidth[dimensionLS1]; + break; + + // in negative case, move the box end to edge of domain, and box begin to + // beyond + case DimensionUtils::DimensionType::NEGX: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGY: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; + returnRegionBegin[dimensionLS1] -= regionWidth[dimensionLS1]; + break; + + default: + Log::global_log->error() + << "Invalid dimension passed for inner buffer calculation" << std::endl; + mardyn_exit(1); + } + return std::make_tuple(returnRegionBegin, returnRegionEnd); +} diff --git a/src/parallel/boundaries/RegionUtils.h b/src/parallel/boundaries/RegionUtils.h new file mode 100644 index 0000000000..54508b71d8 --- /dev/null +++ b/src/parallel/boundaries/RegionUtils.h @@ -0,0 +1,69 @@ +/* + * RegionUtils.h + * + * Created on: 18 Sep 2024 + * Author: amartyads + */ + +#pragma once + +#include +#include "DimensionUtils.h" +#include "molecules/Molecule.h" + +namespace RegionUtils { + +/** + * When given a domain delimited by givenRegionBegin and givenRegionEnd + * and a DimensionType, and a requested regionWidth, this function + * returns a cropped box from the domain. This box is of size regionWidth + * in the dimension specified, and the size of the domain otherwise. + * + * E.g. if the dimension given is +x, and the regionWidth is 3, this function + * returns a box, which would contain every particle that is within 3 + * units from the +x boundary wall, in the original domain + * demarcated by givenRegion{begin,end}. + */ +std::tuple, std::array> +getInnerRegionSlab(const std::array &givenRegionBegin, + const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, double regionWidth); + +/** + * Checks if a given molecule is leaving the given region in the next timestep, + * with added scalar velocity adjustment, but only in the given dimension. + * + * The molecule's position and velocity in the specified dimension is extracted + * from the molecule itself, and the next position is calculated using the + * velocity adjustment and the timestep length. + * + * When this function is called, it is usually expected that the forces have + * been updated for the current timestep and the positions and velocities + * aren't. Hence the nextStepVelAdjustment is provided to the caller function, + * so that it can handle the change in velocity due to forces. This is not done + * by the util function itself, to keep it as generic as possible. + */ +bool isMoleculeLeaving(const Molecule &molecule, + const std::array ®ionBegin, + const std::array ®ionEnd, + DimensionUtils::DimensionType dimension, double timestepLength, + double nextStepVelAdjustment); + +/** + * When given a domain delimited by givenRegionBegin and givenRegionEnd + * and a DimensionType, and a requested regionWidth, this function + * returns a box outside the domain. This box is of size regionWidth + * in the dimension specified, and the size of the domain plus regionwidth + * otherwise. + * + * E.g. if the dimension given is +x, and the regionWidth is 3, this function + * returns a box, which contains every ghost particle that is 3 units away + * from +x. + */ +std::tuple, std::array> +getOuterRegionSlab(const std::array &givenRegionBegin, + const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, + const std::array ®ionWidth); + +} // namespace RegionUtils \ No newline at end of file From 10de6cb1cd0e6a648bb5ff342e9a8b654a768cf1 Mon Sep 17 00:00:00 2001 From: amartyads Date: Thu, 19 Sep 2024 10:04:48 +0200 Subject: [PATCH 83/94] new clangformat --- src/parallel/boundaries/BoundaryHandler.cpp | 279 +++++++++----------- src/parallel/boundaries/BoundaryHandler.h | 188 +++++++------ src/parallel/boundaries/BoundaryUtils.cpp | 65 +++-- src/parallel/boundaries/DimensionUtils.cpp | 149 +++++------ src/parallel/boundaries/DimensionUtils.h | 7 +- src/parallel/boundaries/RegionUtils.cpp | 187 ++++++------- src/parallel/boundaries/RegionUtils.h | 25 +- 7 files changed, 423 insertions(+), 477 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 41422e3c6d..f0f503c9a4 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -11,188 +11,165 @@ #include "integrators/Integrator.h" +#include "utils/Logger.h" #include "utils/Math.h" #include "utils/mardyn_assert.h" -#include "utils/Logger.h" -BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType( - DimensionUtils::DimensionType dimension) const { - return _boundaries.at(dimension); +BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(DimensionUtils::DimensionType dimension) const { + return _boundaries.at(dimension); } -BoundaryUtils::BoundaryType -BoundaryHandler::getGlobalWallType(int dimension) const { - return getGlobalWallType( - DimensionUtils::convertLS1DimIndexToEnumPositive(dimension)); +BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(int dimension) const { + return getGlobalWallType(DimensionUtils::convertLS1DimIndexToEnumPositive(dimension)); } -void BoundaryHandler::setGlobalWallType(DimensionUtils::DimensionType dimension, - BoundaryUtils::BoundaryType value) { - if (dimension != DimensionUtils::DimensionType::ERROR) - _boundaries[dimension] = value; - else { - Log::global_log->error() - << "DimensionType::ERROR received in setGlobalWallType!!" << std::endl; - mardyn_exit(1); - } +void BoundaryHandler::setGlobalWallType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType value) { + if (dimension != DimensionUtils::DimensionType::ERROR) + _boundaries[dimension] = value; + else { + Log::global_log->error() << "DimensionType::ERROR received in setGlobalWallType!!" << std::endl; + mardyn_exit(1); + } } void BoundaryHandler::setGlobalRegion(const double *start, const double *end) { - for (short int i = 0; i < 3; i++) { - _globalRegionStart[i] = start[i]; - _globalRegionEnd[i] = end[i]; - } + for (short int i = 0; i < 3; i++) { + _globalRegionStart[i] = start[i]; + _globalRegionEnd[i] = end[i]; + } } void BoundaryHandler::setLocalRegion(const double *start, const double *end) { - for (short int i = 0; i < 3; i++) { - _localRegionStart[i] = start[i]; - _localRegionEnd[i] = end[i]; - } + for (short int i = 0; i < 3; i++) { + _localRegionStart[i] = start[i]; + _localRegionEnd[i] = end[i]; + } } void BoundaryHandler::updateGlobalWallLookupTable() { - _isGlobalWall[DimensionUtils::DimensionType::POSX] = - isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); - _isGlobalWall[DimensionUtils::DimensionType::NEGX] = - isNearRel(_localRegionStart[0], _globalRegionStart[0]); - _isGlobalWall[DimensionUtils::DimensionType::POSY] = - isNearRel(_localRegionEnd[1], _globalRegionEnd[1]); - _isGlobalWall[DimensionUtils::DimensionType::NEGY] = - isNearRel(_localRegionStart[1], _globalRegionStart[1]); - _isGlobalWall[DimensionUtils::DimensionType::POSZ] = - isNearRel(_localRegionEnd[2], _globalRegionEnd[2]); - _isGlobalWall[DimensionUtils::DimensionType::NEGZ] = - isNearRel(_localRegionStart[2], _globalRegionStart[2]); + _isGlobalWall[DimensionUtils::DimensionType::POSX] = isNearRel(_localRegionEnd[0], _globalRegionEnd[0]); + _isGlobalWall[DimensionUtils::DimensionType::NEGX] = isNearRel(_localRegionStart[0], _globalRegionStart[0]); + _isGlobalWall[DimensionUtils::DimensionType::POSY] = isNearRel(_localRegionEnd[1], _globalRegionEnd[1]); + _isGlobalWall[DimensionUtils::DimensionType::NEGY] = isNearRel(_localRegionStart[1], _globalRegionStart[1]); + _isGlobalWall[DimensionUtils::DimensionType::POSZ] = isNearRel(_localRegionEnd[2], _globalRegionEnd[2]); + _isGlobalWall[DimensionUtils::DimensionType::NEGZ] = isNearRel(_localRegionStart[2], _globalRegionStart[2]); } bool BoundaryHandler::hasInvalidBoundary() const { - return std::any_of(_boundaries.begin(), _boundaries.end(),[](const auto &keyVal) { - const auto [dim, boundaryType] = keyVal; - return boundaryType == BoundaryUtils::BoundaryType::ERROR; - }); + return std::any_of(_boundaries.begin(), _boundaries.end(), [](const auto &keyVal) { + const auto [dim, boundaryType] = keyVal; + return boundaryType == BoundaryUtils::BoundaryType::ERROR; + }); } bool BoundaryHandler::hasNonPeriodicBoundary() const { - return std::any_of(_boundaries.begin(), _boundaries.end(),[](const auto &keyVal) { - const auto [dim, boundaryType] = keyVal; - return boundaryType == BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL; - }); + return std::any_of(_boundaries.begin(), _boundaries.end(), [](const auto &keyVal) { + const auto [dim, boundaryType] = keyVal; + return boundaryType == BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL; + }); } -bool BoundaryHandler::isGlobalWall( - DimensionUtils::DimensionType dimension) const { - return _isGlobalWall.at(dimension); +bool BoundaryHandler::isGlobalWall(DimensionUtils::DimensionType dimension) const { + return _isGlobalWall.at(dimension); } bool BoundaryHandler::isGlobalWall(int dimension) const { - return isGlobalWall(DimensionUtils::convertLS1DimIndexToEnumPositive(dimension)); + return isGlobalWall(DimensionUtils::convertLS1DimIndexToEnumPositive(dimension)); } -void BoundaryHandler::processGlobalWallLeavingParticles( - ParticleContainer *moleculeContainer, double timestepLength) const { - const auto cutoff = moleculeContainer->getCutoff(); - for (auto const [currentDim, currentWallIsGlobalWall] : _isGlobalWall) { - if (!currentWallIsGlobalWall) - continue; - - switch (getGlobalWallType(currentDim)) { - case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: - // nothing changes from normal ls1 behaviour, so leaving particles not touched by BoundaryHandler and are processed by - // DomainDecompBase::handleDomainLeavingParticles() - break; - - case BoundaryUtils::BoundaryType::OUTFLOW: - [[fallthrough]]; - case BoundaryUtils::BoundaryType::REFLECTING: { - // create region by using getInnerRegionSlab() - const auto [curWallRegionBegin, curWallRegionEnd] = - RegionUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, - currentDim, cutoff); - // grab an iterator from the converted coords - const auto particlesInRegion = moleculeContainer->regionIterator( - curWallRegionBegin.data(), curWallRegionEnd.data(), - ParticleIterator::ONLY_INNER_AND_BOUNDARY); - - // iterate through all molecules - for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { - // Calculate the change in velocity, which the leapfrog method will - // apply in the next velocity update to the dimension of interest. - const int currentDimInt = - DimensionUtils::convertEnumToLS1DimIndex(currentDim); - const double halfTimestep = .5 * timestepLength; - const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); - const double force = moleculeIter->F(currentDimInt); - const double nextStepVelAdjustment = halfTimestepByMass * force; - - // check if the molecule would leave the bounds - if (RegionUtils::isMoleculeLeaving( - *moleculeIter, curWallRegionBegin, curWallRegionEnd, currentDim, - timestepLength, nextStepVelAdjustment)) { - if (getGlobalWallType(currentDim) == - BoundaryUtils::BoundaryType::REFLECTING) { - const double currentVel = moleculeIter->v(currentDimInt); - // change the velocity in the dimension of interest such that when - // the leapfrog integrator adds nextStepVelAdjustment in the next - // velocity update, the final result ends up being the intended, - // reversed velocity: -(currentVel+nextStepVelAdjustment) - moleculeIter->setv(currentDimInt, -currentVel - nextStepVelAdjustment - - nextStepVelAdjustment); - } else { // outflow, delete the particle if it would leave - moleculeContainer->deleteMolecule(moleculeIter, false); - } - } - } - break; - } - default: - Log::global_log->error() - << "Boundary type error! Received type not allowed!" << std::endl; - mardyn_exit(1); - } - } +void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, + double timestepLength) const { + const auto cutoff = moleculeContainer->getCutoff(); + for (auto const [currentDim, currentWallIsGlobalWall] : _isGlobalWall) { + if (!currentWallIsGlobalWall) + continue; + + switch (getGlobalWallType(currentDim)) { + case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: + // nothing changes from normal ls1 behaviour, so leaving particles not touched by BoundaryHandler and are + // processed by DomainDecompBase::handleDomainLeavingParticles() + break; + + case BoundaryUtils::BoundaryType::OUTFLOW: + [[fallthrough]]; + case BoundaryUtils::BoundaryType::REFLECTING: { + // create region by using getInnerRegionSlab() + const auto [curWallRegionBegin, curWallRegionEnd] = + RegionUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, currentDim, cutoff); + // grab an iterator from the converted coords + const auto particlesInRegion = moleculeContainer->regionIterator( + curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ONLY_INNER_AND_BOUNDARY); + + // iterate through all molecules + for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { + // Calculate the change in velocity, which the leapfrog method will + // apply in the next velocity update to the dimension of interest. + const int currentDimInt = DimensionUtils::convertEnumToLS1DimIndex(currentDim); + const double halfTimestep = .5 * timestepLength; + const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); + const double force = moleculeIter->F(currentDimInt); + const double nextStepVelAdjustment = halfTimestepByMass * force; + + // check if the molecule would leave the bounds + if (RegionUtils::isMoleculeLeaving(*moleculeIter, curWallRegionBegin, curWallRegionEnd, currentDim, + timestepLength, nextStepVelAdjustment)) { + if (getGlobalWallType(currentDim) == BoundaryUtils::BoundaryType::REFLECTING) { + const double currentVel = moleculeIter->v(currentDimInt); + // change the velocity in the dimension of interest such that when + // the leapfrog integrator adds nextStepVelAdjustment in the next + // velocity update, the final result ends up being the intended, + // reversed velocity: -(currentVel+nextStepVelAdjustment) + moleculeIter->setv(currentDimInt, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); + } else { // outflow, delete the particle if it would leave + moleculeContainer->deleteMolecule(moleculeIter, false); + } + } + } + break; + } + default: + Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + mardyn_exit(1); + } + } } -void BoundaryHandler::removeNonPeriodicHalos( - ParticleContainer *moleculeContainer) const { - // get halo lengths in each dimension - const std::array haloWidths = { - moleculeContainer->getHaloWidthForDimension(0), - moleculeContainer->getHaloWidthForDimension(1), - moleculeContainer->getHaloWidthForDimension(2)}; - for (auto const [currentDim, currentWallIsGlobalWall] : _isGlobalWall) { - if (!currentWallIsGlobalWall) - continue; - - switch (getGlobalWallType(currentDim)) { - case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: - // nothing changes from normal ls1 behaviour, so empty case, and halo particles left untouched - break; - - case BoundaryUtils::BoundaryType::OUTFLOW: - [[fallthrough]]; - case BoundaryUtils::BoundaryType::REFLECTING: { - // create region by using getOuterRegionSlab() - auto const [curWallRegionBegin, curWallRegionEnd] = - RegionUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, - currentDim, haloWidths); - - // grab an iterator from the converted coords - auto particlesInRegion = moleculeContainer->regionIterator( - curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ALL_CELLS); - for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { - // delete all halo particles - moleculeContainer->deleteMolecule(moleculeIter, false); - } - break; - } - default: - Log::global_log->error() - << "Boundary type error! Received type not allowed!" << std::endl; - mardyn_exit(1); - } - } +void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer *moleculeContainer) const { + // get halo lengths in each dimension + const std::array haloWidths = {moleculeContainer->getHaloWidthForDimension(0), + moleculeContainer->getHaloWidthForDimension(1), + moleculeContainer->getHaloWidthForDimension(2)}; + for (auto const [currentDim, currentWallIsGlobalWall] : _isGlobalWall) { + if (!currentWallIsGlobalWall) + continue; + + switch (getGlobalWallType(currentDim)) { + case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: + // nothing changes from normal ls1 behaviour, so empty case, and halo particles left untouched + break; + + case BoundaryUtils::BoundaryType::OUTFLOW: + [[fallthrough]]; + case BoundaryUtils::BoundaryType::REFLECTING: { + // create region by using getOuterRegionSlab() + auto const [curWallRegionBegin, curWallRegionEnd] = + RegionUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, currentDim, haloWidths); + + // grab an iterator from the converted coords + auto particlesInRegion = moleculeContainer->regionIterator( + curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ALL_CELLS); + for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { + // delete all halo particles + moleculeContainer->deleteMolecule(moleculeIter, false); + } + break; + } + default: + Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + mardyn_exit(1); + } + } #ifndef MARDYN_AUTOPAS - moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); + moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); #endif } diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index 1e7c2cd761..eb6fac8271 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -7,9 +7,9 @@ #pragma once -#include "RegionUtils.h" #include "BoundaryUtils.h" #include "DimensionUtils.h" +#include "RegionUtils.h" #include "particleContainer/ParticleContainer.h" #include @@ -34,99 +34,95 @@ */ class BoundaryHandler { -public: - BoundaryHandler() = default; - - /* Find the boundary type of a global wall for a particular dimension. */ - BoundaryUtils::BoundaryType - getGlobalWallType(DimensionUtils::DimensionType dimension) const; - - /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWallType(DimensionUtils::DimensionType dimension, - BoundaryUtils::BoundaryType value); - - - BoundaryUtils::BoundaryType getGlobalWallType(int dimension) const; - - /* Check if any of the global boundaries have invalid types. */ - bool hasInvalidBoundary() const; - - /** - * Check if any of the global boundaries are non-periodic. - * - * This check helps bypass all boundary-related code if default behaviour - * (all periodic boundaries) is expected. - */ - bool hasNonPeriodicBoundary() const; - - /* Set bounds for global subdomain. */ - void setGlobalRegion(const double *start, const double *end); - - /* Set bounds for local subdomain. */ - void setLocalRegion(const double *start, const double *end); - /** - * Determine which walls in the local region are actually global walls. - * - * Should be called after changing global and local regions (typically after a - * rebalance). - */ - void updateGlobalWallLookupTable(); - - /* Check if the local wall in a particular dimension is actually a global - * wall. */ - bool isGlobalWall(DimensionUtils::DimensionType dimension) const; - - /* Check if the local wall in a particular dimension is actually a global - * wall. */ - bool isGlobalWall(int dimension) const; - - /** - * Processes all particles that would leave the global domain. - * - * If a subdomain has no global walls, this function does nothing. - * For every global wall, the function iterates through all particles that are - * within one cutoff distance away from the wall. If these particles would - * leave the global box in the next simulation, the following is done: - * - * PERIODIC_OR_LOCAL - No actions taken (default behaviour). - * REFLECTING - The particle's velocity is reversed normal to the wall it's - * leaving. - * OUTFLOW - The particle is deleted. - */ - void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, - double timestepLength) const; - - /** - * Processes all halo particles outside the global domain. - * - * If a subdomain has no global walls, this function does nothing. - * For every global wall, the function iterates through all halo particles - * that are within one cutoff distance away from the wall. The following is - * done for each particle: - * - * PERIODIC_OR_LOCAL - No actions taken (default behaviour). - * REFLECTING / OUTFLOW - The halo particle is deleted, so that particles - * approaching the boundary do not decelerate due to influence from the halo - * particles, and preserve their velocities before being bounced/deleted - */ - void removeNonPeriodicHalos(ParticleContainer *moleculeContainer) const; - -private: - /* List of global boundary type per dimension. */ - std::map - _boundaries {{DimensionUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::NEGZ,BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}}; - - /* Lookup table to check if a local wall is also global. */ - std::map _isGlobalWall; - - /* Global region start/end. */ - std::array _globalRegionStart, _globalRegionEnd; - - /* Local region start/end. */ - std::array _localRegionStart, _localRegionEnd; + public: + BoundaryHandler() = default; + + /* Find the boundary type of a global wall for a particular dimension. */ + BoundaryUtils::BoundaryType getGlobalWallType(DimensionUtils::DimensionType dimension) const; + + /* Set the boundary type of a global wall for a particular dimension. */ + void setGlobalWallType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); + + BoundaryUtils::BoundaryType getGlobalWallType(int dimension) const; + + /* Check if any of the global boundaries have invalid types. */ + bool hasInvalidBoundary() const; + + /** + * Check if any of the global boundaries are non-periodic. + * + * This check helps bypass all boundary-related code if default behaviour + * (all periodic boundaries) is expected. + */ + bool hasNonPeriodicBoundary() const; + + /* Set bounds for global subdomain. */ + void setGlobalRegion(const double *start, const double *end); + + /* Set bounds for local subdomain. */ + void setLocalRegion(const double *start, const double *end); + /** + * Determine which walls in the local region are actually global walls. + * + * Should be called after changing global and local regions (typically after a + * rebalance). + */ + void updateGlobalWallLookupTable(); + + /* Check if the local wall in a particular dimension is actually a global + * wall. */ + bool isGlobalWall(DimensionUtils::DimensionType dimension) const; + + /* Check if the local wall in a particular dimension is actually a global + * wall. */ + bool isGlobalWall(int dimension) const; + + /** + * Processes all particles that would leave the global domain. + * + * If a subdomain has no global walls, this function does nothing. + * For every global wall, the function iterates through all particles that are + * within one cutoff distance away from the wall. If these particles would + * leave the global box in the next simulation, the following is done: + * + * PERIODIC_OR_LOCAL - No actions taken (default behaviour). + * REFLECTING - The particle's velocity is reversed normal to the wall it's + * leaving. + * OUTFLOW - The particle is deleted. + */ + void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, double timestepLength) const; + + /** + * Processes all halo particles outside the global domain. + * + * If a subdomain has no global walls, this function does nothing. + * For every global wall, the function iterates through all halo particles + * that are within one cutoff distance away from the wall. The following is + * done for each particle: + * + * PERIODIC_OR_LOCAL - No actions taken (default behaviour). + * REFLECTING / OUTFLOW - The halo particle is deleted, so that particles + * approaching the boundary do not decelerate due to influence from the halo + * particles, and preserve their velocities before being bounced/deleted + */ + void removeNonPeriodicHalos(ParticleContainer *moleculeContainer) const; + + private: + /* List of global boundary type per dimension. */ + std::map _boundaries{ + {DimensionUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, + {DimensionUtils::DimensionType::NEGZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}}; + + /* Lookup table to check if a local wall is also global. */ + std::map _isGlobalWall; + + /* Global region start/end. */ + std::array _globalRegionStart, _globalRegionEnd; + + /* Local region start/end. */ + std::array _localRegionStart, _localRegionEnd; }; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 1b4c0e5327..e33e123527 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -6,47 +6,44 @@ */ #include -#include #include +#include #include "BoundaryUtils.h" -#include "utils/mardyn_assert.h" #include "utils/Logger.h" +#include "utils/mardyn_assert.h" -BoundaryUtils::BoundaryType -BoundaryUtils::convertStringToBoundary(const std::string &boundary) { - std::string boundaryLowercase; - std::transform(boundary.begin(), boundary.end(), boundaryLowercase.begin(), - [](unsigned char c){ return std::tolower(c); }); - if (boundaryLowercase.find("per") != std::string::npos) - return BoundaryType::PERIODIC_OR_LOCAL; - if (boundaryLowercase.find("ref") != std::string::npos) - return BoundaryType::REFLECTING; - if (boundaryLowercase.find("out") != std::string::npos) - return BoundaryType::OUTFLOW; - Log::global_log->error() - << "Invalid boundary type passed to " - "BoundaryUtils::convertStringToBoundary. Check your input file!" - << std::endl; - mardyn_exit(1); - return BoundaryType::ERROR; // warning suppression +BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) { + std::string boundaryLowercase; + std::transform(boundary.begin(), boundary.end(), boundaryLowercase.begin(), + [](unsigned char c) { return std::tolower(c); }); + if (boundaryLowercase.find("per") != std::string::npos) + return BoundaryType::PERIODIC_OR_LOCAL; + if (boundaryLowercase.find("ref") != std::string::npos) + return BoundaryType::REFLECTING; + if (boundaryLowercase.find("out") != std::string::npos) + return BoundaryType::OUTFLOW; + Log::global_log->error() << "Invalid boundary type passed to " + "BoundaryUtils::convertStringToBoundary. Check your input file!" + << std::endl; + mardyn_exit(1); + return BoundaryType::ERROR; // warning suppression } std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { - switch (boundary) { - case BoundaryType::PERIODIC_OR_LOCAL: - return "periodic"; - case BoundaryType::REFLECTING: - return "reflecting"; - case BoundaryType::OUTFLOW: - return "outflow"; - default: - Log::global_log->error() - << "Invalid boundary type passed to " - "BoundaryUtils::convertBoundaryToString. Check your input file!" - << std::endl; - mardyn_exit(1); - } - return "error"; // warning suppression + switch (boundary) { + case BoundaryType::PERIODIC_OR_LOCAL: + return "periodic"; + case BoundaryType::REFLECTING: + return "reflecting"; + case BoundaryType::OUTFLOW: + return "outflow"; + default: + Log::global_log->error() << "Invalid boundary type passed to " + "BoundaryUtils::convertBoundaryToString. Check your input file!" + << std::endl; + mardyn_exit(1); + } + return "error"; // warning suppression } diff --git a/src/parallel/boundaries/DimensionUtils.cpp b/src/parallel/boundaries/DimensionUtils.cpp index de777cf601..e74d0edb38 100644 --- a/src/parallel/boundaries/DimensionUtils.cpp +++ b/src/parallel/boundaries/DimensionUtils.cpp @@ -10,106 +10,103 @@ #include "utils/mardyn_assert.h" // for mardyn_exit() bool DimensionUtils::isDimensionNumericPermissible(int dim) { - // permissible dimensions are {-1, -2, -3, 1, 2, 3} - return (dim >= -3 && dim <= 3 && dim != 0); + // permissible dimensions are {-1, -2, -3, 1, 2, 3} + return (dim >= -3 && dim <= 3 && dim != 0); } DimensionUtils::DimensionType DimensionUtils::convertNumericToDimension(int dim) { - if (!isDimensionNumericPermissible(dim)) { - Log::global_log->error() - << "Invalid dimension passed for enum conversion. Received value: " << dim << std::endl; - mardyn_exit(1); - return DimensionType::ERROR; - } - switch (dim) { - case 1: - return DimensionType::POSX; - case 2: - return DimensionType::POSY; - case 3: - return DimensionType::POSZ; - case -1: - return DimensionType::NEGX; - case -2: - return DimensionType::NEGY; - case -3: - return DimensionType::NEGZ; - } - return DimensionType::ERROR; //warning suppression + if (!isDimensionNumericPermissible(dim)) { + Log::global_log->error() << "Invalid dimension passed for enum conversion. Received value: " << dim + << std::endl; + mardyn_exit(1); + return DimensionType::ERROR; + } + switch (dim) { + case 1: + return DimensionType::POSX; + case 2: + return DimensionType::POSY; + case 3: + return DimensionType::POSZ; + case -1: + return DimensionType::NEGX; + case -2: + return DimensionType::NEGY; + case -3: + return DimensionType::NEGZ; + } + return DimensionType::ERROR; // warning suppression } DimensionUtils::DimensionType DimensionUtils::convertLS1DimIndexToEnumPositive(int dim) { - switch (dim) { - case 0: - return DimensionType::POSX; - case 1: - return DimensionType::POSY; - case 2: - return DimensionType::POSZ; - default: - return DimensionType::ERROR; - } + switch (dim) { + case 0: + return DimensionType::POSX; + case 1: + return DimensionType::POSY; + case 2: + return DimensionType::POSZ; + default: + return DimensionType::ERROR; + } } std::string DimensionUtils::convertDimensionToString(DimensionType dimension) { - switch (dimension) { - case DimensionType::POSX: - return "+x"; + switch (dimension) { + case DimensionType::POSX: + return "+x"; - case DimensionType::POSY: - return "+y"; + case DimensionType::POSY: + return "+y"; - case DimensionType::POSZ: - return "+z"; + case DimensionType::POSZ: + return "+z"; - case DimensionType::NEGX: - return "-x"; + case DimensionType::NEGX: + return "-x"; - case DimensionType::NEGY: - return "-y"; + case DimensionType::NEGY: + return "-y"; - case DimensionType::NEGZ: - return "-z"; + case DimensionType::NEGZ: + return "-z"; - default: - Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return "error"; - } + default: + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return "error"; + } } -std::string -DimensionUtils::convertDimensionToStringAbs(DimensionType dimension) { - return convertDimensionToString(dimension).substr(1, 1); +std::string DimensionUtils::convertDimensionToStringAbs(DimensionType dimension) { + return convertDimensionToString(dimension).substr(1, 1); } int DimensionUtils::convertDimensionToNumeric(DimensionType dimension) { - switch (dimension) { - case DimensionType::POSX: - return 1; - case DimensionType::POSY: - return 2; - case DimensionType::POSZ: - return 3; - case DimensionType::NEGX: - return -1; - case DimensionType::NEGY: - return -2; - case DimensionType::NEGZ: - return -3; - default: - Log::global_log->error() - << "Invalid dimension passed for enum conversion" << std::endl; - mardyn_exit(1); - return 0; - } + switch (dimension) { + case DimensionType::POSX: + return 1; + case DimensionType::POSY: + return 2; + case DimensionType::POSZ: + return 3; + case DimensionType::NEGX: + return -1; + case DimensionType::NEGY: + return -2; + case DimensionType::NEGZ: + return -3; + default: + Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + mardyn_exit(1); + return 0; + } } int DimensionUtils::convertDimensionToNumericAbs(DimensionType dimension) { - return std::abs(convertDimensionToNumeric(dimension)); + return std::abs(convertDimensionToNumeric(dimension)); } int DimensionUtils::convertEnumToLS1DimIndex(DimensionType dimension) { - return convertDimensionToNumericAbs(dimension) - 1; + return convertDimensionToNumericAbs(dimension) - 1; } \ No newline at end of file diff --git a/src/parallel/boundaries/DimensionUtils.h b/src/parallel/boundaries/DimensionUtils.h index 88641eede2..a818f23855 100644 --- a/src/parallel/boundaries/DimensionUtils.h +++ b/src/parallel/boundaries/DimensionUtils.h @@ -7,8 +7,8 @@ #pragma once -#include #include "utils/Math.h" +#include namespace DimensionUtils { /** @@ -60,11 +60,8 @@ int convertDimensionToNumericAbs(DimensionType dimension); */ int convertEnumToLS1DimIndex(DimensionType dimension); - /* Returns the sign of a number, used for determining direction from a * dimension. */ -inline int findSign(DimensionType dimension) { - return ::findSign(convertDimensionToNumeric(dimension)); -} +inline int findSign(DimensionType dimension) { return ::findSign(convertDimensionToNumeric(dimension)); } } // namespace DimensionUtils \ No newline at end of file diff --git a/src/parallel/boundaries/RegionUtils.cpp b/src/parallel/boundaries/RegionUtils.cpp index 365a4a7058..a5fd693df2 100644 --- a/src/parallel/boundaries/RegionUtils.cpp +++ b/src/parallel/boundaries/RegionUtils.cpp @@ -8,119 +8,106 @@ #include "RegionUtils.h" #include "utils/mardyn_assert.h" //for mardyn_exit() -std::tuple, std::array> -RegionUtils::getInnerRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionUtils::DimensionType dimension, double regionWidth) { +std::tuple, std::array> RegionUtils::getInnerRegionSlab( + const std::array &givenRegionBegin, const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, double regionWidth) { - std::array returnRegionBegin = givenRegionBegin; - std::array returnRegionEnd = givenRegionBegin; + std::array returnRegionBegin = givenRegionBegin; + std::array returnRegionEnd = givenRegionBegin; - const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); - switch (dimension) { - // in positive case, set the beginning to end-width, or whole domain if width - // too large - case DimensionUtils::DimensionType::POSX: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSY: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = - std::max(returnRegionEnd[dimensionLS1] - regionWidth, - givenRegionBegin[dimensionLS1]); - break; - // in negative case, set the end to beginning+width, or whole domain if width - // too large - case DimensionUtils::DimensionType::NEGX: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGY: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = - std::min(returnRegionBegin[dimensionLS1] + regionWidth, - givenRegionEnd[dimensionLS1]); - break; + const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); + switch (dimension) { + // in positive case, set the beginning to end-width, or whole domain if width + // too large + case DimensionUtils::DimensionType::POSX: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSY: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = + std::max(returnRegionEnd[dimensionLS1] - regionWidth, givenRegionBegin[dimensionLS1]); + break; + // in negative case, set the end to beginning+width, or whole domain if width + // too large + case DimensionUtils::DimensionType::NEGX: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGY: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = + std::min(returnRegionBegin[dimensionLS1] + regionWidth, givenRegionEnd[dimensionLS1]); + break; - default: - Log::global_log->error() - << "Invalid dimension passed for inner buffer calculation\n"; - mardyn_exit(1); - } - return {returnRegionBegin, returnRegionEnd}; + default: + Log::global_log->error() << "Invalid dimension passed for inner buffer calculation\n"; + mardyn_exit(1); + } + return {returnRegionBegin, returnRegionEnd}; } -bool RegionUtils::isMoleculeLeaving(const Molecule &molecule, - const std::array ®ionBegin, - const std::array ®ionEnd, - DimensionUtils::DimensionType dimension, - double timestepLength, - double nextStepVelAdjustment) { - const int ls1dim = convertEnumToLS1DimIndex(dimension); - const int direction = findSign(dimension); - const double newPos = - molecule.r(ls1dim) + - (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); - if (newPos <= regionBegin[ls1dim] && direction < 0) - return true; - if (newPos >= regionEnd[ls1dim] && direction > 0) - return true; - return false; +bool RegionUtils::isMoleculeLeaving(const Molecule &molecule, const std::array ®ionBegin, + const std::array ®ionEnd, DimensionUtils::DimensionType dimension, + double timestepLength, double nextStepVelAdjustment) { + const int ls1dim = convertEnumToLS1DimIndex(dimension); + const int direction = findSign(dimension); + const double newPos = molecule.r(ls1dim) + (timestepLength * (molecule.v(ls1dim) + nextStepVelAdjustment)); + if (newPos <= regionBegin[ls1dim] && direction < 0) + return true; + if (newPos >= regionEnd[ls1dim] && direction > 0) + return true; + return false; } -std::tuple, std::array> -RegionUtils::getOuterRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionUtils::DimensionType dimension, - const std::array ®ionWidth) { - std::array returnRegionBegin = givenRegionBegin; - std::array returnRegionEnd = givenRegionEnd; +std::tuple, std::array> RegionUtils::getOuterRegionSlab( + const std::array &givenRegionBegin, const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, const std::array ®ionWidth) { + std::array returnRegionBegin = givenRegionBegin; + std::array returnRegionEnd = givenRegionEnd; - for (int i = 0; i < 3; i++) { - returnRegionBegin[i] = givenRegionBegin[i]; - returnRegionEnd[i] = givenRegionEnd[i]; - } + for (int i = 0; i < 3; i++) { + returnRegionBegin[i] = givenRegionBegin[i]; + returnRegionEnd[i] = givenRegionEnd[i]; + } - const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); + const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); - // find the two dimensions that are not being considered - const int extraDim1 = dimensionLS1 == 0 ? 1 : 0; - const int extraDim2 = dimensionLS1 == 2 ? 1 : 2; + // find the two dimensions that are not being considered + const int extraDim1 = dimensionLS1 == 0 ? 1 : 0; + const int extraDim2 = dimensionLS1 == 2 ? 1 : 2; - // extend the extra dimensions to cover all ghost areas - returnRegionBegin[extraDim1] -= regionWidth[extraDim1]; - returnRegionEnd[extraDim1] += regionWidth[extraDim1]; + // extend the extra dimensions to cover all ghost areas + returnRegionBegin[extraDim1] -= regionWidth[extraDim1]; + returnRegionEnd[extraDim1] += regionWidth[extraDim1]; - returnRegionBegin[extraDim2] -= regionWidth[extraDim2]; - returnRegionEnd[extraDim2] += regionWidth[extraDim2]; + returnRegionBegin[extraDim2] -= regionWidth[extraDim2]; + returnRegionEnd[extraDim2] += regionWidth[extraDim2]; - switch (dimension) // can be done with findsign() too, but this is clearer - { - // in positive case, move the box begin to edge of domain, and box end to - // beyond - case DimensionUtils::DimensionType::POSX: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSY: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; - returnRegionEnd[dimensionLS1] += regionWidth[dimensionLS1]; - break; + switch (dimension) { + // in positive case, move the box begin to edge of domain, and box end to + // beyond + case DimensionUtils::DimensionType::POSX: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSY: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; + returnRegionEnd[dimensionLS1] += regionWidth[dimensionLS1]; + break; - // in negative case, move the box end to edge of domain, and box begin to - // beyond - case DimensionUtils::DimensionType::NEGX: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGY: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; - returnRegionBegin[dimensionLS1] -= regionWidth[dimensionLS1]; - break; + // in negative case, move the box end to edge of domain, and box begin to + // beyond + case DimensionUtils::DimensionType::NEGX: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGY: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; + returnRegionBegin[dimensionLS1] -= regionWidth[dimensionLS1]; + break; - default: - Log::global_log->error() - << "Invalid dimension passed for inner buffer calculation" << std::endl; - mardyn_exit(1); - } - return std::make_tuple(returnRegionBegin, returnRegionEnd); + default: + Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; + mardyn_exit(1); + } + return std::make_tuple(returnRegionBegin, returnRegionEnd); } diff --git a/src/parallel/boundaries/RegionUtils.h b/src/parallel/boundaries/RegionUtils.h index 54508b71d8..8e63fe1263 100644 --- a/src/parallel/boundaries/RegionUtils.h +++ b/src/parallel/boundaries/RegionUtils.h @@ -7,9 +7,9 @@ #pragma once -#include #include "DimensionUtils.h" #include "molecules/Molecule.h" +#include namespace RegionUtils { @@ -24,10 +24,9 @@ namespace RegionUtils { * units from the +x boundary wall, in the original domain * demarcated by givenRegion{begin,end}. */ -std::tuple, std::array> -getInnerRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionUtils::DimensionType dimension, double regionWidth); +std::tuple, std::array> getInnerRegionSlab( + const std::array &givenRegionBegin, const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, double regionWidth); /** * Checks if a given molecule is leaving the given region in the next timestep, @@ -43,11 +42,9 @@ getInnerRegionSlab(const std::array &givenRegionBegin, * so that it can handle the change in velocity due to forces. This is not done * by the util function itself, to keep it as generic as possible. */ -bool isMoleculeLeaving(const Molecule &molecule, - const std::array ®ionBegin, - const std::array ®ionEnd, - DimensionUtils::DimensionType dimension, double timestepLength, - double nextStepVelAdjustment); +bool isMoleculeLeaving(const Molecule &molecule, const std::array ®ionBegin, + const std::array ®ionEnd, DimensionUtils::DimensionType dimension, + double timestepLength, double nextStepVelAdjustment); /** * When given a domain delimited by givenRegionBegin and givenRegionEnd @@ -60,10 +57,8 @@ bool isMoleculeLeaving(const Molecule &molecule, * returns a box, which contains every ghost particle that is 3 units away * from +x. */ -std::tuple, std::array> -getOuterRegionSlab(const std::array &givenRegionBegin, - const std::array &givenRegionEnd, - DimensionUtils::DimensionType dimension, - const std::array ®ionWidth); +std::tuple, std::array> getOuterRegionSlab( + const std::array &givenRegionBegin, const std::array &givenRegionEnd, + DimensionUtils::DimensionType dimension, const std::array ®ionWidth); } // namespace RegionUtils \ No newline at end of file From f0a1c3227e4872d5ce1c1c0581a7910b104f793b Mon Sep 17 00:00:00 2001 From: amartyads Date: Thu, 19 Sep 2024 18:36:00 +0200 Subject: [PATCH 84/94] documentation, clangformat (new) --- src/Simulation.cpp | 4 +- src/parallel/DomainDecompBase.cpp | 6 +- src/parallel/DomainDecompBase.h | 4 +- src/parallel/boundaries/BoundaryHandler.cpp | 14 +- src/parallel/boundaries/BoundaryHandler.h | 139 ++++++++++++++------ src/parallel/boundaries/BoundaryUtils.cpp | 12 +- src/parallel/boundaries/BoundaryUtils.h | 40 ++++-- src/parallel/boundaries/DimensionUtils.cpp | 8 +- src/parallel/boundaries/DimensionUtils.h | 90 ++++++++++--- src/parallel/boundaries/RegionUtils.h | 41 +++++- src/utils/Math.h | 1 + 11 files changed, 262 insertions(+), 97 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index c5e69276ce..02adceb4a1 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -423,11 +423,11 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::NEGY, yBoundary); _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::POSZ, zBoundary); _domainDecomposition->setGlobalBoundaryType(DimensionUtils::DimensionType::NEGZ, zBoundary); - if (_domainDecomposition->hasInvalidBoundary()) { + if (_domainDecomposition->hasGlobalInvalidBoundary()) { Log::global_log->error() << "Invalid boundary type! Please check the config file" << std::endl; exit(1); } - if(_overlappingP2P && _domainDecomposition->hasNonPeriodicBoundary()) { + if(_overlappingP2P && _domainDecomposition->hasGlobalNonPeriodicBoundary()) { Log::global_log->info() << "Non-periodic boundaries not supported with overlappingP2P enabled! Exiting..." << std::endl; exit(1); } diff --git a/src/parallel/DomainDecompBase.cpp b/src/parallel/DomainDecompBase.cpp index 190e58c1a0..bb1eb112e4 100644 --- a/src/parallel/DomainDecompBase.cpp +++ b/src/parallel/DomainDecompBase.cpp @@ -43,12 +43,12 @@ void DomainDecompBase::setLocalBoundariesFromGlobal(Domain* domain, Ensemble* en } void DomainDecompBase::processBoundaryConditions(ParticleContainer* moleculeContainer, double timestepLength) { - if(hasNonPeriodicBoundary()) + if(hasGlobalNonPeriodicBoundary()) _boundaryHandler.processGlobalWallLeavingParticles(moleculeContainer, timestepLength); } void DomainDecompBase::removeNonPeriodicHalos(ParticleContainer* moleculeContainer) { - if(hasNonPeriodicBoundary()) + if(hasGlobalNonPeriodicBoundary()) _boundaryHandler.removeNonPeriodicHalos(moleculeContainer); } @@ -315,7 +315,7 @@ void DomainDecompBase::handleDomainLeavingParticlesDirect(const HaloRegion& halo void DomainDecompBase::populateHaloLayerWithCopies(unsigned dim, ParticleContainer* moleculeContainer) const { //reflecting and outflow boundaries do not expect halo particles - if(_boundaryHandler.getGlobalWallType(dim) != BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL) + if(_boundaryHandler.getGlobalWallType(dim) != BoundaryUtils::BoundaryType::PERIODIC) return; double shiftMagnitude = moleculeContainer->getBoundingBoxMax(dim) - moleculeContainer->getBoundingBoxMin(dim); diff --git a/src/parallel/DomainDecompBase.h b/src/parallel/DomainDecompBase.h index 2f0f6cbf86..b29ee19b1e 100644 --- a/src/parallel/DomainDecompBase.h +++ b/src/parallel/DomainDecompBase.h @@ -297,9 +297,9 @@ class DomainDecompBase: public MemoryProfilable { void setLocalBoundariesFromGlobal(Domain* domain, Ensemble* ensemble); /* Check if any of the global boundaries are invalid. */ - bool hasInvalidBoundary() const { return _boundaryHandler.hasInvalidBoundary();} + bool hasGlobalInvalidBoundary() const { return _boundaryHandler.hasGlobalInvalidBoundary();} - bool hasNonPeriodicBoundary() const { return _boundaryHandler.hasNonPeriodicBoundary();} + bool hasGlobalNonPeriodicBoundary() const { return _boundaryHandler.hasGlobalNonPeriodicBoundary();} /* Processes leaving particles according to the boundary coundition of the wall the particles would be leaving. */ void processBoundaryConditions(ParticleContainer* moleculeContainer, double timestepLength); diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index f0f503c9a4..33b8462168 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -5,8 +5,6 @@ * Author: amartyads */ -#include - #include "BoundaryHandler.h" #include "integrators/Integrator.h" @@ -15,6 +13,8 @@ #include "utils/Math.h" #include "utils/mardyn_assert.h" +#include + BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(DimensionUtils::DimensionType dimension) const { return _boundaries.at(dimension); } @@ -55,17 +55,17 @@ void BoundaryHandler::updateGlobalWallLookupTable() { _isGlobalWall[DimensionUtils::DimensionType::NEGZ] = isNearRel(_localRegionStart[2], _globalRegionStart[2]); } -bool BoundaryHandler::hasInvalidBoundary() const { +bool BoundaryHandler::hasGlobalInvalidBoundary() const { return std::any_of(_boundaries.begin(), _boundaries.end(), [](const auto &keyVal) { const auto [dim, boundaryType] = keyVal; return boundaryType == BoundaryUtils::BoundaryType::ERROR; }); } -bool BoundaryHandler::hasNonPeriodicBoundary() const { +bool BoundaryHandler::hasGlobalNonPeriodicBoundary() const { return std::any_of(_boundaries.begin(), _boundaries.end(), [](const auto &keyVal) { const auto [dim, boundaryType] = keyVal; - return boundaryType == BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL; + return boundaryType == BoundaryUtils::BoundaryType::PERIODIC; }); } @@ -85,7 +85,7 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer *molec continue; switch (getGlobalWallType(currentDim)) { - case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: + case BoundaryUtils::BoundaryType::PERIODIC: // nothing changes from normal ls1 behaviour, so leaving particles not touched by BoundaryHandler and are // processed by DomainDecompBase::handleDomainLeavingParticles() break; @@ -144,7 +144,7 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer *moleculeContaine continue; switch (getGlobalWallType(currentDim)) { - case BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL: + case BoundaryUtils::BoundaryType::PERIODIC: // nothing changes from normal ls1 behaviour, so empty case, and halo particles left untouched break; diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index eb6fac8271..f6860906a3 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -18,7 +18,8 @@ #include /** - * Class to handle boundary conditions, namely leaving and halo particles. + * @brief Class to handle boundary conditions, namely leaving and halo particles. + * @author Amartya Das Sharma * * The objects of this class store the local and global bounds of the subdomain * in every process, and provide functions to deal with leaving particles, and @@ -28,94 +29,156 @@ * walls while the walls that are also the limits of the global domain are * 'global' walls. * - * Since the behaviour of 'local' walls are unchanged (and is identical to the - * behaviour of global periodic walls), they are assigned to - * 'PERIODIC_OR_LOCAL'. + * All subdomains have a copy of the global wall types, and do not store their local + * boundary conditions; instead they check whether a particular local wall is also a + * global wall, and then use the global lookup table to ascertain what boundary effects to use. + * + * The default state for all global walls is 'PERIODIC', since that is the default ls1 behaviour. + * */ - class BoundaryHandler { - public: +public: BoundaryHandler() = default; - /* Find the boundary type of a global wall for a particular dimension. */ + /** + * @brief Find the boundary type of a global wall for a particular dimension. + * + * Since this returns the global wall type, every subdomain on every rank will return + * the same value for the same input. + * + * @param dimension the dimension of interest, must be DimensionType enum member + * @return BoundaryUtils::BoundaryType enum member corresponding to the global wall type + */ BoundaryUtils::BoundaryType getGlobalWallType(DimensionUtils::DimensionType dimension) const; - /* Set the boundary type of a global wall for a particular dimension. */ - void setGlobalWallType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); - + /** + * @brief Find the boundary type of a global wall for a particular dimension. + * + * Since this returns the global wall type, every subdomain on every rank will return + * the same value for the same input. + * + * @param dimension tte dimension of interest, must be an ls1-style index (0 for x, 1 for y, 2 for z) + * @return BoundaryUtils::BoundaryType enum member corresponding to the global wall type + */ BoundaryUtils::BoundaryType getGlobalWallType(int dimension) const; - /* Check if any of the global boundaries have invalid types. */ - bool hasInvalidBoundary() const; + /** + * @brief Set the boundary type of a global wall for a particular dimension. + * + * @param dimension the dimension of interest, must be DimensionType enum member + * @param value the type of the boundary, must be BoundaryType enum member + */ + void setGlobalWallType(DimensionUtils::DimensionType dimension, BoundaryUtils::BoundaryType value); + + /** + * @brief Check if any of the global boundaries have invalid types. + * + * @return true if any of the global boundaries is BoundaryType::ERROR + * @return false if none of the global boundaries are BoundaryType::ERROR + */ + bool hasGlobalInvalidBoundary() const; /** - * Check if any of the global boundaries are non-periodic. + * @brief Check if any of the global boundaries are non-periodic. + * + * This check helps bypass all boundary-handling related code if default behaviour + * (all periodic boundaries) is found. * - * This check helps bypass all boundary-related code if default behaviour - * (all periodic boundaries) is expected. + * @return true if any of the global boundaries are non-periodic + * @return false if all of the global boundaries are periodic */ - bool hasNonPeriodicBoundary() const; + bool hasGlobalNonPeriodicBoundary() const; - /* Set bounds for global subdomain. */ + /** + * @brief Set bounds for global domain. + * + * @param start double[3] array with coordinates of the start point + * @param end double[3] array with coordinates of the end point + */ void setGlobalRegion(const double *start, const double *end); - /* Set bounds for local subdomain. */ + /** + * @brief Set bounds for local subdomain. + * + * @param start double[3] array with coordinates of the start point + * @param end double[3] array with coordinates of the end point + */ void setLocalRegion(const double *start, const double *end); + /** - * Determine which walls in the local region are actually global walls. + * @brief Determine which walls in the local region are actually global walls. * - * Should be called after changing global and local regions (typically after a - * rebalance). + * Should be called after changing global and local regions (typically after a rebalance). */ void updateGlobalWallLookupTable(); - /* Check if the local wall in a particular dimension is actually a global - * wall. */ + /** + * @brief Check if the local wall in a particular dimension is actually a global wall. + * + * @param dimension the dimension of interest, must be DimensionType enum member + * @return true if the local wall in the given dimension is a global wall + * @return false if the local wall in the given dimension is not a global wall + */ bool isGlobalWall(DimensionUtils::DimensionType dimension) const; - /* Check if the local wall in a particular dimension is actually a global - * wall. */ + /** + * @brief Check if the local wall in a particular dimension is actually a global wall. + * + * @param dimension the dimension of interest, must be an ls1-style index (0 for x, 1 for y, 2 for z) + * @return true if the local wall in the given dimension is a global wall + * @return false if the local wall in the given dimension is not a global wall + */ bool isGlobalWall(int dimension) const; /** - * Processes all particles that would leave the global domain. + * @brief Processes all particles that would leave the global domain. * * If a subdomain has no global walls, this function does nothing. * For every global wall, the function iterates through all particles that are * within one cutoff distance away from the wall. If these particles would * leave the global box in the next simulation, the following is done: * - * PERIODIC_OR_LOCAL - No actions taken (default behaviour). - * REFLECTING - The particle's velocity is reversed normal to the wall it's - * leaving. + * PERIODIC - No actions taken (default behaviour). + * REFLECTING - The particle's velocity is reversed normal to the wall it's leaving. * OUTFLOW - The particle is deleted. + * + * If a particle would hit multiple walls with multiple types, the following happens: + * - If any of the walls is an outflow wall, the particle is deleted immediately, otherwise the following happen + * - The particle's velocity is reversed for the components where the wall is reflecting + * - Periodic effects happen as normal + * + * @param moleculeContainer used to get the cutoff, region iterators, and to delete particles if needed + * @param timestepLength the full timestep length, used to determine the position of the molecule + * in the next timestep to check whether it is leaving */ void processGlobalWallLeavingParticles(ParticleContainer *moleculeContainer, double timestepLength) const; /** - * Processes all halo particles outside the global domain. + * @brief Processes all halo particles outside the global domain. * * If a subdomain has no global walls, this function does nothing. * For every global wall, the function iterates through all halo particles * that are within one cutoff distance away from the wall. The following is * done for each particle: * - * PERIODIC_OR_LOCAL - No actions taken (default behaviour). + * PERIODIC - No actions taken (default behaviour). * REFLECTING / OUTFLOW - The halo particle is deleted, so that particles * approaching the boundary do not decelerate due to influence from the halo * particles, and preserve their velocities before being bounced/deleted + * + * @param moleculeContainer used to get the cutoff, region iterators, and to delete particles if needed */ void removeNonPeriodicHalos(ParticleContainer *moleculeContainer) const; - private: +private: /* List of global boundary type per dimension. */ std::map _boundaries{ - {DimensionUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}, - {DimensionUtils::DimensionType::NEGZ, BoundaryUtils::BoundaryType::PERIODIC_OR_LOCAL}}; + {DimensionUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC}, + {DimensionUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC}, + {DimensionUtils::DimensionType::POSZ, BoundaryUtils::BoundaryType::PERIODIC}, + {DimensionUtils::DimensionType::NEGX, BoundaryUtils::BoundaryType::PERIODIC}, + {DimensionUtils::DimensionType::NEGY, BoundaryUtils::BoundaryType::PERIODIC}, + {DimensionUtils::DimensionType::NEGZ, BoundaryUtils::BoundaryType::PERIODIC}}; /* Lookup table to check if a local wall is also global. */ std::map _isGlobalWall; diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index e33e123527..20fd3fa4a7 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -5,21 +5,21 @@ * Author: amartyads */ -#include -#include -#include - #include "BoundaryUtils.h" #include "utils/Logger.h" #include "utils/mardyn_assert.h" +#include +#include +#include + BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) { std::string boundaryLowercase; std::transform(boundary.begin(), boundary.end(), boundaryLowercase.begin(), [](unsigned char c) { return std::tolower(c); }); if (boundaryLowercase.find("per") != std::string::npos) - return BoundaryType::PERIODIC_OR_LOCAL; + return BoundaryType::PERIODIC; if (boundaryLowercase.find("ref") != std::string::npos) return BoundaryType::REFLECTING; if (boundaryLowercase.find("out") != std::string::npos) @@ -33,7 +33,7 @@ BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::st std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { switch (boundary) { - case BoundaryType::PERIODIC_OR_LOCAL: + case BoundaryType::PERIODIC: return "periodic"; case BoundaryType::REFLECTING: return "reflecting"; diff --git a/src/parallel/boundaries/BoundaryUtils.h b/src/parallel/boundaries/BoundaryUtils.h index da0d9b4524..f5f039b74b 100644 --- a/src/parallel/boundaries/BoundaryUtils.h +++ b/src/parallel/boundaries/BoundaryUtils.h @@ -8,32 +8,48 @@ #pragma once #include + /** - * Includes enums and helper functions for processing boundary conditions. - * - * Does not actually work on any molecule containers, hence can be used - * in a general sense for other calculations. + * @brief Includes the BoundaryType enum and helper functions for boundary types. + * @author Amartya Das Sharma */ namespace BoundaryUtils { /** - * enum storing the types of boundaries currently supported. + * @brief enum storing the types of global boundaries currently supported. * * The currently supported boundary types are - * PERIODIC_OR_LOCAL - periodic boundaries or local boundaries: both of which - * use the default (communicate particle transfers with neighbours) behaviour + * PERIODIC - periodic boundaries, using the default (communicate particle transfers with neighbours) behaviour * OUTFLOW - molecules exiting the boundary are deleted - * REFLECTING - molecules exiting the boundary have their velocities - * reversed in the direction they are leaving - * ERROR - kept for sanity checks + * REFLECTING - molecules exiting the boundary have their velocities reversed in the direction they are leaving (i.e. + * reflected) ERROR - kept for sanity checks * * This can be extended if needed. */ -enum class BoundaryType { PERIODIC_OR_LOCAL, OUTFLOW, REFLECTING, ERROR }; +enum class BoundaryType { PERIODIC, OUTFLOW, REFLECTING, ERROR }; -/* Used to convert string read from the XML input file. */ +/** + * @brief Convert strings read from the XML input file into BoundaryType enum members. + * + * The conversion logic is as follows: + * - Any string with "per" - BoundaryType::PERIODIC + * - Any string with "ref" - BoundaryType::REFLECTING + * - Any string with "out" - BoundaryType::OUTFLOW + * An error occurs if none of the substrings are found. + * + * @param boundary string read from xml file + * @return BoundaryType which is the corresponding BoundaryType enum member + */ BoundaryType convertStringToBoundary(const std::string &boundary); +/** + * @brief Converts BoundaryType enum members into strings. + * + * Used mainly for logging. + * + * @param boundary BoundaryType enum member + * @return std::string corresponding to the enum member + */ std::string convertBoundaryToString(BoundaryType boundary); } // namespace BoundaryUtils diff --git a/src/parallel/boundaries/DimensionUtils.cpp b/src/parallel/boundaries/DimensionUtils.cpp index e74d0edb38..fe08228599 100644 --- a/src/parallel/boundaries/DimensionUtils.cpp +++ b/src/parallel/boundaries/DimensionUtils.cpp @@ -55,23 +55,17 @@ std::string DimensionUtils::convertDimensionToString(DimensionType dimension) { switch (dimension) { case DimensionType::POSX: return "+x"; - case DimensionType::POSY: return "+y"; - case DimensionType::POSZ: return "+z"; - case DimensionType::NEGX: return "-x"; - case DimensionType::NEGY: return "-y"; - case DimensionType::NEGZ: return "-z"; - - default: + default: // ERROR Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; mardyn_exit(1); return "error"; diff --git a/src/parallel/boundaries/DimensionUtils.h b/src/parallel/boundaries/DimensionUtils.h index a818f23855..20cf7b3b22 100644 --- a/src/parallel/boundaries/DimensionUtils.h +++ b/src/parallel/boundaries/DimensionUtils.h @@ -10,9 +10,14 @@ #include "utils/Math.h" #include +/** + * @brief Includes the DimensionType enum and helper functions for dimension types. + * @author Amartya Das Sharma + */ namespace DimensionUtils { + /** - * enum storing the axes and direction. + * @brief enum storing the axes and direction. * * The dimensions are POSX, NEGX, POSY, NEGY, POSZ and NEGZ. * @@ -20,48 +25,99 @@ namespace DimensionUtils { */ enum class DimensionType { POSX, NEGX, POSY, NEGY, POSZ, NEGZ, ERROR }; -/* Check if a dimension is allowed. */ +/** + * @brief Checks if a numeric dimension is allowed. + * + * Allowed numeric dimensions are +-1 for x, +-2 for y, +-3 for z + * + * @param dim integer dimension + * @return true if `dim` is one of (1, 2, 3, -1, -2, -3) + * @return false if `dim` is not one of (1, 2, 3, -1, -2, -3) + */ bool isDimensionNumericPermissible(int dim); -/* Convert a dimension from number to DimensionType, where x = +-1, y = +-2 and - * z = +-3 */ +/** + * @brief Converts a dimension from number to DimensionType, where x = +-1, y = +-2 and z = +-3. + * + * Throws an error and exits if the dimension is not permissible. + * + * @param dim integer dimension + * @return DimensionType enum member corresponding to the integer dimension + */ DimensionType convertNumericToDimension(int dim); /** - * Convert an LS1 internal dimension representation int to DimensionType, where + * @brief Converts an LS1 internal dimension representation int to DimensionType, where * x = 0, y = 1 and z = 2 Since this does not contain direction information, the * positive direction is returned. + * + * Throws an error and exits if the dimension is not permissible. + * + * @param dim integer dimension (either 0, 1 or 2) + * @return DimensionType enum member corresponding to the integer dimension */ DimensionType convertLS1DimIndexToEnumPositive(int dim); -/* Convert a DimensionType into a string from permissibleDimensionsString */ +/** + * @brief Converts a DimensionType into a string. + * + * The expected return values are +x, -x, +y, -y, +z, -z. Can be used for logging purposes. + * Throws an error and exits if DimensionType::ERROR is encountered. + * + * @param dimension DimensionType enum member + * @return std::string which can be +x, -x, +y, -y, +z, -z + */ std::string convertDimensionToString(DimensionType dimension); /** - * Convert a DimensionType into a string from permissibleDimensionsString, and - * remove directions Ex: POSX and NEGX both return "x" + * @brief Converts a DimensionType into a string, and remove directional information. + * + * POSX and NEGX both return "x", POSY and NEGY return "y", and POSZ and NEGZ return "z". + * Can be used for logging purposes. Throws an error and exits if DimensionType::ERROR is encountered. + * + * @param dimension DimensionType enum member + * @return std::string which can be x, y, or z */ std::string convertDimensionToStringAbs(DimensionType dimension); -/* Convert a dimension from DimensionType to number, where x = +-1, y = +-2 and - * z = +-3 */ +/** + * @brief Converts a dimension from DimensionType to number, where x = +-1, y = +-2 and + * z = +-3. Throws an error and exits if DimensionType::ERROR is encountered. + * + * @param dimension DimensionType enum member + * @return int which is one of (1, 2, 3, -1, -2, -3) + */ int convertDimensionToNumeric(DimensionType dimension); /** - * Convert a DimensionType into an int, and remove directions - * +x/-x returns 1, +y/-y returns 2, +z/-z returns 3 + * @brief Converts a DimensionType into an int, and remove directions. + * + * +x/-x returns 1, +y/-y returns 2, +z/-z returns 3. + * Throws an error and exits if DimensionType::ERROR is encountered. + * + * @param dimension DimensionType enum member + * @return int which is one of (1, 2, 3) */ int convertDimensionToNumericAbs(DimensionType dimension); /** - * Convert a DimensionType to LS1 internal dimension representation int, where x - * = 0, y = 1 and z = 2 Since this does not contain direction information, both - * POSX and NEGX return 0, for example. + * @brief Converts a DimensionType to LS1 internal dimension representation int, where x + * = 0, y = 1 and z = 2 + * + * Since this does not contain direction information, both POSX and NEGX return 0, for example. + * Throws an error and exits if DimensionType::ERROR is encountered. + * + * @param dimension DimensionType enum member + * @return int which is one of (0, 1, 2) */ int convertEnumToLS1DimIndex(DimensionType dimension); -/* Returns the sign of a number, used for determining direction from a - * dimension. */ +/** + * @brief Returns the direction from a given DimensionType. + * + * @param dimension DimensionType enum member + * @return int which is 1 if the direction is positive, and -1 otherwise + */ inline int findSign(DimensionType dimension) { return ::findSign(convertDimensionToNumeric(dimension)); } } // namespace DimensionUtils \ No newline at end of file diff --git a/src/parallel/boundaries/RegionUtils.h b/src/parallel/boundaries/RegionUtils.h index 8e63fe1263..8e89b36209 100644 --- a/src/parallel/boundaries/RegionUtils.h +++ b/src/parallel/boundaries/RegionUtils.h @@ -11,10 +11,17 @@ #include "molecules/Molecule.h" #include +/** + * @brief Includes helper functions for region-related computation during boundary handling. + * @author Amartya Das Sharma + * + * Does not actually work on any molecule containers, hence can be used + * in a general sense for other calculations. + */ namespace RegionUtils { /** - * When given a domain delimited by givenRegionBegin and givenRegionEnd + * @brief When given a domain delimited by givenRegionBegin and givenRegionEnd * and a DimensionType, and a requested regionWidth, this function * returns a cropped box from the domain. This box is of size regionWidth * in the dimension specified, and the size of the domain otherwise. @@ -23,31 +30,52 @@ namespace RegionUtils { * returns a box, which would contain every particle that is within 3 * units from the +x boundary wall, in the original domain * demarcated by givenRegion{begin,end}. + * + * @param givenRegionBegin the start of the region to be cropped + * @param givenRegionEnd the end of the region to be cropped + * @param dimension the dimension which is cropped i.e. the resulting slab will be regionWidth wide in this dimension, + * and unchanged otherwise. + * @param regionWidth the width of the slab + * @return std::tuple, std::array> the corners of the resultant slab inside the given + * region */ std::tuple, std::array> getInnerRegionSlab( const std::array &givenRegionBegin, const std::array &givenRegionEnd, DimensionUtils::DimensionType dimension, double regionWidth); /** - * Checks if a given molecule is leaving the given region in the next timestep, + * @brief Checks if a given molecule is leaving the given region in the next timestep, * with added scalar velocity adjustment, but only in the given dimension. * * The molecule's position and velocity in the specified dimension is extracted * from the molecule itself, and the next position is calculated using the * velocity adjustment and the timestep length. * + * If the molecule was already out of the box (and stay out of the box after position adjustment), this function returns + * true. If the molecule somehow ends up entering the box after the position adjustment, the function returns false. + * * When this function is called, it is usually expected that the forces have * been updated for the current timestep and the positions and velocities * aren't. Hence the nextStepVelAdjustment is provided to the caller function, * so that it can handle the change in velocity due to forces. This is not done * by the util function itself, to keep it as generic as possible. + * + * @param molecule the molecule to be checked + * @param regionBegin the start of the region to be checked + * @param regionEnd the end of the region to be checked + * @param dimension the dimension in which the molecule's new position must be calculated, to check for leaving + * @param timestepLength the length of the whole time step, after which the molecule's position is calculated + * @param nextStepVelAdjustment a flat scalar velocity added to the velocity in the `dimension` component after + * calculations + * @return true if the molecule would leave the box after timestepLength + * @return false if the molecule would not leave the box after timestepLength */ bool isMoleculeLeaving(const Molecule &molecule, const std::array ®ionBegin, const std::array ®ionEnd, DimensionUtils::DimensionType dimension, double timestepLength, double nextStepVelAdjustment); /** - * When given a domain delimited by givenRegionBegin and givenRegionEnd + * @brief When given a domain delimited by givenRegionBegin and givenRegionEnd * and a DimensionType, and a requested regionWidth, this function * returns a box outside the domain. This box is of size regionWidth * in the dimension specified, and the size of the domain plus regionwidth @@ -56,6 +84,13 @@ bool isMoleculeLeaving(const Molecule &molecule, const std::array &re * E.g. if the dimension given is +x, and the regionWidth is 3, this function * returns a box, which contains every ghost particle that is 3 units away * from +x. + * + * @param givenRegionBegin the start of the region under consideration + * @param givenRegionEnd the end of the region under consideration + * @param dimension the dimension in which the box should be sharing a wall with the givenRegion + * @param regionWidth the width of the slab + * @return std::tuple, std::array> the corners of the resultant region outside the + * given region */ std::tuple, std::array> getOuterRegionSlab( const std::array &givenRegionBegin, const std::array &givenRegionEnd, diff --git a/src/utils/Math.h b/src/utils/Math.h index e28b38ede4..7ba96efe5e 100644 --- a/src/utils/Math.h +++ b/src/utils/Math.h @@ -10,6 +10,7 @@ #include #include +#include template struct square From b311f23f9709a61b56cd9fd86e54715bebe553f6 Mon Sep 17 00:00:00 2001 From: amartyads Date: Thu, 19 Sep 2024 18:58:53 +0200 Subject: [PATCH 85/94] better error messages, format and docstring plugin --- src/parallel/boundaries/BoundaryHandler.cpp | 12 +- src/parallel/boundaries/BoundaryUtils.cpp | 3 +- src/parallel/boundaries/DimensionUtils.cpp | 6 +- src/parallel/boundaries/RegionUtils.cpp | 4 +- src/plugins/MamicoCoupling.cpp | 55 ++--- src/plugins/MamicoCoupling.h | 219 +++++++++----------- 6 files changed, 134 insertions(+), 165 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 33b8462168..3b422cf817 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -27,7 +27,8 @@ void BoundaryHandler::setGlobalWallType(DimensionUtils::DimensionType dimension, if (dimension != DimensionUtils::DimensionType::ERROR) _boundaries[dimension] = value; else { - Log::global_log->error() << "DimensionType::ERROR received in setGlobalWallType!!" << std::endl; + Log::global_log->error() << "DimensionType::ERROR received in BoundaryHandler::setGlobalWallType!!" + << std::endl; mardyn_exit(1); } } @@ -128,7 +129,8 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer *molec break; } default: - Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + Log::global_log->error() + << "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!" << std::endl; mardyn_exit(1); } } @@ -165,11 +167,9 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer *moleculeContaine break; } default: - Log::global_log->error() << "Boundary type error! Received type not allowed!" << std::endl; + Log::global_log->error() << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!" + << std::endl; mardyn_exit(1); } } -#ifndef MARDYN_AUTOPAS - moleculeContainer->updateBoundaryAndHaloMoleculeCaches(); -#endif } diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 20fd3fa4a7..f578cc1a48 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -40,8 +40,7 @@ std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { case BoundaryType::OUTFLOW: return "outflow"; default: - Log::global_log->error() << "Invalid boundary type passed to " - "BoundaryUtils::convertBoundaryToString. Check your input file!" + Log::global_log->error() << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!" << std::endl; mardyn_exit(1); } diff --git a/src/parallel/boundaries/DimensionUtils.cpp b/src/parallel/boundaries/DimensionUtils.cpp index fe08228599..f2e5373250 100644 --- a/src/parallel/boundaries/DimensionUtils.cpp +++ b/src/parallel/boundaries/DimensionUtils.cpp @@ -66,7 +66,8 @@ std::string DimensionUtils::convertDimensionToString(DimensionType dimension) { case DimensionType::NEGZ: return "-z"; default: // ERROR - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!" + << std::endl; mardyn_exit(1); return "error"; } @@ -91,7 +92,8 @@ int DimensionUtils::convertDimensionToNumeric(DimensionType dimension) { case DimensionType::NEGZ: return -3; default: - Log::global_log->error() << "Invalid dimension passed for enum conversion" << std::endl; + Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!" + << std::endl; mardyn_exit(1); return 0; } diff --git a/src/parallel/boundaries/RegionUtils.cpp b/src/parallel/boundaries/RegionUtils.cpp index a5fd693df2..d77a5f32e4 100644 --- a/src/parallel/boundaries/RegionUtils.cpp +++ b/src/parallel/boundaries/RegionUtils.cpp @@ -39,7 +39,7 @@ std::tuple, std::array> RegionUtils::getInnerRe break; default: - Log::global_log->error() << "Invalid dimension passed for inner buffer calculation\n"; + Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl; mardyn_exit(1); } return {returnRegionBegin, returnRegionEnd}; @@ -106,7 +106,7 @@ std::tuple, std::array> RegionUtils::getOuterRe break; default: - Log::global_log->error() << "Invalid dimension passed for inner buffer calculation" << std::endl; + Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl; mardyn_exit(1); } return std::make_tuple(returnRegionBegin, returnRegionEnd); diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index 1181ac7120..c652a16be4 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -3,47 +3,30 @@ #include "MamicoCoupling.h" #include "Domain.h" -void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) {} - -void MamicoCoupling::init(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain) { - Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; +void MamicoCoupling::init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) { + Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; } -void MamicoCoupling::beforeEventNewTimestep( - ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, - unsigned long simstep) {} - -void MamicoCoupling::beforeForces(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, - unsigned long simstep) { - if (_couplingEnabled) { - // This object should be set by MaMiCo after the plugins are created in the - // simulation readxml file Even though this method is called before the - // object is set, at this point the coupling switch is always off - _couplingCellService->processInnerCouplingCellAfterMDTimestep(); - _couplingCellService->distributeMass(simstep); - _couplingCellService->applyTemperatureToMolecules(simstep); +void MamicoCoupling::beforeForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, + unsigned long simstep) { + if (_couplingEnabled) { + // This object should be set by MaMiCo after the plugins are created in the simulation readxml file. + // Even though this method is called before the object is set, at this point the coupling switch is always off + _couplingCellService->processInnerCouplingCellAfterMDTimestep(); + _couplingCellService->distributeMass(simstep); + _couplingCellService->applyTemperatureToMolecules(simstep); #ifndef MARDYN_AUTOPAS - particleContainer->deleteOuterParticles(); + particleContainer->deleteOuterParticles(); #endif - } + } } -void MamicoCoupling::afterForces(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, - unsigned long simstep) { - if (_couplingEnabled) { - _couplingCellService->distributeMomentum(simstep); - _couplingCellService->applyBoundaryForce(simstep); - } +void MamicoCoupling::afterForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, + unsigned long simstep) { + if (_couplingEnabled) { + _couplingCellService->distributeMomentum(simstep); + _couplingCellService->applyBoundaryForce(simstep); + } } -void MamicoCoupling::endStep(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain, - unsigned long simstep) {} - -void MamicoCoupling::finish(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain) {} - -#endif +#endif // MAMICO_COUPLING diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index 12195b295e..3523f75190 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -2,133 +2,118 @@ #pragma once -#include "PluginBase.h" #include #include +#include "PluginBase.h" /** - * Allows execution of MaMiCo code to enable coupling with MaMiCo. + * @brief Allows execution of MaMiCo code to enable coupling with MaMiCo. + * @author Amartya Das Sharma + * + * When MaMiCo is coupled with any simulation software, it needs to control the simulation from both the outside and + * inside. From the outside, MaMiCo needs to be able to start and stop the simulation, and keep unique simulations + * distinct. From the inside, MaMiCo code needs to be executed at specific points within the same simulation step. This + * plugin enables the "inside" behaviour. * - * When MaMiCo is coupled with any simulation software, it needs to control the - * simulation from both the outside and inside. From the outside, MaMiCo needs - * to be able to start and stop the simulation, and keep unique simulations - * distinct. From the inside, MaMiCo code needs to be executed at specific - * points within the same simulation step. This plugin enables the "inside" - * behaviour. + * MaMiCo coupling requires the MAMICO_COUPLING flag to be set, and the MAMICO_SRD_DIR flag to point to MaMiCo source + * files. With these enabled, ls1 compiles as a library. To make sure the program compiles and works with tests, the + * relevant MaMiCo portions for the code are put in #ifdef regions. * - * MaMiCo coupling requires the MAMICO_COUPLING flag to be set, and the - * MAMICO_SRD_DIR flag to point to MaMiCo source files. With these enabled, ls1 - * compiles as a library. To make sure the program compiles and works with - * tests, the relevant MaMiCo portions for the code are put in #ifdef regions. + * \code{.xml} + * + * + * \endcode */ class MamicoCoupling : public PluginBase { - public: - MamicoCoupling() = default; - ~MamicoCoupling() override = default; - - void init(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain) override; - - /* - * No XML tags defined for this plugin, so does nothing - */ - void readXML(XMLfileUnits &xmlconfig) override; - - void beforeEventNewTimestep(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, - unsigned long simstep) override; - - /** - * Takes coupling steps such as particle insertion, to make sure they are - * accounted for before forces are calculated. - * - * Following steps are taken, if coupling is switched on: - * - Iterate over cells to average values like momentum and mass, to pass to - * macroscopic solvers - * - Distribute incoming mass from macroscopic solver by inserting perticles - * (if enabled) - * - Run the MaMiCo thermostat cell by cell - * - * The distributeMass method calls the - * updateParticleContainerAndDecomposition() function at the end, so we end up - * with a container with halo particles present. Hence a manual halo clearance - * is done to restore the state of the container. - */ - void beforeForces(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, - unsigned long simstep) override; - - /** - * Performs adjustments after force calculation - * - * Following steps are taken, if coupling is switched on: - * - Distribute incoming momentum among affected cells - * - Apply boundary force to molecules near microscopic domain boundary - */ - void afterForces(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, - unsigned long simstep) override; - - void endStep(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain, - unsigned long simstep) override; - - void finish(ParticleContainer *particleContainer, - DomainDecompBase *domainDecomp, Domain *domain) override; - - std::string getPluginName() override { return "MamicoCoupling"; } - - static PluginBase *createInstance() { return new MamicoCoupling(); } - - /** - * Sets the macroscopicCellService object that controls the inner coupling - * logic. - * - * MaMiCo extracts the MamicoCoupling plugin object from the simulation object - * after initialization and uses this function to set the - * macroscopicCellCervice. The code for this object can be found in - * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/CouplingCellService.cpph - */ - void setMamicoCouplingCellService( - coupling::services::CouplingCellService<3> *couplingCellService) { - _couplingCellService = - static_cast *>(couplingCellService); - } - - /** - * Enables coupling logic, allowing coupling steps to run while simulation is - * running. - * - * Set from within MaMiCo, check - * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, - * class LS1MDSimulation - */ - void switchOnCoupling() { _couplingEnabled = true; } - - /** - * Disables coupling logic, not allowing coupling steps to run. Typically done - * when equilibrating the simulation initially. - * - * Set from within MaMiCo, check - * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, - * class LS1MDSimulation - */ - void switchOffCoupling() { _couplingEnabled = false; } - - /** - * Getter method for the coupling state. - * - * Not used currently, but may be used in future - */ - bool getCouplingState() const { return _couplingEnabled; } + MamicoCoupling() = default; + ~MamicoCoupling() override = default; + + void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override; + + /** + * No XML tags defined for this plugin, so does nothing + */ + void readXML(XMLfileUnits &) {} + + void beforeEventNewTimestep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, + unsigned long simstep) {} + + /** + * @brief Takes coupling steps such as particle insertion, to make sure they are + * accounted for before forces are calculated. + * + * Following steps are taken, if coupling is switched on: + * - Iterate over cells to average values like momentum and mass, to pass to macroscopic solvers + * - Distribute incoming mass from macroscopic solver by inserting perticles (if enabled) + * - Run the MaMiCo thermostat cell by cell + * + * The distributeMass method calls the updateParticleContainerAndDecomposition() function at the end, so we end up + * with a container with halo particles present. Hence a manual halo clearance is done to restore the state of the + * container. + */ + void beforeForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, + unsigned long simstep) override; + + /** + * @brief Performs adjustments after force calculation + * + * Following steps are taken, if coupling is switched on: + * - Distribute incoming momentum among affected cells + * - Apply boundary force to molecules near microscopic domain boundary + */ + void afterForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, + unsigned long simstep) override; + + void endStep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain, + unsigned long simstep) {} + + void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) {} + + std::string getPluginName() override { return "MamicoCoupling"; } + + static PluginBase *createInstance() { return new MamicoCoupling(); } + + /** + * @brief Sets the macroscopicCellService object that controls the inner coupling logic. + * + * MaMiCo extracts the MamicoCoupling plugin object from the simulation object after initialization and uses this function to set the macroscopicCellCervice. + * + * The code for this object can be found in https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/CouplingCellService.cpph + */ + void setMamicoCouplingCellService(coupling::services::CouplingCellService<3> *couplingCellService) { + _couplingCellService = + static_cast *>(couplingCellService); + } + + /** + * @brief Enables coupling logic, allowing coupling steps to run while simulation is running. + * + * Set from within MaMiCo, check + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, class LS1MDSimulation + */ + void switchOnCoupling() { _couplingEnabled = true; } + + /** + * @brief Disables coupling logic, not allowing coupling steps to run. Typically done + * when equilibrating the simulation initially. + * + * Set from within MaMiCo, check + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, + * class LS1MDSimulation + */ + void switchOffCoupling() { _couplingEnabled = false; } + + /** + * @brief Getter method for the coupling state. + * + * Not used currently, but may be used in future + */ + bool getCouplingState() const { return _couplingEnabled; } private: - coupling::services::CouplingCellServiceImpl - *_couplingCellService = nullptr; - - bool _couplingEnabled = false; + coupling::services::CouplingCellServiceImpl *_couplingCellService = nullptr; + bool _couplingEnabled = false; }; -#endif +#endif // MAMICO_COUPLING From e625661e19b8a76c20d207e9443891131e20af66 Mon Sep 17 00:00:00 2001 From: amartyads Date: Thu, 19 Sep 2024 19:05:31 +0200 Subject: [PATCH 86/94] removed unised vars, clangformat --- src/plugins/MamicoCoupling.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index 3523f75190..1512edb15c 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -36,8 +36,7 @@ class MamicoCoupling : public PluginBase { */ void readXML(XMLfileUnits &) {} - void beforeEventNewTimestep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, - unsigned long simstep) {} + void beforeEventNewTimestep(ParticleContainer *, DomainDecompBase *, unsigned long) {} /** * @brief Takes coupling steps such as particle insertion, to make sure they are @@ -65,10 +64,9 @@ class MamicoCoupling : public PluginBase { void afterForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) override; - void endStep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain, - unsigned long simstep) {} + void endStep(ParticleContainer *, DomainDecompBase *, Domain *, unsigned long) {} - void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) {} + void finish(ParticleContainer *, DomainDecompBase *, Domain *) {} std::string getPluginName() override { return "MamicoCoupling"; } @@ -77,9 +75,11 @@ class MamicoCoupling : public PluginBase { /** * @brief Sets the macroscopicCellService object that controls the inner coupling logic. * - * MaMiCo extracts the MamicoCoupling plugin object from the simulation object after initialization and uses this function to set the macroscopicCellCervice. - * - * The code for this object can be found in https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/CouplingCellService.cpph + * MaMiCo extracts the MamicoCoupling plugin object from the simulation object after initialization and uses this + * function to set the macroscopicCellCervice. + * + * The code for this object can be found in + * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/CouplingCellService.cpph */ void setMamicoCouplingCellService(coupling::services::CouplingCellService<3> *couplingCellService) { _couplingCellService = @@ -89,7 +89,7 @@ class MamicoCoupling : public PluginBase { /** * @brief Enables coupling logic, allowing coupling steps to run while simulation is running. * - * Set from within MaMiCo, check + * Set from within MaMiCo, check * https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, class LS1MDSimulation */ void switchOnCoupling() { _couplingEnabled = true; } From 76d5191039ef41ea75a0aec475b98f719a25586a Mon Sep 17 00:00:00 2001 From: HomesGH <55833544+HomesGH@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:48:32 +0200 Subject: [PATCH 87/94] Add const to getters and add some doc --- src/Domain.h | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Domain.h b/src/Domain.h index faabdca061..237889919e 100644 --- a/src/Domain.h +++ b/src/Domain.h @@ -140,7 +140,7 @@ class Domain { unsigned getNumFluidComponents(); //! @brief get the fluid and fluid-solid potential of the local process - double getLocalUpotCompSpecific(); + double getLocalUpotCompSpecific() const; //! @brief set the virial of the local process void setLocalVirial(double Virial); @@ -149,12 +149,12 @@ class Domain { double getLocalVirial() const; //! @brief get thermostat scaling for translations - double getGlobalBetaTrans(); - double getGlobalBetaTrans(int thermostat); + double getGlobalBetaTrans() const; + double getGlobalBetaTrans(int thermostat) const; //! @brief get thermostat scaling for rotations - double getGlobalBetaRot(); - double getGlobalBetaRot(int thermostat); + double getGlobalBetaRot() const; + double getGlobalBetaRot(int thermostat) const; //! @brief return the length of the domain //! @@ -168,9 +168,9 @@ class Domain { void setGlobalLength(int index, double length); //! @brief get the global temperature for the whole system (i.e. thermostat ID 0) - double getGlobalCurrentTemperature() { return getCurrentTemperature(0); } - double getCurrentTemperature(int thermostatID) { return _globalTemperatureMap[thermostatID]; } - double getTargetTemperature(int thermostatID) { return _universalTargetTemperature[thermostatID]; } + double getGlobalCurrentTemperature() const { return getCurrentTemperature(0); } + double getCurrentTemperature(int thermostatID) const { return _globalTemperatureMap[thermostatID]; } + double getTargetTemperature(int thermostatID) const { return _universalTargetTemperature[thermostatID]; } //! @brief set the global temperature void setGlobalTemperature(double T) { setTargetTemperature(0, T); } @@ -208,24 +208,26 @@ class Domain { void updateMaxMoleculeID(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp); //! @brief get the global pressure - double getGlobalPressure(); + double getGlobalPressure() const; //! @brief get the global average potential per particle //! //! Before this method is called, it has to be sure that the //! global potential has been calculated (method calculateGlobalValues) - double getAverageGlobalUpot(); + double getAverageGlobalUpot() const; double getGlobalUpot() const; //! by Stefan Becker: return the average global potential of the fluid-fluid and fluid-solid interaction (but NOT solid-solid interaction) - double getAverageGlobalUpotCSpec(); + double getAverageGlobalUpotCSpec() const; //! @brief get the global kinetic energy //! - //! Before this method is called, it has to be sure that the - //! global energies has been calculated (method calculateGlobalValues) - double getGlobalUkinTrans() { return 0.5*_globalsummv2; } - double getGlobalUkinRot() { return 0.5*_globalsumIw2; } + //! Before this method is called, the user has to be sure that the + //! global energy (rot and trans) has been calculated via calculateGlobalValues() + //! Since variables _globalsummv2 and _globalsumIw2 store the sum of m_i*(v_i^2). + //! Therefore, the constant factor 0.5 has to be applied to yield the kinetic energies + double getGlobalUkinTrans() const { return 0.5*_globalsummv2; } + double getGlobalUkinRot() const { return 0.5*_globalsumIw2; } //! by Stefan Becker: determine and return the totel number of fluid molecules //! this method assumes all molecules with a component-ID less than _numFluidComponent to be fluid molecules @@ -235,7 +237,7 @@ class Domain { //! //! Before this method is called, it has to be sure that the //! global virial has been calculated (method calculateGlobalValues) - double getAverageGlobalVirial(); + double getAverageGlobalVirial() const; //! @brief sets _localSummv2 to the given value void setLocalSummv2(double summv2, int thermostat); @@ -250,13 +252,13 @@ class Domain { } //! @brief get globalRho - double getglobalRho(); + double getglobalRho() const; //! @brief set globalRho void setglobalRho(double grho); //! @brief get globalRotDOF - unsigned long getglobalRotDOF(); + unsigned long getglobalRotDOF() const; //! @brief set globalRotDOF void setglobalRotDOF(unsigned long grotdof); @@ -329,7 +331,7 @@ class Domain { //! It should be obvious that this method only returns sensible values //! for thermostats marked as "undirected", because otherwise the //! directed velocity is not explicitly computed. - double getThermostatDirectedVelocity(int thermostat, int d) { return this->_universalThermostatDirectedVelocity[thermostat][d]; } + double getThermostatDirectedVelocity(int thermostat, int d) const { return this->_universalThermostatDirectedVelocity[thermostat][d]; } //! @brief returns whether there are several distinct thermostats in the system bool severalThermostats() { return this->_componentwiseThermostat; } @@ -386,9 +388,9 @@ class Domain { // by Stefan Becker /* method returning the sigma parameter of a component => needed in the output of the MmspdWriter (specifying the particles' radii in a movie) */ - double getSigma(unsigned cid, unsigned nthSigma); + double getSigma(unsigned cid, unsigned nthSigma) const; // needed for the MmspdWriter (MegaMol) - unsigned getNumberOfComponents(); + unsigned getNumberOfComponents() const; void setUpotCorr(double upotcorr){ _UpotCorr = upotcorr; } void setVirialCorr(double virialcorr){ _VirialCorr = virialcorr; } From e38f4c7e1dcbe360019b3babd21f5e1c0fcac728 Mon Sep 17 00:00:00 2001 From: HomesGH <55833544+HomesGH@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:53:13 +0200 Subject: [PATCH 88/94] Apply suggestions from review to ResultWriter.cpp --- src/io/ResultWriter.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/io/ResultWriter.cpp b/src/io/ResultWriter.cpp index 543d715593..7361191119 100644 --- a/src/io/ResultWriter.cpp +++ b/src/io/ResultWriter.cpp @@ -15,7 +15,7 @@ void ResultWriter::readXML(XMLfileUnits& xmlconfig) { Log::global_log->info() << "[ResultWriter] Write frequency: " << _writeFrequency << std::endl; if (_writeFrequency <= 0) { Log::global_log->error() << "[ResultWriter] Write frequency must be a positive nonzero integer, but is " << _writeFrequency << std::endl; - mardyn_exit(123); + mardyn_exit(13831); } xmlconfig.getNodeValue("outputprefix", _outputPrefix); @@ -66,9 +66,8 @@ void ResultWriter::endStep(ParticleContainer *particleContainer, DomainDecompBas // Writing of cavities now handled by CavityWriter - unsigned long globalNumMolecules = domain->getglobalNumMolecules(true, particleContainer, domainDecomp); - double cv = domain->cv(); - double ekin = domain->getGlobalUkinTrans()+domain->getGlobalUkinRot(); + const unsigned long globalNumMolecules = domain->getglobalNumMolecules(true, particleContainer, domainDecomp); + const double ekin = domain->getGlobalUkinTrans()+domain->getGlobalUkinRot(); _U_pot_acc->addEntry(domain->getGlobalUpot()); _U_kin_acc->addEntry(ekin); @@ -90,7 +89,7 @@ void ResultWriter::endStep(ParticleContainer *particleContainer, DomainDecompBas printOutput(_p_acc->getAverage()); printOutput(domain->getGlobalBetaTrans()); printOutput(domain->getGlobalBetaRot()); - printOutput(cv); + printOutput(domain->cv()); printOutput(globalNumMolecules); resultStream << std::endl; resultStream.close(); From 741885fac0d63d70f880c3a91ca1f879d0751905 Mon Sep 17 00:00:00 2001 From: HomesGH <55833544+HomesGH@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:15:52 +0200 Subject: [PATCH 89/94] Minor fixes regarding const in Domain --- src/Domain.cpp | 18 +++++++++--------- src/Domain.h | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Domain.cpp b/src/Domain.cpp index e02fd03fde..15cfc49a76 100644 --- a/src/Domain.cpp +++ b/src/Domain.cpp @@ -142,9 +142,9 @@ double Domain::getGlobalPressure() return globalTemperature * _globalRho + _globalRho * getAverageGlobalVirial()/3.; } -double Domain::getAverageGlobalVirial() { return _globalVirial/_globalNumMolecules; } +double Domain::getAverageGlobalVirial() const { return _globalVirial/_globalNumMolecules; } -double Domain::getAverageGlobalUpot() { return getGlobalUpot()/_globalNumMolecules; } +double Domain::getAverageGlobalUpot() const { return getGlobalUpot()/_globalNumMolecules; } double Domain::getGlobalUpot() const { return _globalUpot; } Comp2Param& Domain::getComp2Params(){ @@ -786,9 +786,9 @@ void Domain::updateMaxMoleculeID(ParticleContainer* particleContainer, DomainDec #endif } -double Domain::getglobalRho(){ return _globalRho;} +double Domain::getglobalRho() const { return _globalRho;} -void Domain::setglobalRho(double grho){ _globalRho = grho;} +void Domain::setglobalRho(double grho) { _globalRho = grho;} unsigned long Domain::getglobalRotDOF() { @@ -827,10 +827,10 @@ double Domain::cv() //! methods implemented by Stefan Becker // the following two methods are used by the MmspdWriter (writing the output file in a format used by MegaMol) -double Domain::getSigma(unsigned cid, unsigned nthSigma){ +double Domain::getSigma(unsigned cid, unsigned nthSigma) const { return _simulation.getEnsemble()->getComponent(cid)->getSigma(nthSigma); } -unsigned Domain::getNumberOfComponents(){ +unsigned Domain::getNumberOfComponents() const { return _simulation.getEnsemble()->getComponents()->size(); } @@ -858,10 +858,10 @@ void Domain::submitDU(unsigned /*cid*/, double DU, double* r) void Domain::setLocalUpotCompSpecific(double UpotCspec){_localUpotCspecif = UpotCspec;} - double Domain::getLocalUpotCompSpecific(){return _localUpotCspecif;} + double Domain::getLocalUpotCompSpecific() const {return _localUpotCspecif;} -double Domain::getAverageGlobalUpotCSpec() { +double Domain::getAverageGlobalUpotCSpec() const { Log::global_log->debug() << "number of fluid molecules = " << getNumFluidMolecules() << "\n"; return _globalUpotCspecif / getNumFluidMolecules(); } @@ -871,7 +871,7 @@ void Domain::setNumFluidComponents(unsigned nc){_numFluidComponent = nc;} unsigned Domain::getNumFluidComponents(){return _numFluidComponent;} -unsigned long Domain::getNumFluidMolecules(){ +unsigned long Domain::getNumFluidMolecules() const { unsigned long numFluidMolecules = 0; for(unsigned i = 0; i < _numFluidComponent; i++){ Component& ci=*(global_simulation->getEnsemble()->getComponent(i)); diff --git a/src/Domain.h b/src/Domain.h index 237889919e..cabc179377 100644 --- a/src/Domain.h +++ b/src/Domain.h @@ -149,12 +149,12 @@ class Domain { double getLocalVirial() const; //! @brief get thermostat scaling for translations - double getGlobalBetaTrans() const; - double getGlobalBetaTrans(int thermostat) const; + double getGlobalBetaTrans(); + double getGlobalBetaTrans(int thermostat); //! @brief get thermostat scaling for rotations - double getGlobalBetaRot() const; - double getGlobalBetaRot(int thermostat) const; + double getGlobalBetaRot(); + double getGlobalBetaRot(int thermostat); //! @brief return the length of the domain //! @@ -168,9 +168,9 @@ class Domain { void setGlobalLength(int index, double length); //! @brief get the global temperature for the whole system (i.e. thermostat ID 0) - double getGlobalCurrentTemperature() const { return getCurrentTemperature(0); } - double getCurrentTemperature(int thermostatID) const { return _globalTemperatureMap[thermostatID]; } - double getTargetTemperature(int thermostatID) const { return _universalTargetTemperature[thermostatID]; } + double getGlobalCurrentTemperature() { return getCurrentTemperature(0); } + double getCurrentTemperature(int thermostatID) { return _globalTemperatureMap[thermostatID]; } + double getTargetTemperature(int thermostatID) { return _universalTargetTemperature[thermostatID]; } //! @brief set the global temperature void setGlobalTemperature(double T) { setTargetTemperature(0, T); } @@ -208,7 +208,7 @@ class Domain { void updateMaxMoleculeID(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp); //! @brief get the global pressure - double getGlobalPressure() const; + double getGlobalPressure(); //! @brief get the global average potential per particle //! @@ -231,7 +231,7 @@ class Domain { //! by Stefan Becker: determine and return the totel number of fluid molecules //! this method assumes all molecules with a component-ID less than _numFluidComponent to be fluid molecules - unsigned long getNumFluidMolecules(); + unsigned long getNumFluidMolecules() const; //! @brief get the global average virial per particle //! @@ -258,7 +258,7 @@ class Domain { void setglobalRho(double grho); //! @brief get globalRotDOF - unsigned long getglobalRotDOF() const; + unsigned long getglobalRotDOF(); //! @brief set globalRotDOF void setglobalRotDOF(unsigned long grotdof); @@ -331,7 +331,7 @@ class Domain { //! It should be obvious that this method only returns sensible values //! for thermostats marked as "undirected", because otherwise the //! directed velocity is not explicitly computed. - double getThermostatDirectedVelocity(int thermostat, int d) const { return this->_universalThermostatDirectedVelocity[thermostat][d]; } + double getThermostatDirectedVelocity(int thermostat, int d) { return this->_universalThermostatDirectedVelocity[thermostat][d]; } //! @brief returns whether there are several distinct thermostats in the system bool severalThermostats() { return this->_componentwiseThermostat; } From 570edcec2a3f6a91fe827ea24adb0e4f82a2451c Mon Sep 17 00:00:00 2001 From: amartyads Date: Fri, 20 Sep 2024 14:18:49 +0200 Subject: [PATCH 90/94] align switch cases --- src/parallel/boundaries/BoundaryHandler.cpp | 134 ++++++++++---------- src/parallel/boundaries/BoundaryUtils.cpp | 20 +-- src/parallel/boundaries/DimensionUtils.cpp | 108 ++++++++-------- src/parallel/boundaries/RegionUtils.cpp | 92 +++++++------- 4 files changed, 178 insertions(+), 176 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index 3b422cf817..a88ccd36b9 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -86,52 +86,54 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer *molec continue; switch (getGlobalWallType(currentDim)) { - case BoundaryUtils::BoundaryType::PERIODIC: - // nothing changes from normal ls1 behaviour, so leaving particles not touched by BoundaryHandler and are - // processed by DomainDecompBase::handleDomainLeavingParticles() - break; - - case BoundaryUtils::BoundaryType::OUTFLOW: - [[fallthrough]]; - case BoundaryUtils::BoundaryType::REFLECTING: { - // create region by using getInnerRegionSlab() - const auto [curWallRegionBegin, curWallRegionEnd] = - RegionUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, currentDim, cutoff); - // grab an iterator from the converted coords - const auto particlesInRegion = moleculeContainer->regionIterator( - curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ONLY_INNER_AND_BOUNDARY); - - // iterate through all molecules - for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { - // Calculate the change in velocity, which the leapfrog method will - // apply in the next velocity update to the dimension of interest. - const int currentDimInt = DimensionUtils::convertEnumToLS1DimIndex(currentDim); - const double halfTimestep = .5 * timestepLength; - const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); - const double force = moleculeIter->F(currentDimInt); - const double nextStepVelAdjustment = halfTimestepByMass * force; - - // check if the molecule would leave the bounds - if (RegionUtils::isMoleculeLeaving(*moleculeIter, curWallRegionBegin, curWallRegionEnd, currentDim, - timestepLength, nextStepVelAdjustment)) { - if (getGlobalWallType(currentDim) == BoundaryUtils::BoundaryType::REFLECTING) { - const double currentVel = moleculeIter->v(currentDimInt); - // change the velocity in the dimension of interest such that when - // the leapfrog integrator adds nextStepVelAdjustment in the next - // velocity update, the final result ends up being the intended, - // reversed velocity: -(currentVel+nextStepVelAdjustment) - moleculeIter->setv(currentDimInt, -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); - } else { // outflow, delete the particle if it would leave - moleculeContainer->deleteMolecule(moleculeIter, false); + case BoundaryUtils::BoundaryType::PERIODIC: + // nothing changes from normal ls1 behaviour, so leaving particles not touched by BoundaryHandler and + // are processed by DomainDecompBase::handleDomainLeavingParticles() + break; + + case BoundaryUtils::BoundaryType::OUTFLOW: + [[fallthrough]]; + case BoundaryUtils::BoundaryType::REFLECTING: { + // create region by using getInnerRegionSlab() + const auto [curWallRegionBegin, curWallRegionEnd] = + RegionUtils::getInnerRegionSlab(_localRegionStart, _localRegionEnd, currentDim, cutoff); + // grab an iterator from the converted coords + const auto particlesInRegion = moleculeContainer->regionIterator( + curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ONLY_INNER_AND_BOUNDARY); + + // iterate through all molecules + for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { + // Calculate the change in velocity, which the leapfrog method will + // apply in the next velocity update to the dimension of interest. + const int currentDimInt = DimensionUtils::convertEnumToLS1DimIndex(currentDim); + const double halfTimestep = .5 * timestepLength; + const double halfTimestepByMass = halfTimestep / moleculeIter->mass(); + const double force = moleculeIter->F(currentDimInt); + const double nextStepVelAdjustment = halfTimestepByMass * force; + + // check if the molecule would leave the bounds + if (RegionUtils::isMoleculeLeaving(*moleculeIter, curWallRegionBegin, curWallRegionEnd, currentDim, + timestepLength, nextStepVelAdjustment)) { + if (getGlobalWallType(currentDim) == BoundaryUtils::BoundaryType::REFLECTING) { + const double currentVel = moleculeIter->v(currentDimInt); + // change the velocity in the dimension of interest such that when + // the leapfrog integrator adds nextStepVelAdjustment in the next + // velocity update, the final result ends up being the intended, + // reversed velocity: -(currentVel+nextStepVelAdjustment) + moleculeIter->setv(currentDimInt, + -currentVel - nextStepVelAdjustment - nextStepVelAdjustment); + } else { // outflow, delete the particle if it would leave + moleculeContainer->deleteMolecule(moleculeIter, false); + } } } + break; } - break; - } - default: - Log::global_log->error() - << "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!" << std::endl; - mardyn_exit(1); + default: + Log::global_log->error() + << "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!" + << std::endl; + mardyn_exit(1); } } } @@ -146,30 +148,30 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer *moleculeContaine continue; switch (getGlobalWallType(currentDim)) { - case BoundaryUtils::BoundaryType::PERIODIC: - // nothing changes from normal ls1 behaviour, so empty case, and halo particles left untouched - break; - - case BoundaryUtils::BoundaryType::OUTFLOW: - [[fallthrough]]; - case BoundaryUtils::BoundaryType::REFLECTING: { - // create region by using getOuterRegionSlab() - auto const [curWallRegionBegin, curWallRegionEnd] = - RegionUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, currentDim, haloWidths); - - // grab an iterator from the converted coords - auto particlesInRegion = moleculeContainer->regionIterator( - curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ALL_CELLS); - for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { - // delete all halo particles - moleculeContainer->deleteMolecule(moleculeIter, false); + case BoundaryUtils::BoundaryType::PERIODIC: + // nothing changes from normal ls1 behaviour, so empty case, and halo particles left untouched + break; + + case BoundaryUtils::BoundaryType::OUTFLOW: + [[fallthrough]]; + case BoundaryUtils::BoundaryType::REFLECTING: { + // create region by using getOuterRegionSlab() + auto const [curWallRegionBegin, curWallRegionEnd] = + RegionUtils::getOuterRegionSlab(_localRegionStart, _localRegionEnd, currentDim, haloWidths); + + // grab an iterator from the converted coords + auto particlesInRegion = moleculeContainer->regionIterator( + curWallRegionBegin.data(), curWallRegionEnd.data(), ParticleIterator::ALL_CELLS); + for (auto moleculeIter = particlesInRegion; moleculeIter.isValid(); ++moleculeIter) { + // delete all halo particles + moleculeContainer->deleteMolecule(moleculeIter, false); + } + break; } - break; - } - default: - Log::global_log->error() << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!" - << std::endl; - mardyn_exit(1); + default: + Log::global_log->error() << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!" + << std::endl; + mardyn_exit(1); } } } diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index f578cc1a48..4ac699e45e 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -33,16 +33,16 @@ BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::st std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { switch (boundary) { - case BoundaryType::PERIODIC: - return "periodic"; - case BoundaryType::REFLECTING: - return "reflecting"; - case BoundaryType::OUTFLOW: - return "outflow"; - default: - Log::global_log->error() << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!" - << std::endl; - mardyn_exit(1); + case BoundaryType::PERIODIC: + return "periodic"; + case BoundaryType::REFLECTING: + return "reflecting"; + case BoundaryType::OUTFLOW: + return "outflow"; + default: + Log::global_log->error() << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!" + << std::endl; + mardyn_exit(1); } return "error"; // warning suppression } diff --git a/src/parallel/boundaries/DimensionUtils.cpp b/src/parallel/boundaries/DimensionUtils.cpp index f2e5373250..2fda16e22d 100644 --- a/src/parallel/boundaries/DimensionUtils.cpp +++ b/src/parallel/boundaries/DimensionUtils.cpp @@ -22,54 +22,54 @@ DimensionUtils::DimensionType DimensionUtils::convertNumericToDimension(int dim) return DimensionType::ERROR; } switch (dim) { - case 1: - return DimensionType::POSX; - case 2: - return DimensionType::POSY; - case 3: - return DimensionType::POSZ; - case -1: - return DimensionType::NEGX; - case -2: - return DimensionType::NEGY; - case -3: - return DimensionType::NEGZ; + case 1: + return DimensionType::POSX; + case 2: + return DimensionType::POSY; + case 3: + return DimensionType::POSZ; + case -1: + return DimensionType::NEGX; + case -2: + return DimensionType::NEGY; + case -3: + return DimensionType::NEGZ; } return DimensionType::ERROR; // warning suppression } DimensionUtils::DimensionType DimensionUtils::convertLS1DimIndexToEnumPositive(int dim) { switch (dim) { - case 0: - return DimensionType::POSX; - case 1: - return DimensionType::POSY; - case 2: - return DimensionType::POSZ; - default: - return DimensionType::ERROR; + case 0: + return DimensionType::POSX; + case 1: + return DimensionType::POSY; + case 2: + return DimensionType::POSZ; + default: + return DimensionType::ERROR; } } std::string DimensionUtils::convertDimensionToString(DimensionType dimension) { switch (dimension) { - case DimensionType::POSX: - return "+x"; - case DimensionType::POSY: - return "+y"; - case DimensionType::POSZ: - return "+z"; - case DimensionType::NEGX: - return "-x"; - case DimensionType::NEGY: - return "-y"; - case DimensionType::NEGZ: - return "-z"; - default: // ERROR - Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!" - << std::endl; - mardyn_exit(1); - return "error"; + case DimensionType::POSX: + return "+x"; + case DimensionType::POSY: + return "+y"; + case DimensionType::POSZ: + return "+z"; + case DimensionType::NEGX: + return "-x"; + case DimensionType::NEGY: + return "-y"; + case DimensionType::NEGZ: + return "-z"; + default: // ERROR + Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!" + << std::endl; + mardyn_exit(1); + return "error"; } } @@ -79,23 +79,23 @@ std::string DimensionUtils::convertDimensionToStringAbs(DimensionType dimension) int DimensionUtils::convertDimensionToNumeric(DimensionType dimension) { switch (dimension) { - case DimensionType::POSX: - return 1; - case DimensionType::POSY: - return 2; - case DimensionType::POSZ: - return 3; - case DimensionType::NEGX: - return -1; - case DimensionType::NEGY: - return -2; - case DimensionType::NEGZ: - return -3; - default: - Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!" - << std::endl; - mardyn_exit(1); - return 0; + case DimensionType::POSX: + return 1; + case DimensionType::POSY: + return 2; + case DimensionType::POSZ: + return 3; + case DimensionType::NEGX: + return -1; + case DimensionType::NEGY: + return -2; + case DimensionType::NEGZ: + return -3; + default: + Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!" + << std::endl; + mardyn_exit(1); + return 0; } } diff --git a/src/parallel/boundaries/RegionUtils.cpp b/src/parallel/boundaries/RegionUtils.cpp index d77a5f32e4..3fb88616c6 100644 --- a/src/parallel/boundaries/RegionUtils.cpp +++ b/src/parallel/boundaries/RegionUtils.cpp @@ -17,30 +17,30 @@ std::tuple, std::array> RegionUtils::getInnerRe const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); switch (dimension) { - // in positive case, set the beginning to end-width, or whole domain if width - // too large - case DimensionUtils::DimensionType::POSX: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSY: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = - std::max(returnRegionEnd[dimensionLS1] - regionWidth, givenRegionBegin[dimensionLS1]); - break; - // in negative case, set the end to beginning+width, or whole domain if width - // too large - case DimensionUtils::DimensionType::NEGX: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGY: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = - std::min(returnRegionBegin[dimensionLS1] + regionWidth, givenRegionEnd[dimensionLS1]); - break; + // in positive case, set the beginning to end-width, or whole domain if width + // too large + case DimensionUtils::DimensionType::POSX: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSY: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = + std::max(returnRegionEnd[dimensionLS1] - regionWidth, givenRegionBegin[dimensionLS1]); + break; + // in negative case, set the end to beginning+width, or whole domain if width + // too large + case DimensionUtils::DimensionType::NEGX: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGY: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = + std::min(returnRegionBegin[dimensionLS1] + regionWidth, givenRegionEnd[dimensionLS1]); + break; - default: - Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl; - mardyn_exit(1); + default: + Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl; + mardyn_exit(1); } return {returnRegionBegin, returnRegionEnd}; } @@ -83,31 +83,31 @@ std::tuple, std::array> RegionUtils::getOuterRe returnRegionEnd[extraDim2] += regionWidth[extraDim2]; switch (dimension) { - // in positive case, move the box begin to edge of domain, and box end to - // beyond - case DimensionUtils::DimensionType::POSX: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSY: - [[fallthrough]]; - case DimensionUtils::DimensionType::POSZ: - returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; - returnRegionEnd[dimensionLS1] += regionWidth[dimensionLS1]; - break; + // in positive case, move the box begin to edge of domain, and box end to + // beyond + case DimensionUtils::DimensionType::POSX: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSY: + [[fallthrough]]; + case DimensionUtils::DimensionType::POSZ: + returnRegionBegin[dimensionLS1] = returnRegionEnd[dimensionLS1]; + returnRegionEnd[dimensionLS1] += regionWidth[dimensionLS1]; + break; - // in negative case, move the box end to edge of domain, and box begin to - // beyond - case DimensionUtils::DimensionType::NEGX: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGY: - [[fallthrough]]; - case DimensionUtils::DimensionType::NEGZ: - returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; - returnRegionBegin[dimensionLS1] -= regionWidth[dimensionLS1]; - break; + // in negative case, move the box end to edge of domain, and box begin to + // beyond + case DimensionUtils::DimensionType::NEGX: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGY: + [[fallthrough]]; + case DimensionUtils::DimensionType::NEGZ: + returnRegionEnd[dimensionLS1] = returnRegionBegin[dimensionLS1]; + returnRegionBegin[dimensionLS1] -= regionWidth[dimensionLS1]; + break; - default: - Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl; - mardyn_exit(1); + default: + Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl; + mardyn_exit(1); } return std::make_tuple(returnRegionBegin, returnRegionEnd); } From 8b6a5f67312cbcdd5a7644e9afbbdf3c9f62c972 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 23 Sep 2024 17:27:39 +0200 Subject: [PATCH 91/94] bugfix --- src/parallel/boundaries/BoundaryUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 4ac699e45e..985a560cd7 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -15,8 +15,8 @@ #include BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) { - std::string boundaryLowercase; - std::transform(boundary.begin(), boundary.end(), boundaryLowercase.begin(), + std::string boundaryLowercase(boundary); + std::transform(boundaryLowercase.begin(), boundaryLowercase.end(), boundaryLowercase.begin(), [](unsigned char c) { return std::tolower(c); }); if (boundaryLowercase.find("per") != std::string::npos) return BoundaryType::PERIODIC; From 2db952e0ebd87350f014fdf38da8433907d7b1f9 Mon Sep 17 00:00:00 2001 From: amartyads Date: Mon, 23 Sep 2024 17:38:06 +0200 Subject: [PATCH 92/94] some more documentation --- src/parallel/boundaries/BoundaryHandler.h | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.h b/src/parallel/boundaries/BoundaryHandler.h index f6860906a3..08bcea4945 100644 --- a/src/parallel/boundaries/BoundaryHandler.h +++ b/src/parallel/boundaries/BoundaryHandler.h @@ -21,20 +21,17 @@ * @brief Class to handle boundary conditions, namely leaving and halo particles. * @author Amartya Das Sharma * - * The objects of this class store the local and global bounds of the subdomain - * in every process, and provide functions to deal with leaving particles, and - * delete halo particles. + * The objects of this class store the local and global bounds of the subdomain in every process, and provide functions + * to deal with leaving particles, and delete halo particles. * - * The internal walls of the subdomain, touching other subdomains are 'local' - * walls while the walls that are also the limits of the global domain are - * 'global' walls. + * The internal walls of the subdomain, touching other subdomains are 'local' walls while the walls that are also the + * limits of the global domain are 'global' walls. * - * All subdomains have a copy of the global wall types, and do not store their local - * boundary conditions; instead they check whether a particular local wall is also a - * global wall, and then use the global lookup table to ascertain what boundary effects to use. + * All subdomains have a copy of the global wall types, and do not store their local boundary conditions; instead they + * check whether a particular local wall is also a global wall, and then use the global lookup table to ascertain what + * boundary effects to use. * * The default state for all global walls is 'PERIODIC', since that is the default ls1 behaviour. - * */ class BoundaryHandler { public: @@ -171,7 +168,12 @@ class BoundaryHandler { void removeNonPeriodicHalos(ParticleContainer *moleculeContainer) const; private: - /* List of global boundary type per dimension. */ + /** + * @brief Lookup table for global boundary type in every dimension. + * + * Set as periodic by default, since the default behaviour of LS1 is all periodic boundaries. + * This allows the tag to be optional. + */ std::map _boundaries{ {DimensionUtils::DimensionType::POSX, BoundaryUtils::BoundaryType::PERIODIC}, {DimensionUtils::DimensionType::POSY, BoundaryUtils::BoundaryType::PERIODIC}, From c0c55819163a5b09a4fb085f5a25c76fcb3d568e Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 22 Oct 2024 16:26:28 +0200 Subject: [PATCH 93/94] bugfix, particles actually being reflected now --- examples/simple-boundary-test/ls1config.xml | 4 ++-- src/parallel/boundaries/BoundaryHandler.cpp | 2 +- src/parallel/boundaries/RegionUtils.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/simple-boundary-test/ls1config.xml b/examples/simple-boundary-test/ls1config.xml index fb880faeaa..942e1a694b 100644 --- a/examples/simple-boundary-test/ls1config.xml +++ b/examples/simple-boundary-test/ls1config.xml @@ -57,10 +57,10 @@ - + particles.bp BP4 diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index a88ccd36b9..cc22f872b3 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -66,7 +66,7 @@ bool BoundaryHandler::hasGlobalInvalidBoundary() const { bool BoundaryHandler::hasGlobalNonPeriodicBoundary() const { return std::any_of(_boundaries.begin(), _boundaries.end(), [](const auto &keyVal) { const auto [dim, boundaryType] = keyVal; - return boundaryType == BoundaryUtils::BoundaryType::PERIODIC; + return boundaryType != BoundaryUtils::BoundaryType::PERIODIC; }); } diff --git a/src/parallel/boundaries/RegionUtils.cpp b/src/parallel/boundaries/RegionUtils.cpp index 3fb88616c6..d5a0715725 100644 --- a/src/parallel/boundaries/RegionUtils.cpp +++ b/src/parallel/boundaries/RegionUtils.cpp @@ -13,7 +13,7 @@ std::tuple, std::array> RegionUtils::getInnerRe DimensionUtils::DimensionType dimension, double regionWidth) { std::array returnRegionBegin = givenRegionBegin; - std::array returnRegionEnd = givenRegionBegin; + std::array returnRegionEnd = givenRegionEnd; const int dimensionLS1 = convertEnumToLS1DimIndex(dimension); switch (dimension) { From ed42fac282149901ea6a70e86030081efb58825b Mon Sep 17 00:00:00 2001 From: amartyads Date: Tue, 29 Oct 2024 13:50:23 +0100 Subject: [PATCH 94/94] static codechecker, MARDYN_EXIT --- src/parallel/boundaries/BoundaryHandler.cpp | 20 ++++++++++---------- src/parallel/boundaries/BoundaryUtils.cpp | 14 +++++++------- src/parallel/boundaries/DimensionUtils.cpp | 21 +++++++++++++-------- src/parallel/boundaries/DimensionUtils.h | 2 +- src/parallel/boundaries/RegionUtils.cpp | 14 +++++++++----- src/parallel/boundaries/RegionUtils.h | 2 +- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/parallel/boundaries/BoundaryHandler.cpp b/src/parallel/boundaries/BoundaryHandler.cpp index cc22f872b3..2b02d6029e 100644 --- a/src/parallel/boundaries/BoundaryHandler.cpp +++ b/src/parallel/boundaries/BoundaryHandler.cpp @@ -14,6 +14,7 @@ #include "utils/mardyn_assert.h" #include +#include // for ostringstream BoundaryUtils::BoundaryType BoundaryHandler::getGlobalWallType(DimensionUtils::DimensionType dimension) const { return _boundaries.at(dimension); @@ -27,9 +28,9 @@ void BoundaryHandler::setGlobalWallType(DimensionUtils::DimensionType dimension, if (dimension != DimensionUtils::DimensionType::ERROR) _boundaries[dimension] = value; else { - Log::global_log->error() << "DimensionType::ERROR received in BoundaryHandler::setGlobalWallType!!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "DimensionType::ERROR received in BoundaryHandler::setGlobalWallType!!" << std::endl; + MARDYN_EXIT(error_message.str()); } } @@ -130,10 +131,9 @@ void BoundaryHandler::processGlobalWallLeavingParticles(ParticleContainer *molec break; } default: - Log::global_log->error() - << "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "BoundaryType::ERROR received in BoundaryHandler::processGlobalWallLeavingParticles!" << std::endl; + MARDYN_EXIT(error_message.str()); } } } @@ -169,9 +169,9 @@ void BoundaryHandler::removeNonPeriodicHalos(ParticleContainer *moleculeContaine break; } default: - Log::global_log->error() << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "BoundaryType::ERROR received in BoundaryHandler::removeNonPeriodicHalos!" << std::endl; + MARDYN_EXIT(error_message.str()); } } } diff --git a/src/parallel/boundaries/BoundaryUtils.cpp b/src/parallel/boundaries/BoundaryUtils.cpp index 985a560cd7..747f39d2ae 100644 --- a/src/parallel/boundaries/BoundaryUtils.cpp +++ b/src/parallel/boundaries/BoundaryUtils.cpp @@ -13,6 +13,7 @@ #include #include #include +#include // for ostringstream BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::string &boundary) { std::string boundaryLowercase(boundary); @@ -24,10 +25,9 @@ BoundaryUtils::BoundaryType BoundaryUtils::convertStringToBoundary(const std::st return BoundaryType::REFLECTING; if (boundaryLowercase.find("out") != std::string::npos) return BoundaryType::OUTFLOW; - Log::global_log->error() << "Invalid boundary type passed to " - "BoundaryUtils::convertStringToBoundary. Check your input file!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "Invalid boundary type passed to BoundaryUtils::convertStringToBoundary. Check your input file!" << std::endl; + MARDYN_EXIT(error_message.str()); return BoundaryType::ERROR; // warning suppression } @@ -40,9 +40,9 @@ std::string BoundaryUtils::convertBoundaryToString(BoundaryType boundary) { case BoundaryType::OUTFLOW: return "outflow"; default: - Log::global_log->error() << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!" - << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "BoundaryType::ERROR received in BoundaryUtils::convertBoundaryToString!" << std::endl; + MARDYN_EXIT(error_message.str()); } return "error"; // warning suppression } diff --git a/src/parallel/boundaries/DimensionUtils.cpp b/src/parallel/boundaries/DimensionUtils.cpp index 2fda16e22d..9788512f1a 100644 --- a/src/parallel/boundaries/DimensionUtils.cpp +++ b/src/parallel/boundaries/DimensionUtils.cpp @@ -7,7 +7,9 @@ #include "DimensionUtils.h" #include "utils/Logger.h" -#include "utils/mardyn_assert.h" // for mardyn_exit() +#include "utils/mardyn_assert.h" // for MARDYN_EXIT() + +#include // for ostringstream bool DimensionUtils::isDimensionNumericPermissible(int dim) { // permissible dimensions are {-1, -2, -3, 1, 2, 3} @@ -16,9 +18,10 @@ bool DimensionUtils::isDimensionNumericPermissible(int dim) { DimensionUtils::DimensionType DimensionUtils::convertNumericToDimension(int dim) { if (!isDimensionNumericPermissible(dim)) { - Log::global_log->error() << "Invalid dimension passed for enum conversion. Received value: " << dim + std::ostringstream error_message; + error_message << "Invalid dimension passed for enum conversion. Received value: " << dim << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return DimensionType::ERROR; } switch (dim) { @@ -66,9 +69,10 @@ std::string DimensionUtils::convertDimensionToString(DimensionType dimension) { case DimensionType::NEGZ: return "-z"; default: // ERROR - Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!" + std::ostringstream error_message; + error_message << "DimesionType::ERROR received in DimensionUtils::convertDimensionToString!" << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return "error"; } } @@ -92,9 +96,10 @@ int DimensionUtils::convertDimensionToNumeric(DimensionType dimension) { case DimensionType::NEGZ: return -3; default: - Log::global_log->error() << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!" + std::ostringstream error_message; + error_message << "DimesionType::ERROR received in DimensionUtils::convertDimensionToNumeric!" << std::endl; - mardyn_exit(1); + MARDYN_EXIT(error_message.str()); return 0; } } @@ -105,4 +110,4 @@ int DimensionUtils::convertDimensionToNumericAbs(DimensionType dimension) { int DimensionUtils::convertEnumToLS1DimIndex(DimensionType dimension) { return convertDimensionToNumericAbs(dimension) - 1; -} \ No newline at end of file +} diff --git a/src/parallel/boundaries/DimensionUtils.h b/src/parallel/boundaries/DimensionUtils.h index 20cf7b3b22..2b6fb0ba0a 100644 --- a/src/parallel/boundaries/DimensionUtils.h +++ b/src/parallel/boundaries/DimensionUtils.h @@ -120,4 +120,4 @@ int convertEnumToLS1DimIndex(DimensionType dimension); */ inline int findSign(DimensionType dimension) { return ::findSign(convertDimensionToNumeric(dimension)); } -} // namespace DimensionUtils \ No newline at end of file +} // namespace DimensionUtils diff --git a/src/parallel/boundaries/RegionUtils.cpp b/src/parallel/boundaries/RegionUtils.cpp index d5a0715725..337ffc864b 100644 --- a/src/parallel/boundaries/RegionUtils.cpp +++ b/src/parallel/boundaries/RegionUtils.cpp @@ -6,7 +6,9 @@ */ #include "RegionUtils.h" -#include "utils/mardyn_assert.h" //for mardyn_exit() +#include "utils/mardyn_assert.h" //for MARDYN_EXIT() + +#include // for ostringstream std::tuple, std::array> RegionUtils::getInnerRegionSlab( const std::array &givenRegionBegin, const std::array &givenRegionEnd, @@ -39,8 +41,9 @@ std::tuple, std::array> RegionUtils::getInnerRe break; default: - Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "DimensionType::ERROR received in RegionUtils::getInnerRegionSlab" << std::endl; + MARDYN_EXIT(error_message.str()); } return {returnRegionBegin, returnRegionEnd}; } @@ -106,8 +109,9 @@ std::tuple, std::array> RegionUtils::getOuterRe break; default: - Log::global_log->error() << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl; - mardyn_exit(1); + std::ostringstream error_message; + error_message << "DimensionType::ERROR received in RegionUtils::getOuterRegionSlab" << std::endl; + MARDYN_EXIT(error_message.str()); } return std::make_tuple(returnRegionBegin, returnRegionEnd); } diff --git a/src/parallel/boundaries/RegionUtils.h b/src/parallel/boundaries/RegionUtils.h index 8e89b36209..6f613178c7 100644 --- a/src/parallel/boundaries/RegionUtils.h +++ b/src/parallel/boundaries/RegionUtils.h @@ -96,4 +96,4 @@ std::tuple, std::array> getOuterRegionSlab( const std::array &givenRegionBegin, const std::array &givenRegionEnd, DimensionUtils::DimensionType dimension, const std::array ®ionWidth); -} // namespace RegionUtils \ No newline at end of file +} // namespace RegionUtils