adflow icon indicating copy to clipboard operation
adflow copied to clipboard

Convert some pyADflow options to alwaysRealType to get simpler code in complex mode.

Open anilyil opened this issue 4 years ago • 0 comments

Description of feature

Currently we can only pass pyADflow options that are defined as float in Python to the realType in Fortran. This is because of the limitation of the current state of the .pyf preprocessor. Ideally, there are several python-level options that should be passed as alwaysRealType due to how they are used inside Fortran. For most of these, we have extra real() checks in Fortran and complex mode, but if we passed these to Fortran as alwaysRealType, we would be able to remove these checks. Furthermore, this leaves some room for error where the float variables may result in a non-zero complex part, though I never ran into this up to now.

Potential solution

The pyf_preprocessor.py file at https://github.com/mdolab/adflow/blob/master/src/f2py/pyf_preprocessor.py is responsible from parsing the preprocessor. We need to add the case for alwaysRealType in the check here: https://github.com/mdolab/adflow/blob/master/src/f2py/pyf_preprocessor.py#L75

@joanibal has an implementation of this in his dev branch: https://github.com/mdolab/adflow/compare/master...joanibal:dev#diff-2674555147d45ec975151530704950e671ebb3e8f70d0333a2bee0af06ad0750

The modification of the relevant part of the code looks like this:

            if 'real(kind=realtype)' in orig_lines[i]:
                if mode == 'real':
                    orig_lines[i] = orig_lines[i].replace('kind=realtype','kind=8')
                else:
                    orig_lines[i] = orig_lines[i].replace(
                        'real(kind=realtype)','complex(kind=8)')

            if 'real(kind=alwaysrealtype)' in orig_lines[i]:
                orig_lines[i] = orig_lines[i].replace('kind=alwaysrealtype','kind=8')

After we make this change to the pyf preprocessor, we also should update all of the options used as always real but defined as realType in the Fortran level to use the alwaysRealType instead of the realType. These include options like convergence tolerances, CFL numbers, etc.

anilyil avatar Mar 19 '21 08:03 anilyil