wawi 0.0.7__py3-none-any.whl → 0.0.9__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 wawi might be problematic. Click here for more details.

wawi/ext/abq_legacy.py ADDED
@@ -0,0 +1,462 @@
1
+ import numpy as np
2
+ import pdb
3
+
4
+ from abaqus import *
5
+ from abaqus import session
6
+ from abaqusConstants import *
7
+ import __main__
8
+ import section
9
+ import regionToolset
10
+ import displayGroupMdbToolset as dgm
11
+ import step
12
+ import part
13
+ import material
14
+ import assembly
15
+ import interaction
16
+ import load
17
+ import mesh
18
+ import optimization
19
+ import job
20
+ import sketch
21
+ import visualization
22
+ import xyPlot
23
+ import displayGroupOdbToolset as dgo
24
+ import connectorBehavior
25
+ import symbolicConstants
26
+ import odbAccess
27
+ import shutil
28
+
29
+ import regionToolset
30
+
31
+ import csv
32
+ from copy import deepcopy
33
+
34
+ import numpy as np
35
+ import os
36
+
37
+ from wawi.general import merge_tr_phi
38
+
39
+
40
+ def export_wawi(odb_path, path):
41
+ pass
42
+
43
+ def get_modal_parameters(frequency_step):
44
+ '''
45
+ Output the modal parameters from frequency step of current output database.
46
+
47
+ Parameters
48
+ -------------
49
+ frequency_step : str
50
+ name of step containing the modal results (frequency step)
51
+
52
+ Returns
53
+ --------------
54
+ f : float
55
+ numpy array with undamped natural frequencies in Hz of all modes computed
56
+ m : float
57
+ numpy array with modal mass for all modes computed
58
+ '''
59
+
60
+ odb = get_db('odb')
61
+ history_region_key = odb.steps[frequency_step].historyRegions.keys()[0]
62
+
63
+ ftemp = odb.steps[frequency_step].historyRegions[history_region_key].historyOutputs['EIGFREQ'].data
64
+ f = np.array([x[1] for x in ftemp])
65
+
66
+ if 'GM' in odb.steps[frequency_step].historyRegions[history_region_key].historyOutputs.keys():
67
+ mtemp = odb.steps[frequency_step].historyRegions[history_region_key].historyOutputs['GM'].data
68
+ m = np.array([x[1] for x in mtemp])
69
+ else:
70
+ m = np.ones(np.shape(f)) #if no GM field is available, mass normalization is assumed used on eigenvalues
71
+ return f, m
72
+
73
+ def session_is_odb():
74
+ """
75
+ Check if current session is ODB.
76
+
77
+ Returns:
78
+ is_odb: boolean indicating if the session is odb or not
79
+ """
80
+ is_odb =(('session' in locals() or 'session' in globals()) and
81
+ session.viewports['Viewport: 1'].displayedObject is not None and
82
+ hasattr(session.viewports['Viewport: 1'].displayedObject, 'jobData'))
83
+
84
+ return is_odb
85
+
86
+ def get_db(db_type):
87
+ """
88
+ Return the current database (either a model or an odb object).
89
+
90
+ If a model db is wanted and no model is active, the model in the mdb is selected regardless,
91
+ as long as there is only one model open in the mdb. If no database fits the requirements, None is returned.
92
+
93
+ Args:
94
+ db_type: 'odb' or 'model'
95
+ Returns:
96
+ db: database
97
+
98
+ NTNU / Knut Andreas Kvaale, 2018
99
+ """
100
+ if db_type is 'model' or db_type is 'mdb':
101
+ if not session_is_odb():
102
+ db = mdb.models[session.viewports['Viewport: 1'].displayedObject.modelName]
103
+ elif len(mdb.models.keys()) is 1:
104
+ db = mdb.models[mdb.models.keys()[0]]
105
+ elif len(mdb.models.keys()) > 1:
106
+ raise AttributeError('No model is not active, and more than one model is available in model database. Impossible to select correct.')
107
+ else:
108
+ db = None
109
+ else:
110
+ if session_is_odb():
111
+ db = session.viewports[session.currentViewportName].displayedObject
112
+ else:
113
+ db = None
114
+
115
+ return db
116
+
117
+
118
+ def modeshapes_from_region(regionobjs, frequency_step, field_outputs):
119
+ """
120
+ Get modes (shape, frequency and modal mass) from "Frequency step" (eigenvalue analysis) in active Abaqus ODB.
121
+
122
+ """
123
+ odb = get_db('odb')
124
+
125
+ if odb.steps[frequency_step].domain != MODAL: #MODAL is a variable in abaqusConstants
126
+ raise TypeError('Type of input step is not modal!')
127
+
128
+ Nmodes = len(odb.steps[frequency_step].frames)-1
129
+ phi = [None]*len(field_outputs)
130
+
131
+ for iout, field_output in enumerate(field_outputs):
132
+ Ndofs, point_ranges, dof_ranges = count_region(regionobjs, field_output, odb.steps[frequency_step].frames[0])
133
+ phio = np.zeros([np.sum(Ndofs), Nmodes])
134
+ foobj0 = odb.steps[frequency_step].frames[0].fieldOutputs[field_output]
135
+
136
+ for ix, regionobj in enumerate(regionobjs):
137
+ current_dof_range = np.arange(dof_ranges[ix], dof_ranges[ix+1])
138
+
139
+ for mode in range(0, Nmodes):
140
+ foobj = odb.steps[frequency_step].frames[mode+1].fieldOutputs[field_output]
141
+ phio[:, mode] = np.reshape((np.array([v.data for v in foobj.getSubset(region=regionobj).values])), [np.sum(Ndofs)])
142
+
143
+ phi[iout] = phio
144
+
145
+ return phi
146
+
147
+ def str2region(instance_name, setnames, region_type, db_type, *args):
148
+ """
149
+ Construct a region object from a string defining the set name or a region object.
150
+
151
+ Args:
152
+ instance_name: string defining the set name (either node or element set) or a region object
153
+ setnames: name of set asked for
154
+ region_type: type of set ('elements' or 'nodes')
155
+ db_type: 'odb' or 'model'
156
+ Optional args:
157
+ db: database object, either mdb.model[...] or session.openOdb(...) - will get from viewport 1 if not given
158
+ Returns:
159
+ regionobjs: region objects
160
+
161
+ """
162
+
163
+ is_assembly = instance_name is None
164
+
165
+ set_type = settype(region_type, db_type)
166
+ standard_sets = {'nodes': [' ALL NODES'], 'elements': [' ALL ELEMENTS']}
167
+
168
+ if setnames is None:
169
+ setnames = standard_sets[region_type]
170
+
171
+ if len(args)==1: # a db has been input
172
+ db = args[0]
173
+ isodb = hasattr(db,'jobData') #check if the input db is reffering to result/odb or model
174
+
175
+ else:
176
+ db = get_db(db_type)
177
+
178
+ if db is None:
179
+ raise TypeError('The database is empty. Please input a database object, or input parameters that matches one. Remember that odbs have to be active to get the db automatically!')
180
+
181
+ if is_assembly: # Instance name is given
182
+ regroot = db.rootAssembly
183
+ else:
184
+ regroot = db.rootAssembly.instances[instance_name]
185
+
186
+ regionobjs = [None] * np.size(setnames)
187
+
188
+ for ix,thisname in enumerate(setnames):
189
+ regionobjs[ix] = getattr(regroot, set_type)[thisname]
190
+
191
+ return regionobjs
192
+
193
+
194
+ def settype(region_type, db_type):
195
+ """
196
+ Define the string used to get set based on region type and database type.
197
+
198
+ Args:
199
+ region_type: 'element' or 'node'
200
+ db_type: 'odb' or 'mdb'
201
+ Returns:
202
+ set_string: string used to obtain set data from database object (odb or mdb)
203
+
204
+ """
205
+ if db_type is 'odb':
206
+ if 'element' in region_type.lower():
207
+ set_string = 'elementSets'
208
+ elif 'node' in region_type.lower():
209
+ set_string = 'nodeSets'
210
+ else:
211
+ raise TypeError('Wrong input!')
212
+ elif db_type == 'mdb' or db_type == 'model':
213
+ set_string = 'sets'
214
+
215
+ return set_string
216
+
217
+ def count_region(regionobjs, field_output, frame):
218
+ """
219
+ Count the number of DOFs and points in the specified region objects for given field output and frame object.
220
+
221
+ Args:
222
+ regionobjs: list of region objects to query
223
+ field_output: string specifying field output
224
+ frame: frame object (from where fieldOutputs field is accessible)
225
+ Returns:
226
+ Ndofs: number of DOFs for each region (list)
227
+ point_ranges: point/node ranges for each region (list of lists)
228
+ dof_ranges: dof ranges for each region (list of lists)
229
+ """
230
+ odb = get_db('odb')
231
+
232
+ Npoints = [len(frame.fieldOutputs[field_output].getSubset(region=regionobj).values) for regionobj in regionobjs]
233
+ Ndofs = np.dot(Npoints, len(frame.fieldOutputs[field_output].componentLabels))
234
+
235
+ dof_ranges = np.cumsum(np.append([0], Ndofs))
236
+ point_ranges = np.cumsum(np.append([0], Npoints))
237
+
238
+ return Ndofs, point_ranges, dof_ranges
239
+
240
+
241
+ def wind_set_data(set_strings, frequency_step, instance, db_type, field_outputs, mode_type='nodes', use_node_region_acronym=False):
242
+ # use_node_region_acronym: if True, a node set with identical name as the element set given in set_strings is picked and the nodes assumed to correspond to the element. If not the case, the element set is used to establish the nodes (and thus phi)
243
+ wind_element_regions = str2region(instance, set_strings, 'elements', db_type) # index 0 is girder, index 1 is columns
244
+
245
+ if use_node_region_acronym:
246
+ wind_node_regions = str2region(instance, set_strings, 'nodes', db_type)
247
+
248
+ element_labels = [None]*len(set_strings)
249
+ element_node_indices = [None]*len(set_strings)
250
+ node_labels = [None]*len(set_strings)
251
+ node_coordinates = [None]*len(set_strings)
252
+ phi_ae = [None]*len(set_strings)
253
+
254
+ for set_ix, set_string in enumerate(set_strings):
255
+ element_labels[set_ix], element_node_indices[set_ix], nl, nc = region2elnodes_legacy(wind_element_regions[set_ix])
256
+ if use_node_region_acronym:
257
+ nl, nc = region2nodes(wind_node_regions[set_ix])
258
+
259
+ node_labels[set_ix] = nl
260
+ node_coordinates[set_ix] = nc
261
+
262
+ # Establish modal transformation matrix, phi
263
+ if mode_type=='nodes':
264
+ for set_ix, set_string in enumerate(set_strings):
265
+ phi_ae_temp = modeshapes_from_nodelist(node_labels[set_ix], frequency_step, field_outputs)
266
+ phi_ae[set_ix] = merge_tr_phi(phi_ae_temp[0][0], phi_ae_temp[0][1])
267
+ elif mode_type=='elements':
268
+ for set_ix, set_string in enumerate(set_strings):
269
+ phi_ae_temp, integration_points = modeshapes_from_elementlist(element_labels[set_ix], frequency_step, field_outputs)
270
+ phi_ae[set_ix] = merge_tr_phi(phi_ae_temp[0], phi_ae_temp[1])
271
+
272
+ return element_labels, element_node_indices, node_labels, node_coordinates, phi_ae
273
+
274
+
275
+ def region2elnodes_legacy(regionobjs, avoid_central_nodes=True):
276
+ """
277
+ Give node labels (indices) for each node in specified element set.
278
+
279
+ Args:
280
+ regionobjs: region objects to query for node labels
281
+
282
+ Returns:
283
+ element_labels: the labels (indices) of the elements in list
284
+ element_node_indices: the labels (indices) of the ndoes in each element; list of lists
285
+ node_labels: all the nodes labels (indices) in a flattened list
286
+ node_coordinates: node coordinates for each element (list of lists)
287
+
288
+ """
289
+
290
+ objstr = regionobjs.__repr__()
291
+ instance_name = objstr.split(".instances['")[1].split("'].")[0]
292
+
293
+ if '.odb' in objstr:
294
+ db = get_db('odb')
295
+ dbtype = 'odb'
296
+ else:
297
+ db = get_db('mdb')
298
+ dbtype = 'mdb'
299
+
300
+ # Get the elements object root
301
+ if len(np.shape(regionobjs.elements))>1:
302
+ elements = regionobjs.elements[0]
303
+ else:
304
+ elements = regionobjs.elements
305
+
306
+ # Get all element labels and corresponding connectivity (node labels)
307
+ element_labels = np.array([element.label for element in elements])
308
+
309
+ # Instance object
310
+ instance = db.rootAssembly.instances[instance_name]
311
+
312
+ # Full arrays labels and coordinates
313
+ all_node_labels = np.array([node.label for node in instance.nodes]).flatten([-1])
314
+ all_node_coords = np.array([node.coordinates for node in instance.nodes])
315
+
316
+ # Nodes belonging to all the elements
317
+ if dbtype is 'odb':
318
+ element_node_labels = [element.connectivity for element in elements]
319
+ else:
320
+ element_node_labels = [[all_node_labels[ix] for ix in element.connectivity] for element in elements]
321
+
322
+ if avoid_central_nodes:
323
+ element_node_labels = [[node_lb[0], node_lb[-1]] for node_lb in element_node_labels]
324
+
325
+ node_labels = np.unique(np.array(element_node_labels).flatten())
326
+
327
+ nodeixs = np.array([np.where(all_node_labels==node)[0] for node in node_labels]).flatten()
328
+ node_coordinates = all_node_coords[nodeixs, :]
329
+ element_node_indices = np.array([np.array([np.where(node_labels==node_label) for node_label in node_labels_for_element]).flatten() for node_labels_for_element in element_node_labels])
330
+
331
+ return element_labels, element_node_indices, node_labels, node_coordinates
332
+
333
+
334
+ def region2nodes(regionobj, sortfun=None):
335
+ """
336
+ Give node labels (indices) of nodes in specified node set(s).
337
+
338
+ Args:
339
+ regionobj: region object to query for node labels
340
+
341
+ Optional args:
342
+ sortfun: function with three inputs (1: x, 2: y, 3:z) to sort nodes by
343
+ examples: sortfun = lambda x, y, z: -np.arctan2(y,x)
344
+ sortfun = lambda x, y, z: x
345
+
346
+ Returns:
347
+ node_labels: list with nodelabels
348
+
349
+ NTNU / Knut Andreas Kvaale, 2018
350
+ """
351
+
352
+ set_name = regionobj.__repr__().split("ets[")[1].split("'")[1]
353
+
354
+ if len(np.shape(regionobj.nodes))>1:
355
+ nodes = regionobj.nodes[0]
356
+ else:
357
+ nodes = regionobj.nodes
358
+
359
+ node_labels = np.array([node.label for node in nodes])
360
+ node_coordinates = np.array([node.coordinates for node in nodes])
361
+
362
+ if sortfun != None:
363
+ vals = sortfun(x=node_coordinates[:,0], y=node_coordinates[:,1], z=node_coordinates[:,2])
364
+ sort_ix = np.argsort(vals)
365
+ node_labels = node_labels[:, sort_ix]
366
+ node_coordinates = node_coordinates[sort_ix, :]
367
+
368
+ return node_labels, node_coordinates
369
+
370
+ def modeshapes_from_nodelist(node_labels, frequency_step, field_outputs):
371
+ """
372
+ Get mode shapes from "Frequency step" (eigenvalue analysis) in active Abaqus ODB.
373
+
374
+ Args:
375
+ node_labels:
376
+ frequency_step:
377
+ field_outputs:
378
+ Returns:
379
+ phi: mode shape transformation matrix, ordered as NumPy matrices in list for each specified outputs
380
+
381
+ """
382
+ odb = get_db('odb')
383
+
384
+ if odb.steps[frequency_step].domain != MODAL: #MODAL is a variable in abaqusConstants
385
+ raise TypeError('Type of input step is not modal!')
386
+
387
+ Nnodes = len(node_labels)
388
+ Nmodes = len(odb.steps[frequency_step].frames) - 1
389
+ phi = [None]*len(field_outputs)
390
+ basedisp = [None]*len(field_outputs)
391
+
392
+ for iout, field_output in enumerate(field_outputs):
393
+ foobj0 = odb.steps[frequency_step].frames[0].fieldOutputs[field_output]
394
+
395
+ Ndofs = len(foobj0.values[0].data)
396
+ phio = np.zeros([Ndofs*Nnodes, Nmodes])
397
+
398
+ # Get correct data indices to get correct order (as given in node_labels)
399
+ all_nodes = [value.nodeLabel for value in foobj0.values]
400
+ data_indices = [None]*Nnodes
401
+
402
+ for ix, node in enumerate(node_labels):
403
+ data_indices[ix] = all_nodes.index(node)
404
+
405
+ basedisp[iout] = np.array([foobj0.values[data_ix].data for data_ix in data_indices]).flatten()
406
+
407
+ for mode in range(0, Nmodes):
408
+ foobj = odb.steps[frequency_step].frames[mode+1].fieldOutputs[field_output]
409
+ phio[:, mode] = np.array([foobj.values[data_ix].data for data_ix in data_indices]).flatten()
410
+
411
+ phi[iout] = phio
412
+
413
+ return phi, basedisp
414
+
415
+
416
+ def modeshapes_from_elementlist(element_labels, frequency_step, field_outputs):
417
+ """
418
+ Get mode shape from "Frequency step" (eigenvalue analysis) in active Abaqus ODB.
419
+
420
+ Args:
421
+ node_labels:
422
+ frequency_step:
423
+ field_outputs:
424
+ Returns:
425
+ phi: mode shape transformation matrix, ordered as NumPy matrices in list for each specified outputs
426
+
427
+ """
428
+ odb = get_db('odb')
429
+
430
+ if odb.steps[frequency_step].domain != MODAL: #MODAL is a variable in abaqusConstants
431
+ raise TypeError('Type of input step is not modal!')
432
+
433
+
434
+ Nmodes = len(odb.steps[frequency_step].frames) - 1
435
+ phi = [None]*len(field_outputs)
436
+ integration_points = [None]*len(field_outputs)
437
+
438
+ for iout, field_output in enumerate(field_outputs):
439
+ foobj0 = odb.steps[frequency_step].frames[0].fieldOutputs[field_output]
440
+ Ndofs = len(foobj0.values[0].data)
441
+
442
+ # Get correct data indices to get correct order (as given in node_labels)
443
+ all_elements = [value.elementLabel for value in foobj0.values]
444
+ all_integration_points = [value.integrationPoint for value in foobj0.values]
445
+
446
+ Nintpoints = len(element_labels) # number of integration points (same element label might appear multiple times if multiple integration points in element)
447
+ phio = np.zeros([Ndofs*Nintpoints, Nmodes])
448
+
449
+ data_indices = [None]*Nintpoints
450
+
451
+ for ix, element in enumerate(element_labels):
452
+ data_indices[ix] = all_elements.index(element)
453
+
454
+ for mode in range(0, Nmodes):
455
+ foobj = odb.steps[frequency_step].frames[mode+1].fieldOutputs[field_output]
456
+ phio[:, mode] = np.array([foobj.values[data_ix].data for data_ix in data_indices]).flatten()
457
+
458
+ integration_points[iout] = [all_integration_points[ix] for ix in data_indices]
459
+ phi[iout] = phio
460
+
461
+
462
+ return phi, integration_points
wawi/ext/ansys.py ADDED
File without changes
wawi/ext/orcaflex.py ADDED
File without changes
wawi/ext/sofistik.py ADDED
File without changes
wawi/io.py CHANGED
@@ -355,25 +355,25 @@ def import_wadam_hydro_transfer(wadam_file):
355
355
  6-by-len(theta)-by-len(omega)
356
356
  '''
357
357
 
358
- string = ('.+W A V E P E R I O D.+=\s+(?P<period>.+):.+\n.+'
359
- 'H E A D I N G A N G L E.+=\s+(?P<theta>.+):(?:.*\n){5,10}'
358
+ string = (r'.+W A V E P E R I O D.+=\s+(?P<period>.+):.+\n.+'
359
+ r'H E A D I N G A N G L E.+=\s+(?P<theta>.+):(?:.*\n){5,10}'
360
360
 
361
- '.+EXCITING FORCES AND MOMENTS FROM THE HASKIN RELATIONS(?:.*\n){4,6}\s+'
361
+ r'.+EXCITING FORCES AND MOMENTS FROM THE HASKIN RELATIONS(?:.*\n){4,6}\s+'
362
362
 
363
- '-F1-\s+(?P<F1_real>[-?.E\d+]+)\s+(?P<F1_imag>[-?.E\d+]+)\s.+\n\s+'
364
- '-F2-\s+(?P<F2_real>[-?.E\d+]+)\s+(?P<F2_imag>[-?.E\d+]+)\s.+\n\s+'
365
- '-F3-\s+(?P<F3_real>[-?.E\d+]+)\s+(?P<F3_imag>[-?.E\d+]+)\s.+\n\s+'
366
- '-F4-\s+(?P<F4_real>[-?.E\d+]+)\s+(?P<F4_imag>[-?.E\d+]+)\s.+\n\s+'
367
- '-F5-\s+(?P<F5_real>[-?.E\d+]+)\s+(?P<F5_imag>[-?.E\d+]+)\s.+\n\s+'
368
- '-F6-\s+(?P<F6_real>[-?.E\d+]+)\s+(?P<F6_imag>[-?.E\d+]+)\s.+\n')
363
+ r'-F1-\s+(?P<F1_real>[-?.E\d+]+)\s+(?P<F1_imag>[-?.E\d+]+)\s.+\n\s+'
364
+ r'-F2-\s+(?P<F2_real>[-?.E\d+]+)\s+(?P<F2_imag>[-?.E\d+]+)\s.+\n\s+'
365
+ r'-F3-\s+(?P<F3_real>[-?.E\d+]+)\s+(?P<F3_imag>[-?.E\d+]+)\s.+\n\s+'
366
+ r'-F4-\s+(?P<F4_real>[-?.E\d+]+)\s+(?P<F4_imag>[-?.E\d+]+)\s.+\n\s+'
367
+ r'-F5-\s+(?P<F5_real>[-?.E\d+]+)\s+(?P<F5_imag>[-?.E\d+]+)\s.+\n\s+'
368
+ r'-F6-\s+(?P<F6_real>[-?.E\d+]+)\s+(?P<F6_imag>[-?.E\d+]+)\s.+\n')
369
369
  regex = re.compile(string)
370
370
 
371
- nondim_string = ('\s+NON-DIMENSIONALIZING FACTORS:\n(?:.*\n)+'
372
- '\s+RO\s+=\s+(?P<rho>[-?.E\d+]+)\n'
373
- '\s+G\s+=\s+(?P<g>[-?.E\d+]+)\n'
374
- '\s+VOL\s+=\s+(?P<vol>[-?.E\d+]+)\n'
375
- '\s+L\s+=\s+(?P<l>[-?.E\d+]+)\n'
376
- '\s+WA\s+=\s+(?P<wa>[-?.E\d+]+)')
371
+ nondim_string = (r'\s+NON-DIMENSIONALIZING FACTORS:\n(?:.*\n)+'
372
+ r'\s+RO\s+=\s+(?P<rho>[-?.E\d+]+)\n'
373
+ r'\s+G\s+=\s+(?P<g>[-?.E\d+]+)\n'
374
+ r'\s+VOL\s+=\s+(?P<vol>[-?.E\d+]+)\n'
375
+ r'\s+L\s+=\s+(?P<l>[-?.E\d+]+)\n'
376
+ r'\s+WA\s+=\s+(?P<wa>[-?.E\d+]+)')
377
377
 
378
378
  regex_nondim = re.compile(nondim_string)
379
379
 
wawi/model/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ from ._aero import *
2
+ from ._dry import *
3
+ from ._hydro import *
4
+ from ._model import *
5
+ from ._screening import *
6
+
7
+ '''
8
+ MODEL GENERATION/SIMULATION MODULE
9
+ '''
10
+
11
+ __all__ = ['_aero', '_dry', '_hydro', '_model', '_screening']