PSCF v1.5.0
r1/sweep/SweepParameter.h
1#ifndef R1_SWEEP_PARAMETER_H
2#define R1_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 <util/containers/DArray.h>
12#include <util/containers/GArray.h>
13#include <iostream>
14#include <string>
15#include <pscf/sweep/ParameterType.h>
16
17using namespace Util;
18
19namespace Pscf {
20namespace R1 {
21
22 class System;
23
105 {
106
107 public:
108
113
119 SweepParameter(System& system);
120
129 void setSystem(System& system)
130 { systemPtr_ = &system; }
131
138 { parameterTypesPtr_ = &array; }
139
147
151 int parameterTypeId() const
152 { return parameterTypeId_; }
153
157 bool isSpecialized() const
158 { return (parameterTypeId_ != -1); }
159
166 void getInitial();
167
175 void checkIds() const;
176
182 void update(double newVal);
183
187 std::string type() const;
188
194 void writeParamType(std::ostream& out) const;
195
207 int id(int i) const
208 { return id_[i];}
209
213 double current()
214 { return get_(); }
215
219 double initial() const
220 { return initial_; }
221
225 double change() const
226 { return change_; }
227
234 template <class Archive>
235 void serialize(Archive& ar, const unsigned int version);
236
237 private:
238
240 enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
241 Mu_Polymer, Mu_Solvent, Solvent, Cell_Param,
242 Special, Null};
243
245 ParamType type_;
246
248 int nId_;
249
251 DArray<int> id_;
252
254 double initial_;
255
257 double change_;
258
260 System* systemPtr_;
261
263 GArray<ParameterType>* parameterTypesPtr_;
264
266 int parameterTypeId_;
267
275 void checkId(int i, int n, std::string const & name) const;
276
282 void readParamType(std::istream& in);
283
287 double get_();
288
294 void set_(double newVal);
295
296 // friends:
297
298 friend
299 std::istream& operator >> (std::istream&, SweepParameter&);
300
301 friend
302 std::ostream&
303 operator << (std::ostream&, SweepParameter const &);
304
305 };
306
307 template <class Archive>
308 void SweepParameter::serialize(Archive& ar, const unsigned int version)
309 {
310 serializeEnum(ar, type_, version);
311 ar & nId_;
312 if (Archive::is_loading()) {
313 if (id_.isAllocated()) id_.deallocate();
314 if (nId_ > 0) id_.allocate(nId_);
315 }
316 for (int i = 0; i < nId_; ++i) {
317 ar & id_[i];
318 }
319 ar & initial_;
320 ar & change_;
321 }
322
323}
324}
325#endif
Block within a block polymer.
Solver and descriptor for a solvent species in a mixture.
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.
int parameterTypeId() const
Get the array index for the specialized sweep parameter.
SweepParameter()
Default constructor.
void checkIds() const
Check that the indices of this parameter are in range.
double current()
Return the current system parameter value.
friend std::ostream & operator<<(std::ostream &, SweepParameter const &)
Extractor for writing a SweepParameter to ostream.
bool isSpecialized() const
Is this SweepParameter a specialized parameter type?
void serialize(Archive &ar, const unsigned int version)
Serialize to or from an archive.
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.
double initial() const
Return the initial system parameter value.
void setSystem(System &system)
Set the system associated with this object.
double change() const
Return the total change planned for this parameter during sweep.
friend std::istream & operator>>(std::istream &, SweepParameter &)
Inserter for reading a SweepParameter from an istream.
void setParameterTypesArray(GArray< ParameterType > &array)
Set the pointer to the array of specialized sweep parameter types.
ParameterType & parameterType() const
Get the ParameterType object for a specialized sweep parameter.
Main class in SCFT simulation of one system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
An automatically growable array, analogous to a std::vector.
Definition GArray.h:34
void serializeEnum(Archive &ar, T &data, const unsigned int version=0)
Serialize an enumeration value.
Definition serialize.h:59
SCFT with real 1D fields.
PSCF package top-level namespace.
Utility classes for scientific computation.
Declaration of a specialized sweep parameter type.