From b7bd2ac6561112c124f2a7f56e12dceae4de5872 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 --- .gitignore | 1 + src/velocity.c | 12 ++++++++++++ src/velocity.h | 3 +++ test/velocity_test.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/.gitignore b/.gitignore index 509633e..25f8ad2 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ **/*.cbp **/CMakeScripts **/compile_commands.json +**/_deps ## Local .idea/ 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