3D-ICE 3.0.0
output.c
1/******************************************************************************
2 * This file is part of 3D-ICE, version 3.1.0 . *
3 * *
4 * 3D-ICE is free software: you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free *
6 * Software Foundation, either version 3 of the License, or any later *
7 * version. *
8 * *
9 * 3D-ICE is distributed in the hope that it will be useful, but WITHOUT *
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
12 * more details. *
13 * *
14 * You should have received a copy of the GNU General Public License along *
15 * with 3D-ICE. If not, see <http://www.gnu.org/licenses/>. *
16 * *
17 * Copyright (C) 2021 *
18 * Embedded Systems Laboratory - Ecole Polytechnique Federale de Lausanne *
19 * All Rights Reserved. *
20 * *
21 * Authors: Arvind Sridhar Alessandro Vincenzi *
22 * Giseong Bak Martino Ruggiero *
23 * Thomas Brunschwiler Eder Zulian *
24 * Federico Terraneo Darong Huang *
25 * Luis Costero Marina Zapater *
26 * David Atienza *
27 * *
28 * For any comment, suggestion or request about 3D-ICE, please register and *
29 * write to the mailing list (see http://listes.epfl.ch/doc.cgi?liste=3d-ice) *
30 * Any usage of 3D-ICE for research, commercial or other purposes must be *
31 * properly acknowledged in the resulting products or publications. *
32 * *
33 * EPFL-STI-IEL-ESL Mail : 3d-ice@listes.epfl.ch *
34 * Batiment ELG, ELG 130 (SUBSCRIPTION IS NECESSARY) *
35 * Station 11 *
36 * 1015 Lausanne, Switzerland Url : http://esl.epfl.ch/3d-ice *
37 ******************************************************************************/
38
39#include <stdlib.h> // For the memory functions malloc/free
40#include <string.h> // For strlen
41
42#include "output.h"
43
44/******************************************************************************/
45
46void output_init (Output_t *output)
47{
48 inspection_point_list_init (&output->InspectionPointListFinal) ;
49 inspection_point_list_init (&output->InspectionPointListSlot) ;
50 inspection_point_list_init (&output->InspectionPointListStep) ;
51}
52
53/******************************************************************************/
54
55void output_copy (Output_t *dst, Output_t *src)
56{
57 output_destroy (dst) ;
58
59 inspection_point_list_copy
60
61 (&dst->InspectionPointListFinal, &src->InspectionPointListFinal) ;
62
63 inspection_point_list_copy
64
65 (&dst->InspectionPointListSlot, &src->InspectionPointListSlot) ;
66
67 inspection_point_list_copy
68
69 (&dst->InspectionPointListStep, &src->InspectionPointListStep) ;
70}
71
72/******************************************************************************/
73
75{
76 inspection_point_list_destroy (&output->InspectionPointListFinal) ;
77 inspection_point_list_destroy (&output->InspectionPointListSlot) ;
78 inspection_point_list_destroy (&output->InspectionPointListStep) ;
79
80 output_init (output) ;
81}
82
83/******************************************************************************/
84
86(
87 Output_t *output,
88 OutputInstant_t instant,
89 OutputType_t type,
90 OutputQuantity_t quantity
91)
92{
93 Quantity_t number = 0u ;
94
95 InspectionPointList_t *list = NULL ;
96
97 if (instant == TDICE_OUTPUT_INSTANT_FINAL)
98
99 list = &output->InspectionPointListFinal ;
100
101 else if (instant == TDICE_OUTPUT_INSTANT_STEP)
102
103 list = &output->InspectionPointListStep ;
104
105 else if (instant == TDICE_OUTPUT_INSTANT_SLOT)
106
107 list = &output->InspectionPointListSlot ;
108
109 else
110 {
111 fprintf (stderr, "Error: Wrong ipoint instant %d\n", instant) ;
112
113 return number ;
114 }
115
116 InspectionPointListNode_t *ipn ;
117
118 for (ipn = inspection_point_list_begin (list) ;
119 ipn != NULL ;
120 ipn = inspection_point_list_next (ipn))
121 {
122 InspectionPoint_t *ipoint = inspection_point_list_data (ipn) ;
123
124 if (is_inspection_point (ipoint, type, quantity) == true)
125
126 number++ ;
127 }
128
129 return number ;
130}
131
132/******************************************************************************/
133
134void output_print (Output_t *output, FILE *stream, String_t prefix)
135{
136 fprintf (stream, "%soutput :\n", prefix) ;
137
138 String_t new_prefix = (String_t) malloc (sizeof(*new_prefix) * (5 + strlen(prefix))) ;
139
140 if (new_prefix == NULL) return ;
141
142 sprintf (new_prefix, "%s ", prefix) ;
143
144 inspection_point_list_print (&output->InspectionPointListFinal, stream, new_prefix) ;
145
146 fprintf (stream, "%s\n", prefix) ;
147
148 inspection_point_list_print (&output->InspectionPointListSlot, stream, new_prefix) ;
149
150 fprintf (stream, "%s\n", prefix) ;
151
152 inspection_point_list_print (&output->InspectionPointListStep, stream, new_prefix) ;
153
154 fprintf (stream, "%s\n", prefix) ;
155
156 free (new_prefix) ;
157}
158
159/******************************************************************************/
160
162{
163 InspectionPointList_t *list = NULL ;
164
165 if (ipoint->Instant == TDICE_OUTPUT_INSTANT_FINAL)
166
167 list = &output->InspectionPointListFinal ;
168
169 else if (ipoint->Instant == TDICE_OUTPUT_INSTANT_STEP)
170
171 list = &output->InspectionPointListStep ;
172
173 else if (ipoint->Instant == TDICE_OUTPUT_INSTANT_SLOT)
174
175 list = &output->InspectionPointListSlot ;
176
177 else
178 {
179 fprintf (stderr, "Error: Unset ipoint instant %d\n", ipoint->Instant) ;
180
181 return ;
182 }
183
184
185 inspection_point_list_insert_end (list, ipoint) ;
186}
187
188/******************************************************************************/
189
191(
192 Output_t *output,
193 Dimensions_t *dimensions,
194 String_t prefix
195)
196{
197 InspectionPointListNode_t *ipn ;
198
199 for (ipn = inspection_point_list_begin (&output->InspectionPointListFinal) ;
200 ipn != NULL ;
201 ipn = inspection_point_list_next (ipn))
202 {
203 InspectionPoint_t *ipoint = inspection_point_list_data (ipn) ;
204
205 if (generate_inspection_point_header (ipoint, dimensions, prefix) != TDICE_SUCCESS)
206
207 return TDICE_FAILURE ;
208 }
209
210 for (ipn = inspection_point_list_begin (&output->InspectionPointListSlot) ;
211 ipn != NULL ;
212 ipn = inspection_point_list_next (ipn))
213 {
214 InspectionPoint_t *ipoint = inspection_point_list_data (ipn) ;
215
216 if (generate_inspection_point_header (ipoint, dimensions, prefix) != TDICE_SUCCESS)
217
218 return TDICE_FAILURE ;
219 }
220
221 for (ipn = inspection_point_list_begin (&output->InspectionPointListStep) ;
222 ipn != NULL ;
223 ipn = inspection_point_list_next (ipn))
224 {
225 InspectionPoint_t *ipoint = inspection_point_list_data (ipn) ;
226
227 if (generate_inspection_point_header (ipoint, dimensions, prefix) != TDICE_SUCCESS)
228
229 return TDICE_FAILURE ;
230 }
231
232 return TDICE_SUCCESS ;
233}
234
235/******************************************************************************/
236
238(
239 Output_t *output,
240 Dimensions_t *dimensions,
241 Temperature_t *temperatures,
242 Source_t *sources,
243 Time_t current_time,
244 OutputInstant_t output_instant
245)
246{
247 InspectionPointList_t *list ;
248
249 if (output_instant == TDICE_OUTPUT_INSTANT_FINAL)
250
251 list = &output->InspectionPointListFinal ;
252
253 else if (output_instant == TDICE_OUTPUT_INSTANT_STEP)
254
255 list = &output->InspectionPointListStep ;
256
257 else if (output_instant == TDICE_OUTPUT_INSTANT_SLOT)
258
259 list = &output->InspectionPointListSlot ;
260
261 else
262 {
263 fprintf (stderr, "Error: Wrong ipoint instant %d\n", output_instant) ;
264
265 return TDICE_FAILURE ;
266 }
267
268 InspectionPointListNode_t *ipn ;
269
270 for (ipn = inspection_point_list_begin (list) ;
271 ipn != NULL ;
272 ipn = inspection_point_list_next (ipn))
273 {
274 InspectionPoint_t *ipoint = inspection_point_list_data (ipn) ;
275
277
278 (ipoint, dimensions, temperatures, sources, current_time) ;
279
280 if (error != TDICE_SUCCESS)
281
282 return TDICE_FAILURE ;
283 }
284
285 return TDICE_SUCCESS ;
286}
287
288/******************************************************************************/
289
291(
292 Output_t *output,
293 Dimensions_t *dimensions,
294 Temperature_t *temperatures,
295 Source_t *sources,
296 OutputInstant_t output_instant,
297 OutputType_t output_type,
298 OutputQuantity_t output_quantity,
299 NetworkMessage_t *message
300)
301{
302 InspectionPointList_t *list ;
303
304 if (output_instant == TDICE_OUTPUT_INSTANT_FINAL)
305
306 list = &output->InspectionPointListFinal ;
307
308 else if (output_instant == TDICE_OUTPUT_INSTANT_STEP)
309
310 list = &output->InspectionPointListStep ;
311
312 else if (output_instant == TDICE_OUTPUT_INSTANT_SLOT)
313
314 list = &output->InspectionPointListSlot ;
315
316 else
317 {
318 fprintf (stderr, "Error: Wrong ipoint instant %d\n", output_instant) ;
319
320 return TDICE_FAILURE ;
321 }
322
323 InspectionPointListNode_t *ipn ;
324
325 for (ipn = inspection_point_list_begin (list) ;
326 ipn != NULL ;
327 ipn = inspection_point_list_next (ipn))
328 {
329 InspectionPoint_t *ipoint = inspection_point_list_data (ipn) ;
330
331 if (output_type == ipoint->OType)
332
334
335 (ipoint, output_quantity, dimensions, temperatures, sources, message) ;
336 }
337
338 return TDICE_SUCCESS ;
339}
340
341/******************************************************************************/
Error_t generate_inspection_point_output(InspectionPoint_t *ipoint, Dimensions_t *dimensions, Temperature_t *temperatures, Source_t *sources, Time_t current_time)
Error_t generate_inspection_point_header(InspectionPoint_t *ipoint, Dimensions_t *dimensions, String_t prefix)
void fill_message_inspection_point(InspectionPoint_t *ipoint, OutputQuantity_t output_quantity, Dimensions_t *dimensions, Temperature_t *temperatures, Source_t *sources, NetworkMessage_t *message)
bool is_inspection_point(InspectionPoint_t *ipoint, OutputType_t type, OutputQuantity_t quantity)
void output_destroy(Output_t *output)
Definition: output.c:74
void output_print(Output_t *output, FILE *stream, String_t prefix)
Definition: output.c:134
void add_inspection_point(Output_t *output, InspectionPoint_t *ipoint)
Definition: output.c:161
Error_t fill_output_message(Output_t *output, Dimensions_t *dimensions, Temperature_t *temperatures, Source_t *sources, OutputInstant_t output_instant, OutputType_t output_type, OutputQuantity_t output_quantity, NetworkMessage_t *message)
Definition: output.c:291
Error_t generate_output(Output_t *output, Dimensions_t *dimensions, Temperature_t *temperatures, Source_t *sources, Time_t current_time, OutputInstant_t output_instant)
Definition: output.c:238
Error_t generate_output_headers(Output_t *output, Dimensions_t *dimensions, String_t prefix)
Definition: output.c:191
Quantity_t get_number_of_inspection_points(Output_t *output, OutputInstant_t instant, OutputType_t type, OutputQuantity_t quantity)
Definition: output.c:86
void output_copy(Output_t *dst, Output_t *src)
Definition: output.c:55
void output_init(Output_t *output)
Definition: output.c:46
char * String_t
Definition: string_t.h:55
Collections of all the structures that are needed for the thermal simulation.
Definition: dimensions.h:311
Structure containing info about the output to be printed while simulating.
OutputInstant_t Instant
OutputType_t OType
Structure used to store messages to be sent over network.
Informations about the type of thermal simulation to be run and its initial settings.
Definition: output.h:69
InspectionPointList_t InspectionPointListFinal
Definition: output.h:73
InspectionPointList_t InspectionPointListSlot
Definition: output.h:78
InspectionPointList_t InspectionPointListStep
Definition: output.h:83
Error_t
Definition: types.h:401
@ TDICE_SUCCESS
The function returns with success.
Definition: types.h:402
@ TDICE_FAILURE
The function retuerns with a generic error.
Definition: types.h:403
OutputType_t
Definition: types.h:500
OutputInstant_t
Definition: types.h:525
@ TDICE_OUTPUT_INSTANT_FINAL
At the end of the simulation.
Definition: types.h:527
@ TDICE_OUTPUT_INSTANT_STEP
At every internal time step.
Definition: types.h:529
@ TDICE_OUTPUT_INSTANT_SLOT
At the end of each time slot.
Definition: types.h:528
double Time_t
Definition: types.h:65
double Temperature_t
Definition: types.h:71
OutputQuantity_t
Definition: types.h:477
double Source_t
Definition: types.h:77
uint32_t Quantity_t
Definition: types.h:59