12#include <prdc/crystal/UnitCell.h>
13#include <pscf/solvers/MixtureTmpl.tpp>
14#include <pscf/mesh/Mesh.h>
15#include <pscf/chem/Monomer.h>
16#include <pscf/chem/PolymerModel.h>
17#include <util/containers/DArray.h>
18#include <util/misc/ioUtil.h>
19#include <util/misc/FileMaster.h>
32 template <
int D,
class T>
37 unitCellPtr_(nullptr),
47 template <
int D,
class T>
54 template <
int D,
class T>
76 template <
int D,
class T>
99 for (j = 0; j <
polymer(i).nBlock(); ++j) {
100 polymer(i).block(j).associate(
mesh, fft, cell, waveList);
107 for (
int i = 0; i <
nSolvent(); ++i) {
117 template <
int D,
class T>
124 template <
int D,
class T>
139 if (nSolvent() > 0) {
140 for (
int i = 0; i < nSolvent(); ++i) {
141 solvent(i).allocate();
153 template <
int D,
class T>
170 for (i = 0; i < nm; ++i) {
179 polymer(i).compute(wFields, phiTot);
184 for (j = 0; j <
polymer(i).nBlock(); ++j) {
185 monomerId =
polymer(i).block(j).monomerId();
188 FieldT& monomerField = cFields[monomerId];
197 if (nSolvent() > 0) {
200 for (i = 0; i < nSolvent(); ++i) {
201 monomerId = solvent(i).monomerId();
202 solvent(i).compute(wFields[monomerId], phiTot);
207 monomerId =
solvent(i).monomerId();
210 FieldT& monomerField = cFields[monomerId];
217 isSymmetric_ =
false;
224 template <
int D,
class T>
226 { isSymmetric_ = isSymmetric; }
231 template <
int D,
class T>
240 for (i = 0; i < nParam_; ++i) {
252 for (i = 0; i < nParam_; ++i) {
254 stress_[i] +=
polymer(j).stress(i);
262 for (i = 0; i < nParam_; ++i) {
263 stress_[i] /= phiTot;
277 template <
int D,
class T>
281 monomer(monomerId).setKuhn(kuhn);
284 for (
int i = 0; i <
nPolymer(); ++i) {
285 for (
int j = 0; j <
polymer(i).nBlock(); ++j) {
287 if (monomerId == block.monomerId()) {
298 template <
int D,
class T>
302 for (
int i = 0; i <
nPolymer(); ++i) {
303 polymer(i).clearUnitCellData();
315 template <
int D,
class T>
void
322 int nx =
mesh().size();
332 for (i = 0; i < np; ++i) {
333 if (!blockCFields[i].isAllocated()) {
334 blockCFields[i].
allocate(mesh().dimensions());
345 for (j = 0; j <
polymer(i).nBlock(); ++j) {
349 blockCFields[sectionId] =
polymer(i).block(j).cField();
357 if (nSolvent() > 0) {
358 for (i = 0; i < nSolvent(); ++i) {
362 blockCFields[sectionId] =
solvent(i).cField();
374 template <
int D,
class T>
385 for (
int i = 0; i < np; i++) {
393 fieldIo().writeFieldsRGrid(filename, blockCFields,
402 template <
int D,
class T>
404 std::string
const & filename,
420 propagator = polymerRef.propagator(blockId, directionId);
421 FieldT const & field = propagator.q(sliceId);
428 template <
int D,
class T>
430 std::string
const & filename,
433 int directionId)
const
445 field = polymerRef.propagator(blockId, directionId).tail();
452 template <
int D,
class T>
454 std::string
const & filename,
457 int directionId)
const
469 propagator = polymerRef.propagator(blockId, directionId);
470 int ns = propagator.ns();
474 fieldIo().fileMaster().openOutputFile(filename, file);
478 file <<
"mesh" << std::endl
479 <<
" " <<
mesh().dimensions() << std::endl
480 <<
"nslice" << std::endl
481 <<
" " << ns << std::endl;
484 bool hasHeader =
false;
485 for (
int i = 0; i < ns; ++i) {
486 file <<
"slice " << i << std::endl;
496 template <
int D,
class T>
500 std::string filename;
501 int np, nb, ip, ib, id;
503 for (ip = 0; ip < np; ++ip) {
505 for (ib = 0; ib < nb; ++ib) {
506 for (
id = 0;
id < 2; ++id) {
515 writeQ(filename, ip, ib,
id);
526 template <
int D,
class T>
531 out <<
"stress:" << std::endl;
533 for (
int i = 0; i < nParam_; i++) {
536 <<
Dbl(stress_[i], 18, 11)
Description of a regular grid of points in a periodic domain.
Monomer const & monomer(int id) const
void readParameters(std::istream &in) override
Read parameters from file and initialize.
int nParameter() const
Get the number of parameters in the unit cell.
Base template for UnitCell<D> classes, D=1, 2 or 3.
typename Types< D >::RField FieldT
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
void writeQ(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the complete propagator for one block, in r-grid format.
void writeQSlice(std::string const &filename, int polymerId, int blockId, int directionId, int segmentId) const
Write one slice of a propagator at fixed s in r-grid format.
void writeStress(std::ostream &out) const
Write stress values to output stream.
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
SolventT & solvent(int id)
Get a solvent solver object.
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
void allocate()
Allocate required internal memory for all solvers.
typename T::Polymer PolymerT
Polymer object type.
typename T::Propagator PropagatorT
Propagator type, for one direction within a block.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
typename T::WaveList WaveListT
WaveList type.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
void writeBlockCRGrid(std::string const &filename) const
Write c fields for all blocks and solvents in r-grid format.
void associate(Mesh< D > const &mesh, FFTT const &fft, UnitCell< D > const &cell, WaveListT &waveList)
Create associations with Mesh, FFT, UnitCell, and WaveList objects.
typename Types< D >::Block BlockT
void createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
FieldIoT const & fieldIo() const
Return associated FieldIoT by const reference.
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields, double phiTot=1.0)
Compute partition functions and concentrations.
typename T::FFT FFTT
WaveList type.
UnitCell< D > const & unitCell() const
void setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
typename T::FieldIo FieldIoT
FieldIo type.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
bool isAllocated() const
Return true if this DArray has been allocated, false otherwise.
Wrapper for a double precision number, for formatted ostream output.
Wrapper for an int, for formatted ostream output.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
std::string toString(int n)
Return string representation of an integer.
void addEqV(Array< double > &a, Array< double > const &b)
Vector-vector in-place addition, a[i] += b[i] (real).
void eqS(Array< double > &a, double b)
Vector assignment, a[i] = b (real).
bool isThread()
Is the thread model in use ?
Periodic fields and crystallography.
Class templates for real-valued periodic fields.
PSCF package top-level namespace.