8#include <r1/sweep/SweepParameter.h>
9#include <r1/system/System.h>
10#include <r1/solvers/Block.h>
11#include <r1/solvers/Mixture.h>
12#include <r1/solvers/Polymer.h>
13#include <r1/solvers/Solvent.h>
14#include <pscf/interaction/Interaction.h>
15#include <pscf/sweep/ParameterModifier.h>
16#include <util/containers/FSArray.h>
17#include <util/misc/ioUtil.h>
38 parameterTypesPtr_(0),
52 parameterTypesPtr_(0),
59 void SweepParameter::readParamType(std::istream& in)
63 std::transform(buffer.begin(), buffer.end(),
64 buffer.begin(), ::tolower);
66 if (buffer ==
"block" || buffer ==
"block_length") {
69 }
else if (buffer ==
"chi") {
72 }
else if (buffer ==
"kuhn") {
75 }
else if (buffer ==
"phi_polymer") {
78 }
else if (buffer ==
"phi_solvent") {
81 }
else if (buffer ==
"mu_polymer") {
84 }
else if (buffer ==
"mu_solvent") {
87 }
else if (buffer ==
"solvent" || buffer ==
"solvent_size") {
93 for (
int i = 0; i < parameterTypesPtr_->size(); i++) {
94 ParameterType& pType = (*parameterTypesPtr_)[i];
95 if (buffer == pType.name) {
105 msg =
"Invalid SweepParameter::ParamType value: " + buffer;
110 if (id_.isAllocated()) id_.deallocate();
128 return (*parameterTypesPtr_)[parameterTypeId_];
146 Mixture const & mixture = systemPtr_->mixture();
147 if (type_ == Block) {
148 checkId(0, mixture.
nPolymer(),
"polymer");
149 checkId(1, mixture.
polymer(
id(0)).nBlock(),
"block");
150 }
else if (type_ == Chi) {
151 checkId(0, mixture.
nMonomer(),
"monomer");
152 checkId(1, mixture.
nMonomer(),
"monomer");
153 }
else if (type_ == Kuhn) {
154 checkId(0, mixture.
nMonomer(),
"monomer");
155 }
else if (type_ == Phi_Polymer || type_ == Mu_Polymer) {
156 checkId(0, mixture.
nPolymer(),
"polymer");
157 }
else if (type_ == Phi_Solvent || type_ == Mu_Solvent
158 || type_ == Solvent) {
159 checkId(0, mixture.
nSolvent(),
"solvent");
166 void SweepParameter::checkId(
int i,
int n,
167 std::string
const & name)
const
169 if (
id(i) < 0 ||
id(i) >= n) {
170 std::string msg =
"Sweep parameter " +
type() +
": " + name
172 +
" out of range [0, " +
toString(n) +
")";
190 if (type_ == Block) {
192 }
else if (type_ == Chi) {
194 }
else if (type_ == Kuhn) {
196 }
else if (type_ == Phi_Polymer) {
197 return "phi_polymer";
198 }
else if (type_ == Phi_Solvent) {
199 return "phi_solvent";
200 }
else if (type_ == Mu_Polymer) {
202 }
else if (type_ == Mu_Solvent) {
204 }
else if (type_ == Solvent) {
205 return "solvent_size";
206 }
else if (type_ == Special) {
209 UTIL_THROW(
"Invalid type_ in accessor SweepParameter::type().");
213 double SweepParameter::get_()
215 if (type_ ==
Block) {
216 return systemPtr_->
mixture().
polymer(
id(0)).block(
id(1)).length();
217 }
else if (type_ == Chi) {
219 }
else if (type_ == Kuhn) {
221 }
else if (type_ == Phi_Polymer) {
222 return systemPtr_->mixture().polymer(
id(0)).phi();
223 }
else if (type_ == Phi_Solvent) {
224 return systemPtr_->mixture().solvent(
id(0)).phi();
225 }
else if (type_ == Mu_Polymer) {
226 return systemPtr_->mixture().polymer(
id(0)).mu();
227 }
else if (type_ == Mu_Solvent) {
228 return systemPtr_->mixture().solvent(
id(0)).mu();
229 }
else if (type_ == Solvent) {
230 return systemPtr_->mixture().solvent(
id(0)).size();
231 }
else if (type_ == Special) {
234 return modifier->getParameter(name,id_);
236 UTIL_THROW(
"Invalid type_ in SweepParameter::get_.");
240 void SweepParameter::set_(
double newVal)
242 if (type_ == Block) {
243 systemPtr_->mixture().polymer(
id(0)).block(
id(1)).setLength(newVal);
244 }
else if (type_ == Chi) {
245 systemPtr_->interaction().setChi(
id(0),
id(1), newVal);
246 }
else if (type_ == Kuhn) {
247 systemPtr_->mixture().setKuhn(
id(0), newVal);
248 }
else if (type_ == Phi_Polymer) {
249 systemPtr_->mixture().polymer(
id(0)).setPhi(newVal);
250 }
else if (type_ == Phi_Solvent) {
251 systemPtr_->mixture().solvent(
id(0)).setPhi(newVal);
252 }
else if (type_ == Mu_Polymer) {
253 systemPtr_->mixture().polymer(
id(0)).setMu(newVal);
254 }
else if (type_ == Mu_Solvent) {
255 systemPtr_->mixture().solvent(
id(0)).setMu(newVal);
256 }
else if (type_ == Solvent) {
257 systemPtr_->mixture().solvent(
id(0)).setSize(newVal);
258 }
else if (type_ == Special) {
261 return modifier->setParameter(name,id_,newVal);
263 UTIL_THROW(
"Invalid type_ in SweepParameter::set_.");
279 param.readParamType(in);
281 for (
int i = 0; i < param.nId_; ++i) {
301 for (
int i = 0; i < param.nId_; ++i) {
305 out << param.change_;
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.
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
DMatrix< double > const & chi() const
Return the chi matrix by const reference.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
double kuhn() const
Statistical segment length (random walk step size).
Block within a block polymer.
Solver and descriptor for a mixture of polymers and solvents.
std::string type() const
Return a string representation of the parameter type.
int id(int i) const
Get a id for a sub-object or element to which this is applied.
SweepParameter()
Default constructor.
void checkIds() const
Check that the indices of this parameter are in range.
bool isSpecialized() const
Is this SweepParameter a specialized parameter type?
void update(double newVal)
Update the corresponding parameter value in the system.
void writeParamType(std::ostream &out) const
Write the parameter type to an output stream.
void getInitial()
Store the pre-sweep value of the corresponding parameter.
ParameterType & parameterType() const
Get the ParameterType object for a specialized sweep parameter.
Main class in SCFT simulation of one system.
Mixture & mixture()
Get Mixture by reference.
Interaction & interaction()
Get interaction (i.e., excess free energy) by reference.
File containing preprocessor macros for error handling.
#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.
SCFT with real 1D fields.
PSCF package top-level namespace.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Declaration of a specialized sweep parameter type.