Skip to content

Commit

Permalink
simple velocity model function for generating quick velocity model wi…
Browse files Browse the repository at this point in the history
…th just a starting velocity and gradient
  • Loading branch information
dpgraham4401 committed May 5, 2024
1 parent ff84a21 commit b7bd2ac
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
**/*.cbp
**/CMakeScripts
**/compile_commands.json
**/_deps

## Local
.idea/
Expand Down
12 changes: 12 additions & 0 deletions src/velocity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/velocity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions test/velocity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit b7bd2ac

Please sign in to comment.