TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
OpConvQuickIJKScalar.tpp
1/****************************************************************************
2* Copyright (c) 2015 - 2016, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef OpConvQuickIJKScalar_TPP_included
17#define OpConvQuickIJKScalar_TPP_included
18
19#include <OpConvQuickIJKScalar.h>
20
21#ifndef OpConvQuickIJKScalar_included
22#error __FILE__ should only be included from corresponding header
23#endif
24
25#include <IJK_Field.h>
26
27template <DIRECTION _DIR_>
28
29void OpConvQuickIJKScalar_double::compute_flux_(IJK_Field_local_double& resu, const int k_layer)
30{
31 if(_DIR_==DIRECTION::Z)
32 {
33 // The previous layer of curv and fram values might have been computed already
34 if (stored_curv_fram_layer_z_ != k_layer-1)
35 {
36 compute_curv_fram(_DIR_, k_layer-1);
38 }
39 }
40 compute_curv_fram(_DIR_, k_layer);
41
42 if (is_grad_ && !is_flux_)
43 {
47 }
48
49 ConstIJK_double_ptr velocity_dir(get_input_velocity(_DIR_), 0, 0, k_layer);
50 ConstIJK_double_ptr input_field(*input_field_, 0, 0, k_layer);
51 ConstIJK_double_ptr curv_values(tmp_curv_fram_, 0, 0, 1); /* if z direction, "left" will be in layer 0 */
52 ConstIJK_double_ptr fram_values(tmp_curv_fram_, 0, 0, 3); /* if z direction, "left" is in layer 2 */
53 IJK_double_ptr resu_ptr(resu, 0, 0, 0);
54 const int nx = _DIR_==DIRECTION::X ? input_field_->ni() + 1 : input_field_->ni();
55 const int ny = _DIR_==DIRECTION::Y ? input_field_->nj() + 1 : input_field_->nj();
56
57 const double delta_xyz = _DIR_==DIRECTION::Z ? (channel_data_.get_delta_z()[k_layer-1] + channel_data_.get_delta_z()[k_layer]) * 0.5 : channel_data_.get_delta((int)_DIR_);
58 double surface = 1.;
59 if (!is_grad_ || is_flux_)
60 surface = channel_data_.get_surface(k_layer, 1, (int) _DIR_);
61 else
62 {
63 switch(_DIR_)
64 {
65 case DIRECTION::X:
66 surface = 1 / channel_data_.get_delta_x();
67 break;
68 case DIRECTION::Y:
69 surface = 1 / channel_data_.get_delta_y();
70 break;
71 case DIRECTION::Z:
72 break;
73 }
74 }
75
76 if(_DIR_==DIRECTION::Z)
77 {
78 // Are we on the wall ?
79 const int global_k_layer = k_layer + channel_data_.offset_to_global_k_layer();
80 // global index of the layer of flux of the wall
81 // (assume one walls at zmin and zmax)
82 const int first_global_k_layer = 0;
83 const int last_global_k_layer = channel_data_.nb_elem_k_tot();
84
85 // GB 21/12/2020 : Similarly to velocity, we make the same adjustments.
86 // if (global_k_layer == first_global_k_layer || global_k_layer == last_global_k_layer) {
87 // ie (i) replace the former "==" by "<=" and ">=" to be identic to the condition in OpCentre4IJK
88 // and (ii) add the condition on perio_k
89 if (!perio_k_ && (global_k_layer <= first_global_k_layer || global_k_layer >= last_global_k_layer))
90 {
91 // We are on (or worse inside) the wall, zero flux
92 putzero(resu);
93 return;
94 }
95 }
96
97 const double velocity_frame = velocity_frame_of_reference_[(int) _DIR_];
98
99 const double delta_xyz_squared_over_8 = delta_xyz * delta_xyz * 0.125;
100 const int imax = nx;
101 const int jmax = ny;
102 const int vsize = Simd_double::size();
103 for (int j = 0; ; j++)
104 {
105 for (int i = 0; i < imax; i += vsize)
106 {
107 Simd_double velocity;
108 if (!is_grad_ || is_flux_)
109 velocity_dir.get_center(i, velocity);
110 Simd_double T0, T1; // scalar value at left and at right of the computed flux
111 Simd_double fram0, fram1;
112 Simd_double curv0, curv1;
113 input_field.get_left_center(_DIR_, i, T0, T1);
114 fram_values.get_left_center(_DIR_, i, fram0, fram1);
115 curv_values.get_left_center(_DIR_, i, curv0, curv1);
116 Simd_double fram = SimdMax(fram0, fram1);
117 Simd_double curv = SimdSelect<double>(velocity, 0., curv1, curv0);
118 Simd_double T_amont = SimdSelect<double>(velocity, 0., T1 /* if velocity < 0 */, T0 /* if velocity > 0 */);
119 Simd_double flux = (T0 + T1) * 0.5 - delta_xyz_squared_over_8 * curv;
120 flux = ((1. - fram) * flux + fram * T_amont) * (velocity - velocity_frame) * surface;
121 resu_ptr.put_val(i, flux);
122 }
123 // do not execute end_iloop at last iteration (because of assert on valid j+1)
124 if (j+1==jmax)
125 break;
126 input_field.next_j();
127 velocity_dir.next_j();
128 fram_values.next_j();
129 curv_values.next_j();
130 resu_ptr.next_j();
131 }
132
133 if(_DIR_==DIRECTION::Z)
134 {
135 // store curv and fram for next layer of fluxes in z direction
138 }
139}
140#endif
const IJK_Field_double & get_input_velocity(DIRECTION _DIR_)
void compute_curv_fram(DIRECTION _DIR_, int k_layer)
void shift_curv_fram(IJK_Field_local_double &tmp_curv_fram)