1#ifndef RPG_EXT_GEN_FILM_TPP
2#define RPG_EXT_GEN_FILM_TPP
11#include "FilmFieldGenExt.h"
12#include <rpg/scft/iterator/Iterator.h>
13#include <rpg/field/FieldIo.h>
14#include <rpg/solvers/Mixture.h>
15#include <rpg/field/Domain.h>
16#include <prdc/cpu/RField.h>
17#include <prdc/crystal/Basis.h>
18#include <prdc/crystal/UnitCell.h>
19#include <prdc/crystal/paramIdConversions.h>
20#include <prdc/cuda/resources.h>
55 __global__
void _hFieldDerivatives(cudaReal ** hDerivs,
56 cudaReal
const * mask,
57 cudaReal
const * chiBottom,
58 cudaReal
const * chiTop,
59 cudaReal
const interfaceThickness,
60 int const normalVecId,
65 int ix = blockIdx.x * blockDim.x + threadIdx.x;
66 int iy = blockIdx.y * blockDim.y + threadIdx.y;
67 int iz = blockIdx.z * blockDim.z + threadIdx.z;
77 if (normalVecId == 2) d = (cudaReal)ix / (cudaReal)
meshDims.x;
78 if (normalVecId == 1) d = (cudaReal)iy / (cudaReal)
meshDims.y;
79 if (normalVecId == 0) d = (cudaReal)iz / (cudaReal)
meshDims.z;
81 if (normalVecId == 1) d = (cudaReal)ix / (cudaReal)
meshDims.x;
82 if (normalVecId == 0) d = (cudaReal)iy / (cudaReal)
meshDims.y;
84 d = (cudaReal)ix / (cudaReal)
meshDims.x;
89 cudaReal dPhidL = mask[id];
92 dPhidL = dPhidL * (dPhidL - 1) * 8.0 * (
abs(d - 0.5) - 0.5)
96 for (
int in = 0; in < nMonomer; in++) {
98 hDerivs[in][id] = -1.0 * dPhidL * chiBottom[in];
100 hDerivs[in][id] = -1.0 * dPhidL * chiTop[in];
118 __global__
void _generateHFields(cudaReal ** hFields,
119 cudaReal
const * mask,
120 cudaReal
const * chiBottom,
121 cudaReal
const * chiTop,
122 int const normalVecId,
127 int ix = blockIdx.x * blockDim.x + threadIdx.x;
128 int iy = blockIdx.y * blockDim.y + threadIdx.y;
129 int iz = blockIdx.z * blockDim.z + threadIdx.z;
139 if (normalVecId == 2) topHalf = (ix >
meshDims.x / 2);
140 if (normalVecId == 1) topHalf = (iy >
meshDims.y / 2);
141 if (normalVecId == 0) topHalf = (iz >
meshDims.z / 2);
143 if (normalVecId == 1) topHalf = (ix >
meshDims.x / 2);
144 if (normalVecId == 0) topHalf = (iy >
meshDims.y / 2);
151 cudaReal maskVal = mask[id];
154 for (
int in = 0; in < nMonomer; in++) {
156 hFields[in][id] = (1.0 - maskVal) * chiTop[in];
158 hFields[in][id] = (1.0 - maskVal) * chiBottom[in];
204 system().domain().lattice());
205 if (nvParamId != paramId)
return 0.0;
214 int nMonomer =
system().mixture().nMonomer();
221 for (
int i = 0; i < nMonomer; i++) {
223 hDerivPtrs_h[i] = hDerivatives[i].
cArray();
225 hDerivPtrs = hDerivPtrs_h;
229 for (
int i = 0; i < nMonomer; i++) {
233 chiBottom_d = chiBottom_h;
242 _hFieldDerivatives<D><<<gridDims, blockDims>>>
249 for (
int i = 0; i < nMonomer; i++) {
278 if (
system().iterator().isSymmetric()) {
283 int nMonomer =
system().mixture().nMonomer();
290 for (
int i = 0; i < nMonomer; i++) {
292 hPtrs_h[i] = hFields[i].
cArray();
298 for (
int i = 0; i < nMonomer; i++) {
302 chiBottom_d = chiBottom_h;
311 _generateHFields<D><<<gridDims, blockDims>>>
317 system().h().setRGrid(hFields,
system().iterator().isSymmetric());
Dynamic array on the GPU device with aligned data.
Data * cArray()
Return pointer to underlying C array.
Template for dynamic array stored in host CPU memory.
DArray< double > chiTopCurrent_
The chiTop array used to generate the current external fields.
DArray< double > const & chiTop() const
Get const chiTop array by reference.
DArray< double > chiBottomCurrent_
The chiBottom array used to generate the current external fields.
DArray< double > const & chiBottom() const
Get const chiBottom matrix by reference.
bool isAthermal() const
Are the walls athermal?
double interfaceThickness() const
Get value of interfaceThickness.
RealVec< D > normalVecCurrent_
The lattice vector normal to the film used to generate these fields.
int normalVecId() const
Get value of normalVecId.
FilmFieldGenExtBase()
Constructor.
FilmFieldGenExt()
Default constructor.
void setClassName(const char *className)
Set class name string.
void compute()
Compute the fields and store where the System can access.
~FilmFieldGenExt()
Destructor.
RealVec< D > systemLatticeVector(int id) const
Get one of the lattice vectors for this system.
double stress(int paramId) const
Get contribution to the stress from the external fields.
System< D > & system()
Get the System associated with this object by reference.
Main class, representing a complete physical system.
Data * cArray()
Return a pointer to the underlying C array.
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
void allocate(int capacity)
Allocate the underlying C array.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
int convertFullParamIdToReduced(const int fullId, const typename UnitCell< D >::LatticeSystem lattice)
Convert full lattice parameter index to a reduced index.
void setConfig(IntVec< D > const &meshDims, bool invert, int blockSize)
Given a multidimensional grid of threads, set execution configuration.
dim3 gridDims()
Get the multidimensional grid of blocks determined by setConfig.
dim3 meshDims()
Return last requested multidimensional grid of threads.
dim3 blockDims()
Get the dimensions of a single block determined by setConfig.
RT abs(CT const &a)
Return absolute magnitude of a complex number.
double innerProduct(Array< double > const &a, Array< double > const &b)
Compute inner product of two real arrays .
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Periodic fields and crystallography.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.