Giter Club home page Giter Club logo

deltares / meshkernel Goto Github PK

View Code? Open in Web Editor NEW
29.0 7.0 8.0 124.68 MB

Deltares C++library for creating and editing meshes. It supports 1D & 2D unstructured meshes as well as curvilinear meshes.

Home Page: https://deltares.github.io/MeshKernel

License: GNU Lesser General Public License v2.1

CMake 1.29% C++ 96.63% Python 1.44% Shell 0.01% PowerShell 0.61% Batchfile 0.02%
unstructured-grids curvilinear-grids mesh-orthogonalization mesh-generation algorithm computational-geometry

meshkernel's Introduction

MeshKernel

Quality Gate Status

MeshKernel is a library for creating and editing meshes. It supports 1D & 2D unstructured meshes as well as curvilinear meshes.

Wrappers for the following languages are available:

The library is separated in an API namespace (MeshKernelApi) used for communication with the client and a backend namespace (MeshKernel) where the algorithms are implemented. The API namespace contains several structures used as parameters for the API methods (see API usage section). These structures must be mirrored in the client application and filled with appropriate values.

Examples

  1. Creating a triangular mesh inside a polygon

In this example a mesh is created by discretizing the polygon perimeter with the desired edge length.

alt tag

  1. Mesh orthogonalization

Finite volume staggered flow solvers require the mesh to be as much orthogonal as possible. MeshKernel provides an algorithm to adapt the mesh and achieve a good balance between mesh orthogonality and smoothness.

alt tag

  1. Curvilinear mesh generation

Curvilinear meshes for rivers can be generated using splines.

alt tag

  1. Mesh refinement

A mesh can be refined in areas based on samples or polygon selections.

alt tag

Shared library dependencies (Linux)

  • libgomp

Build Requirements

The requirements are:

  • Git
  • CMake 3.23 or higher
  • A C++20 compatible compiler. Currently the following compilers are supported:
    • Windows: Microsoft Visual C++
    • Linux: GCC
    • macOS: GCC. Clang is not yet supported. Care must be taken if gcc and g++ are symbolic links to clang and clang++
  • The Boost libraries
  • NetCDF
  • Doxygen (optional)

Dependencies

Boost

  • Under Windows, precompiled boost binaries (with MSVC compiler) can be downloaded here. Alternatively, the source code is available here and the installation instructions can be found here. Once installed, set the boost environment variable BOOST_INCLUDEDIR to the appropriate path. For example, if version 1.74.0 in installed in C:\Apps, set BOOST_INCLUDEDIR=C:\Apps\boost_1_74_0.
  • Under Linux, Boost can be either obtained from the package repository of the used Linux distribution or built from source following these instructions.
  • Under macOS, Boost can be installed by following these instructions.

NetCDF

The NetCDF static library is required for building MeshKernel. Optionally, a PowerShell script is made available for cloning and building NetCDF and its dependencies (HDF5, ZLIB, Curl, and m4). It can be used under Windows, Linux, and macOS. The script is compatible with Powershell version 7 and higher. If necessary, Windows users need to upgrade to from version 5 to 7. The procedure is described here.

To run the script in a PowerShell session, use

.\install_netcdf_static.ps1 -WorkDir '/path/to/work/directory' -InstallDir '/path/to/install/directory' -BuildType 'Release' -ParallelJobs 10 -GitTags @{zlib = 'v1.2.13'; curl = 'curl-7_88_1';  hdf5 = 'hdf5-1_14_0';  netcdf_c = 'v4.9.1'}

with /path/to/work/directory and /path/to/install/directory replaced with valid paths.

For more information regarding the script's options above, use

Get-Help .\install_netcdf_static.ps1 -Detailed

Upon successful installation, to build MeshKernel successfully, it is important to either

  • add the path to the install directory to the system path, or
  • configure the MeshKernel build with -DCMAKE_PREFIX_PATH=/path/to/install/directory.

Note: Additional dependencies may be required depending on the system configuration:

Configuring and Building MeshKernel

Follow the steps below to configure, build and install MeshKernel.

Steps

  1. To configure under Windows with Visual Studio, a solution is generated using

    cmake -S <path-to-source-dir> -B <path-to-build-dir> -G "Visual Studio 16 2019" --install-prefix <path-to-install-dir>

    This example uses Visual Studio 16 2019. A different version can be specified. In the above

    • <path-to-source-dir> is the path to the MeshKernel source tree (the top-level directory containing source files provided by the project).
    • <path-to-build-dir> is the path to the directory where MeshKernel is to be built.
    • <path-to-install-dir> is the path top the directory where MeshKernel is to be installed.

    Under Linux and macOS , the generator option can be omitted or the following can be used:

    cmake -S <path-to-source-dir> -B <path-to-build-dir> -G "Unix Makefiles" --install-prefix <path-to-install-dir>
  2. To build the project's targets, use:

    cmake --build <path-to-build-dir> --config <cfg> --parallel <jobs>

    where

    • <cfg> is the build type (Debug, Release, RelWithDebInfo and MinSizeRel), see CMAKE_BUILD_TYPE.
    • <jobs> is the maximum number of concurrent processes to use when building.

    Note: this builds the documentation by default in <path-to-build-dir>/docs/html.

  3. To install, use:

    cmake --install <path-to-build-dir>

    or

    cmake --install <path-to-build-dir> --prefix [<path-to-install-dir>]

    to override the installation path specified during configuration (step 1).

Additional configuration options

MeshKernel can be configured with a set of options, which are summarized in the table below.

Option Description Type Default Notes
ENABLE_UNIT_TESTING Enables building the unit test executables Bool ON
ENABLE_BENCHMARKING Enables building the benchmark executable Bool OFF
ENABLE_BENCHMARKING_MEM_REPORT Enables reporting memory usage statistics Bool OFF Applicable only when ENABLE_BENCHMARKING is ON, ignored otherwise
ENABLE_CODE_COVERAGE Generates code coverage report Bool OFF Valid only under Linux and macOS when a GNU compiler is used (requires gcov), ignored otherwise
HAVE_SRC_LOC_IN_ERR_MSGS Includes the source location information in custom exceptions Bool OFF

meshkernel's People

Contributors

ahmad-el-sayed avatar andreasbuykx avatar arthurvd avatar beardedplatypus avatar billsenior avatar carloslubbers avatar evetion avatar hiddeelzinga avatar hofer-julian avatar lrvl avatar lucacarniato avatar mooiman avatar scottwillcox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meshkernel's Issues

Feature request: clipping mesh by (Multi)Polygon with holes

A GeometryList can contain a representation of a MultiPolygon or Polygon with holes. The function mkernel_mesh2d_delete now only seems to work for a Polygon without holes (a GeometryList with -999.0 or -998.0 is not processed). It would be convenient if for example a rectilinear mesh can be clipped by a Multipolygon. Now problems arise when generating a mesh with islands, or even worse, things like islands with lakes.

Trying to create a 2D Surface mesh using 2D Splines

I'm trying to generate a 2D mesh using 2D splines, but I get the following output:

image

I use the following code

        splines->AddSpline(sp1, 0, sp1.size());
	splines->AddSpline(sp2, 0, sp2.size());
	splines->AddSpline(sp3, 0, sp3.size());
	splines->AddSpline(sp4, 0, sp4.size());
	splines->AddSpline(sp5, 0, sp5.size());
	splines->AddSpline(sp6, 0, sp6.size());
	splines->AddSpline(sp7, 0, sp7.size());

    meshkernelapi::CurvilinearParameters curvilinearParameters;
    meshkernelapi::SplinesToCurvilinearParameters splinesToCurvilinearParameters;

    splinesToCurvilinearParameters.aspect_ratio = 0.1;
    splinesToCurvilinearParameters.aspect_ratio_grow_factor = 1.1;
    splinesToCurvilinearParameters.average_width = 10000.0;
    splinesToCurvilinearParameters.nodes_on_top_of_each_other_tolerance = 1e-4;
    splinesToCurvilinearParameters.min_cosine_crossing_angles = 0.95;
    splinesToCurvilinearParameters.check_front_collisions = false;
    splinesToCurvilinearParameters.curvature_adapted_grid_spacing = true;
    splinesToCurvilinearParameters.remove_skinny_triangles = 0;
    curvilinearParameters.m_refinement = 20;
    curvilinearParameters.n_refinement = 40;

    // create the algorithm
    meshkernel::CurvilinearGridFromSplines curvilinearGridFromSplines(splines, curvilinearParameters, splinesToCurvilinearParameters);

    // compute
    const auto curviGrid = curvilinearGridFromSplines.Compute();

	meshkernel::Mesh2D mesh(curviGrid.m_edges, curviGrid.m_nodes, meshkernel::Projection::cartesian);

	points_voronoi = vtkSmartPointer<vtkPoints>::New();

	for (auto& v : mesh.m_nodes)
	{
		points_mesh.push_back({ v.x, v.y });


	}
	for (int i = 0; i < mesh.m_facesNodes.size(); i++)
	{
		for (int j = 0; j < 4; j++)
		{
			indices_mesh.push_back(mesh.m_facesNodes[i][j]);
		}
	}

and the Splines are attached here:
L1.txt
L2.txt
L3.txt
L4.txt
L5.txt
L6.txt
L7.txt
L8.txt

Add an API for extracting cross-section information

@veenstrajelmer would like to add an API that exports the geometrical information about cross sections. The use case is shown in this figure

crosssection

For each crossed face the API should return its index AND the coordinates of the two intersections (green dots). The order must be increased along the line direction (in the figure above the order will be [0,1,5,6,7,11]).

Important notes:

  • The face indices are provided in the netCDF file and the Mesh2D parameter in mkernel_mesh2d_set must contain the face nodes information
  • To limit the search of the potential crossed faces, the m_facesRTree RTree with a search radius could be used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.