CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
BVPTroesch.cpp File Reference
#include <BVP_bundle.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Classes

class  CppNoddy::Example::Troesch_equation< _Type, _Xtype >
 Define the harmonic equation by inheriting the Equation base class. More...
 
class  CppNoddy::Example::Troesch_left_BC< _Type >
 
class  CppNoddy::Example::Troesch_right_BC< _Type >
 

Namespaces

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

Enumerations

enum  { f , fd }
 

Functions

int main ()
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
fd 

Definition at line 13 of file BVPTroesch.cpp.

13{f, fd };
@ fd
Definition: BVPTroesch.cpp:13
@ f
Definition: BVPTroesch.cpp:13

Function Documentation

◆ main()

int main ( )

Definition at line 75 of file BVPTroesch.cpp.

76{
77 cout << "\n";
78 cout << "=== BVP: finite-difference solution of Troesch eqn ==\n";
79 cout << "\n";
80
81 Example::Troesch_equation<double, double> problem;
82 Example::Troesch_left_BC <double> BC_left;
83 Example::Troesch_right_BC<double> BC_right;
84
85 double left = 0.0;
86 double right = 1.0;
87 // number of nodal points
88 unsigned N = 151;
89 // a real mesh -- along real axis
90 DenseVector<double> nodes( Utility::uniform_node_vector( left, right, N ) );
91 // Example tolerance
92 const double tol = 1.e-4;
93
94 // a real ODE BVP
95 problem.c = 5.0;
96 ODE_BVP<double> ode( &problem, nodes, &BC_left, &BC_right );
97
98 // our initial guess
99 for ( unsigned i = 0; i < N; ++i )
100 {
101 double y = ode.solution().coord( i );
102 // set f(y)
103 ode.solution()( i, f ) = y;
104 // set f'(y)
105 ode.solution()( i, fd ) = 1;
106 }
107
108 // solve the problem using 2nd order finite-difference
109 try
110 {
111 ode.solve2();
112 }
113 catch (const std::runtime_error &error )
114 {
115 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
116 return 1;
117 }
118
119 // find deviation from y=0.5 solution obtianed from: http://www2.imperial.ac.uk/~jcash/BVP_software/readme.php
120 const double diff = std::abs( ode.solution().get_interpolated_vars(0.5)[f] - 0.55437396E-01 );
121
122 // validation test
123 if ( diff > tol )
124 {
125 cout << "\033[1;31;48m * FAILED \033[0m\n";
126 cout << "Real problem error " << diff << "\n";
127 return 1;
128 }
129 else
130 {
131 cout << "\033[1;32;48m * PASSED \033[0m\n";
132 return 0;
133 }
134}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_BVP.h:37
DenseVector< double > uniform_node_vector(const double &lower, const double &upper, const std::size_t &N)
Return a DENSE vector with the nodal points of a uniform mesh distributed between the upper/lower bou...
Definition: Utility.cpp:113

References CppNoddy::Example::Troesch_equation< _Type, _Xtype >::c, f, fd, CppNoddy::ODE_BVP< _Type, _Xtype >::solution(), CppNoddy::ODE_BVP< _Type, _Xtype >::solve2(), and CppNoddy::Utility::uniform_node_vector().

© 2012

R.E. Hewitt