PSCF v1.3.3
rpg/fts/analyzer/ConcentrationDerivative.tpp
1#ifndef RPG_CONCENTRATION_DERIVATIVE_TPP
2#define RPG_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#include <rpg/fts/perturbation/Perturbation.h>
13#include <rpg/fts/simulator/Simulator.h>
14#include <rpg/system/System.h>
15#include <rpg/solvers/Mixture.h>
16#include <rpg/field/Domain.h>
17
18namespace Pscf {
19namespace Rpg {
20
21 using namespace Util;
22
23 /*
24 * Constructor.
25 */
26 template <int D>
31
32 /*
33 * Destructor.
34 */
35 template <int D>
38
39 template <int D>
41 {
42 UTIL_CHECK(system().w().hasData());
43
44 // For AB diblock
45 const int nMonomer = system().mixture().nMonomer();
46 UTIL_CHECK(nMonomer == 2);
47
48 double vMonomer = system().mixture().vMonomer();
49 const int meshSize = system().domain().mesh().size();
50
51 // Compute hamiltonian, if necessary
52 if (!system().c().hasData()) {
53 system().compute();
54 }
55 if (!simulator().hasWc()){
56 simulator().computeWc();
57 }
58 if (!simulator().hasHamiltonian()) {
59 simulator().computeHamiltonian();
60 }
61
62 // Obtain Hamiltonian
63 double h = simulator().hamiltonian();
64
65 // Calculate derivative with respect to concentration
66 double dfdc = h * vMonomer;
67
68 // With N term
69 double Hh = double(meshSize)/2.0 * vMonomer;
70 dfdc -= Hh;
71
72 return dfdc;
73 }
74
75 template <int D>
76 void ConcentrationDerivative<D>::outputValue(int step, double value)
77 {
78 if (simulator().hasRamp() && nSamplePerOutput() == 1) {
79 double vMonomer = system().mixture().vMonomer();
80
81 UTIL_CHECK(outputFile_.is_open());
82 outputFile_ << Int(step);
83 outputFile_ << Dbl(vMonomer);
84 outputFile_ << Dbl(value);
85 outputFile_ << "\n";
86 } else {
88 }
89 }
90
91}
92}
93#endif
AverageAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
Simulator< D > & simulator()
Return reference to parent simulator.
System< D > & system()
Return reference to parent system.
void setClassName(const char *className)
Set class name string.
ConcentrationDerivative(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
virtual double compute()
Compute and return the derivative of H w/ respect to concentration.
Field theoretic simulator (base class).
Main class, representing a complete physical 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
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.