File: ReadArray.py

package info (click to toggle)
xdmf 3.0%2Bgit20190531-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,796 kB
  • sloc: cpp: 67,089; ansic: 5,172; python: 4,566; f90: 1,247; java: 187; fortran: 173; makefile: 92; sh: 28
file content (76 lines) | stat: -rw-r--r-- 2,982 bytes parent folder | download | duplicates (6)
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
from Xdmf import *


def maximum(values):
	values = ArrayVector(values)#need to cast to the right data type
        if values[0].getArrayType() == XdmfArrayType.String():
                returnArray = XdmfArray.New()
                returnArray.pushBackAsString(values[0].getValueAsString(0))
                return returnArray;
        else:
                maxVal = values[0].getValueAsFloat64(0)
                for i in range (0, values.size()):
                        for j in range (0, values[i].getSize()):
                                if maxVal < values[i].getValueAsFloat64(j):
                                        maxVal = values[i].getValueAsFloat64(j)
                returnArray = XdmfArray.New()
                returnArray.pushBackAsFloat64(maxVal)
                return returnArray

def prepend(val1, val2):
	val1 = XdmfArray.XdmfArrayPtr(val1)#need to cast to the right data type
	val2 = XdmfArray.XdmfArrayPtr(val2)#had to write a custom casting method to integrate it properly
	returnArray = XdmfArray.New()
	returnArray.insert(0, val2, 0, val2.getSize())
	returnArray.insert(val2.getSize(), val1, 0, val1.getSize())
	return returnArray

if __name__ == "__main__":
	#functions are passed as callable pyobjects
	XdmfFunction.addFunction("MAX", maximum)
	functionVector = XdmfFunction.getSupportedFunctions()
	for i in range (0, functionVector.size()):
		print functionVector[i]
	XdmfFunction.addOperation("@", prepend, 2)
	print XdmfFunction.getSupportedOperations()
        testVector = ArrayVector()
	testArray = XdmfArray.New()
	testArray.pushBackAsInt32(10)
	testArray.pushBackAsInt32(9)
	testVector.push_back(testArray)
	print "before evaluating function"
	resultArray = XdmfFunction.evaluateFunction(testVector, "MAX")
	print type(resultArray)
	print "after function is evaulated"
	print resultArray.getValuesString()
	print "before evaluating function"
	resultArray = XdmfFunction.evaluateFunction(testVector, "AVE")
	print type(resultArray)
	print "after function is evaulated"
	print resultArray.getValuesString()
	testArray2 = XdmfArray.New()
	testArray2.pushBackAsInt32(1)
	testArray2.pushBackAsInt32(2)
	print "before evaluating Operation"
	resultArray = XdmfFunction.evaluateOperation(testArray, testArray2, "|")
	print type(resultArray)
	print "after evaluationg Operation"
	print resultArray.getValuesString()
	resultArray = XdmfFunction.evaluateOperation(testArray, testArray2, "@")
	print type(resultArray)
	print "after evaluationg Operation"
	print resultArray.getValuesString()
	print "before evaluating expression"
	testMap = ArrayMap()
	testMap["A"] = testArray
	testMap["B"] = testArray2
	testArray3 = XdmfArray.New()
	testArray3.pushBackAsInt32(5)
	testArray3.pushBackAsInt32(5)
	testArray3.pushBackAsInt32(5)
	testArray3.pushBackAsInt32(5)
	testMap["C"] = testArray3
	resultArray = XdmfFunction.evaluateExpression("A|B#C", testMap)
	print type(resultArray)
	print resultArray.getValuesString()
	print "after evaluating expression"