File: t_P1LagrangeEvaluation_std.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (41 lines) | stat: -rwxr-xr-x 1,016 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott


mesh = ot.RegularGrid(0.0, 1.0, 4)
values = ot.Sample([[0.5], [1.5], [1.0], [-0.5]])
field = ot.Field(mesh, values)
evaluation = ot.P1LagrangeEvaluation(field)
x = [2.3]
y = evaluation(x)
print(y)
ott.assert_almost_equal(y, [0.55])


# Learning sample on meshD
mesher = ot.IntervalMesher([7, 7])
lowerbound = [-1.0, -1.0]
upperBound = [1, 1]
interval = ot.Interval(lowerbound, upperBound)
meshD = mesher.build(interval)
sample = ot.ProcessSample(meshD, 10, 1)
field = ot.Field(meshD, 1)
for k in range(sample.getSize()):
    field.setValues(ot.Normal().getSample(64))
    sample[k] = field
lagrange = ot.P1LagrangeEvaluation(sample)
# New mesh
mesh = ot.Mesh(
    ot.MonteCarloExperiment(
        ot.JointDistribution([ot.Uniform(-1, 1)] * 2), 200
    ).generate()
)

point = mesh.getVertices()[0]
y = lagrange(point)
print(y)
index = lagrange.getEnclosingSimplexAlgorithm().query(point)
print(index)
assert index == 12, "wrong index"