PSCF v1.3
rpg/fts/analyzer/ChiDerivative.tpp
1#ifndef RPG_CHI_DERIVATIVE_TPP
2#define RPG_CHI_DERIVATIVE_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 "ChiDerivative.h"
12
13#include <rpg/system/System.h>
14#include <rpg/fts/simulator/Simulator.h>
15#include <pscf/inter/Interaction.h>
16
17namespace Pscf {
18namespace Rpg
19{
20
21 using namespace Util;
22
23 /*
24 * Constructor.
25 */
26 template <int D>
31
32 /*
33 * Destructor.
34 */
35 template <int D>
38
39 template <int D>
41 {
42 UTIL_CHECK(system().w().hasData());
43
44 // For AB diblock
45 const int nMonomer = system().mixture().nMonomer();
46 UTIL_CHECK(nMonomer == 2);
47
48 const double vSystem = system().domain().unitCell().volume();
49 const double vMonomer = system().mixture().vMonomer();
50 const double nMonomerSystem = vSystem / vMonomer;
51 const int meshSize = system().domain().mesh().size();
52 double chi = system().interaction().chi(0,1);
53
54 // Pre-requisite computations
55 if (!system().c().hasData()) {
56 system().compute();
57 }
58 if (!simulator().hasWc()){
59 simulator().computeWc();
60 }
61 if (!simulator().hasHamiltonian()) {
62 simulator().computeHamiltonian();
63 }
64
65 // Get field Hamiltonian per monomer
66 double hField = simulator().fieldHamiltonian()/nMonomerSystem;
67
68 // Compute derivative of f (per monomer) w/respect to chi_bare
69 double dfdchi = -(hField - 0.5*simulator().sc(nMonomer - 1))/chi
70 + 1.0/4.0;
71
72 // Convert to derivative of total free energy F
73 dfdchi *= nMonomerSystem;
74
75 // With N term
76 dfdchi += double(meshSize)/(2.0 * chi);
77
78 return dfdchi;
79 }
80
81 template <int D>
82 void ChiDerivative<D>::outputValue(int step, double value)
83 {
84 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
85 double chi= system().interaction().chi(0,1);
86
87 UTIL_CHECK(outputFile_.is_open());
88 outputFile_ << Int(step);
89 outputFile_ << Dbl(chi);
90 outputFile_ << Dbl(value);
91 outputFile_ << "\n";
92 } else {
94 }
95 }
96
97}
98}
99#endif
AverageAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
Simulator< D > & simulator()
Return reference to parent simulator.
System< D > & system()
Return reference to parent system.
void setClassName(const char *className)
Set class name string.
virtual double compute()
Compute and return the derivative of H w/ respect to chi.
ChiDerivative(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
Field theoretic simulator (base class).
Main class, representing one complete system.
Wrapper for a double precision number, for formatted ostream output.
Definition Dbl.h:40
Wrapper for an int, for formatted ostream output.
Definition Int.h:37
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1