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
|
from Xdmf import *
from numpy import *
if __name__ == "__main__":
#//initialization begin
exampleArray = XdmfArray.New()
#//initialization end
#//setName begin
newName = "New Name"
exampleArray.setName(newName)
#//setName end
#//reserve begin
newSize = 10
exampleArray.reserve(newSize)
#//reserve end
#//initializesingle begin
newSize = 10
exampleArray.initialize(XdmfArrayType.Int32(), newSize)
#//initializesingle end
#//initializevector begin
newSizeVector = UInt32Vector()
newSizeVector.push_back(5)
newSizeVector.push_back(5)
newSizeVector.push_back(5)
exampleArray.initialize(XdmfArrayType.Int32(), newSizeVector)
#//initializevector end
#//getArrayType begin
exampleType = exampleArray.getArrayType()
#//getArrayType end
#//getCapacity begin
exampleCapacity = exampleArray.getCapacity()
#//getCapacity end
#//getDimensions begin
exampleDimensions = exampleArray.getDimensions()
#//getDimensions end
#//getDimensionsString begin
exampleDimensionString = exampleArray.getDimensionsString()
#//getDimensionsString end
#//getName begin
exampleName = exampleArray.getName()
#//getName end
#//getSize begin
exampleSize = exampleArray.getSize()
#//getSize end
#//insertarray begin
initArray = [0,1,2,3,4,5,6,7,8,9]
storeArray = XdmfArray.New()
exampleArray.insertAsInt32(0, initArray)
storeArray.insert(0, exampleArray, 0, 10, 1, 1)
#storeArray now contains {0,1,2,3,4,5,6,7,8,9}
storeArray.insert(0, exampleArray, 0, 5, 2, 1)
#storeArray now contains {0,1,1,3,2,5,3,7,4,9}
storeArray.insert(0, exampleArray, 0, 5, 1, 2)
#storeArray now contains {0,2,4,6,8,5,3,7,4,9}
#//insertarray end
#//insertlist begin
initArray = [0,1,2,3,4,5,6,7,8,9]
exampleArray.insertAsInt32(0, initArray)
#exampleArray now contains {0,1,2,3,4,5,6,7,8,9}
exampleArray.insertAsInt32(0, initArray[0:5:2])
#exampleArray now contains {0,2,4,6,8,5,3,7,4,9}
exampleArray.insertAsInt32(0, initArray[::-1])
#exampleArray now contains {9,8,7,6,5,4,3,2,1,0}
#Python uses a different function for each data type
#This example uses insertAsInt32 to insert ints
#insertAsFloat64 can also be used to insert doubles
#This function takes a start index and a list
#Sublists are inserted using Python's sublist notation
#//insertlist end
#//getNumpyArray begin
outputArray = exampleArray.getNumpyArray()
#//getNumpyArray end
#//arraydefaultvalues begin
initArray = [0,1,2,3,4,5,6,7,8,9]
exampleArray.insertAsInt32(0, initArray)
#//arraydefaultvalues end
#//resizesingle begin
newSize = 20
baseValue = 1
exampleArray.resizeAsInt32(newSize, baseValue)
#exampleArray now contains {0,1,2,3,4,5,6,7,8,9,1,1,1,1,1,1,1,1,1,1}
newSize = 5
exampleArray.resizeAsInt32(newSize, baseValue)
#exampleArray now contains {0,1,2,3,4}
#This example uses resizeAsInt32 because the baseValue inserted is to be an integer
#All other supported data types have similarly named function calls
#For example to insert a double resizeAsFloat64 is called
#//resizesingle end
#//resizevector begin
newSizeArray = UInt32Vector()
newSizeArray.push_back(4)
newSizeArray.push_back(5)
baseValue = 1
exampleArray.resizeAsInt32(newSizeArray, baseValue)
#exampleArray now contains {0,1,2,3,4,5,6,7,8,9,1,1,1,1,1,1,1,1,1,1}
newSizeArray[0] = 1
exampleArray.resizeAsInt32(newSizeArray, baseValue)
#exampleArray now contains {0,1,2,3,4}
#This example uses resizeAsInt32 because the baseValue inserted is to be an integer
#All other supported data types have similarly named function calls
#For example to insert a double resizeAsFloat64 is called
#//resizevector end
#//getValueindex begin
#If exampleArray contains [0, 1, 2, 3, 4, 5, 6, 7]
exampleValue = exampleArray.getValueAsInt32(4)
#exampleValue now equals 4
#The data type of the returned value can be changed by changing the function name
#getValueAsInt32 returns an int value while getValueAsFloat64 returns a double value
#Variations of this function exist for all supported data types
#//getValueindex end
#//getValuesparse begin
exampleValueString = exampleArray.getValuesString()
valueArray = [float(piece) for piece in exampleArray.getValuesString().split()]
#This is one method of getting the contained values of the array
#//getValuesparse end
#//isInitialized begin
if not(exampleArray.isInitialized()):
exampleArray.read()
#//isInitialized end
#//getValuesInternal begin
exampleValues = exampleArray.getValuesInternal()
#alternatively getBuffer gives a buffer object
exampleValues = exampleArray.getBuffer()
#due to the way python handles void pointers, this function is only useful for getting a pointer to pass
#if the retrieval of the internal values of the array is required, another function should be used
#//getValuesInternal end
#//swap begin
swapArray = XdmfArray.New()
initArray2 = [1,2,3,4,5]
swapArray.insertAsInt32(0, initArray2)
#exampleArray contains {0,1,2,3,4,5,6,7,8,9} and swapArray contains {1,2,3,4,5}
exampleArray.swap(swapArray)
#Now exampleArray contains {1,2,3,4,5} and swapArray contains {0,1,2,3,4,5,6,7,8,9}
#//swap end
#//pushBack begin
newValue = 5
exampleArray.pushBackAsInt32(newValue)
#For Python pushBack has multiple functions to cover different data types
#This case used an int so the function was pushBackAsInt32
#Another example would be to use pushBackAsFloat64 for double values
#//pushBack end
#//pointinsert begin
newIndex = 0
newValue = 3.5
exampleArray.insertAsFloat64(newIndex, [newValue])
#this example uses insertAsFloat64 to insert a double value
#versions for all other data types exist
#for example insertAsInt32 inserts as an int
#//pointinsert end
#//erase begin
#If exampleArray contains [0, 1, 2, 3, 4, 5, 6, 7]
erasedIndex = 4
exampleArray.erase(erasedIndex)
#exampleArray now contains the following
#[0, 1, 2, 3, 5, 6, 7]
#//erase end
#//clear begin
exampleArray.clear()
#//clear end
#//getHeavyDataController begin
exampleController = exampleArray.getHeavyDataController()
#//getHeavyDataController end
#//setHeavyDataController begin
newArray = XdmfArray.New()
newArray.setHeavyDataController(exampleController)
#//setHeavyDataController end
#//setHeavyDataControllerVector begin
sourceArray = XdmfArray.New()
sourceArray.pushBackAsInt32(5)
heavywriter = XdmfHDF5Writer.New("heavyfile.h5")
sourceArray.accept(heavywriter)
transferVector = HeavyControllerVector()
for i in range(0, sourceArray.getNumberHeavyDataControllers()):
transferVector.push_back(sourceArray.getHeavyDataController(i))
exampleArray.setHeavyDataController(transferVector)
#//setHeavyDataControllerVector end
#//readController begin
newArray->readController()
#//readController end
#//release begin
exampleArray.release()
#//release end
#//insertmultidim begin
writtenArray = XdmfArray.New()
dimensionVector = UInt32Vector()
dimensionVector.push_back(5)
dimensionVector.push_back(4)
writtenArray.initializeAsInt32(dimensionVector)
for i in range (0, 20):
writtenArray.insertAsInt32(i, i + 1)
readArray = XdmfArray.New()
readDimensionVector = UInt32Vector()
readDimensionVector.push_back(6)
readDimensionVector.push_back(4)
readArray.initializeAsInt32(readDimensionVector)
writeStarts = UInt32Vector()
writeStarts.push_back(0)
writeStarts.push_back(0)
writeStrides = UInt32Vector()
writeStrides.push_back(2)
writeStrides.push_back(2)
writeDim = UInt32Vector()
writeDim.push_back(3)
writeDim.push_back(2)
readStarts = UInt32Vector()
readStarts.push_back(0)
readStarts.push_back(0)
readStrides = UInt32Vector()
readStrides.push_back(2)
readStrides.push_back(2)
readDim = UInt32Vector()
readDim.push_back(3)
readDim.push_back(2)
readArray.insert(readStarts, writtenArray, writeStarts, writeDim, readDim, readStrides, writeStrides)
#//insertmultidim end
#//setReference begin
variableArray = XdmfArray.New()
for i in range(0, 10):
variableArray.pushBack(i)
variableMap = ArrayMap()
variableMap["A"] = variableArray
arrayFunction = XdmfFunction.New("AVE(A)", variableMap)
exampleArray.setReference(arrayFunction)
#//setReference end
#//getReference begin
exampleReference = exampleArray.getReference()
#//getReference end
#//readReference begin
exampleArray.readReference()
#//readReference end
#//setReadMode begin
exampleArray.setReadMode(XdmfArray.Reference)
#//setReadMode end
#//getReadMode begin
isReference = exampleArray.getReadMode()
if isReference == XdmfArray.Reference:
exampleArray.readReference()
#//getReadMode end
|