| 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 paraview.simple import * |
| 35 |
|
| 36 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 37 |
global gDuplicateNameCounter |
| 38 |
gDuplicateNameCounter = {} |
| 39 |
|
| 40 |
class PhactoriExtractBlockOperation(PhactoriOperationSpecifics): |
| 41 |
"""Extract Block operation, phactori interface adapter to the catalyst filter |
| 42 |
For detailed information on the ExtractBlock() filter from ParaView, see the |
| 43 |
ParaView Documentation. The basic operation of this filter is to take a list |
| 44 |
of block names and create a new mesh which includes only the blocks in the |
| 45 |
which have the names in the given list (and their children). Alternatively |
| 46 |
the list can contain blocks to be excluded instead of included. The current |
| 47 |
ParaView (5.8) implementation of this filter takes a list of block indices |
| 48 |
which can become inaccurate if the mesh structure is unexpected, so this |
| 49 |
Phactori adapter uses the block names to create the block index list at |
| 50 |
run time rather than at script creation time. |
| 51 |
|
| 52 |
To add a PhactoriExtractBlock to the incoming script, you add |
| 53 |
a sub-block to the "operation blocks" section of the data with the "type" |
| 54 |
key given a value of "extractblock". You also supply a list of block names |
| 55 |
with a key of either "include blocks" or "exclude blocks". One complete but |
| 56 |
simple example script: |
| 57 |
|
| 58 |
:: |
| 59 |
|
| 60 |
{ |
| 61 |
"camera blocks":{"mycam1":{"type":"camera", "look direction":[1.0, 2.0, 3.0]}}, |
| 62 |
"representation blocks":{"rep_tmprtr":{"color by scalar":"temperature"}}, |
| 63 |
"imageset blocks":{ |
| 64 |
"temperature_on_slice_1":{ |
| 65 |
"operation":"myincludeblocks1", |
| 66 |
"camera":"mycam1", |
| 67 |
"representation":"rep_tmprtr", |
| 68 |
"image basedirectory":"CatalystOutput", |
| 69 |
"image basename":"myincludeblocks1_temperature." |
| 70 |
} |
| 71 |
}, |
| 72 |
"operation blocks":{ |
| 73 |
"myincludeblocks1":{ |
| 74 |
"type":"extractblock", |
| 75 |
"include blocks":["blk-2", "blk-3", "blk-7"] |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
As mentioned previously, you can specify "exclude blocks" instead of |
| 81 |
"include blocks", but you may not specify both. |
| 82 |
|
| 83 |
""" |
| 84 |
|
| 85 |
def __init__(self): |
| 86 |
PhactoriOperationSpecifics.__init__(self) |
| 87 |
#mIncludeblockList OR mExcludeBlockList will be filled in from parsing |
| 88 |
self.mIncludeBlockList = None |
| 89 |
self.mExpandedIncludeBlockList = None |
| 90 |
self.mExcludeBlockList = None |
| 91 |
self.mRemoveBlanksAndDashes = True |
| 92 |
|
| 93 |
def ParseParametersFromJson(self, inJson): |
| 94 |
|
| 95 |
if 'include blocks' in inJson: |
| 96 |
self.mIncludeBlockList = inJson['include blocks'] |
| 97 |
|
| 98 |
if 'exclude blocks' in inJson: |
| 99 |
self.mExcludeBlockList = inJson['exclude blocks'] |
| 100 |
|
| 101 |
if self.mIncludeBlockList == None and self.mExcludeBlockList == None: |
| 102 |
myDebugPrint3AndException( |
| 103 |
"PhactoriExtractBlockOperation::ParseParametersFromJson\n" |
| 104 |
"Error: must have 'include block list' or 'exclude block list'\n") |
| 105 |
|
| 106 |
#2022Aug09 only include blocks is working |
| 107 |
if self.mIncludeBlockList == None: |
| 108 |
myDebugPrint3AndException( |
| 109 |
"PhactoriExtractBlockOperation::ParseParametersFromJson\n" |
| 110 |
"Error: must have 'include block list'\n" |
| 111 |
"currently (2022Aug09) exclude blocks is not working\n") |
| 112 |
|
| 113 |
def MakeExpandedIncludeBlockList(self): |
| 114 |
if self.mExpandedIncludeBlockList == None: |
| 115 |
self.mExpandedIncludeBlockList = list(self.mIncludeBlockList) |
| 116 |
for oneItem in self.mIncludeBlockList: |
| 117 |
#add leader, remove spaces and dashes, this might change |
| 118 |
if self.mRemoveBlanksAndDashes: |
| 119 |
baseItem = oneItem.replace(" ","") |
| 120 |
baseItem = baseItem.replace("-","") |
| 121 |
else: |
| 122 |
baseItem = oneItem |
| 123 |
extraItem = "/Root/ElementBlocks/" + baseItem |
| 124 |
self.mExpandedIncludeBlockList.append(extraItem) |
| 125 |
extraItem = "/Root/Bases/Base/Zones/" + baseItem |
| 126 |
self.mExpandedIncludeBlockList.append(extraItem) |
| 127 |
if PhactoriDbg(100): |
| 128 |
myDebugPrint3("self.mExpandedIncludeBlockList:\n" + \ |
| 129 |
str(self.mExpandedIncludeBlockList) + "\n") |
| 130 |
|
| 131 |
def CreateParaViewFilter(self, inInputFilter): |
| 132 |
"""create the extract block filter for ParaView""" |
| 133 |
if PhactoriDbg(100): |
| 134 |
myDebugPrint3("PhactoriExtractBlockOperation.CreateParaViewFilter " |
| 135 |
"entered\n", 100) |
| 136 |
#info in block class should already be parsed and checked |
| 137 |
|
| 138 |
savedActiveSource = GetActiveSource() |
| 139 |
|
| 140 |
UpdatePipelineWithCurrentTimeArgument(inInputFilter) |
| 141 |
|
| 142 |
if PhactoriDbg(): |
| 143 |
myDebugPrint3(" extractblock inInputFilter point data arrays:\n") |
| 144 |
numArrays = inInputFilter.PointData.GetNumberOfArrays() |
| 145 |
for ii in range (0, numArrays): |
| 146 |
myDebugPrint3(" " + str(ii) + ": " + inInputFilter.PointData.GetArray(ii).GetName() + "\n") |
| 147 |
|
| 148 |
if PhactoriDbg(): |
| 149 |
myDebugPrint3(" extractblock inInputFilter cell data arrays:\n") |
| 150 |
numArrays = inInputFilter.CellData.GetNumberOfArrays() |
| 151 |
for ii in range (0, numArrays): |
| 152 |
myDebugPrint3(" " + str(ii) + ": " + inInputFilter.CellData.GetArray(ii).GetName() + "\n") |
| 153 |
|
| 154 |
newParaViewFilter = ExtractBlock(inInputFilter) |
| 155 |
self.MakeExpandedIncludeBlockList() |
| 156 |
newParaViewFilter.Selectors = self.mExpandedIncludeBlockList |
| 157 |
|
| 158 |
SetActiveSource(newParaViewFilter) |
| 159 |
|
| 160 |
UpdatePipelineWithCurrentTimeArgument(newParaViewFilter) |
| 161 |
if PhactoriDbg(): |
| 162 |
myDebugPrint3(" extractblock newParaViewFilter point data arrays:\n") |
| 163 |
numArrays = newParaViewFilter.PointData.GetNumberOfArrays() |
| 164 |
for ii in range (0, numArrays): |
| 165 |
myDebugPrint3(" " + str(ii) + ": " + newParaViewFilter.PointData.GetArray(ii).GetName() + "\n") |
| 166 |
|
| 167 |
if PhactoriDbg(): |
| 168 |
myDebugPrint3(" extractblock newParaViewFilter cell data arrays:\n") |
| 169 |
numArrays = newParaViewFilter.CellData.GetNumberOfArrays() |
| 170 |
for ii in range (0, numArrays): |
| 171 |
myDebugPrint3(" " + str(ii) + ": " + newParaViewFilter.CellData.GetArray(ii).GetName() + "\n") |
| 172 |
|
| 173 |
SetActiveSource(savedActiveSource) |
| 174 |
|
| 175 |
if PhactoriDbg(100): |
| 176 |
myDebugPrint3("PhactoriExtractBlockOperation.CreateParaViewFilter " |
| 177 |
"returning\n", 100) |
| 178 |
|
| 179 |
return newParaViewFilter |
| 180 |
#phactori_combine_to_single_python_file_subpiece_end_1 |