CppNoddy  0.92
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CppNoddy::reversed_BL< _Type > Class Template Reference

A templated object for real/complex vector system of unsteady equations. More...

#include <reversed_BL.h>

Inheritance diagram for CppNoddy::reversed_BL< _Type >:
CppNoddy::Uncopyable

Public Member Functions

 reversed_BL (Equation_3matrix< _Type > *equation_ptr, const DenseVector< double > &xnodes, const DenseVector< double > &ynodes, Residual_with_coords< _Type > *ptr_to_bottom_residual, Residual_with_coords< _Type > *ptr_to_top_residual)
 The class is defined by a vector function for the system. More...
 
 ~reversed_BL ()
 Destructor. More...
 
void update_previous_solution ()
 Copy the current solution to the previous solution. More...
 
void step2 (const double &dt)
 A Crank-Nicolson 'time' stepper. More...
 
void bidirectional_step2 (const double &dt)
 A Crank-Nicolson 'time' stepper. More...
 
double & t ()
 Return a reference to the current value of the 'timelike' coordinate. More...
 
double & tolerance ()
 Return a reference to the convergence tolerance. More...
 
TwoD_Node_Mesh< _Type > & solution ()
 

Detailed Description

template<typename _Type>
class CppNoddy::reversed_BL< _Type >

A templated object for real/complex vector system of unsteady equations.

Definition at line 24 of file reversed_BL.h.

Constructor & Destructor Documentation

◆ reversed_BL()

template<typename _Type >
CppNoddy::reversed_BL< _Type >::reversed_BL ( Equation_3matrix< _Type > *  equation_ptr,
const DenseVector< double > &  xnodes,
const DenseVector< double > &  ynodes,
Residual_with_coords< _Type > *  ptr_to_bottom_residual,
Residual_with_coords< _Type > *  ptr_to_top_residual 
)

The class is defined by a vector function for the system.

Parameters
equation_ptrA pointer to an inherited Equation object.
xnodesA vector that defines the nodal x-positions.
ynodesA vector that defines the nodal y-positions.
ptr_to_bottom_residualA pointer to a residual object that defines the y=y1 boundary conditions.
ptr_to_top_residualA pointer to a residual object that defines the y=y2 boundary conditions.

Definition at line 17 of file reversed_BL.cpp.

22 :
23 TOL(1.e-8),
24 T(0.0),
25 MAX_ITERATIONS(30),
26 p_EQUATION(ptr_to_equation),
27 p_BOTTOM_RESIDUAL(ptr_to_bottom_residual),
28 p_TOP_RESIDUAL(ptr_to_top_residual),
29 UPDATED(false) {
30 // create the 2D mesh for the current time level and previous time level
31 SOLN = TwoD_Node_Mesh<_Type>(xnodes, ynodes, p_EQUATION -> get_order());
32 // copy construct the previous solution's storage
33 PREV_SOLN = SOLN;
34 // initialise the eqn object
35 p_EQUATION -> coord(2) = xnodes[0];
36#ifdef TIME
37 // timers
38 T_ASSEMBLE = Timer("Assembling of the matrix (incl. equation updates):");
39 T_SOLVE = Timer("Solving of the matrix:");
40#endif
41 }

◆ ~reversed_BL()

template<typename _Type >
CppNoddy::reversed_BL< _Type >::~reversed_BL

Destructor.

Definition at line 44 of file reversed_BL.cpp.

44 {
45#ifdef TIME
46 std::cout << "\n";
47 T_ASSEMBLE.stop();
48 T_ASSEMBLE.print();
49 T_SOLVE.stop();
50 T_SOLVE.print();
51#endif
52 }

Member Function Documentation

◆ bidirectional_step2()

template<typename _Type >
void CppNoddy::reversed_BL< _Type >::bidirectional_step2 ( const double &  dt)

A Crank-Nicolson 'time' stepper.

Definition at line 141 of file reversed_BL.cpp.

141 {
142 DT = dt;
143 if(!UPDATED) {
144 std::string problem;
145 problem = " You have called the reversed_BL::bidirectional_step2 method without calling\n";
146 problem += " the reversed_BL::update_previous_solution method first. This\n";
147 problem += " method is required to copy/store the previous time level's solution\n";
148 problem += " and then allow you to specify/alter the x-initial condition by\n";
149 problem += " for the current time level.";
150 throw ExceptionRuntime(problem);
151 }
152 // the order of the problem
153 unsigned order(p_EQUATION -> get_order());
154 // get the number of nodes in the mesh
155 // -- this may have been refined by the user since the last call.
156 unsigned nx(SOLN.get_nnodes().first);
157 unsigned ny(SOLN.get_nnodes().second);
158 // measure of maximum residual
159 double max_residual(1.0);
160 // the current solution moves to the previous solution
161 // ANY LARGE STORAGE USED IN THE MAIN LOOP IS
162 // DEFINED HERE TO AVOID REPEATED CONSTRUCTION.
163 // Note we blank the A matrix after every iteration.
164 //
165 // Banded LHS matrix - max obove diagonal band width is
166 // from first variable at node i to last variable at node i+1
167 BandedMatrix<_Type> a(ny * order, 2 * order - 1, 0.0);
168 // RHS
169 DenseVector<_Type> b(ny * order, 0.0);
170 // linear solver definition
171#ifdef LAPACK
172 BandedLinearSystem<_Type> system(&a, &b, "lapack");
173#else
174 BandedLinearSystem<_Type> system(&a, &b, "native");
175#endif
176 // which node did convergence fail?
177 unsigned jfail = 0;
178 // step from j=0 to j=nx-3 ... at each we assemble and solve for j+1
179 // which covers the positions j=1,2,...,nx-2. Note that the solution
180 // at j=0 and nx-1 are defined in the bidirectional problem.
181 for(std::size_t j = 0; j < nx - 2; ++j) {
182 //// next x-soln guess is the previous x-soln
183 //for ( std::size_t i = 0; i < ny; ++i )
184 //{
185 //for ( std::size_t var = 0; var < order; ++var )
186 //{
187 //SOLN( j + 1, i, var ) = SOLN( j, i, var );
188 //}
189 //}
190 // iteration counter
191 int counter = 0;
192 // loop until converged or too many iterations
193 do {
194 // iteration counter
195 ++counter;
196 // time the assemble phase
197#ifdef TIME
198 T_ASSEMBLE.start();
199#endif
200 // *** hardwired velocity direction/shear hackery
201 // if ( SOLN( j+2, 0, 2) > 0.0 )
202
203 bool reversed(false);
204 if(SOLN(j+2, 0, 2) < 0.0) {
205 reversed = true;
206 }
207
208 if(!reversed) {
209 assemble_matrix_problem(a, b, j);
210 } else {
211
212 //std::cout << SOLN.coord(j+2,0).first << " Reversed \n";
213 bidirectional_assemble_matrix_problem(a, b, j);
214 }
215 max_residual = b.inf_norm();
216#ifdef DEBUG
217 std::cout.precision(12);
218 std::cout << " reversed_BL.bidirectional_step2 : x_j = " << SOLN.coord(j,0).first << " Residual_max = " << max_residual << " tol = " << TOL << " counter = " << counter << "\n";
219#endif
220#ifdef TIME
221 T_ASSEMBLE.stop();
222 T_SOLVE.start();
223#endif
224 jfail = j;
225 // linear solver
226 system.solve();
227 // write the solution back into the TwoD_Node_Mesh object
228 for(std::size_t i = 0; i < ny; ++i) {
229 for(std::size_t var = 0; var < order; ++var) {
230 SOLN(j + 1, i, var) += b[ i * order + var ];
231 }
232 }
233#ifdef TIME
234 T_SOLVE.stop();
235#endif
236 } while((max_residual > TOL) && (counter < MAX_ITERATIONS));
237 if(counter >= MAX_ITERATIONS) {
238 std::cout << " reversed_BL.bidirectional_step2 : x_j = " << SOLN.coord(jfail,0).first << "\n";
239 std::string problem("\n The reversed_BL.bidirectional_step2 method took too many iterations. \n");
240 throw ExceptionItn(problem, counter, max_residual);
241 }
242 }
243 // set the time to the updated level
244 T += DT;
245#ifdef DEBUG
246 std::cout << "[DEBUG] solved at t = " << T << "\n";
247#endif
248 UPDATED = false;
249 }

References CppNoddy::DenseVector< _Type >::inf_norm(), and CppNoddy::BandedLinearSystem< _Type >::solve().

◆ solution()

template<typename _Type >
TwoD_Node_Mesh< _Type > & CppNoddy::reversed_BL< _Type >::solution
inline
Returns
A handle to the solution mesh

Definition at line 113 of file reversed_BL.h.

113 {
114 return SOLN;
115 }

◆ step2()

template<typename _Type >
void CppNoddy::reversed_BL< _Type >::step2 ( const double &  dt)

A Crank-Nicolson 'time' stepper.

Definition at line 55 of file reversed_BL.cpp.

55 {
56 DT = dt;
57 if(!UPDATED) {
58 std::string problem;
59 problem = " You have called the reversed_BL::step2 method without calling\n";
60 problem += " the reversed_BL::update_previous_solution method first. This\n";
61 problem += " method is required to copy/store the previous time level's solution\n";
62 problem += " and then allow you to specify/alter the x-initial condition by\n";
63 problem += " for the current time level.";
64 throw ExceptionRuntime(problem);
65 }
66 // the order of the problem
67 unsigned order(p_EQUATION -> get_order());
68 // get the number of nodes in the mesh
69 // -- this may have been refined by the user since the last call.
70 unsigned nx(SOLN.get_nnodes().first);
71 unsigned ny(SOLN.get_nnodes().second);
72 // measure of maximum residual
73 double max_residual(1.0);
74 // the current solution moves to the previous solution
75 // ANY LARGE STORAGE USED IN THE MAIN LOOP IS
76 // DEFINED HERE TO AVOID REPEATED CONSTRUCTION.
77 // Note we blank the A matrix after every iteration.
78 //
79 // Banded LHS matrix - max obove diagonal band width is
80 // from first variable at node i to last variable at node i+1
81 BandedMatrix<_Type> a(ny * order, 2 * order - 1, 0.0);
82 // RHS
83 DenseVector<_Type> b(ny * order, 0.0);
84 // linear solver definition
85#ifdef LAPACK
86 BandedLinearSystem<_Type> system(&a, &b, "lapack");
87#else
88 BandedLinearSystem<_Type> system(&a, &b, "native");
89#endif
90 unsigned jfail = 0;
91 for(std::size_t j = 0; j < nx - 1; ++j) {
92 // iteration counter
93 int counter = 0;
94 // loop until converged or too many iterations
95 do {
96 // iteration counter
97 ++counter;
98 // time the assemble phase
99#ifdef TIME
100 T_ASSEMBLE.start();
101#endif
102 assemble_matrix_problem(a, b, j);
103 max_residual = b.inf_norm();
104#ifdef DEBUG
105 std::cout.precision(12);
106 std::cout << " reversed_BL.step2 : x_j = " << SOLN.coord(j,0).first << " Residual_max = " << max_residual << " tol = " << TOL << " counter = " << counter << "\n";
107#endif
108#ifdef TIME
109 T_ASSEMBLE.stop();
110 T_SOLVE.start();
111#endif
112 jfail = j;
113 // linear solver
114 system.solve();
115 // keep the solution in a OneD_GenMesh object
116 for(std::size_t i = 0; i < ny; ++i) {
117 for(std::size_t var = 0; var < order; ++var) {
118 SOLN(j + 1, i, var) += b[ i * order + var ];
119 }
120 }
121#ifdef TIME
122 T_SOLVE.stop();
123#endif
124 } while((max_residual > TOL) && (counter < MAX_ITERATIONS));
125 if(counter >= MAX_ITERATIONS) {
126 std::cout << " reversed_BL.step2 : x_j = " << SOLN.coord(jfail,0).first << "\n";
127 std::string problem("\n The reversed_BL.step2 method took too many iterations. \n");
128 throw ExceptionItn(problem, counter, max_residual);
129 }
130 }
131 // set the time to the updated level
132 T += DT;
133#ifdef DEBUG
134 std::cout << "[DEBUG] solved at t = " << T << "\n";
135#endif
136 UPDATED = false;
137 }

References CppNoddy::DenseVector< _Type >::inf_norm(), and CppNoddy::BandedLinearSystem< _Type >::solve().

◆ t()

template<typename _Type >
double & CppNoddy::reversed_BL< _Type >::t
inline

Return a reference to the current value of the 'timelike' coordinate.

Returns
A handle to the current timelinke coordinate stored in the object

Definition at line 118 of file reversed_BL.h.

118 {
119 return T;
120 }

◆ tolerance()

template<typename _Type >
double & CppNoddy::reversed_BL< _Type >::tolerance ( )
inline

Return a reference to the convergence tolerance.

Definition at line 59 of file reversed_BL.h.

59 {
60 return TOL;
61 }

◆ update_previous_solution()

template<typename _Type >
void CppNoddy::reversed_BL< _Type >::update_previous_solution ( )
inline

Copy the current solution to the previous solution.

Definition at line 43 of file reversed_BL.h.

43 {
44 PREV_SOLN = SOLN;
45 UPDATED = true;
46 }

The documentation for this class was generated from the following files:

© 2012

R.E. Hewitt