| 1 |
# Copyright(C) 1999-2020, 2024 National Technology & Engineering Solutions |
| 2 |
# of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
# NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
# |
| 5 |
# Redistribution and use in source and binary forms, with or without |
| 6 |
# modification, are permitted provided that the following conditions are |
| 7 |
# met: |
| 8 |
# |
| 9 |
# * Redistributions of source code must retain the above copyright |
| 10 |
# notice, this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# * Redistributions in binary form must reproduce the above |
| 13 |
# copyright notice, this list of conditions and the following |
| 14 |
# disclaimer in the documentation and/or other materials provided |
| 15 |
# with the distribution. |
| 16 |
# |
| 17 |
# * Neither the name of NTESS nor the names of its |
| 18 |
# contributors may be used to endorse or promote products derived |
| 19 |
# from this software without specific prior written permission. |
| 20 |
# |
| 21 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
|
| 33 |
from phactori import * |
| 34 |
from .PhactoriOperationBlock import * |
| 35 |
from .PhactoriVectorLibrary import * |
| 36 |
from paraview.simple import * |
| 37 |
from .PhactoriSegment import * |
| 38 |
from .PhactoriMpiUtilities import * |
| 39 |
from .PhactoriParaviewMultiBlockRecursion import * |
| 40 |
from .PhactoriSampledCellInfo import * |
| 41 |
from .PhactoriOutputFileNameAndDirectoryManager import * |
| 42 |
|
| 43 |
import vtk |
| 44 |
import json |
| 45 |
|
| 46 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 47 |
|
| 48 |
|
| 49 |
class GatherGeometricallySampledCellsRecursionParams: |
| 50 |
def __init__(self): |
| 51 |
self.leafVisitCount = 0 |
| 52 |
self.dataArrayNames = ["noname"] |
| 53 |
self.boundingBox = [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0] |
| 54 |
self.CellsMeetingGeometricCriteria = [] |
| 55 |
|
| 56 |
def CellTestPointMeetsGeometricCriteria(self, cellTestPoint): |
| 57 |
if cellTestPoint[0] < self.boundingBox[0]: |
| 58 |
return False |
| 59 |
if cellTestPoint[0] > self.boundingBox[1]: |
| 60 |
return False |
| 61 |
if cellTestPoint[1] < self.boundingBox[2]: |
| 62 |
return False |
| 63 |
if cellTestPoint[1] > self.boundingBox[3]: |
| 64 |
return False |
| 65 |
if cellTestPoint[2] < self.boundingBox[4]: |
| 66 |
return False |
| 67 |
if cellTestPoint[2] > self.boundingBox[5]: |
| 68 |
return False |
| 69 |
return True |
| 70 |
|
| 71 |
def SetUpForRecursion(self, creatingSamplerInstance): |
| 72 |
self.dataArrayNames = creatingSamplerInstance.CellDataArrayNames |
| 73 |
self.boundingBox = creatingSamplerInstance.SamplingGeometryBoundingBox |
| 74 |
|
| 75 |
class CollectDataOnSampledCellsRecursionParams: |
| 76 |
def __init__(self): |
| 77 |
self.leafVisitCount = 0 |
| 78 |
self.dataArrayNames = ["noname"] |
| 79 |
self.GeometricallySampledCellsByRecursionLeaf = None |
| 80 |
|
| 81 |
def SetUpForRecursion(self, creatingSamplerInstance): |
| 82 |
self.dataArrayNames = creatingSamplerInstance.CellDataArrayNames |
| 83 |
self.GeometricallySampledCellsByRecursionLeaf = creatingSamplerInstance.GeometricallySampledCellsByRecursionLeaf |
| 84 |
|
| 85 |
|
| 86 |
def localGetCellijk(ii, jj, kk, inInputCsData, myExtent): |
| 87 |
#returnCell = inInputCsData.GetCell(ii, jj, kk) |
| 88 |
computedIndex = vtk.vtkStructuredData.ComputeCellIdForExtent(myExtent, [ii,jj,kk]) |
| 89 |
returnCell = inInputCsData.GetCell(computedIndex) |
| 90 |
return returnCell |
| 91 |
|
| 92 |
class PhactoriGeometricCellSampler1(PhactoriOperationSpecifics): |
| 93 |
"""Filter/operation which reads in a .json file which is a list of 3d |
| 94 |
coordinates pairs (representating segments, and then finds all cells |
| 95 |
in the input data that cross that segment and sets a masking value |
| 96 |
into a cell data array for those cells""" |
| 97 |
def __init__(self): |
| 98 |
self.myCopyOfInputFilter = None |
| 99 |
|
| 100 |
#indicates whether we should conduct our segment-picking cell calculations |
| 101 |
#by projecting onto an ordinal plane. -1 is no projection, 0, 1, or 2 are |
| 102 |
#the x, y, or z axes. This is of particular use if you are doing a slice |
| 103 |
#before selecting elements. The slice does not need to be axis aligned, |
| 104 |
#just choose the axis plane closest to parallel to the slice plane. |
| 105 |
self.ProjectionAxis = -1 |
| 106 |
|
| 107 |
#as of 2019Aug13, we are having the programmable filter core dump with |
| 108 |
#structured data: this allows us to turn off the programmable filter to |
| 109 |
#do the other operations |
| 110 |
self.DoProgrammableFilterToAddMaskVariable = False |
| 111 |
self.mProgFilterMaskSetter = None |
| 112 |
self.mProgFilterString = None |
| 113 |
self.ProgrammableFilterOutputCellVariableName = "mask1" |
| 114 |
self.mainScriptString = None |
| 115 |
|
| 116 |
self.WriteOutGeometricallySampledCellData = True |
| 117 |
self.GeometricSampledCellOutputFilePathManager = PhactoriOutputFileNameAndDirectoryManager( |
| 118 |
"PhactoriGeometricCellSampler1_geometric_", |
| 119 |
"PhactoriGeometricCellSampler1_Output", 5, ".csv") |
| 120 |
|
| 121 |
self.WriteOutDataControlledSampledCellData = True |
| 122 |
self.DataControlledSampledCellOutputFilePathManager = PhactoriOutputFileNameAndDirectoryManager( |
| 123 |
"PhactoriGeometricCellSampler1_data_controlled_", |
| 124 |
"PhactoriGeometricCellSampler1_Output", 5, ".csv") |
| 125 |
|
| 126 |
self.CellDataArrayNames = ["V"] |
| 127 |
self.CellDataArrayTupleSize = 8 |
| 128 |
|
| 129 |
self.SamplingGeometryBoundingBox = [-0.5, 0.5, -0.5, 0.5, -0.5, 0.5] |
| 130 |
self.GeometricallySampledCellsForThisProcess = None |
| 131 |
self.GeometricallySampledCellsByRecursionLeaf = None |
| 132 |
|
| 133 |
self.DoPerCallbackDataControlledSampling = True |
| 134 |
self.DataControlledSampledCellsForThisProcess = None |
| 135 |
self.DataControlledSamplingMethod = "cells with ratio of min/max data value" |
| 136 |
#self.DataControlledSamplingMethod = "cells within distance of min/max highest data value cell" |
| 137 |
#self.DataControlledSamplingMethod = "cells within bounding box around min/max highest data value cell" |
| 138 |
self.DataControlledRatioBasis = "ratio is from zero to data maximum" |
| 139 |
#self.DataControlledRatioBasis = "ratio is from data minimum to data maximum" |
| 140 |
self.DataControlledRatio = 0.75 |
| 141 |
self.DataControlledRatioGreaterOrLess = "cells greater/equal" |
| 142 |
#self.DataControlledRatioGreaterOrLess = "cells less/equal" |
| 143 |
#self.RatioBasis = "data range based" |
| 144 |
self.DataControlledDistance = 0.1 |
| 145 |
self.DataControlledUseMinOrMax = "max" |
| 146 |
self.DataControlledBoundingBox = [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0] |
| 147 |
|
| 148 |
def CheckBoundingBox(self, boundingBox, parsekey, infoString): |
| 149 |
goodFlag = True |
| 150 |
if len(boundingBox) != 6: |
| 151 |
myDebugPrint3AndException(infoString + "\n" |
| 152 |
"bounding box is invalid for key: " + parseKey + "\n" |
| 153 |
"must be six float list, like:\n" |
| 154 |
"[-1.0, 1.0, -1.0, 1.0, -1.0, 1.0]\n") |
| 155 |
if (boundingBox[0] > boundingBox[1]) or \ |
| 156 |
(boundingBox[2] > boundingBox[3]) or \ |
| 157 |
(boundingBox[4] > boundingBox[5]): |
| 158 |
myDebugPrint3AndException(infoString + "\n" |
| 159 |
"bounding box is invalid for key: " + parseKey + "\n" |
| 160 |
"we need max >= min for each axis, like:\n" |
| 161 |
"[-1.0, 1.0, -1.0, 1.0, -1.0, 1.0]\n") |
| 162 |
|
| 163 |
def ParseParametersFromJson(self, inJson): |
| 164 |
#if "filename" in inJson: |
| 165 |
# self.JsonListFileName = inJson['filename'] |
| 166 |
#else: |
| 167 |
# myDebugPrint3AndException( |
| 168 |
# "PhactoriGeometricCellSampler1:ParseParametersFromJson\n" |
| 169 |
# "Error: must have 'filename' key\n") |
| 170 |
|
| 171 |
keyval1 = "sampling geometry bounding box" |
| 172 |
if keyval1 in inJson: |
| 173 |
newBB = inJson[keyval1] |
| 174 |
self.CheckBoundingBox(newBB, keyval1, |
| 175 |
"PhactoriGeometricCellSampler1:ParseParametersFromJson") |
| 176 |
self.SamplingGeometryBoundingBox = newBB |
| 177 |
|
| 178 |
keyval4 = "projection axis" |
| 179 |
if keyval4 in inJson: |
| 180 |
val4 = inJson[keyval4] |
| 181 |
if val4 == "none": |
| 182 |
self.ProjectionAxis = -1 |
| 183 |
elif val4 == "x": |
| 184 |
self.ProjectionAxis = 0 |
| 185 |
elif val4 == "y": |
| 186 |
self.ProjectionAxis = 1 |
| 187 |
elif val4 == "z": |
| 188 |
self.ProjectionAxis = 2 |
| 189 |
elif int(val4) == 1: |
| 190 |
self.ProjectionAxis = 0 |
| 191 |
elif int(val4) == 2: |
| 192 |
self.ProjectionAxis = 1 |
| 193 |
elif int(val4) == 3: |
| 194 |
self.ProjectionAxis = 2 |
| 195 |
|
| 196 |
keyval5 = "do programmable filter" |
| 197 |
if keyval5 in inJson: |
| 198 |
self.DoProgrammableFilterToAddMaskVariable = inJson[keyval5] |
| 199 |
|
| 200 |
self.GeometricSampledCellOutputFilePathManager.ParseOutputFileNameControl( |
| 201 |
inJson, "geometric sampled cell output file ") |
| 202 |
|
| 203 |
self.DataControlledSampledCellOutputFilePathManager.ParseOutputFileNameControl( |
| 204 |
inJson, "data controlled sampled cell output file ") |
| 205 |
|
| 206 |
keyval7e = "export geometric sampled cell data as json file" |
| 207 |
if keyval7e in inJson: |
| 208 |
self.WriteOutGeometricallySampledCellData = inJson[keyval7e] |
| 209 |
|
| 210 |
keyval7f = "export data controlled sampled cell data as json file" |
| 211 |
if keyval7f in inJson: |
| 212 |
self.WriteOutDataControlledSampledCellData = inJson[keyval7f] |
| 213 |
|
| 214 |
keyval8 = "cell data array names" |
| 215 |
if keyval8 in inJson: |
| 216 |
self.CellDataArrayNames = inJson[keyval8] |
| 217 |
|
| 218 |
keyval9 = "cell data array tuple size" |
| 219 |
if keyval9 in inJson: |
| 220 |
self.CellDataArrayTupleSize = inJson[keyval9] |
| 221 |
|
| 222 |
keyval10 = "programmable filter output cell variable name" |
| 223 |
if keyval10 in inJson: |
| 224 |
self.ProgrammableFilterOutputCellVariableName = inJson[keyval10] |
| 225 |
|
| 226 |
keyval11 = "data controlled sampling method" |
| 227 |
if keyval11 in inJson: |
| 228 |
self.DataControlledSamplingMethod = inJson[keyval11] |
| 229 |
if self.DataControlledSamplingMethod == "cells within distance of min/max highest data value cell": |
| 230 |
keyval11b = "data controlled distance" |
| 231 |
if keyval11b not in inJson: |
| 232 |
myDebugPrint3AndException("must have 'data controlled distance'\n") |
| 233 |
self.DataControlledDistance = inJson[keyval11b] |
| 234 |
elif self.DataControlledSamplingMethod == "cells with ratio of min/max data value": |
| 235 |
keyval11b = "data controlled ratio of min/max" |
| 236 |
if keyval11b in inJson: |
| 237 |
self.DataControlledRatio = inJson[keyval11b] |
| 238 |
if (self.DataControlledRatio < 0.0) or (self.DataControlledRatio > 1.0): |
| 239 |
myDebugPrint3AndException("'data controlled ratio of min/max must be in range [0.0, 1.0]\n") |
| 240 |
if PhactoriDbg(100): |
| 241 |
myDebugPrint3("self.DataControlledRatio set to " + str(self.DataControlledRatio) + "\n", 100) |
| 242 |
keyval11c = "data controlled ratio basis" |
| 243 |
if keyval11c in inJson: |
| 244 |
self.DataControlledRatioBasis = inJson[keyval11c] |
| 245 |
if (self.DataControlledRatioBasis != "ratio is from zero to data maximum") and \ |
| 246 |
(self.DataControlledRatioBasis != "ratio is from data minimum to data maximum"): |
| 247 |
myDebugPrint3("bad 'data controlled ratio basis'\n" |
| 248 |
"must be one of:\n" |
| 249 |
"'ratio is from zero to data maximum'\n" |
| 250 |
"'ratio is from data minimum to data maximum'\n") |
| 251 |
keyval11d = "collect cells relative to ratio" |
| 252 |
if keyval11d in inJson: |
| 253 |
self.DataControlledRatioGreaterOrLess = inJson[keyval11d] |
| 254 |
if (self.DataControlledRatioGreaterOrLess != "cells greater/equal") and \ |
| 255 |
(self.DataControlledRatioGreaterOrLess != "cells less/equal"): |
| 256 |
myDebugPrint3("bad 'collect cells relative to ratio'\n" |
| 257 |
"must be one of:\n" |
| 258 |
"'cells greater/equal'\n" |
| 259 |
"'cells less/equal'\n") |
| 260 |
elif self.DataControlledSamplingMethod == "cells within bounding box around min/max highest data value cell": |
| 261 |
keyval11b = "data controlled bounding box" |
| 262 |
if keyval11b in inJson: |
| 263 |
self.DataControlledBoundingBox = inJson[keyval11b] |
| 264 |
self.CheckBoundingBox(self.DataControlledBoundingBox, keyval11b, |
| 265 |
"PhactoriGeometricCellSampler1:ParseParametersFromJson") |
| 266 |
else: |
| 267 |
myDebugPrint3AndException("bad 'data controlled sampling method'\n") |
| 268 |
if PhactoriDbg(100): |
| 269 |
myDebugPrint3("self.DataControlledSamplingMethod set to " + \ |
| 270 |
str(self.DataControlledSamplingMethod) + "\n", 100) |
| 271 |
|
| 272 |
keyval11c = "data controlled sampling use min or max" |
| 273 |
if keyval11c in inJson: |
| 274 |
if inJson[keyval11c] == "max": |
| 275 |
self.DataControlledUseMinOrMax = "max" |
| 276 |
else: |
| 277 |
self.DataControlledUseMinOrMax = "min" |
| 278 |
|
| 279 |
def CreateParaViewFilter(self, inInputFilter): |
| 280 |
if PhactoriDbg(100): |
| 281 |
myDebugPrint3("PhactoriGeometricCellSampler1.CreateParaViewFilter entered\n", 100) |
| 282 |
|
| 283 |
savedActiveSource = GetActiveSource() |
| 284 |
|
| 285 |
self.myCopyOfInputFilter = inInputFilter |
| 286 |
|
| 287 |
UpdatePipelineWithCurrentTimeArgument(self.myCopyOfInputFilter) |
| 288 |
|
| 289 |
self.CreateInternalListOfGeometricallySampledCellsOnThisProcess() |
| 290 |
self.CreateInternalListOfDataControlledSampledCellsOnThisProcess() |
| 291 |
|
| 292 |
if self.DoProgrammableFilterToAddMaskVariable: |
| 293 |
self.mProgFilterMaskSetter = ProgrammableFilter( |
| 294 |
Input = self.myCopyOfInputFilter) |
| 295 |
self.mProgFilterMaskSetter.CopyArrays = 1 |
| 296 |
self.CreateProgrammableFilterString() |
| 297 |
self.mProgFilterMaskSetter.Script = self.mProgFilterString |
| 298 |
self.mProgFilterMaskSetter.UpdatePipeline() |
| 299 |
else: |
| 300 |
self.mProgFilterMaskSetter = self.myCopyOfInputFilter |
| 301 |
|
| 302 |
SetActiveSource(savedActiveSource) |
| 303 |
|
| 304 |
if PhactoriDbg(100): |
| 305 |
myDebugPrint3("PhactoriGeometricCellSampler1.CreateParaViewFilter returning\n", 100) |
| 306 |
return self.mProgFilterMaskSetter |
| 307 |
|
| 308 |
@staticmethod |
| 309 |
def GatherGeometricallySampledCellsInBlock(recursionObject, inInputCsData, inParameters): |
| 310 |
if PhactoriDbg(100): |
| 311 |
myDebugPrint3("GatherGeometricallySampledCellsInBlock entered\n") |
| 312 |
|
| 313 |
numCells = inInputCsData.GetNumberOfCells() |
| 314 |
numPoints = inInputCsData.GetNumberOfPoints() |
| 315 |
inParameters.leafVisitCount += 1 |
| 316 |
if (numCells == 0) or (numPoints == 0): |
| 317 |
#no cells here |
| 318 |
return |
| 319 |
|
| 320 |
cellData = inInputCsData.GetCellData() |
| 321 |
outputCellArrays = [] |
| 322 |
dataArrayNumCmpnts = 0 |
| 323 |
if cellData != None: |
| 324 |
for oneDataArrayName in inParameters.dataArrayNames: |
| 325 |
oneCellDataArray = cellData.GetArray(oneDataArrayName) |
| 326 |
outputCellArrays.append(oneCellDataArray) |
| 327 |
if oneCellDataArray != None: |
| 328 |
dataArrayNumCmpnts += oneCellDataArray.GetNumberOfComponents() |
| 329 |
if PhactoriDbg(100): |
| 330 |
myDebugPrint3("inParameters.dataArrayNames: " + str(inParameters.dataArrayNames) + "\n") |
| 331 |
for oneCellDataArray in outputCellArrays: |
| 332 |
if oneCellDataArray == None: |
| 333 |
myDebugPrint3("None\n") |
| 334 |
else: |
| 335 |
myDebugPrint3(str(oneCellDataArray.GetNumberOfTuples()) + "\n") |
| 336 |
|
| 337 |
if dataArrayNumCmpnts != 0: |
| 338 |
defaultTuple = [] |
| 339 |
for ii in range(0, dataArrayNumCmpnts): |
| 340 |
defaultTuple.append(-1.0) |
| 341 |
else: |
| 342 |
dataArrayNumCmpnts = -1 |
| 343 |
defaultTuple = [] |
| 344 |
|
| 345 |
myPid = SmartGetLocalProcessId() |
| 346 |
for cellIndex in range(0,numCells): |
| 347 |
oneCell = inInputCsData.GetCell(cellIndex) |
| 348 |
cellTestPoint = GetCellTestPoint(oneCell) |
| 349 |
if inParameters.CellTestPointMeetsGeometricCriteria(cellTestPoint): |
| 350 |
if dataArrayNumCmpnts == 0: |
| 351 |
thisCellDataTuple = defaultTuple |
| 352 |
else: |
| 353 |
thisCellDataTuple = [] |
| 354 |
for oneCellDataArray in outputCellArrays: |
| 355 |
if oneCellDataArray != None: |
| 356 |
dataTupleSub1 = oneCellDataArray.GetTuple(cellIndex) |
| 357 |
thisCellDataTuple.extend(dataTupleSub1) |
| 358 |
newCellInfo = PhactoriSampledCellInfo() |
| 359 |
newCellInfo.SetFromList([cellTestPoint, [-1,-1,-1], thisCellDataTuple, myPid, inParameters.leafVisitCount, cellIndex, -1, -1]) |
| 360 |
inParameters.CellsMeetingGeometricCriteria.append(newCellInfo) |
| 361 |
|
| 362 |
|
| 363 |
if PhactoriDbg(100): |
| 364 |
myDebugPrint3("GatherGeometricallySampledCellsInBlock returning\n") |
| 365 |
|
| 366 |
def CreateInternalListOfGeometricallySampledCellsOnThisProcess(self): |
| 367 |
if PhactoriDbg(100): |
| 368 |
myDebugPrint3("CreateInternalListOfGeometricallySampledCellsOnThisProcess entered\n") |
| 369 |
|
| 370 |
recursionParams = GatherGeometricallySampledCellsRecursionParams() |
| 371 |
recursionParams.SetUpForRecursion(self) |
| 372 |
recursionObj = PhactoriParaviewMultiBlockRecursionControl() |
| 373 |
recursionObj.mParameters = recursionParams |
| 374 |
recursionObj.mOperationToDoPerBlock = self.GatherGeometricallySampledCellsInBlock |
| 375 |
|
| 376 |
PhactoriRecusivelyDoMethodPerBlockFromParaViewFilter(recursionObj, self.myCopyOfInputFilter) |
| 377 |
if PhactoriDbg(100): |
| 378 |
myDebugPrint3("CreateInternalListOfGeometricallySampledCellsOnThisProcess returning\n") |
| 379 |
|
| 380 |
self.GeometricallySampledCellsForThisProcess = recursionParams.CellsMeetingGeometricCriteria |
| 381 |
self.CreateLeafRecursionTrackingStructure() |
| 382 |
|
| 383 |
def PointIsInsideBoundingBox(self, testPoint, testBoundingBox): |
| 384 |
if testPoint[0] < testBoundingBox[0]: |
| 385 |
return False |
| 386 |
if testPoint[0] > testBoundingBox[1]: |
| 387 |
return False |
| 388 |
if testPoint[1] < testBoundingBox[2]: |
| 389 |
return False |
| 390 |
if testPoint[1] > testBoundingBox[3]: |
| 391 |
return False |
| 392 |
if testPoint[2] < testBoundingBox[4]: |
| 393 |
return False |
| 394 |
if testPoint[2] > testBoundingBox[5]: |
| 395 |
return False |
| 396 |
return True |
| 397 |
|
| 398 |
def CreateInternalListOfDataControlledSampledCellsOnThisProcess(self): |
| 399 |
if PhactoriDbg(100): |
| 400 |
myDebugPrint3("CreateInternalListOfDataControlledSampledCellsOnThisProcess entered\n") |
| 401 |
|
| 402 |
if self.DoPerCallbackDataControlledSampling == False: |
| 403 |
self.DataControlledSampledCellsForThisProcess = self.GeometricallySampledCellsForThisProcess |
| 404 |
if PhactoriDbg(100): |
| 405 |
myDebugPrint3("CreateInternalListOfDataControlledSampledCellsOnThisProcess returning (no processing)\n") |
| 406 |
return |
| 407 |
|
| 408 |
self.DataControlledSampledCellsForThisProcess = [] |
| 409 |
|
| 410 |
#find min/max cell this process |
| 411 |
currentMax = -sys.float_info.max |
| 412 |
currentMin = sys.float_info.max |
| 413 |
if len(self.GeometricallySampledCellsForThisProcess) >= 1: |
| 414 |
for ii, oneCell in enumerate(self.GeometricallySampledCellsForThisProcess): |
| 415 |
testVal = oneCell.dataTuple[0] |
| 416 |
if testVal > currentMax: |
| 417 |
localMaxCell = oneCell |
| 418 |
currentMax = testVal |
| 419 |
if testVal < currentMin: |
| 420 |
localMinCell = oneCell |
| 421 |
currentMin = testVal |
| 422 |
else: |
| 423 |
myPid = SmartGetLocalProcessId() |
| 424 |
defaultDataTuple = [] |
| 425 |
for ii in range(0, self.CellDataArrayTupleSize): |
| 426 |
defaultDataTuple.append(0.0) |
| 427 |
localMinCell = PhactoriSampledCellInfo() |
| 428 |
defaultDataTuple[0] = currentMax |
| 429 |
localMinCell.SetFromList([[0.0,0.0,0.0], [-1,-1,-1], defaultDataTuple, myPid, -1, -1, -1, -1]) |
| 430 |
localMaxCell = PhactoriSampledCellInfo() |
| 431 |
defaultDataTuple[0] = currentMin |
| 432 |
localMaxCell.SetFromList([[0.0,0.0,0.0], [-1,-1,-1], defaultDataTuple, myPid, -1, -1, -1, -1]) |
| 433 |
|
| 434 |
if PhactoriDbg(100): |
| 435 |
myDebugPrint3("localMinCell:\n" + localMinCell.ToStrTerseOneLineList() + "\n") |
| 436 |
myDebugPrint3("localMaxCell:\n" + localMaxCell.ToStrTerseOneLineList() + "\n") |
| 437 |
#find min/max cell all processes |
| 438 |
globalMinMaxCellPair = PhactoriLocalToGlobalCellsWithMinMaxDataUsingMPI([localMinCell, localMaxCell], self.CellDataArrayTupleSize) |
| 439 |
if PhactoriDbg(100): |
| 440 |
myDebugPrint3("globalMinCell:\n" + globalMinMaxCellPair[0].ToStrTerseOneLineList() + "\n") |
| 441 |
myDebugPrint3("globalMaxCell:\n" + globalMinMaxCellPair[1].ToStrTerseOneLineList() + "\n") |
| 442 |
myDebugPrint3("self.DataControlledSamplingMethod: " + self.DataControlledSamplingMethod + "\n") |
| 443 |
|
| 444 |
if self.DataControlledSamplingMethod == "cells with ratio of min/max data value": |
| 445 |
if self.DataControlledRatioBasis == "ratio is from zero to data maximum": |
| 446 |
maxCell = globalMinMaxCellPair[1] |
| 447 |
thresholdValue = self.DataControlledRatio * maxCell.dataTuple[0] |
| 448 |
if PhactoriDbg(100): |
| 449 |
myDebugPrint3("ratio is from zero to data maximum: " + str(maxCell.dataTuple[0]) + \ |
| 450 |
", " + str(self.DataControlledRatio) + "\n") |
| 451 |
else: |
| 452 |
minCell = globalMinMaxCellPair[0] |
| 453 |
maxCell = globalMinMaxCellPair[1] |
| 454 |
minValue = minCell.dataTuple[0] |
| 455 |
maxValue = maxCell.dataTuple[0] |
| 456 |
minMaxRange = maxValue - minValue |
| 457 |
thresholdValue = minValue + self.DataControlledRatio * minMaxRange |
| 458 |
if PhactoriDbg(100): |
| 459 |
myDebugPrint3("ratio is from data minimum to data maximum: " + str(minValue) + ", " + \ |
| 460 |
str(maxValue) + ", " + str(minMaxRange) + ", " + \ |
| 461 |
str(self.DataControlledRatio) + "\n") |
| 462 |
if PhactoriDbg(100): |
| 463 |
myDebugPrint3("thresholdValue: " + str(thresholdValue) + "\n") |
| 464 |
if self.DataControlledRatioGreaterOrLess == "cells greater/equal": |
| 465 |
for ii, oneCell in enumerate(self.GeometricallySampledCellsForThisProcess): |
| 466 |
if oneCell.dataTuple[0] >= thresholdValue: |
| 467 |
self.DataControlledSampledCellsForThisProcess.append(oneCell) |
| 468 |
else: |
| 469 |
for ii, oneCell in enumerate(self.GeometricallySampledCellsForThisProcess): |
| 470 |
if oneCell.dataTuple[0] <= thresholdValue: |
| 471 |
self.DataControlledSampledCellsForThisProcess.append(oneCell) |
| 472 |
if PhactoriDbg(100): |
| 473 |
myDebugPrint3("number of cells out of how many got sampled: " + \ |
| 474 |
str(len(self.DataControlledSampledCellsForThisProcess)) + ", " + \ |
| 475 |
str(len(self.GeometricallySampledCellsForThisProcess)) + "\n") |
| 476 |
elif self.DataControlledSamplingMethod == "cells within distance of min/max highest data value cell": |
| 477 |
if PhactoriDbg(100): |
| 478 |
myDebugPrint3("doing distance test: " + \ |
| 479 |
str(self.DataControlledUseMinOrMax) + ", " + \ |
| 480 |
str(self.DataControlledDistance) + "\n") |
| 481 |
if self.DataControlledUseMinOrMax == "max": |
| 482 |
centerCellPoint = globalMinMaxCellPair[1].cellTestPoint |
| 483 |
else: |
| 484 |
centerCellPoint = globalMinMaxCellPair[0].cellTestPoint |
| 485 |
if PhactoriDbg(100): |
| 486 |
myDebugPrint3("centerCellPoint: " + str(centerCellPoint) + "\n") |
| 487 |
for ii, oneCell in enumerate(self.GeometricallySampledCellsForThisProcess): |
| 488 |
cellDistance = vecDistance(centerCellPoint, oneCell.cellTestPoint) |
| 489 |
if cellDistance <= self.DataControlledDistance: |
| 490 |
self.DataControlledSampledCellsForThisProcess.append(oneCell) |
| 491 |
elif self.DataControlledSamplingMethod == "cells within bounding box around min/max highest data value cell": |
| 492 |
if PhactoriDbg(100): |
| 493 |
myDebugPrint3("doing bounding box test: " + \ |
| 494 |
str(self.DataControlledUseMinOrMax) + ", " + \ |
| 495 |
str(self.DataControlledBoundingBox) + "\n") |
| 496 |
if self.DataControlledUseMinOrMax == "max": |
| 497 |
centerCellPoint = globalMinMaxCellPair[1].cellTestPoint |
| 498 |
else: |
| 499 |
centerCellPoint = globalMinMaxCellPair[0].cellTestPoint |
| 500 |
if PhactoriDbg(100): |
| 501 |
myDebugPrint3("centerCellPoint: " + str(centerCellPoint) + "\n") |
| 502 |
testBoundingBox = [ |
| 503 |
centerCellPoint[0] + self.DataControlledBoundingBox[0], |
| 504 |
centerCellPoint[0] + self.DataControlledBoundingBox[1], |
| 505 |
centerCellPoint[1] + self.DataControlledBoundingBox[2], |
| 506 |
centerCellPoint[1] + self.DataControlledBoundingBox[3], |
| 507 |
centerCellPoint[2] + self.DataControlledBoundingBox[4], |
| 508 |
centerCellPoint[2] + self.DataControlledBoundingBox[5] |
| 509 |
] |
| 510 |
for ii, oneCell in enumerate(self.GeometricallySampledCellsForThisProcess): |
| 511 |
if self.PointIsInsideBoundingBox(oneCell.cellTestPoint, testBoundingBox): |
| 512 |
self.DataControlledSampledCellsForThisProcess.append(oneCell) |
| 513 |
else: |
| 514 |
myDebugPrint3AndException("CreateInternalListOfDataControlledSampledCellsOnThisProcess:\n" +\ |
| 515 |
"bad self.DataControlledSamplingMethod\n") |
| 516 |
|
| 517 |
|
| 518 |
if PhactoriDbg(100): |
| 519 |
myDebugPrint3("CreateInternalListOfDataControlledSampledCellsOnThisProcess returning\n") |
| 520 |
|
| 521 |
#self.CreateLeafRecursionTrackingStructure() |
| 522 |
|
| 523 |
@staticmethod |
| 524 |
def CollectDataOnSampledCellsInBlock(recursionObject, inInputCsData, inParameters): |
| 525 |
if PhactoriDbg(100): |
| 526 |
myDebugPrint3("CollectDataOnSampledCellsInBlock entered 1\n") |
| 527 |
|
| 528 |
inParameters.leafVisitCount += 1 |
| 529 |
|
| 530 |
if inParameters.GeometricallySampledCellsByRecursionLeaf == None: |
| 531 |
#no cells collected for sampling on this process |
| 532 |
if PhactoriDbg(100): |
| 533 |
myDebugPrint3("CollectDataOnSampledCellsInBlock returning 1\n") |
| 534 |
return |
| 535 |
|
| 536 |
if inParameters.leafVisitCount not in inParameters.GeometricallySampledCellsByRecursionLeaf: |
| 537 |
#no cells collected for sampling on this block on this process |
| 538 |
if PhactoriDbg(100): |
| 539 |
myDebugPrint3("CollectDataOnSampledCellsInBlock returning 2\n") |
| 540 |
return |
| 541 |
|
| 542 |
numCells = inInputCsData.GetNumberOfCells() |
| 543 |
numPoints = inInputCsData.GetNumberOfPoints() |
| 544 |
if (numCells == 0) or (numPoints == 0): |
| 545 |
#no cells here |
| 546 |
if PhactoriDbg(100): |
| 547 |
myDebugPrint3("CollectDataOnSampledCellsInBlock returning 3\n") |
| 548 |
return |
| 549 |
|
| 550 |
cellData = inInputCsData.GetCellData() |
| 551 |
if cellData == None: |
| 552 |
if PhactoriDbg(100): |
| 553 |
myDebugPrint3("CollectDataOnSampledCellsInBlock returning 4\n") |
| 554 |
return |
| 555 |
|
| 556 |
testDataCellArray = None |
| 557 |
testDataCellArray = cellData.GetArray(inParameters.dataArrayNames[0]) |
| 558 |
|
| 559 |
if testDataCellArray == None: |
| 560 |
if PhactoriDbg(100): |
| 561 |
myDebugPrint3("CollectDataOnSampledCellsInBlock returning 5\n") |
| 562 |
return |
| 563 |
|
| 564 |
outputCellArrays = [] |
| 565 |
dataArrayNumCmpnts = 0 |
| 566 |
if cellData != None: |
| 567 |
for oneDataArrayName in inParameters.dataArrayNames: |
| 568 |
oneCellDataArray = cellData.GetArray(oneDataArrayName) |
| 569 |
outputCellArrays.append(oneCellDataArray) |
| 570 |
if oneCellDataArray != None: |
| 571 |
dataArrayNumCmpnts += oneCellDataArray.GetNumberOfComponents() |
| 572 |
if PhactoriDbg(100): |
| 573 |
myDebugPrint3("inParameters.dataArrayNames: " + str(inParameters.dataArrayNames) + "\n") |
| 574 |
for oneCellDataArray in outputCellArrays: |
| 575 |
if oneCellDataArray == None: |
| 576 |
myDebugPrint3("None\n") |
| 577 |
else: |
| 578 |
myDebugPrint3(str(oneCellDataArray.GetNumberOfTuples()) + "\n") |
| 579 |
|
| 580 |
if dataArrayNumCmpnts != 0: |
| 581 |
defaultTuple = [] |
| 582 |
for ii in range(0, dataArrayNumCmpnts): |
| 583 |
defaultTuple.append(-1.0) |
| 584 |
else: |
| 585 |
dataArrayNumCmpnts = -1 |
| 586 |
defaultTuple = [] |
| 587 |
|
| 588 |
myPid = SmartGetLocalProcessId() |
| 589 |
|
| 590 |
sampleCellList = inParameters.GeometricallySampledCellsByRecursionLeaf[inParameters.leafVisitCount] |
| 591 |
if PhactoriDbg(100): |
| 592 |
myDebugPrint3("num cells, leaf: " + str(len(sampleCellList)) + ", " + str(inParameters.leafVisitCount) + "\n") |
| 593 |
for oneSampleCell in sampleCellList: |
| 594 |
#thisCellDataTuple = outputCellArray.GetTuple(oneSampleCell.index) |
| 595 |
if dataArrayNumCmpnts == 0: |
| 596 |
thisCellDataTuple = defaultTuple |
| 597 |
else: |
| 598 |
thisCellDataTuple = [] |
| 599 |
for oneCellDataArray in outputCellArrays: |
| 600 |
if oneCellDataArray != None: |
| 601 |
dataTupleSub1 = oneCellDataArray.GetTuple(oneSampleCell.index) |
| 602 |
thisCellDataTuple.extend(dataTupleSub1) |
| 603 |
tupleCount = min(len(thisCellDataTuple), len(oneSampleCell.dataTuple)) |
| 604 |
if PhactoriDbg(100): |
| 605 |
myDebugPrint3(str(oneSampleCell.index) + ", " + str(thisCellDataTuple) + ", " + str(tupleCount) + "\n") |
| 606 |
for ii in range(0, tupleCount): |
| 607 |
oneSampleCell.dataTuple[ii] = thisCellDataTuple[ii] |
| 608 |
|
| 609 |
if PhactoriDbg(100): |
| 610 |
myDebugPrint3("CollectDataOnSampledCellsInBlock returning 6\n") |
| 611 |
|
| 612 |
def CollectDataOnSampledCellsOnThisProcess(self): |
| 613 |
"""go through existing list of cells for this process, and get the data |
| 614 |
value for the current time into each cell sample instance""" |
| 615 |
if PhactoriDbg(100): |
| 616 |
myDebugPrint3("CollectDataOnSampledCellsOnThisProcess entered\n") |
| 617 |
|
| 618 |
recursionParams = CollectDataOnSampledCellsRecursionParams() |
| 619 |
recursionParams.SetUpForRecursion(self) |
| 620 |
recursionObj = PhactoriParaviewMultiBlockRecursionControl() |
| 621 |
recursionObj.mParameters = recursionParams |
| 622 |
recursionObj.mOperationToDoPerBlock = self.CollectDataOnSampledCellsInBlock |
| 623 |
|
| 624 |
PhactoriRecusivelyDoMethodPerBlockFromParaViewFilter(recursionObj, self.myCopyOfInputFilter) |
| 625 |
if PhactoriDbg(100): |
| 626 |
myDebugPrint3("CollectDataOnSampledCellsOnThisProcess returning\n") |
| 627 |
|
| 628 |
def CreateLeafRecursionTrackingStructure(self): |
| 629 |
if PhactoriDbg(100): |
| 630 |
myDebugPrint3("CreateLeafRecursionTrackingStructure entered\n") |
| 631 |
|
| 632 |
if len(self.GeometricallySampledCellsForThisProcess) <= 0: |
| 633 |
self.GeometricallySampledCellsByRecursionLeaf = None |
| 634 |
if PhactoriDbg(100): |
| 635 |
myDebugPrint3("CreateLeafRecursionTrackingStructure returning (no cells)\n") |
| 636 |
return |
| 637 |
|
| 638 |
self.GeometricallySampledCellsByRecursionLeaf = {} |
| 639 |
for oneCell in self.GeometricallySampledCellsForThisProcess: |
| 640 |
leafVal = oneCell.leafVisitCount |
| 641 |
if leafVal not in self.GeometricallySampledCellsByRecursionLeaf: |
| 642 |
self.GeometricallySampledCellsByRecursionLeaf[leafVal] = [] |
| 643 |
listForLeaf = self.GeometricallySampledCellsByRecursionLeaf[leafVal] |
| 644 |
listForLeaf.append(oneCell) |
| 645 |
|
| 646 |
if PhactoriDbg(100): |
| 647 |
for leafKey in self.GeometricallySampledCellsByRecursionLeaf: |
| 648 |
cellListForLeaf = self.GeometricallySampledCellsByRecursionLeaf[leafKey] |
| 649 |
myDebugPrint3(str(len(cellListForLeaf)) + " cells for leaf " + str(leafKey) + "\n") |
| 650 |
|
| 651 |
if PhactoriDbg(100): |
| 652 |
myDebugPrint3("CreateLeafRecursionTrackingStructure returning\n") |
| 653 |
|
| 654 |
def WriteCellListToFile(self, filename, cellList): |
| 655 |
|
| 656 |
sumTuple = [] |
| 657 |
for ii in range(0, self.CellDataArrayTupleSize): |
| 658 |
sumTuple.append(0.0) |
| 659 |
for oneCellInfo in cellList: |
| 660 |
dataTuple = oneCellInfo.dataTuple |
| 661 |
for ii in range(0, self.CellDataArrayTupleSize): |
| 662 |
sumTuple[ii] += dataTuple[ii] |
| 663 |
floatCellCount = float(len(cellList)) |
| 664 |
averageTuple = [] |
| 665 |
for oneItem in sumTuple: |
| 666 |
averageTuple.append(oneItem / floatCellCount) |
| 667 |
|
| 668 |
ff = open(filename, "w") |
| 669 |
ff.write("{\n") |
| 670 |
ff.write('"format for cells in lists": ' + PhactoriSampledCellInfo.TerseOneLineJsonFormatComment() + ",\n") |
| 671 |
ff.write('"sampling geometry bounding box": ' + str(self.SamplingGeometryBoundingBox) + ",\n") |
| 672 |
ff.write('"number of cells": ' + str(len(cellList)) + ",\n") |
| 673 |
ff.write('"cell variable names": ') |
| 674 |
ff.write('[') |
| 675 |
lastIndex = len(self.CellDataArrayNames) - 1 |
| 676 |
for ii, oneArrayName in enumerate(self.CellDataArrayNames): |
| 677 |
if ii != lastIndex: |
| 678 |
ff.write('"' + str(oneArrayName) + '", ') |
| 679 |
else: |
| 680 |
ff.write('"' + str(oneArrayName) + '"') |
| 681 |
ff.write('],\n') |
| 682 |
ff.write('"data tuple size": ' + str(self.CellDataArrayTupleSize) + ",\n") |
| 683 |
ff.write('"sum variable values": ' + str(sumTuple) + ",\n") |
| 684 |
ff.write('"average variable values": ' + str(averageTuple) + ",\n") |
| 685 |
ff.write('"list of sampled cells": [\n') |
| 686 |
for cellCntr, oneCellInfo in enumerate(cellList): |
| 687 |
if cellCntr != 0: |
| 688 |
ff.write(",\n") |
| 689 |
cellStr = oneCellInfo.ToStrTerseOneLineList() |
| 690 |
ff.write(cellStr) |
| 691 |
ff.write("]\n") |
| 692 |
ff.write("}\n") |
| 693 |
|
| 694 |
ff.close() |
| 695 |
|
| 696 |
def GatherSampledCellDataFromAllProcessesUsingMPI(self, thisProcessCellList): |
| 697 |
if PhactoriDbg(100): |
| 698 |
myDebugPrint3("PhactoriGeometricCellSampler1.GatherSampledCellDataFromAllProcessesUsingMPI entered\n", 100) |
| 699 |
|
| 700 |
myPid = SmartGetLocalProcessId() |
| 701 |
|
| 702 |
##to start with, just have each process output it's data |
| 703 |
if PhactoriDbg(100): |
| 704 |
thisProcessHasData = False |
| 705 |
if thisProcessCellList != None: |
| 706 |
if len(thisProcessCellList) != 0: |
| 707 |
basename = "PhactoriGeometricCellSampler1_oneprocess_" + str(myPid) + ".json" |
| 708 |
self.WriteCellListToFile(pidfname, thisProcessCellList) |
| 709 |
|
| 710 |
if PhactoriDbg(100): |
| 711 |
myDebugPrint3("about to serialize cell infos\n", 100) |
| 712 |
|
| 713 |
tupleSize = self.CellDataArrayTupleSize |
| 714 |
cellListSerializedFloatArray = [] |
| 715 |
cellListSerializedIntArray = [] |
| 716 |
for idx, oneCellInfo in enumerate(thisProcessCellList): |
| 717 |
oneCellInfo.SerializeAppendToFloatAndIntArray(cellListSerializedFloatArray, cellListSerializedIntArray, tupleSize) |
| 718 |
|
| 719 |
if PhactoriDbg(100): |
| 720 |
myDebugPrint3("done serializing " + str(len(cellListSerializedFloatArray)) + " " + str(len(cellListSerializedIntArray)) + "\n", 100) |
| 721 |
|
| 722 |
pidToDoOutput = SmartGetNumberOfProcesses() - 1 |
| 723 |
globalSerializedFloatArray = UseMpiToSendAllProcessesFloatArrayToOneProcess(cellListSerializedFloatArray, pidToDoOutput) |
| 724 |
globalSerializedIntArray = UseMpiToSendAllProcessesIntArrayToOneProcess(cellListSerializedIntArray, pidToDoOutput) |
| 725 |
|
| 726 |
if PhactoriDbg(100): |
| 727 |
myDebugPrint3("returned from getting globalSerializedFloatArray and globalSerializedIntArray\n") |
| 728 |
|
| 729 |
globalCellList = [] |
| 730 |
if myPid == pidToDoOutput: |
| 731 |
if PhactoriDbg(100): |
| 732 |
myDebugPrint3("I'm the output pid, about to serialize in\n") |
| 733 |
|
| 734 |
serialFloatSize, serialIntSize = PhactoriSampledCellInfo.GetSerializeFloatAndIntSize(tupleSize) |
| 735 |
globalNumCells = len(globalSerializedFloatArray) / serialFloatSize |
| 736 |
|
| 737 |
for ii in range(0, globalNumCells): |
| 738 |
newCell = PhactoriSampledCellInfo() |
| 739 |
newCell.SerializeSetFromFloatAndIntArray(globalSerializedFloatArray, globalSerializedIntArray, ii, tupleSize) |
| 740 |
globalCellList.append(newCell) |
| 741 |
|
| 742 |
if PhactoriDbg(100): |
| 743 |
myDebugPrint3("PhactoriGeometricCellSampler1.GatherSampledCellDataFromAllProcessesUsingMPI returning\n", 100) |
| 744 |
|
| 745 |
return globalCellList |
| 746 |
|
| 747 |
|
| 748 |
def GatherSampledCellDataFromAllProcessesAndWriteFromOneProcessUsingMPI(self, outputFilenameCounter = -1): |
| 749 |
if PhactoriDbg(100): |
| 750 |
myDebugPrint3("PhactoriGeometricCellSampler1.GatherSampledCellDataFromAllProcessesAndWriteFromOneProcessUsingMPI entered\n", 100) |
| 751 |
myPid = SmartGetLocalProcessId() |
| 752 |
|
| 753 |
if outputFilenameCounter < 0: |
| 754 |
ftc = GetFrameTagCounter() |
| 755 |
else: |
| 756 |
ftc = outputFilenameCounter |
| 757 |
|
| 758 |
|
| 759 |
pidToDoOutput = SmartGetNumberOfProcesses() - 1 |
| 760 |
if self.WriteOutGeometricallySampledCellData == True: |
| 761 |
globalCellList = self.GatherSampledCellDataFromAllProcessesUsingMPI(self.GeometricallySampledCellsForThisProcess) |
| 762 |
if myPid == pidToDoOutput: |
| 763 |
if PhactoriDbg(100): |
| 764 |
myDebugPrint3("finished serialize, about to write to geometric sample cell file\n" +\ |
| 765 |
"number of cells from all processes: " + str(len(globalCellList)) + "\n") |
| 766 |
|
| 767 |
fname = self.GeometricSampledCellOutputFilePathManager.GetOutputFilePath(ftc, "") |
| 768 |
if PhactoriDbg(100): |
| 769 |
myDebugPrint3("output filename will be: " + str(fname) + "\n") |
| 770 |
self.WriteCellListToFile(fname, globalCellList) |
| 771 |
|
| 772 |
if self.WriteOutDataControlledSampledCellData == True: |
| 773 |
globalCellList = self.GatherSampledCellDataFromAllProcessesUsingMPI(self.DataControlledSampledCellsForThisProcess) |
| 774 |
if myPid == pidToDoOutput: |
| 775 |
if PhactoriDbg(100): |
| 776 |
myDebugPrint3("finished serialize, about to write to data controlled sample cell file\n" +\ |
| 777 |
"number of cells from all processes: " + str(len(globalCellList)) + "\n") |
| 778 |
|
| 779 |
fname = self.DataControlledSampledCellOutputFilePathManager.GetOutputFilePath(ftc, "") |
| 780 |
if PhactoriDbg(100): |
| 781 |
myDebugPrint3("output filename will be: " + str(fname) + "\n") |
| 782 |
self.WriteCellListToFile(fname, globalCellList) |
| 783 |
|
| 784 |
if PhactoriDbg(100): |
| 785 |
myDebugPrint3("PhactoriGeometricCellSampler1.GatherSampledCellDataFromAllProcessesAndWriteFromOneProcessUsingMPI returning\n", 100) |
| 786 |
|
| 787 |
def ExportOperationData(self, datadescription): |
| 788 |
if PhactoriDbg(100): |
| 789 |
myDebugPrint3("PhactoriGeometricCellSampler1.ExportOperationData entered\n", 100) |
| 790 |
|
| 791 |
UpdatePipelineWithCurrentTimeArgument(self.myCopyOfInputFilter) |
| 792 |
|
| 793 |
#if we are supposed to resample data after first timestep, we call Create again |
| 794 |
#self.CreateInternalListOfGeometricallySampledCellsOnThisProcess |
| 795 |
#the idea here is that we already have our cell collection and we want to pull the data |
| 796 |
self.CollectDataOnSampledCellsOnThisProcess() |
| 797 |
|
| 798 |
self.CreateInternalListOfDataControlledSampledCellsOnThisProcess() |
| 799 |
|
| 800 |
self.GatherSampledCellDataFromAllProcessesAndWriteFromOneProcessUsingMPI() |
| 801 |
|
| 802 |
if self.DoProgrammableFilterToAddMaskVariable: |
| 803 |
self.CreateProgrammableFilterString() |
| 804 |
self.mProgFilterMaskSetter.Script = self.mProgFilterString |
| 805 |
self.mProgFilterMaskSetter.UpdatePipeline() |
| 806 |
|
| 807 |
#if PhactoriDbg(100): |
| 808 |
# minCellmaxCellPair = PhactoriFindCellWithMinMaxDataOnThisProcess(self.myCopyOfInputFilter, "eqps") |
| 809 |
# myDebugPrint3("min cell this process:\n" + minCellmaxCellPair[0].ToStr()) |
| 810 |
# myDebugPrint3("max cell this process:\n" + minCellmaxCellPair[1].ToStr()) |
| 811 |
# globalMinCellmaxCellPair = PhactoriFindCellWtihMinMaxDataUsingMPI(self.myCopyOfInputFilter, "eqps") |
| 812 |
# myDebugPrint3("min cell global:\n" + globalMinCellmaxCellPair[0].ToStr()) |
| 813 |
# myDebugPrint3("max cell global:\n" + globalMinCellmaxCellPair[1].ToStr()) |
| 814 |
|
| 815 |
if PhactoriDbg(100): |
| 816 |
myDebugPrint3("PhactoriGeometricCellSampler1.ExportOperationData returning\n", 100) |
| 817 |
|
| 818 |
def CreateProgrammableFilterString(self): |
| 819 |
|
| 820 |
if self.mainScriptString == None: |
| 821 |
scriptLines = [] |
| 822 |
|
| 823 |
scriptLines.append("#print('test2')\n") |
| 824 |
|
| 825 |
scriptLines.append("#cellIndexesToSet = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]\n") |
| 826 |
scriptLines.append("#maskValuesToSet = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0]\n") |
| 827 |
scriptLines.append("#leafVisitCount = [0,0,0,0,0,0,0,0,0,0,0]\n") |
| 828 |
|
| 829 |
scriptLines.append("localLeafVisitCount = 0\n") |
| 830 |
|
| 831 |
scriptLines.append("def flatten(input, output):\n") |
| 832 |
scriptLines.append(" # Copy the cells etc.\n") |
| 833 |
scriptLines.append(" output.ShallowCopy(input)\n") |
| 834 |
scriptLines.append(" numPoints = input.GetNumberOfPoints()\n") |
| 835 |
scriptLines.append(" celldata = output.GetCellData()\n") |
| 836 |
scriptLines.append(" numCells = input.GetNumberOfCells()\n") |
| 837 |
scriptLines.append(" #print(str(numCells))\n") |
| 838 |
scriptLines.append(" ncda = vtk.vtkDoubleArray()\n") |
| 839 |
scriptLines.append(" ncda.SetNumberOfTuples(numCells)\n") |
| 840 |
scriptLines.append(" numTuples = ncda.GetNumberOfTuples()\n") |
| 841 |
scriptLines.append(" for ii in range(0, numTuples):\n") |
| 842 |
scriptLines.append(" ncda.SetValue(ii, 0.0)\n") |
| 843 |
scriptLines.append(" for ii, cellNdx in enumerate(cellIndexesToSet):\n") |
| 844 |
scriptLines.append(" if localLeafVisitCount == leafVisitCount[ii]:\n") |
| 845 |
scriptLines.append(" if cellNdx < numCells:\n") |
| 846 |
scriptLines.append(" ncda.SetValue(cellNdx, float(maskValuesToSet[ii]))\n") |
| 847 |
scriptLines.append(" ncda.SetName('" + self.ProgrammableFilterOutputCellVariableName + "')\n") |
| 848 |
scriptLines.append(" #print(ncda.GetName())\n") |
| 849 |
scriptLines.append(" celldata.AddArray(ncda)\n") |
| 850 |
|
| 851 |
scriptLines.append("input = self.GetInputDataObject(0, 0)\n") |
| 852 |
scriptLines.append("output = self.GetOutputDataObject(0)\n") |
| 853 |
|
| 854 |
scriptLines.append("if input.IsA('vtkMultiBlockDataSet'):\n") |
| 855 |
scriptLines.append(" output.CopyStructure(input)\n") |
| 856 |
scriptLines.append(" iter = input.NewIterator()\n") |
| 857 |
scriptLines.append(" iter.UnRegister(None)\n") |
| 858 |
scriptLines.append(" iter.InitTraversal()\n") |
| 859 |
scriptLines.append(" while not iter.IsDoneWithTraversal():\n") |
| 860 |
scriptLines.append(" localLeafVisitCount += 1\n") |
| 861 |
scriptLines.append(" curInput = iter.GetCurrentDataObject()\n") |
| 862 |
scriptLines.append(" curOutput = curInput.NewInstance()\n") |
| 863 |
scriptLines.append(" curOutput.UnRegister(None)\n") |
| 864 |
scriptLines.append(" output.SetDataSet(iter, curOutput)\n") |
| 865 |
scriptLines.append(" flatten(curInput, curOutput)\n") |
| 866 |
scriptLines.append(" iter.GoToNextItem();\n") |
| 867 |
scriptLines.append("else:\n") |
| 868 |
scriptLines.append(" flatten(input, output)\n") |
| 869 |
|
| 870 |
self.mainScriptString = "".join(scriptLines) |
| 871 |
|
| 872 |
myCellIndexesToSet = [] |
| 873 |
myMaskValuesToSet = [] |
| 874 |
myLeafVisitCount = [] |
| 875 |
if self.GeometricallySampledCellsForThisProcess != None: |
| 876 |
for cellIdx, oneCellInfo in enumerate(self.GeometricallySampledCellsForThisProcess): |
| 877 |
maskValue = 1.0 |
| 878 |
myCellIndexesToSet.append(oneCellInfo.index) |
| 879 |
myMaskValuesToSet.append(maskValue) |
| 880 |
myLeafVisitCount.append(oneCellInfo.leafVisitCount) |
| 881 |
if self.DataControlledSampledCellsForThisProcess != None: |
| 882 |
for cellIdx, oneCellInfo in enumerate(self.DataControlledSampledCellsForThisProcess): |
| 883 |
maskValue = 2.0 |
| 884 |
myCellIndexesToSet.append(oneCellInfo.index) |
| 885 |
myMaskValuesToSet.append(maskValue) |
| 886 |
myLeafVisitCount.append(oneCellInfo.leafVisitCount) |
| 887 |
|
| 888 |
newstr1 = "cellIndexesToSet = " + str(myCellIndexesToSet) + "\n" |
| 889 |
newstr2 = "maskValuesToSet = " + str(myMaskValuesToSet) + "\n" |
| 890 |
newstr3 = "leafVisitCount = " + str(myLeafVisitCount) + "\n" |
| 891 |
self.mProgFilterString = newstr1 + newstr2 + newstr3 + self.mainScriptString |
| 892 |
|
| 893 |
if PhactoriDbg(100): |
| 894 |
myDebugPrint3("PhactoriMarkCellSetsOperation constructed script:\n" + \ |
| 895 |
self.mProgFilterString) |
| 896 |
|
| 897 |
#phactori_combine_to_single_python_file_subpiece_end_1 |
| 898 |
|