PSCF v1.4.0
fts/ramp/RampParameter.h
1#ifndef RP_RAMP_PARAMETER_H
2#define RP_RAMP_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 <util/containers/DArray.h> // member
12#include <util/global.h>
13
14#include <iostream>
15#include <string>
16
17namespace Pscf {
18namespace Rp {
19
20 using namespace Util;
21
99 template <int D, class T>
101 {
102
103 public:
104
105 // Protected constructor and destructor (see below).
106
116 void setSimulator(typename T::Simulator& simulator);
117
124 void getInitial();
125
131 void update(double newVal);
132
136 std::string type() const;
137
143 void writeParamType(std::ostream& out) const;
144
159 int id(int i) const
160 {
161 UTIL_CHECK(i < nId_);
162 return id_[i];
163 }
164
170 int nId() const
171 { return nId_; }
172
176 double current()
177 { return get_(); }
178
182 double initial() const
183 { return initial_; }
184
188 double change() const
189 { return change_; }
190
197 template <class Archive>
198 void serialize(Archive ar, const unsigned int version);
199
200 protected:
201
206
212 RampParameter(typename T::Simulator& simulator);
213
217 ~RampParameter() = default;
218
219 private:
220
222 enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
223 Mu_Polymer, Mu_Solvent, Solvent, Cell_Param,
224 Lambda_Pert, Vmonomer, Null};
225
227 ParamType type_;
228
230 int nId_;
231
233 DArray<int> id_;
234
236 double initial_;
237
239 double change_;
240
242 typename T::Simulator* simulatorPtr_;
243
245 typename T::System* systemPtr_;
246
252 void readParamType(std::istream& in);
253
257 double get_();
258
264 void set_(double newVal);
265
266 // friends:
267
268 template <int U, class V>
269 friend
270 std::istream& operator >> (std::istream&, RampParameter<U,V>&);
271
272 template <int U, class V>
273 friend
274 std::ostream& operator << (std::ostream&, RampParameter<U,V> const&);
275
276 };
277
284 template <int D, class T>
285 std::istream& operator >> (std::istream& in,
286 RampParameter<D,T>& param);
287
294 template <int D, class T>
295 std::ostream& operator << (std::ostream& out,
296 RampParameter<D,T> const & param);
297
298 // Function definitions (implicitly instantiated)
299
300 template <int D, class T>
301 template <class Archive>
303 const unsigned int version)
304 {
305 serializeEnum(ar, type_, version);
306 ar & nId_;
307 if (nId_ > 0) {
308 for (int i = 0; i < nId_; ++i) {
309 ar & id_[i];
310 }
311 }
312 ar & initial_;
313 ar & change_;
314 }
315
316 /*
317 * Inserter for reading a RampParameter from an istream.
318 */
319 template <int D, class T>
320 std::istream& operator >> (std::istream& in,
321 RampParameter<D,T>& param)
322 {
323 // Read the parameter type identifier string
324 param.readParamType(in);
325
326 // Read the identifiers associated with this parameter type.
327 if (param.nId_ > 0) {
328 for (int i = 0; i < param.nId_; ++i) {
329 in >> param.id_[i];
330 }
331 }
332
333 // Read in the range in the parameter to sweep over
334 in >> param.change_;
335
336 return in;
337 }
338
339 /*
340 * Extractor for writing a RampParameter to ostream.
341 */
342 template <int D, class T>
343 std::ostream& operator << (std::ostream& out,
344 RampParameter<D,T> const & param)
345 {
346 param.writeParamType(out);
347 out << " ";
348 if (param.nId_ > 0) {
349 for (int i = 0; i < param.nId_; ++i) {
350 out << param.id(i);
351 out << " ";
352 }
353 }
354 out << param.change_;
355
356 return out;
357 }
358
359}
360}
361#endif
Class for storing data about an individual linear ramp parameter.
RampParameter()
Default constructor.
int nId() const
Number of indices associated with this type of parameter.
std::string type() const
Return a string representation of the parameter type.
double current()
Get the current system parameter value.
int id(int i) const
Get id for a sub-object or element to which this is applied.
void serialize(Archive ar, const unsigned int version)
Serialize to or from an archive.
~RampParameter()=default
Destructor.
void writeParamType(std::ostream &out) const
Write the parameter type to an output stream.
void getInitial()
Get and store initial value this parameters.
void setSimulator(typename T::Simulator &simulator)
Set the simulator and system associated with this object.
double change() const
Get the total change planned for this parameter during ramp.
double initial() const
Get the initial system parameter value.
void update(double newVal)
Update the corresponding parameter value in the System.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
File containing preprocessor macros for error handling.
#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