1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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
|
#! /usr/bin/env python
import openturns as ot
import os
ot.TESTPREAMBLE()
nrVertices = 100
vertices = ot.Normal().getSample(nrVertices).sort()
simplices = [[i, i + 1] for i in range(nrVertices - 1)]
mesh1 = ot.Mesh(vertices, simplices)
vertices *= -1.0
mesh2 = ot.Mesh(vertices, simplices)
for mesh in [mesh1, mesh2]:
lowerBound = mesh.getLowerBound()[0]
upperBound = mesh.getUpperBound()[0]
n = mesh.getSimplicesNumber()
print(
"mesh=",
mesh,
"lowerBound=",
lowerBound,
"upperBound=",
upperBound,
n,
"simplices",
)
algo = ot.EnclosingSimplexMonotonic1D(mesh.getVertices())
ot.RandomGenerator.SetSeed(0)
test = ot.Sample(ot.Uniform(-3.0, 3.0).getSample(1000))
vertices = mesh.getVertices()
for vertex in test:
index = algo.query(vertex)
x = vertex[0]
if x < lowerBound or x > upperBound:
if index < n:
print("Point", x, "should be outside but query returned index", index)
os.exit(1)
else:
if index >= n:
print("Point", x, "should be inside but query returned index", index)
os.exit(1)
found, coordinates = mesh.checkPointInSimplexWithCoordinates(vertex, index)
if not found:
print(
"Wrong simplex found for",
x,
"(index=",
index,
") barycentric coordinates=",
coordinates,
)
os.exit(1)
if (
coordinates[0] < 0.0
or coordinates[0] > 1.0
or coordinates[1] < 0.0
or coordinates[1] > 1.0
):
print(
"Wrong barycentric coordinates found found for",
x,
"(index=",
index,
") barycentric coordinates=",
coordinates,
)
os.exit(1)
if (
abs(
x
- coordinates[0] * vertices[index, 0]
- coordinates[1] * vertices[index + 1, 0]
)
> 1.0e-10
):
print(
"Wrong barycentric coordinates found found for",
x,
"(index=",
index,
") barycentric coordinates=",
coordinates,
)
os.exit(1)
|