Skip to content

Commit aa81d02

Browse files
author
ganansuan647
committed
feat: v0.1.0 modify all command Manager classes to singleton pattern, optimize command invocation logic, and update documentation
1 parent 400953b commit aa81d02

14 files changed

Lines changed: 392 additions & 180 deletions

docs/examples/Auto_new_tag.ipynb

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,38 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 1,
16+
"execution_count": 4,
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
20-
"# import OpenSeesPy and demo model\n",
20+
"# import OpenSeesPy and demo modElement\n",
2121
"import openseespy.opensees as ops\n",
2222
"from opsparser import OpenSeesParser\n",
2323
"from ArchBridge2 import ArchBridge2"
2424
]
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 2,
28+
"execution_count": 5,
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
3232
"# first hook all commands before your opensees code\n",
3333
"parser = OpenSeesParser(ops)\n",
3434
"parser.hook_all()\n",
3535
"\n",
36-
"# some else may have provided some code\n",
36+
"# some Elementse may have provided some code\n",
3737
"ArchBridge2()"
3838
]
3939
},
4040
{
4141
"cell_type": "markdown",
4242
"metadata": {},
4343
"source": [
44-
"### Challenge: Determining appropriate new tag values for model components\n",
44+
"### Challenge: Determining appropriate new tag values for modElement components\n",
4545
"\n",
4646
"- when you want to add some code after existing code, you may find it difficult to know which new tag to use\n",
47-
"- sometimes during parametric studies, change of elesize(occupying more tags) becomes problematic due to cascade effect\n",
47+
"- sometimes during parametric studies, change of Elementesize(occupying more tags) becomes problematic due to cascade effect\n",
4848
"\n",
4949
"Common approaches:\n",
5050
"1. Using large numbers (e.g., 10001, 20001) to avoid conflicts\n",
@@ -60,7 +60,7 @@
6060
},
6161
{
6262
"cell_type": "code",
63-
"execution_count": 3,
63+
"execution_count": 6,
6464
"metadata": {},
6565
"outputs": [
6666
{
@@ -75,21 +75,22 @@
7575
}
7676
],
7777
"source": [
78+
"from opsparser import OpenSeesCommand as Command\n",
7879
"# Example of adding a new node:\n",
79-
"nh = parser.handlers.Node\n",
80-
"print(nh.newtag) # in this case 242\n",
81-
"print(nh.newtag_upper) # in this case also 242\n",
80+
"Node = Command.NODE.instance\n",
81+
"print(Node.newtag) # in this case 242\n",
82+
"print(Node.newtag_upper) # in this case also 242\n",
8283
"\n",
8384
"# but what will happen after adding a new node?\n",
84-
"ops.node(nh.newtag+10, *[-1,-1,-1])\n",
85+
"ops.node(Node.newtag+10, *[-1,-1,-1])\n",
8586
"\n",
86-
"print(nh.newtag) # This value remains unchanged until you actually use ops.node(nh.newtag, *coords)\n",
87-
"print(nh.newtag_upper) # in this case not 242"
87+
"print(Node.newtag) # This value remains unchanged until you actually use ops.node(Node.newtag, *coords)\n",
88+
"print(Node.newtag_upper) # in this case not 242"
8889
]
8990
},
9091
{
9192
"cell_type": "code",
92-
"execution_count": 4,
93+
"execution_count": 7,
9394
"metadata": {},
9495
"outputs": [
9596
{
@@ -106,28 +107,28 @@
106107
}
107108
],
108109
"source": [
109-
"# and you can also get a list to build your model if you want, like:\n",
110+
"# and you can also get a list to build your modElement if you want, like:\n",
110111
"print(\"5 newtag list:\")\n",
111-
"for tag in nh.get_new_tags(5):\n",
112+
"for tag in Node.get_new_tags(5):\n",
112113
" # ops.node(tag,*coords)\n",
113114
" print(tag, end=\" \")\n",
114115
" \n",
115116
"print(\"\\n15 newtag list:\")\n",
116117
"# if it exceeds 11(252 is already used), it will start from 253\n",
117-
"for tag in nh.get_new_tags(15):\n",
118+
"for tag in Node.get_new_tags(15):\n",
118119
" # ops.node(tag,*coords)\n",
119120
" print(tag, end=\" \")\n",
120121
" \n",
121122
"# you can also put a large number before it(but your code should be more robust)\n",
122123
"print(\"\\n10 newtag list:\")\n",
123-
"for tag in nh.get_new_tags(10,start = 5000):\n",
124+
"for tag in Node.get_new_tags(10,start = 5000):\n",
124125
" # ops.node(tag,*coords)\n",
125126
" print(tag, end=\" \")"
126127
]
127128
},
128129
{
129130
"cell_type": "code",
130-
"execution_count": null,
131+
"execution_count": 8,
131132
"metadata": {},
132133
"outputs": [
133134
{
@@ -144,16 +145,16 @@
144145
}
145146
],
146147
"source": [
147-
"# similarliy, we have these property & method for elements and materials and so on\n",
148-
"eh = parser.handlers.Element\n",
149-
"print(eh.newtag)\n",
150-
"print(eh.newtag_upper)\n",
151-
"print(eh.get_new_tags(5))\n",
148+
"# similarliy, we have these property & method for Elementements and materials and so on\n",
149+
"Element = Command.ELEMENT.instance\n",
150+
"print(Element.newtag)\n",
151+
"print(Element.newtag_upper)\n",
152+
"print(Element.get_new_tags(5))\n",
152153
"\n",
153-
"mh = parser.handlers.Material\n",
154-
"print(mh.newtag)\n",
155-
"print(mh.newtag_upper)\n",
156-
"print(mh.get_new_tags(5))"
154+
"Material = Command.MATERIAL.instance\n",
155+
"print(Material.newtag)\n",
156+
"print(Material.newtag_upper)\n",
157+
"print(Material.get_new_tags(5))"
157158
]
158159
}
159160
],

docs/examples/Element_info.ipynb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {"nbsphinx": {
6-
"thumbnail": "../../_static/images/element.png"
7-
}},
5+
"metadata": {
6+
"nbsphinx": {
7+
"thumbnail": "../../_static/images/element.png"
8+
}
9+
},
810
"source": [
911
"## Node Coords & Mass"
1012
]
1113
},
1214
{
1315
"cell_type": "code",
14-
"execution_count": 2,
16+
"execution_count": 1,
1517
"metadata": {},
1618
"outputs": [],
1719
"source": [
@@ -25,7 +27,7 @@
2527
},
2628
{
2729
"cell_type": "code",
28-
"execution_count": 4,
30+
"execution_count": 2,
2931
"metadata": {},
3032
"outputs": [
3133
{
@@ -977,7 +979,7 @@
977979
},
978980
{
979981
"cell_type": "code",
980-
"execution_count": 5,
982+
"execution_count": 3,
981983
"metadata": {},
982984
"outputs": [
983985
{
@@ -4946,15 +4948,16 @@
49464948
}
49474949
],
49484950
"source": [
4951+
"from opsparser import OpenSeesCommand as Command\n",
49494952
"# element info\n",
4950-
"ele_dict = parser.handlers[\"Element\"].elements\n",
4953+
"Element = Command.ELEMENT.instance\n",
49514954
"\n",
4952-
"pprint(ele_dict)"
4955+
"pprint(Element.elements)"
49534956
]
49544957
},
49554958
{
49564959
"cell_type": "code",
4957-
"execution_count": null,
4960+
"execution_count": 4,
49584961
"metadata": {},
49594962
"outputs": [
49604963
{
@@ -4976,7 +4979,7 @@
49764979
],
49774980
"source": [
49784981
"# show only one element info\n",
4979-
"ele1 = ele_dict[1]\n",
4982+
"ele1 = Element.elements[1]\n",
49804983
"pprint(ele1)"
49814984
]
49824985
},
@@ -4989,7 +4992,7 @@
49894992
},
49904993
{
49914994
"cell_type": "code",
4992-
"execution_count": 8,
4995+
"execution_count": 5,
49934996
"metadata": {},
49944997
"outputs": [
49954998
{
@@ -5006,33 +5009,31 @@
50065009
}
50075010
],
50085011
"source": [
5009-
"eh = parser.handlers[\"Element\"]\n",
5010-
"\n",
50115012
"# by tag\n",
5012-
"ele = eh.get_element(eleTag = 10)\n",
5013+
"ele = Element.get_element(eleTag = 10)\n",
50135014
"print(f\"By eleTag 10: {ele = }\")\n",
50145015
"\n",
50155016
"# by 2 nodes(1 result)\n",
5016-
"ele = eh.get_elements_by_nodes(node_tags = [5, 6])\n",
5017+
"ele = Element.get_elements_by_nodes(node_tags = [5, 6])\n",
50175018
"print(f\"By node Tag [5, 6]: {ele = }\")\n",
50185019
"\n",
50195020
"# by one node(maybe more than 1 result)\n",
5020-
"ele = eh.get_elements_by_nodes(node_tags = [6])\n",
5021+
"ele = Element.get_elements_by_nodes(node_tags = [6])\n",
50215022
"print(f\"By node Tag [6]: {ele = }\")\n",
50225023
"\n",
50235024
"# by 3 or more node(no result here)\n",
5024-
"ele = eh.get_elements_by_nodes(node_tags = [6, 7, 8])\n",
5025+
"ele = Element.get_elements_by_nodes(node_tags = [6, 7, 8])\n",
50255026
"print(f\"By node Tag [6, 7, 8]: {ele = }\")\n",
50265027
"\n",
50275028
"# by Type (\"zerolength\", \"truss\", \"beamcolumn\", \"joint\", \"link\",\n",
50285029
" # \"bearing\", \"quadrilateral\", \"triangular\", \"brick\",\n",
50295030
" # \"tetrahedron\", \"ucsd_up\", \"other_up\", \"contact\",\n",
50305031
" # \"cable\", \"pfem\", \"misc\")\n",
5031-
"ele = eh.get_elements(Type = \"beamcolumn\") # you can try with other type\n",
5032+
"ele = Element.get_elements(Type = \"beamcolumn\") # you can try with other type\n",
50325033
"print(f\"By Type `beamcolumn` = {ele = }\")\n",
50335034
"\n",
50345035
"# by eleType (first argument(str) for ops.element(eleType, eleTag, eleArgs*))\n",
5035-
"ele = eh.get_elements_by_type(eleType = \"elasticBeamColumn\")\n",
5036+
"ele = Element.get_elements_by_type(eleType = \"elasticBeamColumn\")\n",
50365037
"print(f\"By Type `elasticBeamColumn` = {ele = }\")"
50375038
]
50385039
}
@@ -5057,7 +5058,7 @@
50575058
},
50585059
"nbsphinx": {
50595060
"thumbnail": "../_static/images/element.png"
5060-
}
5061+
}
50615062
},
50625063
"nbformat": 4,
50635064
"nbformat_minor": 2

docs/examples/Material_info.ipynb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {"nbsphinx": {
6-
"thumbnail": "../../_static/images/material.png"
7-
}},
5+
"metadata": {
6+
"nbsphinx": {
7+
"thumbnail": "../../_static/images/material.png"
8+
}
9+
},
810
"source": [
911
"## Node Coords & Mass"
1012
]
1113
},
1214
{
1315
"cell_type": "code",
14-
"execution_count": 18,
16+
"execution_count": 1,
1517
"metadata": {},
1618
"outputs": [],
1719
"source": [
@@ -25,7 +27,7 @@
2527
},
2628
{
2729
"cell_type": "code",
28-
"execution_count": 19,
30+
"execution_count": 2,
2931
"metadata": {},
3032
"outputs": [
3133
{
@@ -977,7 +979,7 @@
977979
},
978980
{
979981
"cell_type": "code",
980-
"execution_count": null,
982+
"execution_count": 3,
981983
"metadata": {},
982984
"outputs": [
983985
{
@@ -993,9 +995,11 @@
993995
}
994996
],
995997
"source": [
998+
"from opsparser import OpenSeesCommand as Command\n",
996999
"# material info\n",
997-
"material_dict = parser.handlers[\"Material\"].materials\n",
998-
"pprint(material_dict)"
1000+
"Material = Command.MATERIAL.instance\n",
1001+
"\n",
1002+
"pprint(Material.materials)"
9991003
]
10001004
},
10011005
{
@@ -1007,36 +1011,35 @@
10071011
},
10081012
{
10091013
"cell_type": "code",
1010-
"execution_count": 26,
1014+
"execution_count": 4,
10111015
"metadata": {},
10121016
"outputs": [
10131017
{
10141018
"name": "stdout",
10151019
"output_type": "stream",
10161020
"text": [
1017-
"nDMaterial: {'ElasticIsotropic', 'PlateFiber'}\n",
1021+
"nDMaterial: {'PlateFiber', 'ElasticIsotropic'}\n",
10181022
"uniaxialMaterial: {'Elastic'}\n",
10191023
"By Tag 2 : {'matType': 'Elastic', 'matTag': 2, 'E': 26000.0}\n",
10201024
"By Type `ElasticIsotropic`: {4: {'matType': 'ElasticIsotropic', 'matTag': 4, 'E': 26000, 'nu': 0.2}}\n"
10211025
]
10221026
}
10231027
],
10241028
"source": [
1025-
"mh = parser.handlers[\"Material\"]\n",
10261029
"# get material by type\n",
1027-
"nDMaterial_dict = mh.nDMaterial\n",
1028-
"uniaxialMaterial_dict = mh.uniaxialMaterial\n",
1030+
"nDMaterial_dict = Material.nDMaterial\n",
1031+
"uniaxialMaterial_dict = Material.uniaxialMaterial\n",
10291032
"\n",
10301033
"# print unique matType you have used\n",
10311034
"print(f\"nDMaterial: {set([mat['matType'] for mat in nDMaterial_dict.values()])}\")\n",
10321035
"print(f\"uniaxialMaterial: {set([mat['matType'] for mat in uniaxialMaterial_dict.values()])}\")\n",
10331036
"\n",
10341037
"# get material by Tag\n",
1035-
"mat = mh.get_material(matTag = 2)\n",
1038+
"mat = Material.get_material(matTag = 2)\n",
10361039
"print(f\"By Tag 2 : {mat}\")\n",
10371040
"\n",
10381041
"# by matType (first argument(str) for ops.XXmaterial(matType, matTag, matArgs*))\n",
1039-
"mat = mh.get_materials_by_type(matType=\"ElasticIsotropic\")\n",
1042+
"mat = Material.get_materials_by_type(matType=\"ElasticIsotropic\")\n",
10401043
"print(f\"By Type `ElasticIsotropic`: {mat}\")\n"
10411044
]
10421045
}
@@ -1061,7 +1064,7 @@
10611064
},
10621065
"nbsphinx": {
10631066
"thumbnail": "../_static/images/material.png"
1064-
}
1067+
}
10651068
},
10661069
"nbformat": 4,
10671070
"nbformat_minor": 2

0 commit comments

Comments
 (0)