Flow123d  JS_before_hm-1576-g4d0b70e
field_value_cache.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file field_value_cache.cc
15  * @brief
16  * @author David Flanderka
17  */
18 
19 #include <limits>
21 #include "fields/field_values.hh"
22 #include "fields/eval_points.hh"
23 #include "fields/eval_subset.hh"
24 #include "fem/dh_cell_accessor.hh"
25 #include "mesh/accessors.hh"
26 
27 
28 /******************************************************************************
29  * Implementation of ElementCacheMap methods
30  */
31 
32 const unsigned int ElementCacheMap::undef_elem_idx = std::numeric_limits<unsigned int>::max();
33 const unsigned int ElementCacheMap::simd_size_double = 4;
34 
35 
37 : elm_idx_(CacheMapElementNumber::get(), ElementCacheMap::undef_elem_idx),
38  ready_to_reading_(false), element_eval_points_map_(nullptr), eval_point_data_(0),
39  regions_starts_(2*ElementCacheMap::regions_in_chunk,ElementCacheMap::regions_in_chunk),
40  element_starts_(2*ElementCacheMap::elements_in_chunk,ElementCacheMap::elements_in_chunk) {}
41 
42 
44  if (element_eval_points_map_!=nullptr) {
46  }
47 }
48 
49 
50 void ElementCacheMap::init(std::shared_ptr<EvalPoints> eval_points) {
51  this->eval_points_ = eval_points;
52  unsigned int ep_data_size = CacheMapElementNumber::get() * eval_points_->max_size();
53  eval_point_data_.resize(ep_data_size);
54  element_eval_points_map_ = new int [ep_data_size];
55  for (unsigned int i=0; i<ep_data_size; ++i)
57 }
58 
59 
61  RevertableList<EvalPointData> eval_point_data_tmp = eval_point_data_;
62  std::sort(eval_point_data_tmp.begin(), eval_point_data_tmp.end());
64 
65  unsigned int last_region_idx = -1;
66  unsigned int last_element_idx = -1;
67  unsigned int i_pos=0; // position in eval_point_data_
68 
69  // Erase element data of previous step
72  element_to_map_.clear();
73  std::fill(elm_idx_.begin(), elm_idx_.end(), ElementCacheMap::undef_elem_idx);
74 
75  for (auto it=eval_point_data_tmp.begin(); it!=eval_point_data_tmp.end(); ++it) {
76  if (it->i_element_ != last_element_idx) { // new element
77  if (it->i_reg_ != last_region_idx) { // new region
78  unsigned int last_eval_point = i_pos-1; // set size of block by SIMD size
79  while (i_pos % ElementCacheMap::simd_size_double > 0) {
81  i_pos++;
82  }
83 
85  last_region_idx = it->i_reg_;
86  }
87  elm_idx_[element_starts_.temporary_size()] = it->i_element_;
90  last_element_idx = it->i_element_;
91  }
93  set_element_eval_point(element_starts_.temporary_size()-1, it->i_eval_point_, i_pos);
94  i_pos++;
95  }
96  unsigned int last_eval_point = i_pos-1; // set size of block of last region by SIMD size
97  while (i_pos % ElementCacheMap::simd_size_double > 0) {
99  i_pos++;
100  }
101 
107 }
108 
109 
111  ready_to_reading_ = false;
112 }
113 
115  ready_to_reading_ = true;
116 }
117 
RevertableList< unsigned int > regions_starts_
Start positions of elements in regions (size = n_regions+1, last value is end of last region) ...
void init(std::shared_ptr< EvalPoints > eval_points)
Init cache.
bool ready_to_reading_
Flag is set down during update of cache when this can&#39;t be read.
ElementCacheMap()
Constructor.
static unsigned int get()
Return number of stored elements.
std::vector< Type >::iterator end()
static const int unused_point
Special constant (.
Directing class of FieldValueCache.
std::unordered_map< unsigned int, unsigned int > element_to_map_
Maps element_idx to element index in patch - TODO remove.
Auxiliary data class holds number of elements in cache and allow to set this value explicitly (e...
int * element_eval_points_map_
Holds data of evaluating points in patch.
RevertableList< EvalPointData > eval_point_data_
std::vector< Type >::iterator begin()
void set_element_eval_point(unsigned int i_elem_in_cache, unsigned int i_eval_point, int val) const
Set item of element_eval_points_map_.
static const unsigned int undef_elem_idx
Index of invalid element in cache.
void reset()
Clear the list.
~ElementCacheMap()
Destructor.
std::size_t emplace_back(Args &&...args)
void resize(std::size_t new_size)
std::vector< unsigned int > elm_idx_
Vector of element indexes stored in cache.
void start_elements_update()
Start update of cache.
void finish_elements_update()
Finish update after reading data to cache.
void create_patch()
Create patch of cached elements before reading data to cache.
std::shared_ptr< EvalPoints > eval_points_
Pointer to EvalPoints.
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points object.
std::size_t temporary_size() const
Return temporary size of list (full size of stored data).
std::size_t make_permanent()
Finalize temporary part of data.
static const unsigned int simd_size_double
RevertableList< unsigned int > element_starts_
Start positions of elements in eval_point_data_ (size = n_elements+1)