Plugins
eddy_current_gf_user_data.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  * UserData class for computations with the time-harmonic Nedelec-based
35  * representation of the electric field.
36  */
37 #ifndef __H__UG__PLUGINS__ELECTROMAGNETISM__EDDY_CURRENT_GF_USER_DATA__
38 #define __H__UG__PLUGINS__ELECTROMAGNETISM__EDDY_CURRENT_GF_USER_DATA__
39 
40 #include <map>
41 #include <vector>
42 
43 // ug4 headers
44 #include "common/common.h"
45 #include "lib_grid/lg_base.h"
48 
49 // Nedelec-type-1 headers:
50 #include "../nedelec_local_ass.h"
51 
52 // Further local headers
53 #include "eddy_current_traits.h"
54 #include "../em_material.h"
55 
56 namespace ug{
57 namespace Electromagnetism{
58 
66 template <typename TGridFunc>
68 : public StdDependentUserData<EddyCurrentHeat<TGridFunc>, number, TGridFunc::dim>,
69  public EddyCurrentTraits
70 {
71 public:
73  typedef typename TGridFunc::domain_type domain_type;
74 
76  static const int dim = domain_type::dim;
77 
80 
81 private:
84 
86  size_t m_fct [2];
87 
90 
91 public:
94  (
95  SmartPtr<TGridFunc> spGridFct,
96  const char * cmp,
97  SmartPtr<EMaterial<domain_type> > emMatherial
98  )
99  : m_spGF (spGridFct), m_spEMaterial (emMatherial)
100  {
101  // get strings, tokenize them and select functions
102  std::string fctString = std::string (cmp);
103  std::vector<std::string> tokens;
104  TokenizeString (fctString, tokens, ',');
105  if ((int) tokens.size () != 2)
106  UG_THROW("EddyCurrentHeat: Needed 2 components "
107  "in symbolic function names (for Re and Im), "
108  "but given: " << cmp);
109  for (size_t i = 0; i < tokens.size (); i++)
110  RemoveWhitespaceFromString (tokens [i]);
111 
112  // get function id's by names
113  for (int i = 0; i < 2; i++)
114  try
115  {
116  m_fct [i] = m_spGF->fct_id_by_name (tokens[i].c_str ());
117  }
118  UG_CATCH_THROW ("EddyCurrentHeat: Cannot find symbolic function "
119  "component for the name '" << tokens[i] << "'.");
120 
121  // check the function space of the grid function
122  for (int i = 0; i < 2; i++)
123  if (m_spGF->local_finite_element_id(m_fct[i]).type () != LFEID::NEDELEC)
124  UG_THROW ("EddyCurrentHeat: The function space of component "
125  << tokens[i] << " of the grid function does not correspond "
126  "to the Nedelec element.");
127  };
128 
130  virtual bool continuous () const {return false;}
131 
133  virtual bool requires_grid_fct () const {return true;}
134 
136  template <int refDim>
138  (
139  number vValue[],
140  const MathVector<dim> vGlobIP[],
141  number time,
142  int si,
143  GridObject* elem,
144  const MathVector<dim> vCornerCoords[],
145  const MathVector<refDim> vLocIP[],
146  const size_t nip,
147  LocalVector* u,
148  bool bDeriv,
149  int s,
150  std::vector<std::vector<number> > vvvDeriv[],
151  const MathMatrix<refDim, dim>* vJT = NULL
152  ) const
153  {
154  // Derivatives are not implemented
155  if (bDeriv)
156  UG_THROW ("EddyCurrentHeat: Derivatives are not implemented.");
157 
158  // Get the material data
159  number mu, sigma;
160  int elem_si = m_spGF->approx_space()->subset_handler()->get_subset_index (elem);
161  if (m_spEMaterial->get_mu_sigma (elem_si, mu, sigma))
162  UG_THROW ("EddyCurrentHeat: No material data set to subset" << si
163  << " (or this is a low-dim. domain).");
164  if (sigma == 0) // no currents in insulators
165  {
166  for (size_t i = 0; i < nip; i++) vValue [i] = 0.0;
167  return;
168  }
169 
170  // Compute the values
171  std::vector<MathVector<dim> > E [2]; // Re and Im parts of E
172  std::vector<DoFIndex> ind;
173  std::vector<number> dofValues;
174 
175  for (size_t part = 0; part < 2; part++) // part: Re or Im
176  {
177  E[part].resize (nip);
178 
179  // Get multiindices of element
180  m_spGF->dof_indices (elem, m_fct [part], ind);
181 
182  // The DoF values of the grid function
183  dofValues.resize (ind.size ());
184  for (size_t sh = 0; sh < dofValues.size (); ++sh)
185  dofValues[sh] = DoFRef (*m_spGF, ind[sh]);
186 
187  // Compute the values of the grid function
189  (m_spGF->domain().get(), elem, vCornerCoords, &(dofValues[0]),
190  vLocIP, nip, & (E[part][0]));
191  }
192 
193  // Compute \f$ \frac{1}{2} \sigma \mathbf{E} \overline{\mathbf{E}} \f$
194  for (size_t i = 0; i < nip; i++)
195  vValue [i] = sigma * (VecTwoNormSq (E[_Re_][i]) + VecTwoNormSq (E[_Im_][i])) / 2;
196  };
197 };
198 
209 template <typename TImpl, size_t ReIm, typename TGFunc>
211 : public StdDependentUserData <TImpl, MathVector<TGFunc::dim>, TGFunc::dim>,
212  public EddyCurrentTraits
213 {
214 public:
216  typedef typename TGFunc::domain_type domain_type;
217 
219  static const int dim = domain_type::dim;
220 
223 
224 protected:
227 
229  size_t m_fct [2];
230 
231 private:
233  const TImpl * this_impl () const {return static_cast<const TImpl*> (this);}
234 
235 public:
238  (
239  SmartPtr<TGFunc> spGridFct,
240  const char * cmp
241  )
242  : m_spGF (spGridFct)
243  {
244  // get strings, tokenize them and select functions
245  std::string fctString = std::string (cmp);
246  std::vector<std::string> tokens;
247  TokenizeString (fctString, tokens, ',');
248  if ((int) tokens.size () != 2)
249  UG_THROW("EddyCurrentReB: Needed 2 components "
250  "in symbolic function names (for Re and Im), "
251  "but given: " << cmp);
252  for (size_t i = 0; i < tokens.size (); i++)
253  RemoveWhitespaceFromString (tokens [i]);
254 
255  // get function id's by names
256  for (int i = 0; i < 2; i++)
257  try
258  {
259  m_fct [i] = m_spGF->fct_id_by_name (tokens[i].c_str ());
260  }
261  UG_CATCH_THROW ("EddyCurrent: Cannot find symbolic function "
262  "component for the name '" << tokens[i] << "'.");
263 
264  // check the function space of the grid function
265  for (int i = 0; i < 2; i++)
266  if (m_spGF->local_finite_element_id(m_fct[i]).type () != LFEID::NEDELEC)
267  UG_THROW ("EddyCurrent: The function space of component "
268  << tokens[i] << " of the grid function does not correspond "
269  "to the Nedelec element.");
270  };
271 
273  virtual bool continuous () const {return false;}
274 
276  virtual bool requires_grid_fct () const {return true;}
277 
279  template <int refDim>
281  (
282  MathVector<dim> vValue[],
283  const MathVector<dim> vGlobIP[],
284  number time,
285  int si,
286  GridObject * elem,
287  const MathVector<dim> vCornerCoords[],
288  const MathVector<refDim> vLocIP[],
289  const size_t nip,
290  LocalVector * u,
291  bool bDeriv,
292  int s,
293  std::vector<std::vector<MathVector<dim> > > vvvDeriv[],
294  const MathMatrix<refDim, dim> * vJT = NULL
295  ) const
296  {
297  // Derivatives are not implemented
298  if (bDeriv)
299  UG_THROW ("EddyCurrentReB: Derivatives are not implemented.");
300 
301  // Get multiindices of element
302  std::vector<DoFIndex> ind;
303  m_spGF->dof_indices (elem, m_fct [ReIm], ind);
304 
305  // The DoF values of the grid function
306  std::vector<number> dofValues (ind.size());
307  for (size_t sh = 0; sh < dofValues.size (); ++sh)
308  dofValues[sh] = DoFRef (*m_spGF, ind[sh]);
309 
310  // Compute the curl
311  MathVector<dim> curl;
313  (m_spGF->domain().get(), elem, vCornerCoords, &(dofValues[0]), curl);
314  for (size_t ip = 0; ip < nip; ip++)
315  this_impl()->get_value (curl, vValue [ip]);
316  };
317 };
318 
327 template <typename TGridFunc>
330  <EddyCurrentReBofEUserData<TGridFunc>, EddyCurrentTraits::_Im_, TGridFunc>
331 {
333  typedef typename TGridFunc::domain_type domain_type;
334 
336  static const int dim = domain_type::dim;
337 
338 private:
341 
342 public:
345  (
346  SmartPtr<TGridFunc> spGridFct,
347  const char * cmp,
348  number omega
349  )
351  <EddyCurrentReBofEUserData<TGridFunc>, EddyCurrentTraits::_Im_, TGridFunc> (spGridFct, cmp),
352  m_omega (omega)
353  {};
354 
356  inline void get_value (const MathVector<dim> & ImCurlE, MathVector<dim> & ReB) const
357  {
358  ReB = ImCurlE;
359  ReB /= - m_omega;
360  }
361 };
362 
371 template <typename TGridFunc>
374  <EddyCurrentImBofEUserData<TGridFunc>, EddyCurrentTraits::_Re_, TGridFunc>
375 {
377  typedef typename TGridFunc::domain_type domain_type;
378 
380  static const int dim = domain_type::dim;
381 
382 private:
385 
386 public:
389  (
390  SmartPtr<TGridFunc> spGridFct,
391  const char * cmp,
392  number omega
393  )
395  <EddyCurrentImBofEUserData<TGridFunc>, EddyCurrentTraits::_Re_, TGridFunc> (spGridFct, cmp),
396  m_omega (omega)
397  {};
398 
400  inline void get_value (const MathVector<dim> & ReCurlE, MathVector<dim> & ImB) const
401  {
402  ImB = ReCurlE;
403  ImB /= m_omega;
404  }
405 };
406 
407 } // end namespace Electromagnetism
408 } // end namespace ug
409 
410 #endif // __H__UG__PLUGINS__ELECTROMAGNETISM__EDDY_CURRENT_GF_USER_DATA__
411 
412 /* End of File */
T * get()
Class for subdomain-dependent data for the E-based formulated problems.
Definition: em_material.h:63
Definition: eddy_current_gf_user_data.h:213
EddyCurrentCurlEDependentCmpUserData(SmartPtr< TGFunc > spGridFct, const char *cmp)
constructor
Definition: eddy_current_gf_user_data.h:238
size_t m_fct[2]
components (Re and Im) of the grid function
Definition: eddy_current_gf_user_data.h:229
domain_type::position_type position_type
Type of position coordinates (e.g. position_type)
Definition: eddy_current_gf_user_data.h:222
static const int dim
World dimension.
Definition: eddy_current_gf_user_data.h:219
void eval_and_deriv(MathVector< dim > vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, bool bDeriv, int s, std::vector< std::vector< MathVector< dim > > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Performs the main computations:
Definition: eddy_current_gf_user_data.h:281
virtual bool continuous() const
The vector field retrieved from the Nedelec-type 1 (Whitney-1) dofs are not continuous.
Definition: eddy_current_gf_user_data.h:273
TGFunc::domain_type domain_type
Type of domain.
Definition: eddy_current_gf_user_data.h:216
SmartPtr< TGFunc > m_spGF
grid function
Definition: eddy_current_gf_user_data.h:226
const TImpl * this_impl() const
const 'this' pointer of the implementation class
Definition: eddy_current_gf_user_data.h:233
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition: eddy_current_gf_user_data.h:276
Definition: eddy_current_gf_user_data.h:70
static const int dim
World dimension.
Definition: eddy_current_gf_user_data.h:76
SmartPtr< EMaterial< domain_type > > m_spEMaterial
subdomain-dependent data (propertiels of the materials)
Definition: eddy_current_gf_user_data.h:89
SmartPtr< TGridFunc > m_spGF
grid function for
Definition: eddy_current_gf_user_data.h:83
size_t m_fct[2]
components (Re and Im) of the grid function
Definition: eddy_current_gf_user_data.h:86
virtual bool continuous() const
The vector field retrieved from the Nedelec-type 1 (Whitney-1) dofs are not continuous.
Definition: eddy_current_gf_user_data.h:130
domain_type::position_type position_type
Type of position coordinates (e.g. position_type)
Definition: eddy_current_gf_user_data.h:79
virtual bool requires_grid_fct() const
Returns true to get the grid element in the evaluation routine.
Definition: eddy_current_gf_user_data.h:133
EddyCurrentHeat(SmartPtr< TGridFunc > spGridFct, const char *cmp, SmartPtr< EMaterial< domain_type > > emMatherial)
constructor
Definition: eddy_current_gf_user_data.h:94
TGridFunc::domain_type domain_type
Type of domain.
Definition: eddy_current_gf_user_data.h:73
void eval_and_deriv(number vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, bool bDeriv, int s, std::vector< std::vector< number > > vvvDeriv[], const MathMatrix< refDim, dim > *vJT=NULL) const
Performs the main computations:
Definition: eddy_current_gf_user_data.h:138
Definition: eddy_current_gf_user_data.h:375
void get_value(const MathVector< dim > &ReCurlE, MathVector< dim > &ImB) const
Definition: eddy_current_gf_user_data.h:400
static const int dim
World dimension.
Definition: eddy_current_gf_user_data.h:380
TGridFunc::domain_type domain_type
Type of domain.
Definition: eddy_current_gf_user_data.h:377
EddyCurrentImBofEUserData(SmartPtr< TGridFunc > spGridFct, const char *cmp, number omega)
constructor
Definition: eddy_current_gf_user_data.h:389
number m_omega
Frequency .
Definition: eddy_current_gf_user_data.h:384
Definition: eddy_current_gf_user_data.h:331
TGridFunc::domain_type domain_type
Type of domain.
Definition: eddy_current_gf_user_data.h:333
static const int dim
World dimension.
Definition: eddy_current_gf_user_data.h:336
void get_value(const MathVector< dim > &ImCurlE, MathVector< dim > &ReB) const
Definition: eddy_current_gf_user_data.h:356
EddyCurrentReBofEUserData(SmartPtr< TGridFunc > spGridFct, const char *cmp, number omega)
constructor
Definition: eddy_current_gf_user_data.h:345
number m_omega
Frequency .
Definition: eddy_current_gf_user_data.h:340
Auxiliary class defining some important constants.
Definition: eddy_current_traits.h:44
static const size_t _Im_
index of the imaginary part in the grid functions
Definition: eddy_current_traits.h:50
static const size_t _Re_
index of the real part in the grid functions
Definition: eddy_current_traits.h:48
static void curl(const TDomain *domain, GridObject *elem, const position_type corners[], const number dofs[], MathVector< WDim > &curl_vec)
computes curl of the function
Definition: nedelec_local_ass.h:434
static void value(const TDomain *domain, GridObject *elem, const position_type corners[], const number dofs[], const MathVector< refDim > local[], const size_t n_pnt, MathVector< WDim > values[])
computes the values at given points
Definition: nedelec_local_ass.h:411
const MathVector< dim > & ip(size_t s, size_t ip) const
number time() const
MathVector< dim > position_type
static const int dim
StringTable s
vector< string > TokenizeString(const char *str, const char delimiter=',')
void RemoveWhitespaceFromString(std::string &string)
#define UG_CATCH_THROW(msg)
#define UG_THROW(msg)
double number
vector_t::value_type VecTwoNormSq(const vector_t &v)
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)