10#include <pspc/System.h>
11#include <pscf/inter/Interaction.h>
12#include <pscf/sweep/SweepTmpl.tpp>
13#include <util/misc/FileMaster.h>
14#include <util/misc/ioUtil.h>
22 # define PSPC_HISTORY_CAPACITY 3
60 { systemPtr_ = &system; }
72 readOptional(in,
"writeCRGrid", writeCRGrid_);
73 readOptional(in,
"writeCBasis", writeCBasis_);
74 readOptional(in,
"writeWRGrid", writeWRGrid_);
86 state.
unitCell() = system().unitCell();
96 checkAllocation(trial_);
99 std::string fileName = baseFileName_;
100 fileName +=
"sweep.log";
101 system().fileMaster().openOutputFile(fileName, logFile_);
102 logFile_ <<
" step ds free_energy pressure"
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 system().iterator().flexibleParams();
179 const int nParameter = system().unitCell().nParameter();
183 for (k = 0; k < historySize(); ++k) {
185 for (
int i = 0; i < nParameter; ++i) {
188 unitCellParameters_[i] = 0;
190 parameter = state(k).unitCell().parameter(i);
191 unitCellParameters_[i] += coeff*parameter;
198 trial_.unitCell().setParameters(unitCellParameters_);
201 bool newCellParams(
true);
202 for (
int i = 0; i < oldParameters.
size(); i++) {
203 if (fabs(oldParameters[i] - unitCellParameters_[i]) < 1e-10) {
204 newCellParams =
false;
210 trial_.setSystemState(newCellParams);
223 {
return system().iterate(isContinuation); };
234 bool isFlexible = system().iterator().isFlexible();
235 state(0).setSystemState(isFlexible);
248 state(0).setSystem(system());
249 state(0).getSystemState();
255 outputSummary(logFile_);
263 std::string outFileName;
264 std::string indexString =
toString(nAccept() - 1);
267 outFileName = baseFileName_;
268 outFileName += indexString;
269 outFileName +=
".stt";
270 system().fileMaster().openOutputFile(outFileName, out);
273 system().writeParamNoSweep(out);
275 system().writeThermo(out);
279 outFileName = baseFileName_;
280 outFileName += indexString;
282 outFileName +=
".bf";
285 system().fieldIo().writeFieldsBasis(outFileName,
286 system().w().basis(),
287 system().unitCell());
291 outFileName = baseFileName_;
292 outFileName += indexString;
294 outFileName +=
".rf";
295 system().fieldIo().writeFieldsRGrid(outFileName,
296 system().c().rgrid(),
297 system().unitCell());
302 outFileName = baseFileName_;
303 outFileName += indexString;
305 outFileName +=
".bf";
307 system().fieldIo().writeFieldsBasis(outFileName,
308 system().c().basis(),
309 system().unitCell());
314 outFileName = baseFileName_;
315 outFileName += indexString;
317 outFileName +=
".rf";
318 system().fieldIo().writeFieldsRGrid(outFileName,
319 system().w().rgrid(),
320 system().unitCell());
325 void Sweep<D>::outputSummary(std::ostream& out)
327 int i = nAccept() - 1;
329 if (!system().hasFreeEnergy()) system().computeFreeEnergy();
330 out <<
Int(i,5) <<
Dbl(sNew)
331 <<
Dbl(system().fHelmholtz(),16)
332 <<
Dbl(system().pressure(),16);
338 { 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 setup()
Setup operation at the beginning of a sweep.
virtual int solve(bool isContinuation)
Call current iterator to solve SCFT problem.
void setSystem(System< D > &system)
Set association with parent System.
virtual void setParameters(double sNew)=0
Set non-adjustable system parameters to new values.
virtual void extrapolate(double sNew)
Create a guess for adjustable variables by continuation.
Sweep()
Default Constructor.
virtual void cleanup()
Cleanup operation at the beginning of a sweep.
virtual void reset()
Reset system to previous solution after iterature failure.
virtual void checkAllocation(BasisFieldState< D > &state)
Check allocation state of fields in one state, allocate if necessary.
virtual void getSolution()
Update state(0) and output data after successful convergence.
virtual void readParameters(std::istream &in)
Read parameters from param file.
Main class for 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.