PSCF v1.3.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/fts/simulator/Simulator.h>
14#include <rpg/system/System.h>
15#include <rpg/solvers/Mixture.h>
16#include <rpg/field/Domain.h>
17#include <pscf/inter/Interaction.h>
18
19namespace Pscf {
20namespace Rpg
21{
22
23 using namespace Util;
24
25 /*
26 * Constructor.
27 */
28 template <int D>
33
34 /*
35 * Destructor.
36 */
37 template <int D>
40
41 template <int D>
43 {
44 UTIL_CHECK(system().w().hasData());
45
46 // For AB diblock
47 const int nMonomer = system().mixture().nMonomer();
48 UTIL_CHECK(nMonomer == 2);
49
50 const double vSystem = system().domain().unitCell().volume();
51 const double vMonomer = system().mixture().vMonomer();
52 const double nMonomerSystem = vSystem / vMonomer;
53 const int meshSize = system().domain().mesh().size();
54 double chi = system().interaction().chi(0,1);
55
56 // Pre-requisite computations
57 if (!system().c().hasData()) {
58 system().compute();
59 }
60 if (!simulator().hasWc()){
61 simulator().computeWc();
62 }
63 if (!simulator().hasHamiltonian()) {
64 simulator().computeHamiltonian();
65 }
66
67 // Get field Hamiltonian per monomer
68 double hField = simulator().fieldHamiltonian()/nMonomerSystem;
69
70 // Compute derivative of f (per monomer) w/respect to chi_bare
71 double dfdchi = -(hField - 0.5*simulator().sc(nMonomer - 1))/chi
72 + 1.0/4.0;
73
74 // Convert to derivative of total free energy F
75 dfdchi *= nMonomerSystem;
76
77 // With N term
78 dfdchi += double(meshSize)/(2.0 * chi);
79
80 return dfdchi;
81 }
82
83 template <int D>
84 void ChiDerivative<D>::outputValue(int step, double value)
85 {
86 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
87 double chi= system().interaction().chi(0,1);
88
89 UTIL_CHECK(outputFile_.is_open());
90 outputFile_ << Int(step);
91 outputFile_ << Dbl(chi);
92 outputFile_ << Dbl(value);
93 outputFile_ << "\n";
94 } else {
96 }
97 }
98
99}
100}
101#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 a complete physical 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.