|
| 1 | +from Generator.IBM import buildOctree, generateIBMMesh, createRefinementBodies |
| 2 | + |
| 3 | +from Connector.IBM import prepareIBMData, dist2wallIBM, blankingIBM, buildFrontIBM, setInterpDataIBM, initializeIBM |
| 4 | + |
| 5 | +from Geom.IBM import setSnear, _setSnear, setDfar, _setDfar, snearFactor, _snearFactor, setIBCType, changeIBCType, _changeIBCType, initOutflow, _initOutflow, initInj, _initInj, setFluidInside, setFluidOutside |
| 6 | + |
| 7 | +from Generator.IBMmodelHeight import computeModelisationHeight, computeSnearOpt |
| 8 | + |
| 9 | +from Apps.Fast.WindTunnelOutPres import getInfo, _setUpOutletPressure, getPointsFromTree, setupMachProbe, recordDataMach, _controlOutletPressureMachProbe |
| 10 | + |
| 11 | +import Converter.PyTree as C |
| 12 | +import Converter.Mpi as Cmpi |
| 13 | +import Converter.Internal as Internal |
| 14 | +import Converter.Filter as Filter |
| 15 | +import Generator.PyTree as G |
| 16 | +import Post.PyTree as P |
| 17 | +import Geom.PyTree as D |
| 18 | +import Post.Mpi as Pmpi |
| 19 | +import Transform.PyTree as T |
| 20 | +import Intersector.PyTree as XOR |
| 21 | +import Post.Probe as Probe |
| 22 | +import Distributor2.PyTree as D2 |
| 23 | + |
| 24 | +import numpy |
| 25 | +import math |
| 26 | +import os |
| 27 | + |
| 28 | +# Ajouter l'initialisation de la pression, temperature et masse volumique |
| 29 | +# à l'aide des formulations isentropiques (cf. tau de S Mouton) |
| 30 | + |
| 31 | +############### |
| 32 | +# Point Probes |
| 33 | +############### |
| 34 | + |
| 35 | +def createPointProbes(probe_in, probePointsList): |
| 36 | + listOfZones = [] |
| 37 | + |
| 38 | + for cpt, (x,y,z) in enumerate(probePointsList): |
| 39 | + point = D.point((x,y,z)) |
| 40 | + point[0] = "point_{:03d}".format(cpt) |
| 41 | + listOfZones.append(point) |
| 42 | + |
| 43 | + probe = C.newPyTree(['Base', listOfZones]) |
| 44 | + |
| 45 | + if Cmpi.rank == 0: C.convertPyTree2File(probe, probe_in) |
| 46 | + |
| 47 | + Cmpi.barrier() |
| 48 | + |
| 49 | + return None |
| 50 | + |
| 51 | +def initPointProbes(t, probe_in, fields, bufferSize=100, append=False, historyDirectory='.'): |
| 52 | + if isinstance(probe_in, str): probes = C.convertFile2PyTree(probe_in) |
| 53 | + else: probes = Internal.copyTree(probe_in) |
| 54 | + |
| 55 | + fields = ['centers:'+fname for fname in fields if 'centers' not in fname] #extraction from cell-centered t |
| 56 | + |
| 57 | + dictOfProbes = {} |
| 58 | + for z in Internal.getZones(probes): |
| 59 | + name = z[0] |
| 60 | + xnode = Internal.getNodeFromName(z,'CoordinateX') |
| 61 | + ynode = Internal.getNodeFromName(z,'CoordinateY') |
| 62 | + znode = Internal.getNodeFromName(z,'CoordinateZ') |
| 63 | + point = [Internal.getValue(xnode),Internal.getValue(ynode),Internal.getValue(znode)] |
| 64 | + dictOfProbes[name] = point |
| 65 | + |
| 66 | + if 'centers:Mach' in fields: P._computeVariables(t, ['centers:Mach']) |
| 67 | + if 'centers:Pressure' in fields: P._computeVariables(t, ['centers:Pressure']) |
| 68 | + |
| 69 | + for pname in dictOfProbes.keys(): |
| 70 | + point = dictOfProbes[pname] |
| 71 | + filename = "probe_{:s}.cgns".format(pname) |
| 72 | + filename = os.path.join(historyDirectory, filename) |
| 73 | + |
| 74 | + probe = Probe.Probe(filename, t, X=point, fields=fields, bufferSize=bufferSize, append=append) |
| 75 | + dictOfProbes[pname] = probe |
| 76 | + |
| 77 | + if 'centers:Mach' in fields: C._rmVars(t, ['centers:Mach']) |
| 78 | + if 'centers:Pressure' in fields: C._rmVars(t, ['centers:Pressure']) |
| 79 | + |
| 80 | + Cmpi.barrier() |
| 81 | + |
| 82 | + return dictOfProbes |
| 83 | + |
| 84 | +def _updatePointProbes(t, dictOfProbes, it, fields): |
| 85 | + fields = ['centers:'+fname for fname in fields if 'centers' not in fname] #extraction from cell-centered t |
| 86 | + |
| 87 | + if 'centers:Mach' in fields: P._computeVariables(t, ['centers:Mach']) |
| 88 | + if 'centers:Pressure' in fields: P._computeVariables(t, ['centers:Pressure']) |
| 89 | + |
| 90 | + for name, probe in dictOfProbes.items(): |
| 91 | + probe.extract(t, time=it) |
| 92 | + |
| 93 | + if 'centers:Mach' in fields: C._rmVars(t, ['centers:Mach']) |
| 94 | + if 'centers:Pressure' in fields: C._rmVars(t, ['centers:Pressure']) |
| 95 | + |
| 96 | + Cmpi.barrier() |
| 97 | + |
| 98 | + return None |
| 99 | + |
| 100 | +############### |
| 101 | +# Surface Probes |
| 102 | +############### |
| 103 | + |
| 104 | +def generateIsoXSurface__(tb, x): |
| 105 | + bbox = G.bbox(tb) |
| 106 | + alpha= 0.05 |
| 107 | + DY = bbox[4]-bbox[1]; DZ = bbox[5]-bbox[2] |
| 108 | + YMIN = bbox[1]-alpha*DY ; ZMIN = bbox[2]-alpha*DY |
| 109 | + LY = DY + 2*alpha*DY ; LZ = DZ + 2*alpha*DZ |
| 110 | + NJ = 51; NK = 51 |
| 111 | + a = G.cart((x, YMIN, ZMIN), (1, LY/(NJ-1), LZ/(NK-1)), (1, NJ, NK)) |
| 112 | + a = C.convertArray2Tetra(a) |
| 113 | + zones = Internal.getZones(tb)+[a] |
| 114 | + z = T.join(zones) |
| 115 | + z = XOR.conformUnstr(z, tol=1e-10, itermax=1) |
| 116 | + zones = T.splitManifold(z) |
| 117 | + candidates = [] |
| 118 | + eps = 1e-4 |
| 119 | + for z in zones: |
| 120 | + bboxz = G.bbox(z) |
| 121 | + if abs(bboxz[0]-x)<eps and abs(bboxz[3]-x)<eps: |
| 122 | + if bboxz[1]>=bbox[1]-eps and bboxz[4]<=bbox[4]+eps and bboxz[2]>=bbox[2]-eps and bboxz[5]<=bbox[5]+eps: |
| 123 | + candidates.append(z) |
| 124 | + for i,z in enumerate(candidates): |
| 125 | + z[0] = "zone_{:02d}".format(i) |
| 126 | + candidates = T.join(candidates) |
| 127 | + surface = C.newPyTree(["X_{:5.3f}".format(x), candidates]) |
| 128 | + return surface |
| 129 | + |
| 130 | +def createSurfaceProbes(tb, surface_in, probeSurfaceList): |
| 131 | + surfaces = [] |
| 132 | + |
| 133 | + for x in probeSurfaceList: |
| 134 | + ts = generateIsoXSurface__(tb, x) |
| 135 | + G._getSmoothNormalMap(ts) |
| 136 | + surfaces.append(ts) |
| 137 | + |
| 138 | + ts = Internal.merge(surfaces) |
| 139 | + |
| 140 | + if Cmpi.size > 1: |
| 141 | + for b in Internal.getBases(ts): |
| 142 | + T._splitNParts(b, Cmpi.size) |
| 143 | + D2._distribute(b, Cmpi.size) |
| 144 | + |
| 145 | + if Cmpi.rank == 0: C.convertPyTree2File(ts, surface_in) |
| 146 | + |
| 147 | + Cmpi.barrier() |
| 148 | + |
| 149 | + return None |
| 150 | + |
| 151 | +def initSurfaceProbes(t, tc, surface_in, fields, bufferSize=100, historyDirectory='.'): |
| 152 | + if isinstance(surface_in, str): |
| 153 | + if Cmpi.size > 1: probes = Cmpi.convertFile2PyTree(surface_in, proc=Cmpi.rank) |
| 154 | + else: probes = C.convertFile2PyTree(surface_in) |
| 155 | + else: probes = Internal.copyTree(surface_in) |
| 156 | + |
| 157 | + dictOfProbes = {} |
| 158 | + |
| 159 | + if 'Mach' in fields: P._computeVariables(t, ['centers:Mach']) |
| 160 | + if 'Pressure' in fields: P._computeVariables(t, ['centers:Pressure']) |
| 161 | + |
| 162 | + tcs = Internal.rmNodesFromType(tc, 'ZoneSubRegion_t') |
| 163 | + if Cmpi.size <= 1: Cmpi._setProc(tcs, 0) # Security for Probe functions |
| 164 | + for var in fields+['cellN']: C._cpVars(t, 'centers:'+var, tcs, var) |
| 165 | + |
| 166 | + for b in Internal.getBases(probes): |
| 167 | + sname = b[0] |
| 168 | + tbs_loc = C.newPyTree([sname, Internal.getZones(b)]) |
| 169 | + |
| 170 | + filename = "surface_{:s}.cgns".format(sname) |
| 171 | + filename = os.path.join(historyDirectory, filename) |
| 172 | + |
| 173 | + probe = Probe.Probe(filename, tPermeable=tbs_loc, fields=fields, bufferSize=bufferSize) |
| 174 | + tcs_loc = probe.prepare(tcs) |
| 175 | + |
| 176 | + dictOfProbes[sname] = [probe, tbs_loc, tcs_loc] |
| 177 | + |
| 178 | + Cmpi.barrier() |
| 179 | + |
| 180 | + return dictOfProbes |
| 181 | + |
| 182 | +def _updateSurfaceProbes(t, dictOfProbes, fields): |
| 183 | + if 'Mach' in fields: P._computeVariables(t, ['centers:Mach']) |
| 184 | + if 'Pressure' in fields: P._computeVariables(t, ['centers:Pressure']) |
| 185 | + |
| 186 | + for key in dictOfProbes: |
| 187 | + probe, tbs_loc, tcs_loc = dictOfProbes[key] |
| 188 | + for var in fields: |
| 189 | + C._cpVars(t, 'centers:'+var, tcs_loc, var) |
| 190 | + C._initVars(tbs_loc, var, 1) |
| 191 | + |
| 192 | + probe.extract(tcs_loc, time=1, onlyTransfer=True) |
| 193 | + |
| 194 | + if 'Mach' in fields: C._rmVars(t, ['centers:Mach']) |
| 195 | + if 'Pressure' in fields: C._rmVars(t, ['centers:Pressure']) |
| 196 | + |
| 197 | + Cmpi.barrier() |
| 198 | + |
| 199 | + return None |
| 200 | + |
| 201 | +def getMassflow(t): |
| 202 | + C._initVars(t, '{massflow}={Density}*({sx}*{VelocityX}+{sy}*{VelocityY}+{sz}*{VelocityZ})') |
| 203 | + massflow = abs(Pmpi.integ(t, 'massflow')[0]) |
| 204 | + return massflow |
| 205 | + |
| 206 | +def integrateSurfaceProbes(dictOfProbes): |
| 207 | + massflows = [] |
| 208 | + for key in dictOfProbes: |
| 209 | + probe, tbs_loc, tcs_loc = dictOfProbes[key] |
| 210 | + massflow_loc = getMassflow(tbs_loc) # intégration de la masse volumique sur chaque surface probe |
| 211 | + massflows.append(massflow_loc) |
| 212 | + |
| 213 | + Cmpi.barrier() |
| 214 | + |
| 215 | + return massflows |
0 commit comments