SyFi
0.3
|
Functions | |
def | UnitCell |
def | element_to_function_space |
def | as_coeff |
def | assemble_on_cell |
def | num_integrals |
Variables | |
dictionary | cell2dim |
dictionary | cell2volume |
def test_sfc.cell_assembly.as_coeff | ( | c | ) |
Definition at line 82 of file cell_assembly.py.
Referenced by assemble_on_cell().
00082 00083 def as_coeff(c): 00084 if isinstance(c, dolfin.cpp.GenericFunction): 00085 return c 00086 elif (isinstance(c, (float,int)) or 00087 (isinstance(c, tuple) and isinstance(c[0],(float,int))) or 00088 (isinstance(c, tuple) and isinstance(c[0],tuple) and isinstance(c[0][0],(float,int)))): 00089 return dolfin.Constant(c) 00090 elif isinstance(c, str) or (isinstance(c, tuple) and isinstance(c[0],str)): 00091 return dolfin.Expression(c) 00092 else: 00093 raise TypeError("Invalid coefficient type %s." % str(type(c)))
def test_sfc.cell_assembly.assemble_on_cell | ( | form, | |
celltype, | |||
coeffs, | |||
elements = () |
|||
) |
Definition at line 94 of file cell_assembly.py.
References as_coeff(), element_to_function_space(), and UnitCell().
Referenced by test_sfc.test_jit_functionals.TestJitFunctionals._test_piecewise_constant_assembly_on_cell_single(), test_sfc.test_jit_volumes.VolumeTest._testJitConstant(), test_sfc.test_geometry_code.GeometryTestMixin.assertAssembledAlmostEqual(), test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAssembledAlmostEqual(), test_sfc.test_uflacsmode.TestUflacsMode.test_uflacs_jit(), test_sfc.test_quadjit.QuadJitTest.testJitMass(), test_sfc.test_jit.JitTest.testJitMass(), test_sfc.test_jit.JitTest.testJitSource(), test_sfc.test_jit.JitTest.testJitSplitTerms(), test_sfc.test_jit.JitTest.testJitWeightedMass(), test_sfc.test_element_indexing.ElementIndexingTest.testScalarArgument(), test_sfc.test_element_indexing.ElementIndexingTest.testScalarCoefficient(), test_sfc.test_element_indexing.ElementIndexingTest.testVectorArgument(), and test_sfc.test_element_indexing.ElementIndexingTest.testVectorCoefficient().
00094 00095 def assemble_on_cell(form, celltype, coeffs, elements=()): 00096 "Assemble UFC form on a unit cell mesh and return the result as a float or numpy array." 00097 00098 if not isinstance(celltype, str): 00099 celltype = celltype.domain() 00100 00101 # Convert data to dolfin formats 00102 mesh = UnitCell(celltype) 00103 coefficients = [as_coeff(c) for c in coeffs] 00104 function_spaces = [element_to_function_space(e, mesh) for e in elements] 00105 00106 # Assemble ufc form with dolfin 00107 A = assemble(form, mesh=mesh, function_spaces=function_spaces, coefficients=coefficients) 00108 00109 # Return in python/numpy format 00110 if isinstance(A, float): 00111 return A 00112 return A.array()
def test_sfc.cell_assembly.element_to_function_space | ( | element, | |
mesh | |||
) |
Definition at line 70 of file cell_assembly.py.
Referenced by assemble_on_cell().
00070 00071 def element_to_function_space(element, mesh): 00072 if isinstance(element, ufl.FiniteElement): 00073 return dolfin.FunctionSpace(mesh, element.family(), element.degree()) 00074 if isinstance(element, ufl.VectorElement): 00075 dim = len(element._sub_elements) # Hack! 00076 return dolfin.VectorFunctionSpace(mesh, element.family(), element.degree(), dim) 00077 if isinstance(element, ufl.TensorElement): 00078 shape = element._shape # Hack! 00079 return dolfin.TensorFunctionSpace(mesh, element.family(), element.degree(), 00080 shape, element.symmetry()) 00081 raise TypeError("Invalid element type, cannot construct function space.")
def test_sfc.cell_assembly.num_integrals | ( | form | ) |
Definition at line 113 of file cell_assembly.py.
Referenced by test_sfc.test_jit_volumes.VolumeTest._testJitConstant(), test_sfc.test_uflacsmode.TestUflacsMode.test_uflacs_jit(), test_sfc.test_quadjit.QuadJitTest.testJitMass(), test_sfc.test_jit.JitTest.testJitMass(), test_sfc.test_jit.JitTest.testJitSource(), test_sfc.test_jit.JitTest.testJitSplitTerms(), test_sfc.test_jit.JitTest.testJitWeightedMass(), test_sfc.test_element_indexing.ElementIndexingTest.testScalarArgument(), test_sfc.test_element_indexing.ElementIndexingTest.testScalarCoefficient(), test_sfc.test_element_indexing.ElementIndexingTest.testVectorArgument(), and test_sfc.test_element_indexing.ElementIndexingTest.testVectorCoefficient().
00113 00114 def num_integrals(form): 00115 return (form.num_cell_domains(), 00116 form.num_exterior_facet_domains(), 00117 form.num_interior_facet_domains())
def test_sfc.cell_assembly.UnitCell | ( | celltype | ) |
Definition at line 30 of file cell_assembly.py.
Referenced by assemble_on_cell().
00030 00031 def UnitCell(celltype): 00032 tdim = cell2dim[celltype] 00033 gdim = tdim 00034 mesh = Mesh() 00035 editor = MeshEditor() 00036 editor.open(mesh, celltype, tdim, gdim) 00037 if celltype == "interval": 00038 vertices = [(0.0,), 00039 (1.0,)] 00040 if celltype == "triangle": 00041 vertices = [(0.0, 0.0), 00042 (1.0, 0.0), 00043 (0.0, 1.0)] 00044 if celltype == "tetrahedron": 00045 vertices = [(0.0, 0.0, 0.0), 00046 (1.0, 0.0, 0.0), 00047 (0.0, 1.0, 0.0), 00048 (0.0, 0.0, 1.0)] 00049 if celltype == "quadrilateral": 00050 vertices = [(0.0, 0.0), 00051 (1.0, 0.0), 00052 (1.0, 1.0), 00053 (0.0, 1.0)] 00054 if celltype == "hexahedron": 00055 vertices = [(0.0, 0.0, 0.0), 00056 (1.0, 0.0, 0.0), 00057 (1.0, 1.0, 0.0), 00058 (0.0, 1.0, 0.0), 00059 (0.0, 0.0, 1.0), 00060 (1.0, 0.0, 1.0), 00061 (1.0, 1.0, 1.0), 00062 (0.0, 1.0, 1.0)] 00063 editor.init_vertices(len(vertices)) 00064 editor.init_cells(1) 00065 for i, p in enumerate(vertices): 00066 editor.add_vertex(i, *p) 00067 editor.add_cell(0, *range(len(vertices))) 00068 editor.close() 00069 return mesh
dictionary test_sfc::cell_assembly::cell2dim |
00001 { "interval": 1, 00002 "triangle": 2, 00003 "tetrahedron": 3, 00004 "quadrilateral": 2, 00005 "hexahedron": 3, 00006 ufl.interval: 1, 00007 ufl.triangle: 2, 00008 ufl.tetrahedron: 3, 00009 ufl.quadrilateral: 2, 00010 ufl.hexahedron: 3, 00011 }
Definition at line 6 of file cell_assembly.py.
dictionary test_sfc::cell_assembly::cell2volume |
00001 { "interval": 1.0, 00002 "triangle": 0.5, 00003 "tetrahedron": 1.0/6.0, 00004 "quadrilateral": 1.0, 00005 "hexahedron": 1.0, 00006 ufl.interval: 1.0, 00007 ufl.triangle: 0.5, 00008 ufl.tetrahedron: 1.0/6.0, 00009 ufl.quadrilateral: 1.0, 00010 ufl.hexahedron: 1.0, 00011 }
Definition at line 18 of file cell_assembly.py.