v0.15.0
Loading...
Searching...
No Matches
objective_function.py
Go to the documentation of this file.
1import math
2import numpy as np
3from numpy.polynomial.legendre import legval
4
5def f(coords, u, stress, strain):
6 energy = 0.5*((strain*stress).sum(axis=0)) + 20*np.ones(stress.shape[1])
7 return energy;
8
9def f_stress(coords, u, stress, strain):
10 return 0.5*strain
11
12def f_strain(coords, u, stress, strain):
13 return 0.5*stress
14
15def f_u(coords, u, stress, strain):
16 return np.zeros(u.shape)
17
18def number_of_modes(block_id):
19 return 1
20
21def block_modes(block_id, coords, cenytroid, bbox):
22 # print ("block_modes: block_id ", block_id)
23 # print ("block_modes: coords ", coords)
24 # print ("block_modes: centroid ", cenytroid)
25 # print ("block_modes: bbox ", bbox)
26
27 nb_points = coords.shape[0]
28 M = np.zeros((number_of_modes(block_id), nb_points, 3))
29 x0 = coords[:, 0]
30 y0 = coords[:, 1]
31
32 x = x0 - cenytroid[0]
33 y = y0 - cenytroid[1]
34 r = np.sqrt(x*x + y*y)
35
36 for i in range(number_of_modes(block_id)):
37 ksi = x/r
38 coeffs = np.zeros(i+1)
39 coeffs[-1] = 1
40 l = legval(ksi, coeffs)
41 n = -l*(ksi+1)*(ksi-1)*np.sign(y)
42 M[i] = np.array([np.zeros(nb_points), n, np.zeros(nb_points)]).T
43
44 return M
block_modes(block_id, coords, cenytroid, bbox)
f_u(coords, u, stress, strain)
f_strain(coords, u, stress, strain)
f(coords, u, stress, strain)
f_stress(coords, u, stress, strain)