mdolab / mdolab/adflow

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

Open
#133 0 comments 0 reactions 2 assignees View on GitHub

@joanibal is already working on this.

Since Mar 19, 2021.

good first issue
Dominant language
Fortran
Stars
332
Forks
124
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.