Skip to content

Commit 873c56c

Browse files
committed
Fix GMG projection and edge clamping
1 parent f3f7b0b commit 873c56c

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/GeographicProjection.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ void GeographicProjection::computeCartesianCoordGMG(double &x, double &y,
205205

206206
ASSERT(m_Pgmg);
207207

208-
// lat lon is switched in GMG CRS
209-
c = proj_coord(lat, lon, 0.0, 0.0);
208+
c = proj_coord(lon, lat, 0.0, 0.0);
210209
c_out = proj_trans(m_Pgmg, PJ_FWD, c);
211210

212211
x = c_out.xyzt.y;

src/MaterialGMG.C

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ void MaterialGMG::set_material_properties(std::vector<Sarray> & rho,
117117
gmg_y = xRel*sinAz + yRel*cosAz;
118118

119119

120-
const int top_i = static_cast<int>(floor(gmg_x/m_Top_hx));
121-
const int top_j = static_cast<int>(floor(gmg_y/m_Top_hy));
122-
if (top_i < 0 || top_i >= static_cast<int>(m_Top_dims[0]) ||
123-
top_j < 0 || top_j >= static_cast<int>(m_Top_dims[1])) {
124-
outside += static_cast<size_t>(mEW->m_kEnd[g] - mEW->m_kStart[g] + 1);
125-
continue;
126-
}
120+
int top_i = static_cast<int>(floor(gmg_x/m_Top_hx));
121+
int top_j = static_cast<int>(floor(gmg_y/m_Top_hy));
122+
if (top_i < 0)
123+
top_i = 0;
124+
else if (top_i >= static_cast<int>(m_Top_dims[0]))
125+
top_i = static_cast<int>(m_Top_dims[0]) - 1;
126+
if (top_j < 0)
127+
top_j = 0;
128+
else if (top_j >= static_cast<int>(m_Top_dims[1]))
129+
top_j = static_cast<int>(m_Top_dims[1]) - 1;
127130

128131
top = -m_Top_surface[top_i*m_Top_dims[1] + top_j];
129132

@@ -163,8 +166,12 @@ void MaterialGMG::set_material_properties(std::vector<Sarray> & rho,
163166
// Extend the material value if simulation grid is larger than material grid
164167
if (i0 >= m_ni[gr] - 1)
165168
i0 = m_ni[gr] - 2;
169+
if (i0 < 0)
170+
i0 = 0;
166171
if (j0 >= m_nj[gr] - 1)
167172
j0 = m_nj[gr] - 2;
173+
if (j0 < 0)
174+
j0 = 0;
168175
if (k0 >= m_nk[gr] - 1)
169176
k0 = m_nk[gr] - 2;
170177
if (k0 < 0)

0 commit comments

Comments
 (0)