INL/CON-07-13373
Dr. George L Mesina (INL)Joshua Hykes (PSU), Riley Cumberland (UMR)Donna Guillen (INL)
STREAMLINING OF RELAP5-3D
RELAP5 International User SeminarNov 4-6, 2007
05-GA
Outline
• Motivation and overview of Streamlining
• History of RELAP5-3D developments
– Impact of these developments
• Streamlining Algorithm
• Valuation of Streamlining
05-GA
Motivation for Streamlining
• Something you do BEFORE verification or validation
• Improves source code and shortens time for V&V
Verification
Source code
Validation
DACode implements what documents say.
Code calculations are correct.
Improved code
05-GA
Streamlining for Legacy Codes
• Legacy codes
– Successful applications, in active use, developed over the course of many years or even decades.
• Some examples
– RELAP5, TRAC/TRACE, CATHARE, RETRAN, COBRA, CONTAIN, MELCOR, MCNP
– Model (portion or whole) nuclear plant
– In use for over a decade
– Most still undergoing development
05-GA
Some Legacy Code Common Issues
• Extension of applicability beyond original design
• Many adaptations for operating systems/compilers
• Optimizations for computer architectures
• New features with very different data structures
– Imported/subsumed “library” subprograms
• Numerics improvements often complicate coding
• Multiple different programming styles
• Use of conditional coding
05-GA
Legacy Code Common Difficulties
• Difficult to read and understand
– Especially for new/next-generation developers
• Difficult to maintain and develop
– Maintain
• Adapt to computing industry changes
• Solve reported problems and issue fixes
– Develop - add features needed by code users
• These difficulties can impact co$t and $chedule
05-GA
Purpose of Streamlining
• Increase code readability and understandability
• Reduce time and cost of maintenance and development
• This will increase code/team longevity
– Adapt to computer industry continual changes
– Add new/young programmers to team
05-GA
RELAP5-3D Development History
Version Capability Added Affects
MOD1 Small Break LOCA physics code length
BWR physics code length
Semi-implicit time step numerics complexity
MOD2 6 governing equations numerics *
Nearly-implicit time step numerics complexity
Alternate fluids physics conditional
• At its inception RELAP5 was designed to analyze large break LOCA in a PWR
05-GA
RELAP5-3D Development History
MOD3 Textbook correlations physics numerics
Offtake & CCFL models physics length
vectorize architecture complexity
MOD3.2 NESTLE 3D kinetics physics conditional
3D Hydrodynamics physics conditional
multi-D heat transfer physics conditional
05-GA
RELAP5-3D History, DOE funded
Realtime Parallel processing architecture complexity(simulators)
Vector-parallel solver numerics code length
SIMPORT (GUI) hook architecture complexity
3D PVM coupling architecture complexity
RGUI (3D visualization) architecture code length
Models, components, fluids physics complex, “
• Much more in 3D including: SCDAP, proprietary coding, optimizations, architectural upgrades, etc.
05-GA
Specific Impact of Developments
• Many sections of conditional code
• Too many GO TO statements in some subprograms
• Many subprograms too large (up to 5000 lines long)
• Baggage: obsolete language constructs, machine-specific code, unused sections of code
• Many patches (bug fixes, machine adaptations, etc.)
• Styles of 2 dozen programmers
05-GA
Streamlining Method
• Rework database and source code– Database streamlining presented elsewhere
• Source code streamlining– Create and apply consistent programming style
rules– Transform code into structured programming– Eliminate unused and obsolete sections of code– Simplify complex subprograms– Replace programming “tricks” (workarounds that
overcome language limitations)
05-GA
Streamlining Approach
• Apply FOR_STRUCT commercial restructuring tool to eliminate GO TOs & apply style rules
• Cannot be done directly
– No conditional or non-ANSI standard code (Fortran 77) can be restructured
• Solution: Preprocess – transform – post-process
– Replace or comment out non-standard code
– Preprocessor handles conditional code
– Afterwards restore non-standard & conditional
05-GA
Pre-compiling Conditional Code
• Example of conditional code: Proprietary Code
– Either proprietary code or generic code used
– Sections of proprietary code and generic code are marked by “pre-compiler directives”
• Mark at beginning indicates conditional-kind
• Another indicates end of section
– Pre-compiler removes all sections of one conditional-kind but leaves the alternate
05-GA
High Level Streamlining Approach
05-GA
Some Difficulties and Workarounds
• Combinations of different kinds of conditional code.
– N different kinds => 2N combinations
• Solution: Restructure and carefully recombine
– Use minimal set of combinations << 2N.
• If > 500 lines of source, does not fully restructure
• Solution: Use FOR_STRUCT output as new input
– Iterate three times
05-GA
Automated Streamlining Algorithm
• Marker: a comment placed where a conditional section of code (and directives) must be restored
• Def file: specifies a combination of conditional code
• Test and debug
• Apply process one subprogram at a time
05-GA
Manual Streamlining Necessary
• Some conditional code directives get misplaced by restructuring (automated algorithm).
– Reposition manually after restoration
OR
– Manually create internal subroutine from section of conditional code, including directives.
• Some subprograms are harder to read/understand after restructuring
– Manually rewrite
05-GA
Valuation of Streamlining
Go to statements Before After Ratio
Sub w/ 0 GO TOs 255 386 0.66
Sub w/ 100+ GO TOs
9 1 9
Total GO TOs 6707 3977 1.69
Computed GO TOs 100 7 14.29
Backward GO TOs 822 125 6.32
• Readability measure: reduction of GOTO statements and labels.
– Tangle logic flow paths. Obscure base algorithm.
05-GA
Valuation of Streamlining
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
0 labels 100 ormorelabels
Totallabels
Labelsof
formats
Non-formatlabels
Reduction in Labels
Af ter
Before
05-GA
Valuation of Streamlining
• Improvements from streamlining
– Uniform style rules applied
– Measurable reduction in GO TO statements and labels
– No dead code
– Use of internal subroutines
• These result in logic flow paths being easier to trace
– Often reduce the number of logic flow paths
• Enhance readability and understandability
05-GA
Valuation of Streamlining
• Streamlining time (relap & envrl): About 3/4 year
– 28 weeks by summer interns
– 12 weeks (initial work and mentor supervision)
• Effect on size: slightly fewer (0.5%) lines of code
– No dead code, shorter rewritten sections
• Effect on code portability
– Fewer ANSI-standard obsolescent constructs
• Effect on code calculations and runtime
– None
05-GA
Conclusion
• Streamlining is a process for legacy codes.
• It improves code readability and understandability in measurable ways
– This can help reduce the time and cost of code maintenance and development
– Should be done before V&V, DA
• It has no effect on code calculations or run time
• It costs comparatively little to enact