Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions structuralcodes/sections/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ def calculate_strain_profile(
geom = self.section.geometry

# Collect loads in a numpy array
loads = np.array([n, my, mz])
loads = np.array([n, my, mz], dtype=float)

# Compute initial tangent stiffness matrix
stiffness_tangent, integration_data = (
Expand All @@ -1790,9 +1790,14 @@ def calculate_strain_profile(

# Calculate strain plane with Newton Rhapson Iterative method
num_iter = 0
strain = np.zeros(3, dtype=float)
residual = np.zeros(3, dtype=float)
converged = False
strain = np.zeros(3, dtype=float)

# Calculate the initial response and residuals. Note that the initial
# residual might be different from the applied loads if any initial
# strain is present
Comment on lines +1796 to +1798
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right observation! perfect

response = self.integrate_strain_profile(strain=strain).asarray()
residual = loads - response

residual_history = []
strain_history = []
Expand All @@ -1809,14 +1814,6 @@ def calculate_strain_profile(
if num_iter > max_iter:
break

# Calculate response and residuals
response = self.integrate_strain_profile(strain=strain).asarray()
residual = loads - response

# Append to history variables
residual_history.append(residual.copy())
strain_history.append(strain.copy())

if initial:
# Solve using the decomposed matrix
delta_strain = lu_solve((lu, piv), residual)
Expand All @@ -1829,14 +1826,22 @@ def calculate_strain_profile(
# Solve using the current tangent stiffness
delta_strain = np.linalg.solve(stiffness_tangent, residual)

# Update the strain
strain += delta_strain

# Calculate response and residuals
response = self.integrate_strain_profile(strain=strain).asarray()
residual = loads - response

# Append to history variables
residual_history.append(residual.copy())
strain_history.append(strain.copy())

# Check for convergence:
if np.linalg.norm(delta_strain) < tol:
converged = True
break

# Update the strain
strain += delta_strain

num_iter += 1

# Create the results object
Expand Down
Loading