PSCF v1.2
rpc/fts/ramp/LinearRamp.tpp
1#ifndef RPC_LINEAR_RAMP_TPP
2#define RPC_LINEAR_RAMP_TPP
3
4#include "LinearRamp.h"
5#include <rpc/fts/simulator/Simulator.h>
6
7#include <util/containers/DArray.h>
8#include <util/global.h>
9
10namespace Pscf {
11namespace Rpc {
12
13 using namespace Util;
14
15 /*
16 * Constructor.
17 */
18 template <int D>
20 : Ramp<D>(simulator)
21 {}
22
23 /*
24 * Destructor.
25 */
26 template <int D>
29
30 template <int D>
31 void LinearRamp<D>::readParameters(std::istream& in)
32 {
33 // Read the number of ramp parameters, allocate parameters_ array
34 ParamComposite::read(in, "nParameter", nParameter_);
35 UTIL_CHECK(nParameter_ > 0);
36 parameters_.allocate(nParameter_);
37
38 // Read array of RampParameters, using << operator for each
39 ParamComposite::readDArray(in, "parameters", parameters_, nParameter_);
40
41 // Verify net zero change in volume fractions, if these are swept
42 double sum = 0.0;
43 for (int i = 0; i < nParameter_; ++i) {
44 if (parameters_[i].type() == "phi_polymer" ||
45 parameters_[i].type() == "phi_solvent")
46 {
47 sum += parameters_[i].change();
48 }
49 }
50 UTIL_CHECK(sum > -0.000001);
51 UTIL_CHECK(sum < 0.000001);
52 }
53
54 template <int D>
55 void LinearRamp<D>::setup(int nStep)
56 {
57 nStep_ = nStep;
58
59 // Set simulator pointer and initial value for each parameter object
60 for (int i = 0; i < nParameter_; ++i) {
61 parameters_[i].setSimulator(Ramp<D>::simulator());
62 parameters_[i].getInitial();
63 }
64 }
65
66 template <int D>
68 {
69 // Compute a ramp parameter in the range [0,1]
70 double s = double(iStep)/double(nStep_);
71
72 // Update the system parameter values
73 double newVal;
74 for (int i = 0; i < nParameter_; ++i) {
75 newVal = parameters_[i].initial() + s*parameters_[i].change();
76 parameters_[i].update(newVal);
77
78 // Update chiEvals and chiEvecs if paramter is chi
79 if (parameters_[i].type() == "chi") {
80 simulator().analyzeChi();
81 }
82
83 }
84 }
85
86 template <int D>
88 {
89 for (int i = 0; i < nParameter_; ++i) {
90
91 // Output parameter type
92 Log::file()<< "Linear Ramp parameter: "
93 << parameters_[i].type() << std::endl;
94
95 // Output initial value
96 Log::file()<< "The initial value is: "
97 << parameters_[i].initial() << " ";
98
99 // Output final value
100 Log::file()<< "The final value is: "
101 << parameters_[i].initial() + parameters_[i].change()
102 << std::endl;
103
104 // Output the magnitude of change
105 Log::file()<< "The change is: "
106 << parameters_[i].change() <<std::endl;
107 }
108 }
109
110}
111}
112#endif
virtual void setup(int nStep)
Set nStep and complete initialization.
virtual void setParameters(int iStep)
Set new parameters values in associated System and Simulator.
virtual ~LinearRamp()
Destructor.
virtual void readParameters(std::istream &in)
Read parameters from parameter file input stream.
virtual void output()
Output initial and final parameter values of linear ramp at the end of the simulation.
LinearRamp(Simulator< D > &simulator)
Constructor.
Class that varies parameters during a simulation (abstract).
Field theoretic simulator (base class).
Definition rpc/System.h:38
static std::ostream & file()
Get log ostream by reference.
Definition Log.cpp:57
DArrayParam< Type > & readDArray(std::istream &in, const char *label, DArray< Type > &array, int n)
Add and read a required DArray < Type > parameter.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.