PSCF v1.4.0
LinearSweep.tpp
1#ifndef RP_LINEAR_SWEEP_TPP
2#define RP_LINEAR_SWEEP_TPP
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 "LinearSweep.h"
12
13namespace Pscf {
14namespace Rp {
15
16 using namespace Util;
17
18 template <int D, class T>
19 LinearSweep<D,T>::LinearSweep(typename T::System& system)
20 : SweepT(system)
21 {}
22
23 template <int D, class T>
24 void LinearSweep<D,T>::readParameters(std::istream& in)
25 {
26 // Call the base class's readParameters function
27 SweepT::readParameters(in);
28
29 // Read the number of sweep parameters, allocate parameters_ array
30 ParamComposite::read(in, "nParameter", nParameter_);
31 parameters_.allocate(nParameter_);
32
33 // Set the pointer to the array of specialized parameter types for
34 // each SweepParameter object
35 for (int i = 0; i < nParameter_; ++i) {
36 parameters_[i].setParameterTypesArray(SweepTmplT::parameterTypes_);
37 }
39 // Read array of SweepParameters, calling << operator for each
40 ParamComposite::readDArray(in, "parameters", parameters_,nParameter_);
41
42 // Verify net zero change in volume fractions, if these are swept
43 double sum = 0.0;
44 for (int i = 0; i < nParameter_; ++i) {
45 if (parameters_[i].type() == "phi_polymer" ||
46 parameters_[i].type() == "phi_solvent")
47 { sum += parameters_[i].change(); }
48 }
49 UTIL_CHECK(sum > -0.000001);
50 UTIL_CHECK(sum < 0.000001);
51 }
52
53 template <int D, class T>
55 {
56 // Verify that the LinearSweep has a pointer to parent System
57 UTIL_CHECK(SweepT::hasSystem());
58
59 // Call base class setup function
60 SweepT::setup();
62 // Set system pointer and initial value for each parameter object
63 for (int i = 0; i < nParameter_; ++i) {
64 parameters_[i].setSystem(system());
65 parameters_[i].getInitial();
66 }
67 }
68
69 template <int D, class T>
71 {
72 // Update the system parameter values
73 double newVal;
74 for (int i = 0; i < nParameter_; ++i) {
75 newVal = parameters_[i].initial() + s*parameters_[i].change();
76 parameters_[i].update(newVal);
77 }
78 }
79
80 template <int D, class T>
81 void LinearSweep<D,T>::outputSummary(std::ostream& out)
82 {}
83
84}
85}
86#endif
LinearSweep(typename T::System &system)
Constructor.
void readParameters(std::istream &in)
Read parameters from param file.
void setParameters(double s)
Set state parameters before solving an SCFT problem.
void setup()
Setup operation at the beginning of a sweep.
void outputSummary(std::ostream &out)
Output data to a running summary.
GArray< ParameterType > parameterTypes_
Definition SweepTmpl.h:311
DArrayParam< Type > & readDArray(std::istream &in, const char *label, DArray< Type > &array, int n)
Add and read a required DArray < Type > parameter.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Class templates for real-valued periodic fields.
PSCF package top-level namespace.