1#ifndef RP_RAMP_PARAMETER_TPP
2#define RP_RAMP_PARAMETER_TPP
11#include "RampParameter.h"
13#include <rp/fts/simulator/Simulator.h>
14#include <rp/system/System.h>
15#include <rp/fts/perturbation/Perturbation.h>
16#include <rp/solvers/Mixture.h>
17#include <rp/solvers/MixtureModifier.h>
18#include <rp/solvers/Polymer.h>
19#include <rp/solvers/Solvent.h>
20#include <rp/solvers/Block.h>
21#include <rp/field/Domain.h>
23#include <pscf/crystal/UnitCell.h>
24#include <pscf/chem/Monomer.h>
25#include <pscf/chem/PolymerModel.h>
26#include <pscf/interaction/Interaction.h>
27#include <util/containers/FSArray.h>
28#include <util/misc/ioUtil.h>
40 template <
int D,
class T>
54 template <
int D,
class T>
61 simulatorPtr_(&simulator),
62 systemPtr_(&(simulator.system()))
68 template <
int D,
class T>
71 simulatorPtr_ = &simulator;
72 systemPtr_ = &(simulator.
system());
78 template <
int D,
class T>
79 void RampParameter<D,T>::readParamType(std::istream& in)
85 std::transform(buffer.begin(), buffer.end(),
86 buffer.begin(), ::tolower);
89 if (buffer ==
"block" || buffer ==
"block_length") {
93 }
else if (buffer ==
"chi") {
96 }
else if (buffer ==
"kuhn") {
99 }
else if (buffer ==
"phi_polymer") {
102 }
else if (buffer ==
"phi_solvent") {
105 }
else if (buffer ==
"mu_polymer") {
108 }
else if (buffer ==
"mu_solvent") {
111 }
else if (buffer ==
"solvent" || buffer ==
"solvent_size") {
114 }
else if (buffer ==
"cell_param") {
117 }
else if (buffer ==
"lambda_pert") {
120 }
else if (buffer ==
"v_monomer") {
124 UTIL_THROW(
"Invalid RampParameter::ParamType value");
128 if (id_.isAllocated()) id_.deallocate();
138 template <
int D,
class T>
146 template <
int D,
class T>
158 template <
int D,
class T>
163 if (type_ == Block) {
164 checkId(0, mixture.
nPolymer(),
"polymer");
166 }
else if (type_ == Chi) {
167 checkId(0, mixture.
nMonomer(),
"monomer");
168 checkId(1, mixture.
nMonomer(),
"monomer");
169 }
else if (type_ == Kuhn) {
170 checkId(0, mixture.
nMonomer(),
"monomer");
171 }
else if (type_ == Phi_Polymer || type_ == Mu_Polymer) {
172 checkId(0, mixture.
nPolymer(),
"polymer");
173 }
else if (type_ == Phi_Solvent || type_ == Mu_Solvent
174 || type_ == Solvent) {
175 checkId(0, mixture.
nSolvent(),
"solvent");
176 }
else if (type_ == Cell_Param) {
177 checkId(0, systemPtr_->domain().unitCell().nParameter(),
178 "lattice parameter");
185 template <
int D,
class T>
186 void RampParameter<D,T>::checkId(
int i,
int n,
187 std::string
const & name)
const
189 if (
id(i) < 0 ||
id(i) >= n) {
190 std::string msg =
"Ramp parameter " + type() +
": " + name
192 +
" out of range [0, " +
toString(n) +
")";
200 template <
int D,
class T>
207 template <
int D,
class T>
210 if (type_ == Block) {
213 }
else if (type_ == Chi) {
215 }
else if (type_ == Kuhn) {
217 }
else if (type_ == Phi_Polymer) {
218 return "phi_polymer";
219 }
else if (type_ == Phi_Solvent) {
220 return "phi_solvent";
221 }
else if (type_ == Mu_Polymer) {
223 }
else if (type_ == Mu_Solvent) {
225 }
else if (type_ == Solvent) {
226 return "solvent_size";
227 }
else if (type_ == Cell_Param) {
229 }
else if (type_ == Lambda_Pert) {
230 return "lambda_pert";
231 }
else if (type_ == V_monomer) {
233 }
else if (type_ == Null) {
235 =
"Attempt to convert a Null RampParameter type ";
236 msg +=
"enum value to a string";
239 UTIL_THROW(
"This should have been impossible.");
246 template <
int D,
class T>
247 double RampParameter<D,T>::get_()
249 if (type_ ==
Block) {
251 return systemPtr_->mixture().polymer(
id(0)).block(
id(1)).length();
252 }
else if (type_ == Chi) {
253 return systemPtr_->interaction().chi(
id(0),
id(1));
254 }
else if (type_ == Kuhn) {
255 return systemPtr_->mixture().monomer(
id(0)).kuhn();
256 }
else if (type_ == Phi_Polymer) {
257 return systemPtr_->mixture().polymer(
id(0)).phi();
258 }
else if (type_ == Phi_Solvent) {
259 return systemPtr_->mixture().solvent(
id(0)).phi();
260 }
else if (type_ == Mu_Polymer) {
261 return systemPtr_->mixture().polymer(
id(0)).mu();
262 }
else if (type_ == Mu_Solvent) {
263 return systemPtr_->mixture().solvent(
id(0)).mu();
265 return systemPtr_->mixture().solvent(
id(0)).size();
266 }
else if (type_ == V_monomer) {
267 return systemPtr_->mixture().vMonomer();
268 }
else if (type_ == Cell_Param) {
269 return systemPtr_->domain().unitCell().parameter(
id(0));
270 }
else if (type_ == Lambda_Pert) {
272 return simulatorPtr_->perturbation().lambda();
281 template <
int D,
class T>
282 void RampParameter<D,T>::set_(
double newVal)
285 systemPtr_->interaction().setChi(
id(0),
id(1), newVal);
286 }
else if (type_ == Kuhn) {
287 systemPtr_->mixtureModifier().setKuhn(
id(0), newVal);
288 }
else if (type_ == Phi_Polymer) {
289 systemPtr_->mixtureModifier().setPhiPolymer(
id(0), newVal);
290 }
else if (type_ == Mu_Polymer) {
291 systemPtr_->mixtureModifier().setMuPolymer(
id(0), newVal);
292 }
else if (type_ ==
Block) {
294 systemPtr_->mixtureModifier().setBlockLength(
id(0),
id(1), newVal);
295 }
else if (type_ == Phi_Solvent) {
296 systemPtr_->mixtureModifier().setPhiSolvent(
id(0), newVal);
297 }
else if (type_ == Mu_Solvent) {
298 systemPtr_->mixtureModifier().setMuSolvent(
id(0), newVal);
300 systemPtr_->mixtureModifier().setSolventSize(
id(0), newVal);
301 }
else if (type_ == V_monomer) {
302 systemPtr_->mixtureModifier().setVMonomer(newVal);
303 }
else if (type_ == Cell_Param) {
305 params = systemPtr_->domain().unitCell().parameters();
307 params[id(0)] = newVal;
308 systemPtr_->setUnitCell(params);
309 }
else if (type_ == Lambda_Pert) {
311 return simulatorPtr_->perturbation().setLambda(newVal);
int nMonomer() const
Get number of monomer types.
int nPolymer() const
Get number of polymer species.
int nSolvent() const
Get number of solvent (point particle) species.
int nBlock() const
Number of blocks.
Solver and descriptor for a mixture of polymers and solvents.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
RampParameter()
Default constructor.
std::string type() const
Return a string representation of the parameter type.
void writeParamType(std::ostream &out) const
Write the parameter type to an output stream.
void setSimulator(Simulator< D, T > &simulator)
Set the simulator and system associated with this object.
void getInitial()
Get and store initial value this parameters.
void update(double newVal)
Update the corresponding parameter value in the System.
void checkIds() const
Check that any indices of this parameter are in range.
Base class for field theoretic PS-FTS simulator.
System< D, T > & system()
Get the parent system by reference.
Solver and descriptor for a solvent species.
A fixed capacity (static) contiguous array with a variable logical size.
int size() const
Return logical size of this array (i.e., number of elements).
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
std::string toString(int n)
Return string representation of an integer.
bool isThread()
Is the thread model in use ?
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.