11# -*- coding: utf-8 -*-
22
3- import pytest
4- import numpy as np
53from 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
811from pyleecan .Classes .MeshSolution import MeshSolution
912from 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
1313from 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 )
0 commit comments