PSCF v1.5.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 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "LinearSweep.h"
12#include <rp/system/System.h>
13#include <rp/solvers/Mixture.h>
14
15namespace Pscf {
16namespace Rp {
17
18 using namespace Util;
19
20 template <int D, class T>
24
25 template <int D, class T>
26 void LinearSweep<D,T>::readParameters(std::istream& in)
27 {
28 // Call the base class's readParameters function
30
31 // Read the number of sweep parameters, allocate parameters_ array
32 ParamComposite::read(in, "nParameter", nParameter_);
33 parameters_.allocate(nParameter_);
34
35 // Set the pointer to the array of specialized parameter types for
36 // each SweepParameter object
37 for (int i = 0; i < nParameter_; ++i) {
38 parameters_[i].setParameterTypesArray(SweepTmplT::parameterTypes_);
39 }
40
41 // Read array of SweepParameters, calling << operator for each
42 ParamComposite::readDArray(in, "parameters", parameters_,nParameter_);
43
44 // Verify net zero change in volume fractions, if these are swept
45 // and every species is closed (with open species, which take up
46 // the rest of the volume, the closed volume fractions may change
47 // independently)
48 if (system().mixture().isCanonical()) {
49 double sum = 0.0;
50 for (int i = 0; i < nParameter_; ++i) {
51 if (parameters_[i].type() == "phi_polymer" ||
52 parameters_[i].type() == "phi_solvent")
53 { sum += parameters_[i].change(); }
54 }
55 if (sum > 1.0E-10 || sum < -1.0E-10) {
56 UTIL_THROW("Changes of the volume fractions of a closed "
57 "mixture must add up to zero");
58 }
59 }
60 }
61
62 template <int D, class T>
64 {
65 // Verify that the LinearSweep has a pointer to parent System
67
68 // Call base class setup function
70
71 // Set system pointer and initial value for each parameter object
72 for (int i = 0; i < nParameter_; ++i) {
73 parameters_[i].setSystem(system());
74 parameters_[i].getInitial();
75 }
76 }
77
78 template <int D, class T>
80 {
81 // Update the system parameter values
82 double newVal;
83 for (int i = 0; i < nParameter_; ++i) {
84 newVal = parameters_[i].initial() + s*parameters_[i].change();
85 parameters_[i].update(newVal);
86 }
87 }
88
89 template <int D, class T>
90 void LinearSweep<D,T>::outputSummary(std::ostream& out)
91 {}
92
93}
94}
95#endif
void readParameters(std::istream &in)
Read parameters from param file.
void setParameters(double s)
Set state parameters before solving an SCFT problem.
System< D, T > & system()
Return the parent system by reference.
void setup()
Setup operation at the beginning of a sweep.
void outputSummary(std::ostream &out)
Output data to a running summary.
LinearSweep(System< D, T > &system)
Constructor.
virtual void setup()
Setup operation at the beginning of a sweep.
Definition Sweep.tpp:115
bool hasSystem()
Does an association with the parent system exist?
virtual void readParameters(std::istream &in)
Read parameters from param file.
Definition Sweep.tpp:88
Base class template for classes that represent a complete system.
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
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.