Commit 0191aaa2 authored by Adel Kara Slimane's avatar Adel Kara Slimane
Browse files

Renamed energy classes and moved them to tkwant.operator module

parent 2d921848
Pipeline #34341 failed with stages
in 16 minutes
### tkwant-energy-transport
This is a fork of [tkwant](https://gitlab.kwant-project.org/kwant/tkwant) where an additional module, `tkwant.operator.energy`, have been added: it enables the calculation of the time dependant energy related quantities: energy current, source, density and heat current.
This is a fork of [tkwant](https://gitlab.kwant-project.org/kwant/tkwant) where an additional module, `tkwant.operator`, have been added: it enables the calculation of the time dependant energy related quantities: energy current, source, density and heat current.
This specific branch contains our newer approach in implementing these energy related classes.
......
......@@ -10,7 +10,7 @@ The following modules of tkwant are used directly most frequently
tkwant.leads
tkwant.onebody
tkwant.manybody
tkwant.operator.energy
tkwant.operator
Modules mainly for internal use
===============================
......
:mod:`tkwant.operator.energy` -- Energy related operators and observables
:mod:`tkwant.operator` -- Energy related operators and observables
=========================================================================
.. module:: tkwant.operator.energy
.. module:: tkwant.operator
Helper Functions
----------------
.. autosummary::
:toctree: generated/
SiteValidation
EnergySiteValidator
Observables
-----------
.. autosummary::
:toctree: generated/
Current
Source
Density
EnergyCurrent
EnergySource
EnergyDensity
LeadHeatCurrent
CurrentDivergence
EnergyCurrentDivergence
......@@ -64,7 +64,7 @@ The heat current leaving a lead :math:`α` to the central system :math:`C` is de
where :math:`I^ε_α=\sum_{i \in α}\sum_{j \in C}I^ε_{ji}`, :math:`I^N_α=\sum_{i \in α}\sum_{j \in C}I^N_{ji}`, :math:`S^ε_α=\sum_{i \in α}S^ε_i`, and :math:`μ_α` is chemical potential of lead :math:`α`.
Each one of the previously defined energy quantities have been implemented as classes in tKwant under the `~tkwant.operator.energy` module. Namely `~tkwant.operator.energy.Density`, `~tkwant.operator.energy.Current`, `~tkwant.operator.energy.Source` and `~tkwant.operator.energy.LeadHeatCurrent`. An additional class `~tkwant.operator.energy.CurrentDivergence` exists to calculate easily the outgoing energy flux off a set of sites. These classes enable using :math:`\hat ε`, :math:`\hat H` or a user defined operator (with specified values on sites) as energy operators, more information is available in the class' documentation.
Each one of the previously defined energy quantities have been implemented as classes in tKwant under the `~tkwant.operator` module. Namely `~tkwant.operator.EnergyDensity`, `~tkwant.operator.EnergyCurrent`, `~tkwant.operator.EnergySource` and `~tkwant.operator.LeadHeatCurrent`. An additional class `~tkwant.operator.EnergyCurrentDivergence` exists to calculate easily the outgoing energy flux off a set of sites. These classes enable using :math:`\hat ε`, :math:`\hat H` or a user defined operator (with specified values on sites) as energy operators, more information is available in the class' documentation.
Example : Quantum dot embedded in a 1D chain
......@@ -143,7 +143,7 @@ The system is thus the following
kwant.plot(builder)
The lists of sites ``added_sites_left`` and ``added_sites_right`` are used when declaring `~tkwant.operator.energy.LeadHeatCurrent` operator instances by giving them to the ``added_lead_sites`` parameter:
The lists of sites ``added_sites_left`` and ``added_sites_right`` are used when declaring `~tkwant.operator.LeadHeatCurrent` operator instances by giving them to the ``added_lead_sites`` parameter:
.. jupyter-execute::
......@@ -153,11 +153,11 @@ The lists of sites ``added_sites_left`` and ``added_sites_right`` are used when
μL = 0.5 * Γ # Chemical potential in the left lead
μR = -0.5 * Γ # Chemical potential in the right lead
lead_heat_current_right_op = tkwant.operator.energy.LeadHeatCurrent(syst, chemical_potential=μR, added_lead_sites=added_sites_right)
lead_heat_current_right_op = tkwant.operator.LeadHeatCurrent(syst, chemical_potential=μR, added_lead_sites=added_sites_right)
lead_heat_current_left_op = tkwant.operator.energy.LeadHeatCurrent(syst, chemical_potential=μL, added_lead_sites=added_sites_left)
lead_heat_current_left_op = tkwant.operator.LeadHeatCurrent(syst, chemical_potential=μL, added_lead_sites=added_sites_left)
The ``added_lead_sites`` parameter is used by the `~tkwant.operator.energy.LeadHeatCurrent` class to find the hopping(s) on which it will calculate the heat current: they are the outgoing hoppings from the set of sites ``added_lead_sites``, excluding hoppings that connect to lead sites. The calculated hoppings are stored in its `~tkwant.operator.energy.LeadHeatCurrent.hoppings` member. We can check that these correspond to ``(lat(0), lat(-1))`` for the left lead and ``(lat(0), lat(1))`` for the right lead:
The ``added_lead_sites`` parameter is used by the `~tkwant.operator.LeadHeatCurrent` class to find the hopping(s) on which it will calculate the heat current: they are the outgoing hoppings from the set of sites ``added_lead_sites``, excluding hoppings that connect to lead sites. The calculated hoppings are stored in its `~tkwant.operator.LeadHeatCurrent.hoppings` member. We can check that these correspond to ``(lat(0), lat(-1))`` for the left lead and ``(lat(0), lat(1))`` for the right lead:
.. jupyter-execute::
......@@ -169,9 +169,9 @@ Now let's declare the other operators. Just like the particle `~kwant.operator.C
.. jupyter-execute::
particle_current_op = kwant.operator.Current(syst, where=[(lat(0), lat(-1)), (lat(0), lat(1))])
energy_current_op = tkwant.operator.energy.Current(syst, where=[(lat(0), lat(-1)), (lat(0), lat(1))])
energy_source_op = tkwant.operator.energy.Source(syst, where=[lat(-1),lat(1)])
energy_density_op = tkwant.operator.energy.Density(syst, where=[lat(0)])
energy_current_op = tkwant.operator.EnergyCurrent(syst, where=[(lat(0), lat(-1)), (lat(0), lat(1))])
energy_source_op = tkwant.operator.EnergySource(syst, where=[lat(-1),lat(1)])
energy_density_op = tkwant.operator.EnergyDensity(syst, where=[lat(0)])
We can now initialize the solver
......@@ -183,13 +183,13 @@ We can now initialize the solver
TR = 0.0 * Γ # Temperature in the right lead
occupation = [None] * len(syst.leads)
occupation[0] = tkwant.manybody.make_occupation(chemical_potential=μL, temperature=TL)
occupation[1] = tkwant.manybody.make_occupation(chemical_potential=μR, temperature=TR)
occupation[0] = tkwant.manybody.lead_occupation(chemical_potential=μL, temperature=TL)
occupation[1] = tkwant.manybody.lead_occupation(chemical_potential=μR, temperature=TR)
# Maximum simulation time
tmax = 6. / Γ
# Initialize the solver (to solve t-dep SEQ)
solver = tkwant.manybody.State(syst, tmax, occupation, params={'t0': t0, 'ε0': ε0, 'Δε': Δε}, error_estimate_operator=energy_density_op)
solver = tkwant.manybody.State(syst, tmax, occupation, params={'t0': t0, 'ε0': ε0, 'Δε': Δε}, error_op=energy_density_op)
And run the simulation. Energy operators are evaluated in the same way as the particle operators.
......
......@@ -105,8 +105,8 @@ def main():
builder, lat, added_sites_left, added_sites_right = make_system(a, γ, γc)
syst = builder.finalized()
lead_heat_current_right_op = tkwant.operator.energy.LeadHeatCurrent(syst, chemical_potential=μR, added_lead_sites=added_sites_right, baseOperator='kinetic+')
lead_heat_current_left_op = tkwant.operator.energy.LeadHeatCurrent(syst, chemical_potential=μL, added_lead_sites=added_sites_left, baseOperator='kinetic+')
lead_heat_current_right_op = tkwant.operator.LeadHeatCurrent(syst, chemical_potential=μR, added_lead_sites=added_sites_right, baseOperator='kinetic+')
lead_heat_current_left_op = tkwant.operator.LeadHeatCurrent(syst, chemical_potential=μL, added_lead_sites=added_sites_left, baseOperator='kinetic+')
if am_master():
......@@ -118,19 +118,19 @@ def main():
print("Left=", used_hoppings_left)
energy_current_op = tkwant.operator.energy.Current(syst, where=[(lat(0), lat(1)), (lat(2), lat(1))], baseOperator='kinetic+', sum=False)
energy_source_op = tkwant.operator.energy.Source(syst, where=[lat(1)], baseOperator='kinetic+', sum=True)
energy_density_op = tkwant.operator.energy.Density(syst, where=[lat(1)], baseOperator='kinetic+', sum=True)
energy_current_divergence_op = tkwant.operator.energy.CurrentDivergence(syst, where=[lat(1)])
energy_current_op = tkwant.operator.EnergyCurrent(syst, where=[(lat(0), lat(1)), (lat(2), lat(1))], baseOperator='kinetic+', sum=False)
energy_source_op = tkwant.operator.EnergySource(syst, where=[lat(1)], baseOperator='kinetic+', sum=True)
energy_density_op = tkwant.operator.EnergyDensity(syst, where=[lat(1)], baseOperator='kinetic+', sum=True)
energy_current_divergence_op = tkwant.operator.EnergyCurrentDivergence(syst, where=[lat(1)])
# Occupation, for each lead
occupation = [None] * len(syst.leads)
occupation[0] = tkwant.manybody.make_occupation(chemical_potential=μL, temperature=TL)
occupation[1] = tkwant.manybody.make_occupation(chemical_potential=μR, temperature=TR)
occupation[0] = tkwant.manybody.lead_occupation(chemical_potential=μL, temperature=TL)
occupation[1] = tkwant.manybody.lead_occupation(chemical_potential=μR, temperature=TR)
# Initialize the solver (to solve t-dep SEQ)
solver = tkwant.manybody.State(syst, tmax, occupation, params={'t0': t0, 'ε0': ε0, 'Δε': Δε}, error_estimate_operator=energy_density_op)
solver = tkwant.manybody.State(syst, tmax, occupation, params={'t0': t0, 'ε0': ε0, 'Δε': Δε}, error_op=energy_density_op)
# Have the system evolve forward in time, calculating the operator over the system
energy_current = []
......
......@@ -8,7 +8,9 @@
# http://kwant-project.org/authors.
"""tkwant operators"""
import importlib
__all__ = ["energy"]
from .energy import __all__
from . import energy
for classname in __all__:
exec("from .energy import {0}".format(classname))
\ No newline at end of file
......@@ -11,7 +11,7 @@ from kwant.graph.defs import gint_dtype
from kwant.graph.defs cimport gint
from kwant.operator cimport Current as ParticleCurrent
cdef class Current:
cdef class EnergyCurrent:
cdef public int sum, where_size, operatorType
cdef public object syst, customOnsite
cdef public str time_name
......@@ -19,7 +19,7 @@ cdef class Current:
cdef public gint[:, :] where, _site_ranges
cdef public list _neighbors_i, _neighbors_j # List of lists of the neighbors of each site i and j in of the (j, i) hoppings in the `where` list
cdef class Source:
cdef class EnergySource:
cdef public int sum, where_size, operatorType, has_dt_hamiltonian, has_dt_customOnsite, _saved_static_onsite
cdef public object syst, customOnsite, dt_hamiltonian, dt_customOnsite
cdef public str time_name
......@@ -29,7 +29,7 @@ cdef class Source:
cdef public list _neighbors_i # List of lists of the neighbors of each site i in the `where` list
cdef public dict _static_onsite
cdef class Density:
cdef class EnergyDensity:
cdef public int sum, where_size, operatorType
cdef public object syst, customOnsite
cdef public str time_name
......@@ -40,17 +40,17 @@ cdef class Density:
cdef class LeadHeatCurrent:
cdef public object syst
cdef public ParticleCurrent _particle_current_op
cdef public Source _energy_source_op
cdef public Current _energy_current_op
cdef public EnergySource _energy_source_op
cdef public EnergyCurrent _energy_current_op
cdef public double chemical_potential
cdef public gint[:, :] added_lead_sites # Sites of the lead that have been added to the system
cdef public list hoppings # Hoppings on wich to calculate the heat current contributions
cdef public list source_sites # Sites on which to calculate the energy source, it's the head of each hopping of `hoppings`
cdef class CurrentDivergence:
cdef class EnergyCurrentDivergence:
cdef public int sum, where_size
cdef public object syst
cdef public Current _energy_current_op
cdef public EnergyCurrent _energy_current_op
cdef public gint[:, :] where
cdef public gint[:] _neighbors_num # number of neighbors of each site of the where list
cdef public list _energy_current_where # The where list of hoppings (j, i) to give to the energy current
\ No newline at end of file
......@@ -21,15 +21,15 @@ from kwant.operator cimport _get_orbs
from kwant.operator import _get_tot_norbs
from kwant._common import deprecate_args
from kwant.operator cimport Current as PartsicleCurrent
from kwant.operator cimport Current as ParticleCurrent
from .. import _common
from .. import onebody
__all__ = ['Current', 'Source', 'Density', 'LeadHeatCurrent', 'SiteValidation']
__all__ = ['EnergyCurrent', 'EnergyCurrentDivergence', 'EnergySource', 'EnergyDensity', 'LeadHeatCurrent', 'EnergySiteValidator']
class SiteValidation:
class EnergySiteValidator:
r"""
A class that tells if energy related quantities can be calculated on a given site or hopping.
......@@ -145,7 +145,7 @@ class SiteValidation:
return normalized_hop[0] not in self.interface_site_ids and normalized_hop[1] not in self.interface_site_ids
cdef class Current:
cdef class EnergyCurrent:
r"""
An operator for calculating the local energy current between two sites.
......@@ -153,7 +153,7 @@ cdef class Current:
The value of current between two sites has no physical meaning as it is not uniquely defined.
However, the total outgoing current from a site (*i.e.* the sum of the energy currents
from a site :math:`i` to all its neighbors :math:`j`), calculated by the class
`~tkwant.operator.energy.CurrentDivergence`, is uniquely defined.
`~tkwant.operator.EnergyCurrentDivergence`, is uniquely defined.
"""
@cython.embedsignature
......@@ -441,7 +441,7 @@ cdef class Current:
return np.sum(result) if self.sum else result
cdef class Source:
cdef class EnergySource:
r"""
An operator for calculating the local input power on sites.
......@@ -845,7 +845,7 @@ cdef class Source:
cdef class Density:
cdef class EnergyDensity:
r"""
An operator for calculating the local energy density on sites.
"""
......@@ -1184,12 +1184,12 @@ cdef class LeadHeatCurrent:
the central system :math:`C`:
.. math::
I_^H(t) = \sum_{i \in L}\sum_{j \in C}I^ε_{ji} - \sum_{i \in L}S^ε_i - μ \sum_{i \in L}\sum_{j \in C}I^N_{ji}
I_L^H(t) = \sum_{i \in L, j \in C} I^ε_{ji} - \sum_{i \in L} S^ε_i - μ \sum_{i \in L, j \in C} I^N_{ji}
where :math:`I^ε_{ji}` is local the energy current flowing from
:math:`i` to :math:`j` (calculated by the `~tkwant.operator.energy.Current`
:math:`i` to :math:`j` (calculated by the `~tkwant.operator.EnergyCurrent`
class); :math:`S^ε_i` is the input power
on site :math:`i` (calculated by the `~tkwant.operator.energy.Source` class);
on site :math:`i` (calculated by the `~tkwant.operator.EnergySource` class);
and :math:`I^{N}_{ji}` is the particle current flowing from site :math:`i`
to site :math:`j` (calculated by the `~kwant.operator.Current` class). :math:`μ`
is the chemical potential of the lead, given by `chemical_potential`.
......@@ -1267,12 +1267,12 @@ cdef class LeadHeatCurrent:
the heat current. The attribute `hoppings` are given to it as a
``where`` at instantiation.
_energy_source_op : `~tkwant.operator.energy.Source`
_energy_source_op : `~tkwant.operator.EnergySource`
An instance of tKwant's energy source, used internally to calculate
the heat current. The attribute `source_sites` are given to it as a
``where`` at instantiation.
_energy_current_op : `~tkwant.operator.energy.Current`
_energy_current_op : `~tkwant.operator.EnergyCurrent`
An instance of tKwant's energy current, used internally to calculate
the heat current. The attribute `hoppings` are given to it as a
``where`` at instantiation.
......@@ -1306,8 +1306,8 @@ cdef class LeadHeatCurrent:
self._update_hoppings_and_sites()
self._particle_current_op = ParticleCurrent(syst, where=self.hoppings)
self._energy_current_op = Current(syst, where=self.hoppings, baseOperator=baseOperator, customOnsite=customOnsite)
self._energy_source_op = Source(syst, where=self.source_sites, baseOperator=baseOperator, dt_hamiltonian=dt_hamiltonian,\
self._energy_current_op = EnergyCurrent(syst, where=self.hoppings, baseOperator=baseOperator, customOnsite=customOnsite)
self._energy_source_op = EnergySource(syst, where=self.source_sites, baseOperator=baseOperator, dt_hamiltonian=dt_hamiltonian,\
dt_customOnsite=dt_customOnsite, customOnsite=customOnsite, dt=dt)
def _check_added_lead_sites(self):
......@@ -1397,7 +1397,7 @@ cdef class LeadHeatCurrent:
- self.chemical_potential * self._particle_current_op(bra=psi, params=params))
cdef class CurrentDivergence:
cdef class EnergyCurrentDivergence:
r"""
An operator that calculates the net energy current leaving a given site
of the system by summing the outgoing energy currents towards its neighbors.
......@@ -1448,7 +1448,7 @@ cdef class CurrentDivergence:
D_i(t) = \sum_j I^ε_{ji}
where :math:`I^ε_{ji}` is the energy current flowing from site :math:`i`
to site :math:`j` (calculated by the class `~tkwant.operator.energy.Current`).
to site :math:`j` (calculated by the class `~tkwant.operator.EnergyCurrent`).
Attributes
----------
......@@ -1465,7 +1465,7 @@ cdef class CurrentDivergence:
Whether to sum the current divergences over the `where` list and return a
single float result.
_energy_current_op : `~tkwant.operator.energy.Current`
_energy_current_op : `~tkwant.operator.EnergyCurrent`
An instance of tKwant's energy current, used internally to calculate
the divergences. The attribute `_energy_current_where` is given to it as a
``where`` at instantiation.
......@@ -1489,7 +1489,7 @@ cdef class CurrentDivergence:
self._update_energy_current_where()
self._energy_current_op = Current(syst, self._energy_current_where, baseOperator=baseOperator, customOnsite=customOnsite, sum=sum)
self._energy_current_op = EnergyCurrent(syst, self._energy_current_where, baseOperator=baseOperator, customOnsite=customOnsite, sum=sum)
def _update_energy_current_where(self):
......@@ -1528,8 +1528,8 @@ cdef class CurrentDivergence:
.. math::
D_i^E(ψ, t) = \sum_j I^E_{ji}(ψ, t)
Where :math:`I^E_{ji}(ψ, t)` is calculated with `~tkwant.operator.energy.Current.__call__`
from the `~tkwant.operator.energy.Current` class.
Where :math:`I^E_{ji}(ψ, t)` is calculated with `~tkwant.operator.EnergyCurrent.__call__`
from the `~tkwant.operator.EnergyCurrent` class.
Parameters
----------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment