This example show how to use expressions to do complex calculation on particles
He define some useful constants
We define a kernel function. In general a kernel is a function like \( K(x_p,x_q,A_p,A_q) \). Where \( x_p \) and \( x_q \) are positions of the 2 particles p and q. \( A_p \) and \( A_q \) are the properties on p and q.
A second version more General is
\( K(p,q,A_p,A_q,particles) \)
Where \( p \) in the index of the particle and \( q \) are the index of the particles produced by the cell-List. and particles is the vector containing the particle p and q (In multi-phase SPH this can also be not true)
In this case we are defining an exponential-like function \( A_q e^{\frac{|x_p-x_q|^2}{\sigma}} \)
Here we Initialize the library, we create a Box that define our domain, boundary conditions, and ghost
We create 2 vectors one with 4 properties 2 scalar and 2 vectors. and one with one scalar
We assign random position to particles for both vectors
Redistribute the particles according to the decomposition
Before using expression we have to get alias for each properties we want to use for the expression
Once we have the expression properties we can use them to compose expressions
All these expression are applied point wise for each particles
With this function we output the particles in VTK format.
If we want to use an object like Point into an expression we have to first convert into an expression with the function getVExpr. Every expression does not produce any code execution until we do not assin this expression to some property
Each operator= produce an iteration across particles. It is possible to use the function assign to execute multiple assignment in one cycle. Assign support a variable number of expression
we shown the simple usage of simple point-wise function like sin and exp. Here we show the function applyKernel that encapsulate the operation
\(\sum_{q = Neighborhood(p)} Kernel(x_p,x_q,A_p,A_q) \)
where \( x_p \) is the position of the particle p, \( x_q \) is the position of the particle q, \( A_p \) is the value of the property carried by the particle p, \( A_q \) is the value of the property carried by the particle q
We create some useful object to use apply kernel plus we synchronize the ghost for the property 3 because apply kernel require to read the ghost part
Than we construct an expression with applyKernel
A renormalizaion of the vector vD is calculated on fly for each particle q neighborhood of p. The the following expression is calculated for each particle p
\( (\sum_{q = Neighborhood p} Ker(x_p,x_q,(\frac{vD}{norm(vD)})_p,(\frac{vD}{norm(vD)})_q)) + vD \)
Exist also a second version suitable for more General cases
In the case of General-Finite-Differences, DC-PSE and Multi-Phase SPH. \( K(x_p,x_q,A_p,A_q)\) is limitative and we have to use the following \( K(p,q,A_p,A_q,particles) \). In this case the position \( x_p \) and \( x_q \) are substituted by the id of p and id of q comming from the cell list + the vector on which we are operating.
If the expression is point-wise the rule the propety on the right cannot appear on the left does not apply
Write a VTK file and visualize. Before write the particles also delete Ghost (VTK writer in general output also the ghost particles)
At the very end of the program we have always de-initialize the library