treverhines / RBF

Python package containing the tools necessary for radial basis function (RBF) applications
MIT License
220 stars 51 forks source link

Trying to understand _disperse_step #32

Closed RomanLF closed 1 year ago

RomanLF commented 1 year ago

Hello Trever,

In rbf/pde /nodes.py at _disperse_step function you compute a proportionality constant based on electrorepulsion law with the support of $\rho$ density function. You wrote :

 all_nodes = np.vstack((nodes, fixed_nodes))
    # find index and distance to nearest nodes
    dist, idx = KDTree(all_nodes).query(nodes, neighbors + 1)
    # dont consider a node to be one of its own nearest neighbors
    dist, idx = dist[:, 1:], idx[:, 1:]
    # compute the force proportionality constant between each node
    # based on their charges
    c = 1.0/(rho(all_nodes)[idx, None]*rho(nodes)[:, None, None])
    # calculate forces on each node resulting from the neighboring nodes. This
    # will result in a division by zero warning if there are duplicate nodes.
    # Do not suppress the warning because it is a real problem.
    forces = c*(nodes[:, None, :] - all_nodes[idx, :])/dist[:, :, None]**3
    # sum up all the forces for each node to get the direction that the nodes
    # should move.
    direction = np.sum(forces, axis=1)

$$ c(\mathbf{X, S}) = 1 / (\rho(\mathbf{X}) \rho(\mathbf{S})) $$

And compute forces with,

$$ \mathbf{F}_{\mathbf{X}~on~ \mathbf{S}} = \frac{1}{\rho(\mathbf{X}) \rho(\mathbf{S})} \frac{\mathbf{S} - \mathbf{X}}{| \mathbf{S} - \mathbf{X}|^3} $$

Where for Cloumb's law force exerced by charged by a particule 1 on particule 2 is,

$$ \vec{F}_{1 / 2}= {q_1 q_2} \frac{\vec{r}_2-\vec{r}_1}{\left|\vec{r}_2-\vec{r}_1\right|^3} $$

Does it mean that you assume that node density is $\rho$ is equivalent to $1/q$ in term of charge density ?

Best regards, Roman

treverhines commented 1 year ago

I am using the inverse of the desired node density for the charge. However, if you run _disperse_step enough times, it wont actually arrive at that desired node density as a steady state. So this function is really just used to refine nodes that are already placed close to the desired node density. By setting the charge to the inverse of the node density, I am just trying to keep _disperse_step from significantly changing the node density.

RomanLF commented 1 year ago

Ok thank you very much for your explanation.