Scripting

Page under development!

OpenSPH allows to create custom nodes and modify node data using the Chaiscript language.

Script node

Script node can define any number of slots and additional value parameters. These can then be accessed from the script using
getInput(name) Returns the input of given name as Particles object
getParam(name) Returns the parameter of given name as double
The script node must return a Particles object.

Example:

// spin particles around z-axis by given factor
var particles = getInput("particles");
auto& r = particle.getPositions();
auto& v = particle.getVelocities();

var factor = getParam("factor");
var N = particles.getParticleCnt();
for (var i = 0; i < N; i++) {
    var perp = Vec3(r[i].y, -r[i].x, 0);
    var dir = normalized(perp);
    var dist = length(Vec3(r[i].x, r[i].y, 0));
    v[i] += dir * dist * f;
}
return particles;

Available functions:

Math functions

sqr(x) Square of a number
sqrt(x)Square root
cos(x)Cosine
sin(x)Sine
lerp(a, b, x)Linear interpolation between two numbers
abs(x)Absolute value
pow(x, y)Power

Vector algebra

dotProd(u, v)Dot product
crossProd(u, v)Cross product
length(u)Norm of the vector
max(u, v)Element-wise maximum of two vectors
min(u, v)Element-wise minimum of two vectors
normalized(u)Returns normalized vector

Member functions of the Particles class

getParticleCnt()returns the number of particles
getBoundingBox()returns the bounding box of all particles as Box3
getMasses()returns masses of particles
getEnergies()returns specific energies of particles
getDensities()returns densities of particles
getPositions()return position vectors of particles
getVelocities()return velocities of particles
getAccelerations()return current accelerations of particles
getRadii()return radii of particles
merge(other)adds all particles from another variable
getBoundingBox()returns the bounding box of particles
getCenterOfMass()returns the center of mass of particles
getTotalMass()return the total mass of all particles
getTotalMomentum()return the total momentum of particles
getTotalAngularMomentum()return the total angular momentum w.r.t. origin
getAngularFrequency()returns the angular frequence of particles w.r.t. origin

Constants

DEG_TO_RADConversion factor from degrees to radians
RAD_TO_DEGConversion factor from radians to degrees
M_earthMass of the Earth (in kg)
M_sunMass of the Sun (in kg)
GGravitational constant