Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Bo_Q_
Beginner
63 Views

passing additional parameters to RHS function of ODE solver

Jump to solution

Hi,

I am trying to use the Intel's ODE solver to solver a system of equations. Below is the how the RHS function is supposed to be defined (from manual):

subroutine <name>(n, t, y, f)
integer n
double precision t, y(n), f(n)
..................
f(i) = .....
..................
return
end

The problem is I need to pass additional parameters to the RHS function. Is there a way to do that?

Thanks!

Bo

 

0 Kudos
1 Solution
mecej4
Black Belt
63 Views

Declare the additional parameters and variables in a module. USE that module in the main program, and read/assign values to the module variables as needed. In the subroutine that implements the specific ODE, USE the module and access the variables as needed.

For example, you can modify the van der Pol example that is included with the Intel ODE solver to take a parameter K in place of 1.0d6 in the equation: y” - K * [ ( 1 - y*y ) * y’ + K * y = 0. Then, the module contains:

      MODULE PARS_MOD
         double precision :: K
      END MODULE

Add "USE PARS_MOD" to all subprograms that need to set/get the value of K.

In the main program, you can do:

      WRITE(*,'(A)',advance='no')' Enter K : '
      READ (*,*) K

In subroutine rhs_v_d_p, change to

         f(2)=K*((1.d0-y(1)*y(1))*y(2)-y(1))

and, in subroutine jacmat_v_d_p, change to

         a(2,1)=-K*(1.d0+2.d0*y(1)*y(2))
         a(2,2)= K*(1.d0-y(1)* y(1))

You will probably need to deactivate all the result checks, since they use pre-computed results that are correct only for the specific case K = 1.0d6.

 

View solution in original post

1 Reply
mecej4
Black Belt
64 Views

Declare the additional parameters and variables in a module. USE that module in the main program, and read/assign values to the module variables as needed. In the subroutine that implements the specific ODE, USE the module and access the variables as needed.

For example, you can modify the van der Pol example that is included with the Intel ODE solver to take a parameter K in place of 1.0d6 in the equation: y” - K * [ ( 1 - y*y ) * y’ + K * y = 0. Then, the module contains:

      MODULE PARS_MOD
         double precision :: K
      END MODULE

Add "USE PARS_MOD" to all subprograms that need to set/get the value of K.

In the main program, you can do:

      WRITE(*,'(A)',advance='no')' Enter K : '
      READ (*,*) K

In subroutine rhs_v_d_p, change to

         f(2)=K*((1.d0-y(1)*y(1))*y(2)-y(1))

and, in subroutine jacmat_v_d_p, change to

         a(2,1)=-K*(1.d0+2.d0*y(1)*y(2))
         a(2,2)= K*(1.d0-y(1)* y(1))

You will probably need to deactivate all the result checks, since they use pre-computed results that are correct only for the specific case K = 1.0d6.

 

View solution in original post

Reply