1#ifndef SAMPLINGCONTAINER_H
2#define SAMPLINGCONTAINER_H
6#include "AMReX_AmrParticles.H"
60 :
public amrex::AmrParticleContainer<
68 :
amrex::AmrParticleContainer<
79 const int num_real_components,
const int num_int_components = 0);
84 const amrex::Vector<std::unique_ptr<SamplerBase>>& );
87 template <
typename FType>
90 BL_PROFILE(
"amr-wind::SamplingContainer::interpolate_fields");
92 const int nlevels =
m_mesh.finestLevel() + 1;
94 for (
int lev = 0; lev < nlevels; ++lev) {
95 for (ParIterType pti(*
this, lev); pti.isValid(); ++pti) {
96 int scomp_curr = scomp;
97 for (
const auto* fld : fields) {
98 AMREX_ALWAYS_ASSERT(fld->num_grow() > amrex::IntVect{0});
99 const auto farr = (*fld)(lev).const_array(pti);
101 pti, farr, lev, fld->field_location(), fld->num_comp(),
104 scomp_curr += fld->num_comp();
135 template <
typename FType>
139 SamplingContainer::ParticleVector& pvec,
140 SamplingContainer::RealVector& pavec,
142 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& problo,
143 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxi,
144 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dx,
145 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& offset)
147 BL_PROFILE(
"amr-wind::SamplingContainer::sample_impl");
149 auto* pstruct = pvec.data();
150 auto* parr = pavec.data();
152 amrex::ParallelFor(np, [=] AMREX_GPU_DEVICE(
int ip)
noexcept {
153 auto& p = pstruct[ip];
155 const amrex::Real x =
156 (p.pos(0) - problo[0] - offset[0] * dx[0]) * dxi[0];
157 const amrex::Real y =
158 (p.pos(1) - problo[1] - offset[1] * dx[1]) * dxi[1];
159 const amrex::Real z =
160 (p.pos(2) - problo[2] - offset[2] * dx[2]) * dxi[2];
163 const int i =
static_cast<int>(std::floor(x));
164 const int j =
static_cast<int>(std::floor(y));
165 const int k =
static_cast<int>(std::floor(z));
168 const amrex::Real wx_hi = (x - i);
169 const amrex::Real wy_hi = (y - j);
170 const amrex::Real wz_hi = (z - k);
172 const amrex::Real wx_lo = 1.0 - wx_hi;
173 const amrex::Real wy_lo = 1.0 - wy_hi;
174 const amrex::Real wz_lo = 1.0 - wz_hi;
176 parr[ip] = wx_lo * wy_lo * wz_lo * farr(i, j, k, ic) +
177 wx_lo * wy_lo * wz_hi * farr(i, j, k + 1, ic) +
178 wx_lo * wy_hi * wz_lo * farr(i, j + 1, k, ic) +
179 wx_lo * wy_hi * wz_hi * farr(i, j + 1, k + 1, ic) +
180 wx_hi * wy_lo * wz_lo * farr(i + 1, j, k, ic) +
181 wx_hi * wy_lo * wz_hi * farr(i + 1, j, k + 1, ic) +
182 wx_hi * wy_hi * wz_lo * farr(i + 1, j + 1, k, ic) +
183 wx_hi * wy_hi * wz_hi * farr(i + 1, j + 1, k + 1, ic);
189 template <
typename FType>
191 const ParIterType& pti,
198 const auto& geom =
m_mesh.Geom(lev);
199 const auto dx = geom.CellSizeArray();
200 const auto dxi = geom.InvCellSizeArray();
201 const auto plo = geom.ProbLoArray();
202 const int np = pti.numParticles();
203 auto& pvec = pti.GetArrayOfStructs()();
205 for (
int ic = 0; ic < ncomp; ++ic) {
206 auto& parr = pti.GetStructOfArrays().GetRealData(fidx++);
210 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> offset{
212 sample_field(np, ic, pvec, parr, farr, plo, dxi, dx, offset);
217 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> offset{
219 sample_field(np, ic, pvec, parr, farr, plo, dxi, dx, offset);
224 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> offset{
226 sample_field(np, ic, pvec, parr, farr, plo, dxi, dx, offset);
231 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> offset{
233 sample_field(np, ic, pvec, parr, farr, plo, dxi, dx, offset);
238 amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> offset{
240 sample_field(np, ic, pvec, parr, farr, plo, dxi, dx, offset);
Definition DerivedQuantity.H:32
Definition FieldRepo.H:86
Definition SamplingContainer.H:65
long m_total_particles
Definition SamplingContainer.H:249
const amrex::AmrCore & m_mesh
Definition SamplingContainer.H:247
void interpolate(const ParIterType &pti, const FType &farr, const int lev, const FieldLoc floc, const int ncomp, const int scomp)
Interpolate from an array4 onto particles.
Definition SamplingContainer.H:190
void interpolate_fields(const amrex::Vector< FType > &fields, const int scomp)
Perform field interpolation to sampling locations.
Definition SamplingContainer.H:88
SamplingContainer(amrex::AmrCore &mesh)
Definition SamplingContainer.H:67
long & num_sampling_particles()
Definition SamplingContainer.H:121
long num_sampling_particles() const
Definition SamplingContainer.H:119
void initialize_particles(const amrex::Vector< std::unique_ptr< SamplerBase > > &)
Definition SamplingContainer.cpp:28
void populate_buffer(std::vector< double > &buf)
Populate the buffer with data for all the particles.
Definition SamplingContainer.cpp:151
void setup_container(const int num_real_components, const int num_int_components=0)
Definition SamplingContainer.cpp:8
void interpolate_derived_fields(const DerivedQtyMgr &derived_mgr, const FieldRepo &repo, const int scomp)
Perform derived field interpolation to sampling locations.
Definition SamplingContainer.cpp:131
void sample_field(const int np, const int ic, SamplingContainer::ParticleVector &pvec, SamplingContainer::RealVector &pavec, const FType &farr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &problo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxi, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dx, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &offset)
Definition SamplingContainer.H:136
FieldLoc
Definition FieldDescTypes.H:27
@ NODE
Node-centered (e.g., for pressure)
@ ZFACE
Face-centered in z-direction.
@ XFACE
Face-centered in x-direction (e.g., face normal velocity)
@ CELL
Cell-centered (default)
@ YFACE
Face-centered in y-direction.
static constexpr int SNArrayReal
Definition SamplingContainer.H:19
static constexpr int SNStructReal
Definition SamplingContainer.H:17
static constexpr int SNArrayInt
Definition SamplingContainer.H:20
static constexpr int SNStructInt
Definition SamplingContainer.H:18
Definition BCInterface.cpp:7
Definition console_io.cpp:25
Definition SamplingContainer.H:26
Indices
Definition SamplingContainer.H:27
@ nid
Index within the set for this particle.
Definition SamplingContainer.H:30
@ uid
Unique identifier for this particle.
Definition SamplingContainer.H:28
@ sid
Identifier of the set this particle belongs to.
Definition SamplingContainer.H:29