PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
delta_test.cpp
Go to the documentation of this file.
1
8#include <algorithm>
9#include <random>
10#include <vector>
11
12#include <petsc.h>
13
14#include "gtest/gtest.h"
15
16#include "petibm/delta.h"
17
18using namespace petibm::delta;
19
20// check value is zero outside region of influence
21TEST(deltaRomaEtAlTest, zeroOutside)
22{
23 const PetscReal h = 1.0;
24 EXPECT_EQ(0.0, Roma_et_al_1999(1.5, h));
25 EXPECT_EQ(0.0, Roma_et_al_1999(2.0, h));
26}
27
28// check maximum value at 0
29TEST(deltaRomaEtAlTest, maximumValue)
30{
31 const PetscReal h = 1.0;
32 EXPECT_EQ(2.0 / 3.0, Roma_et_al_1999(0.0, h));
33}
34
35// check delta function is monotonically decreasing
36TEST(deltaRomaEtAlTest, decreasingInfluence)
37{
38 const PetscReal h = 1.0;
39 // create a sorted vector of random reals between 0.0 and 1.5
40 std::vector<PetscReal> vals(10);
41 std::default_random_engine engine;
42 std::uniform_real_distribution<PetscReal> distrib(0.0, 1.5);
43 std::generate(vals.begin(), vals.end(), [&]() { return distrib(engine); });
44 std::sort(vals.begin(), vals.end());
45 // assert decreasing influence as the distance increases
46 for (unsigned int i = 0; i < vals.size() - 1; i++)
47 ASSERT_GT(Roma_et_al_1999(vals[i], h), Roma_et_al_1999(vals[i + 1], h));
48}
49
50// Run all tests
51int main(int argc, char **argv)
52{
53 PetscErrorCode ierr, status;
54
55 ::testing::InitGoogleTest(&argc, argv);
56 ierr = PetscInitialize(&argc, &argv, nullptr, nullptr); CHKERRQ(ierr);
57 status = RUN_ALL_TESTS();
58 ierr = PetscFinalize(); CHKERRQ(ierr);
59
60 return status;
61} // main
Prototype of Delta functions.
TEST(deltaRomaEtAlTest, zeroOutside)
Definition: delta_test.cpp:21
int main(int argc, char **argv)
Definition: delta_test.cpp:51
PetscReal Roma_et_al_1999(const PetscReal &r, const PetscReal &dr)
Regularized delta function from Roma et al. (1999).
Definition: delta.cpp:17
A namespace of all kinds of discretized delta functions.
Definition: delta.h:22