Download 26.py from TestCaseGeneration/NumFEM_Eval: direct link, hf CLI and curl.
- Browser
- Download file 4.15 kB
-
https://huggingface.co/datasets/TestCaseGeneration/NumFEM_Eval/resolve/main/26.py
- Command line
-
hf download hf://datasets/TestCaseGeneration/NumFEM_Eval/26.py
-
curl -L -o 26.py https://huggingface.co/datasets/TestCaseGeneration/NumFEM_Eval/resolve/main/26.py
4.15 kB
| from numpy import * | |
| def legendre_interval(count): | |
| from math import sqrt | |
| if count <= 1: | |
| p = array([0.0]) | |
| w = array([2.0]) | |
| return p, w | |
| elif count == 2: | |
| p = array([-1.0 / sqrt(3.0), 1.0 / sqrt(3.0)]) | |
| w = array([1.0, 1.0]) | |
| return p, w | |
| elif count == 3: | |
| p = array([-sqrt(3.0 / 5.0), 0.0, sqrt(3.0 / 5.0)]) | |
| w = array([5.0 / 9.0, 8.0 / 9.0, 5.0 / 9.0]) | |
| return p, w | |
| elif count == 4: | |
| p = array([-sqrt((3.0 + 2.0 * sqrt(6.0 / 5.0)) / 7.0), -sqrt((3.0 - 2.0 * sqrt(6.0 / 5.0)) / 7.0), sqrt((3.0 - 2.0 * sqrt(6.0 / 5.0)) / 7.0), sqrt((3.0 + 2.0 * sqrt(6.0 / 5.0)) / 7.0)]) | |
| w = array([(18.0 - sqrt(30.0)) / 36.0, (18.0 + sqrt(30.0)) / 36.0, (18.0 + sqrt(30.0)) / 36.0, (18.0 - sqrt(30.0)) / 36.0]) | |
| return p, w | |
| else: | |
| p = array([-(1.0 / 3.0) * sqrt(5.0 + 2.0 * sqrt(10.0 / 7.0)), -(1.0 / 3.0) * sqrt(5.0 - 2.0 * sqrt(10.0 / 7.0)), 0.0, (1.0 / 3.0) * sqrt(5.0 - 2.0 * sqrt(10.0 / 7.0)), (1.0 / 3.0) * sqrt(5.0 + 2.0 * sqrt(10.0 / 7.0))]) | |
| w = array([(322.0 - 13.0 * sqrt(70.0)) / 900.0, (322.0 + 13.0 * sqrt(70.0)) / 900.0, 128.0 / 225.0, (322.0 + 13.0 * sqrt(70.0)) / 900.0, (322.0 - 13.0 * sqrt(70.0)) / 900.0]) | |
| return p, w | |
| def legendre_quad(order): | |
| from numpy import zeros | |
| (p, w) = legendre_interval(order) | |
| size = len(p) | |
| xi = zeros(size * size) | |
| eta = zeros(size * size) | |
| weight = zeros(size * size) | |
| for i in range(size): | |
| for j in range(size): | |
| xi[i * size + j] = p[i] | |
| eta[i * size + j] = p[j] | |
| weight[i * size + j] = w[i] * w[j] | |
| return xi, eta, weight | |
| def iso_quad(element_nodes, xi, eta): | |
| from numpy import array | |
| from numpy import sum | |
| from numpy.linalg import det | |
| from numpy.linalg import inv | |
| shape = array([ (1.0 - xi) * (1.0 - eta) / 4.0, (1.0 + xi) * (1.0 - eta) / 4.0, (1.0 + xi) * (1.0 + eta) / 4.0, (1.0 - xi) * (1.0 + eta) / 4.0 ]) # bilinear shape functions | |
| shape_dxi = array([ -(1.0 - eta) / 4.0, (1.0 - eta) / 4.0, (1.0 + eta) / 4.0, -(1.0 + eta) / 4.0 ]) # derivatives of the shape functions in the first parametric direction | |
| shape_deta = array([ -(1.0 - xi) / 4.0, -(1.0 + xi) / 4.0, (1.0 + xi) / 4.0, (1.0 - xi) / 4.0 ]) # derivatives of the shape functions in the second parametric direction | |
| x = element_nodes[:, 0] | |
| y = element_nodes[:, 1] | |
| jacobi = array([ [sum(shape_dxi * x), sum(shape_dxi * y)], [sum(shape_deta * x), sum(shape_deta * y)] ]) # Jacobi matrix | |
| jacobian = det(jacobi) | |
| inverted_jacobi = inv(jacobi) | |
| shape_dx = inverted_jacobi[0, 0] * shape_dxi + inverted_jacobi[0, 1] * shape_deta | |
| shape_dy = inverted_jacobi[1, 0] * shape_dxi + inverted_jacobi[1, 1] * shape_deta | |
| return jacobian, shape, shape_dx, shape_dy | |
| def thermal_force_quads(nodes, elements, thickness, elasticity_matrix, alpha_t, tfunc=None, gauss_order=3): | |
| from numpy import sum, array | |
| freedom = 2 | |
| dimension = len(nodes) * freedom | |
| force = zeros(dimension) | |
| element_nodes = 4 | |
| (xi, eta, w) = legendre_quad(gauss_order) | |
| alpha = array([alpha_t, alpha_t, 0.0]) | |
| for element in elements: | |
| fe = zeros(element_nodes * freedom) | |
| vertices = nodes[element[:], :] | |
| for i in range(len(w)): | |
| (jacobian, shape, shape_dx, shape_dy) = iso_quad(vertices, xi[i], eta[i]) | |
| b = array([ [shape_dx[0], 0.0, shape_dx[1], 0.0, shape_dx[2], 0.0, shape_dx[3], 0.0], [0.0, shape_dy[0], 0.0, shape_dy[1], 0.0, shape_dy[2], 0.0, shape_dy[3]], [shape_dy[0], shape_dx[0], shape_dy[1], shape_dx[1], shape_dy[2], shape_dx[2], shape_dy[3], shape_dx[3]] ]) | |
| if tfunc is None: | |
| fe = fe + thickness * b.transpose().dot(elasticity_matrix).dot(alpha) * w[i] * jacobian | |
| else: | |
| therm = tfunc(sum(vertices[:, 0] * shape), sum(vertices[:, 1] * shape)) | |
| fe = fe + thickness * therm * b.transpose().dot(elasticity_matrix).dot(alpha) * w[i] * jacobian | |
| for i in range(element_nodes * freedom): | |
| ii = element[i / freedom] * freedom + i % freedom | |
| force[ii] += fe[i] | |
| return force |