Skip to content

Commit

Permalink
Merge pull request #1 from claudioperez/update
Browse files Browse the repository at this point in the history
cmp - add `OpenSeesError`, clean `getTangent`
  • Loading branch information
claudioperez authored Apr 28, 2024
2 parents 66b9369 + 263ae07 commit 49f13d3
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 147 deletions.
Binary file added notebooks/IncrementalAnalysis/7920.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
335 changes: 209 additions & 126 deletions notebooks/IncrementalAnalysis/IncrementalAnalysis.ipynb

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions notebooks/IncrementalAnalysis/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
def arch_model():

# Define model parameters
L = 5000
Rise = 500
L = 5000
Rise = 500
Offset = 200

# Define material parameters
Expand All @@ -28,7 +28,7 @@ def arch_model():
ne = 10
nen = 2
nn = ne*(nen-1)+1
mid = (nn+1)//2 # midpoint node
mid = (nn+1)//2 # midpoint node

for i, angle in enumerate(np.linspace(-th/2, th/2, nn)):
tag = i + 1
Expand Down Expand Up @@ -63,6 +63,16 @@ def arch_model():
# Add a nodal load to the pattern
model.load(mid, 0.0, -1.0, 0.0, pattern=1)


model.system("ProfileSPD")
# model.system("FullGeneral")
# model.system("BandGeneral")
# model.system("Umfpack", det=True)

model.test("NormUnbalance", 1e-6, 25, 0)
model.algorithm("Newton")
model.analysis("Static")


return model, mid

Expand Down
3 changes: 2 additions & 1 deletion notebooks/IncrementalAnalysis/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
imageio[ffmpeg]
# imageio[ffmpeg]
opensees
sees
mdof
SciencePlots
nbconvert[webpdf]

2 changes: 1 addition & 1 deletion src/libg3
Submodule libg3 updated 485 files
40 changes: 24 additions & 16 deletions src/opensees/openseespy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
# from this module. All of these are dynamically
# resolved by the function __getattr__ below.
__all__ = [
#
"tcl"
"OpenSeesError"

# OpenSeesPy attributes
"uniaxialMaterial",
"testUniaxialMaterial",
"setStrain",
Expand Down Expand Up @@ -232,33 +237,38 @@
"partition",
"pressureConstraint",
"domainCommitTag",
"runFOSMAnalysis",
# "runFOSMAnalysis",
"findDesignPoint",
"runFORMAnalysis",
"getLSFTags",
"runImportanceSamplingAnalysis",
"IGA",
"NDTest",

"tcl"
]

def _as_str_arg(arg):
class OpenSeesError(Exception):
pass

def _as_str_arg(arg, name: str = None):
"""
Convert arg to a string that represents
Tcl semantics.
"""
if isinstance(arg, list):
return f"{{{' '.join(_as_str_arg(a) for a in arg)}}}"

elif isinstance(arg, bool):
return str(int(arg))
# elif isinstance(arg, bool):
# if name is None:
# return str(int(arg))
# else:
# return f"-{name.replace('_','-')}"

elif isinstance(arg, dict):
return "{\n" + "\n".join([
f"{cmd} " + " ".join(_as_str_arg(a) for a in val)
for cmd, val in kwds
]) + "}"
]) + "}"

else:
return str(arg)

Expand Down Expand Up @@ -293,18 +303,19 @@ def _str_call(self, proc_name: str, *args, **kwds)->str:
strings.
"""

tcl_args = [_as_str_arg(i) for i in args]
tcl_args += [
f"-{key} " + _as_str_arg(val)
tcl_args = (_as_str_arg(i) for i in args)
tcl_kwds = (
(f"-{key.replace('_','-')}" if val else "") if isinstance(val, bool)
else f"-{key} " + _as_str_arg(val)
for key, val in kwds.items()
]
cmd = f"{proc_name} " + " ".join(tcl_args)
)
cmd = f"{proc_name} {' '.join(tcl_args)} {' '.join(tcl_kwds)}"

# TODO: make sure errors print nicely
try:
ret = self.eval(cmd)
except Exception as e:
raise e
raise OpenSeesError() from e

if ret is None or ret == "":
return None
Expand Down Expand Up @@ -421,10 +432,7 @@ def getResidual(self):

def getTangent(self):
import numpy as np
# TODO
# self._openseespy.eval("system FullGeneral")
A = np.array(self._openseespy._str_call("printA", "-ret"))
# self._openseespy.eval("system ProfileSPD")
return A.reshape([int(np.sqrt(len(A)))]*2)

def __getattr__(self, name: str):
Expand Down

0 comments on commit 49f13d3

Please sign in to comment.