PSCF v1.5.0
CubicLengthDerivative.tpp
1#ifndef RP_CUBIC_LENGTH_DERIVATIVE_TPP
2#define RP_CUBIC_LENGTH_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 "CubicLengthDerivative.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#include <pscf/backend/Reduce.h>
20#include <util/global.h>
21
22namespace Pscf {
23namespace Rp {
24
25 using namespace Util;
26
27 /*
28 * Constructor.
29 */
30 template <int D, class T>
36
37 /*
38 * Compute and return required derivative.
39 */
40 template <int D, class T>
42 {
43 // Preconditions
44 UTIL_CHECK(D == 3);
45 UTIL_CHECK(system().domain().unitCell().nParameter() == 1);
46 UTIL_CHECK(system().w().hasData());
47
48 // Compute field Hamiltonian per monomer.
49 if (!system().c().hasData()) {
50 system().compute();
51 }
52 if (!system().mixture().hasStress()) {
53 system().computeStress();
54 }
55 if (!simulator().hasWc()){
56 simulator().computeWc();
57 }
58 if (!simulator().hasHamiltonian()) {
59 simulator().computeHamiltonian();
60 }
61
62 // Length of cubic box
63 double l = system().domain().unitCell().parameter(0);
64
65 // Term extensive in Hamiltonian
66 double const hamiltonian = simulator().hamiltonian();
67 double dFdL = hamiltonian * (3.0 / l);
68
69 // "Stress" term arising from changes in ln Q
70 double const stress = system().mixture().stress(0);
71 double const vSystem = system().domain().unitCell().volume();
72 double const vMonomer = system().mixture().vMonomer();
73 dFdL += stress * vSystem / vMonomer;
74
75 // Term arising from ln N
76 int const meshSize = system().domain().mesh().size();
77 int const nMonomer = system().mixture().nMonomer();
78 dFdL -= 3.0 * double( (nMonomer-1) * meshSize ) / (2.0 * l);
79
80 return dFdL;
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.
CubicLengthDerivative(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
double compute() override
Compute and return the derivative of H w/ respect to L.
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.
File containing preprocessor macros for error handling.
#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.