TrioCFD 1.9.9_beta
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 Base class for diffused inputs: the master processor reads data from get_entree_master() and broadcasts it
24 *
25 * to all processors.
26 * Warning: the methods operator>>(), get(), eof(), good() and bad()
27 * must be called simultaneously on all processors.
28 * Derived classes must reimplement get_entree_master().
29 * The get_entree_master() method must return a reference to the input
30 * that serves as source on the master processor; it is never called
31 * on other processors.
32 * Warning: the source input must have 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()
Returns error_action_ for this input (allows modifying it and restoring the previous value afterwards...
Definition Entree.cpp:371
virtual Entree & get_entree_master()=0
int get(int *ob, std::streamsize n) override
void set_check_types(bool flag) override
Calls get_entree_master().
Entree & operator>>(int &ob) override
Lec_Diffuse_base(const Lec_Diffuse_base &)=default
Lec_Diffuse_base()
Does nothing (protected constructor since this is a base class).
void set_bin(bool bin) override
Calls get_entree_master().
void set_diffuse(bool diffuse) override
Sets the diffuse flag for this input stream.
Lec_Diffuse_base & operator=(const Lec_Diffuse_base &)
Error.
friend class Entree
Definition Objet_U.h:71
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82