treverhines / RBF

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

Vertices defining simplices are not preserved? #5

Closed maxrudolph closed 5 years ago

maxrudolph commented 5 years ago

I'm trying to use your package to solve a heat transfer problem on an irregular domain using radial basis functions. When I use min_energy_nodes, the vertices at the corners of the domain are not part of the set of nodes returned by min_energy_nodes. Is there an easy way to force this, so that the corners of the domain do not get truncated?

treverhines commented 5 years ago

There is some functionality in min_energy_nodes that will help you get what you want. There is a fixed_nodes argument for min_energy_nodes which lets you specify nodes that will not move and they will just provide a "repulsion force" when the nodes are being distributed in the domain. These fixed nodes are not included in the nodes returned by min_energy_nodes and you will see gaps in the returned nodes at the locations of the fixed nodes. So you will need to append the fixed nodes to the nodes returned by min_energy_nodes. You will also have to do some bookkeeping to make sure the indices for these newly appended nodes are part of the boundary group. Here is a script that demonstrate what I am talking about:

import numpy as np
import matplotlib.pyplot as plt
from rbf.nodes import min_energy_nodes

vert = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])
smp = np.array([[0, 1], [1, 2], [2, 3], [3, 0]])

nodes, indices, _ = min_energy_nodes(100, vert, smp, fixed_nodes=vert)
nodes = np.vstack((nodes, vert))
# update the list of boundary indices to include the newly appended
# nodes
indices['boundary'] = np.hstack(
    (indices['boundary'], range(len(nodes) - len(vert), len(nodes))))

plt.plot(nodes[indices['boundary'], 0], nodes[indices['boundary'], 1], 'ro')
plt.plot(nodes[indices['interior'], 0], nodes[indices['interior'], 1], 'bo')
plt.show()

Since these nodes are located at a cusp, things will get a little more complicated if you are dealing with free surface boundary conditions or any other boundary condition that requires you to know the normal vector to the boundary surface. Let me know if that is an issue.

I am thinking that the expected behavior for min_energy_nodes should be to include the fixed_nodes in with the output nodes. I will make that change.

Let me know if this helps.

maxrudolph commented 5 years ago

@treverhines thank you for your detailed response. Yes, the nodes are on boundary segments for which I need to know the boundary normal vector. In principle I suppose that I can compute this myself since these nodes would be part of the input simplices, but it might be tidier to add an option to preserve the input nodes in min_energy_nodes.

treverhines commented 5 years ago

@maxrudolph I have been reworking min_energy_nodes for the past couple of days. I added a include_vertices flag and I changed its output a bit. You can find its documentation and examples here https://rbf.readthedocs.io/en/latest/nodes.html. I also added a relatively simple example of using the output from min_energy_nodes to solve a PDE with mixed boundary conditions. It is the second example down on this page https://rbf.readthedocs.io/en/latest/fd.html. Let me know if you have any other questions/comments about this package or about using RBFs for solving PDEs.

maxrudolph commented 5 years ago

@treverhines thank you for your reply. I'm checking it out now and it appears to be working perfectly for my problem.