File: t_PointToFieldFunction_python.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 (61 lines) | stat: -rwxr-xr-x 1,387 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()

mesh = ot.RegularGrid(0.0, 0.1, 11)


class FUNC(ot.OpenTURNSPythonPointToFieldFunction):
    def __init__(self):
        super(FUNC, self).__init__(2, mesh, 2)
        self.setInputDescription(["R", "S"])
        self.setOutputDescription(["T", "U"])
        self.mesh_ = ot.RegularGrid(0.0, 0.1, 11)

    def _exec(self, X):
        size = self.mesh_.getVerticesNumber()
        values = [ot.Point(X) * i for i in range(size)]
        Y = ot.Field(self.mesh_, values)
        return Y


F = FUNC()
print(
    "in_dim=" + str(F.getInputDimension()) + " out_dim=" + str(F.getOutputDimension())
)

print((F((10.0, 5.0))))

print((F(((10.0, 5.0), (6.0, 7.0)))))


# Instance creation
myFunc = ot.PointToFieldFunction(F)

# Copy constructor
newFunc = ot.PointToFieldFunction(myFunc)

print(("myFunc input dimension= " + str(myFunc.getInputDimension())))
print(("myFunc output dimension= " + str(myFunc.getOutputDimension())))

inPt = ot.Point(2, 2.0)
print((repr(inPt)))

outPt = myFunc(inPt)
print((repr(outPt)))

outPt = myFunc((10.0, 11.0))
print((repr(outPt)))

inSample = ot.Sample(10, 2)
for i in range(10):
    inSample[i] = ot.Point((i, i))
print((repr(inSample)))

outSample = myFunc(inSample)
print((repr(outSample)))

outSample = myFunc(((100.0, 100.0), (101.0, 101.0), (102.0, 102.0)))
print((repr(outSample)))