8#include "FilmFieldGenMask_u.h"
10#include <rp/system/System.h>
11#include <rp/scft/ScftThermo.h>
12#include <rp/scft/iterator/Iterator.h>
13#include <rp/solvers/Mixture.h>
14#include <rp/field/Domain.h>
15#include <rp/field/CFields.h>
16#include <rp/field/WFields.h>
17#include <rp/field/Mask.h>
19#include <pscf/field/RField.h>
20#include <pscf/crystal/Basis.h>
21#include <pscf/crystal/UnitCell.h>
22#include <pscf/crystal/paramIdConversions.h>
23#include <pscf/field/cuda/resources.h>
25#include <pscf/interaction/Interaction.h>
53 __global__
void _maskDerivative(
cudaReal * deriv,
56 int const normalVecId,
60 int ix = blockIdx.x * blockDim.x + threadIdx.x;
61 int iy = blockIdx.y * blockDim.y + threadIdx.y;
62 int iz = blockIdx.z * blockDim.z + threadIdx.z;
87 deriv[id] = maskVal * (maskVal - 1) * 8.0 * (
abs(d - 0.5) - 0.5)
106 int const normalVecId, dim3
const meshDims)
109 int ix = blockIdx.x * blockDim.x + threadIdx.x;
110 int iy = blockIdx.y * blockDim.y + threadIdx.y;
111 int iz = blockIdx.z * blockDim.z + threadIdx.z;
139 0.5 * (excludedThickness - nvLength) +
140 abs(d - (nvLength / 2.0))
142 * 4.0 / interfaceThickness
189 system().domain().lattice());
190 if (normalVecParamId != paramId)
return 0.0;
196 double phiTot =
system().mask().phiTot();
200 deriv.allocate(
system().domain().mesh().dimensions());
208 _maskDerivative<D><<<gridDims, blockDims>>>
209 (deriv.cArray(),
system().mask().rgrid().cArray(),
214 xi.allocate(
system().domain().mesh().dimensions());
216 if (
system().h().hasData()) {
222 int nMonomer =
system().mixture().nMonomer();
223 for (
int i = 0; i < nMonomer; i++) {
224 double chi =
system().interaction().chi(0, i);
225 if (fabs(chi) > 1e-6) {
232 intTerm /= phiTot * deriv.capacity();
235 if (!sysPtr_->scft().hasData()) {
236 sysPtr_->scft().compute();
238 double pSys = sysPtr_->scft().pressure();
242 double dPhiTot =
Reduce::sum(deriv) / double(deriv.capacity());
243 double pTerm = pSys * dPhiTot / phiTot;
245 return pTerm - intTerm;
259 system().domain().lattice());
262 if (nvParamId != paramId)
return stress;
268 UTIL_THROW(
"fBulk must be set before calling modifyStress.");
272 if (!sysPtr_->scft().hasData()) {
273 sysPtr_->scft().compute();
275 double fSys = sysPtr_->scft().fHelmholtz();
278 double L =
system().domain().unitCell().parameter(paramId);
283 return modifiedStress;
299 system().domain().lattice());
300 double nvLength =
system().domain().unitCell().parameter(paramId);
304 rGrid.allocate(
system().domain().mesh().dimensions());
312 _generateMask<D><<<gridDims, blockDims>>>
317 bool isSymmetric =
system().domain().hasGroup();
323 system().mask().setRGrid(rGrid, isSymmetric);
335 if (
system().hasIterator() &&
system().iterator().isFlexible()) {
338 system().domain().unitCell());
339 sysPtr_->iterator().setFlexibleParams(updated);
349 template class FilmFieldGenMask<1,CUT>;
350 template class FilmFieldGenMask<2,CUT>;
351 template class FilmFieldGenMask<3,CUT>;
double excludedThickness() const
Get value of excludedThickness.
double fBulk_
Reference free energy used to calculate stress normal to the film.
int normalVecId() const
Get value of normalVecId.
FilmFieldGenMaskBase()
Constructor.
double interfaceThickness() const
Get value of interfaceThickness.
bool hasFBulk() const
Check whether a value of fBulk was provided.
FSArray< bool, 6 > modifyFlexibleParams(FSArray< bool, 6 > current, UnitCell< D > const &cell) const
Modifies a flexibleParams array to be compatible with this mask.
RealVec< D > normalVecCurrent_
The lattice vector normal to the film used to generate these fields.
double stress(int paramId) const
Get contribution to the stress from this mask.
RealVec< D > systemLatticeVector(int id) const
Get one of the lattice vectors for this system.
System< D, CUT > & system()
Get the System associated with this object by reference.
FilmFieldGenMask()
Default constructor.
Base class template for classes that represent a complete system.
A fixed capacity (static) contiguous array with a variable logical size.
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
double abs(fftw_complex const &a)
Return absolute magnitude of an fftw_complex number.
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.
double innerProduct(Array< double > const &a, Array< double > const &b)
Compute Euclidean inner product of two real arrays .
double sum(Array< double > const &in)
Compute sum of array elements (real).
void eqV(Array< double > &a, Array< double > const &b, const int beginIdA, const int beginIdB, const int n)
Vector assignment, a[i] = b[i] (real, slice).
void subVV(Array< double > &a, Array< double > const &b, Array< double > const &c)
Vector-vector subtraction, a[i] = b[i] - c[i] (real).
void addEqVc(Array< double > &a, Array< double > const &b, const double c)
Add scaled vector in-place, a[i] += b[i]*c (real).
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.
cufftDoubleReal cudaReal
Real number type used in CPU code that uses FFTW.