10#include <rpg/system/System.h>
11#include <rpg/scft/iterator/Iterator.h>
12#include <rpg/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 RPG_HISTORY_CAPACITY 3
51 if (
system().hasEnvironment()) {
108 fileName +=
"sweep.log";
109 system().fileMaster().openOutputFile(fileName, logFile_);
121 UTIL_THROW(
"Calling unimplemented function Sweep::setParameters");
139 bool isFlexible =
system().iterator().isFlexible();
146 int nMonomer =
system().mixture().nMonomer();
147 int nBasis =
system().domain().basis().nBasis();
151 for (i=0; i < nMonomer; ++i) {
152 newFieldPtr = &(trial_.field(i));
155 oldFieldPtr = &
state(0).field(i);
157 for (j=0; j < nBasis; ++j) {
158 (*newFieldPtr)[j] = coeff*(*oldFieldPtr)[j];
163 oldFieldPtr = &
state(k).field(i);
165 for (j=0; j < nBasis; ++j) {
166 (*newFieldPtr)[j] += coeff*(*oldFieldPtr)[j];
175 unitCellParameters_ =
system().domain().unitCell().parameters();
185 const int nParameter = indices.
size();
190 for (
int i = 0; i < nParameter; ++i) {
192 unitCellParameters_[indices[i]] = 0;
194 parameter =
state(k).unitCell().parameter(indices[i]);
195 unitCellParameters_[indices[i]] += coeff*parameter;
201 const int nParameter = unitCellParameters_.size();
204 for (
int i = 0; i < nParameter; ++i) {
206 unitCellParameters_[i] = 0.0;
208 parameter =
state(k).unitCell().parameter(i);
209 unitCellParameters_[i] += coeff*parameter;
216 trial_.unitCell().setParameters(unitCellParameters_);
219 bool newCellParams(
true);
220 for (
int i = 0; i < oldParameters.
size(); i++) {
221 if (fabs(oldParameters[i] - unitCellParameters_[i]) < 1e-10) {
222 newCellParams =
false;
228 trial_.setSystemState(newCellParams);
240 {
return system().iterate(isContinuation); };
251 bool isFlexible =
system().iterator().isFlexible();
252 state(0).setSystemState(isFlexible);
266 state(0).getSystemState();
272 outputSummary(logFile_);
277 void Sweep<D>::outputSolution()
280 std::string outFileName;
281 std::string indexString =
toString(nAccept() - 1);
284 outFileName = baseFileName_;
285 outFileName += indexString;
286 outFileName +=
".stt";
287 system().fileMaster().openOutputFile(outFileName, out);
290 system().writeParamNoSweep(out);
292 system().scft().write(out);
296 outFileName = baseFileName_;
297 outFileName += indexString;
299 outFileName +=
".bf";
300 system().w().writeBasis(outFileName);
304 outFileName = baseFileName_;
305 outFileName += indexString;
307 outFileName +=
".rf";
308 system().c().writeRGrid(outFileName);
313 outFileName = baseFileName_;
314 outFileName += indexString;
316 outFileName +=
".bf";
317 system().c().writeBasis(outFileName);
322 outFileName = baseFileName_;
323 outFileName += indexString;
325 outFileName +=
".rf";
326 system().w().writeRGrid(outFileName);
331 void Sweep<D>::outputSummary(std::ostream& out)
333 int i = nAccept() - 1;
335 out <<
Int(i,5) <<
Dbl(sNew)
336 <<
Dbl(system().scft().fHelmholtz(),16)
337 <<
Dbl(system().scft().pressure(),16);
343 { logFile_.close(); }
FieldState for fields in symmetry-adapted basis format.
virtual void getSolution()
Update state(0) and output data after successful convergence.
bool writeCBasis_
Whether to write concentration field files in basis format.
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 checkAllocation(BasisFieldState< D > &state)
Check allocation state of fields in one state, allocate if necessary.
virtual void extrapolate(double sNew)
Create a guess for adjustable variables by continuation.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
virtual void setup()
Setup operation at the beginning of a sweep.
bool writeWRGrid_
Whether to write real space potential field files.
bool writeCRGrid_
Whether to write real space concentration field files.
bool hasSystem()
Has an association with the parent System been set?
virtual void reset()
Reset system to previous solution after iterature failure.
virtual void setParameters(double sNew)=0
Set non-adjustable system parameters to new values.
Sweep()
Default Constructor.
System< D > & system()
Return the parent system by reference.
void setSystem(System< D > &system)
Set association with parent System.
virtual void cleanup()
Cleanup 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.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.