PSCF v1.4.0
ForceBiasMove.cu
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "ForceBiasMove.h"
9#include "McMove.h"
10#include <rpg/fts/montecarlo/McSimulator.h>
11#include <rpg/fts/compressor/Compressor.h>
12#include <rpg/system/System.h>
13#include <rpg/solvers/Mixture.h>
14#include <rpg/field/Domain.h>
15#include <rpg/field/CFields.h>
16#include <rpg/field/WFields.h>
17
18#include <pscf/cuda/VecOp.h>
19#include <pscf/cuda/Reduce.h>
20#include <pscf/cuda/CudaVecRandom.h>
21#include <pscf/cuda/ThreadArray.h>
22#include <pscf/cuda/DeviceArray.h>
23#include <pscf/cuda/HostDArray.h>
24
25#include <rp/fts/montecarlo/ForceBiasMove.tpp>
26
27namespace Pscf {
28namespace Rpg {
29
30 using namespace Util;
31 using namespace Prdc;
32 using namespace Prdc::Cuda;
33
34 /*
35 * Constructor.
36 */
37 template <int D>
39 : Rp::ForceBiasMove<D, Types<D> > (simulator)
40 {}
41
42 // Anonymous namespace for CUDA kernel
43 namespace {
44
45 // Compute force bias
46 __global__
47 void _computeForceBias(cudaReal* result,
48 cudaReal const * di,
49 cudaReal const * df,
50 cudaReal const * dwc,
51 double mobility,
52 const int n)
53 {
54 int nThreads = blockDim.x * gridDim.x;
55 int startID = blockIdx.x * blockDim.x + threadIdx.x;
56 for (int i = startID; i < n; i += nThreads) {
57 result[i] = 0.5 * (di[i] + df[i]) *
58 (dwc[i] + mobility * (0.5 * (di[i] - df[i])));
59 }
60 }
61
62 }
63
64 /*
65 * Compute force bias field for use in Metropolis acceptance test.
66 */
67 template<int D>
68 void ForceBiasMove<D>::computeForceBias(
69 RField<D>& result,
70 RField<D> const & di,
71 RField<D> const & df,
72 RField<D> const & dwc,
73 double mobility)
74 {
75 const int n = result.capacity();
76 UTIL_CHECK(di.capacity() == n);
77 UTIL_CHECK(df.capacity() == n);
78 UTIL_CHECK(dwc.capacity() == n);
79
80 // GPU resources
81 int nBlocks, nThreads;
82 ThreadArray::setThreadsLogical(n, nBlocks, nThreads);
83
84 // Launch kernel
85 _computeForceBias<<<nBlocks, nThreads>>>(
86 result.cArray(), di.cArray(),
87 df.cArray(), dwc.cArray(),
88 mobility, n);
89 }
90
91}
92}
93
94// Explicit instantiation definitions
95namespace Pscf {
96 namespace Rp {
97 template class ForceBiasMove<1, Rpg::Types<1> >;
98 template class ForceBiasMove<2, Rpg::Types<2> >;
99 template class ForceBiasMove<3, Rpg::Types<3> >;
100 }
101 namespace Rpg {
102 template class ForceBiasMove<1>;
103 template class ForceBiasMove<2>;
104 template class ForceBiasMove<3>;
105 }
106}
Field of real values on a regular mesh, allocated on a GPU device.
Definition cuda/RField.h:33
ForceBiasMove attempts a Brownian dynamics move.
ForceBiasMove attempts a Brownian dynamics move.
ForceBiasMove(McSimulator< D > &simulator)
Constructor.
Monte Carlo simulator for PS-FTS.
List of aliases for types used in the Rpg program-level namespace.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void setThreadsLogical(int nThreadsLogical)
Given total number of threads, set 1D execution configuration.
int nThreads()
Get the number of threads per block for execution.
int nBlocks()
Get the current number of blocks for execution.
Periodic fields and crystallography.
Definition complex.cpp:11
Class templates for real-valued periodic fields.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
cufftDoubleReal cudaReal
Real number type used in CPU code that uses FFTW.
Definition cudaTypes.h:35