1#ifndef PRDC_MIXTURE_PRDC_TPP
2#define PRDC_MIXTURE_PRDC_TPP
11#include "MixturePrdc.h"
12#include <prdc/crystal/UnitCell.h>
13#include <pscf/mesh/Mesh.h>
14#include <pscf/chem/Monomer.h>
15#include <pscf/chem/PolymerModel.h>
16#include <util/containers/DArray.h>
17#include <util/misc/ioUtil.h>
18#include <util/misc/FileMaster.h>
28 template <
int D,
class PT,
class ST>
33 unitCellPtr_(nullptr),
43 template <
int D,
class PT,
class ST>
50 template <
int D,
class PT,
class ST>
73 template <
int D,
class PT,
class ST>
96 for (j = 0; j <
polymer(i).nBlock(); ++j) {
97 polymer(i).block(j).associate(
mesh, fft, cell, waveList);
103 if (nSolvent() > 0) {
104 for (
int i = 0; i < nSolvent(); ++i) {
114 template <
int D,
class PT,
class ST>
121 template <
int D,
class PT,
class ST>
137 for (
int i = 0; i <
nSolvent(); ++i) {
150 template <
int D,
class PT,
class ST>
167 for (i = 0; i < nm; ++i) {
168 eqS(cFields[i], 0.0);
172 if (nPolymer() > 0) {
175 for (i = 0; i < nPolymer(); ++i) {
176 polymer(i).compute(wFields, phiTot);
180 for (i = 0; i < nPolymer(); ++i) {
181 for (j = 0; j < polymer(i).nBlock(); ++j) {
182 monomerId = polymer(i).block(j).monomerId();
185 FieldT& monomerField = cFields[monomerId];
186 FieldT
const & blockField = polymer(i).block(j).cField();
187 addEqV(monomerField, blockField);
194 if (nSolvent() > 0) {
197 for (i = 0; i < nSolvent(); ++i) {
199 solvent(i).compute(wFields[monomerId], phiTot);
203 for (i = 0; i < nSolvent(); ++i) {
204 monomerId = solvent(i).monomerId();
207 FieldT& monomerField = cFields[monomerId];
208 FieldT
const & solventField = solvent(i).cField();
209 addEqV(monomerField, solventField);
214 isSymmetric_ =
false;
221 template <
int D,
class PT,
class ST>
223 { isSymmetric_ = isSymmetric; }
228 template <
int D,
class PT,
class ST>
237 for (i = 0; i < nParam_; ++i) {
249 for (i = 0; i < nParam_; ++i) {
251 stress_[i] +=
polymer(j).stress(i);
259 for (i = 0; i < nParam_; ++i) {
260 stress_[i] /= phiTot;
274 template <
int D,
class PT,
class ST>
278 monomer(monomerId).setKuhn(kuhn);
281 for (
int i = 0; i <
nPolymer(); ++i) {
282 for (
int j = 0; j <
polymer(i).nBlock(); ++j) {
284 if (monomerId == block.monomerId()) {
295 template <
int D,
class PT,
class ST>
299 for (
int i = 0; i <
nPolymer(); ++i) {
300 polymer(i).clearUnitCellData();
312 template <
int D,
class PT,
class ST>
void
319 int nx =
mesh().size();
329 for (i = 0; i < np; ++i) {
330 if (!blockCFields[i].isAllocated()) {
331 blockCFields[i].
allocate(mesh().dimensions());
333 eqS(blockCFields[i], 0.0);
340 if (nPolymer() > 0) {
341 for (i = 0; i < nPolymer(); ++i) {
342 for (j = 0; j < polymer(i).nBlock(); ++j) {
346 blockCFields[sectionId] =
polymer(i).block(j).cField();
354 if (nSolvent() > 0) {
355 for (i = 0; i < nSolvent(); ++i) {
359 blockCFields[sectionId] = solvent(i).cField();
371 template <
int D,
class PT,
class ST>
382 for (
int i = 0; i < np; i++) {
387 createBlockCRGrid(blockCFields);
390 fieldIo().writeFieldsRGrid(filename, blockCFields,
391 unitCell(), isSymmetric_);
399 template <
int D,
class PT,
class ST>
401 std::string
const & filename,
417 propagator = polymerRef.propagator(blockId, directionId);
418 FieldT const & field = propagator.q(sliceId);
425 template <
int D,
class PT,
class ST>
427 std::string
const & filename,
430 int directionId)
const
442 field = polymerRef.propagator(blockId, directionId).tail();
449 template <
int D,
class PT,
class ST>
451 std::string
const & filename,
454 int directionId)
const
466 propagator = polymerRef.propagator(blockId, directionId);
467 int ns = propagator.ns();
471 fieldIo().fileMaster().openOutputFile(filename, file);
475 file <<
"mesh" << std::endl
476 <<
" " <<
mesh().dimensions() << std::endl
477 <<
"nslice" << std::endl
478 <<
" " << ns << std::endl;
481 bool hasHeader =
false;
482 for (
int i = 0; i < ns; ++i) {
483 file <<
"slice " << i << std::endl;
493 template <
int D,
class PT,
class ST>
497 std::string filename;
498 int np, nb, ip, ib, id;
500 for (ip = 0; ip < np; ++ip) {
502 for (ib = 0; ib < nb; ++ib) {
503 for (
id = 0;
id < 2; ++id) {
512 writeQ(filename, ip, ib,
id);
523 template <
int D,
class PT,
class ST>
528 out <<
"stress:" << std::endl;
530 for (
int i = 0; i < nParam_; i++) {
533 <<
Dbl(stress_[i], 18, 11)
Description of a regular grid of points in a periodic domain.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
void writeBlockCRGrid(std::string const &filename) const
Write c fields for all blocks and solvents in r-grid format.
SolventT & solvent(int id)
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 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.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
void setClassName(const char *className)
Set class name string.
typename PT::BlockT BlockT
Block polymer block type.
typename BlockT::FFTT FFTT
WaveList type.
void associate(Mesh< D > const &mesh, FFTT const &fft, UnitCell< D > const &cell, WaveListT &waveList)
Create associations with Mesh, FFT, UnitCell, and WaveList objects.
void createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
void setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
typename BlockT::WaveListT WaveListT
WaveList type.
int nPolymer() const
Get number of polymer species.
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
PT PolymerT
Polymer species solver type.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
int nMonomer() const
Get number of monomer types.
int nBlock() const
Get total number blocks among all polymer species.
typename BlockT::FieldIoT FieldIoT
FieldIo type.
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.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
int nSolvent() const
Get number of solvent (point particle) species.
MixturePrdc()
Constructor.
typename PropagatorT::FieldT FieldT
Field type, for data defined on a real-space grid.
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
void allocate()
Allocate required internal memory for all solvers.
void writeQTail(std::string const &filename, int polymerId, int blockId, int directionId) const
Write the final slice of a propagator in r-grid format.
void writeStress(std::ostream &out) const
Write stress values to output stream.
~MixturePrdc()
Destructor.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
typename BlockT::PropagatorT PropagatorT
Polymer block propagator type.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
FieldIoT const & fieldIo() const
Return associated FieldIoT by const reference.
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
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.
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.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
std::string toString(int n)
Return string representation of an integer.
bool isThread()
Is the thread model in use ?
Periodic fields and crystallography.
PSCF package top-level namespace.