[go: up one dir, main page]

Menu

[r40]: / source / transient.c  Maximize  Restore  History

Download this file

230 lines (200 with data), 6.8 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* 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.
*
*/
#include "cooldt.h"
/*
* Calculate linear system coefficients A, B, C & D
* based on alpha, beta, gamma and time step (dt)
*/
void TransientSystem(PipeProblem *PP, PipeDicretize *PZ, double *T, double dt,
double *A, double *B, double *C, double *D)
{
/*
* At the pipe center
*/
int i = 0 ;
A[i] = 0.0 ;
B[i] = PZ->beta[i] + dt * PZ->gamma[i] ;
C[i] = - dt * PZ->gamma[i] ;
D[i] = PZ->gamma[i] * ( T[i+1] - T[i] ) ;
/*
* In fluid and solids
*/
for( i = 1 ; i < PZ->N ; i++ )
{
A[i] = - dt * PZ->alpha[i];
B[i] = PZ->beta[i] + dt * ( PZ->alpha[i] + PZ->gamma[i] ) ;
C[i] = - dt * PZ->gamma[i] ;
D[i] = PZ->alpha[i] * ( T[i-1] - T[i] ) + PZ->gamma[i] * ( T[i+1] - T[i] ) ;
}
/*
* At the ambiant fluid / outer wall interface
*/
i = PZ->N ;
A[i] = - dt * PZ->alpha[i];
B[i] = PZ->beta[i] + dt * ( PZ->alpha[i] + PZ->gamma[i] ) ;
C[i] = 0.0 ;
D[i] = PZ->alpha[i] * ( T[i-1] - T[i] ) + PZ->gamma[i] * ( PP->Tambient - T[i] ) ;
}
/*
* Calculate temperature change derivative / time for each cell (=dT/dt)
* return the result to *DTodt
*/
void CalcDTodt(PipeProblem *PP, PipeDicretize *PZ, double *T, double dt, double *DTodt)
{
size_t DoublesSize = (PZ->N + 1) * sizeof(double) ;
double *A = (double*)malloc(DoublesSize) ;
double *B = (double*)malloc(DoublesSize) ;
double *C = (double*)malloc(DoublesSize) ;
double *D = (double*)malloc(DoublesSize) ;
/*
* Calculate coef, then the next temperature
*/
TransientSystem(PP, PZ, T, dt, A, B, C, D) ;
TriDiagonalSolve(A, B, C, D, 0, PZ->N, DTodt) ;
free(A) ;
free(B) ;
free(C) ;
free(D) ;
}
/*
* Calculate next temperature with exponential decay approximation
*/
void TimeIntegration(PipeProblem *PP, PipeDicretize *PZ, double *T)
{
int i ;
double *DTodt = (double*)malloc((PZ->N + 1) * sizeof(double)) ;
double Tau ;
/*
* Step 1: Calculate DT/dt
*/
CalcDTodt(PP, PZ, T, PP->dt, DTodt) ;
/*
* Step 2: Calculate Tau[i] then new T[i]
*/
for( i = 0 ; i <= PZ->N ; i++ )
{
/*
* Time constant for each cell temperature decay
*/
Tau = - ( T[i] + PP->dt * DTodt[i] - PP->Tambient ) / DTodt[i];
/*
* Apply the exponential decay approximation
*/
T[i] = PP->Tambient + ( T[i] - PP->Tambient ) * exp( - PP->dt / Tau ) ;
}
/*
* Free local pointers
*/
free(DTodt) ;
}
/*
* Return the temperature at the fluid/solid interface
*/
double TfluidSolidInterface(PipeDicretize *PZ, int NbFluidCell, double *T)
{
return ( ( ( PZ->alphaSharp + PZ->gamma[NbFluidCell] ) * T[NbFluidCell]
- PZ->gamma[NbFluidCell] * T[NbFluidCell+1] ) / PZ->alphaSharp ) ;
}
/*
* Calculate the transient problem solution
* return the cool down time
*/
double CalcTransient(PipeProblem *PP, PipeDicretize *PZ, double *Tcurrent, TfluidSolid *TfS)
{
double *Tprev = (double*)malloc((PZ->N + 1) * sizeof(double)) ; /* Previous temperature */
double TfScurrent ;
double time = 0.0 ;
int i ;
/*
* Save the initial temperature at fluid/solid interface
*/
Size0TfluidSolid(TfS) ;
TfS->tn[TfS->n] = time ;
TfScurrent = TfS->T[TfS->n] = TfluidSolidInterface(PZ, PP->NbCell[0], Tcurrent) ;
/*
* While the temperature have not reach the target
*/
while ( TfScurrent >= PP->Tfinal )
{
/*
* Save the previous temperature
*/
for( i = 0 ; i <= PZ->N ; i++)
Tprev[i] = Tcurrent[i] ;
/*
* Calculate next temperature
*/
TimeIntegration(PP, PZ, Tcurrent) ;
/*
* Increment time
*/
time += PP->dt ;
/*
* Calculate temperature at fluid/solid interface
*/
TfScurrent = TfluidSolidInterface(PZ, PP->NbCell[0], Tcurrent) ;
/*
* Check if the temperature change since the last save is significant
*/
if ( ((TfS->T[TfS->n] - TfScurrent ) > ((PP->Tinitial - PP->Tfinal) / NbTfluidSolidSave))
&& (TfScurrent >= PP->Tfinal) )
{
/*
* It's significant: Save the actual temperature at fluid/solid interface
*/
IncrementSizeTfluidSolid(TfS) ;
TfS->tn[TfS->n] = time ;
TfS->T[TfS->n] = TfScurrent ;
}
}
/*
* Linear interpolation to retreive the CDT at the exact target temperature
*/
double x = ( PP->Tfinal - TfScurrent )
/ ( TfluidSolidInterface(PZ, PP->NbCell[0], Tprev) - TfScurrent ) ;
time -= PP->dt * x ;
/*
* Do the same for the temperature profile
*/
for( i = 0 ; i <= PZ->N ; i++)
Tcurrent[i] += x * ( Tprev[i] - Tcurrent[i] ) ;
/*
* Save the last temperature at fluid/solid interface
*/
IncrementSizeTfluidSolid(TfS) ;
TfS->tn[TfS->n] = time ;
TfS->T[TfS->n] = TfluidSolidInterface(PZ, PP->NbCell[0], Tcurrent) ;
/*
* Free local pointers
*/
free(Tprev) ;
/*
* Return the cool down time
*/
return(time) ;
}
/* End of transient.c */