TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Corrige_flux_FT_temperature_subresolution.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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#include <Corrige_flux_FT_temperature_subresolution.h>
17#include <IJK_Field_vector.h>
18#include <Probleme_FTD_IJK.h>
19
20Implemente_instanciable_sans_constructeur( Corrige_flux_FT_temperature_subresolution, "Corrige_flux_FT_temperature_subresolution", Corrige_flux_FT_base ) ;
21
22Corrige_flux_FT_temperature_subresolution::Corrige_flux_FT_temperature_subresolution()
23{
24
25}
26
31
33{
35 return os;
36}
37
39{
41 return is;
42}
43
45{
46 int c, l;
47
48 for (c=0; c<3; c++)
53
54 for (l=0; l<2; l++)
55 for (c=0; c<3; c++)
57
58 for (c=0; c<3; c++)
59 {
64 }
65
66 for (l=0; l<2; l++)
67 for (c=0; c<3; c++)
69
70 for (c=0; c<3; c++)
71 {
76 }
77
78 for (c=0; c<3; c++)
79 flux_frontier_map_[c].clear();
80
81 /*
82 * M.G (07/12/23) All fluxes may be useless; Diagonal fluxes are not relevant for the moment
83 */
84
85 for (l=0; l<2; l++)
86 for (c=0; c<3; c++)
88
89 for (l=0; l<2; l++)
90 for (c=0; c<3; c++)
92
93 /*
94 * Face fluxes on a reconstructed convex shell around the bubble !
95 */
96
97 for (l=0; l<2; l++)
98 for (c=0; c<3; c++)
100
101 for (c=0; c<3; c++)
102 {
107 }
108
109 /*
110 * Face fluxes on a reconstructed convex shell around the bubble (Parallel) !
111 */
112
113 for (l=0; l<2; l++)
114 for (c=0; c<3; c++)
116
117 for (c=0; c<3; c++)
119
120
121 for (c=0; c<3; c++)
123
125 for (c=0; c<3; c++)
127
128 for (c=0; c<3; c++)
129 {
134 }
135
136 for (c=0; c<3; c++)
137 {
139 flux_frontier_all_map_[c].clear();
140 }
141}
142
144{
145 for (int k=0; k<(int) indices_to_clear.size(); k++)
146 indices_to_clear[k].reset();
147}
149{
150 for (int k=0; k<(int) values_to_clear.size(); k++)
151 values_to_clear[k].reset();
152}
153
154static int compute_periodic_index(const int index, const int n)
155{
156 return (n + index % n) % n;
157}
158
160 const IJK_Field_double& field,
161 const IJK_Interfaces& interfaces,
162 const Probleme_FTD_IJK_base& ijk_ft,
163 Intersection_Interface_ijk_face& intersection_ijk_face,
164 Intersection_Interface_ijk_cell& intersection_ijk_cell,
165 IJK_One_Dimensional_Subproblems& thermal_subproblems)
166{
167 Corrige_flux_FT_base::initialize_with_subproblems(splitting, field, interfaces, ijk_ft, intersection_ijk_face, intersection_ijk_cell, thermal_subproblems);
168 associate_thermal_problems(thermal_subproblems);
169}
170
172{
173
174 // if (!distance_cell_faces_from_lrs_)
175 {
176 // On commence par calculer les temperatures aux faces mouillées
177 intersection_ijk_cell_->update_interpolations_cell_centres_on_interface();
178 /*
179 * TODO update with face cell centres positions
180 */
182 intersection_ijk_cell_->update_interpolations_cell_faces_on_interface();
183
184 Cerr << "The intersections have been updated" << finl;
185 }
186}
187
192
194{
196 {
197 const int nb_diph = intersection_ijk_cell_->get_nb_diph();
198 const int nb_subproblems = thermal_subproblems_->get_subproblems_counter();
199 const int nb_effective_subproblems = thermal_subproblems_->get_effective_subproblems_counter();
200 has_checked_consistency_ = (nb_diph==nb_subproblems);
203 ijk_intersections_subproblems_indices_.resize(nb_effective_subproblems);
204 int index_i_problem = 0;
205 int index_j_problem = 0;
206 int index_k_problem = 0;
207 int problem_index;
208 for (problem_index=0; problem_index<nb_effective_subproblems; problem_index++)
209 {
210 thermal_subproblems_->get_subproblem_ijk_indices(index_i_problem, index_j_problem, index_k_problem, problem_index);
211 const int ijk_intersections_index = (*intersection_ijk_cell_)(index_i_problem, index_j_problem, index_k_problem);
212 if (ijk_intersections_index > -1)
213 {
214 ijk_intersections_subproblems_indices_[problem_index] = ijk_intersections_index;
216 }
217 else
218 {
219 Cerr << "Inconsistency between intersection_ijk_cell and the thermal_subproblem (index " << problem_index << ")" << finl;
221 }
222 }
225 {
226 Cerr << "There is an inconsistency between the LRS sub-problem and the intersection_ijk_elem" << finl;
228 }
229 }
230 else
231 Cerr << "Inconsistency has already be checked" << finl;
232}
233
235{
236 // if (!distance_cell_faces_from_lrs_)
237 {
239 intersection_ijk_cell_->set_pas_a_jour();
240 }
241}
242
243
245{
246 /*
247 * For each subproblem fill the right interfacial_cell
248 */
249 DoubleTab dist_interf;
251 dist_interf = intersection_ijk_cell_->dist_interf();
252
253 const double min_temperature = thermal_subproblems_->get_min_temperature_domain_ends();
254 const double max_temperature = thermal_subproblems_->get_max_temperature_domain_ends();
255
256 for (int i=0; i<thermal_subproblems_->get_effective_subproblems_counter(); i++)
257 {
258 double dist = 0;
259 double dist_sub_res = 0;
260 double temperature_ghost = 0.;
261 int intersection_ijk_cell_index = 0;
262 int ijk_indices_i = 0;
263 int ijk_indices_j = 0;
264 int ijk_indices_k = 0;
265 dist_sub_res = thermal_subproblems_->get_dist_cell_interface(i);
267 {
268 intersection_ijk_cell_index = ijk_intersections_subproblems_indices_[i];
269 dist = dist_interf(intersection_ijk_cell_index, 0);
270 temperature_ghost = thermal_subproblems_->get_temperature_profile_at_point(i, dist);
271 ijk_indices_i = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 0);
272 ijk_indices_j = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 1);
273 ijk_indices_k = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 2);
274 }
275 else
276 {
277 temperature_ghost = thermal_subproblems_->get_temperature_profile_at_point(i, dist_sub_res);
278 thermal_subproblems_->get_subproblem_ijk_indices(ijk_indices_i, ijk_indices_j, ijk_indices_k, i);
279 }
280
281 temperature(ijk_indices_i, ijk_indices_j, ijk_indices_k) = temperature_ghost;
282
283 if (debug_)
284 {
285 Cerr << "Time-step: " << ref_ijk_ft_->schema_temps_ijk().get_tstep() << "--" << ref_ijk_ft_->schema_temps_ijk().get_timestep() << " s" << finl;
287 {
288 Cerr << "Distance at cell : " << intersection_ijk_cell_index <<
289 ", subproblem " << i << "."<<
290 " -- (" << ijk_indices_i << ", " << ijk_indices_j << ", " << ijk_indices_k << ")" << finl;
291 Cerr << "Distance from intersection_ijk_cell: " << dist << finl;
292 }
293 Cerr << "Distance from sub-resolution: " << dist_sub_res << finl;
294 Vecteur3 bary_facet_debug = thermal_subproblems_->get_bary_facet(i);
295 Cerr << "Facet barycentre: " << bary_facet_debug[0] << ";"
296 << bary_facet_debug[1] << ";"
297 << bary_facet_debug[2] << finl;
298
299 const IJK_Field_double& indicator = ref_ijk_ft_->get_interface().I();
300 const double indic = indicator(ijk_indices_i, ijk_indices_j, ijk_indices_k);
301 if (temperature_ghost < min_temperature && indic > 0.5)
302 Cerr << "Ghost temperature: " << temperature_ghost << " is lower than the minimum temperature:" << min_temperature << finl;
303 if (temperature_ghost > max_temperature && indic > 0.5)
304 Cerr << "Ghost temperature: " << temperature_ghost << " is higher than the maximum temperature:" << max_temperature << finl;
305 }
306 }
307}
308
310 IJK_Field_int& neighbours_weighting,
311 IJK_Field_double& neighbours_weighting_colinearity)
312{
314 {
315
316 const int ni = neighbours_weighting.ni();
317 const int nj = neighbours_weighting.nj();
318 const int nk = neighbours_weighting.nk();
319
320 const int offset_i = neighbours_weighting.get_domaine().get_offset_local(0);
321 const int offset_j = neighbours_weighting.get_domaine().get_offset_local(1);
322 const int offset_k = neighbours_weighting.get_domaine().get_offset_local(2);
323
324 const int ni_tot = neighbours_weighting.get_domaine().get_nb_elem_tot(0);
325 const int nj_tot = neighbours_weighting.get_domaine().get_nb_elem_tot(1);
326 const int nk_tot = neighbours_weighting.get_domaine().get_nb_elem_tot(2);
327
328 neighbours_weighting.data() = 0;
329 neighbours_weighting.echange_espace_virtuel(neighbours_weighting.ghost());
330 temperature_neighbours.data() = 0.;
331 temperature_neighbours.echange_espace_virtuel(temperature_neighbours.ghost());
333 {
334 neighbours_weighting_colinearity.data() = 0.;
335 neighbours_weighting_colinearity.echange_espace_virtuel(neighbours_weighting_colinearity.ghost());
336 }
337 std::vector<std::vector<std::vector<double>>> pure_neighbours_corrected_colinearity;
338 int index_i_problem, index_j_problem, index_k_problem;
339 int index_i_neighbour, index_j_neighbour, index_k_neighbour;
340 int index_i_procs, index_j_procs, index_k_procs;
341 int index_i_neighbour_global, index_j_neighbour_global, index_k_neighbour_global;
342 int m,l,n;
343 double neighbours_colinearity = 0.;
344 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
345 {
346 if (thermal_subproblems_->get_dxyz_increment_bool(i))
347 {
348 thermal_subproblems_->get_subproblem_ijk_indices(index_i_problem, index_j_problem, index_k_problem, i);
349 const FixedVector<int,3>& pure_neighbours_corrected_sign = thermal_subproblems_->get_pure_neighbours_corrected_sign(i);
350 const std::vector<std::vector<std::vector<bool>>>& pure_neighbours_to_correct = thermal_subproblems_->get_pure_neighbours_to_correct(i);
351 const std::vector<std::vector<std::vector<double>>>& pure_neighbours_corrected_distance = thermal_subproblems_->get_pure_neighbours_corrected_distance(i);
353 pure_neighbours_corrected_colinearity = thermal_subproblems_->get_pure_neighbours_corrected_colinearity(i);
354 const int l_dir_size = (int) pure_neighbours_to_correct.size() -1;
355 const int m_dir_size = (int) pure_neighbours_to_correct[0].size() -1;
356 const int n_dir_size = (int) pure_neighbours_to_correct[0][0].size() -1;
357 for (l=l_dir_size; l>=0; l--)
358 for (m=m_dir_size; m>=0; m--)
359 for (n=n_dir_size; n>=0; n--)
360 if (pure_neighbours_to_correct[l][m][n])
361 {
362 const double dist_sub_res = pure_neighbours_corrected_distance[l][m][n];
363 const double temperature_ghost = thermal_subproblems_->get_temperature_profile_at_point(i, dist_sub_res);
364 index_i_neighbour = index_i_problem + ((pure_neighbours_corrected_sign[0]) ? l * (-1) : l);
365 index_j_neighbour = index_j_problem + ((pure_neighbours_corrected_sign[1]) ? m * (-1) : m);
366 index_k_neighbour = index_k_problem + ((pure_neighbours_corrected_sign[2]) ? n * (-1) : n);
367 /*
368 * Handle both positive and negative periodicity !
369 */
370 index_i_neighbour_global = compute_periodic_index((index_i_neighbour + offset_i), ni_tot);
371 index_j_neighbour_global = compute_periodic_index((index_j_neighbour + offset_j), nj_tot);
372 index_k_neighbour_global = compute_periodic_index((index_k_neighbour + offset_k), nk_tot);
373 index_i_procs = compute_periodic_index(index_i_neighbour, ni);
374 index_j_procs = compute_periodic_index(index_j_neighbour, nj);
375 index_k_procs = compute_periodic_index(index_k_neighbour, nk);
377 neighbours_colinearity = pure_neighbours_corrected_colinearity[l][m][n];
378 if (index_i_procs == index_i_neighbour
379 && index_j_procs == index_j_neighbour
380 && index_k_procs == index_k_neighbour)
381 {
383 {
384 neighbours_weighting_colinearity(index_i_neighbour, index_j_neighbour, index_k_neighbour)
385 += neighbours_colinearity;
386 temperature_neighbours(index_i_neighbour, index_j_neighbour, index_k_neighbour)
387 += temperature_ghost * neighbours_colinearity;
388 }
389 else
390 temperature_neighbours(index_i_neighbour, index_j_neighbour, index_k_neighbour) += temperature_ghost;
391 neighbours_weighting(index_i_neighbour, index_j_neighbour, index_k_neighbour) += 1;
392 }
393 else
394 {
396 neighbours_colinearity,
397 index_i_neighbour_global,
398 index_j_neighbour_global,
399 index_k_neighbour_global);
400 }
401 }
402 }
403 }
406 neighbours_weighting,
407 neighbours_weighting_colinearity,
408 ni,
409 nj,
410 nk,
411 offset_i,
412 offset_j,
413 offset_k);
415 neighbours_weighting_colinearity.echange_espace_virtuel(neighbours_weighting_colinearity.ghost());
416 neighbours_weighting.echange_espace_virtuel(neighbours_weighting.ghost());
417 temperature_neighbours.echange_espace_virtuel(temperature_neighbours.ghost());
418 }
419}
420
421
423 const double& neighbours_weighting_colinearity,
424 const int& index_i_neighbour_global,
425 const int& index_j_neighbour_global,
426 const int& index_k_neighbour_global)
427{
428 indices_temperature_neighbours_on_procs_[0].append_array(index_i_neighbour_global);
429 indices_temperature_neighbours_on_procs_[1].append_array(index_j_neighbour_global);
430 indices_temperature_neighbours_on_procs_[2].append_array(index_k_neighbour_global);
431 temperature_neighbours_on_procs_.append_array(temperature_neighbours);
433 neighbours_weighting_colinearity_on_procs_.append_array(neighbours_weighting_colinearity);
434}
435
437{
438 Cerr << "Copy temperature on every processors" << finl;
440 {
441 const int nb_procs = Process::nproc();
442 const int proc_num = Process::me();
443 if (nb_procs > 1)
444 {
445 ArrOfInt local_indices_tmp;
446 ArrOfDouble local_values_tmp;
447
448 const int size_vector = indices_temperature_neighbours_on_procs_[0].size_array();
449 int size_vector_total = size_vector;
450 size_vector_total = Process::check_int_overflow(Process::mp_sum(size_vector_total));
451
452 ArrOfInt overall_numerotation(nb_procs);
453 ArrOfInt start_indices(nb_procs);
454 overall_numerotation(proc_num) = size_vector;
455 mp_sum_for_each_item(overall_numerotation);
456 int l;
457 for (l=1; l<overall_numerotation.size_array(); l++)
458 start_indices(l) = start_indices(l-1) + overall_numerotation(l-1);
459
460 for (int c=0; c<3; c++)
461 {
462 local_indices_tmp = indices_temperature_neighbours_on_procs_[c];
463 indices_temperature_neighbours_on_procs_[c].resize(size_vector_total);
465 for (l=0; l<local_indices_tmp.size_array(); l++)
466 indices_temperature_neighbours_on_procs_[c](start_indices(proc_num) + l) = local_indices_tmp(l);
467 }
468 local_indices_tmp.reset();
469
470 local_values_tmp = temperature_neighbours_on_procs_;
471 temperature_neighbours_on_procs_.resize(size_vector_total);
473 for (l=0; l<local_values_tmp.size_array(); l++)
474 temperature_neighbours_on_procs_(start_indices(proc_num) + l) = local_values_tmp(l);
476 {
478 neighbours_weighting_colinearity_on_procs_.resize(size_vector_total);
480 for (l=0; l<local_values_tmp.size_array(); l++)
481 neighbours_weighting_colinearity_on_procs_(start_indices(proc_num) + l) = local_values_tmp(l);
482 }
483
484 for (int c=0; c<3; c++)
485 {
486 ArrOfInt& indices_dir = indices_temperature_neighbours_on_procs_[c];
487 mp_sum_for_each_item(indices_dir);
488 }
493 }
494 }
495}
496
498 IJK_Field_int& neighbours_weighting,
499 IJK_Field_double& neighbours_weighting_colinearity,
500 const int& ni,
501 const int& nj,
502 const int& nk,
503 const int& offset_i,
504 const int& offset_j,
505 const int& offset_k)
506{
507 Cerr << "Combine temperature on every processors" << finl;
509 {
510 const int size_array = indices_temperature_neighbours_on_procs_[0].size_array();
511 int index_i_local, index_j_local, index_k_local;
512 for (int l=0; l<size_array; l++)
513 {
514 index_i_local = indices_temperature_neighbours_on_procs_[0](l) - offset_i;
515 index_j_local = indices_temperature_neighbours_on_procs_[1](l) - offset_j;
516 index_k_local = indices_temperature_neighbours_on_procs_[2](l) - offset_k;
517 if ((0 <= index_i_local && index_i_local < ni) &&
518 (0 <= index_j_local && index_j_local < nj) &&
519 (0 <= index_k_local && index_k_local < nk))
520 {
521 const double temperature_ghost = temperature_neighbours_on_procs_(l);
522 neighbours_weighting(index_i_local, index_j_local, index_k_local) += 1;
524 {
525 const double colinearity = neighbours_weighting_colinearity_on_procs_(l);
526 neighbours_weighting_colinearity(index_i_local, index_j_local, index_k_local) += colinearity;
527 temperature_neighbours(index_i_local, index_j_local, index_k_local) += colinearity * temperature_ghost;
528 }
529 else
530 temperature_neighbours(index_i_local, index_j_local, index_k_local) += temperature_ghost;
531 }
532 }
533 }
534}
535
537 const int nb_k_layer)
538{
539 for (int l=0; l<2; l++)
540 {
541 for (int dir=0; dir<2; dir++)
542 fixed_vectors[l][dir].resize(nb_k_layer);
543 fixed_vectors[l][2].resize(nb_k_layer + 1);
544 }
545}
546
548 const int nb_k_layer)
549{
550 for (int dir=0; dir<2; dir++)
551 fixed_vector[dir].resize(nb_k_layer);
552 fixed_vector[2].resize(nb_k_layer + 1);
553}
554
556 const int nb_k_layer)
557{
558 for (int dir=0; dir<2; dir++)
559 fixed_vector_values[dir].resize(nb_k_layer);
560 fixed_vector_values[2].resize(nb_k_layer + 1);
561}
562
564 const int global_indices)
565{
566 int nb_k_layer;
567 if (global_indices)
568 nb_k_layer = ref_ijk_ft_->get_interface().I().get_domaine().get_nb_elem_tot(2);
569 else
570 nb_k_layer = ref_ijk_ft_->get_interface().I().nk();
571
572 const int first_iter = !(ref_ijk_ft_->schema_temps_ijk().get_tstep());
573
574 int dir, l;
575 if (first_iter)
576 initialise_fixed_vectors(index_face_ij_flux_xyz_faces_sorted, nb_k_layer);
577
578 for (l=0; l<2; l++)
579 for (dir=0; dir<3; dir++)
580 for (int k_layer=0; k_layer<nb_k_layer+1; k_layer++)
581 {
582 if ((dir==DIRECTION_I || dir==DIRECTION_J) && k_layer==nb_k_layer)
583 break;
584 index_face_ij_flux_xyz_faces_sorted[l][dir][k_layer].reset();
585 }
586}
587
589 FixedVector<std::vector<ArrOfDouble>,3>& fluxes,
590 FixedVector<std::vector<ArrOfInt>,3>& weighting_flux_xyz_faces_sorted,
591 FixedVector<std::vector<ArrOfDouble>,3>& colinearity_flux_xyz_faces_sorted,
592 FixedVector<std::vector<ArrOfDouble>,3>& temperature_flux_xyz_faces_sorted,
593 const bool& ini_index,
594 const int global_indices,
595 const int weighting_colinearity)
596{
597 if (!ini_index)
598 initialise_any_cell_neighbours_indices_to_correct(index_face_ij_flux_xyz_faces_sorted,
599 global_indices);
600
601 int nb_k_layer;
602 if (global_indices)
603 nb_k_layer = ref_ijk_ft_->get_interface().I().get_domaine().get_nb_elem_tot(2);
604 else
605 nb_k_layer = ref_ijk_ft_->get_interface().I().nk();
606
607 const int first_iter = !(ref_ijk_ft_->schema_temps_ijk().get_tstep());
608
609 if (first_iter)
610 {
611 initialise_fixed_vector_values(fluxes, nb_k_layer);
612 if (weighting_colinearity && !ini_index)
613 {
614 initialise_fixed_vector(weighting_flux_xyz_faces_sorted, nb_k_layer);
615 initialise_fixed_vector_values(colinearity_flux_xyz_faces_sorted, nb_k_layer);
617 initialise_fixed_vector_values(temperature_flux_xyz_faces_sorted, nb_k_layer);
618 }
619 }
620
621 int dir;
622 for (dir=0; dir<3; dir++)
623 for (int k_layer=0; k_layer<nb_k_layer+1; k_layer++)
624 {
625 if ((dir==DIRECTION_I || dir==DIRECTION_J) && k_layer==nb_k_layer)
626 break;
627 fluxes[dir][k_layer].reset();
628 if (weighting_colinearity && !ini_index)
629 {
630 weighting_flux_xyz_faces_sorted[dir][k_layer].reset();
631 colinearity_flux_xyz_faces_sorted[dir][k_layer].reset();
632 temperature_flux_xyz_faces_sorted[dir][k_layer].reset();
633 }
634 }
635}
636
638{
640 {
641 /*
642 * Test to correct flux in the diagonal (strongly not aligned with the cartesian grid !)
643 */
645 }
646
648 {
649 const int seq = (Process::nproc() == 1);
650 if (!seq)
651 {
653 {
660 1,
661 1);
662 Cerr << "Thermal Sub-resolutions all reachable convective fluxes variables are now initialised" << finl;
663 flux_init_ = 1;
664 }
666 {
673 1,
674 1);
675 Cerr << "Thermal Sub-resolutions all reachable diffusive fluxes variables are now initialised" << finl;
676 flux_init_ = 1;
677 }
678 flux_init_ = 0;
679 }
680 }
681
683 {
685 {
686 Cerr << "Sort the thermal min-max reachable convective fluxes" << finl;
691 dummy_int_array,
692 dummy_double_array,
693 dummy_double_array,
694 flux_init_);
695 Cerr << "Thermal Sub-resolutions min-max reachable convective fluxes variables are now initialised" << finl;
696 flux_init_ = 1;
697 }
699 {
700 Cerr << "Sort the thermal diffusive min-max reachable fluxes" << finl;
705 dummy_int_array,
706 dummy_double_array,
707 dummy_double_array,
708 flux_init_);
709 Cerr << "Thermal Sub-resolutions min-max reachable diffusive fluxes variables are now initialised" << finl;
710 flux_init_ = 1;
711 }
712 flux_init_ = 0;
713 }
714}
715
716
718{
719 /*
720 * TODO: Works only in sequential
721 */
723 {
724 for (int c=0; c<3; c++)
726 (*cell_faces_neighbours_corrected_bool_).echange_espace_virtuel();
727 const int nb_i_layer = ref_ijk_ft_->get_interface().I().ni();
728 const int nb_j_layer = ref_ijk_ft_->get_interface().I().nj();
729 const int nb_k_layer = ref_ijk_ft_->get_interface().I().nk();
730
731 // index_face_i_sorted[0] = &index_face_i_flux_x_neighbours_diag_faces_sorted_;
732
733 int m,l,n;
734 int index_i_problem, index_j_problem, index_k_problem;
735 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
736 {
737 if (thermal_subproblems_->get_dxyz_increment_bool(i))
738 {
739 thermal_subproblems_->get_subproblem_ijk_indices(index_i_problem, index_j_problem, index_k_problem, i);
740 const FixedVector<int,3>& pure_neighbours_corrected_sign = thermal_subproblems_->get_pure_neighbours_corrected_sign(i);
741 const std::vector<std::vector<std::vector<bool>>>& pure_neighbours_to_correct = thermal_subproblems_->get_pure_neighbours_to_correct(i);
742 const int l_dir_size = (int) pure_neighbours_to_correct.size() -1;
743 const int m_dir_size = (int) pure_neighbours_to_correct[0].size() -1;
744 const int n_dir_size = (int) pure_neighbours_to_correct[0][0].size() -1;
745 for (l=l_dir_size; l>=0; l--)
746 for (m=m_dir_size; m>=0; m--)
747 for (n=n_dir_size; n>=0; n--)
748 if (l <= n_iter_distance && m <= n_iter_distance && n <= n_iter_distance) // Need an underlying normal vector for correction
749 if (pure_neighbours_to_correct[l][m][n] && ((l!=0 && m!=0) || (l!=0 && n!=0) || (m!=0 && n!=0))) // (l!=0 || m!=0 || n!=0) &&
750 {
751 const int i_offset = ((pure_neighbours_corrected_sign[0]) ? l * (-1) : l);
752 const int j_offset = ((pure_neighbours_corrected_sign[1]) ? m * (-1) : m);
753 const int k_offset = ((pure_neighbours_corrected_sign[2]) ? n * (-1) : n);
754 const int index_i_neighbour = index_i_problem + i_offset;
755 const int index_j_neighbour = index_j_problem + j_offset;
756 const int index_k_neighbour = index_k_problem + k_offset;
757 const int i_offset_face = ((signbit(i_offset)) ? (index_i_neighbour + 1) : index_i_neighbour);
758 const int j_offset_face = ((signbit(j_offset)) ? (index_j_neighbour + 1) : index_j_neighbour);
759 const int k_offset_face = ((signbit(k_offset)) ? (index_k_neighbour + 1) : index_k_neighbour);
760 if (l !=0 )
761 {
762 if (!(*cell_faces_neighbours_corrected_bool_)[0](i_offset_face, index_j_neighbour, index_k_neighbour))
763 {
764 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][0][index_k_neighbour].append_array(i_offset_face);
765 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][0][index_k_neighbour].append_array(index_j_neighbour);
766 }
767 (*cell_faces_neighbours_corrected_bool_)[0](i_offset_face, index_j_neighbour, index_k_neighbour) += 1;
768 if (i_offset_face == 0)
769 {
770 if(!(*cell_faces_neighbours_corrected_bool_)[0](nb_i_layer, index_j_neighbour, index_k_neighbour))
771 {
772 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][0][index_k_neighbour].append_array(nb_i_layer);
773 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][0][index_k_neighbour].append_array(index_j_neighbour);
774 }
775 (*cell_faces_neighbours_corrected_bool_)[0](nb_i_layer, index_j_neighbour, index_k_neighbour) += 1;
776 }
777 if (i_offset_face == nb_i_layer)
778 {
779 if (!(*cell_faces_neighbours_corrected_bool_)[0](0, index_j_neighbour, index_k_neighbour))
780 {
781 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][0][index_k_neighbour].append_array(0);
782 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][0][index_k_neighbour].append_array(index_j_neighbour);
783 }
784 (*cell_faces_neighbours_corrected_bool_)[0](0, index_j_neighbour, index_k_neighbour) += 1;
785 }
786 }
787 if (m != 0)
788 {
789 if (!(*cell_faces_neighbours_corrected_bool_)[1](index_i_neighbour, j_offset_face, index_k_neighbour))
790 {
791 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][1][index_k_neighbour].append_array(index_i_neighbour);
792 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][1][index_k_neighbour].append_array(j_offset_face);
793 }
794 (*cell_faces_neighbours_corrected_bool_)[1](index_i_neighbour, j_offset_face, index_k_neighbour) += 1;
795 if (j_offset_face == 0)
796 {
797 if (!(*cell_faces_neighbours_corrected_bool_)[1](index_i_neighbour, nb_j_layer, index_k_neighbour))
798 {
799 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][1][index_k_neighbour].append_array(index_i_neighbour);
800 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][1][index_k_neighbour].append_array(nb_j_layer);
801 }
802 (*cell_faces_neighbours_corrected_bool_)[1](index_i_neighbour, nb_j_layer, index_k_neighbour) += 1;
803 }
804 if (i_offset_face == nb_j_layer)
805 {
806 if (!(*cell_faces_neighbours_corrected_bool_)[1](index_i_neighbour, 0, index_k_neighbour))
807 {
808 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][1][index_k_neighbour].append_array(index_i_neighbour);
809 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][1][index_k_neighbour].append_array(0);
810 }
811 (*cell_faces_neighbours_corrected_bool_)[1](index_i_neighbour, 0, index_k_neighbour) += 1;
812 }
813 }
814 if (n != 0)
815 {
816 if (!(*cell_faces_neighbours_corrected_bool_)[2](index_i_neighbour, index_j_neighbour, k_offset_face))
817 {
818 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][2][k_offset_face].append_array(index_i_neighbour);
819 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][2][k_offset_face].append_array(index_j_neighbour);
820 }
821 (*cell_faces_neighbours_corrected_bool_)[2](index_i_neighbour, index_j_neighbour, k_offset_face) += 1;
822 if (j_offset_face == 0)
823 {
824 if (!(*cell_faces_neighbours_corrected_bool_)[2](index_i_neighbour, index_j_neighbour, nb_k_layer))
825 {
826 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][2][nb_k_layer].append_array(index_i_neighbour);
827 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][2][nb_k_layer].append_array(index_j_neighbour);
828 }
829 (*cell_faces_neighbours_corrected_bool_)[2](index_i_neighbour, index_j_neighbour, nb_k_layer) += 1;
830 }
831 if (i_offset_face == nb_k_layer)
832 {
833 if (!(*cell_faces_neighbours_corrected_bool_)[2](index_i_neighbour, index_j_neighbour, 0))
834 {
835 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[0][2][0].append_array(index_i_neighbour);
836 index_face_ij_flux_xyz_neighbours_diag_faces_sorted_[1][2][0].append_array(index_j_neighbour);
837 }
838 (*cell_faces_neighbours_corrected_bool_)[2](index_i_neighbour, index_j_neighbour, 0) += 1;
839 }
840 }
841 }
842 }
843 }
844 (*cell_faces_neighbours_corrected_bool_).echange_espace_virtuel();
845 }
846}
847
849 Simd_double& b,
850 const int& i,
851 const int& j,
852 const int& k_layer,
853 const int dir)
854{
855 /*
856 * I wanted to use index_face_i_sorted, index_face_j_sorted to avoid reading cell_faces_neighbours_corrected_bool again
857 */
859 {
860 int bool_a, bool_b;
861 bool_a = (*cell_faces_neighbours_corrected_bool_)[dir](i, j, k_layer);
862 bool_a = bool_a || (*cell_faces_neighbours_corrected_bool_)[dir](i, j, k_layer);
863 bool_a = bool_a || (*cell_faces_neighbours_corrected_bool_)[dir](i, j, k_layer);
864 bool_b = (*cell_faces_neighbours_corrected_bool_)[dir](i+1, j, k_layer);
865 bool_b = bool_b || (*cell_faces_neighbours_corrected_bool_)[dir](i, j+1, k_layer);
866 bool_b = bool_b || (*cell_faces_neighbours_corrected_bool_)[dir](i, j, k_layer + 1);
867 if (bool_a || bool_b)
868 {
869 double n;
870 n = abs((*eulerian_normal_vectors_ns_normed_)[dir](i, j, k_layer));
871 a *= n;
872 b *= n;
873 }
874 }
875}
876
877void Corrige_flux_FT_temperature_subresolution::compute_cell_neighbours_mixed_cell_faces_indices_to_correct(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool_mixed_cell,
878 IJK_Field_vector3_double& cell_faces_neighbours_corrected_velocity_temperature,
879 IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective_mixed_cell,
880 IJK_Field_vector3_double& cell_faces_neighbours_corrected_diffusive_mixed_cell,
881 IJK_Field_vector3_double& neighbours_weighting_colinearity_mixed_cell)
882{
883
885 {
886
887 const int ni = ref_ijk_ft_->get_interface().I().ni();
888 const int nj = ref_ijk_ft_->get_interface().I().nj();
889 const int nk = ref_ijk_ft_->get_interface().I().nk();
890
891 IJK_Field_local_int cell_faces_neighbours_corrected_bool_tmp;
892 cell_faces_neighbours_corrected_bool_tmp.allocate(ni, nj, nk, 1);
893
894
895 for (int c=0; c<3; c++)
896 {
897 const int index_ini = 2*c;
898 cell_faces_neighbours_corrected_bool_tmp.data() = 0;
899 for (int k = 0; k < nk; k++)
900 for (int j = 0; j < nj; j++)
901 for (int i = 0; i < ni; i++)
902 {
903 const double indic = ref_ijk_ft_->get_interface().I()(i,j,k);
904 if (indic < LIQUID_INDICATOR_TEST && indic > VAPOUR_INDICATOR_TEST)
905 {
906 for (int l=index_ini; l<index_ini + 2; l++)
907 {
908 const int i_neighbour = NEIGHBOURS_I[l];
909 const int j_neighbour = NEIGHBOURS_J[l];
910 const int k_neighbour = NEIGHBOURS_K[l];
911 const int ii = NEIGHBOURS_FACES_I[l];
912 const int jj = NEIGHBOURS_FACES_J[l];
913 const int kk = NEIGHBOURS_FACES_K[l];
914 const int cell_faces_neighbours_ijk = cell_faces_neighbours_corrected_bool_mixed_cell[c](i + ii,j + jj, k + kk);
915 const double indic_neighbour = ref_ijk_ft_->get_interface().I()(i+i_neighbour,j+j_neighbour,k+k_neighbour);
916 if (cell_faces_neighbours_ijk && indic_neighbour > LIQUID_INDICATOR_TEST)
917 cell_faces_neighbours_corrected_bool_tmp(i+ii,j+jj,k+kk) = cell_faces_neighbours_ijk;
918 }
919 }
920 if (indic > LIQUID_INDICATOR_TEST)
921 {
922 for (int l=index_ini; l<index_ini + 2; l++)
923 {
924 const int i_neighbour = NEIGHBOURS_I[l];
925 const int j_neighbour = NEIGHBOURS_J[l];
926 const int k_neighbour = NEIGHBOURS_K[l];
927 const int ii = NEIGHBOURS_FACES_I[l];
928 const int jj = NEIGHBOURS_FACES_J[l];
929 const int kk = NEIGHBOURS_FACES_K[l];
930 const int cell_faces_neighbours_ijk = cell_faces_neighbours_corrected_bool_mixed_cell[c](i + ii,j + jj, k + kk);
931 const double indic_neighbour = ref_ijk_ft_->get_interface().I()(i+i_neighbour,j+j_neighbour,k+k_neighbour);
932 if (cell_faces_neighbours_ijk && (indic_neighbour < LIQUID_INDICATOR_TEST && indic_neighbour > VAPOUR_INDICATOR_TEST))
933 cell_faces_neighbours_corrected_bool_tmp(i+ii,j+jj,k+kk) = cell_faces_neighbours_ijk;
934 }
935 }
936 }
937 for (int k = 0; k < nk; k++)
938 for (int j = 0; j < nj; j++)
939 for (int i = 0; i < ni; i++)
940 cell_faces_neighbours_corrected_bool_mixed_cell[c](i,j,k) = cell_faces_neighbours_corrected_bool_tmp(i,j,k);
941 }
942 // cell_faces_neighbours_corrected_bool_tmp.~IJK_Field_local_int();
944 {
945 IJK_Field_local_double cell_faces_neighbours_corrected_field_tmp;
947 {
948 cell_faces_neighbours_corrected_field_tmp.allocate(ni, nj, nk, 0);
949 cell_faces_neighbours_corrected_bool_mixed_cell.echange_espace_virtuel(); // Important
950 }
951
953 {
954 compute_cell_neighbours_mixed_cell_faces_any_field(cell_faces_neighbours_corrected_bool_mixed_cell,
955 cell_faces_neighbours_corrected_field_tmp,
956 cell_faces_neighbours_corrected_convective_mixed_cell);
958 compute_cell_neighbours_mixed_cell_faces_any_field(cell_faces_neighbours_corrected_bool_mixed_cell,
959 cell_faces_neighbours_corrected_field_tmp,
960 cell_faces_neighbours_corrected_velocity_temperature);
961
962 }
963
965 compute_cell_neighbours_mixed_cell_faces_any_field(cell_faces_neighbours_corrected_bool_mixed_cell,
966 cell_faces_neighbours_corrected_field_tmp,
967 cell_faces_neighbours_corrected_diffusive_mixed_cell);
968
970 compute_cell_neighbours_mixed_cell_faces_any_field(cell_faces_neighbours_corrected_bool_mixed_cell,
971 cell_faces_neighbours_corrected_field_tmp,
972 neighbours_weighting_colinearity_mixed_cell);
973 }
974 }
975}
976
977void Corrige_flux_FT_temperature_subresolution::compute_cell_neighbours_mixed_cell_faces_any_field(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool,
978 IJK_Field_local_double& cell_faces_neighbours_corrected_field,
979 IJK_Field_vector3_double& cell_faces_neighbours_corrected_field_mixed_cell)
980{
981 const int ni = cell_faces_neighbours_corrected_field_mixed_cell[0].ni();
982 const int nj = cell_faces_neighbours_corrected_field_mixed_cell[1].nj();
983 const int nk = cell_faces_neighbours_corrected_field_mixed_cell[2].nk();
984
985 for (int c=0; c<3; c++)
986 {
987 cell_faces_neighbours_corrected_field.data() = 0;
988 for (int k = 0; k < nk; k++)
989 for (int j = 0; j < nj; j++)
990 for (int i = 0; i < ni; i++)
991 if (cell_faces_neighbours_corrected_bool[c](i,j,k))
992 cell_faces_neighbours_corrected_field(i,j,k) = cell_faces_neighbours_corrected_field_mixed_cell[c](i,j,k);
993 cell_faces_neighbours_corrected_field_mixed_cell[c].data() = 0.;
994 for (int k = 0; k < nk; k++)
995 for (int j = 0; j < nj; j++)
996 for (int i = 0; i < ni; i++)
997 cell_faces_neighbours_corrected_field_mixed_cell[c](i,j,k) = cell_faces_neighbours_corrected_field(i,j,k);
998
999 }
1000 cell_faces_neighbours_corrected_field_mixed_cell.echange_espace_virtuel();
1001}
1002
1003void Corrige_flux_FT_temperature_subresolution::compute_cell_neighbours_faces_indices_to_correct(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool,
1004 IJK_Field_vector3_double& cell_faces_neighbours_corrected_velocity_temperature,
1005 IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective,
1006 IJK_Field_vector3_double& cell_faces_neighbours_corrected_diffusive,
1007 IJK_Field_vector3_double& neighbours_weighting_colinearity)
1008{
1010 {
1011 for (int c=0; c<3; c++)
1012 cell_faces_neighbours_corrected_bool[c].data() = 0;
1013 cell_faces_neighbours_corrected_bool.echange_espace_virtuel();
1014
1016 {
1017 for (int c=0; c<3; c++)
1018 neighbours_weighting_colinearity[c].data() = 0;
1019 neighbours_weighting_colinearity.echange_espace_virtuel();
1020 }
1021
1023 {
1024 for (int c=0; c<3; c++)
1025 cell_faces_neighbours_corrected_convective[c].data() = 0;
1026 cell_faces_neighbours_corrected_convective.echange_espace_virtuel();
1028 {
1029 for (int c=0; c<3; c++)
1030 cell_faces_neighbours_corrected_velocity_temperature[c].data() = 0;
1031 cell_faces_neighbours_corrected_velocity_temperature.echange_espace_virtuel();
1032 }
1033 }
1034
1036 {
1037 for (int c=0; c<3; c++)
1038 cell_faces_neighbours_corrected_diffusive[c].data() = 0;
1039 cell_faces_neighbours_corrected_diffusive.echange_espace_virtuel();
1040 }
1041
1042 const int seq = (Process::nproc() == 1);
1043
1044 const int nb_i_layer = cell_faces_neighbours_corrected_bool[0].ni();
1045 const int nb_j_layer = cell_faces_neighbours_corrected_bool[0].nj();
1046 const int nb_k_layer = cell_faces_neighbours_corrected_bool[0].nk();
1047
1048 const Domaine_IJK& dom_ns = ref_ijk_ft_->get_interface().I().get_domaine();
1049 const int offset_i = dom_ns.get_offset_local(0);
1050 const int offset_j = dom_ns.get_offset_local(1);
1051 const int offset_k = dom_ns.get_offset_local(2);
1052
1053 const int nb_i_layer_tot = dom_ns.get_nb_elem_tot(0);
1054 const int nb_j_layer_tot = dom_ns.get_nb_elem_tot(1);
1055 const int nb_k_layer_tot = dom_ns.get_nb_elem_tot(2);
1056
1057 int m,l,n;
1058 int index_i_problem, index_j_problem, index_k_problem;
1059 int index_i_neighbour, index_j_neighbour, index_k_neighbour;
1060 int index_i_procs, index_j_procs, index_k_procs;
1061 int index_i_neighbour_global, index_j_neighbour_global, index_k_neighbour_global;
1062 int l_dir, m_dir, n_dir;
1063 double distance, colinearity, convective_flux, diffusive_flux;
1064 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
1065 {
1066 if (thermal_subproblems_->get_dxyz_over_two_increment_bool(i))
1067 {
1068 thermal_subproblems_->get_subproblem_ijk_indices(index_i_problem, index_j_problem, index_k_problem, i);
1069 const FixedVector<int,3>& pure_neighbours_corrected_sign = thermal_subproblems_->get_pure_neighbours_corrected_sign(i);
1070 const std::vector<std::vector<std::vector<std::vector<bool>>>>& pure_neighbours_to_correct = thermal_subproblems_->get_pure_neighbours_last_faces_to_correct(i);
1071 const std::vector<std::vector<std::vector<std::vector<double>>>>& pure_neighbours_distance_to_correct = thermal_subproblems_->get_pure_neighbours_last_faces_corrected_distance(i);
1072 const std::vector<std::vector<std::vector<std::vector<double>>>>& pure_neighbours_colinearity_to_correct = thermal_subproblems_->get_pure_neighbours_last_faces_corrected_colinearity(i);
1073 for (int c=0; c<3; c++)
1074 {
1075 const int l_dir_size = (int) pure_neighbours_to_correct[c].size() -1;
1076 const int m_dir_size = (int) pure_neighbours_to_correct[c][0].size() -1;
1077 const int n_dir_size = (int) pure_neighbours_to_correct[c][0][0].size() -1;
1078 for (l=l_dir_size; l>=0; l--)
1079 for (m=m_dir_size; m>=0; m--)
1080 for (n=n_dir_size; n>=0; n--)
1081 if (pure_neighbours_to_correct[c][l][m][n])
1082 {
1083 switch(c)
1084 {
1085 case 0:
1086 // l_dir = (pure_neighbours_corrected_sign[0]) ? l * (-1) : l + 1;
1087 l_dir = (pure_neighbours_corrected_sign[0]) ? l * (-1) + 1 : l;
1088 m_dir = (pure_neighbours_corrected_sign[1]) ? m * (-1) : m;
1089 n_dir = (pure_neighbours_corrected_sign[2]) ? n * (-1) : n;
1090 break;
1091 case 1:
1092 l_dir = (pure_neighbours_corrected_sign[0]) ? l * (-1) : l;
1093 m_dir = (pure_neighbours_corrected_sign[1]) ? m * (-1) + 1 : m;
1094 n_dir = (pure_neighbours_corrected_sign[2]) ? n * (-1) : n;
1095 break;
1096 case 2:
1097 l_dir = (pure_neighbours_corrected_sign[0]) ? l * (-1) : l;
1098 m_dir = (pure_neighbours_corrected_sign[1]) ? m * (-1) : m;
1099 n_dir = (pure_neighbours_corrected_sign[2]) ? n * (-1) + 1 : n;
1100 break;
1101 default:
1102 l_dir = (pure_neighbours_corrected_sign[0]) ? l * (-1) + 1 : l;
1103 m_dir = (pure_neighbours_corrected_sign[1]) ? m * (-1) : m;
1104 n_dir = (pure_neighbours_corrected_sign[2]) ? n * (-1) : n;
1105 break;
1106 }
1107 /*
1108 * TODO: Handle the periodicity and check if it works
1109 */
1110 index_i_neighbour = (index_i_problem + l_dir);
1111 index_j_neighbour = (index_j_problem + m_dir);
1112 index_k_neighbour = (index_k_problem + n_dir);
1113 index_i_neighbour_global = compute_periodic_index((index_i_neighbour + offset_i), nb_i_layer_tot);
1114 index_j_neighbour_global = compute_periodic_index((index_j_neighbour + offset_j), nb_j_layer_tot);
1115 index_k_neighbour_global = compute_periodic_index((index_k_neighbour + offset_k), nb_k_layer_tot);
1116 index_i_procs = compute_periodic_index(index_i_neighbour, nb_i_layer);
1117 index_j_procs = compute_periodic_index(index_j_neighbour, nb_j_layer);
1118 index_k_procs = compute_periodic_index(index_k_neighbour, nb_k_layer);
1119 colinearity = 1.;
1120 distance = pure_neighbours_distance_to_correct[c][l][m][n];
1122 colinearity = pure_neighbours_colinearity_to_correct[c][l][m][n];
1123 if ((index_i_procs == index_i_neighbour
1124 && index_j_procs == index_j_neighbour
1125 && index_k_procs == index_k_neighbour)
1126 || seq)
1127 // && (index_i_neighbour > 0 && index_j_neighbour > 0 && index_k_neighbour > 0)) // Is it right ? Not needed if echange espace virtuel later ?
1128 // || seq)
1129 {
1130 // cell_faces_neighbours_corrected_bool[c](index_i_procs, index_j_procs, index_k_procs) += 1;
1131 compute_cell_neighbours_fluxes_to_correct(cell_faces_neighbours_corrected_bool,
1132 neighbours_weighting_colinearity,
1133 cell_faces_neighbours_corrected_convective,
1134 cell_faces_neighbours_corrected_diffusive,
1135 cell_faces_neighbours_corrected_velocity_temperature,
1136 i,
1137 index_i_procs,
1138 index_j_procs,
1139 index_k_procs,
1140 distance,
1141 c,
1142 colinearity,
1144 convective_flux,
1145 diffusive_flux);
1146 }
1147 else
1148 {
1149 compute_flux_neighbours_on_procs(index_i_neighbour_global,
1150 index_j_neighbour_global,
1151 index_k_neighbour_global,
1152 i,
1153 distance,
1154 c,
1155 colinearity,
1156 index_i_neighbour,
1157 index_j_neighbour,
1158 index_k_neighbour);
1159 }
1160 }
1161 }
1162 }
1163 }
1165 if (debug_)
1166 Cerr << "Fluxes have been received from procs" << finl;
1167
1168 combine_all_fluxes_from_outisde_frontier_on_procs(cell_faces_neighbours_corrected_bool,
1169 cell_faces_neighbours_corrected_velocity_temperature,
1170 cell_faces_neighbours_corrected_convective,
1171 cell_faces_neighbours_corrected_diffusive,
1172 neighbours_weighting_colinearity);
1173 if (debug_)
1174 Cerr << "Fluxes have been combined on procs" << finl;
1175
1176
1177 complete_neighbours_and_weighting_colinearity(cell_faces_neighbours_corrected_bool,
1178 cell_faces_neighbours_corrected_velocity_temperature,
1179 cell_faces_neighbours_corrected_convective,
1180 cell_faces_neighbours_corrected_diffusive,
1181 neighbours_weighting_colinearity,
1183 if (debug_)
1184 Cerr << "Weighted calculation of all fluxes has been performed" << finl;
1185
1186
1187 compute_cell_neighbours_mixed_cell_faces_indices_to_correct(cell_faces_neighbours_corrected_bool,
1188 cell_faces_neighbours_corrected_velocity_temperature,
1189 cell_faces_neighbours_corrected_convective,
1190 cell_faces_neighbours_corrected_diffusive,
1191 neighbours_weighting_colinearity);
1192 if (debug_)
1193 Cerr << "Only the fluxes in the immediate interface vicinity have been eventually kept" << finl;
1194 }
1195}
1196
1197
1199 const int& index_j_neighbour_global,
1200 const int& index_k_neighbour_global,
1201 const int& subproblem_index,
1202 const double& dist,
1203 const int& dir,
1204 const double& colinearity,
1205 const int& index_i,
1206 const int& index_j,
1207 const int& index_k,
1208 const double& convective_flux_computed,
1209 const double& diffusive_flux_computed)
1210{
1211 double convective_flux = convective_flux_computed;
1212 double diffusive_flux = diffusive_flux_computed;
1213 double temperature = 0.;
1215 {
1217 {
1219 subproblem_index,
1220 dist,
1221 dir,
1222 colinearity,
1223 index_i,
1224 index_j,
1225 index_k);
1227 {
1228
1230 subproblem_index,
1231 dist,
1232 dir,
1233 colinearity,
1234 index_i,
1235 index_j,
1236 index_k,
1237 1);
1238 }
1239 }
1242 subproblem_index,
1243 dist,
1244 dir,
1245 colinearity,
1246 index_i,
1247 index_j,
1248 index_k);
1249 }
1250
1251 const int linear_index_global = get_linear_index_global(index_i_neighbour_global,
1252 index_j_neighbour_global,
1253 index_k_neighbour_global,
1254 dir);
1255 const int count_val = (int) flux_outside_frontier_all_map_[dir].count(linear_index_global);
1256
1257 if (!count_val)
1258 {
1259 const int size_array = (int) index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][dir][index_k_neighbour_global].size_array();
1260 flux_outside_frontier_all_map_[dir][linear_index_global] = size_array;
1261 index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][dir][index_k_neighbour_global].append_array(index_i_neighbour_global);
1262 index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[1][dir][index_k_neighbour_global].append_array(index_j_neighbour_global);
1263 weighting_flux_xyz_neighbours_all_faces_remaining_global_sorted_[dir][index_k_neighbour_global].append_array(1);
1265 {
1267 colinearity_flux_xyz_neighbours_all_faces_remaining_global_sorted_[dir][index_k_neighbour_global].append_array(colinearity);
1269 {
1270 convective_diffusive_flux_all_faces_remaining_global_sorted_[0][dir][index_k_neighbour_global].append_array(convective_flux);
1272 temperature_flux_all_faces_remaining_global_sorted_[dir][index_k_neighbour_global].append_array(temperature);
1273 }
1275 convective_diffusive_flux_all_faces_remaining_global_sorted_[1][dir][index_k_neighbour_global].append_array(diffusive_flux);
1276 }
1277 }
1278 else
1279 {
1280 const int index_array = flux_outside_frontier_all_map_[dir][linear_index_global];
1281 weighting_flux_xyz_neighbours_all_faces_remaining_global_sorted_[dir][index_k_neighbour_global](index_array) += 1;
1283 {
1285 colinearity_flux_xyz_neighbours_all_faces_remaining_global_sorted_[dir][index_k_neighbour_global](index_array) += colinearity;
1287 {
1288 convective_diffusive_flux_all_faces_remaining_global_sorted_[0][dir][index_k_neighbour_global](index_array) += convective_flux;
1290 temperature_flux_all_faces_remaining_global_sorted_[dir][index_k_neighbour_global](index_array) += temperature;
1291 }
1293 convective_diffusive_flux_all_faces_remaining_global_sorted_[1][dir][index_k_neighbour_global](index_array) += diffusive_flux;
1294 }
1295 }
1296}
1297
1298
1300{
1301 const int nb_procs = Process::nproc();
1302 const int proc_num = Process::me();
1304 {
1305 if (nb_procs > 1)
1306 {
1307 for (int c=0; c<3; c++)
1308 {
1309 const int size_k_layers = (int) index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][c].size();
1310 for (int k=0; k<size_k_layers; k++)
1311 {
1312 const int size_array = index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][c][k].size_array();
1313 int size_array_global = size_array;
1314 size_array_global = Process::check_int_overflow(Process::mp_sum(size_array_global));
1315 ArrOfInt overall_numerotation(nb_procs);
1316 ArrOfInt start_indices(nb_procs);
1317 overall_numerotation(proc_num) = size_array;
1318 mp_sum_for_each_item(overall_numerotation);
1319 int l;
1320 for (l=1; l<overall_numerotation.size_array(); l++)
1321 start_indices(l) = start_indices(l-1) + overall_numerotation(l-1);
1322
1323 if (debug_)
1324 {
1325 Cerr << "Size array" << size_array << finl;
1326 Cerr << "Size array global" << size_array_global << finl;
1327 Cerr << "Overall_numerotation" << overall_numerotation(0) << "-" << overall_numerotation(1) << finl;
1328 }
1329
1330 ArrOfInt local_indices_i_tmp;
1331 ArrOfInt local_indices_j_tmp;
1332 ArrOfInt local_weighting_tmp;
1333
1334 ArrOfInt& global_indices_i_tmp = index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][c][k];
1335 ArrOfInt& global_indices_j_tmp = index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[1][c][k];
1336 ArrOfInt& global_weighting_tmp = weighting_flux_xyz_neighbours_all_faces_remaining_global_sorted_[c][k];
1337
1338 local_indices_i_tmp = global_indices_i_tmp;
1339 local_indices_j_tmp = global_indices_j_tmp;
1340 local_weighting_tmp = global_weighting_tmp;
1341
1342 global_indices_i_tmp.resize(size_array_global);
1343 global_indices_j_tmp.resize(size_array_global);
1344 global_weighting_tmp.resize(size_array_global);
1345
1346 global_indices_i_tmp *= 0;
1347 global_indices_j_tmp *= 0;
1348 global_weighting_tmp *= 0;
1349
1350 for (l=0; l<local_indices_i_tmp.size_array(); l++)
1351 {
1352 global_indices_i_tmp(start_indices(proc_num) + l) = local_indices_i_tmp(l);
1353 global_indices_j_tmp(start_indices(proc_num) + l) = local_indices_j_tmp(l);
1354 global_weighting_tmp(start_indices(proc_num) + l) = local_weighting_tmp(l);
1355 }
1356
1357 mp_sum_for_each_item(global_indices_i_tmp);
1358 mp_sum_for_each_item(global_indices_j_tmp);
1359 mp_sum_for_each_item(global_weighting_tmp);
1360
1362 {
1364 {
1365 ArrOfDouble local_colinearity_tmp;
1366 ArrOfDouble& global_colinearity_tmp = colinearity_flux_xyz_neighbours_all_faces_remaining_global_sorted_[c][k];
1367 local_colinearity_tmp = global_colinearity_tmp;
1368 global_colinearity_tmp.resize(size_array_global);
1369 global_colinearity_tmp *= 0.;
1370 for (l=0; l<local_indices_i_tmp.size_array(); l++)
1371 global_colinearity_tmp(start_indices(proc_num) + l) = local_colinearity_tmp(l);
1372 mp_sum_for_each_item(global_colinearity_tmp);
1373 }
1374
1375
1377 {
1378 ArrOfDouble local_convective_flux_values_tmp;
1379 ArrOfDouble& global_convective_flux_values_tmp = convective_diffusive_flux_all_faces_remaining_global_sorted_[0][c][k];
1380 local_convective_flux_values_tmp = global_convective_flux_values_tmp;
1381 global_convective_flux_values_tmp.resize(size_array_global);
1382 global_convective_flux_values_tmp *= 0.;
1383 for (l=0; l<local_indices_i_tmp.size_array(); l++)
1384 global_convective_flux_values_tmp(start_indices(proc_num) + l) = local_convective_flux_values_tmp(l);
1385 mp_sum_for_each_item(global_convective_flux_values_tmp);
1386
1388 {
1389 ArrOfDouble local_temperature_flux_values_tmp;
1390 ArrOfDouble& global_temperature_flux_values_tmp = temperature_flux_all_faces_remaining_global_sorted_[c][k];
1391 local_temperature_flux_values_tmp = global_temperature_flux_values_tmp;
1392 global_temperature_flux_values_tmp.resize(size_array_global);
1393 global_temperature_flux_values_tmp *= 0.;
1394 for (l=0; l<local_indices_i_tmp.size_array(); l++)
1395 global_temperature_flux_values_tmp(start_indices(proc_num) + l) = local_temperature_flux_values_tmp(l);
1396 mp_sum_for_each_item(global_temperature_flux_values_tmp);
1397 }
1398
1399
1400 }
1401
1403 {
1404 ArrOfDouble local_diffusive_flux_values_tmp;
1405 ArrOfDouble& global_diffusive_flux_values_tmp = convective_diffusive_flux_all_faces_remaining_global_sorted_[1][c][k];
1406 local_diffusive_flux_values_tmp = global_diffusive_flux_values_tmp;
1407 global_diffusive_flux_values_tmp.resize(size_array_global);
1408 global_diffusive_flux_values_tmp *= 0.;
1409 for (l=0; l<local_indices_i_tmp.size_array(); l++)
1410 global_diffusive_flux_values_tmp(start_indices(proc_num) + l) = local_diffusive_flux_values_tmp(l);
1411 mp_sum_for_each_item(global_diffusive_flux_values_tmp);
1412 }
1413 }
1414 }
1415 }
1416 }
1417 }
1418}
1419
1420void Corrige_flux_FT_temperature_subresolution::combine_all_fluxes_from_outisde_frontier_on_procs(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool,
1421 IJK_Field_vector3_double& cell_faces_neighbours_corrected_velocity_temperature,
1422 IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective,
1423 IJK_Field_vector3_double& cell_faces_neighbours_corrected_diffusive,
1424 IJK_Field_vector3_double& neighbours_weighting_colinearity)
1425{
1426 const IJK_Field_double& indicator = ref_ijk_ft_->get_interface().I();
1427 const int ni = indicator.ni();
1428 const int nj = indicator.nj();
1429 const int nk = indicator.nk();
1430
1431 const Domaine_IJK& dom_ns = ref_ijk_ft_->get_interface().I().get_domaine();
1432 const int offset_i = dom_ns.get_offset_local(0);
1433 const int offset_j = dom_ns.get_offset_local(1);
1434 const int offset_k = dom_ns.get_offset_local(2);
1435
1436 double convective_flux = 0.;
1437 double diffusive_flux = 0.;
1438 double colinearity = 0.;
1439 double temperature = 0.;
1440 for (int dir=0; dir<3; dir++)
1441 {
1442 const int size_k_layers = (int) index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][dir].size();
1443 for (int k_global=0; k_global<size_k_layers; k_global++)
1444 {
1445 const int global_size_array = index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][dir][k_global].size_array();
1446 for (int l=0; l<global_size_array; l++)
1447 {
1448 const int i_global = index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[0][dir][k_global](l);
1449 const int j_global = index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_[1][dir][k_global](l);
1451 {
1453 {
1454 convective_flux = convective_diffusive_flux_all_faces_remaining_global_sorted_[0][dir][k_global](l);
1456 temperature = temperature_flux_all_faces_remaining_global_sorted_[dir][k_global](l);
1457 }
1459 diffusive_flux = convective_diffusive_flux_all_faces_remaining_global_sorted_[1][dir][k_global](l);
1462 }
1463 const int local_weighting = weighting_flux_xyz_neighbours_all_faces_remaining_global_sorted_[dir][k_global](l);
1464 const int i = i_global - offset_i;
1465 const int j = j_global - offset_j;
1466 const int k = k_global - offset_k;
1467 if ((0 <= i && i < ni) && (0 <= j && j < nj) && (0 <= k && k < nk))
1468 {
1470 {
1471 // if (convective_flux_correction_)
1472 // cell_faces_neighbours_corrected_convective[dir](i,j,k) += convective_flux;
1473 // if (diffusive_flux_correction_)
1474 // cell_faces_neighbours_corrected_diffusive[dir](i,j,k) += diffusive_flux;
1476 {
1477 get_add_replace_flux_value(cell_faces_neighbours_corrected_convective, dir, i, j, k, convective_flux, colinearity);
1479 get_add_replace_flux_value(cell_faces_neighbours_corrected_velocity_temperature, dir, i, j, k, temperature, colinearity);
1480 }
1482 get_add_replace_flux_value(cell_faces_neighbours_corrected_diffusive, dir, i, j, k, diffusive_flux, colinearity);
1484 neighbours_weighting_colinearity[dir](i,j,k) += colinearity;
1485 }
1486 cell_faces_neighbours_corrected_bool[dir](i,j,k) += local_weighting;
1487 }
1488 }
1489 }
1490 }
1491}
1492
1493bool Corrige_flux_FT_temperature_subresolution::identify_wrong_predicted_values(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool,
1494 IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective_diffusive_flux,
1495 const int& dir,
1496 const int& index_i,
1497 const int& index_j,
1498 const int& index_k,
1499 double& convective_diffusive_flux)
1500{
1501 // const int nb_contrib = cell_faces_neighbours_corrected_bool[dir](index_i, index_j, index_k);
1502 // if (abs(convective_diffusive_flux) > MAX_FLUX_VAL)
1503 // return false;
1504 // else if (nb_contrib > 0)
1505 // {
1506 // double tmp_avg = cell_faces_neighbours_corrected_convective_diffusive_flux[dir](index_i, index_j, index_k);
1507 // tmp_avg /= nb_contrib;
1508 // if (abs(convective_diffusive_flux) > abs(tmp_avg) * MAX_FLUX_DIFF)
1509 // return false;
1510 // else
1511 // return true;
1512 // }
1513 // else
1514 // return true;
1515 return true;
1516}
1517
1518void Corrige_flux_FT_temperature_subresolution::get_add_replace_flux_value(IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective_diffusive_flux,
1519 const int& dir,
1520 const int& i,
1521 const int& j,
1522 const int& k,
1523 double& convective_diffusive_flux,
1524 const double& replace_weighting_values)
1525{
1527 {
1528 const double current_flux_value = cell_faces_neighbours_corrected_convective_diffusive_flux[dir](i,j,k);
1529 const int sign_flux = signbit(convective_diffusive_flux);
1530 convective_diffusive_flux = std::max(abs(convective_diffusive_flux), abs(current_flux_value));
1531 convective_diffusive_flux = sign_flux ? -convective_diffusive_flux: convective_diffusive_flux;
1532 cell_faces_neighbours_corrected_convective_diffusive_flux[dir](i,j,k) = convective_diffusive_flux;
1533 // if (neighbours_colinearity_weighting_)
1534 }
1535 else
1536 cell_faces_neighbours_corrected_convective_diffusive_flux[dir](i,j,k) += convective_diffusive_flux;
1537}
1538
1539void Corrige_flux_FT_temperature_subresolution::complete_neighbours_and_weighting_colinearity(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool,
1540 IJK_Field_vector3_double& cell_faces_neighbours_corrected_velocity_temperature,
1541 IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective,
1542 IJK_Field_vector3_double& cell_faces_neighbours_corrected_diffusive,
1543 IJK_Field_vector3_double& neighbours_weighting_colinearity,
1544 const int& compute_fluxes_values)
1545{
1546 cell_faces_neighbours_corrected_bool.echange_espace_virtuel();
1547 if (compute_fluxes_values)
1548 {
1549 // if (convective_flux_correction_)
1550 // cell_faces_neighbours_corrected_convective.echange_espace_virtuel();
1551 // if (diffusive_flux_correction_)
1552 // cell_faces_neighbours_corrected_diffusive.echange_espace_virtuel();
1553 // if (neighbours_colinearity_weighting_)
1554 // neighbours_weighting_colinearity.echange_espace_virtuel();
1555 const int ni = cell_faces_neighbours_corrected_bool[0].ni();
1556 const int nj = cell_faces_neighbours_corrected_bool[0].nj();
1557 const int nk = cell_faces_neighbours_corrected_bool[0].nk();
1559 {
1560 for (int k = 0; k < nk; k++)
1561 for (int j = 0; j < nj; j++)
1562 for (int i = 0; i < ni; i++)
1563 for (int c=0; c<3; c++)
1564 if(cell_faces_neighbours_corrected_bool[c](i,j,k))
1565 {
1567 {
1568 const double colinearity = neighbours_weighting_colinearity[c](i,j,k);
1569 if (colinearity > 1e-12)
1570 {
1572 {
1573 cell_faces_neighbours_corrected_convective[c](i,j,k) /= colinearity;
1575 cell_faces_neighbours_corrected_velocity_temperature[c](i,j,k) /= colinearity;
1576 }
1578 cell_faces_neighbours_corrected_diffusive[c](i,j,k) /= colinearity;
1579 }
1580 }
1581 else
1582 {
1583 const double weighting = (double) (cell_faces_neighbours_corrected_bool[c](i,j,k));
1585 {
1586 cell_faces_neighbours_corrected_convective[c](i,j,k) /= weighting;
1588 cell_faces_neighbours_corrected_velocity_temperature[c](i,j,k) /= weighting;
1589 }
1591 cell_faces_neighbours_corrected_diffusive[c](i,j,k) /= weighting;
1592 }
1593 }
1594 }
1596 {
1597 cell_faces_neighbours_corrected_convective.echange_espace_virtuel();
1599 cell_faces_neighbours_corrected_velocity_temperature.echange_espace_virtuel();
1600 }
1602 cell_faces_neighbours_corrected_diffusive.echange_espace_virtuel();
1604 neighbours_weighting_colinearity.echange_espace_virtuel();
1605 }
1606}
1607
1608void Corrige_flux_FT_temperature_subresolution::compute_cell_neighbours_fluxes_to_correct(IJK_Field_vector3_int& cell_faces_neighbours_corrected_bool,
1609 IJK_Field_vector3_double& neighbours_weighting_colinearity,
1610 IJK_Field_vector3_double& cell_faces_neighbours_corrected_convective,
1611 IJK_Field_vector3_double& cell_faces_neighbours_corrected_diffusive,
1612 IJK_Field_vector3_double& cell_faces_neighbours_corrected_velocity_temperature,
1613 const int& subproblem_index,
1614 const int& index_i, const int& index_j, const int& index_k,
1615 const double& dist,
1616 const int& dir,
1617 const double& colinearity,
1618 const int& compute_fluxes_values,
1619 double& convective_flux,
1620 double& diffusive_flux)
1621{
1622 bool valid_flux_value = true;
1623 if (compute_fluxes_values)
1624 {
1626 {
1627// compute_cell_neighbours_convective_fluxes_to_correct(cell_faces_neighbours_corrected_convective);
1628 valid_flux_value = compute_cell_neighbours_convective_fluxes_to_correct(convective_flux,
1629 subproblem_index,
1630 dist,
1631 dir,
1632 colinearity,
1633 index_i,
1634 index_j,
1635 index_k);
1636 valid_flux_value = identify_wrong_predicted_values(cell_faces_neighbours_corrected_bool,
1637 cell_faces_neighbours_corrected_convective,
1638 dir,
1639 index_i,
1640 index_j,
1641 index_k,
1642 convective_flux);
1643 if (valid_flux_value)
1644 get_add_replace_flux_value(cell_faces_neighbours_corrected_convective, dir, index_i, index_j, index_k, convective_flux, colinearity);
1645 if (store_flux_operators_for_energy_balance_ && valid_flux_value)
1646 {
1647 double temperature = 0.;
1649 subproblem_index,
1650 dist,
1651 dir,
1652 colinearity,
1653 index_i,
1654 index_j,
1655 index_k,
1656 1);
1657 get_add_replace_flux_value(cell_faces_neighbours_corrected_velocity_temperature, dir, index_i, index_j, index_k, temperature, colinearity);
1658 }
1659 }
1660 if (diffusive_flux_correction_ && valid_flux_value)
1661 {
1662 valid_flux_value = compute_cell_neighbours_diffusive_fluxes_to_correct(diffusive_flux,
1663 subproblem_index,
1664 dist,
1665 dir,
1666 colinearity,
1667 index_i,
1668 index_j,
1669 index_k);
1670 valid_flux_value = identify_wrong_predicted_values(cell_faces_neighbours_corrected_bool,
1671 cell_faces_neighbours_corrected_convective,
1672 dir,
1673 index_i,
1674 index_j,
1675 index_k,
1676 diffusive_flux);
1677 if (valid_flux_value)
1678 get_add_replace_flux_value(cell_faces_neighbours_corrected_diffusive, dir, index_i, index_j, index_k, diffusive_flux, colinearity);
1679 }
1680 }
1681 if (valid_flux_value)
1682 {
1683 cell_faces_neighbours_corrected_bool[dir](index_i, index_j, index_k) += 1;
1685 neighbours_weighting_colinearity[dir](index_i, index_j, index_k) += colinearity;
1686 }
1687}
1688
1690 const int& subproblem_index,
1691 const double& dist,
1692 const int& dir,
1693 const double& colinearity,
1694 const int& index_i,
1695 const int& index_j,
1696 const int& index_k,
1697 const int& temperature)
1698{
1699 if (!discrete_integral_ || temperature)
1701 subproblem_index,
1702 dist,
1703 dir,
1704 colinearity,
1705 index_i,
1706 index_j,
1707 index_k,
1708 temperature);
1709 else
1710 {
1712 subproblem_index,
1713 dist,
1714 dir,
1715 colinearity,
1716 index_i,
1717 index_j,
1718 index_k);
1719 return true;
1720 }
1721}
1722
1724 const int& subproblem_index,
1725 const double& dist,
1726 const int& dir,
1727 const double& colinearity,
1728 const int& index_i,
1729 const int& index_j,
1730 const int& index_k,
1731 const int& temperature)
1732{
1734 subproblem_index,
1735 dist,
1736 dir,
1737 colinearity,
1738 index_i,
1739 index_j,
1740 index_k,
1741 temperature);
1742}
1743
1745 const int& subproblem_index,
1746 const double& dist,
1747 const int& dir,
1748 const double& colinearity,
1749 const int& index_i,
1750 const int& index_j,
1751 const int& index_k)
1752{
1754 subproblem_index,
1755 dist,
1756 dir,
1757 colinearity,
1758 index_i,
1759 index_j,
1760 index_k);
1761}
1762
1764 const int& subproblem_index,
1765 const double& dist,
1766 const int& dir,
1767 const double& colinearity,
1768 const int& index_i,
1769 const int& index_j,
1770 const int& index_k)
1771{
1772 if (!discrete_integral_)
1774 subproblem_index,
1775 dist,
1776 dir,
1777 colinearity,
1778 index_i,
1779 index_j,
1780 index_k);
1781 else
1782 {
1784 subproblem_index,
1785 dist,
1786 dir,
1787 colinearity,
1788 index_i,
1789 index_j,
1790 index_k);
1791 return true;
1792 }
1793}
1794
1796 const int& subproblem_index,
1797 const double& dist,
1798 const int& dir,
1799 const double& colinearity,
1800 const int& index_i,
1801 const int& index_j,
1802 const int& index_k)
1803{
1805 subproblem_index,
1806 dist,
1807 dir,
1808 colinearity,
1809 index_i,
1810 index_j,
1811 index_k);
1812}
1813
1815 const int& subproblem_index,
1816 const double& dist,
1817 const int& dir,
1818 const double& colinearity,
1819 const int& index_i,
1820 const int& index_j,
1821 const int& index_k)
1822{
1824 subproblem_index,
1825 dist,
1826 dir,
1827 colinearity,
1828 index_i,
1829 index_j,
1830 index_k);
1831}
1832
1834 const int fluxes_type,
1835 const int& subproblem_index,
1836 const double& dist,
1837 const int& dir,
1838 const double& colinearity,
1839 const int& index_i,
1840 const int& index_j,
1841 const int& index_k,
1842 const int& temperature)
1843{
1844 bool valid_flux_value = true;
1845 int flux_sign[2][6] = FLUX_SIGN;
1846 double surf_face = 1.;
1847 for (int c = 0; c < 3; c++)
1848 if (c!=dir)
1849 surf_face *= domaine_->get_constant_delta(c);
1850 surf_face *= flux_sign[fluxes_type][(int) (2*dir)];
1851 flux = compute_thermal_flux_face_centre(fluxes_type,
1852 subproblem_index,
1853 dist,
1854 dir,
1855 valid_flux_value,
1856 -1,
1857 index_i,
1858 index_j,
1859 index_k,
1860 temperature);
1861 flux *= surf_face;
1863 flux *= colinearity;
1864 return valid_flux_value;
1865}
1866
1868 const int fluxes_type,
1869 const int& subproblem_index,
1870 const double& dist,
1871 const int& dir,
1872 const double& colinearity,
1873 const int& index_i,
1874 const int& index_j,
1875 const int& index_k)
1876{
1877 int flux_sign[2][6] = FLUX_SIGN;
1878 double surf_face = 1.;
1879 surf_face *= flux_sign[fluxes_type][(int) (2*dir)];
1880 DoubleVect discrete_flux_integral;
1881 discrete_flux_integral = compute_thermal_flux_face_centre_discrete_integral(fluxes_type, subproblem_index, dist, dir);
1882 for (int val=0; val < discrete_flux_integral.size(); val++)
1883 flux += discrete_flux_integral[val];
1884 flux *= surf_face;
1886 flux *= colinearity;
1887}
1888
1889void Corrige_flux_FT_temperature_subresolution::replace_cell_neighbours_thermal_convective_diffusive_fluxes_faces(const IJK_Field_vector3_int& cell_faces_neighbours_corrected_min_max_bool,
1890 const IJK_Field_vector3_int& cell_faces_neighbours_corrected_all_bool,
1891 const IJK_Field_vector3_double& cell_faces_neighbours_fluxes_corrected,
1892 const int& fluxes_type)
1893{
1894 int counter = 0;
1895 if (debug_)
1896 Cerr << "Replace cell neighbours thermal_convective diffusive fluxes faces" << finl;
1898 {
1899 replace_cell_neighbours_thermal_fluxes_faces(cell_faces_neighbours_corrected_min_max_bool,
1900 cell_faces_neighbours_corrected_all_bool,
1901 cell_faces_neighbours_fluxes_corrected,
1903 counter);
1904 counter++;
1905 }
1906 if (!diffusion_negligible_ && use_reachable_fluxes_ && fluxes_type == diffusion)
1907 {
1908 replace_cell_neighbours_thermal_fluxes_faces(cell_faces_neighbours_corrected_min_max_bool,
1909 cell_faces_neighbours_corrected_all_bool,
1910 cell_faces_neighbours_fluxes_corrected,
1912 counter);
1913 counter++;
1914 }
1915}
1916
1917void Corrige_flux_FT_temperature_subresolution::replace_cell_neighbours_thermal_fluxes_faces(const IJK_Field_vector3_int& cell_faces_neighbours_corrected_min_max_bool,
1918 const IJK_Field_vector3_int& cell_faces_neighbours_corrected_all_bool,
1919 const IJK_Field_vector3_double& cell_faces_neighbours_fluxes_corrected,
1920 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz,
1921 const int counter)
1922{
1923 const IJK_Field_vector3_int * cell_faces_neighbours_corrected_bool = nullptr;
1925 cell_faces_neighbours_corrected_bool = &cell_faces_neighbours_corrected_all_bool;
1926 else
1927 cell_faces_neighbours_corrected_bool = &cell_faces_neighbours_corrected_min_max_bool;
1928 const int ni = (*cell_faces_neighbours_corrected_bool)[0].ni();
1929 const int nj = (*cell_faces_neighbours_corrected_bool)[0].nj();
1930 const int nk = (*cell_faces_neighbours_corrected_bool)[0].nk();
1931 for (int c=0; c<3; c++)
1932 {
1933 const int ni_max = (c == 0 ? ni + 1 : ni);
1934 const int nj_max = (c == 1 ? nj + 1 : nj);
1935 const int nk_max = (c == 2 ? nk + 1 : nk);
1936 for (int k = 0; k < nk_max; k++)
1937 for (int j = 0; j < nj_max; j++)
1938 for (int i = 0; i < ni_max; i++)
1939 if ((*cell_faces_neighbours_corrected_bool)[c](i,j,k))
1940 {
1941 flux_xyz[c][k].append_array(cell_faces_neighbours_fluxes_corrected[c](i,j,k));
1942 if (!counter)
1943 {
1946 }
1947 }
1948 }
1949}
1950
1952 IJK_Field_double& temperature_neighbours,
1953 IJK_Field_int& neighbours_weighting,
1954 IJK_Field_double& neighbours_weighting_colinearity) const
1955{
1956 if (debug_)
1957 Cerr << "Corrige flux - Replace temperature cell neighbours - INI" << finl;
1959 {
1960 temperature_neighbours.echange_espace_virtuel(temperature_neighbours.ghost());
1961 neighbours_weighting.echange_espace_virtuel(neighbours_weighting.ghost());
1963 neighbours_weighting_colinearity.echange_espace_virtuel(neighbours_weighting_colinearity.ghost());
1964 const int ni = temperature.ni();
1965 const int nj = temperature.nj();
1966 const int nk = temperature.nk();
1967
1968 const Domaine_IJK& splitting = temperature.get_domaine();
1969 ArrOfInt corrected_values;
1970 ArrOfInt out_of_bounds_corrected_values;
1971 ArrOfDouble out_of_bounds_values;
1972
1973 for (int k = 0; k < nk; k++)
1974 for (int j = 0; j < nj; j++)
1975 for (int i = 0; i < ni; i++)
1976 {
1977 double neighbours_weighting_ijk;
1978 const double temperature_old = temperature(i,j,k);
1980 neighbours_weighting_ijk = neighbours_weighting_colinearity(i,j,k);
1981 else
1982 neighbours_weighting_ijk = (double) neighbours_weighting(i,j,k);
1983 const int elem = splitting.convert_ijk_cell_to_packed(i,j,k);
1984 if (neighbours_weighting(i,j,k))
1985 {
1986 temperature(i,j,k) = temperature_neighbours(i,j,k) / neighbours_weighting_ijk;
1988 corrected_values.append_array(elem);
1989
1990 }
1992 {
1993 const double local_temperature = temperature(i,j,k);
1994 const double indic = ref_ijk_ft_->get_interface().I()(i,j,k);
1995 if (local_temperature > 0)
1996 {
1997 if (indic < LIQUID_INDICATOR_TEST && indic > VAPOUR_INDICATOR_TEST)
1998 if (indic > 0.5)
1999 {
2000 const int rank = thermal_subproblems_->get_subproblem_index_from_ijk_indices(i,j,k);
2001 const double dist_sub_res = thermal_subproblems_->get_dist_cell_interface(rank);
2002 if (dist_sub_res > 0)
2003 {
2004 if (debug_)
2005 {
2006 Cerr << "Thermal subproblem is: " << rank << finl;
2007 Cerr << "Temperature value has the wrong sign at i: " << i << ", j: " << j << ", k: " << k << finl;
2008 Cerr << "Temperature value is: " << local_temperature << finl;
2009 Cerr << "Distance to cell centre is: " << dist_sub_res << finl;
2010 Cerr << "Enforce zero value" << finl;
2011 }
2012 // temperature(i,j,k) = 0.;
2013 out_of_bounds_corrected_values.append_array(elem);
2014 out_of_bounds_values.append_array(local_temperature);
2015 temperature(i,j,k) = temperature_old;
2016 }
2017 }
2018 if (indic > LIQUID_INDICATOR_TEST)
2019 {
2020 if (debug_)
2021 {
2022 Cerr << "Temperature value has the wrong sign at i: " << i << ", j: " << j << ", k: " << k << finl;
2023 Cerr << "Temperature value is: " << local_temperature << finl;
2024 Cerr << "Enforce zero value" << finl;
2025 }
2026 // temperature(i,j,k) = 0.;
2027 out_of_bounds_corrected_values.append_array(elem);
2028 out_of_bounds_values.append_array(local_temperature);
2029 temperature(i,j,k) = temperature_old;
2030 }
2031 }
2032 }
2033 }
2034 temperature.echange_espace_virtuel(temperature.ghost());
2036 corrected_values,
2037 out_of_bounds_corrected_values,
2038 out_of_bounds_values,
2039 temperature);
2040 }
2041
2042 if (debug_)
2043 Cerr << "Corrige flux - Replace temperature cell neighbours - END" << finl;
2044}
2045
2047 ArrOfInt& corrected_values,
2048 ArrOfInt& out_of_bounds_corrected_values,
2049 ArrOfDouble& out_of_bounds_values,
2050 IJK_Field_double& distance) const
2051{
2052 // const Domaine_IJK& splitting = temperature.get_domaine();
2053 // const Int3 num_elem_ijk = splitting.convert_packed_to_ijk_cell(elem);
2054 // (num_elem_ijk[DIRECTION_I], num_elem_ijk[DIRECTION_J], num_elem_ijk[DIRECTION_K]);
2056 {
2057 const Domaine_IJK& splitting = temperature.get_domaine();
2058 ArrOfDouble temperature_smoothed;
2059 int counter;
2060 double temperature_neighbour;
2061 for (int ielem=0; ielem<out_of_bounds_corrected_values.size_array(); ielem++)
2062 {
2063 const int elem = out_of_bounds_corrected_values[ielem];
2064 const Int3 num_elem_ijk = splitting.convert_packed_to_ijk_cell(elem);
2065 const int i = num_elem_ijk[DIRECTION_I];
2066 const int j = num_elem_ijk[DIRECTION_J];
2067 const int k = num_elem_ijk[DIRECTION_K];
2068 // const double temperature_old = temperature(i,j,k);
2069 const double temperature_old_subres = out_of_bounds_values[ielem];
2070 const double temperature_old = temperature(i,j,k);
2071 counter=0;
2072 temperature_neighbour=0;
2073 for (int l=0; l<6; l++)
2074 {
2075 const int ii = NEIGHBOURS_I[l];
2076 const int jj = NEIGHBOURS_J[l];
2077 const int kk = NEIGHBOURS_K[l];
2078 const double indic = ref_ijk_ft_->get_interface().I()(i+ii, j+jj, k+kk);
2079 // if (indic > VAPOUR_INDICATOR_TEST)
2080 if (indic > LIQUID_INDICATOR_TEST)
2081 {
2082 temperature_neighbour += temperature(i+ii, j+jj, k+kk);
2083 counter++;
2084 }
2085 }
2086 double mean_temperature = 1e20;
2087 if (counter != 0)
2088 mean_temperature = (temperature_neighbour / counter + temperature_old_subres) * 0.5;
2089 if (counter != 0)
2090 {
2091 if (mean_temperature < 0.)
2092 temperature_smoothed.append_array(mean_temperature);
2093 else
2094 temperature_smoothed.append_array(temperature_neighbour/counter);
2095 }
2096 else
2097 temperature_smoothed.append_array(temperature_old);
2098 }
2099
2100 for (int ielem=0; ielem<out_of_bounds_corrected_values.size_array(); ielem++)
2101 {
2102 const int elem = out_of_bounds_corrected_values[ielem];
2103 const Int3 num_elem_ijk = splitting.convert_packed_to_ijk_cell(elem);
2104 const int i = num_elem_ijk[DIRECTION_I];
2105 const int j = num_elem_ijk[DIRECTION_J];
2106 const int k = num_elem_ijk[DIRECTION_K];
2107 temperature(i,j,k) = temperature_smoothed(ielem);
2108 if (debug_)
2109 Cerr << "Smoothed temperature value is:" << temperature_smoothed(ielem) << finl;
2110 }
2111 }
2112}
2113
2121
2129
2131{
2132 for (int i=0; i<thermal_subproblems_->get_effective_subproblems_counter(); i++)
2133 {
2134 int ijk_indices_i, ijk_indices_j, ijk_indices_k;
2135 thermal_subproblems_->get_subproblem_ijk_indices(ijk_indices_i, ijk_indices_j, ijk_indices_k, i);
2136 d_temperature(ijk_indices_i, ijk_indices_j, ijk_indices_k) = 0.;
2137 }
2138 // for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
2139 // {
2140 // const int intersection_ijk_cell_index = ijk_intersections_subproblems_indices_[i];
2141 // const int ijk_indices_i = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 0);
2142 // const int ijk_indices_j = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 1);
2143 // const int ijk_indices_k = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 2);
2144 // d_temperature(ijk_indices_i, ijk_indices_j, ijk_indices_k) = 0.;
2145 // }
2146}
2147
2152
2157
2159 const int fluxes_type,
2160 const int& last_flux)
2161{
2162 const int flux_out[6] = FLUXES_OUT;
2163 const int faces_dir[6] = FACES_DIR;
2164 const int flux_sign[2][6] = FLUX_SIGN;
2165 const int nb_faces_to_correct = intersection_ijk_cell_->get_nb_faces_to_correct();
2166 fluxes.reset();
2167 fluxes.resize(nb_faces_to_correct);
2168 dist_.reset();
2169 dist_.resize(nb_faces_to_correct);
2170 int counter_faces = 0;
2171 const DoubleTab& dist_interf = intersection_ijk_cell_->dist_pure_faces_interf();
2172 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
2173 {
2174 const int intersection_ijk_cell_index = ijk_intersections_subproblems_indices_[i];
2175 for (int l=0; l<6; l++)
2176 {
2177 const int is_neighbour_pure_liquid = intersection_ijk_cell_->get_ijk_pure_face_neighbours(intersection_ijk_cell_index, l);
2178 double surf_face = 1.;
2179 const int dir = faces_dir[l];
2180 if (is_neighbour_pure_liquid)
2181 {
2182 for (int c = 0; c < 3; c++)
2183 if (c!= faces_dir[l])
2184 surf_face *= domaine_->get_constant_delta(c);
2185 const double dist = dist_interf(intersection_ijk_cell_index, l);
2186 const double dist_sub_res = thermal_subproblems_->get_dist_faces_interface(i)[l];
2187 double local_flux_face = 0.;
2188 bool valid_flux = true;
2190 local_flux_face = compute_thermal_flux_face_centre(fluxes_type, i, dist_sub_res, dir, valid_flux, l);
2191 else
2192 local_flux_face = compute_thermal_flux_face_centre(fluxes_type, i, dist, dir, valid_flux, l);
2193 double flux_face = local_flux_face * surf_face;
2194 thermal_subproblems_->set_pure_flux_corrected(flux_face * flux_out[l], i, l, fluxes_type);
2195 flux_face *= flux_sign[fluxes_type][l];
2196 // surf_face *= flux_sign[fluxes_type][l];
2197 fluxes[counter_faces] = flux_face;
2198 dist_[counter_faces] = dist;
2199 counter_faces++;
2200 }
2201 }
2202// if (last_flux)
2203// {
2204// thermal_subproblems_->compute_error_flux_interface(i);
2205// // std::vector<double> radial_flux_error;
2206// // thermal_subproblems_->compare_flux_interface(i, radial_flux_error);
2207// // const int nb_flux = (int) radial_flux_error.size();
2208// // for (int l=0; l<nb_flux; l++)
2209// // {
2210// // const double flux = fluxes[counter_faces + (l - nb_flux)];
2211// // fluxes[counter_faces + (l - nb_flux)] = flux - radial_flux_error[l] * flux_sign[fluxes_type][0];
2212// // }
2213// }
2214 }
2215 if (last_flux)
2216 thermal_subproblems_->compute_error_flux_interface();
2217 thermal_subproblems_->complete_frame_of_reference_lrs_fluxes_eval();
2218 /*
2219 * Useless if a treat a sub-problem per mixed cells
2220 * May be useful if a treat one subproblem per interface portion
2221 */
2222 // check_pure_fluxes_duplicates(convective_fluxes_, convective_fluxes_unique_, pure_face_unique_, 1);
2223}
2224
2226{
2227 DoubleVect * fluxes = nullptr;
2228 fluxes = &diffusive_fluxes_;
2230 fluxes = &convective_fluxes_;
2231 complete_thermal_fluxes_face_centre(fluxes, fluxes_correction_conservations);
2232}
2233
2235 const int& fluxes_correction_conservations)
2236{
2237 if (fluxes_correction_conservations)
2238 {
2239 int counter_faces = 0;
2240 const int flux_sign[2][6] = FLUX_SIGN;
2241 const int flux_out[6] = FLUXES_OUT;
2242 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
2243 {
2244 const int intersection_ijk_cell_index = ijk_intersections_subproblems_indices_[i];
2245 for (int l=0; l<6; l++)
2246 {
2247 const int is_neighbour_pure_liquid = intersection_ijk_cell_->get_ijk_pure_face_neighbours(intersection_ijk_cell_index, l);
2248 if (is_neighbour_pure_liquid)
2249 {
2250 double flux_corr = thermal_subproblems_->get_corrective_flux_from_neighbours(i, l);
2251 flux_corr += thermal_subproblems_->get_corrective_flux_from_current(i, l);
2252 // double flux_corr = thermal_subproblems_->get_corrective_flux_from_current(i, l);
2253 flux_corr *= (flux_sign[1][l]);
2254 const double flux_final = (*fluxes)[counter_faces] - flux_corr;
2255 (*fluxes)[counter_faces] = flux_final;
2256 thermal_subproblems_->set_pure_flux_corrected(flux_final * flux_out[l] * flux_sign[1][l], i, l, 1);
2257 counter_faces++;
2258 }
2259 }
2260 }
2261 }
2262}
2263
2265 const int& index_subproblem,
2266 const double& dist,
2267 const int& dir,
2268 bool& valid_val,
2269 const int& l,
2270 const int& index_i,
2271 const int& index_j,
2272 const int& index_k,
2273 const int& temperature)
2274{
2275 switch(fluxes_type)
2276 {
2277 case convection:
2278 return thermal_subproblems_->get_temperature_times_velocity_profile_at_point(index_subproblem,
2279 dist,
2280 dir,
2281 valid_val,
2282 l,
2283 index_i,
2284 index_j,
2285 index_k,
2286 temperature);
2287 case diffusion:
2288 return thermal_subproblems_->get_temperature_gradient_times_conductivity_profile_at_point(index_subproblem, dist, dir, valid_val);
2289 default:
2290 return thermal_subproblems_->get_temperature_times_velocity_profile_at_point(index_subproblem,
2291 dist,
2292 dir,
2293 valid_val,
2294 l,
2295 index_i,
2296 index_j,
2297 index_k,
2298 temperature);
2299 }
2300}
2301
2306
2311
2313{
2314 const int flux_out[6] = FLUXES_OUT;
2315 const int faces_dir[6] = FACES_DIR;
2316 const int flux_sign[2][6] = FLUX_SIGN;
2317 const int nb_faces_to_correct = intersection_ijk_cell_->get_nb_faces_to_correct();
2318 fluxes.reset();
2319 fluxes.resize(nb_faces_to_correct);
2320 dist_.reset();
2321 dist_.resize(nb_faces_to_correct);
2322 const DoubleTab& dist_interf = intersection_ijk_cell_->dist_pure_faces_interf();
2323 int counter_faces = 0;
2324 // const DoubleTab& pos_pure_faces_interf = intersection_ijk_cell_->pos_pure_faces_interf();
2325 // positions.resize(nb_diph, 3, 6);
2326 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
2327 {
2328 // double surface = 0.;
2329 const int intersection_ijk_cell_index = ijk_intersections_subproblems_indices_[i];
2330 for (int l=0; l<6; l++)
2331 {
2332 const int dir = faces_dir[l];
2333 const int is_neighbour_pure_liquid = intersection_ijk_cell_->get_ijk_pure_face_neighbours(intersection_ijk_cell_index, l);
2334 if (is_neighbour_pure_liquid)
2335 {
2336 const double dist = dist_interf(intersection_ijk_cell_index, l);
2337 const double dist_sub_res = thermal_subproblems_->get_dist_faces_interface(i)[l];
2338 DoubleVect discrete_flux_integral;
2340 discrete_flux_integral = compute_thermal_flux_face_centre_discrete_integral(fluxes_type, i, dist_sub_res, dir, l);
2341 else
2342 discrete_flux_integral = compute_thermal_flux_face_centre_discrete_integral(fluxes_type, i, dist, dir, l);
2343 double flux_face = 0;
2344 for (int val=0; val < discrete_flux_integral.size(); val++)
2345 flux_face += discrete_flux_integral[val];
2346 thermal_subproblems_->set_pure_flux_corrected(flux_face * flux_out[l], i, l, fluxes_type);
2347 flux_face *= flux_sign[fluxes_type][l];
2348 fluxes[counter_faces] = flux_face;
2349 dist_[counter_faces] = dist;
2350 counter_faces++;
2351 }
2352 }
2353 }
2354 thermal_subproblems_->complete_frame_of_reference_lrs_fluxes_eval();
2355 /*
2356 * Useless if a treat a sub-problem per mixed cells
2357 * May be useful if a treat one subproblem per interface portion
2358 */
2359 // check_pure_fluxes_duplicates(convective_fluxes_, convective_fluxes_unique_, pure_face_unique_, 0);
2360}
2361
2363 const int& index_subproblem,
2364 const double& dist,
2365 const int& dir,
2366 const int& l)
2367{
2368 switch(fluxes_type)
2369 {
2370 case convection:
2371 return thermal_subproblems_->get_temperature_times_velocity_profile_discrete_integral_at_point(index_subproblem,
2372 dist,
2373 levels_,
2374 dir,
2375 l);
2376 case diffusion:
2377 return thermal_subproblems_->get_temperature_gradient_times_conductivity_profile_discrete_integral_at_point(index_subproblem,
2378 dist,
2379 levels_,
2380 dir);
2381 default:
2382 return thermal_subproblems_->get_temperature_times_velocity_profile_discrete_integral_at_point(index_subproblem,
2383 dist,
2384 levels_,
2385 dir,
2386 l);
2387 }
2388}
2389
2390void Corrige_flux_FT_temperature_subresolution::compute_min_max_ijk_reachable_fluxes(const IJK_Field_vector3_int& cell_faces_neighbours_corrected_all_bool,
2391 const IJK_Field_int& neighbours_temperature_to_correct,
2392 IJK_Field_vector3_int& cell_faces_neighbours_corrected_min_max_bool,
2393 const int& max_flux_per_dir,
2394 const int& check_cell_center_neighbour,
2395 const int& remove_external_neighbour_values,
2396 IJK_Field_int& neighbours_temperature_to_correct_trimmed)
2397{
2398 /*
2399 * TODO: Work only for static bubbles
2400 */
2402 {
2403
2405 {
2406 FixedVector<IJK_Field_local_int, 3> cell_faces_neighbours_corrected_min_max_bool_local;
2407
2408 remove_min_max_ijk_reachable_fluxes_discontinuous(cell_faces_neighbours_corrected_all_bool,
2409 cell_faces_neighbours_corrected_min_max_bool_local);
2410
2411 const int ni = cell_faces_neighbours_corrected_all_bool[0].ni();
2412 const int nj = cell_faces_neighbours_corrected_all_bool[0].nj();
2413 const int nk = cell_faces_neighbours_corrected_all_bool[0].nk();
2414 int i,j,k,c;
2415 for (c = 0; c < 3; c++)
2416 cell_faces_neighbours_corrected_min_max_bool[c].data() = 0.;
2417 int c_ini = 0;
2418 int c_end = 3;
2419
2420 if (remove_external_neighbour_values)
2421 {
2422 for (k = 0; k < nk; k++)
2423 for (j = 0; j < nj; j++)
2424 for (i = 0; i < ni; i++)
2425 neighbours_temperature_to_correct_trimmed(i,j,k) = neighbours_temperature_to_correct(i,j,k);
2426 neighbours_temperature_to_correct_trimmed.echange_espace_virtuel(neighbours_temperature_to_correct_trimmed.ghost());
2427 }
2428 /*
2429 * i_min, i_max
2430 */
2431 if (max_flux_per_dir)
2432 {
2433 c_ini = 0;
2434 c_end = 1;
2435 }
2436 int index_neighbour_cell = 0;
2437 bool index_found = false;
2438 bool centre_neighbour_bool = false;
2439 for (c = c_ini; c < c_end; c++)
2440 for (k = 0; k < nk; k++)
2441 for (j = 0; j < nj; j++)
2442 {
2443 for (i = 0; i < ni; i++)
2444 {
2445 if (neighbours_temperature_to_correct(i,j,k) && !index_found)
2446 {
2447 index_neighbour_cell = i;
2448 index_found = true;
2449 }
2450 if(cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k))
2451 {
2452 if (neighbours_temperature_to_correct(i - 1,j,k) && check_cell_center_neighbour && !remove_external_neighbour_values)
2453 centre_neighbour_bool = true;
2454 if (!centre_neighbour_bool)
2455 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k);
2456 centre_neighbour_bool = false;
2457 index_found = false;
2458 for(int ii = index_neighbour_cell; ii < i; ii++)
2459 neighbours_temperature_to_correct_trimmed(ii,j,k) = 0;
2460 break;
2461 }
2462 }
2463 for (i = ni - 1; i >=0; i--)
2464 {
2465 if (neighbours_temperature_to_correct(i,j,k) && !index_found)
2466 {
2467 index_neighbour_cell = i;
2468 index_found = true;
2469 }
2470 if(cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k))
2471 {
2472 if (neighbours_temperature_to_correct(i,j,k) && check_cell_center_neighbour && !remove_external_neighbour_values)
2473 centre_neighbour_bool = true;
2474 if (!centre_neighbour_bool)
2475 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k);
2476 centre_neighbour_bool = false;
2477 index_found = false;
2478 for(int ii = index_neighbour_cell; ii >= i; ii--)
2479 neighbours_temperature_to_correct_trimmed(ii,j,k) = 0;
2480 break;
2481 }
2482 }
2483 }
2484 /*
2485 * j_min, j_max
2486 */
2487 if (max_flux_per_dir)
2488 {
2489 c_ini = 1;
2490 c_end = 2;
2491 }
2492 for (c = c_ini; c < c_end; c++)
2493 for (k = 0; k < nk; k++)
2494 for (i = 0; i < ni; i++)
2495 {
2496 for (j = 0; j < nj; j++)
2497 {
2498 if (neighbours_temperature_to_correct(i,j,k) && !index_found)
2499 {
2500 index_neighbour_cell = j;
2501 index_found = true;
2502 }
2503 if(cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k))
2504 {
2505 if (neighbours_temperature_to_correct(i,j - 1,k) && check_cell_center_neighbour && !remove_external_neighbour_values)
2506 centre_neighbour_bool = true;
2507 if (!centre_neighbour_bool)
2508 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k);
2509 centre_neighbour_bool = false;
2510 index_found = false;
2511 for(int jj = index_neighbour_cell; jj < j; jj++)
2512 neighbours_temperature_to_correct_trimmed(i,jj,k) = 0;
2513 break;
2514 }
2515 }
2516 for (j = nj - 1; j >=0; j--)
2517 {
2518 if (neighbours_temperature_to_correct(i,j,k) && !index_found)
2519 {
2520 index_neighbour_cell = j;
2521 index_found = true;
2522 }
2523 if(cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k))
2524 {
2525 if (neighbours_temperature_to_correct(i,j,k) && check_cell_center_neighbour && !remove_external_neighbour_values)
2526 centre_neighbour_bool = true;
2527 if (!centre_neighbour_bool)
2528 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k);
2529 centre_neighbour_bool = false;
2530 index_found = false;
2531 for(int jj = index_neighbour_cell; jj >= j; jj--)
2532 neighbours_temperature_to_correct_trimmed(i,jj,k) = 0;
2533 break;
2534 }
2535 }
2536 }
2537 /*
2538 * k_min, k_max
2539 */
2540 if (max_flux_per_dir)
2541 {
2542 c_ini = 2;
2543 c_end = 3;
2544 }
2545 for (c = c_ini; c < c_end; c++)
2546 for (i = 0; i < ni; i++)
2547 for (j = 0; j < nj; j++)
2548 {
2549 for (k = 0; k < nk; k++)
2550 {
2551 if (neighbours_temperature_to_correct(i,j,k) && !index_found)
2552 {
2553 index_neighbour_cell = k;
2554 index_found = true;
2555 }
2556 if(cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k))
2557 {
2558 if (neighbours_temperature_to_correct(i,j,k - 1) && check_cell_center_neighbour && !remove_external_neighbour_values)
2559 centre_neighbour_bool = true;
2560 if (!centre_neighbour_bool)
2561 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k);
2562 centre_neighbour_bool = false;
2563 index_found = false;
2564 for(int kk = index_neighbour_cell; kk < k; kk++)
2565 neighbours_temperature_to_correct_trimmed(i,j,kk) = 0;
2566 break;
2567 }
2568 }
2569 for (k = nk - 1; k >=0; k--)
2570 {
2571 if (neighbours_temperature_to_correct(i,j,k) && !index_found)
2572 {
2573 index_neighbour_cell = k;
2574 index_found = true;
2575 }
2576 if(cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k))
2577 {
2578 if (neighbours_temperature_to_correct(i,j,k) && check_cell_center_neighbour && !remove_external_neighbour_values)
2579 centre_neighbour_bool = true;
2580 if (!centre_neighbour_bool)
2581 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_min_max_bool_local[c](i,j,k);
2582 centre_neighbour_bool = false;
2583 index_found = false;
2584 for(int kk = index_neighbour_cell; kk >= k; kk--)
2585 neighbours_temperature_to_correct_trimmed(i,j,kk) = 0;
2586 break;
2587 }
2588 }
2589 }
2590 cell_faces_neighbours_corrected_min_max_bool.echange_espace_virtuel();
2591 }
2592 }
2593
2594}
2595
2596void Corrige_flux_FT_temperature_subresolution::compute_min_max_ijk_any_reachable_fluxes(const IJK_Field_vector3_int& cell_faces_neighbours_corrected_all_bool,
2597 const IJK_Field_int& neighbours_temperature_to_correct,
2598 IJK_Field_vector3_int& cell_faces_neighbours_corrected_min_max_bool,
2599 const int& max_flux_per_dir,
2600 const int& check_cell_center_neighbour,
2601 const int& remove_external_neighbour_values,
2602 IJK_Field_int& neighbours_temperature_to_correct_trimmed)
2603{
2605 {
2606
2608 {
2609 FixedVector<IJK_Field_local_int, 3> cell_faces_neighbours_corrected_min_max_bool_local;
2610
2611 remove_min_max_ijk_reachable_fluxes_discontinuous(cell_faces_neighbours_corrected_all_bool,
2612 cell_faces_neighbours_corrected_min_max_bool_local);
2613
2614 int c;
2615 for (c = 0; c < 3; c++)
2616 cell_faces_neighbours_corrected_min_max_bool[c].data() = 0.;
2617
2618 const int ni = cell_faces_neighbours_corrected_all_bool[0].ni();
2619 const int nj = cell_faces_neighbours_corrected_all_bool[0].nj();
2620 const int nk = cell_faces_neighbours_corrected_all_bool[0].nk();
2621 int i,j,k;
2622 int c_ini = 0;
2623 int c_end = 3;
2624 if (remove_external_neighbour_values)
2625 {
2626 for (k = 0; k < nk; k++)
2627 for (j = 0; j < nj; j++)
2628 for (i = 0; i < ni; i++)
2629 neighbours_temperature_to_correct_trimmed(i,j,k) = neighbours_temperature_to_correct(i,j,k);
2630 neighbours_temperature_to_correct_trimmed.echange_espace_virtuel(neighbours_temperature_to_correct_trimmed.ghost());
2631 /*
2632 * i_min, i_max, j_min, j_max, k_min, k_max
2633 */
2634 ArrOfInt indices_found_ini, indices_found_end;
2635 ArrOfInt indices_flux_found_ini, indices_flux_found_end;
2636 ArrOfInt indices_to_remove;
2637 ArrOfInt indices_fluxes_to_remove;
2638 FixedVector<ArrOfInt,2> indices_sorted;
2639 FixedVector<ArrOfInt,2> indices_fluxes_sorted;
2640
2641// if (max_flux_per_dir)
2642// {
2643// c_ini = 0;
2644// c_end = 1;
2645// }
2646 const int * n_first = nullptr;
2647 const int * n_bis = nullptr;
2648 const int * n_ter = nullptr;
2649 int * i_ref = nullptr;
2650 int * j_ref = nullptr;
2651 int * k_ref = nullptr;
2652 int * i_ref_remove = nullptr;
2653 int * j_ref_remove = nullptr;
2654 int * k_ref_remove = nullptr;
2655 int index_first = 0, index_bis = 0, index_ter = 0;
2656 int val = 0;
2657 const int factor_pos[3][3] = {{1, 0, 0},{0, 1, 0},{0, 0, 1}};
2658 for (c = c_ini; c < c_end; c++)
2659 {
2660 switch(c)
2661 {
2662 case 0:
2663 n_first = &nk;
2664 n_bis = &nj;
2665 n_ter = &ni;
2666 k_ref = &index_first;
2667 j_ref = &index_bis;
2668 i_ref = &index_ter;
2669 k_ref_remove = &index_first;
2670 j_ref_remove = &index_bis;
2671 i_ref_remove = &val;
2672 break;
2673 case 1:
2674 n_first = &nk;
2675 n_bis = &ni;
2676 n_ter = &nj;
2677 k_ref = &index_first;
2678 i_ref = &index_bis;
2679 j_ref = &index_ter;
2680 k_ref_remove = &index_first;
2681 i_ref_remove = &index_bis;
2682 j_ref_remove = &val;
2683 break;
2684 case 2:
2685 n_first = &ni;
2686 n_bis = &nj;
2687 n_ter = &nk;
2688 i_ref = &index_first;
2689 j_ref = &index_bis;
2690 k_ref = &index_ter;
2691 i_ref_remove = &index_first;
2692 j_ref_remove = &index_bis;
2693 k_ref_remove = &val;
2694 break;
2695 default:
2696 break;
2697 }
2698 for (index_first = 0; index_first < *n_first; index_first++)
2699 for (index_bis = 0; index_bis < *n_bis; index_bis++)
2700 {
2701 indices_found_ini.reset();
2702 indices_found_end.reset();
2703 indices_flux_found_ini.reset();
2704 indices_flux_found_end.reset();
2705 indices_to_remove.reset();
2706 indices_fluxes_to_remove.reset();
2707 for (int l=0; l<2; l++)
2708 {
2709 indices_sorted[l].reset();
2710 indices_fluxes_sorted[l].reset();
2711 }
2712 for (index_ter = 0; index_ter < *n_ter; index_ter++)
2713 {
2714 if (neighbours_temperature_to_correct(*i_ref,*j_ref,*k_ref))
2715 {
2716 if (!neighbours_temperature_to_correct(*i_ref + factor_pos[c][0],*j_ref + factor_pos[c][1],*k_ref + factor_pos[c][2]))
2717 indices_found_end.append_array(index_ter);
2718 if (!neighbours_temperature_to_correct(*i_ref - factor_pos[c][0],*j_ref - factor_pos[c][1],*k_ref - factor_pos[c][2]))
2719 indices_found_ini.append_array(index_ter);
2720 }
2721 if(cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref,*j_ref,*k_ref))
2722 {
2723 if (!cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref + factor_pos[c][0],*j_ref + factor_pos[c][1],*k_ref + factor_pos[c][2]))
2724 indices_flux_found_end.append_array(index_ter);
2725 if (!cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref - factor_pos[c][0],*j_ref - factor_pos[c][1],*k_ref - factor_pos[c][2]))
2726 indices_flux_found_ini.append_array(index_ter);
2727 }
2728 }
2729
2730 const int indices_test = indices_found_ini.size_array() || indices_found_end.size_array();
2731 if (indices_test)
2732 {
2733 sort_ini_end_arrays(indices_found_ini,
2734 indices_found_end,
2735 indices_sorted,
2736 *n_ter);
2737 }
2738
2739 const int indices_flux_test = indices_flux_found_ini.size_array() || indices_flux_found_end.size_array();
2740 if (indices_flux_test)
2741 {
2742// sort_ini_end_arrays(indices_flux_found_ini,
2743// indices_flux_found_end,
2744// indices_fluxes_sorted,
2745// *n_ter);
2746 sort_ini_end_arrays(indices_flux_found_ini,
2747 indices_flux_found_end,
2748 indices_fluxes_sorted,
2749 (*n_ter) + 1);
2750 }
2751 if (indices_test || indices_flux_test)
2753 indices_fluxes_sorted,
2754 indices_to_remove,
2755 indices_fluxes_to_remove,
2756 index_first, index_bis, c);
2757
2758// for (index_ter = 0; index_ter < indices_fluxes_sorted[0].size_array(); index_ter++)
2759// {
2760// val = indices_fluxes_sorted[0](index_ter);
2761// cell_faces_neighbours_corrected_min_max_bool[c](*i_ref_remove, *j_ref_remove, *k_ref_remove) =
2762// cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref_remove, *j_ref_remove, *k_ref_remove);
2763// val = indices_fluxes_sorted[1](index_ter);
2764// cell_faces_neighbours_corrected_min_max_bool[c](*i_ref_remove, *j_ref_remove, *k_ref_remove) =
2765// cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref_remove, *j_ref_remove, *k_ref_remove);
2766// }
2767//
2768// /*
2769// * Keep max min flux values to build a convex shape
2770// */
2771 for (index_ter = 0; index_ter < indices_flux_found_ini.size_array(); index_ter++)
2772 {
2773 val = indices_flux_found_ini(index_ter);
2774 const double indic_ini = ref_ijk_ft_->get_interface().I()(*i_ref_remove,
2775 *j_ref_remove,
2776 *k_ref_remove);
2777 const double indic_ini_prev = ref_ijk_ft_->get_interface().I()(*i_ref_remove - factor_pos[c][0],
2778 *j_ref_remove - factor_pos[c][1],
2779 *k_ref_remove - factor_pos[c][2]);
2780 if(indic_ini > LIQUID_INDICATOR_TEST && indic_ini_prev > LIQUID_INDICATOR_TEST)
2781 {
2782 cell_faces_neighbours_corrected_min_max_bool[c](*i_ref_remove, *j_ref_remove, *k_ref_remove) =
2783 cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref_remove, *j_ref_remove, *k_ref_remove);
2784 // break;
2785 }
2786 }
2787 for (index_ter = 0; index_ter < indices_flux_found_end.size_array(); index_ter++)
2788 {
2789 val = indices_flux_found_end(index_ter);
2790 const double indic_end = ref_ijk_ft_->get_interface().I()(*i_ref_remove,
2791 *j_ref_remove,
2792 *k_ref_remove);
2793 const double indic_end_prev = ref_ijk_ft_->get_interface().I()(*i_ref_remove - factor_pos[c][0],
2794 *j_ref_remove - factor_pos[c][1],
2795 *k_ref_remove - factor_pos[c][2]);
2796 if(indic_end > LIQUID_INDICATOR_TEST && indic_end_prev > LIQUID_INDICATOR_TEST)
2797 {
2798 cell_faces_neighbours_corrected_min_max_bool[c](*i_ref_remove, *j_ref_remove, *k_ref_remove) =
2799 cell_faces_neighbours_corrected_min_max_bool_local[c](*i_ref_remove, *j_ref_remove, *k_ref_remove);
2800 //break;
2801 }
2802 }
2803
2804 /*
2805 * Remove temperature and non-consistent fluxes values
2806 */
2807 for (index_ter = 0; index_ter < indices_to_remove.size_array(); index_ter++)
2808 {
2809 val = indices_to_remove(index_ter);
2810 neighbours_temperature_to_correct_trimmed(*i_ref_remove, *j_ref_remove, *k_ref_remove) = 0;
2811 }
2812
2813 for (index_ter = 0; index_ter < indices_fluxes_to_remove.size_array(); index_ter++)
2814 {
2815 val = indices_fluxes_to_remove(index_ter);
2816 cell_faces_neighbours_corrected_min_max_bool[c](*i_ref_remove, *j_ref_remove, *k_ref_remove) = 0;
2817 }
2818 }
2819 }
2820 }
2821 }
2822 Cerr << "Echange espace virtuel" << finl;
2823 cell_faces_neighbours_corrected_min_max_bool.echange_espace_virtuel();
2824 }
2825}
2826
2828 ArrOfInt& indices_found_end,
2829 FixedVector<ArrOfInt,2>& indices_sorted,
2830 const int& max_n_layer)
2831{
2832 int counter_ini = 0;
2833 int counter_end = 0;
2834 FixedVector<int*, 2> counters;
2835 counters[0] = &counter_ini;
2836 counters[1] = &counter_end;
2837 FixedVector<ArrOfInt*, 2> indices_references;
2838 indices_references[0] = &indices_found_ini;
2839 indices_references[1] = &indices_found_end;
2840 int size_ini = indices_found_ini.size_array();
2841 int size_end = indices_found_end.size_array();
2842 FixedVector<int*, 2> size_references;
2843 size_references[0] = &size_ini;
2844 size_references[1] = &size_end;
2845 int max_counter = 0;
2846 const int max_index = size_ini + size_end;
2847 std::vector<int> index_tmp;
2848 while(counter_ini < size_ini || counter_end < size_end)
2849 {
2850 for (int l=0; l<2; l++)
2851 {
2852 const int index_int_tmp = (*counters[l] < *size_references[l]) ? (*indices_references[l])(*counters[l]) : std::numeric_limits<int>::max();
2853 index_tmp.push_back(index_int_tmp);
2854 }
2855 const int index_min = (int) std::distance(index_tmp.begin(), std::min_element(index_tmp.begin(), index_tmp.end()));
2856 if (!index_min)
2857 {
2858 indices_sorted[0].append_array((*indices_references[index_min])(*counters[index_min]));
2859 if (max_counter == max_index - 1)
2860 indices_sorted[1].append_array(max_n_layer - 1);
2861 }
2862 else
2863 {
2864 indices_sorted[1].append_array((*indices_references[index_min])(*counters[index_min]));
2865 if (!indices_sorted[0].size_array())
2866 indices_sorted[0].append_array(0);
2867 }
2868 (*(counters[index_min]))++;
2869 max_counter++;
2870 index_tmp.clear();
2871 }
2872 assert(indices_sorted[0].size_array() == indices_sorted[1].size_array());
2873}
2874
2876 const FixedVector<ArrOfInt,2>& indices_fluxes_sorted,
2877 ArrOfInt& indices_to_remove,
2878 ArrOfInt& indices_fluxes_to_remove,
2879 int& index_bis,
2880 int& index_ter,
2881 const int& dir)
2882{
2883 int * i = nullptr;
2884 int * j = nullptr;
2885 int * k = nullptr;
2886 int val = 0;
2887 switch(dir)
2888 {
2889 case 0:
2890 j = &index_ter;
2891 k = &index_bis;
2892 i = &val;
2893 break;
2894 case 1:
2895 i = &index_ter;
2896 k = &index_bis;
2897 j = &val;
2898 break;
2899 case 2:
2900 i = &index_bis;
2901 j = &index_ter;
2902 k = &val;
2903 break;
2904 default:
2905 break;
2906 }
2907 const int factor_pos[3][3] = {{1, 0, 0},{0, 1, 0},{0, 0, 1}};
2908 std::vector<int> is_in_interval = {0, 0};
2909 int ll;
2910 int m = 0;
2911 for(int l=0; l<indices_sorted[0].size_array(); l++)
2912 if (m < indices_fluxes_sorted[0].size_array())
2913 // for (int m=0; m<indices_fluxes_sorted[0].size_array(); m++)
2914 {
2915 for (int n=0; n<2; n++)
2916 {
2917 // use indicator
2918 val = indices_fluxes_sorted[n][m];
2919 const double indic = ref_ijk_ft_->get_interface().I()(*i, *j, *k);
2920 const double indic_prev = ref_ijk_ft_->get_interface().I()(*i - factor_pos[dir][0], *j - factor_pos[dir][1], *k - factor_pos[dir][2]);
2921 const int indic_test = (indic > LIQUID_INDICATOR_TEST && indic_prev > LIQUID_INDICATOR_TEST);
2922 if (indic_test)
2923 switch(n)
2924 {
2925 case 0:
2926 is_in_interval[n] = (indices_fluxes_sorted[n][m] > indices_sorted[n][l]) ? 1 : 0;
2927 break;
2928 case 1:
2929 is_in_interval[n] = (indices_fluxes_sorted[n][m] <= indices_sorted[n][l]) ? 1 : 0;
2930 break;
2931 default:
2932 break;
2933 }
2934 }
2935 if (is_in_interval[0] || is_in_interval[1])
2936 {
2937 if (is_in_interval[0])
2938 for (ll=indices_sorted[0][l]; ll<indices_fluxes_sorted[0][m]; ll++)
2939 indices_to_remove.append_array(ll);
2940 if (is_in_interval[1])
2941 for (ll=indices_fluxes_sorted[1][m]; ll<=indices_sorted[1][l]; ll++)
2942 indices_to_remove.append_array(ll);
2943 m++;
2944 }
2945 is_in_interval = {0, 0};
2946 }
2947 for (m=0; m<indices_fluxes_sorted[0].size_array(); m++)
2948 if (indices_fluxes_sorted[0][m] == indices_fluxes_sorted[1][m])
2949 indices_fluxes_to_remove.append_array(indices_fluxes_sorted[0][m]);
2950}
2951
2952void Corrige_flux_FT_temperature_subresolution::remove_min_max_ijk_reachable_fluxes_discontinuous(const IJK_Field_vector3_int& cell_faces_neighbours_corrected_all_bool,
2953 FixedVector<IJK_Field_local_int, 3>& cell_faces_neighbours_corrected_min_max_bool)
2954{
2955 const int ni = cell_faces_neighbours_corrected_all_bool[0].ni();
2956 const int nj = cell_faces_neighbours_corrected_all_bool[0].nj();
2957 const int nk = cell_faces_neighbours_corrected_all_bool[0].nk();
2958
2959 int i,j,k,c;
2960 const int nb_ghost = 1;
2961
2962 for (c = 0; c < 3; c++)
2963 cell_faces_neighbours_corrected_min_max_bool[c].allocate(ni,nj,nk,nb_ghost);
2964
2965 for (c = 0; c < 3; c++)
2966 for (k = -nb_ghost; k < nk + nb_ghost; k++)
2967 for (j = -nb_ghost; j < nj + nb_ghost; j++)
2968 for (i = -nb_ghost; i < ni + nb_ghost; i++)
2969 cell_faces_neighbours_corrected_min_max_bool[c](i,j,k) = cell_faces_neighbours_corrected_all_bool[c](i,j,k);
2970
2971 const int neighbouring_face_index_from_sign[2] = {1, -1};
2972 const int neighbouring_cell_index_from_sign[2] = {0, -1};
2973 const int neighbouring_face_first_second_index_from_sign[2] = {1, 0};
2974 int neighbouring_face_index;
2975 int n_sign_mean, n_sign_first_dir, n_sign_second_dir;
2976
2977 for (c = 0; c < 3; c++)
2978 for (k = 0; k < nk; k++)
2979 for (j = 0; j < nj; j++)
2980 for (i = 0; i < ni; i++)
2981 {
2982 if (cell_faces_neighbours_corrected_all_bool[c](i,j,k))
2983 {
2984 switch(c)
2985 {
2986 case 0:
2987 n_sign_mean = signbit((*eulerian_normal_vectors_ns_normed_)[0](i-1,j,k) + (*eulerian_normal_vectors_ns_normed_)[0](i,j,k));
2988 neighbouring_face_index = neighbouring_face_index_from_sign[n_sign_mean];
2989 if (!cell_faces_neighbours_corrected_min_max_bool[0](i + neighbouring_face_index,j,k))
2990 {
2991 const int neighbouring_cell_index = neighbouring_cell_index_from_sign[n_sign_mean];
2992 n_sign_first_dir = signbit((*eulerian_normal_vectors_ns_normed_)[1](i+neighbouring_cell_index,j,k));
2993 n_sign_second_dir = signbit((*eulerian_normal_vectors_ns_normed_)[2](i+neighbouring_cell_index,j,k));
2994
2995 const int j_face = neighbouring_face_first_second_index_from_sign[n_sign_first_dir];
2996 cell_faces_neighbours_corrected_min_max_bool[1](i+neighbouring_cell_index, j+j_face, k) = 0;
2997 const int k_face = neighbouring_face_first_second_index_from_sign[n_sign_second_dir];
2998 cell_faces_neighbours_corrected_min_max_bool[2](i+neighbouring_cell_index, j, k+k_face) = 0;
2999 }
3000 break;
3001 case 1:
3002 n_sign_mean = signbit((*eulerian_normal_vectors_ns_normed_)[1](i,j-1,k) + (*eulerian_normal_vectors_ns_normed_)[1](i,j,k));
3003 neighbouring_face_index = neighbouring_face_index_from_sign[n_sign_mean];
3004 if (!cell_faces_neighbours_corrected_min_max_bool[1](i,j + neighbouring_face_index,k))
3005 {
3006 const int neighbouring_cell_index = neighbouring_cell_index_from_sign[n_sign_mean];
3007 n_sign_first_dir = signbit((*eulerian_normal_vectors_ns_normed_)[0](i, j+neighbouring_cell_index, k));
3008 n_sign_second_dir = signbit((*eulerian_normal_vectors_ns_normed_)[2](i, j+neighbouring_cell_index, k));
3009
3010 const int i_face = neighbouring_face_first_second_index_from_sign[n_sign_first_dir];
3011 cell_faces_neighbours_corrected_min_max_bool[0](i+i_face, j+neighbouring_cell_index, k) = 0;
3012 const int k_face = neighbouring_face_first_second_index_from_sign[n_sign_second_dir];
3013 cell_faces_neighbours_corrected_min_max_bool[2](i, j+neighbouring_cell_index, k+k_face) = 0;
3014
3015 }
3016 break;
3017 case 2:
3018 n_sign_mean = signbit((*eulerian_normal_vectors_ns_normed_)[2](i,j,k-1) + (*eulerian_normal_vectors_ns_normed_)[2](i,j,k));
3019 neighbouring_face_index = neighbouring_face_index_from_sign[n_sign_mean];
3020 if (!cell_faces_neighbours_corrected_min_max_bool[2](i,j,k + neighbouring_face_index))
3021 {
3022 const int neighbouring_cell_index = neighbouring_cell_index_from_sign[n_sign_mean];
3023 n_sign_first_dir = signbit((*eulerian_normal_vectors_ns_normed_)[0](i, j, k+neighbouring_cell_index));
3024 n_sign_second_dir = signbit((*eulerian_normal_vectors_ns_normed_)[1](i, j, k+neighbouring_cell_index));
3025
3026 const int i_face = neighbouring_face_first_second_index_from_sign[n_sign_first_dir];
3027 cell_faces_neighbours_corrected_min_max_bool[0](i+i_face, j, k+neighbouring_cell_index) = 0;
3028 const int j_face = neighbouring_face_first_second_index_from_sign[n_sign_second_dir];
3029 cell_faces_neighbours_corrected_min_max_bool[1](i, j+j_face, k+neighbouring_cell_index) = 0;
3030 }
3031 break;
3032 default:
3033 break;
3034 }
3035 }
3036 }
3037}
3038
3039
3041{
3042 /*
3043 * Be careful, the ijk_intersection class is not sorting the faces the same way
3044 */
3045 const int faces_dir[6] = FACES_DIR;
3046
3047 int nb_faces_to_correct = 0;
3048 const int nb_faces_to_correct_from_ijk = intersection_ijk_cell_->get_nb_faces_to_correct();
3049
3050 IntVect& i_pure_face_to_correct = ijk_faces_to_correct_[0];
3051 IntVect& j_pure_face_to_correct = ijk_faces_to_correct_[1];
3052 IntVect& k_pure_face_to_correct = ijk_faces_to_correct_[2];
3053 IntVect& dir_pure_face_to_correct = ijk_faces_to_correct_[3];
3054
3055 i_pure_face_to_correct.resize(nb_faces_to_correct_from_ijk);
3056 j_pure_face_to_correct.resize(nb_faces_to_correct_from_ijk);
3057 k_pure_face_to_correct.resize(nb_faces_to_correct_from_ijk);
3058 dir_pure_face_to_correct.resize(nb_faces_to_correct_from_ijk);
3059 /*
3060 * TODO: Make a clever loop
3061 */
3062 for (int i=0; i<ijk_intersections_subproblems_indices_.size_array(); i++)
3063 {
3064 const int intersection_ijk_cell_index = ijk_intersections_subproblems_indices_[i];
3065 const int ijk_indices_i = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 0);
3066 const int ijk_indices_j = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 1);
3067 const int ijk_indices_k = (*intersection_ijk_cell_)(intersection_ijk_cell_index, 2);
3068 for (int l=0; l<6; l++)
3069 {
3070 const int is_neighbour_pure_liquid = intersection_ijk_cell_->get_ijk_pure_face_neighbours(intersection_ijk_cell_index, l);
3071 if (is_neighbour_pure_liquid)
3072 {
3073 const int ii_f = NEIGHBOURS_FACES_I[l];
3074 const int jj_f = NEIGHBOURS_FACES_J[l];
3075 const int kk_f = NEIGHBOURS_FACES_K[l];
3076 i_pure_face_to_correct[nb_faces_to_correct] = (ijk_indices_i + ii_f);
3077 j_pure_face_to_correct[nb_faces_to_correct] = (ijk_indices_j + jj_f);
3078 k_pure_face_to_correct[nb_faces_to_correct] = (ijk_indices_k + kk_f);
3079 dir_pure_face_to_correct[nb_faces_to_correct] = faces_dir[l];
3080 nb_faces_to_correct++;
3081 }
3082 }
3083 }
3084 assert(nb_faces_to_correct== nb_faces_to_correct_from_ijk);
3085 const int convective_fluxes_size = convective_fluxes_.size();
3086 const int diffusive_fluxes_size = diffusive_fluxes_.size();
3087 if (convective_fluxes_size > 0)
3088 assert(convective_fluxes_size == nb_faces_to_correct);
3089 if (diffusive_fluxes_size > 0)
3090 assert(diffusive_fluxes_size == nb_faces_to_correct);
3091}
3092
3094 FixedVector<FixedVector<std::vector<ArrOfInt>,3>,2>& index_face_ij_flux_xyz_remaining_global,
3095 FixedVector<std::vector<ArrOfDouble>, 3>& flux_xyz,
3096 FixedVector<std::vector<ArrOfDouble>, 3>& flux_xyz_remaining_global,
3097 FixedVector<std::map<int, int>, 3>& flux_frontier_map,
3098 const DoubleVect& fluxes_subgrid,
3099 const int ini_index)
3100
3101{
3102
3103 const IJK_Field_double& indicator = ref_ijk_ft_->get_interface().I();
3104 const int nb_i_layer = indicator.ni();
3105 const int nb_j_layer = indicator.nj();
3106 const int nb_k_layer = indicator.nk();
3107
3108 // Make it parallel
3109 const Domaine_IJK& dom_ns = ref_ijk_ft_->get_interface().I().get_domaine();
3110 const int offset_i = dom_ns.get_offset_local(0);
3111 const int offset_j = dom_ns.get_offset_local(1);
3112 const int offset_k = dom_ns.get_offset_local(2);
3113
3114 const int nb_i_layer_tot = dom_ns.get_nb_elem_tot(0);
3115 const int nb_j_layer_tot = dom_ns.get_nb_elem_tot(1);
3116 const int nb_k_layer_tot = dom_ns.get_nb_elem_tot(2);
3117
3118 const int seq = (Process::nproc() == 1);
3119
3120 FixedVector<std::vector<ArrOfInt>,3>& dummy_int_array = index_face_ij_flux_xyz[0];
3121 FixedVector<std::vector<ArrOfDouble>,3>& dummy_double_array = flux_xyz;
3122
3124 flux_xyz,
3125 dummy_int_array,
3126 dummy_double_array,
3127 dummy_double_array,
3128 ini_index);
3129 if (!seq)
3130 {
3131 initialise_any_cell_neighbours_indices_to_correct_with_flux(index_face_ij_flux_xyz_remaining_global,
3132 flux_xyz_remaining_global,
3133 dummy_int_array,
3134 dummy_double_array,
3135 dummy_double_array,
3136 ini_index,
3137 1);
3138 }
3139
3140 IntVect& i_pure_face_to_correct = ijk_faces_to_correct_[0];
3141 IntVect& j_pure_face_to_correct = ijk_faces_to_correct_[1];
3142 IntVect& k_pure_face_to_correct = ijk_faces_to_correct_[2];
3143 IntVect& dir_pure_face_to_correct = ijk_faces_to_correct_[3];
3144 const int nb_fluxes = ijk_faces_to_correct_[0].size();
3145
3146 for (int i_flux=0; i_flux < nb_fluxes; i_flux++)
3147 {
3148 const int k = k_pure_face_to_correct[i_flux];
3149 const int dir = dir_pure_face_to_correct[i_flux];
3150 const double flux = fluxes_subgrid[i_flux];
3151 flux_xyz[dir][k].append_array(flux);
3152 const int i = i_pure_face_to_correct[i_flux];
3153 const int j = j_pure_face_to_correct[i_flux];
3154 if (!ini_index)
3155 {
3156 index_face_ij_flux_xyz[0][dir][k].append_array(i);
3157 index_face_ij_flux_xyz[1][dir][k].append_array(j);
3158 }
3159 switch(dir)
3160 {
3161 case DIRECTION_I:
3162 if (seq)
3163 {
3164 if (i == 0)
3165 {
3166 if (!ini_index)
3167 {
3168 index_face_ij_flux_xyz[0][dir][k].append_array(nb_i_layer);
3169 index_face_ij_flux_xyz[1][dir][k].append_array(j);
3170 }
3171 flux_xyz[dir][k].append_array(fluxes_subgrid[i_flux]);
3172
3173 }
3174 if (i == nb_i_layer)
3175 {
3176 if (!ini_index)
3177 {
3178 index_face_ij_flux_xyz[0][dir][k].append_array(0);
3179 index_face_ij_flux_xyz[1][dir][k].append_array(j);
3180 }
3181 flux_xyz[dir][k].append_array(fluxes_subgrid[i_flux]);
3182 }
3183 }
3184 else
3185 {
3186 if (i == 0 || i == nb_i_layer)
3187 {
3188 const int i_global = (i + offset_i); // % (ni_tot + 1);
3189 const int j_global = (j + offset_j); // % nj_tot;
3190 const int k_global = (k + offset_k); // % nj_tot;
3191 const int index_flux = flux_xyz[dir][k].size_array() - 1;
3192
3193 if (!ini_index)
3194 {
3195 const int linear_index = get_linear_index_local(i, j, k, 0);
3196 flux_frontier_map[dir][linear_index] = index_flux;
3197 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(i_global);
3198 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(j_global);
3199 }
3200 /*
3201 * Overall periodicity
3202 */
3203 if (i_global == 0)
3204 {
3205 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(nb_i_layer_tot);
3206 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(j_global);
3207 }
3208 if (i_global == nb_i_layer_tot)
3209 {
3210 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(i_global);
3211 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(j_global);
3212 }
3213 flux_xyz_remaining_global[dir][k_global].append_array(flux);
3214 if (i_global == 0 || i_global == nb_i_layer_tot)
3215 flux_xyz_remaining_global[dir][k_global].append_array(flux);
3216 }
3217 }
3218 break;
3219 case DIRECTION_J:
3220 if (seq)
3221 {
3222 if (j == 0)
3223 {
3224 if (!ini_index)
3225 {
3226 index_face_ij_flux_xyz[0][dir][k].append_array(i);
3227 index_face_ij_flux_xyz[1][dir][k].append_array(nb_j_layer);
3228 }
3229 flux_xyz[dir][k].append_array(fluxes_subgrid[i_flux]);
3230
3231 }
3232 if (j == nb_j_layer)
3233 {
3234 if (!ini_index)
3235 {
3236 index_face_ij_flux_xyz[0][dir][k].append_array(i);
3237 index_face_ij_flux_xyz[1][dir][k].append_array(0);
3238 }
3239 flux_xyz[dir][k].append_array(fluxes_subgrid[i_flux]);
3240 }
3241 }
3242 else
3243 {
3244 if (j == 0 || j == nb_j_layer)
3245 {
3246 const int i_global = (i + offset_i); // % (ni_tot + 1);
3247 const int j_global = (j + offset_j); // % nj_tot;
3248 const int k_global = (k + offset_k); // % nj_tot;
3249 const int index_flux = flux_xyz[dir][k].size_array() - 1;
3250
3251 if (!ini_index)
3252 {
3253 const int linear_index = get_linear_index_local(i, j, k, 1);
3254 flux_frontier_map[dir][linear_index] = index_flux;
3255 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(i_global);
3256 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(j_global);
3257 }
3258 /*
3259 * Overall periodicity
3260 */
3261 if (j_global == 0)
3262 {
3263 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(i_global);
3264 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(nb_j_layer_tot);
3265 }
3266 if (j_global == nb_j_layer_tot)
3267 {
3268 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(i_global);
3269 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(0);
3270 }
3271
3272 flux_xyz_remaining_global[dir][k_global].append_array(flux);
3273 if (j_global == 0 || j_global == nb_j_layer_tot)
3274 flux_xyz_remaining_global[dir][k_global].append_array(flux);
3275 }
3276 }
3277 break;
3278 case DIRECTION_K:
3279 if (seq)
3280 {
3281 if (k == 0)
3282 {
3283 if (!ini_index)
3284 {
3285 index_face_ij_flux_xyz[0][dir][nb_k_layer_tot].append_array(i);
3286 index_face_ij_flux_xyz[1][dir][nb_k_layer_tot].append_array(j);
3287 }
3288 flux_xyz[dir][nb_k_layer].append_array(fluxes_subgrid[i_flux]);
3289 }
3290 if (k == nb_k_layer)
3291 {
3292 if (!ini_index)
3293 {
3294 index_face_ij_flux_xyz[0][dir][0].append_array(i);
3295 index_face_ij_flux_xyz[1][dir][0].append_array(j);
3296 }
3297 flux_xyz[dir][0].append_array(fluxes_subgrid[i_flux]);
3298 }
3299 }
3300 else
3301 {
3302 if (k == 0 || k == nb_k_layer)
3303 {
3304 const int i_global = (i + offset_i); // % (ni_tot + 1);
3305 const int j_global = (j + offset_j); // % nj_tot;
3306 const int k_global = (k + offset_k); // % nj_tot;
3307 const int index_flux = flux_xyz[dir][k].size_array() - 1;
3308
3309 if (!ini_index)
3310 {
3311 const int linear_index = get_linear_index_local(i, j, k, 2);
3312 flux_frontier_map[dir][linear_index] = index_flux;
3313 index_face_ij_flux_xyz_remaining_global[0][dir][k_global].append_array(i_global);
3314 index_face_ij_flux_xyz_remaining_global[1][dir][k_global].append_array(j_global);
3315 }
3316 /*
3317 * Overall periodicity
3318 */
3319 if (k_global == 0)
3320 {
3321 index_face_ij_flux_xyz_remaining_global[0][dir][nb_k_layer_tot].append_array(i_global);
3322 index_face_ij_flux_xyz_remaining_global[1][dir][nb_k_layer_tot].append_array(j_global);
3323 }
3324 if (k_global == nb_k_layer_tot)
3325 {
3326 index_face_ij_flux_xyz_remaining_global[0][dir][0].append_array(i_global);
3327 index_face_ij_flux_xyz_remaining_global[1][dir][0].append_array(0);
3328 }
3329 flux_xyz_remaining_global[dir][k_global].append_array(flux);
3330 if (k_global == 0)
3331 flux_xyz_remaining_global[dir][nb_k_layer_tot].append_array(flux);
3332 if (k_global == nb_k_layer_tot)
3333 flux_xyz_remaining_global[dir][0].append_array(flux);
3334 }
3335 }
3336 break;
3337 }
3338 }
3339
3340 receive_fluxes_from_frontier_on_procs(index_face_ij_flux_xyz_remaining_global,
3341 flux_xyz_remaining_global,
3342 ini_index);
3343 if (debug_)
3344 Cerr << "Fluxes have been received from procs" << finl;
3345 combine_fluxes_from_frontier_on_procs(index_face_ij_flux_xyz,
3346 index_face_ij_flux_xyz_remaining_global,
3347 flux_xyz,
3348 flux_xyz_remaining_global,
3349 flux_frontier_map,
3350 ini_index);
3351 if (debug_)
3352 Cerr << "Fluxes have been combined on procs" << finl;
3353}
3354
3355int Corrige_flux_FT_temperature_subresolution::get_linear_index_local(const int& i, const int& j, const int& k, const int& dir)
3356{
3357 int nb_i_layer_tot = ref_ijk_ft_->get_interface().I().ni();
3358 int nb_j_layer_tot = ref_ijk_ft_->get_interface().I().nj();
3359 if (dir == 0)
3360 nb_i_layer_tot += 1;
3361 if (dir == 1)
3362 nb_j_layer_tot += 1;
3363 return (i + j * (nb_i_layer_tot) + k * (nb_i_layer_tot * nb_j_layer_tot));
3364}
3365
3366int Corrige_flux_FT_temperature_subresolution::get_linear_index_global(const int& i, const int& j, const int& k, const int& dir)
3367{
3368 const Domaine_IJK& geometry = ref_ijk_ft_->get_interface().I().get_domaine();
3369 int nb_i_layer_tot = geometry.get_nb_elem_tot(0);
3370 int nb_j_layer_tot = geometry.get_nb_elem_tot(1);
3371 if (dir == 0)
3372 nb_i_layer_tot += 1;
3373 if (dir == 1)
3374 nb_j_layer_tot += 1;
3375 return (i + j * (nb_i_layer_tot) + k * (nb_i_layer_tot * nb_j_layer_tot));
3376}
3377
3378
3379void Corrige_flux_FT_temperature_subresolution::receive_fluxes_from_frontier_on_procs(FixedVector<FixedVector<std::vector<ArrOfInt>,3>,2>& index_face_ij_flux_xyz_remaining_global,
3380 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz_remaining_global,
3381 const int ini_index)
3382{
3383 const int nb_procs = Process::nproc();
3384 const int proc_num = Process::me();
3386 {
3387 if (nb_procs > 1)
3388 {
3389 FixedVector<std::vector<ArrOfInt>, 3> overall_numerotation_array;
3390 FixedVector<std::vector<ArrOfInt>, 3> start_indices_array;
3391 FixedVector<ArrOfInt, 3> size_array_global_array;
3392
3393 int c, k, l;
3394 for (c=0; c<3; c++)
3395 {
3396 const int size_k_layers = (int) flux_xyz_remaining_global[c].size();
3397 overall_numerotation_array[c].resize(size_k_layers);
3398 start_indices_array[c].resize(size_k_layers);
3399 size_array_global_array[c] = ArrOfInt(size_k_layers);
3400 for (k=0; k<size_k_layers; k++)
3401 {
3402 const int size_array = flux_xyz_remaining_global[c][k].size_array();
3403 int size_array_global = size_array;
3404 size_array_global = Process::check_int_overflow(Process::mp_sum(size_array_global));
3405 size_array_global_array[c](k) = size_array_global;
3406 overall_numerotation_array[c][k] = ArrOfInt(nb_procs);
3407 start_indices_array[c][k] = ArrOfInt(nb_procs);
3408 overall_numerotation_array[c][k](proc_num) = size_array;
3409 mp_sum_for_each_item(overall_numerotation_array[c][k]);
3410 for (l=1; l<overall_numerotation_array[c][k].size_array(); l++)
3411 start_indices_array[c][k](l) = start_indices_array[c][k](l-1) + overall_numerotation_array[c][k](l-1);
3412 // start_indices_array[c][k](l) = start_indices_array[c][k](l-1) + start_indices_array[c][k](l-1);
3413
3414 if (debug_)
3415 {
3416 Cerr << "Size array" << size_array << finl;
3417 Cerr << "Size array global" << size_array_global << finl;
3418 Cerr << "Overall_numerotation" << overall_numerotation_array[c][k](0) << "-" << overall_numerotation_array[c][k](1) << finl;
3419 }
3420
3421 ArrOfDouble local_flux_values_tmp;
3422 ArrOfDouble& global_flux_values_tmp = flux_xyz_remaining_global[c][k];
3423
3424 local_flux_values_tmp = global_flux_values_tmp;
3425 global_flux_values_tmp.resize(size_array_global);
3426 global_flux_values_tmp *= 0.;
3427
3428 for (l=0; l<local_flux_values_tmp.size_array(); l++)
3429 global_flux_values_tmp(start_indices_array[c][k](proc_num) + l) = local_flux_values_tmp(l);
3430
3431 mp_sum_for_each_item(global_flux_values_tmp);
3432
3433 }
3434 }
3435
3436 if (!ini_index)
3437 {
3438 for (c=0; c<3; c++)
3439 {
3440 const int size_k_layers = (int) index_face_ij_flux_xyz_remaining_global[0][c].size();
3441 for (k=0; k<size_k_layers; k++)
3442 {
3443 const int size_array_global = size_array_global_array[c](k);
3444 ArrOfInt& start_indices = start_indices_array[c][k];
3445 ArrOfInt local_indices_i_tmp;
3446 ArrOfInt local_indices_j_tmp;
3447
3448 ArrOfInt& global_indices_i_tmp = index_face_ij_flux_xyz_remaining_global[0][c][k];
3449 ArrOfInt& global_indices_j_tmp = index_face_ij_flux_xyz_remaining_global[1][c][k];
3450
3451 local_indices_i_tmp = global_indices_i_tmp;
3452 local_indices_j_tmp = global_indices_j_tmp;
3453
3454 global_indices_i_tmp.resize(size_array_global);
3455 global_indices_j_tmp.resize(size_array_global);
3456
3457 global_indices_i_tmp *= 0;
3458 global_indices_j_tmp *= 0;
3459
3460 for (l=0; l<local_indices_i_tmp.size_array(); l++)
3461 {
3462 global_indices_i_tmp(start_indices(proc_num) + l) = local_indices_i_tmp(l);
3463 global_indices_j_tmp(start_indices(proc_num) + l) = local_indices_j_tmp(l);
3464 }
3465 mp_sum_for_each_item(global_indices_i_tmp);
3466 mp_sum_for_each_item(global_indices_j_tmp);
3467 }
3468 }
3469 }
3470 }
3471 }
3472}
3473
3475 FixedVector<FixedVector<std::vector<ArrOfInt>,3>,2>& index_face_ij_flux_xyz_remaining_global,
3476 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz,
3477 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz_remaining_global,
3478 FixedVector<std::map<int, int>, 3>& flux_frontier_map,
3479 const int ini_index)
3480{
3481
3482 const IJK_Field_double& indicator = ref_ijk_ft_->get_interface().I();
3483 const int ni = indicator.ni();
3484 const int nj = indicator.nj();
3485 const int nk = indicator.nk();
3486
3487 const Domaine_IJK& dom_ns = ref_ijk_ft_->get_interface().I().get_domaine();
3488 const int offset_i = dom_ns.get_offset_local(0);
3489 const int offset_j = dom_ns.get_offset_local(1);
3490 const int offset_k = dom_ns.get_offset_local(2);
3491
3492 FixedVector<std::map<int, int>, 3> multiple_flux_values_k;
3493 FixedVector<std::map<int, int>, 3> multiple_flux_values_count;
3494 FixedVector<std::map<int, double>, 3> multiple_flux_values_sum;
3495
3496 FixedVector<std::map<int, int>, 3> flux_frontier_map_tmp = flux_frontier_map;
3497
3498 for (int dir=0; dir<3; dir++)
3499 {
3500 const int size_k_layers = (int) index_face_ij_flux_xyz_remaining_global[0][dir].size();
3501 for (int k_global=0; k_global<size_k_layers; k_global++)
3502 {
3503 const int global_size_array = index_face_ij_flux_xyz_remaining_global[0][dir][k_global].size_array();
3504 for (int l=0; l<global_size_array; l++)
3505 {
3506 const int i_global = index_face_ij_flux_xyz_remaining_global[0][dir][k_global](l);
3507 const int j_global = index_face_ij_flux_xyz_remaining_global[1][dir][k_global](l);
3508 const double flux = flux_xyz_remaining_global[dir][k_global](l);
3509 const int i = i_global - offset_i;
3510 const int j = j_global - offset_j;
3511 const int k = k_global - offset_k;
3512 const int ni_max = (dir == 0 ? ni + 1 : ni);
3513 const int nj_max = (dir == 1 ? nj + 1 : nj);
3514 const int nk_max = (dir == 2 ? nk + 1 : nk);
3515 if ((0 <= i && i < ni_max) && (0 <= j && j < nj_max) && (0 <= k && k < nk_max))
3516 {
3517 const int linear_local_index = get_linear_index_local(i, j, k, dir);
3518 const int non_zero_value_local = (int) flux_frontier_map_tmp[dir].count(linear_local_index);
3519 if (!non_zero_value_local)
3520 {
3521 // Add flux at the end of the list if new
3522 flux_xyz[dir][k].append_array(flux);
3523 if (!ini_index)
3524 {
3525 index_face_ij_flux_xyz[0][dir][k].append_array(i);
3526 index_face_ij_flux_xyz[1][dir][k].append_array(j);
3527 }
3528 const int local_size_array = flux_xyz[dir][k].size_array() - 1;
3529 flux_frontier_map_tmp[dir][linear_local_index] = local_size_array;
3530 multiple_flux_values_count[dir][linear_local_index] = 1;
3531 multiple_flux_values_sum[dir][linear_local_index] = flux;
3532 multiple_flux_values_k[dir][linear_local_index] = k;
3533 }
3534 else
3535 {
3536 const int non_zero_local_count = (int) multiple_flux_values_count[dir].count(linear_local_index);
3537 // const int array_index = (int) flux_frontier_map_[dir][linear_local_index];
3538 if (!non_zero_local_count)
3539 {
3540 /*
3541 * The processor will see its value twice
3542 */
3543 // multiple_flux_values_count[dir][linear_local_index] = 1;
3544 // multiple_flux_values_sum[dir][linear_local_index] = (*(fluxes[dir]))[k](array_index);
3545 multiple_flux_values_count[dir][linear_local_index] = 0;
3546 multiple_flux_values_sum[dir][linear_local_index] = 0.;
3547 multiple_flux_values_k[dir][linear_local_index] = k;
3548 }
3549 multiple_flux_values_count[dir][linear_local_index] += 1;
3550 multiple_flux_values_sum[dir][linear_local_index] += flux;
3551 }
3552 }
3553 }
3554 }
3555 for(std::map<int,double>::iterator it=multiple_flux_values_sum[dir].begin(); it!=multiple_flux_values_sum[dir].end(); ++it)
3556 {
3557 const int key = it->first;
3558 const double val_flux_sum = it->second;
3559 const double count_val = (double) multiple_flux_values_count[dir][key];
3560 const int array_index = (int) flux_frontier_map_tmp[dir][key];
3561 const int k_local = (int) multiple_flux_values_k[dir][key];
3562 flux_xyz[dir][k_local](array_index) = val_flux_sum / count_val;
3563 }
3564 }
3565 if (ini_index)
3566 flux_frontier_map = flux_frontier_map_tmp;
3567}
3568
3570 FixedVector<std::vector<std::vector<ArrOfDouble>>,3>& flux_xyz,
3571 const int ini_index)
3572{
3573 const int nb_proc = Process::nproc();
3574 int c;
3575 if(!ini_index)
3576 {
3577 for(int l=0; l<2; l++)
3578 for (c=0; c<3; c++)
3579 index_face_ij_flux_xyz[l][c].resize(nb_proc);
3580 }
3581 for (c=0; c<3; c++)
3582 flux_xyz[c].resize(nb_proc);
3583}
3584
3586 FixedVector<FixedVector<std::vector<ArrOfInt>,3>,2>& index_face_i_flux_x_remaining_global,
3587 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz,
3588 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz_remaining_global,
3589 const int ini_index)
3590{
3591
3592}
3593
3594void Corrige_flux_FT_temperature_subresolution::store_cell_faces_corrected(IJK_Field_vector3_int& cell_faces_corrected_bool,
3595 IJK_Field_vector3_double& cell_faces_corrected_convective,
3596 IJK_Field_vector3_double& cell_faces_corrected_diffusive)
3597{
3598 int counter = 0;
3600 {
3602 store_any_cell_faces_corrected(cell_faces_corrected_bool,
3604 cell_faces_corrected_convective,
3607 counter);
3608// else
3609// store_any_cell_faces_corrected(cell_faces_corrected_bool,
3610// index_face_ij_flux_xyz_neighbours_min_max_faces_sorted_,
3611// cell_faces_corrected_convective,
3612// convective_fluxes_,
3613// convective_diffusive_flux_xyz_min_max_faces_sorted_[0],
3614// counter);
3615 counter ++;
3616 }
3618 {
3620 store_any_cell_faces_corrected(cell_faces_corrected_bool,
3622 cell_faces_corrected_diffusive,
3625 counter);
3626// else
3627// store_any_cell_faces_corrected(cell_faces_corrected_bool,
3628// index_face_ij_flux_xyz_neighbours_min_max_faces_sorted_,
3629// cell_faces_corrected_convective,
3630// convective_fluxes_,
3631// convective_diffusive_flux_xyz_min_max_faces_sorted_[1],
3632// counter);
3633 }
3634}
3635
3636void Corrige_flux_FT_temperature_subresolution::store_any_cell_faces_corrected(IJK_Field_vector3_int& cell_faces_corrected_bool,
3637 FixedVector<FixedVector<std::vector<ArrOfInt>,3>,2>& index_face_ij_flux_xyz_sorted,
3638 IJK_Field_vector3_double& cell_faces_corrected,
3639 const DoubleVect& fluxes,
3640 FixedVector<std::vector<ArrOfDouble>,3>& flux_xyz,
3641 const int counter)
3642{
3643 for (int c=0; c<3; c++)
3644 {
3645 if (!counter)
3646 cell_faces_corrected_bool[c].data() = 0.;
3647 cell_faces_corrected[c].data() = 0.;
3648 }
3649 if (Process::nproc() == 1)
3650 {
3651 IntVect& i_pure_face_to_correct = ijk_faces_to_correct_[0];
3652 IntVect& j_pure_face_to_correct = ijk_faces_to_correct_[1];
3653 IntVect& k_pure_face_to_correct = ijk_faces_to_correct_[2];
3654 IntVect& dir_pure_face_to_correct = ijk_faces_to_correct_[3];
3655 const int nb_fluxes = ijk_faces_to_correct_[0].size();
3656 int i,j,k;
3657 for (int i_flux=0; i_flux < nb_fluxes; i_flux++)
3658 {
3659 i = i_pure_face_to_correct[i_flux];
3660 j = j_pure_face_to_correct[i_flux];
3661 k = k_pure_face_to_correct[i_flux];
3662 const int dir = dir_pure_face_to_correct[i_flux];
3663 if (!counter)
3664 cell_faces_corrected_bool[dir](i,j,k) += 1;
3665 cell_faces_corrected[dir](i,j,k) += fluxes[i_flux];
3666 }
3667 }
3668 else
3669 {
3670 const IJK_Field_double& indicator = ref_ijk_ft_->get_interface().I();
3671 const int ni = indicator.ni();
3672 const int nj = indicator.nj();
3673 const int nk = indicator.nk();
3674
3675 for (int dir=0; dir<3; dir++)
3676 {
3677 const int size_k = (int) index_face_ij_flux_xyz_sorted[0][dir].size();
3678 for (int k=0; k<size_k; k++)
3679 {
3680 const int size_array = index_face_ij_flux_xyz_sorted[0][dir][k].size_array();
3681 for (int l=0; l<size_array; l++)
3682 {
3683 const int i = index_face_ij_flux_xyz_sorted[0][dir][k](l);
3684 const int j = index_face_ij_flux_xyz_sorted[1][dir][k](l);
3685 const double flux = flux_xyz[dir][k](l);
3686 /*
3687 * Offset for verification (not at the exact places of the fluxes)!
3688 */
3689 // const int i_display = (i >= ni ? i-1: i);
3690 // const int j_display = (j >= nj ? j-1: j);
3691 // const int k_display = (k >= nk ? k-1: k);
3692 const int i_display = (i >= ni ? i: i);
3693 const int j_display = (j >= nj ? j: j);
3694 const int k_display = (k >= nk ? k: k);
3695 if (!counter)
3696 cell_faces_corrected_bool[dir](i_display, j_display, k_display) += 1;
3697 cell_faces_corrected[dir](i_display,j_display,k_display) += flux;
3698 }
3699 }
3700 }
3701 }
3702}
3703
3705{
3707 {
3708 Cerr << "Sort the thermal convective fluxes" << finl;
3715 flux_init_);
3716 Cerr << "Thermal Sub-resolutions convective fluxes are now sorted" << finl;
3717 flux_init_ = 1;
3718 }
3720 {
3721 Cerr << "Sort the thermal diffusive fluxes" << finl;
3728 flux_init_);
3729 Cerr << "Thermal Sub-resolutions diffusive fluxes are now sorted" << finl;
3730 flux_init_ = 1;
3731 }
3732 flux_init_ = 0;
3733}
3734
3736 const int k_layer,
3737 const int dir)
3738{
3740 {
3745 k_layer,
3746 dir);
3747 else
3751 k_layer,
3752 dir);
3753 }
3754}
3755
3757 const int k_layer,
3758 const int dir)
3759{
3761 {
3766 k_layer,
3767 dir);
3768 else
3772 k_layer,
3773 dir);
3774 }
3775}
3776
3778 FixedVector<FixedVector<std::vector<ArrOfInt>,3>,2>& index_face_ij_flux_xyz_sorted,
3779 FixedVector<std::vector<ArrOfDouble>,3>& subgrid_fluxes_xyz,
3780 const int k_layer,
3781 const int dir)
3782{
3783 const int nb_fluxes = subgrid_fluxes_xyz[dir][k_layer].size_array();
3784 for (int i_flux=0; i_flux<nb_fluxes; i_flux++)
3785 {
3786 const int i=index_face_ij_flux_xyz_sorted[0][dir][k_layer][i_flux];
3787 const int j=index_face_ij_flux_xyz_sorted[1][dir][k_layer][i_flux];
3788 const double flux_ij = subgrid_fluxes_xyz[dir][k_layer][i_flux];
3789 (*flux)(i,j,0) = flux_ij;
3790 }
3791}
3792
3794 DoubleVect& fluxes_unique,
3795 IntVect& pure_face_unique,
3796 const int known_unique)
3797{
3798 // FixedVector<DoubleVect, 3>& pure_face_to_correct = intersection_ijk_cell_->get_set_ijk_pure_face_to_correct();
3799 FixedVector<IntVect, 4>& pure_face_to_correct = ijk_faces_to_correct_;
3800 const int nb_fluxes = fluxes.size();
3801 fluxes_unique.reset();
3802 int i;
3803 if (known_unique)
3804 {
3805 const int size_face_unique = pure_face_unique.size();
3806 for (i=0; i<size_face_unique; i++)
3807 {
3808 fluxes_unique.append_array(fluxes(pure_face_unique(i)));
3809 }
3810 }
3811 else
3812 {
3813 DoubleVect shared_face;
3814 shared_face.reset();
3815 for (i=0; i<nb_fluxes; i++)
3816 {
3817 const int i_f = pure_face_to_correct[0](i);
3818 const int j_f = pure_face_to_correct[1](i);
3819 const int k_f = pure_face_to_correct[2](i);
3820 for (int j=i; j<nb_fluxes; j++)
3821 if (i != j)
3822 {
3823 const int i_ff = pure_face_to_correct[0](j);
3824 const int j_ff = pure_face_to_correct[1](j);
3825 const int k_ff = pure_face_to_correct[2](j);
3826 if ((i_f==i_ff) && (j_f==j_ff) && (k_f==k_ff))
3827 {
3828 if (shared_face.size() == 0)
3829 shared_face.append_array(i);
3830 shared_face.append_array(j);
3831 }
3832 }
3833 /*
3834 * Take the closest portion
3835 */
3836 const int nb_duplicates = shared_face.size();
3837 int min_dist_index = 0;
3838 double min_dist = dist_[i];
3839 for (int j=1; j<nb_duplicates; j++)
3840 if (min_dist > dist_[j])
3841 {
3842 min_dist = dist_[j];
3843 min_dist_index = j;
3844 }
3845 pure_face_unique.append_array(min_dist_index);
3846 fluxes_unique.append_array(fluxes(min_dist_index));
3847 }
3848 }
3849}
: class Corrige_flux_FT API pour modifier un champ de flux à partir de donnees à l'interface....
Intersection_Interface_ijk_cell * intersection_ijk_cell_
virtual void initialize_with_subproblems(const Domaine_IJK &splitting, const IJK_Field_double &field, const IJK_Interfaces &interfaces, const Probleme_FTD_IJK_base &ijk_ft, Intersection_Interface_ijk_face &intersection_ijk_face, Intersection_Interface_ijk_cell &intersection_ijk_cell, IJK_One_Dimensional_Subproblems &thermal_local_subproblems)
void initialize_with_subproblems(const Domaine_IJK &splitting, const IJK_Field_double &field, const IJK_Interfaces &interfaces, const Probleme_FTD_IJK_base &ijk_ft, Intersection_Interface_ijk_face &intersection_ijk_face, Intersection_Interface_ijk_cell &intersection_ijk_cell, IJK_One_Dimensional_Subproblems &thermal_subproblems) override
void get_add_replace_flux_value(IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective_diffusive_flux, const int &dir, const int &i, const int &j, const int &k, double &convective_diffusive_flux, const double &replace_weighting_values)
void store_any_cell_faces_corrected(IJK_Field_vector3_int &cell_faces_corrected_bool, FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_sorted, IJK_Field_vector3_double &cell_faces_corrected, const DoubleVect &fluxes, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz, const int counter)
void compute_cell_neighbours_faces_indices_to_correct(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool, IJK_Field_vector3_double &cell_faces_neighbours_corrected_velocity_temperature, IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective, IJK_Field_vector3_double &cell_faces_neighbours_corrected_diffusive, IJK_Field_vector3_double &neighbours_weighting_colinearity) override
bool compute_cell_neighbours_thermal_convective_fluxes_face_centre(double &convective_flux, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k, const int &temperature=0)
void compute_cell_neighbours_thermal_fluxes_face_centre_discrete_integral(double &flux, const int fluxes_type, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k)
void combine_all_fluxes_from_outisde_frontier_on_procs(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool, IJK_Field_vector3_double &cell_faces_neighbours_corrected_velocity_temperature, IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective, IJK_Field_vector3_double &cell_faces_neighbours_corrected_diffusive, IJK_Field_vector3_double &neighbours_weighting_colinearity)
void redistribute_indices_fluxes_by_k_layers(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_i_flux_x, FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_i_flux_x_remaining_global, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz_remaining_global, const int ini_index)
void corrige_flux_diff_faceIJ(IJK_Field_local_double *const flux, const int k_layer, const int dir) override
void compute_cell_neighbours_faces_indices_for_spherical_correction(const int &n_iter_distance) override
void replace_cell_neighbours_thermal_convective_diffusive_fluxes_faces(const IJK_Field_vector3_int &cell_faces_neighbours_corrected_min_max_bool, const IJK_Field_vector3_int &cell_faces_neighbours_corrected_all_bool, const IJK_Field_vector3_double &cell_faces_neighbours_fluxes_corrected, const int &fluxes_type) override
FixedVector< FixedVector< std::vector< ArrOfDouble >, 3 >, 2 > convective_diffusive_flux_xyz_sorted_
void sort_ijk_intersections_subproblems_indices_fluxes_by_k_layers(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz, FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_remaining_global, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz_remaining_global, FixedVector< std::map< int, int >, 3 > &flux_frontier_map, const DoubleVect &fluxes_subgrid, const int ini_index)
void combine_fluxes_from_frontier_on_procs(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz, FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_remaining_global, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz_remaining_global, FixedVector< std::map< int, int >, 3 > &flux_frontier_map, const int ini_index)
void initialise_any_cell_neighbours_indices_to_correct(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_faces_sorted, const int global_indices=0)
void clear_std_vectors_array_of_double(std::vector< ArrOfDouble > &values_to_clear)
int get_linear_index_local(const int &i, const int &j, const int &k, const int &dir)
void remove_min_max_ijk_reachable_fluxes_discontinuous(const IJK_Field_vector3_int &cell_faces_neighbours_corrected_all_bool, FixedVector< IJK_Field_local_int, 3 > &cell_faces_neighbours_corrected_min_max_bool)
void check_pure_fluxes_duplicates(const DoubleVect &fluxes, DoubleVect &fluxes_unique, IntVect &pure_face_unique, const int known_unique)
void receive_fluxes_from_frontier_on_procs(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_remaining_global, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz_remaining_global, const int ini_index)
int get_linear_index_global(const int &i, const int &j, const int &k, const int &dir)
FixedVector< FixedVector< std::vector< ArrOfDouble >, 3 >, 2 > convective_diffusive_flux_xyz_remaining_global_sorted_
void replace_temperature_cell_centre_neighbours(IJK_Field_double &temperature, IJK_Field_double &temperature_neighbours, IJK_Field_int &neighbours_weighting, IJK_Field_double &neighbours_weighting_colinearity) const override
void store_cell_faces_corrected(IJK_Field_vector3_int &cell_faces_corrected_bool, IJK_Field_vector3_double &cell_faces_corrected_convective, IJK_Field_vector3_double &cell_faces_corrected_diffusive) override
void compute_thermal_fluxes_face_centre(DoubleVect &fluxes, const int fluxes_type, const int &last_flux)
bool compute_cell_neighbours_diffusive_fluxes_to_correct(double &diffusive_flux, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k)
FixedVector< std::vector< ArrOfDouble >, 3 > colinearity_flux_xyz_neighbours_all_faces_remaining_global_sorted_
void initialise_fixed_vectors(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &fixed_vectors, const int nb_k_layer)
FixedVector< std::vector< ArrOfDouble >, 3 > temperature_flux_all_faces_remaining_global_sorted_
FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > index_face_ij_flux_xyz_remaining_global_sorted_
void compute_cell_neighbours_thermal_convective_fluxes_face_centre_discrete_integral(double &convective_flux, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k)
void corrige_flux_faceIJ(IJK_Field_local_double *const flux, const int k_layer, const int dir) override
void compute_flux_neighbours_on_procs(const int &index_i_neighbour_global, const int &index_j_neighbour_global, const int &index_k_neighbour_global, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k, const double &convective_flux_computed=0, const double &diffusive_flux_computed=0)
FixedVector< std::vector< ArrOfInt >, 3 > weighting_flux_xyz_neighbours_all_faces_remaining_global_sorted_
void clear_std_vectors_array_of_int(std::vector< ArrOfInt > &indices_to_clear)
DoubleVect compute_thermal_flux_face_centre_discrete_integral(const int fluxes_type, const int &index_subproblem, const double &dist, const int &dir, const int &l=-1)
bool compute_cell_neighbours_thermal_fluxes_face_centre(double &flux, const int fluxes_type, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k, const int &temperature=0)
void smooth_temperature_cell_centre_neighbours(IJK_Field_double &temperature, ArrOfInt &corrected_values, ArrOfInt &out_of_bounds_corrected_values, ArrOfDouble &out_of_bounds_values, IJK_Field_double &distance) const
void initialise_any_cell_neighbours_indices_to_correct_with_flux(FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_faces_sorted, FixedVector< std::vector< ArrOfDouble >, 3 > &fluxes, FixedVector< std::vector< ArrOfInt >, 3 > &weighting_flux_xyz_faces_sorted, FixedVector< std::vector< ArrOfDouble >, 3 > &colinearity_flux_xyz_faces_sorted, FixedVector< std::vector< ArrOfDouble >, 3 > &temperature_flux_xyz_faces_sorted, const bool &ini_index, const int global_indices=0, const int weighting_colinearity=0)
double compute_thermal_flux_face_centre(const int fluxes_type, const int &index_subproblem, const double &dist, const int &dir, bool &valid_val, const int &l=-1, const int &index_i=INVALID_INDEX, const int &index_j=INVALID_INDEX, const int &index_k=INVALID_INDEX, const int &temperature=0)
void set_zero_temperature_increment(IJK_Field_double &d_temperature) const override
void compute_min_max_ijk_any_reachable_fluxes(const IJK_Field_vector3_int &cell_faces_neighbours_corrected_all_bool, const IJK_Field_int &neighbours_temperature_to_correct, IJK_Field_vector3_int &cell_faces_neighbours_corrected_min_max_bool, const int &max_flux_per_dir, const int &check_cell_center_neighbour, const int &remove_external_neighbour_values, IJK_Field_int &neighbours_temperature_to_correct_trimmed) override
void replace_cell_neighbours_thermal_fluxes_faces(const IJK_Field_vector3_int &cell_faces_neighbours_corrected_min_max_bool, const IJK_Field_vector3_int &cell_faces_neighbours_corrected_all_bool, const IJK_Field_vector3_double &cell_faces_neighbours_fluxes_corrected, FixedVector< std::vector< ArrOfDouble >, 3 > &flux_xyz, const int counter)
void compute_temperature_cell_centre_neighbours(IJK_Field_double &temperature_neighbours, IJK_Field_int &neighbours_weighting, IJK_Field_double &neighbours_weighting_colinearity) override
void compute_cell_neighbours_mixed_cell_faces_any_field(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool, IJK_Field_local_double &cell_faces_neighbours_corrected_field, IJK_Field_vector3_double &cell_faces_neighbours_corrected_field_mixed_cell)
FixedVector< FixedVector< std::vector< ArrOfDouble >, 3 >, 2 > convective_diffusive_flux_all_faces_remaining_global_sorted_
void corrige_flux_faceIJ_any_flux(IJK_Field_local_double *const flux, FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > &index_face_ij_flux_xyz_sorted, FixedVector< std::vector< ArrOfDouble >, 3 > &subgrid_fluxes_xyz, const int k_layer, const int dir)
void complete_neighbours_and_weighting_colinearity(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool, IJK_Field_vector3_double &cell_faces_neighbours_corrected_velocity_temperature, IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective, IJK_Field_vector3_double &cell_faces_neighbours_corrected_diffusive, IJK_Field_vector3_double &neighbours_weighting_colinearity, const int &compute_fluxes_values)
void sort_ini_end_arrays(ArrOfInt &indices_found_transition_ini, ArrOfInt &indices_found_transition_end, ArrOfInt &indices_found_ini, ArrOfInt &indices_found_end, FixedVector< ArrOfInt, 2 > &indices_sorted, const int &max_n_layer)
bool compute_cell_neighbours_convective_fluxes_to_correct(double &convective_flux, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k, const int &temperature=0)
void compute_cell_neighbours_fluxes_to_correct(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool, IJK_Field_vector3_double &neighbours_weighting_colinearity, IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective, IJK_Field_vector3_double &cell_faces_neighbours_corrected_diffusive, IJK_Field_vector3_double &cell_faces_neighbours_corrected_velocity_temperature, const int &subproblem_index, const int &index_i, const int &index_j, const int &index_k, const double &dist, const int &dir, const double &colinearity, const int &compute_fluxes_values, double &convective_flux, double &diffusive_flux)
void compute_min_max_ijk_reachable_fluxes(const IJK_Field_vector3_int &cell_faces_neighbours_corrected_all_bool, const IJK_Field_int &neighbours_temperature_to_correct, IJK_Field_vector3_int &cell_faces_neighbours_corrected_min_max_bool, const int &max_flux_per_dir, const int &check_cell_center_neighbour, const int &remove_external_neighbour_values, IJK_Field_int &neighbours_temperature_to_correct_trimmed) override
void associate_thermal_problems(IJK_One_Dimensional_Subproblems &thermal_subproblems)
FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > index_face_ij_flux_xyz_sorted_
bool compute_cell_neighbours_thermal_diffusive_fluxes_face_centre(double &diffusive_flux, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k)
FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > index_face_ij_flux_xyz_neighbours_min_max_faces_sorted_
bool identify_wrong_predicted_values(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool, IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective_diffusive_flux, const int &dir, const int &index_i, const int &index_j, const int &index_k, double &convective_diffusive_flux)
void initialise_fixed_vector(FixedVector< std::vector< ArrOfInt >, 3 > &fixed_vector, const int nb_k_layer)
void complete_thermal_fluxes_face_centre(const int &fluxes_correction_conservations) override
FixedVector< std::map< int, int >, 3 > flux_outside_frontier_all_map_
void combine_temperature_cell_centre_neighbours_from_procs(IJK_Field_double &temperature_neighbours, IJK_Field_int &neighbours_weighting, IJK_Field_double &neighbours_weighting_colinearity, const int &ni, const int &nj, const int &nk, const int &offset_i, const int &offset_j, const int &offset_k)
FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > index_face_ij_flux_xyz_neighbours_all_faces_sorted_
void initialise_any_cell_neighbours_indices_to_correct_on_processors(FixedVector< FixedVector< std::vector< std::vector< ArrOfInt > >, 3 >, 2 > &index_face_ij_flux_xyz, FixedVector< std::vector< std::vector< ArrOfDouble > >, 3 > &flux_xyz, const int ini_index)
void compute_cell_neighbours_thermal_diffusive_fluxes_face_centre_discrete_integral(double &diffusive_flux, const int &subproblem_index, const double &dist, const int &dir, const double &colinearity, const int &index_i, const int &index_j, const int &index_k)
void correct_flux_spherical(Simd_double &a, Simd_double &b, const int &i, const int &j, const int &k_layer, const int dir) override
FixedVector< FixedVector< std::vector< ArrOfDouble >, 3 >, 2 > convective_diffusive_flux_xyz_min_max_faces_sorted_
void remove_non_overlapping_fluxes_values(const FixedVector< ArrOfInt, 2 > &indices_sorted, const FixedVector< ArrOfInt, 2 > &indices_fluxes_sorted, ArrOfInt &indices_to_remove, ArrOfInt &indices_fluxes_to_remove, int &index_bis, int &index_ter, const int &dir)
void compute_temperature_cell_centre_neighbours_on_procs(const double &temperature_neighbours, const double &neighbours_weighting_colinearity, const int &index_i_neighbour_global, const int &index_j_neighbour_global, const int &index_k_neighbour_global)
FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > index_face_ij_flux_xyz_neighbours_diag_faces_sorted_
void initialise_fixed_vector_values(FixedVector< std::vector< ArrOfDouble >, 3 > &fixed_vector_values, const int nb_k_layer)
FixedVector< FixedVector< std::vector< ArrOfInt >, 3 >, 2 > index_face_ij_flux_xyz_neighbours_all_faces_remaining_global_sorted_
void compute_temperature_cell_centre(IJK_Field_double &temperature) const override
void compute_thermal_fluxes_face_centre_discrete_integral(DoubleVect &fluxes, const int fluxes_type)
void compute_cell_neighbours_mixed_cell_faces_indices_to_correct(IJK_Field_vector3_int &cell_faces_neighbours_corrected_bool_mixed_cell, IJK_Field_vector3_double &cell_faces_neighbours_corrected_velocity_temperature, IJK_Field_vector3_double &cell_faces_neighbours_corrected_convective_mixed_cell, IJK_Field_vector3_double &cell_faces_neighbours_corrected_diffusive_mixed_cell, IJK_Field_vector3_double &neighbours_weighting_colinearity_mixed_cell)
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
int get_offset_local(int direction) const
Returns the local offset in requested direction.
int convert_ijk_cell_to_packed(const FixedVector< int, 3 > ijk) const
Converts the ijk index of an element to a cell index.
int get_nb_elem_tot(int direction) const
Returns the total (global) number of mesh cells in requested direction.
FixedVector< int, 3 > convert_packed_to_ijk_cell(int index) const
Convert the local index of an element to a vector with IJK indices.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void allocate(int ni, int nj, int nk, int ghosts, int additional_k_layers=0, int nb_compo=1, bool external_storage=false)
void echange_espace_virtuel(int ghost)
Exchange data over "ghost" number of cells.
const Domaine_IJK & get_domaine() const
: class IJK_Interfaces
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static int check_int_overflow(trustIdType)
Definition Process.cpp:428
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:193
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
Definition Process.cpp:104
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
static int me()
renvoie mon rang dans le groupe de communication courant.
Definition Process.cpp:125
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
virtual void reset()
Definition TRUSTArray.h:240
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
void resize(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTArray.h:156
_SIZE_ size() const
Definition TRUSTVect.tpp:45
void reset() override
met l'objet dans l'etat obtenu par le constructeur par defaut.
Definition TRUSTVect.h:189
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91