WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
computational_domain.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, 2010, 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 // We start with including a bunch
17 // of include files: they might be more than
18 // needed, we might want to check, some time
19 #ifndef computational_domain_h
20 #define computational_domain_h
21 
27 #include <deal.II/base/utilities.h>
28 
31 #include <deal.II/lac/matrix_lib.h>
32 #include <deal.II/lac/vector.h>
38 
39 #include <deal.II/grid/tria.h>
44 #include <deal.II/grid/grid_in.h>
45 #include <deal.II/grid/grid_out.h>
47 
50 #include <deal.II/dofs/dof_tools.h>
52 #include <deal.II/fe/fe_q.h>
53 #include <deal.II/fe/fe_values.h>
54 #include <deal.II/fe/fe_system.h>
56 #include <deal.II/fe/mapping_q.h>
57 
62 
63 #include <cmath>
64 #include <iostream>
65 #include <fstream>
66 #include <string>
67 #include <set>
68 #include <map>
69 
70 
71 #include "../include/octree_block.h"
72 #include "../include/local_expansion.h"
73 #include "../include/multipole_expansion.h"
74 #include "../include/ass_leg_function.h"
75 #include "../include/geometry_flags.h"
76 #include "../include/boat_model.h"
77 
78 
79 using namespace dealii;
80 
81 
82 template <int dim>
84 {
85 public:
86 
87  // constructor: since this is the
88  // class containing all the geometry and
89  // the base instruments needed by all the
90  // other classes, it is created first and
91  // the constructor does not need
92  // arguments.
93  // For the same reason, most of the class
94  // attributes are public: we can leter
95  // make them public end introduce suitable
96  // Get and Set methods, if needed
97 
98  ComputationalDomain(const unsigned int fe_degree = 1,
99  const unsigned int mapping_degree = 1);
100 
101 
102  virtual ~ComputationalDomain();
103 
104  // method to declare the parameters
105  // to be read from the parameters file
106 
107  virtual void declare_parameters(ParameterHandler &prm);
108 
109  // method to parse the needed parameters
110  // from the parameters file
111 
112  virtual void parse_parameters(ParameterHandler &prm);
113 
114  // method to parse mesh from the
115  // input file
116 
117  virtual void read_domain();
118 
119  // method to refine the imported mesh
120  // according to the level requested in
121  // the parameters file
122 
123  virtual void refine_and_resize();
124 
125  // method to perform an adaptive refinement
126  // of the mesh according to the smoothness
127  // of the surface (kelly error estimator
128  // computed with map_points vector)
129 
130  bool mesh_check_and_update();
131 
132  // method to compute the size of the smallest
133  // cell of the computational grid
134 
135  void compute_min_diameter();
136 
137 
138  // in the imported mesh, the nodes on the
139  // domain edges are doubled: this routine
140  // creates a std::vector of std::set which
141  // allows to relate each node to their
142  // double(s)
143 
144  void generate_double_nodes_set();
145 
146 
147  // this method creates the adaptive
148  // octree partitioning of the domain,
149  // needed by the FMA algorithm
150 
151  void generate_octree_blocking();
152  // this function adjusts the boat
153  // superficial mesh for each time instant
154  // of the simulation
155 
156  void boat_mesh_smoothing();
157 
158  // this function adjusts the inflow
159  // surface mesh for each time instant
160  // of the simulation (waves motion
161  // might flip some cells on top of
162  // such surface)
163 
164  void inflow_mesh_smoothing();
165 
166  void dump_tria(std::string fname) const;
167 
168  void restore_tria(std::string fname);
169 
170  // computation of normals at collocation points (dofs)
171  void compute_normals();
172 
173 
174  void update_support_points();
175 
176 
177  // Here are the members of the class:
178  // they are all public, as the upper level
179  // classes (bem_problem, bem_fma,
180  // free_surface) will all need to perform
181  // operations based on the greometry (and
182  // the tools to handle it) contained in
183  // this class
184 
185 
186  // here are some basic classes needed by
187  // the program: a triangulation, and the
188  // FiniteElement and DoFHandler classes.
189  // A second DoF handler and FiniteElement
190  // must be created in order to compute
191  // the solution gradients, which are
192  // vectorial functions
193 
194  //const unsigned int fe_degree;
195  const unsigned int mapping_degree;
196 
199  FE_Q<dim-1,dim> fe;
200  DoFHandler<dim-1,dim> dh;
201  FESystem<dim-1,dim> vector_fe;
202  DoFHandler<dim-1,dim> vector_dh;
203 
204  // these are the std::vectors of std::sets
205  // containing informations on multiple
206  // nodes on the edges: one vector is
207  // created for the points associated with
208  // the degrees of freedom of the potential
209  // function, and one is created for the
210  // points associated with the degrees of
211  // freedom of its gradient (a vector field)
212 
213  std::vector <std::set<unsigned int> > double_nodes_set;
214  std::vector <std::set<unsigned int> > vector_double_nodes_set;
215 
216  // An Eulerian Mapping is created to deal
217  // with the free surface and boat mesh
218  // deformation
219 
221  //MappingQ<dim-1, dim> mapping;
222  //MappingQEulerian<dim-1, Vector<double>, dim> * mapping;
223  Mapping<dim-1, dim> * mapping;
224  // here we are just renaming the cell
225  // iterator
226 
227  typedef typename DoFHandler<dim-1,dim>::active_cell_iterator cell_it;
228  typedef typename Triangulation<dim-1,dim>::active_cell_iterator tria_it;
229 
230 
231  // the following vectors are needed to
232  // treat Dirichlet and Neumann nodes
233  // differently. Each component of the
234  // first one is null if it corresponds
235  // to a Dirichlet node, and zero if
236  // it corresponds to a Neumann node.
237  // The second vector has instead null
238  // entries for Dirichlet nodes, and ones
239  // for Neumann nodes
240 
243 
244  // values to be imported from the
245  // parameters file:
246 
247  // number of refining cycles
248 
249  unsigned int n_cycles;
250 
251  // the number of standard quadrature points
252  // and singular kernel quadrature to be
253  // used
254 
255  std_cxx1x::shared_ptr<Quadrature<dim-1> > quadrature;
257 
258  // the material ID numbers in the mesh
259  // input file, for the free surface cells
260  // and wall boundary (boat) cells
261 
262  unsigned int free_sur_ID1;
263  unsigned int free_sur_ID2;
264  unsigned int free_sur_ID3;
265  unsigned int wall_sur_ID1;
266  unsigned int wall_sur_ID2;
267  unsigned int wall_sur_ID3;
268  unsigned int inflow_sur_ID1;
269  unsigned int inflow_sur_ID2;
270  unsigned int inflow_sur_ID3;
271  unsigned int pressure_sur_ID;
273 
274  // number of levels of the octree
275  // partitioning
276 
277  unsigned int num_octree_levels;
278 
279  // here are declared dome structures which
280  // will be created in the framework of the
281  // octree partitioning of the mesh, and
282  // will be used in the FMA
283 
284  // a map associating each DoF with the cells
285  // it belongs to
286 
287  std::map<unsigned int, std::vector<cell_it> > dof_to_elems;
288 
289  // a map associating each gradient DoF
290  // with the cells it belongs to
291 
292  std::map<unsigned int, std::vector<cell_it> > vector_dof_to_elems;
293 
294  // a vector associating each gradient DoF
295  // with the component it represents
296 
297  std::vector<unsigned int > vector_dof_components;
298 
299  // a map associating each DoF to the
300  // block it belongs to
301  // for each level
302 
303  std::map<unsigned int, std::vector<unsigned int> > dof_to_block;
304 
305  // a map associating each quad point to the
306  // block it belongs to for
307  // each level
308 
309  std::map<cell_it, std::vector<std::vector <unsigned int> > > quad_point_to_block;
310 
311  // a map associating each cell with a std::set
312  // containing the surrounding
313  // cells
314 
315  std::map <cell_it, std::set <cell_it> > elem_to_surr_elems;
316 
317  // a vector to store all OctreeBlocks
318  // in which the geometry is divided
319 
320  mutable std::vector<OctreeBlock<dim> *> blocks;
321 
322  // the total blocks number
323 
324  unsigned int num_blocks;
325 
326  // the indices in the blocks vector, at which
327  // each of the levels start or end
328 
329  std::vector <unsigned int> endLevel;
330  std::vector <unsigned int> startLevel;
331 
332  // a list of the indices of all the childless
333  // blocks
334 
335  std::vector <unsigned int> childlessList;
336 
337  // a list of the number of parent blocks
338  // for each level
339  std::vector <unsigned int> numParent;
340 
341  // a std::vector containing the list of
342  // parent blocks for each level
343 
344  std::vector <std::vector<unsigned int> > parentList;
345 
346  // a std::map of std::vectors containing the
347  // list of quadrature points
348 
349  std::map <cell_it, std::vector <Point <dim> > > quadPoints;
350 
351  // a std::map of std::vectors containing the
352  // list of normals at quadrature points
353 
354  std::map <cell_it, std::vector <Point <dim> > > quadNormals;
355 
356  // a std::map of std::vectors containing the
357  // list of shape function values at
358  // quadrature points
359 
360  std::map <cell_it, std::vector <std::vector<double> > > quadShapeFunValues;
361 
362  // a std::map of std::vectors containing the
363  // list of JxW values at
364  // quadrature points
365 
366  std::map <cell_it, std::vector <double > > quadJxW;
367 
368  // a std::vector containing std::vectors with
369  // the IDs of blocks with at least one dof,
370  // for each level
371 
372  std::vector< std::vector<unsigned int> > dofs_filled_blocks;
373 
374  // a std::vector containing std::vectors with
375  // the IDs of blocks with at least one
376  // quad point, for each level
377 
378  std::vector< std::vector<unsigned int> > quad_points_filled_blocks;
379 
380 
381  // a std::set containing nodes of
382  // free surface with doubles on the boat
383  // needed to calculate their displacement
384 
385  std::set<unsigned int> free_surf_and_boat_nodes;
386 
387  // a std::set containing nodes of
388  // the boat with nodes on the boat
389  // needed to calculate the boat
390  // surface smoothing
391 
392  std::set<unsigned int> boat_nodes;
393 
394 
395 
396  //______________________
397  //just for check: to be removed
398 
399  std::map <unsigned int, std::map<cell_it,unsigned int> > integralCheck;
400 
401 
402  double min_diameter;
403 
404  std::vector<Point<dim> > vector_support_points;
405  std::vector<Point<dim> > support_points;
406  std::vector<GeometryFlags> flags;
407  std::vector<GeometryFlags> vector_flags;
408  std::vector<GeometryFlags> cell_flags;
409  // this is the vector with the support points
410  // in reference position
411  std::vector<Point<3> > ref_points;
412 
413  // vector of Point<dim> containing the node normals
414 
415  std::vector<Point<dim> > nodes_normals;
416 };
417 
418 #endif
DoFHandler< dim-1, dim >::active_cell_iterator cell_it
std::vector< std::vector< unsigned int > > dofs_filled_blocks
std::vector< Point< dim > > nodes_normals
std::vector< GeometryFlags > cell_flags
DoFHandler< dim-1, dim > vector_dh
std::map< cell_it, std::vector< double > > quadJxW
std::vector< Point< dim > > support_points
Triangulation< dim-1, dim > coarse_tria
std::vector< unsigned int > endLevel
Vector< double > other_nodes
std::vector< OctreeBlock< dim > * > blocks
FE_Q< dim-1, dim > fe
std::map< unsigned int, std::vector< unsigned int > > dof_to_block
std_cxx1x::shared_ptr< Quadrature< dim-1 > > quadrature
std::vector< std::vector< unsigned int > > parentList
std::map< cell_it, std::vector< std::vector< double > > > quadShapeFunValues
std::map< unsigned int, std::map< cell_it, unsigned int > > integralCheck
Vector< double > map_points
std::set< unsigned int > boat_nodes
const unsigned int mapping_degree
std::vector< unsigned int > numParent
std::vector< GeometryFlags > flags
Vector< double > surface_nodes
std::map< cell_it, std::vector< std::vector< unsigned int > > > quad_point_to_block
unsigned int singular_quadrature_order
FESystem< dim-1, dim > vector_fe
std::vector< unsigned int > vector_dof_components
std::set< unsigned int > free_surf_and_boat_nodes
std::vector< Point< dim > > vector_support_points
std::vector< std::vector< unsigned int > > quad_points_filled_blocks
PersistentTriangulation< dim-1, dim > tria
std::map< cell_it, std::set< cell_it > > elem_to_surr_elems
unsigned int free_sur_edge_on_boat_ID
std::vector< std::set< unsigned int > > vector_double_nodes_set
Mapping< dim-1, dim > * mapping
std::map< cell_it, std::vector< Point< dim > > > quadNormals
std::vector< unsigned int > childlessList
std::vector< std::set< unsigned int > > double_nodes_set
std::vector< unsigned int > startLevel
DoFHandler< dim-1, dim > dh
std::vector< GeometryFlags > vector_flags
std::vector< Point< 3 > > ref_points
Triangulation< dim-1, dim >::active_cell_iterator tria_it
std::map< unsigned int, std::vector< cell_it > > dof_to_elems
std::map< cell_it, std::vector< Point< dim > > > quadPoints
std::map< unsigned int, std::vector< cell_it > > vector_dof_to_elems