CppNoddy  0.92
Loading...
Searching...
No Matches
ArcCircle.cpp
Go to the documentation of this file.
1/// \file ArcCircle.cpp
2/// \ingroup Tests
3/// \ingroup Arclength
4/// A simple arc-length continuation solving the equation
5/// \f[ x^2 + p^2 = 2\,, \f] where \f$p\f$ is a parameter. The solution is obtained by
6/// Newton iteration combined with (pseudo) arclength continuation with
7/// the parameter \f$p\f$. For a (slightly) more serious example see the
8/// FalknerSkan_arc.cpp example.
9
10#include <cassert>
11
12#include <Newton_bundle.h>
13
14namespace CppNoddy
15{
16 namespace Example
17 {
18 /// Define the residual for arc-length continuation of a circle
19 class Arc_problem : public Residual<double>
20 {
21 public:
22 double p;
23
24 Arc_problem() : Residual<double>( 1 ) {}
25
27 {
28 f[ 0 ] = z[ 0 ] * z[ 0 ] + p * p - 2.0;
29 }
30 };
31
32 } // end Example namespace
33} // end CppNoddy namespace
34
35
36using namespace CppNoddy;
37using namespace std;
38
39int main()
40{
41
42 cout << "\n";
43 cout << "=== ARC: continuation of x^2 + p^2 = 2.0 ============\n";
44 cout << "\n";
45
46 // Instantiate the problem
47 Example::Arc_problem residual_problem;
48 residual_problem.p = 1.0;
49
50 const double tol = 1.e-10;
51 // Scalar Newton iteration problem
52 Newton<double> newton( &residual_problem, 8, tol );
53 newton.set_monitor_det( true );
54
55 // initial guess
56 DenseVector<double> state( 1, 1.1 );
57 // initialise a state for arc length cont.
58 newton.init_arc( state, &residual_problem.p, 0.001, 0.1 );
59
60 bool failed = false;
61 for ( int i = 0; i < 100; ++i )
62 {
63 try
64 {
65 try
66 {
67 newton.arclength_solve( state );
68 }
69 catch ( const std::runtime_error &error )
70 {
71 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
72 return 1;
73 }
74 }
75 catch ( const ExceptionBifurcation &bifn )
76 {
77 cout << " Bifurcation detected near x = " << state[ 0 ] << " p = " << residual_problem.p << "\n\n";
78 }
79 if ( abs( pow( state[ 0 ], 2 ) + pow( residual_problem.p, 2 ) - 2.0 ) > tol )
80 {
81 failed = true;
82 cout << " Error = " << pow( state[ 0 ], 2 ) + pow( residual_problem.p, 2 ) - 2.0 << "\n";
83 }
84 }
85
86 if ( failed )
87 {
88 cout << "\033[1;31;48m * FAILED \033[0m\n";
89 return 1;
90 }
91 else
92 {
93 cout << "\033[1;32;48m * PASSED \033[0m\n";
94 return 0;
95 }
96}
int main()
Definition: ArcCircle.cpp:39
@ 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.
Definition: ArcCircle.cpp:26
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