### Compile and install NutStore Nautilus plugin Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-11-04-nutstore.md These commands extract the downloaded source package, navigate into the directory, configure the build, compile the plugin, and then install it system-wide. ```bash tar zxf nutstore_linux_src_installer.tar.gz cd nutstore_linux_src_installer && ./configure && make sudo make install ``` -------------------------------- ### Verify FEALPy Installation Source: https://github.com/weihuayi/fealpy/blob/master/README.md A Python command to import the `fealpy` package and print its version, confirming successful installation. ```python import fealpy; print(fealpy.__version__) ``` -------------------------------- ### Install FEALPy with Development and Optional Dependencies Source: https://github.com/weihuayi/fealpy/blob/master/README.md Command to install FEALPy including both its development tools and all optional dependencies, suitable for contributors. ```bash pip install -e ".[dev,optional]" ``` -------------------------------- ### Install Doxygen and Graphviz on Linux Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-14-doxygen-manual.md Instructions to install Doxygen and Graphviz on a Linux system using the apt package manager, which are essential for generating comprehensive code documentation. ```bash sudo apt install graphviz sudo apt install doxygen ``` -------------------------------- ### Install Miniconda Source: https://github.com/weihuayi/fealpy/blob/master/README.md Provides commands to download and initialize Miniconda, a minimal installer for conda, which is used for managing environments and packages. ```bash mkdir -p ~/miniconda3 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 rm -rf ~/miniconda3/miniconda.sh ~/miniconda3/bin/conda init bash ``` -------------------------------- ### Install build dependencies for NutStore on Linux Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-11-04-nutstore.md This command installs necessary development libraries and Python dependencies required to compile the NutStore Nautilus plugin on a Debian/Ubuntu-based Linux system. ```bash sudo apt-get install libglib2.0-dev libgtk2.0-dev libnautilus-extension-dev gvfs-bin python3-gi gir1.2-appindicator3-0.1 ``` -------------------------------- ### Install FEALPy with Optional Dependencies Source: https://github.com/weihuayi/fealpy/blob/master/README.md Command to install FEALPy along with its optional dependencies, such as `pypardiso`, `pyamg`, and `meshpy`, which provide extended functionality. ```bash pip install -e ".[optional]" ``` -------------------------------- ### Full C++ Doxygen Example: Tetrahedron Quadrature Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-14-doxygen-manual.md A comprehensive C++ example demonstrating Doxygen comments for file information, function descriptions, struct members, and a test function for numerical integration, including usage of common tags and LaTeX formulas. ```c++ /** * \\file test_TetrahedronQuadrature.cpp * \\author Chunyu Chen * \\date 2021/09/08 * \\brief TetrahedronQuadrature.h 测试文件 */ #include #include #include #include #include "TestMacro.h" #include "geometry/Point_3.h" #include "geometry/Vector_3.h" #include "quadrature/TetrahedronQuadrature.h" typedef WHYSC::GeometryObject::Point_3 Point; typedef WHYSC::Quadrature::TetrahedronQuadrature TetrahedronQuadrature; /** * \\brief 被积函数 * \\param p 函数的参数 */ double f(const Point & p) { return p[0];//p[0]*p[1]; } /** * \\brief 四面体类, 即积分区域 */ struct Tetrahedron { Point p0, p1, p2, p3; /**< 四面体顶点 */ /** * \\brief 四面体面积 */ double area() { auto v1 = p1 - p0; auto v2 = p2 - p0; auto v3 = p3 - p0; return std::abs(dot(cross(v1, v2), v3)/6); } }; /** * \\brief 积分测试函数 */ void test_integral(int p = 3, double h = 0.5) { Tetrahedron tet; tet.p0 = Point({0, 0, 0}); tet.p1 = Point({h, 0, 0}); tet.p2 = Point({0, h, 0}); tet.p3 = Point({0, 0, h}); TetrahedronQuadrature tetQ ``` -------------------------------- ### Run NutStore runtime bootstrap Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-11-04-nutstore.md This command executes the runtime bootstrap script, which automatically downloads and installs the main NutStore application and other necessary binary components. ```bash ./runtime_bootstrap ``` -------------------------------- ### Install FEALPy in Editable Development Mode Source: https://github.com/weihuayi/fealpy/blob/master/README.md Commands to navigate into the cloned FEALPy directory and install the package in editable mode, allowing local changes to be reflected without reinstallation. ```bash cd fealpy pip install -e . ``` -------------------------------- ### LaTeX Matrix or Matrix Function Example Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Example of a matrix definition using LaTeX, illustrating the convention for bold uppercase letters representing matrices or matrix functions. ```latex \boldsymbol A = \boldsymbol L \boldsymbol L^T. ``` -------------------------------- ### Define Basic C++ Executables with CMake Source: https://github.com/weihuayi/fealpy/blob/master/src/whysc/test/CMakeLists.txt This CMake snippet defines two fundamental C++ executables: 'hello_world' for a basic program and 'sizeof' for demonstrating type sizes. These are common initial setup targets in C++ projects. ```CMake add_executable(hello_world hello_world.cpp) add_executable(sizeof sizeof.cpp) ``` -------------------------------- ### LaTeX Vector or Vector Function Example Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Example of a vector definition using LaTeX, illustrating the convention for bold lowercase letters representing vectors or vector functions. ```latex \boldsymbol a = [0,1,\cdots,n]. ``` -------------------------------- ### Create and Visualize Quadrangle Mesh in FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb Demonstrates how to create a 2D quadrangle mesh using QuadrangleMesh.from_one_quadrangle or QuadrangleMesh.from_unit_square and visualize it with Matplotlib, including finding nodes, cells, and edges. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.mesh import QuadrangleMesh i = 1 if i == 0: mesh = QuadrangleMesh.from_one_quadrangle(meshtype='square') elif i == 1:mesh = QuadrangleMesh.from_unit_square( nx=10, ny=10, threshold=None) fig, axes = plt.subplots() mesh.add_plot(axes) mesh.find_node(axes) mesh.find_cell(axes) mesh.find_edge(axes) plt.show() ``` -------------------------------- ### LaTeX Command Spacing Example Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Compares good and bad practices for spacing between LaTeX commands within a formula, emphasizing the importance of spaces for proper rendering. ```tex $\Omega \subset \mathbbR^d$ % nice $\Omega\subset\mathbbR^d$ % bad ``` -------------------------------- ### LaTeX Operator Definition Example Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Example of an operator definition using LaTeX, illustrating the convention for calligraphic uppercase letters representing operators. ```latex \mcA : H^1_0(\Omega) \to H^{-1}(\Omega). ``` -------------------------------- ### Update FEALPy from Source Repository Source: https://github.com/weihuayi/fealpy/blob/master/README.md Commands to navigate to the FEALPy directory and pull the latest changes from the `main` branch of the origin repository, updating the local installation. ```bash cd fealpy git pull origin main ``` -------------------------------- ### Restart Nautilus file manager Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-11-04-nutstore.md This command quits the running Nautilus file manager process, which is often necessary for newly installed plugins to take effect. ```bash nautilus -q ``` -------------------------------- ### Create and Visualize Hexahedron Mesh in FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb Provides examples for generating 3D hexahedron meshes. It covers creating a mesh from a box with a threshold function using HexahedronMesh.from_box and converting from an existing TetrahedronMesh using HexahedronMesh.from_tetrahedron_mesh. The mesh is then plotted in 3D. ```python import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from fealpy.mesh import TetrahedronMesh from fealpy.mesh import HexahedronMesh i = 1 if i==0: def threshold(p): x = p[..., 0] y = p[..., 1] z = p[..., 2] return (x > 0.0) & (y < 0.0) & (z > 0.0) box = [-1, 1, -1, 1, -1, 1] mesh = HexahedronMesh.from_box( box=box, nx=10, ny=10, nz=10, threshold=threshold) if i==1: tmesh = TetrahedronMesh.from_one_tetrahedron(meshtype='equ') mesh = HexahedronMesh.from_tetrahedron_mesh(tmesh) fig = plt.figure() axes = fig.add_subplot(111, projection='3d') mesh.add_plot(axes) plt.show() ``` -------------------------------- ### LaTeX Scalar Function Example Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Example of a scalar function definition using LaTeX, illustrating the convention for lowercase English or Greek letters. ```latex f(x) = 2x + 3. ``` -------------------------------- ### Solving a Simple Poisson Equation with Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/docs/_layouts/none.html This example illustrates the basic steps to solve a Poisson equation (∇²u = f) using Fealpy's finite element capabilities. It involves defining the domain, boundary conditions, source term, and then assembling and solving the linear system. ```Python import numpy as np from fealpy.mesh import UniformMesh2d from fealpy.functionspace import LagrangeFiniteElementSpace from fealpy.boundarycondition import DirichletBC from fealpy.solver import solve_linear_system # 1. Mesh Generation a, b, c, d = 0.0, 1.0, 0.0, 1.0 NX, NY = 10, 10 mesh = UniformMesh2d([a, b, c, d], NX, NY) # 2. Function Space p = 1 # Degree of polynomial space = LagrangeFiniteElementSpace(mesh, p=p) # 3. Source Term (f = -2*pi^2*sin(pi*x)*sin(pi*y)) f = lambda p: -2*np.pi**2 * np.sin(np.pi*p[..., 0]) * np.sin(np.pi*p[..., 1]) # 4. Assemble Stiffness Matrix and Load Vector A = space.stiff_matrix() F = space.source_vector(f) # 5. Boundary Conditions (u = sin(pi*x)*sin(pi*y) on boundary) bc = DirichletBC(space, lambda p: np.sin(np.pi*p[..., 0]) * np.sin(np.pi*p[..., 1])) A, F = bc.apply(A, F) # 6. Solve Linear System u = solve_linear_system(A, F) # u now contains the nodal solution ``` -------------------------------- ### Configure Basic CMake Project Source: https://github.com/weihuayi/fealpy/blob/master/CMakeLists.txt This CMake snippet sets the minimum required CMake version to 3.0, defines a C++ project named 'fealpy_extent', and includes the 'src' subdirectory for compilation. It's a foundational setup for a C++ project using CMake. ```CMake cmake_minimum_required(VERSUION 3.0) project(fealpy_extent CXX) add_subdirectory(src) ``` -------------------------------- ### LaTeX Inline Formula with Punctuation Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Example demonstrating the placement of punctuation immediately after an inline LaTeX formula. ```latex 设 $x \in \mmathbb R$, 则有 $\cdots$. ``` -------------------------------- ### Conditionally Set SIGMA Installation Directory Source: https://github.com/weihuayi/fealpy/blob/master/exten/CMakeLists.txt This snippet defines the `SIGMA_DIR` variable, which points to the SIGMA software installation. It first sets a default path if `SIGMA_DIR` is not already defined, then overrides it with a specific path if the build is running on a particular host machine. ```CMake if(NOT SIGMA_DIR) set(SIGMA_DIR "/usr/local") endif() message(STATUS "${SIGMA_DIR}") site_name(HOST_NAME) if( HOST_NAME STREQUAL "why-XPS-15-9530") message(STATUS ${HOST_NAME}) set(SIGMA_DIR "/home/why/software/sigma/1.2.1") endif() ``` -------------------------------- ### Construct and Display Tetrahedron Mesh in FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb Shows how to create 3D tetrahedron meshes using TetrahedronMesh.from_one_tetrahedron, from_cylinder_gmsh, or from_meshpy with custom points and facets. The resulting 3D mesh is visualized using Matplotlib's 3D projection. ```python import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from fealpy.mesh import TetrahedronMesh i = 0 if i == 0: mesh = TetrahedronMesh.from_one_tetrahedron(meshtype='equ') if i == 1: mesh = TetrahedronMesh.from_cylinder_gmsh(1, 5, 0.1) if i == 2: points = np.array([ (0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1), ]) facets = np.array([ [0, 1, 2, 3], [4, 5, 6, 7], [0, 4, 5, 1], [1, 5, 6, 2], [2, 6, 7, 3], [3, 7, 4, 0], ]) mesh = TetrahedronMesh.from_meshpy(points, facets, 0.2) fig = plt.figure() axes = fig.add_subplot(111, projection='3d') mesh.add_plot(axes) plt.show() ``` -------------------------------- ### Generate 1D Uniform Cartesian Mesh with Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet demonstrates how to create and visualize a one-dimensional uniform Cartesian mesh using `fealpy.mesh.UniformMesh1d`. It defines a domain, sets the number of divisions, calculates the step size, and then initializes the mesh. The mesh nodes and cells are extracted and plotted with their indices. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.mesh import UniformMesh1d domain = [0.0, 1.0] nx = 5 hx = (domain[1] - domain[0])/nx mesh = UniformMesh1d([0, nx], h=hx, origin=domain[0]) node = mesh.entity('node') cell = mesh.entity('cell') fig, axes = plt.subplots() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) plt.show() ``` -------------------------------- ### Generate 3D Uniform Cartesian Mesh with Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet demonstrates the creation of a three-dimensional uniform Cartesian mesh using `fealpy.mesh.UniformMesh3d`. It defines a 3D domain, sets divisions for x, y, and z axes, calculates step sizes, and initializes the 3D mesh. The mesh is then plotted in a 3D projection. ```python from fealpy.mesh import UniformMesh3d from mpl_toolkits.mplot3d import Axes3D domain = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0] nx = 5 ny = 5 nz = 5 hx = (domain[1] - domain[0])/nx hy = (domain[3] - domain[2])/ny hz = (domain[5] - domain[4])/nz mesh = UniformMesh3d( [0, nx, 0, ny, 0, nz], h=(hx, hy, hz), origin=(domain[0], domain[2], domain[3])) fig = plt.figure() axes = fig.add_subplot(111, projection='3d') mesh.add_plot(axes) plt.show() ``` -------------------------------- ### Set Up Conda Environment for FEALPy with GPU Support Source: https://github.com/weihuayi/fealpy/blob/master/README.md Commands to create and activate a new conda environment named `gpufealpy310` with Python 3.10, and install essential scientific computing libraries including NumPy, IPython, Jupyter Notebook, JAX with CUDA support, CuPy, and PyTorch. ```bash conda create -n gpufealpy310 python=3.10 conda activate gpufealpy310 conda install numpy=2.0.1 -c conda-forge #2.0.1 conda install ipython notebook -c conda-forge conda install jaxlib=*=*cuda* jax cuda-nvcc -c conda-forge -c nvidia # 0.4.31 conda install cupy -c conda-forge -c nvidia conda install pytorch=2.3.1 -c conda-forge -c nvidia ``` -------------------------------- ### Visualize Triangle Mesh Shape Functions Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet demonstrates utility methods of `fealpy.mesh.TriangleMesh` to visualize lattice structures and shape functions. It shows how to display the lattice for a given refinement level, and how to plot linear ('L') shape functions and their gradients. ```python from fealpy.mesh import TriangleMesh TriangleMesh.show_lattice(4) TriangleMesh.show_shape_function(4, funtype='L') TriangleMesh.show_grad_shape_function(4, funtype='L') ``` -------------------------------- ### LaTeX Long Matrix Equation Alignment Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-18-team-writing-rule.md Example of a long mathematical formula using LaTeX's `aligned` environment and `bmatrix` for matrix representation, demonstrating proper alignment for readability. ```latex $$ \begin{aligned} \begin{bmatrix} \boldsymbol A & \boldsymbol 0 &\boldsymbol B_{1} \\ \boldsymbol 0 & \boldsymbol A &\boldsymbol B_{2}\\ \boldsymbol B_{1}^{T} & \boldsymbol B_{2}^{T} & \boldsymbol 0\\ \end{bmatrix} \begin{bmatrix} \boldsymbol U_x \\ \boldsymbol U_y \\ \boldsymbol P \end{bmatrix} \end{aligned} $$ ``` -------------------------------- ### Generate Triangle Mesh using Distmesh Algorithm Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet demonstrates generating a `fealpy.mesh.TriangleMesh` using the Distmesh algorithm, integrated with `fealpy.geometry` domains like `LShapeDomain` or `CircleDomain`. It shows how to define a sizing function for adaptive mesh generation based on the domain's signed distance function, then creates and plots the mesh. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.geometry import LShapeDomain, CircleDomain from fealpy.mesh import TriangleMesh i = 1 if i == 0: domain = LShapeDomain() hmin = 0.1 if i == 1: hmin = 0.05 hmax = .2 def sizing_function(p, *args): fd = args[0] x = p[:, 0] y = p[:, 1] h = hmin + np.abs(fd(p))*0.1 h[h>hmax] = hmax return h domain = CircleDomain(fh=sizing_function) mesh = TriangleMesh.from_domain_distmesh( domain, hmin, maxit=100) fig, axes = plt.subplots() mesh.add_plot(axes) plt.show() ``` -------------------------------- ### Generate 2D Uniform Cartesian Mesh with Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet extends the uniform mesh generation to two dimensions using `fealpy.mesh.UniformMesh2d`. It defines a 2D domain, sets divisions for both x and y axes, calculates step sizes, and initializes the 2D mesh. The mesh is then plotted. ```python from fealpy.mesh import UniformMesh2d domain = [0.0, 1.0, 0.0, 1.0] nx = 5 ny = 5 hx = (domain[1] - domain[0])/nx hy = (domain[3] - domain[2])/ny mesh = UniformMesh2d( [0, nx, 0, ny], h=(hx, hy), origin=(domain[0], domain[2])) fig, axes = plt.subplots() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) plt.show() ``` -------------------------------- ### Generate and Plot Polygon Mesh in FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb Illustrates various methods to create a 2D polygon mesh, including PolygonMesh.from_one_triangle, from_one_square, from_one_pentagon, from_one_hexagon, and converting from a TriangleMesh generated by GMSH. The mesh is then plotted using Matplotlib. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.mesh import PolygonMesh, TriangleMesh i = 4 if i == 0: mesh = PolygonMesh.from_one_triangle(meshtype='iso') elif i == 1: mesh = PolygonMesh.from_one_square() elif i == 2: mesh = PolygonMesh.from_one_pentagon() elif i == 3: mesh = PolygonMesh.from_one_hexagon() elif i == 4: vertices = np.array([(0, 0), (1, 0), (0.5, 1)]) h = 0.1 tmesh = TriangleMesh.from_polygon_gmsh(vertices, h) mesh = PolygonMesh.from_triangle_mesh_by_dual(tmesh, bc=True) fig, axes = plt.subplots() mesh.add_plot(axes, cellcolor=[0.5, 0.9, 0.45], edgecolor='k') plt.show() ``` -------------------------------- ### Fealpy Triangle Mesh and Lagrange Finite Element Space Visualization Source: https://github.com/weihuayi/fealpy/blob/master/notebook/jax.ipynb This snippet illustrates the creation and visualization of a `TriangleMesh` using Fealpy, along with the setup of a `LagrangeFESpace`. It shows how to obtain interpolation points and cell-to-dof mappings, and then plot the mesh and its nodes using Matplotlib. ```python import matplotlib.pyplot as plt from fealpy.mesh import TriangleMesh from fealpy.functionspace import LagrangeFESpace mesh = TriangleMesh.from_box(box=[0, 1, 0, 1], nx=1, ny=1) space = LagrangeFESpace(mesh, p = 3) ips = space.interpolation_points() cell2dof = space.cell_to_dof() print(cell2dof) print(ips) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, node=ips, showindex=True) #mesh.find_cell(axes, showindex=True) #mesh.find_edge(axes, showindex=True) ``` -------------------------------- ### Create 1D Interval Mesh from Explicit Nodes and Cells Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet demonstrates how to construct a one-dimensional interval mesh using `fealpy.mesh.IntervalMesh` by explicitly providing node coordinates and cell connectivity. It then uniformly refines the mesh and visualizes it, showing node and cell indices. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.mesh import IntervalMesh node = np.array([[0], [0.5], [1]], dtype=np.float64) # (NN, 1) array cell = np.array([[0, 1], [1, 2]], dtype=np.int_) # (NN, 2) array mesh = IntervalMesh(node, cell) mesh.uniform_refine(n=2) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_cell(axes, showindex=True) plt.show() ``` -------------------------------- ### Download NutStore Nautilus plugin source Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-11-04-nutstore.md This command downloads the compressed source code package for the NutStore Nautilus plugin from the official NutStore website using wget. ```bash wget https://www.jianguoyun.com/static/exe/installer/nutstore_linux_src_installer.tar.gz ``` -------------------------------- ### Configure a Basic CMake Project Source: https://github.com/weihuayi/fealpy/blob/master/src/whysc/CMakeLists.txt This CMake snippet outlines the fundamental commands for initializing a C++ project. It sets the minimum required CMake version, defines the project name, specifies an include directory, prints the project source directory, adds an executable target from a source file, and includes a subdirectory for modular build organization. ```CMake cmake_minimum_required(VERSION 3.0) project(WHYSC) include_directories(${PROJECT_SOURCE_DIR}/include) message(STATUS "${PROJECT_SOURCE_DIR}") add_executable(hello hello.cpp) add_subdirectory(test) ``` -------------------------------- ### Create Triangle Mesh in FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh_beginner.ipynb Demonstrates how to quickly create a TriangleMesh instance in FEALPy using the `from_box()` method. This method initializes a triangular mesh within a specified bounding box and resolution, simplifying mesh generation for common geometries. ```python from fealpy.mesh import TriangleMesh mesh = TriangleMesh.from_box([-1, 1, -1, 1], nx=3, ny=3) ``` -------------------------------- ### Create and Activate Python Virtual Environment for FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/README.md Commands to create a dedicated Python virtual environment for FEALPy and activate it, ensuring dependency isolation. Includes instructions for both Linux/macOS and Windows. ```bash python -m venv fealpy_env source fealpy_env/bin/activate # On Windows, use `fealpy_env\Scripts\activate` ``` -------------------------------- ### Create Triangle Mesh Embedded in 3D Space Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb This snippet illustrates how `fealpy.mesh.TriangleMesh` can represent a triangular mesh embedded in three-dimensional space. It shows examples of creating meshes from a torus surface or a unit sphere surface, and then plots them in a 3D projection. ```python import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from fealpy.mesh import TriangleMesh i = 1 if i == 0: mesh = TriangleMesh.from_torus_surface(5, 1, 30, 30) elif i == 1: mesh = TriangleMesh.from_unit_sphere_surface(refine=3) fig = plt.figure() axes = fig.add_subplot(111, projection='3d') mesh.add_plot(axes) plt.show() ``` -------------------------------- ### Clone Forked FEALPy Repository for Development Source: https://github.com/weihuayi/fealpy/blob/master/README.md Instructions for developers to clone their personal fork of the FEALPy repository from GitHub to their local machine, replacing `` with their GitHub username. ```bash git clone git@github.com:/fealpy.git ``` -------------------------------- ### Liquid Template: Check if Page Path Starts with Underscore Source: https://github.com/weihuayi/fealpy/blob/master/docs/_includes/snippets/is_collection.html This Liquid snippet extracts the first character of `include.page.path` and compares it to an underscore. It's commonly used in Jekyll or similar static site generators to identify special pages (e.g., drafts or internal pages) that might start with an underscore, controlling their visibility or processing. ```Liquid {%- assign _page_path_first_char = include.page.path | slice: 0, 1 -%}{%- if _page_path_first_char == '_' -%}{%- assign __return = true -%}{%- else -%}{%- assign __return = false -%}{%- endif -%} ``` -------------------------------- ### C++ Doxygen Single-line Comment Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-14-doxygen-manual.md Example of a single-line Doxygen comment in C++, suitable for concise descriptions. ```c++ /** 注释内容 */ ``` -------------------------------- ### C++ Doxygen Comment for Code Below Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-14-doxygen-manual.md Doxygen comments typically describe the code that follows them. This example shows a comment block for a function definition. ```c++ /** 两个整数相加 * */ int add(int a, int b) { return a+b; } ``` -------------------------------- ### Clone FEALPy Repository from GitHub Source: https://github.com/weihuayi/fealpy/blob/master/README.md Command to clone the FEALPy source code repository directly from GitHub. ```bash git clone https://github.com/weihuayi/fealpy.git ``` -------------------------------- ### Python Doxygen Simple Comment Block Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-14-doxygen-manual.md Example of a simple Doxygen comment block in Python using the `'''!` syntax, similar to docstrings but recognized by Doxygen. ```python '''! 注释内容''' ``` -------------------------------- ### CMake Configuration for fealpy Project Source: https://github.com/weihuayi/fealpy/blob/master/src/CMakeLists.txt This snippet demonstrates essential CMake commands for configuring a project. It includes finding the 'pybind11' package, which is marked as REQUIRED, and adding 'cgal' as a subdirectory. The 'detri2' subdirectory is commented out, suggesting it's either optional or temporarily disabled. ```CMake find_package(pybind11 REQUIRED) add_subdirectory(cgal) #add_subdirectory(detri2) ``` -------------------------------- ### Add User (Shell) Source: https://github.com/weihuayi/fealpy/blob/master/docs/_draft/ubuntu-skills.md This command is used to create a new user account on a Linux-like system. It interactively prompts for the new user's password and other account details such as full name, room number, work phone, home phone, and other information. The "sudo" prefix indicates that the command requires superuser privileges. ```Shell sudo adduser name ``` -------------------------------- ### C++ Doxygen Multi-line Comment Block Source: https://github.com/weihuayi/fealpy/blob/master/docs/_posts/2021-09-14-doxygen-manual.md Example of a standard multi-line Doxygen comment block in C++, typically used for detailed descriptions of files, classes, or functions. ```c++ /** 注释内容 * */ ``` -------------------------------- ### Get Edge to Node Adjacency in Triangle Mesh Source: https://github.com/weihuayi/fealpy/blob/master/docs/_docs/zh/mesh/tri-mesh.md This snippet demonstrates how to obtain the edge-to-node adjacency relationship using `mesh.ds.edge_to_node()`. The output shows for each edge, the IDs of its two endpoint nodes. ```python edge2node = mesh.ds.edge_to_node() ``` -------------------------------- ### Creating a Uniform Mesh in Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/docs/_layouts/none.html This snippet demonstrates how to initialize a uniform triangular mesh using the Fealpy library. It sets up a 2D domain and divides it into a specified number of cells along each axis, suitable for basic finite element simulations. ```Python from fealpy.mesh import UniformMesh2d # Define domain boundaries a = 0.0 b = 1.0 c = 0.0 d = 1.0 # Number of cells in each direction NX = 10 NY = 10 # Create a uniform triangular mesh mesh = UniformMesh2d([a, b, c, d], NX, NY) ``` -------------------------------- ### Initialize Triangle Mesh from Node and Cell Data Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh_beginner.ipynb Explains how to construct a new TriangleMesh instance directly from existing node coordinates and cell connectivity data. This method allows for creating a copy or reconstructing a mesh from its fundamental geometric and topological components. ```python mesh_copy = TriangleMesh(node, cell) ``` -------------------------------- ### Clone FEALPy Repository from Gitee Source: https://github.com/weihuayi/fealpy/blob/master/README.md Alternative command to clone the FEALPy source code repository from Gitee, useful if GitHub access is restricted. ```bash git clone https://gitee.com/whymath/fealpy ``` -------------------------------- ### Configure DETRI2 Project with CMake Source: https://github.com/weihuayi/fealpy/blob/master/src/detri2/CMakeLists.txt This CMake configuration script defines the DETRI2 project, sets its version, includes necessary directories for GMP, compiles a list of C++ source files into an executable named 'detri2', and links against the GMP and GMPXX libraries. ```CMake cmake_minimum_required (VERSION 2.6) project (DETRI2) # The version number. set (DETRI2_VERSION_MAJOR 1) set (DETRI2_VERSION_MINOR 5) set (DETRI2_PATCH_VERSION 0) set (DETRI2_VERSION "${DETRI2_MAJOR_VERSION}.${DETRI2_MINOR_VERSION}") #find_package(GMP REQUIRED) add_definitions(-DUSING_GMP) include_directories(/usr/local/include) link_directories(/usr/local/lib) #include_directories(/opt/local/include) #link_directories(/opt/local/lib) add_executable(detri2 detri2.cpp flips.cpp pred3d.cpp io.cpp sort.cpp delaunay.cpp constrained.cpp refine.cpp voronoi.cpp #meshadapt.cpp adapt.cpp metric.cpp main.cpp) target_link_libraries(detri2 gmp gmpxx) ``` -------------------------------- ### Get Cell to Node Adjacency in Triangle Mesh Source: https://github.com/weihuayi/fealpy/blob/master/docs/_docs/zh/mesh/tri-mesh.md This snippet demonstrates how to obtain the cell-to-node adjacency relationship using `mesh.ds.cell_to_node()`. The output shows for each cell, the three node IDs that form its vertices. ```python cell2node = mesh.ds.cell_to_node() #(NC,3),单元和节点的邻接关系,储存每个单元相邻的三个节点编号,实际也就是构成三角形单元的三个顶点编号 print('cell2node:\n',cell2node) ``` ```text cell2node: [[1 2 0] [3 0 2]] ``` -------------------------------- ### Generate and Plot 3D Edge Mesh in FEALPy Source: https://github.com/weihuayi/fealpy/blob/master/notebook/mesh.ipynb Demonstrates the creation of a 3D edge mesh, suitable for structures like beams or trusses, using EdgeMesh.from_tower(). The mesh is then visualized in a 3D Matplotlib plot. ```python import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from fealpy.mesh import EdgeMesh mesh = EdgeMesh.from_tower() fig = plt.figure() axes = fig.add_subplot(111, projection='3d') mesh.add_plot(axes) plt.show() ``` -------------------------------- ### Jekyll Site Configuration with Multi-Language Support Source: https://github.com/weihuayi/fealpy/blob/master/docs/_layouts/home.html This snippet defines the front matter for a Jekyll page, configuring multi-language titles, article display settings (like showing cover, excerpt, readmore, and info), and includes for pagination and a home script. It uses YAML for configuration and Liquid for includes. ```Jekyll/Liquid --- layout: articles titles: # @start locale config en : &EN Home en-GB : *EN en-US : *EN en-CA : *EN en-AU : *EN zh-Hans : &ZH_HANS 主页 zh : *ZH_HANS zh-CN : *ZH_HANS zh-SG : *ZH_HANS zh-Hant : &ZH_HANT 主頁 zh-TW : *ZH_HANT zh-HK : *ZH_HANT ko : &KO 홈 ko-KR : *KO fr : &FR Accueil fr-BE : *FR fr-CA : *FR fr-CH : *FR fr-FR : *FR fr-LU : *FR # @end locale config show_title: false articles: data_source: paginator.posts article_type: BlogPosting show_cover: false show_excerpt: true show_readmore: true show_info: true --- {%- include paginator.html -%} {%- include scripts/home.js -%} {{ content }} ``` -------------------------------- ### CMake: Build 'curve_intersections_test' with CGAL Source: https://github.com/weihuayi/fealpy/blob/master/exten/cgal/test/CMakeLists.txt Configures CMake to build the 'curve_intersections_test' executable from 'curve_intersections_test.cpp' and links it against CGAL's core and third-party libraries. This setup is typical for projects involving geometric computations. ```CMake add_executable(curve_intersections_test curve_intersections_test.cpp) target_link_libraries(curve_intersections_test ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) ``` -------------------------------- ### Set Up Upstream Remote for FEALPy Development Source: https://github.com/weihuayi/fealpy/blob/master/README.md Command to add the original `weihuayi/fealpy` repository as an 'upstream' remote, facilitating synchronization with the main project. ```bash git remote add upstream git@github.com:weihuayi/fealpy.git ``` -------------------------------- ### Get Cell to Edge Adjacency in Triangle Mesh Source: https://github.com/weihuayi/fealpy/blob/master/docs/_docs/zh/mesh/tri-mesh.md This snippet demonstrates how to obtain the cell-to-edge adjacency relationship using `mesh.ds.cell_to_edge()`. The output shows for each cell, the three edge IDs that form its boundaries, along with their local indices within the cell. ```python cell2edge = mesh.ds.cell_to_edge() # (NC, 3) #(NC,3),单元和边的邻接关系,储存每个单元相邻的三个边的编号,实际也为构成三角形三条边的编号 print('cell2edge:\n',cell2edge) ``` ```text cell2edge: [[1 0 3] [1 4 2]] ``` -------------------------------- ### Calculate Area of FealPy Mesh Cells Source: https://github.com/weihuayi/fealpy/blob/master/docs/_docs/zh/mesh/quad-mesh.md This snippet calculates the area of each cell in the mesh using `mesh.area()`. It returns an array where each element represents the area of a corresponding cell. The example output shows the areas for a mesh with four cells. ```python area = mesh.area() print('the area of mesh:', area) ``` -------------------------------- ### Define and Initialize a Taichi Field Source: https://github.com/weihuayi/fealpy/blob/master/notebook/taichi_backend.ipynb This code defines a 2D Taichi field named 'a' with integer data type and a shape of 10x3. It then fills all elements of the field with the value 10 and demonstrates how to get the number of dimensions of the field. ```python a = ti.field(dtype=ti.i32, shape=(10, 3)) N = 3 a.fill(10) len(a.shape) ``` -------------------------------- ### Find and Configure MOAB Library Paths Source: https://github.com/weihuayi/fealpy/blob/master/exten/CMakeLists.txt This snippet sets up the directories for the MOAB library and then attempts to find it. If MOAB is found, its include and link directories are added to the project, and a flag `HAVE_MOAB` is set to true; otherwise, a status message indicates its absence. ```CMake set(MOAB_DIR ${SIGMA_DIR}/lib) set(MOAB_LIBRARIES_DIR ${MOAB_DIR}) find_package(MOAB) if(MOAB_FOUND) include_directories(${MOAB_INCLUDE_DIRS}) link_directories(${MOAB_LIBRARIES_DIR}) message(STATUS "${MOAB_LIBRARIES}") set(HAVE_MOAB True) else() set(HAVE_MOAB False) message(STATUS "config package without MOAB!") endif() ``` -------------------------------- ### Liquid Template for Sidebar Navigation Rendering Source: https://github.com/weihuayi/fealpy/blob/master/docs/_includes/sidebar/toc.html This Liquid template processes navigation data to construct a sidebar menu. It checks for the presence of `page.sidebar.nav` and then iterates through the `site.data.navigation` data structure. For each navigation item, it renders the title and, if children exist, iterates through them, generating links. It uses `snippets/get-nav-url.html` to resolve URLs and compares the current page's URL to highlight the active navigation item. ```Liquid {%- if page.sidebar.nav -%} {%- assign _sidebar_nav = site.data.navigation[page.sidebar.nav] -%} {%- if _sidebar_nav -%} {%- for _item in _sidebar_nav -%}* {{ _item.title }} {%- if _item.children -%} {%- for _child in _item.children -%} {%- include snippets/get-nav-url.html path=_child.url -%} {%- assign _nav_url = __return -%} {%- include snippets/get-nav-url.html path=page.url -%} {%- assign _page_url = __return -%} {%- if _nav_url == _page_url -%}* [{{ _child.title }}]({{ _nav_url }}) {%- else -%}* [{{ _child.title }}]({{ _nav_url }}) {%- endif -%} {%- endfor -%} {%- endif -%} {%- endfor -%} {%- endif -%} {%- endif -%} ``` -------------------------------- ### Fealpy Implementation of Distmesh 2D Algorithm Source: https://github.com/weihuayi/fealpy/blob/master/docs/_docs/zh/mesh/mesh-factory.md This section highlights the `distmesh2d` functionality, which is a partial implementation of the popular Matlab mesh generator within Fealpy. The `MeshFactory` module provides examples, such as `unitcirclemesh`, that leverage this underlying algorithm for mesh generation. ```python from fealpy.mesh import MeshFactory as mf import numpy as np import matplotlib.pyplot as plt mesh = mf.unitcirclemesh() ``` -------------------------------- ### Generate and Visualize 1D Interval Mesh with Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/tutorial/Mesh_practice.ipynb This Python snippet initializes a 1D interval mesh with specified nodes and cells using `fealpy.mesh.IntervalMesh`. It then visualizes the mesh, including node and cell indices, using `matplotlib.pyplot`. The commented-out section indicates potential further steps for setting up a Lagrange finite element space and assembling stiffness and mass matrices. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.mesh import IntervalMesh from fealpy.functionspace import LagrangeFiniteElementSpace NN = 6 #节点数 NC = 5 #单元数 node = np.linspace(0, 1, NN) node = node.reshape((NN, 1)) cell = np.zeros((NC, 2), dtype=np.int_) for i in range(NC): cell[i, 0] = i cell[i, 1] = i+1 mesh = IntervalMesh(node, cell) fig = plt.figure() axes = fig.gca() mesh.add_plot(axes) mesh.find_node(axes, fontsize=10, fontcolor='r', showindex=True, markersize=10) mesh.find_cell(axes, fontsize=10, fontcolor='b', showindex=True, markersize=15) plt.show # space = LagrangeFiniteElementSpace(mesh, 1) # ldof = space.number_of_local_dofs() # gdof = space.number_of_global_dofs() # A = space.stiff_matrix() # M = space.mass_matrix() ``` -------------------------------- ### Create and Visualize Fealpy Triangle Mesh Source: https://github.com/weihuayi/fealpy/blob/master/tutorial/notebook/mesh.ipynb This Python snippet initializes a `TriangleMesh` object with specified nodes and cells using `fealpy`'s backend. It then uses `matplotlib` to plot the mesh and highlight its nodes, edges, and cells with their respective indices, demonstrating basic mesh visualization capabilities. ```python import numpy as np import matplotlib.pyplot as plt from fealpy.backend import backend_manager as bm bm.set_backend('numpy') from fealpy.mesh import TriangleMesh node = bm.array([ [0, 0], # 0 [1, 0], # 1 [1, 1], # 2 [0, 1]], # 3 dtype=bm.float64) cell = bm.array([ [1, 2, 0], # 0 [3, 0, 2]], # 1 dtype=bm.int32) mesh = TriangleMesh(node, cell) fig, axes = plt.subplots() mesh.add_plot(axes, cellcolor='g') mesh.find_node(axes, showindex=True, color='r', marker='o', fontsize=15, fontcolor='r') mesh.find_edge(axes, showindex=True, color='b', marker='v', fontsize=20, fontcolor='b') mesh.find_cell(axes, showindex=True, color='k', marker='s', fontsize=25, fontcolor='k') plt.show() ``` -------------------------------- ### Get Node-to-Node Adjacency Matrix in Fealpy Source: https://github.com/weihuayi/fealpy/blob/master/docs/_docs/zh/mesh/tri-mesh.md Retrieves a sparse boolean matrix indicating whether two nodes are adjacent. The matrix has dimensions (NN, NN), where NN is the number of nodes. A value of True at (i, j) means node i and node j are adjacent. ```python node2node = mesh.ds.node_to_node() # sparse, (NN, NN) # 稀疏矩阵,(NN,NN),判断某两个节点是否相邻,若是则对应位置为True,否则为False ``` -------------------------------- ### Fealpy LagrangeFiniteElementSpace Class API Documentation Source: https://github.com/weihuayi/fealpy/blob/master/docs/_layouts/none.html API documentation for the `LagrangeFiniteElementSpace` class, which defines the finite element function space based on Lagrange polynomials. This class is crucial for constructing basis functions and assembling system matrices. ```APIDOC class fealpy.functionspace.LagrangeFiniteElementSpace: """Finite element space based on Lagrange polynomials.""" __init__(self, mesh: fealpy.mesh.Mesh, p: int = 1) mesh: fealpy.mesh.Mesh The mesh object on which the function space is defined. p: int The degree of the Lagrange polynomial (default is 1 for linear elements). properties: dof: fealpy.functionspace.Dof Degree of freedom (DOF) manager for the space. basis_type: str Type of basis functions ('Lagrange'). mesh: fealpy.mesh.Mesh The associated mesh object. methods: stiff_matrix() -> scipy.sparse.csr_matrix Assembles the stiffness matrix for the given function space. Returns: scipy.sparse.csr_matrix The global stiffness matrix. source_vector(f: Callable) -> numpy.ndarray Assembles the load vector from a given source function f. f: Callable A callable function representing the source term. Returns: numpy.ndarray The global load vector. ```