3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 22:03:43 +01:00
dft_tools/pytriqs/operators/operators2_desc.py
Olivier Parcollet 243d4a798b wrapper: add use_module
- a module can use the converters used by another
  with the use_module('A') command.
  In which case :
    - the generate converter header for A will be included.
    - the header, at the top, now contains a simple list of all
      wrapped types, which is then included in the wrapped_types
      of the module for proper code generation.
- simplify the code generation : just generate_code.
- all arguments are analyzed from sys.argv at the import of the
  wrap_generator module. In any case, the xx_desc.py will be called from the corresponding
  cmake command, hence with the right arguments.
- Added a dependencies in my_module_B of wrap_test to show how to make
  the dependencies in the cmake file, if needed.
2014-05-30 19:34:13 +02:00

56 lines
2.6 KiB
Python

from wrap_generator import *
# The operator class
op = class_(
py_type = "Operator",
c_type = "many_body_operator<double>",
is_printable= True,
arithmetic = ("algebra","double")
)
op.add_constructor(signature="()", doc="create zero operator")
# Complete the number_protocol
mbo = 'many_body_operator<double>'
scal = 'double'
# Allow + and - between scalar and operator
add = op.number_protocol['add']
add.add_overload (calling_pattern = "+", args = [(mbo,'x'), (scal,'y')], rtype = mbo)
add.add_overload (calling_pattern = "+", args = [(scal,'x'), (mbo,'y')], rtype = mbo)
sub = op.number_protocol['subtract']
sub.add_overload (calling_pattern = "-", args = [(mbo,'x'), (scal,'y')], rtype = mbo)
sub.add_overload (calling_pattern = "-", args = [(scal,'x'), (mbo,'y')], rtype = mbo)
# Allow unary - on an operator
neg = pyfunction(py_name = "__neg__")
neg.arity = 1
neg.add_overload (calling_pattern = "-", args = [(mbo,'x')], rtype = mbo)
op.number_protocol['negative'] = neg
# The many_body_operators module
module = module_(full_name = "operators2", doc = "Doc of my_module")
module.add_include("<triqs/operators/many_body_operator.hpp>")
module.add_include("<triqs/arrays.hpp>")
module.add_using("namespace triqs::utility")
module.add_class(op)
# Annihilation operators
module.add_function(name = "c", signature="many_body_operator<double>(std::string ind1)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(std::string ind1, std::string ind2)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(std::string ind1, int i)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(int i, std::string ind1)", doc="annihilation operator")
module.add_function(name = "c", signature="many_body_operator<double>(int i, int j)", doc="annihilation operator")
# Construction operators
module.add_function(name = "c_dag", signature="many_body_operator<double>(std::string ind1)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(std::string ind1, std::string ind2)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(std::string ind1, int i)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(int i, std::string ind1)", doc="annihilation operator")
module.add_function(name = "c_dag", signature="many_body_operator<double>(int i, int j)", doc="annihilation operator")
# to generate the module code
if __name__ == '__main__' :
module.generate_code()