Skip to content

Commit df0992a

Browse files
committedSep 20, 2024·
Add some additional code to respect fillvalues.
1 parent a999325 commit df0992a

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed
 

‎src/orca-jedi/increment/Increment.cc

+17-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Increment & Increment::operator*=(const double & zz) {
212212
return *this;
213213
}
214214

215-
/// \brief Create increment from the different of two state objects.
215+
/// \brief Create increment from the difference of two state objects.
216216
/// \param x1 State object.
217217
/// \param x2 State object subtracted.
218218
void Increment::diff(const State & x1, const State & x2) {
@@ -227,6 +227,13 @@ void Increment::diff(const State & x1, const State & x2) {
227227
atlas::Field field2 = x2.getField(i);
228228
atlas::Field fieldi = incrementFields_[i];
229229

230+
atlas::field::MissingValue mv1(field1);
231+
bool has_mv1 = static_cast<bool>(mv1);
232+
atlas::field::MissingValue mv2(field2);
233+
bool has_mv2 = static_cast<bool>(mv2);
234+
bool has_mv = has_mv1 || has_mv2;
235+
oops::Log::debug() << "DJL Increment::diff mv1 " << mv1 << " mv2 " << mv2 << " has_mv " << has_mv << std::endl;
236+
230237
std::string fieldName1 = field1.name();
231238
std::string fieldName2 = field2.name();
232239
std::string fieldNamei = fieldi.name();
@@ -239,8 +246,15 @@ void Increment::diff(const State & x1, const State & x2) {
239246
auto field_viewi = atlas::array::make_view<double, 2>(fieldi);
240247
for (atlas::idx_t j = 0; j < field_viewi.shape(0); ++j) {
241248
for (atlas::idx_t k = 0; k < field_viewi.shape(1); ++k) {
242-
if (!ghost(j)) { field_viewi(j, k) = field_view1(j, k) - field_view2(j, k);
243-
} else { field_viewi(j, k) = 0; }
249+
if (!ghost(j)) {
250+
if (!has_mv1 || (has_mv1 && !mv1(field_view1(j,k)))) {
251+
if (!has_mv2 || (has_mv2 && !mv2(field_view2(j,k)))) {
252+
field_viewi(j, k) = field_view1(j, k) - field_view2(j, k);
253+
}
254+
}
255+
} else {
256+
field_viewi(j, k) = 0;
257+
}
244258
}
245259
}
246260
}

‎src/orca-jedi/interpolator/Interpolator.cc

+3
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ void Interpolator::apply(const oops::Variables& vars, const Increment& inc,
229229
auto field_view = atlas::array::make_view<double, 2>(tgt_field);
230230
atlas::field::MissingValue mv(inc.incrementFields()[gv_varname]);
231231
bool has_mv = static_cast<bool>(mv);
232+
oops::Log::debug() << "DJL Interpolator::apply mv " << mv << " has_mv " << has_mv << std::endl;
232233
for (std::size_t klev=0; klev < varSizes[jvar]; ++klev) {
233234
for (std::size_t iloc=0; iloc < nlocs_; iloc++) {
234235
if (has_mv && mv(field_view(iloc, klev))) {
@@ -310,6 +311,8 @@ void Interpolator::applyAD(const oops::Variables& vars, Increment& inc,
310311
// field_view.assign(0.0);
311312
atlas::field::MissingValue mv(inc.incrementFields()[gv_varname]);
312313
bool has_mv = static_cast<bool>(mv);
314+
oops::Log::debug() << "DJL Interpolator::applyAD mv " << mv << " has_mv " << has_mv << std::endl;
315+
313316
for (std::size_t klev=0; klev < varSizes[jvar]; ++klev) {
314317
for (std::size_t iloc=0; iloc < nlocs_; iloc++) {
315318
if (has_mv && mv(field_view(iloc, klev))) {

‎src/orca-jedi/state/State.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ State & State::operator+=(const Increment & dx) {
178178
for (int i = 0; i< stateFields_.size();i++)
179179
{
180180
atlas::Field field = stateFields_[i];
181+
atlas::field::MissingValue mv(field);
182+
bool has_mv = static_cast<bool>(mv);
183+
181184
atlas::Field fieldi = dx.incrementFields()[i];
182185

183186
std::string fieldName = field.name();
@@ -189,7 +192,11 @@ State & State::operator+=(const Increment & dx) {
189192
auto field_viewi = atlas::array::make_view<double, 2>(fieldi);
190193
for (atlas::idx_t j = 0; j < field_view.shape(0); ++j) {
191194
for (atlas::idx_t k = 0; k < field_view.shape(1); ++k) {
192-
if (!ghost(j)) field_view(j, k) += field_viewi(j, k);
195+
if (!ghost(j)) {
196+
if (!has_mv || (has_mv && !mv(field_view(j,k)))) {
197+
field_view(j, k) += field_viewi(j, k);
198+
}
199+
}
193200
}
194201
}
195202
}

0 commit comments

Comments
 (0)
Please sign in to comment.