Simpatico  v1.10
ExternalEnergyAnalyzer.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "ExternalEnergyAnalyzer.h"
9 #include <ddMd/simulation/Simulation.h>
10 #include <ddMd/potentials/external/ExternalPotential.h>
11 
12 #include <sstream>
13 
14 namespace DdMd
15 {
16 
17  using namespace Util;
18 
19  /*
20  * Constructor.
21  */
23  : AverageAnalyzer(simulation)
24  { setClassName("ExternalEnergyAnalyzer"); }
25 
26  /*
27  * Destructor.
28  */
30  {}
31 
32  /*
33  * Compute current value.
34  */
36  {
37  MPI::Intracomm& communicator = simulation().domain().communicator();
38  simulation().externalPotential().computeEnergy(communicator);
39  }
40 
41  /*
42  * Get value current value (call only on master)
43  */
45  {
46  if (!simulation().domain().isMaster()) {
47  UTIL_THROW("Error: Not master processor");
48  }
49  return simulation().externalPotential().energy();
50  }
51 
52 }
virtual void computeEnergy(MPI::Intracomm &communicator)=0
Compute potential energy on all processors.
Simulation & simulation()
Get the parent Simulation by reference.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
const ExternalPotential & externalPotential() const
Get the ExternalPotential by reference.
MPI::Intracomm & communicator() const
Return Cartesian communicator by reference.
Definition: Domain.h:257
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Analyze average and block averages of a single floating point variable.
virtual double value()
Current value, set by compute function.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual ~ExternalEnergyAnalyzer()
Destructor.
ExternalEnergyAnalyzer(Simulation &simulation)
Constructor.
virtual void compute()
Function to compute value.
double energy() const
Return the total potential, from all processors.
Definition: Potential.cpp:39
void setClassName(const char *className)
Set class name string.
Domain & domain()
Get the Domain by reference.