CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
ArcCircleVector.cpp File Reference

A simple arc-length continuation solving the vector equation. More...

#include <cassert>
#include <Newton_bundle.h>

Go to the source code of this file.

Classes

class  CppNoddy::Example::Arc_problem
 Define the residual for arc-length continuation of a circle. More...
 

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Functions

int main ()
 

Detailed Description

A simple arc-length continuation solving the vector equation.

\[ x^2 + p^2 = 1\,, y = \sin(x) \]

where $p$ is a parameter. The solution is obtained by Newton iteration combined with arclength continuation with the parameter $p$.

Definition in file ArcCircleVector.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 37 of file ArcCircleVector.cpp.

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}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A vector NEWTON iteration class.
Definition: Newton.h:25

References CppNoddy::Newton< _Type >::arclength_solve(), CppNoddy::ArcLength_base< _Type >::init_arc(), CppNoddy::Example::Arc_problem::p, and CppNoddy::Newton< _Type >::set_monitor_det().

© 2012

R.E. Hewitt