Skip to content

Commit

Permalink
Adjusted test assert.
Browse files Browse the repository at this point in the history
  • Loading branch information
odlomax committed Jan 5, 2024
1 parent f4f859c commit 673729b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/tests/interpolation/test_interpolation_spherical_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ void testInterpolation(const Config& config) {
FieldSpecFixtures::get(config.getString("field_spec_fixture"));
if constexpr (Rank == 3) fieldSpec.set("levels", 2);

auto sourceField = array::make_view<double, Rank>(
sourceFieldSet.add(sourceFunctionSpace.createField<double>(fieldSpec)));
auto sourceField = sourceFieldSet.add(sourceFunctionSpace.createField<double>(fieldSpec));
auto targetField = targetFieldSet.add(targetFunctionSpace.createField<double>(fieldSpec));

auto targetField = array::make_view<double, Rank>(
targetFieldSet.add(targetFunctionSpace.createField<double>(fieldSpec)));
auto sourceView = array::make_view<double, Rank>(sourceField);
auto targetView = array::make_view<double, Rank>(targetField);

ArrayForEach<0>::apply(std::tie(sourceLonLat, sourceField),
ArrayForEach<0>::apply(std::tie(sourceLonLat, sourceView),
[](auto&& lonLat, auto&& sourceColumn) {

const auto setElems = [&](auto&& sourceElem) {
Expand Down Expand Up @@ -203,7 +203,7 @@ void testInterpolation(const Config& config) {
targetFunctionSpace.createField<double>(errorFieldSpec)));

auto maxError = 0.;
ArrayForEach<0>::apply(std::tie(targetLonLat, targetField, errorField),
ArrayForEach<0>::apply(std::tie(targetLonLat, targetView, errorField),
[&](auto&& lonLat, auto&& targetColumn,
auto&& errorColumn) {

Expand Down Expand Up @@ -238,7 +238,7 @@ void testInterpolation(const Config& config) {


// Adjoint test
auto targetAdjoint = targetFieldSet[0].clone();
auto targetAdjoint = targetField.clone();
targetAdjoint.adjointHaloExchange();

auto sourceAdjoint = sourceFunctionSpace.createField<double>(fieldSpec);
Expand All @@ -248,8 +248,9 @@ void testInterpolation(const Config& config) {
interp.execute_adjoint(sourceAdjoint, targetAdjoint);

constexpr auto tinyNum = 1e-13;
const auto dotProdRatio = fieldDotProd(targetFieldSet[0], targetFieldSet[0]) /
fieldDotProd(sourceFieldSet[0], sourceAdjoint);
const auto targetDotTarget = fieldDotProd(targetField, targetField);
const auto sourceDotSourceAdjoint = fieldDotProd(sourceField, sourceAdjoint);
const auto dotProdRatio = targetDotTarget / sourceDotSourceAdjoint;
EXPECT_APPROX_EQ(std::abs(1. - dotProdRatio), 0., tinyNum);
}

Expand Down

0 comments on commit 673729b

Please sign in to comment.