PSCF v1.5.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 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "HamiltonianAnalyzer.h"
12
13#include <rp/fts/simulator/Simulator.h>
14#include <rp/system/System.h>
15#include <rp/field/Domain.h>
16#include <rp/field/WFields.h>
17#include <rp/field/CFields.h>
18
19#include <iostream>
20
21namespace Pscf {
22namespace Rp {
23
24 using namespace Util;
25
26 /*
27 * Constructor.
28 */
29 template <int D, class T>
34 idealId_(-1),
35 fieldId_(-1),
36 totalId_(-1)
37 { ParamComposite::setClassName("HamiltonianAnalyzer"); }
38
39 /*
40 * Read interval and outputFileName.
41 */
42 template <int D, class T>
44 {
47
48 idealId_ = 0;
49 AverageListAnalyzer<D,T>::setName(idealId_, "ideal");
50 fieldId_ = 1;
51 AverageListAnalyzer<D,T>::setName(fieldId_, "field");
52 totalId_ = 2;
53 AverageListAnalyzer<D,T>::setName(totalId_, "total");
54 }
55
56 /*
57 * Output energy to file.
58 */
59 template <int D, class T>
61 {
62 UTIL_CHECK(system().w().hasData());
63 if (!system().c().hasData()) {
64 system().compute();
65 }
66 UTIL_CHECK(system().c().hasData());
67 if (!simulator().hasWc()){
68 simulator().computeWc();
69 }
70 UTIL_CHECK(simulator().hasWc());
71 if (!simulator().hasHamiltonian()) {
72 simulator().computeHamiltonian();
73 }
74 UTIL_CHECK(simulator().hasHamiltonian());
75
76 double ideal = simulator().idealHamiltonian();
78
79 double field = simulator().fieldHamiltonian();
81
82 double total = simulator().hamiltonian();
84 }
85
86}
87}
88#endif
void initializeAccumulators(int nValue)
Initialize Average accumulators and set nValue.
Simulator< D, T > & simulator()
Get the parent Simulator by reference.
Definition Analyzer.h:233
AverageListAnalyzer(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
void setName(int i, std::string name)
Set name of variable.
System< D, T > & system()
Get the parent System by reference.
Definition Analyzer.h:243
void readParameters(std::istream &in) override
Read interval, outputFileName and (optionally) nSamplePerOutput.
void setValue(int i, double value)
Set current value, used by compute function.
HamiltonianAnalyzer(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
void readParameters(std::istream &in) override
Read interval and output file name.
void compute() override
Compute and store values of Hamiltonian components.
Base class for field theoretic PS-FTS simulator.
Definition Simulator.h:93
Base class template for classes that represent a complete system.
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.