1#ifndef PRDC_CL_MIXTURE_TPP
2#define PRDC_CL_MIXTURE_TPP
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>
33 unitCellPtr_(nullptr),
40 template <
int D,
class PT,
class ST,
class TT>
47 template <
int D,
class PT,
class ST,
class TT>
70 template <
int D,
class PT,
class ST,
class TT>
91 for (j = 0; j <
polymer(i).nBlock(); ++j) {
92 polymer(i).block(j).associate(
mesh, fft, cell, waveList);
99 for (
int i = 0; i <
nSolvent(); ++i) {
109 template <
int D,
class PT,
class ST,
class TT>
116 template <
int D,
class PT,
class ST,
class TT>
132 for (
int i = 0; i <
nSolvent(); ++i) {
145 template <
int D,
class PT,
class ST,
class TT>
161 for (i = 0; i < nm; ++i) {
162 eqS(cFields[i], 0.0);
166 if (nPolymer() > 0) {
169 for (i = 0; i < nPolymer(); ++i) {
170 polymer(i).compute(wFields);
174 for (i = 0; i < nPolymer(); ++i) {
175 for (j = 0; j < polymer(i).nBlock(); ++j) {
176 monomerId = polymer(i).block(j).monomerId();
179 FieldT& monomerField = cFields[monomerId];
180 FieldT
const & blockField = polymer(i).block(j).cField();
181 addEqV(monomerField, blockField);
188 if (nSolvent() > 0) {
191 for (i = 0; i < nSolvent(); ++i) {
192 monomerId = solvent(i).monomerId();
193 solvent(i).compute(wFields[monomerId]);
197 for (i = 0; i < nSolvent(); ++i) {
198 monomerId = solvent(i).monomerId();
201 FieldT& monomerField = cFields[monomerId];
203 addEqV(monomerField, solventField);
215 template <
int D,
class PT,
class ST,
class TT>
219 monomer(monomerId).setKuhn(kuhn);
222 for (
int i = 0; i <
nPolymer(); ++i) {
223 for (
int j = 0; j <
polymer(i).nBlock(); ++j) {
225 if (monomerId == block.monomerId()) {
235 template <
int D,
class PT,
class ST,
class TT>
239 for (
int i = 0; i <
nPolymer(); ++i) {
240 polymer(i).clearUnitCellData();
251 template <
int D,
class PT,
class ST,
class TT>
void
255 int np = nSolvent() + nBlock();
258 int nx = mesh().
size();
268 for (i = 0; i < np; ++i) {
269 if (!blockCFields[i].isAllocated()) {
270 blockCFields[i].
allocate(mesh().dimensions());
272 eqS(blockCFields[i], 0.0);
279 if (nPolymer() > 0) {
280 for (i = 0; i < nPolymer(); ++i) {
281 for (j = 0; j < polymer(i).nBlock(); ++j) {
285 blockCFields[sectionId] = polymer(i).block(j).cField();
293 if (nSolvent() > 0) {
294 for (i = 0; i < nSolvent(); ++i) {
298 blockCFields[sectionId] = solvent(i).cField();
310 template <
int D,
class PT,
class ST,
class TT>
319 int np = nSolvent() + nBlock();
321 for (
int i = 0; i < np; i++) {
322 blockCFields[i].
allocate(mesh().dimensions());
326 createBlockCRGrid(blockCFields);
329 fieldIo().writeCFields(filename, blockCFields, unitCell());
339 template <
int D,
class PT,
class ST,
class TT>
341 std::string
const & filename,
350 PolymerT
const& polymerRef = polymer(polymerId);
357 propagator = polymerRef.propagator(blockId, directionId);
358 FieldT
const & field = propagator.q(sliceId);
359 fieldIo().writeCField(filename, field, unitCell());
365 template <
int D,
class PT,
class ST,
class TT>
367 std::string
const & filename,
370 int directionId)
const
375 PolymerT
const& polymerRef = polymer(polymerId);
382 field = polymerRef.propagator(blockId, directionId).tail();
383 fieldIo().writeCField(filename, field, unitCell());
389 template <
int D,
class PT,
class ST,
class TT>
391 std::string
const & filename,
394 int directionId)
const
399 PolymerT
const& polymerRef = polymer(polymerId);
406 propagator = polymerRef.propagator(blockId, directionId);
407 int ns = propagator.ns();
411 fieldIo().fileMaster().openOutputFile(filename, file);
414 fieldIo().writeFieldHeader(file, 1, unitCell());
415 file <<
"mesh" << std::endl
417 <<
"nslice" << std::endl
418 <<
" " << ns << std::endl;
421 bool hasHeader =
false;
422 for (
int i = 0; i < ns; ++i) {
423 file <<
"slice " << i << std::endl;
424 fieldIo().writeCField(file, propagator.q(i), unitCell(),
433 template <
int D,
class PT,
class ST,
class TT>
437 std::string filename;
438 int np, nb, ip, ib, id;
440 for (ip = 0; ip < np; ++ip) {
441 nb = polymer(ip).nBlock();
442 for (ib = 0; ib < nb; ++ib) {
443 for (
id = 0;
id < 2; ++id) {
452 writeQ(filename, ip, ib,
id);
Solver and descriptor for a mixture of polymers and solvents.
typename TT::FFT FFTT
WaveList type.
int nPolymer() const
Get number of polymer species.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
Monomer const & monomer(int id) const
Get a Monomer type descriptor by const reference.
typename TT::FieldIo FieldIoT
FieldIo type.
void setClassName(const char *className)
Set class name string.
void clearUnitCellData()
Clear all data that depends on the unit cell parameters.
typename TT::WaveList WaveListT
WaveList type.
int nSolvent() const
Get number of solvent (point particle) species.
void setKuhn(int monomerId, double kuhn)
Reset statistical segment length for one monomer type.
PolymerT & polymer(int id)
Get a polymer solver object by non-const reference.
SolventT & solvent(int id)
void compute(DArray< FieldT > const &wFields, DArray< FieldT > &cFields)
Compute partition functions and concentrations.
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 allocate()
Allocate required internal memory for all solvers.
Mesh< D > const & mesh() const
Return associated Mesh<D> by const reference.
FieldIoT const & fieldIo() const
Return associated FieldIoT by const reference.
typename TT::Block BlockT
Block type, for a block in a block polymer.
void setFieldIo(FieldIoT const &fieldIo)
Create an association with a FieldIoT object.
typename Types< D >::CField FieldT
int nMonomer() const
Get number of monomer types.
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
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.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
std::string toString(int n)
Return string representation of an integer.
Complex-valued periodic fields (class templates).
bool isThread()
Is the thread model in use ?
PSCF package top-level namespace.