Conversation
…ticleGeneratorTest, FileReaderTest
# Conflicts: # src/Main.cpp # src/MolSim.h
…in but without the periodic tests to check if all the tests except the new ones pass
manishmishra6016
left a comment
There was a problem hiding this comment.
Note
This is only feedback regarding the code directly. Grade feedback will be on Moodle once we are through with all groups.
Thank you for your nice submission 💪
Unfortunately you could not run your big cases, probably because you had to spend time in implementing features from previous worksheet. But I am sure you will do a great job in final worksheet and you are on the right track :) Having said, if you feel like you have too much to do from previous worksheet, let us know via email and we can provide a working code that you can use. Ofc, if you want to fix and work with your own code, that is much appreciated 😄
I have left some comments, so go over them and see if they make sense. I tried to share some ideas about improving performance and code structure. Feel free to ask if something is not clear. Focus on finishing the tasks with priority, minor changes can be done later. Good luck with the worksheet :)
| std::unique_ptr<fileReaders::FileReader> fileReader; | ||
| std::unique_ptr<outputWriters::FileWriter> outputWriter; | ||
| std::shared_ptr<calculators::Calculator> calculator; | ||
| std::unique_ptr<Thermostat> thermostat = std::make_unique<Thermostat>(10, 20, 5, 1, 3); |
There was a problem hiding this comment.
I would recommend passing variables with meaningful names as arguments. If you are worried about performance, you can just declare them as const and it should be fine. But this is not a major issue, just a recommendation.
| /** | ||
| if (result.count("boundaries")) { | ||
| std::string boundariesArg = result["boundaries"].as<std::string>(); | ||
| if (boundariesArg.size() == 4) { | ||
| std::array<boundaries::BoundaryDirection, 4> directions = { | ||
| boundaries::BoundaryDirection::LEFT, | ||
| boundaries::BoundaryDirection::BOTTOM, | ||
| boundaries::BoundaryDirection::RIGHT, | ||
| boundaries::BoundaryDirection::TOP | ||
| }; | ||
|
|
||
| for (int i = 0; i < 4; ++i) { | ||
| switch (boundariesArg[i]) { | ||
| case '0': | ||
| boundaryMap[directions[i]] = boundaries::BoundaryType::OFF; | ||
| break; | ||
| case '1': | ||
| boundaryMap[directions[i]] = boundaries::BoundaryType::REFLECTING; | ||
| break; | ||
| case '2': | ||
| boundaryMap[directions[i]] = boundaries::BoundaryType::OUTFLOW; | ||
| break; | ||
| case '3': | ||
| boundaryMap[directions[i]] = boundaries::BoundaryType::PERIODIC; | ||
| break; | ||
| default: | ||
| SPDLOG_WARN("Invalid boundary value '{}', defaulting all to PERIODIC", boundariesArg[i]); | ||
| boundaryMap[directions[i]] = boundaries::BoundaryType::PERIODIC; | ||
| } | ||
| } | ||
| } else { | ||
| SPDLOG_WARN("Invalid boundary string length, defaulting all boundaries to REFLECTING"); | ||
| boundaryMap[boundaries::BoundaryDirection::LEFT] = boundaries::BoundaryType::REFLECTING; | ||
| boundaryMap[boundaries::BoundaryDirection::BOTTOM] = boundaries::BoundaryType::REFLECTING; | ||
| boundaryMap[boundaries::BoundaryDirection::RIGHT] = boundaries::BoundaryType::REFLECTING; | ||
| boundaryMap[boundaries::BoundaryDirection::TOP] = boundaries::BoundaryType::REFLECTING; | ||
| } | ||
| } else { | ||
| SPDLOG_WARN("No boundary conditions specified, defaulting all boundaries to REFLECTING"); | ||
| boundaryMap[boundaries::BoundaryDirection::LEFT] = boundaries::BoundaryType::REFLECTING; | ||
| boundaryMap[boundaries::BoundaryDirection::BOTTOM] = boundaries::BoundaryType::REFLECTING; | ||
| boundaryMap[boundaries::BoundaryDirection::RIGHT] = boundaries::BoundaryType::REFLECTING; | ||
| boundaryMap[boundaries::BoundaryDirection::TOP] = boundaries::BoundaryType::REFLECTING; | ||
| } | ||
| **/ |
There was a problem hiding this comment.
dead code - if you don't plan to use, just remove it. In general, do not keep dead code on master.
| if (iteration % 10 == 0) { | ||
| outputWriter->plotParticles(iteration, particleContainer, filename); | ||
| } | ||
| if (linkedCellsUsed) { |
There was a problem hiding this comment.
While it is fine for the worksheet, I would generally not use if-else here. You can think of Runtime Polymorphism to implement this. The main idea being that you have a pointer to a base class from which directSum and LinkedCell containers are derived. You can initialize the pointer to base class with object of the derived class during runtime based on the user input.
| REFLECTING, /**< Boundary reflects particles. */ | ||
| OUTFLOW, /**< Boundary allows particles to flow out. */ | ||
| PERIODIC, | ||
| OFF /**< Boundary is turned off. */ |
There was a problem hiding this comment.
Is this really needed, isn't it same as outflow? You can keep one of the above as default case (maybe even outflow). Ofcourse, it is fine as it is, this is just a recommendation.
| for (auto &p: cell->getParticles()) { | ||
| double distanceToBoundary = isLowerBound ? p->getX().at(relevantIndex) : boundaryPosition - | ||
| p->getX().at(relevantIndex); | ||
| double tolerance = pow(2, 1.0 / 6) * p->getSigma(); |
There was a problem hiding this comment.
possible optimization: you can precompute pow(2, 1.0 / 6) as constexpr and use it here. pow() is expensive, so you can avoid computing it a lot of time.
| #include "../objects/ParticleContainer.h" | ||
| #include "objects/LinkedCellContainer.h" | ||
|
|
||
| class Thermostat { |
There was a problem hiding this comment.
No documentation. Please add comments, it is hard to understand the code for others and even you in future.
| const double currentTemp = calculateCurrentTemp(linkedCellContainer); | ||
| double beta; | ||
| if (std::abs(currentTemp) < COMPARISON_TOLERANCE) { // Check if currentTemp is zero | ||
| beta = sqrt(newTemp / COMPARISON_TOLERANCE); // or some default value |
There was a problem hiding this comment.
if you don't want user to input init temp as 0, just throw an error here. And if initial temp is not 0, it should never get to 0 (because even in dimensionless case 0 temp corresponds to 0 K, which is improbable and no real physics happens there).
| #include <vector> | ||
| #include <memory> | ||
|
|
||
| class Cell { |
There was a problem hiding this comment.
no documentation
|
|
||
| #include <vector> | ||
|
|
||
| class LinkedCellContainer { |
There was a problem hiding this comment.
doxygen documentation missing
| double Particle::getSigma() const { | ||
| return sigma; | ||
| } | ||
|
|
||
| double Particle::getEpsilon() const { | ||
| return epsilon; |
No description provided.