TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
EOS_to_TRUST_generique.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 <EOS_to_TRUST_generique.h>
17
18// iterator index !
19#define i_it std::distance(TT.begin(), &val)
20
21void EOS_to_TRUST_generique::set_fluide_generique(const char *const model_name, const char *const fluid_name)
22{
23#ifdef HAS_EOS
24 fluide = new NEPTUNE::EOS(model_name, fluid_name);
25 fluide->set_error_handler(handler); // Set error handler
26#else
27 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
28 throw;
29#endif
30}
31
32int EOS_to_TRUST_generique::tppi_get_single_property_T_(Loi_en_T enum_prop, const SpanD P, const SpanD T, SpanD R, int ncomp, int id) const
33{
34#ifdef HAS_EOS
35 assert((int )T.size() == ncomp * (int )P.size() && (int )T.size() == ncomp * (int )R.size());
36 if (ncomp == 1)
37 return compute_eos_field(P, T, R, EOS_prop_en_T[(int)enum_prop][0], EOS_prop_en_T[(int)enum_prop][1]);
38 else /* attention stride */
39 {
40 VectorD temp_((int)P.size());
41 SpanD TT(temp_);
42 for (auto& val : TT) val = T[i_it * ncomp + id];
43 return compute_eos_field(P, TT, R, EOS_prop_en_T[(int)enum_prop][0], EOS_prop_en_T[(int)enum_prop][1]);
44 }
45#else
46 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
47 throw;
48#endif
49}
50
51int EOS_to_TRUST_generique::tppi_get_single_property_h_(Loi_en_h enum_prop, const SpanD P, const SpanD H, SpanD R, int ncomp, int id) const
52{
53#ifdef HAS_EOS
54 assert((int )H.size() == ncomp * (int )P.size() && (int )H.size() == ncomp * (int )R.size());
55 assert (ncomp == 1);
56 if (ncomp == 1)
57 return compute_eos_field_h(P, H, R, EOS_prop_en_h[(int)enum_prop][0], EOS_prop_en_h[(int)enum_prop][1]);
58 else /* attention stride */
59 {
60 VectorD temp_((int)P.size());
61 SpanD TT(temp_);
62 for (auto& val : TT) val = H[i_it * ncomp + id];
63 return compute_eos_field_h(P, TT, R, EOS_prop_en_h[(int)enum_prop][0], EOS_prop_en_h[(int)enum_prop][1]);
64 }
65#else
66 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
67 throw;
68#endif
69}
70
71int EOS_to_TRUST_generique::tppi_get_beta_ph(const SpanD P, const SpanD H, SpanD R, int ncomp, int id) const
72{
73 Cerr << "EOS_to_TRUST_generique::" << __func__ << " is not implemented ! Use EOS_to_TRUST_generique::tppi_get_beta_pT or call the 911 for help !! " << finl;
74 throw;
75}
76
77int EOS_to_TRUST_generique::tppi_get_beta_pT(const SpanD P, const SpanD T, SpanD R, int ncomp, int id) const
78{
79#ifdef HAS_EOS
80 assert((int )T.size() == ncomp * (int )R.size() && (int )T.size() == ncomp * (int )P.size());
81 VectorD drho_dt_((int)P.size()), rho_((int)P.size()), temp_((int)P.size());
82 SpanD drho_dt(drho_dt_), rho(rho_), TT(temp_);
83 int err1_, err2_;
84 for (auto& val : TT) val = T[i_it * ncomp + id];
85 err1_ = compute_eos_field(P, TT, rho, EOS_prop_en_T[(int) Loi_en_T::RHO][0], EOS_prop_en_T[(int) Loi_en_T::RHO][1]);
86 err2_ = compute_eos_field(P, TT, drho_dt, EOS_prop_en_T[(int) Loi_en_T::RHO_DT][0], EOS_prop_en_T[(int) Loi_en_T::RHO_DT][1]);
87 // fill beta ...
88 for (int i = 0; i < (int) R.size(); i++) R[i] = drho_dt[i] / rho[i];
89 return std::max(err1_, err2_);
90#else
91 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
92 throw;
93#endif
94}
95
96// methodes particulieres par application pour gagner en performance : utilisees dans Pb_Multiphase (pour le moment !)
97#ifdef HAS_EOS
98int EOS_to_TRUST_generique::tppi_get_all_properties_T_(const MSpanD input , NEPTUNE::EOS_Fields& flds_out, NEPTUNE::EOS_Error_Field& ferr, int ncomp, int id) const
99{
100 const SpanD T = input.at("temperature"), P = input.at("pressure");
101 if (ncomp == 1)
102 {
103 NEPTUNE::EOS_Field T_fld("Temperature", "T", (int) T.size(), (double*) T.begin()), P_fld("Pressure", "P", (int) P.size(), (double*) P.begin());
104 return (int)fluide->compute(P_fld, T_fld, flds_out, ferr);
105 }
106 else /* attention stride */
107 {
108 VectorD temp_((int) P.size());
109 SpanD TT(temp_);
110 for (auto &val : TT) val = T[i_it * ncomp + id];
111
112 NEPTUNE::EOS_Field T_fld("Temperature", "T", (int) TT.size(), (double*) TT.begin()), P_fld("Pressure", "P", (int) P.size(), (double*) P.begin());
113 return (int)fluide->compute(P_fld, T_fld, flds_out, ferr);
114 }
115}
116
117int EOS_to_TRUST_generique::tppi_get_all_properties_h_(const MSpanD input , NEPTUNE::EOS_Fields& flds_out, NEPTUNE::EOS_Error_Field& ferr, int ncomp, int id) const
118{
119 const SpanD T = input.at("enthalpie"), P = input.at("pressure");
120 if (ncomp == 1)
121 {
122 NEPTUNE::EOS_Field T_fld("Enthalpy", "h", (int) T.size(), (double*) T.begin()), P_fld("Pressure", "P", (int) P.size(), (double*) P.begin());
123 return (int)fluide->compute(P_fld, T_fld, flds_out, ferr);
124 }
125 else /* attention stride */
126 {
127 VectorD temp_((int) P.size());
128 SpanD TT(temp_);
129 for (auto &val : TT) val = T[i_it * ncomp + id];
130
131 NEPTUNE::EOS_Field T_fld("Enthalpy", "h", (int) TT.size(), (double*) TT.begin()), P_fld("Pressure", "P", (int) P.size(), (double*) P.begin());
132 return (int)fluide->compute(P_fld, T_fld, flds_out, ferr);
133 }
134}
135#endif
136
137int EOS_to_TRUST_generique::tppi_get_CPMLB_pb_multiphase_pT(const MSpanD input, MLoiSpanD prop, int ncomp, int id) const
138{
139#ifdef HAS_EOS
140 assert((int )prop.size() == 4 && (int )input.size() == 2);
141
142 const SpanD T = input.at("temperature"), P = input.at("pressure");
143 assert((int )T.size() == ncomp * (int )P.size());
144
145 Tk_(T); // XXX : ATTENTION : need Kelvin
146
147 SpanD B = prop.at(Loi_en_T::BETA);
148
149 const int nb_out = 5; /* 5 variables to fill */
150 VectorD drho_dt_((int) P.size()), rho_((int) P.size());
151 SpanD drho_dt(drho_dt_), rho(rho_);
152 NEPTUNE::ArrOfInt tmp((int)P.size());
153 NEPTUNE::EOS_Error_Field ferr(tmp);
154 NEPTUNE::EOS_Fields flds_out(nb_out);
155 int i_out = 0;
156
157 for (auto& itr : prop)
158 {
159 assert((int )T.size() == ncomp * (int )itr.second.size());
160 Loi_en_T prop_ = itr.first;
161 SpanD span_ = itr.second;
162 if (prop_ != Loi_en_T::BETA)
163 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_T[(int) prop_][0], EOS_prop_en_T[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
164 else /* pour beta on recalcule sans appel a beta de eos ... */
165 {
166 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_T[(int) Loi_en_T::RHO][0], EOS_prop_en_T[(int) Loi_en_T::RHO][1], (int) rho.size(), (double*) rho.begin());
167 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_T[(int) Loi_en_T::RHO_DT][0], EOS_prop_en_T[(int) Loi_en_T::RHO_DT][1], (int) drho_dt.size(), (double*) drho_dt.begin());
168 }
169 }
170
171 int err_ = tppi_get_all_properties_T_(input, flds_out, ferr, ncomp, id);
172
173 /* beta */
174 for (int i = 0; i < (int) B.size(); i++) B[i] = drho_dt[i] / rho[i];
175
176 // XXX : ATTENTION : need to put back T in C
177 Tc_(T);
178 return err_;
179#else
180 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
181 throw;
182#endif
183}
184
185int EOS_to_TRUST_generique::tppi_get_all_pb_multiphase_pT(const MSpanD input, MLoiSpanD inter, MLoiSpanD bord, int ncomp, int id) const
186{
187#ifdef HAS_EOS
188 assert( (int )input.size() == 4 && (int )inter.size() == 6 && (int )bord.size() == 2);
189
190 const SpanD T = input.at("temperature"), P = input.at("pressure"), bT = input.at("bord_temperature"), bP = input.at("bord_pressure");
191 assert ((int )bT.size() == ncomp * (int )bP.size() && (int )T.size() == ncomp * (int )P.size());
192
193 // XXX : ATTENTION : need Kelvin
194 Tk_(T), Tk_(bT);
195
196 const int nb_out = (int )inter.size(), bnb_out = (int )bord.size();
197 NEPTUNE::ArrOfInt tmp((int)P.size()), btmp((int)bP.size());
198 NEPTUNE::EOS_Error_Field ferr(tmp), bferr(btmp);
199 NEPTUNE::EOS_Fields flds_out(nb_out), bflds_out(bnb_out);
200
201 int i_out = 0, bi_out = 0;
202
203 for (auto& itr : bord)
204 {
205 Loi_en_T prop_ = itr.first;
206 SpanD span_ = itr.second;
207 assert((int ) bT.size() == ncomp * (int ) span_.size());
208 bflds_out[bi_out++] = NEPTUNE::EOS_Field(EOS_prop_en_T[(int) prop_][0], EOS_prop_en_T[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
209 }
210
211 for (auto& itr : inter)
212 {
213 Loi_en_T prop_ = itr.first;
214 SpanD span_ = itr.second;
215 assert((int ) T.size() == ncomp * (int ) span_.size());
216 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_T[(int) prop_][0], EOS_prop_en_T[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
217 }
218
219 int err1_ = tppi_get_all_properties_T_( { { "temperature", bT }, { "pressure", bP } }, bflds_out, bferr, ncomp, id); // bords
220 int err2_ = tppi_get_all_properties_T_( { { "temperature", T }, { "pressure", P } }, flds_out, ferr, ncomp, id); // interne
221
222 // XXX : ATTENTION : need to put back T in C
223 Tc_(T), Tc_(bT);
224 return std::max(err1_, err2_);
225#else
226 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
227 throw;
228#endif
229}
230
231int EOS_to_TRUST_generique::tppi_get_all_prop_loi_F5(const MSpanD input, MLoiSpanD_h spans, int ncomp, int id, bool is_liq) const
232{
233#ifdef HAS_EOS
234 assert(ncomp == 1);
235 const SpanD P = input.at("pression"), H = is_liq ? input.at("H_L") : input.at("H_V");
236 int i_out = 0, nb_out = (int) spans.size(), sz = (int) P.size();
237 NEPTUNE::ArrOfInt tmp(sz);
238 NEPTUNE::EOS_Error_Field ferr(tmp);
239 NEPTUNE::EOS_Fields flds_out(nb_out);
240
241 for (auto &itr : spans)
242 {
243 Loi_en_h prop_ = itr.first;
244 SpanD span_ = itr.second;
245 assert(sz == (int ) span_.size());
246 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_h[(int) prop_][0], EOS_prop_en_h[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
247 }
248
249 NEPTUNE::EOS_Field T_fld("Enthalpy", "h", (int) H.size(), (double*) H.begin()), P_fld("Pressure", "P", (int) P.size(), (double*) P.begin());
250 return (int)fluide->compute(P_fld, T_fld, flds_out, ferr);
251
252#else
253 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
254 throw;
255#endif
256}
257
258int EOS_to_TRUST_generique::tppi_get_CPMLB_pb_multiphase_ph(const MSpanD input, MLoiSpanD_h prop, int ncomp, int id) const
259{
260#ifdef HAS_EOS
261 assert((int )prop.size() == 4 && (int )input.size() == 2);
262
263 const SpanD H = input.at("enthalpie"), P = input.at("pressure");
264 if ((int )H.size() != ncomp * (int )P.size()) Process::exit("Ah bon ? NON !");
265
266 const int nb_out = 3; /* 4 variables to fill --- without BETA :: TODO FIXME */
267 NEPTUNE::ArrOfInt tmp((int)P.size());
268 NEPTUNE::EOS_Error_Field ferr(tmp);
269 NEPTUNE::EOS_Fields flds_out(nb_out);
270 int i_out = 0;
271
272 for (auto& itr : prop)
273 {
274 assert((int )H.size() == ncomp * (int )itr.second.size());
275 Loi_en_h prop_ = itr.first;
276 SpanD span_ = itr.second;
277 if (prop_ != Loi_en_h::BETA)
278 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_h[(int) prop_][0], EOS_prop_en_h[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
279 }
280
281 /* beta FIXME */
282 SpanD B = prop.at(Loi_en_h::BETA);
283 for (int i = 0; i < (int) B.size(); i++) B[i] = 0.;
284
285 int err_ = tppi_get_all_properties_h_(input, flds_out, ferr, ncomp, id);
286
287 return err_;
288#else
289 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
290 throw;
291#endif
292}
293
294int EOS_to_TRUST_generique::tppi_get_all_pb_multiphase_ph(const MSpanD input, MLoiSpanD_h inter, MLoiSpanD_h bord, int ncomp, int id) const
295{
296#ifdef HAS_EOS
297 assert( (int )input.size() == 4 && (int )inter.size() == 6 && (int )bord.size() == 2);
298 const SpanD H = input.at("enthalpie"), P = input.at("pressure"), bH = input.at("bord_enthalpie"), bP = input.at("bord_pressure");
299 assert ((int )bH.size() == ncomp * (int )bP.size() && (int )H.size() == ncomp * (int )P.size());
300
301 const int nb_out = (int )inter.size(), bnb_out = (int )bord.size();
302 NEPTUNE::ArrOfInt tmp((int)P.size()), btmp((int)bP.size());
303 NEPTUNE::EOS_Error_Field ferr(tmp), bferr(btmp);
304 NEPTUNE::EOS_Fields flds_out(nb_out), bflds_out(bnb_out);
305
306 int i_out = 0, bi_out = 0;
307
308 for (auto& itr : bord)
309 {
310 Loi_en_h prop_ = itr.first;
311 SpanD span_ = itr.second;
312 assert((int ) bH.size() == ncomp * (int ) span_.size());
313 bflds_out[bi_out++] = NEPTUNE::EOS_Field(EOS_prop_en_h[(int) prop_][0], EOS_prop_en_h[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
314 }
315
316 for (auto& itr : inter)
317 {
318 Loi_en_h prop_ = itr.first;
319 SpanD span_ = itr.second;
320 assert((int ) H.size() == ncomp * (int ) span_.size());
321 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_en_h[(int) prop_][0], EOS_prop_en_h[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
322 }
323
324 int err1_ = tppi_get_all_properties_h_( { { "enthalpie", bH }, { "pressure", bP } }, bflds_out, bferr, ncomp, id); // bords
325 int err2_ = tppi_get_all_properties_h_( { { "enthalpie", H }, { "pressure", P } }, flds_out, ferr, ncomp, id); // interne
326
327 // XXX : put T in C !!
328 SpanD T = inter.at(Loi_en_h::T), bT = bord.at(Loi_en_h::T);
329 Tc_(T), Tc_(bT);
330
331 return std::max(err1_, err2_);
332#else
333 Cerr << "EOS_to_TRUST_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
334 throw;
335#endif
336}
int tppi_get_CPMLB_pb_multiphase_ph(const MSpanD, MLoiSpanD_h, int ncomp=1, int id=0) const override
void set_fluide_generique(const char *const model_name, const char *const fluid_name) override
int tppi_get_CPMLB_pb_multiphase_pT(const MSpanD, MLoiSpanD, int ncomp=1, int id=0) const override
int tppi_get_all_prop_loi_F5(const MSpanD, MLoiSpanD_h, int ncomp=1, int id=0, bool is_liq=true) const override
int tppi_get_all_pb_multiphase_pT(const MSpanD, MLoiSpanD, MLoiSpanD, int ncomp=1, int id=0) const override
int tppi_get_all_pb_multiphase_ph(const MSpanD, MLoiSpanD_h, MLoiSpanD_h, int ncomp=1, int id=0) const override
int tppi_get_beta_ph(const SpanD P, const SpanD H, SpanD R, int ncomp=1, int id=0) const override
int tppi_get_beta_pT(const SpanD P, const SpanD T, SpanD R, int ncomp=1, int id=0) const override
int compute_eos_field(const SpanD P, SpanD res, const char *const pt, const char *const pn, bool is_T=false) const
int compute_eos_field_h(const SpanD P, const SpanD H, SpanD res, const char *const pt, const char *const pn) const
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455