{"id":25730421,"url":"https://github.com/qtiptip/lrsplines","last_synced_at":"2025-05-07T14:10:06.099Z","repository":{"id":83434981,"uuid":"147192280","full_name":"qTipTip/LRSplines","owner":"qTipTip","description":"A Python implementation of locally refined B-splines (LR-splines).","archived":false,"fork":false,"pushed_at":"2023-11-11T11:55:34.000Z","size":5829,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T14:10:00.571Z","etag":null,"topics":["splines"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qTipTip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-09-03T11:00:25.000Z","updated_at":"2025-03-20T08:35:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"483fbacc-0b92-40c0-8578-9a8d7e77e81a","html_url":"https://github.com/qTipTip/LRSplines","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qTipTip%2FLRSplines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qTipTip%2FLRSplines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qTipTip%2FLRSplines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qTipTip%2FLRSplines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qTipTip","download_url":"https://codeload.github.com/qTipTip/LRSplines/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252892503,"owners_count":21820648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["splines"],"created_at":"2025-02-26T01:47:36.576Z","updated_at":"2025-05-07T14:10:06.041Z","avatar_url":"https://github.com/qTipTip.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LR Splines\n[![Build Status](https://travis-ci.org/qTipTip/LRSplines.svg?branch=master)](https://travis-ci.org/qTipTip/LRSplines)\n[![Coverage Status](https://coveralls.io/repos/github/qTipTip/LRSplines/badge.svg?branch=master)](https://coveralls.io/github/qTipTip/LRSplines?branch=master)\n[![Documentation Status](https://readthedocs.org/projects/lrsplines/badge/?version=latest)](https://lrsplines.readthedocs.io/en/latest/?badge=latest)\n#### An LR-Spline implementation written in Python.\n\nThis aim of Python library is to provide a lightweight framework for understanding\nLR-splines. The library is in no shape or form optimized for high performance computing, but is rather aimed\nat being a small toolkit for gaining some intuition for LR-splines. For more industrial grade\nperformance and a more complete set of tools, see the [GoTools library](https://github.com/SINTEF-Geometry/GoTools) written in C++.\n\nOther LR-spline-related projects:\n\n1. [LRSplines](https://github.com/VikingScientist/LRsplines): A C++ library which some of the code in this repository is based on. \n2. [LRSplines: Android App](https://github.com/VikingScientist/LR-introduction): An app for interactive demonstration of the LR-spline refinement procedure.\n\n### Introduction\n\nThe need for adaptive refinement techniques is evident when it comes to optimizing the tradeoff between computational cost\nand computational accuracy. When utilizing spline spaces with an underlying tensor-product structure,\nrefinement of a mesh induces a global propagation of the newly introduced meshlines to the whole mesh. This can be\nvery inefficient. The concept of LR-Splines was introduced in 2013 in the paper [Polynomial splines over locally refined box-partitions](https://www.sciencedirect.com/science/article/pii/S0167839613000113),\nand can be seen as an attempt to remedy this aforementioned problem.\nLR-Splines have several desirable properties:\n\n1. They form a non-negative partition of unity by construction.\n2. Linear independence (under some conditions on the refinement).\n\n### Construction\n\nLR-splines are construced by starting with an initial **tensor product** spline space. Meshlines are then inserted one at the time,\nmaking sure the line **completely traverses** the support of at least one B-spline.\n\nThis B-spline is then **split** according to the standard knot insertion procedure, producing two new B-splines.\nThese new B-splines are subsequently tested against **all previously existing meshlines**, to check for further splitting.\n\n### Installation\n\nDownload the repository and run:\n```bash\n    python setup.py install\n```\n\nVerify the installation by running:\n```bash\n    python -m import LRSplines\n```\n \n### Basic Usage\n\nThe central object in the LRSplines-package is the LRSpline object.\nWe initialize an LRSpline at the tensor-product level by specifying two knot vectors, and corresponding polynomial degrees.\nThe following code initializes a biquadratic LR-spline. \n\n#### Initialization and mesh visualization\n\n```python\nimport LRSplines\n\ndu = 2\ndv = 2\nknots_u = [0, 0, 0, 1, 2, 3, 3, 3]\nknots_v = [0, 0, 0, 1, 2, 3, 3, 3]\n\nLR = LRSplines.init_tensor_product_LR_spline(du, dv, knots_u, knots_v)\n```\n\nWe can at any stage visualize the LR-mesh which underlies a given LR-spline, as seen:\n\n```python\nLR.visualize_mesh()\n```\nyielding the image\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=resources/mesh_1.png/\u003e\n\u003c/p\u003e\n\nHere, each **element** of the mesh displays the number of supported B-splines. In this case there are nine supported B-splines on\neach element. The green color indicates that the element is not **overloaded**. Each meshline displays its **multiplicity**\nindicated by a number in a white box. As we can see, the boundary mesh-lines have multiplicity 3, which reflects the knot\nvectors we chose. The dimension of the spline space is displayed at the top. In this case, we have five basis splines in each direction, totaling 25\ntensor product B-splines.\n\n#### Meshline insertion\n\nWe can insert mesh-lines into the mesh by creating a new Meshline object. In this example, we insert a meshline\nbetween the points (1.5, 0) and (1.5, 2) and between the points(1, 1.5) and (3, 1.5). \nThis is represented in Python as:\n\n```python\nm1 = LRSplines.Meshline(start=0, stop=2, constant_value=1.5, axis=0)\nm2 = LRSplines.Meshline(start=1, stop=3, constant_value=1.5, axis=1)\n```\n\nThe `axis` parameter determines the direction of the meshline, i.e., 0 for vertical and 1 for horizontal.\nWe insert this meshline into the LR-spline, and visualize the result.\n\n```python\nLR.insert_line(m1)\nLR.insert_line(m2)\nLR.visualize_mesh()\n```\n\nThis yields the following image:\n\u003cp align=\"center\"\u003e\n  \u003cimg src=resources/mesh_2.png/\u003e\n\u003c/p\u003e\nAs we can see, some of the elements have turned red, indicating that they are now overloaded, which may result in loss of linear independence.\n\n    \n#### Evaluation\n\nWe can at any stage evaluate the LR-spline. At the moment there is no clever functionality for setting\nthe coefficients of the underlying B-splines, but we can do so explicitly by looping over the set of basis functions\n`LR.S`.\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\n# set the coefficients explicitly\nfor b in LR.S:\n    b.coefficient = np.random.random(-3, 3)\n\nN = 20\nx = np.linspace(knots_u[0], knots_u[-1], N)\ny = np.linspace(knots_v[0], knots_v[-1], N)\nz = np.zeros((N, N))\nX, Y = np.meshgrid(x, y)\n\nfor i in range(N):\n    for j in range(N):\n        z[i, j] = LR(x[i], y[j])\n\nfig = plt.figure()\naxs = Axes3D(fig)\n \naxs.plot_wireframe(X, Y, z) # or plot_surface\n\n```\n\nThis gives the resulting surface:\n\u003cp align=\"center\"\u003e\n  \u003cimg src=resources/surf_1.png/\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqtiptip%2Flrsplines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqtiptip%2Flrsplines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqtiptip%2Flrsplines/lists"}