Skip to content

Commit

Permalink
black reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
TchilDill committed Apr 10, 2023
1 parent 32235b8 commit f744cbd
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 217 deletions.
91 changes: 56 additions & 35 deletions src/openpile/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ def get_soil_properties(self) -> pd.DataFrame:

def _postinit(self):
def check_springs(arr):
check_nan = np.isnan(arr).any()
check_negative = (arr < 0).any()
return check_nan or check_negative
check_nan = np.isnan(arr).any()
check_negative = (arr < 0).any()

return check_nan or check_negative

def get_coordinates() -> pd.DataFrame:
# Primary discretisation over x-axis
x = np.array([], dtype=np.float16)
Expand Down Expand Up @@ -766,14 +766,14 @@ def create_springs() -> np.ndarray:
# py curve
if layer.lateral_model is None:
pass
else:
else:
# Set local layer parameters for each element of the layer
for i in elements_for_layer:
# vertical effective stress
sig_v = self.soil_properties[
["sigma_v top [kPa]", "sigma_v bottom [kPa]"]
].iloc[i]
# elevation
# elevation
elevation = self.soil_properties[["x_top [m]", "x_bottom [m]"]].iloc[i]
# depth from ground
depth_from_ground = (
Expand All @@ -783,7 +783,9 @@ def create_springs() -> np.ndarray:
pile_width = self.element_properties["Diameter [m]"].iloc[i]

# p-y curves
if layer.lateral_model.spring_signature[0] and self.distributed_lateral: # True if py spring function exist
if (
layer.lateral_model.spring_signature[0] and self.distributed_lateral
): # True if py spring function exist

# calculate springs (top and) for each element
for j in [0, 1]:
Expand All @@ -798,7 +800,9 @@ def create_springs() -> np.ndarray:
output_length=spring_dim,
)

if layer.lateral_model.spring_signature[2] and self.distributed_moment: # True if mt spring function exist
if (
layer.lateral_model.spring_signature[2] and self.distributed_moment
): # True if mt spring function exist

# calculate springs (top and) for each element
for j in [0, 1]:
Expand All @@ -813,60 +817,77 @@ def create_springs() -> np.ndarray:
output_length=spring_dim,
)

#check if pile tip is within layer
if layer.top >= self.pile.bottom_elevation and layer.bottom <= self.pile.bottom_elevation:
# check if pile tip is within layer
if (
layer.top >= self.pile.bottom_elevation
and layer.bottom <= self.pile.bottom_elevation
):

#Hb curve
# Hb curve
sig_v_tip = self.soil_properties["sigma_v bottom [kPa]"].iloc[-1]

if layer.lateral_model.spring_signature[1] and self.base_shear:
if layer.lateral_model.spring_signature[1] and self.base_shear:

# calculate Hb spring
(Hb[0, 0, 0], Hb[0, 0, 1]) = layer.lateral_model.Hb_spring_fct(
sig=sig_v_tip,
X=self.pile.bottom_elevation,
layer_height=(layer.top - layer.bottom),
depth_from_top_of_layer=(layer.top - self.pile.bottom_elevation),
depth_from_top_of_layer=(
layer.top - self.pile.bottom_elevation
),
D=pile_width,
L=(self.soil.top_elevation - self.pile.bottom_elevation),
below_water_table=self.pile.bottom_elevation <= self.soil.water_elevation,
below_water_table=self.pile.bottom_elevation
<= self.soil.water_elevation,
output_length=spring_dim,
)
#Mb curve
if layer.lateral_model.spring_signature[3] and self.base_moment:

# Mb curve
if layer.lateral_model.spring_signature[3] and self.base_moment:

(Mb[0, 0, 0], Mb[0, 0, 1]) = layer.lateral_model.Mb_spring_fct(
sig=sig_v_tip,
X=self.pile.bottom_elevation,
layer_height=(layer.top - layer.bottom),
depth_from_top_of_layer=(layer.top - self.pile.bottom_elevation),
depth_from_top_of_layer=(
layer.top - self.pile.bottom_elevation
),
D=pile_width,
L=(self.soil.top_elevation - self.pile.bottom_elevation),
below_water_table=self.pile.bottom_elevation <= self.soil.water_elevation,
below_water_table=self.pile.bottom_elevation
<= self.soil.water_elevation,
output_length=spring_dim,
)

if check_springs(py):
print('py springs have negative or NaN values.')
print("""if using PISA type springs, this can be due to parameters behind out of the parameter space.
print("py springs have negative or NaN values.")
print(
"""if using PISA type springs, this can be due to parameters behind out of the parameter space.
Please check that: 2 < L/D < 6.
""")
"""
)
if check_springs(mt):
print('mt springs have negative or NaN values.')
print("""if using PISA type springs, this can be due to parameters behind out of the parameter space.
print("mt springs have negative or NaN values.")
print(
"""if using PISA type springs, this can be due to parameters behind out of the parameter space.
Please check that: 2 < L/D < 6.
""")
"""
)
if check_springs(Hb):
print('Hb spring has negative or NaN values.')
print("""if using PISA type springs, this can be due to parameters behind out of the parameter space.
print("Hb spring has negative or NaN values.")
print(
"""if using PISA type springs, this can be due to parameters behind out of the parameter space.
Please check that: 2 < L/D < 6.
""")
"""
)
if check_springs(Mb):
print('Mb spring has negative or NaN values.')
print("""if using PISA type springs, this can be due to parameters behind out of the parameter space.
print("Mb spring has negative or NaN values.")
print(
"""if using PISA type springs, this can be due to parameters behind out of the parameter space.
Please check that: 2 < L/D < 6.
""")
"""
)
return py, mt, Hb, Mb, tz

# creates mesh coordinates
Expand Down Expand Up @@ -1237,7 +1258,7 @@ def py_springs(self) -> pd.DataFrame:
Returns
-------
pd.DataFrame
Table with p-y springs.
Table with p-y springs.
"""
return misc.get_springs(
springs=self._py_springs,
Expand All @@ -1253,6 +1274,6 @@ def embedment(self) -> float:
Returns
-------
float
Pile embedment
Pile embedment
"""
return (self.soil.top_elevation - self.pile.bottom_elevation)
return self.soil.top_elevation - self.pile.bottom_elevation
30 changes: 17 additions & 13 deletions src/openpile/core/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ def elem_mt_stiffness_matrix(model, u, kind):
d = model.element_properties["Diameter [m]"].to_numpy(dtype=float).reshape((-1, 1, 1))
wt = model.element_properties["Wall thickness [m]"].to_numpy(dtype=float).reshape((-1, 1, 1))


# calculate shear component in stiffness matrix (if Timorshenko)
if model.element_type == "EulerBernoulli":
N = 0 * L
Expand All @@ -423,14 +422,18 @@ def elem_mt_stiffness_matrix(model, u, kind):

else:
raise ValueError("Timoshenko beams cannot be used yet for non-circular pile types")
phi = (12*omega+1)**2

phi = (12 * omega + 1) ** 2

N = 0 * L
A = 6 * (120*omega**2 + 20*omega + 1) / ((5 * L) * phi) + 12*I / ( A * L**3 * phi)
B = 1 / (10 * phi) + 6*I / ( A*L**2 * phi)
C = (2 * L * (90*omega**2 + 15*omega +1) ) / ( 15 * phi ) + 4*I*(36*omega**2 + 6*omega + 1)/(A*L*phi)
D = - L * (360*omega**2 + 60*omega + 1) / (30 * phi) - 2*I*(72*omega**2 + 12*omega - 1)/(A*L*phi)
A = 6 * (120 * omega**2 + 20 * omega + 1) / ((5 * L) * phi) + 12 * I / (A * L**3 * phi)
B = 1 / (10 * phi) + 6 * I / (A * L**2 * phi)
C = (2 * L * (90 * omega**2 + 15 * omega + 1)) / (15 * phi) + 4 * I * (
36 * omega**2 + 6 * omega + 1
) / (A * L * phi)
D = -L * (360 * omega**2 + 60 * omega + 1) / (30 * phi) - 2 * I * (
72 * omega**2 + 12 * omega - 1
) / (A * L * phi)

else:
raise ValueError(
Expand Down Expand Up @@ -569,9 +572,9 @@ def struct_internal_force(model, u) -> np.ndarray:
elif model.distributed_moment:
k += elem_mt_stiffness_matrix(model, u, kind)
elif model.base_shear:
k[-1,-2,-2] += calculate_base_spring_stiffness(u[-2], model._Hb_spring, kind)
k[-1, -2, -2] += calculate_base_spring_stiffness(u[-2], model._Hb_spring, kind)
elif model.base_moment:
k[-1,-1,-1] += calculate_base_spring_stiffness(u[-1], model._Mb_spring, kind)
k[-1, -1, -1] += calculate_base_spring_stiffness(u[-1], model._Mb_spring, kind)

# create array u of shape [n_elem x 6 x 1]
u = global_dof_vector_to_consistent_stacked_array(u, ndof_per_node * node_per_element)
Expand Down Expand Up @@ -599,7 +602,7 @@ def calculate_base_spring_stiffness(
Returns
-------
k: float
secant or tangent stiffness for all elements.
secant or tangent stiffness for all elements.
"""

# displacemet with same dimension as spring
Expand Down Expand Up @@ -634,6 +637,7 @@ def calculate_base_spring_stiffness(

return k


@njit(cache=True)
def calculate_py_springs_stiffness(
u: np.ndarray, springs: np.ndarray, kind: Literal["initial", "secant", "tangent"]
Expand Down Expand Up @@ -776,11 +780,11 @@ def calculate_mt_springs_stiffness(
else:
m1 = np.interp(dt, t, m)
elif kind == "tangent":
dt = min(0.01*t[1], d[i, j, 0, 0])
if (d[i, j, 0, 0]-dt) > t[-1]:
dt = min(0.01 * t[1], d[i, j, 0, 0])
if (d[i, j, 0, 0] - dt) > t[-1]:
m0 = m[-1]
else:
m0 = np.interp(d[i, j, 0, 0]-dt, t, m)
m0 = np.interp(d[i, j, 0, 0] - dt, t, m)
if (d[i, j, 0, 0]) > t[-1]:
m1 = m[-1]
else:
Expand Down
30 changes: 14 additions & 16 deletions src/openpile/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,31 @@ def springs_to_df(springs: np.ndarray, elevations: np.ndarray, flag) -> pd.DataF
return springs_to_df(springs, elevations, flag=kind)




@njit(cache=True)
def conic(
x_u : float,
n : float,
k : float,
y_u : float,
output_length : int,
x_u: float,
n: float,
k: float,
y_u: float,
output_length: int,
):
# Create x vector with 10% extension
x = np.linspace(0,x_u,output_length-1).astype(np.float32)
x = np.append(x,1.1*x_u)
x = np.linspace(0, x_u, output_length - 1).astype(np.float32)
x = np.append(x, 1.1 * x_u)

a = 1-2*n
a = 1 - 2 * n

y = np.zeros((len(x)),dtype=np.float32)
y = np.zeros((len(x)), dtype=np.float32)

for i in range(len(x)):
if abs(x[i]-x_u) < 1e-4:
if abs(x[i] - x_u) < 1e-4:
y[i] = y_u
elif x[i] < x_u:
b = 2*n*x[i]/x_u - (1-n)*(1+x[i]*k/y_u)
c = x[i] * (k / y_u) * (1-n) - n * (x[i]**2 / x_u**2)
b = 2 * n * x[i] / x_u - (1 - n) * (1 + x[i] * k / y_u)
c = x[i] * (k / y_u) * (1 - n) - n * (x[i] ** 2 / x_u**2)

y[i] = y_u * 2*c / (-b + ( b**2 - 4*a*c)**0.5 )
y[i] = y_u * 2 * c / (-b + (b**2 - 4 * a * c) ** 0.5)
else:
y[i] = y_u

return x, y
return x, y
Loading

0 comments on commit f744cbd

Please sign in to comment.