10#include <rpc/system/System.h>
11#include <rpc/scft/iterator/Iterator.h>
12#include <rpc/scft/ScftThermo.h>
13#include <prdc/environment/Environment.h>
14#include <pscf/inter/Interaction.h>
15#include <pscf/sweep/SweepTmpl.tpp>
16#include <util/misc/FileMaster.h>
17#include <util/misc/ioUtil.h>
25 # define RPC_HISTORY_CAPACITY 3
51 if (
system().hasEnvironment()) {
108 fileName +=
"sweep.log";
109 system().fileMaster().openOutputFile(fileName, logFile_);
110 logFile_ <<
" step ds free_energy pressure"
123 UTIL_THROW(
"Calling unimplemented function Sweep::setParameters");
141 bool isFlexible =
system().iterator().isFlexible();
148 int nMonomer =
system().mixture().nMonomer();
149 int nBasis =
system().domain().basis().nBasis();
153 for (i=0; i < nMonomer; ++i) {
154 newFieldPtr = &(trial_.field(i));
157 oldFieldPtr = &
state(0).field(i);
159 for (j=0; j < nBasis; ++j) {
160 (*newFieldPtr)[j] = coeff*(*oldFieldPtr)[j];
165 oldFieldPtr = &
state(k).field(i);
167 for (j=0; j < nBasis; ++j) {
168 (*newFieldPtr)[j] += coeff*(*oldFieldPtr)[j];
177 unitCellParameters_ =
system().domain().unitCell().parameters();
186 system().iterator().flexibleParams();
188 =
system().domain().unitCell().nParameter();
194 for (
int i = 0; i < nParameter; ++i) {
197 unitCellParameters_[i] = 0;
199 parameter =
state(k).unitCell().parameter(i);
200 unitCellParameters_[i] += coeff*parameter;
207 trial_.unitCell().setParameters(unitCellParameters_);
210 bool newCellParams(
true);
211 for (
int i = 0; i < oldParameters.
size(); i++) {
212 if (fabs(oldParameters[i] - unitCellParameters_[i]) < 1e-10) {
213 newCellParams =
false;
219 trial_.setSystemState(newCellParams);
232 {
return system().iterate(isContinuation); };
243 bool isFlexible =
system().iterator().isFlexible();
244 state(0).setSystemState(isFlexible);
258 state(0).getSystemState();
264 outputSummary(logFile_);
269 void Sweep<D>::outputSolution()
272 std::string outFileName;
273 std::string indexString =
toString(nAccept() - 1);
276 outFileName = baseFileName_;
277 outFileName += indexString;
278 outFileName +=
".stt";
279 system().fileMaster().openOutputFile(outFileName, out);
282 system().writeParamNoSweep(out);
284 system().scft().write(out);
287 FieldIo<D> const & fieldIo = system().domain().fieldIo();
288 UnitCell<D> const & unitCell = system().domain().unitCell();
291 outFileName = baseFileName_;
292 outFileName += indexString;
294 outFileName +=
".bf";
298 system().w().basis(), unitCell);
302 outFileName = baseFileName_;
303 outFileName += indexString;
305 outFileName +=
".rf";
307 system().c().rgrid(), unitCell);
312 outFileName = baseFileName_;
313 outFileName += indexString;
315 outFileName +=
".bf";
318 system().c().basis(), unitCell);
324 outFileName = baseFileName_;
325 outFileName += indexString;
327 outFileName +=
".rf";
329 system().w().rgrid(), unitCell);
335 void Sweep<D>::outputSummary(std::ostream& out)
337 int i = nAccept() - 1;
339 if (!system().scft().hasData()) system().scft().compute();
340 out <<
Int(i,5) <<
Dbl(sNew)
341 <<
Dbl(system().scft().fHelmholtz(),16)
342 <<
Dbl(system().scft().pressure(),16);
348 { logFile_.close(); }
Base template for UnitCell<D> classes, D=1, 2 or 3.
FieldState for fields in symmetry-adapted basis format.
File input/output operations and format conversions for fields.
void writeFieldsRGrid(std::ostream &out, DArray< RField< D > > const &fields, UnitCell< D > const &unitCell, bool writeHeader=true, bool isSymmetric=true, bool writeMeshSize=true) const override
Write array of RField objects (fields on r-space grid) to a stream.
void writeFieldsBasis(std::ostream &out, DArray< DArray< double > > const &fields, UnitCell< D > const &unitCell) const
Write an array of fields in basis format to an output stream.
virtual int solve(bool isContinuation)
Call current iterator to solve SCFT problem.
virtual void extrapolate(double sNew)
Create a guess for adjustable variables by continuation.
void setSystem(System< D > &system)
Set association with parent System.
Sweep()
Default Constructor.
virtual void getSolution()
Update state(0) and output data after successful convergence.
virtual void checkAllocation(BasisFieldState< D > &state)
Check allocation of fields in one state, allocate if necessary.
System< D > & system()
Return the parent system by reference.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
virtual void reset()
Reset system to previous solution after iterature failure.
bool writeCRGrid_
Should concentration fields be written to file in r-grid format?
virtual void cleanup()
Cleanup operation at the beginning of a sweep.
bool writeCBasis_
Should concentration fields be written to file in basis format?
virtual void readParameters(std::istream &in)
Read parameters from param file.
virtual void setParameters(double sNew)=0
Set system parameters to new values.
bool writeWRGrid_
Should converged w fields be written to file in r-grid format?
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.
void addParameterTypes(GArray< ParameterType > paramTypes)
BasisFieldState< D > & state(int i)
std::string baseFileName_
SweepTmpl(int historyCapacity)
void setCoefficients(double sNew)
int historyCapacity() const
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.
Real periodic fields, SCFT and PS-FTS (CPU).
PSCF package top-level namespace.