The second part of the trajectory is optimized by adjusting the velocity component of the initial conditions so that the trajectory ends just outside of Mars' orbit. Then, contrary to how the conjunction to Earth flight path was configured, the initial conditions of the problem must be adjusted so that the spacecraft actually rendezvous with Mars. That is, the starting position of Mars is adjusted by a few days so that the spacecraft and Mars both arrive at the same time when their paths intersect near apoapse of the transfer ellipse.
The first few iterations target Mars' Sphere of Influence (a circle centered at Mars with a radius of about 5.8 E5 Km). Subsequent iterations continue integrating the flight path until it either intersects Mars or goes beyond Mars.
The program output shows both stages of the process - the coarse, heliocentric targeting of the SOI, then the fine geocentric targeting of Mars itself. The integration is stopped as soon as the range to Mars starts increasing. This is the closest point of approach to Mars, and a tangential thrust is applied to put the spacecraft in a circular orbit. The spacecraft must still reach the 100 Km parking orbit, so addtional thrust is added for a simple Hohmann Transfer to the lower orbit.
NOTE: In this "pure" Hohmann scenario, the optimal trajectory begins at the 100 Km parking orbit itself (even though the optimization technique calculates an additional small Hohmann for prior iterations that do not terminate at the parking orbit; the program still needs a total thrust for each pass).
The user defined options allow more complex conditions. One scenario is for the spacecraft to go beyond Mars, to a higher altitude orbit, and to begin the final trajectory from there, slightly behind Mars. The spacecraft has a small gravity assisted
flyby
. Another option allows the periapse of this hyperbola to drop as low as 5 Km above Mars. In either case there will be two thrusts calculated for the maneuver: The large thrust to enter orbit around Mars, and a second small thrust to go to the final 100 Km parking orbit.
The optimization of the user-defined scenarios is more complex than just stopping the integration when the range starts opening. These options are intended to explore the possibility of letting the spacecraft go closer to Mars to take best advantage of Mars' gravity in slowing down the orbit, and adjusting the geometry of the flight path so it's easier to enter a circular orbit around Mars. So, once the range begins opening, the program calculates the total thrust to reach the 100 Km parking orbit at each step of the integrator. The lowest final thrust among these values is saved as the global minimum is the optimal thrust for that particular pass. Additional passes are done until the closest point of approach to Mars on the trajectory is 100 Km (or less, as specified by the user). The lowest total thrust among all these passes is the global minimum for the Mars half of the flight path.