COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
ElementData.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #ifndef cf3_mesh_ElementData_hpp
8 #define cf3_mesh_ElementData_hpp
9 
11 
13 
14 #include "math/MatrixTypes.hpp"
15 
16 #include "mesh/LibMesh.hpp"
17 #include "common/Table.hpp"
18 
20 
21 namespace cf3 {
22 namespace mesh {
23 
25 
27 template<typename NodeValuesT, typename RowT>
28 void fill(NodeValuesT& to_fill, const common::Table<Real>& data_array, const RowT& element_row, const Uint start=0)
29 {
30  const Uint nb_nodes = element_row.size();
31  const Uint dim = data_array.row_size();
32  const Uint end = start+dim;
33  for(Uint node = 0; node != nb_nodes; ++node)
34  {
35  const common::Table<Real>::ConstRow data_row = data_array[element_row[node]];
36  for(Uint j = start; j != end; ++j)
37  to_fill[node][j-start] = data_row[j];
38  }
39 }
40 
42 template<typename RowT, int NbRows, int NbCols>
43 void fill(Eigen::Matrix<Real, NbRows, NbCols>& to_fill, const common::Table<Real>& data_array, const RowT& element_row, const Uint start=0)
44 {
45  for(int node = 0; node != NbRows; ++node)
46  {
47  const common::Table<Real>::ConstRow data_row = data_array[element_row[node]];
48  for(Uint j = 0; j != NbCols; ++j)
49  to_fill(node, j) = data_row[j+start];
50  }
51 }
52 
54 template<typename RowT>
55 void fill(RealMatrix& to_fill, const common::Table<Real>& data_array, const RowT& element_row, const Uint start=0)
56 {
57  const Uint nb_nodes = element_row.size();
58  const Uint dim = data_array.row_size();
59  const Uint end = start+dim;
60  for(Uint node = 0; node != nb_nodes; ++node)
61  {
62  const common::Table<Real>::ConstRow data_row = data_array[element_row[node]];
63  for(Uint j = start; j != end; ++j)
64  to_fill(node, j-start) = data_row[j];
65  }
66 }
67 
70 // template<Uint NbNodes, Uint NbRows, Uint NbCols=1>
71 // struct ElementNodeValues
72 // {
73 // static const Uint nb_nodes = NbNodes;
74 // static const Uint nb_rows = NbRows;
75 // static const Uint nb_cols = NbCols;
76 // static const Uint node_size = NbRows*NbCols;
77 //
78 // /// Type of value at each node
79 // typedef Eigen::Matrix<Real, NbRows, NbCols> ValueT;
80 //
81 // Uint size() const
82 // {
83 // return nb_nodes;
84 // }
85 //
86 // ElementNodeValues() :m_data(NbNodes) {}
87 //
88 // const ValueT& operator[](const Uint i) const
89 // {
90 // return m_data[i];
91 // }
92 //
93 // template<typename RowT>
94 // void fill(const common::Table<Real>& data_array, const RowT& element_row, const Uint start=0)
95 // {
96 // static const Uint end = start+node_size;
97 // for(Uint node = 0; node != nb_nodes; ++node)
98 // {
99 // ValueT& mat = m_data[node];
100 // const common::Table<Real>::ConstRow data_row = data_array[element_row[node]];
101 // for(Uint j = 0; j != NbCols; ++j)
102 // {
103 // const Uint offset = start + j*NbRows;
104 // for(Uint i = 0; i != NbRows; ++i)
105 // {
106 // mat(i, j) = data_row[offset + i];
107 // }
108 // }
109 // }
110 // }
111 //
112 // private:
113 // std::vector<ValueT,Eigen::aligned_allocator<ValueT> > m_data;
114 // };
115 
116 
118 
120 template<Uint NbNodes, Uint NbRows, Uint NbCols=1>
122 
124 template<Uint NbNodes>
125 struct ElementNodeView<NbNodes, 1, 1>
126 {
127  static const Uint nb_nodes = NbNodes;
128  static const Uint nb_rows = 1;
129  static const Uint nb_cols = 1;
130  static const Uint node_size = 1;
131 
132  Uint size() const
133  {
134  return nb_nodes;
135  }
136 
137  const Real& operator[](const Uint i) const
138  {
139  return *m_data[i];
140  }
141 
142  Real& operator[](const Uint i)
143  {
144  return *m_data[i];
145  }
146 
147  template<typename RowT>
148  void fill(common::Table<Real>& data_array, const RowT& element_row, const Uint start=0)
149  {
150  for(Uint i = 0; i != nb_nodes; ++i)
151  {
152  m_data[i] = &data_array[element_row[i]][start];
153  }
154  }
155 
156 private:
157  Real* m_data[NbNodes];
158 };
159 
161 template<typename RowT>
162 RealVector to_vector(const RowT& row)
163 {
164  const Uint row_size = row.size();
165  RealVector result(row_size);
166  for(Uint i =0; i != row_size; ++i)
167  result[i] = row[i];
168  return result;
169 }
170 
172 
173 } // mesh
174 } // cf3
175 
177 
178 #endif // cf3_mesh_ElementData_hpp
const Real & operator[](const Uint i) const
RealVector to_vector(const RowT &row)
Utility function to convert a vector-like type to a RealVector.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealMatrix
Dynamic sized matrix of Real scalars.
Definition: MatrixTypes.hpp:22
View of nodal data, allowing modification of the referenced data.
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Definition: MatrixTypes.hpp:25
void fill(common::Table< Real > &data_array, const RowT &element_row, const Uint start=0)
TableConstRow< ValueT >::type ConstRow
the const type of a row in the internal structure of the table
Definition: Table.hpp:59
Top-level namespace for coolfluid.
Definition: Action.cpp:18
void fill(NodeValuesT &to_fill, const common::Table< Real > &data_array, const RowT &element_row, const Uint start=0)
Fill STL-vector like per-node data storage.
Definition: ElementData.hpp:28
Uint row_size(Uint i=0) const
Definition: Table.hpp:133
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
Send comments to:
COOLFluiD Web Admin