PSCF v1.4.0
rp/scft/sweep/SweepParameter.h
1#ifndef RP_SWEEP_PARAMETER_H
2#define RP_SWEEP_PARAMETER_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/sweep/ParameterType.h>
12#include <util/containers/DArray.h>
13#include <util/containers/GArray.h>
14#include <iostream>
15#include <string>
16
17namespace Pscf {
18namespace Rp {
19
20 using namespace Util;
21
114 template <int D, class T>
116 {
117
118 public:
119
128 void setSystem(typename T::System& system)
129 { systemPtr_ = &system; }
130
137 { parameterTypesPtr_ = &array; }
138
146
150 int parameterTypeId() const
151 { return parameterTypeId_; }
152
156 bool isSpecialized() const
157 { return (parameterTypeId_ != -1); }
158
165 void getInitial();
166
172 void update(double newVal);
173
177 std::string type() const;
178
184 void writeParamType(std::ostream& out) const;
185
197 int id(int i) const
198 {
199 UTIL_CHECK(i >= 0);
200 UTIL_CHECK(i < nId_);
201 return id_[i];
202 }
203
209 int nId() const
210 { return nId_; }
211
215 double current()
216 { return get_(); }
217
221 double initial() const
222 { return initial_; }
223
227 double change() const
228 { return change_; }
229
236 template <class Archive>
237 void serialize(Archive ar, const unsigned int version);
238
239 protected:
240
245
251 SweepParameter(typename T::System& system);
252
253 private:
254
256 enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
257 Mu_Polymer, Mu_Solvent, Solvent, Cell_Param,
258 Special, Null};
259
261 ParamType type_;
262
264 int nId_;
265
267 DArray<int> id_;
268
270 double initial_;
271
273 double change_;
274
276 typename T::System* systemPtr_;
277
279 GArray<ParameterType>* parameterTypesPtr_;
280
282 int parameterTypeId_;
283
289 void readParamType(std::istream& in);
290
294 double get_();
295
301 void set_(double newVal);
302
303 // friends:
304
305 template <int DT, class TT>
306 friend std::istream&
307 operator >> (std::istream&, SweepParameter<DT,TT>&);
308
309 template <int DT, class TT>
310 friend std::ostream&
311 operator << (std::ostream&, SweepParameter<DT,TT> const&);
312
313 };
314
315 /*
316 * Serialize member function.
317 */
318 template <int D, class T>
319 template <class Archive>
321 const unsigned int version)
322 {
323 serializeEnum(ar, type_, version);
324 ar & nId_;
325 for (int i = 0; i < nId_; ++i) {
326 ar & id_[i];
327 }
328 ar & initial_;
329 ar & change_;
330 }
331
338 template <int D, class T>
339 std::istream& operator >> (std::istream& in,
340 SweepParameter<D,T>& param)
341 {
342 // Read the parameter type identifier string
343 param.readParamType(in);
344
345 // Read the identifiers associated with this parameter type.
346 for (int i = 0; i < param.nId_; ++i) {
347 in >> param.id_[i];
348 }
349 // Read in the range in the parameter to sweep over
350 in >> param.change_;
351
352 return in;
353 }
354
361 template <int D, class T>
362 std::ostream& operator << (std::ostream& out,
363 SweepParameter<D,T> const & param)
364 {
365 param.writeParamType(out);
366 out << " ";
367 for (int i = 0; i < param.nId_; ++i) {
368 out << param.id(i);
369 out << " ";
370 }
371 out << param.change_;
372
373 return out;
374 }
375
376}
377}
378#endif
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.
double initial() const
Get the initial system parameter value.
int parameterTypeId() const
Get the array index for the specialized sweep parameter.
int id(int i) const
Get id for a sub-object or element to which this is applied.
void update(double newVal)
Update the corresponding parameter value in the system.
void setParameterTypesArray(GArray< ParameterType > &array)
Set the pointer to the array of specialized sweep parameter types.
bool isSpecialized() const
Is this SweepParameter a specialized parameter type?
double current()
Get the current system parameter value.
void setSystem(typename T::System &system)
Set the system associated with this object.
double change() const
Get the total change planned for this parameter during sweep.
int nId() const
Number of indices associated with this parameter.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
An automatically growable array, analogous to a std::vector.
Definition GArray.h:34
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void serializeEnum(Archive &ar, T &data, const unsigned int version=0)
Serialize an enumeration value.
Definition serialize.h:59
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.
Definition Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition Pair.h:57
Declaration of a specialized sweep parameter type.