PSCF v1.3
rpc/fts/analyzer/HamiltonianAnalyzer.tpp
1#ifndef RPC_HAMILTONIAN_ANALYZER_TPP
2#define RPC_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
13#include <rpc/system/System.h>
14#include <rpc/fts/simulator/Simulator.h>
15
16#include <iostream>
17
18namespace Pscf {
19namespace Rpc {
20
21 using namespace Util;
22
23 /*
24 * Constructor.
25 */
26 template <int D>
30 idealId_(-1),
31 fieldId_(-1),
32 totalId_(-1)
33 { setClassName("HamiltonianAnalyzer"); }
34
35 /*
36 * Read interval and outputFileName.
37 */
38 template <int D>
40 {
42
44
45 idealId_ = 0;
46 setName(idealId_, "ideal");
47 fieldId_ = 1;
48 setName(fieldId_, "field");
49 totalId_ = 2;
50 setName(totalId_, "total");
51 }
52
53 /*
54 * Output energy to file
55 */
56 template <int D>
58 {
59 UTIL_CHECK(system().w().hasData());
60
61 if (!system().c().hasData()) {
62 system().compute();
63 }
64 UTIL_CHECK(system().c().hasData());
65 if (!simulator().hasWc()){
66 simulator().computeWc();
67 }
68 UTIL_CHECK(simulator().hasWc());
69 if (!simulator().hasHamiltonian()) {
70 simulator().computeHamiltonian();
71 }
72 UTIL_CHECK(simulator().hasHamiltonian());
73
74 double ideal = simulator().idealHamiltonian();
75 setValue(idealId_, ideal);
76
77 double field = simulator().fieldHamiltonian();
78 setValue(fieldId_, field);
79
80 double total = simulator().hamiltonian();
81 setValue(totalId_, total);
82 }
83
84}
85}
86#endif
AverageListAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
void initializeAccumulators(int nValue)
Instantiate Average accumulators and set nValue.
System< D > & system()
Return reference to parent system.
void setName(int i, std::string name)
Set name of variable.
void setValue(int i, double value)
Set current value, used by compute function.
Simulator< D > & simulator()
Return reference to parent Simulator.
virtual void readParameters(std::istream &in)
Read interval, outputFileName and (optionally) nSamplePerOutput.
void setClassName(const char *className)
Set class name string.
void compute()
Compute and store values of Hamiltonian components.
virtual void readParameters(std::istream &in)
Read interval and output file name.
HamiltonianAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
Field theoretic simulator (base class).
Main class, representing one complete system.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1