def C8(): a = Geom.polyline([(1,0,0), (0,1,0), (0,3,0), (0.5,3.5,0), (0,4,0), (0,5,0), (1,6,0), (5,6,0), (6,5,0), (6,4,0), (5.5,3.5,0), (6,3,0), (6,1,0), (5,0,0), (1,0,0) ]) b = Geom.polyline([(1.6,1.2,0), (1.6,2.6,0), (4.5,2.6,0), (4.5,1.2,0), (1.6,1.2,0) ]) c = Geom.polyline([(1.6,4.,0), (1.6,4.9,0), (4.5,4.9,0), (4.5,4.,0), (1.6,4.,0) ]) return [a, b, c], 6
def mapCurvature(a, N, factor=1., sharpAngle=30.): L = D.getLength(a) h = L / (N - 1) ang = D.getSharpestAngle(a) radius = D.getCurvatureRadius(a) # split at local max of radius + angles alpha = ang[1][0] rad = radius[1][0] npts = alpha.size out = [] radiusp = 0. split = [0] for i in range(npts): alpha0 = abs(alpha[i] - 180.) radius0 = rad[i] if alpha0 > 30.: split.append(i) split.append(npts - 1) nsplit = len(split) for x in range(nsplit): isp = split[x] alp = abs(alpha[isp] - 180.) / 180. alp = max(1. - alp, 0.1) # set in split setH(a, split[x], h * alp) # set middle if x < nsplit - 1: setH(a, 0.5 * (split[x] + split[x + 1]), h) out = enforceh(a, N) return out
def moyenne(a, hl): L = D.getLength(a) npts = hl.size h1 = -1 h2 = -1 i1 = -1 i2 = -1 href = 0. for i in range(npts): hi = hl[i] if hi == 0. and i == npts - 1: hi = h1 if hi > 1.e-12: if i == 0: i1 = 0 h1 = hi if i > 0: if i1 == -1: i1 = 0 i2 = i h1 = hi h2 = hi if h1 > 0: i2 = i h2 = hi sub = T.subzone(a, (i1 + 1, 1, 1), (i2 + 1, 1, 1)) Li = D.getLength(sub) href += (h1 + h2) * 0.5 * Li # loop i1 = i2 h1 = h2 href = href / L return href
def enforce(a, h, ind, supp, add): c = D.getDistribution(a) L = D.getLength(a) if ind == 0: b = G.enforceMoinsX(b, h / L, supp, add) elif ind == a[2] - 1: b = G.enforcePlusX(b, h / L, supp, add) else: b = G.enforceX(b, c[1][0, ind], h / L, supp, add) a = G.map(a, b) return a
def meshQuad(P1, P2, P3, P4, distrib1, distrib2): l1 = D.line(P1,P4) l2 = D.line(P2,P3) l1 = G.map(l1, distrib2) l2 = G.map(l2, distrib2) l3 = D.line(P1,P2) l4 = D.line(P4,P3) l3 = G.map(l3, distrib1) l4 = G.map(l4, distrib1) m = G.TFI([l1,l2,l3,l4]) return m
def D(): a = Geom.polyline([(0.,0.,0.), (0.,6.,0.), (5.,6.,0.), (6.,5.,0.), (6.,1.,0.), (5.,0.,0.), (0.,0.,0.)]) b = Geom.polyline([(2.,5.,0.), (4.,5.,0.), (4.,1,0.), (2.,1,0.), (2.,5.,0.)]) return [a,b], 6
def uniformize__(a, N, h, factor, density, sharpAngle): if len(a) == 4: ntype = 1 else: ntype = 0 L = D.getLength(a) if density > 0: N = int(L * density) + 1 elif factor > 0: N = int(factor * (C.getNPts(a) - 1)) + 1 elif h > 0: N = int(L / (N - 1)) N = max(N, 2) # I can add splitConnexity if needed b = T.splitSharpEdges(a, alphaRef=sharpAngle) # b is BAR closed if ntype == 1: b = T.splitTBranches(b) out = [] Nt = 0 nt = len(b) ct = 0 rest = 0 for i in b: ct += 1 Li = D.getLength(i) Ni = int(round(N * 1. * (Li / L))) + 1 if Ni - 1 - N * 1. * (Li / L) < 0: if rest == -1: rest = 0 Ni += 1 elif rest == 0: rest = -1 elif rest == +1: rest = 0 elif Ni - 1 - N * 1. * (Li / L) > 0: if rest == +1: rest = 0 Ni -= 1 elif rest == 0: rest = +1 elif rest == -1: rest = 0 Ni = max(Ni, 2) Nt += Ni - 1 if ct == nt: Ni = Ni - Nt + N - 1 Ni = max(Ni, 2) i = C.convertBAR2Struct(i) distrib = G.cart((0, 0, 0), (1. / (Ni - 1.), 1., 1.), (Ni, 1, 1)) c = G.map(i, distrib) # c is STRUCT out.append(c) if ntype == 1: out = C.convertArray2Hexa(out) if len(out) > 1: b = T.join(out) else: b = out[0] if ntype == 1: b = G.close(b) # because of closed BARs return b
def EQUAL(): a = Geom.polyline([(0.2,2.,0), (0.2,3.4,0), (5.8,3.4,0), (5.8,2.,0), (0.2,2.,0) ]) b = Geom.polyline([(0.2,0.,0), (0.2,1.4,0), (5.8,1.4,0), (5.8,0.,0), (0.2,0.,0) ]) return [a, b], 6
def refine__(a, N, factor, sharpAngle): if len(a) == 4: ntype = 1 else: ntype = 0 NPts = C.getNPts(a) L = D.getLength(a) N = max(N, 2) b = T.splitSharpEdges(a, alphaRef=sharpAngle) if ntype == 1: b = T.splitTBranches(b) out = [] Nt = 0 nt = len(b) ct = 0 rest = 0 for i in b: ct += 1 i = C.convertBAR2Struct(i) Li = D.getLength(i) if factor < 0.: Ni = int(round(N * (C.getNPts(i) - 1) / (NPts - 1)) + 1) if Ni - 1 - N * 1. * (Li / L) < 0: if rest == -1: rest = 0 Ni += 1 elif rest == 0: rest = -1 elif rest == +1: rest = 0 elif Ni - 1 - N * 1. * (Li / L) > 0: if rest == +1: rest = 0 Ni -= 1 elif rest == 0: rest = +1 elif rest == -1: rest = 0 Ni = max(Ni, 2) Nt += Ni - 1 if ct == nt: Ni = Ni - Nt + N - 1 factori = (Ni - 1.) / (C.getNPts(i) - 1.) else: factori = factor out.append(G.refine(i, factori)) if ntype == 0: b = T.join(out) else: out = C.convertArray2Hexa(out) b = T.join(out) b = G.close(b) return b
def __init__(self, method, reduced_temp, max_displacement, cutoff, num_particles = None, file_name = None, tune_displacement = True, reduced_den = None): """ Initialize a MC simulation object Parameters ---------- method : string, either 'random' or 'file' Method to initialize system. random: Randomly create initial configuration. file: Initialize system by reading from a file. reduced_temp : float Reduced temperature at which the simulation will run. max_displacement : float Maximum trial move displacement in each dimension. cutoff : float Cutoff distance for energy calculation. tune_displacement : Boolean, default to True Whether to tune maximum displacement in trial move based on previous acceptance probability. num_particles : int, required if method is 'random' Number of particles in the system. reduced_den : float, required if method is 'random' Reduced density of the system. file_name : string, required if method is 'file' Name of file from which initial configuration will be read and generated. Returns ------- None """ self.beta = 1./float(reduced_temp) self._n_trials = 0 self._n_accept = 0 self.max_displacement = max_displacement self.tune_displacement = tune_displacement self._energy_array = np.array([]) self.current_step = 0 if method == 'random': self._Geom = Geom(method, num_particles = num_particles, reduced_den = reduced_den) elif method == 'file': self._Geom = Geom(method, file_name = file_name) else: raise ValueError("Method must be either 'file' or 'random'") if reduced_den < 0.0 or reduced_temp < 0.0: raise ValueError("reduced temperature and density must be greater than zero.") self._Energy = Energy(self._Geom, cutoff)
def A(): a = Geom.polyline([(0.,0.,0.), (1.5,6.,0.), (4.5,6.,0.), (6.,0.,0.), (4.,0.,0.), (3.5,2.,0.), (2.5,2.,0.), (2.,0.,0.), (0.,0.,0.)]) b = Geom.polyline([(3.5,3.,0.), (2.5,3.,0.), (3.,5.,0.), (3.5,3.,0.)]) return [a,b], 6
def naca(e, N=101, sharpte=True): """Create a naca profile of N points. Usage: naca(e, N)""" a = Geom.naca(e, N, sharpte) zname = 'naca' if isinstance(e, str): zname = 'NACA' + e return C.convertArrays2ZoneNode(zname, [a])
def I(): a = Geom.polyline([(0.,0.,0.), (0.,6.,0.), (2.,6.,0.), (2.,0,0.), (0.,0,0.)]) return [a], 2
def C0(): a = Geom.polyline([(1.,0.,0.), (0,1,0), (0.,5.,0.), (1,6,0), (5.,6.,0.), (6.,5.,0.), (6.,1.,0.), (5.,0.,0.), (1.,0.,0.)]) b = Geom.polyline([(2.,5.,0.), (4.,5.,0.), (4.,1,0.), (2.,1,0.), (2.,5.,0.)]) return [a,b], 6
def P(): a = Geom.polyline([(0.,0.,0.), (0.,6.,0.), (5.,6.,0.), (6.,5.5,0.), (6.,3.5,0.), (5.,2.5,0.), (2.,2.5,0.), (2,0,0), (0.,0.,0.)]) b = Geom.polyline([(2.,5.,0.), (4.,5.,0.), (4.,4,0.), (2.,4,0.), (2.,5.,0.)]) return [a,b], 6
def MINUS(): a = Geom.polyline([(0.2,1.8,0), (0.2,3.2,0), (5.8,3.2,0), (5.8,1.8,0), (0.2,1.8,0) ]) return [a], 6
def enforceh_(a, N, h): if len(a) == 4: ntype = 1 else: ntype = 0 L = D.getLength(a) if ntype == 1: a = T.splitTBranches(a) a = C.convertBAR2Struct(a) out = [] for i in a: Li = D.getLength(i) Ni = Li / L * N out.append(enforceh__(i, Ni, h)) out = C.convertArray2Hexa(out) out = T.join(out) else: out = enforceh__(a, N, h) return out
def sphereYinYang(center, R, N=100): """Create a sphere of center C and radius R made of two overlapping zones. Usage: sphereYinYang((xc,yc,zc), R, N)""" A = Geom.sphereYinYang(center, R, N) return [ C.convertArrays2ZoneNode('sphere-part1', [A[0]]), C.convertArrays2ZoneNode('sphere-part2', [A[1]]) ]
def generateExtExt(curve, density, extension, delta): l = D.getLength(curve) ni = int(l * density) + 1 hm = l / (ni - 1) ext = extension vars = curve[0] curve[0] = 'x,y,z' # extension lineaire x1 = curve[1][0, 0] y1 = curve[1][1, 0] z1 = curve[1][2, 0] x2 = curve[1][0, 1] y2 = curve[1][1, 1] z2 = curve[1][2, 1] norm = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)) px1 = x1 - ext * (x2 - x1) * hm / norm py1 = y1 - ext * (y2 - y1) * hm / norm pz1 = z1 - ext * (z2 - z1) * hm / norm line = D.line((x1, y1, z1), (px1, py1, pz1), ext) curve2 = T.join(line, curve) n = curve[1].shape[1] x1 = curve[1][0, n - 2] y1 = curve[1][1, n - 2] z1 = curve[1][2, n - 2] x2 = curve[1][0, n - 1] y2 = curve[1][1, n - 1] z2 = curve[1][2, n - 1] norm = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)) px1 = x2 + ext * (x2 - x1) * hm / norm py1 = y2 + ext * (y2 - y1) * hm / norm pz1 = z2 + ext * (z2 - z1) * hm / norm line = D.line((x2, y2, z2), (px1, py1, pz1), ext) curve2 = T.join(curve2, line) l = D.getLength(curve2) ni = ni + 2 * ext hd = 1. / (ni - 1) db = G.cart((0, 0, 0), (hd, 1, 1), (ni, 1, 1)) m = G.map(curve2, db) m = G.addNormalLayers(m, delta, niter=50, check=0) m = T.reorder(m, (1, -3, 2)) curve[0] = vars return m
def nurbs(t, weight='weight', order=3, N=100, M=100, density=-1): """Create a nurbs of N points. Usage: nurbs(ctrlPts, order, N)""" w = C.getField(weight, t)[0] Pts = C.getFields(Internal.__GridCoordinates__, t)[0] Pts = Converter.addVars([Pts, w]) surf = Geom.nurbs(Pts, weight, order, N, M, density) return C.convertArrays2ZoneNode('nurbs', [surf])
def L(): a = Geom.polyline([(0.,0.,0.), (0.,6.,0.), (2.,6.,0.), (2.,1,0.), (6.,1,0.), (6.,0,0.), (0.,0,0.)]) return [a], 6
def getFirstPointsInfo__(z, wallRanges, loc='nodes'): coords = C.getFields(Internal.__GridCoordinates__, z)[0] wallsc = getFirstPointsInfo0__(coords, wallRanges, loc) # calcul de la hauteur de courbure hmax = Geom.getCurvatureHeight(wallsc) wallsc = Converter.addVars([wallsc, hmax]) # conversion en 'NODE' wallsc = Converter.convertArray2Node(wallsc) return wallsc
def C1(): a = Geom.polyline([(1.,0.,0.), (1,4,0), (0.,4.,0.), (1,6,0), (3.,6.,0.), (3.,0.,0.), (1.,0.,0.)]) return [a], 3
def text1D(string, font='text1', smooth=0, offset=0.5): """Create a 1D text. offset is the space between letters, font indicates used font, smooth indicates the smoothing intensity. Usage: text1D(string, font, smooth, offset)""" a = Geom.text1D(string, font, smooth, offset) zones = [] for i in a: zone = C.convertArrays2ZoneNode(string, [i]) zones.append(zone) return zones
def V(): a = Geom.polyline([(2.,0.,0.), (0.,6.,0.), (2,6,0), (3.,2.,0.), (4.,6.,0.), (6.,6.,0.), (4.,0.,0.), (2,0,0)]) return [a], 6
def EXCLAMATION(): a = Geom.polyline([(0.25,0,0), (0,0.25,0), (0.,0.5,0), (0.25,0.75,0), (0.5,0.75,0), (0.75,0.5,0), (0.75,0.25,0), (0.5,0.,0), (0.25,0,0) ]) b = Geom.polyline([(0.1,1,0), (0.65,1,0), (0.75,6,0), (0.,6,0), (0.1,1,0) ]) return [a,b], 1
def makeGeometry(self): returnValue = libpanda._inPMAKPIeEy(self.this) import Geom returnObject = Geom.Geom(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject.setPointer() return
def getGeom(self, n): returnValue = libpanda._inPkJyoAgFb(self.this, n) import Geom returnObject = Geom.Geom(None) returnObject.this = returnValue if returnObject.this == 0: return None returnObject.userManagesMemory = 1 return returnObject.setPointer() return
def C7(): a = Geom.polyline([(0.,0.,0.), (3.5,5,0), (0,5,0), (0,6,0), (6,6,0), (2,0,0), (0,0,0) ]) return [a], 6
def C4(): a = Geom.polyline([(2,0.,0.), (2,1,0), (0,1,0.), (2,6,0), (5,6,0), (5,3,0), (6,3,0.), (6,1,0.), (5,1,0.), (5,0,0), (2,0,0) ]) b = Geom.polyline([(2.2,2,0.), (3.5,5,0), (3.5,2,0), (2.2,2,0) ]) return [a,b], 6