PSCF v1.4.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 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "CubicLengthDerivative.h"
12#include <util/global.h>
13
14namespace Pscf {
15namespace Rp {
16
17 using namespace Util;
18
19 /*
20 * Constructor.
21 */
22 template <int D, class T>
24 typename T::Simulator& simulator,
25 typename T::System& system)
26 : AverageAnalyzerT(simulator, system)
27 { ParamComposite::setClassName("CubicLengthDerivative"); }
28
29 /*
30 * Compute and return required derivative.
31 */
32 template <int D, class T>
34 {
35 // Preconditions
36 UTIL_CHECK(D == 3);
37 UTIL_CHECK(system().domain().unitCell().nParameter() == 1);
38 UTIL_CHECK(system().w().hasData());
39
40 // Compute field Hamiltonian per monomer.
41 if (!system().c().hasData()) {
42 system().compute();
43 }
44 if (!system().mixture().hasStress()) {
45 system().computeStress();
46 }
47 if (!simulator().hasWc()){
48 simulator().computeWc();
49 }
50 if (!simulator().hasHamiltonian()) {
51 simulator().computeHamiltonian();
52 }
53
54 // Length of cubic box
55 double l = system().domain().unitCell().parameter(0);
56
57 // Term extensive in Hamiltonian
58 double const hamiltonian = simulator().hamiltonian();
59 double dFdL = hamiltonian * (3.0 / l);
60
61 // "Stress" term arising from changes in ln Q
62 double const stress = system().mixture().stress(0);
63 double const vSystem = system().domain().unitCell().volume();
64 double const vMonomer = system().mixture().vMonomer();
65 dFdL += stress * vSystem / vMonomer;
66
67 // Term arising from ln N
68 int const meshSize = system().domain().mesh().size();
69 dFdL -= 3.0 * double(meshSize) / (2.0 * l);
70
71 return dFdL;
72 }
73
74}
75}
76#endif
double compute() override
Compute and return the derivative of H w/ respect to L.
CubicLengthDerivative(typename T::Simulator &simulator, typename T::System &system)
Constructor.
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
Class templates for real-valued periodic fields.
PSCF package top-level namespace.