deal2lkit: A ToolKit library for Deal.II
parsed_dirichlet_bcs.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2015 by the deal2lkit authors
4 //
5 // This file is part of the deal2lkit library.
6 //
7 // The deal2lkit library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal2lkit distribution.
13 //
14 //-----------------------------------------------------------
15 
17 
18 
19 
20 D2K_NAMESPACE_OPEN
21 
22 
23 
24 template <int dim, int spacedim>
26 ParsedDirichletBCs (const std::string &parsed_name,
27  const unsigned int &n_components,
28  const std::string &parsed_component_names,
29  const std::string &parsed_id_components,
30  const std::string &parsed_id_functions,
31  const std::string &parsed_constants)
32  :
33 
34  ParsedMappedFunctions<spacedim>(parsed_name,
35  n_components,
36  parsed_component_names,
37  parsed_id_components,
38  parsed_id_functions,
39  parsed_constants),
40  n_components(n_components)
41 {}
42 
43 template<int dim, int spacedim>
45 {
47 }
48 
49 template<int dim, int spacedim>
51 {
53 }
54 
55 template<int dim, int spacedim>
57  ConstraintMatrix &constraints) const
58 {
59  std::vector<unsigned int> ids = this->get_mapped_ids();
60  for (unsigned int i=0; i<ids.size(); ++i)
62  ids[i],
63  *(this->get_mapped_function(ids[i])),
64  constraints,
65  this->get_mapped_mask(ids[i]));
66 }
67 
68 template<int dim, int spacedim>
70  const DoFHandler<dim,spacedim> &dof_handler,
71  ConstraintMatrix &constraints) const
72 {
73  std::vector<unsigned int> ids = this->get_mapped_ids();
74  for (unsigned int i=0; i<ids.size(); ++i)
76  dof_handler,
77  ids[i],
78  *(this->get_mapped_function(ids[i])),
79  constraints,
80  this->get_mapped_mask(ids[i]));
81 }
82 
83 template<int dim, int spacedim>
85  std::map<types::global_dof_index,double> &d_dofs) const
86 {
87  std::vector<unsigned int> ids = this->get_mapped_ids();
88  for (unsigned int i=0; i<ids.size(); ++i)
90  ids[i],
91  *(this->get_mapped_function(ids[i])),
92  d_dofs,
93  this->get_mapped_mask(ids[i]));
94 }
95 
96 template<int dim, int spacedim>
98  const DoFHandler<dim,spacedim> &dof_handler,
99  std::map<types::global_dof_index,double> &d_dofs) const
100 {
101  std::vector<unsigned int> ids = this->get_mapped_ids();
102  for (unsigned int i=0; i<ids.size(); ++i)
104  dof_handler,
105  ids[i],
106  *(this->get_mapped_function(ids[i])),
107  d_dofs,
108  this->get_mapped_mask(ids[i]));
109 }
110 
111 
112 // [TODO] Fix this in deal.II.
113 
114 template<>
115 void ParsedDirichletBCs<1, 2>::project_boundary_values(dealii::DoFHandler<1, 2> const &, dealii::Quadrature<0> const &, dealii::ConstraintMatrix &) const
116 {
118 }
119 
120 template<>
121 void ParsedDirichletBCs<1, 3>::project_boundary_values(dealii::DoFHandler<1, 3> const &, dealii::Quadrature<0> const &, dealii::ConstraintMatrix &) const
122 {
124 }
125 
126 template<>
127 void ParsedDirichletBCs<2, 3>::project_boundary_values(dealii::DoFHandler<2, 3> const &, dealii::Quadrature<1> const &, dealii::ConstraintMatrix &) const
128 {
130 }
131 
132 
133 template<>
135  dealii::DoFHandler<1, 2> const &,
136  dealii::Quadrature<0> const &, dealii::ConstraintMatrix &) const
137 {
139 }
140 
141 template<>
143  dealii::DoFHandler<1, 3> const &,
144  dealii::Quadrature<0> const &, dealii::ConstraintMatrix &) const
145 {
147 }
148 
149 
150 
151 template<>
153  dealii::DoFHandler<2, 3> const &,
154  dealii::Quadrature<1> const &, dealii::ConstraintMatrix &) const
155 {
157 }
158 
159 
160 
161 
162 template <int dim, int spacedim>
164  const DoFHandler<dim,spacedim> &dof_handler,
165  const Quadrature<dim-1> &quadrature,
166  ConstraintMatrix &constraints) const
167 {
168  std::vector<unsigned int> ids = this->get_mapped_ids();
169  for (unsigned int i=0; i<ids.size(); ++i)
170  {
171  typename FunctionMap<spacedim>::type boundary_map;
172 
174  f = &(*(this->get_mapped_function(ids[i])));
175  boundary_map[ids[i]] = f;
176 
177  // from bool to int
178  std::vector<unsigned int> component_mapping;
179  if (spacedim > 1) // component_mapping is not supported in deal.II for dim==1
180  for (unsigned int j=0; j<component_mapping.size(); ++j)
181  component_mapping.push_back(this->get_mapped_mask(ids[i])[j]);
182 
184  dof_handler,
185  boundary_map,
186  quadrature,
187  constraints,
188  component_mapping);
189  }
190 }
191 
192 template <int dim, int spacedim>
194  const Quadrature<dim-1> &quadrature,
195  ConstraintMatrix &constraints) const
196 {
197  std::vector<unsigned int> ids = this->get_mapped_ids();
198  for (unsigned int i=0; i<ids.size(); ++i)
199  {
200  typename FunctionMap<spacedim>::type boundary_map;
201 
203  f = &(*(this->get_mapped_function(ids[i])));
204  boundary_map[ids[i]] = f;
205 
206  // from bool to int
207  std::vector<unsigned int> component_mapping;
208  if (spacedim > 1) // component_mapping is not supported in deal.II for dim==1
209  for (unsigned int j=0; j<component_mapping.size(); ++j)
210  component_mapping.push_back(this->get_mapped_mask(ids[i])[j]);
211 
213  boundary_map,
214  quadrature,
215  constraints,
216  component_mapping);
217  }
218 }
219 
220 template<>
221 void
223  DoFHandler<1, 2> const &,
224  Quadrature<0> const &,
225  std::map<types::global_dof_index, double> &) const
226 {
227  Assert(false, ExcImpossibleInDim(1));
228 }
229 
230 template<>
231 void
233  DoFHandler<1, 3> const &,
234  Quadrature<0> const &,
235  std::map<types::global_dof_index, double> &) const
236 {
237  Assert(false,ExcImpossibleInDim(1));
238 }
239 
240 
241 
242 template<>
243 void
245  DoFHandler<2, 3> const &,
246  Quadrature<1> const &,
247  std::map<types::global_dof_index, double> &) const
248 {
249  Assert(false,ExcImpossibleInDim(2));
250 }
251 
252 
253 template <int dim, int spacedim>
255  const DoFHandler<dim,spacedim> &dof_handler,
256  const Quadrature<dim-1> &quadrature,
257  std::map<types::global_dof_index,double> &projected_bv) const
258 {
259  std::vector<unsigned int> ids = this->get_mapped_ids();
260  for (unsigned int i=0; i<ids.size(); ++i)
261  {
262  typename FunctionMap<spacedim>::type boundary_map;
263 
265  f = &(*(this->get_mapped_function(ids[i])));
266  boundary_map[ids[i]] = f;
267 
268  // from bool to int
269  std::vector<unsigned int> component_mapping;
270  if (spacedim > 1) // component_mapping is not supported in deal.II for dim==1
271  for (unsigned int j=0; j<n_components; ++j)
272  component_mapping.push_back(this->get_mapped_mask(ids[i])[j]);
273 
275  dof_handler,
276  boundary_map,
277  quadrature,
278  projected_bv,
279  component_mapping);
280 
281  }
282 }
283 
284 
285 template <>
287  const Quadrature<0> &,
288  std::map<types::global_dof_index,double> &) const
289 {
290  Assert(false,ExcImpossibleInDim(1));
291 }
292 
293 
294 template <>
296  const Quadrature<0> &,
297  std::map<types::global_dof_index,double> &) const
298 {
299  Assert(false,ExcImpossibleInDim(1));
300 }
301 
302 
303 template <>
305  const Quadrature<1> &,
306  std::map<types::global_dof_index,double> &) const
307 {
308  Assert(false,ExcNotImplemented());
309 }
310 
311 
312 template <int dim, int spacedim>
314  const Quadrature<dim-1> &quadrature,
315  std::map<types::global_dof_index,double> &projected_bv) const
316 {
317  std::vector<unsigned int> ids = this->get_mapped_ids();
318  for (unsigned int i=0; i<ids.size(); ++i)
319  {
320  typename FunctionMap<spacedim>::type boundary_map;
321 
323  f = &(*(this->get_mapped_function(ids[i])));
324  boundary_map[ids[i]] = f;
325 
326  // from bool to int
327  std::vector<unsigned int> component_mapping;
328  if (spacedim > 1) // component_mapping is not supported in deal.II for dim==1
329  for (unsigned int j=0; j<n_components; ++j)
330  component_mapping.push_back(this->get_mapped_mask(ids[i])[j]);
331 
333  boundary_map,
334  quadrature,
335  projected_bv,
336  component_mapping);
337  }
338 }
339 
340 
341 
342 template <>
344  ConstraintMatrix &) const
345 {
346  Assert(false,ExcImpossibleInDim(1));
347 }
348 
349 template<>
351  const Mapping<1, 1> &,
352  ConstraintMatrix &) const
353 {
354  Assert(false,ExcImpossibleInDim(1));
355 }
356 
357 
358 
359 template<>
361  ConstraintMatrix &) const
362 {
363  Assert(false,ExcImpossibleInDim(1));
364 }
365 
366 template <>
368  const Mapping<1,1> &,
369  ConstraintMatrix &) const
370 {
371  Assert(false,ExcImpossibleInDim(1));
372 }
373 
374 
375 
376 template <>
378  ConstraintMatrix &) const
379 {
380  Assert(false,ExcImpossibleInDim(1));
381 }
382 
383 template<>
385  const Mapping<1,2> &,
386  ConstraintMatrix &) const
387 {
388  Assert(false,ExcImpossibleInDim(1));
389 }
390 
391 
392 
393 template<>
395  ConstraintMatrix &) const
396 {
397  Assert(false,ExcImpossibleInDim(1));
398 }
399 
400 template <>
402  const Mapping<1,2> &,
403  ConstraintMatrix &) const
404 {
405  Assert(false,ExcImpossibleInDim(1));
406 }
407 
408 
409 template <>
411  ConstraintMatrix &) const
412 {
413  Assert(false,ExcImpossibleInDim(1));
414 }
415 
416 template<>
418  const Mapping<1,3> &,
419  ConstraintMatrix &) const
420 {
421  Assert(false,ExcImpossibleInDim(1));
422 }
423 
424 
425 
426 template<>
428  ConstraintMatrix &) const
429 {
430  Assert(false,ExcImpossibleInDim(1));
431 }
432 
433 template <>
435  const Mapping<1,3> &,
436  ConstraintMatrix &) const
437 {
438  Assert(false,ExcImpossibleInDim(1));
439 }
440 
441 
442 
443 template <>
445  ConstraintMatrix &) const
446 {
447  Assert(false,ExcImpossibleInDim(2));
448 }
449 
450 template<>
452  const Mapping<2,3> &,
453  ConstraintMatrix &) const
454 {
455  Assert(false,ExcImpossibleInDim(2));
456 }
457 
458 
459 
460 template<>
462  ConstraintMatrix &) const
463 {
464  Assert(false,ExcImpossibleInDim(2));
465 }
466 
467 template <>
469  const Mapping<2,3> &,
470  ConstraintMatrix &) const
471 {
472  Assert(false,ExcImpossibleInDim(2));
473 }
474 
475 
476 template <int dim, int spacedim>
478  ConstraintMatrix &constraints) const
479 {
480  std::set<types::boundary_id> no_normal_flux_boundaries;
481 
482  typedef std::map<std::string, std::pair<std::vector<unsigned int>, unsigned int > >::const_iterator it_type;
483 
484  for (it_type it=this->mapped_normal_components.begin(); it != this->mapped_normal_components.end(); ++it)
485  {
486  std::vector<unsigned int> normal_ids = (it->second).first;
487 
488  for (unsigned int i=0; i<normal_ids.size(); ++i)
489  no_normal_flux_boundaries.insert(normal_ids[i]);
490 
492  (it->second).second, // unsigned int first component vector
493  no_normal_flux_boundaries,
494  constraints);
495  }
496 }
497 
498 template <int dim, int spacedim>
500  const Mapping< dim, spacedim > &mapping,
501  ConstraintMatrix &constraints) const
502 {
503  std::set<types::boundary_id> no_normal_flux_boundaries;
504 
505  typedef std::map<std::string, std::pair<std::vector<unsigned int>, unsigned int > >::const_iterator it_type;
506 
507  for (it_type it=this->mapped_normal_components.begin(); it != this->mapped_normal_components.end(); ++it)
508  {
509  std::vector<unsigned int> normal_ids = (it->second).first;
510 
511  for (unsigned int i=0; i<normal_ids.size(); ++i)
512  no_normal_flux_boundaries.insert(normal_ids[i]);
513 
515  (it->second).second, // unsigned int first component vector
516  no_normal_flux_boundaries,
517  constraints,
518  mapping);
519  }
520 }
521 
522 
523 template <int dim, int spacedim>
525  ConstraintMatrix &constraints) const
526 {
527  std::set<types::boundary_id> no_normal_flux_boundaries;
528 
529  typedef std::map<std::string, std::pair<std::vector<unsigned int>, unsigned int > >::const_iterator it_type;
530 
531  for (it_type it=this->mapped_normal_components.begin(); it != this->mapped_normal_components.end(); ++it)
532  {
533  typename FunctionMap<spacedim>::type boundary_map;
534 
535  std::vector<unsigned int> normal_ids = (it->second).first;
536  unsigned int fcv = (it->second).second; // unsigned int first component vector
537 
538  for (unsigned int i=0; i<normal_ids.size(); ++i)
539  {
541  f = &(*(this->get_mapped_normal_function(normal_ids[i], fcv)));
542  boundary_map[normal_ids[i]] = f;
543  no_normal_flux_boundaries.insert(normal_ids[i]);
544  }
545 
547  fcv,
548  no_normal_flux_boundaries,
549  boundary_map,
550  constraints);
551  }
552 }
553 
554 template <int dim, int spacedim>
556  const Mapping< dim, spacedim > &mapping,
557  ConstraintMatrix &constraints) const
558 {
559  std::set<types::boundary_id> no_normal_flux_boundaries;
560 
561  typedef std::map<std::string, std::pair<std::vector<unsigned int>, unsigned int > >::const_iterator it_type;
562 
563  for (it_type it=this->mapped_normal_components.begin(); it != this->mapped_normal_components.end(); ++it)
564  {
565  typename FunctionMap<spacedim>::type boundary_map;
566 
567  std::vector<unsigned int> normal_ids = (it->second).first;
568  unsigned int fcv = (it->second).second; // unsigned int first component vector
569 
570  for (unsigned int i=0; i<normal_ids.size(); ++i)
571  {
573 
574  f = &(*(this->get_mapped_normal_function(normal_ids[i], fcv)));
575  boundary_map[normal_ids[i]] = f;
576  no_normal_flux_boundaries.insert(normal_ids[i]);
577  }
578 
580  fcv,
581  no_normal_flux_boundaries,
582  boundary_map,
583  constraints,
584  mapping);
585  }
586 }
587 
588 template class ParsedDirichletBCs<1,1>;
589 template class ParsedDirichletBCs<1,2>;
590 template class ParsedDirichletBCs<1,3>;
591 template class ParsedDirichletBCs<2,2>;
592 template class ParsedDirichletBCs<2,3>;
593 template class ParsedDirichletBCs<3,3>;
594 
595 D2K_NAMESPACE_CLOSE
void interpolate_boundary_values(const Mapping< dim, spacedim > &mapping, const DoFHandlerType< dim, spacedim > &dof, const std::map< types::boundary_id, const Function< spacedim, number > *> &function_map, std::map< types::global_dof_index, number > &boundary_values, const ComponentMask &component_mask=ComponentMask())
void compute_nonzero_normal_flux_constraints(const DoFHandler< dim, spacedim > &dof_handler, ConstraintMatrix &constraints) const
This function must be called in order to apply the Dirichlet boundary conditions to the normal compon...
void interpolate_boundary_values(const DoFHandler< dim, spacedim > &dof_handler, ConstraintMatrix &constraints) const
This function must be called in order to apply the boundary conditions to the ConstraintMatrix.
static ParameterHandler prm
Static parameter.
std::vector< unsigned int > ids
void compute_no_normal_flux_constraints(const DoFHandlerType< dim, spacedim > &dof_handler, const unsigned int first_vector_component, const std::set< types::boundary_id > &boundary_ids, ConstraintMatrix &constraints, const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim >::mapping)
Parsed DirichletBCs.
void compute_nonzero_normal_flux_constraints(const DoFHandlerType< dim, spacedim > &dof_handler, const unsigned int first_vector_component, const std::set< types::boundary_id > &boundary_ids, typename FunctionMap< spacedim >::type &function_map, ConstraintMatrix &constraints, const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim >::mapping)
std::vector< unsigned int > normal_ids
ParsedMappedFunctions object.
std::vector< unsigned int > get_mapped_ids() const
return the list of the mapped ids
virtual void parse_parameters_call_back()
these method calls the method of the Parent class
virtual void declare_parameters(ParameterHandler &prm)
these method calls the method of the Parent class
static::ExceptionBase & ExcImpossibleInDim(int arg1)
std::map< std::string, std::pair< std::vector< unsigned int >, unsigned int > > mapped_normal_components
virtual void parse_parameters_call_back()
parse_parameters_call_back is inherithed by ParameterAcceptor
#define Assert(cond, exc)
void project_boundary_values(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const std::map< types::boundary_id, const Function< spacedim, number > *> &boundary_functions, const Quadrature< dim-1 > &q, std::map< types::global_dof_index, number > &boundary_values, std::vector< unsigned int > component_mapping=std::vector< unsigned int >())
std::map< types::boundary_id, const Function< dim, Number > *> type
virtual void declare_parameters(ParameterHandler &prm)
declare_parameters is inherithed by ParameterAcceptor
ParsedDirichletBCs(const std::string &name="Dirichlet BCs", const unsigned int &n_components=1, const std::string &component_names="", const std::string &default_id_components="0=ALL", const std::string &default_id_functions="", const std::string &default_constants="")
Constructor.
void compute_no_normal_flux_constraints(const DoFHandler< dim, spacedim > &dof_handler, ConstraintMatrix &constraints) const
This function must be called in order to apply the homogeneous Dirichlet boundary conditions to the n...
static::ExceptionBase & ExcNotImplemented()
shared_ptr< dealii::Functions::ParsedFunction< spacedim > > get_mapped_function(const unsigned int &id) const
return a shared_ptr to the ParsedFunction corresponding to the given id
void project_boundary_values(const DoFHandler< dim, spacedim > &dof_handler, const Quadrature< dim-1 > &quadrature, ConstraintMatrix &constraints) const
This function must be called in order to apply the boundary conditions to the ConstraintMatrix.
shared_ptr< dealii::Functions::ParsedFunction< spacedim > > get_mapped_normal_function(const unsigned int &id, const unsigned int &fcv) const
return a shared_ptr to the ParsedFunction corresponding to the given id the function has spacedim com...
const unsigned int n_components
Number of components of the underlying Function objects.
ComponentMask get_mapped_mask(const unsigned int &id) const
return the ComponentMask corresponding to the given id