1#ifndef RP_SWEEP_PARAMETER_TPP
2#define RP_SWEEP_PARAMETER_TPP
11#include <rp/scft/sweep/SweepParameter.h>
13#include <prdc/crystal/UnitCell.h>
14#include <pscf/interaction/Interaction.h>
15#include <pscf/sweep/ParameterModifier.h>
16#include <util/containers/FSArray.h>
31 template <
int D,
class T>
39 parameterTypesPtr_(nullptr),
46 template <
int D,
class T>
54 parameterTypesPtr_(nullptr),
61 template <
int D,
class T>
62 void SweepParameter<D,T>::readParamType(std::istream& in)
66 std::transform(buffer.begin(), buffer.end(),
67 buffer.begin(), ::tolower);
69 if (buffer ==
"block" || buffer ==
"block_length") {
72 }
else if (buffer ==
"chi") {
75 }
else if (buffer ==
"kuhn") {
78 }
else if (buffer ==
"phi_polymer") {
81 }
else if (buffer ==
"phi_solvent") {
84 }
else if (buffer ==
"mu_polymer") {
87 }
else if (buffer ==
"mu_solvent") {
90 }
else if (buffer ==
"solvent" || buffer ==
"solvent_size") {
93 }
else if (buffer ==
"cell_param") {
99 if (parameterTypesPtr_) {
100 for (
int i = 0; i < parameterTypesPtr_->size(); i++) {
102 if (buffer == pType.name) {
105 parameterTypeId_ = i;
113 msg =
"Invalid SweepParameter::ParamType value: " + buffer;
118 if (id_.isAllocated()) id_.deallocate();
126 template <
int D,
class T>
133 template <
int D,
class T>
138 return (*parameterTypesPtr_)[parameterTypeId_];
144 template <
int D,
class T>
146 { initial_ = get_(); }
151 template <
int D,
class T>
158 template <
int D,
class T>
161 if (type_ == Block) {
163 }
else if (type_ == Chi) {
165 }
else if (type_ == Kuhn) {
167 }
else if (type_ == Phi_Polymer) {
168 return "phi_polymer";
169 }
else if (type_ == Phi_Solvent) {
170 return "phi_solvent";
171 }
else if (type_ == Mu_Polymer) {
173 }
else if (type_ == Mu_Solvent) {
175 }
else if (type_ == Solvent) {
176 return "solvent_size";
177 }
else if (type_ == Cell_Param) {
179 }
else if (type_ == Special) {
180 return parameterType().name;
186 template <
int D,
class T>
187 double SweepParameter<D,T>::get_()
191 return systemPtr_->interaction().chi(
id(0),
id(1));
192 }
else if (type_ == Kuhn) {
193 return systemPtr_->mixture().monomer(
id(0)).kuhn();
194 }
else if (type_ == Phi_Polymer) {
195 return systemPtr_->mixture().polymer(
id(0)).phi();
196 }
else if (type_ == Mu_Polymer) {
197 return systemPtr_->mixture().polymer(
id(0)).mu();
198 }
else if (type_ == Block) {
199 return systemPtr_->mixture().polymer(
id(0)).block(
id(1)).length();
200 }
else if (type_ == Phi_Solvent) {
201 return systemPtr_->mixture().solvent(
id(0)).phi();
202 }
else if (type_ == Mu_Solvent) {
203 return systemPtr_->mixture().solvent(
id(0)).mu();
205 return systemPtr_->mixture().solvent(
id(0)).size();
206 }
else if (type_ == Cell_Param) {
207 return systemPtr_->domain().unitCell().parameter(
id(0));
208 }
else if (type_ == Special) {
210 std::string name = parameterType().name;
217 template <
int D,
class T>
218 void SweepParameter<D,T>::set_(
double newVal)
222 systemPtr_->interaction().setChi(
id(0),
id(1), newVal);
223 }
else if (type_ == Kuhn) {
224 systemPtr_->mixtureModifier().setKuhn(
id(0), newVal);
225 }
else if (type_ == Phi_Polymer) {
226 systemPtr_->mixtureModifier().setPhiPolymer(
id(0), newVal);
227 }
else if (type_ == Mu_Polymer) {
228 systemPtr_->mixtureModifier().setMuPolymer(
id(0), newVal);
229 }
else if (type_ == Block) {
230 systemPtr_->mixtureModifier().setBlockLength(
id(0),
id(1), newVal);
231 }
else if (type_ == Phi_Solvent) {
232 systemPtr_->mixtureModifier().setPhiSolvent(
id(0), newVal);
233 }
else if (type_ == Mu_Solvent) {
234 systemPtr_->mixtureModifier().setMuSolvent(
id(0), newVal);
236 systemPtr_->mixtureModifier().setSolventSize(
id(0), newVal);
237 }
else if (type_ == Cell_Param) {
239 = systemPtr_->domain().unitCell().parameters();
240 params[id(0)] = newVal;
241 systemPtr_->setUnitCell(params);
242 }
else if (type_ == Special) {
245 return modifier->setParameter(name,id_,newVal);
252 template <
int D,
class T>
253 template <
class Archive>
258 for (
int i = 0; i < nId_; ++i) {
270 template <
int D,
class T>
275 param.readParamType(in);
278 for (
int i = 0; i < param.nId_; ++i) {
290 template <
int D,
class T>
294 param.writeParamType(out);
296 for (
int i = 0; i < param.nId_; ++i) {
300 out << param.change_;
Base class allowing subclasses to define sweepable parameters.
virtual double getParameter(std::string name, DArray< int > ids, bool &success) const
Get the value of a specialized sweep parameter.
Solver and descriptor for a solvent species.
Class template for storing data about an individual sweep parameter.
void getInitial()
Get initial value of this parameter.
SweepParameter()
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 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.
void update(double newVal)
Update the corresponding parameter value in the system.
bool isSpecialized() const
Is this SweepParameter a specialized parameter type?
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.
Class templates for real-valued periodic 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.