Dependable algorithms for nonideal vapor-liquid equilibrium calculations are essential for effective process design, simulation and optimization. At present, the inside-out formulation
for flash calculations serves as the basis for many of the algorithms used by process simulation software due to its robustness with respect to initialization and inexpensive computational cost. However, the original inside-out algorithm will fail if the specified conditions lead to a single-phase result, as the solution is constrained to obey equilibrium relationships which are only valid in the two-phase region. While heuristic modifications of the algorithm have shown effectiveness in allowing process simulators to converge to single-phase solutions, 
these provide no guarantee of success. Such behavior is particularly undesirable in a process simulation/optimization problem where flash calculations must be performed on streams where the phase regime at the solution is not known a-priori.
To address these issues, we present a modification of the classical inside-out algorithm, which features an additional nonsmooth equation in the inner loop to relax equilibrium conditions when necessary and a modified scheme for updating the outer loop variables. Additional nonsmooth equations are also employed in the outer loop to avoid numerical issues and nonphysical solutions, such as those needed to identify the correct compressibility factor roots from cubic equations of state. These modifications guarantee existence of a solution that is physically correct, regardless of the number of phases present. The nonsmooth subproblems are efficiently solved with a linear-programming based Newton method
supplied with automatically calculated elements of generalized derivatives,
while the outer loop may be converged either by a similar nonsmooth Newton-type method or simply by successive substitution. Numerical results for simulations involving different flash types and property packages are shown, highlighting the capability of the algorithm to handle both two-phase and single-phase behavior robustly and efficiently. This flash module can also readily be included as a subroutine in more complex problems, since desirable properties of the generalized derivative elements and our nonsmooth framework allow objects which behave in the same way as classical derivatives to be passed around a flowsheet for use in Newton-type methods for simulation and optimization.
 J. F. Boston and H. I. Britt, â??A radically different formulation and solution of the single-stage flash problem,â? Computers & Chemical Engineering, Vol. 2, pp. 109-122, 1978.
 V. S. Parekh and P. M. Mathias, â??Efficient flash calculations for chemical process design â?? extension of the Boston-Britt â??Inside-outâ? flash algorithm to extreme conditions and new flash types,â? Computers & Chemical Engineering, Vol. 22, No. 10, pp. 1371-1380, 1998.
 F. Facchinei, A. Fischer and M. Herrich, â??An LP-Newton method: nonsmooth equations, KKT systems, and nonisolated solutions,â? Mathematical Programming, Vol. 146, pp. 1-36, 2014.
 K. A. Khan and P. I. Barton, â??A vector forward mode of automatic differentiation for generalized derivative evaluation.â? Optimization Methods & Software, Vol. 30, No. 6, pp. 1185-1212, 2015.