382 Vector<int> is_counted;
383 is_counted.resize(
xloc.size(),0);
385 amrex::Gpu::DeviceVector<Real> d_xloc(
xloc.size());
386 amrex::Gpu::DeviceVector<Real> d_yloc(
yloc.size());
387 amrex::Gpu::DeviceVector<Real> d_zloc(
xloc.size());
388 amrex::Gpu::DeviceVector<int> d_is_counted(
xloc.size());
389 amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice,
xloc.begin(),
xloc.end(), d_xloc.begin());
390 amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice,
yloc.begin(),
yloc.end(), d_yloc.begin());
391 amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice,
zloc.begin(),
zloc.end(), d_zloc.begin());
392 amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, is_counted.begin(), is_counted.end(), d_is_counted.begin());
394 Real* d_xloc_ptr = d_xloc.data();
395 Real* d_yloc_ptr = d_yloc.data();
396 Real* d_zloc_ptr = d_zloc.data();
397 int* d_is_counted_ptr = d_is_counted.data();
401 int i_lo = geom.Domain().smallEnd(0);
int i_hi = geom.Domain().bigEnd(0);
402 int j_lo = geom.Domain().smallEnd(1);
int j_hi = geom.Domain().bigEnd(1);
403 auto dx = geom.CellSizeArray();
404 if(
dx[0]<= 1e-3 or
dx[1]<=1e-3 or
dx[2]<= 1e-3) {
405 Abort(
"The value of mesh spacing for wind farm parametrization cannot be less than 1e-3 m. "
406 "It should be usually of order 1 m");
408 auto ProbLoArr = geom.ProbLoArray();
409 auto ProbHiArr = geom.ProbHiArray();
410 int num_turb =
xloc.size();
412 bool is_terrain = z_phys_nd ?
true:
false;
415 for ( MFIter mfi(mf_Nturb,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
416 const Box& bx = mfi.tilebox();
417 auto Nturb_array = mf_Nturb.array(mfi);
418 const Array4<const Real>& z_nd_arr = z_phys_nd->const_array(mfi);
419 int k0 = bx.smallEnd()[2];
420 ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
421 int li = amrex::min(amrex::max(i, i_lo), i_hi);
422 int lj = amrex::min(amrex::max(j, j_lo), j_hi);
424 Real x1 = ProbLoArr[0] + li*
dx[0];
425 Real x2 = ProbLoArr[0] + (li+1)*
dx[0];
426 Real y1 = ProbLoArr[1] + lj*
dx[1];
427 Real y2 = ProbLoArr[1] + (lj+1)*
dx[1];
429 for(
int it=0; it<num_turb; it++){
430 if( d_xloc_ptr[it]+1e-3 > x1 and d_xloc_ptr[it]+1e-3 < x2 and
431 d_yloc_ptr[it]+1e-3 > y1 and d_yloc_ptr[it]+1e-3 < y2){
432 Nturb_array(i,j,k,0) = Nturb_array(i,j,k,0) + 1;
438 if (Gpu::Atomic::CAS(&d_is_counted_ptr[it], expected, desired) == expected) {
440 Gpu::Atomic::Add(&d_zloc_ptr[it], z_nd_arr(i, j, k0));
448 Gpu::copy(Gpu::deviceToHost, d_zloc.begin(), d_zloc.end(),
zloc.begin());
449 Gpu::copy(Gpu::deviceToHost, d_is_counted.begin(), d_is_counted.end(), is_counted.begin());
451 amrex::ParallelAllReduce::Sum(
zloc.data(),
453 amrex::ParallelContext::CommunicatorAll());
455 amrex::ParallelAllReduce::Sum(is_counted.data(),
457 amrex::ParallelContext::CommunicatorAll());
459 for(
int it=0;it<num_turb;it++) {
461 xloc[it] > ProbLoArr[0] and
462 xloc[it] < ProbHiArr[0] and
463 yloc[it] > ProbLoArr[1] and
464 yloc[it] < ProbHiArr[1] ) {
465 if(is_counted[it] != 1) {
466 Abort(
"Wind turbine " + std::to_string(it) +
"has been counted " + std::to_string(is_counted[it]) +
" times" +
467 " It should have been counted only once. Aborting....");
const auto dx
Definition: ERF_InitCustomPertVels_ParticleTests.H:15
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const auto prob_lo=geomdata.ProbLo();const auto dx=geomdata.CellSize();const Real x=(prob_lo[0]+(i+0.5) *dx[0])/mf_m(i, j, 0);const Real z=z_cc(i, j, k);Real L=std::sqrt(std::pow((x - x_c)/x_r, 2)+std::pow((z - z_c)/z_r, 2));if(L<=1.0) { Real dT=T_pert *(std::cos(PI *L)+1.0)/2.0;Real Tbar_hse=p_hse(i, j, k)/(R_d *r_hse(i, j, k));Real theta_perturbed=(Tbar_hse+dT) *std::pow(p_0/p_hse(i, j, k), rdOcp);Real theta_0=(Tbar_hse) *std::pow(p_0/p_hse(i, j, k), rdOcp);if(const_rho) { state_pert(i, j, k, RhoTheta_comp)=r_hse(i, j, k) *(theta_perturbed - theta_0);} else { state_pert(i, j, k, Rho_comp)=getRhoThetagivenP(p_hse(i, j, k))/theta_perturbed - r_hse(i, j, k);} } })
amrex::Real Real
Definition: ERF_ShocInterface.H:19
amrex::Vector< amrex::Real > yloc
Definition: ERF_WindFarm.H:153
amrex::Vector< amrex::Real > zloc
Definition: ERF_WindFarm.H:153
amrex::Vector< amrex::Real > xloc
Definition: ERF_WindFarm.H:153