@@ -42,14 +42,20 @@ void OceanWavesBoundary::post_init_actions()
42
42
m_repo.get_field (" velocity" )
43
43
.register_fill_patch_op <OceanWavesFillInflow>(
44
44
m_mesh, m_time, *this );
45
- if (m_repo.field_exists (" vof" )) {
45
+ m_vof_exists = m_repo.field_exists (" vof" );
46
+ if (m_vof_exists) {
46
47
m_repo.get_field (" vof" )
47
48
.register_fill_patch_op <OceanWavesFillInflow>(
48
49
m_mesh, m_time, *this );
49
50
m_repo.get_field (" density" )
50
51
.register_fill_patch_op <OceanWavesFillInflow>(
51
52
m_mesh, m_time, *this );
52
53
}
54
+
55
+ m_terrain_exists = m_repo.int_field_exists (" terrain_blank" );
56
+ if (m_terrain_exists) {
57
+ m_terrain_blank_ptr = &m_repo.get_int_field (" terrain_blank" );
58
+ }
53
59
}
54
60
}
55
61
@@ -73,6 +79,8 @@ void OceanWavesBoundary::set_velocity(
73
79
const int nghost = 1 ;
74
80
const auto & domain = geom.growPeriodicDomain (nghost);
75
81
82
+ const bool terrain_and_vof_exist = m_terrain_exists && m_vof_exists;
83
+
76
84
for (amrex::OrientationIter oit; oit != nullptr ; ++oit) {
77
85
auto ori = oit ();
78
86
if ((bctype[ori] != BC::mass_inflow) &&
@@ -85,10 +93,14 @@ void OceanWavesBoundary::set_velocity(
85
93
const auto & dbx = ori.isLow () ? amrex::adjCellLo (domain, idir, nghost)
86
94
: amrex::adjCellHi (domain, idir, nghost);
87
95
96
+ auto shift_to_interior =
97
+ amrex::IntVect::TheDimensionVector (idir) * (ori.isLow () ? 1 : -1 );
98
+
88
99
for (amrex::MFIter mfi (mfab); mfi.isValid (); ++mfi) {
89
100
auto gbx = amrex::grow (mfi.validbox (), nghost);
90
- const auto & bx =
91
- utils::face_aware_boundary_box_intersection (gbx, dbx, ori);
101
+ amrex::IntVect shift_to_cc = {0 , 0 , 0 };
102
+ const auto & bx = utils::face_aware_boundary_box_intersection (
103
+ shift_to_cc, gbx, dbx, ori);
92
104
if (!bx.ok ()) {
93
105
continue ;
94
106
}
@@ -98,12 +110,25 @@ void OceanWavesBoundary::set_velocity(
98
110
const auto & arr = mfab[mfi].array ();
99
111
const int numcomp = mfab.nComp ();
100
112
113
+ const auto terrain_blank_flags =
114
+ terrain_and_vof_exist
115
+ ? (*m_terrain_blank_ptr)(lev).const_array (mfi)
116
+ : amrex::Array4<int const >();
117
+
101
118
amrex::ParallelFor (
102
119
bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
120
+ const amrex::IntVect iv{i, j, k};
103
121
for (int n = 0 ; n < numcomp; n++) {
104
- if (targ_vof (i, j, k) > constants::TIGHT_TOL) {
105
- arr (i, j, k, dcomp + n) =
106
- targ_arr (i, j, k, orig_comp + n);
122
+ if (targ_vof (iv) > constants::TIGHT_TOL) {
123
+ arr (iv, dcomp + n) = targ_arr (iv, orig_comp + n);
124
+ }
125
+ if (terrain_and_vof_exist) {
126
+ // Terrain-blanked adjacent cell means 0 velocity
127
+ if (terrain_blank_flags (
128
+ iv + shift_to_cc + shift_to_interior) ==
129
+ 1 ) {
130
+ arr (iv, dcomp + n) = 0.0 ;
131
+ }
107
132
}
108
133
}
109
134
});
@@ -225,6 +250,7 @@ void OceanWavesBoundary::set_inflow_sibling_velocity(
225
250
226
251
BL_PROFILE (" amr-wind::OceanWavesBoundary::set_inflow_sibling_velocity" );
227
252
253
+ const bool terrain_and_vof_exist = m_terrain_exists && m_vof_exists;
228
254
const auto & bctype = fld.bc_type ();
229
255
const auto & geom = fld.repo ().mesh ().Geom (lev);
230
256
@@ -238,6 +264,10 @@ void OceanWavesBoundary::set_inflow_sibling_velocity(
238
264
239
265
const int idir = ori.coordDir ();
240
266
const auto & domain_box = geom.Domain ();
267
+
268
+ auto shift_to_interior =
269
+ amrex::IntVect::TheDimensionVector (idir) * (ori.isLow () ? 1 : -1 );
270
+
241
271
for (int fdir = 0 ; fdir < AMREX_SPACEDIM; ++fdir) {
242
272
243
273
// Only face-normal velocities populated here
@@ -268,6 +298,11 @@ void OceanWavesBoundary::set_inflow_sibling_velocity(
268
298
const auto & targ_arr = m_ow_velocity (lev).const_array (mfi);
269
299
const auto & marr = mfab[mfi].array ();
270
300
301
+ const auto terrain_blank_flags =
302
+ terrain_and_vof_exist
303
+ ? (*m_terrain_blank_ptr)(lev).const_array (mfi)
304
+ : amrex::Array4<int const >();
305
+
271
306
amrex::ParallelFor (
272
307
bx, [=] AMREX_GPU_DEVICE (
273
308
const int i, const int j, const int k) noexcept {
@@ -277,6 +312,14 @@ void OceanWavesBoundary::set_inflow_sibling_velocity(
277
312
if (targ_vof (cc_iv) > constants::TIGHT_TOL) {
278
313
marr (i, j, k, 0 ) = targ_arr (cc_iv, fdir);
279
314
}
315
+ if (terrain_and_vof_exist) {
316
+ // Terrain-blanked boundary-adjacent cell should set
317
+ // boundary velocity to 0
318
+ if (terrain_blank_flags (
319
+ cc_iv + shift_to_interior) == 1 ) {
320
+ marr (i, j, k, 0 ) = 0.0 ;
321
+ }
322
+ }
280
323
});
281
324
}
282
325
}
0 commit comments