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/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>
29 template <
int D,
class PT,
class ST,
class TT>
34 unitCellPtr_(nullptr),
44 template <
int D,
class PT,
class ST,
class TT>
51 template <
int D,
class PT,
class ST,
class TT>
74 template <
int D,
class PT,
class ST,
class TT>
97 for (j = 0; j <
polymer(i).nBlock(); ++j) {
98 polymer(i).block(j).associate(
mesh, fft, cell, waveList);
104 if (nSolvent() > 0) {
115 template <
int D,
class PT,
class ST,
class TT>
122 template <
int D,
class PT,
class ST,
class TT>
151 template <
int D,
class PT,
class ST,
class TT>
168 for (i = 0; i < nm; ++i) {
169 eqS(cFields[i], 0.0);
173 if (nPolymer() > 0) {
176 for (i = 0; i < nPolymer(); ++i) {
177 polymer(i).compute(wFields, phiTot);
181 for (i = 0; i < nPolymer(); ++i) {
182 for (j = 0; j < polymer(i).nBlock(); ++j) {
183 monomerId = polymer(i).block(j).monomerId();
186 FieldT& monomerField = cFields[monomerId];
187 FieldT
const & blockField = polymer(i).block(j).cField();
188 addEqV(monomerField, blockField);
195 if (nSolvent() > 0) {
199 monomerId =
solvent(i).monomerId();
200 solvent(i).compute(wFields[monomerId], phiTot);
204 for (i = 0; i < nSolvent(); ++i) {
205 monomerId = solvent(i).monomerId();
208 FieldT& monomerField = cFields[monomerId];
209 FieldT
const & solventField = solvent(i).cField();
210 addEqV(monomerField, solventField);
215 isSymmetric_ =
false;
222 template <
int D,
class PT,
class ST,
class TT>
224 { isSymmetric_ = isSymmetric; }
229 template <
int D,
class PT,
class ST,
class TT>
238 for (i = 0; i < nParam_; ++i) {
250 for (i = 0; i < nParam_; ++i) {
252 stress_[i] +=
polymer(j).stress(i);
260 for (i = 0; i < nParam_; ++i) {
261 stress_[i] /= phiTot;
275 template <
int D,
class PT,
class ST,
class TT>
279 monomer(monomerId).setKuhn(kuhn);
282 for (
int i = 0; i <
nPolymer(); ++i) {
283 for (
int j = 0; j <
polymer(i).nBlock(); ++j) {
285 if (monomerId == block.monomerId()) {
296 template <
int D,
class PT,
class ST,
class TT>
300 for (
int i = 0; i <
nPolymer(); ++i) {
301 polymer(i).clearUnitCellData();
313 template <
int D,
class PT,
class ST,
class TT>
void
320 int nx =
mesh().size();
330 for (i = 0; i < np; ++i) {
331 if (!blockCFields[i].isAllocated()) {
332 blockCFields[i].
allocate(mesh().dimensions());
334 eqS(blockCFields[i], 0.0);
341 if (nPolymer() > 0) {
342 for (i = 0; i < nPolymer(); ++i) {
343 for (j = 0; j < polymer(i).nBlock(); ++j) {
347 blockCFields[sectionId] =
polymer(i).block(j).cField();
355 if (nSolvent() > 0) {
356 for (i = 0; i < nSolvent(); ++i) {
360 blockCFields[sectionId] = solvent(i).cField();
372 template <
int D,
class PT,
class ST,
class TT>
383 for (
int i = 0; i < np; i++) {
391 fieldIo().writeFieldsRGrid(filename, blockCFields,
400 template <
int D,
class PT,
class ST,
class TT>
402 std::string
const & filename,
418 propagator = polymerRef.propagator(blockId, directionId);
419 FieldT const & field = propagator.q(sliceId);
426 template <
int D,
class PT,
class ST,
class TT>
428 std::string
const & filename,
431 int directionId)
const
443 field = polymerRef.propagator(blockId, directionId).tail();
450 template <
int D,
class PT,
class ST,
class TT>
452 std::string
const & filename,
455 int directionId)
const
467 propagator = polymerRef.propagator(blockId, directionId);
468 int ns = propagator.ns();
472 fieldIo().fileMaster().openOutputFile(filename, file);
476 file <<
"mesh" << std::endl
477 <<
" " <<
mesh().dimensions() << std::endl
478 <<
"nslice" << std::endl
479 <<
" " << ns << std::endl;
482 bool hasHeader =
false;
483 for (
int i = 0; i < ns; ++i) {
484 file <<
"slice " << i << std::endl;
494 template <
int D,
class PT,
class ST,
class TT>
498 std::string filename;
499 int np, nb, ip, ib, id;
501 for (ip = 0; ip < np; ++ip) {
503 for (ib = 0; ib < nb; ++ib) {
504 for (
id = 0;
id < 2; ++id) {
513 writeQ(filename, ip, ib,
id);
524 template <
int D,
class PT,
class ST,
class TT>
529 out <<
"stress:" << std::endl;
531 for (
int i = 0; i < nParam_; i++) {
534 <<
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 createBlockCRGrid(DArray< FieldT > &blockCFields) const
Get c-fields for all blocks and solvents as array of r-grid fields.
SolventT & solvent(int id)
MixturePrdc()
Constructor.
~MixturePrdc()
Destructor.
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
void allocate()
Allocate required internal memory for all solvers.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
void computeStress(double phiTot=1.0)
Compute derivatives of free energy w/ respect to cell parameters.
void writeQAll(std::string const &basename)
Write all propagators of all blocks, each to a separate file.
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.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
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 >::FieldIo FieldIoT
void setClassName(const char *className)
Set class name string.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
UnitCell< D > const & unitCell() const
int nPolymer() const
Get number of polymer species.
typename TT::Propagator PropagatorT
Propagator type, for one direction within a block.
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
PT PolymerT
Polymer species solver type.
typename TT::FFT FFTT
WaveList type.
FieldIoT const & fieldIo() const
typename TT::RField FieldT
Field type, for data defined on a real-space grid.
void setIsSymmetric(bool isSymmetric)
Set the isSymmetric flag true or false.
int nMonomer() const
Get number of monomer types.
int nBlock() const
Get total number blocks among all polymer species.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
int nSolvent() const
Get number of solvent (point particle) species.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields, double phiTot=1.0)
Compute partition functions and concentrations.
void writeStress(std::ostream &out) const
Write stress values to output stream.
typename TT::WaveList WaveListT
WaveList type.
typename TT::Block 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.
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 setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
void writeBlockCRGrid(std::string const &filename) const
Write c fields for all blocks and solvents in r-grid format.
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.