GCC Code Coverage Report


Directory: ./
File: InputOutput/io.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 61 76 80.3%
Branches: 21 60 35.0%

Line Branch Exec Source
1 // ______ ______ _ _ _____ ______
2 // | ____| ____| | (_)/ ____| | ____|
3 // | |__ | |__ | | _| (___ ___| |__
4 // | __| | __| | | | |\___ \ / __| __|
5 // | | | |____| |____| |____) | (__| |____
6 // |_| |______|______|_|_____/ \___|______|
7 // Finite Elements for Life Sciences and Engineering
8 //
9 // License: LGL2.1 License
10 // FELiScE default license: LICENSE in root folder
11 //
12 // Main authors: J.Castelneau & J.Foulon
13 //
14
15 // System includes
16
17 // External includes
18
19 // Project includes
20 #include "Core/felisceParam.hpp"
21 #include "Core/felisceTransient.hpp"
22 #include "InputOutput/io.hpp"
23
24 namespace felisce
25 {
26
27
1/2
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 IO::IO():typeInput(-1),typeOutput(-1)
28 1 {}
29
30 /***********************************************************************************/
31 /***********************************************************************************/
32
33 /*! IO object built from information read on mesh*/
34 1054 IO::IO(const std::string& inputDirectory, const std::string& inputFile, const std::string& inputMesh,
35
1/2
✓ Branch 8 taken 1054 times.
✗ Branch 9 not taken.
1054 const std::string& outputMesh, const std::string& meshDir, const std::string& resultDir, const std::string& prefixName)
36 {
37
1/2
✓ Branch 1 taken 1054 times.
✗ Branch 2 not taken.
1054 this->initialize(inputDirectory, inputFile, inputMesh, outputMesh, meshDir, resultDir, prefixName);
38 1054 }
39
40 /***********************************************************************************/
41 /***********************************************************************************/
42
43 1055 void IO::initialize(const std::string& inputDirectory, const std::string& inputFile, const std::string& inputMesh,
44 const std::string& outputMesh, const std::string& meshDir, const std::string& resultDir, const std::string& prefixName)
45 {
46 1055 m_inputDirectory = inputDirectory;
47 1055 m_inputFile = inputFile;
48 1055 m_inputMesh = inputMesh;
49 1055 m_outputMesh = outputMesh;
50 1055 m_meshDir = meshDir;
51 1055 m_resultDir = resultDir;
52 1055 m_prefixName = prefixName;
53 1055 m_ens.initialize(m_inputDirectory,m_inputFile,m_inputMesh,m_outputMesh,m_meshDir,m_resultDir);
54 1055 m_med.initialize(m_inputMesh,m_outputMesh,m_meshDir,m_resultDir);
55
56 // Switch over the extension
57 // =========================
58
2/2
✓ Branch 1 taken 1039 times.
✓ Branch 2 taken 16 times.
1055 if ( m_inputMesh.find(".mesh") != std::string::npos ) {
59 1039 typeInput = 0;
60
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 } else if ( m_inputMesh.find(".geo") != std::string::npos ) {
61 16 typeInput = 1;
62 } else {
63 const std::string meshFileExt = m_inputMesh.substr( m_inputMesh.find_last_of( '.' ) +1);
64 const std::string error = "No read mesh for such extension: " + meshFileExt;
65 felisce_error( error.c_str() , __FILE__, __LINE__);
66 }
67
68 // Switch over the extension
69 // =========================
70
2/2
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 1005 times.
1055 if ( m_outputMesh.find(".mesh") != std::string::npos ) {
71 50 typeOutput = 0;
72
1/2
✓ Branch 1 taken 1005 times.
✗ Branch 2 not taken.
1005 } else if ( m_outputMesh.find(".geo") != std::string::npos ) {
73 1005 typeOutput = 1;
74 } else {
75 const std::string meshFileExt = m_outputMesh.substr( m_outputMesh.find_last_of( '.' ) +1);
76 const std::string error = "No writer mesh for such extension: " + meshFileExt;
77 felisce_error( error.c_str() , __FILE__, __LINE__);
78 }
79 1055 }
80
81 /***********************************************************************************/
82 /***********************************************************************************/
83
84 995 void IO::initializeOutput()
85 {
86 995 m_ens.initializeOutput(m_outputMesh,1, 0 , 0, 1);
87 995 }
88
89 /***********************************************************************************/
90 /***********************************************************************************/
91
92 /*! reading of the mesh file according to its extension */
93 515 void IO::readMesh(GeometricMeshRegion& mesh, double spaceUnit)
94 {
95
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 11 times.
515 if ( typeInput == 0 ) {
96 504 m_med.readerMedit(mesh, spaceUnit);
97
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 } else if ( typeInput == 1 ) {
98 11 m_ens.readerGeo(mesh, spaceUnit);
99 }
100 515 }
101
102 /***********************************************************************************/
103 /***********************************************************************************/
104
105 /*! writing of the mesh file according to output extension contains in mesh */
106 170 void IO::writeMesh(GeometricMeshRegion& mesh, std::string nameOfGeoFile)
107 {
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 170 times.
170 if ( typeOutput == 0 ) {
109 m_med.writerMedit(mesh);
110 } else {
111
1/2
✓ Branch 0 taken 170 times.
✗ Branch 1 not taken.
170 if ( typeOutput == 1 ) {
112
1/2
✓ Branch 1 taken 170 times.
✗ Branch 2 not taken.
170 if(FelisceParam::instance().outputFileFormat == ENSIGHT6)
113
1/2
✓ Branch 2 taken 170 times.
✗ Branch 3 not taken.
170 m_ens.writerGeo(mesh, nameOfGeoFile);
114 else if(FelisceParam::instance().outputFileFormat == ENSIGHTGOLD)
115 m_ens.writerGeoGold(mesh, nameOfGeoFile);
116 else if (FelisceParam::instance().outputFileFormat == ENSIGHT6BIN)
117 m_ens.writerGeoBin(mesh, nameOfGeoFile);
118 else
119 FEL_ERROR("Unknown output file format type");
120 }
121 }
122 170 }
123
124 /***********************************************************************************/
125 /***********************************************************************************/
126
127 29 void IO::writeOutput(GeometricMeshRegion& mesh, int rank)
128 {
129
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if ( typeOutput == 0 ) {
130 29 m_med.writerMedit(mesh);
131 } else {
132 if ( typeOutput == 1 ) {
133 m_ens.writerGeo(mesh,rank);
134 }
135 }
136 29 }
137
138 /***********************************************************************************/
139 /***********************************************************************************/
140
141 468 void IO::readInputFile() {
142 468 m_ens.readCaseFile();
143 468 }
144
145 /***********************************************************************************/
146 /***********************************************************************************/
147
148 24 void IO::readVariable(int idVariable, double time,
149 double* valueOfVariable, felInt size)
150 {
151 24 m_ens.readVariable(idVariable, time, valueOfVariable, size);
152 24 }
153
154 /***********************************************************************************/
155 /***********************************************************************************/
156
157 2 void IO::addVariable(const EnsightVariable::TypeVar& type, const std::string nameVariable,
158 const double* solution, const felInt size, bool manageMemory)
159 {
160
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 m_ens.addVariable(type, nameVariable, solution, size, manageMemory);
161 2 }
162
163 /***********************************************************************************/
164 /***********************************************************************************/
165
166 3112 void IO::postProcess(double& time, int flagMultipleCase)
167 {
168 3112 m_ens.postProcess(m_resultDir, m_prefixName, flagMultipleCase, time);
169 3112 }
170
171 /***********************************************************************************/
172 /***********************************************************************************/
173
174 5376 void IO::writeSolution(int rankProc, double& time, int iteration, const int & typeVariable, const std::string& nameVariable, const double* solution,
175 felInt size, int dimension, bool manageMemory)
176 {
177 IGNORE_UNUSED_RANK_PROC;
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5376 times.
5376 if ( typeOutput == 0 ) {
179 m_med.writeSolution(time, iteration, typeVariable, nameVariable, solution, size, dimension);
180
1/2
✓ Branch 0 taken 5376 times.
✗ Branch 1 not taken.
5376 } else if ( typeOutput == 1 ) {
181
1/2
✓ Branch 2 taken 5376 times.
✗ Branch 3 not taken.
5376 m_ens.addVariable(typeVariable, nameVariable, solution, size, manageMemory);
182 }
183 5376 }
184
185 }
186