cochain
Cochain
A cochain data structure.
A discrete version of the mathematical notion of differential k-form. Defined on a discrete version of the notion of manifold.
Attributes:
| Name | Type | Description |
|---|---|---|
_complex |
simplicialcomplex
|
The simplicial complex the cochain is defined on. |
_dim |
int
|
The topological dimension at which the cochain is defined. |
_val |
ndarray(float)
|
The value of the cochain on the associated simplices. |
_dual |
bool
|
Default is False. If True the cochain is defined on the dual complex. |
Notes
- The values of the
Cochaincan be scalars or vectors. - We can also define values as sparse matrices but this is mostly used
to define differential operators on a whole
SimplicialComplex.
Source code in src/dxtr/cochains/cochain.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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
complex
property
Gets the SimplicialComplex on which the Cochain is defined.
Returns:
| Type | Description |
|---|---|
SimplicialComplex
|
The simplicial complex. |
dim
property
The topological dimension of the Cochain.
Returns:
| Type | Description |
|---|---|
int
|
The topological dimension. |
indices
property
Gets the indices of the k-simplices where the Cochain is defined.
Returns:
| Type | Description |
|---|---|
list of int
|
The indices of the k-simplices. |
isdual
property
Checks if the Cochain is defined on the dual complex.
Returns:
| Type | Description |
|---|---|
bool
|
True if the cochain is defined on the dual complex, False otherwise. |
isvectorvalued
property
Checks if the values of the Cochain are vectors.
Returns:
| Type | Description |
|---|---|
bool
|
True if the values are vectors, False otherwise. |
name
property
Gets the name of the Cochain.
Returns:
| Type | Description |
|---|---|
str
|
The name of the cochain. |
positions
property
Gets the vertices of the simplices where cochain values are defined.
Returns:
| Type | Description |
|---|---|
np.ndarray of float, optional
|
The vertices of the simplices. |
Notes
- Returns None if the
Cochainis defined on anAbstractSimplicialComplex.
shape
property
Gets the Cochain shape.
Returns:
| Type | Description |
|---|---|
tuple of int or None
|
The shape of the cochain. |
Notes
- The shape is given as a tuple. The second number is 0 for a scalar-valued cochain, 1 for a vector, 2 for a tensor, etc...
values
property
Gets the values of the Cochain.
Returns:
| Type | Description |
|---|---|
np.ndarray of float, sp.spmatrix, or dict, optional
|
The values of the cochain. |
__add__(other)
Enables to add two cochains together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cochain
|
The other cochain to add. |
required |
Returns:
| Type | Description |
|---|---|
Cochain or None
|
The resulting cochain if compatible, None otherwise. |
Source code in src/dxtr/cochains/cochain.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__(complex, dim, values=None, dual=False, name=None)
Instantiates a Cochain object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
complex
|
SimplicialComplex
|
The simplicial complex the cochain is defined on. |
required |
dim
|
int
|
The topological dimension at which the cochain is defined. |
required |
values
|
iterable of float
|
The value of the cochain on the associated simplices. Default is None. |
None
|
dual
|
bool
|
If True the cochain is defined on the dual complex. Default is False. |
False
|
name
|
str
|
The name of the cochain. Default is None. |
None
|
Notes
- If no dim is specified, we look for the k-Module with the same dimension as the provided values.
Source code in src/dxtr/cochains/cochain.py
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 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
__is_compatible_with__(other)
Checks if algebraic operations can be performed between two cochains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cochain
|
The other cochain to check compatibility with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the cochains are compatible, False otherwise. |
Source code in src/dxtr/cochains/cochain.py
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 187 188 189 | |
__mul__(other)
Enables the multiplication on the right.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
float, int, np.ndarray of float, or Cochain
|
The value or cochain to multiply with. |
required |
Returns:
| Type | Description |
|---|---|
Cochain or None
|
The resulting cochain if compatible, None otherwise. |
Notes
- WARNING: when multiplying a
Cochainby anp.ndarray, one must keep theCochainon the left side of the*operator:C2 = C1 * arrThe inverse would not work for the array will try to multiply term by term.
Source code in src/dxtr/cochains/cochain.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
__rmul__(other)
Enables the multiplication with a number on the left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
float, int, np.ndarray of float, or Cochain
|
The value or cochain to multiply with. |
required |
Returns:
| Type | Description |
|---|---|
Cochain or None
|
The resulting cochain if compatible, None otherwise. |
Source code in src/dxtr/cochains/cochain.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
__sub__(other)
Enables to subtract two cochains from one another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Cochain
|
The other cochain to subtract. |
required |
Returns:
| Type | Description |
|---|---|
Cochain or None
|
The resulting cochain if compatible, None otherwise. |
Source code in src/dxtr/cochains/cochain.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
__truediv__(other)
Enables the division on the right.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
float, int, or np.ndarray of float
|
The value to divide by. |
required |
Returns:
| Type | Description |
|---|---|
Cochain or None
|
The resulting cochain if compatible, None otherwise. |
Notes
- The division is not implemented between
Cochaininstances yet.
Source code in src/dxtr/cochains/cochain.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
from_file(path, name=None)
classmethod
Instantiates a Cochain from a .vtk file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
The path to the |
required |
name
|
str
|
The name of the cochain. Default is None. |
None
|
Notes
- For now can only work with primal
Cochainobjects.
Source code in src/dxtr/cochains/cochain.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
items()
Enables to iterate over Cochain indices and values.
Yields:
| Type | Description |
|---|---|
tuple of int and float
|
Indices of the k-simplices where values are defined and the values of the cochain. |
Source code in src/dxtr/cochains/cochain.py
459 460 461 462 463 464 465 466 467 468 469 | |
to_file(file_name, format='.ply', folder=None)
Saves the Cochain instance on disk in the .vtk format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
The name of the file to write on disk. |
required |
format
|
str
|
The type of file to write, see Notes. Default is |
'.ply'
|
folder
|
str or Path
|
The location where to write the file. Default is the current working directory. |
None
|
Notes
Cochaininstances can only be saved in thevtkformat.- If no folder is provided, the file will be recorded in the current working directory.
Source code in src/dxtr/cochains/cochain.py
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 | |
toarray()
Gets the values of the cochain as a numpy array.
Returns:
| Type | Description |
|---|---|
np.ndarray of float, optional
|
The values of the cochain as a numpy array. |
Source code in src/dxtr/cochains/cochain.py
472 473 474 475 476 477 478 479 480 481 482 483 | |
value_closest_to(position)
Gets the value closest to a provided position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
np.ndarray of float
|
The position to find the closest value to. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The value closest to the provided position. |
Source code in src/dxtr/cochains/cochain.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
cochain_base(complex, dim, dual=False)
Generates The k-cochain base on a given manifold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
complex
|
SimplicialComplex
|
The simplicial manifold to work on. |
required |
dim
|
int
|
The topological dimension (k) of the desired k-cochain base. |
required |
dual
|
bool
|
If True the returned |
False
|
Returns:
| Type | Description |
|---|---|
Cochain or None
|
A k- |
Notes
- The identity matrix is implemented as a
scipy.sparse.identity()one.
Source code in src/dxtr/cochains/cochain.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |