TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_lu_proto.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <Champ_lu_proto.h>
17#include <EntreeSortie.h>
18#include <sstream>
19#include <fstream>
20#include <vector>
21
22inline int tokenize_string_if_double(const std::string line, std::vector<std::string>& result)
23{
24 std::istringstream iss(line);
25 for (std::string s; iss >> s;)
26 try
27 {
28 std::stod(s);
29 result.push_back(s);
30 }
31 catch (std::exception&) { return 0; }
32 return 1;
33}
34
35
36Nom Champ_lu_proto::put_file_into_nom(int nb_comp, const Nom& column_file) const
37{
38 // open column file
39 std::ifstream infile(column_file);
40 Nom liste_temps(""), liste_vals("");
41
42 // read line by line
43 int nb_val = 0;
44 std::string line;
45 for (int l = 1; std::getline(infile, line); l++)
46 if (!(line.rfind("#", 0) == 0))
47 {
48 nb_val++;
49 std::vector<std::string> result;
50 if (!tokenize_string_if_double(line, result))
51 {
52 Cerr << "The file " << column_file << " contains non double values at line " << l << " !" << finl;
54 }
55 const int nb_col_lues = (int)result.size();
56 if (nb_col_lues != (nb_comp + 1))
57 {
58 Cerr << "The file " << column_file << " should contain " << nb_comp + 1 << " columns but " << nb_col_lues << " have been detected on line " << l << finl;
60 }
61 liste_temps += Nom(" ") + result[0];
62 for (int n = 0; n < nb_comp; n++)
63 liste_vals += Nom(" ") + result[1 + n];
64 }
65
66 // send to the parent class readOn
67 Nom chaine_tabulee(" { ");
68 chaine_tabulee += Nom(nb_val) + liste_temps + liste_vals + Nom(" }");
69 Cerr << "Creation from " << column_file << " of the field" << finl;
70 Cerr << "Champ_front_Tabule " << chaine_tabulee << finl;
71
72 return chaine_tabulee;
73}
Nom put_file_into_nom(int n, const Nom &col_file) const
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455