CppNoddy  0.92
Loading...
Searching...
No Matches
ArcCircleVector.cpp
Go to the documentation of this file.
1/// \file ArcCircleVector.cpp
2/// \ingroup Tests
3/// \ingroup Arclength
4/// A simple arc-length continuation solving the vector equation
5/// \f[ x^2 + p^2 = 1\,, y = \sin(x) \f] where \f$p\f$ is a parameter.
6/// The solution is obtained by Newton iteration combined with arclength
7/// continuation with the parameter \f$p\f$.
8
9#include <cassert>
10
11#include <Newton_bundle.h>
12
13namespace CppNoddy
14{
15 namespace Example
16 {
17 class Arc_problem : public Residual<double>
18 {
19 public:
20 // the control parameter
21 double p;
22
23 Arc_problem() : Residual<double>( 2 ) {}
24
26 {
27 f[ 0 ] = 1.0 - std::pow( z[ 0 ], 2 ) - std::pow( p, 2 );
28 f[ 1 ] = z[ 1 ] - std::sin( z[ 0 ] );
29 }
30 };
31 }
32}
33
34using namespace CppNoddy;
35using namespace std;
36
37int main()
38{
39 cout << "\n";
40 cout << "=== ARC: cont of x^2 + p^2 = 1.0, y = sin(x) ========\n";
41 cout << "\n";
42
43 // initial guess
44 DenseVector<double> x( 2, 0.0 );
45 x[ 0 ] = 0.4;
46 x[ 1 ] = 0.4;
47
48 // Instantiate the problem
49 Example::Arc_problem residual;
50 // initialise the parameter
51 residual.p = 0.9;
52 // A Newton object
53 Newton<double> newton( &residual );
54 newton.set_monitor_det( true );
55 newton.init_arc( x, &residual.p, 0.05, 0.1 );
56
57 double tol( 1.e-7 );
58 bool failed = false;
59 for ( int i = 0; i < 400; ++i )
60 {
61 try
62 {
63 try
64 {
65 newton.arclength_solve( x );
66 }
67 catch ( const std::runtime_error &error )
68 {
69 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
70 return 1;
71 }
72 }
73 catch ( const ExceptionBifurcation &bifn )
74 {
75 cout << " Bifurcation detected near x = " << x[ 0 ]
76 << " p = " << residual.p << "\n\n";
77 }
78 if ( abs( pow( x[ 0 ], 2 )
79 + pow( residual.p, 2 ) - 1.0 ) > tol )
80 {
81 failed = true;
82 cout << " Error = " << pow( x[ 0 ], 2 )
83 + pow( residual.p, 2 ) - 1.0 << "\n";
84 }
85 }
86
87 if ( failed )
88 {
89 cout << "\033[1;31;48m * FAILED \033[0m\n";
90 return 1;
91 }
92 else
93 {
94 cout << "\033[1;32;48m * PASSED \033[0m\n";
95 return 0;
96 }
97}
int main()
@ f
Definition: BVPBerman.cpp:15
A shorter bundled include file for Newton iteration problems.
void init_arc(DenseVector< _Type > x, _Type *p, const double &length, const double &max_length)
Initialise the class ready for arc-length continuation.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
Define the residual for arc-length continuation of a circle.
Definition: ArcCircle.cpp:20
void residual_fn(const DenseVector< double > &z, DenseVector< double > &f) const
A blank virtual residual function method.
A vector NEWTON iteration class.
Definition: Newton.h:25
void set_monitor_det(bool flag)
If set then the system will monitor the sign of determinant of the Jacobian matrix and cause an Excep...
Definition: Newton.h:47
void arclength_solve(DenseVector< _Type > &x)
Arc-length solve the system.
Definition: Newton.cpp:98
A base class to be inherited by objects that define residuals.
Definition: Residual.h:15
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt