9#include "Propagator_c.h"
11#include <pscf/field/cpp/WaveList.h>
12#include <pscf/field/cpp/FFT.h>
13#include <pscf/crystal/UnitCell.h>
14#include <pscf/crystal/shiftToMinimum.h>
16#include <pscf/chem/Edge.h>
17#include <pscf/mesh/Mesh.h>
18#include <pscf/mesh/MeshIterator.h>
20#include <util/containers/DMatrix.h>
21#include <util/containers/DArray.h>
23#include <pscf/solvers/BlockTmpl.tpp>
38 unitCellPtr_(nullptr),
39 waveListPtr_(nullptr),
76 waveListPtr_ = &waveList;
95 UTIL_CHECK(mesh().dimensions() == fft().meshDimensions());
102 expKsq_.allocate(kMeshDimensions_);
103 expKsq2_.allocate(kMeshDimensions_);
104 expW_.allocate(mesh().dimensions());
105 qr_.allocate(mesh().dimensions());
106 qk_.allocate(mesh().dimensions());
107 qr2_.allocate(mesh().dimensions());
108 qk2_.allocate(mesh().dimensions());
110 expW2_.allocate(mesh().dimensions());
112 expWInv_.allocate(mesh().dimensions());
116 cField().allocate(mesh().dimensions());
126 tempNs = floor(
length / (2.0 *
ds) + 0.5);
131 ds_ =
length/double(ns_-1);
162 int tempNs = floor(
length / (2.0 *dsTarget_) + 0.5 );
167 ds_ =
length / double(ns_-1);
188 if (isAllocated_ && ns_ !=
nBead + 2) {
225 const double b = BlockTmplT::kuhn();
226 double bSqFactor = -1.0 * b * b / 6.0;
232 if (!waveList().hasKSq()) {
233 waveList().computeKSq();
235 RField<D,CPT>
const & kSq = waveList().kSq();
237 MeshIterator<D> iter;
238 iter.setDimensions(kMeshDimensions_);
241 for (iter.begin(); !iter.atEnd(); ++iter) {
243 arg = kSq[i]*bSqFactor;
244 expKsq_[i] = exp(arg);
245 expKsq2_[i] = exp(0.5*arg);
259 int nx = mesh().size();
267 for (
int i = 0; i < nx; ++i) {
270 expW2_[i] = exp(0.5*arg);
274 for (
int i = 0; i < nx; ++i) {
277 expWInv_[i] = 1.0/expW_[i];
297 int nx = mesh().size();
300 UTIL_CHECK(mesh().dimensions() == fft().meshDimensions());
304 int nk = qk_.capacity();
323 for (i = 0; i < nx; ++i) {
324 qr_[i] = q[i]*expW_[i];
325 qr2_[i] = q[i]*expW2_[i];
327 fft().forwardTransform(qr_, qk_);
328 fft().forwardTransform(qr2_, qk2_);
329 for (i = 0; i < nk; ++i) {
330 qk_[i][0] *= expKsq_[i];
331 qk_[i][1] *= expKsq_[i];
332 qk2_[i][0] *= expKsq2_[i];
333 qk2_[i][1] *= expKsq2_[i];
335 fft().inverseTransformUnsafe(qk_, qr_);
336 fft().inverseTransformUnsafe(qk2_, qr2_);
337 for (i = 0; i < nx; ++i) {
338 qr_[i] = qr_[i]*expW_[i];
339 qr2_[i] = qr2_[i]*expW_[i];
347 fft().forwardTransform(qr2_, qk2_);
348 for (i = 0; i < nk; ++i) {
349 qk2_[i][0] *= expKsq2_[i];
350 qk2_[i][1] *= expKsq2_[i];
352 fft().inverseTransformUnsafe(qk2_, qr2_);
353 for (i = 0; i < nx; ++i) {
354 qr2_[i] = qr2_[i]*expW2_[i];
358 for (i = 0; i < nx; ++i) {
359 qout[i] = (4.0*qr2_[i] - qr_[i])/3.0;
384 int nx = mesh().size();
388 int nk = qk_.capacity();
393 fft().forwardTransform(q, qk_);
394 for (
int i = 0; i < nk; ++i) {
395 qk_[i][0] *= expKsq_[i];
396 qk_[i][1] *= expKsq_[i];
398 fft().inverseTransformUnsafe(qk_, qout);
410 int nx = mesh().size();
414 int nk = qk_.capacity();
419 fft().forwardTransform(q, qk_);
420 for (
int i = 0; i < nk; ++i) {
421 qk_[i][0] *= expKsq2_[i];
422 qk_[i][1] *= expKsq2_[i];
424 fft().inverseTransformUnsafe(qk_, qout);
434 int nx = mesh().size();
440 for (
int i = 0; i < nx; ++i) {
453 int nx = mesh().size();
462 for (i = 0; i < nx; ++i) {
473 for (i = 0; i < nx; ++i) {
474 cField()[i] += p0.q(0)[i]*p1.q(ns_ - 1)[i];
475 cField()[i] += p0.q(ns_ -1)[i]*p1.q(0)[i];
480 for (j = 1; j < (ns_ -1); j += 2) {
483 for (i = 0; i < nx; ++i) {
485 cField()[i] += qf[i] * qr[i] * 4.0;
490 for (j = 2; j < (ns_ -2); j += 2) {
493 for (i = 0; i < nx; ++i) {
495 cField()[i] += qf[i] * qr[i] * 2.0;
500 prefactor *= ds_ / 3.0;
501 for (i = 0; i < nx; ++i) {
515 int nx = mesh().size();
524 for (i = 0; i < nx; ++i) {
534 for (j = 1; j < (ns_ -1); ++j) {
537 for (i = 0; i < nx; ++i) {
538 cField()[i] += qf[i] * qr[i] * expWInv_[i];
543 for (i = 0; i < nx; ++i) {
556 int nx = mesh().size();
559 UTIL_CHECK(mesh().dimensions() == fft().meshDimensions());
571 if (!waveList().hasdKSq()) {
572 waveList().computedKSq();
577 const int nParam = unitCell().nParameter();
578 for (
int i = 0; i < nParam; ++i) {
584 const double bSq = b * b / 6.0;
585 double dels, prod, increment;
589 for (
int j = 0; j < ns_ ; ++j) {
592 fft().forwardTransform(qr_, qk_);
594 qr2_ = p1.q(ns_ - 1 - j);
595 fft().forwardTransform(qr2_, qk2_);
599 if (j != 0 && j != ns_ - 1) {
608 for (n = 0; n < nParam ; ++n) {
612 for (m = 0; m < kSize_ ; ++m) {
613 prod = (qk2_[m][0] * qk_[m][0]) + (qk2_[m][1] * qk_[m][1]);
617 increment *= bSq * dels;
618 dQ[n] = dQ[n] - increment;
625 for (
int n = 0; n < nParam; ++n) {
626 stress_.append(-1.0*prefactor*dQ[n]);
639 int nx = mesh().size();
642 UTIL_CHECK(mesh().dimensions() == fft().meshDimensions());
654 if (!waveList().hasdKSq()) {
655 waveList().computedKSq();
660 int nParam = unitCell().nParameter();
661 for (
int i = 0; i < nParam; ++i) {
666 const double bSq = b * b / 6.0;
667 double increment, prod;
670 if (!p0.isHeadEnd()) {
674 fft().forwardTransform(qr_, qk_);
677 qr2_ = p1.q(ns_ - 2);
678 fft().forwardTransform(qr2_, qk2_);
681 for (
int n = 0; n < nParam ; ++n) {
685 for (
int m = 0; m < kSize_ ; ++m) {
686 prod = (qk2_[m][0] * qk_[m][0]) + (qk2_[m][1] * qk_[m][1]);
687 prod *= dKSq[m]*expKsq2_[m];
690 increment *= 0.5*bSq;
691 dQ[n] = dQ[n] - increment;
696 for (
int j = 1; j < ns_ - 2 ; ++j) {
700 fft().forwardTransform(qr_, qk_);
703 qr2_ = p1.q(ns_ - 2 - j);
704 fft().forwardTransform(qr2_, qk2_);
707 for (
int n = 0; n < nParam ; ++n) {
711 for (
int m = 0; m < kSize_ ; ++m) {
712 prod = (qk2_[m][0] * qk_[m][0]) + (qk2_[m][1] * qk_[m][1]);
713 prod *= dKSq[m]*expKsq_[m];
717 dQ[n] = dQ[n] - increment;
723 if (!p0.isTailEnd()) {
727 fft().forwardTransform(qr_, qk_);
731 fft().forwardTransform(qr2_, qk2_);
734 for (
int n = 0; n < nParam ; ++n) {
738 for (
int m = 0; m < kSize_ ; ++m) {
739 prod = (qk2_[m][0] * qk_[m][0]) + (qk2_[m][1] * qk_[m][1]);
740 prod *= dKSq[m]*expKsq2_[m];
743 increment *= 0.5*bSq;
744 dQ[n] = dQ[n] - increment;
751 for (
int i = 0; i < nParam; ++i) {
752 stress_.append(-1.0*prefactor*dQ[i]);
763 template class BlockTmpl< Rp::Propagator<1,CPT>, RField<1,CPT> >;
764 template class BlockTmpl< Rp::Propagator<2,CPT>, RField<2,CPT> >;
765 template class BlockTmpl< Rp::Propagator<3,CPT>, RField<3,CPT> >;
768 template class Block<1,CPT>;
769 template class Block<2,CPT>;
770 template class Block<3,CPT>;
virtual void setKuhn(double kuhn)
virtual void setNBead(int nBead)
Set the number of beads in this block (only valid for bead model).
int nBead() const
Get the number of beads in this block, in the bead model.
virtual void setLength(double length)
Set the length of this block (only valid for thread model).
double length() const
Get the length of this block, in the thread model.
Description of a regular grid of points in a periodic domain.
double ds() const
Get contour length step size.
void stepBondBead(RField< D, CPT > const &qin, RField< D, CPT > &qout) const
Apply a bond operator for the bead model.
Rp::Propagator< D, CPT > & propagator(int directionId)
Get a Propagator for a specified direction (non-const reference).
RField< D, CPT > const & cField() const
Get the associated monomer concentration field (const reference).
void stepFieldBead(RField< D, CPT > &q) const
Apply the exponential field operator for the bead model.
Base template for UnitCell<D> classes, D=1, 2 or 3.
A fixed capacity (static) contiguous array with a variable logical size.
void append(Data const &data)
Append data to the end of the array.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
bool isThread()
Is the thread model in use ?
bool isBead()
Is the bead model in use ?
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.