PSCF v1.5.0
BinaryChiDerivative.tpp
1#ifndef RP_CHI_DERIVATIVE_TPP
2#define RP_CHI_DERIVATIVE_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 "BinaryChiDerivative.h"
12
13#include <rp/system/System.h>
14#include <rp/fts/simulator/Simulator.h>
15#include <rp/solvers/Mixture.h>
16#include <rp/field/Domain.h>
17#include <rp/field/WFields.h>
18#include <rp/field/CFields.h>
19
20#include <pscf/interaction/Interaction.h>
21
22namespace Pscf {
23namespace Rp {
24
25 using namespace Util;
26
27 /*
28 * Constructor.
29 */
30 template <int D, class T>
35
36
37 /*
38 * Compute and return derivative w/ respect to chi.
39 */
40 template <int D, class T>
42 {
43 // Preconditions
44 UTIL_CHECK(system().w().hasData());
45 const int nMonomer = system().mixture().nMonomer();
46 UTIL_CHECK(nMonomer == 2);
47 // Only valid for nMonomer == 2
48
49 const double vSystem = system().domain().unitCell().volume();
50 const double vMonomer = system().mixture().vMonomer();
51 const double nMonomerSystem = vSystem / vMonomer;
52 const int meshSize = system().domain().mesh().size();
53 const double chi = -simulator().chiEval(0);
54
55 // Pre-requisite computations
56 if (!system().c().hasData()) {
57 system().compute();
58 }
59 if (!simulator().hasWc()){
60 simulator().computeWc();
61 }
62 if (!simulator().hasHamiltonian()) {
63 simulator().computeHamiltonian();
64 }
65
66 // Get field Hamiltonian per monomer
67 double hField = simulator().fieldHamiltonian();
68 hField /= (double)nMonomerSystem;
69
70 // Compute derivative of f (per monomer) w/respect to bare chi
71 double dfdchi = -(hField - 0.5*simulator().sc(nMonomer - 1))/chi
72 + 0.25;
73
74 // Convert to derivative of total free energy F
75 dfdchi *= (double)nMonomerSystem;
76
77 // With N term
78 dfdchi += double(meshSize)/(2.0 * chi);
79
80 return dfdchi;
81 }
82
83}
84}
85#endif
Simulator< D, T > & simulator()
Get the parent Simulator by reference.
Definition Analyzer.h:233
System< D, T > & system()
Get the parent System by reference.
Definition Analyzer.h:243
AverageAnalyzer(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
double compute() override
Compute and return the derivative of H w/ respect to chi.
BinaryChiDerivative(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
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.