Skip to content

Cleanup of SubDyn module#351

Merged
rafmudaf merged 7 commits intoOpenFAST:devfrom
ebranlard:f/flexsub
Oct 30, 2019
Merged

Cleanup of SubDyn module#351
rafmudaf merged 7 commits intoOpenFAST:devfrom
ebranlard:f/flexsub

Conversation

@ebranlard
Copy link
Contributor

@ebranlard ebranlard commented Oct 24, 2019

Complete this sentence
THIS PULL REQUEST IS READY TO MERGE

Feature or improvement description

Removed about 1500 lines in two of the main SubDyn files, for code readability. I'll be working on a important re-write of the SubDyn module, so I'd like to commit this before I start doing updates to the code.

Most of the lines removed were gained from using a more concise error handling (see #272), and gathering copy-pasted calls into "contained"subroutines at the end. The input file routine for instance is significantly more condensed and readable. Note that I usually use the concise error handling on parts of the code that are only called "once", to limit additional overhead.

Automated test results

I've run 5 different SubDyn test cases. Hopefully the regression test will capture that as well.

Below is an example of the subfunctions I usually introduce at the end of a routine

   LOGICAL FUNCTION Check(Condition, ErrMsg_in)
        logical, intent(in) :: Condition
        character(len=*), intent(in) :: ErrMsg_in
        Check=Condition
        if (Check) call Abort(' Error in file '//TRIM(SDInputFile)//': '//trim(ErrMsg_in))
   END FUNCTION Check

   LOGICAL FUNCTION Failed()
        call SetErrStat(ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'SD_Input') 
        Failed =  ErrStat >= AbortErrLev
        if (Failed) call CleanUp()
   END FUNCTION Failed

   SUBROUTINE Abort(ErrMsg_in)
      character(len=*), intent(in) :: ErrMsg_in
      CALL SetErrStat(ErrID_Fatal, ErrMsg_in, ErrStat, ErrMsg, 'SD_Input');
      CALL CleanUp()
   END SUBROUTINE Abort

   SUBROUTINE CleanUp()
      CLOSE( UnIn )
      IF (Echo) CLOSE( UnEc )
   END SUBROUTINE

@ebranlard ebranlard requested a review from rafmudaf October 24, 2019 17:49
@bjonkman
Copy link
Contributor

I'd prefer the Abort() subroutine be called something else since there is a built-in portability routine called abort: https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-abort

@ebranlard ebranlard changed the title Clean of SubDyn module Cleanup of SubDyn module Oct 24, 2019
@ebranlard
Copy link
Contributor Author

ebranlard commented Oct 24, 2019

Oh, right, I'll change that! I've replaced it with Fatal.

@ebranlard ebranlard force-pushed the f/flexsub branch 2 times, most recently from 4231be2 to ae6d379 Compare October 25, 2019 14:26
ErrMsg = 'Invalid FEMMod in AssembleKM'
RETURN
ENDIF
! for current application
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebranlard Are these if-statements correct? At least the error messages may not be...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm questioning because the original code allowed FEMMod 1, 2, 3 or 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only 1 and 3 are implemented so far. These if statements were located in a for loop (line 688 of the old code), and as Bonnie noted, these could be put outside.

CALL AllocAry( Ke, NNE*6, NNE*6 , 'Ke', ErrStat2, ErrMsg2); CALL SetErrStat ( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'AssembleKM' ) ! element stiffness matrix
CALL AllocAry( Me, NNE*6, NNE*6 , 'Me', ErrStat2, ErrMsg2); CALL SetErrStat ( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'AssembleKM' ) ! element mass matrix
CALL AllocAry( FGe, NNE*6, 'FGe', ErrStat2, ErrMsg2); CALL SetErrStat ( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'AssembleKM' ) ! element gravity force vector
CALL AllocAry( nn, NNE, 'nn', ErrStat2, ErrMsg2); CALL SetErrStat ( ErrStat2, ErrMsg2, ErrStat, ErrMsg, 'AssembleKM' ) ! node number in element array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nn is used later but not allocated. Is this ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I allocated it line 484 of the new code. A lot of the code assumes that the number of nodes is 2, and I don't think we'll support higher number of nodes anytime soon. In fact I'll likely have to get rid of this variable in the next implementation.

Copy link
Collaborator

@rafmudaf rafmudaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked over all changes and everything looks good to me. @ebranlard Thanks a lot!

@rafmudaf
Copy link
Collaborator

What do you think about replacing all older Fortran number comparisons (i.e. .LT.) with the more modern version: <? Currently, there is mixed usage throughout SubDyn and OpenFAST.

@rafmudaf rafmudaf self-assigned this Oct 30, 2019
@andrew-platt
Copy link
Collaborator

Sounds reasonable to me to change the < and other symbols. I don't know that I would bother changing them over all modules, but maybe in modules you happen to be working on.

@rafmudaf
Copy link
Collaborator

@andrew-platt I was thinking just in SubDyn since so many formatting changes are already here

@ebranlard
Copy link
Contributor Author

ebranlard commented Oct 30, 2019

I've changed these signs in my recent commit.

@rafmudaf
Copy link
Collaborator

The SubDyn related tests pass on Eagle:

(/home/rmudafor/.conda-envs/openfast) >>eagle@~/Development/openfast/build $ ctest -j 3 -L subdyn
Test project /home/rmudafor/Development/openfast/build
    Start 20: 5MW_OC4Jckt_DLL_WTurb_WavesIrr_MGrowth
    Start 19: 5MW_OC3Trpd_DLL_WSt_WavesReg
    Start 18: 5MW_OC3Mnpl_DLL_WTurb_WavesIrr
    
1/3 Test #18: 5MW_OC3Mnpl_DLL_WTurb_WavesIrr ...........   Passed  172.47 sec
2/3 Test #19: 5MW_OC3Trpd_DLL_WSt_WavesReg .............   Passed  496.60 sec
3/3 Test #20: 5MW_OC4Jckt_DLL_WTurb_WavesIrr_MGrowth ...   Passed  1152.27 sec

100% tests passed, 0 tests failed out of 3

Label Time Summary:
aerodyn15    = 1821.34 sec*proc (3 tests)
elastodyn    = 1821.34 sec*proc (3 tests)
hydrodyn     = 1821.34 sec*proc (3 tests)
openfast     = 1821.34 sec*proc (3 tests)
servodyn     = 1821.34 sec*proc (3 tests)
subdyn       = 1821.34 sec*proc (3 tests)

Total Test time (real) = 1152.31 sec

@rafmudaf rafmudaf merged commit 7714d34 into OpenFAST:dev Oct 30, 2019
@ebranlard ebranlard mentioned this pull request Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants