Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nopass to simplify the interface for the user-defined function #1

Open
arjenmarkus opened this issue Aug 16, 2021 · 3 comments
Open

Comments

@arjenmarkus
Copy link

The abstract interface func has two arguments, "me" of type "class(root_solver)" and the proper argument of the function. The first serves no purpose for the evaluation of the function and can actually be suppressed:

procedure(func),pointer, nopass :: f => null()  !! user function to find the root of

This way the interface becomes the same as func2 and unifies the usage.

@jacobwilliams
Copy link
Owner

jacobwilliams commented Aug 19, 2021

The reason for it is so in the object-oriented interface you can put data required by the function in the class. Look at the oo example in the repo.

    type,extends(muller_solver_real64) :: my_solver
        integer :: ifunc = 0
        integer :: n = 1
    end type my_solver
    type(my_solver) :: solver

ifunc and n are used in the function.

In my mind, the oo interface is how it should be used, and the functional one is just a wrapper for simple use cases.

@arjenmarkus
Copy link
Author

arjenmarkus commented Aug 20, 2021 via email

@jacobwilliams
Copy link
Owner

No, since the function interface uses root_solver like so:

  function func(me,x)

    class(root_solver),intent(inout) :: me
    real(wp),intent(in) :: x
    real(wp) :: f

    select type (me)
    class is (my_solver)
      f = me%n * sin(x)
      me%ifunc = me%ifunc + 1
    end select 

  end function func

So the same function works for any method. But, you do have to use the annoying select type construct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants