Gehan Zheng's blog 2025-01-03T13:37:40.581Z https://grahamzen.github.io/ Gehan Zheng Hexo 使用图着色(graph coloring)加速Gauss-Seidel迭代 https://grahamzen.github.io/2025/01/02/graph-coloring/ 2025-01-02T11:41:24.000Z 2025-01-03T13:37:40.581Z <p>Jacobi和Gauss-Seidel都是用于求解线性方程组的迭代方法。Jacobi迭代很容易实现在GPU上并行的版本,但是收敛速度很慢甚至有可能发散。Gauss-Seidel迭代并不能用类似Jacobi的方法并行,因为它是一个依赖于顺序的迭代方法。但是Gauss-Seidel迭代的收敛速度比Jacobi快很多。因此出现了用图论的图着色算法加速Gauss-Seidel迭代的研究。</p> Hermite Interpolation https://grahamzen.github.io/2024/10/30/hermite-interpolation/ 2024-10-30T04:52:19.000Z 2025-01-02T11:47:42.179Z <h2 id="hermite插值多项式">Hermite插值多项式</h2> <p>Hermite插值是一种插值方法,可以通过给定的点和导数值构造插值多项式。给定点<span class="math inline">\((x_0,y_0),(x_1,y_1),...,(x_n,y_n)\)</span>和导数值<span class="math inline">\(y&#39;_0,y&#39;_1,...,y&#39;_n\)</span>,可以构造插值多项式。本文介绍如何使用Newton差商生成Hermite插值多项式。</p> Point triangle distance https://grahamzen.github.io/2024/09/15/point-triangle-distance/ 2024-09-15T06:17:09.000Z 2025-01-02T11:47:34.021Z <h2 id="介绍">介绍</h2> <p>该文章中的c++代码参考了<a href="https://github.com/ipc-sim/ipc-toolkit">ipc-toolkit</a>的实现。</p> <p>点到三角形的距离可以用如下定义:</p> <p><span class="math display">\[ \begin{aligned} \text{distance}(\vec{\mathbf{x_p}}, \vec{\mathbf{x_t}_1}, \vec{\mathbf{x_t}_2}, \vec{\mathbf{x_t}_3}) &amp;= \min_{\beta_1, \beta_2} \left\| \vec{\mathbf{x_p}} - ( \vec{\mathbf{x_t}_1} + \beta_1 (\vec{\mathbf{x_t}_2} - \vec{\mathbf{x_t}_1}) + \beta_2 (\vec{\mathbf{x_t}_3} - \vec{\mathbf{x_t}_1}) ) \right\| \\&amp;s.t. \beta_1 \geq 0, \beta_2 \geq 0, \beta_1 + \beta_2 \leq 1 \end{aligned} \]</span></p> <p>这是一个分断连续的函数,实际计算时可以根据点和三角形的位置关系分以下几种情况讨论,首先要将点投影到三角形所在的平面上:</p> <ol type="1"> <li>投影后,点在三角形内部,此时距离为点到三角形所在平面的距离。</li> <li>投影后,点在三角形的某个边朝外的半平面且投影在边上的点在边上,此时距离为点到边的距离。</li> <li>其他情况,此时距离为点到三角形的三个顶点的最小距离。</li> </ol> Stress hessian computation in FEM https://grahamzen.github.io/2024/08/08/stress-hessian/ 2024-08-08T10:05:16.000Z 2025-01-02T11:53:30.855Z <h2 id="介绍">介绍</h2> <p>在进行软体模拟时,如果使用牛顿法计算最优的下降方向,需要计算能量密度函数<span class="math inline">\(\Psi\)</span>关于位置<span class="math inline">\(\vec {\mathbf{x}}\)</span> 的Hessian矩阵,即<span class="math inline">\(\frac{\partial^2 \Psi}{\partial \vec {\mathbf{x}}^2}\)</span>。其中<span class="math inline">\(\vec {\mathbf{x}}\)</span>是一个四面体的四个顶点的位置。</p> <p><span class="math display">\[ \begin{equation} \frac{\partial^2 \Psi}{\partial {\mathbf{x}^2}} = \text{vec}(\frac{\partial F}{\partial {\mathbf{x}}})^T \text{vec}(\frac{\partial P}{\partial F}) \text{vec}(\frac{\partial F}{\partial {\mathbf{x}}}) \end{equation} \]</span></p> Force computation in FEM https://grahamzen.github.io/2024/05/02/FEM-gradient/ 2024-05-02T14:43:25.000Z 2025-01-02T11:47:34.062Z <h2 id="证明1">证明1</h2> <p>首先,已知</p> <p><span class="math display">\[ \vec {\mathbf{x}} = \begin{bmatrix} \vec x_1 &amp; \vec x_2 &amp; \vec x_3 \end{bmatrix}\\ D_s = \begin{bmatrix} \vec x_1-\vec x_4 &amp; \vec x_2-\vec x_4 &amp; \vec x_3-\vec x_4 \end{bmatrix}\\ \begin{aligned} &amp;\frac{\partial (D_s)_{kl}}{\partial \vec {\mathbf{x}_{ij}}} e_i\otimes e_j\otimes e_k\otimes e_l\\ &amp;=\frac{\partial \vec {\mathbf{x}}_{kl}}{\partial \vec {\mathbf{x}}_{ij}} e_i\otimes e_j\otimes e_k\otimes e_l\\ &amp;= \delta_{ik}\delta_{jl} e_i\otimes e_j\otimes e_k\otimes e_l \end{aligned} \]</span> 这里把<span class="math inline">\(\vec {\mathbf{x}}\)</span>后三列写成一个3x3的矩阵。<span class="math inline">\(D_m^{-1}\)</span>的分量表示为<span class="math inline">\(d_{mn}\)</span>,<span class="math inline">\(P\)</span>的分量表示为<span class="math inline">\(P_{rs}\)</span>,则能量密度函数<span class="math inline">\(\Psi\)</span>关于位置<span class="math inline">\(\vec {\mathbf{x}}\)</span> 的梯度为:</p> SVD https://grahamzen.github.io/2023/12/24/Applied%20Numerical%20Algorithms/SVD/ 2023-12-24T04:29:22.000Z 2024-01-11T23:49:22.000Z <h2 id="understading-the-geometry-of-ain-mathbbrmtimes-n">Understading the Geometry of <span class="math inline">\(A\in \mathbb{R}^{m\times n}\)</span></h2> <p><span class="math display">\[ A\in \mathbb{R}^{m\times n} \\ x\in \mathbb{R}^n \mapsto Ax \in \mathbb{R}^m \]</span></p> QR iteration https://grahamzen.github.io/2023/12/23/Applied%20Numerical%20Algorithms/QR-iteration/ 2023-12-23T05:14:20.000Z 2023-12-24T05:58:07.000Z <p>Assumption: <span class="math inline">\(A \in \mathbb{R}^{n \times n}\)</span> is symmetric, no repeated eigenvalues <span class="math inline">\(\lambda\)</span>s.</p> Eigenvalue iteration, deflation https://grahamzen.github.io/2023/12/23/Applied%20Numerical%20Algorithms/Eigenvalue-iteration-deflation/ 2023-12-23T05:14:17.000Z 2023-12-23T23:15:31.000Z <h2 id="two-basic-properties">Two basic Properties</h2> <p><strong>Lemma</strong>: Every matrix <span class="math inline">\(A \in \mathbb{R}^{n \times n}\)</span> has at least one (complex) eigenvalue.</p> Applications of eigenvectors https://grahamzen.github.io/2023/12/22/Applied%20Numerical%20Algorithms/Applications-of-eigenvectors/ 2023-12-22T05:14:13.000Z 2023-12-23T23:06:50.000Z <p>很多时候需要把已有问题转化为特征值问题。</p> <ol type="1"> <li>有一个对称矩阵(有时候是对称半正定矩阵),我们想要找一个方便的基。</li> <li>具体的优化问题。</li> </ol> Column Space QR https://grahamzen.github.io/2023/12/21/Applied%20Numerical%20Algorithms/QR-factorization/ 2023-12-21T02:46:03.000Z 2023-12-22T03:13:23.000Z <h2 id="high-level-idea">High-Level Idea</h2> <h3 id="why-qr">Why QR?</h3> <p><span class="math display">\[ \begin{aligned} cond A^T A &amp;= ||A^T A|| \cdot ||(A^T A)^{-1}||\\ &amp;\approx ||A^T|| \cdot ||A|| \cdot ||A^{-1}|| \cdot ||A^{-T}|| &amp;= cond A^2 \end{aligned} \]</span></p> <p>为了避免计算<span class="math inline">\(A^T A\)</span>,我们可以使用QR分解。</p> Projective Dynamics 的local step实现推导 https://grahamzen.github.io/2023/12/20/local-step-inference/ 2023-12-20T08:08:06.000Z 2025-01-02T11:47:34.062Z <h2 id="介绍">介绍</h2> <p><a href="https://dl.acm.org/doi/10.1145/2601097.2601116">Projective Dynamics</a>是一种用于软体模拟的方法,算法分为local step和global step两个部分。其中local step可以对于每个四面体约束并行计算,global step只需要求解一个线性方程组,而他的矩阵非常特殊,是一个Gram矩阵,因此可以预先用Cholesky分解。本文主要介绍local step的实现的推导过程。用Corotated strain model的CUDA的实现作为例子。</p> Condition number for linear systems https://grahamzen.github.io/2023/12/20/Applied%20Numerical%20Algorithms/Condition-number-for-linear-systems/ 2023-12-20T04:06:16.000Z 2023-12-20T18:55:11.000Z <h2 id="sensitivity-and-conditioning">Sensitivity and Conditioning</h2> <p>Gaussian elimination works in theory, but what about floating point precision?</p> <p>How much can we trust <span class="math inline">\(x_0\)</span> if <span class="math inline">\(0&lt;||Ax_0 - b||_2 \ll 1\)</span>(backwards error)?</p> Cholesky factorization, sparse matrices https://grahamzen.github.io/2023/12/17/Applied%20Numerical%20Algorithms/Cholesky-factorization-sparse-matrices/ 2023-12-17T10:23:19.000Z 2023-12-20T18:55:43.000Z <h2 id="structured-linear-systems">Structured Linear Systems</h2> <p>Gaussian elimination and/or LU can solve all the example problems above. But these systems can have special properties that make them easier or stabler to solve.</p> <p>Today's example: Positive definite, sparsity.</p> Linear Systems and LU https://grahamzen.github.io/2023/12/17/Applied%20Numerical%20Algorithms/Linear-Systems-and-LU/ 2023-12-17T04:50:28.000Z 2023-12-20T18:56:55.000Z <h2 id="linear-systems">Linear Systems</h2> <p><span class="math display">\[ \begin{aligned} Ax &amp;= b \\ A &amp;\in \mathbb{R}^{n \times n} \\ x &amp;\in \mathbb{R}^n \\ b &amp;\in \mathbb{R}^n \end{aligned} \]</span></p> Introduction, number systems, measuring error https://grahamzen.github.io/2023/12/16/Applied%20Numerical%20Algorithms/Introduction-number-systems-measuring-error/ 2023-12-16T07:47:52.000Z 2023-12-20T17:31:00.000Z <p>Mathematically correct != numerically sound. Using Tolerance: <figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">double</span> x = <span class="number">1.0</span>;</span><br><span class="line"><span class="type">double</span> y = x / <span class="number">3.0</span>;</span><br><span class="line"><span class="keyword">if</span>(<span class="built_in">fabs</span>(x-y*<span class="number">3.0</span>) &lt; numeric_limits&lt;<span class="type">double</span>&gt;::<span class="built_in">epsilon</span>())&#123;</span><br><span class="line"> cout &lt;&lt; <span class="string">&quot;They are equal&quot;</span> &lt;&lt; endl;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line"> cout &lt;&lt; <span class="string">&quot;They are not equal&quot;</span> &lt;&lt; endl;</span><br></pre></td></tr></table></figure></p> 对LLVM的Pass进行调试的vscode配置 https://grahamzen.github.io/2023/11/20/llvm-vscode/ 2023-11-20T04:26:12.000Z 2023-11-20T17:42:30.000Z <h2 id="文件夹结构">文件夹结构</h2> <p>安装LLVM的过程省去,假设当前目录下有:</p> <ul> <li>CMakeLists.txt文件;编译pass</li> <li>include文件夹:pass的头文件</li> <li>src文件夹;pass的源码</li> <li>test文件夹:用于静态分析pass的测试代码(.c文件)</li> </ul> 张量 https://grahamzen.github.io/2023/11/19/tensor/ 2023-11-19T15:32:17.000Z 2023-12-17T23:09:58.000Z <p>对于三维空间中的各向同性材料,弹性模量张量(Elastic Modulus Tensor)可以视为一个<span class="math inline">\(3 \times 3\)</span>矩阵,其中每个元素本身又是一个 <span class="math inline">\(3 \times 3\)</span> 的矩阵。这样的表示反映了张量的四阶本质,即它有四个索引。</p> GAMES103:刚体模拟笔记 https://grahamzen.github.io/2023/04/09/rigidBody-note/ 2023-04-09T09:50:21.000Z 2025-01-02T11:47:33.931Z <h1 id="math">2 Math</h1> <h2 id="tetrahedral-volume">Tetrahedral Volume</h2> <figure> <img src="../../../../../images/GAMES103/1681077071804.png" alt="1681077071804" /> <figcaption aria-hidden="true">1681077071804</figcaption> </figure> VkPresentModeKHR-呈现模式 https://grahamzen.github.io/2023/03/07/VkPresentModeKHR/ 2023-03-07T06:15:11.000Z 2025-01-02T11:47:33.930Z <p>在构建交换链 <code>vk::SwapchainCreateInfoKHR</code>时,有一个设置是 <code>VkPresentModeKHR</code>。根据官方手册<a href="https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPresentModeKHR.html">VkPresentModeKHR(3) Manual Page</a>,呈现模式有6种。</p> <h2 id="相关术语">相关术语</h2> <h3 id="垂直空白间隙vertical-blank-interval">垂直空白间隙(Vertical Blank Interval)</h3> Bspline https://grahamzen.github.io/2023/03/04/BSpline/ 2023-03-04T14:13:56.000Z 2025-01-02T11:47:42.179Z <h2 id="bspline上任意点的计算公式">Bspline上任意点的计算公式</h2>