File:  [CENS] / python / pyGiNaC / wrappers / tensor.py
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Apr 11 20:31:31 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Exposed lots of functions. Documented most important classes/functions. minor_version = 2

# This file is part of the PyGiNaC package.
# http://cens.ioc.ee/projects/pyginac/
#
# $Revision: 1.2 $
# $Id: tensor.py,v 1.2 2001-04-11 20:31:31 pearu Exp $
#
# Copyright 2001 Pearu Peterson all rights reserved,
# Pearu Peterson <pearu@cens.ioc.ee>
# Permission to use, modify, and distribute this software is given under the
# terms of the LGPL.  See http://www.fsf.org
#
# NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
#

depends = ['basic']

uses = []

#STARTPROTO

class diracgamma(tensor):
    """Represents the Dirac gamma Lorentz vector."""
class diracone(tensor):
    """Represents the Clifford algebra unity element."""
class su3d(tensor):
    """Represents the tensor of symmetric su(3) structure constants."""
class su3f(tensor):
    """Represents the tensor of antisymmetric su(3) structure constants."""
class su3one(tensor):
    """Represents the su(3) unity element."""
class su3t(tensor):
    """Represents an su(3) generator."""
class tensdelta(tensor):
    """Represents the delta tensor.
    If indexed, it must have exactly two indices of the same type.
    """
class tensepsilon(tensor):
    """Represents the totally antisymmetric epsilon tensor.
    If indexed, all indices must be of the same type and their number
    must be equal to the dimension of the index space.
    """
    def __init__(self,minkowski,pos_sig):
        """tensepsilon(minkowski,pos_sig)
    minkowski - If true, tensor is in Minkowski-type space. Otherwise
        it is in a Euclidean space.
    pos_sig - If true, the metric is assumed to be diag(-1,1,1...).
        Otherwise it is diag(1,-1,-1,...). This is only relevant if
        minkowski = true. 
    """

class tensmetric(tensor):
    """Represents a general metric tensor which can be used to
    raise/lower indices.
    If indexed, it must have exactly two indices of the same type
    which must be of class varidx or a subclass.
    """
class minkmetric(tensmetric):
    """Represents a Minkowski metric tensor.
    It has all the properties of a metric tensor and is (as a matrix)
    equal to diag(1,-1,-1,...) or diag(-1,1,1,...).
    """
    def __init__(self,pos_sig):
        """minkmetric(pos_sig) - construct Lorentz metric tensor
    with given signature.
    pos_sig - If true, the metric is diag(-1,1,1...). Otherwise it
        is diag(1,-1,-1,...).
    """

def delta_tensor(i1,i2):
    """Create a delta tensor with specified indices. The indices must be
    of class idx or a subclass. The delta tensor is always symmetric
    and its trace is the dimension of the index space.
    """
def metric_tensor(i1,i2):
    """Create a symmetric metric tensor with specified indices. The
    indices must be of class varidx or a subclass. A metric tensor
    with one covariant and one contravariant index is equivalent to
    the delta tensor.
    """
def lorentz_g(i1,i2,pos_sig = 0):
    """Create a Minkowski metric tensor with specified indices. The
    indices must be of class varidx or a subclass. The Lorentz metric
    is a symmetric tensor with a matrix representation of
    diag(1,-1,-1,...) (negative signature, the default) or
    diag(-1,1,1,...) (positive signature).
    pos_sig   - Whether the signature is positive
    """

def epsilon_tensor(i1,i2,i3=None):
    """Create an epsilon tensor in a Euclidean space with two
    indices. The indices must be of class idx or a subclass, and have
    a dimension of 2. (i3 is None).

    Create an epsilon tensor in a Euclidean space with three
    indices. The indices must be of class idx or a subclass, and have
    a dimension of 3.
    """
def lorentz_eps(i1,i2,i3,i4,pos_sig=0):
    """Create an epsilon tensor in a Minkowski space with four
    indices. The indices must be of class varidx or a subclass, and
    have a dimension of 4.
    pos_sig   - Whether the signature of the metric is positive
    """

#ENDPROTO

wrapperclass = '''
UNEX_RET delta_tensor_w(python::ref i1,python::ref i2) {
  return UNEX(GiNaC::delta_tensor(ex_w(i1),ex_w(i2)));}
UNEX_RET metric_tensor_w(python::ref i1,python::ref i2) {
  return UNEX(GiNaC::metric_tensor(ex_w(i1),ex_w(i2)));}
UNEX_RET lorentz_g1_w(python::ref i1,python::ref i2) {
  return UNEX(GiNaC::lorentz_g(ex_w(i1),ex_w(i2)));}
UNEX_RET lorentz_g2_w(python::ref i1,python::ref i2, bool pos_sig) {
  return UNEX(GiNaC::lorentz_g(ex_w(i1),ex_w(i2),pos_sig));}
UNEX_RET epsilon_tensor1_w(python::ref i1,python::ref i2) {
  return UNEX(GiNaC::epsilon_tensor(ex_w(i1),ex_w(i2)));}
UNEX_RET epsilon_tensor2_w(python::ref i1,python::ref i2,python::ref i3) {
  return UNEX(GiNaC::epsilon_tensor(ex_w(i1),ex_w(i2),ex_w(i3)));}
UNEX_RET lorentz_eps1_w(python::ref i1,python::ref i2,python::ref i3,python::ref i4) {
  return UNEX(GiNaC::lorentz_eps(ex_w(i1),ex_w(i2),ex_w(i3),ex_w(i4)));}
UNEX_RET lorentz_eps2_w(python::ref i1,python::ref i2,python::ref i3,python::ref i4,bool pos_sig) {
  return UNEX(GiNaC::lorentz_eps(ex_w(i1),ex_w(i2),ex_w(i3),ex_w(i4),pos_sig));}

'''

protos = '''
'''

builder = '''
python::class_builder<GiNaC::tensor> tensor_class(this_module, "_tensor");
tensor_class.declare_base(basic_class);
tensor_py_class = python::as_object(tensor_class.get_extension_class());
'''

constructors = '''
'''

defs = '''
//tensor_class.def(&basic_w::python_str, "__str__");
//tensor_class.def(&basic_w::python_repr, "__repr__");
'''

for t in ['diracgamma','diracone',
          'su3d','su3f','su3one','su3t',
          'tensdelta','tensepsilon','tensmetric','minkmetric']:
    builder += '''
python::class_builder<GiNaC::#tensor#> #tensor#_class(this_module, "#tensor#");
#tensor#_class.declare_base(basic_class);
#tensor#_class.declare_base(tensor_class);
#tensor#_py_class = python::as_object(#tensor#_class.get_extension_class());
'''.replace('#tensor#',t)
    if t=='minkmetric':
        builder += '''minkmetric_class.declare_base(tensmetric_class);'''
        constructors += '''minkmetric_class.def(python::constructor<>());'''
    elif t=='tensmetric2':
        constructors += '''tensmetric_class.def(python::constructor<int,int>());'''
    else:
        constructors += '''
    #tensor#_class.def(python::constructor<>());
'''.replace('#tensor#',t)
    defs += '''
#tensor#_class.def(&basic_w::python_str, "__str__");
#tensor#_class.def(&basic_w::python_repr, "__repr__");
'''.replace('#tensor#',t)

    constructors += '''
    this_module.def(delta_tensor_w,"delta_tensor");
    this_module.def(metric_tensor_w,"metric_tensor");
    this_module.def(lorentz_g1_w,"lorentz_g");
    this_module.def(lorentz_g2_w,"lorentz_g");
    this_module.def(epsilon_tensor1_w,"epsilon_tensor");
    this_module.def(epsilon_tensor2_w,"epsilon_tensor");
    this_module.def(lorentz_eps1_w,"lorentz_eps");
    this_module.def(lorentz_eps2_w,"lorentz_eps");
'''
    
implementation = '''
'''

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>