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

Add plugin for extended sampling #231

Draft
wants to merge 83 commits into
base: master
Choose a base branch
from
Draft

Add plugin for extended sampling #231

wants to merge 83 commits into from

Conversation

HomesGH
Copy link
Contributor

@HomesGH HomesGH commented Mar 10, 2022

Description

This PR adds a plugin to sample multiple quantities plus the chemical potential directly using Widom's insertion method. For now, it works for the LJTS fluid, which does not need any LR corrections. In addition, minor improvements and fixes were made in other parts of the code.
The plugin offers the possibility to choose, if the test particles are inserted randomly or in a lattice structure. The number of inserted particles in the lattice structure is adjusted according to the local density.

  • Add plugin for sampling multiple quantities and the chemical potential for LJTS fluid
  • Fix in MMPLD writer since _simulation.getNumTimesteps() may lead to wrong value during read in of xml config. The number of timesteps may be overwritten later by the command line argument. Therefore, the stopTimestep variable must be set not earlier than in the init() method
  • Add doc to particle containter -> getEnergy(), since it only returns the correct energy if the halo cells are still present. So for plugins, the getEnergy() method must be called in afterForces()
  • Simplify code for output in DriftCtrl, make component 0 (= all components) work and dump momentum (use velocities instead)
  • Get rid of warning caused by AlignedArray
  • Fix in RegionSampling to make stop of sampling work
  • Add postprocessing python script to calculate shear viscosity using the correlation proposed by Lautenschläger
  • Abort simulation if path to included xmls is not found. Otherwise it's very error-prone, as these errors only appear at the very beginning and are easily overlooked in the total output

How Has This Been Tested?

The sampling was tested by conducting several test runs at different state points. The result was compare to the PeTS EOS and results from ms2 simulations.

Open issues

  • In the sampling step, the global potential energy is displayed wrong as the endTraversal() method called by getEnergy() sets the local Upot to some wrong value. Is the call of endTraversal() needed in the getEnergy() method?
  • The OpenMP implementation is rudimentary. It may need some revision.
  • Get rid of LGTM warning (Resource not released)

@HomesGH HomesGH changed the title Chem pot sampling Add plugin for chemical potential sampling Mar 10, 2022
@HomesGH HomesGH requested review from pramathe and FG-TUM March 10, 2022 13:44
@lgtm-com
Copy link

lgtm-com bot commented Mar 10, 2022

This pull request introduces 2 alerts when merging cdd1b25 into e7c0ca9 - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Resource not released in destructor

@lgtm-com
Copy link

lgtm-com bot commented Mar 10, 2022

This pull request introduces 1 alert when merging 8d8e1e5 into e7c0ca9 - view on LGTM.com

new alerts:

  • 1 for Resource not released in destructor

@lgtm-com
Copy link

lgtm-com bot commented Mar 11, 2022

This pull request introduces 1 alert when merging e022806 into e7c0ca9 - view on LGTM.com

new alerts:

  • 1 for Resource not released in destructor

@HomesGH HomesGH marked this pull request as draft November 9, 2022 16:10
Copy link
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@FG-TUM FG-TUM added the help wanted Extra attention is needed label May 24, 2023
@FG-TUM
Copy link
Member

FG-TUM commented May 24, 2023

Main obstacle is that this branch adds significant overhead. TODO:

  • identify main sources of overhead
  • Make these optional

for (unsigned int sj = 0; sj < nc2; ++sj) {
const std::array<double,3> djj = mj.ljcenter_d_abs(sj);
// const std::array<double,3> dsitejj = mj.ljcenter_d(sj);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
const unsigned int nc1 = mi.numLJcenters();
const unsigned int nc2 = mj.numLJcenters();
for (unsigned int si = 0; si < nc1; ++si) {
const std::array<double,3> dii = mi.ljcenter_d_abs(si);
// const std::array<double,3> dsiteii = mi.ljcenter_d(si);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
// Check if we have to add the macroscopic values up
if (calculateMacroscopic) {
const RealAccumVec upot_accum = RealAccumVec::convertCalcToAccum(upot);
sum_upotXpoles = sum_upotXpoles + upot_accum;
sum_virial = sum_virial + V_x + V_y + V_z;//DoubleVec::scal_prod(m_dx, m_dy, m_dz, f_x, f_y, f_z);
sum_virial = sum_virial + V_xx + V_yy + V_zz;//DoubleVec::scal_prod(m_dx, m_dy, m_dz, f_x, f_y, f_z);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
// Check if we have to add the macroscopic values up
if (calculateMacroscopic) {
RealAccumVec upot_accum = RealAccumVec::convertCalcToAccum(upot);
sum_upotXpoles = sum_upotXpoles + upot_accum;
sum_virial = sum_virial + V_x + V_y + V_z;//DoubleVec::scal_prod(m_dx, m_dy, m_dz, f_x, f_y, f_z);
sum_virial = sum_virial + V_xx + V_yy + V_zz;//DoubleVec::scal_prod(m_dx, m_dy, m_dz, f_x, f_y, f_z);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

void Fadd(const double a[]) override { for(unsigned short d=0;d<3;++d) _F[d]+=a[d]; }
void Madd(const double a[]) override { for(unsigned short d=0;d<3;++d) _M[d]+=a[d]; }
void Viadd(const double a[]) override { for(unsigned short d=0;d<3;++d) _Vi[d]+=a[d]; }
void Viadd(const double a[]) override { for(unsigned short d=0;d<9;++d) _Vi[d]+=a[d]; }

Check notice

Code scanning / CodeQL

No raw arrays in interfaces Note

Raw arrays should not be used in interfaces. A container class should be used instead.
@@ -271,17 +273,19 @@
* @param M force vector (x,y,z)
*/
void setM(double M[3]) override { for(int d = 0; d < 3; d++ ) { _M[d] = M[d]; } }
void setVi(double Vi[3]) override { for(int d = 0; d < 3; d++) { _Vi[d] = Vi[d]; } }
void setVi(double Vi[9]) override { for(int d = 0; d < 9; d++) { _Vi[d] = Vi[d]; } }

Check notice

Code scanning / CodeQL

No raw arrays in interfaces Note

Raw arrays should not be used in interfaces. A container class should be used instead.
@@ -191,7 +191,9 @@

virtual void setF(double F[3]) = 0;
virtual void setM(double M[3]) = 0;
virtual void setVi(double Vi[3]) = 0;
virtual void setVi(double Vi[9]) = 0;

Check notice

Code scanning / CodeQL

No raw arrays in interfaces Note

Raw arrays should not be used in interfaces. A container class should be used instead.
@@ -218,7 +218,7 @@

void setF(double /*F*/ [3]) override {}
void setM(double /*M*/[3]) override {}
void setVi(double /*Vi*/[3]) override {}
void setVi(double /*Vi*/[9]) override {}

Check notice

Code scanning / CodeQL

No raw arrays in interfaces Note

Raw arrays should not be used in interfaces. A container class should be used instead.
_globalBoxLength[2] = domain->getGlobalLength(2);

_numBinsGlobal = static_cast<unsigned int>(_globalBoxLength[1]/_binwidth);
if (_globalBoxLength[1]/_binwidth != static_cast<float>(_numBinsGlobal)) {

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note

Equality checks on floating point values can yield unexpected results.
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import numpy as np
import pandas as pd

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'pd' is not used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants