midas-civil 0.0.8__py3-none-any.whl → 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of midas-civil might be problematic. Click here for more details.

@@ -0,0 +1,415 @@
1
+ from ._mapi import *
2
+
3
+ class CS:
4
+
5
+ CSA = []
6
+
7
+ def __init__(self,
8
+ name: str,
9
+ duration: float = 0,
10
+ s_group: str = None,
11
+ s_age: float = None,
12
+ s_type: str= None,
13
+ b_group: str = None,
14
+ b_pos: str = None,
15
+ b_type: str = None,
16
+ l_group: str = None,
17
+ l_day: str = None,
18
+ l_type: str = None,
19
+ id: int = None,
20
+ sr_stage: bool = True,
21
+ ad_stage: bool = False,
22
+ load_in: bool = False,
23
+ nl: int = 5,
24
+ addstp: list = None):
25
+ """
26
+ Construction Stage define.
27
+
28
+ Parameters:
29
+ name: Name of Construction Stage
30
+ duration: Duration of Construction Stage in days (default 0)
31
+ s_group: Structure group name or list of group names (default None)
32
+ s_age: Age of structure group in days and Redistribution value(%) win case of Deactivation (default 0)
33
+ s_type: Structure activation type - "A" to activate, "D" to deactivate(default A)
34
+ b_group: Boundary group name or list of group names (default None)
35
+ b_pos: Boundary position type - "ORIGINAL" or "DEFORMED", or list (default DEFORMED)
36
+ b_type: Boundary activation type - "A" to activate, "D" to deactivate (default A)
37
+ l_group: Load group name or list of group names (default None)
38
+ l_day: Load activation day - "FIRST" or "LAST" (default "FIRST")
39
+ l_type: Load activation type - "A" to activate, "D" to deactivate (default A)
40
+ id: The construction stage ID (optional)
41
+ sr_stage: Save results of this stage (default True)
42
+ ad_stage: Add additional step results (default False)
43
+ load_in: Load incremental steps for material nonlinear analysis (default False)
44
+ nl: Number of load incremental steps (default 5)
45
+ addstp: List of additional steps (default None)
46
+
47
+ Examples:
48
+ ```python
49
+ # Single group activation
50
+ CS("CS1", 7, "S1", 7, "A", "B1", "DEFORMED", "A", "L1", "FIRST", "A")
51
+
52
+ # Multiple group activation
53
+ CS("CS1", 7, ["S1", "S2"], [7, 10], ["A", "A"], ["B1", "B2"],
54
+ ["DEFORMED", "DEFORMED"], ["A", "A"], ["L1", "L2"], ["FIRST", "FIRST"], ["A", "A"])
55
+
56
+ # Mixed activation and deactivation
57
+ CS("CS1", 7, ["S1", "S2"], [7, 10], ["A", "D"], ["B1", "B2"],
58
+ ["DEFORMED", "DEFORMED"], ["A", "D"], "L1", "FIRST", "A")
59
+
60
+ # With additional options
61
+ CS("CS1", 7, "S1", 7, "A", "B1", "DEFORMED", "A", "L1", "FIRST", "A",
62
+ sr_stage=True, ad_stage=True, load_in=True, nl=6, addstp=[1, 2, 3])
63
+ ```
64
+ """
65
+
66
+ self.NAME = name
67
+ self.DURATION = duration
68
+ self.SR_stage = sr_stage
69
+ self.Ad_stage = ad_stage
70
+ self.Load_IN = load_in
71
+ self.NL = nl
72
+ self.addstp = [] if addstp is None else addstp
73
+
74
+ # Initialize group containers
75
+ self.act_structure_groups = []
76
+ self.deact_structure_groups = []
77
+ self.act_boundary_groups = []
78
+ self.deact_boundary_groups = []
79
+ self.act_load_groups = []
80
+ self.deact_load_groups = []
81
+
82
+ # Set ID
83
+ if id is None:
84
+ self.ID = len(CS.CSA) + 1
85
+ else:
86
+ self.ID = id
87
+
88
+ # Process structure groups
89
+ if s_group:
90
+ # Convert single values to lists for uniform processing
91
+ if not isinstance(s_group, list):
92
+ s_group = [s_group]
93
+ s_age = [s_age if s_age is not None else 0]
94
+ s_type = [s_type if s_type is not None else "A"]
95
+ else:
96
+ # Ensure other parameters are lists too
97
+ if s_age is None:
98
+ s_age = [0] * len(s_group)
99
+ elif not isinstance(s_age, list):
100
+ s_age = [s_age] * len(s_group)
101
+
102
+ if s_type is None:
103
+ s_type = ["A"] * len(s_group)
104
+ elif not isinstance(s_type, list):
105
+ s_type = [s_type] * len(s_group)
106
+
107
+ # Process each structure group
108
+ for i, group in enumerate(s_group):
109
+ if i < len(s_type) and s_type[i] == "A":
110
+ # Activation: Check if already activated in previous stages
111
+ for stage in CS.CSA:
112
+ for existing_group in stage.act_structure_groups:
113
+ if existing_group["name"] == group:
114
+ raise ValueError(f"Structure group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
115
+
116
+ age = s_age[i] if i < len(s_age) else 0
117
+ self.act_structure_groups.append({"name": group, "age": age})
118
+ else:
119
+ # Deactivation: Check if activated in previous stages
120
+ activated = False
121
+ for stage in CS.CSA:
122
+ for existing_group in stage.act_structure_groups:
123
+ if existing_group["name"] == group:
124
+ activated = True
125
+ break
126
+ if activated:
127
+ break
128
+
129
+ if not activated:
130
+ raise ValueError(f"Structure group '{group}' cannot be deactivated as it has not been activated in any previous stage")
131
+
132
+ # For deactivation, s_age value is used as redist percentage
133
+ redist = s_age[i] if i < len(s_age) else 100
134
+ self.deact_structure_groups.append({"name": group, "redist": redist})
135
+
136
+ # Process boundary groups
137
+ if b_group:
138
+ # Convert single values to lists for uniform processing
139
+ if not isinstance(b_group, list):
140
+ b_group = [b_group]
141
+ b_pos = [b_pos if b_pos is not None else "DEFORMED"]
142
+ b_type = [b_type if b_type is not None else "A"]
143
+ else:
144
+ # Ensure other parameters are lists too
145
+ if b_pos is None:
146
+ b_pos = ["DEFORMED"] * len(b_group)
147
+ elif not isinstance(b_pos, list):
148
+ b_pos = [b_pos] * len(b_group)
149
+
150
+ if b_type is None:
151
+ b_type = ["A"] * len(b_group)
152
+ elif not isinstance(b_type, list):
153
+ b_type = [b_type] * len(b_group)
154
+
155
+ # Process each boundary group
156
+ for i, group in enumerate(b_group):
157
+ if i < len(b_type) and b_type[i] == "A":
158
+ # Activation: Check if already activated in previous stages
159
+ for stage in CS.CSA:
160
+ for existing_group in stage.act_boundary_groups:
161
+ if existing_group["name"] == group:
162
+ raise ValueError(f"Boundary group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
163
+
164
+ pos = b_pos[i] if i < len(b_pos) else "DEFORMED"
165
+ self.act_boundary_groups.append({"name": group, "pos": pos})
166
+ else:
167
+ # Deactivation: Check if activated in previous stages
168
+ activated = False
169
+ for stage in CS.CSA:
170
+ for existing_group in stage.act_boundary_groups:
171
+ if existing_group["name"] == group:
172
+ activated = True
173
+ break
174
+ if activated:
175
+ break
176
+
177
+ if not activated:
178
+ raise ValueError(f"Boundary group '{group}' cannot be deactivated as it has not been activated in any previous stage")
179
+
180
+ self.deact_boundary_groups.append(group)
181
+
182
+ # Process load groups
183
+ if l_group:
184
+ # Convert single values to lists for uniform processing
185
+ if not isinstance(l_group, list):
186
+ l_group = [l_group]
187
+ l_day = [l_day if l_day is not None else "FIRST"]
188
+ l_type = [l_type if l_type is not None else "A"]
189
+ else:
190
+ # Ensure other parameters are lists too
191
+ if l_day is None:
192
+ l_day = ["FIRST"] * len(l_group)
193
+ elif not isinstance(l_day, list):
194
+ l_day = [l_day] * len(l_group)
195
+
196
+ if l_type is None:
197
+ l_type = ["A"] * len(l_group)
198
+ elif not isinstance(l_type, list):
199
+ l_type = [l_type] * len(l_group)
200
+
201
+ # Process each load group
202
+ for i, group in enumerate(l_group):
203
+ if i < len(l_type) and l_type[i] == "A":
204
+ # Activation: Check if already activated in previous stages
205
+ for stage in CS.CSA:
206
+ for existing_group in stage.act_load_groups:
207
+ if existing_group["name"] == group:
208
+ raise ValueError(f"Load group '{group}' has already been activated in stage '{stage.NAME}' (ID: {stage.ID})")
209
+
210
+ day = l_day[i] if i < len(l_day) else "FIRST"
211
+ self.act_load_groups.append({"name": group, "day": day})
212
+ else:
213
+ # Deactivation: Check if activated in previous stages
214
+ activated = False
215
+ for stage in CS.CSA:
216
+ for existing_group in stage.act_load_groups:
217
+ if existing_group["name"] == group:
218
+ activated = True
219
+ break
220
+ if activated:
221
+ break
222
+
223
+ if not activated:
224
+ raise ValueError(f"Load group '{group}' cannot be deactivated as it has not been activated in any previous stage")
225
+
226
+ day = l_day[i] if i < len(l_day) else "FIRST"
227
+ self.deact_load_groups.append({"name": group, "day": day})
228
+
229
+ CS.CSA.append(self)
230
+
231
+ @classmethod
232
+ def json(cls):
233
+ """
234
+ Converts Construction Stage data to JSON format
235
+ Example:
236
+ # Get the JSON data for all construction stages
237
+ json_data = CS.json()
238
+ print(json_data)
239
+ """
240
+ json = {"Assign": {}}
241
+
242
+ for csa in cls.CSA:
243
+ stage_data = {
244
+ "NAME": csa.NAME,
245
+ "DURATION": csa.DURATION,
246
+ "bSV_RSLT": csa.SR_stage,
247
+ "bSV_STEP": csa.Ad_stage,
248
+ "bLOAD_STEP": csa.Load_IN
249
+ }
250
+
251
+ # Add incremental steps if load step is enabled
252
+ if csa.Load_IN:
253
+ stage_data["INCRE_STEP"] = csa.NL
254
+
255
+ # Add additional steps if specified
256
+ if csa.addstp:
257
+ stage_data["ADD_STEP"] = csa.addstp
258
+ else:
259
+ stage_data["ADD_STEP"] = []
260
+
261
+ # Handle structure group activation
262
+ if csa.act_structure_groups:
263
+ stage_data["ACT_ELEM"] = []
264
+ for group in csa.act_structure_groups:
265
+ stage_data["ACT_ELEM"].append({
266
+ "GRUP_NAME": group["name"],
267
+ "AGE": group["age"]
268
+ })
269
+
270
+ # Handle structure group deactivation
271
+ if csa.deact_structure_groups:
272
+ stage_data["DACT_ELEM"] = []
273
+ for group in csa.deact_structure_groups:
274
+ stage_data["DACT_ELEM"].append({
275
+ "GRUP_NAME": group["name"],
276
+ "REDIST": group["redist"]
277
+ })
278
+
279
+ # Handle boundary group activation
280
+ if csa.act_boundary_groups:
281
+ stage_data["ACT_BNGR"] = []
282
+ for group in csa.act_boundary_groups:
283
+ stage_data["ACT_BNGR"].append({
284
+ "BNGR_NAME": group["name"],
285
+ "POS": group["pos"]
286
+ })
287
+
288
+ # Handle boundary group deactivation
289
+ if csa.deact_boundary_groups:
290
+ stage_data["DACT_BNGR"] = []
291
+ for group_name in csa.deact_boundary_groups:
292
+ stage_data["DACT_BNGR"].append(group_name)
293
+
294
+ # Handle load group activation
295
+ if csa.act_load_groups:
296
+ stage_data["ACT_LOAD"] = []
297
+ for group in csa.act_load_groups:
298
+ stage_data["ACT_LOAD"].append({
299
+ "LOAD_NAME": group["name"],
300
+ "DAY": group["day"]
301
+ })
302
+
303
+ # Handle load group deactivation
304
+ if csa.deact_load_groups:
305
+ stage_data["DACT_LOAD"] = []
306
+ for group in csa.deact_load_groups:
307
+ stage_data["DACT_LOAD"].append({
308
+ "LOAD_NAME": group["name"],
309
+ "DAY": group["day"]
310
+ })
311
+
312
+ json["Assign"][str(csa.ID)] = stage_data
313
+
314
+ return json
315
+
316
+ @classmethod
317
+ def create(cls):
318
+ """Creates construction stages in the database"""
319
+ MidasAPI("PUT", "/db/stag", CS.json())
320
+
321
+ @classmethod
322
+ def get(cls):
323
+ """Gets construction stage data from the database"""
324
+ return MidasAPI("GET", "/db/stag")
325
+
326
+ @classmethod
327
+ def sync(cls):
328
+ """Updates the CS class with data from the database"""
329
+ cls.CSA = []
330
+ a = CS.get()
331
+ if a != {'message': ''}:
332
+ if "STAG" in a:
333
+ stag_data_dict = a["STAG"]
334
+ else:
335
+ return
336
+
337
+ for stag_id, stag_data in stag_data_dict.items():
338
+ # Basic stage data
339
+ name = stag_data.get("NAME")
340
+ duration = stag_data.get("DURATION")
341
+ sr_stage = stag_data.get("bSV_RSLT")
342
+ ad_stage = stag_data.get("bSV_STEP")
343
+ load_in = stag_data.get("bLOAD_STEP")
344
+ nl = stag_data.get("INCRE_STEP")
345
+ addstp = stag_data.get("ADD_STEP")
346
+
347
+ # Create a new CS object with basic properties
348
+ new_cs = CS(
349
+ name=name,
350
+ duration=duration,
351
+ id=int(stag_id),
352
+ sr_stage=sr_stage,
353
+ ad_stage=ad_stage,
354
+ load_in=load_in,
355
+ nl=nl,
356
+ addstp=addstp
357
+ )
358
+
359
+ CS.CSA.pop()
360
+
361
+ # Process activation elements
362
+ if "ACT_ELEM" in stag_data and stag_data["ACT_ELEM"]:
363
+ for elem in stag_data["ACT_ELEM"]:
364
+ group_name = elem.get("GRUP_NAME")
365
+ age = elem.get("AGE")
366
+ new_cs.act_structure_groups.append({"name": group_name, "age": age})
367
+
368
+ # Process deactivation elements
369
+ if "DACT_ELEM" in stag_data and stag_data["DACT_ELEM"]:
370
+ for elem in stag_data["DACT_ELEM"]:
371
+ if isinstance(elem, dict):
372
+ group_name = elem.get("GRUP_NAME")
373
+ redist = elem.get("REDIST")
374
+ else:
375
+ group_name = elem
376
+ redist = 0
377
+ new_cs.deact_structure_groups.append({"name": group_name, "redist": redist})
378
+
379
+ # Process activation boundary groups
380
+ if "ACT_BNGR" in stag_data and stag_data["ACT_BNGR"]:
381
+ for bngr in stag_data["ACT_BNGR"]:
382
+ group_name = bngr.get("BNGR_NAME")
383
+ pos = bngr.get("POS")
384
+ new_cs.act_boundary_groups.append({"name": group_name, "pos": pos})
385
+
386
+ # Process deactivation boundary groups
387
+ if "DACT_BNGR" in stag_data and stag_data["DACT_BNGR"]:
388
+ for bngr in stag_data["DACT_BNGR"]:
389
+ new_cs.deact_boundary_groups.append(bngr)
390
+
391
+ # Process activation loads
392
+ if "ACT_LOAD" in stag_data and stag_data["ACT_LOAD"]:
393
+ for load in stag_data["ACT_LOAD"]:
394
+ group_name = load.get("LOAD_NAME")
395
+ day = load.get("DAY")
396
+ new_cs.act_load_groups.append({"name": group_name, "day": day})
397
+
398
+ # Process deactivation loads
399
+ if "DACT_LOAD" in stag_data and stag_data["DACT_LOAD"]:
400
+ for load in stag_data["DACT_LOAD"]:
401
+ if isinstance(load, dict):
402
+ group_name = load.get("LOAD_NAME")
403
+ day = load.get("DAY")
404
+ else:
405
+ group_name = load
406
+ day = "FIRST"
407
+ new_cs.deact_load_groups.append({"name": group_name, "day": day})
408
+
409
+ CS.CSA.append(new_cs)
410
+
411
+ @classmethod
412
+ def delete(cls):
413
+ """Deletes all construction stages from the database and resets the class"""
414
+ cls.CSA = []
415
+ return MidasAPI("DELETE", "/db/stag")
midas_civil/_group.py CHANGED
@@ -65,7 +65,7 @@ class Group:
65
65
 
66
66
  @classmethod
67
67
  def json(cls):
68
- "Generates the json file for all defined structure groups."
68
+ """Generates the json file for all defined structure groups."""
69
69
  json = {"Assign":{}}
70
70
  for i in cls.Groups:
71
71
  json["Assign"][i.ID] = {