Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
temporal_sampler_exact.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
48 #ifndef MUI_TEMPORAL_SAMPLER_EXACT_H_
49 #define MUI_TEMPORAL_SAMPLER_EXACT_H_
50 
51 #include <limits>
52 #include "../../general/util.h"
53 #include "../../config.h"
54 
55 namespace mui {
56 
57 template<typename CONFIG=default_config> class temporal_sampler_exact {
58 public:
59  using REAL = typename CONFIG::REAL;
60  using INT = typename CONFIG::INT;
61  using time_type = typename CONFIG::time_type;
62  using iterator_type = typename CONFIG::iterator_type;
63 
64  temporal_sampler_exact( time_type tol = time_type(std::numeric_limits<time_type>::epsilon()) ) {
65  int exponent;
66  frexp10<time_type>( std::numeric_limits<time_type>::max(), exponent );
67  time_type real_precision_time = static_cast<time_type>( exponent );
68  iterator_type real_precision_it = static_cast<iterator_type>( exponent );
69  tolerance_time = tol*real_precision_time;
70  tolerance_it = tol*real_precision_it;
71  }
72 
73  //- Filter based on time input
74  template<typename TYPE>
75  TYPE filter( time_type focus, const std::vector<std::pair<std::pair<time_type,iterator_type>, TYPE> > &points ) const {
76  for( auto i: points ) {
77  time_type dt = std::abs(i.first.first - focus);
78  if ( dt <= tolerance_time ) {
79  return i.second;
80  }
81  }
82 
83  return TYPE();
84  }
85 
86  //- Filter based on time and iterator input - both used
87  template<typename TYPE>
88  TYPE filter( std::pair<time_type,iterator_type> focus, const std::vector<std::pair<std::pair<time_type,iterator_type>, TYPE> > &points ) const {
89  for( auto i: points ) {
90  time_type dt = std::abs(i.first.first - focus.first);
91  iterator_type di = std::abs(i.first.second - focus.second);
92  if ( dt <= tolerance_time && di <= tolerance_it ) {
93  return i.second;
94  }
95  }
96 
97  return TYPE();
98  }
99 
100  template<typename TYPE>
101  TYPE get_upper_bound( TYPE focus ) const {
102  return focus;
103  }
104 
105  template<typename TYPE>
106  TYPE get_lower_bound( TYPE focus ) const {
107  return focus;
108  }
109 
110 private:
111  time_type tolerance_time;
112  time_type tolerance_it;
113 };
114 
115 }
116 
117 #endif /* MUI_TEMPORAL_SAMPLER_EXACT_H_ */
Definition: temporal_sampler_exact.h:57
typename CONFIG::time_type time_type
Definition: temporal_sampler_exact.h:61
typename CONFIG::iterator_type iterator_type
Definition: temporal_sampler_exact.h:62
TYPE filter(time_type focus, const std::vector< std::pair< std::pair< time_type, iterator_type >, TYPE > > &points) const
Definition: temporal_sampler_exact.h:75
typename CONFIG::INT INT
Definition: temporal_sampler_exact.h:60
typename CONFIG::REAL REAL
Definition: temporal_sampler_exact.h:59
TYPE get_lower_bound(TYPE focus) const
Definition: temporal_sampler_exact.h:106
TYPE filter(std::pair< time_type, iterator_type > focus, const std::vector< std::pair< std::pair< time_type, iterator_type >, TYPE > > &points) const
Definition: temporal_sampler_exact.h:88
temporal_sampler_exact(time_type tol=time_type(std::numeric_limits< time_type >::epsilon()))
Definition: temporal_sampler_exact.h:64
TYPE get_upper_bound(TYPE focus) const
Definition: temporal_sampler_exact.h:101
Definition: comm.h:54
SCALAR max(vexpr< E, SCALAR, D > const &u)
Definition: point.h:350