PSCF v1.4.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 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "BinaryChiDerivative.h"
12#include <pscf/interaction/Interaction.h>
13
14namespace Pscf {
15namespace Rp {
16
17 using namespace Util;
18
19 /*
20 * Constructor.
21 */
22 template <int D, class T>
23 BinaryChiDerivative<D,T>::BinaryChiDerivative(typename T::Simulator& simulator,
24 typename T::System& system)
25 : AverageAnalyzerT(simulator, system)
26 { ParamComposite::setClassName("BinaryChiDerivative"); }
27
28
29 /*
30 * Compute and return derivative w/ respect to chi.
31 */
32 template <int D, class T>
34 {
35 // Preconditions
36 UTIL_CHECK(system().w().hasData());
37 const int nMonomer = system().mixture().nMonomer();
38 UTIL_CHECK(nMonomer == 2);
39 // Only valid for nMonomer == 2
40
41 const double vSystem = system().domain().unitCell().volume();
42 const double vMonomer = system().mixture().vMonomer();
43 const double nMonomerSystem = vSystem / vMonomer;
44 const int meshSize = system().domain().mesh().size();
45 double chi = system().interaction().chi(0,1);
46
47 // Pre-requisite computations
48 if (!system().c().hasData()) {
49 system().compute();
50 }
51 if (!simulator().hasWc()){
52 simulator().computeWc();
53 }
54 if (!simulator().hasHamiltonian()) {
55 simulator().computeHamiltonian();
56 }
57
58 // Get field Hamiltonian per monomer
59 double hField = simulator().fieldHamiltonian();
60 hField /= (double)nMonomerSystem;
61
62 // Compute derivative of f (per monomer) w/respect to bare chi
63 double dfdchi = -(hField - 0.5*simulator().sc(nMonomer - 1))/chi
64 + 0.25;
65
66 // Convert to derivative of total free energy F
67 dfdchi *= (double)nMonomerSystem;
68
69 // With N term
70 dfdchi += double(meshSize)/(2.0 * chi);
71
72 return dfdchi;
73 }
74
75}
76}
77#endif
double compute() override
Compute and return the derivative of H w/ respect to chi.
BinaryChiDerivative(typename T::Simulator &simulator, typename T::System &system)
Constructor.
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
Class templates for real-valued periodic fields.
PSCF package top-level namespace.