WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
restart_nonlinear_problem_alg.h
Go to the documentation of this file.
1 // The program starts with including a bunch
2 // of include files that we will use in the
3 // various parts of the program. Most of them
4 // have been discussed in previous tutorials
5 // already:
6 #ifndef restart_nonlinear_problem_alg_h
7 #define restart_nonlinear_problem_alg_h
8 
9 
10 #include <free_surface.h>
11 #include <numerical_towing_tank.h>
12 #include <newton_argument.h>
13 
14 
16  public NewtonArgument
17 {
18 public:
21  const double &time,
25  free_surface(free_surface),
26  comp_dom(comp_dom),
27  time(time),
28  free_surf_y(free_surf_y),
29  free_surf_y_dot(free_surf_y_dot),
30  free_surf_jacobian(free_surf_jacobian)
31  {
32 
33  dphi_dn_indices.clear();
34 
35 
36  // let's take care of the potential normal derivative dofs
37  for (unsigned int i=0; i<comp_dom.dh.n_dofs(); ++i)
38  {
39  // if node is not on water all dofs are algebraic components
40  if (!(comp_dom.flags[i] & water))
41  {
42  // neumann boundary condition on boat surface is what we're interested in
43  //if (comp_dom.vector_constraints.is_constrained(3*i) )
44  // {// if node is constrained, it is disregarded
45  // }
46  //else
47  // {// otherwise, it is the kind of dof we're looking for
48  dphi_dn_indices.insert(i);
49  // }
50  }
51  }
52 
53  free_surf_jac_x_delta.reinit(free_surf_y.size());
54  free_surf_res.reinit(free_surf_y.size());
55 
56 
57 
58  unsigned int count = 0;
59 
60  for (std::set <unsigned int>::iterator pos = dphi_dn_indices.begin(); pos != dphi_dn_indices.end(); ++pos)
61  {
62  unsigned int i=*pos;
63  indices_map[i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs()] = count;
64  count++;
65  }
66 
67  //cout<<" MAP "<<endl;
68  //for (std::map <unsigned int,unsigned int>::iterator pos = indices_map.begin(); pos != indices_map.end(); ++pos)
69  // {
70  // cout<<"Restart: "<<pos->second<<" ---> DAE: "<<pos->first<<endl;
71  // }
72  //cout<<" REPORT "<<endl;
73  //cout<<count<<endl;
74  //cout<<2*water_line_indices.size()<<endl;
75  //cout<<3*bow_stern_indices.size()<<endl;
76  //cout<<water_indices.size()<<endl;
77  //cout<<phi_indices.size()<<endl;
78  //cout<<dphi_dn_indices.size()<<endl;
79  //cout<<2*water_line_indices.size()+3*bow_stern_indices.size()+water_indices.size()+phi_indices.size()+dphi_dn_indices.size()<<endl;
81  dphi_dn_indices.size(),
82  30);
83 
84  count = 0;
85  for (std::set <unsigned int>::iterator pos = dphi_dn_indices.begin(); pos != dphi_dn_indices.end(); ++pos)
86  {
87  unsigned int i=*pos;
88  for (SparsityPattern::iterator col=free_surf_jacobian.get_sparsity_pattern().begin(i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs());
89  col!=free_surf_jacobian.get_sparsity_pattern().end(i+comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs()); ++col)
90  if ( (indices_map.count(col->column())) && ((col->column())>= comp_dom.vector_dh.n_dofs()+comp_dom.dh.n_dofs()) )
91  {
92  jacobian_sparsity_pattern.add(count,indices_map.find(col->column())->second);
93  //cout<<"prima "<<count<<","<<indices_map.find(col->column())->second<<endl;
94  }
95  count++;
96  }
97 
100 
101 
102 
103  }
104 
105  virtual unsigned int n_dofs() const;
106 
107  virtual void output_step(Vector<double> &solution,
108  const unsigned int step_number);
109 
113  virtual int residual(Vector<double> &dst,
114  const Vector<double> &src_yy);
115 
117  virtual int jacobian(Vector<double> &dst,
118  const Vector<double> &src_yy,
119  const Vector<double> &src);
120 
122  virtual int setup_jacobian_prec(const Vector<double> &src_yy);
123 
126  virtual int jacobian_prec(Vector<double> &dst,
127  const Vector<double> &src_yy,
128  const Vector<double> &src);
129 
132  virtual int jacobian_prec_prod(Vector<double> &dst,
133  const Vector<double> &src_yy,
134  const Vector<double> &src);
135 
136 private:
137 
140  const double &time;
144 
147  std::set<unsigned int> dphi_dn_indices;
150 
151 public:
152  std::map<unsigned int,unsigned int> indices_map;
153 
154 };
155 
156 #endif
const NumericalTowingTank & comp_dom
DoFHandler< dim-1, dim > vector_dh
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 void reinit(const SparsityPattern &sparsity)
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.
void add(const size_type i, const size_type j)
std::vector< GeometryFlags > flags
types::global_dof_index n_dofs() const
std::size_t size() 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.
void reinit(const size_type m, const size_type n, const unsigned int max_per_row)
RestartNonlinearProblemAlg(FreeSurface< 3 > &free_surface, const NumericalTowingTank &comp_dom, const double &time, Vector< double > &free_surf_y, Vector< double > &free_surf_y_dot, const SparseMatrix< double > &free_surf_jacobian)
Base class that needs to be inherited by any function that wants to use the newton solver class...
const SparsityPattern & get_sparsity_pattern() const
virtual int residual(Vector< double > &dst, const Vector< double > &src_yy)
For newton solver, we need a residual function.
std::set< unsigned int > dphi_dn_indices
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
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.
std::map< unsigned int, unsigned int > indices_map