CppNoddy  0.92
Loading...
Searching...
No Matches
ArcTranscritFold.cpp
Go to the documentation of this file.
1/// \file ArcTranscritFold.cpp
2/// \ingroup Tests
3/// \ingroup Arclength
4/// Solve the nonlinear scalar residual problem
5/// \f[ R \equiv (x - 3)( (x-2)^2 + (p-4) ) = 0 \f]
6/// by arc-length continuation from the starting solution
7/// \f$ x=0, p=0 \f$. There is a limit point \f$ x=2, p =4 \f$ and a
8/// transcritical bifurcation \f$ x =3, p=3 \f$ on the computed branch of
9/// solutions, both of which should be flagged through an exception being
10/// raised. The Example will fail if two bifurcations are not found.
11
12#include <cassert>
13
14#include <Newton_bundle.h>
15
16namespace CppNoddy
17{
18 namespace Example
19 {
20 /// Define the residual for arc-length continuation
21 class Arc_problem : public Residual<double>
22 {
23 public:
24 double p;
25 double eps;
26
27 Arc_problem() : Residual<double>( 1 ) {}
28
30 {
31 f[0] = ( z[0] - 3 ) * ( ( z[0] - 2 ) * ( z[0] - 2 )
32 + ( p - 4 ) ) + eps;
33 }
34 };
35
36 } // end Example namespace
37} // end CppNoddy namespace
38
39
40using namespace CppNoddy;
41using namespace std;
42
43int main()
44{
45
46 cout << "\n";
47 cout << "=== ARC: Scalar continuation and bifn detection =====\n";
48 cout << "\n";
49
50 // Instantiate the problem
51 Example::Arc_problem residual_problem;
52 residual_problem.p = 0.0;
53 residual_problem.eps = 0.0;
54
55 const double tol = 1.e-10;
56 // Scalar Newton iteration problem
57 Newton<double> newton( &residual_problem, 8, tol );
58 newton.set_monitor_det( true );
59 // initial guess
60 DenseVector<double> state( 1, 0.1 );
61 // initialise a state for arc length cont.
62 newton.init_arc( state, &residual_problem.p, 0.01, 0.5 );
63
64 // output for the data
65 std::string dirname("./DATA");
66 mkdir( dirname.c_str(), S_IRWXU );
67 TrackerFile my_file( "./DATA/Trans_Fold.dat" );
68 my_file.push_ptr( &residual_problem.p, "parameter" );
69 my_file.push_ptr( &state, "system state" );
70 my_file.header();
71 my_file.precision( 8 );
72
73 unsigned n_bif( 0 );
74 for ( int i = 0; i < 100; ++i )
75 {
76 try
77 {
78 try
79 {
80 newton.arclength_solve( state );
81 }
82 catch (const std::runtime_error &error )
83 {
84 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
85 return 1;
86 }
87 }
88 catch (const ExceptionBifurcation &bifn )
89 {
90 cout << " Bifurcation detected near x = " << state[0] <<
91 " p = " << residual_problem.p << "\n\n";
92 ++n_bif;
93 }
94 my_file.update();
95 }
96
97 if ( n_bif != 2 )
98 {
99 cout << "\033[1;31;48m * FAILED \033[0m\n";
100 return 1;
101 }
102 else
103 {
104 cout << "\033[1;32;48m * PASSED \033[0m\n";
105 return 0;
106 }
107}
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
void precision(unsigned prec)
Definition: TrackerFile.cpp:76
void push_ptr(double *scalar, std::string desc="")
Definition: TrackerFile.cpp:27
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt