unit DirectUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, ComCtrls, ShellCtrls, DBCtrls, FileCtrl,
  Math, HCArrays, HCConduct, HCMaterial, HCModel, UPohMath, UPohStrConv;

procedure SetBoundCond(var model: tHCModel);
procedure MainDirectTask(var VysledkyFile:TextFile; MatDtb: tMatDB; var model:tHCModel; q: array of double; n:integer; path:string; dt:double; hloubka:double);

const
  mm=0.001;
  Cel_Kel=273.15;
  

implementation

procedure SetBoundCond(var model: tHCModel);
begin
	// left side - q
	  fHC_SetBoundaryIntWE(model, model.bW_kind, 2);
  	fHC_SetBoundaryFloatWE(model, model.bW_v, 0);
	  fHC_SetBoundaryFloatWE(model, model.bW_t, 0);
  	fHC_SetBoundaryFloatWE(model, model.bW_e, 0);
	// rigth side - insulation
	  fHC_SetBoundaryIntWE(model, model.bE_kind, 2);
  	fHC_SetBoundaryFloatWE(model, model.bE_v, 0);
	  fHC_SetBoundaryFloatWE(model, model.bE_t, 0);
  	fHC_SetBoundaryFloatWE(model, model.bE_e, 0);
end;

procedure MainDirectTask(var VysledkyFile:TextFile; MatDtb: tMatDB; var model:tHCModel; q: array of double; n:integer; path:string; dt:double; hloubka:double);
var
  step, iterations:integer;
  str:string;
  t, max_err:double;
begin
  t := (n-1)*dt; // end time [s]
  max_err := 1.0/(t/dt); // desired accuracy for one time step
  //max_err := Max(0.0001, 0.25 * dt);
  
  step := 0;
  while(step < n) do begin
    Inc(step);
  	fHC_SetBoundaryFloatWE(model, model.bW_v, q[step]);     // q
    iterations := fHC_HC1TimeStep(model, MatDtb, dt, 5, max_err); // compute one time step and return number of internal iterations
    //str := Format('%5.5d', [step]);
    //fHC_SaveFloatChart4D_HCModel(model, model.vT, PChar(path + '\Graph\T' + str), -Cel_Kel, 1/ mm);
    writeln(VysledkyFile,IntToStr(step),#9,FloatToStr(step*dt),#9,FloatToStr(fHC_GetInterpValHCModel(model.vT, model, hloubka, 0, 0)-Cel_Kel));
  end;
end;

end.
