TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Associer.cpp
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#include <Associer.h>
17#include <Nom.h>
18
19Implemente_instanciable(Associer,"Associer|Associate",Interprete);
20// XD associate interprete associer INHERITS_BRACE This interpretor allows one object to be associated with another. The
21// XD_CONT order of the two objects in this instruction is not important. The object objet_2 is associated to objet_1 if
22// XD_CONT this makes sense; if not either objet_1 is associated to objet_2 or the program exits with error because it
23// XD_CONT cannot execute the Associate (Associer) instruction. For example, to calculate water flow in a pipe, a
24// XD_CONT Pb_Hydraulique type object needs to be defined. But also a Domaine type object to represent the pipe, a time
25// XD_CONT discretization object (Scheme_euler_explicit for ex.). These two objects must then be associated with the
26// XD_CONT problem.
27// XD attr objet_1 chaine objet_1 REQ Objet_1
28// XD attr objet_2 chaine objet_2 REQ Objet_2
29
30
32{
33 return Interprete::printOn(os);
34}
35
37{
38 return Interprete::readOn(is);
39}
40
41/*! @brief Main function of the Associer interpreter: associate two objects.
42 *
43 * We try to associate 1 to 2 and 2 to 1, causes an
44 * error if this fails.
45 *
46 * @param (Entree& is) an input stream, from which the names of the objects to be associated are read
47 * @return (Entree&) the modified input stream
48 * @throws we cannot associate obj1 and obj2
49 */
51{
52 // Parameter acquisition:
53 Nom nom1, nom2;
54 is >> nom1 >> nom2;
55 if(is.eof())
56 {
57 Cerr << "Reading problem in Associer" << finl;
58 exit();
59 }
60 Objet_U& ob1=objet(nom1);
61 Objet_U& ob2=objet(nom2);
62 int association12,association21;
63 association12=ob1.associer_(ob2);
64 association21=0;
65 if (!association12)
66 {
67 association21=ob2.associer_(ob1);
68 if(!association21)
69 {
70 Cerr << "Impossible to associate objects '" << ob1.que_suis_je()
71 << "' and '" << ob2.que_suis_je() << "'" << finl;
72 exit();
73 }
74 }
75
76 if (association12==2)
77 {
78 Cerr << finl;
79 Cerr << "The medium " << ob2.que_suis_je() << " \"" << nom2
80 << "\" can not be associated to the problem" << finl;
81 Cerr << ob1.que_suis_je() << " \"" << nom1
82 << "\" because it is already associated with another problem." << finl;
83 exit();
84 }
85 if (association21==2)
86 {
87 Cerr << finl;
88 Cerr << "The medium " << ob1.que_suis_je() << " \"" << nom1
89 << "\" can not be associated to the problem" << finl;
90 Cerr << ob2.que_suis_je() << " \"" << nom2
91 << "\" because it is already associated with another problem." << finl;
92 exit();
93 }
94
95 return is;
96}
Associer class, Interprete that associates two objects obj1 and obj2:
Definition Associer.h:31
Entree & interpreter(Entree &) override
Main function of the Associer interpreter: associate two objects.
Definition Associer.cpp:50
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual int eof()
Definition Entree.cpp:256
Base class for "interpreter" objects.
Definition Interprete.h:38
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:71
virtual int associer_(Objet_U &)
Associates the Objet_U with another Objet_U. Virtual method to override.
Definition Objet_U.cpp:200
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52