Skip to content

Commit

Permalink
Merge 69bd756 into 7c9e5d5
Browse files Browse the repository at this point in the history
  • Loading branch information
ndem0 committed Mar 14, 2018
2 parents 7c9e5d5 + 69bd756 commit 151b004
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 30 deletions.
43 changes: 14 additions & 29 deletions ezyrb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,17 @@
'parametricspace', 'interpolation', 'rbf'
]

try:
from . import filehandler
from . import matlabhandler
from . import interpolation
from . import vtkhandler
from . import stlhandler
from . import podinterpolation
from . import parametricspace
from . import online
from . import offline
from . import mapper
from . import points
from . import snapshots
from . import utilities
from .ndinterpolator import rbf
except:
import filehandler
import matlabhandler
import interpolation
import vtkhandler
import stlhandler
import podinterpolation
import parametricspace
import online
import offline
import utilities
import mapper
import points
import snapshots
from . import filehandler
from . import matlabhandler
from . import interpolation
from . import vtkhandler
from . import stlhandler
from . import podinterpolation
from . import parametricspace
from . import online
from . import offline
from . import mapper
from . import points
from . import snapshots
from . import utilities
from .ndinterpolator import rbf
3 changes: 2 additions & 1 deletion ezyrb/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def _append_weighted(self, values):
:param array_like values: the output.
"""
array = np.asarray(np.sqrt(self._weights) * values).reshape(-1, 1)
print(values.shape)
array = np.dot(np.sqrt(self._weights), values.T).reshape(-1, 1)
try:
self._weighted = np.append(self._weighted, array, 1)
except ValueError:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_datasets/wrongmu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ================================================= #
# Mu file #
# ================================================= #

# Lines starting with '#' are comments, they will be ignored.

# mu0 mu1 file
tests/test_datasets/matlab_00.vtk
tests/test_datasets/matlab_01.vtk
tests/test_datasets/matlab_02.vtk
tests/test_datasets/matlab_03.vtk
37 changes: 37 additions & 0 deletions tests/test_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,42 @@ def test_mapper_set_output_append4(self):
mapper.output_name = mapper.output_name + [names2]
assert (["this", "a"] == mapper.output_name)

def test_interpolate_function_setter(self):
def custom_interp(values, dist):
return values[np.argmin(dist)]
mapper = ma.Mapper()
mapper.interpolate_function = custom_interp

def test_interpolate_function_setter_wrongtype(self):
mapper = ma.Mapper()
with self.assertRaises(TypeError):
mapper.interpolate_function = 3

def test_interpolation_mode_setter_wrongtype(self):
mapper = ma.Mapper()
with self.assertRaises(TypeError):
mapper.interpolation_mode = 5

def test_interpolation_mode_setter_wrongvalue(self):
mapper = ma.Mapper()
with self.assertRaises(ValueError):
mapper.interpolation_mode = 'node'

def test_mapper_number_neighbors(self):
mapper = ma.Mapper()
mapper.number_neighbors = 3
assert (3 == mapper.number_neighbors)

def test_mapper_number_neighbors_setter_wrongtype(self):
mapper = ma.Mapper()
with self.assertRaises(TypeError):
mapper.number_neighbors = np.array([3])

def test_find_neighbour(self):
mapper = ma.Mapper()
with self.assertRaises(RuntimeError):
mapper._find_neighbour([0, 0, 0])

def test_mapper_callable_build_neighbour_locator(self):
mapper = ma.Mapper()
points = np.eye(3)
Expand Down Expand Up @@ -126,6 +157,12 @@ def test_mapper_map_solution(self):
os.remove(map_file)
assert (test_map.shape == (197, 1))

def test_mapper_map_solution_nogeometryfile(self):
mapper = ma.Mapper()
mapper.output_name = "Pressure"
mapper.interpolation_mode = 'point'
mapper.map_solution(vtk_file, 'tests/test_datasets/matlab_00.vtk')

def test_mapper_map_solution2(self):
mapper = ma.Mapper()
mapper.output_name = "test"
Expand Down
47 changes: 47 additions & 0 deletions tests/test_ndinterpolator_rbf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from unittest import TestCase
import unittest
import numpy as np
import filecmp
import os
import sys
from ezyrb.ndinterpolator.rbf import RBFInterpolator


class TestRBFInterpolator(TestCase):
def test_rbf(self):
pts = np.eye(3)
values = np.arange(15).reshape(3, 5)
space = RBFInterpolator(pts, values)

def test_points(self):
pts = np.eye(3)
values = np.arange(15).reshape(3, 5)
space = RBFInterpolator(pts, values)
np.testing.assert_array_equal(space.points, pts)

def test_default_basis(self):
pts = np.eye(3)
values = np.arange(15).reshape(3, 5)
space = RBFInterpolator(pts, values)
assert space.basis == RBFInterpolator.multi_quadratic

def test_default_radius(self):
pts = np.eye(3)
values = np.arange(15).reshape(3, 5)
space = RBFInterpolator(pts, values)
assert space.radius == 1.0

def test_multi_quadratic(self):
func_res = RBFInterpolator.multi_quadratic(np.linspace(0, 1, 5), .5)
exct_res = np.array([0.5, 0.559017, 0.707107, 0.901388, 1.118034])
np.testing.assert_array_almost_equal(func_res, exct_res, decimal=6)

def test_default_call(self):
pts = np.eye(3)
values = np.arange(15).reshape(3, 5)
space = RBFInterpolator(pts, values)
exct_res = np.array([
[ 4.75195353, 5.70234424, 6.65273494, 7.60312565, 8.55351636]
])
np.testing.assert_array_almost_equal(
space([[0, 0, 0]]), exct_res, decimal=6)
12 changes: 12 additions & 0 deletions tests/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def test_init_database_from_file2(self):
offline.init_database_from_file(conf_file)
assert offline.snapshots.values.shape == (2500, 4)

def test_init_database_from_file_nofile(self):
conf_file = 'tests/test_datasets/notexisting_mu.conf'
offline = Offline(output_name='Pressure', dformat='point')
with self.assertRaises(IOError):
offline.init_database_from_file(conf_file)

def test_init_database_from_file_wrongfile(self):
conf_file = 'tests/test_datasets/wrongmu.conf'
offline = Offline(output_name='Pressure', dformat='point')
with self.assertRaises(ValueError):
offline.init_database_from_file(conf_file)

def test_add_snapshot(self):
conf_file = 'tests/test_datasets/mu.conf'
offline = Offline(output_name='Pressure', dformat='point')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_parametricspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest import TestCase
import unittest
import numpy as np
import filecmp
import os

from ezyrb.parametricspace import ParametricSpace

class TestParametricSpace(TestCase):
def test_init(self):
with self.assertRaises(NotImplementedError):
ParametricSpace()

def test_call(self):
with self.assertRaises(NotImplementedError):
ParametricSpace()(0.0)
11 changes: 11 additions & 0 deletions tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def test_append2(self):
snaps.append("tests/test_datasets/matlab_01.vtk")
assert snaps.weighted.shape == (2500, 2)

def test_append_weights(self):
snaps = Snapshots(output_name='Weights', weight_name='Weights',
dformat="cell")
snaps.append("tests/test_datasets/matlab_00.vtk")
assert snaps.weights.shape == (2401, 1)

def test_append_wrongname(self):
snaps = Snapshots(output_name='Pressure', dformat="point")
with self.assertRaises(TypeError):
snaps.append(3.6)

def test_size(self):
snaps = Snapshots(output_name='Pressure', dformat="point")
snaps.append("tests/test_datasets/matlab_00.vtk")
Expand Down
29 changes: 29 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,32 @@ def test_simplex_volume(self):
volume = ezyrb.utilities.simplex_volume(p)
real_volume = 1. / 6.
np.testing.assert_almost_equal(volume, real_volume)

def test_compute_area(self):
area = ezyrb.utilities.compute_area('tests/test_datasets/test_sphere.stl')
np.testing.assert_almost_equal(3.076495, area.sum(), decimal=6)

def test_compute_normals_points(self):
normals = ezyrb.utilities.compute_normals(
'tests/test_datasets/test_sphere.stl', datatype='point')
np.testing.assert_array_almost_equal(
[0, 0, 0], normals.sum(axis=0), decimal=4)

def test_compute_normals_cell(self):
normals = ezyrb.utilities.compute_normals(
'tests/test_datasets/test_sphere.stl')
np.testing.assert_array_almost_equal(
[0, 0, 0], normals.sum(axis=0), decimal=4)

def test_write_area(self):
ezyrb.utilities.write_area('tests/test_datasets/test_sphere.vtk')
area = FileHandler(
'tests/test_datasets/test_sphere.vtk').get_dataset('Area', 'cell')
np.testing.assert_almost_equal(3.118406, area.sum(), decimal=6)

def test_write_normals(self):
ezyrb.utilities.write_normals('tests/test_datasets/test_sphere.vtk')
normals = FileHandler(
'tests/test_datasets/test_sphere.vtk').get_dataset('Normals', 'cell')
np.testing.assert_array_almost_equal(
[0, 0, 0], normals.sum(axis=0), decimal=4)

0 comments on commit 151b004

Please sign in to comment.