| 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 |
import sys |
| 36 |
from .PhactoriParaviewMultiBlockRecursion import * |
| 37 |
from .PhactoriVectorLibrary import * |
| 38 |
from .PhactoriVtkCellOperations import * |
| 39 |
|
| 40 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 41 |
|
| 42 |
class CellEdgeAngleMetricParameters(): |
| 43 |
def __init__(self): |
| 44 |
self.numPointsPerBlock = None |
| 45 |
self.numCellsPerBlock = None |
| 46 |
self.UseSmallestAngle = True |
| 47 |
self.OffsetIndex = 0 |
| 48 |
self.OutputCellVariableName = None |
| 49 |
|
| 50 |
def Initialize(self, inUseSmallestAngle, inOffsetIndex, inCellVariableName): |
| 51 |
self.numPointsPerBlock = [] |
| 52 |
self.numCellsPerBlock = [] |
| 53 |
self.UseSmallestAngle = inUseSmallestAngle |
| 54 |
self.OffsetIndex = inOffsetIndex |
| 55 |
self.OutputCellVariableName = inCellVariableName |
| 56 |
|
| 57 |
class PhactoriMarkCellSurfaceStatus2(PhactoriOperationSpecifics): |
| 58 |
"""experimental filter to find the lengths of the edges of cells in the mesh""" |
| 59 |
def __init__(self): |
| 60 |
PhactoriOperationSpecifics.__init__(self) |
| 61 |
self.inPvFilter = None |
| 62 |
self.pfcelProgrammableFilter = None |
| 63 |
self.mProgFilterString = None |
| 64 |
self.OutputCellVariableName = "surfacestatus" |
| 65 |
self.UseSmallestAngle = True |
| 66 |
self.OffsetIndex = 0 |
| 67 |
self.DoOperationInCreateParaViewMethod = True |
| 68 |
self.CreateProgrammableFilter = False |
| 69 |
|
| 70 |
def ParseParametersFromJson(self, inJson): |
| 71 |
|
| 72 |
keyval3 = "output nth smallest angle" |
| 73 |
keyval4 = "output nth largest angle" |
| 74 |
if keyval3 in inJson: |
| 75 |
self.UseSmallestAngle = True |
| 76 |
self.OffsetIndex = inJson[keyval3] |
| 77 |
elif keyval4 in inJson: |
| 78 |
self.UseSmallestAngle = False |
| 79 |
self.OffsetIndex = inJson[keyval3] |
| 80 |
else: |
| 81 |
self.UseSmallestAngle = True |
| 82 |
self.OffsetIndex = 0 |
| 83 |
|
| 84 |
keyval10 = "output cell variable name" |
| 85 |
if keyval10 in inJson: |
| 86 |
self.OutputCellVariableName = inJson[keyval10] |
| 87 |
|
| 88 |
keyval11 = "do operation in createparaview method" |
| 89 |
if keyval11 in inJson: |
| 90 |
self.DoOperationInCreateParaViewMethod = inJson[keyval11] |
| 91 |
|
| 92 |
keyval12 = "create programmable filter" |
| 93 |
if keyval12 in inJson: |
| 94 |
self.ProgrammableFilterOutputCellVariableName = inJson[keyval10] |
| 95 |
|
| 96 |
def CreateParaViewFilter(self, inInputFilter): |
| 97 |
"""create the MergeBlocks filter for ParaView""" |
| 98 |
if PhactoriDbg(100): |
| 99 |
myDebugPrint3("PhactoriMarkCellSurfaceStatus2.CreateParaViewFilter " |
| 100 |
"entered\n", 100) |
| 101 |
self.inPvFilter = inInputFilter |
| 102 |
|
| 103 |
savedActiveSource = GetActiveSource() |
| 104 |
|
| 105 |
UpdatePipelineWithCurrentTimeArgument(inInputFilter) |
| 106 |
|
| 107 |
if self.DoOperationInCreateParaViewMethod: |
| 108 |
if PhactoriDbg(100): |
| 109 |
myDebugPrint3("make variable during CreateParaViewFilter\n", 100) |
| 110 |
recursionObj = PhactoriParaviewMultiBlockRecursionControl() |
| 111 |
recursionObj.mParameters = CellEdgeAngleMetricParameters() |
| 112 |
recursionObj.mParameters.Initialize(self.UseSmallestAngle, |
| 113 |
self.OffsetIndex, self.OutputCellVariableName) |
| 114 |
recursionObj.mOperationToDoPerBlock = self.MarkCellStatusInBlock |
| 115 |
PhactoriRecusivelyDoMethodPerBlockFromParaViewFilter(recursionObj, self.inPvFilter) |
| 116 |
|
| 117 |
UpdatePipelineWithCurrentTimeArgument(inInputFilter) |
| 118 |
if PhactoriDbg(100): |
| 119 |
myDebugPrint3("done make variable during CreateParaViewFilter\n", 100) |
| 120 |
|
| 121 |
if self.CreateProgrammableFilter: |
| 122 |
self.pfcelProgrammableFilter = ProgrammableFilter(Input = self.inPvFilter) |
| 123 |
self.pfcelProgrammableFilter.CopyArrays = 1 |
| 124 |
self.CreateProgrammableFilterString() |
| 125 |
self.pfcelProgrammableFilter.Script = self.mProgFilterString |
| 126 |
self.pfcelProgrammableFilter.UpdatePipeline() |
| 127 |
UpdatePipelineWithCurrentTimeArgument(self.pfcelProgrammableFilter) |
| 128 |
if PhactoriDbg(100): |
| 129 |
myDebugPrint3("self.CreateProgrammableFilter true, created programmable filter\n", 100) |
| 130 |
|
| 131 |
SetActiveSource(savedActiveSource) |
| 132 |
|
| 133 |
if self.CreateProgrammableFilter: |
| 134 |
if PhactoriDbg(100): |
| 135 |
myDebugPrint3("PhactoriMarkCellSurfaceStatus2.CreateParaViewFilter " |
| 136 |
"returning programmable filter\n", 100) |
| 137 |
return self.pfcelProgrammableFilter |
| 138 |
else: |
| 139 |
if PhactoriDbg(100): |
| 140 |
myDebugPrint3("PhactoriMarkCellSurfaceStatus2.CreateParaViewFilter " |
| 141 |
"returning passthrough filter\n", 100) |
| 142 |
return self.inPvFilter |
| 143 |
|
| 144 |
@staticmethod |
| 145 |
def MarkCellStatusInBlock(recursionObject, inInputCsData, inParameters): |
| 146 |
if PhactoriDbg(100): |
| 147 |
myDebugPrint3("MarkCellStatusInBlock entered\n") |
| 148 |
|
| 149 |
numCells = inInputCsData.GetNumberOfCells() |
| 150 |
|
| 151 |
celldata = inInputCsData.GetCellData() |
| 152 |
|
| 153 |
newCellArrayName = inParameters.OutputCellVariableName |
| 154 |
|
| 155 |
inParameters.numCellsPerBlock.append(numCells) |
| 156 |
ncda = vtk.vtkIntArray() |
| 157 |
ncda.SetNumberOfTuples(numCells) |
| 158 |
|
| 159 |
if numCells <= 0: |
| 160 |
ncda.SetName(newCellArrayName) |
| 161 |
celldata.AddArray(ncda) |
| 162 |
|
| 163 |
if PhactoriDbg(100): |
| 164 |
myDebugPrint3("numCells 0, MarkCellStatusInBlock returning 2\n") |
| 165 |
|
| 166 |
#see how many cells are touching each point |
| 167 |
cellsTouchingPointCount = PhactoriCountCellTouchingEachPoint(inInputCsData) |
| 168 |
|
| 169 |
#see which cells have how many points with 8 or other cells |
| 170 |
for ii in range(0, numCells): |
| 171 |
#if PhactoriDbg(100): |
| 172 |
# myDebugPrint3("(b) cell index " + str(ii) + " of " + str(numCells) + "\n") |
| 173 |
oneCellSurfaceStatus = PhactoriFindSurfaceStatusForOneCell(inInputCsData, ii, |
| 174 |
cellsTouchingPointCount) |
| 175 |
ncda.SetValue(ii, oneCellSurfaceStatus) |
| 176 |
|
| 177 |
ncda.SetName(newCellArrayName) |
| 178 |
celldata.AddArray(ncda) |
| 179 |
|
| 180 |
if PhactoriDbg(100): |
| 181 |
myDebugPrint3("MarkCellStatusInBlock returning\n") |
| 182 |
|
| 183 |
def CreateProgrammableFilterString(self): |
| 184 |
|
| 185 |
if self.mProgFilterString != None: |
| 186 |
return |
| 187 |
|
| 188 |
scriptLines = [] |
| 189 |
|
| 190 |
scriptLines.append("import math\n") |
| 191 |
GetPhactoriVectorLibraryProgrammableFilterLines(scriptLines) |
| 192 |
GetPhactoriVtkCellOperationsProgrammableFilterLines(scriptLines) |
| 193 |
|
| 194 |
scriptLines.append("localLeafVisitCount = 0\n") |
| 195 |
scriptLines.append("def flatten(input, output):\n") |
| 196 |
scriptLines.append(" # Copy the cells etc.\n") |
| 197 |
scriptLines.append(" output.ShallowCopy(input)\n") |
| 198 |
scriptLines.append(" celldata = output.GetCellData()\n") |
| 199 |
scriptLines.append(" numCells = input.GetNumberOfCells()\n") |
| 200 |
scriptLines.append(" ncda = vtk.vtkIntArray()\n") |
| 201 |
scriptLines.append(" ncda.SetNumberOfTuples(numCells)\n") |
| 202 |
|
| 203 |
#the first three of the next lines use face connections to find |
| 204 |
#interior/surface/edge/corner cells, and the next three use point |
| 205 |
#connections. Point connections create 1/3 the size intermediate data as |
| 206 |
#face connectinos, but face connections should work with wedge cells too |
| 207 |
#scriptLines.append(" cellsTouchingPointCount = PhactoriCountCellTouchingEachPoint(input)\n") |
| 208 |
#scriptLines.append(" for ii in range(0, numCells):\n") |
| 209 |
#scriptLines.append(" oneCellSurfaceStatus = PhactoriFindSurfaceStatusForOneCell(input, ii, cellsTouchingPointCount)\n") |
| 210 |
scriptLines.append(" cellsTouchingEachFace = PhactoriCountCellTouchingEachFace(input)\n") |
| 211 |
scriptLines.append(" for ii in range(0, numCells):\n") |
| 212 |
scriptLines.append(" oneCellSurfaceStatus = PhactoriFindSurfaceStatusForOneCellUsingFaceInfo(input, ii, cellsTouchingEachFace)\n") |
| 213 |
|
| 214 |
scriptLines.append(" ncda.SetValue(ii, oneCellSurfaceStatus)\n") |
| 215 |
scriptLines.append(" ncda.SetName('" + self.OutputCellVariableName + "')\n") |
| 216 |
scriptLines.append(" celldata.AddArray(ncda)\n") |
| 217 |
|
| 218 |
scriptLines.append("input = self.GetInputDataObject(0, 0)\n") |
| 219 |
scriptLines.append("output = self.GetOutputDataObject(0)\n") |
| 220 |
|
| 221 |
scriptLines.append("if input.IsA('vtkMultiBlockDataSet'):\n") |
| 222 |
scriptLines.append(" output.CopyStructure(input)\n") |
| 223 |
scriptLines.append(" iter = input.NewIterator()\n") |
| 224 |
scriptLines.append(" iter.UnRegister(None)\n") |
| 225 |
scriptLines.append(" iter.InitTraversal()\n") |
| 226 |
scriptLines.append(" while not iter.IsDoneWithTraversal():\n") |
| 227 |
scriptLines.append(" localLeafVisitCount += 1\n") |
| 228 |
scriptLines.append(" curInput = iter.GetCurrentDataObject()\n") |
| 229 |
scriptLines.append(" curOutput = curInput.NewInstance()\n") |
| 230 |
scriptLines.append(" curOutput.UnRegister(None)\n") |
| 231 |
scriptLines.append(" output.SetDataSet(iter, curOutput)\n") |
| 232 |
scriptLines.append(" flatten(curInput, curOutput)\n") |
| 233 |
scriptLines.append(" iter.GoToNextItem();\n") |
| 234 |
scriptLines.append("else:\n") |
| 235 |
scriptLines.append(" flatten(input, output)\n") |
| 236 |
|
| 237 |
self.mProgFilterString = "".join(scriptLines) |
| 238 |
|
| 239 |
if PhactoriDbg(100): |
| 240 |
myDebugPrint3("PhactoriMarkCellSurfaceStatus2 constructed script:\n" + \ |
| 241 |
self.mProgFilterString) |
| 242 |
|
| 243 |
#phactori_combine_to_single_python_file_subpiece_end_1 |