Skip to content

differential

L(obj, dim=None, dual=False, version='LdR')

An alias for the laplacian() operator.

See also
  • The laplacian() function documentation.
Source code in src/dxtr/operators/differential.py
210
211
212
213
214
215
216
217
218
def L(obj:Cochain|SimplicialManifold, dim:Optional[int]=None, 
      dual:bool=False, version:str='LdR') -> Optional[Cochain]:
    """An alias for the `laplacian()` operator.

    See also
    --------
      * The `laplacian()` function documentation.
    """
    return laplacian(obj, dim=dim, dual=dual, version=version)

codifferential(cochain)

Codifferential operator acting on Cochain.

Returns:

Type Description
The (k-1)-cochain derived from the former.
Notes
  • It can only be applied on Cochain defined on a SimplicialManifold.
  • The codifferential is mathematically defined as:
  • For 1-cochain, it corresponds to the divergence of the corresponding vector field.
Source code in src/dxtr/operators/differential.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@on_manifold
def codifferential(cochain:Cochain) -> Optional[Cochain]:
    """Codifferential operator acting on `Cochain`.

    Returns
    -------
        The (k-1)-cochain derived from the former.

    Notes
    -----
      * It can only be applied on `Cochain` defined on a `SimplicialManifold`.
      * The codifferential is mathematically defined as:
                          $$\delta(\cdot) = \star d \star(\cdot)$$
      * For 1-cochain, it corresponds to the divergence of the corresponding vector field.
    """
    n, k = cochain.complex.dim, cochain.dim

    sign = (-1)**(1 + n*(k-1))

    codiff = sign * hodge_star(exterior_derivative(hodge_star(cochain)))
    codiff._name = f'Codifferential of {cochain.name}'

    return codiff 

d(cochain)

An alias for the exterior_derivative() operator.

See also
  • The exterior_derivative() function documentation.
Source code in src/dxtr/operators/differential.py
192
193
194
195
196
197
198
199
def d(cochain:Cochain) -> Cochain:
    """An alias for the `exterior_derivative()` operator.

    See also
    --------
      * The `exterior_derivative()` function documentation.
    """
    return exterior_derivative(cochain)

delta(cochain)

An alias for the codifferential() operator.

See also
  • The codifferential() function documentation.
Source code in src/dxtr/operators/differential.py
201
202
203
204
205
206
207
208
def delta(cochain:Cochain) -> Optional[Cochain]:
    """An alias for the `codifferential()` operator.

    See also
    --------
      * The `codifferential()` function documentation.
    """
    return codifferential(cochain)

exterior_derivative(cochain)

Exterior derivative acting on Cochain.

Paramters

cochain The k-cochain we want to compute the exterior derivative of.

Returns:

Type Description
The (k+1)-cochain derived from the former.
Notes
  • The exterior derivative can be applied to k-cochains with k > complex.dim, but in these cases, it will return a zero array of size N = number of top-simplices in the primal case or number of 0-simplices in the dual case.
  • In the case of primal vector-valued 1-cochain, we apply a 'correction' to account for the fact that the vectors are not tangent to the primal complex. This correction is necessary for the computation of the mean curvature.
  • The correction mentioned above might not be always necessary, keep that in mind.
Source code in src/dxtr/operators/differential.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def exterior_derivative(cochain:Cochain) -> Cochain:
    """Exterior derivative acting on `Cochain`.

    Paramters
    ---------
    cochain
        The k-cochain we want to compute the exterior derivative of.

    Returns
    -------
        The (k+1)-cochain derived from the former.

    Notes
    -----
      * The exterior derivative can be applied to k-cochains with 
        k > complex.dim, but in these cases, it will return a zero array of
        size N = number of top-simplices in the primal case or number of 
        0-simplices in the dual case.
      * In the case of primal vector-valued 1-cochain, we apply a 'correction'
        to account for the fact that the vectors are not tangent to the primal 
        complex. This correction is necessary for the computation of the 
        mean curvature. 
      * The correction mentioned above might not be always necessary, keep
        that in mind.
    """

    cplx = cochain.complex
    n = cplx.dim
    k = cochain.dim
    isdual = cochain.isdual
    vals = cochain.values
    name = f'Exterior derivative of {cochain.name}'

    if 0<=k<=n:
        mtrx = cplx[n-k].boundary if isdual else cplx[k].coboundary

        if cochain.isvectorvalued  & (not cochain.isdual) & (k == 1):
            logger.info('A correction is applied to account for the a priori' +
                        ' non-tangent nature of the vector-valued cochain.')
            mtrx = mtrx @ _correction(cplx)

    if n < k:
        Nk = cplx[0].size if isdual else cplx[n].size
        mtrx = sp.diags(Nk*[0])
    if k < 0:
        Nk = cplx[n].size if isdual else cplx[0].size
        mtrx = sp.diags(Nk*[0])

    return Cochain(cplx, dim=k+1, values=mtrx@vals, dual=isdual, name=name)

laplacian(obj, dim=None, dual=False, version='LdR')

Laplacian acting on Cochain or SimplicialManifold.

Paramters

obj Either the Cochain we want to apply the Laplacian on; or the SimplicialManifold we want to compute the Laplacian of, see Notes. dim Optional (Default is None). Should only be specified when the 1st argument is a SimplicialManifold. Corresponds in this case to the topological dimension at which the Laplacian should be computed. dual Optional (default is False). Should only be specified when the 1st argument is a SimplicialManifold. If true, the generated cochain base is a dual Cochain version Optional (default is 'LdR'). Triggers the formula to use. - 'LdR': Laplace-deRham is used. - 'LB': Laplace-Beltrami is used.

Returns:

Type Description
A k-`Cochain` representing the laplacian of the input.
Notes
  • The Laplace-Beltrami operator is defined as:
  • The Laplace-deRham operator is defined as:
  • For 0-cochain the two should match.
  • Accepting SimplicialManifolds as inputs is usefull to perform
    spectral analysis.
  • It is not clear to me if we should allow this operator to be applied on a SimplicialManifold... It makes life easier but I feel
Source code in src/dxtr/operators/differential.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def laplacian(obj: Cochain|SimplicialManifold, dim:Optional[int]=None, 
              dual:bool=False, version:str='LdR') -> Optional[Cochain]:
    """Laplacian acting on `Cochain` or `SimplicialManifold`.

    Paramters
    ---------
    obj
        Either the `Cochain` we want to apply the Laplacian on; or the 
        `SimplicialManifold` we want to compute the Laplacian of, see Notes.
    dim
        Optional (Default is None). Should only be specified when the 1st 
        argument is a SimplicialManifold. Corresponds in this case to the 
        topological dimension at which the Laplacian should be computed.
    dual
        Optional (default is False). Should only be specified when the 1st 
        argument is a SimplicialManifold. If true, the generated cochain 
        base is a dual `Cochain`
    version
        Optional (default is 'LdR'). Triggers the formula to use.
        - 'LdR': Laplace-deRham is used.
        - 'LB': Laplace-Beltrami is used.

    Returns
    -------
        A k-`Cochain` representing the laplacian of the input.

    Notes
    -----
      * The Laplace-Beltrami operator is defined as:
                          $$\Delta_{B} = \delta d(\cdot)$$
      * The Laplace-deRham operator is defined as:
                          $$\Delta_{LdR} = \delta d(\cdot) + d\delta(\cdot)$$
      * For 0-cochain the two should match.
      * Accepting `SimplicialManifolds` as inputs is usefull to perform    
        spectral analysis.
      * It is not clear to me if we should allow this operator to be applied on 
        a `SimplicialManifold`... It makes life easier but I feel
    """

    if not isinstance(obj, Cochain):
        try:
            assert isinstance(obj, SimplicialManifold), (
    f'Argument of type {type(obj)} are not supported. Please provide '
    +'a `Cochain` or a `SimplicialManifold`.')

            assert dim is not None, (
    'Must specify dimension when applying Laplacian to a `SimplicialManifold`')

            cochain = cochain_base(obj, dim, dual=dual)

        except AssertionError as msg:
            logger.warning(msg)
            return None
    else:
        try: 
            cochain = obj
            assert isinstance(cochain.complex, SimplicialManifold), (
                'Input `Cochain` must be defined on a `SimplicialManifold`.')

        except AssertionError as msg:
            logger.warning(msg)
            return None


    if cochain.dim == 0: version = 'LB'

    lpc = delta(d(cochain))

    if version == 'LdR': lpc += d(delta(cochain))

    lpc._name = f'Laplacian of {cochain.name}'

    return lpc