SyFi  0.3
cell_assembly.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 from dolfin import Mesh, MeshEditor, assemble
00003 
00004 cell2dim = { "interval": 1, "triangle": 2, "tetrahedron": 3, "quadrilateral": 2, "hexahedron": 3 }
00005 
00006 cell2volume = { "interval": 1.0, "triangle": 0.5, "tetrahedron": 1.0/6.0, "quadrilateral": 1.0, "hexahedron": 1.0 }
00007 
00008 def UnitCell(celltype):
00009     tdim = cell2dim[celltype]
00010     gdim = tdim
00011     mesh = Mesh()
00012     editor = MeshEditor()
00013     editor.open(mesh, celltype, tdim, gdim)
00014     if celltype == "interval":
00015         vertices = [(0.0,),
00016                     (1.0,)]
00017     if celltype == "triangle":
00018         vertices = [(0.0, 0.0),
00019                     (1.0, 0.0),
00020                     (0.0, 1.0)]
00021     if celltype == "tetrahedron":
00022         vertices = [(0.0, 0.0, 0.0),
00023                     (1.0, 0.0, 0.0),
00024                     (0.0, 1.0, 0.0),
00025                     (0.0, 0.0, 1.0)]
00026     if celltype == "quadrilateral":
00027         vertices = [(0.0, 0.0),
00028                     (1.0, 0.0),
00029                     (1.0, 1.0),
00030                     (0.0, 1.0)]
00031     if celltype == "hexahedron":
00032         vertices = [(0.0, 0.0, 0.0),
00033                     (1.0, 0.0, 0.0),
00034                     (1.0, 1.0, 0.0),
00035                     (0.0, 1.0, 0.0),
00036                     (0.0, 0.0, 1.0),
00037                     (1.0, 0.0, 1.0),
00038                     (1.0, 1.0, 1.0),
00039                     (0.0, 1.0, 1.0)]
00040     editor.initVertices(len(vertices))
00041     editor.initCells(1)
00042     for i, p in enumerate(vertices):
00043         editor.addVertex(i, *p)
00044     editor.addCell(0, *range(len(vertices)))
00045     editor.close()
00046     return mesh
00047 
00048 
00049 def assemble_on_cell(form, celltype, coeffs):
00050     "Assemble UFC form on a unit cell mesh and return the result as a float or numpy array."
00051     mesh = UnitCell(celltype)
00052     A = assemble(form, mesh, coeffs)
00053     if isinstance(A, float):
00054         return A
00055     return A.array()
00056 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines