WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
restart_nonlinear_problem_diff.cc
Go to the documentation of this file.
1 #include "../include/restart_nonlinear_problem_diff.h"
2 
4 {
5 
6  return 2*water_line_indices.size()+3*bow_stern_indices.size()+water_indices.size()+phi_indices.size()+rigid_modes_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" velocity 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_dot(pos->first) = src_yy(pos->second);
28  }
29 
30 
31 
32  // now we can call the residual funtion of free surface class
35 
36 
37  // the resulting free surface residual must be "distributed" on the present problem degrees of freedom (with proper ordering)
38  cout<<"Restart problem residual "<<endl;
39  unsigned int count = 0;
40  for (std::set <unsigned int>::iterator pos = water_line_indices.begin(); pos != water_line_indices.end(); ++pos)
41  {
42  unsigned int i=*pos;
43  dst(count) = src_yy(count) + src_yy(count+1)*comp_dom.iges_normals[i](2)/comp_dom.iges_normals[i](1);
44  //cout<<count<<"("<<3*i+1<<")WL "<<dst(count)<<" "<<src_yy(count)<<endl;
45  count++;
46  dst(count) = free_surf_res(3*i+2);
47  //cout<<count<<"("<<3*i+2<<")WL "<<dst(count)<<" "<<src_yy(count)<<endl;
48  count++;
49  }
50  for (std::set <unsigned int>::iterator pos = bow_stern_indices.begin(); pos != bow_stern_indices.end(); ++pos)
51  {
52  unsigned int i=*pos;
54  dst(count) = src_yy(count) - src_yy(count+2)*t(0)/t(2);
55  //cout<<count<<"("<<3*i<<")BS "<<dst(count)<<" "<<src_yy(count)<<endl;
56  count++;
57  dst(count) = src_yy(count) - src_yy(count+1)*t(1)/t(2);
58  //cout<<count<<"("<<3*i+1<<")BS "<<dst(count)<<" "<<src_yy(count)<<endl;
59  count++;
60  dst(count) = free_surf_res(3*i+2);
61  //cout<<count<<"("<<3*i+2<<")BS "<<dst(count)<<" "<<src_yy(count)<<endl;
62  count++;
63  }
64  for (std::set <unsigned int>::iterator pos = water_indices.begin(); pos != water_indices.end(); ++pos)
65  {
66  unsigned int i=*pos;
67  dst(count) = free_surf_res(3*i+2);
68  //cout<<count<<"("<<3*i+2<<")W "<<dst(count)<<" "<<src_yy(count)<<endl;
69  count++;
70  }
71  for (std::set <unsigned int>::iterator pos = phi_indices.begin(); pos != phi_indices.end(); ++pos)
72  {
73  unsigned int i=*pos;
74  dst(count) = free_surf_res(i+comp_dom.vector_dh.n_dofs());
75  //cout<<count<<"("<<3*i+2<<")W "<<dst(count)<<" "<<src_yy(count)<<endl;
76  count++;
77  }
78  for (std::set <unsigned int>::iterator pos = rigid_modes_indices.begin(); pos != rigid_modes_indices.end(); ++pos)
79  {
80  unsigned int i=*pos;
82  //cout<<count<<"("<<3*i+2<<")W "<<dst(count)<<" "<<src_yy(count)<<endl;
83  count++;
84  }
85 
86  cout<<"Restart problem nonlin residual: "<<dst.l2_norm()<<endl;
87  return 0;
88 }
89 
92  const Vector<double> &src_yy,
93  const Vector<double> &src)
94 {
95 
96 
97  //cout<<"Original jacobian"<<endl;
98  //for (unsigned int i=0; i<free_surf_res.size(); ++i)
99  // for (SparsityPattern::iterator c=free_surf_jacobian.get_sparsity_pattern().begin(i); c!=free_surf_jacobian.get_sparsity_pattern().end(i); ++c)
100  // {
101  // unsigned int j = c->column();
102  // cout<<" "<<i<<" "<<j<<" "<<free_surf_jacobian(i,j)<<endl;
103  // }
104  cout<<"Restart problem jacobian"<<endl;
105  jacobian_matrix = 0;
106 
107  unsigned int count = 0;
108  for (std::set <unsigned int>::iterator pos = water_line_indices.begin(); pos != water_line_indices.end(); ++pos)
109  {
110  unsigned int i=*pos;
111  jacobian_matrix.set(count,count,1.0);
112  jacobian_matrix.set(count,count+1,comp_dom.iges_normals[i](2)/comp_dom.iges_normals[i](1));
113  //cout<<count<<" "<<count<<" "<<1.0<<endl;
114  //cout<<count<<" "<<count+1<<" "<<comp_dom.iges_normals[i](2)/comp_dom.iges_normals[i](1)<<endl;
115  count++;
117  col!=free_surf_jacobian_dot.get_sparsity_pattern().end(3*i+2); ++col)
118  if ( indices_map.count(col->column()) )
119  {
120  jacobian_matrix.set(count,indices_map.find(col->column())->second,free_surf_jacobian_dot(3*i+2,col->column()));
121  //cout<<count<<" "<<indices_map.find(col->column())->second<<" "<<free_surf_jacobian_dot(3*i+2,col->column())<<endl;
122  }
123  count++;
124  }
125  for (std::set <unsigned int>::iterator pos = bow_stern_indices.begin(); pos != bow_stern_indices.end(); ++pos)
126  {
127  unsigned int i=*pos;
129  jacobian_matrix.set(count,count,1.0);
130  jacobian_matrix.set(count,count+2,-t(0)/t(2));
131  //cout<<count<<" "<<count<<" "<<1.0<<endl;
132  //cout<<count<<" "<<count+2<<" "<<-t(0)/t(2)<<endl;
133  count++;
134  jacobian_matrix.set(count,count,1.0);
135  jacobian_matrix.set(count,count+1,-t(1)/t(2));
136  //cout<<count<<" "<<count<<" "<<1.0<<endl;
137  //cout<<count<<" "<<count+1<<" "<<-t(1)/t(2)<<endl;
138  count++;
140  col!=free_surf_jacobian_dot.get_sparsity_pattern().end(3*i+2); ++col)
141  if ( indices_map.count(col->column()) )
142  {
143  jacobian_matrix.set(count,indices_map.find(col->column())->second,free_surf_jacobian_dot(3*i+2,col->column()));
144  //cout<<count<<" "<<indices_map.find(col->column())->second<<" "<<free_surf_jacobian_dot(3*i+2,col->column())<<endl;
145  }
146  count++;
147  }
148  for (std::set <unsigned int>::iterator pos = water_indices.begin(); pos != water_indices.end(); ++pos)
149  {
150  unsigned int i=*pos;
152  col!=free_surf_jacobian_dot.get_sparsity_pattern().end(3*i+2); ++col)
153  if ( indices_map.count(col->column()) )
154  {
155  jacobian_matrix.set(count,indices_map.find(col->column())->second,free_surf_jacobian_dot(3*i+2,col->column()));
156  //cout<<count<<" "<<indices_map.find(col->column())->second<<" "<<free_surf_jacobian_dot(3*i+2,col->column())<<endl;
157  }
158  count++;
159  }
160  for (std::set <unsigned int>::iterator pos = phi_indices.begin(); pos != phi_indices.end(); ++pos)
161  {
162  unsigned int i=*pos;
165  if ( indices_map.count(col->column()) )
166  {
167  jacobian_matrix.set(count,indices_map.find(col->column())->second,free_surf_jacobian_dot(i+comp_dom.vector_dh.n_dofs(),col->column()));
168  //cout<<count<<" "<<indices_map.find(col->column())->second<<" "<<free_surf_jacobian_dot(i+comp_dom.vector_dh.n_dofs(),col->column())<<endl;
169  }
170  count++;
171  }
172 
173  for (std::set <unsigned int>::iterator pos = rigid_modes_indices.begin(); pos != rigid_modes_indices.end(); ++pos)
174  {
175  unsigned int i=*pos;
178  if ( indices_map.count(col->column()) )
179  {
180  jacobian_matrix.set(count,indices_map.find(col->column())->second,free_surf_jacobian_dot(i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs()+comp_dom.dh.n_dofs(),col->column()));
181  //cout<<count<<" "<<indices_map.find(col->column())->second<<" "<<free_surf_jacobian_dot(i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs()+comp_dom.dh.n_dofs(),col->column())<<endl;
182  }
183  count++;
184  }
185 
186  jacobian_matrix.vmult(dst,src);
187 
188  return 0;
189 }
190 
191 
194  const Vector<double> &src_yy,
195  const Vector<double> &src)
196 {
197 
198  SparseDirectUMFPACK prec_direct;
199  prec_direct.initialize(jacobian_matrix);
200  prec_direct.vmult(dst,src);
201 
202  return 0;
203 }
204 
207  const Vector<double> &src_yy,
208  const Vector<double> &src)
209 {
210  jacobian_matrix.vmult(dst,src);
211 
212  return 0;
213 }
214 
217 {
218  return 0;
219 }
virtual int setup_jacobian_prec(const Vector< double > &src_yy)
Setup Jacobian preconditioner for Newton.
std::set< unsigned int > rigid_modes_indices
void vmult(OutVector &dst, const InVector &src) const
real_type l2_norm() const
DoFHandler< dim-1, dim > vector_dh
void set(const size_type i, const size_type j, const number value)
iterator begin() const
virtual int jacobian_prec(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian inverse preconditioner vector product for newton solver.
virtual int jacobian_prec_prod(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian preconditioner vector product for newton solver.
virtual int residual(Vector< double > &dst, const Vector< double > &src_yy)
For newton solver, we need a residual function.
virtual unsigned int n_dofs() const
Returns the number of degrees of freedom.
types::global_dof_index n_dofs() const
iterator end() const
std::map< unsigned int, unsigned int > indices_map
const SparseMatrix< double > & free_surf_jacobian_dot
const SparsityPattern & get_sparsity_pattern() const
void initialize(const SparsityPattern &sparsity_pattern)
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...
virtual int jacobian(Vector< double > &dst, const Vector< double > &src_yy, const Vector< double > &src)
Jacobian vector product for newton solver.
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.
std::vector< Point< 3 > > iges_normals
Vector< double > edges_tangents
DoFHandler< dim-1, dim > dh
void vmult(Vector< double > &dst, const Vector< double > &src) const