TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
OpConvAmontIJK.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 OpConvAmontIJK_TPP_included
17#define OpConvAmontIJK_TPP_included
18
19#include <OpConvAmontIJK.h>
20
21#ifndef OpConvAmontIJK_included
22#error __FILE__ should only be included from corresponding header
23#endif
24
25#include <IJK_ptr.h>
26#include <Simd_template.h>
27
28#include <ConstIJK_ptr.h>
29#include <IJK_Field_local_template.h>
30#include <Operateur_IJK_base.h>
31
32/*! @brief compute fluxes in direction _DIR_ for velocity component _VCOMPO_ for the layer of fluxes k_layer
33 *
34 * 4-th order centered convection scheme
35 *
36 */
37template <DIRECTION _DIR_, DIRECTION _VCOMPO_>
38void OpConvAmontIJK_double::compute_flux_(IJK_Field_local_double& resu, const int k_layer)
39{
40 // convected field
41 const IJK_Field_local_double& src = get_input(_VCOMPO_);
42 // Convected vector field:
43 ConstIJK_double_ptr src_ptr(src, 0, 0, k_layer);
44 // Velocity in x direction (convecting velocity)
45 ConstIJK_double_ptr vconv_ptr(get_v(_DIR_), 0, 0, k_layer);
46
47 const int idir = (int)_DIR_;
48 const int nx = _DIR_ == DIRECTION::X ? src.ni() + 1 : src.ni();
49 const int ny = _DIR_ == DIRECTION::Y ? src.nj() + 1 : src.nj();
50 const int icompo = (int)_VCOMPO_;
51
52 // Result (fluxes in direction x for component x of the convected field)
53 IJK_double_ptr resu_ptr(resu, 0, 0, 0);
54
55 const int global_k_layer = k_layer + channel_data_.offset_to_global_k_layer();
56 // global index of the layer of flux of the wall
57 // (assume one walls at zmin and zmax)
58 const int first_global_k_layer = channel_data_.first_global_k_layer_flux(icompo, idir);
59 const int last_global_k_layer = channel_data_.last_global_k_layer_flux(icompo, idir);
60
61 // GB 21/12/2020 : Similarly to velocity,
62 // if (global_k_layer < first_global_k_layer || global_k_layer > last_global_k_layer) {
63 if (!perio_k_ && (global_k_layer <= first_global_k_layer || global_k_layer >= last_global_k_layer))
64 {
65 // We are in the wall
66 putzero(resu);
67 return;
68 }
69
70 double half_surface = channel_data_.get_surface(k_layer, icompo, idir) * 0.5;
71 {
72 const int imax = nx;
73 const int jmax = ny;
74 const int vsize = Simd_double::size();
75 for (int j = 0; ; j++)
76 {
77 for (int i = 0; i < imax; i += vsize) // specific coding for uniform mesh in x and y: surfaces are constant on an xy plane
78 {
79 Simd_double vit_0,vit_1; // 2 adjacent velocity values
80 src_ptr.get_left_center(_DIR_,i,vit_0,vit_1);
81 // get convecting velocity
82 Simd_double vconv0, vconv1;
83 vconv_ptr.get_left_center(_VCOMPO_, i, vconv0, vconv1);
84
85 // Average of the convecting velocity (copied from Eval_Amont_VDF_Face : not weighted)
86 Simd_double psc = (vconv0 + vconv1) * half_surface;
87 Simd_double upwind_velocity = SimdSelect<double>(psc, 0., vit_1 /* if psc < 0 */, vit_0 /* if psc > 0 */);
88 Simd_double flux = psc * upwind_velocity;
89 resu_ptr.put_val(i, flux);
90 }
91 // do not execute end_iloop at last iteration (because of assert on valid j+1)
92 if (j+1==jmax)
93 break;
94 // instructions to perform to jump to next row
95 src_ptr.next_j();
96 resu_ptr.next_j();
97 vconv_ptr.next_j();
98 }
99 }
100}
101
102#endif
const IJK_Field_double & get_input(DIRECTION _DIR_)
const IJK_Field_double & get_v(DIRECTION _DIR_)