Models are stored in the repository models
and only a constructor such as Model()
can add models to the repository:
>>> mdb.Model(name='M1')
The model "M1" has been created.
mdb.models['M1']
The only required argument is name
, while the optional arguments will typically be just fine as defaults. For example, the argument modelType
has default value STANDARD_EXPLICIT
where the other alternative is ELECTROMAGNETIC
, the latter being very much outside the scope of this site...
The argument description
can however be useful:
>>> mdb.Model(name='M2', description = 'Some description of M2')
The model "M2" has been created.
mdb.models['M2']
>>>
The description is now a property, and can be modified by setValue(...)
:
>>> mdb.models['M2'].description
'Some description of M2'
>>> mdb.models['M2'].setValues(description='New description of M2')
>>> mdb.models['M2'].description
'New description of M2'
Pranking your fellow workers in the simulation department by handing over a model database where the description of the models are ten random words from Shakespears Hamlet:
from random import randint
modelnames = ['Model-{}'.format(i) for i in ('A', 'B', 'C', 'D', 'E', 'F', 'G')]
text = 'To be or not to be that is the question Whether tis nobler in the mind to suffer The slings and arrows' \
'of outrageous fortune Or to take arms against a sea of troubles And by opposing end them To die to sleep' \
'No more and by a sleep to say we end The heart ache and the thousand natural shocks That flesh is heir to' \
'tis a consummation'
words = text.split(' ')
for m in modelnames:
desc = ''
for i in range(0,10):
desc = desc + words[randint(0,len(words)-1)] + ' '
mdb.Model(name=m, description = desc)
>>> for name, model in mdb.models.items():
... print name, model.description
...
Model-1
Model-A we that end the the end nobler we by by
Model-B troubles end be mind die be more And a and
Model-C to Whether to To end be Whether be outrageous end
Model-D we arms tis heir consummation mind to end and The
Model-E and the a we To question sleep troubles a slings
Model-F against thousand sea be heir a slings The natural the
Model-G mind slings in not the take die end a take
The repository mdb.models
behaves similar to a Python dictionary having the standard methods itmes()
, values()
, and keys()
:
>>> print mdb.models
{'Model-A': 'Model object', 'Model-B': 'Model object', 'Model-C': 'Model object', 'Model-D': 'Model object',
'Model-E': 'Model object', 'Model-F': 'Model object', 'Model-G': 'Model object'}
>>>
>>> mdb.models.items()
[('Model-A', mdb.models['Model-A']), ('Model-B', mdb.models['Model-B']), ('Model-C', mdb.models['Model-C']),
('Model-D', mdb.models['Model-D']), ('Model-E', mdb.models['Model-E']), ('Model-F', mdb.models['Model-F']),
('Model-G', mdb.models['Model-G'])]
>>>
>>> mdb.models.keys()
['Model-A', 'Model-B', 'Model-C', 'Model-D', 'Model-E', 'Model-F', 'Model-G']
>>>
>>> mdb.models.values()
[mdb.models['Model-A'], mdb.models['Model-B'], mdb.models['Model-C'], mdb.models['Model-D'], mdb.models['Model-E'],
mdb.models['Model-F'], mdb.models['Model-G']]
>>>
# alternative 1
for name in mdb.models.keys():
mod = mdb.models[name]
print(name, mod.description)
# alternative 2
for name, mod in mdb.models.items():
print(name, mod.description)
In Python, the del
keyword is used to delete objects. In Python everything is an object, so the method for deleting itmes such as a model comes as no supprise:
>>> del mdb.models['Model-1']
As the most significant type of object, the number of properties end methods is huge. For instanc, only the constructors starting with either 'M' or 'P':
>>> key = mdb.models.keys()[0]
>>> mod = mdb.models[key]
>>> [i for i in dir(mod) if i[0] in ['M', 'P'] ]
['MPCSection', 'MagneticVectorPotentialBC', 'MappedField', 'MassDiffusionStep', 'Material', 'MaterialAssignment',
'MaterialFlowBC', 'MembraneSection', 'ModalDynamicsStep', 'ModelChange', 'ModelInstance', 'ModulatedAmplitude',
'Moment', 'MultipointConstraint', 'PEGLoad', 'PEGSection', 'Part', 'Part2DGeomFrom2DMesh', 'PartFromAcis',
'PartFromExtrude2DMesh', 'PartFromGeometryFile', 'PartFromIges', 'PartFromInputFile', 'PartFromLumps',
'PartFromMeshMirror', 'PartFromNodesAndElements', 'PartFromOdb', 'PartFromSection3DMeshByPlane',
'PartFromSubstructure', 'PeriodicAmplitude', 'PinnedBC', 'PipePressure', 'PipeProfile', 'PointSection',
'PorDragBodyForce', 'PorePressure', 'PorePressureBC', 'PorousFluidSection', 'PredefinedField', 'Pressure',
'PressurePenetration', 'Profile', 'PsdDefinition']
>>>
Of these, Material(...)
and Part(...)
can be found frequently in the examples on this site. Materials and parts are stored in respective repositories: materials
and parts
:
>>> [i for i in dir(mod) if i[0] in ['m', 'p'] ]
['materials', 'materialsFromOdb', 'modelType', 'parts', 'predefinedFields', 'profiles']
>>>