13#include <rp/scft/iterator/Iterator.h>
14#include <rp/scft/ScftThermo.h>
15#include <rp/system/System.h>
16#include <rp/solvers/Mixture.h>
17#include <rp/field/Domain.h>
18#include <rp/field/WFields.h>
19#include <rp/field/CFields.h>
20#include <rp/environment/Environment.h>
22#include <pscf/crystal/Basis.h>
23#include <pscf/crystal/UnitCell.h>
25#include <pscf/interaction/Interaction.h>
27#include <util/misc/FileMaster.h>
28#include <util/misc/ioUtil.h>
30#include <pscf/sweep/SweepTmpl.tpp>
38 #define RP_HISTORY_CAPACITY 3
43 template <
int D,
class T>
45 : SweepTmplT(RP_HISTORY_CAPACITY),
55 template <
int D,
class T>
57 : SweepTmplT(RP_HISTORY_CAPACITY),
64 if (
system().hasEnvironment()) {
66 system().environment().getParameterTypes());
73 template <
int D,
class T>
80 template <
int D,
class T>
87 template <
int D,
class T>
102 template <
int D,
class T>
114 template <
int D,
class T>
126 fileName +=
"sweep.log";
127 system().fileMaster().openOutputFile(fileName, logFile_);
128 logFile_ <<
" step ds free_energy pressure"
137 template <
int D,
class T>
141 UTIL_THROW(
"Calling unimplemented function Sweep::setParameters");
147 template <
int D,
class T>
160 bool isFlexible =
system().iterator().isFlexible();
167 int nMonomer =
system().mixture().nMonomer();
168 int nBasis =
system().domain().basis().nBasis();
172 for (i=0; i < nMonomer; ++i) {
173 newFieldPtr = &(trial_.field(i));
178 for (j=0; j < nBasis; ++j) {
179 (*newFieldPtr)[j] = coeff*(*oldFieldPtr)[j];
186 for (j=0; j < nBasis; ++j) {
187 (*newFieldPtr)[j] += coeff*(*oldFieldPtr)[j];
196 =
system().domain().unitCell().parameters();
197 unitCellParameters_ = systemParameters;
205 =
system().iterator().flexibleParams();
207 =
system().domain().unitCell().nParameter();
213 for (
int i = 0; i < nParameter; ++i) {
216 unitCellParameters_[i] = 0.0;
220 unitCellParameters_[i] += coeff*parameter;
228 trial_.unitCell().setParameters(unitCellParameters_);
232 bool newCellParams(
false);
233 for (
int i = 0; i < systemParameters.
size(); i++) {
234 if (fabs(systemParameters[i] - unitCellParameters_[i]) >= 1e-10) {
235 newCellParams =
true;
241 trial_.setSystemState(newCellParams);
251 template <
int D,
class T>
253 {
return system().iterate(isContinuation); };
261 template <
int D,
class T>
264 bool isFlexible =
system().iterator().isFlexible();
275 template <
int D,
class T>
285 outputSummary(logFile_);
289 template <
int D,
class T>
290 void Sweep<D,T>::outputSolution()
293 std::string outFileName;
294 std::string indexString =
toString(SweepTmplT::nAccept() - 1);
297 outFileName = SweepTmplT::baseFileName_;
298 outFileName += indexString;
299 outFileName +=
".stt";
300 system().fileMaster().openOutputFile(outFileName, out);
303 system().writeParamNoSweep(out);
305 system().scft().write(out);
310 outFileName = SweepTmplT::baseFileName_;
311 outFileName += indexString;
313 if (system().w().isSymmetric()) {
314 outFileName +=
".bf";
315 system().w().writeBasis(outFileName);
317 outFileName +=
".rf";
318 system().w().writeRGrid(outFileName);
324 outFileName = SweepTmplT::baseFileName_;
325 outFileName += indexString;
327 outFileName +=
".rf";
328 system().c().writeRGrid(outFileName);
332 if (writeCBasis_ && system().c().isSymmetric()) {
334 outFileName = SweepTmplT::baseFileName_;
335 outFileName += indexString;
337 outFileName +=
".bf";
338 system().c().writeBasis(outFileName);
342 if (writeWRGrid_ && system().w().isSymmetric()) {
343 outFileName = SweepTmplT::baseFileName_;
344 outFileName += indexString;
346 outFileName +=
".rf";
347 system().w().writeRGrid(outFileName);
352 template <
int D,
class T>
353 void Sweep<D,T>::outputSummary(std::ostream& out)
355 int i = SweepTmplT::nAccept() - 1;
356 double sNew = SweepTmplT::s(0);
357 if (!system().scft().hasData()) system().scft().compute();
358 out <<
Int(i,5) <<
Dbl(sNew)
359 <<
Dbl(system().scft().fHelmholtz(),16)
360 <<
Dbl(system().scft().pressure(),16);
364 template <
int D,
class T>
366 { logFile_.close(); }
void setSystem(ST &system)
Set association with System, after default construction.
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.
bool writeWRGrid_
Should converged w fields be written to file in r-grid format?
Sweep()
Default constructor.
virtual void setup()
Setup operation at the beginning of a sweep.
bool hasSystem()
Does an association with the parent system exist?
virtual void getSolution()
Update state(0) and output data after successful convergence.
bool writeCRGrid_
Should concentration fields be written to file in r-grid format?
virtual void cleanup()
Cleanup operation at the beginning of a sweep.
virtual int solve(bool isContinuation)
Call current iterator to solve SCFT problem.
virtual void setParameters(double sNew)=0
Set system parameters to new values.
void setSystem(System< D, T > &system)
Set association with parent system.
virtual void checkAllocation(BasisFieldState< D, T > &state)
Check allocation of fields in one state, allocate if necessary.
System< D, T > & system()
Return the parent system by reference.
virtual void readParameters(std::istream &in)
Read parameters from param file.
bool writeCBasis_
Should concentration fields be written to file in basis format?
virtual void extrapolate(double sNew)
Create a guess for adjustable variables by continuation.
virtual void reset()
Reset system to previous solution after iterature failure.
Base class template for classes that represent a complete system.
void addParameterTypes(GArray< ParameterType > paramTypes)
BasisFieldState< D, T > & state(int i)
std::string baseFileName_
void setCoefficients(double sNew)
virtual void readParameters(std::istream &in)
int historyCapacity() const
Dynamically allocatable contiguous array template.
Dbl()
Default constructor.
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).
Int()
Default constructor.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#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.
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.