Skip to content

Commit 3d06896

Browse files
Merge pull request #676 from EOMYS-Public/MeshSolution
Mesh solution
2 parents 5b7caac + 3db1fea commit 3d06896

File tree

221 files changed

+6006
-5221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+6006
-5221
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ run_GUI_internal.py
2424
/.spyproject/config/workspace.ini
2525
/build
2626
/dist
27-
node_modules
27+
node_modules
28+
/.venv

Tests/Data/Mesh/mesh_test_mixte.unv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ CS1
1717
2412
1818
1 44 0 0 1 4
1919
3 4 5 6
20-
2 44 0 0 1 3
20+
2 41 0 0 1 3
2121
3 4 11
22-
3 44 0 0 1 3
22+
3 41 0 0 1 3
2323
4 5 11
24-
4 44 0 0 1 3
24+
4 41 0 0 1 3
2525
5 6 11
26-
5 44 0 0 1 3
26+
5 41 0 0 1 3
2727
3 6 11
2828
-1

Tests/Data/Mesh/mesh_test_tri.unv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ CS1
1414
-1
1515
-1
1616
2412
17-
1 44 0 0 1 3
17+
1 41 0 0 1 3
1818
3 4 5
19-
2 44 0 0 1 3
19+
2 41 0 0 1 3
2020
3 4 11
21-
3 44 0 0 1 3
21+
3 41 0 0 1 3
2222
4 5 11
23-
4 44 0 0 1 3
23+
4 41 0 0 1 3
2424
3 5 11
2525
-1

Tests/Methods/Import/test_import_mesh_unv.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
# TODO: debug mesh with mix of elements (not handled in pyuff)
44

5-
import pytest
65
from os import mkdir
7-
from os.path import isdir, join, basename, splitext
6+
from os.path import basename, isdir, join, splitext
7+
8+
import pytest
89

910
from pyleecan.Classes.ImportMeshMat import ImportMeshMat
1011
from pyleecan.Classes.MeshSolution import MeshSolution
11-
from Tests import save_plot_path as save_path
1212
from pyleecan.definitions import TEST_DIR
13+
from Tests import save_plot_path as save_path
1314

1415
save_path = join(save_path, "Import")
1516
if not isdir(save_path):
@@ -60,7 +61,7 @@ def test_import_mesh_unv(unv_file):
6061
mesh = test_obj.get_data()
6162

6263
meshsol = MeshSolution(dimension=3)
63-
meshsol.mesh = [mesh]
64+
meshsol.mesh = mesh
6465
meshsol.plot_mesh(
6566
save_path=join(save_path, splitext(basename(unv_file["path"]))[0] + ".png"),
6667
is_show_axes=True,

Tests/Methods/Mesh/Interpolation/test_interpolation.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
import pytest
4-
import numpy as np
53
from unittest import TestCase
64

7-
from pyleecan.Classes.CellMat import CellMat
5+
import numpy as np
6+
import pytest
7+
8+
from pyleecan.Classes.ElementMat import ElementMat
9+
from pyleecan.Classes.FPGNSeg import FPGNSeg
10+
from pyleecan.Classes.MeshMat import MeshMat
811
from pyleecan.Classes.MeshSolution import MeshSolution
912
from pyleecan.Classes.NodeMat import NodeMat
10-
from pyleecan.Classes.MeshMat import MeshMat
11-
from pyleecan.Classes.ScalarProductL2 import ScalarProductL2
12-
from pyleecan.Classes.Interpolation import Interpolation
1313
from pyleecan.Classes.RefSegmentP1 import RefSegmentP1
14-
from pyleecan.Classes.FPGNSeg import FPGNSeg
1514

1615

1716
@pytest.mark.MeshSol
@@ -22,67 +21,67 @@ def test_line(self):
2221
DELTA = 1e-10
2322

2423
mesh = MeshMat()
25-
mesh.cell["line"] = CellMat(nb_node_per_cell=2)
24+
mesh.element_dict["line"] = ElementMat(
25+
nb_node_per_element=2, ref_element=RefSegmentP1(), gauss_point=FPGNSeg()
26+
)
2627
mesh.node = NodeMat()
2728
mesh.node.add_node(np.array([0, 0]))
2829
mesh.node.add_node(np.array([1, 0]))
2930
mesh.node.add_node(np.array([0, 1]))
3031
mesh.node.add_node(np.array([2, 3]))
3132
mesh.node.add_node(np.array([3, 3]))
3233

33-
mesh.add_cell(np.array([0, 1]), "line")
34-
mesh.add_cell(np.array([0, 2]), "line")
35-
mesh.add_cell(np.array([1, 2]), "line")
36-
37-
c_line = mesh.cell["line"]
34+
mesh.add_element(np.array([0, 1]), "line")
35+
mesh.add_element(np.array([0, 2]), "line")
36+
mesh.add_element(np.array([1, 2]), "line")
3837

39-
c_line.interpolation = Interpolation()
40-
c_line.interpolation.ref_cell = RefSegmentP1()
41-
c_line.interpolation.scalar_product = ScalarProductL2()
42-
c_line.interpolation.gauss_point = FPGNSeg()
38+
c_line = mesh.element_dict["line"]
4339

4440
meshsol = MeshSolution()
45-
meshsol.mesh = [mesh]
41+
meshsol.mesh = mesh
4642

47-
vert = mesh.get_vertice(0)["line"]
43+
# Constant field
44+
vert = mesh.get_element_coordinate(0)["line"]
4845
test_pt = np.array([0.7, 0])
4946
test_field = np.array([1, 1])
5047
sol = [1]
51-
func = c_line.interpolation.ref_cell.interpolation(test_pt, vert, test_field)
48+
func = c_line.interpolate(test_pt, vert, test_field)
5249
testA = np.sum(abs(func - sol))
5350
msg = "Wrong result: returned " + str(func) + ", expected: " + str(test_field)
5451
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
5552

56-
vert = mesh.get_vertice(0)["line"]
53+
# Constant field with multiple time steps
54+
vert = mesh.get_element_coordinate(0)["line"]
5755
test_pt = np.array([0.7, 0])
5856
test_field = np.ones(
5957
(2, 120, 3)
6058
) # Simulate a 3D vector field for 120 time step
61-
func = c_line.interpolation.ref_cell.interpolation(test_pt, vert, test_field)
59+
func = c_line.interpolate(test_pt, vert, test_field)
6260
sol = np.ones((120, 3))
6361
testA = np.sum(abs(func - sol))
6462
msg = "Wrong result: returned " + str(func) + ", expected: " + str(sol)
6563
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
6664

67-
vert = mesh.get_vertice(2)["line"]
65+
# Not constant
66+
vert = mesh.get_element_coordinate(2)["line"]
6867
test_pt = np.array([0.6, 0.4])
6968
test_field = np.zeros((2, 120, 3))
7069
test_field[0, :] = np.ones(
7170
(1, 120, 3)
7271
) # Simulate a 3D vector field for 120 time step
73-
func = c_line.interpolation.ref_cell.interpolation(test_pt, vert, test_field)
72+
func = c_line.interpolate(test_pt, vert, test_field)
7473
sol = 0.6 * np.ones((120, 3))
7574
testA = np.sum(abs(sol - func))
7675
msg = "Wrong result: returned " + str(func) + ", expected: " + str(sol)
7776
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
7877

79-
vert = mesh.get_vertice(1)["line"]
78+
vert = mesh.get_element_coordinate(1)["line"]
8079
test_pt = np.array([0, 0.4])
8180
test_field = np.zeros((2, 120, 3))
8281
test_field[1, :] = np.ones(
8382
(1, 120, 3)
8483
) # Simulate a 3D vector field for 120 time step
85-
func = c_line.interpolation.ref_cell.interpolation(test_pt, vert, test_field)
84+
func = c_line.interpolate(test_pt, vert, test_field)
8685
sol = 0.4 * np.ones((120, 3))
8786
testA = np.sum(abs(sol - func))
8887
msg = "Wrong result: returned " + str(func) + ", expected: " + str(sol)

Tests/Methods/Mesh/Interpolation/test_real_points.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
import pytest
4-
import numpy as np
53
from unittest import TestCase
64

7-
from pyleecan.Classes.CellMat import CellMat
5+
import numpy as np
6+
import pytest
7+
8+
from pyleecan.Classes.ElementMat import ElementMat
9+
from pyleecan.Classes.FPGNSeg import FPGNSeg
10+
from pyleecan.Classes.MeshMat import MeshMat
811
from pyleecan.Classes.MeshSolution import MeshSolution
912
from pyleecan.Classes.NodeMat import NodeMat
10-
from pyleecan.Classes.MeshMat import MeshMat
11-
12-
from pyleecan.Classes.ScalarProductL2 import ScalarProductL2
13-
from pyleecan.Classes.Interpolation import Interpolation
1413
from pyleecan.Classes.RefSegmentP1 import RefSegmentP1
15-
from pyleecan.Classes.FPGNSeg import FPGNSeg
1614

1715

1816
@pytest.mark.MeshSol
@@ -23,72 +21,69 @@ def test_line(self):
2321
DELTA = 1e-10
2422

2523
mesh = MeshMat()
26-
mesh.cell["line"] = CellMat(nb_node_per_cell=2)
24+
mesh.element_dict["line"] = ElementMat(
25+
nb_node_per_element=2, ref_element=RefSegmentP1(), gauss_point=FPGNSeg()
26+
)
2727
mesh.node = NodeMat()
2828
mesh.node.add_node(np.array([0, 0]))
2929
mesh.node.add_node(np.array([1, 0]))
3030
mesh.node.add_node(np.array([0, 1]))
3131
mesh.node.add_node(np.array([2, 3]))
3232
mesh.node.add_node(np.array([3, 3]))
3333

34-
mesh.add_cell(np.array([0, 1]), "line")
35-
mesh.add_cell(np.array([0, 2]), "line")
36-
mesh.add_cell(np.array([1, 2]), "line")
37-
38-
c_line = mesh.cell["line"]
34+
mesh.add_element(np.array([0, 1]), "line")
35+
mesh.add_element(np.array([0, 2]), "line")
36+
mesh.add_element(np.array([1, 2]), "line")
3937

40-
c_line.interpolation = Interpolation()
41-
c_line.interpolation.ref_cell = RefSegmentP1()
42-
c_line.interpolation.scalar_product = ScalarProductL2()
43-
c_line.interpolation.gauss_point = FPGNSeg()
38+
c_line = mesh.element_dict["line"]
4439

4540
meshsol = MeshSolution()
46-
meshsol.mesh = [mesh]
41+
meshsol.mesh = mesh
4742

48-
vert = mesh.get_vertice(0)["line"]
43+
vert = mesh.get_element_coordinate(0)["line"]
4944
test = np.array([0, 0])
5045
solution = np.array([0.5, 0])
51-
ref_nodes = c_line.interpolation.ref_cell.get_real_point(vert, test)
46+
ref_nodes = c_line.ref_element.get_real_point(vert, test)
5247
testA = np.sum(abs(solution - ref_nodes))
5348
msg = (
5449
"Wrong result: returned " + str(ref_nodes) + ", expected: " + str(solution)
5550
)
5651
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
5752

58-
vert = mesh.get_vertice(1)["line"]
53+
vert = mesh.get_element_coordinate(1)["line"]
5954
test = np.array([0, 0])
6055
solution = np.array([0, 0.5])
61-
ref_nodes = c_line.interpolation.ref_cell.get_real_point(vert, test)
56+
ref_nodes = c_line.ref_element.get_real_point(vert, test)
6257
testA = np.sum(abs(solution - ref_nodes))
6358
msg = (
6459
"Wrong result: returned " + str(ref_nodes) + ", expected: " + str(solution)
6560
)
6661
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
6762

68-
vert = mesh.get_vertice(2)["line"]
63+
vert = mesh.get_element_coordinate(2)["line"]
6964
test = np.array([0, 0])
7065
solution = np.array([0.5, 0.5])
71-
ref_nodes = c_line.interpolation.ref_cell.get_real_point(vert, test)
66+
ref_nodes = c_line.ref_element.get_real_point(vert, test)
7267
testA = np.sum(abs(solution - ref_nodes))
7368
msg = (
7469
"Wrong result: returned " + str(ref_nodes) + ", expected: " + str(solution)
7570
)
7671
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
7772

78-
vert = mesh.get_vertice(2)["line"]
73+
vert = mesh.get_element_coordinate(2)["line"]
7974
test = np.array([-1, 0])
8075
solution = np.array([1, 0])
81-
ref_nodes = c_line.interpolation.ref_cell.get_real_point(vert, test)
76+
ref_nodes = c_line.ref_element.get_real_point(vert, test)
8277
testA = np.sum(abs(solution - ref_nodes))
8378
msg = (
8479
"Wrong result: returned " + str(ref_nodes) + ", expected: " + str(solution)
8580
)
8681
self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)
8782

88-
vert = mesh.get_vertice(2)["line"]
83+
vert = mesh.get_element_coordinate(2)["line"]
8984
test = np.array([-0.2, 0])
9085
solution = np.array([0.6, 0.4])
91-
ref_nodes = c_line.interpolation.ref_cell.get_real_point(vert, test)
86+
ref_nodes = c_line.ref_element.get_real_point(vert, test)
9287
testA = np.sum(abs(solution - ref_nodes))
9388
msg = (
9489
"Wrong result: returned " + str(ref_nodes) + ", expected: " + str(solution)

0 commit comments

Comments
 (0)