PSCF v1.5.0
IntraCorrelation.tpp
1#ifndef RP_INTRACORRELATION_TPP
2#define RP_INTRACORRELATION_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "IntraCorrelation.h"
12
13#include <rp/system/System.h>
14#include <rp/solvers/Mixture.h>
15#include <rp/field/Domain.h>
16
17#include <pscf/field/FFT.h>
18#include <pscf/field/RField.h>
19#include <pscf/crystal/shiftToMinimum.h>
20#include <pscf/crystal/UnitCell.h>
21
22#include <pscf/mesh/Mesh.h>
23#include <pscf/mesh/MeshIterator.h>
24#include <pscf/correlation/Mixture.h>
25
26#include <util/global.h>
27
28namespace Pscf {
29namespace Rp {
30
31 using namespace Util;
32
33 /*
34 * Constructor.
35 */
36 template <int D, class T>
38 System<D,T> const & system)
39 : systemPtr_(&system),
40 correlationMixturePtr_(nullptr),
41 kSize_(-1)
42 {
43 correlationMixturePtr_
44 = new Pscf::Correlation::Mixture<RealT>(system.mixture());
45 }
46
47 /*
48 * Destructor.
49 */
50 template <int D, class T>
52 { delete correlationMixturePtr_; }
53
54 /*
55 * Compute k-space array of intramolecular correlation functions (on device).
56 */
57 template<int D, class T>
58 void
60 {
61 getMeshDimensions();
62 int nk = kSize_;
63 UTIL_CHECK(correlations.isAllocated());
64 UTIL_CHECK(correlations.capacity() == nk);
65
66 correlations_h_.associate(correlations);
67 computeOmegaTotalArray(correlations_h_);
68 correlations = correlations_h_;
69 correlations_h_.dissociate();
70 }
71
72 /*
73 * Compute k-space array of intramolecular correlation functions (on host).
74 */
75 template <int D, class T>
76 void
77 IntraCorrelation<D,T>::computeOmegaTotalArray(Array<RealT>& correlations)
78 {
79 getMeshDimensions();
80 UTIL_CHECK(correlations.capacity() == kSize_);
81 computeGsq();
82 if (!correlationMixturePtr_->isAllocated()) {
83 correlationMixturePtr_->allocate();
84 }
85 correlationMixturePtr_->setup();
86 correlationMixturePtr_->computeOmegaTotal(Gsq_, correlations);
87 }
88
89 /*
90 * Compute k-grid mesh dimensions and Gsq.
91 */
92 template <int D, class T>
93 void IntraCorrelation<D,T>::getMeshDimensions()
94 {
95 meshDimensions_ = system().domain().mesh().dimensions();
96
97 // Compute k-space mesh dimensions kMeshDimensions_ and size Size_
98 FFT<D,T>::computeKMesh(meshDimensions_, kMeshDimensions_, kSize_);
99 }
100
101 /*
102 * Construct array of squared wavevector values (on host).
103 */
104 template <int D, class T>
105 void IntraCorrelation<D,T>::computeGsq()
106 {
107 // Get mesh dimensions if not done previously
108 if (kSize_ <= 0) {
109 getMeshDimensions();
110 }
111
112 // Check allocation of Gsq_ (k-space array of square wavenumbers)
113 if (Gsq_.isAllocated()) {
114 if (Gsq_.capacity() != kSize_) {
115 Gsq_.deallocate();
116 }
117 }
118 if (!Gsq_.isAllocated()) {
119 Gsq_.allocate(kSize_);
120 }
121 UTIL_CHECK(Gsq_.capacity() == kSize_);
122
123 // Compute Gsq_
124 UnitCell<D> const & unitCell = system().domain().unitCell();
125 IntVec<D> G, Gmin;
126 MeshIterator<D> iter;
127 iter.setDimensions(kMeshDimensions_);
128 for (iter.begin(); !iter.atEnd(); ++iter) {
129 G = iter.position();
130 Gmin = shiftToMinimum(G, meshDimensions_, unitCell);
131 Gsq_[iter.rank()] = unitCell.ksq(Gmin);
132 }
133 }
134
135}
136}
137#endif
Correlations in a homogeneous ideal gas mixture.
virtual void computeOmegaTotal(RField< D, T > &correlations)
Compute total intramolecular correlation function (all blocks).
IntraCorrelation(System< D, T > const &system)
Constructor.
Base class template for classes that represent a complete system.
Array container class template.
Definition Array.h:41
int capacity() const
Return allocated size.
Definition Array.h:250
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.