PSCF v1.5.0
r1/sweep/LinearSweep.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "LinearSweep.h"
9#include <r1/system/System.h>
10#include <cstdio>
11
12namespace Pscf {
13namespace R1 {
14
15 using namespace Util;
16
20
21 void LinearSweep::readParameters(std::istream& in)
22 {
23 // Call the base class's readParameters function.
25
26 // Read in the number of sweep parameters and allocate.
27 read(in, "nParameter", nParameter_);
28 parameters_.allocate(nParameter_);
29
30 // Set the pointer to the array of specialized parameter types for
31 // each SweepParameter object
32 for (int i = 0; i < nParameter_; ++i) {
33 parameters_[i].setParameterTypesArray(
35 }
36
37 // Read in array of SweepParameters, calling << for each
38 readDArray< SweepParameter >(in, "parameters",
39 parameters_, nParameter_);
40
41 // Verify net zero change in volume fractions if being swept and
42 // every species is closed (open species take up the rest of the
43 // volume, so closed volume fractions may then change freely)
44 if (mixture().isCanonical()) {
45 double sum = 0.0;
46 for (int i = 0; i < nParameter_; ++i) {
47 if (parameters_[i].type() == "phi_polymer"
48 || parameters_[i].type() == "phi_solvent")
49 {
50 sum += parameters_[i].change();
51 }
52 }
53 if (sum > 1.0E-10 || sum < -1.0E-10) {
54 UTIL_THROW("Changes of the volume fractions of a closed "
55 "mixture must add up to zero");
56 }
57 }
58 }
59
61 {
62 // Call base class's setup function
64
65 // Set system pointer and initial value for each parameter object
66 for (int i = 0; i < nParameter_; ++i) {
67 parameters_[i].setSystem(system());
68 parameters_[i].getInitial();
69 }
70 }
71
73 {
74 // Update the system parameter values
75 double newVal;
76 for (int i = 0; i < nParameter_; ++i) {
77 newVal = parameters_[i].initial() + s*parameters_[i].change();
78 parameters_[i].update(newVal);
79 }
80 }
81
82}
83}
84
LinearSweep(System &system)
Constructor.
void setup()
Setup operation at the beginning of a sweep.
void readParameters(std::istream &in)
Read parameters from param file.
void setParameters(double s)
Set the state before an iteration.
virtual void setup()
Setup operation at beginning sweep.
virtual void readParameters(std::istream &in)
Read ns and baseFileName parameters.
Sweep(System &system)
Constructor.
const Mixture & mixture() const
Get Mixture by reference.
const System & system() const
Get parent System by reference.
Main class in SCFT simulation of one system.
GArray< ParameterType > parameterTypes_
Definition SweepTmpl.h:311
Dynamically allocatable contiguous array template.
Definition DArray.h:32
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_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
SCFT with real 1D fields.
PSCF package top-level namespace.