| 40 | } |
| 41 | |
| 42 | void test_scalar_function() |
| 43 | { |
| 44 | auto grid = geode::RegularGrid3D::create(); |
| 45 | auto builder = geode::RegularGridBuilder3D::create( *grid ); |
| 46 | builder->initialize_grid( |
| 47 | geode::Point3D{ { 1.5, 0, 1 } }, { 5, 10, 15 }, { 1, 2, 3 } ); |
| 48 | const auto function_name = "scalar_function"; |
| 49 | auto scalar_function = |
| 50 | geode::GridScalarFunction3D::create( *grid, function_name, 26 ); |
| 51 | scalar_function.set_value( { 1, 2, 3 }, 22 ); |
| 52 | for( const auto i : geode::LRange{ 6 } ) |
| 53 | { |
| 54 | for( const auto j : geode::LRange{ 11 } ) |
| 55 | { |
| 56 | for( const auto k : geode::LRange{ 16 } ) |
| 57 | { |
| 58 | if( i == 1 && j == 2 && k == 3 ) |
| 59 | { |
| 60 | geode::OpenGeodeMeshException::test( |
| 61 | scalar_function.value( |
| 62 | geode::Grid3D::VertexIndices{ { i, j, k } } ) |
| 63 | == 22, |
| 64 | "Object function value is wrong." ); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | geode::OpenGeodeMeshException::test( |
| 69 | scalar_function.value( |
| 70 | geode::Grid3D::VertexIndices{ { i, j, k } } ) |
| 71 | == 26, |
| 72 | "Object function value is wrong." ); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | scalar_function.set_value( 217, 22 ); |
| 78 | geode::OpenGeodeMeshException::test( |
| 79 | scalar_function.value( 217 ) == 22, "Object function value is wrong." ); |
| 80 | scalar_function.set_value( { 1, 2, 4 }, 22 ); |
| 81 | scalar_function.set_value( { 1, 3, 4 }, 22 ); |
| 82 | scalar_function.set_value( { 2, 2, 3 }, 22 ); |
| 83 | scalar_function.set_value( { 2, 3, 3 }, 22 ); |
| 84 | scalar_function.set_value( { 2, 2, 4 }, 22 ); |
| 85 | scalar_function.set_value( { 2, 3, 4 }, 22 ); |
| 86 | geode::Point3D point{ { 2.6, 4.1, 11.2 } }; |
| 87 | auto cell_indices = grid->cells( point ); |
| 88 | geode::OpenGeodeMeshException::test( |
| 89 | inexact_equal( |
| 90 | scalar_function.value( point, cell_indices[0] ), 22, 1e-7 ), |
| 91 | "Object function value 1 is wrong." ); |
| 92 | point = geode::Point3D{ { 1.5, 0, 1 } }; |
| 93 | cell_indices = grid->cells( point ); |
| 94 | geode::OpenGeodeMeshException::test( |
| 95 | inexact_equal( |
| 96 | scalar_function.value( point, cell_indices[0] ), 26, 1e-7 ), |
| 97 | "Object function value 2 is wrong." ); |
| 98 | point = geode::Point3D{ { 3, 4, 10 } }; |
| 99 | cell_indices = grid->cells( point ); |
no test coverage detected