WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
surface_smoothing.cc
Go to the documentation of this file.
1 #include "surface_smoothing.h"
2 
6 #include <deal.II/grid/tria.h>
12 
20 
21 // all include files you need here
22 
24 #include <deal.II/dofs/dof_tools.h>
25 #include <deal.II/fe/fe_q.h>
26 #include <deal.II/fe/fe_system.h>
27 #include <deal.II/fe/mapping_q1.h>
30 
31 #include "occ_utilities.h"
32 
33 using namespace dealii;
34 using namespace std;
35 using namespace OpenCascade;
36 
38  Vector<double> &curvature_vector,
39  const DoFHandler<2,3> &dh,
40  const Mapping<2,3> &mapping) :
41  euler_vector(euler_vector),
42  curvature_vector(curvature_vector),
43  dh(dh),
44  mapping(mapping)
45 {
47 }
48 
50 {
53 
56 
59  rhs.reinit(dh.n_dofs());
60 
61  matrix.clear();
63 
67 
68  CompressedSparsityPattern csp (dh.n_dofs(), dh.n_dofs());
70  sparsity.copy_from (csp);
71 
74 
75  vector<Point<3> > ref_support_points(dh.n_dofs());
76  // Compute the reference support
77  // points.
78  DoFTools::map_dofs_to_support_points<2,3>(StaticMappingQ1<2,3>::mapping,
79  dh, ref_support_points);
80 
81  // build the reference_identity
82  // vector
83  for (unsigned int i=0; i<dh.n_dofs(); ++i)
84  reference_identity(i) = ref_support_points[i](i%3);
85 
86  std::vector< bool > comp_sel(3, true);
87  boundary_dofs.resize(dh.n_dofs());
88 
90 }
91 
93 {
96 
98 //cout<<"S1"<<endl;
100 //cout<<"S2"<<endl;
101  solve_system();
102 //cout<<"S3"<<endl;
104 //cout<<"S4"<<endl;
105 }
106 
108 {
109  boundary_values.clear();
110 
111  for (unsigned int i=0; i<dh.n_dofs(); ++i)
112  if (boundary_dofs[i] == true)
113  {
115  curvature_vector(i) = 0;
116  }
117 }
118 
120 {
122 }
123 
124 
126 {
127  solution = 0;
128  rhs = 0;
129  matrix = 0;
130  //cout<<"SS1"<<endl;
131  const FiniteElement<2,3> &fe = dh.get_fe();
132  QGauss<2> quad(fe.degree*2+1);
133 
134  FEValues<2,3> fe_v(mapping, fe, quad,
135  update_values |
136  update_gradients |
137  update_JxW_values);
138  //cout<<"SS2"<<endl;
139  const unsigned int n_q_points = fe_v.n_quadrature_points;
140  const unsigned int dofs_per_cell = fe.dofs_per_cell;
141  std::vector<unsigned int> local_dof_indices (dofs_per_cell);
142  std::vector<Vector<double> > local_curvature (n_q_points, Vector<double>(3));
143 
144  FullMatrix<double> local_matrix (dofs_per_cell, dofs_per_cell);
145  FullMatrix<double> local_mass_matrix (dofs_per_cell, dofs_per_cell);
146  Vector<double> local_rhs (dofs_per_cell);
147  //cout<<"SS3"<<endl;
149  cell = dh.begin_active(),
150  endc = dh.end();
151  //cout<<"SS4"<<endl;
152  for (; cell!=endc; ++cell)
153  {
154  fe_v.reinit (cell);
155  local_matrix = 0;
156  local_mass_matrix = 0;
157  local_rhs = 0;
158  fe_v.get_function_values(curvature,
159  local_curvature);
160 
161  unsigned int comp_i, comp_j;
162 
163  for (unsigned int i=0; i<dofs_per_cell; ++i)
164  {
165  comp_i = fe.system_to_component_index(i).first;
166  for (unsigned int j=0; j<dofs_per_cell; ++j)
167  {
168  comp_j = fe.system_to_component_index(j).first;
169  if (comp_i == comp_j)
170 
171  for (unsigned int q=0; q<n_q_points; ++q)
172  {
173  local_matrix(i,j) += fe_v.shape_grad(i,q)*
174  fe_v.shape_grad(j,q)*
175  fe_v.JxW(q);
176  local_mass_matrix(i,j) += fe_v.shape_value(i,q)*
177  fe_v.shape_value(j,q)*
178  fe_v.JxW(q);
179 
180  }
181  }
182  for (unsigned int q=0; q<n_q_points; ++q)
183  {
184  local_rhs(i) += fe_v.shape_value(i,q)*
185  local_curvature[q](comp_i)*
186  fe_v.JxW(q);
187  }
188  }
189  //cout<<"SS5"<<endl;
190  cell->get_dof_indices (local_dof_indices);
191 
193  (local_matrix, local_rhs, local_dof_indices, matrix, rhs);
194 
196  (local_mass_matrix, local_dof_indices, mass_matrix);
197  //cout<<"SS6"<<endl;
198  }
200  //cout<<"SS7"<<endl;
201 }
202 
204 {
205  SparseDirectUMFPACK inverse;
206  inverse.initialize(matrix);
207  inverse.vmult(solution, rhs);
209 }
210 
211 
213 {
214  Assert(curvatures.size() == dh.n_dofs(),
215  ExcDimensionMismatch(curvatures.size(), dh.n_dofs()));
216  Vector <double> positions(dh.n_dofs());
217  for (unsigned int i=0; i<dh.n_dofs(); ++i)
218  {
219  positions(i) = reference_identity(i)+euler_vector(i);
220  }
221  assemble_system();
222  matrix.vmult(curvatures,positions);
223  SparseDirectUMFPACK inverse_mass;
224  inverse_mass.initialize(mass_matrix);
225  inverse_mass.solve(curvatures);
226  constraints.distribute(curvatures);
227 }
228 
230  const vector<bool> &boundary_dofs)
231 {
232  AssertThrow(curvatures.size() == dh.n_dofs(),
233  ExcDimensionMismatch(curvatures.size(), dh.n_dofs()));
234  //fix_boundary_values();
235 
236  boundary_values.clear();
237 
238  for (unsigned int i=0; i<dh.n_dofs(); ++i)
239  if (boundary_dofs[i] == true)
240  {
242  curvature_vector(i) = 0;
243  }
244 
245  assemble_system(curvatures);
246  solve_system();
248 }
249 
void get_function_values(const InputVector &fe_function, std::vector< typename InputVector::value_type > &values) const
const Tensor< 1, spacedim > & shape_grad(const unsigned int function_no, const unsigned int quadrature_point) const
void update_reference()
Whenever the underlying dh.
void vmult(OutVector &dst, const InVector &src) const
void apply_boundary_values(const std::map< types::global_dof_index, number > &boundary_values, SparseMatrix< number > &matrix, Vector< number > &solution, Vector< number > &right_hand_side, const bool eliminate_columns=true)
active_cell_iterator begin_active(const unsigned int level=0) const
void sadd(const doubles, const Vector< double > &V)
SparseMatrix< double > matrix
Vector< double > & curvature_vector
const unsigned int degree
void distribute(VectorType &vec) const
STL namespace.
#define AssertThrow(cond, exc)
virtual void reinit(const SparsityPattern &sparsity)
void assemble_system()
Assemble the Laplace.
void solve_system()
Solve the system.
void make_hanging_node_constraints(const DoFHandlerType &dof_handler, ConstraintMatrix &constraints)
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
void fix_boundary_values()
All boundaries are fixed to.
#define Assert(cond, exc)
types::global_dof_index n_dofs() const
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void solve(Vector< double > &rhs_and_solution, bool transpose=false) const
std::size_t size() const
void extract_boundary_dofs(const DoFHandlerType &dof_handler, const ComponentMask &component_mask, std::vector< bool > &selected_dofs, const std::set< types::boundary_id > &boundary_ids=std::set< types::boundary_id >())
SparseMatrix< double > mass_matrix
SparsityPattern sparsity
ConstraintMatrix constraints
const DoFHandler< 2, 3 > & dh
void apply_curvatures(const Vector< double > &curvatures, const std::vector< bool > &boundary_dofs)
Apply curvatures at the.
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
cell_iterator end() const
Vector< double > rhs
const unsigned int dofs_per_cell
const unsigned int n_quadrature_points
const Mapping< 2, 3 > & mapping
const double & shape_value(const unsigned int function_no, const unsigned int point_no) const
SurfaceSmoothing(Vector< double > &euler_vector, Vector< double > &curvature_vector, const DoFHandler< 2, 3 > &dh, const Mapping< 2, 3 > &mapping)
Smooth all dofs in.
Vector< double > & euler_vector
void make_sparsity_pattern(const DoFHandlerType &dof_handler, SparsityPatternType &sparsity_pattern, const ConstraintMatrix &constraints=ConstraintMatrix(), const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
void initialize(const SparsityPattern &sparsity_pattern)
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
void smooth()
Perform the full smoothing.
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
void compute_curvatures(Vector< double > &curvatures)
Compute curvatures at the.
std::vector< bool > boundary_dofs
We collect in this namespace all utilities which operate on OpenCascade entities which don't need cla...
Vector< double > reference_identity
Vector< double > solution
void reinit(const TriaIterator< DoFCellAccessor< DoFHandlerType< dim, spacedim >, level_dof_access > > &cell)
virtual void clear()
std::map< unsigned int, double > boundary_values
double JxW(const unsigned int quadrature_point) const
const FiniteElement< dim, spacedim > & get_fe() const
void vmult(Vector< double > &dst, const Vector< double > &src) const