TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Check_espace_virtuel.h
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Check_espace_virtuel_H
17#define Check_espace_virtuel_H
18
19#include <Comm_Group.h>
20#include <TRUSTVect.h>
21
22// Returns 1 if the virtual space of v is up to date, 0 otherwise
23int check_espace_virtuel_vect(const DoubleVect& v);
24int check_espace_virtuel_vect(const IntVect& v);
25void assert_invalide_items_non_calcules(DoubleVect& v, double valeur = 0.);
26
27template <typename _TYPE_>
28extern void remplir_items_non_calcules_(TRUSTVect<_TYPE_>& v, _TYPE_ valeur);
29
30/*! @brief Fills the "non-computed items" of the array with an invalid value.
31 *
32 * These are all items not listed in v.get_md_vector().valeurs().get_blocs_items_to_compute(). (items not computed by default vector operations, generally the virtual items)
33 * It is recommended to apply this method at the end of functions that do not return an up-to-date virtual space (using declare_espace_virtuel_invalide(...))
34 * so as to trigger an error if the virtual space is used.
35 *
36 */
37template<typename _TYPE_>
38inline void remplir_items_non_calcules(TRUSTVect<_TYPE_>& v, _TYPE_ valeur = 0)
39{
40 remplir_items_non_calcules_(v, valeur);
41}
42
43/*! @brief In comm_check_enabled() mode, checks if the virtual space of the vector is up to date; if not, calls exit().
44 *
45 * This test is only performed in comm_check_enabled() mode because it requires communications.
46 *
47 */
48template<typename _TYPE_>
49inline void assert_espace_virtuel_vect(const TRUSTVect<_TYPE_>& v)
50{
52 {
53 if (! check_espace_virtuel_vect(v))
54 {
55 Cerr << "Fatal error in assert_espace_virtuel_vect: virtual space of this vector is not up to date." << finl;
58 }
59 }
60}
61
62/*! @brief When compiled without NDEBUG or when running with check_enabled flag, fills all "not computed" items with an invalid value (ie, items that are not VECT_REAL_ITEMS, usually, these are the virtual items).
63 *
64 * You should call this method whenever you compute some field values but you don't compute or update the virtual space.
65 *
66 */
67template<typename _TYPE_>
68inline void declare_espace_virtuel_invalide(TRUSTVect<_TYPE_>& v)
69{
70 const _TYPE_ valeur = (std::is_same<_TYPE_,double>::value) ? -98765.4321 : -1999999999;
71#ifdef NDEBUG
73 remplir_items_non_calcules(v, valeur);
74#else
75 remplir_items_non_calcules(v, valeur);
76#endif
77}
78
79#endif /* Check_espace_virtuel_H */
static int check_enabled()
Definition Comm_Group.h:154
static void barrier()
Synchronizes all processors in the current group (waits until all processors have reached the barrier...
Definition Process.cpp:133
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466