PSCF v1.5.0
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 - 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> // member
12
13#include <pscf/backend/TmplDeclare.h>
14#include <util/global.h>
15
16#include <iostream>
17#include <string>
18
19// Forward declarations
20namespace Pscf {
21 namespace Rp {
22 template <int D, class T> class System;
23 template <int D, class T> class Simulator;
24 }
25}
26
27namespace Pscf {
28namespace Rp {
29
30 using namespace Util;
31
104 template <int D, class T>
106 {
107
108 public:
109
114
120 RampParameter(Simulator<D,T>& simulator);
121
125 ~RampParameter() = default;
126
136 void setSimulator(Simulator<D,T>& simulator);
137
145 void getInitial();
146
154 void checkIds() const;
155
161 void update(double newVal);
162
166 std::string type() const;
167
173 void writeParamType(std::ostream& out) const;
174
189 int id(int i) const
190 {
191 UTIL_CHECK(i < nId_);
192 return id_[i];
193 }
194
200 int nId() const
201 { return nId_; }
202
206 double current()
207 { return get_(); }
208
212 double initial() const
213 { return initial_; }
214
218 double change() const
219 { return change_; }
220
227 template <class Archive>
228 void serialize(Archive& ar, const unsigned int version);
229
230 private:
231
233 enum ParamType { Block, Chi, Kuhn, Phi_Polymer, Phi_Solvent,
234 Mu_Polymer, Mu_Solvent, Solvent, Cell_Param,
235 Lambda_Pert, V_monomer, Null};
236
238 ParamType type_;
239
241 int nId_;
242
244 DArray<int> id_;
245
247 double initial_;
248
250 double change_;
251
253 Simulator<D,T>* simulatorPtr_;
254
256 System<D,T>* systemPtr_;
257
263 void readParamType(std::istream& in);
264
272 void checkId(int i, int n, std::string const & name) const;
273
277 double get_();
278
284 void set_(double newVal);
285
286 // friends:
287
288 template <int U, class V>
289 friend
290 std::istream& operator >> (std::istream&, RampParameter<U,V>&);
291
292 template <int U, class V>
293 friend
294 std::ostream& operator << (std::ostream&, RampParameter<U,V> const&);
295
296 };
297
304 template <int D, class T>
305 std::istream& operator >> (std::istream& in,
306 RampParameter<D,T>& param);
307
314 template <int D, class T>
315 std::ostream& operator << (std::ostream& out,
316 RampParameter<D,T> const & param);
317
318 // Function definitions (implicitly instantiated)
319
320 template <int D, class T>
321 template <class Archive>
323 const unsigned int version)
324 {
325 serializeEnum(ar, type_, version);
326 ar & nId_;
327 if (Archive::is_loading()) {
328 if (id_.isAllocated()) id_.deallocate();
329 if (nId_ > 0) id_.allocate(nId_);
330 }
331 if (nId_ > 0) {
332 for (int i = 0; i < nId_; ++i) {
333 ar & id_[i];
334 }
335 }
336 ar & initial_;
337 ar & change_;
338 }
339
340 /*
341 * Inserter for reading a RampParameter from an istream.
342 */
343 template <int D, class T>
344 std::istream& operator >> (std::istream& in,
345 RampParameter<D,T>& param)
346 {
347 // Read the parameter type identifier string
348 param.readParamType(in);
349
350 // Read the identifiers associated with this parameter type.
351 if (param.nId_ > 0) {
352 for (int i = 0; i < param.nId_; ++i) {
353 in >> param.id_[i];
354 }
355 }
356
357 // Read in the range in the parameter to sweep over
358 in >> param.change_;
359
360 return in;
361 }
362
363 /*
364 * Extractor for writing a RampParameter to ostream.
365 */
366 template <int D, class T>
367 std::ostream& operator << (std::ostream& out,
368 RampParameter<D,T> const & param)
369 {
370 param.writeParamType(out);
371 out << " ";
372 if (param.nId_ > 0) {
373 for (int i = 0; i < param.nId_; ++i) {
374 out << param.id(i);
375 out << " ";
376 }
377 }
378 out << param.change_;
379
380 return out;
381 }
382
383 // Explicit instantiation declarations
384 PSCF_TMPL_DECLARE(RampParameter)
385
386} // namespace Rp
387} // namespace Pscf
388#endif
Data about an individual linear ramp parameter.
RampParameter()
Default constructor.
int nId() const
Number of indices associated with this type of parameter.
void serialize(Archive &ar, const unsigned int version)
Serialize to or from an archive.
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.
~RampParameter()=default
Destructor.
void writeParamType(std::ostream &out) const
Write the parameter type to an output stream.
void setSimulator(Simulator< D, T > &simulator)
Set the simulator and system associated with this object.
void getInitial()
Get and store initial value this parameters.
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.
void checkIds() const
Check that any indices of this parameter are in range.
Base class for field theoretic PS-FTS simulator.
Definition Simulator.h:93
Solver and descriptor for a solvent species.
Base class template for classes that represent a complete 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
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