Plugins
nedelec_dirichlet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014: G-CSC, Goethe University Frankfurt
3  * Author: Dmitry Logashenko
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 /*
34  * Dirichlet boundary conditions for the rot-rot-discretizations based on the
35  * Nedelec-type-1 elements (the Whitney-1 forms).
36  */
37 #ifndef __H__UG__PLUGINS__ELECTROMAGNETISM__NEDELEC_DIRICHLET__
38 #define __H__UG__PLUGINS__ELECTROMAGNETISM__NEDELEC_DIRICHLET__
39 
40 #include <map>
41 #include <vector>
42 
43 // ug4 headers
44 #include "common/common.h"
45 
46 // library-specific headers
47 #include "lib_grid/lg_base.h"
54 
55 #include "em_material.h"
56 
57 namespace ug{
58 namespace Electromagnetism{
59 
61 
83 template <typename TDomain, typename TAlgebra>
85  : public EMDirichlet<TDomain, TAlgebra>
86 {
87 public:
90 
93 
95  typedef TDomain domain_type;
96 
98  static const int dim = domain_type::dim;
99 
102 
104  typedef TAlgebra algebra_type;
105 
108 
111 
112 private:
115 
116 public:
119  (
120  const char * funcNames
121  )
122  : m_vDirichletFunc (TokenizeString (funcNames))
123  {};
124 
126  void add_0 (const char * subsets);
127 
129  void add (MathVector<dim> & value, const char * function, const char * subsets);
131  void add (std::vector<number> vValue, const char * function, const char * subsets);
132 
134  void add (SmartPtr<UserData<MathVector<dim>, dim> > & func, const char * function, const char * subsets);
135 #ifdef UG_FOR_LUA
137  void add (const char * name, const char * function, const char * subsets);
138 #endif
139 
141  virtual void get_dirichlet_subsets
142  (
143  SubsetGroup & dirichlet_ssgrp
144  ) const;
145 
146 private:
147 // Data, auxiliary types and auxiliary functions:
148 
151 
153  std::vector<std::string> m_vDirichletFunc;
154 
156 
161  std::map<std::string, std::vector<std::string> > m_mDirichletSS;
162 
164  struct TConstBC
165  {
167  std::string fctName;
168  size_t fct;
169  std::string ssName;
171 
174  (
175  MathVector<dim> & the_bcValue,
176  std::string the_fctName,
177  std::string the_ssName
178  )
179  : bcValue (the_bcValue), fctName (the_fctName), ssName (the_ssName)
180  {}
181 
183  inline number operator ()
184  (
185  Edge * edge,
186  int si,
187  typename domain_type::position_accessor_type & aaPos,
188  number time
189  )
190  {
191  // Get the vector pointing along the edge from its beginning to its end:
192  position_type edgeVector = aaPos [edge->vertex(1)];
193  edgeVector -= aaPos [edge->vertex(0)];
194 
195  // Return the scalar product:
196  return bcValue * edgeVector;
197  }
198  };
199 
201  std::vector<TConstBC> m_vConstBCData;
203  std::map<int, std::vector<TConstBC *> > m_mConstBC;
204 
206  struct TUserDataBC
207  {
209  std::string fctName;
210  size_t fct;
211  std::string ssName;
213 
216  (
217  SmartPtr<UserData<MathVector<dim>, dim> > the_spFunc,
218  std::string the_fctName,
219  std::string the_ssName
220  )
221  : spBCFunc (the_spFunc), fctName (the_fctName), ssName (the_ssName)
222  {}
223 
225  inline number operator ()
226  (
227  Edge * edge,
228  int si,
229  typename domain_type::position_accessor_type & aaPos,
230  number time
231  )
232  {
233  number dofValue;
234  MathVector<dim> func_value;
235 
236  // Get the vector pointing along the edge from its beginning to its end:
237  position_type edgeVector = aaPos [edge->vertex(1)];
238  edgeVector -= aaPos [edge->vertex(0)];
239 
240  // Evaluate the function
241  (*spBCFunc) (func_value, aaPos [edge->vertex(0)], time, si);
242  dofValue = func_value * edgeVector;
243 
244  (*spBCFunc) (func_value, aaPos [edge->vertex(1)], time, si);
245  dofValue += func_value * edgeVector;
246 
247  return dofValue / 2;
248  }
249  };
250 
252  std::vector<TUserDataBC> m_vUserDataBCData;
254  std::map<int, std::vector<TUserDataBC *> > m_mUserDataBC;
255 
257  std::map<int, FunctionGroup> m_mZeroBC;
258 
260  void add_subset
261  (
262  const char* f_name,
263  const char* ss_names
264  );
265 
268  (
270  )
271  {
273  m_aaPos = base_type::m_spApproxSpace->domain()->position_accessor();
274  }
275 
278  (
279  FunctionGroup & functionGroup,
280  SubsetGroup & subsetGroup
281  );
282 
284  void extract_implicit ();
285 
288  template <typename TUserData>
289  void extract_data
290  (
291  std::map<int, std::vector<TUserData*> >& mvUserDataBndSegment,
292  std::vector<TUserData>& vUserData
293  );
294  void extract_data ()
295  {
296  if (! base_type::m_spApproxSpace.valid ())
297  UG_THROW ("NedelecDirichletBC: Approximation space not set.");
300  extract_implicit ();
301  }
303 
305  template <typename TUserData>
306  void adjust_solution
307  (
308  const std::vector<TUserData *> & vUserData,
309  int si,
310  vector_type& u,
312  number time
313  );
314 
317  (
318  vector_type& u,
320  number time
321  );
322 
323 public:
324 // The interface:
325 
327  void adjust_jacobian
328  (
329  matrix_type & J,
330  const vector_type & u,
332  int type,
333  number time = 0.0,
335  const number s_a0 = 1.0
336  );
337 
339  void adjust_defect
340  (
341  vector_type & d,
342  const vector_type & u,
344  int type,
345  number time = 0.0,
347  const std::vector<number> * vScaleMass = NULL,
348  const std::vector<number> * vScaleStiff = NULL
349  );
350 
352  void adjust_solution
353  (
354  vector_type & u,
356  int type,
357  number time = 0.0
358  );
359 
362  (
363  matrix_type & A,
364  vector_type & b,
366  int type,
367  number time = 0.0
368  )
369  {
370  this_type::adjust_jacobian (A, b, dd, type, time); // the 2nd arg. is dummy: A does not depend on u
371  this_type::adjust_solution (b, dd, type, time);
372  };
373 
376  (
377  vector_type & b,
378  const vector_type & u,
380  int type,
381  number time = 0.0
382  )
383  {
384  this_type::adjust_solution (b, dd, type, time);
385  };
386 
388  int type () const {return CT_DIRICHLET;}
389 
390 };
391 
392 } // end namespace Electromagnetism
393 } // end namespace ug
394 
395 // Implementation of the functions:
396 #include "nedelec_dirichlet_impl.h"
397 
398 #endif // __H__UG__PLUGINS__ELECTROMAGNETISM__NEDELEC_DIRICHLET__
399 
400 /* End of File */
Common interface to get the Dirichlet boundary conditions.
Definition: em_material.h:287
Dirichlet BC for a rot-rot operator.
Definition: nedelec_dirichlet.h:86
void adjust_jacobian(matrix_type &J, const vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0, ConstSmartPtr< VectorTimeSeries< vector_type > > vSol=SPNULL, const number s_a0=1.0)
sets a unity row for all dirichlet indices
Definition: nedelec_dirichlet_impl.h:313
NedelecDirichletBC(const char *funcNames)
class constructor
Definition: nedelec_dirichlet.h:119
algebra_type::matrix_type matrix_type
type of algebra matrix
Definition: nedelec_dirichlet.h:107
static const int dim
world dimension
Definition: nedelec_dirichlet.h:98
std::map< int, std::vector< TConstBC * > > m_mConstBC
Constant values as Dirichlet BC: correspondens between the subsets and the specifications.
Definition: nedelec_dirichlet.h:203
algebra_type::vector_type vector_type
type of algebra vector
Definition: nedelec_dirichlet.h:110
domain_type::position_type position_type
type of position coordinates (e.g. position_type)
Definition: nedelec_dirichlet.h:101
std::map< int, std::vector< TUserDataBC * > > m_mUserDataBC
Dirichlet BC specified as functions: correspondens between the subsets and the specifications.
Definition: nedelec_dirichlet.h:254
int type() const
returns the type of the constraints
Definition: nedelec_dirichlet.h:388
void add_subset(const char *f_name, const char *ss_names)
inserts a subset to the list of the Dirichlet subsets
Definition: nedelec_dirichlet_impl.h:50
void extract_data()
Definition: nedelec_dirichlet.h:294
std::vector< TUserDataBC > m_vUserDataBCData
Dirichlet boundary conditions specified as functions: the specifications.
Definition: nedelec_dirichlet.h:252
std::map< std::string, std::vector< std::string > > m_mDirichletSS
all the subsets with the Dirichlet BC
Definition: nedelec_dirichlet.h:161
void adjust_solution(const std::vector< TUserData * > &vUserData, int si, vector_type &u, ConstSmartPtr< DoFDistribution > dd, number time)
Sets the specified Dirichlet values in the solution.
Definition: nedelec_dirichlet_impl.h:403
void add(MathVector< dim > &value, const char *function, const char *subsets)
adds a constant Dirichlet value on a subset
Definition: nedelec_dirichlet_impl.h:104
domain_type::position_accessor_type m_aaPos
accessor type for the coordinates of the grid vertices
Definition: nedelec_dirichlet.h:150
std::map< int, FunctionGroup > m_mZeroBC
List of all the Dirichlet subsets with implicitly specified Dirichlet BC: zero values.
Definition: nedelec_dirichlet.h:257
void adjust_solution_implicit(vector_type &u, ConstSmartPtr< DoFDistribution > dd, number time)
Sets the zero Dirichlet values for the implicitly specified BC.
Definition: nedelec_dirichlet_impl.h:436
void adjust_linear(matrix_type &A, vector_type &b, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0)
sets unity rows in A and dirichlet values in right-hand side b
Definition: nedelec_dirichlet.h:362
void extract_implicit()
Composes the list of the implicit BC.
Definition: nedelec_dirichlet_impl.h:281
std::vector< std::string > m_vDirichletFunc
functions for which the Dirichlet conditions are imposed
Definition: nedelec_dirichlet.h:153
TDomain domain_type
type of domain
Definition: nedelec_dirichlet.h:95
void check_functions_and_subsets(FunctionGroup &functionGroup, SubsetGroup &subsetGroup)
Verifies whether the string input represents legal data.
Definition: nedelec_dirichlet_impl.h:192
NedelecDirichletBC< TDomain, TAlgebra > this_type
this type
Definition: nedelec_dirichlet.h:92
void adjust_rhs(vector_type &b, const vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0)
sets the dirichlet value in the right-hand side
Definition: nedelec_dirichlet.h:376
void adjust_defect(vector_type &d, const vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0, ConstSmartPtr< VectorTimeSeries< vector_type > > vSol=SPNULL, const std::vector< number > *vScaleMass=NULL, const std::vector< number > *vScaleStiff=NULL)
sets a zero value in the defect for all dirichlet indices
Definition: nedelec_dirichlet_impl.h:357
std::vector< TConstBC > m_vConstBCData
Constant values as Dirichlet boundary conditions: the specifications.
Definition: nedelec_dirichlet.h:201
IDomainConstraint< TDomain, TAlgebra > base_type
base type
Definition: nedelec_dirichlet.h:89
void add_0(const char *subsets)
adds a zero Dirichlet value on a subset
Definition: nedelec_dirichlet_impl.h:92
DoFDistribution::traits< Edge >::const_iterator t_edge_iterator
iterator over edges
Definition: nedelec_dirichlet.h:114
void set_approximation_space(SmartPtr< ApproximationSpace< TDomain > > approxSpace)
sets the approximation space to work on
Definition: nedelec_dirichlet.h:268
TAlgebra algebra_type
type of algebra
Definition: nedelec_dirichlet.h:104
virtual void get_dirichlet_subsets(SubsetGroup &dirichlet_ssgrp) const
composes an array of subset indices of the Dirichlet boundary
Definition: nedelec_dirichlet_impl.h:174
algebra_type::vector_type vector_type
algebra_type::matrix_type matrix_type
SmartPtr< ApproximationSpace< TDomain > > m_spApproxSpace
ConstSmartPtr< DoFDistribution > dd(const GridLevel &gl) const
virtual void set_approximation_space(SmartPtr< ApproximationSpace< TDomain > > approxSpace)
ParallelMatrix< SparseMatrix< double > > matrix_type
ParallelVector< Vector< double > > vector_type
Grid::VertexAttachmentAccessor< position_attachment_type > position_accessor_type
MathVector< dim > position_type
static const int dim
vector< string > TokenizeString(const char *str, const char delimiter=',')
const NullSmartPtr SPNULL
#define UG_THROW(msg)
double number
CT_DIRICHLET
SurfaceView::traits< TElem >::const_iterator const_iterator
structure for the Dirichlet BC that is constant over a patch
Definition: nedelec_dirichlet.h:165
SubsetGroup ssGrp
subset group
Definition: nedelec_dirichlet.h:170
std::string fctName
grid function component name
Definition: nedelec_dirichlet.h:167
TConstBC(MathVector< dim > &the_bcValue, std::string the_fctName, std::string the_ssName)
constructor
Definition: nedelec_dirichlet.h:174
size_t fct
grid function component
Definition: nedelec_dirichlet.h:168
MathVector< dim > bcValue
the boundary condition
Definition: nedelec_dirichlet.h:166
std::string ssName
subset name
Definition: nedelec_dirichlet.h:169
Structure for the Dirichlet BC that are given by a function.
Definition: nedelec_dirichlet.h:207
std::string fctName
grid function component name
Definition: nedelec_dirichlet.h:209
std::string ssName
subset name
Definition: nedelec_dirichlet.h:211
SubsetGroup ssGrp
subset group
Definition: nedelec_dirichlet.h:212
TUserDataBC(SmartPtr< UserData< MathVector< dim >, dim > > the_spFunc, std::string the_fctName, std::string the_ssName)
constructor
Definition: nedelec_dirichlet.h:216
SmartPtr< UserData< MathVector< dim >, dim > > spBCFunc
user-defined function for
Definition: nedelec_dirichlet.h:208
size_t fct
grid function component
Definition: nedelec_dirichlet.h:210