async def fetch_data(url, method='GET', callback=None, timeout=20, clear_cache_after=False, **kwargs):
    ''' Queue a task on another thread to get the data with urllib then
    await until the data is available and call the callback to handle the
    response data. The callback will render objects, meshes, etc) as required
    to view the results.

    This will **not** block the UI while retreiving the data (which may be large
    files) - but it will block while the callback does whatever it does to
    handle the data.  So if the handler does some large operations such as making
    large/complex objects - then the UI will block during that step.
    '''
    # Clear the cache that holds the response data
    RESPONSE_CACHE[url] = None
    # Queue up the thread that will get the data
    queue_fun('requests', fetch_sync, args=(method, url), kwargs=kwargs)
    # Now loop for timeout seconds waiting for data
    response_data = None
    for i in range(timeout):
        print("Awaiting for response data from thread", i)
        await asyncio.sleep(1)
        response_data = RESPONSE_CACHE[url]
        if response_data is not None:
            break
    # Call the callback that handles the response data
    callback(response_data)
    # Clear the cache after handling the response
    if clear_cache_after:
        del RESPONSE_CACHE[url]
    def rtraceStencils(self):
        # Now do the calculation
        b = bpy.context.scene.RAD.Stencil
        s = bpy.context.scene.RAD
        timestamp = getTimeStamp()
        for o in bpy.context.selected_objects:
            (minX, minY, maxX, maxY, xres, yres) = self.getDimRes(o)
            XC = (minX + maxX) / 2.0
            YC = (minY + maxY) / 2.0
            X = maxX - minX
            Y = maxY - minY
            Zvec = (o.matrix_world.to_3x3() *
                    o.data.polygons[0].normal).normalized()
            Zo = (o.matrix_world * o.data.vertices[0].co)
            Z = (Zo + Zvec)[2]

            # Get the arguments for the rtrace command
            rtargs = " -ab %i -ad %i -as %i -aa %f -av .0 .0 .0 " % (
                b.ambB, b.ambD, b.ambS, b.ambA)
            if not 'Windows' in bpy.app.build_platform.decode():
                rtargs = " -n %i" % (s.nproc) + rtargs
                rtargs += " -ar `getinfo -d<octrees/%s.oct|rcalc -e '$1=floor(16*$4/(%f+%f))'`" % (
                    timestamp, X, Y)
            else:
                octDir = bpy.path.abspath("%s/octrees/%s.oct" %
                                          (caseDir(), timestamp))
                (AR, err) = waitOUTPUT(
                    "getinfo -d<%s|rcalc -e \"$1=floor(16*$4/(%f+%f))\"" %
                    (octDir, X, Y),
                    cwd=caseDir())
                rtargs += " -ar %i" % (int(AR))

            # Generate a rectangular grid of rays over the stencil limits
            cmd = "cnt %u %u" % (yres, xres)
            cmd += " | rcalc -e '$1=%f + ($2-(%u/2)+0.5)*(%f)' " % (XC, xres,
                                                                    X / xres)
            cmd += " -e '$2=%f - ($1-(%u/2)+0.5)*(%f)' " % (YC, yres, Y / yres)
            cmd += " -e '$3=%f' -e '$4=0;$5=0;$6=%f' " % (Z, -1 * Zvec[2])
            # raytrace upwards to the stencil area
            cmd += " | rtrace -w -h -opv  stencils/%s.oct " % (o.name)
            cmd += " | rcalc -e '$1=$1;$2=$2;$3=$3;$4=0;$5=0;$6=if($6-0.5,1,0)' "
            cmd += " | rtrace %s -h+ -I+ -ov octrees/%s.oct " % (rtargs,
                                                                 timestamp)
            cmd += " | pvalue -r -x %u -y %u " % (yres, xres)
            cmd += " | pfilt -h 20 -p 1 > images/dftrace_%s_%s.hdr" % (
                o.name, timestamp)

            if 'Windows' in bpy.app.build_platform.decode():
                cmd = cmd.replace("'", "\"")

            queue_fun("rtrace", waitSTDOUT, (cmd, caseDir()))
        return None
Example #3
0
 def basicMesh(self):
     mpi = bpy.context.scene.ODS_CFD.system.runMPI
     self.runFoamBlockMesh()
     if bpy.context.scene.ODS_CFD.mesh.nFeatureSnapIter > 0:
         self.runFoamSurfaceFeatureExtract()
     if mpi:
         self.decomposePar()
     self.runFoamSnapMesh()
     if mpi:
         self.reconstructParMesh()
         threads.queue_fun("cfdRun", self.delProcessDirs,
                           (self.caseDir(), ))
     return None
Example #4
0
 def batchStats(self):
     p = bpy.context.scene.RAD.falsecolor
     cdir = bpy.path.abspath(bpy.context.scene.RAD.caseDir)
     ts = getTimeStamp()
     outFile = "%s/images/Stats-%s.csv" % (cdir, ts)
     files = glob.glob('%s/images/*%s.hdr' % (cdir, ts))
     f = open(outFile, 'w')
     f.write("")
     f.close()
     for f in files:
         #self.fileStats(f, p.mult, p.limit, outFile)
         queue_fun("rtrace", self.fileStats, (f, p.mult, p.limit, outFile))
     return None
 def executeAnimScript(self, context):
     sc = bpy.context.scene
     commands = bpy.path.abspath("%s/animation.sh" % (sc.RAD.caseDir))
     if not os.path.exists(commands):
         self.report({
             'ERROR'
         }, 'Could not find render commands.\\Have you exported the animation case files first?'
                     )
         return {'FINISHED'}
     # Open the list of commands to execute for the sequence and run them
     f = open(commands, 'r')
     for cmd in f.readlines():
         queue_fun("rpict", waitSTDOUT, (cmd, caseDir()))
     f.close()
     return {'FINISHED'}
Example #6
0
    def runPostMeshUtils(self):
        def run(cmd):
            setSets = fileUtils.getFilesByExtension('.setSet',
                                                    '%s/' % self.caseDir())
            for s in setSets:
                waitSTDOUT("%s setSet %s -batch %s | tee logPMesh.txt" %
                           (self.getMpiCall(), self.parStr(), s),
                           cwd=self.caseDir())
            waitSTDOUT("%s setsToZones %s %s | tee logPMesh.txt" %
                       (self.getMpiCall(), self.parStr(), s),
                       cwd=self.caseDir())
            waitSTDOUT("%s changeDictionary %s %s | tee logPMesh.txt" %
                       (self.getMpiCall(), self.parStr(), s),
                       cwd=self.caseDir())

        threads.queue_fun("cfdRun", run, ())
        return None
Example #7
0
 def calcYearRays(self):
     sc = bpy.context.scene
     (nDays, nFrames) = self.writeYearRays()
     for o in bpy.context.selected_objects:
         timestamp = getTimeStamp()
         if not 'Windows' in bpy.app.build_platform.decode():
             cmd = "cat yearRays | rcalc -e '$1=%f' -e '$2=%f' -e '$3=%f' -e '$4=$1' -e '$5=$2' -e '$6=$3'" % (
                 o.location[0], o.location[1], o.location[2])
         else:
             cmd = "cat yearRays | rcalc -e \"$1=%f\" -e \"$2=%f\" -e \"$3=%f\" -e \"$4=$1\" -e \"$5=$2\" -e \"$6=$3\"" % (
                 o.location[0], o.location[1], o.location[2])
         cmd += " | rtrace -ab 0 -h+ -ov -fac -x %u -y %u octrees/%s.oct " % (
             nFrames, nDays, timestamp)
         cmd += " | pfilt -h 20 -n 0 -p 1 -r 1 > images/yearTrace_temp.hdr "
         cmd += " && protate images/yearTrace_temp.hdr images/yearTrace_%s.hdr && rm -v images/yearTrace_temp.hdr" % (
             o.name)
         queue_fun("rtrace", waitSTDOUT, (cmd, caseDir()))
     return
Example #8
0
 def reconstructParMesh(self):
     cmd = "reconstructParMesh -constant -mergeTol 1e-6 | tee -a logPar.txt"
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return None
Example #9
0
 def reconstructPar(self):
     cmd = "reconstructPar -latestTime | tee -a logPar.txt"
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return None
Example #10
0
 def decomposePar(self):
     cmd = "decomposePar | tee -a logPar.txt"  # latestTime by default in OF-2.0
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return {'FINISHED'}
Example #11
0
 def runFoamSnapMesh(self):
     cmd = "%s snappyHexMesh -overwrite %s | tee logSHM.txt" % (
         self.getMpiCall(), self.parStr())
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return None
Example #12
0
 def runFoamSurfaceFeatureExtract(self):
     cmd = "surfaceFeatureExtract | tee logSFE.txt"
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return None
 def oconvStensils(self):
     for o in bpy.context.selected_objects:
         cmd = "oconv stencils/%s.rad > stencils/%s.oct" % (o.name, o.name)
         queue_fun("rtrace", waitSTDOUT, (cmd, caseDir()))
     return
Example #14
0
 def genOctree(self):
     ts = getTimeStamp()
     cmd = "oconv %s.rad > octrees/%s.oct" % (ts, ts)
     queue_fun("rtrace", waitSTDOUT, (cmd, caseDir()))
Example #15
0
 def executeRifFile(self):
     sc = bpy.context.scene
     cmd = "rad -N %i %s.rif" % (sc.RAD.nproc, getTimeStamp())
     queue_fun("rpict", waitSTDOUT, (cmd, caseDir()))
     getOutsideAmb()
     return {'FINISHED'}
Example #16
0
 def paraView(self):
     cmd = "paraFoam | tee -a logPP.txt"
     threads.queue_fun("cfdPost", waitSTDOUT, (cmd, self.caseDir()))
     return None
Example #17
0
 def runFoamCase(self):
     CFD = bpy.context.scene.ODS_CFD
     cmd = "%s %s %s | tee -a log.txt" % (self.getMpiCall(),
                                          CFD.solver.name, self.parStr())
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return None
Example #18
0
 def runFoamBlockMesh(self):
     cmd = "blockMesh | tee logBM.txt"
     threads.queue_fun("cfdRun", waitSTDOUT, (cmd, self.caseDir()))
     return None