dwsimopt.sim_opt.py

Main module that contains SimulationOptimization class definition

Module

sim_opt.py

Author

Lucas F. Santos <lfs.francisco.95@gmail.com>

class dwsimopt.sim_opt.SimulationOptimization(path2sim, dof=array([], dtype=object), path2dwsim='C:\\Users\\lfsfr\\AppData\\Local\\DWSIM7\\', savepath='', verbose=True)

Bases: object

Class that defines DWSIM simulation optimization objects.

Variables
  • path2sim – Absolute path to a DWSIM simulation (.dwxmz)

  • path2dwsim – Absolute path to the DWSIM installation

  • savepath – Absolute path to save the DWSIM simulation (.dwxmz)

  • verbose – Boolean that controls display messages during simulation calculation

  • x_val – Last simulated degrees of freedom values

  • f_val – Last simulated objective functions values

  • g_val – Last simulated constraints values

  • dof – Lambda function that assign the degrees of freedom of the DWSIM process simulation to be handled by the optimization solver

  • f – Lambda function that returns a numpy.array with objective functions values after converging the simulation

  • g – Lambda function that returns a numpy.array with constraints values after converging the simulation

  • n_dof – Number of degrees of freedom (size of optimization problem)

  • n_f – Number of objective functions (still unsupported for n_f>1, i.e. multi-objective problem)

  • n_g – Number of constraints

add_constraint(g_func, description=[None, None, None, None])

Append a new constraint to the SimulationOptimization object

Args:

g_func (lambda function): Lambda function that returns a numpy.array with constraint value after converging the simulation

add_dof(dof_new, description=[None, None, None, None])

Append a new degree of freedom to the SimulationOptimization object

Args:

dof_new (lambda function): Lambda function that assign the appended degrees of freedom of the DWSIM process simulation

add_fobj(func, description=[None, None, None, None])

Append a new objective function to the SimulationOptimization object

Args:

func (lambda function): Lambda function that returns a numpy.array with objective function value after converging the simulation

add_refs()

This method add reference in the proggraming environment to the DWSIM dlls, so they can be imported.

calculate_optProblem(x)

Assign degrees of freedom values to the simulation if norm > 1e-10. Converge the simulation and return an array with objectives and constraints values.

Args:

x (numpy.array): Array of degrees of freedom values to be simulated

Returns:

numpy.array: Array of objectives and constraints values calculated at x

connect(interf)

This method uses the automation manager object to load the DWSIM flowsheet and store them into self.

Args:

interf (DWSIM.Automation.Automation2): Automation manager object with methods to load, save, and create DWSIM flowsheet simulations.

converge_simulation(x)

Converge the simulation with degrees of freedom values of x

Args:

x (numpy.array): Array of degrees of freedom values to be simulated

fpen_barrier(x, pen=1000)

Calculates a penalized objective function using barrier method and considering f and g.

Args:

x (numpy.array): Array of degrees of freedom values to be simulated. pen (float, optional): Penalization parameter. Defaults to 1000.

Returns:

float: Penalized objective function.

fpen_exp(x, pen=1000)

Calculates a penalized objective function using exponential penalization method and considering f and g.

Args:

x (numpy.array): Array of degrees of freedom values to be simulated. pen (float, optional): Penalization parameter. Defaults to 1000.

Returns:

float: Penalized objective function.

fpen_quad(x, pen=1000)

Calculates a penalized objective function using quadratic penalization method and considering f and g.

Args:

x (numpy.array): Array of degrees of freedom values to be simulated. pen (float, optional): Penalization parameter. Defaults to 1000.

Returns:

float: Penalized objective function.

dwsimopt.py2dwsim.py

Module that contains functions for data exchange from-to python to-from dwsim

Module

py2dwsim.py

Author

Lucas F. Santos <lfs.francisco.95@gmail.com>

dwsimopt.py2dwsim.assign_pddx(f, desc, sim, element='dof')

Assign pddx to sim object. This is useful for more complex objective/constaint functions. Basic use is to generate pddx getter functions to define a more complicated one and assign to sim.

Args:

f (function): function (def or lambda) containing the definition of objective/constraint function. desc (list): list of string containing [‘dwsim object name as in the simulation’, ‘object attribute’,’phase or component name’, ‘unit’] sim (dwsimopt.SimulationOpimization): object of dwsimopt.SimulationOpimization element (str, optional): optimization problem element: ‘dof’, ‘fobj’, or ‘constraint’. Defaults to “dof”.

dwsimopt.py2dwsim.create_pddx(desc, sim, element='dof', assign=True)

Main function from py2dwsim.py that creates a python-dwsim data exchange channel. It can return a np.array of getter or setter functions from/to the dwsim simulation. The default is to assing the data exchange hub to the SimulationOptimization object passed to this function.

Args:

desc (list): list of string containing [‘dwsim object name as in the simulation’, ‘object attribute’,’phase or component name’, ‘unit’] sim (dwsimopt.SimulationOpimization): object of dwsimopt.SimulationOpimization element (str, optional): optimization problem element: ‘dof’, ‘fobj’, or ‘constraint’. Defaults to “dof”. assign (bool, optional): if True: assign the python-dwsim data exchange channel to the corresponding element in sim, else: return lambda function. Defaults to True.

Returns:

numpy.array: np.array of getter or setter functions from/to the dwsim simulation if assign==False

dwsimopt.tests