From b6e253c13a2b0ad86d15c7fce9311c5d0804b823 Mon Sep 17 00:00:00 2001 From: David Graham Date: Sun, 5 May 2024 00:04:30 -0400 Subject: [PATCH] simple velocity model function for generating quick velocity model with just a starting velocity and gradient --- src/velocity.c | 12 ++++++++++++ src/velocity.h | 3 +++ test/velocity_test.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/velocity.c b/src/velocity.c index c0e7f56..b90f83d 100644 --- a/src/velocity.c +++ b/src/velocity.c @@ -14,3 +14,15 @@ VelocityModel *allocate_velocity_model(const int rows, const int cols) { return model; } + +VelocityModel *simple_velocity_model(VelocityModel *model, + const double gradient, + const double startingVelocity) { + + for (int i = 0; i < model->rows; i++) { + for (int j = 0; j < model->cols; j++) { + model->data[i][j] = startingVelocity + gradient * i; + } + }; + return model; +} diff --git a/src/velocity.h b/src/velocity.h index 007c8a4..5b56f6c 100644 --- a/src/velocity.h +++ b/src/velocity.h @@ -13,4 +13,7 @@ typedef struct { VelocityModel *allocate_velocity_model(int rows, int cols); +VelocityModel *simple_velocity_model(VelocityModel *model, double gradient, + double startingVelocity); + #endif // VELOCITY_H diff --git a/test/velocity_test.cpp b/test/velocity_test.cpp index 5fe9205..cffe957 100644 --- a/test/velocity_test.cpp +++ b/test/velocity_test.cpp @@ -25,3 +25,33 @@ TEST(VelocityModel, AllocateVelocityModel) { ASSERT_NE(model->data[i], nullptr); } } + +TEST(SimpleVelocityModel, ShouldApplyCorrectGradient) { + int rows = 5; + int cols = 10; + double gradient = 2.0; + double startingVelocity = 1.0; + VelocityModel *model = allocate_velocity_model(rows, cols); + model = simple_velocity_model(model, gradient, startingVelocity); + for (int i = 0; i < model->rows; i++) { + for (int j = 0; j < model->cols; j++) { + ASSERT_EQ(model->data[i][j], startingVelocity + gradient * i); + } + } + free(model); +} + +TEST(SimpleVelocityModel, ShouldHandleZeroGradient) { + int rows = 5; + int cols = 10; + double gradient = 0.0; + double startingVelocity = 1.0; + VelocityModel *model = allocate_velocity_model(rows, cols); + model = simple_velocity_model(model, gradient, startingVelocity); + for (int i = 0; i < model->rows; i++) { + for (int j = 0; j < model->cols; j++) { + ASSERT_EQ(model->data[i][j], startingVelocity); + } + } + free(model); +} \ No newline at end of file