PSCF v1.3.3
rpg/solvers/Mixture.tpp
1#ifndef RPG_MIXTURE_TPP
2#define RPG_MIXTURE_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 "Mixture.h"
12#include "Polymer.h"
13#include "Solvent.h"
14#include "Block.h"
15#include "Propagator.h"
16#include <rpg/field/FieldIo.h>
17#include <prdc/solvers/MixturePrdc.tpp>
18#include <prdc/cuda/FFT.h>
19#include <prdc/cuda/RField.h>
20
21namespace Pscf {
22namespace Rpg {
23
24 using namespace Prdc;
25 using namespace Prdc::Cuda;
26
27 /*
28 * Constructor
29 */
30 template <int D>
32 : MixturePrdcT(),
33 useBatchedFFT_(true)
34 {}
35
36 /*
37 * Read all parameters and initialize.
38 */
39 template <int D>
40 void Mixture<D>::readParameters(std::istream& in)
41 {
42 MixturePrdcT::readParameters(in);
43
44 // Optionally read useBatchedFFT boolean
45 useBatchedFFT_ = true;
46 ParamComposite::readOptional(in, "useBatchedFFT", useBatchedFFT_);
47 }
48
49 /*
50 * Set all elements of a field to a single scalar: A[i] = c.
51 */
52 template <int D>
53 void Mixture<D>::eqS(FieldT& A, double c) const
54 {
55 const int nx = mesh().size();
56 UTIL_CHECK(nx == A.capacity());
57 VecOp::eqS(A,c);
58 }
59
60 /*
61 * Compound addition-assignment of two fields: A[i] += B[i]
62 */
63 template <int D>
64 void Mixture<D>::addEqV(FieldT& A, FieldT const & B) const
65 {
66 const int nx = mesh().size();
67 UTIL_CHECK(nx == A.capacity());
68 UTIL_CHECK(nx == B.capacity());
69 VecOp::addEqV(A, B);
70 }
71
72 /*
73 * Allocate memory for all blocks.
74 */
75 template <int D>
76 void Mixture<D>::allocateBlocks()
77 {
78 int i, j;
79 for (i = 0; i < nPolymer(); ++i) {
80 for (j = 0; j < polymer(i).nBlock(); ++j) {
81 polymer(i).block(j).allocate(ds(), useBatchedFFT_);
82 }
83 }
84 }
85
86} // namespace Rpg
87} // namespace Pscf
88#endif
void readParameters(std::istream &in) override
Read all parameters and initialize.
typename Prdc::MixturePrdc< D, Polymer< D >, Solvent< D >, Types< D > > MixturePrdcT
Direct (parent) base class.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void addEqV(Array< double > &a, Array< double > const &b)
Vector addition in-place, a[i] += b[i].
Definition VecOp.cpp:199
void eqS(Array< double > &a, double b)
Vector assignment, a[i] = b.
Definition VecOp.cpp:36
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.