msml.model

MSML – Meta model.

defines classes for:

  • operators
  • environments
  • scene elements
  • msml-files

Functions

Classes

class msml.model.Alphabet(elements=[])[source]

Bases: object

`Alphabet`holds the information about defined :py:class:`Operator`s and :py:class:`ObjectAttribute`s

Normally it will created from a bunch of xml files.

append(elements)[source]

add a new element (operator or attribute) to the alphabet

get(obj)[source]
Parameters:obj (str) – an identifier for an Operator or an ObjectAttribute
static load(filename)[source]

loads a pickled alphabet from the given filename :param filename: :type filename: str

object_attributes

a dictionary of all available object attributes :type: OrderedDict

operators

dictionary of defined operators :type: OrderedDict

save(filename)[source]

pickles the alphabet into a binary dump to the given filename :type filename: str

type(obj)[source]
Returns:the type of the given obj
validate()[source]

Validates the alphabet. Calls .validate() on each contained element.

class msml.model.Constant(value)[source]

Bases: object

A constant value within attribute values.

Note

<op-name a="c">

The attribute a will be coded as an Constant with value c.

This class will be created py parse_attribute_value()

See also

parse_parse_attribute_value()

value

the value of this constant, readonly

class msml.model.ContactGeometry(type='linear', id=None, value=None, exportFile='')[source]

Bases: object

Represent the given contact surface within the <object> node:

<contactsurface id="" surface=""/>
surface

legacy support

validate()[source]
Returns:always valid
class msml.model.DiGraph(data=None, **attr)[source]

Bases: networkx.classes.multidigraph.MultiDiGraph

A networkx.MultiDiGraph but extends this by to methods:

  • self.toporder
  • self.show
toporder()[source]

Returns the topological order of the graph.

Returns:
list[set]: a list of buckets (set of nodes),
that has only predecessor from the previous bucket
Raises:
ValueError: iff. the graph is not acyclic
class msml.model.IndexGroup(id, indices)[source]

Bases: object

The indexgroup element

<indexgroup id="" indices="" />
class msml.model.MSMLEnvironment(solver=None, steps=None)[source]

Bases: object

class Simulation(*args)[source]

Bases: list

..code-block:

<simulation>

</simulaiton>
class Step(name='initial', dt=0.05, iterations=100, gravity=None)[source]

Bases: object

dt
gravity
iterations
MSMLEnvironment.Simulation.add_step(name='initial', dt=0.05, iterations=100, gravity=None)[source]

Add a new step to the Simlation :param name: step name :type str: :param dt: delta T :type dt: float :param iterations: number of iterations :type iterations: int :return:

class MSMLEnvironment.Solver(linearSolver='iterativeCG', processingUnit='CPU', timeIntegration='dynamicImplicitEuler', preconditioner='SGAUSS_SEIDL', dampingRayleighRatioMass=0.0, dampingRayleighRatioStiffness=0.2, mass='lumped')[source]

Bases: object

Represents the solver xml tag.

class msml.model.MSMLFile(variables=None, workflow=None, scene=None, env=None, output=None)[source]

Bases: object

Main model of this project.

It holds the datastructure for an whole file. Consists of variables, workflow, scene and environment settings. It provides function for validation and reference bind between workflow, scene and variables.

add_variable(var)[source]

adds the given var to the list of variables This call replaces a variable with the same name. :param var: a new variable :type var: MSMLVariable :return: None

bind(alphabet=None)[source]
env
Type:msml.model.base.MSMLEnvironment
Returns:
exists_var(name)[source]

checks if variable with name exists

Parameters:name (str) – name of a variable
Returns:
Return type:bool
exporter
find_simulation_step(name)[source]

Tries to find the simulation step with the given name

Parameters:name (str) – name of the simulation step
Return type:NoneType or msml.model.base.Environment.Simulation.Step
get_var(name)[source]

returns a variable with name if it exists

Parameters:name
Returns:
lookup(ref, outarg=True)[source]

Lookup a reference. In reference the task has to be set. The user get a warnung if the reference is ambiguous. The lookup order is: task, variable, exporter.

Parameters:
  • ref (Reference) – an open reference
  • outarg (bool) – specifies to look for an input (+ parameters) or output slot
Returns:

the closed reference or None

Return type:

Reference or None

output
Type:list[ObjectElement]
Returns:
scene
Type:list[ SceneObject ]
Returns:
validate(alphabet=None)[source]

validates the given MSMLFile. Delegate this to his children.

Parameters:alphabet
Return type:bool
Returns:
variables
Type:dict[str, MSMLVariable]
Returns:
workflow
Type:Workflow
Returns:
class msml.model.MSMLFileVariable(name, format=None, typ=None, location=None)[source]

Bases: object

class msml.model.MSMLVariable(name, physical=None, logical=None, value=None, role=None)[source]

Bases: object

Represents an MSMLVariable. An execution of an variable results in setting the appropriate value into

the exectioner’s memory.
class msml.model.MaterialRegion(id, indices, elements=None)[source]

Bases: msml.model.base.IndexGroup, list

Represents an material region from an MSMLFile within an SceneObject

<material>
    <region id="" indices="">
        [object elements]
    </region>
</material>

See also

SceneObject

bind(alphabet)[source]

binds all sub elements to the corresponding msml.model.alphabet.ObjectAttribute

Parameters:alphabet (msml.model.alphabet.Alphabet) – the current alphabet
Returns:None
validate()[source]
Type:bool
Returns:True iff. all sub elements are valid and the region is valid.
class msml.model.Mesh(type='linear', id=None, value=None)[source]

Bases: object

Represent the given mesh within the <object> node:

<mesh>
    <*type* id="" mesh="" />
<mesh>
mesh

legacy support

validate()[source]
Returns:always valid
class msml.model.OAConstraint(name, quantity='single', description='documentation N/A', parameters=None, inputs=None)[source]

Bases: msml.model.alphabet.ObjectAttribute

validate()[source]

validates a Object Constraints.

Constraints:
  • indices attribute have to present
Return type:

bool

class msml.model.OAMaterial(name, quantity='single', description='documentation N/A', parameters=None, inputs=None)[source]

Bases: msml.model.alphabet.ObjectAttribute

class msml.model.OAOutput(name, quantity='single', description='documentation N/A', parameters=None, inputs=None)[source]

Bases: msml.model.alphabet.ObjectAttribute

class msml.model.ObjectAttribute(name, quantity='single', description='documentation N/A', parameters=None, inputs=None)[source]

Bases: object

Class of all user-defineable constraints, outputs, materials.

static find_class(category)[source]

Finds the correct class for an given category. :returns: the suitable constructor :type category: str :rtype: type

validate()[source]

Validation of this attribute

class msml.model.ObjectConstraints(name, forStep='initial', constraints=None)[source]

Bases: object

Constraints for a timestep (for_step)

add_constraint(*constraints)[source]

add constraints to this object ;type constraints: ObjectElement :param constraints: :return:

bind(alphabet)[source]

binds all constraints to the given alphabet :type alphabet: msml.model.alphabet.Alphabet :return: None

constraints
Type:list[ObjectElement]
Returns:
for_step
Type:str
Returns:
index_group
name
Type:str
Returns:
validate()[source]

validates all constraints :return: True iff. all constraints valid, and for_step is set

class msml.model.ObjectElement(attrib={}, meta=None)[source]

Bases: object

This class describe an instance of an ObjectAttribute

bind(alphabet=None)[source]
get(attribute, default=None)[source]
Parameters:
  • attribute
  • default
Returns:

meta
tag
Returns:the element (tag) name, this is the same as the ObjectAttribute.name in self.meta
validate()[source]
Returns:
class msml.model.Operator(name, input=None, output=None, parameters=None, runtime=None, settings=None, meta=None)[source]

Bases: object

Operator hold all slots, runtime information and meta data

acceptable_names()[source]

all names of input or parameter slots :rtype: list[str]

get_default_args()[source]
get_targets()[source]
input_names()[source]

:returns all names of the input slots :rtype: list[str]

output_names()[source]

:returns all names of the output slots :rtype: list[str]

parameter_names()[source]

:returns all names of the parameter slots :rtype: list[str]

settings()[source]

all settingss :rtype: list[str]

validate()[source]

validation of this operator :returns: True iff. this operator is well-defined :rtype: bool

class msml.model.PythonOperator(name, input=None, output=None, parameters=None, runtime=None, meta=None, settings=None)[source]

Bases: msml.model.alphabet.operator.base.Operator

Operator for Python functions.

bind_function()[source]

Search and bind the python function. Have to be called before __call__

validate()[source]
class msml.model.Reference(task, out=None)[source]

Bases: object

Describes a connection from an input slot to an output slot.

sets the outgoing task and slot

sets the outgoing slot from an variable

set the ingoging slot

linked

Returns True iff. the Reference is closed iff. input and output slot found and set. :return: bool

class ref(task, name, arginfo)

Bases: tuple

arginfo

Alias for field number 2

name

Alias for field number 1

task

Alias for field number 0

Reference.valid

Returns True iff. the input and output slot are physical type compatible :return: bool

class msml.model.SceneObject(oid, mesh=None, sets=SceneObjectSets(elements=[], nodes=[], surfaces=[]), material=None, constraints=None)[source]

Bases: object

bind(alphabet)[source]
Returns:
constraints
contactGeometry
Type:ContactGeometry
Returns:
hasContactGeometry
id
material
mesh
Type:Mesh
Returns:
output
sets
Type:msml.model.base.SceneObjectSets
Returns:the current sets
validate()[source]
Returns:
Return type:bool
class msml.model.SceneObjectSets(elements=None, nodes=None, surfaces=None)[source]

Bases: object

class msml.model.SharedObjectOperator(name, input=None, output=None, parameters=None, runtime=None, meta=None)[source]

Bases: msml.model.alphabet.operator.python.PythonOperator

Shared Object Call via ctype

bind_function()[source]
class msml.model.ShellOperator(name, input=None, output=None, parameters=None, runtime=None, meta=None, settings=None)[source]

Bases: msml.model.alphabet.operator.python.PythonOperator

bind_function()[source]
command(kwargs)[source]
class msml.model.Slot(name, physical, logical=None, required=True, default=None, meta=None, parent=None)[source]

Bases: object

An input, parameter or output slot of an operator or an element Consists of name, physical and logical type.

Proxy for meta data.

SLOT_TYPE_INPUT = 0
SLOT_TYPE_OUTPUT = 1
SLOT_TYPE_PARAMETER = 2
SLOT_TYPE_UNKNOWN = -1
class msml.model.Task(name, attrib)[source]

Bases: object

A task object is a node in the execution graph. It holds his input arguments and the corresponding operator from the alphabet. It can be called with an **kwargs argument of the input parameters form self.arguments.

ID_ATTRIB = 'id'
bind(alphabet)[source]

binds this task to an operator from the given alphabet

bound
get_default()[source]
id

id of this task if set, If none ìd is set, it will generate one. :returns: :rtype: str

links the input and parameter arguments to the output slots

validate()[source]
class msml.model.Workflow(tasks=[])[source]

Bases: object

add_task(task)[source]
bind_operators(alphabet)[source]

Link all tasks input and paramters slots to output slots and variables form the given msml file.

Parameters:
  • alphabet (msml.model.alphabet.Alphabet) – the current alphabet
  • msmlfile (MSMLFile) – the msmlfile, to which the workflow belongs
Returns:

lookup(id)[source]
tasks
Type:dict[str,Task]
Returns:
validate()[source]

checks if all tasks match the operator definition

msml.model.call_method_list(seq, method, *args)[source]
msml.model.is_generated_name(name)[source]

True iff. the given name is a generated name :param str name: :return: bool

msml.model.parse_attribute_value(value)[source]

Parse attribute values: >>> parse_attribute_value(“${abc}”) # => Reference >>> parse_attribute_value(“abc”) # => Constant

Parameters:value (str) – value of a xml attribute
Returns:Constant | Reference
msml.model.random_var_name()[source]

generate a random variable name :return: str

msml.model.xor(seq, start=False)[source]

xor on iterables

>>> l1 = [0, 1 , 0]
>>> l2 = [1, 1 , 0]
>>> l3 = [1, 1 , 1]
>>> xor(l1)
True
>>> xor(l2)
False
>>> xor(l3)
True
Returns:True if an odd numbers of True values within the seq