Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
interpolate_to_centers.C
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: interpolate_to_centers.C,v 1.3 2008/12/06 08:43:23 mtcampbe Exp $
24 
25 #include "Rocsurf.h"
26 #include "Element_accessors.h"
27 #include "Generic_element_2.h"
28 
30 
34 template <class T>
36 public:
37  typedef T Base_type;
38  typedef const T Value;
39  typedef T Value_nonconst;
40  typedef const T Value_const;
41  typedef unsigned int Size;
42 
44  Nodal_scalar_const_2d(int i, int j) : nc(i),c(j) {}
45  void set_col( int j) { c = j; }
46 
48  Size dimension() const { return 1; }
49 
51  T get_value( const Base_type *buf, int r) const {
52  assert( r>=1);
53  return buf[(r-1)*nc+c];
54  }
55 private:
56  const int nc;
57  int c;
58 };
59 
64 template < class _Cont>
65 class Field {
66 public:
67  typedef typename _Cont::Base_type Base_type;
68  typedef typename _Cont::Value Value;
69  typedef typename _Cont::Value_nonconst Value_nonconst;
70  typedef typename _Cont::Value_const Value_const;
71  typedef unsigned int Size;
72 
73 public:
79  Field( _Cont & cont, Value *p, const Element_node_enumerator &ids)
80  : _cont(cont), _p(p), _enum(ids) {}
82  Size dimension() const { return _cont.dimension(); }
85  Value_const operator[]( int i) const
86  { return _cont.get_value(_p, _enum[i]); }
90  { return _cont.get_value(_p, _enum[i]); }
91 
92 private:
93  _Cont &_cont;
96 };
97 
98 // Interpolate node-centered data x to element-centered data z.
99 // Now support only double precision data.
100 void Rocsurf::interpolate_to_centers( const COM::Attribute *x,
101  COM::Attribute *z) {
102  assert( x->is_nodal() && z->is_elemental()
103  && x->size_of_components() == z->size_of_components());
104  assert( x->data_type() == COM_DOUBLE ||
105  x->data_type() == COM_DOUBLE_PRECISION);
106  assert( z->data_type() == COM_DOUBLE ||
107  z->data_type() == COM_DOUBLE_PRECISION);
108 
109  std::vector<const COM::Pane*> xpanes;
110  std::vector<COM::Pane*> zpanes;
111 
112  x->window()->panes(xpanes);
113  z->window()->panes(zpanes);
114 
115  std::vector<COM::Pane*>::iterator zit, zend;
116  std::vector<const COM::Pane*>::const_iterator xit;
117 
118  const int ndim = x->size_of_components();
119  // Loop through all the panes.
120  for( zit = zpanes.begin(), zend = zpanes.end(), xit = xpanes.begin();
121  zit != zend; ++zit, ++xit) {
122  //Loop for each dimension.
123  for(int i = 0; i < ndim; ++i) {
124  COM::Attribute *z_pa = (*zit)->attribute(z->id()+((ndim>1)?i+1:0));
125  Real *zval = reinterpret_cast<Real *>(z_pa->pointer());
126  int zstrd=z_pa->stride();
127 
128  const COM::Attribute *x_pa = (*xit)->attribute(x->id()+((ndim>1)?i+1:0));
129  const Real *xval = reinterpret_cast<const Real *>(x_pa->pointer());
130 
131  Nodal_scalar_const_2d<Real> X(x_pa->stride(), 0);
132  Element_node_enumerator ene( *xit, 1);
133  Field<Nodal_scalar_const_2d<Real> > f( X, xval, ene);
134 
135  for (int j=(*xit)->size_of_elements(); j>0; --j, ene.next(), zval+=zstrd)
136  Generic_element_2( ene.size_of_edges(), ene.size_of_nodes()).
137  interpolate_to_center( f, zval);
138  }
139  }
140 }
141 
143 
144 
145 
146 
147 
148 
An adaptor for enumerating node IDs of an element.
#define SURF_END_NAMESPACE
Definition: surfbasic.h:29
Value_const operator[](int i) const
Obtain a const reference to the nodal data associated with ith node of the element.
Adpator for element-wise data container.
Encapsulation of the element-wise computations for two-dimensional elements.
double Real
Definition: mapbasic.h:322
unsigned int Size
Size dimension() const
Dimension of each attribute.
T get_value(const Base_type *buf, int r) const
Get the ith data item. Here the index i uses Fortran convention.
#define SURF_BEGIN_NAMESPACE
Definition: surfbasic.h:28
Nodal_scalar_const_2d(int i, int j)
Constructor.
void int int int REAL REAL REAL * z
Definition: write.cpp:76
const Element_node_enumerator & _enum
Adpator for accessing constant scalar node-centered data.
_Cont::Value Value
static void interpolate_to_centers(const COM::Attribute *x, COM::Attribute *z)
Interpolates nodal coordinates to element centers.
Size dimension() const
Dimension of the attribute.
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
Value_nonconst operator[](int i)
Obtain a non-const reference to the nodal data associated with ith node of the element.
_Cont::Base_type Base_type
j indices j
Definition: Indexing.h:6
_Cont::Value_nonconst Value_nonconst
Field(_Cont &cont, Value *p, const Element_node_enumerator &ids)
Constructor.
_Cont::Value_const Value_const