1

かなりの時間 (数時間) 反復処理を行うソルバーがあり、時間を節約するためにメイン ループからいくつかの if ステートメントを削除しようとしています。

ここで本質的にしようとしているのは、割り当てられたルーチンを指すルーチン updateGhosts を作成することです。このルーチンは、他のいくつかのプロパティとルーチンを含む派生データ型に属しています。setGhosts ルーチンを使用して、updateGhost を ghostOne または ghostTwo に設定します。これは、いくつかの条件を適切に更新するルーチンになります。

いくつかの異なることを試してみましたが、コードをコンパイルする方法を理解できないようです。

簡単にするために、コード サンプルを可能な限り削減しようとしましたが、実際には、型 GridPoint と BlockType にはさらに多くのパラメーターを処理する必要があるため、単純なリファクタリングはオプションではありません。

削減されたコードは次のとおりです。

module BlockModule
  implicit none

  type GridPoint
    real(kind=8) :: x, y, T
  end type GridPoint

  type BlockType
    integer :: BC
    type (GridPoint) :: Points(0:102,0:102)
  contains
    procedure :: setGhosts, updateGhosts
    procedure :: ghostOne, ghostTwo
  end type BlockType

contains
  subroutine setGhosts(this)
    class(BlockType), intent(inout) :: this

    if (this%BC == -1) then
      ! We want to assign updateGhosts to ghostOne.
      this%updateGhosts => this%ghostOne
    else
      ! We want to assign updateGhosts to ghostTwo.
      this%updateGhosts => this%ghostTwo
    end if
  end subroutine

  ! Routine that will be either ghostOne or ghostTwo.
  subroutine updateGhosts(this)
    class(BlockType), intent(inout) :: this
  end subroutine

  ! Routine will do something.
  subroutine ghostOne(this)
    class(BlockType), intent(inout) :: this
  end subroutine

  ! Routine will do something completely different, with same inputs.
  subroutine ghostTwo(this)
    class(BlockType), intent(inout) :: this
  end subroutine
end module

Fortran90/95/03 で別のルーチンを指すようにルーチン名を割り当てるにはどうすればよいですか? (可能な限り古いバージョンが理想的ですが、必須ではありません。) 以前に同様の質問があった場合は申し訳ありません。検索してみましたが、何を探す必要があるのか​​よくわかりません。

読んでくれてありがとう!

4

1 に答える 1