Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use max_courant_time in mesh refinement #226

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace meshkernel
void Compute() override;

private:
/// @brief Performs bilinear interpolation
/// @brief Performs bi-linear interpolation
/// @param[in] point The input point
/// @return The result of bilinear interpolation at the point
double Interpolation(const Point& point) const;
Expand All @@ -87,7 +87,7 @@ namespace meshkernel
return m_values[index];
}

const Mesh2D& m_mesh; ///< Pointer to the mesh
const Mesh2D& m_mesh; ///< Reference to the mesh
UInt m_numXCoord; ///< The number of x coordinates of the gridded data
UInt m_numYCoord; ///< The number of y coordinates of the gridded data
Point m_origin; ///< The coordinate of the origin
Expand Down
5 changes: 2 additions & 3 deletions libs/MeshKernel/src/MeshRefinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,11 +1037,10 @@ void MeshRefinement::ComputeEdgeBelowMinSizeAfterRefinement()

bool MeshRefinement::IsRefineNeededBasedOnCourantCriteria(UInt edge, double depthValues) const
{
const double maxDtCourant = 120.0;
const double maxDtCourant = m_meshRefinementParameters.max_courant_time;
const double celerity = constants::physical::sqrt_gravity * std::sqrt(std::abs(depthValues));
const double waveCourant = celerity * maxDtCourant / m_mesh->m_edgeLengths[edge];
bool doRefinement = waveCourant < 1.0;
return doRefinement;
return waveCourant < 1.0;
}

void MeshRefinement::ComputeEdgesRefinementMask()
Expand Down
23 changes: 21 additions & 2 deletions libs/MeshKernelApi/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ add_executable(${TARGET_NAME})
# source directory
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)

# include directory
set(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

# list of target sources
set(SRC_LIST ${SRC_DIR}/ApiTest.cpp)
set(SRC_LIST
${SRC_DIR}/ApiTest.cpp
${SRC_DIR}/Mesh2DRefinmentTests.cpp
)

set(INC_LIST
${INC_DIR}/CartesianApiTestFixture.hpp
)

# add sources to target
target_sources(${TARGET_NAME} PRIVATE ${SRC_LIST})
target_sources(${TARGET_NAME} PRIVATE ${SRC_LIST} ${INC_LIST})

# Expose the interface of the shared lib
target_include_directories(${TARGET_NAME} PUBLIC ${INC_DIR})

# Should be linked to the main library, as well as the google test library
target_link_libraries(
Expand Down Expand Up @@ -49,3 +62,9 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:MeshKernelApi>" "$<TARGET_FILE_DIR:MeshKernelApiUnitTests>"
COMMENT "Copying MeshKernel shared library"
)

# group the sources in IDE tree
source_group("Source Files" FILES ${SRC_LIST})

# group the headers in IDE tree
source_group("Header Files" FILES ${INC_LIST})
110 changes: 110 additions & 0 deletions libs/MeshKernelApi/tests/include/CartesianApiTestFixture.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <MeshKernel/Parameters.hpp>

#include <MeshKernelApi/GeometryList.hpp>
#include <MeshKernelApi/Mesh2D.hpp>
#include <MeshKernelApi/MeshKernel.hpp>

#include <TestUtils/MakeMeshes.hpp>

class CartesianApiTestFixture : public testing::Test
{
public:
/// Constructor for allocating state
CartesianApiTestFixture()
{
int isGeographic = 0;
const auto errorCode = meshkernelapi::mkernel_allocate_state(isGeographic, m_meshKernelId);
if (errorCode != 0)
{
throw std::runtime_error("Could not allocate state");
}
}

/// Destructor for deallocating state
~CartesianApiTestFixture()
{
meshkernelapi::mkernel_deallocate_state(m_meshKernelId);
}

/// @brief Make a mesh
/// @param[in] numRows Number of rows
/// @param[in] numColumns Number of columns
/// @param[in] delta Distance between neighboring nodes
void MakeMesh(meshkernel::UInt numRows = 2, meshkernel::UInt numColumns = 3, double delta = 1.0)
{
// Set-up new mesh
auto [num_nodes, num_edges, node_x, node_y, edge_nodes] = MakeRectangularMeshForApiTesting(numRows, numColumns, delta);
meshkernelapi::Mesh2D mesh2d{};
mesh2d.num_edges = static_cast<int>(num_edges);
mesh2d.num_nodes = static_cast<int>(num_nodes);
mesh2d.node_x = node_x.data();
mesh2d.node_y = node_y.data();
mesh2d.edge_nodes = edge_nodes.data();
const auto errorCode = mkernel_mesh2d_set(m_meshKernelId, mesh2d);
if (errorCode != 0)
{
throw std::runtime_error("Could not set mesh2d");
}
}

void MakeUniformCurvilinearGrid(meshkernel::UInt numberOfColumns = 4,
meshkernel::UInt numberOfRows = 4,
double blockSizeX = 10.0,
double blockSizeY = 10.0,
double originX = 0.0,
double originY = 0.0) const
{
meshkernel::MakeGridParameters makeGridParameters{};
meshkernelapi::GeometryList geometryList{};

makeGridParameters.num_columns = static_cast<int>(numberOfColumns);
makeGridParameters.num_rows = static_cast<int>(numberOfRows);
makeGridParameters.angle = 0.0;
makeGridParameters.origin_x = originX;
makeGridParameters.origin_y = originY;
makeGridParameters.block_size_x = blockSizeX;
makeGridParameters.block_size_y = blockSizeY;

auto const errorCode = mkernel_curvilinear_make_uniform(m_meshKernelId, makeGridParameters, geometryList);
if (errorCode != 0)
{
throw std::runtime_error("Could not create uniform curvilinear grid");
}
}

[[nodiscard]] int GetMeshKernelId() const
{
return m_meshKernelId;
}

private:
int m_meshKernelId{};
};

static auto GebcoMakeGridParameters()
{

double lonMin = -1;
double lonMax = -0.2;
double latMin = 49.1;
double latMax = 49.6;
double lonRes = 0.1;
double latRes = 0.1;
int numX = static_cast<int>(std::ceil((lonMax - lonMin) / lonRes));
int numY = static_cast<int>(std::ceil((latMax - latMin) / latRes));

meshkernel::MakeGridParameters makeGridParameters{};

makeGridParameters.num_columns = numX;
makeGridParameters.num_rows = numY;
makeGridParameters.angle = 0.0;
makeGridParameters.origin_x = lonMin;
makeGridParameters.origin_y = latMin;
makeGridParameters.block_size_x = 0.1;
makeGridParameters.block_size_y = 0.1;

return makeGridParameters;
}
Loading
Loading