Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:54:30+00:00 2026-06-04T17:54:30+00:00

I am designing a Fortran code for solving a PDE system. The way it

  • 0

I am designing a Fortran code for solving a PDE system.

The way it is designed right now is that I have a type Variable that has several attributes, the most important of which is the array val that stores the value.

Now I also have a solver class, which would perform calculations on a variable. I figured that passing the whole variable to the solver and working with variable%val each time I want to run it (several thousands of times during an exectution) would be inefficient, so I decided to to define pointer fields in the solver class to bind the to solver to the appropriate variable. For example

program example
    use variable
    use solvers

    type(Variable) T 
    type(Solver) solver_temperature

    !Contructors
    call T%create()
    call solver_temperature%create(T)

    call solver_temperature%solve()
end program example

And the solver module

module solvers
type Solver
    real*8, pointer :: T(:,:)

contains 
    procedure :: create
    procedure :: solve
end type

contains
    subroutine create(this,T)
        type(Solver) :: this
        type(Variable) :: T

        this%T => T%val
    end subroutine
end module

In my program I define different variable for different physical properties and different solvers that are associated with those variables in the way I showed above.

I am new to OOP in general, so my question is if that is a decent design? Especially from a performance point of view. How does this compare with making T just an array and passing it to a subroutine solve in terms of speed? Is there some regular way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:54:33+00:00Added an answer on June 4, 2026 at 5:54 pm

    I’ve been working with the OO features of Fortran for a year or so now, here are some extended comments masquerading as an answer.

    If you are simply concerned with raw execution speed then you are probably, in general (and based on argument and my experience rather than data), better to steer clear of the OO features; but then in many cases the same argument can be made that you are better to steer clear of anything added to the language after FORTRAN77.

    Arguments in favour of OO are stronger when founded on the issues of code design, comprehensibility, extendibility, that sort of thing. If these matter to you then you should be thinking about using the OO features.

    As Vladimir has already commented, there doesn’t seem to be much point in using the variable pointer. Don’t forget that most Fortran implementations do call-by-reference specifically to avoid the effort of copying (large volumes of) data around.

    Personally, I don’t like the way you have defined your type-bound procedure create. I much prefer to implement that sort of operation as a function, so that I can write lines like this:

    t = solver%new()
    

    rather than your

    call T%create()
    

    Note this is a preference of mine, and it’s more a question of style than of efficiency or correctness. I notice that you haven’t declared the intents of the arguments to the subroutine create; perhaps because you’ve only posted a snippet of your code.

    Because OO is relatively new to Fortran (and, arguably, relatively unfamiliar to most people working in the domains where Fortran is widely used) there isn’t much useful material to guide us in adopting it. I would recommend Scientific Software Design. It gives the topic decent coverage and makes the argument about why scientific and engineering programmers should adopt OO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im designing a system where i will have multiple users uploading large amount of
When designing a new system or getting your head around someone else's code, what
Designing code to handle transfers of objects called contractBundles. Have this in the models.py
Designing AIR application which has to have server side push or notification, don't know
Designing an interface with QT4 I have been advised that using multiple Tabs at
Designing forms has always been fun, but getting them to send email on the
When designing a C API for configuring a library/utility, I have a co-worker who
When designing a stock management database system for sales and purchases what would be
When designing a form I have the option of putting a close button at
When designing a web service that will allow the consumer of the service to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.