PSCF v1.5.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 - 2026, David Morse (morse012@um.edu) and co-authors
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
17// Forward declarations
18namespace Pscf {
19 namespace Rp {
20 template <int D, class T> class System;
21 }
22}
23
24namespace Pscf {
25namespace Rp {
26
27 using namespace Util;
28
116 template <int D, class T>
118 {
119
120 public:
121
126
133
142 void setSystem(System<D,T>& system)
143 { systemPtr_ = &system; }
144
151 { parameterTypesPtr_ = &array; }
152
160
164 int parameterTypeId() const
165 { return parameterTypeId_; }
166
170 bool isSpecialized() const
171 { return (parameterTypeId_ != -1); }
172
180 void getInitial();
181
190 void checkIds() const;
191
197 void update(double newVal);
198
202 std::string type() const;
203
209 void writeParamType(std::ostream& out) const;
210
222 int id(int i) const
223 {
224 UTIL_CHECK(i >= 0);
225 UTIL_CHECK(i < nId_);
226 return id_[i];
227 }
228
234 int nId() const
235 { return nId_; }
236
240 double current()
241 { return get_(); }
242
246 double initial() const
247 { return initial_; }
248
252 double change() const
253 { return change_; }
254
261 template <class Archive>
262 void serialize(Archive& ar, const unsigned int version);
263
264 private:
265
267 enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
268 Mu_Polymer, Mu_Solvent, Solvent, Cell_Param,
269 Special, Null};
270
272 ParamType type_;
273
275 int nId_;
276
278 DArray<int> id_;
279
281 double initial_;
282
284 double change_;
285
287 System<D,T>* systemPtr_;
288
290 GArray<ParameterType>* parameterTypesPtr_;
291
293 int parameterTypeId_;
294
300 void readParamType(std::istream& in);
301
309 void checkId(int i, int n, std::string const & name) const;
310
314 double get_();
315
321 void set_(double newVal);
322
323 // friends:
324
325 template <int DT, class TT>
326 friend std::istream&
327 operator >> (std::istream&, SweepParameter<DT,TT>&);
328
329 template <int DT, class TT>
330 friend std::ostream&
331 operator << (std::ostream&, SweepParameter<DT,TT> const&);
332
333 };
334
335 /*
336 * Serialize member function.
337 */
338 template <int D, class T>
339 template <class Archive>
341 const unsigned int version)
342 {
343 serializeEnum(ar, type_, version);
344 ar & nId_;
345 if (Archive::is_loading()) {
346 if (id_.isAllocated()) id_.deallocate();
347 if (nId_ > 0) id_.allocate(nId_);
348 }
349 for (int i = 0; i < nId_; ++i) {
350 ar & id_[i];
351 }
352 ar & initial_;
353 ar & change_;
354 }
355
362 template <int D, class T>
363 std::istream& operator >> (std::istream& in,
364 SweepParameter<D,T>& param)
365 {
366 // Read the parameter type identifier string
367 param.readParamType(in);
368
369 // Read the identifiers associated with this parameter type.
370 for (int i = 0; i < param.nId_; ++i) {
371 in >> param.id_[i];
372 }
373 // Read in the range in the parameter to sweep over
374 in >> param.change_;
375
376 return in;
377 }
378
385 template <int D, class T>
386 std::ostream& operator << (std::ostream& out,
387 SweepParameter<D,T> const & param)
388 {
389 param.writeParamType(out);
390 out << " ";
391 for (int i = 0; i < param.nId_; ++i) {
392 out << param.id(i);
393 out << " ";
394 }
395 out << param.change_;
396
397 return out;
398 }
399
400}
401}
402#endif
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.
ParameterType & parameterType() const
Get the ParameterType object for a specialized sweep parameter.
void serialize(Archive &ar, const unsigned int version)
Serialize to or from an archive.
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?
void checkIds() const
Check that the indices of this parameter are in range.
double current()
Get the current system parameter value.
void setSystem(System< D, T > &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.
Base class template for classes that represent a complete system.
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
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.