1#ifndef RPC_SWEEP_PARAMETER_TPP
2#define RPC_SWEEP_PARAMETER_TPP
11#include <rpc/system/System.h>
12#include <rpc/solvers/Block.h>
13#include <rpc/solvers/Mixture.h>
14#include <rpc/solvers/MixtureModifier.h>
15#include <rpc/solvers/Polymer.h>
16#include <rpc/solvers/Solvent.h>
17#include <rpc/field/Domain.h>
18#include <prdc/crystal/UnitCell.h>
19#include <pscf/inter/Interaction.h>
20#include <pscf/sweep/ParameterModifier.h>
22#include <util/containers/FSArray.h>
43 parameterTypesPtr_(nullptr),
58 parameterTypesPtr_(nullptr),
66 void SweepParameter<D>::readParamType(std::istream& in)
70 std::transform(buffer.begin(), buffer.end(),
71 buffer.begin(), ::tolower);
73 if (buffer ==
"block" || buffer ==
"block_length") {
76 }
else if (buffer ==
"chi") {
79 }
else if (buffer ==
"kuhn") {
82 }
else if (buffer ==
"phi_polymer") {
85 }
else if (buffer ==
"phi_solvent") {
88 }
else if (buffer ==
"mu_polymer") {
91 }
else if (buffer ==
"mu_solvent") {
94 }
else if (buffer ==
"solvent" || buffer ==
"solvent_size") {
97 }
else if (buffer ==
"cell_param") {
103 if (parameterTypesPtr_) {
104 for (
int i = 0; i < parameterTypesPtr_->size(); i++) {
106 if (buffer == pType.name) {
109 parameterTypeId_ = i;
117 msg =
"Invalid SweepParameter::ParamType value: " + buffer;
122 if (id_.isAllocated()) id_.deallocate();
142 return (*parameterTypesPtr_)[parameterTypeId_];
150 { initial_ = get_(); }
165 if (type_ == Block) {
167 }
else if (type_ == Chi) {
169 }
else if (type_ == Kuhn) {
171 }
else if (type_ == Phi_Polymer) {
172 return "phi_polymer";
173 }
else if (type_ == Phi_Solvent) {
174 return "phi_solvent";
175 }
else if (type_ == Mu_Polymer) {
177 }
else if (type_ == Mu_Solvent) {
179 }
else if (type_ == Solvent) {
180 return "solvent_size";
181 }
else if (type_ == Cell_Param) {
183 }
else if (type_ == Special) {
191 double SweepParameter<D>::get_()
195 return systemPtr_->interaction().chi(
id(0),
id(1));
196 }
else if (type_ == Kuhn) {
197 return systemPtr_->mixture().monomer(
id(0)).kuhn();
198 }
else if (type_ == Phi_Polymer) {
199 return systemPtr_->mixture().polymer(
id(0)).phi();
200 }
else if (type_ == Mu_Polymer) {
201 return systemPtr_->mixture().polymer(
id(0)).mu();
202 }
else if (type_ ==
Block) {
203 return systemPtr_->mixture().polymer(
id(0)).block(
id(1)).length();
204 }
else if (type_ == Phi_Solvent) {
205 return systemPtr_->mixture().solvent(
id(0)).phi();
206 }
else if (type_ == Mu_Solvent) {
207 return systemPtr_->mixture().solvent(
id(0)).mu();
209 return systemPtr_->mixture().solvent(
id(0)).size();
210 }
else if (type_ == Cell_Param) {
211 return systemPtr_->domain().unitCell().parameter(
id(0));
212 }
else if (type_ == Special) {
214 std::string name = parameterType().name;
222 void SweepParameter<D>::set_(
double newVal)
226 systemPtr_->interaction().setChi(
id(0),
id(1), newVal);
227 }
else if (type_ == Kuhn) {
229 systemPtr_->mixtureModifier().setKuhn(
id(0), newVal);
230 }
else if (type_ == Phi_Polymer) {
232 systemPtr_->mixtureModifier().setPhiPolymer(
id(0), newVal);
233 }
else if (type_ == Mu_Polymer) {
235 systemPtr_->mixtureModifier().setMuPolymer(
id(0), newVal);
236 }
else if (type_ ==
Block) {
238 systemPtr_->mixtureModifier().setBlockLength(
id(0),
id(1), newVal);
239 }
else if (type_ == Phi_Solvent) {
241 systemPtr_->mixtureModifier().setPhiSolvent(
id(0), newVal);
242 }
else if (type_ == Mu_Solvent) {
244 systemPtr_->mixtureModifier().setMuSolvent(
id(0), newVal);
247 systemPtr_->mixtureModifier().setSolventSize(
id(0), newVal);
248 }
else if (type_ == Cell_Param) {
250 = systemPtr_->domain().unitCell().parameters();
251 params[id(0)] = newVal;
252 systemPtr_->setUnitCell(params);
253 }
else if (type_ == Special) {
255 std::string name = parameterType().name;
263 template <
class Archive>
268 for (
int i = 0; i < nId_; ++i) {
285 param.readParamType(in);
288 for (
int i = 0; i < param.nId_; ++i) {
306 for (
int i = 0; i < param.nId_; ++i) {
310 out << param.change_;
Base class allowing subclasses to define sweepable parameters.
virtual void setParameter(std::string name, DArray< int > ids, double value, bool &success)
Set the value of a specialized sweep parameter.
virtual double getParameter(std::string name, DArray< int > ids, bool &success) const
Get the value of a specialized sweep parameter.
Block within a linear or branched block polymer.
Solver and descriptor for a solvent species.
Class for storing data about an individual sweep parameter.
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()
Get and store initial value of this parameter.
std::string type() const
Return a string representation of the parameter type.
SweepParameter()
Default constructor.
void serialize(Archive ar, const unsigned int version)
Serialize to or from an archive.
ParameterType & parameterType() const
Get the ParameterType object for a specialized sweep parameter.
int id(int i) const
Get id for a sub-object or element to which this is applied.
Main class, representing a complete physical system.
A fixed capacity (static) contiguous array with a variable logical size.
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.
void serializeEnum(Archive &ar, T &data, const unsigned int version=0)
Serialize an enumeration value.
Periodic fields and crystallography.
Real periodic fields, SCFT and PS-FTS (CPU).
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.