[go: up one dir, main page]

Menu

[r40]: / source / cooldt.h  Maximize  Restore  History

Download this file

209 lines (170 with data), 7.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Cooldt cool-down time calculator for multi-layers pipe
*
* Copyright 2010, 2013, 2014, Benjamin DEGLO DE BESSES. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY Benjamin DEGLO DE BESSES "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. IN NO EVENT SHALL Benjamin DEGLO DE BESSES 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; 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.
*
*/
#ifndef COOLDT_H
#define COOLDT_H
/*
* Libraries
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
/*
* Constants
*/
#define C_Pi 3.141592653589793238 /* PI number */
#define CharBufferSize 256 /* Buffer size for char strings */
#define MaxLayerNumber 19 /* Maximum Layer Number */
#define MaxCellNumberPerLayer 256 /* Maximum number of cell per layer */
#define MinTimeStep 0.01 /* Minimum time step */
#define NbTfluidSolidSave 20.0 /* Number of saving points for Temp. vs time */
#define aacCDTconverge 5.0e-4 /* Cool down time convergence condition for aac */
#define aacInitialTimeStep 1000.0 /* Initial time step for aac */
#define aacInitialFluidCellNumber 2 /* Initial Cell number for aac */
#define aacInitialSolidCellNumber 1 /* Initial Cell number for aac */
#define aacTimeStepDecay 0.1 /* Time step decay factor for aac */
#define aacNbCellGroth 2 /* Cell number groth factor for aac */
/*
* Error messages
*/
#define C_ERROR_INVALID_TEMPERATURES "ERROR: invalid temperatures, T(ambient) < T(final) < T(initial)"
#define C_ERROR_INVALID_HEAT_COEF "ERROR: invalid ambient heat transfer coefficient, 1 <= H(ambient) <= 100 000 W/m2/K"
#define C_ERROR_INVALID_NB_LAYER "ERROR: invalid number of layer, 1 <= layer # <= %i"
#define C_ERROR_INVALID_DIAMETER "ERROR: invalid diameter of layer %i, 0.001 <= D <= 10 m"
#define C_ERROR_DIAMETER_MUST_INCREASES "ERROR: diameter must increases between layer %i and %i"
#define C_ERROR_INVALID_CONDUCTIVITY "ERROR: invalid conductivity of layer %i, 0.005 <= k <= 2500 W/m/K"
#define C_ERROR_INVALID_DENSITY "ERROR: invalid density of layer %i, 0.1 <= d <= 10000 kg/m3"
#define C_ERROR_INVALID_HEAT_CAPACITY "ERROR: invalid heat capacity of layer %i, 100 <= Cp <= 12000 J/kg/K"
#define C_ERROR_NB_NOT_EQUALS "ERROR: numbers of Diameters, Conductivities, Densities and Heat Capacities are not equals"
#define C_ERROR_INPUTFILE_MISSING_DATA "ERROR InputFile: %s, missing and/or invalid data on line %i."
#define C_ERROR_TOO_FEW_ARGUMENTS "ERROR: too few argument."
#define C_ERROR_FILE_NOT_EXISTS "ERROR InputFile: %s does not exist."
#define C_ERROR_INPUTFILE_INVALID_FILE "ERROR InputFile: %s is not a valid data file. For details, see OutputFile: %s"
#define C_ERROR_INPUTFILE_INVALID_VALUES "ERROR InputFile: %s contains invalid values. For details, see OutputFile: %s"
/*
* PipeProblem structure definition
* All physicals peoperties are in SI units except temperature in (C)
*/
typedef struct
{
int N ; /* layer number */
int *NbCell ; /* Number of fluid cell */
double *k ; /* Conductivity */
double *Cp ; /* Heat capacity */
double *d ; /* Density of layers */
double *r ; /* Radius of layers */
double Tfinal ; /* Final fluid temperature */
double Tinitial ; /* Initial temperature */
double Tambient ; /* Ambiant temperature */
double Hout ; /* Ambiant heat transfer coefficient */
double dt ;
} PipeProblem ;
/*
* Temperature over time structure definition
*/
typedef struct
{
int n ; /* Final index of time increment */
double *tn ; /* time */
double *T ; /* temperature */
} TfluidSolid ;
/*
* PipeDicretize structure definition
*/
typedef struct
{
int N ; /* Cell number */
int *L ; /* Layer id */
double *rc ; /* Radius of cells center i */
double *rm ; /* Radius of cells boundary i-1/2 */
double *rp ; /* Radius of cells boundary i+1/2 */
double *S ; /* Surface of cells i */
double *kc ; /* Conductivity of cell i */
double *km ; /* Conductivity of face i-1/2 */
double *kp ; /* Conductivity of face i+1/2 */
double *d ; /* Density of cells i */
double *Cp ; /* Heat capacity of cells i */
double *alpha ; /* Model coefficient alpha */
double *beta ; /* Model coefficient beta */
double *gamma ; /* Model coefficient gamma */
double alphaSharp ;
} PipeDicretize ;
/*
* messages.c
*/
void WriteLicense(FILE *fp) ;
void WriteShortLicense(FILE *fp) ;
void WriteHelpMessage(FILE *fp) ;
/*
* input.c
*/
int ReadData(FILE *fp, PipeProblem *PP, char *InputFile) ;
void FileNameDotTxt(char *InputFile, char *OutputFile) ;
void WriteInputData(FILE *fp, PipeProblem *PP) ;
int fileExists(char *fileName) ;
/*
* check-data.c
*/
int CheckInputData(FILE *fp, char * ErrorMessage, PipeProblem *PP) ;
/*
* alloc.c
*/
void Size0PipeDiscretize(PipeDicretize *PZ) ;
void IncrementSizePipeDiscretize(PipeDicretize *PZ) ;
void FreePipeDiscretize(PipeDicretize *PZ) ;
void SizePipeProblem(PipeProblem *PP) ;
void FreePipeProblem(PipeProblem *PP) ;
void Size0TfluidSolid(TfluidSolid *Tot) ;
void IncrementSizeTfluidSolid(TfluidSolid *Tot) ;
void FreeTfluidSolid(TfluidSolid *Tot) ;
/*
* mesh.c
*/
void BuildModel(PipeProblem *PP, PipeDicretize *PZ) ;
/*
* steady-state.c
*/
void CalcSteadyState(PipeProblem *PP, PipeDicretize *PZ, double *T) ;
/*
* solution.c
*/
double SolutionSimpleOutput(PipeProblem *PP) ;
double SolutionFullOutput(FILE *fp, PipeProblem *PP) ;
/*
* automatic.c
*/
void aaControl(FILE *fp, PipeProblem *PP) ;
/*
* transient.c
*/
double CalcTransient(PipeProblem *PP, PipeDicretize *PZ, double *Tcurrent, TfluidSolid *TfS) ;
/*
* algebra.c
*/
void TriDiagonalSolve(double *A, double *B, double *C, double *D, int I_inf, int I_sup, double *X) ;
#endif /* COOLDT_H */