TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
EOS_to_TRUST_Sat_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_Sat_generique.h>
17
18
19// iterator index !
20#define i_it std::distance(TT.begin(), &val)
21#define i_it2 std::distance(RR.begin(), &val)
22
23void EOS_to_TRUST_Sat_generique::set_saturation_generique(const char *const model_name, const char *const fluid_name)
24{
25#ifdef HAS_EOS
26 fluide = new NEPTUNE::EOS(model_name, fluid_name);
27// assert(fluide->info_fluidequa() == fluid_name);
28 fluide->set_error_handler(handler); // Set error handler
29#else
30 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
31 throw;
32#endif
33}
34
35int EOS_to_TRUST_Sat_generique::tppi_get_single_sat_p_(SAT enum_prop, const SpanD P, SpanD res, int ncomp, int ind, bool ) const
36{
37#ifdef HAS_EOS
38 assert (ncomp * (int)P.size() == (int)res.size());
39 if (ncomp == 1) return compute_eos_field(P, res, EOS_prop_sat[(int)enum_prop][0], EOS_prop_sat[(int)enum_prop][1]);
40 else /* attention stride */
41 {
42 VectorD temp_((int)P.size());
43 SpanD RR(temp_);
44 int err_;
45 for (auto& val : RR) val = res[i_it2 * ncomp + ind];
46 err_ = compute_eos_field(P, RR, EOS_prop_sat[(int)enum_prop][0], EOS_prop_sat[(int)enum_prop][1]);
47 for (auto& val : RR) res[i_it2 * ncomp + ind] = val;
48 return err_;
49 }
50#else
51 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
52 throw;
53#endif
54}
55
56int EOS_to_TRUST_Sat_generique::tppi_get_p_sat_T(const SpanD T, SpanD res, int ncomp, int ind) const
57{
58#ifdef HAS_EOS
59 assert ((int)T.size() == (int)res.size());
60 return compute_eos_field(T, res, EOS_prop_sat[(int)SAT::P_SAT][0], EOS_prop_sat[(int)SAT::P_SAT][1], true /* is_T */);
61#else
62 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
63 throw;
64#endif
65}
66
67int EOS_to_TRUST_Sat_generique::tppi_get_p_sat_d_T_T(const SpanD T, SpanD res, int ncomp, int ind) const
68{
69 Cerr << "EOS_to_TRUST_Sat_generique::tppi_get_p_sat_d_T_T is not coded ! Call the 911 for help !" << finl;
70 throw;
71}
72
73int EOS_to_TRUST_Sat_generique::tppi_get_lvap_p(const SpanD P, SpanD res, int ncomp, int ind) const
74{
75#ifdef HAS_EOS
76 VectorD arr1_((int)P.size()), arr2_((int)P.size());
77 int err1_, err2_;
78 err1_ = tppi_get_h_v_sat_p(P,SpanD(arr1_),1,0);
79 err2_ = tppi_get_h_l_sat_p(P,SpanD(arr2_),1,0);
80 for (int i =0; i < (int)P.size(); i++) res[i * ncomp + ind] = arr1_[i] - arr2_[i];
81 return std::max(err1_,err2_);
82#else
83 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
84 throw;
85#endif
86}
87
88int EOS_to_TRUST_Sat_generique::tppi_get_lvap_d_p_p(const SpanD P, SpanD res, int ncomp, int ind) const
89{
90#ifdef HAS_EOS
91 VectorD arr1_((int)P.size()), arr2_((int)P.size());
92 int err1_, err2_;
93 err1_ = tppi_get_h_v_sat_d_p_p(P,SpanD(arr1_),1,0);
94 err2_ = tppi_get_h_l_sat_d_p_p(P,SpanD(arr2_),1,0);
95 for (int i =0; i < (int)P.size(); i++) res[i * ncomp + ind] = arr1_[i] - arr2_[i];
96 return std::max(err1_,err2_);
97#else
98 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
99 throw;
100#endif
101}
102
103int EOS_to_TRUST_Sat_generique::tppi_get_sigma_pT(const SpanD P, const SpanD T, SpanD R, int ncomp, int id) const
104{
105 // XXX : COCO : ARRETE D'APPELER SIGMA COMME CA CAR JE T'AVAIS DIT POURQUOI
106#ifdef HAS_EOS
107 assert((int )T.size() == ncomp * (int )P.size() && (int )T.size() == ncomp * (int )R.size());
108 if (user_uniform_sigma_ > 0)
109 for (int i =0; i < (int)P.size(); i++) R[i * ncomp + id] = user_uniform_sigma_;
110 else
111 {
112 if (ncomp == 1) return compute_eos_field(P, T, R, EOS_prop_sat[(int)SAT::SIGMA][0], EOS_prop_sat[(int)SAT::SIGMA][1]);
113 else /* attention stride */
114 {
115 VectorD temp_((int)P.size());
116 SpanD TT(temp_);
117 int err_;
118 for (auto& val : TT) val = T[i_it * ncomp + id];
119 err_ = compute_eos_field(P, TT, R, EOS_prop_sat[(int)SAT::SIGMA][0], EOS_prop_sat[(int)SAT::SIGMA][1]);
120 for (auto& val : TT) T[i_it * ncomp + id] = val;
121 return err_;
122 }
123 }
124 return 1;
125#else
126 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
127 throw;
128#endif
129}
130
131int EOS_to_TRUST_Sat_generique::tppi_get_sigma_ph(const SpanD P, const SpanD H, SpanD R, int ncomp, int id) const
132{
133#ifdef HAS_EOS
134 assert((int )H.size() == ncomp * (int )P.size() && (int )H.size() == ncomp * (int )R.size());
135 if (user_uniform_sigma_ > 0)
136 for (int i =0; i < (int)P.size(); i++) R[i * ncomp + id] = user_uniform_sigma_;
137 else
138 {
139 if (ncomp == 1) return compute_eos_field_h(P, H, R, EOS_prop_sat[(int)SAT::SIGMA][0], EOS_prop_sat[(int)SAT::SIGMA][1]);
140 else /* attention stride */
141 Process::exit("No stride allowed for the moment for enthalpie calls ... use temperature or call 911 !");
142 }
143 return 1;
144#else
145 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
146 throw;
147#endif
148}
149
150int EOS_to_TRUST_Sat_generique::tppi_get_all_flux_interfacial_pb_multiphase(const SpanD P, MSatSpanD sats, int ncomp, int id) const
151{
152#ifdef HAS_EOS
153 assert((int )sats.size() == 7);
154
155 SpanD dPTs__ = sats.at(SAT::T_SAT_DP), Hvs__ = sats.at(SAT::HV_SAT), Hls__ = sats.at(SAT::HL_SAT),
156 dPHvs__ = sats.at(SAT::HV_SAT_DP), dPHls__ = sats.at(SAT::HL_SAT_DP), Lvap__ = sats.at(SAT::LV_SAT), dPLvap__ = sats.at(SAT::LV_SAT_DP);
157
158 const int sz = (int) P.size(), nb_out = 5; /* NOTA BENE : 5 car LV_SAT et LV_SAT_DP on recalcule apres */
159 int i_out = 0, err_;
160 NEPTUNE::ArrOfInt tmp(sz);
161 NEPTUNE::EOS_Error_Field ferr(tmp);
162 NEPTUNE::EOS_Fields flds_out(nb_out);
163 NEPTUNE::EOS_Field P_fld("Pressure", "P", sz, (double*) P.begin());
164
165 if (ncomp == 1)
166 {
167 for (auto &itr : sats)
168 {
169 SAT prop_ = itr.first;
170 SpanD span_ = itr.second;
171 assert(ncomp * (int )P.size() == (int )span_.size());
172 if (prop_ != SAT::LV_SAT && prop_ != SAT::LV_SAT_DP)
173 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_sat[(int) prop_][0], EOS_prop_sat[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
174 }
175 err_ = (int)fluide->compute(P_fld, flds_out, ferr);
176
177 // on rempli LV_SAT et LV_SAT_DP
178 for (int i = 0; i < sz; i++)
179 {
180 Lvap__[i] = Hvs__[i] - Hls__[i];
181 dPLvap__[i] = dPHvs__[i] - dPHls__[i];
182 }
183 }
184 else /* attention stride */
185 {
186#ifndef NDEBUG
187 for (auto &itr : sats) assert(ncomp * (int )P.size() == (int )itr.second.size());
188#endif
189 VectorD dPTs(sz), Hvs(sz), Hls(sz), dPHvs(sz), dPHls(sz), Lvap(sz), dPLvap;
190 SpanD dPTs_(dPTs), Hvs_(Hvs), Hls_(Hls), dPHvs_(dPHvs), dPHls_(dPHls), Lvap_(Lvap), dPLvap_(dPLvap);
191
192 MSatSpanD sats_loc = { { SAT::T_SAT_DP, dPTs_ }, { SAT::HV_SAT, Hvs_ }, { SAT::HL_SAT, Hls_ }, { SAT::HV_SAT_DP, dPHvs_ }, { SAT::HL_SAT_DP, dPHls_ } };
193
194 for (auto &itr : sats_loc)
195 {
196 SAT prop_ = itr.first;
197 SpanD span_ = itr.second;
198 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_sat[(int) prop_][0], EOS_prop_sat[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
199 }
200
201 err_ = (int)fluide->compute(P_fld, flds_out, ferr);
202
203 for (int i = 0; i < sz; i++)
204 {
205 dPTs__[i * ncomp + id] = dPTs_[i];
206 Hvs__[i * ncomp + id] = Hvs_[i];
207 Hls__[i * ncomp + id] = Hls_[i];
208 dPHvs__[i * ncomp + id] = dPHvs_[i];
209 dPHls__[i * ncomp + id] = dPHls_[i];
210 Lvap__[i * ncomp + id] = Hvs_[i] - Hls_[i];
211 dPLvap__[i * ncomp + id] = dPHvs_[i] - dPHls_[i];
212 }
213 }
214
215 return err_;
216#else
217 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
218 throw;
219#endif
220}
221
222int EOS_to_TRUST_Sat_generique::tppi_get_all_sat_loi_F5(const MSpanD input, MSatSpanD sats, int ncomp, int id) const
223{
224#ifdef HAS_EOS
225 assert(ncomp == 1);
226 const SpanD P = input.at("pression");
227
228 int i_out = 0, nb_out = (int) sats.size(), sz = (int) P.size();
229 NEPTUNE::ArrOfInt tmp(sz);
230 NEPTUNE::EOS_Error_Field ferr(tmp);
231 NEPTUNE::EOS_Fields flds_out(nb_out);
232 NEPTUNE::EOS_Field P_fld("Pressure", "P", (int) P.size(), (double*) P.begin());
233
234 for (auto &itr : sats)
235 {
236 SAT prop_ = itr.first;
237 SpanD span_ = itr.second;
238 assert(sz == (int ) span_.size());
239 flds_out[i_out++] = NEPTUNE::EOS_Field(EOS_prop_sat[(int) prop_][0], EOS_prop_sat[(int) prop_][1], (int) span_.size(), (double*) span_.begin());
240 }
241
242 return (int)fluide->compute(P_fld, flds_out, ferr);
243#else
244 Cerr << "EOS_to_TRUST_Sat_generique::" << __func__ << " should not be called since TRUST is not compiled with the EOS library !!! " << finl;
245 throw;
246#endif
247}
int tppi_get_lvap_d_p_p(const SpanD P, SpanD res, int ncomp=1, int ind=0) const override
void set_saturation_generique(const char *const model_name, const char *const fluid_name) override
int tppi_get_all_flux_interfacial_pb_multiphase(const SpanD P, MSatSpanD sats, int ncomp=1, int id=0) const override
int tppi_get_p_sat_T(const SpanD T, SpanD res, int ncomp=1, int ind=0) const override
int tppi_get_lvap_p(const SpanD P, SpanD res, int ncomp=1, int ind=0) const override
int tppi_get_sigma_ph(const SpanD P, const SpanD H, SpanD R, int ncomp=1, int id=0) const override
int tppi_get_sigma_pT(const SpanD P, const SpanD T, SpanD R, int ncomp=1, int id=0) const override
int tppi_get_p_sat_d_T_T(const SpanD T, SpanD res, int ncomp=1, int ind=0) const override
int tppi_get_all_sat_loi_F5(const MSpanD input, MSatSpanD sats, 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
virtual int tppi_get_h_l_sat_d_p_p(const SpanD P, SpanD res, int ncomp=1, int ind=0) const
Definition TPPI.h:299
virtual int tppi_get_h_v_sat_d_p_p(const SpanD P, SpanD res, int ncomp=1, int ind=0) const
Definition TPPI.h:309
virtual int tppi_get_h_v_sat_p(const SpanD P, SpanD res, int ncomp=1, int ind=0) const
Definition TPPI.h:304
virtual int tppi_get_h_l_sat_p(const SpanD P, SpanD res, int ncomp=1, int ind=0) const
Definition TPPI.h:294