(********************************************
  Version: 7.0
  Date: 2003/11/25
  This is shareware.
  Copyright (C) Michal Pohanka
  All rights reserved.

  Internet: http://www.volny.cz/profipohanka
 ********************************************)

unit HCMaterial;

interface

uses HCArrays;

const
  pm_ro: integer = $01;
  pm_c: integer = $02;
  pm_k: integer = $04;
  pm_roc: integer = $08;
  pm_h: integer = $10;
  pm_e: integer = $20;
  pm_fs: integer = $40;

type
  tLinProp = record
    v: tXYArray; // loaded values
    arrStep: float; // must be "arrayStep>0" to use with valFast
    arrBegin, arrEnd: float;
    valFast: tXYArray; // created using val, where with valFast[int((X-arrBegin)/arrStep)] do Y=x*X+y
  end;

  // structure for Ro*C
  tRoCProp = record
    arrStep: float; // must be "arrayStep>0" to use with valFast
    arrBegin, arrEnd: float;
    valFast: tXYZArray; // valFast[int((X-arrBegin)/arrStep)] do Y=x*X^2+y*X+z
  end;

  // structure for enthalpy
  tEnthProp = record
    arrStep: float; // must be "arrayStep>0" to use with valFast
    arrBegin, arrEnd: float;
    valFast: tABCDArray; // valFast[int((X-arrBegin)/arrStep)] do Y=a*X^3+b*X^2+c*X+d
  end;

  // Material
  tMat = record
    ver: integer; // version
    name: tMyString; //material name
    ro: tLinProp; // [K], density [kg/m^3]
    c: tLinProp; // [K], specific capacity [J/kg.K]
    k: tLinProp; // [K], conductivity [W/m.K]
    roc: tRoCProp; // Ro*C [SI]
    h: tEnthProp; // enthalphy [SI]
    e: tLinProp; // heat expansion [K] - [1/K]
    fs: tLinProp; // flow stress [K] - [Pa]
  end;

  tempArrMat = packed array[0..1000] of tMat;

  // Material Database
  tMatDB = record
    version: integer; // version
    mat: ^tempArrMat;
    n: integer; // array size
  end;

///////////////////////////////////////////////////////////////////////////////////////////////////
function fHC_GetMaterialAccuracy: float; cdecl; external 'HC.DLL' name '?fHC_GetMaterialAccuracy@@YANXZ';
procedure fHC_SetMaterialAccuracy(accuracy: float); cdecl; external 'HC.DLL' name '?fHC_SetMaterialAccuracy@@YAXN@Z';

procedure fHC_Init(var a: tLinProp); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtLinProp@@@Z';
procedure fHC_Init(var a: tRoCProp); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtRoCProp@@@Z';
procedure fHC_Init(var a: tEnthProp); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtEnthProp@@@Z';
procedure fHC_Init(var a: tMat); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtMat@@@Z';
procedure fHC_Init(var a: tMatDB); overload; cdecl; external 'HC.DLL' name '?fHC_Init@@YAXAAUtMatDB@@@Z';

procedure fHC_Free(var a: tLinProp); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtLinProp@@@Z';
procedure fHC_Free(var a: tRoCProp); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtRoCProp@@@Z';
procedure fHC_Free(var a: tEnthProp); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtEnthProp@@@Z';
procedure fHC_Free(var a: tMat); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtMat@@@Z';
procedure fHC_Free(var a: tMatDB); overload; cdecl; external 'HC.DLL' name '?fHC_Free@@YAXAAUtMatDB@@@Z';

function fHC_Add(var db: tMatDB; var m: tMat): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Add@@YAHAAUtMatDB@@AAUtMat@@@Z'; // return index of added item; -1=error
function fHC_SetLength(var db: tMatDB; l: integer): integer; overload; cdecl; external 'HC.DLL' name '?fHC_SetLength@@YAHAAUtMatDB@@H@Z'; // set array size; return a new size
function fHC_Insert(var db: tMatDB; idx: integer; var m: tMat): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Insert@@YAHAAUtMatDB@@HAAUtMat@@@Z'; // insert item; return 0=OK
function fHC_Delete(var db: tMatDB; idx: integer): integer; cdecl; overload; external 'HC.DLL' name '?fHC_Delete@@YAHAAUtMatDB@@H@Z'; // delete item; return 0=OK
procedure fHC_Sort(var db: tMatDB; key: integer); cdecl; overload; external 'HC.DLL' name '?fHC_Sort@@YAXAAUtMatDB@@H@Z'; // sort array, +-1=, positive-ascending, negative-descending
function fHC_Find(var db: tMatDB; name: PChar): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Find@@YAHAAUtMatDB@@QAD@Z'; // return 0>=OK, -1=Error

function fHC_Copy(var d: tLinProp; var s: tLinProp): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtLinProp@@0@Z'; // return 0=OK, -1=Error
function fHC_Copy(var d: tRoCProp; var s: tRoCProp): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtRoCProp@@0@Z'; // return 0=OK, -1=Error
function fHC_Copy(var d: tEnthProp; var s: tEnthProp): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtEnthProp@@0@Z'; // return 0=OK, -1=Error
function fHC_Copy(var d: tMat; var s: tMat): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtMat@@0@Z'; // return 0=OK, -1=Error
function fHC_Copy(var d: tMatDB; var s: tMatDB): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Copy@@YAHAAUtMatDB@@0@Z'; // return 0=OK, -1=Error

function fHC_LoadMatDB(var d: tMatDB; name: PChar): integer; cdecl; external 'HC.DLL' name '?fHC_Load@@YAHAAUtMatDB@@QAD@Z'; // return number of loaded materials, -1=Unspecified Error, -2=Version error, -100=no memory
function fHC_SaveMatDB(var d: tMatDB; name: PChar): integer; cdecl; external 'HC.DLL' name '?fHC_Save@@YAHAAUtMatDB@@QAD@Z'; // return 0=OK, -1=Error
procedure fHC_GetErrMatDB(var s: tMyString); cdecl; external 'HC.DLL' name '?fHC_GetErrMatDB@@YAXAAUtMyString@@@Z'; // returns error description stored in vHC_MatDBErrString; use with fHC_LoadMatDB fHC_SaveMatDB

function fHC_Prepare(var p: tLinProp): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Prepare@@YAHAAUtLinProp@@@Z'; // return 0=OK, -1=Error
function fHC_Prepare(var roc: tRoCProp; var ro: tLinProp; var c: tLinProp): integer; overload; cdecl; external 'HC.DLL' name '?fHC_PrepareRoCProp@@YAHAAUtRoCProp@@AAUtLinProp@@1@Z'; // return 0=OK, -1=Error
function fHC_Prepare(var h: tEnthProp; var roc: tRoCProp): integer; overload; cdecl; external 'HC.DLL' name '?fHC_PrepareEnthProp@@YAHAAUtEnthProp@@AAUtRoCProp@@@Z'; // return 0=OK, -1=Error
function fHC_Prepare(var m: tMat): integer; overload; cdecl; external 'HC.DLL' name '?fHC_PrepareMat@@YAHAAUtMat@@@Z'; // return 0=OK
function fHC_Prepare(var db: tMatDB): integer; overload; cdecl; external 'HC.DLL' name '?fHC_Prepare@@YAHAAUtMatDB@@@Z'; // return 0=OK

procedure fHC_SetMatAutoFastStep(var m: tMat); cdecl; external 'HC.DLL' name '?fHC_SetMatAutoFastStep@@YAXAAUtMat@@@Z';
procedure fHC_SetMatDBAutoFastStep(var db: tMatDB); cdecl; external 'HC.DLL' name '?fHC_SetMatDBAutoFastStep@@YAXAAUtMatDB@@@Z';

function fHC_GetValFast(var p: tLinProp; x: float): float; overload; cdecl; external 'HC.DLL' name '?fHC_GetValFast@@YANABUtLinProp@@N@Z'; // get=y=X[]*x+Y[]; constant outside range <begin-end>
function fHC_GetValFast(var p: tRoCProp; x: float): float; overload; cdecl; external 'HC.DLL' name '?fHC_GetValFast@@YANABUtRoCProp@@N@Z'; // get=y=X[]*x^2+Y[]*x+Z[]; constant outside range <begin-end>
function fHC_GetValFast(var p: tEnthProp; x: float): float; overload; cdecl; external 'HC.DLL' name '?fHC_GetValFast@@YANABUtEnthProp@@N@Z'; // get=y=A[]*x^3+B[]*x^2+C[]*x+D[]; linear outside range <begin-end>

implementation

end.

