Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with nonlinear problems when using MPhys wrapper #268

Merged
merged 51 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2101c7d
Add python interface for KSM `setOperators` method
A-CGray Oct 29, 2023
ec031bc
Pass new stiffness mat and preconditioner to nonlinear solver linear …
A-CGray Oct 29, 2023
9237f3e
Add MPhys version of nonlinear hemisphere shell test, not working yet
A-CGray Oct 30, 2023
fe9e9e4
Reduce mesh size in nonlinear mphys test
A-CGray Oct 30, 2023
d102f3d
Modifications to nonlinear mphys integration test, still failing
A-CGray Oct 30, 2023
3222433
Add "printLevel" to list of options that doesn't require recreating v…
A-CGray Oct 31, 2023
db2ae16
Fix the nonlinear mphys test (in real mode at least)
A-CGray Oct 31, 2023
37e605f
black formatting
A-CGray Oct 31, 2023
a5e8ad4
Add option for residual scaling to mphys builder
A-CGray Nov 29, 2023
de6c593
Add user facing method for writing solution through mphys interface
A-CGray Nov 29, 2023
fba372c
update test tolerance and ref values
A-CGray Nov 29, 2023
3299702
new hemisphere mesh
A-CGray Nov 29, 2023
a8a6e50
typo
A-CGray Nov 29, 2023
52c8dbe
Rename solution writing method
A-CGray Nov 29, 2023
beb5ff0
Fix bug in continuation solver recovery from failed inner solve
A-CGray Dec 20, 2023
f174380
Merge branch 'master' into fixNonlinearMPhys
A-CGray Feb 9, 2024
9d30ad5
Partial fix for check_totals issue (CS passes in serial now)
A-CGray Feb 10, 2024
c84414b
Small change to when analysis error is raised when solver fails
A-CGray Mar 14, 2024
9a2ab7a
Merge branch 'fixNonlinearMPhys' of github.com:smdogroup/tacs into fi…
A-CGray Mar 14, 2024
27a0960
Merge remote-tracking branch 'origin/master' into fixNonlinearMPhys
A-CGray May 22, 2024
7e20670
Add a global stiffener buckling failure criteria to `TACSBladeStiffen…
A-CGray May 31, 2024
207f157
Compute material failure at bottom of stiffener as well as top
A-CGray Jun 2, 2024
66fbc1a
convert pointers in function signatures to constant pointers
A-CGray Jun 2, 2024
0ae26b9
Formatting
A-CGray Jun 2, 2024
e33640b
Add stiffener crippling failure mode, no derivatives yet
A-CGray Jun 3, 2024
2e1ef61
Refactor crippling calculation
A-CGray Jun 4, 2024
fc03f82
Stiffener crippling strain sensitivity implemented and verified
A-CGray Jun 5, 2024
dc84ae0
crippling DV sensitivities work!
A-CGray Jun 7, 2024
639b3a1
Add ability to enable/disable different failure modes
A-CGray Jun 7, 2024
a534d68
Add a global stiffener buckling failure criteria to `TACSBladeStiffen…
A-CGray May 31, 2024
380ef29
Compute material failure at bottom of stiffener as well as top
A-CGray Jun 2, 2024
4579068
convert pointers in function signatures to constant pointers
A-CGray Jun 2, 2024
12562b3
Formatting
A-CGray Jun 2, 2024
0a9e2a7
Add stiffener crippling failure mode, no derivatives yet
A-CGray Jun 3, 2024
d082fee
Refactor crippling calculation
A-CGray Jun 4, 2024
f5023a3
Stiffener crippling strain sensitivity implemented and verified
A-CGray Jun 5, 2024
42b903e
crippling DV sensitivities work!
A-CGray Jun 7, 2024
0ddc1a5
Add ability to enable/disable different failure modes
A-CGray Jun 7, 2024
1961760
Move local and global panel buckling calculations into their own methods
A-CGray Jun 10, 2024
3fc4ecc
Remove unnecessary logic
A-CGray Jun 10, 2024
9705587
Move column buckling calculations to `evalStiffenerColumnBuckling` to…
A-CGray Jun 10, 2024
d27363c
Update integration test reference values
A-CGray Jun 11, 2024
9fb5e99
Merge branch 'bladeStiffenedShellImprovements' into fixNonlinearMPhys
A-CGray Jun 11, 2024
55e6212
Stop mphys buckling test writing out solution files
A-CGray Jun 17, 2024
86d9604
Revert "Partial fix for check_totals issue (CS passes in serial now)"
A-CGray Jun 17, 2024
388b25c
Add an option to force reset states before every static problem solve
A-CGray Jun 17, 2024
066e1d6
Reset states before every solve in nonlinear hemisphere mphys test
A-CGray Jun 17, 2024
696c6ff
Actually use the supplied initial state in the continuation solver
A-CGray Jun 17, 2024
577ffb8
Remove changes related to `BladeStiffenedShellConstitutive`
A-CGray Jun 18, 2024
fae7aac
Should've been in the last commit
A-CGray Jun 18, 2024
6edc314
Fix typo
A-CGray Jun 24, 2024
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
7 changes: 7 additions & 0 deletions tacs/TACS.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,13 @@ cdef class KSM:
self.ptr.decref()
return

def setOperators(self, Mat mat, Pc pc):
"""
Set the matrix and preconditioner operators
"""
self.ptr.setOperators(mat.ptr, pc.ptr)
return

def solve(self, Vec b, Vec x, int zero_guess=1):
"""
Try to solve the linear system using GMRES.
Expand Down
4 changes: 3 additions & 1 deletion tacs/mphys/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ def solve_nonlinear(self, inputs, outputs):
self.sp.writeSolution(baseName=f"{self.sp.name}-failed")
# TODO: In future we could add something here to distinguish between fatal failures and those that could be recovered from
self.sp.zeroVariables()
raise om.AnalysisError("TACS solver did not converge")

self.sp.getVariables(states=outputs[self.states_name])

if not hasConverged:
raise om.AnalysisError("TACS solver did not converge")

def solve_linear(self, d_outputs, d_residuals, mode):
if mode == "fwd":
if self.check_partials:
Expand Down
18 changes: 18 additions & 0 deletions tacs/problems/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class StaticProblem(TACSProblem):
defaultOptions = {
"outputDir": [str, "./", "Output directory for F5 file writer."],
# Solution Options
"resetBeforeSolve": [
bool,
False,
"Reset the states before every solve, this can be useful for avoiding issues when testing derivatives against finite-difference/complex-step",
],
"linearSolver": [
str,
"GMRES",
Expand Down Expand Up @@ -354,6 +359,16 @@ def _createVariables(self):
freq=opt("monitorFrequency"),
)

# Pass new matrix and preconditioner to nonlinear solver linear solvers
if self.nonlinearSolver is not None:
self.nonlinearSolver.linearSolver.setOperators(self.K, self.PC)
try:
self.nonlinearSolver.innerSolver.linearSolver.setOperators(
self.K, self.PC
)
except AttributeError:
pass

# Linear solver factor flag
self._jacobianUpdateRequired = True
self._preconditionerUpdateRequired = True
Expand Down Expand Up @@ -400,6 +415,7 @@ def setOption(self, name, value):
"printtiming",
"numbersolutions",
"outputdir",
"printLevel",
]:
createVariables = False

Expand Down Expand Up @@ -841,6 +857,8 @@ def solve(self, Fext=None):
self.callCounter += 1

# Set problem vars to assembler
if self.getOption("resetBeforeSolve"):
self.zeroVariables()
self._updateAssemblerVars()

# Check if we need to initialize
Expand Down
3 changes: 2 additions & 1 deletion tacs/solvers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def hasConverged(self) -> bool:
def fatalFailure(self) -> bool:
"""Whether the solver has failed, set as a property rather than an attribute so that it is read-only

Note that a fatalFailure is not the same as not converging, this flag is meant to reflect that there has been a fatal failure in the solver which requires a full reset
Note that a fatalFailure is not the same as not converging, this flag is meant to reflect that there has been a
fatal failure in the solver which requires a full reset
"""
return self._fatalFailure

Expand Down
8 changes: 3 additions & 5 deletions tacs/solvers/continuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ def solve(
USE_PREDICTOR = self.getOption("UsePredictor")
# PREDICTOR_USE_DERIVATIVE = self.getOption("predictorUseDerivative")

self.initializeSolve()

if u0 is not None:
self.stateVec.copyValues(u0)
self.initializeSolve(u0=u0)

# Compute the internal and external forcing vectors at the current point
self.computeForceVectors()
Expand Down Expand Up @@ -421,7 +418,8 @@ def continuationcallBack(solver, u, res, monitorVars):
loadStepDirection = 1
# If the inner solve failed then we'll reduce the step size and try again, unless we've hit the increment or step size limits
elif not isLastIncrement and stepSize > MIN_STEP:
self.setStateFunc(self.incStartState)
self.stateVec.copyValues(self.incStartState)
self.setStateFunc(self.stateVec)
currentLambda -= stepSize * loadStepDirection
self.setLambdaFunc(currentLambda)
stepSize *= STEP_RETRACT_FACTOR
Expand Down
37 changes: 29 additions & 8 deletions tests/constitutive_tests/test_composite_shell_constitutive.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def setUp(self):
self.ply_thicknesses = np.array([ply_thickness] * nplies, dtype=self.dtype)
self.ply_angles = np.array([0.0, -45.0, 90.0], dtype=self.dtype) * DEG2RAD
# Distance between mid-plane and reference plane (nodes) of shell
self.tOffset = 0.5 # This places the nodes at the top ply
self.tOffset = 0.5 # This places the nodes at the top ply

# Seed random number generator in tacs for consistent test results
elements.SeedRandomGenerator(0)
Expand All @@ -102,7 +102,10 @@ def test_constitutive_density(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveDensity(
con,
Expand All @@ -122,7 +125,10 @@ def test_constitutive_specific_heat(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveSpecificHeat(
con,
Expand All @@ -142,7 +148,10 @@ def test_constitutive_heat_flux(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveHeatFlux(
con,
Expand All @@ -162,7 +171,10 @@ def test_constitutive_stress(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveStress(
con,
Expand All @@ -182,7 +194,10 @@ def test_constitutive_thermal_strain(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveThermalStrain(
con,
Expand All @@ -202,7 +217,10 @@ def test_constitutive_failure(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveFailure(
con,
Expand All @@ -221,7 +239,10 @@ def test_constitutive_failure_strain_sens(self):
for layup in self.layup_list:
with self.subTest(layup=layup):
con = constitutive.CompositeShellConstitutive(
layup, self.ply_thicknesses, self.ply_angles, tOffset=self.tOffset,
layup,
self.ply_thicknesses,
self.ply_angles,
tOffset=self.tOffset,
)
fail = constitutive.TestConstitutiveFailureStrainSens(
con,
Expand Down
4 changes: 3 additions & 1 deletion tests/constitutive_tests/test_iso_shell_constitutive.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def setUp(self):
)

# Create stiffness (need class)
self.con = constitutive.IsoShellConstitutive(self.props, t=1.0, tNum=0, tOffset=-0.5)
self.con = constitutive.IsoShellConstitutive(
self.props, t=1.0, tNum=0, tOffset=-0.5
)

# Seed random number generator in tacs for consistent test results
elements.SeedRandomGenerator(0)
Expand Down
Loading
Loading