Skip to content

Commit

Permalink
core: Rename obs_pressure_tensor to obs_pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jun 23, 2020
1 parent c4a3103 commit e735322
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/core/Observable_stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <utility>
#include <vector>

/** Observable for the scalar pressure, pressure tensor and energy. */
/** Observable for the pressure and energy. */
class Observable_stat {
/** Array for observables on each node. */
std::vector<double> m_data;
Expand Down
23 changes: 11 additions & 12 deletions src/core/pressure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "electrostatics_magnetostatics/dipole.hpp"

/** Pressure tensor of the system */
Observable_stat obs_pressure_tensor{9};
Observable_stat obs_pressure{9};

nptiso_struct nptiso = {0.0,
0.0,
Expand All @@ -58,7 +58,7 @@ nptiso_struct nptiso = {0.0,
void calc_long_range_virials(const ParticleRange &particles) {
#ifdef ELECTROSTATICS
/* calculate k-space part of electrostatic interaction. */
Coulomb::calc_pressure_long_range(obs_pressure_tensor, particles);
Coulomb::calc_pressure_long_range(obs_pressure, particles);
#endif
#ifdef DIPOLES
/* calculate k-space part of magnetostatic interaction. */
Expand All @@ -76,7 +76,7 @@ void pressure_calc() {
if (!interactions_sanity_checks())
return;

obs_pressure_tensor = Observable_stat{9};
obs_pressure = Observable_stat{9};

on_observable_calc();

Expand All @@ -93,19 +93,18 @@ void pressure_calc() {
calc_long_range_virials(cell_structure.local_particles());

#ifdef VIRTUAL_SITES
if (!obs_pressure_tensor.virtual_sites.empty()) {
auto const vs_pressure_tensor = virtual_sites()->pressure_tensor();
boost::copy(flatten(vs_pressure_tensor),
obs_pressure_tensor.virtual_sites.begin());
if (!obs_pressure.virtual_sites.empty()) {
auto const vs_pressure = virtual_sites()->pressure_tensor();
boost::copy(flatten(vs_pressure), obs_pressure.virtual_sites.begin());
}
#endif

obs_pressure_tensor.rescale(volume);
obs_pressure.rescale(volume);

/* gather data */
auto obs_pressure_tensor_res = reduce(comm_cart, obs_pressure_tensor);
if (obs_pressure_tensor_res) {
std::swap(obs_pressure_tensor, *obs_pressure_tensor_res);
auto obs_pressure_res = reduce(comm_cart, obs_pressure);
if (obs_pressure_res) {
std::swap(obs_pressure, *obs_pressure_res);
}
}

Expand All @@ -115,7 +114,7 @@ Utils::Vector9d observable_compute_pressure_tensor() {
update_pressure();
Utils::Vector9d pressure_tensor{};
for (size_t j = 0; j < 9; j++) {
pressure_tensor[j] = obs_pressure_tensor.accumulate(0, j);
pressure_tensor[j] = obs_pressure.accumulate(0, j);
}
return pressure_tensor;
}
15 changes: 6 additions & 9 deletions src/core/pressure_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include <utils/math/tensor_product.hpp>

extern Observable_stat obs_pressure_tensor;
extern Observable_stat obs_pressure;

/** Calculate non bonded energies between a pair of particles.
* @param p1 pointer to particle 1.
Expand All @@ -51,18 +51,17 @@ inline void add_non_bonded_pair_virials(Particle const &p1, Particle const &p2,

auto const type1 = p1.p.mol_id;
auto const type2 = p2.p.mol_id;
obs_pressure_tensor.add_non_bonded_contribution(type1, type2,
flatten(stress));
obs_pressure.add_non_bonded_contribution(type1, type2, flatten(stress));
}

#ifdef ELECTROSTATICS
if (!obs_pressure_tensor.coulomb.empty()) {
if (!obs_pressure.coulomb.empty()) {
/* real space Coulomb */
auto const p_coulomb = Coulomb::pair_pressure(p1, p2, d, dist);

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
obs_pressure_tensor.coulomb[i * 3 + j] += p_coulomb[i][j];
obs_pressure.coulomb[i * 3 + j] += p_coulomb[i][j];
}
}
}
Expand Down Expand Up @@ -148,8 +147,7 @@ inline bool add_bonded_pressure_tensor(Particle &p1, int bond_id,
/* pressure tensor part */
for (int k = 0; k < 3; k++)
for (int l = 0; l < 3; l++)
obs_pressure_tensor.bonded_contribution(bond_id)[k * 3 + l] +=
tensor[k][l];
obs_pressure.bonded_contribution(bond_id)[k * 3 + l] += tensor[k][l];

return false;
}
Expand All @@ -167,8 +165,7 @@ inline void add_kinetic_virials(Particle const &p1) {
/* kinetic pressure */
for (int k = 0; k < 3; k++)
for (int l = 0; l < 3; l++)
obs_pressure_tensor.kinetic[k * 3 + l] +=
(p1.m.v[k]) * (p1.m.v[l]) * p1.p.mass;
obs_pressure.kinetic[k * 3 + l] += p1.m.v[k] * p1.m.v[l] * p1.p.mass;
}

#endif
2 changes: 1 addition & 1 deletion src/python/espressomd/analyze.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cdef extern from "statistics_chain.hpp":
array2 calc_rh(int, int, int)

cdef extern from "pressure_inline.hpp":
cdef Observable_stat obs_pressure_tensor
cdef Observable_stat obs_pressure

cdef extern from "pressure.hpp":
cdef void update_pressure()
Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/analyze.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class Analysis:
# Update in ESPResSo core
analyze.update_pressure()

return _Observable_stat_to_dict(analyze.obs_pressure_tensor, 9, True)
return _Observable_stat_to_dict(analyze.obs_pressure, 9, True)

def pressure_tensor(self):
"""Calculate the instantaneous pressure_tensor (in parallel). This is
Expand Down Expand Up @@ -366,7 +366,7 @@ class Analysis:
# Update in ESPResSo core
analyze.update_pressure()

return _Observable_stat_to_dict(analyze.obs_pressure_tensor, 9, False)
return _Observable_stat_to_dict(analyze.obs_pressure, 9, False)

IF DPD == 1:
def dpd_stress(self):
Expand Down

0 comments on commit e735322

Please sign in to comment.