10#include <pscf/sweep/SweepTmpl.tpp>
11#include <pspg/System.h>
12#include <pspg/iterator/Iterator.h>
13#include <pscf/inter/Interaction.h>
15#include <util/misc/FileMaster.h>
16#include <util/misc/ioUtil.h>
24 #define PSPG_HISTORY_CAPACITY 3
62 { systemPtr_ = &system; }
74 readOptional(in,
"writeCRGrid", writeCRGrid_);
75 readOptional(in,
"writeCBasis", writeCBasis_);
76 readOptional(in,
"writeWRGrid", writeWRGrid_);
88 state.
unitCell() = system().unitCell();
98 checkAllocation(trial_);
101 std::string fileName = baseFileName_;
102 fileName +=
"sweep.log";
103 system().fileMaster().openOutputFile(fileName, logFile_);
115 UTIL_THROW(
"Calling unimplemented function Sweep::setParameters");
129 if (historySize() > 1) {
130 UTIL_CHECK(historySize() <= historyCapacity());
133 bool isFlexible = system().iterator().isFlexible();
136 setCoefficients(sNew);
140 int nMonomer = system().mixture().nMonomer();
141 int nBasis = system().basis().nBasis();
145 for (i=0; i < nMonomer; ++i) {
146 newFieldPtr = &(trial_.field(i));
149 oldFieldPtr = &state(0).field(i);
151 for (j=0; j < nBasis; ++j) {
152 (*newFieldPtr)[j] = coeff*(*oldFieldPtr)[j];
156 for (k = 1; k < historySize(); ++k) {
157 oldFieldPtr = &state(k).field(i);
159 for (j=0; j < nBasis; ++j) {
160 (*newFieldPtr)[j] += coeff*(*oldFieldPtr)[j];
169 unitCellParameters_ = system().unitCell().parameters();
178 const FSArray<int,6> indices = system().iterator().flexibleParams();
179 const int nParameter = indices.
size();
182 for (k = 0; k < historySize(); ++k) {
184 for (
int i = 0; i < nParameter; ++i) {
186 unitCellParameters_[indices[i]] = 0;
188 parameter = state(k).unitCell().parameter(indices[i]);
189 unitCellParameters_[indices[i]] += coeff*parameter;
195 const int nParameter = unitCellParameters_.size();
196 for (k = 0; k < historySize(); ++k) {
198 for (
int i = 0; i < nParameter; ++i) {
200 unitCellParameters_[i] = 0.0;
202 parameter = state(k).unitCell().parameter(i);
203 unitCellParameters_[i] += coeff*parameter;
210 trial_.unitCell().setParameters(unitCellParameters_);
213 bool newCellParams(
true);
214 for (
int i = 0; i < oldParameters.
size(); i++) {
215 if (fabs(oldParameters[i] - unitCellParameters_[i]) < 1e-10) {
216 newCellParams =
false;
222 trial_.setSystemState(newCellParams);
234 {
return system().iterate(isContinuation); };
245 bool isFlexible = system().iterator().isFlexible();
246 state(0).setSystemState(isFlexible);
259 state(0).setSystem(system());
260 state(0).getSystemState();
266 outputSummary(logFile_);
274 std::string outFileName;
275 std::string indexString =
toString(nAccept() - 1);
278 outFileName = baseFileName_;
279 outFileName += indexString;
280 outFileName +=
".stt";
281 system().fileMaster().openOutputFile(outFileName, out);
284 out <<
"System{" << std::endl;
285 system().mixture().writeParam(out);
286 system().interaction().writeParam(out);
287 out <<
"}" << std::endl;
289 out <<
"unitCell " << system().unitCell();
290 system().writeThermo(out);
294 outFileName = baseFileName_;
295 outFileName += indexString;
297 outFileName +=
".bf";
298 system().writeWBasis(outFileName);
302 outFileName = baseFileName_;
303 outFileName += indexString;
305 outFileName +=
".rf";
306 system().writeCRGrid(outFileName);
311 outFileName = baseFileName_;
312 outFileName += indexString;
314 outFileName +=
".bf";
315 system().writeCBasis(outFileName);
320 outFileName = baseFileName_;
321 outFileName += indexString;
323 outFileName +=
".rf";
324 system().writeWRGrid(outFileName);
329 void Sweep<D>::outputSummary(std::ostream& out)
331 int i = nAccept() - 1;
333 out <<
Int(i,5) <<
Dbl(sNew)
334 <<
Dbl(system().fHelmholtz(),16)
335 <<
Dbl(system().pressure(),16);
341 { logFile_.close(); }
FieldState for fields in symmetry-adapted basis format.
void allocate()
Allocate all fields.
const UnitCell< D > & unitCell() const
Get UnitCell (i.e., lattice type and parameters) by const reference.
void setSystem(System< D > &system)
Set association with System, after default construction.
Solve a sequence of problems along a line in parameter space.
virtual void getSolution()
Update state(0) and output data after successful convergence.
virtual void setParameters(double sNew)=0
Set non-adjustable system parameters to new values.
virtual int solve(bool isContinuation)
Call current iterator to solve SCFT problem.
virtual void readParameters(std::istream &in)
Read parameters from param file.
virtual void setup()
Setup operation at the beginning of a sweep.
virtual void checkAllocation(BasisFieldState< D > &state)
Check allocation state of fields in one state, allocate if necessary.
virtual void reset()
Reset system to previous solution after iterature failure.
virtual void cleanup()
Cleanup operation at the beginning of a sweep.
void setSystem(System< D > &system)
Set association with parent System.
Sweep()
Default Constructor.
virtual void extrapolate(double sNew)
Create a guess for adjustable variables by continuation.
Main class in SCFT simulation of one system.
Solve a sequence of problems along a path through parameter space.
Dynamically allocatable contiguous array template.
Wrapper for a double precision number, for formatted ostream output.
A fixed capacity (static) contiguous array with a variable logical size.
int size() const
Return logical size of this array (i.e., number of elements).
Wrapper for an int, for formatted ostream output.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
std::string toString(int n)
Return string representation of an integer.
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.