PSCF v1.1
pspg/sweep/LinearSweep.tpp
1#ifndef PSPG_LINEAR_SWEEP_TPP
2#define PSPG_LINEAR_SWEEP_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, 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#include <pspg/System.h>
13#include <cstdio>
14
15namespace Pscf {
16namespace Pspg {
17
18 using namespace Util;
19
20 template <int D>
22 : Sweep<D>(system)
23 {}
24
25 template <int D>
26 void LinearSweep<D>::readParameters(std::istream& in)
27 {
28 // Call the base class's readParameters function.
30
31 // Read in the number of sweep parameters and allocate.
32 this->read(in, "nParameter", nParameter_);
33 parameters_.allocate(nParameter_);
34
35 // Read in array of SweepParameters, calling << for each
36 this->template readDArray< SweepParameter<D> >(in, "parameters", parameters_, nParameter_);
37
38 // Verify net zero change in volume fractions if being swept
39 double sum = 0.0;
40 for (int i = 0; i < nParameter_; ++i) {
41 if (parameters_[i].type() == "phi_polymer" || parameters_[i].type() == "phi_solvent") {
42 sum += parameters_[i].change();
43 }
44 }
45 UTIL_CHECK(sum > -0.000001);
46 UTIL_CHECK(sum < 0.000001);
47 }
48
49 template <int D>
51 {
52 // Verify that the LinearSweep has a system pointer
53 UTIL_CHECK(hasSystem());
54
55 // Call base class's setup function
57
58 // Set system pointer and initial value for each parameter object
59 for (int i = 0; i < nParameter_; ++i) {
60 parameters_[i].setSystem(system());
61 parameters_[i].getInitial();
62 }
63 }
64
65 template <int D>
67 {
68 // Update the system parameter values
69 double newVal;
70 for (int i = 0; i < nParameter_; ++i) {
71 newVal = parameters_[i].initial() + s*parameters_[i].change();
72 parameters_[i].update(newVal);
73 }
74 }
75
76 template <int D>
77 void LinearSweep<D>::outputSummary(std::ostream& out)
78 {}
79
80}
81}
82
83#endif
void outputSummary(std::ostream &out)
Output data to a running summary.
void readParameters(std::istream &in)
Read parameters from param file.
void setParameters(double s)
Set the state before an iteration.
void setup()
Setup operation at the beginning of a sweep.
LinearSweep(System< D > &system)
Constructor.
Solve a sequence of problems along a line in parameter space.
virtual void readParameters(std::istream &in)
Read parameters from param file.
virtual void setup()
Setup operation at the beginning of a sweep.
Main class in SCFT simulation of one system.
Definition: pspg/System.h:71
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1