PSCF v1.4.0
HamiltonianAnalyzer.tpp
1#ifndef RP_HAMILTONIAN_ANALYZER_TPP
2#define RP_HAMILTONIAN_ANALYZER_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "HamiltonianAnalyzer.h"
12#include <iostream>
13
14namespace Pscf {
15namespace Rp {
16
17 using namespace Util;
18
19 /*
20 * Constructor.
21 */
22 template <int D, class T>
24 typename T::Simulator& simulator,
25 typename T::System& system)
26 : AverageListAnalyzerT(simulator, system),
27 idealId_(-1),
28 fieldId_(-1),
29 totalId_(-1)
30 { ParamComposite::setClassName("HamiltonianAnalyzer"); }
31
32 /*
33 * Read interval and outputFileName.
34 */
35 template <int D, class T>
37 {
38 AverageListAnalyzerT::readParameters(in);
39 AverageListAnalyzerT::initializeAccumulators(3);
40
41 idealId_ = 0;
42 AverageListAnalyzerT::setName(idealId_, "ideal");
43 fieldId_ = 1;
44 AverageListAnalyzerT::setName(fieldId_, "field");
45 totalId_ = 2;
46 AverageListAnalyzerT::setName(totalId_, "total");
47 }
49 /*
50 * Output energy to file.
51 */
52 template <int D, class T>
54 {
55 UTIL_CHECK(system().w().hasData());
56 if (!system().c().hasData()) {
57 system().compute();
58 }
59 UTIL_CHECK(system().c().hasData());
60 if (!simulator().hasWc()){
61 simulator().computeWc();
62 }
63 UTIL_CHECK(simulator().hasWc());
64 if (!simulator().hasHamiltonian()) {
65 simulator().computeHamiltonian();
66 }
67 UTIL_CHECK(simulator().hasHamiltonian());
68
69 double ideal = simulator().idealHamiltonian();
70 AverageListAnalyzerT::setValue(idealId_, ideal);
71
72 double field = simulator().fieldHamiltonian();
73 AverageListAnalyzerT::setValue(fieldId_, field);
74
75 double total = simulator().hamiltonian();
76 AverageListAnalyzerT::setValue(totalId_, total);
77 }
78
79}
80}
81#endif
HamiltonianAnalyzer(typename T::Simulator &simulator, typename T::System &system)
Constructor.
void readParameters(std::istream &in) override
Read interval and output file name.
void compute() override
Compute and store values of Hamiltonian components.
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Class templates for real-valued periodic fields.
PSCF package top-level namespace.