Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor the Permittivity function #465

Merged
merged 18 commits into from
Nov 21, 2023

Conversation

Gabrielgerez
Copy link
Contributor

@Gabrielgerez Gabrielgerez commented Oct 2, 2023

Create a Class "StepFunction" which sets up the base structure of any Permittivity-like function. This is in preparation to the pb-solvation and other work, so we can avoid repeating code

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (2dcd68d) 69.25% compared to head (bea133e) 69.23%.

❗ Current head bea133e differs from pull request most recent head c591de0. Consider uploading reports for the commit c591de0 to get more accurate results

Files Patch % Lines
src/environment/StepFunction.cpp 91.52% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #465      +/-   ##
==========================================
- Coverage   69.25%   69.23%   -0.03%     
==========================================
  Files         179      180       +1     
  Lines       14975    14980       +5     
==========================================
  Hits        10371    10371              
- Misses       4604     4609       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@robertodr robertodr left a comment

Choose a reason for hiding this comment

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

Before I get into actually reviewing, I believe what you've implemented is a step function

@Gabrielgerez
Copy link
Contributor Author

Before I get into actually reviewing, I believe what you've implemented is a step function

ah, yes that is the name. I'll rename it properly

Copy link
Contributor

@robertodr robertodr left a comment

Choose a reason for hiding this comment

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

Potentially we can have many step functions in a calculation. The way it's written now, each will make their own copy of the Cavity function, which can possibly become a memory bottleneck. Maybe instead of storing a Cavity the classes should store a std::shared_ptr<Cavity>?

@Gabrielgerez
Copy link
Contributor Author

Potentially we can have many step functions in a calculation. The way it's written now, each will make their own copy of the Cavity function, which can possibly become a memory bottleneck. Maybe instead of storing a Cavity the classes should store a std::shared_ptr<Cavity>?

This is a good idea, but the DHScreening function might potentially need a different cavity than the one for the Permittivity (Different radii due to Ion accessible surface and such)

@Gabrielgerez
Copy link
Contributor Author

Potentially we can have many step functions in a calculation. The way it's written now, each will make their own copy of the Cavity function, which can possibly become a memory bottleneck. Maybe instead of storing a Cavity the classes should store a std::shared_ptr<Cavity>?

This is a good idea, but the DHScreening function might potentially need a different cavity than the one for the Permittivity (Different radii due to Ion accessible surface and such)

This was really a fix waiting to happen (cavity was passed as a shared_ptr from molecule in driver.cpp), we can let whoever (us) wants to do anything in the future deal with cavity ownership

@@ -118,13 +119,11 @@ mrcpp::ComplexFunction SCRF::solvePoissonEquation(const mrcpp::ComplexFunction &
mrcpp::ComplexFunction Vr_np1;
Vr_np1.alloc(NUMBER::Real);

this->epsilon.flipFunction(true);

auto eps_inv_func = mrcpp::AnalyticFunction<3>([this](const mrcpp::Coord<3> &r) { return 1.0 / this->epsilon.evalf(r); });
Copy link
Contributor

Choose a reason for hiding this comment

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

very good 👍🏻

std::shared_ptr<Cavity> getCavity() const { return this->cavity; }

void printParameters() const;
virtual void printHeader() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

there is some duplication between base and derived class.

We can add a free function (outside the class) to generate headers:

void print_header(const std::string &header, const std::string &formulation, double in_value, double out_value) {
    mrcpp::print::header(0, header);
    print_utils::text(0, "Formulation", formulation, true);
    print_utils::scalar(0, "Value inside Cavity", in_value, "(in)", 6);
    print_utils::scalar(0, "Value outside Cavity", out_value, "(out)", 6);
}

then in this class:

virtual void printHeader() const { print_header("Step function of Cavity values", "Standard", getValueIn(), getValueOut()); }

while in Permittivity:

void printHeader() const override { print_header("Solvation Cavity", this->formulation, getValueIn(), getValueOut()); }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slightly harder than expected, ended up adding it to the detail namespace

@robertodr robertodr merged commit 887a887 into MRChemSoft:master Nov 21, 2023
8 checks passed
@robertodr robertodr deleted the cavity-refactor branch November 21, 2023 13:13
gitpeterwind pushed a commit to gitpeterwind/mrchem that referenced this pull request Aug 5, 2024
* Refactor the Permittivity function
for ease of future implementation work.

* Add ShiftFunction to CMakeLists

* Add virtual and override where necessary

* Remove evalf definition from shiftFunction

* Rename ShiftFunction to StepFunction

* Update src/environment/Permittivity.cpp

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Update src/environment/StepFunction.cpp

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Update src/environment/StepFunction.cpp

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Update src/environment/StepFunction.cpp

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Update src/environment/StepFunction.h

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Update src/environment/StepFunction.h

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Pass cavity as a shared_ptr to save memory.

* Fix rebase error

* Remove use for `flipFunction` in Permittivity

* Update src/environment/Permittivity.h

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Update src/environment/StepFunction.cpp

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

* Add print_header to detail namespace

* Update src/environment/StepFunction.h

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>

---------

Co-authored-by: Roberto Di Remigio Eikås <[email protected]>
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.

2 participants