/*
* 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 */