Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
sampler_sph_quintic.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 
51 #ifndef MUI_SAMPLER_SPH_QUINTIC_H_
52 #define MUI_SAMPLER_SPH_QUINTIC_H_
53 
54 #include "../../general/util.h"
55 #include "../../config.h"
56 #include "../sampler.h"
57 
58 namespace mui
59 {
60 
61 template<typename CONFIG=default_config, typename O_TP=typename CONFIG::REAL, typename I_TP=O_TP>
63 {
64 public:
65  using OTYPE = O_TP;
66  using ITYPE = I_TP;
67  using REAL = typename CONFIG::REAL;
68  using INT = typename CONFIG::INT;
69  using point_type = typename CONFIG::point_type;
70  const static int D = CONFIG::D;
71 
72  sampler_sph_quintic( REAL r_ ) : r( r_ ), hinv( REAL( 3 ) / r_ )
73  {
74  static_assert( D == 1 || D == 2 || D == 3, "Quintic kernel for dimension other than 1,2,3 not defined." );
75  REAL sigma;
76  switch( D ) {
77  case 1:
78  sigma = 1.0 / 120.0;
79  break;
80  case 2:
81  sigma = 7.0 / 478.0 / PI;
82  break;
83  case 3:
84  sigma = 1.0 / 120.0 / PI;
85  break;
86  }
87  norm_factor = sigma * powr<D>( hinv );
88  }
89 
90  template<template<typename, typename> class CONTAINER>
91  inline OTYPE filter( point_type focus, const CONTAINER<ITYPE, CONFIG> &data_points ) const
92  {
93  OTYPE vsum = 0;
94  for( size_t i = 0 ; i < data_points.size() ; i++ ) {
95  auto dist2 = normsq( focus - data_points[i].first );
96  if( dist2 < r * r ) {
97  REAL w = quintic_polynomial( sqrt( dist2 ) );
98  vsum += data_points[i].second * w;
99  }
100  }
101  return vsum;
102  }
103 
104  inline geometry::any_shape<CONFIG> support( point_type focus, REAL domain_mag ) const
105  {
106  return geometry::sphere<CONFIG>( focus, r );
107  }
108 
109 protected:
111 
112  inline REAL quintic_polynomial( const REAL dist ) const
113  {
114  REAL s, w;
115  REAL s1, s2, s3;
116  REAL s1_5, s2_5, s3_5;
117  s = dist * hinv;
118  s1 = 1.0 - s;
119  s2 = 2.0 - s;
120  s3 = 3.0 - s;
121  s1_5 = 15.0 * powr<5>( s1 );
122  s2_5 = -6.0 * powr<5>( s2 );
123  s3_5 = powr<5>( s3 );
124  if( s < 1.0 ) {
125  w = s3_5 + s2_5 + s1_5;
126  } else if( s < 2.0 ) {
127  w = s3_5 + s2_5;
128  } else if( s < 3.0 ) {
129  w = s3_5;
130  } else {
131  w = 0.0;
132  }
133  w *= norm_factor;
134  return w;
135  }
136 };
137 
138 }
139 
140 #endif /* MUI_SAMPLER_SPH_QUINTIC_H_ */
Definition: geometry.h:92
Definition: geometry.h:158
Definition: sampler_sph_quintic.h:63
REAL quintic_polynomial(const REAL dist) const
Definition: sampler_sph_quintic.h:112
typename CONFIG::INT INT
Definition: sampler_sph_quintic.h:68
O_TP OTYPE
Definition: sampler_sph_quintic.h:65
REAL r
Definition: sampler_sph_quintic.h:110
typename CONFIG::point_type point_type
Definition: sampler_sph_quintic.h:69
REAL hinv
Definition: sampler_sph_quintic.h:110
OTYPE filter(point_type focus, const CONTAINER< ITYPE, CONFIG > &data_points) const
Definition: sampler_sph_quintic.h:91
I_TP ITYPE
Definition: sampler_sph_quintic.h:66
static const int D
Definition: sampler_sph_quintic.h:70
REAL norm_factor
Definition: sampler_sph_quintic.h:110
geometry::any_shape< CONFIG > support(point_type focus, REAL domain_mag) const
Definition: sampler_sph_quintic.h:104
sampler_sph_quintic(REAL r_)
Definition: sampler_sph_quintic.h:72
typename CONFIG::REAL REAL
Definition: sampler_sph_quintic.h:67
Definition: comm.h:54
SCALAR normsq(vexpr< E, SCALAR, D > const &u)
Definition: point.h:380