From 16b748b5cfaeffefa4a13edd4879d1857b4d0e04 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 6 Feb 2025 10:27:37 +0100 Subject: [PATCH 01/13] GRIDEDIT-1616: Add additional APIs to allow setting curvilinear frozen lines --- src/MeshKernelNET/Api/IMeshKernelApi.cs | 42 ++++++++++++++--- src/MeshKernelNET/Api/MeshKernelApi.cs | 26 ++++++++++- src/MeshKernelNET/Native/MeshKernelDll.cs | 46 ++++++++++++++++--- .../Api/MeshKernelCurvilinearTest.cs | 7 ++- 4 files changed, 103 insertions(+), 18 deletions(-) diff --git a/src/MeshKernelNET/Api/IMeshKernelApi.cs b/src/MeshKernelNET/Api/IMeshKernelApi.cs index fbdc09a..cf59bd0 100644 --- a/src/MeshKernelNET/Api/IMeshKernelApi.cs +++ b/src/MeshKernelNET/Api/IMeshKernelApi.cs @@ -576,21 +576,49 @@ int CurvilinearSetLineLineShift(int meshKernelId, double ySecondGridLineNode); /// - /// Smooths a curvilinear grid + /// Initialize curvilinear smoothing /// /// The meshKernelId of the block to orthogonalize /// The number of smoothing iterations to perform + /// Error code + int CurvilinearInitializeSmoothing([In] int meshKernelId, + [In] int smoothingIterations); + + /// + /// Sets the frozen lines for the curvilinear smoothing algorithm + /// + /// The x coordinate of the first point of the line to freeze + /// The y coordinate of the first point of the line to freeze + /// The x coordinate of the second point of the line to freeze + /// The y coordinate of the second point of the line to freeze + /// Error code + int CurvilinearSetFrozenLinesSmoothing([In] int meshKernelId, + [In] double xFirstGridLineNode, + [In] double yFirstGridLineNode, + [In] double xSecondGridLineNode, + [In] double ySecondGridLineNode); + + /// + /// Smooths the curvilinear grid inside a block + /// + /// The meshKernelId /// The x coordinate of the lower left corner of the block to smooth /// The y coordinate of the lower left corner of the block to smooth /// The x coordinate of the right corner of the block to smooth /// The y coordinate of the upper right corner of the block to smooth /// Error code - int CurvilinearSmoothing(int meshKernelId, - int smoothingIterations, - double xLowerLeftCorner, - double yLowerLeftCorner, - double xUpperRightCorner, - double yUpperRightCorner); + int CurvilinearSmoothing([In] int meshKernelId, + [In] double xLowerLeftCorner, + [In] double yLowerLeftCorner, + [In] double xUpperRightCorner, + [In] double yUpperRightCorner); + + /// + /// Sets the frozen lines for the curvilinear smoothing algorithm + /// + /// The meshKernelId + /// Error code + int CurvilinearFinalizeSmoothing([In] int meshKernelId); /// /// Smooths a curvilinear grid along the direction specified by a segment diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index 0fe5b61..edde9ad 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -538,21 +538,43 @@ public int CurvilinearSetLineLineShift(int meshKernelId, ySecondGridLineNode); } + public int CurvilinearInitializeSmoothing(int meshKernelId, + int smoothingIterations) + { + return MeshKernelDll.CurvilinearInitializeSmoothing(meshKernelId, smoothingIterations); + } + + public int CurvilinearSetFrozenLinesSmoothing(int meshKernelId, + double xFirstGridLineNode, + double yFirstGridLineNode, + double xSecondGridLineNode, + double ySecondGridLineNode) + { + return MeshKernelDll.CurvilinearSetFrozenLinesSmoothing(meshKernelId, + xFirstGridLineNode, + yFirstGridLineNode, + xSecondGridLineNode, + ySecondGridLineNode); + } + public int CurvilinearSmoothing(int meshKernelId, - int smoothingIterations, double xLowerLeftCorner, double yLowerLeftCorner, double xUpperRightCorner, double yUpperRightCorner) { return MeshKernelDll.CurvilinearSmoothing(meshKernelId, - smoothingIterations, xLowerLeftCorner, yLowerLeftCorner, xUpperRightCorner, yUpperRightCorner); } + public int CurvilinearFinalizeSmoothing(int meshKernelId) + { + return MeshKernelDll.CurvilinearFinalizeSmoothing(meshKernelId); + } + public int CurvilinearSmoothingDirectional(int meshKernelId, int smoothingIterations, double xFirstGridlineNode, diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index f6546c8..2271d78 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -635,10 +635,35 @@ internal static extern int CurvilinearSetLineLineShift([In] int meshKernelId, [In] double ySecondGridLineNode); /// - /// Smooths a curvilinear grid + /// Initialize curvilinear smoothing /// - /// The meshKernelId of the block to orthogonalize + /// The meshKernelId /// The number of smoothing iterations to perform + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_initialize_smoothing", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearInitializeSmoothing([In] int meshKernelId, + [In] int smoothingIterations); + + /// + /// Sets the frozen lines for the curvilinear smoothing algorithm + /// + /// The meshKernelId + /// The x coordinate of the first point of the line to freeze + /// The y coordinate of the first point of the line to freeze + /// The x coordinate of the second point of the line to freeze + /// The y coordinate of the second point of the line to freeze + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_set_frozen_lines_smoothing", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearSetFrozenLinesSmoothing([In] int meshKernelId, + [In] double xFirstGridLineNode, + [In] double yFirstGridLineNode, + [In] double xSecondGridLineNode, + [In] double ySecondGridLineNode); + + /// + /// Performs curvilinear smoothing + /// + /// The meshKernelId /// The x coordinate of the lower left corner of the block to smooth /// The y coordinate of the lower left corner of the block to smooth /// The x coordinate of the right corner of the block to smooth @@ -646,11 +671,18 @@ internal static extern int CurvilinearSetLineLineShift([In] int meshKernelId, /// Error code [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_smoothing", CallingConvention = CallingConvention.Cdecl)] internal static extern int CurvilinearSmoothing([In] int meshKernelId, - [In] int smoothingIterations, - [In] double xLowerLeftCorner, - [In] double yLowerLeftCorner, - [In] double xUpperRightCorner, - [In] double yUpperRightCorner); + [In] double xLowerLeftCorner, + [In] double yLowerLeftCorner, + [In] double xUpperRightCorner, + [In] double yUpperRightCorner); + + /// + /// Finalizes curvilinear smoothing algorithm + /// + /// The meshKernelId + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_finalize_smoothing", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFinalizeSmoothing([In] int meshKernelId); /// /// Smooths a curvilinear grid along the direction specified by a segment diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index 05218a5..5907f48 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -593,11 +593,14 @@ public void CurvilinearSmoothingThroughAPI() id = api.AllocateState(0); Assert.AreEqual(0, api.CurvilinearSet(id, grid)); + // Execute - Assert.AreEqual(0, api.CurvilinearSmoothing(id, 10, 10.0, 20.0, 30.0, 20.0)); + Assert.AreEqual(0, api.CurvilinearInitializeSmoothing(id, 10)); + Assert.AreEqual(0, api.CurvilinearSetFrozenLinesSmoothing(id, 10.0,0.0,10.0,10.0)); + Assert.AreEqual(0, api.CurvilinearSmoothing(id, 10.0, 20.0, 30.0, 20.0)); + Assert.AreEqual(0, api.CurvilinearFinalizeSmoothing(id)); // Assert - Assert.AreEqual(0, api.CurvilinearGridGetData(id, out curvilinearGrid)); } finally From f8ddd9f3271fb6af475c985437bd10b42f7b1149 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 6 Feb 2025 15:22:39 +0100 Subject: [PATCH 02/13] Set curvilinear frozen lines in the mesh state --- src/MeshKernelNET/Api/IMeshKernelApi.cs | 87 +++---------- src/MeshKernelNET/Api/MeshKernelApi.cs | 82 ++++--------- src/MeshKernelNET/Native/MeshKernelDll.cs | 114 +++++------------- .../Api/MeshKernelCurvilinearTest.cs | 34 ++++-- 4 files changed, 95 insertions(+), 222 deletions(-) diff --git a/src/MeshKernelNET/Api/IMeshKernelApi.cs b/src/MeshKernelNET/Api/IMeshKernelApi.cs index cf59bd0..6384890 100644 --- a/src/MeshKernelNET/Api/IMeshKernelApi.cs +++ b/src/MeshKernelNET/Api/IMeshKernelApi.cs @@ -238,13 +238,6 @@ int CurvilinearComputeTransfiniteFromTriangle(int meshKernelId, /// Error code int CurvilinearFinalizeLineShift(int meshKernelId); - /// - /// Finalizes curvilinear orthogonalize algorithm - /// - /// Id of the mesh state - /// Error code - int CurvilinearFinalizeOrthogonalize(int meshKernelId); - /// /// Gets the curvilinear data and returns a DisposableCurvilinearGrid /// @@ -334,14 +327,6 @@ int CurvilinearInitializeOrthogonalGridFromSplines(int meshKernelId, in CurvilinearParameters curvilinearParametersNative, in SplinesToCurvilinearParameters splinesToCurvilinearParameters); - /// - /// Initializes the orthogonal curvilinear algorithm - /// - /// The id of the mesh state - /// The orthogonalization parameters to use in the algorithm - /// Error code - int CurvilinearInitializeOrthogonalize(int meshKernelId, in OrthogonalizationParameters orthogonalizationParameters); - /// /// Inserts a new face on a curvilinear grid. The new face will be inserted on top of the closest edge by linear /// extrapolation. @@ -479,8 +464,18 @@ int CurvilinearMoveNodeLineShift(int meshKernelId, /// Orthogonalize a curvilinear grid /// /// The id of the mesh state + /// The orthogonalization parameters to use in the algorithm + /// The x coordinate of the lower left corner of the block to orthogonalize + /// The y coordinate of the lower left corner of the block to orthogonalize + /// The x coordinate of the upper right corner of the block to orthogonalize + /// The y coordinate of the upper right corner of the block to orthogonalize /// Error code - int CurvilinearOrthogonalize(int meshKernelId); + int CurvilinearOrthogonalize(int meshKernelId, + ref OrthogonalizationParameters orthogonalizationParameters, + double xLowerLeftCorner, + double yLowerLeftCorner, + double xUpperRightCorner, + double yUpperRightCorner); /// /// Directional curvilinear grid refinement. Additional gridlines are added perpendicularly to the segment defined by @@ -531,34 +526,21 @@ int CurvilinearSetBlockLineShift(int meshKernelId, double yUpperRightCorner); /// - /// efine a block on the curvilinear grid where to perform orthogonalization - /// - /// The meshKernelId of the block to orthogonalize - /// The xLowerLeftCorner of the block to orthogonalize - /// The yLowerLeftCorner of the block to orthogonalize - /// The xUpperRightCorner of the block to orthogonalize - /// The yUpperRightCorner of the block to orthogonalize - /// Error code - int CurvilinearSetBlockOrthogonalize(int meshKernelId, - double xLowerLeftCorner, - double yLowerLeftCorner, - double xUpperRightCorner, - double yUpperRightCorner); - - /// - /// Freezes a line in the curvilinear orthogonalization process + /// Freezes a line in the curvilinear grid /// /// The id of the mesh state /// The x coordinate of the first point of the line to freeze /// The y coordinate of the first point of the line to freeze /// The x coordinate of the second point of the line to freeze /// The y coordinate of the second point of the line to freeze + /// The frozen line id /// Error code - int CurvilinearSetFrozenLinesOrthogonalize(int meshKernelId, - double xFirstGridLineNode, - double yFirstGridLineNode, - double xSecondGridLineNode, - double ySecondGridLineNode); + int CurvilinearSetFrozenLines(int meshKernelId, + double xFirstGridLineNode, + double yFirstGridLineNode, + double xSecondGridLineNode, + double ySecondGridLineNode, + ref int frozenLineId); /// /// Sets the start and end nodes of the line to shift @@ -575,29 +557,6 @@ int CurvilinearSetLineLineShift(int meshKernelId, double xSecondGridLineNode, double ySecondGridLineNode); - /// - /// Initialize curvilinear smoothing - /// - /// The meshKernelId of the block to orthogonalize - /// The number of smoothing iterations to perform - /// Error code - int CurvilinearInitializeSmoothing([In] int meshKernelId, - [In] int smoothingIterations); - - /// - /// Sets the frozen lines for the curvilinear smoothing algorithm - /// - /// The x coordinate of the first point of the line to freeze - /// The y coordinate of the first point of the line to freeze - /// The x coordinate of the second point of the line to freeze - /// The y coordinate of the second point of the line to freeze - /// Error code - int CurvilinearSetFrozenLinesSmoothing([In] int meshKernelId, - [In] double xFirstGridLineNode, - [In] double yFirstGridLineNode, - [In] double xSecondGridLineNode, - [In] double ySecondGridLineNode); - /// /// Smooths the curvilinear grid inside a block /// @@ -608,18 +567,12 @@ int CurvilinearSetFrozenLinesSmoothing([In] int meshKernelId, /// The y coordinate of the upper right corner of the block to smooth /// Error code int CurvilinearSmoothing([In] int meshKernelId, + [In] int smoothingIterations, [In] double xLowerLeftCorner, [In] double yLowerLeftCorner, [In] double xUpperRightCorner, [In] double yUpperRightCorner); - /// - /// Sets the frozen lines for the curvilinear smoothing algorithm - /// - /// The meshKernelId - /// Error code - int CurvilinearFinalizeSmoothing([In] int meshKernelId); - /// /// Smooths a curvilinear grid along the direction specified by a segment /// diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index edde9ad..5e52fa2 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -214,11 +214,6 @@ public int CurvilinearFinalizeLineShift(int meshKernelId) return MeshKernelDll.CurvilinearFinalizeLineShift(meshKernelId); } - public int CurvilinearFinalizeOrthogonalize(int meshKernelId) - { - return MeshKernelDll.CurvilinearFinalizeOrthogonalize(meshKernelId); - } - public int CurvilinearGridGetData(int meshKernelId, out DisposableCurvilinearGrid disposableCurvilinearGrid) { var curvilinearGrid = new CurvilinearGridNative(); @@ -362,13 +357,6 @@ public int CurvilinearInitializeOrthogonalGridFromSplines(int meshKernelId, ref splinesToCurvilinearParametersNative); } - public int CurvilinearInitializeOrthogonalize(int meshKernelId, - in OrthogonalizationParameters orthogonalizationParameters) - { - var orthogonalizationParametersNative = orthogonalizationParameters.ToOrthogonalizationParametersNative(); - return MeshKernelDll.CurvilinearInitializeOrthogonalize(meshKernelId, ref orthogonalizationParametersNative); - } - public int CurvilinearInsertFace(int meshKernelId, double xCoordinate, double yCoordinate) { return MeshKernelDll.CurvilinearInsertFace(meshKernelId, xCoordinate, yCoordinate); @@ -460,9 +448,20 @@ public int CurvilinearMoveNodeLineShift(int meshKernelId, return MeshKernelDll.CurvilinearMoveNodeLineShift(meshKernelId, xFromCoordinate, yFromCoordinate, xToCoordinate, yToCoordinate); } - public int CurvilinearOrthogonalize(int meshKernelId) + public int CurvilinearOrthogonalize(int meshKernelId, + ref OrthogonalizationParameters orthogonalizationParameters, + double xLowerLeftCorner, + double yLowerLeftCorner, + double xUpperRightCorner, + double yUpperRightCorner) { - return MeshKernelDll.CurvilinearOrthogonalize(meshKernelId); + var orthogonalizationParametersNative = orthogonalizationParameters.ToOrthogonalizationParametersNative(); + return MeshKernelDll.CurvilinearOrthogonalize(meshKernelId, + ref orthogonalizationParametersNative, + xLowerLeftCorner, + yLowerLeftCorner, + xUpperRightCorner, + yUpperRightCorner); } public int CurvilinearRefine(int meshKernelId, @@ -499,30 +498,19 @@ public int CurvilinearSetBlockLineShift(int meshKernelId, yUpperRightCorner); } - public int CurvilinearSetBlockOrthogonalize(int meshKernelId, - double xLowerLeftCorner, - double yLowerLeftCorner, - double xUpperRightCorner, - double yUpperRightCorner) - { - return MeshKernelDll.CurvilinearSetBlockOrthogonalize(meshKernelId, - xLowerLeftCorner, - yLowerLeftCorner, - xUpperRightCorner, - yUpperRightCorner); - } - - public int CurvilinearSetFrozenLinesOrthogonalize(int meshKernelId, + public int CurvilinearSetFrozenLines(int meshKernelId, double xFirstGridLineNode, double yFirstGridLineNode, double xSecondGridLineNode, - double yUpperRightCorner) + double yUpperRightCorner, + ref int frozenLineId) { - return MeshKernelDll.CurvilinearSetFrozenLinesOrthogonalize(meshKernelId, - xFirstGridLineNode, - yFirstGridLineNode, - xSecondGridLineNode, - yUpperRightCorner); + return MeshKernelDll.CurvilinearSetFrozenLines(meshKernelId, + xFirstGridLineNode, + yFirstGridLineNode, + xSecondGridLineNode, + yUpperRightCorner, + ref frozenLineId); } public int CurvilinearSetLineLineShift(int meshKernelId, @@ -538,43 +526,21 @@ public int CurvilinearSetLineLineShift(int meshKernelId, ySecondGridLineNode); } - public int CurvilinearInitializeSmoothing(int meshKernelId, - int smoothingIterations) - { - return MeshKernelDll.CurvilinearInitializeSmoothing(meshKernelId, smoothingIterations); - } - - public int CurvilinearSetFrozenLinesSmoothing(int meshKernelId, - double xFirstGridLineNode, - double yFirstGridLineNode, - double xSecondGridLineNode, - double ySecondGridLineNode) - { - return MeshKernelDll.CurvilinearSetFrozenLinesSmoothing(meshKernelId, - xFirstGridLineNode, - yFirstGridLineNode, - xSecondGridLineNode, - ySecondGridLineNode); - } - public int CurvilinearSmoothing(int meshKernelId, + [In] int smoothingIterations, double xLowerLeftCorner, double yLowerLeftCorner, double xUpperRightCorner, double yUpperRightCorner) { return MeshKernelDll.CurvilinearSmoothing(meshKernelId, + smoothingIterations, xLowerLeftCorner, yLowerLeftCorner, xUpperRightCorner, yUpperRightCorner); } - public int CurvilinearFinalizeSmoothing(int meshKernelId) - { - return MeshKernelDll.CurvilinearFinalizeSmoothing(meshKernelId); - } - public int CurvilinearSmoothingDirectional(int meshKernelId, int smoothingIterations, double xFirstGridlineNode, diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index 2271d78..024cf53 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -280,14 +280,6 @@ public static extern int CurvilinearDerefine([In] int meshKernelId, [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_finalize_line_shift", CallingConvention = CallingConvention.Cdecl)] public static extern int CurvilinearFinalizeLineShift([In] int meshKernelId); - /// - /// Finalizes the curvilinear orthogonalization algorithm - /// - /// Id of the mesh state - /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_finalize_orthogonalize", CallingConvention = CallingConvention.Cdecl)] - public static extern int CurvilinearFinalizeOrthogonalize([In] int meshKernelId); - /// /// Gets the curvilinear grid data as a CurvilinearGrid struct (converted as set of edges and nodes) /// @@ -373,16 +365,6 @@ internal static extern int CurvilinearInitializeOrthogonalGridFromSplines([In] i [In] ref CurvilinearParametersNative curvilinearParametersNative, [In] ref SplinesToCurvilinearParametersNative splinesToCurvilinearParameters); - /// - /// Initializes the orthogonal curvilinear algorithm - /// - /// The id of the mesh state - /// The orthogonalization parameters to use in the algorithm - /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_initialize_orthogonalize", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearInitializeOrthogonalize([In] int meshKernelId, - [In] ref OrthogonalizationParametersNative orthogonalizationParameters); - /// /// Inserts a new face on a curvilinear grid. The new face will be inserted on top of the closest edge by linear /// extrapolation. @@ -528,12 +510,22 @@ internal static extern int CurvilinearMoveNodeLineShift([In] int meshKernelId, [In] double yToCoordinate); /// - /// Orthogonalize a curvilinear grid + /// Define a block on the curvilinear grid where to perform orthogonalization /// - /// The id of the mesh state + /// The id of the mesh state + /// orthogonalizationParameters The orthogonalization parameters to use in the algorithm + /// xLowerLeftCorner The x coordinate of the lower left corner of the block to orthogonalize + /// yLowerLeftCorner The y coordinate of the lower left corner of the block to orthogonalize + /// xUpperRightCorner The x coordinate of the upper right corner of the block to orthogonalize + /// yUpperRightCorner The y coordinate of the upper right corner of the block to orthogonalize /// Error code [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_orthogonalize", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearOrthogonalize([In] int meshKernelId); + internal static extern int CurvilinearOrthogonalize([In] int meshKernelId, + [In] ref OrthogonalizationParametersNative orthogonalizationParameters, + [In] double xLowerLeftCorner, + [In] double yLowerLeftCorner, + [In] double xUpperRightCorner, + [In] double yUpperRightCorner); /// /// Directional curvilinear grid refinement. Additional gridlines are added perpendicularly to the segment defined by @@ -587,36 +579,22 @@ internal static extern int CurvilinearSetBlockLineShift([In] int meshKernelId, [In] double yUpperRightCorner); /// - /// efine a block on the curvilinear grid where to perform orthogonalization - /// - /// The meshKernelId of the block to orthogonalize - /// The xLowerLeftCorner of the block to orthogonalize - /// The yLowerLeftCorner of the block to orthogonalize - /// The xUpperRightCorner of the block to orthogonalize - /// The yUpperRightCorner of the block to orthogonalize - /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_set_block_orthogonalize", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearSetBlockOrthogonalize([In] int meshKernelId, - [In] double xLowerLeftCorner, - [In] double yLowerLeftCorner, - [In] double xUpperRightCorner, - [In] double yUpperRightCorner); - - /// - /// Freezes a line in the curvilinear orthogonalization process + /// Sets a new frozen line in the meshkernel state /// /// The id of the mesh state /// The x coordinate of the first point of the line to freeze /// The y coordinate of the first point of the line to freeze /// The x coordinate of the second point of the line to freeze /// The y coordinate of the second point of the line to freeze + /// The id of the frozen line /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_set_frozen_lines_orthogonalize", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearSetFrozenLinesOrthogonalize([In] int meshKernelId, - [In] double xFirstGridLineNode, - [In] double yFirstGridLineNode, - [In] double xSecondGridLineNode, - [In] double ySecondGridLineNode); + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_set_frozen_lines", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearSetFrozenLines([In] int meshKernelId, + [In] double xFirstGridLineNode, + [In] double yFirstGridLineNode, + [In] double xSecondGridLineNode, + [In] double ySecondGridLineNode, + [In][Out] ref int frozenLineId); /// /// Sets the start and end nodes of the line to shift @@ -635,54 +613,22 @@ internal static extern int CurvilinearSetLineLineShift([In] int meshKernelId, [In] double ySecondGridLineNode); /// - /// Initialize curvilinear smoothing + /// Smooths a curvilinear grid /// - /// The meshKernelId + /// The meshKernelId of the block to orthogonalize /// The number of smoothing iterations to perform - /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_initialize_smoothing", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearInitializeSmoothing([In] int meshKernelId, - [In] int smoothingIterations); - - /// - /// Sets the frozen lines for the curvilinear smoothing algorithm - /// - /// The meshKernelId - /// The x coordinate of the first point of the line to freeze - /// The y coordinate of the first point of the line to freeze - /// The x coordinate of the second point of the line to freeze - /// The y coordinate of the second point of the line to freeze - /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_set_frozen_lines_smoothing", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearSetFrozenLinesSmoothing([In] int meshKernelId, - [In] double xFirstGridLineNode, - [In] double yFirstGridLineNode, - [In] double xSecondGridLineNode, - [In] double ySecondGridLineNode); - - /// - /// Performs curvilinear smoothing - /// - /// The meshKernelId /// The x coordinate of the lower left corner of the block to smooth /// The y coordinate of the lower left corner of the block to smooth - /// The x coordinate of the right corner of the block to smooth + /// The y coordinate of the lower left corner of the block to smooth /// The y coordinate of the upper right corner of the block to smooth /// Error code [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_smoothing", CallingConvention = CallingConvention.Cdecl)] internal static extern int CurvilinearSmoothing([In] int meshKernelId, - [In] double xLowerLeftCorner, - [In] double yLowerLeftCorner, - [In] double xUpperRightCorner, - [In] double yUpperRightCorner); - - /// - /// Finalizes curvilinear smoothing algorithm - /// - /// The meshKernelId - /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_finalize_smoothing", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearFinalizeSmoothing([In] int meshKernelId); + [In] int smoothingIterations, + [In] double xLowerLeftCorner, + [In] double yLowerLeftCorner, + [In] double xUpperRightCorner, + [In] double yUpperRightCorner); /// /// Smooths a curvilinear grid along the direction specified by a segment diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index 5907f48..c602569 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -562,12 +562,22 @@ public void CurvilinearOrthogonalizeWithFrozenLineThroughAPI() Assert.AreEqual(0, api.CurvilinearSet(id, grid)); // Execute var orthogonalizationParameters = OrthogonalizationParameters.CreateDefault(); - Assert.AreEqual(0, api.CurvilinearInitializeOrthogonalize(id, orthogonalizationParameters)); - Assert.AreEqual(0, api.CurvilinearSetFrozenLinesOrthogonalize(id, 20.0, 0.0, 20.0, 10.0), 0); - Assert.AreEqual(0, api.CurvilinearFinalizeOrthogonalize(id)); + int frozenLineId = -1; + Assert.AreEqual(0, api.CurvilinearSetFrozenLines(id, + 10.0, + 0.0, + 10.0, + 10.0, + ref frozenLineId)); + Assert.AreEqual(0, frozenLineId); + Assert.AreEqual(0, api.CurvilinearOrthogonalize(id, + ref orthogonalizationParameters, + 20.0, + 0.0, + 20.0, + 10.0)); // Assert - int gridOut = api.CurvilinearGridGetData(id, out curvilinearGrid); Assert.NotNull(gridOut); } @@ -595,10 +605,10 @@ public void CurvilinearSmoothingThroughAPI() Assert.AreEqual(0, api.CurvilinearSet(id, grid)); // Execute - Assert.AreEqual(0, api.CurvilinearInitializeSmoothing(id, 10)); - Assert.AreEqual(0, api.CurvilinearSetFrozenLinesSmoothing(id, 10.0,0.0,10.0,10.0)); - Assert.AreEqual(0, api.CurvilinearSmoothing(id, 10.0, 20.0, 30.0, 20.0)); - Assert.AreEqual(0, api.CurvilinearFinalizeSmoothing(id)); + int frozenLineId = -1; + Assert.AreEqual(0, api.CurvilinearSetFrozenLines(id, 10.0,0.0,10.0,10.0,ref frozenLineId)); + Assert.AreEqual(0, frozenLineId); + Assert.AreEqual(0, api.CurvilinearSmoothing(id, 10, 10.0, 20.0, 30.0, 20.0)); // Assert Assert.AreEqual(0, api.CurvilinearGridGetData(id, out curvilinearGrid)); @@ -776,15 +786,13 @@ public void CurvilinearOrthogonalizeOnBlockThroughAPI() { // Prepare id = api.AllocateState(0); - Assert.AreEqual(0, api.CurvilinearSet(id, grid)); + // Execute var orthogonalizationParameters = OrthogonalizationParameters.CreateDefault(); - Assert.AreEqual(0, api.CurvilinearInitializeOrthogonalize(id, orthogonalizationParameters)); - Assert.AreEqual(0, api.CurvilinearSetBlockOrthogonalize(id, 0.0, 0.0, 30.0, 30.0), 0); - Assert.AreEqual(0, api.CurvilinearFinalizeOrthogonalize(id)); - // Assert + Assert.AreEqual(0, api.CurvilinearOrthogonalize(id, ref orthogonalizationParameters, 0.0, 0.0, 30.0, 30.0), 0); + // Assert Assert.AreEqual(0, api.CurvilinearGridGetData(id, out curvilinearGrid)); Assert.AreEqual((5, 5), (curvilinearGrid.NumM, curvilinearGrid.NumN)); } From 98d80e432a07c59341e7a54a44ccc56768f6d742 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 6 Feb 2025 16:33:09 +0100 Subject: [PATCH 03/13] Add CurvilinearDeleteFrozenLines --- src/MeshKernelNET/Api/MeshKernelApi.cs | 5 +++ src/MeshKernelNET/Native/MeshKernelDll.cs | 10 ++++++ .../Api/MeshKernelCurvilinearTest.cs | 33 +++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index 5e52fa2..f204f0e 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -513,6 +513,11 @@ public int CurvilinearSetFrozenLines(int meshKernelId, ref frozenLineId); } + public int CurvilinearDeleteFrozenLines(int meshKernelId, int frozenLineId) + { + return MeshKernelDll.CurvilinearDeleteFrozenLines(meshKernelId, frozenLineId); + } + public int CurvilinearSetLineLineShift(int meshKernelId, double xFirstGridLineNode, double yFirstGridLineNode, diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index 024cf53..08f5008 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -596,6 +596,16 @@ internal static extern int CurvilinearSetFrozenLines([In] int meshKernelId, [In] double ySecondGridLineNode, [In][Out] ref int frozenLineId); + /// + /// Sets a new frozen line in the meshkernel state + /// + /// The id of the mesh state + /// The id of the frozen line to delete + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_delete_frozen_lines", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearDeleteFrozenLines([In] int meshKernelId, [In] int frozenLineId); + + /// /// Sets the start and end nodes of the line to shift /// diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index c602569..e41eb37 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -606,7 +606,7 @@ public void CurvilinearSmoothingThroughAPI() // Execute int frozenLineId = -1; - Assert.AreEqual(0, api.CurvilinearSetFrozenLines(id, 10.0,0.0,10.0,10.0,ref frozenLineId)); + Assert.AreEqual(0, api.CurvilinearSetFrozenLines(id, 10.0,0.0,10.0,10.0, ref frozenLineId)); Assert.AreEqual(0, frozenLineId); Assert.AreEqual(0, api.CurvilinearSmoothing(id, 10, 10.0, 20.0, 30.0, 20.0)); @@ -1436,6 +1436,35 @@ public void CurvilinearGetNodeLocationIndex_DoesNotFindNearest_OutsideBoundingBo // Assert Assert.That(actualIndex,Is.EqualTo(expectedIndex)); } - + + [Test] + public void CurvilinearSetAndDeleteFrozenLines_ShouldSetAndDeleteFrozenLines() + { + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int forzenLineId = -1; + + // Set and delete + int returnCode = api.CurvilinearSetFrozenLines(id, + 0.0, + 0.0, + 0.0, + 2.0, + ref forzenLineId); + Assert.That(forzenLineId, Is.EqualTo(0)); + + returnCode = api.CurvilinearDeleteFrozenLines(id, forzenLineId); + Assert.That(returnCode, Is.EqualTo(0)); + + returnCode = api.CurvilinearSetFrozenLines(id, + 0.0, + 0.0, + 0.0, + 2.0, + ref forzenLineId); + // Id is always increasing + Assert.That(returnCode, Is.EqualTo(1)); + + } + } } From 04be903eacad1766babe8f05a2309c201eae5f50 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 6 Feb 2025 16:45:37 +0100 Subject: [PATCH 04/13] Fix sonar cloud issue --- src/MeshKernelNET/Api/MeshKernelApi.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index f204f0e..69ddeb1 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -502,14 +502,14 @@ public int CurvilinearSetFrozenLines(int meshKernelId, double xFirstGridLineNode, double yFirstGridLineNode, double xSecondGridLineNode, - double yUpperRightCorner, + double ySecondGridLineNode, ref int frozenLineId) { return MeshKernelDll.CurvilinearSetFrozenLines(meshKernelId, xFirstGridLineNode, yFirstGridLineNode, xSecondGridLineNode, - yUpperRightCorner, + ySecondGridLineNode, ref frozenLineId); } From 334165d734f7bfdcacdbf7704aaa1c4316ff2130 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Thu, 6 Feb 2025 17:01:16 +0100 Subject: [PATCH 05/13] Use correct nuggie --- test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index e41eb37..741ec0f 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -1462,7 +1462,7 @@ public void CurvilinearSetAndDeleteFrozenLines_ShouldSetAndDeleteFrozenLines() 2.0, ref forzenLineId); // Id is always increasing - Assert.That(returnCode, Is.EqualTo(1)); + Assert.That(forzenLineId, Is.EqualTo(1)); } From 5019826f2958ea74aba981542f3eddba7ce8939e Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Mon, 10 Feb 2025 17:34:29 +0100 Subject: [PATCH 06/13] Add requested frozen line apis --- src/MeshKernelNET/Api/IMeshKernelApi.cs | 12 ++-- src/MeshKernelNET/Api/MeshKernelApi.cs | 52 ++++++++++++++--- src/MeshKernelNET/Native/MeshKernelDll.cs | 57 +++++++++++++++++-- .../Api/MeshKernelCurvilinearTest.cs | 10 ++-- 4 files changed, 105 insertions(+), 26 deletions(-) diff --git a/src/MeshKernelNET/Api/IMeshKernelApi.cs b/src/MeshKernelNET/Api/IMeshKernelApi.cs index 6384890..84633ea 100644 --- a/src/MeshKernelNET/Api/IMeshKernelApi.cs +++ b/src/MeshKernelNET/Api/IMeshKernelApi.cs @@ -535,12 +535,12 @@ int CurvilinearSetBlockLineShift(int meshKernelId, /// The y coordinate of the second point of the line to freeze /// The frozen line id /// Error code - int CurvilinearSetFrozenLines(int meshKernelId, - double xFirstGridLineNode, - double yFirstGridLineNode, - double xSecondGridLineNode, - double ySecondGridLineNode, - ref int frozenLineId); + int CurvilinearFrozenLineAdd(int meshKernelId, + double xFirstGridLineNode, + double yFirstGridLineNode, + double xSecondGridLineNode, + double ySecondGridLineNode, + ref int frozenLineId); /// /// Sets the start and end nodes of the line to shift diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index 69ddeb1..cf7dcb0 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -4,6 +4,7 @@ using System.Runtime.InteropServices; using MeshKernelNET.Helpers; using MeshKernelNET.Native; +using NetTopologySuite.Operation.Valid; namespace MeshKernelNET.Api { @@ -498,24 +499,57 @@ public int CurvilinearSetBlockLineShift(int meshKernelId, yUpperRightCorner); } - public int CurvilinearSetFrozenLines(int meshKernelId, + public int CurvilinearFrozenLineAdd(int meshKernelId, double xFirstGridLineNode, double yFirstGridLineNode, double xSecondGridLineNode, double ySecondGridLineNode, ref int frozenLineId) { - return MeshKernelDll.CurvilinearSetFrozenLines(meshKernelId, - xFirstGridLineNode, - yFirstGridLineNode, - xSecondGridLineNode, - ySecondGridLineNode, - ref frozenLineId); + return MeshKernelDll.CurvilinearFrozenLineAdd(meshKernelId, + xFirstGridLineNode, + yFirstGridLineNode, + xSecondGridLineNode, + ySecondGridLineNode, + ref frozenLineId); } - public int CurvilinearDeleteFrozenLines(int meshKernelId, int frozenLineId) + public int CurvilinearFrozenLineDelete(int meshKernelId, int frozenLineId) { - return MeshKernelDll.CurvilinearDeleteFrozenLines(meshKernelId, frozenLineId); + return MeshKernelDll.CurvilinearFrozenLineDelete(meshKernelId, frozenLineId); + } + public int CurvilinearFrozenLineValid(int meshKernelId, int frozenLineId, ref bool isValid) + { + return MeshKernelDll.CurvilinearFrozenLineValid(meshKernelId, frozenLineId, ref isValid); + } + + public int CurvilinearFrozenLineGet(int meshKernelId, + int frozenLineId, + ref double xFirstGridLineNode, + ref double yFirstGridLineNode, + ref double xSecondGridLineNode, + ref double ySecondGridLineNode) + { + return MeshKernelDll.CurvilinearFrozenLineGet(meshKernelId, + frozenLineId, + ref xFirstGridLineNode, + ref yFirstGridLineNode, + ref xSecondGridLineNode, + ref ySecondGridLineNode); + } + + public int CurvilinearFrozenLinesGetCount(int meshKernelId, ref int numFrozenLines) + { + return MeshKernelDll.CurvilinearFrozenLinesGetCount(meshKernelId, ref numFrozenLines); + } + + public int CurvilinearFrozenLinesGetIds(int meshKernelId, ref int[] frozenLinesIds) + { + IntPtr frozenLinesIdsPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int)) * frozenLinesIds.Length); + int success = MeshKernelDll.CurvilinearFrozenLinesGetIds(meshKernelId, frozenLinesIdsPtr); + Marshal.Copy(frozenLinesIdsPtr, frozenLinesIds, 0, frozenLinesIds.Length); + Marshal.FreeCoTaskMem(frozenLinesIdsPtr); + return success; } public int CurvilinearSetLineLineShift(int meshKernelId, diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index 08f5008..7fce7ac 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -579,7 +579,7 @@ internal static extern int CurvilinearSetBlockLineShift([In] int meshKernelId, [In] double yUpperRightCorner); /// - /// Sets a new frozen line in the meshkernel state + /// Add a new frozen line in the meshkernel state /// /// The id of the mesh state /// The x coordinate of the first point of the line to freeze @@ -588,8 +588,8 @@ internal static extern int CurvilinearSetBlockLineShift([In] int meshKernelId, /// The y coordinate of the second point of the line to freeze /// The id of the frozen line /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_set_frozen_lines", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearSetFrozenLines([In] int meshKernelId, + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_add", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLineAdd([In] int meshKernelId, [In] double xFirstGridLineNode, [In] double yFirstGridLineNode, [In] double xSecondGridLineNode, @@ -597,14 +597,59 @@ internal static extern int CurvilinearSetFrozenLines([In] int meshKernelId, [In][Out] ref int frozenLineId); /// - /// Sets a new frozen line in the meshkernel state + /// Deletes a frozen line in the meshkernel state /// /// The id of the mesh state /// The id of the frozen line to delete /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_delete_frozen_lines", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearDeleteFrozenLines([In] int meshKernelId, [In] int frozenLineId); + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_delete", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLineDelete([In] int meshKernelId, [In] int frozenLineId); + /// + /// Checks if a frozen line is valid + /// + /// The id of the mesh state + /// The id of the frozen line to check + /// True if the provided id is valid + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_valid", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLineValid([In] int meshKernelId, [In] int frozenLineId, [In][Out] ref bool isValid); + + /// + /// Gets the coordinates of the frozen line + /// + /// The id of the mesh state + /// The id of the frozen line to delete + /// The x coordinate of the first point of the frozen line + /// The y coordinate of the first point of the frozen line + /// The x coordinate of the second point of the frozen line + /// The x coordinate of the second point of the frozen line + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_get", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLineGet([In] int meshKernelId, + [In] int frozenLineId, + [In][Out] ref double xFirstFrozenLineCoordinate, + [In][Out] ref double yFirstFrozenLineCoordinate, + [In][Out] ref double xSecondFrozenLineCoordinate, + [In][Out] ref double ySecondFrozenLineCoordinate); + + /// + /// Gets the number of stored frozen lines in the meshkernel state + /// + /// The id of the mesh state + /// The number of stored frozen lines in the meshkernel state + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_lines_get_count", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLinesGetCount([In] int meshKernelId, [In][Out] ref int numFrozenLines); + + /// + /// Gets the ids of the frozen lines + /// + /// The id of the mesh state + /// The frozen line ids + /// Error code + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_lines_get_ids", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLinesGetIds([In] int meshKernelId, [In][Out] IntPtr frozenLinesIds); /// /// Sets the start and end nodes of the line to shift diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index 741ec0f..6d37f6c 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -563,7 +563,7 @@ public void CurvilinearOrthogonalizeWithFrozenLineThroughAPI() // Execute var orthogonalizationParameters = OrthogonalizationParameters.CreateDefault(); int frozenLineId = -1; - Assert.AreEqual(0, api.CurvilinearSetFrozenLines(id, + Assert.AreEqual(0, api.CurvilinearFrozenLineAdd(id, 10.0, 0.0, 10.0, @@ -606,7 +606,7 @@ public void CurvilinearSmoothingThroughAPI() // Execute int frozenLineId = -1; - Assert.AreEqual(0, api.CurvilinearSetFrozenLines(id, 10.0,0.0,10.0,10.0, ref frozenLineId)); + Assert.AreEqual(0, api.CurvilinearFrozenLineAdd(id, 10.0,0.0,10.0,10.0, ref frozenLineId)); Assert.AreEqual(0, frozenLineId); Assert.AreEqual(0, api.CurvilinearSmoothing(id, 10, 10.0, 20.0, 30.0, 20.0)); @@ -1444,7 +1444,7 @@ public void CurvilinearSetAndDeleteFrozenLines_ShouldSetAndDeleteFrozenLines() int forzenLineId = -1; // Set and delete - int returnCode = api.CurvilinearSetFrozenLines(id, + int returnCode = api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, @@ -1452,10 +1452,10 @@ public void CurvilinearSetAndDeleteFrozenLines_ShouldSetAndDeleteFrozenLines() ref forzenLineId); Assert.That(forzenLineId, Is.EqualTo(0)); - returnCode = api.CurvilinearDeleteFrozenLines(id, forzenLineId); + returnCode = api.CurvilinearFrozenLineDelete(id, forzenLineId); Assert.That(returnCode, Is.EqualTo(0)); - returnCode = api.CurvilinearSetFrozenLines(id, + returnCode = api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, From 89933bae978d2433fa924c92bb7c47cbfa769fce Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Mon, 10 Feb 2025 18:12:46 +0100 Subject: [PATCH 07/13] Add unit tests --- .../Api/MeshKernelCurvilinearTest.cs | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index 6d37f6c..42d589b 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using GeoAPI.Geometries; using MeshKernelNET.Api; using NetTopologySuite.Algorithm; @@ -1466,5 +1467,112 @@ public void CurvilinearSetAndDeleteFrozenLines_ShouldSetAndDeleteFrozenLines() } + [Test] + public void CurvilinearFrozenLineAdd_ShouldReturnValidId() + { + // Arrange + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int frozenLineId = -1; + + // Act + int returnCode = api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, 2.0, ref frozenLineId); + + // Assert + Assert.That(returnCode, Is.EqualTo(0)); + Assert.That(frozenLineId, Is.EqualTo(0)); + } + + [Test] + public void CurvilinearFrozenLinesGetCount_ShouldReturnCorrectCount() + { + // Arrange + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int frozenLineId = -1; + api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, 2.0, ref frozenLineId); + + // Act + int numFrozenLines = 0; + int returnCode = api.CurvilinearFrozenLinesGetCount(id, ref numFrozenLines); + + // Assert + Assert.That(returnCode, Is.EqualTo(0)); + Assert.That(numFrozenLines, Is.EqualTo(1)); + } + + [Test] + public void CurvilinearFrozenLinesGetIds_ShouldReturnCorrectIds() + { + // Arrange + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int frozenLineId = -1; + api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, 2.0, ref frozenLineId); + + // Act + int numFrozenLines = 1; + var frozenLinesIds = new int[numFrozenLines]; + int returnCode = api.CurvilinearFrozenLinesGetIds(id, ref frozenLinesIds); + + // Assert + Assert.That(returnCode, Is.EqualTo(0)); + Assert.That(frozenLinesIds[0], Is.EqualTo(frozenLineId)); + } + + [Test] + public void CurvilinearFrozenLineValid_ShouldReturnTrueForValidLine() + { + // Arrange + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int frozenLineId = -1; + api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, 2.0, ref frozenLineId); + + // Act + bool isValid = false; + int returnCode = api.CurvilinearFrozenLineValid(id, frozenLineId, ref isValid); + + // Assert + Assert.That(returnCode, Is.EqualTo(0)); + Assert.That(isValid, Is.True); + } + + [Test] + public void CurvilinearFrozenLineGet_ShouldReturnCorrectCoordinates() + { + // Arrange + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int frozenLineId = -1; + api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, 2.0, ref frozenLineId); + + // Act + double xFirstGridLineNode = 0.0; + double yFirstGridLineNode = 0.0; + double xSecondGridLineNode = 0.0; + double ySecondGridLineNode = 0.0; + int returnCode = api.CurvilinearFrozenLineGet(id, frozenLineId, ref xFirstGridLineNode, ref yFirstGridLineNode, ref xSecondGridLineNode, ref ySecondGridLineNode); + + // Assert + Assert.That(returnCode, Is.EqualTo(0)); + Assert.That(xFirstGridLineNode, Is.EqualTo(0.0).Within(1e-9)); + Assert.That(yFirstGridLineNode, Is.EqualTo(0.0).Within(1e-9)); + Assert.That(xSecondGridLineNode, Is.EqualTo(0.0).Within(1e-9)); + Assert.That(ySecondGridLineNode, Is.EqualTo(2.0).Within(1e-9)); + } + + [Test] + public void CurvilinearFrozenLineAdd_ShouldIncrementId() + { + // Arrange + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int frozenLineId = -1; + api.CurvilinearFrozenLineAdd(id, 0.0, 0.0, 0.0, 2.0, ref frozenLineId); + + // Act + int newFrozenLineId = -1; + int returnCode = api.CurvilinearFrozenLineAdd(id, 1.0, 1.0, 1.0, 3.0, ref newFrozenLineId); + + // Assert + Assert.That(returnCode, Is.EqualTo(0)); + Assert.That(newFrozenLineId, Is.GreaterThan(frozenLineId)); + } + } } From 63471e60f9756750d9e5a092d97961c27823f267 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Mon, 10 Feb 2025 18:27:32 +0100 Subject: [PATCH 08/13] Add missing interface methods --- src/MeshKernelNET/Api/IMeshKernelApi.cs | 53 ++++++++++++++++++++++- src/MeshKernelNET/Native/MeshKernelDll.cs | 6 +-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/MeshKernelNET/Api/IMeshKernelApi.cs b/src/MeshKernelNET/Api/IMeshKernelApi.cs index 84633ea..9be7e28 100644 --- a/src/MeshKernelNET/Api/IMeshKernelApi.cs +++ b/src/MeshKernelNET/Api/IMeshKernelApi.cs @@ -533,7 +533,8 @@ int CurvilinearSetBlockLineShift(int meshKernelId, /// The y coordinate of the first point of the line to freeze /// The x coordinate of the second point of the line to freeze /// The y coordinate of the second point of the line to freeze - /// The frozen line id + /// The id of the frozen line, unique for each frozen line and meshkernel id. + /// It will not be re-issued again for another frozen line /// Error code int CurvilinearFrozenLineAdd(int meshKernelId, double xFirstGridLineNode, @@ -542,6 +543,56 @@ int CurvilinearFrozenLineAdd(int meshKernelId, double ySecondGridLineNode, ref int frozenLineId); + /// + /// Deletes a frozen line in the meshkernel state + /// + /// The id of the mesh state + /// The id of the frozen line to delete + /// Error code + int CurvilinearFrozenLineDelete(int meshKernelId, int frozenLineId); + + /// + /// Checks if a frozen line is valid + /// + /// The id of the mesh state + /// The id of the frozen line to check + /// True if the provided id is valid + /// Error code + int CurvilinearFrozenLineValid(int meshKernelId, int frozenLineId, ref bool isValid); + + /// + /// Gets the coordinates of the frozen line + /// + /// The id of the mesh state + /// The id of the frozen line to delete + /// The x coordinate of the first point of the frozen line + /// The y coordinate of the first point of the frozen line + /// The x coordinate of the second point of the frozen line + /// The x coordinate of the second point of the frozen line + /// Error code + int CurvilinearFrozenLineGet(int meshKernelId, + int frozenLineId, + ref double xFirstFrozenLineCoordinate, + ref double yFirstFrozenLineCoordinate, + ref double xSecondFrozenLineCoordinate, + ref double ySecondFrozenLineCoordinate); + + /// + /// Gets the number of stored frozen lines in the state + /// + /// The id of the mesh state + /// The number of stored frozen lines in the state + /// Error code + int CurvilinearFrozenLinesGetCount(int meshKernelId, ref int numFrozenLines); + + /// + /// Gets the ids of the frozen lines + /// + /// The id of the mesh state + /// The frozen line ids + /// Error code + int CurvilinearFrozenLinesGetIds(int meshKernelId, ref int[] frozenLinesIds); + /// /// Sets the start and end nodes of the line to shift /// diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index 7fce7ac..59d1b19 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -586,7 +586,7 @@ internal static extern int CurvilinearSetBlockLineShift([In] int meshKernelId, /// The y coordinate of the first point of the line to freeze /// The x coordinate of the second point of the line to freeze /// The y coordinate of the second point of the line to freeze - /// The id of the frozen line + /// The id of the frozen line, unique for each frozen line and meshkernel id. It will not be re-issued again for another frozen line /// Error code [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_add", CallingConvention = CallingConvention.Cdecl)] internal static extern int CurvilinearFrozenLineAdd([In] int meshKernelId, @@ -634,10 +634,10 @@ internal static extern int CurvilinearFrozenLineGet([In] int meshKernelId, [In][Out] ref double ySecondFrozenLineCoordinate); /// - /// Gets the number of stored frozen lines in the meshkernel state + /// Gets the number of stored frozen lines in the state /// /// The id of the mesh state - /// The number of stored frozen lines in the meshkernel state + /// The number of stored frozen lines in the state /// Error code [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_lines_get_count", CallingConvention = CallingConvention.Cdecl)] internal static extern int CurvilinearFrozenLinesGetCount([In] int meshKernelId, [In][Out] ref int numFrozenLines); From 387015201487218bc8de122d08443b7213aae57c Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Mon, 10 Feb 2025 18:40:52 +0100 Subject: [PATCH 09/13] Account for comments --- src/MeshKernelNET/Api/IMeshKernelApi.cs | 51 ++++++++++++----------- src/MeshKernelNET/Native/MeshKernelDll.cs | 5 ++- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/MeshKernelNET/Api/IMeshKernelApi.cs b/src/MeshKernelNET/Api/IMeshKernelApi.cs index 9be7e28..b2dbb90 100644 --- a/src/MeshKernelNET/Api/IMeshKernelApi.cs +++ b/src/MeshKernelNET/Api/IMeshKernelApi.cs @@ -526,7 +526,8 @@ int CurvilinearSetBlockLineShift(int meshKernelId, double yUpperRightCorner); /// - /// Freezes a line in the curvilinear grid + /// Adds a frozen in the meshkernel state. A frozen line is stored as a pair of coordinates. + /// The actual edges to freeze are computed during each algorithm execution, as they may change (for example, after a refinement operation). /// /// The id of the mesh state /// The x coordinate of the first point of the line to freeze @@ -614,15 +615,15 @@ int CurvilinearSetLineLineShift(int meshKernelId, /// The meshKernelId /// The x coordinate of the lower left corner of the block to smooth /// The y coordinate of the lower left corner of the block to smooth - /// The x coordinate of the right corner of the block to smooth + /// The x coordinate of the lower corner of the block to smooth /// The y coordinate of the upper right corner of the block to smooth /// Error code - int CurvilinearSmoothing([In] int meshKernelId, - [In] int smoothingIterations, - [In] double xLowerLeftCorner, - [In] double yLowerLeftCorner, - [In] double xUpperRightCorner, - [In] double yUpperRightCorner); + int CurvilinearSmoothing(int meshKernelId, + int smoothingIterations, + double xLowerLeftCorner, + double yLowerLeftCorner, + double xUpperRightCorner, + double yUpperRightCorner); /// /// Smooths a curvilinear grid along the direction specified by a segment @@ -950,7 +951,7 @@ int Mesh2dAveragingInterpolation(int meshKernelId, /// The input polygons /// int Mesh2dCasulliDerefinementOnPolygon(int meshKernelId, - [In] DisposableGeometryList geometryListPolygon); + DisposableGeometryList geometryListPolygon); /// @@ -959,8 +960,8 @@ int Mesh2dCasulliDerefinementOnPolygon(int meshKernelId, /// Id of the mesh state /// The elements to be removed /// Error code - int Mesh2dCasulliDerefinementElements([In] int meshKernelId, - [In][Out] ref DisposableGeometryList geometryListElements); + int Mesh2dCasulliDerefinementElements(int meshKernelId, + ref DisposableGeometryList geometryListElements); /// /// Get the list of elements that will be removed after applying the Casulli de-refinement algorithm to a mesh on polygon @@ -969,9 +970,9 @@ int Mesh2dCasulliDerefinementElements([In] int meshKernelId, /// The input polygon /// The elements to be removed /// Error code - int Mesh2dCasulliDerefinementElementsOnPolygon([In] int meshKernelId, - [In] DisposableGeometryList geometryListPolygon, - [In][Out] ref DisposableGeometryList geometryListElements); + int Mesh2dCasulliDerefinementElementsOnPolygon(int meshKernelId, + DisposableGeometryList geometryListPolygon, + ref DisposableGeometryList geometryListElements); /// /// Refine a whole mesh using the Casulli algorithm @@ -987,7 +988,7 @@ int Mesh2dCasulliDerefinementElementsOnPolygon([In] int meshKernelId, /// The input polygons /// int Mesh2dCasulliRefinementOnPolygon(int meshKernelId, - [In] DisposableGeometryList geometryListPolygon); + DisposableGeometryList geometryListPolygon); /// /// Perform inner orthogonalization iteration @@ -1019,7 +1020,7 @@ int Mesh2dComputeOrthogonalization(int meshKernelId, /// The mesh to merge to the the current domain /// Fraction of the shortest edge (along an edge to be connected) to use when determining neighbour edge closeness /// Error code - int Mesh2dConnectMeshes([In] int meshKernelId, in DisposableMesh2D disposableMesh2D, double searchFraction); + int Mesh2dConnectMeshes(int meshKernelId, in DisposableMesh2D disposableMesh2D, double searchFraction); /// /// Converts the projection of a mesh2d @@ -1028,9 +1029,9 @@ int Mesh2dComputeOrthogonalization(int meshKernelId, /// The new projection for the mesh /// The UTM zone and information string /// Error code - int Mesh2dConvertProjection([In] int meshKernelId, - [In] ProjectionOptions projection, - [In] string zone); + int Mesh2dConvertProjection(int meshKernelId, + ProjectionOptions projection, + string zone); /// /// Converts a mesh into a curvilinear grid, with the grid expanding outward from a specified starting point. @@ -1040,9 +1041,9 @@ int Mesh2dConvertProjection([In] int meshKernelId, /// The x coordinate of the point identifying the face where to start the conversion /// The y coordinate of the point identifying the face where to start the conversion /// Error code - int Mesh2dConvertCurvilinear([In] int meshKernelId, - [In] double startingFaceCoordinateX, - [In] double startingFaceCoordinateY); + int Mesh2dConvertCurvilinear(int meshKernelId, + double startingFaceCoordinateX, + double startingFaceCoordinateY); /// /// Count the number of hanging edges in a mesh2d. @@ -1102,14 +1103,14 @@ int Mesh2dDeleteEdge(int meshKernelId, double xCoordinate, double yCoordinate, d /// Id of the grid state /// The index of the edge to delete /// true if the edge has been deleted, false if not - int Mesh2dDeleteEdgeByIndex(int meshKernelId, [In] int edgeIndex); + int Mesh2dDeleteEdgeByIndex(int meshKernelId, int edgeIndex); /// /// Deletes all hanging edges. An hanging edge is an edge where one of the two nodes is not connected. /// /// The id of the mesh state /// Error code - int Mesh2dDeleteHangingEdges([In] int meshKernelId); + int Mesh2dDeleteHangingEdges(int meshKernelId); /// /// Deletes a node with specified @@ -1658,7 +1659,7 @@ int Mesh2dRefineBasedOnSamples(int meshKernelId, in DisposableGeometryList dispo /// The id of the mesh state /// The polylines describing the network /// Error code - int Network1dSet([In] int meshKernelId, in DisposableGeometryList polylines); + int Network1dSet(int meshKernelId, in DisposableGeometryList polylines); /// /// Convert network chainages to mesh1d nodes and edges diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index 59d1b19..377e2aa 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -510,7 +510,7 @@ internal static extern int CurvilinearMoveNodeLineShift([In] int meshKernelId, [In] double yToCoordinate); /// - /// Define a block on the curvilinear grid where to perform orthogonalization + /// Orthogonalize a curvilinear grid /// /// The id of the mesh state /// orthogonalizationParameters The orthogonalization parameters to use in the algorithm @@ -579,7 +579,8 @@ internal static extern int CurvilinearSetBlockLineShift([In] int meshKernelId, [In] double yUpperRightCorner); /// - /// Add a new frozen line in the meshkernel state + /// Adds a frozen in the meshkernel state. A frozen line is stored as a pair of coordinates. + /// The actual edges to freeze are computed during each algorithm execution, as they may change (for example, after a refinement operation). /// /// The id of the mesh state /// The x coordinate of the first point of the line to freeze From 2603967f342a99cb81a6cb99b47195ca37d74b53 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Tue, 11 Feb 2025 11:26:52 +0100 Subject: [PATCH 10/13] Account for comments --- src/MeshKernelNET/Api/IMeshKernelApi.cs | 6 ++-- src/MeshKernelNET/Api/MeshKernelApi.cs | 19 ++++++++++-- src/MeshKernelNET/Native/MeshKernelDll.cs | 6 ++-- .../Api/MeshKernelCurvilinearTest.cs | 29 +++++++++++++++++-- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/MeshKernelNET/Api/IMeshKernelApi.cs b/src/MeshKernelNET/Api/IMeshKernelApi.cs index b2dbb90..edaaa25 100644 --- a/src/MeshKernelNET/Api/IMeshKernelApi.cs +++ b/src/MeshKernelNET/Api/IMeshKernelApi.cs @@ -559,7 +559,7 @@ int CurvilinearFrozenLineAdd(int meshKernelId, /// The id of the frozen line to check /// True if the provided id is valid /// Error code - int CurvilinearFrozenLineValid(int meshKernelId, int frozenLineId, ref bool isValid); + int CurvilinearFrozenLineIsValid(int meshKernelId, int frozenLineId, ref bool isValid); /// /// Gets the coordinates of the frozen line @@ -587,12 +587,12 @@ int CurvilinearFrozenLineGet(int meshKernelId, int CurvilinearFrozenLinesGetCount(int meshKernelId, ref int numFrozenLines); /// - /// Gets the ids of the frozen lines + /// Gets the ids of the frozen lines. /// /// The id of the mesh state /// The frozen line ids /// Error code - int CurvilinearFrozenLinesGetIds(int meshKernelId, ref int[] frozenLinesIds); + int CurvilinearFrozenLinesGetIds(int meshKernelId, out int[] frozenLinesIds); /// /// Sets the start and end nodes of the line to shift diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index cf7dcb0..0d10327 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -518,9 +518,9 @@ public int CurvilinearFrozenLineDelete(int meshKernelId, int frozenLineId) { return MeshKernelDll.CurvilinearFrozenLineDelete(meshKernelId, frozenLineId); } - public int CurvilinearFrozenLineValid(int meshKernelId, int frozenLineId, ref bool isValid) + public int CurvilinearFrozenLineIsValid(int meshKernelId, int frozenLineId, ref bool isValid) { - return MeshKernelDll.CurvilinearFrozenLineValid(meshKernelId, frozenLineId, ref isValid); + return MeshKernelDll.CurvilinearFrozenLineIsValid(meshKernelId, frozenLineId, ref isValid); } public int CurvilinearFrozenLineGet(int meshKernelId, @@ -543,8 +543,21 @@ public int CurvilinearFrozenLinesGetCount(int meshKernelId, ref int numFrozenLin return MeshKernelDll.CurvilinearFrozenLinesGetCount(meshKernelId, ref numFrozenLines); } - public int CurvilinearFrozenLinesGetIds(int meshKernelId, ref int[] frozenLinesIds) + public int CurvilinearFrozenLinesGetIds(int meshKernelId, out int[] frozenLinesIds) { + int numFrozenLines = -1; + MeshKernelDll.CurvilinearFrozenLinesGetCount(meshKernelId, ref numFrozenLines); + if (numFrozenLines < 0) + { + frozenLinesIds = null; + return -1; + } + + frozenLinesIds = new int[numFrozenLines]; + if (numFrozenLines == 0) + { + return 0; + } IntPtr frozenLinesIdsPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(int)) * frozenLinesIds.Length); int success = MeshKernelDll.CurvilinearFrozenLinesGetIds(meshKernelId, frozenLinesIdsPtr); Marshal.Copy(frozenLinesIdsPtr, frozenLinesIds, 0, frozenLinesIds.Length); diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index 377e2aa..f3d0b36 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -613,8 +613,8 @@ internal static extern int CurvilinearFrozenLineAdd([In] int meshKernelId, /// The id of the frozen line to check /// True if the provided id is valid /// Error code - [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_valid", CallingConvention = CallingConvention.Cdecl)] - internal static extern int CurvilinearFrozenLineValid([In] int meshKernelId, [In] int frozenLineId, [In][Out] ref bool isValid); + [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_frozen_line_is_valid", CallingConvention = CallingConvention.Cdecl)] + internal static extern int CurvilinearFrozenLineIsValid([In] int meshKernelId, [In] int frozenLineId, [In][Out] ref bool isValid); /// /// Gets the coordinates of the frozen line @@ -644,7 +644,7 @@ internal static extern int CurvilinearFrozenLineGet([In] int meshKernelId, internal static extern int CurvilinearFrozenLinesGetCount([In] int meshKernelId, [In][Out] ref int numFrozenLines); /// - /// Gets the ids of the frozen lines + /// Gets the ids of the frozen lines. /// /// The id of the mesh state /// The frozen line ids diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index 42d589b..884bc1a 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -1462,6 +1462,8 @@ public void CurvilinearSetAndDeleteFrozenLines_ShouldSetAndDeleteFrozenLines() 0.0, 2.0, ref forzenLineId); + Assert.That(returnCode, Is.EqualTo(0)); + // Id is always increasing Assert.That(forzenLineId, Is.EqualTo(1)); @@ -1509,8 +1511,8 @@ public void CurvilinearFrozenLinesGetIds_ShouldReturnCorrectIds() // Act int numFrozenLines = 1; - var frozenLinesIds = new int[numFrozenLines]; - int returnCode = api.CurvilinearFrozenLinesGetIds(id, ref frozenLinesIds); + int[] frozenLinesIds; + int returnCode = api.CurvilinearFrozenLinesGetIds(id, out frozenLinesIds); // Assert Assert.That(returnCode, Is.EqualTo(0)); @@ -1527,7 +1529,7 @@ public void CurvilinearFrozenLineValid_ShouldReturnTrueForValidLine() // Act bool isValid = false; - int returnCode = api.CurvilinearFrozenLineValid(id, frozenLineId, ref isValid); + int returnCode = api.CurvilinearFrozenLineIsValid(id, frozenLineId, ref isValid); // Assert Assert.That(returnCode, Is.EqualTo(0)); @@ -1574,5 +1576,26 @@ public void CurvilinearFrozenLineAdd_ShouldIncrementId() Assert.That(newFrozenLineId, Is.GreaterThan(frozenLineId)); } + [Test] + public void CurvilinearSetAndDeleteFrozenLinesTwice_ShouldAddAndDeleteFrozenLineAndReturnErrorCode() + { + CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); + int forzenLineId = -1; + + // Set and delete + int returnCode = api.CurvilinearFrozenLineAdd(id, + 0.0, + 0.0, + 0.0, + 2.0, + ref forzenLineId); + Assert.That(forzenLineId, Is.EqualTo(0)); + + returnCode = api.CurvilinearFrozenLineDelete(id, forzenLineId); + Assert.That(returnCode, Is.EqualTo(0)); + returnCode = api.CurvilinearFrozenLineDelete(id, forzenLineId); + Assert.That(returnCode, Is.EqualTo(1)); + } + } } From 0f3c118a2543f4f8ecb33d962252f4264bc16cc8 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Tue, 11 Feb 2025 11:46:18 +0100 Subject: [PATCH 11/13] Account for comments --- Directory.Packages.props | 5 +++++ src/MeshKernelNET/Api/MeshKernelApi.cs | 2 +- src/MeshKernelNET/Native/MeshKernelDll.cs | 8 ++++---- .../MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs | 10 +++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f53e6d4..86177b4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,8 +2,13 @@ true +<<<<<<< HEAD +======= + + +>>>>>>> eaadc25 (Account for comments) diff --git a/src/MeshKernelNET/Api/MeshKernelApi.cs b/src/MeshKernelNET/Api/MeshKernelApi.cs index 0d10327..70645fc 100644 --- a/src/MeshKernelNET/Api/MeshKernelApi.cs +++ b/src/MeshKernelNET/Api/MeshKernelApi.cs @@ -579,7 +579,7 @@ public int CurvilinearSetLineLineShift(int meshKernelId, } public int CurvilinearSmoothing(int meshKernelId, - [In] int smoothingIterations, + int smoothingIterations, double xLowerLeftCorner, double yLowerLeftCorner, double xUpperRightCorner, diff --git a/src/MeshKernelNET/Native/MeshKernelDll.cs b/src/MeshKernelNET/Native/MeshKernelDll.cs index f3d0b36..8f6329d 100644 --- a/src/MeshKernelNET/Native/MeshKernelDll.cs +++ b/src/MeshKernelNET/Native/MeshKernelDll.cs @@ -673,10 +673,10 @@ internal static extern int CurvilinearSetLineLineShift([In] int meshKernelId, /// /// The meshKernelId of the block to orthogonalize /// The number of smoothing iterations to perform - /// The x coordinate of the lower left corner of the block to smooth - /// The y coordinate of the lower left corner of the block to smooth - /// The y coordinate of the lower left corner of the block to smooth - /// The y coordinate of the upper right corner of the block to smooth + /// The x coordinate of the lower left corner + /// The y coordinate of the lower left corner + /// The x coordinate of the upper right corner + /// The y coordinate of the upper right corner /// Error code [DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_smoothing", CallingConvention = CallingConvention.Cdecl)] internal static extern int CurvilinearSmoothing([In] int meshKernelId, diff --git a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs index 884bc1a..fd72a27 100644 --- a/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs +++ b/test/MeshKernelNETTest/Api/MeshKernelCurvilinearTest.cs @@ -1580,7 +1580,7 @@ public void CurvilinearFrozenLineAdd_ShouldIncrementId() public void CurvilinearSetAndDeleteFrozenLinesTwice_ShouldAddAndDeleteFrozenLineAndReturnErrorCode() { CreateGrid(5, 4, 1.0, 1.0, 1.0, 1.0); - int forzenLineId = -1; + int frozenLineId = -1; // Set and delete int returnCode = api.CurvilinearFrozenLineAdd(id, @@ -1588,12 +1588,12 @@ public void CurvilinearSetAndDeleteFrozenLinesTwice_ShouldAddAndDeleteFrozenLine 0.0, 0.0, 2.0, - ref forzenLineId); - Assert.That(forzenLineId, Is.EqualTo(0)); + ref frozenLineId); + Assert.That(frozenLineId, Is.EqualTo(0)); - returnCode = api.CurvilinearFrozenLineDelete(id, forzenLineId); + returnCode = api.CurvilinearFrozenLineDelete(id, frozenLineId); Assert.That(returnCode, Is.EqualTo(0)); - returnCode = api.CurvilinearFrozenLineDelete(id, forzenLineId); + returnCode = api.CurvilinearFrozenLineDelete(id, frozenLineId); Assert.That(returnCode, Is.EqualTo(1)); } From 3896157626129b7078c8731cc6495ade382db9c7 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Fri, 14 Feb 2025 09:54:56 +0100 Subject: [PATCH 12/13] Update meshkernel version --- Directory.Packages.props | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 86177b4..3d1164c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,13 +2,8 @@ true -<<<<<<< HEAD - - -======= ->>>>>>> eaadc25 (Account for comments) From 5a93c5b1386b6ba51f9891ffebe39456de913877 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Fri, 14 Feb 2025 11:26:36 +0100 Subject: [PATCH 13/13] check --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 3d1164c..5768b47 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,7 +4,7 @@ - +