Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
temporal_sampler_mean.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_MEAN_H_
49 #define MUI_TEMPORAL_SAMPLER_MEAN_H_
50 
51 #include "../../general/util.h"
52 #include "../../config.h"
53 
54 namespace mui {
55 
56 template<typename CONFIG=default_config> class temporal_sampler_mean {
57 public:
58  using REAL = typename CONFIG::REAL;
59  using INT = typename CONFIG::INT;
60  using time_type = typename CONFIG::time_type;
61  using iterator_type = typename CONFIG::iterator_type;
62 
64  left_ = left;
65  right_ = right;
66  }
67 
68  //- Filter based on time input
69  template<typename TYPE>
70  TYPE filter( time_type focus, const std::vector<std::pair<std::pair<time_type,iterator_type>, TYPE> > &points ) const {
71  TYPE sum = TYPE(0);
72 
73  for( auto i: points ) {
74  if ( i.first.first <= focus + right_ && i.first.first >= focus - left_ ) {
75  sum += i.second;
76  }
77  }
78 
79  if ( points.size() )
80  return sum / TYPE(points.size());
81  else
82  return TYPE(0);
83  }
84 
85  //- Filter based on time and iterator input - only time used
86  template<typename TYPE>
87  TYPE filter( std::pair<time_type,iterator_type> focus, const std::vector<std::pair<std::pair<time_type,iterator_type>, TYPE> > &points ) const {
88  TYPE sum = TYPE(0);
89 
90  for( auto i: points ) {
91  if ( i.first.first <= focus.first + right_ && i.first.first >= focus.first - left_ ) {
92  sum += i.second;
93  }
94  }
95 
96  if ( points.size() )
97  return sum / TYPE(points.size());
98  else
99  return TYPE(0);
100  }
101 
103  return focus + right_;
104  }
105 
107  return focus - left_;
108  }
109 
111  return time_type(0);
112  }
113 
114 protected:
117 };
118 
119 }
120 
121 #endif /* MUI_TEMPORAL_SAMPLER_SUM_H_ */
Definition: temporal_sampler_mean.h:56
temporal_sampler_mean(time_type left=time_type(0), time_type right=time_type(0))
Definition: temporal_sampler_mean.h:63
time_type right_
Definition: temporal_sampler_mean.h:116
time_type tolerance() const
Definition: temporal_sampler_mean.h:110
typename CONFIG::time_type time_type
Definition: temporal_sampler_mean.h:60
typename CONFIG::REAL REAL
Definition: temporal_sampler_mean.h:58
time_type get_upper_bound(time_type focus) const
Definition: temporal_sampler_mean.h:102
time_type get_lower_bound(time_type focus) const
Definition: temporal_sampler_mean.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_mean.h:87
typename CONFIG::INT INT
Definition: temporal_sampler_mean.h:59
time_type left_
Definition: temporal_sampler_mean.h:115
typename CONFIG::iterator_type iterator_type
Definition: temporal_sampler_mean.h:61
TYPE filter(time_type focus, const std::vector< std::pair< std::pair< time_type, iterator_type >, TYPE > > &points) const
Definition: temporal_sampler_mean.h:70
Definition: comm.h:54
SCALAR sum(vexpr< E, SCALAR, D > const &u)
Definition: point.h:362