!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
program shock_stand_off
! Original Description (Body Normal Approach):
!
! For a structured grid and function file containing just the function used
! to detect shock location (normally Temperature), calculate shock stand-off
! distance at every inner surface point. A single function is stipulated
! because the normals off the surface may cross block boundaries, meaning
! all the volume data must be stored. This precludes use of the volume data
! processed by the boundary layer edge detection utility, results from which
! the stand-off distances are to be merged with in a subsequent step that
! requires the stand-off results to be saved in Tecplot surface file form.
!
! This version handles 2-D cases as well. It is most expedient to turn a
! single plane of data into two parallel planes then apply the existing
! 3-D technique.
!
! Use a cut-off x (normally) to substitute zero distances for body points
! in the wake.
!
! Revised Description (Shortest Distance Approach):
!
! Instead of calculating distances along body-normal vectors, calculate the
! shortest distances from the body points to the shock envelope. If the
! dot-product of such a distance vector with the body normal vector is
! negative, the shock is blocked by the body, so zero out the stand-off.
! Lines that are found not to be very close to free-stream at the outer
! boundary are interpreted as being in the wake, and their stand-offs are
! zeroed out as well.
!
! The outer boundary of the grid is assumed to be aligned well enough with
! the shock that shortest distances to the outer boundary are along the same
! directions as shortest distances to the shock, which are determined after
! the initial locations of the best outer boundary points.
!
! Initial assumptions (probably generalizable, but they may never need to be):
!
! o The structured volume grid contains one layer of blocks, with k = 1
! at the wall. This simplifies determination of the inner and outer
! boundary patches. (To overcome these restrictions, one could use the
! boundary condition data employed by the relevant flow solver.)
!
! o For the 2-D case, assume j = 1 at the wall initially. The program
! converts 2-D inputs to 3-D form with k = 1 at the wall.
!
! Strategy:
!
! o Read the entire volume data and extract the inner and outer boundaries
! as multiblock surface grids.
!
! o In order to handle 2-D cases transparently, we need to parse the
! grid file header, so 2-D files must be formatted.
!
! o For a 2-D case, the 3rd coordinates are assumed to be missing, even
! though this is incompatible with the I/O package used here.
!
! o For a 2-D case, replicate the given plane of data with a parallel
! plane close apart in the third dimension, then proceed as for 3-D.
!
! o Build a search tree from the outer boundary.
!
! o For each inner surface point:
!
! > (Originally:) Construct a two-point line normal to the wall with
! length that of local radial line. This should be at least as long
! as the straight line distance to the outer boundary. (If x <= input
! cutoff value, set the stand-off to zero and go the next body point.)
! Intersect the line with the outer boundary and store the new end pt.
!
! > (Revised:) Find the shortest distance from the body point to the
! outer boundary. The ADT scheme for searching the outer boundary
! surface produces the point of interest by "interpolating" the surface
! at the body point. [It always provides the cell and associated
! interpolation coefficients for the closest possible point not outside
! the surface.]
!
! o Release the outer surface search tree & build one for the volume grid.
!
! o For each two-point line between the body and the outer boundary, impose
! a radial-grid-line-like distribution on it. For k = nk, nk-1, ...,
! interpolate the flow quantity until a spike is apparent, making further
! (relatively costly) interpolations redundant.
!
! > (Originally:) Linearly interpolate to find the arc length where the
! temperature is (say) 1.1 x free-stream to define the stand-off dist-
! ance.
!
! > (More precise possibility:) Find the temperature spike at the shock
! precisely by maximizing the non-monotonic spline interpolation, and
! return the associated arc length as the stand-off distance. This
! refinement is now considered overkill in view of the good agreement
! of the original and revised methods on a forebody and the inevitable
! raggedness of (parts of) the structured surface formed by the initial
! shortest distance envelope, on the lee-side in particular. A good
! check of the latter is to use SURFACE_INTERP to interpolate the outer
! grid boundary at each inner grid boundary point. This produces the
! best (closest) points not outside the outer boundary, just as the new
! stand-off strategy does, and for the SRL test case, the results are
! indistinguishable. (SURFACE_INTERP needs to be faked out by treating
! (x,y,z) as three functions to be interpolated. It doesn't matter
! that the result is not a smoothly varying surface: for body points
! along the lee-side aft body, the shortest distance locations at the
! outer boundary are all much the same because the aft cone is roughly
! perpendicular to the shock when Alpha is (say) 20°.)
!
! o Save results in Tecplot form for possible merging with BLAYER results
! via the MERGE_FILES utility.
!
! History:
!
! 04/20/07 D.A.Saunders Initial adaptation of LINES_OF_SIGHT and the other
! single-function tools originally strung together
! to provide data for QRAD. They are better suited
! to a thinned set of results.
! 05/08/07 " " Another XYZ convention forced a new control input.
! 08/28/09 " " Option to handle 2-D cases added transparently.
! 08/08/13 " " All ADT variants have been merged into a module
! " " with generic build_adt and search_adt interfaces.
! 08/28/17 " " Cases from John Theisinger at NASA LaRC were so
! tightly aligned that uniform spacing along the
! discretized body-normal profiles was a bad choice.
! Worse: at low Mach, with little or no chemistry,
! there may not be a temperature spike--just a
! rise/no obvious drop, so seek the shock onset
! (rise) rather than a drop that may not be there.
! This precludes using Mach as the function.
! Mach, in retrospect, with a different search,
! would have been preferable.
! 08/30/17 " " Followed John's suggestion of using 1.1xTinf
! to interpolate a stand-off distance smoothly.
! 06/09/24 " " Surface points exceeding the cutoff value don't
! need to calculate intersections with the outer
! boundary.
! 06/10/24 " " Replaced intsec6 call with intsec9: same except
! for an additional first argument (line number) but
! includes the backup search for failures that the
! cutoff should normally prevent.
! 04/02/25 - " " Revised strategy should handle a tumbling capsule
! 04/12/25 (as for launch-abort studies with angles of attack
! anywhere between 0° and 180°). [There is no longer
! a need for some cut-off X that wouldn't make sense
! for a tumbling capsule anyway.]
! 04/13/25 " " A tumbling Dragonfly capsule case at 180° Alpha
! showed that block(1)%q(1,1,1,nk) isn't necessarily
! safe for the free stream temperature.
!
! Author: David Saunders, ELORET Corporation/NASA Ames Research Center, CA
! Subsequently with AMA, Inc. at NASA ARC.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!