File: t_Field_std.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (46 lines) | stat: -rwxr-xr-x 1,242 bytes parent folder | download
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
#! /usr/bin/env python

from __future__ import print_function
import os
import openturns as ot

ot.PlatformInfo.SetNumericalPrecision(6)

vertices = []
vertices.append([0.0, 0.0, 0.0])
vertices.append([0.0, 0.0, 1.0])
vertices.append([0.0, 1.0, 0.0])
vertices.append([0.0, 1.0, 1.0])
vertices.append([1.0, 0.0, 0.0])
vertices.append([1.0, 0.0, 1.0])
vertices.append([1.0, 1.0, 0.0])
vertices.append([1.0, 1.0, 1.0])

simplicies = []
simplicies.append([0, 1, 2, 4])
simplicies.append([3, 5, 6, 7])
simplicies.append([1, 2, 3, 6])
simplicies.append([1, 2, 4, 6])
simplicies.append([1, 3, 5, 6])
simplicies.append([1, 4, 5, 6])

mesh3D = ot.Mesh(vertices, simplicies)

s = 3
values = ot.Normal(s).getSample(mesh3D.getVerticesNumber())
field = ot.Field(mesh3D, values)
print('field=', field)
print('spatial dim=', field.getSpatialDimension())
print('value[4]=', field.getValueAtIndex(4))
print('nearest[2]=', field.getValueAtNearestPosition(field[2]))
print('mesh=', field.getMesh())
print('spatial mean=', field.getSpatialMean())
print('deformed=', field.asDeformedMesh())
print('description=', field.getDescription())

fname = 'field.vtk'
field.exportToVTKFile(fname)
with open(fname) as f:
    data = f.read()
    print(data)
os.remove(fname)