| 1 |
# Copyright(C) 1999-2020 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 |
import vtk |
| 34 |
from .PhactoriVectorLibrary import * |
| 35 |
from phactori import myDebugPrint3 |
| 36 |
from phactori import PhactoriDbg |
| 37 |
|
| 38 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 39 |
class QuadInfoGQC: |
| 40 |
def __init__(self): |
| 41 |
self.ptA = [0.0, 0.0, 0.0] |
| 42 |
self.ptB = [0.0, 0.0, 0.0] |
| 43 |
self.ptC = [0.0, 0.0, 0.0] |
| 44 |
self.ptD = [0.0, 0.0, 0.0] |
| 45 |
#using average of points instead of center |
| 46 |
self.ptAverage = [0.0, 0.0, 0.0] |
| 47 |
self.normal = None |
| 48 |
self.cellId = -1 |
| 49 |
self.index = -1 |
| 50 |
|
| 51 |
def PopulateFromVtkData(self, inInputCsData, globalCellIdArray, quadIndex): |
| 52 |
self.index = quadIndex |
| 53 |
cellPointIds = vtk.vtkIdList() |
| 54 |
inInputCsData.GetCellPoints(quadIndex, cellPointIds) |
| 55 |
numids = cellPointIds.GetNumberOfIds() |
| 56 |
if numids != 4: |
| 57 |
myDebugPrint3AndException("GetQuadClosestToPointsInBlock2Params: not a quad") |
| 58 |
inInputCsData.GetPoint(cellPointIds.GetId(0), self.ptA) |
| 59 |
inInputCsData.GetPoint(cellPointIds.GetId(1), self.ptB) |
| 60 |
inInputCsData.GetPoint(cellPointIds.GetId(2), self.ptC) |
| 61 |
inInputCsData.GetPoint(cellPointIds.GetId(3), self.ptD) |
| 62 |
self.ptAverage[0] = (self.ptA[0] + self.ptB[0] + self.ptC[0] + self.ptD[0]) * 0.25 |
| 63 |
self.ptAverage[1] = (self.ptA[1] + self.ptB[1] + self.ptC[1] + self.ptD[1]) * 0.25 |
| 64 |
self.ptAverage[2] = (self.ptA[2] + self.ptB[2] + self.ptC[2] + self.ptD[2]) * 0.25 |
| 65 |
if globalCellIdArray != None: |
| 66 |
self.cellId = globalCellIdArray.GetValue(quadIndex) |
| 67 |
|
| 68 |
def PopulateFromInfoArrays(self, index, doubleArray, integerArray): |
| 69 |
"""given arrays which were populated with the help of AddToInfoArrays(), |
| 70 |
set up this quad to match the one represented in the arrays at the |
| 71 |
given index""" |
| 72 |
ptIndx = index*15 |
| 73 |
idIndx = index |
| 74 |
self.ptA[0] = doubleArray[ptIndx] |
| 75 |
self.ptA[1] = doubleArray[ptIndx+1] |
| 76 |
self.ptA[2] = doubleArray[ptIndx+2] |
| 77 |
self.ptB[0] = doubleArray[ptIndx+3] |
| 78 |
self.ptB[1] = doubleArray[ptIndx+4] |
| 79 |
self.ptB[2] = doubleArray[ptIndx+5] |
| 80 |
self.ptC[0] = doubleArray[ptIndx+6] |
| 81 |
self.ptC[1] = doubleArray[ptIndx+7] |
| 82 |
self.ptC[2] = doubleArray[ptIndx+8] |
| 83 |
self.ptD[0] = doubleArray[ptIndx+9] |
| 84 |
self.ptD[1] = doubleArray[ptIndx+10] |
| 85 |
self.ptD[2] = doubleArray[ptIndx+11] |
| 86 |
self.ptAverage[0] = doubleArray[ptIndx+12] |
| 87 |
self.ptAverage[1] = doubleArray[ptIndx+13] |
| 88 |
self.ptAverage[2] = doubleArray[ptIndx+14] |
| 89 |
self.cellId = integerArray.append(self.cellId) |
| 90 |
|
| 91 |
def AddToInfoArrays(self, outDoubleArray, outIntegerArray): |
| 92 |
"""add the quad points, point average, and cellId to the argument arrays |
| 93 |
for purspose of doing mpi broadcast/reduce work""" |
| 94 |
outDoubleArray.append(self.ptA[0]) |
| 95 |
outDoubleArray.append(self.ptA[1]) |
| 96 |
outDoubleArray.append(self.ptA[2]) |
| 97 |
outDoubleArray.append(self.ptB[0]) |
| 98 |
outDoubleArray.append(self.ptB[1]) |
| 99 |
outDoubleArray.append(self.ptB[2]) |
| 100 |
outDoubleArray.append(self.ptC[0]) |
| 101 |
outDoubleArray.append(self.ptC[1]) |
| 102 |
outDoubleArray.append(self.ptC[2]) |
| 103 |
outDoubleArray.append(self.ptD[0]) |
| 104 |
outDoubleArray.append(self.ptD[1]) |
| 105 |
outDoubleArray.append(self.ptD[2]) |
| 106 |
outDoubleArray.append(self.ptAverage[0]) |
| 107 |
outDoubleArray.append(self.ptAverage[1]) |
| 108 |
outDoubleArray.append(self.ptAverage[2]) |
| 109 |
outIntegerArray.append(self.cellId) |
| 110 |
|
| 111 |
def AddZeroQuadToInfoArrays(self, outDoubleArray, outIntegerArray): |
| 112 |
"""add zeros to the argument arrays representing a blank quad |
| 113 |
for purspose of doing mpi broadcast/reduce work""" |
| 114 |
for ii in range(0, 15): |
| 115 |
outDoubleArray.append(0.0) |
| 116 |
outIntegerArray.append(int(0)) |
| 117 |
|
| 118 |
def CalculateDistanceSquaredTo(self, onePt): |
| 119 |
return vecDistanceSquared(onePt, self.ptAverage) |
| 120 |
|
| 121 |
def ToString(self): |
| 122 |
retStr = str(self.index) + " " + str(self.cellId) + "\n" + \ |
| 123 |
str(self.ptA) + "\n" + \ |
| 124 |
str(self.ptB) + "\n" + \ |
| 125 |
str(self.ptC) + "\n" + \ |
| 126 |
str(self.ptD) + "\n" + \ |
| 127 |
str(self.ptAverage) + "\n" |
| 128 |
return retStr |
| 129 |
|
| 130 |
def CalculateNormal(self): |
| 131 |
vec1 = vecFromAToB(self.ptA, self.ptC) |
| 132 |
vec2 = vecFromAToB(self.ptB, self.ptD) |
| 133 |
vecCrs = vecCrossProduct(vec1, vec2) |
| 134 |
self.normal = vecNormalize(vecCrs) |
| 135 |
|
| 136 |
def MakeLogSamplePointsAlongRayStartingAtAveragePoint(self, rayDirection, startStep, multiplier, maxDistance): |
| 137 |
smplList = [] |
| 138 |
newPt = vecMultiplyAdd(self.ptAverage, rayDirection, 0.0) |
| 139 |
smplList.append(newPt) |
| 140 |
thisDistance = startStep |
| 141 |
count = 1 |
| 142 |
while thisDistance < maxDistance: |
| 143 |
newPt = vecMultiplyAdd(self.ptAverage, rayDirection, thisDistance) |
| 144 |
smplList.append(newPt) |
| 145 |
thisDistance *= multiplier |
| 146 |
count += 1 |
| 147 |
if count > 200: |
| 148 |
break |
| 149 |
if PhactoriDbg(100): |
| 150 |
myDebugPrint3("MakeLogSamplePointsAlongRayStartingAtAveragePoint:\n" + \ |
| 151 |
str(len(smplList)) + " " + \ |
| 152 |
str(thisDistance) + " " + \ |
| 153 |
str(count) + \ |
| 154 |
"\n" + str(smplList[0]) + \ |
| 155 |
"\n" + str(smplList[-1]) + \ |
| 156 |
"\n", 100) |
| 157 |
return smplList |
| 158 |
|
| 159 |
def MakeSamplePointsAlongRayStartingAtAveragePoint(self, rayDirection, numSamples, maxDistance): |
| 160 |
smplList = [] |
| 161 |
#for ii in range(-50,51): |
| 162 |
sampleStep = maxDistance / (float(numSamples - 1)) |
| 163 |
for ii in range(0, numSamples): |
| 164 |
rr = float(ii) * sampleStep |
| 165 |
newPt = vecMultiplyAdd(self.ptAverage, rayDirection, rr) |
| 166 |
smplList.append(newPt) |
| 167 |
return smplList |
| 168 |
|
| 169 |
def MakeSamplePointsAlongRayFromNearbyPoint(self, rayDefiningPoint): |
| 170 |
"""create a vector from rayDefiningPoint to the average point of this ray, |
| 171 |
VV. Create sample points along a ray starting at the average point of |
| 172 |
the quad (self.ptAverage) along the vector VV""" |
| 173 |
vecVUN = vecFromAToB(rayDefiningPoint, self.ptAverage) |
| 174 |
vecVV= vecNormalize(vecVUN) |
| 175 |
return self.MakeSamplePointsAlongRayStartingAtAveragePoint(vecVV, 50, 0.05) |
| 176 |
|
| 177 |
def MakeLogSamplePointsAlongRayFromNearbyPoint(self, rayDefiningPoint, startStep, multiplier, maxDistance): |
| 178 |
"""create a vector from rayDefiningPoint to the average point of this ray, |
| 179 |
VV. Create sample points along a ray starting at the average point of |
| 180 |
the quad (self.ptAverage) along the vector VV. Space the sample points |
| 181 |
in a logarithmic manner controlled by startStep, multiplier, and |
| 182 |
maxDistance""" |
| 183 |
vecVUN = vecFromAToB(rayDefiningPoint, self.ptAverage) |
| 184 |
vecVV= vecNormalize(vecVUN) |
| 185 |
return self.MakeLogSamplePointsAlongRayStartingAtAveragePoint(vecVV, startStep, multiplier, maxDistance) |
| 186 |
|
| 187 |
def MakePerpendicularSamplePoints(self): |
| 188 |
"""create a list of sample points based on the average quad point (later |
| 189 |
the center) and thr normal to the quad""" |
| 190 |
self.CalculateNormal() |
| 191 |
return self.MakeSamplePointsAlongRayStartingAtAveragePoint(self.normal, 50, 0.05) |
| 192 |
|
| 193 |
#phactori_combine_to_single_python_file_subpiece_end_1 |
| 194 |
|