signature.py

来自「finite element library for mathematic ma」· Python 代码 · 共 52 行

PY
52
字号
"""This module contains utilities for computing signatures ofproducts. Signatures are used to uniquely identify referencetensors that may be common to a group of terms."""__author__ = "Anders Logg (logg@simula.no)"__date__ = "2005-09-06 -- 2007-01-11"__copyright__ = "Copyright (C) 2005-2006 Anders Logg"__license__  = "GNU GPL version 3 or any later version"# Modified by Kristian Oelgaard 2006# Python modulesfrom re import sub# FFC modulesfrom algebra import *from tokens import *def compute_hard_signature(product):    "Compute hard (unique) signature."        # Create signature for numeric constant    numeric = "%.15e" % product.numeric        # Create signatures for basis functions    factors = []    for v in product.basisfunctions:        factors += ["{%s;%s;%s;%s;%s}" % \                    (str(v.element),     \                     str(v.index),       \                     "[" + ", ".join([str(c) for c in v.component]) + "]",                     "[" + ", ".join([str(d) for d in v.derivatives]) + "]",                     str(v.restriction))]    # Sort signatures for basis functions    factors.sort()    # Create signature for integral    integral = str(product.integral)    # Create signature for product    return "*".join([numeric] + factors + [integral])def compute_soft_signature(product):    "Compute soft (modulo secondary index numbers) signature."    # Compute hard signature    signature = compute_hard_signature(product)    # Ignore secondary index numbers    return sub('a\d+', 'a', signature)

⌨️ 快捷键说明

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