PSCF v1.3
rpc/scft/sweep/LinearSweep.tpp
1#ifndef RPC_LINEAR_SWEEP_TPP
2#define RPC_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#include <rpc/system/System.h>
13
14namespace Pscf {
15namespace Rpc {
16
17 using namespace Util;
18
19 template <int D>
23
24 template <int D>
25 void LinearSweep<D>::readParameters(std::istream& in)
26 {
27 // Call the base class's readParameters function
29
30 // Read the number of sweep parameters, allocate parameters_ array
31 read(in, "nParameter", nParameter_);
32 parameters_.allocate(nParameter_);
33
34 // Set the pointer to the array of specialized parameter types for
35 // each SweepParameter object
36 for (int i = 0; i < nParameter_; ++i) {
37 parameters_[i].setParameterTypesArray(
39 }
40
41 // Read array of SweepParameters, calling << operator for each
42 readDArray(in, "parameters", parameters_, nParameter_);
43
44 // Verify net zero change in volume fractions, if these are swept
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 UTIL_CHECK(sum > -0.000001);
54 UTIL_CHECK(sum < 0.000001);
55 }
56
57 template <int D>
59 {
60 // Verify that the LinearSweep has a pointer to parent System
62
63 // Call base class setup function
65
66 // Set system pointer and initial value for each parameter object
67 for (int i = 0; i < nParameter_; ++i) {
68 parameters_[i].setSystem(system());
69 parameters_[i].getInitial();
70 }
71 }
72
73 template <int D>
75 {
76 // Update the system parameter values
77 double newVal;
78 for (int i = 0; i < nParameter_; ++i) {
79 newVal = parameters_[i].initial() + s*parameters_[i].change();
80 parameters_[i].update(newVal);
81 }
82 }
83
84 template <int D>
85 void LinearSweep<D>::outputSummary(std::ostream& out)
86 {}
87
88}
89}
90
91#endif
FieldState for fields in symmetry-adapted basis format.
DArrayParam< Type > & readDArray(std::istream &in, const char *label, DArray< Type > &array, int n)
Add and read a required DArray < Type > parameter.
void readParameters(std::istream &in)
Read parameters from param file.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setup()
Setup operation at the beginning of a sweep.
void outputSummary(std::ostream &out)
Output data to a running summary.
void setParameters(double s)
Set state parameters before solving an SCFT problem.
LinearSweep(System< D > &system)
Constructor.
Sweep()
Default Constructor.
System< D > & system()
Return the parent system by reference.
virtual void readParameters(std::istream &in)
Read parameters from param file.
bool hasSystem()
Does an association with the parent System exist?
virtual void setup()
Setup operation at the beginning of a sweep.
Main class, representing one complete system.
Solve a sequence of problems along a path through parameter space.
Definition SweepTmpl.h:28
GArray< ParameterType > parameterTypes_
Definition SweepTmpl.h:105
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1