WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
numerical_towing_tank.h
Go to the documentation of this file.
1 
2 //---------------------------- template.cc ---------------------------
3 // $Id: testsuite.html 13373 2006-07-13 13:12:08Z kanschat $
4 // Version: $Name$
5 //
6 // Copyright (C) 2005 by the deal.II authors
7 //
8 // This file is subject to QPL and may not be distributed
9 // without copyright and license information. Please refer
10 // to the file deal.II/doc/license.html for the text and
11 // further information on this license.
12 //
13 //---------------------------- template.cc ---------------------------
14 
15 
16 // a short (a few lines) description of what the program does
17 
18 //#include "../tests.h"
19 // Read goteborg.iges and dump its topological structure to the logfile.
20 
21 #ifndef numerical_towing_tank_h
22 #define numerical_towing_tank_h
23 
24 #include <fstream>
25 #include <iostream>
26 #include <cmath>
27 #include <limits>
28 #include <vector>
29 
30 #include <deal.II/base/logstream.h>
31 
32 #include "occ_utilities.h"
33 #include "occ_normal_projection.h"
35 #include "occ_axis_projection.h"
36 
37 #include <TopTools.hxx>
38 #include <Standard_Stream.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
41 
42 
43 #include <IGESControl_Reader.hxx>
44 #include <IGESControl_Controller.hxx>
45 #include <IGESControl_Writer.hxx>
46 #include <TopoDS.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopoDS_Shell.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <BRepTools.hxx>
51 #include <XSControl_Reader.hxx>
52 #include <TopTools_SequenceOfShape.hxx>
53 #include <Handle_Standard_Transient.hxx>
54 #include <TColStd_SequenceOfTransient.hxx>
55 #include <TColStd_HSequenceOfTransient.hxx>
56 #include <TopExp_Explorer.hxx>
57 #include <gp_Pnt.hxx>
58 #include <gp_Vec.hxx>
59 #include <GeomAPI_ProjectPointOnSurf.hxx>
60 #include <GeomAPI_ProjectPointOnCurve.hxx>
61 #include <Standard_Real.hxx>
62 #include <Standard_Integer.hxx>
63 #include <BRep_Tool.hxx>
64 #include <Geom_Surface.hxx>
65 #include <Geom_Plane.hxx>
66 #include <Prs3d_ShapeTool.hxx>
67 #include <Bnd_Box.hxx>
68 #include <gp_Ax3.hxx>
69 #include <gp_Pln.hxx>
70 #include <BRepBuilderAPI_MakeFace.hxx>
71 #include <GeomAPI_IntSS.hxx>
72 #include <TopoDS_Wire.hxx>
73 #include <BRepBuilderAPI_MakePolygon.hxx>
74 #include <Geom_Curve.hxx>
75 #include <Geom_BoundedCurve.hxx>
76 #include <Geom_TrimmedCurve.hxx>
77 #include <TColGeom_Array1OfCurve.hxx>
78 #include <GeomAPI_IntCS.hxx>
79 #include <BRepBuilderAPI_MakeEdge.hxx>
80 #include <GeomLib_Tool.hxx>
81 #include <GCPnts_AbscissaPoint.hxx>
82 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
83 
86 #include <deal.II/grid/tria.h>
88 #include <deal.II/grid/grid_out.h>
92 #include <deal.II/base/point.h>
93 #include "occ_line_smoothing.h"
94 #include "surface_smoothing.h"
95 #include "computational_domain.h"
96 
97 
99 {
100 public:
101 
102  // constructor: since this is the
103  // class containing all the geometry and
104  // the base instruments needed by all the
105  // other classes, it is created first and
106  // the constructor does not need
107  // arguments.
108  // For the same reason, most of the class
109  // attributes are public: we can leter
110  // make them public end introduce suitable
111  // Get and Set methods, if needed
112 
113  NumericalTowingTank(unsigned int, unsigned int);
114 
115  void full_mesh_treatment();
116  // method to compute interpolated curvatures
117  // for geometrically conformal mesh refinement
118  void compute_curvatures(Vector<double> &curvatures);
119  // method to use interpolated curvatures
120  // for geometrically conformal mesh refinement
121  void apply_curvatures(const Vector<double> &curvatures, const std::vector<bool> boundary_dofs);
122 
123  void partial_mesh_treatment(const double blend_factor);
124 
126 
128 
129  virtual void read_domain();
130  virtual void refine_and_resize();
131  virtual void generate_double_nodes_set();
132 
133  // method to declare the parameters
134  // to be read from the parameters file
135 
136  virtual void declare_parameters(ParameterHandler &prm);
137 
138  // method to parse the needed parameters
139  // from the parameters file
140 
141  virtual void parse_parameters(ParameterHandler &prm);
142 
143  // method to parse mesh from the
144  // input file
145 
146  void create_initial_mesh(const Point<3> PointFrontTop,
147  const Point<3> PointFrontBot,
148  const Point<3> PointMidTop,
149  const Point<3> PointMidBot,
150  const Point<3> PointBackTop,
151  const Point<3> PointBackBot,
152  const Point<3> PointLeftTransom,
153  const Point<3> PointRightTransom,
154  const Point<3> PointCenterTransom,
155  Triangulation<2,3> &triangulation);
156 
157  void refine_global_on_boat(const unsigned int num_refinements);
158 
159  void compute_nodes_flags();
160 
161  void set_up_smoother();
162 
163  void initialize_smoother();
164 
165  void update_smoother();
166 
167  void perform_line_smoothing(unsigned int num_smoothings);
168 
170 
172 
173  void perform_smoothing(bool full_treatment, const double blend_factor);
174 
175  void compute_normals_at_nodes(Vector<double> &map_points_used);
176 
178 
179  // this routine detects if mesh is not
180  // conformal at water/boat edges (because of double
181  // nodes) and makes the refinements needed
182  // to make it conformal
183  void make_edges_conformal(bool isotropic_ref_on_opposite_side);
184  // this routine detects if mesh elements have
185  // high aspect ratio and performs anisotropic
186  // refinements until all aspect ratios are below 1.5
188 
189  // in the first layer of water cells past
190  // the transom there can't be hanging nodes:
191  // this method removes them
193 
194  // this routine finds the index of the vector point p
195  unsigned int find_point_id(const Point<3> &p, const std::vector<Point<3> > &ps);
196  // method to get the ids of all dofs lying on a boundary
197  void extract_boundary_dofs(std::vector<bool> &dofs, unsigned int id,
199  // method to obtain an approximated geom_curve
200  Handle(Geom_Curve) get_curve(const std::vector<Point<3> > &ps,
201  const std::vector<bool> &id,
202  const Point<3> direction);
203 
204  // function that computes (vectorial)
205  // distances of each node from the reference
206  // (CAD) surface. Retunrn zero if point is
207  // on the surface or if no reference surface
208  // is specified for the node considered
209  void evaluate_ref_surf_distances(Vector <double> &distances, const bool only_surf_smoothing=false);
210 
211 
212  // number of refining cycles to be performed on the boat
213  unsigned int n_cycles;
214  // name of the iges file to be used
215  std::string iges_file_name;
216  // we first need a boat model, which
217  // will provide deatails about the
218  // boat geometry
220  // surface smoother for mesh refinements: will use mapping
222  // surface smoother for mesh smoothing: will use static mapping
224  // vector containing all the line smoothers in the
225  // following order
226  // 0. line smoothing class for front part of the keel
227  // 1. line smoothing class for left transom edge/rear part of the keel
228  // 2. line smoothing class for right transom edge/rear part of the keel
229  // 3. line smoothing class for right front water line
230  // 4. line smoothing class for left front water line
231  // 5. line smoothing class for right rear water line
232  // 6. line smoothing class for left rear water line
233  std::vector<OpenCascade::LineSmoothing *> line_smoothers;
234 
235  // vector of vectors of booleans needed to decide which
236  // nodes can be displaced by each smoothing
237  // and which ones are fixed. order is the same as line_smoothers
238  std::vector< std::vector<bool> > boundary_dofs;
239  // contains the ids of the boundaries involved in each
240  // line smoothing
241  std::vector<unsigned int> boundary_ids;
242  // contains the base points of each line smoothing
243  std::vector<Point<3> > base_points;
244  // contains the moving points of each line smoothing
245  std::vector<Point<3> > moving_points;
246  // contains the base points ids of each line smoothing
247  std::vector<unsigned int> base_point_ids;
248  // contains the moving points ids of each line smoothing
249  std::vector<unsigned int> moving_point_ids;
250  // contains the curves of each line smoothing
251  std::vector<Handle(Geom_Curve)> curves;
252  // contains booleans if curve must be rebuilt at each
253  // call of smoothing routine. false for keel smoothings
254  // true for water line smoothings
255  std::vector<bool> on_curve_option;
256  // locations are needed when current hull configuration
257  // is roto-translated
258  std::vector< TopLoc_Location *> smoothers_locations;
259  // nodes flags on the scalar dof_handler
260  std::vector<GeometryFlags> flags;
261  // nodes flags on the vector dof_handler
262  std::vector<GeometryFlags> vector_flags;
263  // vector containing the normals on boat nodes
264  // zero vectors on other nodes
265  std::vector< Point<3> > iges_normals;
266  // vector containing the normals on boat nodes
267  // zero vectors on other nodes, but referred to
268  // grid after remesh
269  std::vector< Point<3> > old_iges_normals;
270  // vector containing the mean curvatures on boat
271  // nodes, and zeros on other nodes
272  std::vector<double> iges_mean_curvatures;
273  // sparsity pattern for the normals problem
275  // constraint matrix for normals problem
277  // matrix for the problem for node normals computation
279  // vector for the rhs of the problem for node normals computation
281  // solution vector to problem for node normals computation
283  // node normals at mesh nodes
284  std::vector<Point<3> > node_normals;
285  // set containing cells on edges
286  std::set<tria_it> edge_cells;
287  // set containing cells on boat bordering with free surface
288  std::set<tria_it> boat_edge_cells;
289  // set containing cells on water bordering with boat
290  std::set<tria_it> water_edge_cells;
291  // map containing cells on boat and bordering cell on free surface
292  std::map<tria_it, tria_it> boat_to_water_edge_cells;
293  // map containing cells on boat and bordering cell on free surface
294  std::map<tria_it, tria_it> water_to_boat_edge_cells;
295  // vector containing right hand side for smoothing beltrami problem
297  // vector containing the euler vector for smoothing (always initialized
298  // as a copy of map_points)
300  // the euler vector at the simulation start
302  // the euler vector obtained right after each restart
304  // the euler vector updated at each time step to account for rigid
305  // motions of the hull
307  // x domain dimension
308  double Lx_domain;
309  // y domain dimension
310  double Ly_domain;
311  // z domain dimension
312  double Lz_domain;
313  // boat wet length
314  double Lx_boat;
315 
316  const unsigned int mapping_degree;
317 
318  // vector with edges tangents at dofs
320  // vector with edges dofs length ratios
322  // boat displacement (in Kg) to be passed to boat model class
324  // this is the sink (positive downwards) to be applied to the hydrostatic
325  // equilibrium position
327  // this is the trim (positive when bow goes up) computed from the
328  // hydrostatic equilibrium position (which is assumed to be the angular
329  // position assigned in the CAD file)
331 
332  // hull moments of inertia
333  double Ixx;
334  double Ixy;
335  double Ixz;
336  double Iyy;
337  double Iyz;
338  double Izz;
339 
340  // here we have the maximum aspect ratio allowed for the cells
342  // the next is a factor determining the inclination of the mesh longitudinal
343  // lines on the front
345  // the next is a factor determining the inclination of the mesh longitudinal
346  // lines on the back
348  // this determines the location of the stern bottom point of the first quadrilaterals
349  // built on the hull (in % of the total immersed length of the keel, starting form
350  // the aft perpendicular)
352  // this determines the location of the bow bottom point of the first quadrilaterals
353  // built on the hull (in % of the total immersed length of the keel, starting form
354  // the fore perpendicular)
356  // this determines the location of the central bottom point of the first quadrilaterals
357  // built on the hull (in % of the total immersed length of the keel, starting form
358  // the fore perpendicular)
360  // number of edges composing the transom stern (temporary)
362  // number of uniform refinements on the boat surface requested for the initial mesh
363  unsigned int init_global_boat_refs;
364  // number of non uniform (curvature based) refinements on the boat surface requested
365  // for the initial mesh
367  // fraction of boat cells to be refined per each cycle in the initial curvature
368  // based refinement
370  // a flag that determines if a boat surface has to be used or the numerical wave tank
371  // has to be prepared for the simulation of free waves
372  bool no_boat;
373 
374 };
375 
376 #endif
const unsigned int mapping_degree
std::vector< Point< 3 > > node_normals
Vector< double > initial_map_points
ConstraintMatrix vector_constraints
DoFHandler< dim-1, dim > vector_dh
SparsityPattern normals_sparsity_pattern
unsigned int init_adaptive_boat_refs
SparseMatrix< double > vector_normals_matrix
unsigned int find_point_id(const Point< 3 > &p, const std::vector< Point< 3 > > &ps)
void apply_curvatures(const Vector< double > &curvatures, const std::vector< bool > boundary_dofs)
Vector< double > vector_normals_rhs
Vector< double > smoothing_curvature_vector
std::vector< unsigned int > boundary_ids
std::set< tria_it > edge_cells
std::vector< std::vector< bool > > boundary_dofs
Vector< double > smoothing_map_points
Vector< double > vector_normals_solution
std::vector< unsigned int > moving_point_ids
std::vector< Point< 3 > > old_iges_normals
void compute_constraints(ConstraintMatrix &cc)
void partial_mesh_treatment(const double blend_factor)
std::vector< GeometryFlags > flags
unsigned int number_of_transom_edges
NumericalTowingTank(unsigned int, unsigned int)
Vector< double > old_map_points
void perform_smoothing(bool full_treatment, const double blend_factor)
virtual void generate_double_nodes_set()
virtual void declare_parameters(ParameterHandler &prm)
std::vector< unsigned int > base_point_ids
void make_edges_conformal(bool isotropic_ref_on_opposite_side)
std::vector< bool > on_curve_option
Vector< double > rigid_motion_map_points
SurfaceSmoothing * surface_smoother
std::map< tria_it, tria_it > water_to_boat_edge_cells
std::vector< double > iges_mean_curvatures
PersistentTriangulation< dim-1, dim > tria
void perform_line_smoothing(unsigned int num_smoothings)
std::vector< GeometryFlags > vector_flags
std::vector< OpenCascade::LineSmoothing * > line_smoothers
void remove_mesh_anisotropy(Triangulation< 2, 3 > &tria)
Vector< double > edges_length_ratios
std::vector< TopLoc_Location * > smoothers_locations
void refine_global_on_boat(const unsigned int num_refinements)
virtual void refine_and_resize()
void compute_normals_at_nodes(Vector< double > &map_points_used)
void compute_curvatures(Vector< double > &curvatures)
std::set< tria_it > boat_edge_cells
SurfaceSmoothing * restart_surface_smoother
std::vector< Point< 3 > > moving_points
void create_initial_mesh(const Point< 3 > PointFrontTop, const Point< 3 > PointFrontBot, const Point< 3 > PointMidTop, const Point< 3 > PointMidBot, const Point< 3 > PointBackTop, const Point< 3 > PointBackBot, const Point< 3 > PointLeftTransom, const Point< 3 > PointRightTransom, const Point< 3 > PointCenterTransom, Triangulation< 2, 3 > &triangulation)
Handle(Geom_Curve) NumericalTowingTank
void extract_boundary_dofs(std::vector< bool > &dofs, unsigned int id, DoFHandler< 2, 3 > &vector_dh)
std::vector< Point< 3 > > iges_normals
virtual void parse_parameters(ParameterHandler &prm)
Vector< double > edges_tangents
std::vector< Handle(Geom_Curve)> curves
unsigned int init_global_boat_refs
std::map< tria_it, tria_it > boat_to_water_edge_cells
std::vector< Point< 3 > > base_points
std::set< tria_it > water_edge_cells
void update_mapping(const Vector< double > &map_points)