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 701 702 703 704 705 706 |
|
__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)
¶
Compute the periodic image of x(not implemented).
Warings
This function is not implemented.
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". 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". 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". pseudo: Pseudo random. Halton: Halton sequence. LHS: Latin Hypercube Sampling. |
'pseudo'
|
criteria |
Optional[Callable[..., ndarray]]
|
Criteria function. Given coords from differnet 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
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 |
|
sample_interior(n, random='pseudo', criteria=None, evenly=False, compute_sdf_derivatives=False)
¶
Sample 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". pseudo: Pseudo random. Halton: Halton sequence. LHS: Latin Hypercube Sampling. |
'pseudo'
|
criteria |
Optional[Callable[..., ndarray]]
|
Criteria function. Given coords from differnet 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
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 |
|
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).
Warings
This function is not implemented, please use random_boundary_points instead.
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.
Warings
This function is not implemented, please use random_points instead.
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
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
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
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
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.
Source code in ppsci/geometry/geometry_2d.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
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
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
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
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 |
|
__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.
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
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
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 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 |
|
__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
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 |
|
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 set of random spatial-temporal points. |
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
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 |
|
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
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 |
|
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
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 |
|
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)