WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
free_surface.h
Go to the documentation of this file.
1 //---------------------------- step-34.cc ---------------------------
2 // $Id: step-34.cc 18734 2009-04-25 13:36:48Z heltai $
3 // Version: $Name$
4 //
5 // Copyright (C) 2009, 2011 by the deal.II authors
6 //
7 // This file is subject to QPL and may not be distributed
8 // without copyright and license information. Please refer
9 // to the file deal.II/doc/license.html for the text and
10 // further information on this license.
11 //
12 // Authors: Luca Heltai, Cataldo Manigrasso
13 //
14 //---------------------------- step-34.cc ---------------------------
15 
16 
17 // @sect3{Include files}
18 
19 // The program starts with including a bunch
20 // of include files that we will use in the
21 // various parts of the program. Most of them
22 // have been discussed in previous tutorials
23 // already:
24 #ifndef free_surface_h
25 #define free_surface_h
26 
27 
33 #include <deal.II/base/utilities.h>
34 
35 #include <deal.II/lac/vector.h>
38 //#include <deal.II/lac/matrix_lib.h>
40 //#include <deal.II/lac/solver_gmres.h>
41 //#include <deal.II/lac/precondition.h>
43 
44 
45 #include <deal.II/grid/tria.h>
49 #include <deal.II/grid/grid_in.h>
50 #include <deal.II/grid/grid_out.h>
53 
56 #include <deal.II/dofs/dof_tools.h>
58 
59 #include <deal.II/fe/fe_q.h>
60 #include <deal.II/fe/fe_values.h>
61 #include <deal.II/fe/fe_system.h>
63 #include <deal.II/fe/mapping_q1.h>
64 
69 
70 // And here are a few C++ standard header
71 // files that we will need:
72 #include <cmath>
73 #include <iostream>
74 #include <fstream>
75 #include <string>
76 #include <set>
77 
78 
79 #include <dae_time_integrator.h>
80 //#include <newton_solver.h>
81 #include <newton_argument.h>
82 
83 #include "../include/bem_problem.h"
84 #include "../include/numerical_towing_tank.h"
85 
86 
87 // Helper function
88 template<int dim, class Type>
90 {
91  return static_cast<Tensor<1,dim,Type> &>(p);
92 }
93 
94 
95 // Helper function
96 template<int dim, class Type>
98 {
99  return static_cast<const Tensor<1,dim,Type> &>(p);
100 }
101 
102 
103 template <int dim>
105  public OdeArgument,
106  public NewtonArgument
107 {
108 public:
110  wind(dim), comp_dom(comp_dom), bem(bem)
111  {
112  dofs_number = 0,
113  output_frequency = 1;
114  stop_time_integrator = false;
115  reset_time_integrator = false;
116  }
117 
118  virtual unsigned int n_dofs() const;
119 
120  virtual void output_step(Vector<double> &solution,
121  const unsigned int step_number);
122 
123  virtual void output_step(Vector<double> &solution,
124  Vector<double> &solution_dot,
125  const double t,
126  const unsigned int step_number,
127  const double h);
128 
129  virtual bool solution_check(Vector<double> &solution,
130  Vector<double> &solution_dot,
131  const double t,
132  const unsigned int step_number,
133  const double h);
134 
135 
139  virtual int residual(const double t,
140  Vector<double> &dst,
141  const Vector<double> &src_yy,
142  const Vector<double> &src_yp);
143 
147  virtual int residual(Vector<double> &dst,
148  const Vector<double> &src_yy);
149 
151  virtual int jacobian(const double t,
152  Vector<double> &dst,
153  const Vector<double> &src_yy,
154  const Vector<double> &src_yp,
155  const Vector<double> &src,
156  const double alpha);
157 
158 
160  virtual int jacobian(Vector<double> &dst,
161  const Vector<double> &src_yy,
162  const Vector<double> &src);
163 
170  int residual_and_jacobian(const double t,
171  Vector<double> &dst,
172  const Vector<double> &src_yy,
173  const Vector<double> &src_yp,
174  const Vector<double> &src,
175  const double alpha,
176  const bool is_jacobian);
177 
178 
180  virtual int setup_jacobian_prec(const Vector<double> &src_yy);
181 
183  virtual int setup_jacobian_prec(const double t,
184  const Vector<double> &src_yy,
185  const Vector<double> &src_yp,
186  const double alpha);
187 
190 
193  virtual int jacobian_prec(const double t,
194  Vector<double> &dst,
195  const Vector<double> &src_yy,
196  const Vector<double> &src_yp,
197  const Vector<double> &src,
198  const double alpha);
199 
202  virtual int jacobian_prec(Vector<double> &dst,
203  const Vector<double> &src_yy,
204  const Vector<double> &src);
205 
208  virtual int jacobian_prec_prod(Vector<double> &dst,
209  const Vector<double> &src_yy,
210  const Vector<double> &src);
211 
212 
220 
223  void make_edges_conformal(Vector<double> &solution,
224  Vector<double> &solution_dot,
225  const double t,
226  const unsigned int step_number,
227  const double h);
228 
229  // in the first layer of water cells past
230  // the transom there can't be hanging nodes:
231  // this method removes them
233  Vector<double> &solution_dot,
234  const double t,
235  const unsigned int step_number,
236  const double h);
237 
241  void prepare_restart(const double t, Vector<double> &y, Vector<double> &yp, bool restart_flag=true);
242 
243  typedef typename DoFHandler<dim-1,dim>::active_cell_iterator cell_it;
244  typedef typename Triangulation<dim-1,dim>::active_cell_iterator tria_it;
245 
247 
249 
251 
252  void reinit();
253 
254  void prepare_bem_vectors(double time,
255  Vector<double> &bem_bc,
256  Vector<double> &dphi_dn) const;
257 
258  // In this routine we use the
259  // solution obtained to compute the
260  // DXDt and DphiDt on the domain
261  // boundary.
262 
263 
264  void compute_DXDt_and_DphiDt(double time,
265  const Vector<double> &phi,
266  const Vector<double> &dphi_dn,
267  const Vector<double> &nodes_velocities);
268 
269  // In this routine we compute the
270  // complete potential gradient,
271  // surface potential gradient,
272  // surface normal
273 
274  void vmult(Vector<double> &dst, const Vector<double> &src) const;
275 
276  void compute_potential_gradients(Vector<double> &complete_potential_gradients,
277  const Vector<double> &phi,
278  const Vector<double> &dphi_dn);
279 
280 
281  void compute_keel_smoothing(Vector<double> &smoothing);
282 
283 
284  void compute_pressure(Vector<double> &press,
285  Vector<double> &comp_1, Vector<double> &comp_2, Vector<double> &comp_3, Vector<double> &comp_4,
286  const double t,
287  const Vector<double> &solution,
288  const Vector<double> &solution_dot);
289 
290  void output_results(const std::string,
291  const double t,
292  const Vector<double> &solution,
293  const Vector<double> &pressure);
294 
296  const Vector<double> &dphi_dn);
297 
299 
300  inline unsigned int Rhs_evaluations_counter()
301  {
303  }
304 
305  void dump_solution(const Vector<double> &y,
306  const Vector<double> &yp,
307  const std::string fname) const;
308 
310  Vector<double> &yp,
311  const std::string fname);
312 
313 
314  void enforce_partial_geometry_constraints(const double blend_factor);
315 
317 
319  std::string restore_filename;
321 private:
322 
323  std::string output_file_name;
326 
335 
339 
341 
343 
345 
347 
348  unsigned int dofs_number;
349 
350  unsigned int output_frequency;
351 
353 
354  // vectors for the DAE solver
362 
363 
364 
365  double initial_time;
366 
367 
368 
369  // set of vectors and (mass) matrices
370  // needed in compute_DXDt_and_DphiDt
373 
377 
381 
386 
390 
393 
396 
397 
403  // vector storing the diameters of cells around each node
404  // needed to estimate local tolerances for
405  // the ode solver
406 
408 
409  // max x,y,z coodiante value (needed for
410  // semi-lagrangian free surface
411  // deformation)
412 
414 
416 
418 
420 
421  double min_diameter;
422 
423  unsigned int max_number_of_dofs;
424 
426 
428 
430 
432 
434  // working copy of the map points vector
436  // working copy of the map points vector
438  // vector for position residuals
440  // vector for geometric treatment residuals
441  // (to be passed to num_ tow_tank)
443 
444  // vector for jacobian X delta vector
445  // on differential nodes
447  // vector for jacobian X delta vector
448  // on algebraic nodes
450  // residual of dae equation
452  // residual of dae linear step
454 
455  double alpha;
456 
458 
460 
461  double current_time;
462 
464 
466 
468 
470 
471  // this number sets the bottom limit of the
472  // adaptive refinement. when set to 2.0, it
473  // limits the refinements so that all the cells
474  // have a higher diameter w/r to the min_diameter
475  // cell of the initial mesh. if set to 1.0, it allows
476  // cells to be refined to half of the initial min_diameter,
477  // and so on. On the other side, a value of 4.0 means
478  // that cells being 2 times bigger than initial min_diameter
479  // won't be refined.
481 
482  TopLoc_Location restart_hull_location;
491 
492 };
493 
494 #endif
495 
std::string output_file_name
Definition: free_surface.h:323
Point< 3 > restart_hull_displacement
Definition: free_surface.h:483
SolverControl solver_control
Definition: free_surface.h:342
SparsityPattern vector_sparsity_pattern
Definition: free_surface.h:387
SparseMatrix< double > jacobian_dot_matrix
Definition: free_surface.h:400
Vector< double > temp_src
Definition: free_surface.h:358
Point< 3 > restart_transom_left_tangent
Definition: free_surface.h:489
Point< 3 > restart_transom_center_point
Definition: free_surface.h:486
void prepare_bem_vectors(double time, Vector< double > &bem_bc, Vector< double > &dphi_dn) const
unsigned int dofs_number
Definition: free_surface.h:348
virtual void output_step(Vector< double > &solution, const unsigned int step_number)
This function is called at the end of each iteration step for the newton solver.
Point< 3 > restart_transom_right_tangent
Definition: free_surface.h:490
Vector< double > diff_comp
Definition: free_surface.h:356
Vector< double > working_map_points
Definition: free_surface.h:435
Functions::ParsedFunction< dim > initial_norm_potential_grad
Definition: free_surface.h:330
TopLoc_Location restart_hull_location
Definition: free_surface.h:482
Functions::ParsedFunction< 1 > hull_x_axis_translation
Definition: free_surface.h:332
SparseMatrix< double > vector_beltrami_matrix
Definition: free_surface.h:389
double max_z_coor_value
Definition: free_surface.h:417
void prepare_restart(const double t, Vector< double > &y, Vector< double > &yp, bool restart_flag=true)
Method to make sure residual is null at each (re)start of the computation.
bool is_hull_x_translation_imposed
Definition: free_surface.h:336
unsigned int output_frequency
Definition: free_surface.h:350
unsigned int rhs_evaluations_counter
Definition: free_surface.h:419
Functions::ParsedFunction< dim > initial_wave_potential
Definition: free_surface.h:329
std::string restore_filename
Definition: free_surface.h:319
SparseMatrix< double > DphiDt_sys_matrix
Definition: free_surface.h:375
FreeSurface(NumericalTowingTank &comp_dom, BEMProblem< dim > &bem)
Definition: free_surface.h:109
double max_x_coor_value
Definition: free_surface.h:413
virtual int residual(const double t, Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src_yp)
For dae problems, we need a residual function.
Vector< double > DphiDt_sys_rhs
Definition: free_surface.h:382
double coarsening_fraction
Definition: free_surface.h:425
bool restart_flag
Definition: free_surface.h:431
double adaptive_ref_limit
Definition: free_surface.h:480
Point< 3 > restart_transom_right_point
Definition: free_surface.h:488
Vector< double > DphiDt_sys_solution_3
Definition: free_surface.h:380
Vector< double > DphiDt_sys_rhs_4
Definition: free_surface.h:385
Tensor< 1, dim, Type > & T(Point< dim, Type > &p)
Definition: free_surface.h:89
double min_diameter
Definition: free_surface.h:421
void remove_transom_hanging_nodes(Vector< double > &solution, Vector< double > &solution_dot, const double t, const unsigned int step_number, const double h)
SparseMatrix< double > jacobian_preconditioner_matrix
Definition: free_surface.h:401
void output_results(const std::string, const double t, const Vector< double > &solution, const Vector< double > &pressure)
virtual int setup_jacobian_prec(const Vector< double > &src_yy)
Setup Jacobian preconditioner for Newton.
double ref_transom_wet_surface
Definition: free_surface.h:463
Vector< double > alg_comp
Definition: free_surface.h:357
Vector< double > vector_sys_solution
Definition: free_surface.h:391
double dumping_period
Definition: free_surface.h:325
Vector< double > vector_sys_rhs_2
Definition: free_surface.h:395
bool sync_bem_with_geometry
Definition: free_surface.h:429
double restart_hull_quat_scalar
Definition: free_surface.h:485
double alpha
Definition: free_surface.h:455
void vmult(Vector< double > &dst, const Vector< double > &src) const
double current_time
Definition: free_surface.h:461
Point< 3 > restart_transom_left_point
Definition: free_surface.h:487
Vector< double > current_sol_dot
Definition: free_surface.h:459
ConstraintMatrix constraints
Definition: free_surface.h:371
virtual unsigned int n_dofs() const
Returns the number of degrees of freedom.
double refinement_fraction
Definition: free_surface.h:427
Functions::ParsedFunction< dim > initial_wave_shape
Definition: free_surface.h:328
Vector< double > & get_diameters()
SparsityPattern jacobian_sparsity_pattern
Definition: free_surface.h:398
Vector< double > DphiDt_sys_solution_2
Definition: free_surface.h:379
Vector< double > bem_phi
Definition: free_surface.h:360
DoFHandler< dim-1, dim >::active_cell_iterator cell_it
Definition: free_surface.h:243
Vector< double > diameters
Definition: free_surface.h:407
Functions::ParsedFunction< 1 > hull_z_axis_translation
Definition: free_surface.h:334
void enforce_partial_geometry_constraints(const double blend_factor)
void compute_potential_gradients(Vector< double > &complete_potential_gradients, const Vector< double > &phi, const Vector< double > &dphi_dn)
ConstraintMatrix vector_constraints
Definition: free_surface.h:372
void compute_keel_smoothing(Vector< double > &smoothing)
Vector< double > nodes_alg_jac_x_delta
Definition: free_surface.h:449
NumericalTowingTank & comp_dom
Definition: free_surface.h:344
Triangulation< dim-1, dim >::active_cell_iterator tria_it
Definition: free_surface.h:244
Vector< double > DXDt_and_DphiDt_vector
Definition: free_surface.h:355
void declare_parameters(ParameterHandler &prm)
Definition: free_surface.cc:59
virtual bool solution_check(Vector< double > &solution, Vector< double > &solution_dot, const double t, const unsigned int step_number, const double h)
This function will check the behaviour of the solution.
Vector< double > bem_dphi_dn
Definition: free_surface.h:361
Vector< double > sys_comp
Definition: free_surface.h:320
Vector< double > break_wave_press
Definition: free_surface.h:467
virtual Vector< double > & differential_components()
And an identification of the differential components.
unsigned int refinement_level_on_boat
Definition: free_surface.h:352
Vector< double > nodes_pos_res
Definition: free_surface.h:439
virtual int jacobian_prec(const double t, Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src_yp, const Vector< double > &src, const double alpha)
Jacobian inverse preconditioner vector product for dae.
bool initial_condition_from_dump
Definition: free_surface.h:318
void enforce_full_geometry_constraints()
Vector< double > working_nodes_velocities
Definition: free_surface.h:437
bool is_hull_z_translation_imposed
Definition: free_surface.h:338
Vector< double > vector_sys_solution_2
Definition: free_surface.h:392
void compute_internal_velocities(const Vector< double > &phi, const Vector< double > &dphi_dn)
Vector< double > DphiDt_sys_rhs_3
Definition: free_surface.h:384
Vector< double > DphiDt_sys_rhs_2
Definition: free_surface.h:383
void dump_solution(const Vector< double > &y, const Vector< double > &yp, const std::string fname) const
void compute_pressure(Vector< double > &press, Vector< double > &comp_1, Vector< double > &comp_2, Vector< double > &comp_3, Vector< double > &comp_4, const double t, const Vector< double > &solution, const Vector< double > &solution_dot)
Functions::ParsedFunction< dim > inflow_norm_potential_grad
Definition: free_surface.h:331
virtual int jacobian_prec_prod(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian preconditioner vector product for newton solver.
bool reset_time_integrator
Definition: ode_argument.h:79
Functions::ParsedFunction< 1 > hull_y_axis_translation
Definition: free_surface.h:333
bool stop_time_integrator
Definition: ode_argument.h:83
SparsityPattern DphiDt_sparsity_pattern
Definition: free_surface.h:374
SparseMatrix< double > jacobian_matrix
Definition: free_surface.h:399
virtual int jacobian(const double t, Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src_yp, const Vector< double > &src, const double alpha)
Jacobian vector product for dae.
double last_remesh_time
Definition: free_surface.h:433
std::string node_displacement_type
Definition: free_surface.h:340
Base class that needs to be inherited by any function that wants to use the newton solver class...
Vector< double > transom_pressure_patch
Definition: free_surface.h:469
Vector< double > current_sol
Definition: free_surface.h:457
void make_edges_conformal(Vector< double > &solution, Vector< double > &solution_dot, const double t, const unsigned int step_number, const double h)
Method to enforce mesh conformity at edges at each restart.
int residual_and_jacobian(const double t, Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src_yp, const Vector< double > &src, const double alpha, const bool is_jacobian)
This function computes either DAE residual or corrensponding Jacobian matrix vector product with vect...
Vector< double > nodes_ref_surf_dist
Definition: free_surface.h:442
Point< 3 > restart_hull_quat_vector
Definition: free_surface.h:484
double max_y_coor_value
Definition: free_surface.h:415
void compute_constraints(ConstraintMatrix &constraints, ConstraintMatrix &vector_constraints)
unsigned int Rhs_evaluations_counter()
Definition: free_surface.h:300
double remeshing_period
Definition: free_surface.h:324
SparseMatrix< double > vector_sys_matrix
Definition: free_surface.h:388
Vector< double > DphiDt_sys_solution
Definition: free_surface.h:378
double initial_time
Definition: free_surface.h:365
SparseMatrix< double > preconditioner_preconditioner_matrix
Definition: free_surface.h:402
Vector< double > vector_sys_rhs
Definition: free_surface.h:394
void compute_DXDt_and_DphiDt(double time, const Vector< double > &phi, const Vector< double > &dphi_dn, const Vector< double > &nodes_velocities)
bool is_hull_y_translation_imposed
Definition: free_surface.h:337
BEMProblem< dim > & bem
Definition: free_surface.h:346
Base class that needs to be inherited by any function that wants to use the time integrator class...
Definition: ode_argument.h:12
unsigned int max_number_of_dofs
Definition: free_surface.h:423
Functions::ParsedFunction< dim > wind
Definition: free_surface.h:327
Vector< double > dae_linear_step_residual
Definition: free_surface.h:453
void restore_solution(Vector< double > &y, Vector< double > &yp, const std::string fname)
Vector< double > ref_cell_areas
Definition: free_surface.h:465
void initial_conditions(Vector< double > &dst)
void parse_parameters(ParameterHandler &prm)
Vector< double > bem_residual
Definition: free_surface.h:359
Vector< double > nodes_diff_jac_x_delta
Definition: free_surface.h:446
Vector< double > dae_nonlin_residual
Definition: free_surface.h:451
SparseMatrix< double > DphiDt_sys_matrix_2
Definition: free_surface.h:376