Skip to content

Assignment4#34

Open
laert-ll wants to merge 108 commits intomainfrom
Assignment4
Open

Assignment4#34
laert-ll wants to merge 108 commits intomainfrom
Assignment4

Conversation

@laert-ll
Copy link
Copy Markdown
Owner

No description provided.

laert-ll and others added 30 commits June 12, 2024 15:13
…in but without the periodic tests to check if all the tests except the new ones pass
Copy link
Copy Markdown
Collaborator

@manishmishra6016 manishmishra6016 left a comment

Choose a reason for hiding this comment

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

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 :)

Comment thread src/Main.cpp
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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/MolSim.h
Comment on lines +159 to +203
/**
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;
}
**/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dead code - if you don't plan to use, just remove it. In general, do not keep dead code on master.

Comment thread src/MolSim.h
if (iteration % 10 == 0) {
outputWriter->plotParticles(iteration, particleContainer, filename);
}
if (linkedCellsUsed) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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. */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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).

Comment thread src/objects/Cell.h
#include <vector>
#include <memory>

class Cell {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

no documentation


#include <vector>

class LinkedCellContainer {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

doxygen documentation missing

Comment thread src/objects/Particle.cpp
Comment on lines +130 to +135
double Particle::getSigma() const {
return sigma;
}

double Particle::getEpsilon() const {
return epsilon;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

make it inline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants