sysdynpy/simulator.py
def run_simulation(self, system):
        """Runs a simulation for the given system.

        Once the simulation is finished, results are available by calling
        :py:meth:`~get_simulation_results`

        :param system: The system to run a simulation for.
        :type system: System
        """

        print("Simulation started")

        """
        In the initial iteration values for dynamic variables and
        flows are calculated, but nothing else changes. So we need one iteration
        more to get the required number of steps
        """
        
        for i in range(int(self.simulation_steps / self.dt)+1):
            
            # make a deep copy of the current system state
            system_backup = copy.deepcopy(system)

            # iterate all system elements
            for idx, elem in enumerate(system_backup._system_elements):
                # for flows and dynamic variables
                if "Flow" in str(type(elem)) or "DynamicVariable" in str(type(elem)):
                    # set the calculated value directly
                    system._system_elements[idx].value = \
                        self._calculate_value(elem)
                else:
                    pass # for parameters and stocks

            if i == 0:
                # in the first iteration only store the initial system state
                system_backup = copy.deepcopy(system)
                self._system_states.append(system_backup)
                continue

            # for stocks 
            for idx, elem in enumerate(system_backup._system_elements):
                if  "Stock" in str(type(elem)):
                    current_stock_value = system._system_elements[idx].value
                    change = self._calculate_stock_change(elem)
                    system._system_elements[idx].value = current_stock_value + change * self.dt

            # store copy of system state every 1 / dt iterations
            # example: dt = 0.05 --> every 20 iterations
            if int(i % (1 / self.dt)) == 0:
                self._system_states.append(system_backup)

        print("Simulation finished")
Runs a simulation for the given system.

        Once the simulation is finished, results are available by calling
        :py:meth:`~get_simulation_results`

        :param system: The system to run a simulation for.
        :type system: System
        
Runs a simulation for the given system.
Once the simulation is finished, results are available by calling
Runs a simulation for the given system . Once the simulation is finished results are available by calling
def run_simulation(self, system):
        print("Simulation started")
        for i in range(int(self.simulation_steps / self.dt)+1):
            system_backup = copy.deepcopy(system)
            for idx, elem in enumerate(system_backup._system_elements):
                if "Flow" in str(type(elem)) or "DynamicVariable" in str(type(elem)):
                    system._system_elements[idx].value = \
                        self._calculate_value(elem)
                else:
                    pass 
            if i == 0:
                system_backup = copy.deepcopy(system)
                self._system_states.append(system_backup)
                continue
            for idx, elem in enumerate(system_backup._system_elements):
                if  "Stock" in str(type(elem)):
                    current_stock_value = system._system_elements[idx].value
                    change = self._calculate_stock_change(elem)
                    system._system_elements[idx].value = current_stock_value + change * self.dt
            if int(i % (1 / self.dt)) == 0:
                self._system_states.append(system_backup)
        print("Simulation finished")
def run_simulation ( self , system ) : print ( "Simulation started" ) """
        In the initial iteration values for dynamic variables and
        flows are calculated, but nothing else changes. So we need one iteration
        more to get the required number of steps
        """ for i in range ( int ( self . simulation_steps / self . dt ) + 1 ) : system_backup = copy . deepcopy ( system ) for idx , elem in enumerate ( system_backup . _system_elements ) : if "Flow" in str ( type ( elem ) ) or "DynamicVariable" in str ( type ( elem ) ) : system . _system_elements [ idx ] . value = self . _calculate_value ( elem ) else : pass if i == 0 : system_backup = copy . deepcopy ( system ) self . _system_states . append ( system_backup ) continue for idx , elem in enumerate ( system_backup . _system_elements ) : if "Stock" in str ( type ( elem ) ) : current_stock_value = system . _system_elements [ idx ] . value change = self . _calculate_stock_change ( elem ) system . _system_elements [ idx ] . value = current_stock_value + change * self . dt if int ( i % ( 1 / self . dt ) ) == 0 : self . _system_states . append ( system_backup ) print ( "Simulation finished" )
Runs a simulation for the given system.
Runs a simulation for the given system .
"""Runs a simulation for the given system.

        Once the simulation is finished, results are available by calling
        :py:meth:`~get_simulation_results`

        :param system: The system to run a simulation for.
        :type system: System
        """ """
        In the initial iteration values for dynamic variables and
        flows are calculated, but nothing else changes. So we need one iteration
        more to get the required number of steps
        """ # make a deep copy of the current system state # iterate all system elements # for flows and dynamic variables # set the calculated value directly # for parameters and stocks # in the first iteration only store the initial system state # for stocks  # store copy of system state every 1 / dt iterations # example: dt = 0.05 --> every 20 iterations
self
system
The system to run a simulation for.
The system to run a simulation for .
py
None