~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to demo/ode/homotopy/simple/main.cpp

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2005 Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// First added:  2005-02-03
 
5
// Last changed: 2006-07-04
 
6
//
 
7
// This example demonstrates the homotopy for finding
 
8
// all solutions of a system of polynomial equations
 
9
// for a couple of simple test systems taken from
 
10
// Alexander P. Morgan, ACM TOMS 1983.
 
11
 
 
12
#include <dolfin.h>
 
13
 
 
14
using namespace dolfin;
 
15
 
 
16
class Quadratic : public Homotopy
 
17
{
 
18
public:
 
19
 
 
20
  Quadratic() : Homotopy(1) {}
 
21
 
 
22
  void F(const complex z[], complex y[])
 
23
  {
 
24
    y[0] = 1.0 - z[0]*z[0];
 
25
  }
 
26
  
 
27
  void JF(const complex z[], const complex x[], complex y[])
 
28
  {
 
29
    y[0] = - 2.0*z[0]*x[0];
 
30
  }
 
31
 
 
32
  unsigned int degree(unsigned int i) const
 
33
  {
 
34
    return 2;
 
35
  }
 
36
 
 
37
};
 
38
 
 
39
class Cubic : public Homotopy
 
40
{
 
41
public:
 
42
 
 
43
  Cubic() : Homotopy(2) {}
 
44
 
 
45
  void F(const complex z[], complex y[])
 
46
  {
 
47
    y[0] = 4.0*z[0]*z[0]*z[0] - 3.0*z[0] - z[1];
 
48
    y[1] = z[0]*z[0] - z[1];
 
49
  }
 
50
  
 
51
  void JF(const complex z[], const complex x[], complex y[])
 
52
  {
 
53
    y[0] = 12.0*z[0]*z[0]*x[0] - 3.0*x[0] - x[1];
 
54
    y[1] = 2.0*z[0]*x[0] - x[1];
 
55
  }
 
56
 
 
57
  unsigned int degree(unsigned int i) const
 
58
  {
 
59
    if ( i == 0 )
 
60
      return 3;
 
61
    else
 
62
      return 2;
 
63
  }
 
64
 
 
65
};
 
66
 
 
67
int main(int argc, char* argv[])
 
68
{
 
69
  dolfin_init(argc, argv);
 
70
 
 
71
  dolfin_set("ODE method", "cg");
 
72
  dolfin_set("ODE order", 1);
 
73
  dolfin_set("ODE tolerance", 0.05);
 
74
  dolfin_set("homotopy monitoring", true);
 
75
  dolfin_set("homotopy randomize", false);
 
76
 
 
77
  Quadratic quadratic;
 
78
  quadratic.solve();
 
79
 
 
80
  //Cubic cubic;
 
81
  //cubic.solve();
 
82
  
 
83
  return 0;
 
84
}