<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://e6.ijs.si/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NikaMlinaric</id>
		<title>Medusa: Coordinate Free Mehless Method implementation - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://e6.ijs.si/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NikaMlinaric"/>
		<link rel="alternate" type="text/html" href="https://e6.ijs.si/medusa/wiki/index.php?title=Special:Contributions/NikaMlinaric"/>
		<updated>2026-06-29T12:08:18Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.1</generator>

	<entry>
		<id>https://e6.ijs.si/medusa/wiki/index.php?title=Computation_of_shape_functions&amp;diff=3190</id>
		<title>Computation of shape functions</title>
		<link rel="alternate" type="text/html" href="https://e6.ijs.si/medusa/wiki/index.php?title=Computation_of_shape_functions&amp;diff=3190"/>
				<updated>2022-03-03T09:32:59Z</updated>
		
		<summary type="html">&lt;p&gt;NikaMlinaric: Added missing $\mathcal{L}$ in the 3rd equation of Derivation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Shape functions, often called stencil weights, are functionals, approximating linear partial differential operators at a chosen point. &lt;br /&gt;
A shape function $\b{\chi}_{\mathcal{L}} (\vec{p})$ for a linear parial differential operator $\mathcal{L}$&lt;br /&gt;
in a point $p$ is a vector of stencil weights, such that&lt;br /&gt;
\[&lt;br /&gt;
(\mathcal{L} u)(\vec{p}) \approx \b{\chi}_{\mathcal{L}}(\vec{p})^\T \b{u},&lt;br /&gt;
\]&lt;br /&gt;
where $\b{u}$ is a vector of function values $u(x_i)$ evaluated in the support of $\vec{p}$.&lt;br /&gt;
For usage examples see the section on [[Meshless Local Strong Form Method (MLSM)]] or some [[ Poisson's equation | examples ]].&lt;br /&gt;
&lt;br /&gt;
For computation of shape functions augmented with monomials, see the [[ Radial basis function-generated finite differences (RBF-FD) ]].&lt;br /&gt;
&lt;br /&gt;
== Derivation ==&lt;br /&gt;
Let $\mathcal{L}$ be a linear partial differential operator.&lt;br /&gt;
We wish to approximate $(\mathcal{L}u)(\vec{p})$ using only values of $u$ in support of $p$. To do so, we construct a &lt;br /&gt;
WLS approximation (see [[Weighted Least Squares (WLS)]]) and compute the coefficients $\b{\alpha}$, such that $\hat{u}(\vec{p}) = \b{b}(\vec{p})^\T \b{\alpha}$.&lt;br /&gt;
The coefficients are computed by solving a least-squares system $WB \b{\alpha} = W\b{u}$, (see [[Solving overdetermined systems]])&lt;br /&gt;
writing&lt;br /&gt;
\[ \b{\alpha} = (B^\T W^2 B^\T)^{-1} B^\T W^2 \b{u}. \]&lt;br /&gt;
Writing down the approximation function $\hat{u}$ we get&lt;br /&gt;
\[&lt;br /&gt;
\hat u (\vec{p}) = \b{b}(\vec{p})^\T \b{\alpha} = \b{b}(\vec{p})^\T (WB)^+W\b{u} &lt;br /&gt;
\]&lt;br /&gt;
and applying operator $\mathcal{L}$ we get &lt;br /&gt;
\[&lt;br /&gt;
    \mathcal{L} \hat u (\vec{p}) = (\mathcal{L}\b{b})(\vec{p})^\T \b{\alpha} = &lt;br /&gt;
(\mathcal{L}\b{b})(\vec{p})^\T (B^\T W^2 B)^{-1} B^\T W^2 \b{u} &lt;br /&gt;
= \b{\chi}_{\mathcal{L}}(\vec{p})^\T \b{u}&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
Depending on what data we have available, we can either compute $\b \alpha$ and obtain a continuous approximation $\hat{u}$,&lt;br /&gt;
to which $\mathcal{L}$ can be applied at any point, or, if function values $\b u$ are unknown, we can choose to compute&lt;br /&gt;
$\b \chi_{\mathcal{L}}$ at a point $\vec p$ and approximate the operator for ''any'' set of function values. &lt;br /&gt;
the operator $\mathcal{L}$ at $\vec p$ is approximated as &lt;br /&gt;
\[&lt;br /&gt;
  (\mathcal{L}u)(\vec{p}) \approx (\mathcal{L} \hat{u})(p) = \b{\chi}_{\mathcal{L}}(\vec{p})^\T \b{u}.&lt;br /&gt;
\]&lt;br /&gt;
Vector $\b{\chi}$ is a vector of stencil weights, also called a ''shape function''. The name comes historically from FEM, and it incorporates the idea of being able to take all the information&lt;br /&gt;
about shape of the local domain and choice of approximation and store it in a single vector, being able to approximate&lt;br /&gt;
a function value from given support values $\b{u}$ with a single dot product. For any values $\b{u}$, value $\b{\chi}(p) \b{u}$&lt;br /&gt;
gives us the approximation of $(\mathcal{L}u)(\vec{p})$.&lt;br /&gt;
Mathematically speaking, $\b{\chi}(\vec{p})$ is a Riesz representation of a functional, $\b{\chi}(\vec{p})\colon \R^n \to \R$, mapping $n$-tuples of known function values to&lt;br /&gt;
approximations of $\mathcal{L}$ in point $\vec{p}$.&lt;br /&gt;
&lt;br /&gt;
For example, take a $1$-dimensional case for approximation of derivatives with weight equal to $1$ and $n=m=3$, with equally spaced support values at distances $h$.&lt;br /&gt;
We wish to approximate $u''$ in the middle support point, just by making a weighted sum of the values, something like the finite difference&lt;br /&gt;
\[ u'' \approx \frac{u_1 - 2u_2 + u_3}{h^2}. \]&lt;br /&gt;
This is exactly the same formula as we would have come to by computing $\b{\chi}$, except that our approach is a lot more general. But one should think about&lt;br /&gt;
$\b{\chi}$ as one would about the finite difference scheme, it is a rule, telling us how to compute the derivative.&lt;br /&gt;
\[ u''(s_2) \approx \underbrace{\begin{bmatrix} \frac{1}{h^2} &amp;amp; \frac{-2}{h^2} &amp;amp; \frac{1}{h^2} \end{bmatrix}}_{\b{\chi}^\T} \begin{bmatrix}u_1 \\ u_2 \\ u_3 \end{bmatrix}  \]&lt;br /&gt;
&lt;br /&gt;
The fact that $\b{\chi}$ is independent of the function values $\b{u}$ but depend only on domain geometry means that&lt;br /&gt;
'''we can just compute the shape functions $\b{\chi}$ for points of interest and then approximate any linear operator&lt;br /&gt;
of any function, given its values, very fast, using only a single dot product.'''&lt;br /&gt;
&lt;br /&gt;
== Special case when $B$ is square and invertible ==&lt;br /&gt;
The expression&lt;br /&gt;
\[ \b{\chi}_{\mathcal{L}}(\vec{p})^\T = (\mathcal{L}\b{b})(\vec{p})^\T (B^\T W^2 B)^{-1} B^\T W^2 \]&lt;br /&gt;
can be simplified to &lt;br /&gt;
\[&lt;br /&gt;
  \b \chi_{\mathcal{L}}(\vec{p})^\T = (\mathcal{L}\b{b})(\vec{p})^\T B^{-1}.&lt;br /&gt;
\]&lt;br /&gt;
&lt;br /&gt;
This gives the approximation as $(\mathcal{L} \hat{u})(p) = (\mathcal{L}\b{b})(\vec{p})^\T B^{-1} \b u$. &lt;br /&gt;
&lt;br /&gt;
Coefficients $\b \alpha$ are the solutions of $B\b \alpha = \b u$. Shape function $\b{\chi}_{\mathcal{L}}(\vec{p})$ is defined as&lt;br /&gt;
$$ &lt;br /&gt;
\b{\chi}_{\mathcal{L}}(\vec{p})^\T = (\mathcal{L}\b{b})(\vec{p})^\T B^{-1},&lt;br /&gt;
$$&lt;br /&gt;
which can be rewritten as a solution of &lt;br /&gt;
$$ B^\T \b{\chi}_{\mathcal{L}}(\vec{p}) =  (\mathcal{L}\b{b})(\vec{p}). $$&lt;br /&gt;
&lt;br /&gt;
This formulation is more suitable for numerical solving and also has a deeper interpretation, as presented in the next section.&lt;br /&gt;
&lt;br /&gt;
== Another view on derivation of shape functions ==&lt;br /&gt;
Solving the system $B^\T \b{\chi}_{\mathcal{L}} (\vec{p})^\T = (\mathcal{L}\b{b})(\vec p)$ can be interpreted as using the method of undetermined coefficients.&lt;br /&gt;
&lt;br /&gt;
We wish to find such a combination of function values evaluated in support points $\vec s_i$ that approximates the value of an operator $(\mathcal{L}u)(\vec p)$, i.e., we are looking for coefficients $\chi_{\mathcal{L}, i}$, such that&lt;br /&gt;
\[ \sum_{i=1}^n \chi_{\mathcal{L}, i} u_i \approx (\mathcal{L}u)(p). \]&lt;br /&gt;
&lt;br /&gt;
We require that $\chi_{\mathcal{L}, i}$ be such, that above approximations holds for a certain space of functions, spanned by the basis $\{b_j\}_{j=1}^m$.&lt;br /&gt;
By choosing the basis functions $b_j$ we decide for which functions the aproximation $\b{\chi}_{\mathcal{L}, \vec{p}} \b{u} \approx (\mathcal{L}u)(\vec p)$ should be exact and we write the equations &lt;br /&gt;
$\sum_{i=1}^n \chi_{\mathcal{L}, i} b_j(\vec s_i) = (\mathcal{L}b_j)(\vec p)$ in a system:&lt;br /&gt;
\[&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  b_1(\vec s_1) &amp;amp; \cdots &amp;amp; b_1(\vec s_n) \\&lt;br /&gt;
  \vdots &amp;amp; \ddots &amp;amp; \vdots \\&lt;br /&gt;
  b_m(\vec s_1) &amp;amp; \cdots &amp;amp; b_m(\vec s_n) \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
 \chi_{\mathcal{L}, 1} \\ \vdots \\ \chi_{\mathcal{L}, n}&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
=&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  (\mathcal{L} b_1)(\vec{p}) \\ \vdots \\ (\mathcal{L} b_m)(\vec{p})&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\]&lt;br /&gt;
Note that the matrix above is precisely the transpose of the matrix $B$ from the [[Weighted Least Squares (WLS) ]] approximation. In this sense, the computation of &lt;br /&gt;
shape functions is dual to computation of basis coefficients. The system is written in matrix form as $B^\T \b{\chi}_{\mathcal{L}} (\vec{p})^\T = (\mathcal{L}\b{b})(\vec p)$. &lt;br /&gt;
&lt;br /&gt;
For $n=m$ case as in the previous section, the solution is the sought shape function $\b{\chi}_{\mathcal L}$.&lt;br /&gt;
&lt;br /&gt;
If we do not specify enough functions $b_j$, the system above is underdetermined.&lt;br /&gt;
A common solution is to minimize the weighted norm of $\b \chi_{\mathcal L}$.&lt;br /&gt;
This gives us a minimization problem&lt;br /&gt;
$$&lt;br /&gt;
 \min_{\b \chi_{\mathcal L}} \sum_{i=1}^n (\chi_{\mathcal{L}, i}/w_i)^2, \text{ such that } B^\T \b{\chi}_{\mathcal{L}} (\vec{p})^\T = (\mathcal{L}\b{b})(\vec p).&lt;br /&gt;
$$&lt;br /&gt;
If the central weights are bigger, this also forces the central coefficients to be larger.&lt;br /&gt;
&lt;br /&gt;
Using the solution derived in [[Solving underdetermined systems]] and substituting inverse weights $W = W^{-1}$ and matrix $A = B^\T$, we get the solution&lt;br /&gt;
$$&lt;br /&gt;
\b{\chi}_{\mathcal{L}} (\vec{p}) = (W^{-1})^{-2} (B^\T)^\T (B^\T (W^{-1})^{-2}(B^\T)^\T)^{-1} (\mathcal{L}\b{b})(\vec p) = W^2 B (B^\T W^2 B)^{-1} (\mathcal{L}\b{b})(\vec p).&lt;br /&gt;
$$&lt;br /&gt;
After transposing, we get&lt;br /&gt;
$$&lt;br /&gt;
\b{\chi}_{\mathcal{L}} (\vec{p})^\T = (\mathcal{L}\b{b})(\vec p)^\T (B^\T W^2 B)^{-1} B^\T W^2,&lt;br /&gt;
$$&lt;br /&gt;
which is exactly the same formula as derived using [[ Weighted Least Squares (WLS) ]] approximation.&lt;br /&gt;
&lt;br /&gt;
Just as we get the same stencil weights using interpolation and the method of undetermined coefficients, we get the same result using &lt;br /&gt;
WLS approximation or weighted norm minimization of shape functions.&lt;br /&gt;
&lt;br /&gt;
== Numerical calculation of the shape functions ==&lt;br /&gt;
Numerically cheaper and more stable way is to translate the problem of inverting the matrix to solving a linear system of equations.&lt;br /&gt;
The alternative view above is useful in this aspect.&lt;br /&gt;
&lt;br /&gt;
=== Invertible $B$ ===&lt;br /&gt;
&lt;br /&gt;
If $B$ is invertible, then $\b{\chi}_{\mathcal{L}}(\vec{p})$ can be thought as a solution of a system $B^\T\b{\chi}_{\mathcal{L}}(\vec{p}) = (\mathcal{L}\b{b})(\vec p)$, which can be solved using LU or Cholesky decomposition for example.&lt;br /&gt;
For more on this, see [[Solving linear systems]].&lt;br /&gt;
&lt;br /&gt;
=== General case ===&lt;br /&gt;
In general, the system $B^\T\b{\chi}_{\mathcal{L}}(\vec{p}) = (\mathcal{L}\b{b})(\vec p)$ is underdetermined and must be solved in the least-weighted-norm sense.&lt;br /&gt;
This means solving the underdetermined system $B^\T W y =  (\mathcal{L}\b{b})(\vec p)$ and computing $\b{\chi}_{\mathcal{L}}(\vec{p}) = Wy$.&lt;br /&gt;
For more details on this, see [[Solving underdetermined systems]]. &lt;br /&gt;
&lt;br /&gt;
Depending on our knowledge of the &lt;br /&gt;
problem, we can use Cholesky ($B^\T W$ is positive definite), $LDL^\T$ if it is symmetric, $LU$ for a general square matrix, $QR$ for full rank overdetermined system and SVD for a general system.&lt;br /&gt;
&lt;br /&gt;
If more shapes need to be calculated using the same matrix $B^\T W$ and only different right hand sides (as is often the case, if shapes for more than one operator are computed), &lt;br /&gt;
it can be done efficiently by storing the decomposition of $B^\T W$.&lt;br /&gt;
&lt;br /&gt;
== Linearity and reduction to only computing the shapes of the operator space basis ==&lt;br /&gt;
Observe that the expression for the shape functions&lt;br /&gt;
\[ \b{\chi}_{\mathcal{L}}(\vec{p}) = (\mathcal{L}\b{b})(\vec{p})^\T (WB)^+W \]&lt;br /&gt;
is linear in $\mathcal{L}$. This follows from the fact that if $\mathcal{L} = \mathcal{L}_1 + \mathcal{L}_2$, the vector of&lt;br /&gt;
derivative values $(\mathcal{L}\b{b})(\vec{p}) = ((\mathcal{L}_1 + \mathcal{L}_2)\b{b})(\vec{p}) = &lt;br /&gt;
 (\mathcal{L}_1\b{b} + \mathcal{L}_2\b{b})(\vec{p}) =  (\mathcal{L}_1\b{b})(\vec p) +  (\mathcal{L}_2\b{b})(\vec p)$ &lt;br /&gt;
and consequently&lt;br /&gt;
$$\b{\chi}_{\mathcal{L}}(\vec{p}) = \b{\chi}_{\mathcal{L}_1}(\vec{p}) + \b{\chi}_{\mathcal{L}_2}(\vec{p}).$$&lt;br /&gt;
&lt;br /&gt;
Say that your equation constitutes of operators up to a certain $k$-th order.&lt;br /&gt;
Then it is sufficient to compute only shape functions for the basis of that operator space, namely&lt;br /&gt;
\[&lt;br /&gt;
\{\b{\chi}_{\frac{\partial}{\partial x^\alpha}, p}, 1 \leq |\alpha| \leq k \}, \text{ where } \frac{\partial}{\partial x^\alpha} = \frac{\partial^{|\alpha|}}{\partial x_1^{\alpha_1}\cdots \partial x_d^{\alpha_d}} \text{ and } |\alpha| = \sum_{i=1}^d \alpha_i.&lt;br /&gt;
\]&lt;br /&gt;
Having the shape functions $\b{\chi}_{\frac{\partial}{\partial x^\alpha}, p}$ available, we write $\mathcal{L}$ in the above basis in point $p$, $\mathcal{L} = \displaystyle \sum_{1 \leq |\alpha| \leq k} a_\alpha(p) \frac{\partial}{\partial x^\alpha}$&lt;br /&gt;
and evaluate it's shape function as &lt;br /&gt;
\[&lt;br /&gt;
  \b{\chi}_{\mathcal{L}, \vec{p}} = \sum_{1 \leq |\alpha| \leq k}  a_\alpha(p) \b{\chi}_{\frac{\partial}{\partial x^\alpha}, p}.&lt;br /&gt;
\]&lt;br /&gt;
This saves us space and gives certain elegance to the implementation.&lt;/div&gt;</summary>
		<author><name>NikaMlinaric</name></author>	</entry>

	</feed>