Flow123d  3.9.1-703bcfc
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) {
45  delete[] element_eval_points_map_;
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 = eval_points_->max_size() * CacheMapElementNumber::get();
53  DebugOut() << "ep_data_size: " << ep_data_size << "\n";
54  eval_point_data_.resize(ep_data_size);
55  element_eval_points_map_ = new int [ep_data_size];
56  for (unsigned int i=0; i<ep_data_size; ++i)
58 }
59 
60 
62  RevertableList<EvalPointData> eval_point_data_tmp = eval_point_data_;
63  std::sort(eval_point_data_tmp.begin(), eval_point_data_tmp.end());
65 
66  unsigned int last_region_idx = -1;
67  unsigned int last_element_idx = -1;
68  unsigned int i_pos=0; // position in eval_point_data_
69  bool is_new_reg, is_new_elm;
70 
71  // Erase element data of previous step
74  element_to_map_.clear();
75  element_to_map_bdr_.clear();
76  std::fill(elm_idx_.begin(), elm_idx_.end(), ElementCacheMap::undef_elem_idx);
77 
78  for (auto it=eval_point_data_tmp.begin(); it!=eval_point_data_tmp.end(); ++it) {
79  is_new_reg = (it->i_reg_ != last_region_idx);
80  is_new_elm = is_new_reg || (it->i_element_ != last_element_idx);
81  if (is_new_elm) {
82  if (is_new_reg) {
83  unsigned int last_eval_point = i_pos-1; // set size of block by SIMD size
84  while (i_pos % ElementCacheMap::simd_size_double > 0) {
86  i_pos++;
87  }
88 
90  last_region_idx = it->i_reg_;
91  }
92  elm_idx_[element_starts_.temporary_size()] = it->i_element_;
93  if (it->i_reg_ % 2 == 1) // bulk region > to element_to_map_ (bulk)
95  else // boundary region to element_to_map_bdr_ (boundary)
98  last_element_idx = it->i_element_;
99  }
101  set_element_eval_point(element_starts_.temporary_size()-1, it->i_eval_point_, i_pos);
102  i_pos++;
103  }
104  unsigned int last_eval_point = i_pos-1; // set size of block of last region by SIMD size
105  while (i_pos % ElementCacheMap::simd_size_double > 0) {
106  eval_point_data_.emplace_back( eval_point_data_[last_eval_point] );
107  i_pos++;
108  }
109 
115  set_of_regions_.clear();
116 }
117 
118 
120  ready_to_reading_ = false;
121 }
122 
124  ready_to_reading_ = true;
125 }
126 
CacheMapElementNumber::get
static unsigned int get()
Return number of stored elements.
Definition: field_value_cache.hh:93
fmt::internal::get
T & get()
eval_subset.hh
ElementCacheMap::element_to_map_bdr_
std::unordered_map< unsigned int, unsigned int > element_to_map_bdr_
Maps boundary element_idx to element index in patch - TODO remove.
Definition: field_value_cache.hh:360
ElementCacheMap::create_patch
void create_patch()
Create patch of cached elements before reading data to cache.
Definition: field_value_cache.cc:61
RevertableList::make_permanent
std::size_t make_permanent()
Finalize temporary part of data.
Definition: revertable_list.hh:127
RevertableList::end
std::vector< Type >::iterator end()
Definition: revertable_list.hh:154
RevertableList::emplace_back
std::size_t emplace_back(Args &&... args)
Definition: revertable_list.hh:114
ElementCacheMap::simd_size_double
static const unsigned int simd_size_double
Definition: field_value_cache.hh:158
CacheMapElementNumber
Auxiliary data class holds number of elements in cache and allow to set this value explicitly (e....
Definition: field_value_cache.hh:90
ElementCacheMap
Directing class of FieldValueCache.
Definition: field_value_cache.hh:151
ElementCacheMap::undef_elem_idx
static const unsigned int undef_elem_idx
Index of invalid element in cache.
Definition: field_value_cache.hh:154
eval_points.hh
ElementCacheMap::set_element_eval_point
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_.
Definition: field_value_cache.hh:315
RevertableList::reset
void reset()
Clear the list.
Definition: revertable_list.hh:142
ElementCacheMap::element_eval_points_map_
int * element_eval_points_map_
Holds data of evaluating points in patch.
Definition: field_value_cache.hh:349
ElementCacheMap::set_of_regions_
std::unordered_set< unsigned int > set_of_regions_
Keeps set of unique region indices of added eval. points.
Definition: field_value_cache.hh:365
ElementCacheMap::regions_starts_
RevertableList< unsigned int > regions_starts_
Start positions of elements in regions (size = n_regions+1, last value is end of last region)
Definition: field_value_cache.hh:357
ElementCacheMap::eval_point_data_
RevertableList< EvalPointData > eval_point_data_
Definition: field_value_cache.hh:352
ElementCacheMap::init
void init(std::shared_ptr< EvalPoints > eval_points)
Init cache.
Definition: field_value_cache.cc:50
RevertableList::temporary_size
std::size_t temporary_size() const
Return temporary size of list (full size of stored data).
Definition: revertable_list.hh:77
dh_cell_accessor.hh
accessors.hh
ElementCacheMap::eval_points_
std::shared_ptr< EvalPoints > eval_points_
Pointer to EvalPoints.
Definition: field_value_cache.hh:324
ElementCacheMap::eval_points
std::shared_ptr< EvalPoints > eval_points() const
Getter of eval_points object.
Definition: field_value_cache.hh:193
field_values.hh
ElementCacheMap::unused_point
static const int unused_point
Special constant (.
Definition: field_value_cache.hh:306
ElementCacheMap::element_to_map_
std::unordered_map< unsigned int, unsigned int > element_to_map_
Maps bulk element_idx to element index in patch - TODO remove.
Definition: field_value_cache.hh:359
ElementCacheMap::elm_idx_
std::vector< unsigned int > elm_idx_
Vector of element indexes stored in cache.
Definition: field_value_cache.hh:321
RevertableList< EvalPointData >
RevertableList::resize
void resize(std::size_t new_size)
Definition: revertable_list.hh:64
Input::Type
Definition: balance.hh:41
ElementCacheMap::finish_elements_update
void finish_elements_update()
Finish update after reading data to cache.
Definition: field_value_cache.cc:123
RevertableList::begin
std::vector< Type >::iterator begin()
Definition: revertable_list.hh:149
field_value_cache.hh
ElementCacheMap::~ElementCacheMap
~ElementCacheMap()
Destructor.
Definition: field_value_cache.cc:43
ElementCacheMap::ElementCacheMap
ElementCacheMap()
Constructor.
Definition: field_value_cache.cc:36
ElementCacheMap::start_elements_update
void start_elements_update()
Start update of cache.
Definition: field_value_cache.cc:119
DebugOut
#define DebugOut()
Macro defining 'debug' record of log.
Definition: logger.hh:284
ElementCacheMap::ready_to_reading_
bool ready_to_reading_
Flag is set down during update of cache when this can't be read.
Definition: field_value_cache.hh:327
ElementCacheMap::element_starts_
RevertableList< unsigned int > element_starts_
Start positions of elements in eval_point_data_ (size = n_elements+1)
Definition: field_value_cache.hh:358