Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transfer_base.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Transfer_base.h,v 1.29 2008/12/06 08:43:27 mtcampbe Exp $
24 
25 //=====================================================================
26 // This file contains the prototypes of Transfer_base for
27 // overlay-based data transfer algorithms.
28 //
29 // Author: Xiangmin Jiao
30 // Revision: June 16, 2001
31 //=====================================================================
32 
33 #ifndef __TRANSFER_BASE_H_
34 #define __TRANSFER_BASE_H_
35 
36 #include "rfc_basic.h"
37 #include "Vector_n.h"
38 #include "RFC_Window_transfer.h"
39 #include "Timing.h"
40 #include <cmath>
41 
43 
44 // The base implementation for all the transfer algorithms.
46 public:
48 
52 
54  typedef std::vector<RFC_Pane_transfer*>::iterator Pane_iterator;
55  typedef std::vector<RFC_Pane_transfer*>::const_iterator Pane_iterator_const;
56  typedef std::vector<const RFC_Pane_transfer*>
57  ::const_iterator Pane_const_iterator;
58 
60  : src( *s), trg( *t), sc( s->color()), _src_pane(NULL), _trg_pane(NULL)
61  { src.panes( src_ps); trg.panes( trg_ps); }
62 
63 public:
72  template < class _SDF>
73  void transfer_2f( const _SDF &sDF, Facial_data &tDF, const Real alpha,
74  int doa, bool verb);
75 
86  template < class _SDF>
87  void transfer_2n( const _SDF &sDF, Nodal_data &tDF, const Real alpha,
88  Real *tol, int *iter, int doa, bool verb);
89 
96  template <class _SDF>
97  void interpolate_fe( const _SDF &sDF, Nodal_data &tDF, bool verb);
98 
102  template <class _SDF>
103  void loadtransfer( const _SDF &vS, Nodal_data &vT, const Real alpha,
104  const int order, bool verb);
105 
106 protected:
107  // Integrating over a sub-face whose parent element in the source
108  // window is the face incident on s.
109  template < class _SDF>
110  void integrate_subface( const RFC_Pane_transfer *p_src,
111  RFC_Pane_transfer *p_trg,
112  const _SDF &sDF,
113  ENE &ene_src,
114  ENE &ene_trg,
115  int sfid_src,
116  int sfid_trg,
117  const Real alpha,
118  Facial_data &tDF,
119  Facial_data &tBF,
120  int doa);
121 
122  // The following are helpers for transfer_to_nodes, where
123  // the geometry to be used is (1-alpha)*Source+alpha*Target.
124 
135  template < class _SDF>
136  void init_load_vector( const _SDF &vS, const Real alpha,
137  Nodal_data &ld, Nodal_data &diag,
138  int doa, bool lump);
139 
140  // This is a matrix-free solver that solves the equation M*x=ld,
141  // where M is the mass matrix computed on the fly.
142  int pcg( Nodal_data &x, Nodal_data &b, Nodal_data &p,
144  Nodal_data &z, Nodal_data &di, Real *tol, int *max_iter);
145 
151  const Nodal_data_const &diag,
152  Nodal_data &x);
153 
154  //============== Helper routines for cg==================
155  // Multiply the mass matrix M with a vector X, and get y.
157 
158  Real square( const Array_n_const &x) const { return x*x; }
159 
160  Real norm2( const Nodal_data_const &x) const;
161  Real dot( const Nodal_data_const &x, const Nodal_data_const &y) const;
162  void dot2( const Nodal_data_const &x1, const Nodal_data_const &y1,
163  const Nodal_data_const &x2, const Nodal_data_const &y2,
164  Array_n prod) const;
165 
166  void scale( const Real &a, Nodal_data &x);
167  void invert( Nodal_data &x);
168 
169  // This function computes y = a*x + b*y
170  void copy_vec(const Nodal_data_const &x, Nodal_data &y);
171 
172  void saxpy( const Real &a, const Nodal_data_const &x,
173  const Real &b, Nodal_data &y);
174 
177  template < class _SDF>
178  void
179  compute_load_vector_wra( const RFC_Pane_transfer *p_src, //< Source pane
180  RFC_Pane_transfer *p_dst, //< target pane
181  const _SDF &sDF, //< source data
182  ENE &ene_src, //< node enumerator of source element
183  ENE &ene_trg, //< node enumerator of target element
184  int sfid_src, //< parent face ID in source pane
185  int sfid_trg, //< parent face ID in target pane
186  const Real alpha, //< coordinate interpolation parameter
187  Nodal_data &rhs, //< load vector
188  Nodal_data &diag, //< Diagonal of mass matrix.
189  int doa, //< Degree of accuracy of quadrature
190  bool lump); //< whether to lump mass matrix.
191 
195  template < class _Data, class _Points, class _Loads, class Tag>
196  void
197  element_load_vector( const _Data &data_s, //< Data field
198  const Generic_element &e_s, //< Master source element
199  const Generic_element &e_t, //< Master target element
200  const _Points &pnts_s, //< Points of source element
201  const _Points &pnts_t, //< Points of target element
202  const Point_2 *ncs_s, //< Local coordinates of src
203  const Point_2 *ncs_t, //< Local coordinates or trg
204  const Real alpha, //< coordinate interp para
205  const int sne, //< #edges of sub-element
206  const Tag &tag, //< Tag_facial/Tag_nodal
207  _Loads loads, //< Load vector
208  _Loads diag, //< Diagonal of mass matrix
209  Real *emm, //< Element-wise mass matrix
210  int doa, //< Degree of quadrature
211  bool lump); //< Whether to lump mass mat
212 
213 
214  template < class _Data>
216  const _Data &data_s, const Vector_3 *grads_s,
217  Vector_3 *load_prime, Tag_nodal ) {
218  Vector_3 NULL_VECTOR(0,0,0);
219  for ( unsigned int k=0; k<data_s.dimension(); ++k) {
220  load_prime[k] = NULL_VECTOR;
221  for ( unsigned int j=0; j<e_s.size_of_nodes(); ++j) {
222  load_prime[k] += data_s[j][k] * grads_s[j];
223  }
224  }
225  }
226 
227  template < class _Data>
229  const _Data &data_s, const Vector_3 *grads_s,
230  Vector_3 *load_prime, Tag_facial ) {
231  Vector_3 NULL_VECTOR(0,0,0);
232  for ( unsigned int k=0; k<data_s.dimension(); ++k) {
233  load_prime[k] = NULL_VECTOR;
234  }
235  }
236 
237 public:
238  // Useful utilities
239  void minmax( const RFC_Window_transfer &win,
240  const Facial_data_const &sDF,
241  Array_n &min_v,
242  Array_n &max_v);
243 
244  void minmax( const RFC_Window_transfer &win,
245  const Nodal_data_const &sDF,
246  Array_n &min_v,
247  Array_n &max_v);
248 
249  void integrate( const RFC_Window_transfer &win,
250  const Nodal_data_const &sDF,
251  Array_n &intergral,
252  const int doa);
253 
254  void integrate( const RFC_Window_transfer &win,
255  const Facial_data_const &sDF,
256  Array_n &intergral,
257  const int doa);
258 
259 #ifndef isfinite /* this is a macro under Intel CC 8.0 */
260  bool isfinite( Real x) { return x>-HUGE_VAL && x<HUGE_VAL; }
261 #endif
262 private:
263  // Interpolation
264  template < class _Value>
265  void
267  const Element_var_const values,
268  const Generic_element::Nat_coor &nc,
269  _Value &v)
270  { e.interpolate( values, nc, &v); }
271 
272  template < class _Value>
273  void
275  const Array_n_const value,
276  const Generic_element::Nat_coor &nc,
277  _Value &v)
278  { v = value; }
279 
280 protected:
281  // Data members
284  int sc;
285 
286 private:
287  // Caches for the pane
290 
291  std::vector<const RFC_Pane_transfer*> src_ps;
292  std::vector<RFC_Pane_transfer*> trg_ps;
293 
294 
296  if ( !_src_pane || _src_pane->id())
297  _src_pane = &src.pane(i);
298  return _src_pane;
299  }
301  if ( !_trg_pane || _trg_pane->id())
302  _trg_pane = &trg.pane(i);
303  return _trg_pane;
304  }
305 
309  const RFC_Pane_transfer *pn,
310  const ENE &ene) {
311  return Element_var_const( d, pn->pointer(d.id()), ene);
312  };
313 
316  RFC_Pane_transfer *pn,
317  const ENE &ene) {
318  return Element_var( d, pn->pointer(d.id()), ene);
319  };
320 
323  const RFC_Pane_transfer *pn, int) {
324  RFC_assertion_msg(false, "Should never reach here. Bug in the code?");
325  return Element_var_const( d, pn->pointer(d.id()), ENE());
326  };
327 
328  const Array_n_const
330  const RFC_Pane_transfer *pn,
331  const ENE &ene){
332  return d.get_value( pn->pointer(d.id()), ene.id());
333  };
334 
335  const Array_n_const
337  const RFC_Pane_transfer *pn,
338  int i){
339  return d.get_value( pn->pointer(d.id()), i);
340  };
341 
342  bool is_nodal( Tag_nodal) const { return true; }
343  bool is_nodal( Tag_facial) const { return false; }
344  bool is_nodal( const Element_var_const&) const { return true; }
345  bool is_nodal( const Element_var &) const { return true; }
346  bool is_nodal( const Array_n_const &) const { return false; }
347 };
348 
350 
351 #endif // __TRANSFER_BASE_H_
352 
353 
354 
355 
356 
357 
void loadtransfer(const _SDF &vS, Nodal_data &vT, const Real alpha, const int order, bool verb)
Computes the load vector.
Definition: Transfer_2n.C:493
void dot2(const Nodal_data_const &x1, const Nodal_data_const &y1, const Nodal_data_const &x2, const Nodal_data_const &y2, Array_n prod) const
Real square(const Array_n_const &x) const
void compute_load_vector_wra(const RFC_Pane_transfer *p_src, RFC_Pane_transfer *p_dst, const _SDF &sDF, ENE &ene_src, ENE &ene_trg, int sfid_src, int sfid_trg, const Real alpha, Nodal_data &rhs, Nodal_data &diag, int doa, bool lump)
Computes the element-wise load vector, and also computes mass matrix if diag has a nonnegative ID...
Definition: Transfer_2n.C:292
void invert(Nodal_data &x)
void transfer_2n(const _SDF &sDF, Nodal_data &tDF, const Real alpha, Real *tol, int *iter, int doa, bool verb)
template function for transfering from nodes/faces to nodes.
Definition: Transfer_2n.C:387
RFC_Pane_transfer & pane(const int pid)
An adaptor for enumerating node IDs of an element.
const RFC_Pane_transfer * get_src_pane(int i)
const NT & d
j indices k indices k
Definition: Indexing.h:6
void int int REAL REAL * y
Definition: read.cpp:74
Element_var_const make_field(const Nodal_data_const &d, const RFC_Pane_transfer *pn, const ENE &ene)
Construct a element-wise accessor from nodal data and pointers.
Element_var_const make_field(const Nodal_data_const &d, const RFC_Pane_transfer *pn, int)
NT rhs
double s
Definition: blastest.C:80
bool is_nodal(const Array_n_const &) const
std::vector< RFC_Pane_transfer * > trg_ps
Adpator for element-wise data container.
void integrate_subface(const RFC_Pane_transfer *p_src, RFC_Pane_transfer *p_trg, const _SDF &sDF, ENE &ene_src, ENE &ene_trg, int sfid_src, int sfid_trg, const Real alpha, Facial_data &tDF, Facial_data &tBF, int doa)
bool is_nodal(const Element_var &) const
Value_const get_value(const RFC_Pane_transfer *p, int v) const
void saxpy(const Real &a, const Nodal_data_const &x, const Real &b, Nodal_data &y)
bool is_nodal(Tag_facial) const
double Real
Definition: mapbasic.h:322
void compute_load_prime(const Generic_element &e_s, const _Data &data_s, const Vector_3 *grads_s, Vector_3 *load_prime, Tag_nodal)
SURF::Generic_element_2 Generic_element
Definition: rfc_basic.h:46
Transfer_base(RFC_Window_transfer *s, RFC_Window_transfer *t)
Definition: Transfer_base.h:59
bool isfinite(Real x)
Field< Nodal_data, ENE > Element_var
Definition: Transfer_base.h:49
std::vector< const RFC_Pane_transfer * > src_ps
Transfer_base Self
Definition: Transfer_base.h:53
int id() const
Get the local id of the element within the pane.
void panes(std::vector< Pane * > &ps)
Get a vector of local panes contained in the window.
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
void element_load_vector(const _Data &data_s, const Generic_element &e_s, const Generic_element &e_t, const _Points &pnts_s, const _Points &pnts_t, const Point_2 *ncs_s, const Point_2 *ncs_t, const Real alpha, const int sne, const Tag &tag, _Loads loads, _Loads diag, Real *emm, int doa, bool lump)
Computes the element-wise load vector, and also computes mass matrix if emm is not NULL...
Definition: Transfer_2n.C:139
void interpolate(const Generic_element &e, const Array_n_const value, const Generic_element::Nat_coor &nc, _Value &v)
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
void scale(const Real &a, Nodal_data &x)
Null_vector NULL_VECTOR
Definition: Origin.C:62
void int int int REAL REAL REAL * z
Definition: write.cpp:76
Element_var make_field(Nodal_data &d, RFC_Pane_transfer *pn, const ENE &ene)
void compute_load_prime(const Generic_element &e_s, const _Data &data_s, const Vector_3 *grads_s, Vector_3 *load_prime, Tag_facial)
Field< const Nodal_coor_const, ENE > Element_coor_const
Definition: Transfer_base.h:51
RFC_Window_transfer & trg
RFC_Pane_transfer * _trg_pane
blockLoc i
Definition: read.cpp:79
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
Field< const Nodal_data_const, ENE > Element_var_const
Definition: Transfer_base.h:50
void int int REAL * x
Definition: read.cpp:74
#define RFC_assertion_msg
Definition: rfc_basic.h:67
void transfer_2f(const _SDF &sDF, Facial_data &tDF, const Real alpha, int doa, bool verb)
template function for transfering from nodes/faces to faces.
Definition: Transfer_2f.C:124
int pcg(Nodal_data &x, Nodal_data &b, Nodal_data &p, Nodal_data &q, Nodal_data &r, Nodal_data &s, Nodal_data &z, Nodal_data &di, Real *tol, int *max_iter)
Definition: Transfer_base.C:40
const Array_n_const make_field(const Facial_data_const &d, const RFC_Pane_transfer *pn, int i)
bool is_nodal(Tag_nodal) const
void interpolate(const Generic_element &e, const Element_var_const values, const Generic_element::Nat_coor &nc, _Value &v)
Element_node_enumerator ENE
Definition: Transfer_base.h:47
std::vector< const RFC_Pane_transfer * >::const_iterator Pane_const_iterator
Definition: Transfer_base.h:57
const RFC_Pane_transfer * _src_pane
bool is_nodal(const Element_var_const &) const
void init_load_vector(const _SDF &vS, const Real alpha, Nodal_data &ld, Nodal_data &diag, int doa, bool lump)
Initialize load vector and the diagonal of the mass matrix.
Definition: Transfer_2n.C:341
void integrate(const RFC_Window_transfer &win, const Nodal_data_const &sDF, Array_n &intergral, const int doa)
j indices j
Definition: Indexing.h:6
void copy_vec(const Nodal_data_const &x, Nodal_data &y)
NT q
std::vector< RFC_Pane_transfer * >::const_iterator Pane_iterator_const
Definition: Transfer_base.h:55
void precondition_Jacobi(const Nodal_data_const &rhs, const Nodal_data_const &diag, Nodal_data &x)
Diagonal (Jacobi) preconditioner.
const Array_n_const make_field(const Facial_data_const &d, const RFC_Pane_transfer *pn, const ENE &ene)
Real dot(const Nodal_data_const &x, const Nodal_data_const &y) const
void interpolate_fe(const _SDF &sDF, Nodal_data &tDF, bool verb)
Perform finite-element interpolation (non-conservative), assuming source data has been replicated...
Some basic geometric data types.
Definition: mapbasic.h:54
RFC_Pane_transfer * get_trg_pane(int i)
RFC_Window_transfer & src
int id() const
void multiply_mass_mat_and_x(const Nodal_data_const &x, Nodal_data &y)
void minmax(const RFC_Window_transfer &win, const Facial_data_const &sDF, Array_n &min_v, Array_n &max_v)
Real norm2(const Nodal_data_const &x) const
std::vector< RFC_Pane_transfer * >::iterator Pane_iterator
Definition: Transfer_base.h:54