| 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 |
import vtk |
| 42 |
import json |
| 43 |
|
| 44 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 45 |
class PhactoriStructuredGridSampler(PhactoriOperationSpecifics): |
| 46 |
"""given a multiblock dataset which has leaves that ar structured grids, |
| 47 |
take specified i/j/k sample ranges from specified blocks. Optionally |
| 48 |
make mask variable for sampled cells with programmable filter""" |
| 49 |
def __init__(self): |
| 50 |
self.myCopyOfInputFilter = None |
| 51 |
self.SampleControlSet = None |
| 52 |
|
| 53 |
def ValidateSampleList1(self, sampleList): |
| 54 |
if len(sampleList) < 1: |
| 55 |
myDebugPrint3AndException( |
| 56 |
"PhactoriStructuredGridSampler:ValidateSampleList1\n" \ |
| 57 |
"list of samples must have at least one entry\n") |
| 58 |
|
| 59 |
for oneSample in sampleList: |
| 60 |
sampleBlockName = oneSample[0] |
| 61 |
sampleBlockType = oneSample[1] |
| 62 |
validType = False |
| 63 |
if sampleBlockType == "imax": |
| 64 |
validType = True |
| 65 |
if sampleBlockType == "imin": |
| 66 |
validType = True |
| 67 |
if sampleBlockType == "jmax": |
| 68 |
validType = True |
| 69 |
if sampleBlockType == "jmin": |
| 70 |
validType = True |
| 71 |
if sampleBlockType == "kmax": |
| 72 |
validType = True |
| 73 |
if sampleBlockType == "kmin": |
| 74 |
validType = True |
| 75 |
if validType != True: |
| 76 |
myDebugPrint3AndException( |
| 77 |
"PhactoriStructuredGridSampler:ValidateSampleList1\n" \ |
| 78 |
"invalid sample type: " + str(sampleBlockType) + "\n" \ |
| 79 |
"must be 'imin' 'imax' 'jmin' 'jmax' 'kmin' or 'kmax'\n") |
| 80 |
|
| 81 |
def ParseParametersFromJson(self, inJson): |
| 82 |
keyval1 = "samples to be taken from all blocks" |
| 83 |
if keyval1 in inJson: |
| 84 |
sampleControlList = inJson[keyval1] |
| 85 |
self.ValidateSampleList1(sampleControlList) |
| 86 |
self.SampleControlSet = {} |
| 87 |
for oneSampleControl in sampleControlList: |
| 88 |
self.SampleControlSet[oneSampleControl[0]] = oneSampleControl[1] |
| 89 |
|
| 90 |
@staticmethod |
| 91 |
def GatherStructuredSampledCellsInBlock(recursionObject, inInputCsData, inParameters): |
| 92 |
if PhactoriDbg(100): |
| 93 |
myDebugPrint3("GatherStructuredSampledCellsInBlock entered\n") |
| 94 |
|
| 95 |
numCells = inInputCsData.GetNumberOfCells() |
| 96 |
numPoints = inInputCsData.GetNumberOfPoints() |
| 97 |
inParameters.leafVisitCount += 1 |
| 98 |
if (numCells == 0) or (numPoints == 0): |
| 99 |
#no cells here |
| 100 |
return |
| 101 |
|
| 102 |
if PhactoriDbg(100): |
| 103 |
myDebugPrint3("GatherStructuredSampledCellsInBlock returning\n") |
| 104 |
|
| 105 |
def GatherStructuredSampledCellsOnThisProcess(self): |
| 106 |
if PhactoriDbg(100): |
| 107 |
myDebugPrint3("GatherStructuredCellsFromSeedCells entered\n") |
| 108 |
|
| 109 |
recursionParams = GatherStructuredSampledCellsOnThisProcessRecursionParams() |
| 110 |
recursionParams.SetUpForRecursion(self) |
| 111 |
recursionObj = PhactoriParaviewMultiBlockRecursionControl() |
| 112 |
recursionObj.mParameters = recursionParams |
| 113 |
recursionObj.mOperationToDoPerBlock = self.GatherStructuredSampledCellsInBlock |
| 114 |
PhactoriRecusivelyDoMethodPerBlockFromParaViewFilter(recursionObj, self.myCopyOfInputFilter) |
| 115 |
|
| 116 |
if PhactoriDbg(100): |
| 117 |
myDebugPrint3("GatherStructuredCellsFromSeedCells returning\n") |
| 118 |
return recursionParams.CellsPerSeedCell |
| 119 |
|
| 120 |
cellData = inInputCsData.GetCellData() |
| 121 |
outputCellArray = None |
| 122 |
#if cellData != None: |
| 123 |
# outputCellArray = cellData.GetArray(inParameters.dataArrayName) |
| 124 |
|
| 125 |
if outputCellArray != None: |
| 126 |
dataArrayNumCmpnts = outputCellArray.GetNumberOfComponents() |
| 127 |
defaultTuple = [] |
| 128 |
for ii in range(0, dataArrayNumCmpnts): |
| 129 |
defaultTuple.append(-1.0) |
| 130 |
else: |
| 131 |
dataArrayNumCmpnts = -1 |
| 132 |
defaultTuple = [] |
| 133 |
|
| 134 |
|
| 135 |
def CreateParaViewFilter(self, inInputFilter): |
| 136 |
if PhactoriDbg(100): |
| 137 |
myDebugPrint3("PhactoriStructuredGridSampler.CreateParaViewFilter entered\n", 100) |
| 138 |
|
| 139 |
savedActiveSource = GetActiveSource() |
| 140 |
|
| 141 |
##segmentListJson = ReadAndMpiBroadcastJsonFile(self.JsonListFileName) |
| 142 |
|
| 143 |
self.myCopyOfInputFilter = inInputFilter |
| 144 |
|
| 145 |
UpdatePipelineWithCurrentTimeArgument(self.myCopyOfInputFilter) |
| 146 |
|
| 147 |
#need to figure global extents |
| 148 |
self.GatherStructuredSampledCellsOnThisProcess() |
| 149 |
|
| 150 |
if PhactoriDbg(100): |
| 151 |
myDebugPrint3("PhactoriStructuredGridSampler.CreateParaViewFilter returning\n", 100) |
| 152 |
|
| 153 |
#phactori_combine_to_single_python_file_subpiece_end_1 |