TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champs_compris_IJK.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
17#include <Champs_compris_IJK.h>
18
19
20/** A vectorial field is considered present in the structure if all its three components are there
21 */
23{
24 assert(nom!="??");
25 auto item = liste_champs_vecto_.find(nom.getString());
26 return item != liste_champs_vecto_.end();
27}
28
29const IJK_Field_vector3_double& Champs_compris_IJK::get_champ_vectoriel(const Motcle& nom) const
30{
31 assert(nom != "??");
32 auto item = liste_champs_vecto_.find(nom.getString());
33 if (item != liste_champs_vecto_.end()) return item->second;
34 throw std::runtime_error(std::string("Vectoriel field ") + nom.getString() + std::string(" not found !"));
35}
36
37void Champs_compris_IJK::ajoute_champ_vectoriel(const IJK_Field_vector3_double& champ)
38{
39 // Adding a field name referring to champ inside liste_champs_ dictionnary
40 auto add_key = [&](const Nom& n)
41 {
42 if (n == "??")
43 {
44 Cerr << "Champs_compris_IJK::ajoute_champ_vectoriel : trying to add a field with no name" << finl;
46 }
47 std::string nom_champ = n.getString();
48 std::string upperCase = nom_champ, lowerCase = nom_champ;
49 std::transform(nom_champ.begin(), nom_champ.end(), upperCase.begin(), ::toupper);
50 std::transform(nom_champ.begin(), nom_champ.end(), lowerCase.begin(), ::tolower);
51
52 if (has_champ_vectoriel(upperCase) || has_champ_vectoriel(lowerCase))
53 {
54 //TODO(teo.boutin) maybe check pointers equality before giving an error.
55 Cerr << "Champs_compris_IJK::ajoute_champ_vectoriel : trying to add a field twice : " << upperCase << finl;
57 }
58 liste_champs_vecto_[upperCase] = champ;
59 liste_champs_vecto_[lowerCase] = champ;
60 };
61
62 // Adding field with its name...
63 add_key(champ.le_nom());
64
65 // ...its synonyms...
66 const Noms& syno = champ.get_synonyms();
67 int nb_syno = syno.size();
68 for (int s = 0; s < nb_syno; s++)
69 add_key(syno[s]);
70
71 // ...and its components
72 int nb_composantes = champ.nb_comp();
73 for (int i = 0; i < nb_composantes; i++)
74 ajoute_champ(champ[i]);
75
76 Cerr<<"Champs_compris_IJK::ajoute_champ_vectoriel " << champ.le_nom() <<finl;
77}
78
80{
81 Noms nom_compris;
82 for (auto const& champ : liste_champs_vecto_)
83 nom_compris.add(champ.first);
84 return nom_compris;
85}
86
88{
89 Cerr << "Champs_compris_IJK : start switch old to next" <<finl;
90
91 for (auto& old : liste_champs_)
92 {
93 Nom old_name = old.first;
94 switch_field(old_name, "OLD_");
95 switch_field(old_name, "old_");
96 }
97
98 for (auto& old : liste_champs_vecto_)
99 {
100 Nom old_name = old.first;
101 switch_vector_field(old_name, "OLD_");
102 switch_vector_field(old_name, "old_");
103 }
104
105 Cerr << "Champs_compris_IJK : end switch old to next" <<finl;
106
107
108}
109
110
111void Champs_compris_IJK::switch_field(const Nom& field_name, const Nom& prefix)
112{
113
114 if (field_name.debute_par(prefix))
115 {
116 Nom next_name = field_name.getSuffix(prefix);
117
118
119 auto next = liste_champs_.find(next_name.getString());
120 if (next == liste_champs_.end())
121 {
122 Cerr << "Champs_compris_IJK : field " << next_name << " not found for swapping with " << field_name <<finl;
123 Cerr << "Champs_compris_IJK : Warning: only name fields with prefix OLD_ if they are in IJK_Interface and using the next/old semantic" <<finl;
125 }
126
127 // do the swapping
128 auto ptr = liste_champs_[field_name.getString()];
129 liste_champs_[field_name.getString()]=liste_champs_[next_name.getString()];
130 liste_champs_[next_name.getString()]=ptr;
131
132 // Must rename the fields so they are written in lata with correct name
133 liste_champs_[field_name.getString()]->nommer(field_name);
134 liste_champs_[next_name.getString()]->nommer(next_name);
135
136 Cerr << "Champs_compris_IJK : swapping IJK field " << field_name << " with " << next_name <<finl;
137
138 }
139
140}
141void Champs_compris_IJK::switch_vector_field(const Nom& field_name, const Nom& prefix)
142{
143
144 if (field_name.debute_par(prefix))
145 {
146 Nom next_name = field_name.getSuffix(prefix);
147
148 auto next = liste_champs_vecto_.find(next_name.getString());
149
150 if (next == liste_champs_vecto_.end())
151 {
152 Cerr << "Champs_compris_IJK : field " << next_name << " not found for swapping with " << field_name <<finl;
153 Cerr << "Champs_compris_IJK : Warning: only name fields with prefix OLD_ if they are in IJK_Interface and using the next/old semantic" <<finl;
155 }
156
157 // do the swapping
158 auto ptr = liste_champs_vecto_[field_name.getString()];
159 liste_champs_vecto_[field_name.getString()]=liste_champs_vecto_[next_name.getString()];
160 liste_champs_vecto_[next_name.getString()]=ptr;
161
162 // Must rename the fields so they are written in lata with correct name
163 liste_champs_vecto_[field_name.getString()]->nommer(field_name);
164 liste_champs_vecto_[next_name.getString()]->nommer(next_name);
165
166 Cerr << "Champs_compris_IJK : swapping IJK field vector " << field_name << " with " << next_name <<finl;
167
168 }
169}
170
172{
173 Noms nom_compris;
174 for (auto const& champ : liste_champs_)
175 nom_compris.add(champ.first);
176 return nom_compris;
177}
bool has_champ_vectoriel(const Motcle &nom) const
const Noms liste_noms_compris() const
const IJK_Field_vector3_double & get_champ_vectoriel(const Motcle &nom) const
void ajoute_champ_vectoriel(const IJK_Field_vector3_double &champ)
const Noms liste_noms_compris_vectoriel() const
std::unordered_map< std::string, OBS_PTR(IJK_Field_double)> liste_champs_
void ajoute_champ(const IJK_Field_double &champ)
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 Nom getSuffix(const char *const) const
Definition Nom.cpp:281
virtual int debute_par(const char *const n) const
Definition Nom.cpp:319
virtual int find(const char *const n) const
Definition Nom.cpp:314
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