Exemple #1
0
def run_custom():
    num_points = 10

    resolution = 96
    serialized_mesh_filename = 'data/serialized_mesh_res_%d.npz' % resolution
    mesh_wrapper = Mesh.from_file(serialized_mesh_filename)
    # k == Diffusion rate.
    mesh_wrapper.k = 6.0

    run_simulation(num_points, mesh_wrapper, num_steps=500, print_frequency=20)
Exemple #2
0
def run_custom():
    num_points = 10

    resolution = 96
    serialized_mesh_filename = 'data/serialized_mesh_res_%d.npz' % resolution
    mesh_wrapper = Mesh.from_file(serialized_mesh_filename)
    # k == Diffusion rate.
    mesh_wrapper.k = 6.0

    run_simulation(num_points, mesh_wrapper, num_steps=500,
                   print_frequency=20)
Exemple #3
0
def plot_custom():
    X_CENTER1 = 0.0
    X_CENTER2 = 100.0
    X_CENTER3 = 200.0
    X_CENTER4 = 300.0
    MAX_RADIUS = 15.0

    def in_box(value, center):
        delta = value - center
        if np.allclose(delta, MAX_RADIUS) or np.allclose(delta, -MAX_RADIUS):
            return True

        return -MAX_RADIUS <= delta <= MAX_RADIUS

    def in_x_y_box(point, x_center):
        return in_box(point.x, x_center) and in_box(point.y, 0.0)

    def custom_color_function(point):
        if np.allclose(point.z, 50.0):
            return 'b'

        if np.allclose(point.z, 0) or point.z >= 0:
            if in_x_y_box(point, X_CENTER1) or in_x_y_box(point, X_CENTER3):
                return 'r'
            elif in_x_y_box(point, X_CENTER2) or in_x_y_box(point, X_CENTER4):
                return 'y'

        return 'g'

    resolution = 96
    serialized_mesh_filename = 'data/serialized_mesh_res_%d.npz' % resolution
    mesh_wrapper = Mesh.from_file(serialized_mesh_filename)
    mesh_wrapper.k = 6.0

    x = mesh_wrapper.all_vertices[:, 0]
    y = mesh_wrapper.all_vertices[:, 1]
    z = mesh_wrapper.all_vertices[:, 2]
    # Consider putting this into `plot_simulation`.
    plot_boundary = PlotBoundary(np.min(x), np.max(x), np.min(y), np.max(y),
                                 np.min(z), np.max(z))

    plot_simulation(10,
                    mesh_wrapper,
                    plot_boundary,
                    color_function=custom_color_function,
                    num_frames=500,
                    print_frequency=20,
                    show_mesh=True,
                    filename='plots/10points_500steps_bigger_k.gif')
Exemple #4
0
def test_accuracy_on_face(mesh_wrapper=None, num_steps=1000):
    if mesh_wrapper is None:
        resolution = 96

        serialized_mesh_filename = ('data/serialized_mesh_res_%d.npz' %
                                    (resolution,))
        mesh_wrapper = Mesh.from_file(serialized_mesh_filename)

    point = Point(mesh_wrapper)

    for i in xrange(num_steps):
        point.move()

    errors = [error_off_plane(mesh_wrapper.faces[face_id], pt)
              for face_id, pt in point.values]
    print 'Max Error after %d steps' % num_steps
    print np.max(np.abs(errors))
Exemple #5
0
def plot_custom():
    X_CENTER1 = 0.0
    X_CENTER2 = 100.0
    X_CENTER3 = 200.0
    X_CENTER4 = 300.0
    MAX_RADIUS = 15.0
    def in_box(value, center):
        delta = value - center
        if np.allclose(delta, MAX_RADIUS) or np.allclose(delta, - MAX_RADIUS):
            return True

        return -MAX_RADIUS <= delta <= MAX_RADIUS

    def in_x_y_box(point, x_center):
        return in_box(point.x, x_center) and in_box(point.y, 0.0)

    def custom_color_function(point):
        if np.allclose(point.z, 50.0):
            return 'b'

        if np.allclose(point.z, 0) or point.z >= 0:
            if in_x_y_box(point, X_CENTER1) or in_x_y_box(point, X_CENTER3):
                return 'r'
            elif in_x_y_box(point, X_CENTER2) or in_x_y_box(point, X_CENTER4):
                return 'y'

        return 'g'

    resolution = 96
    serialized_mesh_filename = 'data/serialized_mesh_res_%d.npz' % resolution
    mesh_wrapper = Mesh.from_file(serialized_mesh_filename)
    mesh_wrapper.k = 6.0

    x = mesh_wrapper.all_vertices[:, 0]
    y = mesh_wrapper.all_vertices[:, 1]
    z = mesh_wrapper.all_vertices[:, 2]
    # Consider putting this into `plot_simulation`.
    plot_boundary = PlotBoundary(np.min(x), np.max(x),
                                 np.min(y), np.max(y),
                                 np.min(z), np.max(z))

    plot_simulation(10, mesh_wrapper, plot_boundary,
                    color_function=custom_color_function,
                    num_frames=500, print_frequency=20, show_mesh=True,
                    filename='plots/10points_500steps_bigger_k.gif')
Exemple #6
0
def test_accuracy_on_face(mesh_wrapper=None, num_steps=1000):
    if mesh_wrapper is None:
        resolution = 96

        serialized_mesh_filename = ('data/serialized_mesh_res_%d.npz' %
                                    (resolution, ))
        mesh_wrapper = Mesh.from_file(serialized_mesh_filename)

    point = Point(mesh_wrapper)

    for i in xrange(num_steps):
        point.move()

    errors = [
        error_off_plane(mesh_wrapper.faces[face_id], pt)
        for face_id, pt in point.values
    ]
    print 'Max Error after %d steps' % num_steps
    print np.max(np.abs(errors))
Exemple #7
0
from mpl_toolkits.mplot3d import Axes3D  # Needs to be imported for 3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

from particle_diffusion_on_mesh import Mesh

resolution = 96
serialized_mesh_filename = 'data/serialized_mesh_res_%d.npz' % resolution
mesh_wrapper = Mesh.from_file(serialized_mesh_filename)

x = mesh_wrapper.all_vertices[:, 0]
y = mesh_wrapper.all_vertices[:, 1]
z = mesh_wrapper.all_vertices[:, 2]

fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot_trisurf(x,
                y,
                z,
                triangles=mesh_wrapper.triangles,
                color=(0, 0, 0, 0),
                edgecolor='Gray',
                linewidth=0.05)

plt.show()

# http://stackoverflow.com/questions/7965743/
# python-matplotlib-setting-aspect-ratio
from mpl_toolkits.mplot3d import Axes3D  # Needs to be imported for 3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

from particle_diffusion_on_mesh import Mesh


resolution = 96
serialized_mesh_filename = 'data/serialized_mesh_res_%d.npz' % resolution
mesh_wrapper = Mesh.from_file(serialized_mesh_filename)

x = mesh_wrapper.all_vertices[:, 0]
y = mesh_wrapper.all_vertices[:, 1]
z = mesh_wrapper.all_vertices[:, 2]

fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot_trisurf(x, y, z, triangles=mesh_wrapper.triangles,
                color=(0, 0, 0, 0), edgecolor='Gray', linewidth=0.05)

plt.show()

# http://stackoverflow.com/questions/7965743/
# python-matplotlib-setting-aspect-ratio