Пример #1
0
def change_value_in_file(filename, quantity, newValue, sim=False, filepath=False, DEBUG=False):
    """ Use to change a quantity in
        - *.in
        - *.local
        - submit*, i.e. submit.sh, submit.csh, files, only works if computer is readily specified in pencilnew.io.get_systemid

    Please add further functionallity by yourself!

    Args:
        filename:   can be "run.in", "start.in", "cparam.local"
        quantity:   variable to read in from file
        sim:        put simulation object here, file will be found by filename automatically
        filepath:   normally not needed, specify here where to find the file with filename, can be a list of paths if unshure
        DEBUG:      make dry run, tell me what you would do but dont change anything!
        silent:     suppress certain output by setting True

    Returns True if successful, else False
    """

    from pencilnew.io import get_value_from_file

    return_value = get_value_from_file(filename, quantity, change_quantity_to=newValue, sim=sim, filepath=filepath, DEBUG=DEBUG)

    if return_value == None:
        return False
    return True
Пример #2
0
    def get_value(self, quantity, DEBUG=False):
        """Optimized version of get_value_from_file. Just state quantity for simulation and param-list together with searchable components will be searched."""

        if DEBUG: print('~ DEBUG: Updating simulation.')
        self.update()

        if DEBUG: print('~ DEBUG: Searching through simulation.params ...')
        if type(self.param) == type({'dictionary': 'with_values'}):
            if quantity in self.param.keys():
                if DEBUG:
                    print('~ DEBUG: ' + quantity +
                          ' found in simulation.params ...')
                return self.param[quantity]

        if DEBUG:
            print(
                '~ DEBUG: Searching through simulation.quantity_searchables ...'
            )
        from pencilnew.io import get_value_from_file
        for filename in self.quantity_searchables:
            q = get_value_from_file(filename,
                                    quantity,
                                    change_quantity_to=False,
                                    sim=self,
                                    DEBUG=DEBUG,
                                    silent=True)
            if q is not None:
                if DEBUG:
                    print('~ DEBUG: ' + quantity + ' found in ' + filename +
                          ' ...')
                return q

        print('! ERROR: Couldnt find ' + quantity + '!')
Пример #3
0
    def get_value(self, quantity, DEBUG=False):
        """Optimized version of get_value_from_file. Just state quantity for simulation and param-list together with searchable components will be searched."""

        if DEBUG: print('~ DEBUG: Updating simulation.')
        self.update()

        if DEBUG: print('~ DEBUG: Searching through simulation.params and dim ...')
        if type(self.param) == type({'dictionary': 'with_values'}):
            if quantity in self.param.keys():
                if DEBUG: print('~ DEBUG: '+quantity+' found in simulation.params ...')
                q = self.param[quantity]
                return q
            elif quantity in [d for d in dir(self.dim) if not d.startswith('__')]:
                if DEBUG: print('~ DEBUG: '+quantity+' found in simulation.params ...')
                q = getattr(self.dim, quantity)
                return q

        if DEBUG: print('~ DEBUG: Searching through simulation.quantity_searchables ...')
        from pencilnew.io import get_value_from_file
        for filename in self.quantity_searchables:
            q = get_value_from_file(filename, quantity, sim=self, DEBUG=DEBUG, silent=True)
            if q is not None:
                if DEBUG: print('~ DEBUG: '+quantity+' found in '+filename+' ...')
                return q
            else:
                if DEBUG: print('~ DEBUG: Couldnt find quantity here.. continue searching')

        print('! ERROR: Couldnt find '+quantity+'!')
        return None