20.07.2015 Views

PhD Thesis - staffweb - University of Greenwich

PhD Thesis - staffweb - University of Greenwich

PhD Thesis - staffweb - University of Greenwich

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPENDIX 2 : Journal Paper "Case Study : An Incremental Approach to Re-Engineeringa Legacy FORTRAN C.F.D. Code in C++", Ewer J., Knight B. and Cowell D.,Advances in Engineering S<strong>of</strong>tware, Vol. 22, pp 153-168, 1995perform some function or uses many intermediate stages for calculating some property. Inthe example code fragment (Figure 1) the routines HCSOLV and LINRLX demonstrate thedifferent levels <strong>of</strong> abstraction mixed together. HCSOLV actually takes flow properties,physical properties and previous conditions to calculate the new values <strong>of</strong> enthalpy forevery cell <strong>of</strong> the domain. The HCSOLV routine was only called once in the whole code.Conversely LINRLX merely added a fraction <strong>of</strong> the difference between an old and newvalue <strong>of</strong> some property and was called from many places within the code. It was concludedthat HCSOLV was a highly abstracted routine whereas the less abstracted LINRLX was autility routine that should be moved down into HCSOLV. The simple assignmentstatements were inappropriately located and should be moved into adjacent routines.Legacy code fragmentIF ( IHEAT ) THENRELAXA = SRELAX(5)RMETHD = VRMETH(5)MITERS = MAXITR(5)FALSET = VFALST(5)CALL HCSOLV(3, RELAXA, ... )CALL SYSRES( ... )SOLERR(5) = RESIDURELAXA = VRELAX(5)CALL LINRLX( ... )VARERR(5) = RESIDURELAXA = VRELAX(8)RMETHD = VRMETH(8)CALL CSOLVT( ... )IF ( ERRINF .EQ. 0 ) STOPVARERR(8) = RESIDUENDIFis problematic becauseLiteral values used and simple assignmentsprior to calling a complex numericalcalculation routine.Highly abstracted routine call.Less abstracted utility routine call.Utility routine call.More low level simple assignments.Call to highly abstract routine.Figure 1 :Mixed levels <strong>of</strong> abstraction.- Inflexible memory usage. FORTRAN-77 array sizes must be statically declared at compiletime. This limits the flexibility <strong>of</strong> the code for running problems <strong>of</strong> different sizes. This<strong>of</strong>ten forces a re-compilation <strong>of</strong> the system for the specific problem to be run. This wasparticularly true <strong>of</strong> the un-structured mesh code where a few cells with a high number <strong>of</strong>faces greatly increased the storage requirements <strong>of</strong> all cells.FORTRAN codeSOLTYP(1) = 5K = K + 0.37777 * (...)is problematic because:The SOLTYP array holds the solver types but the index1 and solver type 5 could relate to anything. Theintended meanings must be found elsewhere in the code.Explicit values used in numerical algorithmsgive no indication <strong>of</strong> the purpose <strong>of</strong> the values used.Figure 2 :Use <strong>of</strong> literal constants.- Excessive use <strong>of</strong> literal constants. Much <strong>of</strong> the meaning <strong>of</strong> CWNN was hidden by the use<strong>of</strong> literal constants. Future code developers would have little understanding <strong>of</strong> what theseAppendix 11.2 Page 142-7 7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!