Geometry(几何) 模块¶
ppsci.geometry
¶
Geometry
¶
Base class for geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ndim
|
int
|
Number of geometry dimension. |
required |
bbox
|
Tuple[ndarray, ndarray]
|
Bounding box of upper and lower. |
required |
diam
|
float
|
Diameter of geometry. |
required |
Source code in ppsci/geometry/geometry.py
34 35 36 37 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 505 506 507 508 509 510 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
__and__(other)
¶
CSG Intersection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Geometry
|
The other geometry. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Geometry |
'Geometry'
|
The intersection of two geometries. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval1 = ppsci.geometry.Interval(0.0, 1.0)
>>> interval2 = ppsci.geometry.Interval(0.5, 1.5)
>>> intersection = interval1.__and__(interval2)
>>> intersection.bbox
(array([[0.5]]), array([[1.]]))
>>> rectangle1 = ppsci.geometry.Rectangle((0.0, 0.0), (2.0, 3.0))
>>> rectangle2 = ppsci.geometry.Rectangle((0.0, 0.0), (3.0, 2.0))
>>> intersection = rectangle1.__and__(rectangle2)
>>> intersection.bbox
(array([0., 0.], dtype=float32), array([2., 2.], dtype=float32))
>>> cuboid1 = ppsci.geometry.Cuboid((0, 0, 0), (1, 2, 2))
>>> cuboid2 = ppsci.geometry.Cuboid((0, 0, 0), (2, 1, 1))
>>> intersection = cuboid1 & cuboid2
>>> intersection.bbox
(array([0., 0., 0.], dtype=float32), array([1., 1., 1.], dtype=float32))
Source code in ppsci/geometry/geometry.py
__or__(other)
¶
CSG Union.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Geometry
|
The other geometry. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Geometry |
'Geometry'
|
The union of two geometries. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval1 = ppsci.geometry.Interval(0, 1)
>>> interval2 = ppsci.geometry.Interval(0.5, 1.5)
>>> union = interval1.__or__(interval2)
>>> union.bbox
(array([[0.]]), array([[1.5]]))
>>> rectangle1 = ppsci.geometry.Rectangle((0, 0), (2, 3))
>>> rectangle2 = ppsci.geometry.Rectangle((0, 0), (3, 2))
>>> union = rectangle1.__or__(rectangle2)
>>> union.bbox
(array([0., 0.], dtype=float32), array([3., 3.], dtype=float32))
>>> cuboid1 = ppsci.geometry.Cuboid((0, 0, 0), (1, 2, 2))
>>> cuboid2 = ppsci.geometry.Cuboid((0, 0, 0), (2, 1, 1))
>>> union = cuboid1 | cuboid2
>>> union.bbox
(array([0., 0., 0.], dtype=float32), array([2., 2., 2.], dtype=float32))
Source code in ppsci/geometry/geometry.py
__str__()
¶
Return the name of class.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Meta information of geometry. |
Examples:
>>> import ppsci
>>> interval = ppsci.geometry.Interval(0, 1)
>>> interval.__str__()
"Interval, ndim = 1, bbox = (array([[0]]), array([[1]])), diam = 1, dim_keys = ('x',)"
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> rectangle.__str__()
"Rectangle, ndim = 2, bbox = (array([0., 0.], dtype=float32), array([1., 1.], dtype=float32)), diam = 1.4142135381698608, dim_keys = ('x', 'y')"
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> cuboid.__str__()
"Cuboid, ndim = 3, bbox = (array([0., 0., 0.], dtype=float32), array([1., 1., 1.], dtype=float32)), diam = 1.7320507764816284, dim_keys = ('x', 'y', 'z')"
Source code in ppsci/geometry/geometry.py
__sub__(other)
¶
CSG Difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Geometry
|
The other geometry. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Geometry |
'Geometry'
|
The difference of two geometries. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval1 = ppsci.geometry.Interval(0.0, 2.0)
>>> interval2 = ppsci.geometry.Interval(1.0, 3.0)
>>> difference = interval1.__sub__(interval2)
>>> difference.bbox
(array([[0.]]), array([[2.]]))
>>> rectangle1 = ppsci.geometry.Rectangle((0.0, 0.0), (2.0, 3.0))
>>> rectangle2 = ppsci.geometry.Rectangle((1.0, 1.0), (2.0, 2.0))
>>> difference = rectangle1.__sub__(rectangle2)
>>> difference.bbox
(array([0., 0.], dtype=float32), array([2., 3.], dtype=float32))
>>> cuboid1 = ppsci.geometry.Cuboid((0, 0, 0), (1, 2, 2))
>>> cuboid2 = ppsci.geometry.Cuboid((0, 0, 0), (2, 1, 1))
>>> difference = cuboid1 - cuboid2
>>> difference.bbox
(array([0., 0., 0.], dtype=float32), array([1., 2., 2.], dtype=float32))
Source code in ppsci/geometry/geometry.py
boundary_normal(x)
¶
difference(other)
¶
CSG Difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Geometry
|
The other geometry. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Geometry |
'Geometry'
|
The difference of two geometries. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval1 = ppsci.geometry.Interval(0.0, 2.0)
>>> interval2 = ppsci.geometry.Interval(1.0, 3.0)
>>> difference = interval1.difference(interval2)
>>> difference.bbox
(array([[0.]]), array([[2.]]))
>>> rectangle1 = ppsci.geometry.Rectangle((0.0, 0.0), (2.0, 3.0))
>>> rectangle2 = ppsci.geometry.Rectangle((1.0, 1.0), (2.0, 2.0))
>>> difference = rectangle1.difference(rectangle2)
>>> difference.bbox
(array([0., 0.], dtype=float32), array([2., 3.], dtype=float32))
>>> cuboid1 = ppsci.geometry.Cuboid((0, 0, 0), (1, 2, 2))
>>> cuboid2 = ppsci.geometry.Cuboid((0, 0, 0), (2, 1, 1))
>>> difference = cuboid1 - cuboid2
>>> difference.bbox
(array([0., 0., 0.], dtype=float32), array([1., 2., 2.], dtype=float32))
Source code in ppsci/geometry/geometry.py
intersection(other)
¶
CSG Intersection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Geometry
|
The other geometry. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Geometry |
'Geometry'
|
The intersection of two geometries. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval1 = ppsci.geometry.Interval(0.0, 1.0)
>>> interval2 = ppsci.geometry.Interval(0.5, 1.5)
>>> intersection = interval1.intersection(interval2)
>>> intersection.bbox
(array([[0.5]]), array([[1.]]))
>>> rectangle1 = ppsci.geometry.Rectangle((0.0, 0.0), (2.0, 3.0))
>>> rectangle2 = ppsci.geometry.Rectangle((0.0, 0.0), (3.0, 2.0))
>>> intersection = rectangle1.intersection(rectangle2)
>>> intersection.bbox
(array([0., 0.], dtype=float32), array([2., 2.], dtype=float32))
>>> cuboid1 = ppsci.geometry.Cuboid((0, 0, 0), (1, 2, 2))
>>> cuboid2 = ppsci.geometry.Cuboid((0, 0, 0), (2, 1, 1))
>>> intersection = cuboid1 & cuboid2
>>> intersection.bbox
(array([0., 0., 0.], dtype=float32), array([1., 1., 1.], dtype=float32))
Source code in ppsci/geometry/geometry.py
is_inside(x)
abstractmethod
¶
Returns a boolean array where x is inside the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points to check if inside the geometry. The shape is [N, D], where D is the number of dimension of geometry. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Boolean array where x is inside the geometry. The shape is [N]. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval = ppsci.geometry.Interval(0, 1)
>>> x = np.array([[0], [0.5], [1.5]])
>>> interval.is_inside(x)
array([ True, True, False])
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> x = np.array([[0.0, 0.0], [0.5, 0.5], [1.5, 1.5]])
>>> rectangle.is_inside(x)
array([ True, True, False])
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> x = np.array([[0, 0, 0], [0.5, 0.5, 0.5], [1.5, 1.5, 1.5]])
>>> cuboid.is_inside(x)
array([ True, True, False])
Source code in ppsci/geometry/geometry.py
on_boundary(x)
abstractmethod
¶
Returns a boolean array where x is on geometry boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points to check if on the geometry boundary. The shape is [N, D], where D is the number of dimension of geometry. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Boolean array where x is on the geometry boundary. The shape is [N]. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval = ppsci.geometry.Interval(0, 1)
>>> x = np.array([[0], [0.5], [1.5]])
>>> interval.on_boundary(x)
array([ True, False, False])
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> x = np.array([[0, 0], [0.5, 0.5], [1, 1.5]])
>>> rectangle.on_boundary(x)
array([ True, False, False])
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> x = np.array([[0, 0, 0], [0.5, 0.5, 0.5], [1, 1, 1.5]])
>>> cuboid.on_boundary(x)
array([ True, False, False])
Source code in ppsci/geometry/geometry.py
periodic_point(x, component)
¶
random_boundary_points(n, random='pseudo')
abstractmethod
¶
Compute the random points on the boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points. |
required |
random
|
Literal['pseudo', 'Halton', 'LHS']
|
Random method. Defaults to "pseudo". Options: - "pseudo": Pseudo random. - "Halton": Halton sequence. - "LHS": Latin Hypercube Sampling. |
'pseudo'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Random points on the boundary. The shape is [N, D]. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> np.random.seed(42)
>>> interval = ppsci.geometry.Interval(0, 1)
>>> interval.random_boundary_points(2)
array([[0.],
[1.]], dtype=float32)
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> rectangle.random_boundary_points(2)
array([[1. , 0.49816048],
[0. , 0.19714284]], dtype=float32)
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> cuboid.random_boundary_points(2)
array([[0.83244264, 0.21233912, 0. ],
[0.18182497, 0.1834045 , 1. ]], dtype=float32)
Source code in ppsci/geometry/geometry.py
random_points(n, random='pseudo')
abstractmethod
¶
Compute the random points in the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points. |
required |
random
|
Literal['pseudo', 'Halton', 'LHS']
|
Random method. Defaults to "pseudo". Options: - "pseudo": Pseudo random. - "Halton": Halton sequence. - "LHS": Latin Hypercube Sampling. |
'pseudo'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Random points in the geometry. The shape is [N, D]. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> np.random.seed(42)
>>> interval = ppsci.geometry.Interval(0, 1)
>>> interval.random_points(2)
array([[0.37454012],
[0.9507143 ]], dtype=float32)
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> rectangle.random_points(2)
array([[0.7319939 , 0.5986585 ],
[0.15601864, 0.15599452]], dtype=float32)
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> cuboid.random_points(2)
array([[0.05808361, 0.8661761 , 0.601115 ],
[0.7080726 , 0.02058449, 0.96990985]], dtype=float32)
Source code in ppsci/geometry/geometry.py
sample_boundary(n, random='pseudo', criteria=None, evenly=False)
¶
Compute the random points in the geometry and return those meet criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points. |
required |
random
|
Literal['pseudo', 'Halton', 'LHS']
|
Random method. Defaults to "pseudo". Options: - "pseudo": Pseudo random. - "Halton": Halton sequence. - "LHS": Latin Hypercube Sampling. |
'pseudo'
|
criteria
|
Optional[Callable[..., ndarray]]
|
Criteria function. Given coords from different dimension and return a boolean array with shape [n,]. Defaults to None. |
None
|
evenly
|
bool
|
Evenly sample points. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
Dict[str, np.ndarray]: Random points in the geometry. The shape is [N, D]. their normal vectors. The shape is [N, D]. their area. The shape is [N, 1].(only if the geometry is a mesh) |
Examples:
>>> import numpy as np
>>> import ppsci
>>> np.random.seed(42)
>>> interval = ppsci.geometry.Interval(0, 1)
>>> interval.sample_boundary(2)
{'x': array([[0.],
[1.]], dtype=float32), 'normal_x': array([[-1.],
[ 1.]], dtype=float32)}
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> rectangle.sample_boundary(2)
{'x': array([[1.],
[0.]], dtype=float32), 'y': array([[0.49816048],
[0.19714284]], dtype=float32), 'normal_x': array([[ 1.],
[-1.]], dtype=float32), 'normal_y': array([[0.],
[0.]], dtype=float32)}
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> cuboid.sample_boundary(2)
{'x': array([[0.83244264],
[0.18182497]], dtype=float32), 'y': array([[0.21233912],
[0.1834045 ]], dtype=float32), 'z': array([[0.],
[1.]], dtype=float32), 'normal_x': array([[0.],
[0.]], dtype=float32), 'normal_y': array([[0.],
[0.]], dtype=float32), 'normal_z': array([[-1.],
[ 1.]], dtype=float32)}
Source code in ppsci/geometry/geometry.py
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 | |
sample_interior(n, random='pseudo', criteria=None, evenly=False, compute_sdf_derivatives=False)
¶
Sample random points in the geometry and return those meet criteria.
NOTE: sdf values returned by this function are negated because the weight in loss function should be positive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points. |
required |
random
|
Literal['pseudo', 'Halton', 'LHS']
|
Random method. Defaults to "pseudo". Options: - "pseudo": Pseudo random. - "Halton": Halton sequence. - "LHS": Latin Hypercube Sampling. |
'pseudo'
|
criteria
|
Optional[Callable[..., ndarray]]
|
Criteria function. Given coords from different dimension and return a boolean array with shape [n,]. Defaults to None. |
None
|
evenly
|
bool
|
Evenly sample points. Defaults to False. |
False
|
compute_sdf_derivatives
|
bool
|
Compute SDF derivatives. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
Dict[str, np.ndarray]: Random points in the geometry. The shape is [N, D]. their signed distance function. The shape is [N, 1]. their derivatives of SDF(optional). The shape is [N, D]. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> np.random.seed(42)
>>> interval = ppsci.geometry.Interval(0, 1)
>>> interval.sample_interior(2)
{'x': array([[0.37454012],
[0.9507143 ]], dtype=float32), 'sdf': array([[0.37454012],
[0.04928571]], dtype=float32)}
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> rectangle.sample_interior(2, "pseudo", None, False, True)
{'x': array([[0.7319939 ],
[0.15601864]], dtype=float32), 'y': array([[0.5986585 ],
[0.15599452]], dtype=float32), 'sdf': array([[0.2680061 ],
[0.15599453]], dtype=float32), 'sdf__x': array([[-1.0001659 ],
[ 0.25868416]], dtype=float32), 'sdf__y': array([[-0. ],
[ 0.74118376]], dtype=float32)}
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> cuboid.sample_interior(2, "pseudo", None, True, True)
{'x': array([[0.],
[0.]], dtype=float32), 'y': array([[0.],
[0.]], dtype=float32), 'z': array([[0.],
[1.]], dtype=float32), 'sdf': array([[0.],
[0.]], dtype=float32), 'sdf__x': array([[0.50008297],
[0.50008297]], dtype=float32), 'sdf__y': array([[0.50008297],
[0.50008297]], dtype=float32), 'sdf__z': array([[ 0.50008297],
[-0.49948692]], dtype=float32)}
Source code in ppsci/geometry/geometry.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 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 | |
sdf_derivatives(x, epsilon=0.0001)
¶
Compute derivatives of SDF function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Points for computing SDF derivatives using central difference. The shape is [N, D], D is the number of dimension of geometry. |
required |
epsilon
|
float
|
Derivative step. Defaults to 1e-4. |
0.0001
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Derivatives of corresponding SDF function. The shape is [N, D]. D is the number of dimension of geometry. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval = ppsci.geometry.Interval(0, 1)
>>> x = np.array([[0], [0.5], [1.5]])
>>> interval.sdf_derivatives(x)
array([[-1.],
[ 0.],
[ 1.]])
>>> rectangle = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> x = np.array([[0.0, 0.0], [0.5, 0.5], [1.5, 1.5]])
>>> rectangle.sdf_derivatives(x)
array([[-0.5 , -0.5 ],
[ 0. , 0. ],
[ 0.70710678, 0.70710678]])
>>> cuboid = ppsci.geometry.Cuboid((0, 0, 0), (1, 1, 1))
>>> x = np.array([[0, 0, 0], [0.5, 0.5, 0.5], [1, 1, 1]])
>>> cuboid.sdf_derivatives(x)
array([[-0.5, -0.5, -0.5],
[ 0. , 0. , 0. ],
[ 0.5, 0.5, 0.5]])
Source code in ppsci/geometry/geometry.py
uniform_boundary_points(n)
¶
Compute the equi-spaced points on the boundary(not implemented).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Random points on the boundary. The shape is [N, D]. |
Source code in ppsci/geometry/geometry.py
uniform_points(n, boundary=True)
¶
Compute the equi-spaced points in the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of points. |
required |
boundary
|
bool
|
Include boundary points. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Random points in the geometry. The shape is [N, D]. |
Source code in ppsci/geometry/geometry.py
union(other)
¶
CSG Union.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Geometry
|
The other geometry. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Geometry |
'Geometry'
|
The union of two geometries. |
Examples:
>>> import numpy as np
>>> import ppsci
>>> interval1 = ppsci.geometry.Interval(0, 1)
>>> interval2 = ppsci.geometry.Interval(0.5, 1.5)
>>> union = interval1.union(interval2)
>>> union.bbox
(array([[0.]]), array([[1.5]]))
>>> rectangle1 = ppsci.geometry.Rectangle((0, 0), (2, 3))
>>> rectangle2 = ppsci.geometry.Rectangle((0, 0), (3, 2))
>>> union = rectangle1.union(rectangle2)
>>> union.bbox
(array([0., 0.], dtype=float32), array([3., 3.], dtype=float32))
>>> cuboid1 = ppsci.geometry.Cuboid((0, 0, 0), (1, 2, 2))
>>> cuboid2 = ppsci.geometry.Cuboid((0, 0, 0), (2, 1, 1))
>>> union = cuboid1 | cuboid2
>>> union.bbox
(array([0., 0., 0.], dtype=float32), array([2., 2., 2.], dtype=float32))
Source code in ppsci/geometry/geometry.py
Cuboid
¶
Bases: Hypercube
Class for Cuboid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
Tuple[float, float, float]
|
Bottom left corner point [x0, y0, z0]. |
required |
xmax
|
Tuple[float, float, float]
|
Top right corner point [x1, y1, z1]. |
required |
Examples:
Source code in ppsci/geometry/geometry_3d.py
31 32 33 34 35 36 37 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 | |
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 3] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/geometry_3d.py
Disk
¶
Bases: Geometry
Class for disk geometry
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Tuple[float, float]
|
Center point of disk [x0, y0]. |
required |
radius
|
float
|
Radius of disk. |
required |
Examples:
Source code in ppsci/geometry/geometry_2d.py
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 2] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/geometry_2d.py
Hypercube
¶
Bases: Geometry
Multi-dimensional hyper cube.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
Tuple[float, ...]
|
Lower corner point. |
required |
xmax
|
Tuple[float, ...]
|
Upper corner point. |
required |
Examples:
Source code in ppsci/geometry/geometry_nd.py
33 34 35 36 37 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 | |
Hypersphere
¶
Bases: Geometry
Multi-dimensional hyper sphere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Tuple[float, ...]
|
Center point coordinate. |
required |
radius
|
Tuple[float, ...]
|
Radius along each dimension. |
required |
Examples:
Source code in ppsci/geometry/geometry_nd.py
Interval
¶
Bases: Geometry
Class for interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l
|
float
|
Left position of interval. |
required |
r
|
float
|
Right position of interval. |
required |
Examples:
Source code in ppsci/geometry/geometry_1d.py
sdf_func(points)
¶
Compute signed distance field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 1] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/geometry_1d.py
Mesh
¶
Bases: Geometry
Class for mesh geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Union[str, Mesh]
|
Mesh file path or mesh object, such as "/path/to/mesh.stl". |
required |
Examples:
Source code in ppsci/geometry/mesh.py
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 505 506 507 508 509 510 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | |
__str__()
¶
Return the name of class
Source code in ppsci/geometry/mesh.py
from_pymesh(mesh)
classmethod
¶
Instantiate Mesh object with given PyMesh object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
PyMesh object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Mesh |
'Mesh'
|
Instantiated ppsci.geometry.Mesh object. |
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1]))
>>> mesh = ppsci.geometry.Mesh.from_pymesh(box)
>>> print(mesh.vertices)
[[0. 0. 0.]
[1. 0. 0.]
[1. 1. 0.]
[0. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[1. 1. 1.]
[0. 1. 1.]]
Source code in ppsci/geometry/mesh.py
init_mesh()
¶
Initialize necessary variables for mesh
Source code in ppsci/geometry/mesh.py
sample_interior(n, random='pseudo', criteria=None, evenly=False, compute_sdf_derivatives=False)
¶
Sample random points in the geometry and return those meet criteria.
NOTE: sdf values returned by this function are negated because the weight in loss function should be positive.
Source code in ppsci/geometry/mesh.py
scale(scale, center=(0, 0, 0))
¶
Scale by given scale coefficient and center coordinate.
NOTE: This API generate a completely new Mesh object with scaled geometry, without modifying original Mesh object inplace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
Scale coefficient. |
required |
center
|
Tuple[float, float, float]
|
Center coordinate, [x, y, z]. Defaults to (0, 0, 0). |
(0, 0, 0)
|
Returns:
| Name | Type | Description |
|---|---|---|
Mesh |
'Mesh'
|
Scaled Mesh object. |
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1]))
>>> mesh = ppsci.geometry.Mesh(box)
>>> print(mesh.vertices)
[[0. 0. 0.]
[1. 0. 0.]
[1. 1. 0.]
[0. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[1. 1. 1.]
[0. 1. 1.]]
>>> mesh = mesh.scale(2, (0.25, 0.5, 0.75))
>>> print(mesh.vertices)
[[-0.25 -0.5 -0.75]
[ 1.75 -0.5 -0.75]
[ 1.75 1.5 -0.75]
[-0.25 1.5 -0.75]
[-0.25 -0.5 1.25]
[ 1.75 -0.5 1.25]
[ 1.75 1.5 1.25]
[-0.25 1.5 1.25]]
Source code in ppsci/geometry/mesh.py
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 3] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/mesh.py
translate(translation, relative=True)
¶
Translate by given offsets.
NOTE: This API generate a completely new Mesh object with translated geometry, without modifying original Mesh object inplace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translation
|
ndarray
|
Translation offsets, numpy array of shape (3,): [offset_x, offset_y, offset_z]. |
required |
relative
|
bool
|
Whether translate relatively. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Mesh |
'Mesh'
|
Translated Mesh object. |
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1]))
>>> mesh = ppsci.geometry.Mesh(box)
>>> print(mesh.vertices)
[[0. 0. 0.]
[1. 0. 0.]
[1. 1. 0.]
[0. 1. 0.]
[0. 0. 1.]
[1. 0. 1.]
[1. 1. 1.]
[0. 1. 1.]]
>>> print(mesh.translate((-0.5, 0, 0.5), False).vertices) # the center is moved to the translation vector.
[[-1. -0.5 0. ]
[ 0. -0.5 0. ]
[ 0. 0.5 0. ]
[-1. 0.5 0. ]
[-1. -0.5 1. ]
[ 0. -0.5 1. ]
[ 0. 0.5 1. ]
[-1. 0.5 1. ]]
>>> print(mesh.translate((-0.5, 0, 0.5), True).vertices) # the translation vector is directly added to the geometry coordinates
[[-0.5 0. 0.5]
[ 0.5 0. 0.5]
[ 0.5 1. 0.5]
[-0.5 1. 0.5]
[-0.5 0. 1.5]
[ 0.5 0. 1.5]
[ 0.5 1. 1.5]
[-0.5 1. 1.5]]
Source code in ppsci/geometry/mesh.py
PointCloud
¶
Bases: Geometry
Class for point cloud geometry, i.e. a set of points from given file or array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interior
|
Dict[str, ndarray]
|
Filepath or dict data, which store interior points of a point cloud, such as {"x": np.ndarray, "y": np.ndarray}. |
required |
coord_keys
|
Tuple[str, ...]
|
Tuple of coordinate keys, such as ("x", "y"). |
required |
boundary
|
Dict[str, ndarray]
|
Boundary points of a point cloud. Defaults to None. |
None
|
boundary_normal
|
Dict[str, ndarray]
|
Boundary normal points of a point cloud. Defaults to None. |
None
|
Examples:
>>> import ppsci
>>> import numpy as np
>>> interior_points = {"x": np.linspace(-1, 1, dtype="float32").reshape((-1, 1))}
>>> geom = ppsci.geometry.PointCloud(interior_points, ("x",))
Source code in ppsci/geometry/pointcloud.py
27 28 29 30 31 32 33 34 35 36 37 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 | |
__str__()
¶
Return the name of class.
Source code in ppsci/geometry/pointcloud.py
random_boundary_points(n, random='pseudo')
¶
Randomly sample points on the boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of sample points. |
required |
random
|
str
|
Random method. Defaults to "pseudo". |
'pseudo'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Randomly sampled points on the boundary.The shape of the returned array is (n, ndim). |
Examples:
>>> import ppsci
>>> import numpy as np
>>> np.random.seed(0)
>>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> boundary_points = {"x": np.array([0.0, 2.0], dtype="float32").reshape((-1, 1))}
>>> geom = ppsci.geometry.PointCloud(interior_points, ("x",), boundary_points)
>>> print(geom.random_boundary_points(1))
[[2.]]
Source code in ppsci/geometry/pointcloud.py
random_points(n, random='pseudo')
¶
Randomly sample points in the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of sample points. |
required |
random
|
str
|
Random method. Defaults to "pseudo". |
'pseudo'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Randomly sampled points in the geometry.The shape of the returned array is (n, ndim). |
Examples:
>>> import ppsci
>>> import numpy as np
>>> np.random.seed(0)
>>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> geom = ppsci.geometry.PointCloud(interior_points, ("x",))
>>> print(geom.random_points(2))
[[1.]
[0.]]
Source code in ppsci/geometry/pointcloud.py
scale(scale)
¶
Scale the geometry by the given factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
ndarray
|
Scale factor.The shape of scale must be the same as the shape of the interior points. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PointCloud |
'PointCloud'
|
Scaled point cloud. |
Examples:
>>> import ppsci
>>> import numpy as np
>>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> geom = ppsci.geometry.PointCloud(interior_points, ("x",))
>>> scale = np.array([2.0])
>>> print(geom.scale(scale).interior)
[[0.]
[1.]
[2.]
[3.]
[4.]]
>>> interior_points_2d = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1)),
... "y": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> geom_2d = ppsci.geometry.PointCloud(interior_points_2d, ("x", "y"))
>>> scale_2d = np.array([2.0, 0.5])
>>> print(geom_2d.scale(scale_2d).interior)
[[0. 0. ]
[1. 0.25]
[2. 0.5 ]
[3. 0.75]
[4. 1. ]]
Source code in ppsci/geometry/pointcloud.py
translate(translation)
¶
Translate the geometry by the given offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translation
|
ndarray
|
Translation offset.The shape of translation must be the same as the shape of the interior points. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PointCloud |
'PointCloud'
|
Translated point cloud. |
Examples:
>>> import ppsci
>>> import numpy as np
>>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> geom = ppsci.geometry.PointCloud(interior_points, ("x",))
>>> translation = np.array([1.0])
>>> print(geom.translate(translation).interior)
[[1. ]
[1.5]
[2. ]
[2.5]
[3. ]]
>>> interior_points_2d = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1)),
... "y": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> geom_2d = ppsci.geometry.PointCloud(interior_points_2d, ("x", "y"))
>>> translation_2d = np.array([1.0, 3.0])
>>> print(geom_2d.translate(translation_2d).interior)
[[1. 3. ]
[1.5 3.5]
[2. 4. ]
[2.5 4.5]
[3. 5. ]]
Source code in ppsci/geometry/pointcloud.py
uniform_boundary_points(n)
¶
uniform_points(n, boundary=True)
¶
Compute the equi-spaced points in the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of sample points. |
required |
boundary
|
bool
|
Whether to include boundary points. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Equi-spaced points in the geometry.The shape of the returned array is (n, ndim). |
Examples:
>>> import ppsci
>>> import numpy as np
>>> interior_points = {"x": np.linspace(0, 2, 5, dtype="float32").reshape((-1, 1))}
>>> geom = ppsci.geometry.PointCloud(interior_points, ("x",))
>>> print(geom.uniform_points(2))
[[0. ]
[0.5]]
Source code in ppsci/geometry/pointcloud.py
Polygon
¶
Bases: Geometry
Class for simple polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
Tuple[Tuple[float, float], ...]
|
The order of vertices can be in a clockwise or counter-clockwise direction. The vertices will be re-ordered in counterclockwise (right hand rule). |
required |
Examples:
Source code in ppsci/geometry/geometry_2d.py
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 505 506 507 508 509 510 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 2] |
required |
Returns: np.ndarray: SDF values of input points without squared, the shape is [N, 1].
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/geometry_2d.py
Rectangle
¶
Bases: Hypercube
Class for rectangle geometry
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
Tuple[float, float]
|
Bottom left corner point, [x0, y0]. |
required |
xmax
|
Tuple[float, float]
|
Top right corner point, [x1, y1]. |
required |
Examples:
Source code in ppsci/geometry/geometry_2d.py
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 | |
is_valid(vertices)
staticmethod
¶
Check if the geometry is a Rectangle.
Source code in ppsci/geometry/geometry_2d.py
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape of the array is [N, 2]. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/geometry_2d.py
SDFMesh
¶
Bases: Geometry
Class for SDF geometry, a kind of implicit surface mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vectors
|
ndarray
|
Vectors of triangles of mesh with shape [M, 3, 3]. |
required |
normals
|
ndarray
|
Unit normals of each triangle face with shape [M, 3]. |
required |
sdf_func
|
Callable[[ndarray, bool], ndarray]
|
Signed distance function of the triangle mesh. |
required |
Examples:
Source code in ppsci/geometry/mesh.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | |
__str__()
¶
Return the name of class
from_stl(mesh_file)
classmethod
¶
Instantiate SDFMesh from given mesh file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh_file
|
str
|
Path to triangle mesh file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SDFMesh |
'SDFMesh'
|
Instantiated ppsci.geometry.SDFMesh object. |
Examples:
>>> import ppsci
>>> import pymesh
>>> import numpy as np
>>> box = pymesh.generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1]))
>>> pymesh.save_mesh("box.stl", box)
>>> mesh = ppsci.geometry.SDFMesh.from_stl("box.stl")
>>> print(sdfmesh.vectors.shape)
(12, 3, 3)
Source code in ppsci/geometry/mesh.py
sample_interior(n, random='pseudo', criteria=None, evenly=False, compute_sdf_derivatives=False)
¶
Sample random points in the geometry and return those meet criteria.
NOTE: sdf values returned by this function are negated because the weight in loss function should be positive.
Source code in ppsci/geometry/mesh.py
scale(scale)
¶
Scale by given scale coefficient and center coordinate.
NOTE: This API generate a completely new Mesh object with scaled geometry, without modifying original Mesh object inplace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
Scale coefficient. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Mesh |
'SDFMesh'
|
Scaled Mesh object. |
Examples:
>>> import ppsci
>>> import pymesh
>>> mesh = ppsci.geometry.SDFMesh.from_stl('/path/to/mesh.stl')
>>> mesh = mesh.scale(np.array([1.3, 1.5, 2.0]))
Source code in ppsci/geometry/mesh.py
sdf_func(points, compute_sdf_derivatives=False)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 3] |
required |
compute_sdf_derivatives
|
bool
|
Whether to compute SDF derivatives. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, Tuple[ndarray, ndarray]]
|
Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]: |
Union[ndarray, Tuple[ndarray, ndarray]]
|
If compute_sdf_derivatives is True, then return both SDF values([N, 1]) and their derivatives([N, 3]); otherwise only return SDF values([N, 1]). |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/mesh.py
translate(translation)
¶
Translate by given offsets.
NOTE: This API generate a completely new Mesh object with translated geometry, without modifying original Mesh object inplace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translation
|
ndarray
|
Translation offsets, numpy array of shape (3,): [offset_x, offset_y, offset_z]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Mesh |
'SDFMesh'
|
Translated Mesh object. |
Examples:
>>> import ppsci
>>> import pymesh
>>> mesh = ppsci.geometry.SDFMesh.from_stl('/path/to/mesh.stl')
>>> mesh = mesh.translate(np.array([1, -1, 2]))
Source code in ppsci/geometry/mesh.py
uniform_boundary_points(n)
¶
Sphere
¶
Bases: Hypersphere
Class for Sphere
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Tuple[float, float, float]
|
Center of the sphere [x0, y0, z0]. |
required |
radius
|
float
|
Radius of the sphere. |
required |
Source code in ppsci/geometry/geometry_3d.py
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape is [N, 3] |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.
Source code in ppsci/geometry/geometry_3d.py
TimeDomain
¶
Bases: Interval
Class for timedomain, an special interval geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t0
|
float
|
Start of time. |
required |
t1
|
float
|
End of time. |
required |
time_step
|
Optional[float]
|
Step interval of time. Defaults to None. |
None
|
timestamps
|
Optional[Tuple[float, ...]]
|
List of timestamps. Defaults to None. |
None
|
Examples:
Source code in ppsci/geometry/timedomain.py
on_initial(t)
¶
Check if a specific time is on the initial time point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
ndarray
|
The time to be checked. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Bool numpy array of whether the specific time is on the initial time point. |
Examples:
>>> import paddle
>>> import ppsci
>>> geom = ppsci.geometry.TimeDomain(0, 1)
>>> T = [0, 0.01, 0.126, 0.2, 0.3]
>>> check = geom.on_initial(T)
>>> print(check)
[ True False False False False]
Source code in ppsci/geometry/timedomain.py
TimeXGeometry
¶
Bases: Geometry
Class for combination of time and geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timedomain
|
TimeDomain
|
TimeDomain object. |
required |
geometry
|
Geometry
|
Geometry object. |
required |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
Source code in ppsci/geometry/timedomain.py
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 505 506 507 508 509 510 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
__init__(timedomain, geometry)
¶
Source code in ppsci/geometry/timedomain.py
__str__()
¶
Return the name of class
Source code in ppsci/geometry/timedomain.py
periodic_point(x, component)
¶
Process given point coordinates to satisfy the periodic boundary conditions of the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Dict[str, ndarray]
|
Contains the coordinates and timestamps of the points. It represents the coordinates of the point to be processed. |
required |
component
|
int
|
Specifies the components or dimensions of specific spatial coordinates that are periodically processed. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
Dict[str, np.ndarray] : contains the original timestamps and the coordinates of the spatial point after periodic processing. |
Examples:
import ppsci timedomain = ppsci.geometry.TimeDomain(0, 1, 0.1) geom = ppsci.geometry.Rectangle((0, 0), (1, 1)) time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom) ts = time_geom.sample_boundary(1000) result = time_geom.periodic_point(ts, 0) for k,v in result.items(): ... print(k, v.shape) t (1000, 1) x (1000, 1) y (1000, 1) normal_x (1000, 1) normal_y (1000, 1)
Source code in ppsci/geometry/timedomain.py
random_boundary_points(n, random='pseudo', criteria=None)
¶
Random boundary points on the spatial-temporal domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of spatial-temporal points generated on a given geometry boundary. |
required |
random
|
str
|
Controls the way to generate random points. Default is "pseudo". |
'pseudo'
|
criteria
|
Optional[Callable]
|
Used to filter the generated boundary points, only points that meet certain conditions are retained. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A set of point coordinates randomly distributed across geometry boundaries on the spatial-temporal domain. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1, 0.001)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.random_boundary_points(1000)
>>> print(ts.shape)
(1000, 3)
Source code in ppsci/geometry/timedomain.py
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 505 506 507 508 509 510 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
random_initial_points(n, random='pseudo')
¶
Generate randomly distributed point coordinates on the spatial-temporal domain at the initial moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of generated points. |
required |
random
|
str
|
Controls the way to generate random points. Default is "pseudo". |
'pseudo'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A set of point coordinates randomly distributed on the spatial-temporal domain at the initial moment. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.random_initial_points(1000)
>>> print(ts.shape)
(1000, 3)
Source code in ppsci/geometry/timedomain.py
random_points(n, random='pseudo', criteria=None)
¶
Generate random points on the spatial-temporal domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of random points to generate. |
required |
random
|
str
|
Specifies the way to generate random points, default is "pseudo" , which means that a pseudo-random number generator is used. |
'pseudo'
|
criteria
|
Optional[Callable]
|
A method that filters on the generated random points. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A array of random spatial-temporal points with shape [N, 1+D], where 1 represents the |
ndarray
|
temporal dimension and D represents the spatial dimensions. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1, 0.001)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.random_points(1000)
>>> print(ts.shape)
(1000, 3)
Source code in ppsci/geometry/timedomain.py
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 | |
sample_initial_interior(n, random='pseudo', criteria=None, evenly=False, compute_sdf_derivatives=False)
¶
Sample random points in the time-geometry and return those meet criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of interior points generated. |
required |
random
|
str
|
The method used to specify the initial point of generation. Default is "pseudo". |
'pseudo'
|
criteria
|
Optional[Callable]
|
Used to filter the generated interior points, only points that meet certain conditions are retained. Default is None. |
None
|
evenly
|
bool
|
Indicates whether the initial points are generated evenly. Default is False. |
False
|
compute_sdf_derivatives
|
bool
|
Indicates whether to calculate the derivative of signed distance function or not. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
np.ndarray: Contains the coordinates of the initial internal point generated, as well as the potentially computed signed distance function and its derivative. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.sample_initial_interior(1000)
>>> for k,v in ts.items():
... print(k, v.shape)
t (1000, 1)
x (1000, 1)
y (1000, 1)
sdf (1000, 1)
Source code in ppsci/geometry/timedomain.py
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | |
uniform_boundary_points(n, criteria=None)
¶
Uniform boundary points on the spatial-temporal domain. Geometry surface area ~ bbox. Time surface area ~ diam.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of boundary points on the spatial-temporal domain to be generated that are evenly distributed across geometry boundaries. |
required |
criteria
|
Optional[Callable]
|
Used to filter the generated boundary points, only points that meet certain conditions are retained. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A set of point coordinates evenly distributed across geometry boundaries on the spatial-temporal domain. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.uniform_boundary_points(1000)
>>> print(ts.shape)
(1000, 3)
Source code in ppsci/geometry/timedomain.py
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 | |
uniform_initial_points(n)
¶
Generate evenly distributed point coordinates on the spatial-temporal domain at the initial moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of generated points. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: A set of point coordinates evenly distributed on the spatial-temporal domain at the initial moment. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.uniform_initial_points(1000)
>>> print(ts.shape)
(1000, 3)
Source code in ppsci/geometry/timedomain.py
uniform_points(n, boundary=True)
¶
Uniform points on the spatial-temporal domain. Geometry volume ~ bbox. Time volume ~ diam.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of sample points to be generated. |
required |
boundary
|
bool
|
Indicates whether boundary points are included, default is True. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: a set of spatial-temporal coordinate points 'tx' that represent sample points evenly distributed within the spatial-temporal domain. |
Examples:
>>> import ppsci
>>> timedomain = ppsci.geometry.TimeDomain(0, 1, 0.001)
>>> geom = ppsci.geometry.Rectangle((0, 0), (1, 1))
>>> time_geom = ppsci.geometry.TimeXGeometry(timedomain, geom)
>>> ts = time_geom.uniform_points(1000)
>>> print(ts.shape)
(1000, 3)
Source code in ppsci/geometry/timedomain.py
Triangle
¶
Bases: Geometry
Class for Triangle
The order of vertices can be in a clockwise or counterclockwise direction. The vertices will be re-ordered in counterclockwise (right hand rule).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
Tuple[float, float]
|
First point of Triangle [x0, y0]. |
required |
x2
|
Tuple[float, float]
|
Second point of Triangle [x1, y1]. |
required |
x3
|
Tuple[float, float]
|
Third point of Triangle [x2, y2]. |
required |
Examples:
Source code in ppsci/geometry/geometry_2d.py
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 | |
sdf_func(points)
¶
Compute signed distance field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
The coordinate points used to calculate the SDF value, the shape of the array is [N, 2]. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: SDF values of input points without squared, the shape is [N, 1]. |
NOTE: This function usually returns ndarray with negative values, because according to the definition of SDF, the SDF value of the coordinate point inside the object(interior points) is negative, the outside is positive, and the edge is 0. Therefore, when used for weighting, a negative sign is often added before the result of this function.