!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
program slos
!
! Description:
!
! SLOS has been adapted from USLOS (unstructured [grid] lines of sight),
! itself an adaptation of LINES_OF_SIGHT and HEMISPHERES_OF_SIGHT, which
! are now superseded by this combination of the two purposes (body-normal
! lines for tangent-slab radiation calculations, or hemispherical lines
! for just one body point at a time) for the 3D structured grid case.
! (See also LINES_OF_SIGHT_2D.)
!
! The volume grid is expected to be right-handed, and for the hemisphere
! case, the y >= 0 half is expected (with x pointing downstream). A single
! layer of grid blocks is assumed (commonly the case for space capsules), so
! that the k = 1 and k = nk planes can be taken to be the inner and outer
! grid surfaces. An off-center body point requires both halves for the
! hemisphere case.
!
! The inner surface is expected to represent a mostly-convex surface. Any
! concavities may cause difficulties with hemisphere lines that encounter
! the body. Ancillary utility ADJUST_HEMISPHERE_LOS is the initial answer
! for such cases.
!
! This version allows for one line of sight per run at an arbitrary direct-
! ion off the body, defined by a cone angle and a clock angle, as needed for
! radio attenuation studies.
!
! Body Point Inputs (one entry per line; trailing comments ignored):
!
! Body-normal (tangent-slab radiation calculation) case:
!
! 0. 0. 0.
! 1.628659741950E-01 5.741545696080E-01 0. ! Nose/cone tangency
! 8.985316209400E-01 1.837811469800E+00 0. ! Cone/shoulder tangency
! : : :
!
! If only one body point is detected, a prompt still allows for the
! tangent-slab case.
!
! Hemispherical lines (full angular integration of radiance) case:
!
! 1.0742 -1.81 1.083 [10.] ! x, y, z[, cone angle]
!
! Only one body point is handled for this case. The optional semi-cone
! angle allows for writing fewer than the full hemisphere's worth of
! lines to avoid unnecessary radiation cone angles outside the viewing
! angle of a radiometer instrument. Note that NEQAIR_INTEGRATION can
! still integrate over a narrower angle than the indicated data angle.
! If the optional angle is omitted, it is taken to be 90 degrees.
!
! Single LOS at an arbitrary direction (for radiation attenutation studies):
!
! In the DPLR coordinate system (body centered, origin at the nose, Ox
! pointing downstream, right-handed), the direction from the body point
! is taken to be defined by a cone angle above Ox and a clock angle
! defined as clockwise from 12 o'clock looking along Ox. Angles are in
! degrees, and should account for any spacecraft Alpha and Beta.
! Both port and starboard halves of the spacecraft volume grid are
! expected (even if Beta = 0.; use REFLECT_BLOCKS if necessary).
!
! 1.0742 -1.81 1.083 cone clock
!
! Input Structured Volume Grid (PLOT3D Format):
!
! Formatted or unformatted multiblock files are handled, and a single layer
! of grid blocks is assumed (normally the case for hypersonic vehicles) so
! that the outer surface of all blocks serves as the shock-aligned boundary
! with which intersections of lines from the body point(s) are calculated.
!
! Outputs:
!
! While the precursors of SLOS discretize the lines of sight with the same
! relative point distributions as found in the nearest off-body grid line,
! this variant follows the USLOS approach of using DPLR-type controls nk,
! d1, and ds2_fraction that are prompted for.
!
! The lines of sight are written to a single multiblock PLOT3D-type file,
! one line per block. These should be checked visually before proceeding
! with radiation calculations. Ensuing procedures will interpolate flow
! data onto the discretized lines of sight and write results compatible with
! the radiation solver. The file name is hard-coded as 'los.g' as part
! of simplifying the original nomenclature.
!
! Method:
!
! > A handful of prompts serve to drive the program -- no control file.
! > Read the indicated body point (x,y,z) file -- one or more points.
! > If a single body point is found, prompt in case hemispherical lines are
! NOT intended.
! > If all body points are on the centerline (y = 0.), the input volume
! grid is assumed to be the starboard (right) half. That half (y > 0.)
! also serves for off-center body-normal lines, but for a hemisphere at
! an off-center body point, a full volume grid is expected, with the
! outer surface closed and convex.
! > Build a search tree from the inner multiblock surface, and search
! for each body point.
! > Generate and store the corresponding unit body-normal vector(s).
! > Build a new search tree from the outer boundary, as needed for line-
! surface intersection calculations.
!
! > Body-normal line case:
! > For each body point B:
! > The body normal unit vector is already in hand.
! > A search interval along the body-normal line for minimizing
! the distance to the outer surface is provided by s = 0 at the
! low end and s = the diagonal of the bounding box for the
! outer surface mesh.
! > The intersection point is then conveniently calculated via
! a 1D minimization w.r.t. distance s from B along the body-
! normal line (INTSEC6).
! > Impose a CFD-type point distribution on the intersected
! interval BP, as needed for interpolated flow field data.
! DPLR-type use of inputs nk, ds1, ds2fraction will suffice.
! > Write the discretized line(s) of sight to the indicated PLOT3D-
! type output file.
!
! > Hemisphere lines of sight case:
! > The vertices of a triangulated unit hemispherical quadrant define
! the lines of sight between the body point and the outer grid
! boundary. The number of uniform points specified along an edge
! determines the resolution. Typically, 25 such points are used,
! giving 650 lines of sight for a centerline body point, or 1300
! lines if the body point is off-center. Centerline points require
! just half the volume data, and the eventual integration over
! solid angle of radiances from the lines of sight can be doubled.
! > Triangulation choice:
! This version of SLOS has the option to read a previously generat-
! ed unit triangulation that the Equal_Area_Triangulation variant
! of the NPOPT_DRIVER framework can now produce. If nedge is spec-
! ified as 25 (say), we look for the file unit_sphere_octant_25.dat
! (likewise for other nedge values). If the file is not found, the
! spherical_triangulation subroutine is employed as originally.
! In principle, the integrations w.r.t. solid angle of radiances
! calculated for each line of sight will be more accurate if the
! solid angle elements are essentially equal, although it is ex-
! pected that the two kinds of triangulation will produce very
! similar results for a given value of nedge.
! > The initial unit quadrant is transformed so that line 1/vertex 1
! corresponds to the body point normal. After The lines for the
! first quadrant are generated, the quadrant is rotated 90 degrees
! about the normal and the next set of lines is generated. Then if
! the body point is off-center, this is repeated twice more.
! > Each intersection involves a 2-point line from the body point
! through a quadrant vertex, of length derived from the bounding
! box of the outer shock surface. This length is overkill for many
! intersection search intervals, but that doesn't matter. Each
! hemisphere line is intersected and discretized as for the body
! normal (tangent-slab) case described above.
! History:
!
! 11/02/2018 D.A.Saunders Started adapting USLOS for the structured case.
! The option for entering body point indices in
! lieu of x/y/z coordinates has been dispensed
! with. Use GU to coarsen a surface grid if
! necessary. Generation of shock-normal lines
! and lines parallel to Ox have also been omitted.
! Use the original LINES_OF_SIGHT for these.
! 11/07/2018 " " Implementation and testing completed.
! 11/09/2018 " " Use 'los.g' for the output file name as part of
! adjusting NEQAIR_Integration to handle the
! original nomenclature and this simplified form.
! 10/04/2019 " " Resetting the lower intersection search interval
! to zero was not being done for each new line.
! Earlier testing must not have encountered any
! intersection failures that are caused by outer
! grid boundaries that are not strictly convex!
! 10/05/2019 " " Failed intersections prompted another way of
! retrying: discretize the part of the line beyond
! the failed solution and evaluate line-surface
! distances from those points; pick the interval
! containing the smallest distance, and redo the
! line-surface intersection. REMEMBER THAT THE
! ARC LENGTH INTERVAL PASSED TO INTSEC6 SHOULD BE
! NORMALIZED BY THE LINE LENGTH IF THAT IS THE
! INTERVAL EXPECTED TO CONTAIN THE INTERSECTION,
! AS IT IS HERE, USING THE BOUNDING BOX DIAGONAL.
! 07/21/2020 " " A "small" tolerance in transform_quadrant was
! too big. Body points near the nose (normally
! not the case for full angular integration)
! produced inaccurate rotation axes for the second
! quadrant of the transformed unit hemisphere.
! This led to irregular heat flux results near the
! heatshield apex on the centerline, now fixed.
! Avoiding a cross product of parallel unit
! vectors (zero length vector) was the root cause.
! 07/26/2020 " " Reluctant special-casing of the body nose point
! that proves pathological in the sense that the
! associated surface grid cell is almost certain
! to be a corner cell for which the existing
! adjustment that forces the body normal to be in
! the symmetry place still doesn't force it to be
! along -Ox as it should be for a body of revolu-
! tion centered on Ox. Remember that we normally
! don't apply the hemisphere LOS method to the
! nose region anyway, but it has been needed as
! part of comparing radiative heat flux results
! with those from a vastly more efficient method.
! 10/08/2020 " " Replace intsec6 with intsec9 as introduced for
! line_surface.f90 (interp3d library) used by the
! Stardust_Lines utility. This packages a retry
! method that is virtually bulletproof.
! 04/12/2021 " " Handle reading of a unit spherical octant tri-
! angulation named unit_sphere_octant_n.dat where
! n = nedge is typically 25. (See above for more
! details.) If the appropriately named file is
! not found, subroutine spherical_triangulation is
! invoked as originally. Not much difference is
! expected to be found in the integrations with
! respect to solid angle subtended at the body
! point, but until the option was provided, we
! could never know ...
! 07/11/2022 " " Installed a new option needed for radio blackout
! predictions: a line of sight in an arbitrary
! direction defined by a cone angle and a clock
! angle appended to the body point x y z.
! 07/13/2022 " " The clock angle was being rotated about Oz when
! it should be about Ox.
! 03/31/2023 " " Use the trigd module for g95 compatibilty.
! 03/08/2024 " " The buffer length of 64 for the body point data
! caused grief! Raise the limit.
! 03/20/2026 " " Made scripts more readable by introducing name-
! list controls in favor of prompts.
!
! Author: David Saunders, AMA, Inc. at NASA Ames Research Center, CA.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!