Example #1
0
def rotate_scene(model_abspath):
    """Rotate Radiance geometry in Daysim project"""
	
	# Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
        '..\config.ini')
    conf.read(conf_file)
    bin_dir = os.path.abspath(conf.get('DAYSIM', 'Bin_Dir'))
    rotatescene_path = os.path.join(bin_dir, 'rotate_scene.exe')

    # Call rotate_scene program
    cmd = [rotatescene_path, model_abspath]
    util.run_cmd(cmd)
    
    # Rename rotated .rad and .pts files
    work_dir = os.path.dirname(model_abspath)
    for root, dirs, files in os.walk(work_dir):
        for fname in files:
            if fname.endswith('rotated.rad') or fname.endswith('rotated.pts'):
                old = os.path.join(root, fname)
                new = os.path.join(root, fname[:-12])
                # Try to rename filename
                # Remove new_fname if already exists because os.rename can't
                # overwrite existing files on Windows
                try:
                    os.rename(old, new)
                except WindowsError:
                    os.remove(new)
                    os.rename(old, new)
Example #2
0
def rotate_scene(model_abspath):
    """Rotate Radiance geometry in Daysim project"""

    # Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             '..\config.ini')
    conf.read(conf_file)
    bin_dir = os.path.abspath(conf.get('DAYSIM', 'Bin_Dir'))
    rotatescene_path = os.path.join(bin_dir, 'rotate_scene.exe')

    # Call rotate_scene program
    cmd = [rotatescene_path, model_abspath]
    util.run_cmd(cmd)

    # Rename rotated .rad and .pts files
    work_dir = os.path.dirname(model_abspath)
    for root, dirs, files in os.walk(work_dir):
        for fname in files:
            if fname.endswith('rotated.rad') or fname.endswith('rotated.pts'):
                old = os.path.join(root, fname)
                new = os.path.join(root, fname[:-12])
                # Try to rename filename
                # Remove new_fname if already exists because os.rename can't
                # overwrite existing files on Windows
                try:
                    os.rename(old, new)
                except WindowsError:
                    os.remove(new)
                    os.rename(old, new)
Example #3
0
def radfiles2daysim(model_abspath):
    """Call radfiles2daysim program to convert source rad file to
    daysim material and geometry rad files"""

    # Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             '..\config.ini')
    conf.read(conf_file)
    bin_dir = os.path.abspath(conf.get('DAYSIM', 'Bin_Dir'))
    radfiles2daysim_path = os.path.join(bin_dir, 'radfiles2daysim.exe')

    # Call radfiles2daysim program
    cmd = [radfiles2daysim_path, model_abspath, '-g', '-m', '-d']
    util.run_cmd(cmd)
Example #4
0
def radfiles2daysim(model_abspath):
    """Call radfiles2daysim program to convert source rad file to 
    daysim material and geometry rad files"""
	
	# Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
        '..\config.ini')
    conf.read(conf_file)
    bin_dir = os.path.abspath(conf.get('DAYSIM', 'Bin_Dir'))
    radfiles2daysim_path = os.path.join(bin_dir, 'radfiles2daysim.exe')

    # Call radfiles2daysim program
    cmd = [radfiles2daysim_path, model_abspath, '-g', '-m', '-d']
    util.run_cmd(cmd)
Example #5
0
def gen_type56(model_abspath, select='all'):
    """Generates Type56 matrices and idf files"""
	
	# Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
        '..\config.ini')
    conf.read(conf_file)
    trnbuild_path = os.path.abspath(conf.get('TRNSYS', 'TRNBuild_Path'))
    trnsidf_path = os.path.abspath(conf.get('TRNSYS', 'trnsIDF_Path'))

    # Get b17 file path from deck file
    pattern = re.compile(r'ASSIGN "(.*b17)"')
    with open(model_abspath, 'rU') as m_f:
        temp = m_f.read()
        match = pattern.search(temp)
        # TRNBUILD is only called if Type56 is found in deck file.
        if match:
            b17_relpath = match.group(1)
            b17_abspath = os.path.join(os.path.dirname(model_abspath), b17_relpath)
            # Generate shading/insolation matrix
            if select == 'all' or select == 'matrices' or select == 'masks':
                cmd = [trnbuild_path, b17_abspath, '/N', '/masks']
                util.run_cmd(cmd)
            # Generate view factor matrix
            if select == 'all' or select == 'matrices' or select == 'vfm':					
                cmd = [trnbuild_path, b17_abspath, '/N', '/vfm']
                util.run_cmd(cmd)
            # Generate trnsys3D idf file, to view geometry in Sketchup
            if select == 'all' or select == 'idf':				
                cmd = [trnsidf_path, b17_abspath]
                util.run_cmd(cmd)
Example #6
0
def gen_type56(model_abspath, select='all'):
    """Generate Type56 matrices and idf files

    Calls TRNBUILD.exe with flags to generate matrices and IDF files.

    Args:
        model_abspath: absolute path to Type56 model file
        select: selects which files should by generated by TRNBUILD.
            'masks' generates insolation matrix, 'vfm' generates de view factor
            matrix, 'matrices' generates both
            'idf' generates the IDF file (similar to TRNBUILD 'export' funtion)
            'all' generates everything

    Returns:
        Generated files.

    """

    # Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             '..\config.ini')
    conf.read(conf_file)
    trnbuild_path = os.path.abspath(conf.get('TRNSYS', 'TRNBuild_Path'))
    trnsidf_path = os.path.abspath(conf.get('TRNSYS', 'trnsIDF_Path'))

    # Get b17 file path from deck file
    pattern = re.compile(r'ASSIGN "(.*b17)"')
    with open(model_abspath, 'rU') as m_f:
        temp = m_f.read()
        match = pattern.search(temp)
        # TRNBUILD is only called if Type56 is found in deck file.
        if match:
            b17_relpath = match.group(1)
            b17_abspath = os.path.join(os.path.dirname(model_abspath),
                                       b17_relpath)
            # Generate shading/insolation matrix
            if select == 'all' or select == 'matrices' or select == 'masks':
                cmd = [trnbuild_path, b17_abspath, '/N', '/masks']
                util.run_cmd(cmd)
            # Generate view factor matrix
            if select == 'all' or select == 'matrices' or select == 'vfm':
                cmd = [trnbuild_path, b17_abspath, '/N', '/vfm']
                util.run_cmd(cmd)
            # Generate trnsys3D idf file, to view geometry in Sketchup
            if select == 'all' or select == 'idf':
                cmd = [trnsidf_path, b17_abspath]
                util.run_cmd(cmd)
Example #7
0
def gen_type56(model_abspath, select='all'):
    """Generate Type56 matrices and idf files
    
    Calls TRNBUILD.exe with flags to generate matrices and IDF files.
    
    Args:
        model_abspath: absolute path to Type56 model file
        select: selects which files should by generated by TRNBUILD.
            'masks' generates insolation matrix, 'vfm' generates de view factor
            matrix, 'matrices' generates both
            'idf' generates the IDF file (similar to TRNBUILD 'export' funtion)
            'all' generates everything
            
    Returns:
        Generated files.
    
    """
	
	# Get information from config file
    conf = SafeConfigParser()
    conf_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
        '..\config.ini')
    conf.read(conf_file)
    trnbuild_path = os.path.abspath(conf.get('TRNSYS', 'TRNBuild_Path'))
    trnsidf_path = os.path.abspath(conf.get('TRNSYS', 'trnsIDF_Path'))

    # Get b17 file path from deck file
    pattern = re.compile(r'ASSIGN "(.*b17)"')
    with open(model_abspath, 'rU') as m_f:
        temp = m_f.read()
        match = pattern.search(temp)
        # TRNBUILD is only called if Type56 is found in deck file.
        if match:
            b17_relpath = match.group(1)
            b17_abspath = os.path.join(os.path.dirname(model_abspath), b17_relpath)
            # Generate shading/insolation matrix
            if select == 'all' or select == 'matrices' or select == 'masks':
                cmd = [trnbuild_path, b17_abspath, '/N', '/masks']
                util.run_cmd(cmd)
            # Generate view factor matrix
            if select == 'all' or select == 'matrices' or select == 'vfm':					
                cmd = [trnbuild_path, b17_abspath, '/N', '/vfm']
                util.run_cmd(cmd)
            # Generate trnsys3D idf file, to view geometry in Sketchup
            if select == 'all' or select == 'idf':				
                cmd = [trnsidf_path, b17_abspath]
                util.run_cmd(cmd)
Example #8
0
    def run(self,
            ncore='max',
            stopwatch=False,
            run_mode='silent',
            debug=False):
        """Run simulation jobs
        
        Args:
            ncore: number of local cores/threads to be used at a time
               For ncore>=2, jobs will run in parallel. 
               By default, all local cores are used to run jobs in parallel
            stopwatch: flag to activate a stopwatch that monitors job run time
            run_mode: for simulation tool that have this kind of command line
               flag, allows to run tools in silent or continuous mode
               For example, 'silent' runs TRNSYS with '/h' flag and
               'nostop' runs TRNSYS with '/n' flag
            debug: by default, simulation tool's standard output is captured 
               and therefore does not appear on screens. if debug is set to 
               'True' any output text return by the simuation tool is printed 
               (useful for debuggingsimulation model)
               
        Returns:
            Info message for current simulation job run
        
        """

        #Create executable path for selected simulation tool
        if self.simtool == 'TRNSYS':
            executable_abspath = self.config['trnexe_path']
            silent_flag = '/h'
            nostop_flag = '/n'
        elif self.simtool == 'DAYSIM':
            executable_abspath = self.config['exe_path']
            silent_flag = ''
            nostop_flag = ''

        # If simulation project is identified as single run, directly
        # call simulation tool to run simulation
        if self._batch == False:
            # Build absolute path to model file
            model_abspath = os.path.join(self.abspath, self.model_relpath)
            # Run the simulation, by default in silent mode
            if run_mode == 'silent': flag = silent_flag
            elif run_mode == 'nostop': flag = nostop_flag
            elif run_mode == 'normal': flag = None
            cmd = [executable_abspath, model_abspath, flag]
            # Measure simulation run time
            start_time = time()
            # Launch command
            if debug == False:
                util.run_cmd(cmd)
            else:
                util.run_cmd(cmd, debug=True)
            # Save simulation time
            self.simtime = round(time() - start_time, 3)
        # If simulation project corresponds to a batch run, run jobs
        # in parallel
        else:
            # Check first if there are some jobs defined
            if self.jobs:
                print('\nStarting batch run ...')
                # Start timer if stopwatch requested by user
                if stopwatch == True:
                    start_time = time()
                # Create multiprocessing pool for parallel subprocess run
                if ncore == 'max':
                    pool = Pool(None)
                    print(
                        str(cpu_count()) +
                        ' core(s) used in current run (max local cores)\n')
                else:
                    pool = Pool(ncore)
                    print(str(ncore) + ' core(s) used in current run\n')
                # This method automatically assigns processes to available
                # cores and the entire operation stops when all values from
                # jobs from the jobs list have been evaluated.
                # A callback function is used to retrieve run summary from job
                # and store it in runsummary list
                r = pool.map_async(self.runjob_func,
                                   self.jobs,
                                   chunksize=1,
                                   callback=self.runsummary.extend)
                r.wait()
                pool.close()
                pool.join()
                # Stop timer if stopwatch requested by user
                if stopwatch == True:
                    self.simtime = time() - start_time
                    print('\nSimulation batch runtime: ' + str(self.simtime) +
                          ' seconds')

# Print an error message if no jobs were found
            else:
                print(
                    "\nNo simulation jobs found" +
                    "\n\nYou should first add simulation jobs to your BPSProject"
                    + "with the 'add_job' or " +
                    "\n'add_jobs' methods prior to calling the 'run' method")
Example #9
0
    def run(self, ncore='max', stopwatch=False, run_mode='silent', debug=False):
        """Comment"""
        
        #Create executable path for selected simulation tool
        if self.simtool == 'TRNSYS':
            executable_abspath = os.path.abspath(self.config['trnexe_path'])
            silent_flag = '/h'
            nostop_flag = '/n'
        elif self.simtool == 'DAYSIM':
            executable_abspath = os.path.abspath(self.config['exe_path'])
            silent_flag = ''
            nostop_flag = ''            
		
        # If simulation project is identified as single run, directly
        # call simulation tool to run simulation
        if self._batch == False:
            # Build absolute path to model file
            model_abspath = os.path.join(self.abspath, self.model_relpath)		
            # Run the simulation, by default in silent mode
            if run_mode == 'silent': flag = silent_flag
            elif run_mode == 'nostop': flag = nostop_flag
            elif run_mode == 'normal': flag = None
            cmd = [executable_abspath, model_abspath, flag]
            # Measure simulation run time
            start_time = time()
            # Launch command
            if debug == False:
                util.run_cmd(cmd)
            else:
                util.run_cmd(cmd, debug=True)
            # Save simulation time
            self.simtime = round(time() - start_time, 3)
        # If simulation project corresponds to a batch run, run jobs
        # in parallel
        else:
            # Check first if there are some jobs defined
            if self.jobs:
                print('\nStarting batch run ...')
                # Start timer if stopwatch requested by user
                if stopwatch == True:
                    start_time = time()			
                # Create multiprocessing pool for parallel subprocess run
                if ncore == 'max':
                    pool = Pool(None)
                    print(str(cpu_count()) + 
                        ' core(s) used in current run (max local cores)\n')
                else:
                    pool = Pool(ncore)
                    print(str(ncore) + ' core(s) used in current run\n')
                # This method automatically assigns processes to available
                # cores and the entire operation stops when all values from
                # jobs from the jobs list have been evaluated.
                # A callback function is used to retrieve run summary from job
                # and store it in runsummary list
                r = pool.map_async(self.runjob_func, self.jobs, chunksize=1,
                        callback=self.runsummary.extend)
                r.wait()
                pool.close()
                pool.join()
                # Stop timer if stopwatch requested by user
                if stopwatch == True:
                    print('\nSimulation batch runtime: ' + 
                        str(time()-start_time) + ' seconds')	        
		    # Print an error message if no jobs were found
            else:
                print("\nNo simulation jobs found" +
                "\n\nYou should first add simulation jobs to your BPSProject" +
                "with the 'add_job' or " +
                "\n'add_jobs' methods prior to calling the 'run' method")
Example #10
0
File: core.py Project: JWW81/PyBPS
    def run(self, ncore='max', stopwatch=False, run_mode='silent', debug=False):
        """Run simulation jobs
        
        Args:
            ncore: number of local cores/threads to be used at a time
               For ncore>=2, jobs will run in parallel. 
               By default, all local cores are used to run jobs in parallel
            stopwatch: flag to activate a stopwatch that monitors job run time
            run_mode: for simulation tool that have this kind of command line
               flag, allows to run tools in silent or continuous mode
               For example, 'silent' runs TRNSYS with '/h' flag and
               'nostop' runs TRNSYS with '/n' flag
            debug: by default, simulation tool's standard output is captured 
               and therefore does not appear on screens. if debug is set to 
               'True' any output text return by the simuation tool is printed 
               (useful for debuggingsimulation model)
               
        Returns:
            Info message for current simulation job run
        
        """
        
        #Create executable path for selected simulation tool
        if self.simtool == 'TRNSYS':
            executable_abspath = self.config['trnexe_path']
            silent_flag = '/h'
            nostop_flag = '/n'
        elif self.simtool == 'DAYSIM':
            executable_abspath = self.config['exe_path']
            silent_flag = ''
            nostop_flag = ''            
		
        # If simulation project is identified as single run, directly
        # call simulation tool to run simulation
        if self._batch == False:
            # Build absolute path to model file
            model_abspath = os.path.join(self.abspath, self.model_relpath)		
            # Run the simulation, by default in silent mode
            if run_mode == 'silent': flag = silent_flag
            elif run_mode == 'nostop': flag = nostop_flag
            elif run_mode == 'normal': flag = None
            cmd = [executable_abspath, model_abspath, flag]
            # Measure simulation run time
            start_time = time()
            # Launch command
            if debug == False:
                util.run_cmd(cmd)
            else:
                util.run_cmd(cmd, debug=True)
            # Save simulation time
            self.simtime = round(time() - start_time, 3)
        # If simulation project corresponds to a batch run, run jobs
        # in parallel
        else:
            # Check first if there are some jobs defined
            if self.jobs:
                print('\nStarting batch run ...')
                # Start timer if stopwatch requested by user
                if stopwatch == True:
                    start_time = time()			
                # Create multiprocessing pool for parallel subprocess run
                if ncore == 'max':
                    pool = Pool(None)
                    print(str(cpu_count()) + 
                        ' core(s) used in current run (max local cores)\n')
                else:
                    pool = Pool(ncore)
                    print(str(ncore) + ' core(s) used in current run\n')
                # This method automatically assigns processes to available
                # cores and the entire operation stops when all values from
                # jobs from the jobs list have been evaluated.
                # A callback function is used to retrieve run summary from job
                # and store it in runsummary list
                r = pool.map_async(self.runjob_func, self.jobs, chunksize=1,
                        callback=self.runsummary.extend)
                r.wait()
                pool.close()
                pool.join()
                # Stop timer if stopwatch requested by user
                if stopwatch == True:
                    self.simtime = time()-start_time
                    print('\nSimulation batch runtime: ' + 
                        str(self.simtime) + ' seconds')	        
		    # Print an error message if no jobs were found
            else:
                print("\nNo simulation jobs found" +
                "\n\nYou should first add simulation jobs to your BPSProject" +
                "with the 'add_job' or " +
                "\n'add_jobs' methods prior to calling the 'run' method")