pirs.solids subpackage

This package provides description of classes representing solids that can be used to describe model geometry. Currently there are Cylinder, Box and Sphere classes.

Model geometry is represented as a set of boxes or cylinders organized in a tree structure. One solid can be inserted into another one (in this case the latter is called a container of the former one), can be positioned arbitrarily within its container (no rotation implemented yet!), and can be partially or completely covered by another solid.

Simple model

In the following example, a box with two cylinders is described and plotted.

from pirs.solids import Box, Cylinder
from pirs.tools.plots import colormap

b = Box()
b.X = 3
b.Y = 4
b.Z = 5
b.material = 'm1'

c1 = Cylinder()
c1.R = 1
c1.Z = 4
c1.material = 'm2'

b.insert(c1)

c2 = c1.copy_tree()
c2.material = 'm3'
c2.R = 0.8 
c2.pos.x = 0.8
c2.pos.y = 0.6

b.insert(c2)


colormap(b, filename='sol1z.png')
colormap(b, plane={'x':0}, filename='sol1x.png')

The Box class describes a rectangular parallelepiped with facets perpendicular to the coordinate axes. Attributes Box.X, Box.Y and Box.Z describe dimensions of the box. The material attribute holds the material name (its particular meaning in the computational code must be defined separately in the code’s high-level interface).

Variable c1 is a cylinder. It is inserted into b by the insert() method. The second cylinder, c2, is a copy of c1, except material and its position in container, represented by pos (an instance of the pirs.core.trageom.Vector3 class) are changed. Cylinder c2 is also inserted into b.

Cross-sections of the model can be plotted with the help of pirs.tools.plots.colormap() function that takes as argument a solid and returns an instance of the Matplotlib’s Axes class. If optional argument filename is given, the plot will be saved to disk.

_images/sol1z.png

Vertical cross-section.

_images/sol1x.png

Horizontal cross-section.

As one can see, cylinder c2 partly covers c1, while it was inserted into b after c1. At the second plot showing horizontal cross-section, cylinder c2 not seen while the cross-section plane, x=0 does not intersect it.

Assembly-like model

The next example shows how an assembly-like geometry can be modelled:

from pirs.solids import Box, Cylinder
from pirs.tools.plots import colormap

# pin model
pin = Cylinder(R=0.45, Z=100, material='clad')
pin.insert(Cylinder(R=0.4, Z=pin.Z-5, material='fuel'))

# assembly box
a = Box(X=5, Y=7, Z=pin.Z+10, material='water')
a.grid.x = 1
a.grid.y = 1.1
a.grid.z = a.Z

# insert pins
for i in range(5):
    for j in range(6):
        a.grid.insert((i,j,0), pin.copy_tree())

# center grid with respect to solid
a.grid.center()

colormap(a, filename='sol2z.png')
colormap(a, plane={'x':0}, filename='sol2x.png', aspect='auto')

The pin variable is a cylinder containing another, 5 cm shorter and 0.05 cm thinner coaxial cylinder. It represents a pin. Note that attributes of created solids can be set by passing correspondent arguments to the constructor.

Next, the box a is created. Its Box.grid attribute (an instance of the pirs.solids.positions.RGrid class) describes a rectangular grid (lattice) superimposed over the solid, which can be used to position inserted elements. In the example, we set grid pitches along axes using x, y and z attributes of the grid.

In the nexted loop over i and j indices a copy of pin is inserted into a using the insert() method of the grid. Unlike the Box.insert() method of the solid, the grid’s insert() method takes additional argument – a 3-tuple with indices (i, j, k), which define the grid element where the inserted solid will be positioned. A grid can be shifted as a whole with respect to its solid. By default, the grid is positioned so that the center of the (0,0,0) grid element conicides with the solid’s center. The grid’s origin attribute can be used to set grid position. Altenatively, there is the grid’s center() method that centers the grid in the solid. Note that we have not defined grid dimensions (number of elements in each direction), since they are defined automatically to include all inserted elements.

_images/sol2z.png

Vertical cross-section.

_images/sol2x.png

Horizontal cross-section.

Axial distribution of dependent variables

Each solid has heat, dens and temp attributes, that are instances of the pirs.solids.zmesh class, representing axial distribution of heat deposition, density and temeprature in the solid. All three axial distributions can be specified on independent axial grid.

from pirs.solids import Cylinder
from pirs.tools.plots import colormap

c = Cylinder(Z=2)

# heat
c.heat.set_grid([1, 2, 1])
c.heat.set_values([0.1, 0.2, 0.3])

# temperature
c.temp.set_grid([1]*20)
c.temp.set_values(lambda z: 300 + 100*z)

# density
c.dens.set_grid([1]*5)
c.dens.set_values(1.)

colormap(c, var='heat', plane={'x':0}, filename='sol3h.png')
colormap(c, var='temp', plane={'x':0}, filename='sol3t.png')
colormap(c, var='dens', plane={'x':0}, filename='sol3d.png')

To specify the grid for axial distribution, the mesh’ set_grid() method is used. It takes a list of scalars which define relative heigth of axial layers (the first list element corresponds to the lowest axial layer). In the example, the axial grid to represent heat deposition has three axial layers, the middle one is two times thicker as the others. The temperature grid has 20 equal layers, and density grid – 5 layers.

Values of axial distribution are set with the help of the set_values() method. It accepts lists (as used for heat), mappings (as used for temperature) or scalars (as used for density).

Axial distribution of heat, temeprature or density can be plotted with the pirs.tools.plots.colormap() by specifying the var argument.

_images/sol3h.png

Heat.

_images/sol3t.png

Temperature.

_images/sol3d.png

Density.

Docstrings

class pirs.solids.Box(**kwargs)

A box with facets perpendicular to the axes.

Box geometry is defined by three atributes, X, Y and Z, which represent box dimensions.

R

Radius of circumscribed sphere.

X = None

Box dimension along x axis

Y = None

Box dimension along y axis

Z = None

Box dimension along z axis

Zrange(cs='abs')

Returns tuple of floats (Zmin, Zmax) – range of self in z coordinate.

_append(othr)

Unconditinally inserts othr to the latest place.

Assumes that othr is not previously inserted

abspos(cs='abs', coordinate=None)

Returns absolute position of the element with respect to the tree’s root.

Optional argument cs (by default ‘abs’) specifies the coordinate system. Can be ‘abs’, ‘rel’, or an instance of the PositionedTree class. In the latter case, it must be a direct or indirect parent of self; the returned position is with respect to this parent.

Optional argument coordinate defines the coordinate’s name returned by the method. By default, coordinate is None and the vector itself is returned. If coordinate is one of ‘x’, ‘y’, ‘z’, ‘r’, etc. (the complete list of variables see in the description of the Vector3 class), the correspondent coordinate is returned.

children

An instance of the OrderedDict class where all children of self are stored.

circumscribe(s, adjust_position=True)

Changes inplace properties of the box, so it circumscribes solid s.

circumscribed(s, adjust_position=True)

Returns a new instance of the class self.__class__ that circumscribes s.

common_zmesh(own=False)

Returns an instance of the Mesh() class, which axial boundaries is the union of axial boundaries of all meshes of the solid itself and all its children.

covering_sibling()

Returns the younger sibling of the solid or the younger sibling of the solid’s parent(s) that covers coimpletely the solid. If there are no such siblings, returns None.

dens

Density axial distribution.

denss()

Iterator. Yeilds child elements with density axial distribution defined, recursively.

extension(a, s='abs')

Returns tuple (min, max) representing extension of the solid along axis a.

Argument a can be ‘x’, ‘y’ or ‘z’.

Optional argument s specifies the coordinate system. ‘abs’ means the gloabal coordinate system (with respect to the root of self), any other means the local element’s coordinate system.

get_child(k)

Returns the node with compound or local key k.

The compound key is relative to the instance the method bound to. Compare with the result of get_key() method.

If k is not a local key, can be indexed but has no 0-th element, the self is returned. For example, if k is an empty tuple or an emtply string.

get_key()

Returns the compound key of the node relative to the tree root.

>>> t = Tree()
>>> t.insert(1, Tree()).inserT(2, Tree())
>>> t.inserT(3, Tree())
>>> for n in t.values():
...     print n.get_key()
...
(1,)
(1, 2)
(3,)
get_parents(reverse=False)

Returns a list of all node parents, starting from the direct parent and ending with the tree root.

The optional boolean argument reverse changes the order of parents in the resulting list.

>>> t = Tree()
>>> t.insert(1, Tree()).inserT(2, Tree())
>>> t.inserT(3, Tree())
>>> for n in t.values():
...     print 'for ', n.get_key(), ' parents are: ', map(lambda x:x.get_key(), n.get_parents())
...
for  (1,)  parents are:  [()]
for  (1, 2)  parents are:  [(1,), ()]
for  (3,)  parents are:  [()]
get_radius(inscribed=True)

Returns radius of circumscribed sphere. Deprecated, use circumscribe method.

get_siblings()

Returns a tuple of two lists with nodes inserted into the node’s parent before and after the node itself.

For example, n0 contains 4 nodes:

>>> n0 = Tree()
>>> n1 = n0.insert(1, Tree())
>>> n2 = n0.insert(2, Tree())
>>> n3 = n0.insert(3, Tree())
>>> n4 = n0.insert(4, Tree())
>>> n2.get_siblings() == ([n1], [n3, n4])
True
>>> n1.get_siblings() == ([], [n2, n3, n4])
True
>>> n4.get_siblings() == ([n1, n2, n3], [])
True
get_value_by_coord(var, xyz, cs='rel')

Returns value of axial distribution specified by var at position given by the xyz tuple.

Optional argument cs specifies whether xyz given in absolute ('abs') or relative ('rel') coordinate system.

get_value_by_index(var, i)

Returns i-th value in the axial distribution specified by var.

If axial distribution is not defined for the solid yet, return default value.

grid

Grid description. Its parameters are used to compute absolute position of children, if they have other than None i,j,k attributes.

has_var(name)

Return True, if axial distribution name (can be ‘temp’, ‘heat’ or ‘dens’) is defined for the solid.

heat

Heat axial distribution.

heats()

Iterator. Yeilds child elements with heat axial distribution, recursively.

hiding_parent()

Returns the container that completely hides the solid. If there are no such parent, returns None.

i

Index to position solid in the parent’s grid along x axis.

id()

Returns id(self).

ijk

Tuple with element indices spcifying the parent’s grid element where the element is positioned.

indexed()

Returns Ture if self is positioned using the indices i, j and k.

insert(othr, i=None)

Insert element othr into self.

Optional argument i specifies index, where othr should be inserted. By default, othr is inserted as the last (most recent) child. One can specify i to set order fo the inserted element in the list of previously inserted.

intersect(othr)

Returns True if self positioned at self.abspos() intersects (i.e. has common points) with othr positioned at othr.abspos().

is_constant(var)

Checks if the axial distribution var is constant.

is_visible()

Checks if the solid is seen from its parent(s), and is not completely covered by the younger siblings. Only in this case the element and its interior can be “seen” in the model. Otherwise, it can be removed from the model tree, without actually changing the model.

Note that the element can also be covered by its child. In this case, however, its children (at least one that covers) are still visible and cannot be removed.

items(selfInclusive=False)

Returns a list of tuples (ckey, node) for all children in self recursively, where ckey is a compound key and node is the correspondent Tree instance.

The order is depth-first.

If the optional argument selfInclusive is True, the first element of the returned list is the node itself (by default, it is not included).

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.items()         
[((1,), <__main__.Tree object at ...>), ((2,), <__main__.Tree object at ...>), ((2, 21), <__main__.Tree object at ...>)]
j

Index to position solid in the parent’s grid along x axis.

k

Index to position solid in the parent’s grid along x axis.

keys()

Returns a list of compound keys of all children in self recursively.

The order is depth-first.

The local key specified in the insert() method refers only to the direct child. To refer to a node inserted into a child node, the compound key is used. The compound key is a tuple of local keys.

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.insert(3, Tree()).insert(31, Tree()).inserT(311, Tree())
>>> t.keys()
[(1,), (2,), (2, 21), (3,), (3, 31), (3, 31, 311)]
lattice_elements()

Returns list of boxes that represent lattice elements of the solid.

Returned values are tuples of the form (ijk, itype, Box()), where ijk is (i,j,k), itype is the type

layers(temp=True, dens=True, heat=True)

Returns iterator with elements describing each layer.

Each returned element is a tuple (Zmin, Zmax, values, children, (is_first, is_last))

lies_in(othr)

Returns True, if self lies completely inside othr.

local_index

The position of element in its parent.

material

Material name. Any immutable, e.g. integer or string.

max(param='heat', filter_=<function <lambda> at 0x2add5e67e398>)

Returns a tuple (v, key) where v is the maximal value of parameter param found in the solid itself and its children. Searched only elements that pass the filter_ functions, i.e if filter_(element) returns True.

parent

If self is inserted into another tree element, parent points to this element.

parents(last=None)

Iterates over all parents of self, starting from the direct parent till the root.

If optional argument last is given, iterates untill this parent, not untill the root.

pos

Position of the element with respect to its parent. By default at the origin.

classmethod properties()

Returns a list of property names defined in the class, including all inherited properties.

classmethod random_tree(N=20, seed=None)

Returns a random tree with N nodes.

Algorithm: untill the number of nodes in the tree, Ne, less than N, sample an integer from [1..Ne] and insert a new node as a child into the node with sampled number.

Note, this is a class method.

remove(obj)

Removes child with local key lkey from the node. The removed element is returned.

Note that this method provides functionality similar to the functionality of the withdraw method. The difference is that remove() removes child from self, and withdraw removes self from its parent.

remove_by_criteria(**kwargs)

Removes direct shildren if they meet all criteria specified by kwargs. For example,

t.remove_by_criteria(name=’fuel’, i=3)

will remove from t all children with name set to ‘fuel’ and positioned in the grid with i index equal to 3.

Returns the list of removed elements.

remove_by_index(i)

Removes i-th child.

remove_child(element)

Removes child from self.

remove_invisible()

Removes all invisible children of the element recursively.

The element itself remains in the model even if its is_visible() method returns False.

root

Link to the root element of the tree self belongs to.

setp(**kwargs)

Set attributes and properties specified in the keyword arguments.

If an attribute or a property does not exist, the AttributeError is raised.

shift_children(i, N, inew)

Shift children [i:i+N] to [inew:inew+N]

str_node(attr_=None)

Returns the string representing the node properties.

The optional argument attr_ specifies the name of an attribute to print out. Can be a list of attribute names.

>>> t = Tree()
>>> t.str_node() == t.str_node('id()')    # by default, t.str_node() returns t.id()
True
>>> t.str_node('parent')                  # prints out the value of the parent attribute.
"Tree 'parent': None"
str_tree(attr_=None)

Returns a string representing the (sub)tree structure of the node and its children.

The optional argument attr_ defines what will be printed. Its meaning and defualt see in the description of the str_node() method.

>>> t = Tree()
>>> t.inserT( 1, Tree())
>>> t.inserT( 2, Tree())
>>> t.get_child(1).inserT( 3, Tree())
>>> t.inserT( 4, Tree())
>>> print t.str_tree()                  
Tree 'id()': ...
        - key 1: Tree 'id()': ...
                - key 3: Tree 'id()': ...
        - key 2: Tree 'id()': ...
        - key 4: Tree 'id()': ...
stype

Returns type of the solid.

temp

Temperature axial distribution.

temps()

Iterator. Yeilds child elements with temperature axial distribution defined, recursively.

values(selfInclusive=False)

Returns a list of all children in self recursively.

The order is depth-first.

If the optional argument selfInclusive is True, the first element of the returned list is the node itself (by default, it is not included).

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.values()         
[<__main__.Tree object at ...>, <__main__.Tree object at ...>, <__main__.Tree object at ...>]
withdraw()

Removes self from its parent.

Method returns self.

class pirs.solids.Cylinder(**kwargs)

A finite-height cylinder with the axis parallel to the z axis. Cylinder geometry is defined by attributes R and Z.

X

Cylinder’s dimension along X axis.

Y

Cylinder’s dimension along Y axis.

Zrange(cs='abs')

Returns tuple of floats (Zmin, Zmax) – range of self in z coordinate.

_append(othr)

Unconditinally inserts othr to the latest place.

Assumes that othr is not previously inserted

abspos(cs='abs', coordinate=None)

Returns absolute position of the element with respect to the tree’s root.

Optional argument cs (by default ‘abs’) specifies the coordinate system. Can be ‘abs’, ‘rel’, or an instance of the PositionedTree class. In the latter case, it must be a direct or indirect parent of self; the returned position is with respect to this parent.

Optional argument coordinate defines the coordinate’s name returned by the method. By default, coordinate is None and the vector itself is returned. If coordinate is one of ‘x’, ‘y’, ‘z’, ‘r’, etc. (the complete list of variables see in the description of the Vector3 class), the correspondent coordinate is returned.

children

An instance of the OrderedDict class where all children of self are stored.

circumscribe(s, adjust_position=True)

Change inplace properties of the cylinder so that it circumscribes solid s.

circumscribed(s, adjust_position=True)

Returns a new instance of the class self.__class__ that circumscribes s.

common_zmesh(own=False)

Returns an instance of the Mesh() class, which axial boundaries is the union of axial boundaries of all meshes of the solid itself and all its children.

covering_sibling()

Returns the younger sibling of the solid or the younger sibling of the solid’s parent(s) that covers coimpletely the solid. If there are no such siblings, returns None.

dens

Density axial distribution.

denss()

Iterator. Yeilds child elements with density axial distribution defined, recursively.

extension(a, s='abs')

Returns tuple (min, max) representing extension of the solid along axis a.

Argument a can be ‘x’, ‘y’ or ‘z’.

Optional argument s specifies the coordinate system. ‘abs’ means the gloabal coordinate system (with respect to the root of self), any other means the local element’s coordinate system.

get_child(k)

Returns the node with compound or local key k.

The compound key is relative to the instance the method bound to. Compare with the result of get_key() method.

If k is not a local key, can be indexed but has no 0-th element, the self is returned. For example, if k is an empty tuple or an emtply string.

get_key()

Returns the compound key of the node relative to the tree root.

>>> t = Tree()
>>> t.insert(1, Tree()).inserT(2, Tree())
>>> t.inserT(3, Tree())
>>> for n in t.values():
...     print n.get_key()
...
(1,)
(1, 2)
(3,)
get_parents(reverse=False)

Returns a list of all node parents, starting from the direct parent and ending with the tree root.

The optional boolean argument reverse changes the order of parents in the resulting list.

>>> t = Tree()
>>> t.insert(1, Tree()).inserT(2, Tree())
>>> t.inserT(3, Tree())
>>> for n in t.values():
...     print 'for ', n.get_key(), ' parents are: ', map(lambda x:x.get_key(), n.get_parents())
...
for  (1,)  parents are:  [()]
for  (1, 2)  parents are:  [(1,), ()]
for  (3,)  parents are:  [()]
get_radius(inscribed=True)

Returns radius of circumscribed sphere. Deprecated, use circumscribe method.

get_siblings()

Returns a tuple of two lists with nodes inserted into the node’s parent before and after the node itself.

For example, n0 contains 4 nodes:

>>> n0 = Tree()
>>> n1 = n0.insert(1, Tree())
>>> n2 = n0.insert(2, Tree())
>>> n3 = n0.insert(3, Tree())
>>> n4 = n0.insert(4, Tree())
>>> n2.get_siblings() == ([n1], [n3, n4])
True
>>> n1.get_siblings() == ([], [n2, n3, n4])
True
>>> n4.get_siblings() == ([n1, n2, n3], [])
True
get_value_by_coord(var, xyz, cs='rel')

Returns value of axial distribution specified by var at position given by the xyz tuple.

Optional argument cs specifies whether xyz given in absolute ('abs') or relative ('rel') coordinate system.

get_value_by_index(var, i)

Returns i-th value in the axial distribution specified by var.

If axial distribution is not defined for the solid yet, return default value.

grid

Grid description. Its parameters are used to compute absolute position of children, if they have other than None i,j,k attributes.

has_var(name)

Return True, if axial distribution name (can be ‘temp’, ‘heat’ or ‘dens’) is defined for the solid.

heat

Heat axial distribution.

heats()

Iterator. Yeilds child elements with heat axial distribution, recursively.

hiding_parent()

Returns the container that completely hides the solid. If there are no such parent, returns None.

i

Index to position solid in the parent’s grid along x axis.

id()

Returns id(self).

ijk

Tuple with element indices spcifying the parent’s grid element where the element is positioned.

indexed()

Returns Ture if self is positioned using the indices i, j and k.

insert(othr, i=None)

Insert element othr into self.

Optional argument i specifies index, where othr should be inserted. By default, othr is inserted as the last (most recent) child. One can specify i to set order fo the inserted element in the list of previously inserted.

intersect(othr)

Returns True if self positioned at self.abspos() intersects (i.e. has common points) with othr positioned at othr.abspos().

is_constant(var)

Checks if the axial distribution var is constant.

is_visible()

Checks if the solid is seen from its parent(s), and is not completely covered by the younger siblings. Only in this case the element and its interior can be “seen” in the model. Otherwise, it can be removed from the model tree, without actually changing the model.

Note that the element can also be covered by its child. In this case, however, its children (at least one that covers) are still visible and cannot be removed.

items(selfInclusive=False)

Returns a list of tuples (ckey, node) for all children in self recursively, where ckey is a compound key and node is the correspondent Tree instance.

The order is depth-first.

If the optional argument selfInclusive is True, the first element of the returned list is the node itself (by default, it is not included).

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.items()         
[((1,), <__main__.Tree object at ...>), ((2,), <__main__.Tree object at ...>), ((2, 21), <__main__.Tree object at ...>)]
j

Index to position solid in the parent’s grid along x axis.

k

Index to position solid in the parent’s grid along x axis.

keys()

Returns a list of compound keys of all children in self recursively.

The order is depth-first.

The local key specified in the insert() method refers only to the direct child. To refer to a node inserted into a child node, the compound key is used. The compound key is a tuple of local keys.

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.insert(3, Tree()).insert(31, Tree()).inserT(311, Tree())
>>> t.keys()
[(1,), (2,), (2, 21), (3,), (3, 31), (3, 31, 311)]
lattice_elements()

Returns list of boxes that represent lattice elements of the solid.

Returned values are tuples of the form (ijk, itype, Box()), where ijk is (i,j,k), itype is the type

layers(temp=True, dens=True, heat=True)

Returns iterator with elements describing each layer.

Each returned element is a tuple (Zmin, Zmax, values, children, (is_first, is_last))

lies_in(othr)

Returns True, if self lies completely inside othr.

local_index

The position of element in its parent.

material

Material name. Any immutable, e.g. integer or string.

max(param='heat', filter_=<function <lambda> at 0x2add5e67e398>)

Returns a tuple (v, key) where v is the maximal value of parameter param found in the solid itself and its children. Searched only elements that pass the filter_ functions, i.e if filter_(element) returns True.

parent

If self is inserted into another tree element, parent points to this element.

parents(last=None)

Iterates over all parents of self, starting from the direct parent till the root.

If optional argument last is given, iterates untill this parent, not untill the root.

pos

Position of the element with respect to its parent. By default at the origin.

classmethod properties()

Returns a list of property names defined in the class, including all inherited properties.

classmethod random_tree(N=20, seed=None)

Returns a random tree with N nodes.

Algorithm: untill the number of nodes in the tree, Ne, less than N, sample an integer from [1..Ne] and insert a new node as a child into the node with sampled number.

Note, this is a class method.

remove(obj)

Removes child with local key lkey from the node. The removed element is returned.

Note that this method provides functionality similar to the functionality of the withdraw method. The difference is that remove() removes child from self, and withdraw removes self from its parent.

remove_by_criteria(**kwargs)

Removes direct shildren if they meet all criteria specified by kwargs. For example,

t.remove_by_criteria(name=’fuel’, i=3)

will remove from t all children with name set to ‘fuel’ and positioned in the grid with i index equal to 3.

Returns the list of removed elements.

remove_by_index(i)

Removes i-th child.

remove_child(element)

Removes child from self.

remove_invisible()

Removes all invisible children of the element recursively.

The element itself remains in the model even if its is_visible() method returns False.

root

Link to the root element of the tree self belongs to.

setp(**kwargs)

Set attributes and properties specified in the keyword arguments.

If an attribute or a property does not exist, the AttributeError is raised.

shift_children(i, N, inew)

Shift children [i:i+N] to [inew:inew+N]

str_node(attr_=None)

Returns the string representing the node properties.

The optional argument attr_ specifies the name of an attribute to print out. Can be a list of attribute names.

>>> t = Tree()
>>> t.str_node() == t.str_node('id()')    # by default, t.str_node() returns t.id()
True
>>> t.str_node('parent')                  # prints out the value of the parent attribute.
"Tree 'parent': None"
str_tree(attr_=None)

Returns a string representing the (sub)tree structure of the node and its children.

The optional argument attr_ defines what will be printed. Its meaning and defualt see in the description of the str_node() method.

>>> t = Tree()
>>> t.inserT( 1, Tree())
>>> t.inserT( 2, Tree())
>>> t.get_child(1).inserT( 3, Tree())
>>> t.inserT( 4, Tree())
>>> print t.str_tree()                  
Tree 'id()': ...
        - key 1: Tree 'id()': ...
                - key 3: Tree 'id()': ...
        - key 2: Tree 'id()': ...
        - key 4: Tree 'id()': ...
stype

Returns type of the solid.

temp

Temperature axial distribution.

temps()

Iterator. Yeilds child elements with temperature axial distribution defined, recursively.

values(selfInclusive=False)

Returns a list of all children in self recursively.

The order is depth-first.

If the optional argument selfInclusive is True, the first element of the returned list is the node itself (by default, it is not included).

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.values()         
[<__main__.Tree object at ...>, <__main__.Tree object at ...>, <__main__.Tree object at ...>]
withdraw()

Removes self from its parent.

Method returns self.

class pirs.solids.Sphere(**kwargs)

A sphere, which radius is defined by the attribute R.

X

Sphere’s dimension along axis X.

Y

Sphere’s dimension along axis Y.

Z

Sphere’s dimension along axis Z.

Zrange(cs='abs')

Returns tuple of floats (Zmin, Zmax) – range of self in z coordinate.

_append(othr)

Unconditinally inserts othr to the latest place.

Assumes that othr is not previously inserted

abspos(cs='abs', coordinate=None)

Returns absolute position of the element with respect to the tree’s root.

Optional argument cs (by default ‘abs’) specifies the coordinate system. Can be ‘abs’, ‘rel’, or an instance of the PositionedTree class. In the latter case, it must be a direct or indirect parent of self; the returned position is with respect to this parent.

Optional argument coordinate defines the coordinate’s name returned by the method. By default, coordinate is None and the vector itself is returned. If coordinate is one of ‘x’, ‘y’, ‘z’, ‘r’, etc. (the complete list of variables see in the description of the Vector3 class), the correspondent coordinate is returned.

children

An instance of the OrderedDict class where all children of self are stored.

circumscribe(s, adjust_position=True)

Changes inplace parameters of the sphere, so that it circumscribes solid s.

circumscribed(s, adjust_position=True)

Returns a new instance of the class self.__class__ that circumscribes s.

common_zmesh(own=False)

Returns an instance of the Mesh() class, which axial boundaries is the union of axial boundaries of all meshes of the solid itself and all its children.

covering_sibling()

Returns the younger sibling of the solid or the younger sibling of the solid’s parent(s) that covers coimpletely the solid. If there are no such siblings, returns None.

dens

Density axial distribution.

denss()

Iterator. Yeilds child elements with density axial distribution defined, recursively.

extension(a, s='abs')

Returns tuple (min, max) representing extension of the solid along axis a.

Argument a can be ‘x’, ‘y’ or ‘z’.

Optional argument s specifies the coordinate system. ‘abs’ means the gloabal coordinate system (with respect to the root of self), any other means the local element’s coordinate system.

get_child(k)

Returns the node with compound or local key k.

The compound key is relative to the instance the method bound to. Compare with the result of get_key() method.

If k is not a local key, can be indexed but has no 0-th element, the self is returned. For example, if k is an empty tuple or an emtply string.

get_key()

Returns the compound key of the node relative to the tree root.

>>> t = Tree()
>>> t.insert(1, Tree()).inserT(2, Tree())
>>> t.inserT(3, Tree())
>>> for n in t.values():
...     print n.get_key()
...
(1,)
(1, 2)
(3,)
get_parents(reverse=False)

Returns a list of all node parents, starting from the direct parent and ending with the tree root.

The optional boolean argument reverse changes the order of parents in the resulting list.

>>> t = Tree()
>>> t.insert(1, Tree()).inserT(2, Tree())
>>> t.inserT(3, Tree())
>>> for n in t.values():
...     print 'for ', n.get_key(), ' parents are: ', map(lambda x:x.get_key(), n.get_parents())
...
for  (1,)  parents are:  [()]
for  (1, 2)  parents are:  [(1,), ()]
for  (3,)  parents are:  [()]
get_radius(inscribed=True)

Returns radius of circumscribed sphere. Deprecated, use circumscribe method.

get_siblings()

Returns a tuple of two lists with nodes inserted into the node’s parent before and after the node itself.

For example, n0 contains 4 nodes:

>>> n0 = Tree()
>>> n1 = n0.insert(1, Tree())
>>> n2 = n0.insert(2, Tree())
>>> n3 = n0.insert(3, Tree())
>>> n4 = n0.insert(4, Tree())
>>> n2.get_siblings() == ([n1], [n3, n4])
True
>>> n1.get_siblings() == ([], [n2, n3, n4])
True
>>> n4.get_siblings() == ([n1, n2, n3], [])
True
get_value_by_coord(var, xyz, cs='rel')

Returns value of axial distribution specified by var at position given by the xyz tuple.

Optional argument cs specifies whether xyz given in absolute ('abs') or relative ('rel') coordinate system.

get_value_by_index(var, i)

Returns i-th value in the axial distribution specified by var.

If axial distribution is not defined for the solid yet, return default value.

grid

Grid description. Its parameters are used to compute absolute position of children, if they have other than None i,j,k attributes.

has_var(name)

Return True, if axial distribution name (can be ‘temp’, ‘heat’ or ‘dens’) is defined for the solid.

heat

Heat axial distribution.

heats()

Iterator. Yeilds child elements with heat axial distribution, recursively.

hiding_parent()

Returns the container that completely hides the solid. If there are no such parent, returns None.

i

Index to position solid in the parent’s grid along x axis.

id()

Returns id(self).

ijk

Tuple with element indices spcifying the parent’s grid element where the element is positioned.

indexed()

Returns Ture if self is positioned using the indices i, j and k.

insert(othr, i=None)

Insert element othr into self.

Optional argument i specifies index, where othr should be inserted. By default, othr is inserted as the last (most recent) child. One can specify i to set order fo the inserted element in the list of previously inserted.

intersect(othr)

Returns True if self positioned at self.abspos() intersects (i.e. has common points) with othr positioned at othr.abspos().

is_constant(var)

Checks if the axial distribution var is constant.

is_visible()

Checks if the solid is seen from its parent(s), and is not completely covered by the younger siblings. Only in this case the element and its interior can be “seen” in the model. Otherwise, it can be removed from the model tree, without actually changing the model.

Note that the element can also be covered by its child. In this case, however, its children (at least one that covers) are still visible and cannot be removed.

items(selfInclusive=False)

Returns a list of tuples (ckey, node) for all children in self recursively, where ckey is a compound key and node is the correspondent Tree instance.

The order is depth-first.

If the optional argument selfInclusive is True, the first element of the returned list is the node itself (by default, it is not included).

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.items()         
[((1,), <__main__.Tree object at ...>), ((2,), <__main__.Tree object at ...>), ((2, 21), <__main__.Tree object at ...>)]
j

Index to position solid in the parent’s grid along x axis.

k

Index to position solid in the parent’s grid along x axis.

keys()

Returns a list of compound keys of all children in self recursively.

The order is depth-first.

The local key specified in the insert() method refers only to the direct child. To refer to a node inserted into a child node, the compound key is used. The compound key is a tuple of local keys.

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.insert(3, Tree()).insert(31, Tree()).inserT(311, Tree())
>>> t.keys()
[(1,), (2,), (2, 21), (3,), (3, 31), (3, 31, 311)]
lattice_elements()

Returns list of boxes that represent lattice elements of the solid.

Returned values are tuples of the form (ijk, itype, Box()), where ijk is (i,j,k), itype is the type

layers(temp=True, dens=True, heat=True)

Returns iterator with elements describing each layer.

Each returned element is a tuple (Zmin, Zmax, values, children, (is_first, is_last))

lies_in(othr)

Returns True, if self lies completely inside othr.

local_index

The position of element in its parent.

material

Material name. Any immutable, e.g. integer or string.

max(param='heat', filter_=<function <lambda> at 0x2add5e67e398>)

Returns a tuple (v, key) where v is the maximal value of parameter param found in the solid itself and its children. Searched only elements that pass the filter_ functions, i.e if filter_(element) returns True.

parent

If self is inserted into another tree element, parent points to this element.

parents(last=None)

Iterates over all parents of self, starting from the direct parent till the root.

If optional argument last is given, iterates untill this parent, not untill the root.

pos

Position of the element with respect to its parent. By default at the origin.

classmethod properties()

Returns a list of property names defined in the class, including all inherited properties.

classmethod random_tree(N=20, seed=None)

Returns a random tree with N nodes.

Algorithm: untill the number of nodes in the tree, Ne, less than N, sample an integer from [1..Ne] and insert a new node as a child into the node with sampled number.

Note, this is a class method.

remove(obj)

Removes child with local key lkey from the node. The removed element is returned.

Note that this method provides functionality similar to the functionality of the withdraw method. The difference is that remove() removes child from self, and withdraw removes self from its parent.

remove_by_criteria(**kwargs)

Removes direct shildren if they meet all criteria specified by kwargs. For example,

t.remove_by_criteria(name=’fuel’, i=3)

will remove from t all children with name set to ‘fuel’ and positioned in the grid with i index equal to 3.

Returns the list of removed elements.

remove_by_index(i)

Removes i-th child.

remove_child(element)

Removes child from self.

remove_invisible()

Removes all invisible children of the element recursively.

The element itself remains in the model even if its is_visible() method returns False.

root

Link to the root element of the tree self belongs to.

setp(**kwargs)

Set attributes and properties specified in the keyword arguments.

If an attribute or a property does not exist, the AttributeError is raised.

shift_children(i, N, inew)

Shift children [i:i+N] to [inew:inew+N]

str_node(attr_=None)

Returns the string representing the node properties.

The optional argument attr_ specifies the name of an attribute to print out. Can be a list of attribute names.

>>> t = Tree()
>>> t.str_node() == t.str_node('id()')    # by default, t.str_node() returns t.id()
True
>>> t.str_node('parent')                  # prints out the value of the parent attribute.
"Tree 'parent': None"
str_tree(attr_=None)

Returns a string representing the (sub)tree structure of the node and its children.

The optional argument attr_ defines what will be printed. Its meaning and defualt see in the description of the str_node() method.

>>> t = Tree()
>>> t.inserT( 1, Tree())
>>> t.inserT( 2, Tree())
>>> t.get_child(1).inserT( 3, Tree())
>>> t.inserT( 4, Tree())
>>> print t.str_tree()                  
Tree 'id()': ...
        - key 1: Tree 'id()': ...
                - key 3: Tree 'id()': ...
        - key 2: Tree 'id()': ...
        - key 4: Tree 'id()': ...
stype

Returns type of the solid.

temp

Temperature axial distribution.

temps()

Iterator. Yeilds child elements with temperature axial distribution defined, recursively.

values(selfInclusive=False)

Returns a list of all children in self recursively.

The order is depth-first.

If the optional argument selfInclusive is True, the first element of the returned list is the node itself (by default, it is not included).

>>> t = Tree()
>>> t.inserT(1, Tree())
>>> t.insert(2, Tree()).inserT(21, Tree())
>>> t.values()         
[<__main__.Tree object at ...>, <__main__.Tree object at ...>, <__main__.Tree object at ...>]
withdraw()

Removes self from its parent.

Method returns self.

class pirs.solids.positions.RGrid(container, x=1, y=1, z=1, origin=(0, 0, 0))[source]
boundaries(d='x')[source]

Returns coordinates of boundaries in direction d with respect to the grid’s container.

center(log=False)[source]

Positions the central element of the grid so that the box circumscribing all inserted grid elements is centered with repsect to the container.

container[source]

Link to the solid containing the grid.

elements()[source]

Iterates over index-positioned elements.

extension(a=None)[source]

Returns tuple (Imin, Imax) of minimal and maximal grid element indices in the direction along axis a.

The argument a can be ‘x’, ‘y’ or ‘z’.

UPD: the default a is None; in this case the tuple (Imin, Imax, Jmin, Jmax, Kmin, Kmax) is returned.

index(x, y, z)[source]

Returns index i,j,k of the element containing point p (with respect to the grid’s container)

index(x=5, y=7, z=8) # returns tuple (i, j, k)

insert(ijk, element, i=None)[source]

Inserts element into the grid’s container and specifies for the inserted element that it should be positioned with respect to the ijk-th grid element.

origin[source]

Position of the grid’s central element (0,0,0) with respect to the container.

position(i, j, k, coordinate=None)[source]

Returns position of element ijk with respect to the grid’s container.

set_origin((i, j, k), (x, y, z))[source]

Sets the grid origin so that the grid element (i,j,k) has position (x, y, z) with respect to the grid’s container.

used()[source]

Returns True if at least one of the grid container’s local children has not None i,j,k attributes.

x[source]

Grid pitch along x axis.

y[source]

Grid pitch along y axis.

z[source]

Grid pitch along z axis.

class pirs.solids.zmesh(boundary)

Class to represent axial mesh for density, temperature and heat in a solid with Z dimension.

An axial mesh is defined by giving a solid (A reference solid)and by giving relative height of mesh elements (a relative grid).

When a new instance of zmesh is created, an instance of one of the solids must be provided, which will be used to define the absolute height of the mesh elements.

b = Box() # default box with X,Y,Z = 1 m = zmesh(b) # axial mesh m with b as the reference solid.

Lenght of mesh elements is specified in relative units. For example,

m.set_grid([0.5, 1., 0.5])

sets number of mesh elements and their lengths. The argument is a list, which i-th element gives the relative length of the i-th mesh element along z axis. The absolute lenght is obtained first by normalizing the values in the list, so their sum gives one, and by multiplying by the dimension of the reference solid. For the above example, mesh elements along z will be 0.25 cm, 0.5 cm and 0.25 cm.

Initialize the axial mesh. Boundary must be an object with attribute Z, which defines the absolute height of the mesh (this is, for example, instance of Box class).

Initially, there is only one mesh element, and value is set to 0.

adjust_grid(Nmax, dVmin, alpha=0.3333333333333333)

Changes the grid by inserting new mesh elements between elements with maximal dV, and by combining elements with dV less than dVmin.

boundary_coords(cs='rel')

Returns list of boundary coordinates of the grid.

The first and last elements in the returned list give coordinates of the facet of the reference solid.

>>> b = solids.Box()
>>> b.pos.z = 6
>>> m = zmesh(b)
>>> m.boundary_coords('abs')
[5.5, 6.5]
>>> m.boundary_coords('rel')
[-0.5, 0.5]
>>> m.set_grid( [1]*4 )
>>> m.boundary_coords('rel')
[-0.5, -0.25, 0.0, 0.25, 0.5]
>>> m.boundary_coords('abs')
[5.5, 5.75, 6.0, 6.25, 6.5]
clear()

Set grid so that the mesh has only one element and set the value to 0.

common_grid(othr)

Deprecated. Use unify()

convert(type_=<type 'float'>)

Converts values saved in zmesh to type_. Argument type_ must be a function.

copy(boundary=None)

return copy of self.

crop(othr)

put to self data from othr, so that mesh elements coincide.

element_coord(k=0, cs='rel')

Returns coordinates of k-th mesh element’s center.

The optional argument cs accepts the following values:

  • ‘rel’ (default): the returned coordinates are in the coordinate system of the reference solid.
  • ‘abs’: the returned coordinates are in the coordinate system of the root of the reference solid.
  • ‘1’: the returned coordinates are relative to the c.s. of the reference solid whose height is set to 1.

Between rel, abs and 1 coordinates hold the following equalities:

Zabs = Zrel - self.__b.abspos()

Zrel = Z1 * self.__b.Z

element_coords(cs='rel')

Returns the list of mesh-elements center coordinates.

element_index(z=0.0, cs='rel')

Returns the index of the mesh element containing coordinate z, relative or absolute.

get_grid(rel=True)

Returns the list of mesh elements lengths

get_max(func=None)

Returns (Vmax, i) tuple, where Vmax is the maximal value, and i –its index.

When func is given, maximum is searched among func(vi).

get_solid()

Returns the reference solid.

get_value_by_coord(xyz, cs='rel')

Returns the value of mesh element, specified by the xyz coordinate.

The value of the mesh element covering point with axial coordinate z is returned.

get_value_by_index(k)

Returns the value of mesh element speficied by its index

has_zeroes()

Returns True if self.values() has one or more zeroes.

integral(A=None, B=None, cs='rel')

Returns integral from A to B of the piecewise-constant function.

cs defines the meaning of A and B. Can be ‘rel’, ‘abs’ and ‘1’.

>>> m = zmesh(solids.Box(Z=4.))
>>> m.integral(-0.5, 0.5, '1')
0.0
>>> m.set_grid([1]*4)
>>> m.set_values([1, 2, 3, 4])
>>> Zlst = [-4.] + map(float, m.boundary_coords('rel')) + map(lambda x: x[2], m.element_coords('rel')) + [4.]
>>> Zlst.sort()
>>> print Zlst
>>> for A in Zlst:
...     for B in Zlst:
...         print '    {0:7.3f} {1:7.3f}   {2:9.5f}'.format(A, B, m.integral(A, B, 'rel'))
...
>>> m.integral(cs='1')
>>> m.integral(cs='rel')
>>> m.integral(cs='abs')
interpolate(z, cs='rel')

Returns interpolated value at coordinate z.

>>> m = zmesh(solids.Box())
>>> m.set_grid([1]*5)
>>> m.set_values([1, 2, 3, 4, 5])
>>> for (x,y,z) in m.element_coords('1'):
...     print z, m.interpolate(z, '1')
...
>>> for z in m.boundary_coords('1'):
...     print z, m.interpolate(z, '1')
...
is_constant()

Returns True if all values of the mesh are equal

items(key_type='index', cs='rel')

Returns a list of tuples (k, val) in the order described in method set_values().

If key_type is ‘index’ (defalut), k is the mesh element index. If key_type is ‘coord’, k is the mesh center’s coordinates, k = (x,y,z). In this case one can additionally specify coordinate system, ‘rel’ or ‘abs’

set_grid(lst=[1.0])

Set relative grid.

lst is a list specifiying the number of grid elements and their relative length.

set_value_by_coord(val, z, cs='rel')

Set value to the mesh element, specified by its z coordinate, relative or absolute.

The value set to the mesh element, which covers the given coordinate.

set_value_by_index(val, k)

Set value to mesh element specified by its index.

Index is an integer. Counting starts from zero.

set_values(val, cs='rel')

Set values of the mesh.

Accepted types of val are:

  • a list or a tuple. Must have the same number of elements as the list returned by the get_grid() method.

  • a mapping (function) used to calculate value at each mesh element center. The meaning of the mapping’s argument can be set by the method’s optional argument cs, its meaning see in element_coord() method.

  • another instance of the zmesh class. In this case, grid and values of this instance are copied to self. This is equal to :

    self.update(othr)

  • if not one of the above, transformed to the list [val]*len(self.get_grid())

set_values_by_function(f, cs='rel')

Set values of the mesh by function f(z): z -> f.

Value of each mesh element is set to f(z), where z is coordinate of the mesh element’s center.

simplify()

Joins adjacent mesh elements if their values are within the precision prec.

unify(othr, log=False)

Changes self and othr so that their mesh boundaries coincide.

values()

Returns the list of values in the order described in method set_values()

pirs.tools.plots.colormap(model, plane={'z': 0}, axis=None, var=None, filter_=None, aspect='equal', colors=None, nmarker={}, mmarker={}, legend=True, filename=None, **kwargs)

Returns an instance of the matplotlib Axes class containing colormap that shows distribution of the system variable var on the cross-section plane defined by the argument plane.

Parameters:
  • model – Model to be plotted. Instance of Box, Cylinder or Sphere class.
  • plane (dict) – Dictionary describing the cut plane.
  • axis – Instance of the matplotlib.axes.Axes class where geometry plot will be added. If not specified, a new instance will be created.
  • var (str) – Variable name, one of ‘material’, ‘temp’, ‘heat’ or ‘dens’ which will be used to color the geometry.
  • filter (func) – boolean function taking a solid as argument. A solid will be plotted only if this function returns True for it. By default, all solids are plotted.
  • aspect (str) – string ‘equal’ or ‘auto’.
  • colors (dict) – dictionary for colors used for material names.
  • nmarker (dict) – dictionary specifying solids names to be marked on the plot. ‘name’:’*’ or ‘name’:dict, where ‘*’ or dict defines the marker shape, as in the maptlotlib.pyplot.plot() function.
  • mmarker (dict) – as nmarker, but to mark solids with particular material names.
  • legend (bool) – Show the legend on the plot.
  • filename (str) – File name where the plot will be stored. This attribute is passed to the matplotlib.pyplot.Figure.savefig() method.
  • **kwargs

    keyword arguments describing contour lines.

Table Of Contents

Previous topic

Welcome to PIRS documentation!

Next topic

pirs.mcnp subpackage

This Page