TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Champs_compris.cpp
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#include <Champs_compris.h>
17#include <Champ_base.h>
18#include <IJK_Field.h>
19
20template<typename FIELD_TYPE>
21const FIELD_TYPE& Champs_compris_T<FIELD_TYPE>::get_champ(const Motcle& motcle) const
22{
23 assert(motcle!="??");
24 auto item = liste_champs_.find(motcle.getString());
25 if (item != liste_champs_.end()) return item->second;
26 throw std::runtime_error(std::string("Field ") + motcle.getString() + std::string(" not found !"));
27}
28
29template<typename FIELD_TYPE>
30bool Champs_compris_T<FIELD_TYPE>::has_champ(const Motcle& motcle, OBS_PTR(FIELD_TYPE)& ref_champ) const
31{
32 assert(motcle!="??");
33 auto item = liste_champs_.find(motcle.getString());
34 if (item != liste_champs_.end())
35 {
36 ref_champ = item->second;
37 return true;
38 }
39 return false;
40}
41
42template<typename FIELD_TYPE>
44{
45 assert(motcle!="??");
46 auto item = liste_champs_.find(motcle.getString());
47 return item != liste_champs_.end();
48}
49
50template<typename FIELD_TYPE>
52{
53 Noms nom_compris;
54 for (auto const& champ : liste_champs_)
55 nom_compris.add(champ.first);
56 return nom_compris;
57}
58
59template<typename FIELD_TYPE>
60void Champs_compris_T<FIELD_TYPE>::ajoute_champ(const FIELD_TYPE& champ)
61{
62 // Adding a field name referring to champ inside liste_champs_ dictionnary
63 auto add_key = [&](const Nom& n)
64 {
65 if (n == "??")
66 {
67 Cerr << "Champs_compris_T<FIELD_TYPE>::ajoute_champ : trying to add a field with no name" << finl;
69 }
70 std::string nom_champ = n.getString();
71 std::string upperCase = nom_champ, lowerCase = nom_champ;
72 std::transform(nom_champ.begin(), nom_champ.end(), upperCase.begin(), ::toupper);
73 std::transform(nom_champ.begin(), nom_champ.end(), lowerCase.begin(), ::tolower);
74
75// [ABN] I agree with the below, but this breaks too many TRUST cases for now.
76// To be reviewed at some point.
77
78// if (has_champ(upperCase) || has_champ(lowerCase))
79// {
80// //TODO(teo.boutin) maybe check pointers equality before giving an error.
81// Cerr << "Champs_compris_T<FIELD_TYPE>::ajoute_champ : trying to add a field twice : " << upperCase << finl;
82// Process::exit();
83// }
84 liste_champs_[upperCase] = champ;
85 liste_champs_[lowerCase] = champ;
86 };
87
88 // Adding field with its name...
89 add_key(champ.le_nom());
90
91 // ...its synonyms...
92 const Noms& syno = champ.get_synonyms();
93 int nb_syno = syno.size();
94 for (int s = 0; s < nb_syno; s++)
95 add_key(syno[s]);
96
97 // ...and its components
98 int nb_composantes = champ.nb_comp();
99 for (int i = 0; i < nb_composantes; i++)
100 if(i < champ.noms_compo().size() and champ.nom_compo(i) != "??")
101 {
102 // teo.boutin: champ.nom_compo(i) could check outside the range of the list of name, resulting in valgrind error (not initialized).
103 // Added an assert in Field_Base, but maybe wrong solution
104 // Finally check for bound here. I still think the asser should be added back
105 add_key(champ.nom_compo(i));
106 }
107
108 Cerr<<"Champs_compris_T<FIELD_TYPE>::ajoute_champ " << champ.le_nom() <<finl;
109}
110
111// Explicit instanciantion
112template class Champs_compris_T<Champ_base>;
114
classe Champs_compris Represente un champ compris par un objet de type Equation, Milieu,
const Noms liste_noms_compris() const
std::unordered_map< std::string, OBS_PTR(FIELD_TYPE)> liste_champs_
const FIELD_TYPE & get_champ(const Motcle &nom) const
void ajoute_champ(const FIELD_TYPE &champ)
bool has_champ(const Motcle &nom, OBS_PTR(FIELD_TYPE)&ref_champ) const
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455