TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Lec_Diffuse_base.h
1/****************************************************************************
2* Copyright (c) 2026, 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
17#ifndef Lec_Diffuse_base_included
18#define Lec_Diffuse_base_included
19
20#include <communications.h>
21#include <EFichier.h>
22
23/*! @brief Classe de base des entrees diffusees: le processeur maitre lit les donnees dans la classe get_entree_master() et les diffuse
24 *
25 * sur tous les processeurs.
26 * Attention, les methodes operator>>(), get(), eof(), good() et bad()
27 * doivent etre appelees simultanement sur tous les processeurs.
28 * Les classes derivees doivent reimplementer get_entree_master().
29 * La methode get_entree_master() doit renvoyer une reference a l'entree
30 * qui sert de source sur le processeur maitre, elle n'est jamais appellee
31 * sur les autres processeurs.
32 * Attention: l'entree source doit avoir set_error_action(ERROR_CONTINUE)
33 *
34 */
35
36// Since 1.7.0 version, Lec_Diffuse_base class inherits EFichier class not Entree class
38{
39 Declare_base_sans_constructeur(Lec_Diffuse_base);
40public:
41 using Entree::operator>>;
42
43 Entree& operator>>(int& ob) override;
44 Entree& operator>>(long& ob) override;
45 Entree& operator>>(long long& ob) override;
46 Entree& operator>>(float& ob) override;
47 Entree& operator>>(double& ob) override;
48
49 int get(int *ob, std::streamsize n) override;
50 int get(long *ob, std::streamsize n) override;
51 int get(long long *ob, std::streamsize n) override;
52 int get(float *ob, std::streamsize n) override;
53 int get(double *ob, std::streamsize n) override;
54 int get(char *buf, std::streamsize bufsize) override;
55
56 int eof() override;
57 int good() override;
58 int fail() override;
59
60 void set_bin(bool bin) override;
61 void set_check_types(bool flag) override;
62
63 void set_diffuse(bool diffuse) override;
64
65protected:
69 virtual Entree& get_entree_master() = 0;
70
71private:
72 template <typename _TYPE_>
73 int get_template(_TYPE_ *ob, std::streamsize n);
74
75 template <typename _TYPE_>
76 Entree& operator_template(_TYPE_&ob);
77};
78
79template <typename _TYPE_>
80int Lec_Diffuse_base::get_template(_TYPE_ *ob, std::streamsize n)
81{
82 int ok = 0;
84 {
86 assert(is.get_error_action() == ERROR_CONTINUE);
87 ok = is.get(ob, n);
88 }
89 else if (!diffuse_)
90 {
91 Cerr << "Lec_Diffuse_base::get(...) can't be used with diffuse_=0 on non master process." << finl;
93 }
94 if (diffuse_)
95 {
96 envoyer_broadcast(ok, 0);
97 assert(n < std::numeric_limits<int>::max());
98 if (ok)
99 envoyer_broadcast_array(ob, (int)n, 0);
100 }
101 return error_handle(!ok);
102}
103
104template <typename _TYPE_>
105Entree& Lec_Diffuse_base::operator_template(_TYPE_& ob)
106{
107 int ok = 0;
109 {
111 assert(is.get_error_action() == ERROR_CONTINUE);
112 is >> ob;
113 ok = is.good();
114 }
115 else if (!diffuse_)
116 {
117 Cerr << "Lec_Diffuse_base::operator>> can't be used with diffuse_=0 on non master process." << finl;
119 }
120 if (diffuse_)
121 {
122 envoyer_broadcast(ok, 0);
123 if (ok)
124 envoyer_broadcast(ob, 0);
125 }
126 error_handle(!ok);
127 return *this;
128}
129
130#endif
EFichier(const char *name, IOS_OPEN_MODE mode=ios::in)
Definition EFichier.cpp:20
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual int good()
Definition Entree.cpp:270
int error_handle(int fail_flag)
Definition Entree.h:105
virtual int get(int *ob, std::streamsize n)
Definition Entree.cpp:222
bool diffuse_
Definition Entree.h:114
@ ERROR_CONTINUE
Definition Entree.h:93
Error_Action get_error_action()
renvoie error_action_ pour cette entree (permet de la modifier et de restaurer ensuite la valeur ante...
Definition Entree.cpp:374
virtual Entree & get_entree_master()=0
int get(int *ob, std::streamsize n) override
void set_check_types(bool flag) override
appelle get_entree_master().
Entree & operator>>(int &ob) override
Lec_Diffuse_base(const Lec_Diffuse_base &)=default
Lec_Diffuse_base()
ne fait rien (constructeur protege car c'est une classe de base)
void set_bin(bool bin) override
appelle get_entree_master().
void set_diffuse(bool diffuse) override
ToDo TMA : commenter.
Lec_Diffuse_base & operator=(const Lec_Diffuse_base &)
erreur
friend class Entree
Definition Objet_U.h:76
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Definition Process.cpp:86