Skip to content

Commit

Permalink
Added norm checks on fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
odlomax committed Jan 6, 2024
1 parent 6c2feb9 commit da790ca
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/tests/interpolation/test_interpolation_spherical_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*/

#include <cmath>
#include <utility>

#include "atlas/array.h"
Expand Down Expand Up @@ -166,8 +167,10 @@ void testInterpolation(const Config& config) {
FieldSpecFixtures::get(config.getString("field_spec_fixture"));
if constexpr (Rank == 3) fieldSpec.set("levels", 2);

auto sourceField = sourceFieldSet.add(sourceFunctionSpace.createField<double>(fieldSpec));
auto targetField = targetFieldSet.add(targetFunctionSpace.createField<double>(fieldSpec));
auto sourceField =
sourceFieldSet.add(sourceFunctionSpace.createField<double>(fieldSpec));
auto targetField =
targetFieldSet.add(targetFunctionSpace.createField<double>(fieldSpec));

auto sourceView = array::make_view<double, Rank>(sourceField);
auto targetView = array::make_view<double, Rank>(targetField);
Expand Down Expand Up @@ -239,6 +242,7 @@ void testInterpolation(const Config& config) {

// Adjoint test
auto targetAdjoint = targetFunctionSpace.createField<double>(fieldSpec);
auto targetAdjointView = array::make_view<double, Rank>(targetAdjoint);
targetAdjoint.array().copy(targetField);
targetAdjoint.adjointHaloExchange();

Expand All @@ -249,6 +253,23 @@ void testInterpolation(const Config& config) {

interp.execute_adjoint(sourceAdjoint, targetAdjoint);

// Check field norms.
const auto targetNorm = dotProduct(targetView, targetView);
const auto sourceNorm = dotProduct(sourceView, sourceView);
const auto targetAdjointNorm =
dotProduct(targetAdjointView, targetAdjointView);
const auto sourceAdjointNorm =
dotProduct(sourceAdjointView, sourceAdjointView);

EXPECT(targetNorm > 0.);
EXPECT(sourceNorm > 0.);
EXPECT(targetAdjointNorm > 0.);
EXPECT(sourceAdjointNorm > 0.);
EXPECT(std::isfinite(targetNorm));
EXPECT(std::isfinite(sourceNorm));
EXPECT(std::isfinite(targetAdjointNorm));
EXPECT(std::isfinite(sourceAdjointNorm));

constexpr auto tinyNum = 1e-13;
const auto targetDotTarget = dotProduct(targetView, targetView);
const auto sourceDotSourceAdjoint = dotProduct(sourceView, sourceAdjointView);
Expand Down

0 comments on commit da790ca

Please sign in to comment.