Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
import proteus.Comm
comm = proteus.Comm.get()
if comm.rank() == 0:
if hasQt:
if useMainWindow:
self.app = QtGui.QApplication(sys.argv)
self.mainWindow = QtGui.QMainWindow()
self.mainWindow.setWindowTitle('Proteus')
self.tabWidget = QtGui.QTabWidget(self.mainWindow)
self.frameWidgetDict={}
self.hboxDict={}
self.mainWindow.setCentralWidget(self.tabWidget)
else:
self.app = QtGui.QApplication(sys.argv)
def initializeMesh(self, mesh):
# cek we eventually need to use the local element diameter
self.eps_density = self.epsFact_density * mesh.h
self.eps_viscosity = self.epsFact * mesh.h
self.mesh = mesh
self.elementMaterialTypes = mesh.elementMaterialTypes
nBoundariesMax = int(
globalMax(max(self.mesh.elementBoundaryMaterialTypes))) + 1
self.wettedAreas = np.zeros((nBoundariesMax,), 'd')
self.netForces_p = np.zeros((nBoundariesMax, 3), 'd')
self.netForces_v = np.zeros((nBoundariesMax, 3), 'd')
self.netMoments = np.zeros((nBoundariesMax, 3), 'd')
if self.barycenters is None:
self.barycenters = np.zeros((nBoundariesMax, 3), 'd')
comm = Comm.get()
import os
# if comm.isMaster():
# self.wettedAreaHistory = open(os.path.join(proteus.Profiling.logDir,"wettedAreaHistory.txt"),"w")
# self.forceHistory_p = open(os.path.join(proteus.Profiling.logDir,"forceHistory_p.txt"),"w")
# self.forceHistory_v = open(os.path.join(proteus.Profiling.logDir,"forceHistory_v.txt"),"w")
# self.momentHistory = open(os.path.join(proteus.Profiling.logDir,"momentHistory.txt"),"w")
self.comm = comm
# initialize so it can run as single phase
"OneLevelTransport"), level=4)
# mwf for interpolating subgrid error for gradients etc
if self.stabilization and self.stabilization.usesGradientStabilization:
self.timeIntegration = TimeIntegrationClass(
self, integrateInterpolationPoints=True)
else:
self.timeIntegration = TimeIntegrationClass(self)
if options is not None:
self.timeIntegration.setFromOptions(options)
log(memory("TimeIntegration", "OneLevelTransport"), level=4)
log("Calculating numerical quadrature formulas", 2)
self.calculateQuadrature()
self.setupFieldStrides()
comm = Comm.get()
self.comm = comm
if comm.size() > 1:
assert numericalFluxType is not None and numericalFluxType.useWeakDirichletConditions, "You must use a numerical flux to apply weak boundary conditions for parallel runs"
# add some structures for elliptic re-distancing
self.interface_locator = None
self.cell_interface_locator = None
self.interface_lumpedMassMatrix = numpy.zeros(self.u[0].dof.shape,'d')
self.abs_grad_u = numpy.zeros(self.u[0].dof.shape,'d')
self.lumped_qx = numpy.zeros(self.u[0].dof.shape,'d')
self.lumped_qy = numpy.zeros(self.u[0].dof.shape,'d')
self.lumped_qz = numpy.zeros(self.u[0].dof.shape,'d')
self.quantDOFs = self.lumped_qy
self.stage = 1
self.auxEllipticFlag = 1
if self.coefficients.ELLIPTIC_REDISTANCING==2:
self.timeIntegration.beta_bdf[0], # mwf was self.timeIntegration.m_last[0],
self.q[('cfl', 0)],
self.shockCapturing.numDiff[0],
self.shockCapturing.numDiff_last[0],
self.offset[0], self.stride[0],
self.mesh.nExteriorElementBoundaries_global,
self.mesh.exteriorElementBoundariesArray,
self.mesh.elementBoundaryElementsArray,
self.mesh.elementBoundaryLocalElementBoundariesArray,
self.mesh.elementBoundaryMaterialTypes,
self.coefficients.ebqe_v,
self.numericalFlux.isDOFBoundary[0],
self.numericalFlux.ebqe[('u', 0)],
self.ebqe[('u', 0)])
from proteus import Comm
comm = Comm.get()
filename = os.path.join(self.coefficients.opts.dataDir, "waterline." + str(comm.rank()) + "." + str(self.waterline_prints))
numpy.save(filename, self.waterline_data[0:self.waterline_npoints[0]])
self.waterline_prints += 1
def findNearestNode(self, femSpace, location):
"""Given a gauge location, attempts to locate the most suitable
process for monitoring information about this location, as
well as the node on the process closest to the location.
Returns a 2-tuple containing an identifier for the closest
'owning' process as well as the local ids of the node and
nearest element.
"""
comm = Comm.get().comm.tompi4py()
comm_rank, nearest_node, nearest_node_distance = self.getLocalNearestNode(location)
local_element = self.getLocalElement(femSpace, location, nearest_node)
# determine global nearest node
haveElement = int(local_element is not None)
global_have_element, owning_proc = comm.allreduce((haveElement, comm.rank),
op=MPI.MAXLOC)
if global_have_element:
logEvent("Gauges on element at location: [%g %g %g] assigned to %d" % (location[0], location[1], location[2],
owning_proc), 3)
else:
# gauge isn't on any of the elements, just use nearest node
global_min_distance, owning_proc = comm.allreduce((nearest_node_distance,comm.rank), op=MPI.MINLOC)
logEvent("Off-element gauge location: [%g %g %g] assigned to %d" % (location[0], location[1], location[2],
owning_proc), 3)
if comm.rank != owning_proc:
prof.logEvent(prof.memory("inflowBC, internalNodes,updateLocal2Global", "OneLevelTransport"), level=4)
# mwf for interpolating subgrid error for gradients etc
if self.stabilization and self.stabilization.usesGradientStabilization:
self.timeIntegration = TimeIntegrationClass(self, integrateInterpolationPoints=True)
else:
self.timeIntegration = TimeIntegrationClass(self)
if options is not None:
self.timeIntegration.setFromOptions(options)
prof.logEvent(prof.memory("TimeIntegration", "OneLevelTransport"), level=4)
prof.logEvent("Calculating numerical quadrature formulas", 2)
self.calculateQuadrature()
self.setupFieldStrides()
comm = proteus.Comm.get()
self.comm = comm
if comm.size() > 1:
assert numericalFluxType is not None and numericalFluxType.useWeakDirichletConditions, "You must use a numerical flux to apply weak boundary conditions for parallel runs"
prof.logEvent(prof.memory("stride+offset", "OneLevelTransport"), level=4)
if numericalFluxType is not None:
if options is None or options.periodicDirichletConditions is None:
self.numericalFlux = numericalFluxType(self,
dofBoundaryConditionsSetterDict,
advectiveFluxBoundaryConditionsSetterDict,
diffusiveFluxBoundaryConditionsSetterDictDict)
else:
self.numericalFlux = numericalFluxType(self,
dofBoundaryConditionsSetterDict,
advectiveFluxBoundaryConditionsSetterDict,
diffusiveFluxBoundaryConditionsSetterDictDict,
local coordinates and the owner of the point.
Parameters
----------
coords: array_like
global coordinates to look for
Returns
-------
xi:
local coordinates
eN: int
(local) element number
rank: int
processor rank containing element
"""
comm = Comm.get().comm.tompi4py()
xi = owning_proc = element = rank = None # initialised as None
self.xi, self.element, self.rank = xi, element, rank
# get nearest node on each processor
# comm.barrier()
self.u = self.model.levelModelList[0].u
self.femSpace_velocity = self.u[1].femSpace
nodes_kdtree = spatial.cKDTree(self.model.levelModelList[0].mesh.nodeArray)
nearest_node, nearest_node_distance = self.getLocalNearestNode(coords, nodes_kdtree)
# look for element containing coords on each processor (if it exists)
local_element = self.getLocalElement(self.femSpace_velocity, coords, nearest_node)
if local_element:
xi = self.femSpace_velocity.elementMaps.getInverseValue(local_element, coords)
rank = comm.rank
else:
xi = None
rank = None