PSCF v1.3
rpc/fts/analyzer/ConcentrationDerivative.tpp
1#ifndef RPC_CONCENTRATION_DERIVATIVE_TPP
2#define RPC_CONCENTRATION_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 "ConcentrationDerivative.h"
12
13#include <rpc/system/System.h>
14#include <rpc/fts/simulator/Simulator.h>
15#include <rpc/solvers/Mixture.h>
16#include <rpc/field/Domain.h>
17#include <rpc/fts/perturbation/Perturbation.h>
18
19namespace Pscf {
20namespace Rpc
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 double vMonomer = system().mixture().vMonomer();
51 const int meshSize = system().domain().mesh().size();
52
53 if (!system().c().hasData()) {
54 system().compute();
55 }
56 if (!simulator().hasWc()){
57 simulator().computeWc();
58 }
59 if (!simulator().hasHamiltonian()) {
60 simulator().computeHamiltonian();
61 }
62
63 // Obtain Hamiltonian
64 double h = simulator().hamiltonian();
65
66 // Calculate derivative with respect to concentration
67 double dfdc = h * vMonomer;
68
69 // With N term
70 double Hh = double(meshSize)/2.0 * vMonomer;
71 dfdc -= Hh;
72
73 return dfdc;
74 }
75
76 template <int D>
77 void ConcentrationDerivative<D>::outputValue(int step, double value)
78 {
79 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
80 double vMonomer = system().mixture().vMonomer();
81
82 UTIL_CHECK(outputFile_.is_open());
83 outputFile_ << Int(step);
84 outputFile_ << Dbl(vMonomer);
85 outputFile_ << Dbl(value);
86 outputFile_ << "\n";
87 } else {
89 }
90 }
91
92}
93}
94#endif
AverageAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
Simulator< D > & simulator()
Return reference to parent simulator.
System< D > & system()
Return reference to parent system.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
void setClassName(const char *className)
Set class name string.
ConcentrationDerivative(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual double compute()
Compute and return the derivative of H w/ respect to concentration.
Field theoretic simulator (base class).
Main class, representing one complete 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
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1