13#include <rp/solvers/Mixture.h>
14#include <rp/solvers/Polymer.h>
15#include <rp/solvers/Solvent.h>
16#include <rp/solvers/Block.h>
17#include <rp/solvers/Propagator.h>
18#include <rp/field/FieldIo.h>
20#include <pscf/field/FFT.h>
21#include <pscf/field/RField.h>
22#include <pscf/crystal/UnitCell.h>
24#include <pscf/backend/VecOp.h>
25#include <pscf/mesh/Mesh.h>
26#include <pscf/chem/Monomer.h>
27#include <pscf/chem/PolymerModel.h>
29#include <util/containers/DArray.h>
30#include <util/misc/ioUtil.h>
31#include <util/misc/FileMaster.h>
33#include <pscf/solvers/MixtureTmpl.tpp>
45 template <
int D,
class T>
50 unitCellPtr_(nullptr),
61 template <
int D,
class T>
68 template <
int D,
class T>
87 useBatchedFFT_ =
true;
95 template <
int D,
class T>
110 unitCellPtr_ = &cell;
117 polymer(i).setNParams(nParam_);
118 for (j = 0; j <
polymer(i).nBlock(); ++j) {
119 polymer(i).block(j).associate(
mesh, fft, cell, waveList);
125 if (nSolvent() > 0) {
126 for (
int i = 0; i < nSolvent(); ++i) {
127 solvent(i).associate(mesh);
136 template <
int D,
class T>
143 template <
int D,
class T>
158 if (nSolvent() > 0) {
159 for (
int i = 0; i < nSolvent(); ++i) {
160 solvent(i).allocate();
172 template <
int D,
class T>
189 for (i = 0; i < nm; ++i) {
198 polymer(i).compute(wFields, phiTot);
203 for (j = 0; j <
polymer(i).nBlock(); ++j) {
204 monomerId =
polymer(i).block(j).monomerId();
207 FieldT& monomerField = cFields[monomerId];
220 monomerId =
solvent(i).monomerId();
221 solvent(i).compute(wFields[monomerId], phiTot);
226 monomerId =
solvent(i).monomerId();
229 FieldT& monomerField = cFields[monomerId];
236 isSymmetric_ =
false;
243 template <
int D,
class T>
245 { isSymmetric_ = isSymmetric; }
250 template <
int D,
class T>
259 for (i = 0; i < nParam_; ++i) {
263 if (nPolymer() > 0) {
266 for (i = 0; i < nPolymer(); ++i) {
267 polymer(i).computeStress();
271 for (i = 0; i < nParam_; ++i) {
273 stress_[i] +=
polymer(j).stress(i);
281 for (i = 0; i < nParam_; ++i) {
282 stress_[i] /= phiTot;
296 template <
int D,
class T>
300 monomer(monomerId).setKuhn(kuhn);
303 for (
int i = 0; i <
nPolymer(); ++i) {
304 for (
int j = 0; j <
polymer(i).nBlock(); ++j) {
306 if (monomerId == block.monomerId()) {
317 template <
int D,
class T>
321 for (
int i = 0; i <
nPolymer(); ++i) {
322 polymer(i).clearUnitCellData();
334 template <
int D,
class T>
void
351 for (i = 0; i < np; ++i) {
352 if (!blockCFields[i].isAllocated()) {
353 blockCFields[i].
allocate(mesh().dimensions());
362 if (nPolymer() > 0) {
363 for (i = 0; i < nPolymer(); ++i) {
364 for (j = 0; j < polymer(i).nBlock(); ++j) {
368 blockCFields[sectionId] = polymer(i).block(j).cField();
376 if (nSolvent() > 0) {
377 for (i = 0; i < nSolvent(); ++i) {
381 blockCFields[sectionId] =
solvent(i).cField();
393 template <
int D,
class T>
404 for (
int i = 0; i < np; i++) {
412 fieldIo().writeFieldsRGrid(filename, blockCFields,
421 template <
int D,
class T>
423 std::string
const & filename,
439 propagator = polymerRef.
propagator(blockId, directionId);
440 FieldT const & field = propagator.q(sliceId);
447 template <
int D,
class T>
449 std::string
const & filename,
452 int directionId)
const
464 field = polymerRef.
propagator(blockId, directionId).tail();
471 template <
int D,
class T>
473 std::string
const & filename,
476 int directionId)
const
488 propagator = polymerRef.
propagator(blockId, directionId);
489 int ns = propagator.ns();
493 fieldIo().fileMaster().openOutputFile(filename, file);
497 file <<
"mesh" << std::endl
499 <<
"nslice" << std::endl
500 <<
" " << ns << std::endl;
503 bool hasHeader =
false;
504 for (
int i = 0; i < ns; ++i) {
505 file <<
"slice " << i << std::endl;
515 template <
int D,
class T>
519 std::string filename;
520 int np, nb, ip, ib, id;
522 for (ip = 0; ip < np; ++ip) {
524 for (ib = 0; ib < nb; ++ib) {
525 for (
id = 0;
id < 2; ++id) {
534 writeQ(filename, ip, ib,
id);
545 template <
int D,
class T>
550 out <<
"stress:" << std::endl;
552 for (
int i = 0; i < nParam_; i++) {
555 <<
Dbl(stress_[i], 18, 11)
566 template <
int D,
class T>
567 void Mixture<D,T>::allocateBlocks()
569 const int np = CompositionT::nPolymer();
571 for (i = 0; i < np; ++i) {
572 for (j = 0; j < polymer(i).nBlock(); ++j) {
573 polymer(i).block(j).allocate(ds_, useBatchedFFT_);
Monomer const & monomer(int id) const
Description of a regular grid of points in a periodic domain.
IntVec< D > dimensions() const
Get an IntVec<D> of the grid dimensions.
int size() const
Get total number of grid points.
void readParameters(std::istream &in) override
Read parameters from file and initialize.
int nBlock() const
Number of blocks.
PT & propagator(int blockId, int directionId)
Get the propagator for a specific block and direction (non-const).
File input/output, format conversions and other utilities for fields.
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.
Polymer< D, T > PolymerT
Polymer object type.
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)
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
void allocate()
Allocate required internal memory for all solvers.
void associate(Mesh< D > const &mesh, FFT< D, T > const &fft, UnitCell< D > const &cell, WaveList< D, T > &waveList)
Create associations with Mesh, FFT, UnitCell, and WaveList objects.
Block< D, T > BlockT
Block type, for a block in a block polymer.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
FieldIo< D, T > const & fieldIo() const
Return associated FieldIo by const reference.
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 createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
Propagator< D, T > PropagatorT
Propagator type, for one direction within a block.
void setFieldIo(FieldIo< D, T > const &fieldIo)
Create an association with a FieldIo object.
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields, double phiTot=1.0)
Compute partition functions and concentrations.
UnitCell< D > const & unitCell() const
Return associated UnitCell<D> by const reference.
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.
PolymerT & polymer(int id)
Mixture()
Default constructor.
int nParameter() const
Get the number of parameters in the unit cell.
Base template for UnitCell<D> classes, D=1, 2 or 3.
int capacity() const
Return allocated size.
bool isAllocated() const
Does this array have associated data?
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
Dbl()
Default constructor.
Int()
Default constructor.
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.
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.
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 ?
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.