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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
from Xdmf import *
from numpy import *
#//definefunction begin
def maximum(values):
# Need to cast to the right data type
values = ArrayVector(values)
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
#//definefunction end
#//defineoperation begin
def prepend(val1, val2):
# Need to cast to the right data type
# Had to write a custom casting method to integrate it properly
val1 = XdmfArray.XdmfArrayPtr(val1)
val2 = XdmfArray.XdmfArrayPtr(val2)
returnArray = XdmfArray.New()
returnArray.insert(0, val2, 0, val2.getSize())
returnArray.insert(val2.getSize(), val1, 0, val1.getSize())
return returnArray
#//defineoperation end
#//programstart begin
if __name__ == "__main__":
#//programstart end
#//getSupportedOperations begin
exampleOperations = XdmfFunction.getSupportedOperations()
#//getSupportedOperations end
#//getSupportedFunctions begin
exampleFunctions = XdmfFunction.getSupportedFunctions()
#//getSupportedFunctions end
#//getValidVariableChars begin
exampleVariableChars = XdmfFunction.getValidVariableChars()
#//getValidVariableChars end
#//getValidDigitChars begin
exampleDigitChars = XdmfFunction.getValidDigitChars()
#//getValidDigitChars end
#//getOperationPriority begin
examplePriority = XdmfFunction.getOperationPriority('|')
#//getOperationPriority end
#//valueinit begin
valueArray1 = XdmfArray.New()
valueArray1.pushBackAsInt32(1)
valueArray1.pushBackAsInt32(2)
valueArray1.pushBackAsInt32(3)
valueArray1.pushBackAsInt32(4)
valueArray2 = XdmfArray.New()
valueArray2.pushBackAsInt32(9)
valueArray2.pushBackAsInt32(8)
valueArray2.pushBackAsInt32(7)
valueArray2.pushBackAsInt32(6)
valueVector = ArrayVector()
valueVector.push_back(valueArray1)
valueVector.push_back(valueArray2)
#//valueinit end
#//sum begin
answerArray = XdmfFunction.sum(valueVector)
#//sum end
#//average begin
answerArray = XdmfFunction.average(valueVector)
#//average end
#//chunk begin
answerArray = XdmfFunction.chunk(valueArray1, valueArray2)
#//chunk end
#//interlace begin
answerArray = XdmfFunction.interlace(valueArray1, valueArray2)
#//interlace end
#//addOperation begin
exampleNumOperations = XdmfFunction.addOperation('@', prepend, 2)
#//addOperation end
#//evaluateOperation begin
answerArray = XdmfFunction.evaluateOperation(valueArray1, valueArray2, '@')
#//evaluateOperation end
#//addFunction begin
exampleNumFunctions = XdmfFunction.addFunction("MAX", maximum)
#//addFunction end
#//evaluateFunction begin
answerArray = XdmfFunction.evaluateFunction(valueVector, "MAX")
#//evaluateFunction end
#//evaluateExpression begin
valueMap = ArrayMap()
valueMap["A"] = valueArray1
valueMap["B"] = valueArray2
parsedExpression = "MAX(A,B)@(A#B)"
answerArray = XdmfFunction.evaluateExpression(parsedExpression, valueMap)
#//evaluateExpression end
#//initialization begin
testFunction = XdmfFunction.New()
#//initalization end
#//initexpression begin
functionExpression = "AVE(A)"
variableArray = XdmfArray.New()
for i in range(0, 10):
variableArray.pushBackAsInt32(i)
variableMap = ArrayMap()
variableMap["A"] = variableArray;
exampleFunction = XdmfFunction.New(functionExpression, variableMap)
#//initexpression end
#//setExpression begin
newExpression = "SUM(A)"
exampleFunction.setExpression(newExpression)
#//setExpression end
#//getExpression begin
exampleExpression = exampleFunction.getExpression()
#//getExpression end
#//insertVariable begin
secondVariableArray = XdmfArray.New()
for i in range(0, 10):
secondVariableArray.pushBack(i)
exampleFunction.insertVariable("B", secondVariableArray)
#//insertVariable end
#//getVariable begin
variableValue = exampleFunction->getVariable("B")
#//getVariable end
#//getVariableList begin
exampleVarList = exampleFunction.getVariableList()
#//getVariableList end
#//removeVariable begin
exampleFunction.removeVariable("B")
#//removeVariable end
#//setConstructedType begin
typeAttribute = XdmfAttribute.New()
exampleFunction.setConstructedType(typeAttribute.getItemTag())
#//setConstructedType end
#//getConstructedType begin
std::string exampleType = exampleFunction->getConstructedType();
#//getConstructedType end
#//setConstructedProperties begin
propertyAttribute = XdmfAttributeNew()
exampleFunction.setConstructedProperties(propertyAttribute.getItemProperties())
#//setConstructedProperties end
#//getConstructedProperties begin
exampleProperties = exampleFunction.getConstructedProperties()
#//getConstructedProperties end
#//read begin
functionResult = exampleFunction.read()
#//read end
#//abs begin
toBeAbs = XdmfArray.New()
toBeAbs.pushBackAsFloat64(-5.5)
absVector = ArrayVector()
absVector.push_back(toBeAbs)
absResult = XdmfFunction.abs(absVector)
assert absResult.getValuesString() == "5.5"
#//abs end
#//arcsin begin
toBeArcsin = XdmfArray.New()
toBeArcsin.pushBackAsFloat64(-0.5)
arcsinVector = ArrayVector()
arcsinVector.push_back(toBeArcsin)
arcsinResult = XdmfFunction.arcsin(arcsinVector)
assert arcsinResult.getValuesString() == "-0.52359877559829893"
#//arcsin end
#//arccos begin
toBeArccos = XdmfArray.New()
toBeArccos.pushBackAsFloat64(-0.5)
arccosVector = ArrayVector()
arccosVector.push_back(toBeArccos)
arccosResult = XdmfFunction.arccos(arccosVector)
assert arccosResult.getValuesString() == "2.0943951023931957"
#//arccos end
#//cos begin
toBeCos = XdmfArray.New()
toBeCos.pushBackAsFloat64(-0.5)
cosVector = ArrayVector()
cosVector.push_back(toBeCos)
cosResult = XdmfFunction.cos(cosVector)
assert cosResult.getValuesString() == "0.87758256189037276"
#//cos end
#//sin begin
toBeSin = XdmfArray.New()
toBeSin.pushBackAsFloat64(-0.5)
sinVector = ArrayVector()
sinVector.push_back(toBeSin)
sinResult = XdmfFunction.sin(sinVector)
assert sinResult.getValuesString() == "-0.47942553860420301"
#//sin end
#//tan begin
toBeTan = XdmfArray.New()
toBeTan.pushBackAsFloat64(-0.5)
tanVector = ArrayVector()
tanVector.push_back(toBeTan)
tanResult = XdmfFunction.tan(tanVector)
assert tanResult.getValuesString() == "-0.54630248984379048"
#//tan end
#//sqrt begin
toBeSqrt = XdmfArray.New()
toBeSqrt.pushBackAsFloat64(2)
sqrtVector = ArrayVector()
sqrtVector.push_back(toBeSqrt)
sqrtResult = XdmfFunction.sqrt(sqrtVector)
assert sqrtResult.getValuesString() == "1.4142135623730951"
#//sqrt end
#//log begin
toBeLog = XdmfArray.New()
toBeLog.pushBackAsFloat64(2)
logBase = XdmfArray.New()
logBase.pushBackAsFloat64(4)
logVector = ArrayVector()
logVector.push_back(toBeLog)
logVector.push_back(logBase)
logResult = XdmfFunction.log(logVector)
assert logResult.getValuesString() == "0.5"
#//log end
#//exp begin
powerBase = XdmfArray.New()
powerBase.pushBackAsFloat64(-0.5)
powerFactor = XdmfArray.New()
powerFactor.pushBackAsFloat64(2)
expVector = ArrayVector()
expVector.push_back(powerBase)
expVector.push_back(powerFactor)
expResult = XdmfFunction.exponent(expVector)
assert expResult.getValuesString() == "0.25"
#//exp end
#//join begin
array1 = XdmfArray.New()
array1.pushBackAsFloat64(-0.5)
array2 = XdmfArray.New()
array2.pushBackAsFloat64(2)
joinVector = ArrayVector()
joinVector.push_back(array1)
joinVector.push_back(array2)
joinResult = XdmfFunction.join(joinVector)
assert joinResult.getValuesString() == "-0.5 2"
#//join end
#//addition begin
addArray1 = XdmfArray.New()
addArray1.pushBackAsFloat64(-0.5)
addArray2 = XdmfArray.New()
addArray2.pushBackAsFloat64(2)
addResult = XdmfFunction.addition(addArray1, addArray2)
assert addResult.getValuesString() == "1.5"
#//addition end
#//division begin
divArray1 = XdmfArray.New()
divArray1.pushBackAsFloat64(-0.5)
divArray2 = XdmfArray.New()
divArray2.pushBackAsFloat64(2)
divResult = XdmfFunction.division(divArray1, divArray2)
assert divResult.getValuesString() == "-0.25"
#//division end
#//multiplication begin
mulArray1 = XdmfArray.New()
mulArray1.pushBackAsFloat64(-0.5)
mulArray2 = XdmfArray.New()
mulArray2.pushBackAsFloat64(2)
mulResult = XdmfFunction.multiplication(mulArray1, mulArray2)
assert mulResult.getValuesString() == "-1"
#//multiplication end
#//subtraction begin
subArray1 = XdmfArray.New()
subArray1.pushBackAsFloat64(-0.5)
subArray2 = XdmfArray.New()
subArray2.pushBackAsFloat64(2)
subResult = XdmfFunction.subtraction(subArray1, subArray2)
assert subResult.getValuesString() == "-2.5"
#//subtraction end
|