Download 20.py from TestCaseGeneration/NumFEM_Eval: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/datasets/TestCaseGeneration/NumFEM_Eval/resolve/main/20.py
- Command line
-
hf download hf://datasets/TestCaseGeneration/NumFEM_Eval/20.py
-
curl -L -o 20.py https://huggingface.co/datasets/TestCaseGeneration/NumFEM_Eval/resolve/main/20.py
1.42 kB
| import numpy as np | |
| def rectangular_triangles(x_count, y_count, x_origin, y_origin, width, height): | |
| nodes = np.zeros((x_count * y_count, 2), dtype=np.float64) | |
| elements = np.zeros((2 * (x_count - 1) * (y_count - 1), 3), dtype=np.int32) | |
| points_x = np.linspace(x_origin, x_origin + width, num=x_count) | |
| points_y = np.linspace(y_origin, y_origin + height, num=y_count) | |
| cx = x_origin + width / 2.0 | |
| cy = y_origin + height / 2.0 | |
| for i in range(x_count): | |
| for j in range(y_count): | |
| nodes[i * y_count + j, 0] = points_x[i] | |
| nodes[i * y_count + j, 1] = points_y[j] | |
| for i in range(x_count - 1): | |
| for j in range(y_count - 1): | |
| bl = i * y_count + j | |
| br = (i + 1) * y_count + j | |
| tr = (i + 1) * y_count + (j + 1) | |
| tl = i * y_count + (j + 1) | |
| all_right_top = np.all(nodes[[bl, br, tr, tl], 0] >= cx) and np.all(nodes[[bl, br, tr, tl], 1] >= cy) | |
| all_left_bottom = np.all(nodes[[bl, br, tr, tl], 0] <= cx) and np.all(nodes[[bl, br, tr, tl], 1] <= cy) | |
| elem_idx = 2 * (i * (y_count - 1) + j) | |
| if all_right_top or all_left_bottom: | |
| elements[elem_idx] = [bl, br, tl] | |
| elements[elem_idx + 1] = [br, tr, tl] | |
| else: | |
| elements[elem_idx] = [bl, br, tr] | |
| elements[elem_idx + 1] = [bl, tr, tl] | |
| return nodes, elements |