def _calculate_f_r(x1, x2, x4, y1, y2, y4, rho): """ _calculate_f_r elementwise "lastvektoren" """ J_r = np.array([[x2 - x1, x4 - x1], [y2 - y1, y4 - y1]]) a_dJ_r = abs(np.linalg.det(J_r)) N = 4 f_r = np.zeros(shape=(N,1)) phi = linear_trial_funcs for i in range(0,4): integrand = lambda xi1, xi2: fem.rho(_ref_to_global(x1, x2, x4, y1, y2, y4, (xi1,xi2)))*phi[i](xi1,xi2)*a_dJ_r f_r[i,0] = numeric.gauss_2D_3(integrand) return f_r
def _calculate_f_r(x1, x2, x4, y1, y2, y4, rho): """ _calculate_f_r elementwise "lastvektoren" """ J_r = np.array([[x2 - x1, x4 - x1], [y2 - y1, y4 - y1]]) a_dJ_r = abs(np.linalg.det(J_r)) N = 4 f_r = np.zeros(shape=(N, 1)) phi = linear_trial_funcs for i in range(0, 4): integrand = lambda xi1, xi2: fem.rho( _ref_to_global(x1, x2, x4, y1, y2, y4, (xi1, xi2))) * phi[i](xi1, xi2) * a_dJ_r f_r[i, 0] = numeric.gauss_2D_3(integrand) return f_r
def _calculate_K_r(x1, x2, x4, y1, y2, y4, eps): """ _calculate_K_r """ J_r = np.array([[x2 - x1, x4 - x1], [y2 - y1, y4 - y1]]) dJ_r = np.linalg.det(J_r); J11 = (y4 - y1)**2 + (-x4 + x1)**2 J12 =(y4 - y1) * (-y2 + y1) + (-x4 + x1) * (x2 - x1) J21 =(y4 - y1) * (-y2 + y1) + (-x4 + x1) * (x2 - x1) J22 = (-y2 + y1)**2 + (x2 - x1)**2; # K_r = np.zeros(shape=(4,4)) #remove constants? # K_r[0,0] = 1/3. * J11 + 1/4. * J12 + 1/4. *J21 + 1/3.*J22 # K_r[0,1] = -1/3. * J11 + 1/4. * J12 - 1/4. * J21 + 1/6.*J22 # K_r[0,2] = -1/6. * J11 - 1/4. * J12 - 1/4. * J21 - 1/6.* J22 # K_r[0,3] = 1/6. *J11 - 1/4.*J12 + 1/4. *J21 - 1/3. *J22 # K_r[1,0] = -1/3.*J11 - 1/4.*J12 + 1/4.*J21 + 1/6.*J22 # K_r[1,1] = 1/3.*J11 - 1/4.*J12 - 1/4.*J21 + 1/3.*J22 # K_r[1,2] = 1/6. *J11 + 1/4.*J12 - 1/4.*J21 - 1/3.*J22 # K_r[1,3] = -1/6.*J11 + 1/4.*J12 + 1/4.*J21 - 1/6.*J22 # K_r[2,0] = -1/6.*J11-1/4.*J12 -1/4.*J21 - 1/6.*J22 # K_r[2,1] = 1/6.*J11-1/4.*J12+1/4.*J21 - 1/3.*J22 # K_r[2,2] = 1/3.*J11 + 1/4.*J12 + 1/4.*J21 + 1/3.*J22 # K_r[2,3] = -1/3.*J11 + 1/4.*J12 - 1/4.*J21 + 1/6.*J22 # K_r[3,0] = 1/6.*J11 + 1/4.*J12-1/4.*J21 - 1/3.*J22 # K_r[3,1] = -1/6.*J11 + 1/4.*J12+1/4.*J21 - 1/6.*J22 # K_r[3,2] = -1/3.*J11 - 1/4.*J12 + 1/4.*J21 + 1/6.*J22 # K_r[3,3] = 1/3.*J11 -1/4.*J12 - 1/4.*J21 + 1/3.*J22 # K_r = 1 * abs(dJ_r)/ (dJ_r**2) * K_r; K_r2 = np.zeros(shape=(4,4)) #for numeric #K_r2[0,0] = numeric.gauss_2D_3(lambda x,y: ((J11 * (-1 + y) + J12 * (-1 + x)) * (-1 + y) + (J21 * (-1 + y) + J22 * (-1 + x)) * (-1 + x))) #eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y))) K_r2[0,0] = numeric.gauss_2D_3(lambda x,y: ((J11 * (-1 + y) + J12 * (-1 + x)) * (-1 + y) + (J21 * (-1 + y) + J22 * (-1 + x)) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[0,1] = numeric.gauss_2D_3(lambda x,y: ((J11 * (1 - y) - J12 * x) * (-1 + y) + (J21 * (1 - y) - J22 * x) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[0,2] = numeric.gauss_2D_3(lambda x,y: ((J11 * y + J12 * x) * (-1 + y) + (J21 * y + J22 * x) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[0,3] = numeric.gauss_2D_3(lambda x,y: ((-J11 * y + J12 * (1 - x)) * (-1 + y) + (-J21 * y + J22 * (1 - x)) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[1,0] = numeric.gauss_2D_3(lambda x,y: ((J11 * (-1 + y) + J12 * (-1 + x)) * (1 - y) - (J21 * (-1 + y) + J22 * (-1 + x)) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[1,1] = numeric.gauss_2D_3(lambda x,y: ((J11 * (1 - y) - J12 * x) * (1 - y) - (J21 * (1 - y) - J22 * x) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[1,2] = numeric.gauss_2D_3(lambda x,y: ((J11 * y + J12 * x) * (1 - y) - (J21 * y + J22 * x) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[1,3] = numeric.gauss_2D_3(lambda x,y: ((-J11 * y + J12 * (1 - x)) * (1 - y) - (-J21 * y + J22 * (1 - x)) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[2,0] = numeric.gauss_2D_3(lambda x,y: ((J11 * (-1 + y) + J12 * (-1 + x)) * y + (J21 * (-1 + y) + J22 * (-1 + x)) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[2,1] = numeric.gauss_2D_3(lambda x,y: ((J11 * (1 - y) - J12 * x) * y + (J21 * (1 - y) - J22 * x) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[2,2] = numeric.gauss_2D_3(lambda x,y: ((J11 * y + J12 * x) * y + (J21 * y + J22 * x) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[2,3] = numeric.gauss_2D_3(lambda x,y: ((-J11 * y + J12 * (1 - x)) * y + (-J21 * y + J22 * (1 - x)) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[3,0] = numeric.gauss_2D_3(lambda x,y: (-(J11 * (-1 + y) + J12 * (-1 + x)) * y + (J21 * (-1 + y) + J22 * (-1 + x)) * (1 - x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[3,1] = numeric.gauss_2D_3(lambda x,y: (-(J11 * (1 - y) - J12 * x) * y + (J21 * (1 - y) - J22 * x) * (1 - x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[3,2] = numeric.gauss_2D_3(lambda x,y: (-(J11 * y + J12 * x) * y + (J21 * y + J22 * x) * (1 - x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2[3,3] = numeric.gauss_2D_3(lambda x,y: (-(-J11 * y + J12 * (1 - x)) * y + (-J21 * y + J22 * (1 - x)) * (1 - x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))) K_r2 = 1./ abs(dJ_r) * K_r2; #print(K_r-K_r2) return K_r2
def _calculate_K_r(x1, x2, x4, y1, y2, y4, eps): """ _calculate_K_r """ J_r = np.array([[x2 - x1, x4 - x1], [y2 - y1, y4 - y1]]) dJ_r = np.linalg.det(J_r) J11 = (y4 - y1)**2 + (-x4 + x1)**2 J12 = (y4 - y1) * (-y2 + y1) + (-x4 + x1) * (x2 - x1) J21 = (y4 - y1) * (-y2 + y1) + (-x4 + x1) * (x2 - x1) J22 = (-y2 + y1)**2 + (x2 - x1)**2 # K_r = np.zeros(shape=(4,4)) #remove constants? # K_r[0,0] = 1/3. * J11 + 1/4. * J12 + 1/4. *J21 + 1/3.*J22 # K_r[0,1] = -1/3. * J11 + 1/4. * J12 - 1/4. * J21 + 1/6.*J22 # K_r[0,2] = -1/6. * J11 - 1/4. * J12 - 1/4. * J21 - 1/6.* J22 # K_r[0,3] = 1/6. *J11 - 1/4.*J12 + 1/4. *J21 - 1/3. *J22 # K_r[1,0] = -1/3.*J11 - 1/4.*J12 + 1/4.*J21 + 1/6.*J22 # K_r[1,1] = 1/3.*J11 - 1/4.*J12 - 1/4.*J21 + 1/3.*J22 # K_r[1,2] = 1/6. *J11 + 1/4.*J12 - 1/4.*J21 - 1/3.*J22 # K_r[1,3] = -1/6.*J11 + 1/4.*J12 + 1/4.*J21 - 1/6.*J22 # K_r[2,0] = -1/6.*J11-1/4.*J12 -1/4.*J21 - 1/6.*J22 # K_r[2,1] = 1/6.*J11-1/4.*J12+1/4.*J21 - 1/3.*J22 # K_r[2,2] = 1/3.*J11 + 1/4.*J12 + 1/4.*J21 + 1/3.*J22 # K_r[2,3] = -1/3.*J11 + 1/4.*J12 - 1/4.*J21 + 1/6.*J22 # K_r[3,0] = 1/6.*J11 + 1/4.*J12-1/4.*J21 - 1/3.*J22 # K_r[3,1] = -1/6.*J11 + 1/4.*J12+1/4.*J21 - 1/6.*J22 # K_r[3,2] = -1/3.*J11 - 1/4.*J12 + 1/4.*J21 + 1/6.*J22 # K_r[3,3] = 1/3.*J11 -1/4.*J12 - 1/4.*J21 + 1/3.*J22 # K_r = 1 * abs(dJ_r)/ (dJ_r**2) * K_r; K_r2 = np.zeros(shape=(4, 4)) #for numeric #K_r2[0,0] = numeric.gauss_2D_3(lambda x,y: ((J11 * (-1 + y) + J12 * (-1 + x)) * (-1 + y) + (J21 * (-1 + y) + J22 * (-1 + x)) * (-1 + x))) #eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x,y))) K_r2[0, 0] = numeric.gauss_2D_3(lambda x, y: ((J11 * (-1 + y) + J12 * ( -1 + x)) * (-1 + y) + (J21 * (-1 + y) + J22 * (-1 + x)) * ( -1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[0, 1] = numeric.gauss_2D_3(lambda x, y: ( (J11 * (1 - y) - J12 * x) * (-1 + y) + (J21 * (1 - y) - J22 * x) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[0, 2] = numeric.gauss_2D_3(lambda x, y: ( (J11 * y + J12 * x) * (-1 + y) + (J21 * y + J22 * x) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[0, 3] = numeric.gauss_2D_3(lambda x, y: ( (-J11 * y + J12 * (1 - x)) * (-1 + y) + (-J21 * y + J22 * (1 - x)) * (-1 + x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[1, 0] = numeric.gauss_2D_3(lambda x, y: ((J11 * (-1 + y) + J12 * ( -1 + x)) * (1 - y) - (J21 * (-1 + y) + J22 * (-1 + x)) * x) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[1, 1] = numeric.gauss_2D_3(lambda x, y: ( (J11 * (1 - y) - J12 * x) * (1 - y) - (J21 * (1 - y) - J22 * x) * x ) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[1, 2] = numeric.gauss_2D_3(lambda x, y: ( (J11 * y + J12 * x) * (1 - y) - (J21 * y + J22 * x) * x) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[1, 3] = numeric.gauss_2D_3(lambda x, y: ( (-J11 * y + J12 * (1 - x)) * (1 - y) - (-J21 * y + J22 * ( 1 - x)) * x) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[2, 0] = numeric.gauss_2D_3(lambda x, y: ((J11 * (-1 + y) + J12 * ( -1 + x)) * y + (J21 * (-1 + y) + J22 * (-1 + x)) * x) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[2, 1] = numeric.gauss_2D_3(lambda x, y: ( (J11 * (1 - y) - J12 * x) * y + (J21 * (1 - y) - J22 * x) * x) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[2, 2] = numeric.gauss_2D_3( lambda x, y: ((J11 * y + J12 * x) * y + (J21 * y + J22 * x) * x) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[2, 3] = numeric.gauss_2D_3(lambda x, y: ( (-J11 * y + J12 * (1 - x)) * y + (-J21 * y + J22 * (1 - x)) * x) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[3, 0] = numeric.gauss_2D_3(lambda x, y: (-(J11 * (-1 + y) + J12 * ( -1 + x)) * y + (J21 * (-1 + y) + J22 * (-1 + x)) * (1 - x)) * eps( _ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[3, 1] = numeric.gauss_2D_3(lambda x, y: ( -(J11 * (1 - y) - J12 * x) * y + (J21 * (1 - y) - J22 * x) * (1 - x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[3, 2] = numeric.gauss_2D_3( lambda x, y: (-(J11 * y + J12 * x) * y + (J21 * y + J22 * x) * (1 - x) ) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2[3, 3] = numeric.gauss_2D_3(lambda x, y: ( -(-J11 * y + J12 * (1 - x)) * y + (-J21 * y + J22 * (1 - x)) * (1 - x)) * eps(_ref_to_global(x1, x2, x4, y1, y2, y4, (x, y)))) K_r2 = 1. / abs(dJ_r) * K_r2 #print(K_r-K_r2) return K_r2
1] * y - y1 * u[2] * y + y1 * u[3] * y + y2 * u[0] - y2 * u[0] * x + y2 * u[1] * x - y2 * u[2] * x - y2 * u[3] + y2 * u[ 3] * x + y1 * u[0] * x - y1 * u[1] * x + y1 * u[ 2] * x + y1 * u[3] - y1 * u[3] * x)**2 + (-x4 * u[0] + x4 * u[0] * y + x4 * u[1] - x4 * u[1] * y + x4 * u[2] * y - x4 * u[3] * y - x1 * u[0] * y - x1 * u[1] + x1 * u[ 1] * y - x1 * u[2] * y + x1 * u[3] * y + x2 * u[0] - x2 * u[0] * x + x2 * u[1] * x - x2 * u[2] * x - x2 * u[3] + x2 * u[ 3] * x + x1 * u[0] * x - x1 * u[1] * x + x1 * u[ 2] * x + x1 * u[3] - x1 * u[3] * x)**2) energy_i = 0 if True: #x1 >= 25 and x2 <= 57 and y1 >= 27 and y4 <= 33: #only between electrodes #if x1 >= 25 and x2 <= 57 and y1 >= 19 and y4 <= 23: #only between electrodes energy_i = adJ_r / dJ_r**2 * numeric.gauss_2D_3(integrand) #print([x1, x2, y1, y4]) #print(energy_i) #integrand = lambda x,y: eps*(u1**2*g1(x,y) + u2**2*g2(x,y) + u3**2*g3(x,y) + u4**2*g4(x,y) ) #wrong...:( energies[r, 0] = energy_i #if x1 >= 25 and x2 <= 57 and y1 >= 19 and y4 <= 23: #only between electrodes # energy += adJ_r/dJ_r**2 * numeric.gauss_2D_3(integrand) #print(adJ_r/dJ_r**2 * numeric.gauss_2D_3(integrand)) energy += energy_i C_ = energy / (1 - (-1))**2
#divide bei 1/detJ^2 #integrand = lambda xi: eps*(u1**2*g1(xi[0],xi[1])) + u2**2*g2(xi[0],xi[1]) + u3**2*g3(xi[0],xi[1]) + u4**2*g4(xi[0],xi[1]) ) #integrand = lambda x,y: eps*(u1**2*g1(x,y) + u2**2*g2(x,y) + u3**2*g3(x,y) + u4**2*g4(x,y) ) #integrand = lambda x,y: eps* ( ((y4-y1)*(u1*(-1+y)+u2*(1-y)+u3*y-u4*y)+(y1-y2)*(u1*(x-1)-u2*x+u3*x+u4*(1-x)))**2+((x1-x4)*(u1*(y-1)+u2*(1-y)+u3*y-u4*y)+(x2-x1)*(u1*(x-1)-u2*x+u3*x+u4*(1-x))))**2 ) u = [u1, u2, u3, u4] integrand = lambda x,y: fem.eps(assembly._ref_to_global(x1, x2, x4, y1, y2, y4, (x,y)))*((-y4 * u[0] + y4 * u[0] * y + y4 * u[1] - y4 * u[1] * y + y4 * u[2] * y - y4 * u[3] * y - y1 * u[0] * y - y1 * u[1] + y1 * u[1] * y - y1 * u[2] * y + y1 * u[3] * y + y2 * u[0] - y2 * u[0] * x + y2 * u[1] * x - y2 * u[2] * x - y2 * u[3] + y2 * u[3] * x + y1 * u[0] * x - y1 * u[1] * x + y1 * u[2] * x + y1 * u[3] - y1 * u[3] * x)**2 + (-x4 * u[0] + x4 * u[0] * y + x4 * u[1] - x4 * u[1] * y + x4 * u[2] * y - x4 * u[3] * y - x1 * u[0] * y - x1 * u[1] + x1 * u[1] * y - x1 * u[2] * y + x1 * u[3] * y + x2 * u[0] - x2 * u[0] * x + x2 * u[1] * x - x2 * u[2] * x - x2 * u[3] + x2 * u[3] * x + x1 * u[0] * x - x1 * u[1] * x + x1 * u[2] * x + x1 * u[3] - x1 * u[3] * x)**2) energy_i = 0 if True:#x1 >= 25 and x2 <= 57 and y1 >= 27 and y4 <= 33: #only between electrodes #if x1 >= 25 and x2 <= 57 and y1 >= 19 and y4 <= 23: #only between electrodes energy_i = adJ_r/dJ_r**2 * numeric.gauss_2D_3(integrand) #print([x1, x2, y1, y4]) #print(energy_i) #integrand = lambda x,y: eps*(u1**2*g1(x,y) + u2**2*g2(x,y) + u3**2*g3(x,y) + u4**2*g4(x,y) ) #wrong...:( energies[r,0] = energy_i #if x1 >= 25 and x2 <= 57 and y1 >= 19 and y4 <= 23: #only between electrodes # energy += adJ_r/dJ_r**2 * numeric.gauss_2D_3(integrand) #print(adJ_r/dJ_r**2 * numeric.gauss_2D_3(integrand)) energy += energy_i