Opale
  presentation
  news
  faq
  docs
  team
  download
  Modules
 
2d
 
3d
  ode
 
  presentation
  examples
  documentation
  links
  matrix
 
parser
Applications
Bugs
 

Module examples

You can use this module in two ways.

Direct use of module classes

You can directly use module classes in a Java program. Let's suppose we wish to solve the following problem:

for each t in [0;1], y'(t) = y(t)
y(0) = 1

First of all, let's create a problem, then an Euler scheme (explicit in our case) by precising number of time steps and linking to the problem the scheme, the initial condition and the equation (to have a lighter and more readable program, we are using internal class mecanism). Then, you can solve the problem by calling solve(). Here is a way to do it in the next program :


import opale.tools.*;  
import opale.mathtools.*;  
import opale.ode.*;  
import opale.ode.scheme.*;  

public class exemple  
{
	  
  public static void main(String[] arg)  
  {  
     Problem pb = new Problem();  
     ExplicitEuler ts = new ExplicitEuler();  
     ts.setNstep(100);
     DVect cd = new DVect(1);  
     cd.set(0,1);  
     pb.setInit(cd);  
     pb.setEqn(new Equation() {   
                   public int dim() {  return  1 ; }
		   public DVect derivs(double t, DVect x) {return x;}    
		   }   
		);  
     pb.setTS(ts);  
     pb.solve(); 
     System.out.println(pb.printSol()); 
   }  
}  

You can use ODE in another way : ODE data files which allow to read/write problems in a fixed format.

Data files

With data files you can save/read a problem in/from a text file and then solve problems.

Keep in mind that data sets have only a meaning when the problem dimension is included from 1 to 3. The reason is simple : the equation interpreter used in Opale can read only variables t, x, y, z in a text format file.

A data set is a text file containing equation descriptions, time schemes and problems to solve. Its structure is simple, look at by yourself :

Equation eq
{
	f1(t,x,y,z)= '3*t'
	f2(t,x,y,z)= '3'
	f3(t,x,y,z)= '1'
}

ExplicitEuler sc
{
	tmin 0
	tmax 1
	N 100
}

Problem pb
{
	dim 3
	sch sc
	eqn eq
	y0 1 1 2
}

We have 3 blocks describing first the equation, then the time scheme and at last the problem to solve. Each block contains at the beginning the object type name which will be described below (Equation, ExplicitScheme or Problem), followed by an id chosen by the user (eq, sc, pb).

Let's see how to use them in a Java program. We have already written the previous data file in file1.ode and we want to write a program able to read this file to solve it. It should be like that :


import opale.ode.*;
import opale.ode.scheme.*;
import opale.tools.*;


public class file
{

  public static void main(String[] arg)
  {
   
   try
   {
     ODE ode = new ODE();
     StreamReader rf = new StreamReader("file1.ode");
     ode.read(rf);
     ode.solve();
     System.err.println(((Problem) ode.getObject("pb")).printSol());
     
     rf = new StreamReader("file2.ode");
     ode.clear();
     ode.read(rf);
     ode.solve();
     System.err.println(((Problem) ode.getObject("pb_ee")).printSol());
	
   }
   catch(java.io.IOException e)
   {}	
   catch(InvalidFormatException e)
   {System.err.println(e);}	
   }
}

Let's focus on a new class : ODE which encaps an ODE module object set. To read a data file, you must create a ODE type object and call its method read(StreamReader). ODE object will then create objects of type Equation, TimeScheme and Problem. You can after access to them thru ODE method ObjectODE getObject(String id) where id is the object identifier (name given in the data file). To solve the problem, you just need to call solve() which will solve each problem (in our case only one).

GUI

It's now possible to use a program build directly on ODE module. For example, the applet AODE, or the software GEOODE.
Here is the applet AODE :

Module evolution

ODE module is by design easy to modify. Future scheduled developments are :

  • new schemes, in particular the family Runge & Kutta
  • multi-step schemes
  • differential systems solving kernel

A last example

To finish, let's see the display of a problem whole processed by Opale tools : it's Van der Pol problem solved by ODE module and displayed by 2D module. Look at the source file.


van

Opale Team : January 31 2004 23:14:10.






valid xhtml image