Simpatico  v1.10
McExternalEnergyAverage.cpp
1 #ifdef SIMP_EXTERNAL
2 /*
3 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
4 *
5 * Copyright 2010 - 2017, The Regents of the University of Minnesota
6 * Distributed under the terms of the GNU General Public License.
7 */
8 
9 #include "McExternalEnergyAverage.h" // class header
10 
11 #include <util/misc/FileMaster.h>
12 #include <mcMd/chemistry/Molecule.h>
13 #include <mcMd/chemistry/Atom.h>
14 #include <mcMd/potentials/external/ExternalPotential.h>
15 
16 
17 #include <cstdio>
18 
19 namespace McMd
20 {
21 
22  using namespace Util;
23 
24  /*
25  * Constructor.
26  */
28  : AverageAnalyzer<McSystem>(system)
29  { setClassName("McExternalEnergyAverage"); }
30 
31  /*
32  * Evaluate external energy, and add to ensemble.
33  */
35  {
36  if (!isAtInterval(iStep)) return;
37 
38  double energy = 0.0;
40  Molecule::AtomIterator atomIter;
41  for (int iSpec=0; iSpec < system().simulation().nSpecies(); ++iSpec){
42  for (system().begin(iSpec, molIter); molIter.notEnd(); ++molIter){
43  for (molIter->begin(atomIter); atomIter.notEnd(); ++atomIter) {
44  energy += system().externalPotential().energy(atomIter->position(), atomIter->typeId());
45  }
46  }
47  }
49  }
50 
51 }
52 #endif
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
void begin(int speciesId, MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this System.
Definition: System.h:1147
bool notEnd() const
Is the current pointer not at the end of the array?
Definition: ArrayIterator.h:83
McSystem & system()
Return reference to parent system.
virtual double energy(const Vector &position, int i) const =0
Returns external potential energy of a single particle.
Simulation & simulation() const
Get the parent Simulation by reference.
Definition: System.h:1055
virtual void sample(long iStep)
Calculate, analyze and/or output a physical quantity.
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
Definition: McSystem.h:473
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
McExternalEnergyAverage(McSystem &system)
Constructor.
Average accumulator_
Average object - statistical accumulator.
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
Forward iterator for a PArray.
Definition: ArraySet.h:19
AverageAnalyzer averages of total potential energy.
void sample(double value)
Add a sampled value to the ensemble.
Definition: Average.cpp:94
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void setClassName(const char *className)
Set class name string.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.