PSCF v1.4.0
cpc/solvers/Polymer.tpp
1#ifndef CPC_POLYMER_TPP
2#define CPC_POLYMER_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Polymer.h"
12#include "Block.h"
13#include "Propagator.h"
14#include <prdc/cpu/CField.h>
15#include <pscf/cpu/complex.h>
16
17namespace Pscf {
18namespace Cpc {
19
20 /*
21 * Constructor.
22 */
23 template <int D>
26
27 /*
28 * Destructor.
29 */
30 template <int D>
33
34 /*
35 * Clear all data that depends on unit cell parameters.
36 */
37 template <int D>
39 {
40 for (int j = 0; j < nBlock(); ++j) {
41 block(j).clearUnitCellData();
42 }
43 }
44
45 /*
46 * Compute solution to MDE and block concentrations.
47 */
48 template <int D>
49 void Polymer<D>::compute(DArray< CField<D> > const & wFields)
50 {
51 // Setup solvers for all blocks
52 int monomerId;
53 for (int j = 0; j < nBlock(); ++j) {
54 monomerId = block(j).monomerId();
55 block(j).setupSolver(wFields[monomerId]);
56 }
57
58 // Call base class PolymerTmpl solve() function
59 // Solve MDE for all propagators
60 double phiTot = 1.0;
61 solve(phiTot);
62
63 // Compute block concentration fields
64 std::complex<double> ratio;
65 fftw_complex prefactor;
67 ratio = phi() / length();
68 ratio /= q();
69 assign(prefactor, ratio);
70 for (int i = 0; i < nBlock(); ++i) {
71 block(i).computeConcentrationThread(prefactor);
72 }
73 } else {
75 double len = (double) nBead();
76 ratio = phi() / len;
77 ratio /= q();
78 assign(prefactor, ratio);
79 for (int i = 0; i < nBlock(); ++i) {
80 block(i).computeConcentrationBead(prefactor);
81 }
82 }
83
84 }
85
86}
87}
88#endif
int nBlock() const
Number of blocks.
void compute(DArray< CField< D > > const &wFields)
Compute solution to MDE and block concentrations.
std::complex< double > q() const
Get the molecular partition function for this species.
double length() const
Sum of the lengths of all blocks in the polymer (thread model).
Block< D > & block(int id)
Get a specified Block (solver and descriptor).
int nBead() const
Total number of beads in the polymer (bead model).
std::complex< double > phi() const
Get the overall volume fraction for this species.
void clearUnitCellData()
Clear all data that depends on unit cell parameters.
Field of complex double precision values on an FFT mesh.
Definition cpu/CField.h:29
Dynamically allocatable contiguous array template.
Definition DArray.h:32
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void assign(fftw_complex &z, double const &a, double const &b)
Create an fftw_complex from real and imaginary parts, z = a + ib.
Complex periodic fields, CL-FTS (CPU).
Definition cpc.mod:6
bool isThread()
Is the thread model in use ?
bool isBead()
Is the bead model in use ?
PSCF package top-level namespace.