WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
restart_nonlinear_problem_alg.cc
Go to the documentation of this file.
1 #include "../include/restart_nonlinear_problem_alg.h"
2 
4 {
5 
6  return dphi_dn_indices.size();
7 }
8 
9 
10 
12  const unsigned int step_number)
13 {
14 }
15 
16 
21  const Vector<double> &src_yy)
22 {
23 
24  // we first put all the "proposed" dphi_dn values in the free surface y_dot vector (with proper positions)
25  for (std::map <unsigned int, unsigned int>::iterator pos = indices_map.begin(); pos != indices_map.end(); ++pos)
26  {
27  free_surf_y(pos->first) = src_yy(pos->second);
28  }
29 
30  // now we can call the residual funtion of free surface class
33 
34 
35  // the resulting free surface residual must be "distributed" on the present problem degrees of freedom (with proper ordering)
36  cout<<"Restart problem residual "<<endl;
37  unsigned int count = 0;
38  for (std::set <unsigned int>::iterator pos = dphi_dn_indices.begin(); pos != dphi_dn_indices.end(); ++pos)
39  {
40  unsigned int i=*pos;
42  //cout<<count<<"("<<3*i+2<<")W "<<dst(count)<<" "<<src_yy(count)<<endl;
43  count++;
44  }
45 
46  cout<<"Restart problem nonlin residual: "<<dst.l2_norm()<<endl;
47  return 0;
48 }
49 
52  const Vector<double> &src_yy,
53  const Vector<double> &src)
54 {
55 
56 
57  //cout<<"Original jacobian"<<endl;
58  //for (unsigned int i=0; i<free_surf_res.size(); ++i)
59  // for (SparsityPattern::iterator c=free_surf_jacobian.get_sparsity_pattern().row_begin(i); c!=free_surf_jacobian.get_sparsity_pattern().row_end(i); ++c)
60  // {
61  // unsigned int j = *c;
62  // cout<<" "<<i<<" "<<j<<" "<<free_surf_jacobian(i,j)<<endl;
63  // }
64  cout<<"Restart problem jacobian"<<endl;
65  jacobian_matrix = 0;
66 
67  unsigned int count = 0;
68  for (std::set <unsigned int>::iterator pos = dphi_dn_indices.begin(); pos != dphi_dn_indices.end(); ++pos)
69  {
70  unsigned int i=*pos;
73  if ( (indices_map.count(col->column())) && ((col->column()) > (comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs()-1)) )
74  {
75  jacobian_matrix.set(count,indices_map.find(col->column())->second,free_surf_jacobian(i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs(),col->column()));
76  //cout<<"dopo "<<count<<","<<indices_map.find(col->column())->second<<endl;
77  //cout<<count<<" "<<indices_map.find(col->column())->second<<" "<<free_surf_jacobian(i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs(),col->column())<<endl;
78  }
79  count++;
80  }
81  jacobian_matrix.vmult(dst,src);
82 
83  return 0;
84 }
85 
86 
89  const Vector<double> &src_yy,
90  const Vector<double> &src)
91 {
92  SparseDirectUMFPACK prec_direct;
93  prec_direct.initialize(jacobian_matrix);
94  prec_direct.vmult(dst,src);
95 
96  return 0;
97 }
98 
101  const Vector<double> &src_yy,
102  const Vector<double> &src)
103 {
104  jacobian_matrix.vmult(dst,src);
105 
106  return 0;
107 }
108 
111 {
112  return 0;
113 }
void vmult(OutVector &dst, const InVector &src) const
real_type l2_norm() const
const NumericalTowingTank & comp_dom
DoFHandler< dim-1, dim > vector_dh
void set(const size_type i, const size_type j, const number value)
iterator begin() const
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.
virtual unsigned int n_dofs() const
Returns the number of degrees of freedom.
virtual int setup_jacobian_prec(const Vector< double > &src_yy)
Setup Jacobian preconditioner for Newton.
types::global_dof_index n_dofs() const
iterator end() const
virtual int jacobian_prec_prod(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian preconditioner vector product for newton solver.
const SparsityPattern & get_sparsity_pattern() const
void initialize(const SparsityPattern &sparsity_pattern)
virtual int residual(Vector< double > &dst, const Vector< double > &src_yy)
For newton solver, we need a residual function.
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...
std::set< unsigned int > dphi_dn_indices
virtual int jacobian_prec(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian inverse preconditioner vector product for newton solver.
const SparseMatrix< double > & free_surf_jacobian
DoFHandler< dim-1, dim > dh
virtual int jacobian(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian vector product for newton solver.
void vmult(Vector< double > &dst, const Vector< double > &src) const
std::map< unsigned int, unsigned int > indices_map