Skip to content

Commit

Permalink
core: Removed multiplication by one
Browse files Browse the repository at this point in the history
  • Loading branch information
fweik committed May 14, 2020
1 parent 5693cc8 commit 74e99b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
12 changes: 5 additions & 7 deletions src/core/Observable_stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,11 @@ class Observable_stat : public Observable_stat_base {
void resize() final;

/** Rescale values */
void rescale(double volume, double time_step) {
auto const factor1 = 1. / (volume * time_step * time_step);
auto const factor2 = 1. / volume;
for (auto it = data.begin(); it != data.begin() + m_chunk_size; ++it)
*it *= factor1;
for (auto it = data.begin() + m_chunk_size; it != data.end(); ++it)
*it *= factor2;
void rescale(double volume) {
auto const factor = 1. / volume;
for(auto &e: data) {
e *= factor;
}
}

/** Get contribution from a bonded interaction */
Expand Down
4 changes: 2 additions & 2 deletions src/core/pressure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ void pressure_calc(bool v_comp) {
#endif

/* rescale kinetic energy (=ideal contribution) */
obs_scalar_pressure.local.rescale(3.0 * volume, time_step);
obs_scalar_pressure.local.rescale(3.0 * volume);

obs_stress_tensor.local.rescale(volume, time_step);
obs_stress_tensor.local.rescale(volume);

/* Intra- and Inter- part of nonbonded interaction */
obs_scalar_pressure_non_bonded.local.rescale(3.0 * volume);
Expand Down
10 changes: 3 additions & 7 deletions src/core/pressure_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,15 @@ inline void add_kinetic_virials(Particle const &p1, bool v_comp) {
/* kinetic energy */
if (v_comp) {
obs_scalar_pressure.local.kinetic[0] +=
((p1.m.v * time_step) -
(p1.f.f * (0.5 * Utils::sqr(time_step) / p1.p.mass)))
.norm2() *
p1.p.mass;
(p1.m.v - (p1.f.f * (0.5 * time_step / p1.p.mass))).norm2() * p1.p.mass;
} else {
obs_scalar_pressure.local.kinetic[0] +=
Utils::sqr(time_step) * p1.m.v.norm2() * p1.p.mass;
obs_scalar_pressure.local.kinetic[0] += p1.m.v.norm2() * p1.p.mass;
}

for (int k = 0; k < 3; k++)
for (int l = 0; l < 3; l++)
obs_stress_tensor.local.kinetic[k * 3 + l] +=
(p1.m.v[k] * time_step) * (p1.m.v[l] * time_step) * p1.p.mass;
(p1.m.v[k]) * (p1.m.v[l]) * p1.p.mass;
}

#endif

0 comments on commit 74e99b5

Please sign in to comment.