generate_elements.py

来自「利用C」· Python 代码 · 共 64 行

PY
64
字号
"Generate finite elements for DOLFIN library of precompiled elements"__author__ = "Anders Logg (logg@simula.no)"__date__ = "2007-04-12 -- 2008-04-13"__copyright__ = "Copyright (C) 2007-2008 Anders Logg"__license__  = "GNU LGPL Version 2.1"from ffc import *from ffc.common.constants import FFC_OPTIONS# Fancy import of list of elements from elements.pyfrom elements import __doc__ as elementselements = [eval(element) for element in elements.split("\n")[1:-1]]# Iterate over elements and compilesignatures = []for i in range(len(elements)):        # Don't generate all functions    OPTIONS = FFC_OPTIONS.copy()    OPTIONS["no-evaluate_basis"] = True    OPTIONS["no-evaluate_basis_derivatives"] = True    # Generate code    print "Compiling element %d out of %d..." % (i, len(elements))    element = elements[i]    name = "ffc_%.2d" % i    compile(element, name, options=OPTIONS)    # Save signatures of elements and dof maps    dof_map = DofMap(element)    signatures += [(name, element.signature(), dof_map.signature())]    # Generate code for elementmap.cppfilename = "element_library.inc"print "Generating file " + filenamefile = open(filename, "w")file.write("// Automatically generated code mapping element and dof map signatures\n")file.write("// to the corresponding ufc::finite_element and ufc::dof_map classes\n")file.write("\n")file.write("#include <cstring>\n")file.write("\n")for (name, element_signature, dof_map_signature) in signatures:    file.write("#include \"%s.h\"\n" % name)file.write("\n")file.write("#include \"ElementLibrary.h\"\n")file.write("\n")file.write("ufc::finite_element* dolfin::ElementLibrary::create_finite_element(const char* signature)\n")file.write("{\n")for (name, element_signature, dof_map_signature) in signatures:    file.write("  if (strcmp(signature, \"%s\") == 0)\n" % element_signature)    file.write("    return new %s_finite_element_0();\n" % name)file.write("  return 0;\n")file.write("}\n")file.write("\n")file.write("ufc::dof_map* dolfin::ElementLibrary::create_dof_map(const char* signature)\n")file.write("{\n")for (name, element_signature, dof_map_signature) in signatures:    file.write("  if (strcmp(signature, \"%s\") == 0)\n" % dof_map_signature)    file.write("    return new %s_dof_map_0();\n" % name)file.write("  return 0;\n")file.write("}\n")file.close()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?