27 #include "boost/lexical_cast.hpp"
52 this->set_vtk_type<T>();
57 ASSERT_GT(
n_comp, 0)(field_name).error(
"Output field returning variable size vectors. Try convert to MultiField.");
72 ASSERT_LT(component_idx, data_.size()).error(
"Index of component is out of range.\n");
73 return data_[component_idx];
80 for (
unsigned int i=0; i<size_of_cache; ++i) {
82 row_vec->resize(row_vec_size, numeric_limits<T>::signaling_NaN());
83 data_cache[i] = row_vec;
93 for (
unsigned int i_vec=0; i_vec<data_.size(); ++i_vec) {
94 idx = i_row * n_components;
96 for (
unsigned int i_col=0; i_col < n_components; ++i_col, ++idx) {
98 vec[idx] = boost::lexical_cast<T>(*tok);
105 template <
typename T>
108 for (
unsigned int i_vec=0; i_vec<data_.size(); ++i_vec) {
109 idx = i_row * n_components;
111 for (
unsigned int i_col=0; i_col < n_components; ++i_col, ++idx) {
112 data_stream.read(
reinterpret_cast<char *
>(&
vec[idx]),
sizeof(T));
124 template <
typename T>
129 for(
unsigned int i = n_comp_*n_dofs_per_element_*idx; i < n_comp_*n_dofs_per_element_*(idx+1); ++i )
130 out_stream <<
vec[i] <<
" ";
140 template <
typename T>
144 for(
unsigned int idx = start; idx < this->n_values_; idx++) {
145 for(
unsigned int i = n_comp_*n_dofs_per_element_*idx; i < n_comp_*n_dofs_per_element_*(idx+1); ++i )
146 out_stream <<
vec[i] <<
" ";
152 template <
typename T>
155 if (print_data_size) {
157 unsigned long long int data_byte_size = this->n_values_ * n_comp_ *
sizeof(T);
158 out_stream.write(
reinterpret_cast<const char*
>(&data_byte_size),
sizeof(
unsigned long long int));
162 for(
unsigned int idx = start; idx < this->n_values_; idx++) {
163 for(
unsigned int i = n_comp_*idx; i < n_comp_*(idx+1); ++i )
164 out_stream.write(
reinterpret_cast<const char*
>(&(
vec[i])),
sizeof(T));
169 template <
typename T>
174 for(
unsigned int idx = begin; idx < end; idx++) {
175 if (idx != begin) out_stream <<
" , ";
176 unsigned int vec_pos = n_comp_ * idx;
177 switch (this->n_comp_) {
178 case NumCompValueType::N_SCALAR: {
182 case NumCompValueType::N_VECTOR: {
183 typename arma::Col<T>::template fixed<3> vec_val;
184 for (
unsigned int i=0; i<3; ++i, ++vec_pos)
185 vec_val(i) =
vec[vec_pos];
189 case NumCompValueType::N_TENSOR: {
190 typename arma::Mat<T>::template fixed<3,3> mat_val;
191 for (
unsigned int i=0; i<3; ++i)
192 for (
unsigned int j=0; j<3; ++j, ++vec_pos)
193 mat_val(i,j) =
vec[vec_pos];
203 template <
typename T>
206 min = std::numeric_limits<double>::max();
207 max = std::numeric_limits<double>::min();
209 for(
unsigned int idx = 0; idx < this->n_values_; idx++) {
210 for(
unsigned int i = n_comp_*n_dofs_per_element_*idx; i < n_comp_*n_dofs_per_element_*(idx+1); ++i ) {
211 if (
vec[i] < min) min =
vec[i];
212 if (
vec[i] > max) max =
vec[i];
221 template <
typename T>
225 unsigned int vec_idx = idx*this->n_comp_*n_dofs_per_element_;
226 for(
unsigned int i = 0; i < this->n_comp_*n_dofs_per_element_; i++, vec_idx++) {
234 template <
typename T>
238 unsigned int vec_idx = idx*this->n_comp_*n_dofs_per_element_;
239 for(
unsigned int i = 0; i < this->n_comp_*n_dofs_per_element_; i++, vec_idx++) {
247 template <
typename T>
251 unsigned int vec_idx = idx*this->n_comp_*n_dofs_per_element_;
252 for(
unsigned int i = 0; i < this->n_comp_*n_dofs_per_element_; i++, vec_idx++) {
260 template <
typename T>
264 unsigned int vec_idx = idx*this->n_comp_*n_dofs_per_element_;
265 for(
unsigned int i = 0; i < this->n_comp_*n_dofs_per_element_; i++, vec_idx++) {
266 vec[vec_idx] /= divisor;
270 template <
typename T>
275 bool is_nan =
false, out_of_limit =
false;
276 for (
unsigned int j=0; j<data_.size(); ++j) {
278 for(
unsigned int i=0; i<
vec.size(); ++i) {
281 else vec[i] = default_val;
283 if ( (
vec[i] < lower_bound) || (
vec[i] > upper_bound) ) out_of_limit =
true;
292 template <
typename T>
294 if (check_scale_data_ == CheckScaleData::scale)
return;
297 for (
unsigned int j=0; j<data_.size(); ++j) {
299 for(
unsigned int i=0; i<
vec.size(); ++i) {
304 check_scale_data_ = CheckScaleData::scale;
308 template <
typename T>
310 std::shared_ptr< ElementDataCache<T> > gather_cache;
311 int rank = distr->
myp();
312 int n_proc = distr->
np();
314 unsigned int n_global_data;
315 int rec_starts[n_proc];
316 int rec_counts[n_proc];
317 int *rec_indices_ids =
nullptr;
318 T *rec_data =
nullptr;
322 for (
int i=0; i<n_proc; ++i) {
323 rec_starts[i] = distr->
begin(i);
324 rec_counts[i] = distr->
lsize(i);
326 n_global_data = distr->
size();
327 rec_indices_ids =
new int [ n_global_data ];
331 for (
int i=0; i<n_proc; ++i) {
332 rec_starts[i] = this->n_comp()*this->n_dofs_per_element()*rec_starts[i];
333 rec_counts[i] = this->n_comp()*this->n_dofs_per_element()*rec_counts[i];
335 rec_data =
new T [ this->n_comp() * this->n_dofs_per_element() * n_global_data ];
337 auto &local_cache_vec = *( this->get_component_data(0).get() );
338 MPI_Gatherv( &local_cache_vec[0], this->n_comp()*this->n_dofs_per_element()*distr->
lsize(), this->mpi_data_type(), rec_data, rec_counts, rec_starts, this->mpi_data_type(), 0,
MPI_COMM_WORLD) ;
342 gather_cache = std::make_shared<ElementDataCache<T>>(this->field_input_name_, (
unsigned int)this->n_comp(), n_global_data, this->fe_type_, this->n_dofs_per_element_);
343 auto &gather_vec = *( gather_cache->get_component_data(0).get() );
344 unsigned int i_global_coord;
345 for (
unsigned int i=0; i<n_global_data; ++i) {
346 i_global_coord = this->n_comp() * this->n_dofs_per_element() * rec_indices_ids[i];
347 for (
unsigned int j=0; j<this->n_comp() * this->n_dofs_per_element(); ++j) {
348 ASSERT_LT(i_global_coord+j, gather_vec.size());
349 gather_vec[ i_global_coord+j ] = rec_data[ this->n_comp()*this->n_dofs_per_element()*i+j ];
353 delete[] rec_indices_ids;
361 template <
typename T>
363 unsigned int n_elem = offset_vec.size()-1;
364 std::shared_ptr< ElementDataCache<T> > elem_node_cache = std::make_shared<ElementDataCache<T>>(this->field_input_name_, 4*this->n_comp(), n_elem, this->fe_type_, this->n_dofs_per_element_);
365 auto &data_out_vec = *( elem_node_cache->get_component_data(0).get() );
366 std::fill( data_out_vec.begin(), data_out_vec.end(), (T)0 );
367 auto &data_in_vec = *( this->get_component_data(0).get() );
369 unsigned int i_node, i_old, i_new;
370 for (
unsigned int i_el=0, i_conn=0; i_el<offset_vec.size()-1; i_el++) {
371 for(i_node=4*i_el; i_conn<offset_vec[i_el+1]; i_conn++, i_node++) {
372 i_old = i_conn*this->n_comp_*this->n_dofs_per_element_;
373 i_new = i_node*this->n_comp_*this->n_dofs_per_element_;
374 for(
unsigned int i = 0; i < this->n_comp_*this->n_dofs_per_element_; i++) {
377 data_out_vec[i_new+i] = data_in_vec[i_old+i];
382 return elem_node_cache;
386 template <
typename T>
388 std::shared_ptr< ElementDataCache<T> > elem_node_cache = std::make_shared<ElementDataCache<T>>(this->field_input_name_,
389 this->n_comp()/4, offset_vec[offset_vec.size()-1], this->fe_type_, this->n_dofs_per_element_);
390 auto &data_out_vec = *( elem_node_cache->get_component_data(0).get() );
391 auto &data_in_vec = *( this->get_component_data(0).get() );
393 unsigned int i_node, i_old, i_new;
394 for (
unsigned int i_el=0, i_conn=0; i_el<offset_vec.size()-1; i_el++) {
395 for(i_node=4*i_el; i_conn<offset_vec[i_el+1]; i_conn++, i_node++) {
396 i_old = i_node*elem_node_cache->n_comp_*this->n_dofs_per_element_;
397 i_new = i_conn*elem_node_cache->n_comp_*this->n_dofs_per_element_;
398 for(
unsigned int i = 0; i < elem_node_cache->n_comp_*this->n_dofs_per_element_; i++) {
401 data_out_vec[i_new+i] = data_in_vec[i_old+i];
405 return elem_node_cache;
409 template <
typename T>
411 ASSERT_EQ(conn_vec.size(), this->n_values());
415 std::shared_ptr< ElementDataCache<T> > node_cache = std::make_shared<ElementDataCache<T>>(this->field_input_name_, this->n_comp(), data_size, this->fe_type_, this->n_dofs_per_element_);
417 for (idx=0; idx < node_cache->n_values(); idx++)
418 node_cache->zero(idx);
420 auto &data_in_vec = *( this->get_component_data(0).get() );
421 for (idx=0; idx < conn_vec.size(); idx++) {
422 ASSERT_LT(conn_vec[idx], node_cache->n_values());
423 ASSERT_LT(this->n_comp()*this->n_dofs_per_element()*idx, data_in_vec.size());
424 node_cache->add( conn_vec[idx], &(data_in_vec[this->n_comp() * this->n_dofs_per_element() * idx]) );
425 count[ conn_vec[idx] ]++;
429 for(idx=0; idx < node_cache->n_values(); idx++)
430 node_cache->normalize(idx, count[idx]);