Программная оболочка для численного решения краевых задач для систем двух связанных параболических уравнений. Программная оболочка для численного решения краевых задач для си. Дипломная работа Программная оболочка для численного решения краевых задач для систем двух связанных параболических уравнений
Скачать 0.78 Mb.
|
Приложениеunit Unit1; var Form1: TForm1; i,j,n,m,q,y:integer; A,B,C,dx,dy,r,s,p:double; //t1,l1:double; catalog:String; x,t,F,alfa,beta:array[0..n1+2] of double; u,v,u1,v1:vect; pogr: byte=0; f1:textfile; //st:extended; e,sf,fs,u0,v0,d11,d22,t11,l11,nn,mm:string; l:string; implementation uses Unit2, Unit3; {$R *.dfm} function timeSetEvent(uDelay, uReolytion:UINT; lpTimeProc: Pointer; dwUser: DWORD; fuEvent: UINT):Integer; stdcall; external 'winmm'; function timeKillEvent(uID:UINT):Integer; stdcall; external 'winmm'; Function LaunchAndWaitThemReturn(Command: String):Word; var Si:TStartupInfo; Pi:TProcessInformation; begin ZeroMemory(@Si, SizeOf(Si)); with Si do begin cb := SizeOf(Si); dwFlags := STARTF_USESHOWWINDOW; wShowWindow:=SW_HIDE; end; if CreateProcess(Nil, PChar(Command), Nil, Nil, True, CREATE_NEW_PROCESS_GROUP, Nil, Nil, Si, Pi) then begin CloseHandle(Pi.hThread); WaitForSingleObject(Pi.hProcess, INFINITE); CloseHandle(Pi.hProcess); Result:=0; end else Result:=107; end; //*************************************** procedure TForm1.fille; var SourceFile: TextFile; //TmpStr: string; TmpStr: string; ni:double; i:integer; begin AssignFile(SourceFile, 'func_lib.pas '); Rewrite(SourceFile); Writeln(SourceFile, 'library ',' ',' func_lib',';'); Writeln(SourceFile, ''); Writeln(SourceFile, 'uses'); Writeln(SourceFile, 'math;'); Writeln(SourceFile, '{$R *.res}'); Writeln(SourceFile, ' function pov(const Base: Extended; const Exponent: Integer): Extended;'); Writeln(SourceFile, 'asm'); Writeln(SourceFile, 'mov ecx, eax'); Writeln(SourceFile, 'cdq'); Writeln(SourceFile, 'fld1 { Result := 1 }'); Writeln(SourceFile, 'xor eax, edx'); Writeln(SourceFile, 'sub eax, edx { eax := Abs(Exponent) }'); Writeln(SourceFile, 'jz @@3'); Writeln(SourceFile, 'fld Base'); Writeln(SourceFile, 'jmp @@2'); Writeln(SourceFile, '@@1: fmul ST, ST { X := Base * Base }'); Writeln(SourceFile, '@@2: shr eax,1'); Writeln(SourceFile, 'jnc @@1'); Writeln(SourceFile, 'fmul ST(1),ST { Result := Result * X }'); Writeln(SourceFile, 'jnz @@1'); Writeln(SourceFile, 'fstp st { pop X from FPU stack }'); Writeln(SourceFile, 'cmp ecx, 0'); Writeln(SourceFile, 'jge @@3'); Writeln(SourceFile, 'fld1'); Writeln(SourceFile, 'fdivrp { Result := 1 / Result }'); Writeln(SourceFile, '@@3:'); Writeln(SourceFile, 'fwait'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, ''); Writeln(SourceFile, 'Function ' ,' ','D', '(u,v: double):double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',fs,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','G', '(u,v: double):double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',sf,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','unach', '(x: double):double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',u0,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','vnach', '(x: double):double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',v0,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','d1', ':double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',d11,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','d2', ':double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',d22,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','n', ':integer;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',nn,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','m', ':integer;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',mm,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','t1', ':double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',t11,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Function ' ,' ','l1', ':double;'); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'Result:=',l11,';'); Writeln(SourceFile, 'end;'); Writeln(SourceFile, 'Exports'); Writeln(SourceFile, 'D',',','G',',','unach',',','vnach',',','d1',',','d2',',','t1',',','l1',',','n',',','m',';'); Writeln(SourceFile, ''); Writeln(SourceFile, 'begin'); Writeln(SourceFile, 'end.'); CloseFile(SourceFile); end; //*************************************** //*************************************** procedure TForm1.BitBtn1Click(Sender: TObject); var uEventID:UINT; delay:Word; BegTime:TdateTime; D,G:function(x,y: double):double; unach,vnach:function(x: double):double; d1,d2,t1,l1:function :double; n,m:function :integer; Handle:LongWord; Edit: array[1..3] of string; begin fs:=Edit7.Text; sf:=Edit8.Text; nn:=Edit1.Text; mm:=Edit2.Text; d11:=Edit5.Text; d22:=Edit6.Text; t11:=Edit4.Text; l11:=Edit3.Text; u0:=Edit9.Text; v0:=Edit10.Text; //FreeLibrary(handle); //DeleteFile('func_lib.dll'); //DeleteFile('func_lib.pas'); fille; LaunchAndWaitThemReturn('dcc32.exe func_lib.pas'); Handle:=LoadLibrary('func_lib.dll'); if handle=0 then begin ShowMessage('не найдена библиотека либо не корректно задана функция'); exit; end; @D:=GetProcAddress(Handle,'D'); @G:=GetProcAddress(Handle,'G'); @unach:=GetProcAddress(Handle,'unach'); @vnach:=GetProcAddress(Handle,'vnach'); @d1:=GetProcAddress(Handle,'d1'); @d2:=GetProcAddress(Handle,'d2'); @t1:=GetProcAddress(Handle,'t1'); @l1:=GetProcAddress(Handle,'l1'); @n:=GetProcAddress(Handle,'n'); @m:=GetProcAddress(Handle,'m'); form2.StringGrid1.ColCount:=n+4; form2.StringGrid1.RowCount:=2*m+18; dx := l1/n; dy :=t1/ m; edit12.Text:=floattostr(dx); edit13.Text:=floattostr(dy); for i:=0 to n do begin x[i]:= i*dx; Form2.StringGrid1.Cells[i+2,9]:=FloatToStr(x[i]); Form2.stringGrid1.Cells[i+2,m+13]:=FloatToStr(x[i]); end; for i:=0 to n do begin u[i,0]:=unach(x[i]); v[i,0]:=vnach(x[i]); Form2.StringGrid1.Cells[i+2,14+m]:=FloatToStr(v[i,0]); Form2.StringGrid1.Cells[i+2,10]:=FloatToStr(u[i,0]); end; Form2.StringGrid1.Cells[y+2,10]:=FloatToStr(u[y,0]); Form2.StringGrid1.Cells[y+2,14+m]:=FloatToStr(v[y,0]); for j:=0 to m do begin t[j]:=j*dy; Form2.StringGrid1.Cells[1,14+m+j]:=FloatToStr(t[j]); Form2.StringGrid1.Cells[1,j+10]:=FloatToStr(t[j]); end; q:=0; alfa[1]:= 1; beta[1]:= 0; For s:=1 To 1 do p:=0; r:=0; For j:=0 To m-1 do begin A:= -d1 / sqr(dx); B:= 1 / dy + (2 * d1) / sqr(dx); C:= -d1 / sqr(dx); For i:=1 To n-1 do begin // u1[i,j+1]:=u[i,j+1]; F[i]:= (1 / dy) * u[i, j]+D(u[i,j],v[i,j]); alfa[i + 1]:= -C / (A * alfa[i] + B); beta[i + 1]:= (F[i] - A * beta[i]) / (A * alfa[i] + B); end; if alfa[n]=1 then begin ShowMessage('не правильно заданы параметры'); exit; // halt; end; u[n, j + 1] := beta[n] / (1 - alfa[n]); Form2.stringGrid1.Cells[n+2,11+j]:=FloatToStr(u[i, j + 1]); For i:= n - 1 downTo 0 do begin u[i, j + 1]:= alfa[i + 1] * u[i + 1, j + 1] + beta[i + 1]; Form2.stringGrid1.Cells[i+2,11+j]:=FloatToStr(u[i, j + 1]); p := Abs(u1[i, j + 1] - u[i, j + 1]); If p > r Then r:= p; end; //************************************* A := -d2 / sqr(dx); B := 1 / dy + (2 * d2) / sqr(dx); C := -d2 / sqr(dx); For i := 1 To n-1 do begin // v1[i, j + 1] := v[i, j + 1]; // F[i] := (1 / dy) * v[i, j] + (u[i, j] - 1 - 0.4 * v[i, j]) * v[i, j]; F[i] := (1 / dy) * v[i, j] + G(u[i,j],v[i,j]); alfa[i + 1]:= -C / (A * alfa[i]+ B); beta[i + 1]:= (F[i] - A * beta[i]) / (A * alfa[i] + B); end; if alfa[n]=1 then begin ShowMessage('не правильно заданы параметры'); exit;// halt; end; v[n, j + 1] := beta[n] / (1 - alfa[n]); Form2.stringGrid1.Cells[n+2,15+m+j]:=FloatToStr(v[i, j + 1]); For i:= n - 1 downTo 0 do begin v[i, j + 1]:= alfa[i + 1] * v[i + 1, j + 1] + beta[i + 1]; Form2.stringGrid1.Cells[i+2,15+m+j]:=FloatToStr(v[i, j + 1]); p := Abs(v1[i, j + 1] - v[i, j + 1]); If p > r Then r:= p; end; end; //по j q := q + 1; Form2.stringGrid1.Cells[3,1]:=FloatToStr(q); If q > 10 Then s := s + 2; If r > 0.0001 Then s := s - 1; //Timer1.Enabled := False; begin DeleteFile('text.dat'); AssignFile(f1, 'text.dat'); Rewrite(f1); writeln(f1,'TITLE = "Example: Simple 3D-Volume Data"'); writeln(f1,'VARIABLES = "X", "Y", "Density"'); writeln(f1,'ZONE I=', n+1,' J=',m,' F=POINT'); for j:=1 to m do for i:=0 to n do begin Writeln(f1,i*l1/n,' ',j*t1/m,' ',u[i,j]); end; //timeKillEvent(uEventID); CloseFile(f1); end; begin DeleteFile('text2.dat'); AssignFile(f1, 'text2.dat'); Rewrite(f1); writeln(f1,'TITLE = "Example: Simple 3D-Volume Data"'); writeln(f1,'VARIABLES = "X", "Y", "Density"'); writeln(f1,'ZONE I=', n+1,' J=',m,' F=POINT'); for j:=1 to m do for i:=0 to n do begin Writeln(f1,i*l1/n,' ',j*t1/m,' ',v[i,j]); end; //timeKillEvent(uEventID); CloseFile(f1); end; Form3.Chart1.Series[0].Clear; Form3.Chart1.Series[1].Clear; For i := 1 To n do begin Form3.Chart1.SeriesList[0].Add(u[i,m],IntToStr(i),clRed); end; Form3.Chart2.Series[0].Clear; Form3.Chart2.Series[1].Clear; For i := 1 To n do begin Form3.Chart2.SeriesList[0].Add(v[i,m],IntToStr(i),clRed); end; FreeLibrary(handle); DeleteFile('func_lib.dll'); DeleteFile('func_lib.pas'); timeToStr(Time-BegTime); // edit11:=FloatToStr(); edit11.Text:=(timeToStr(Time-BegTime)); // showmessage(timeToStr(Time-BegTime)); Form3.Show; end; //************************************************* procedure TForm1.clear; begin for i:=0 to n do for j:=0 to m do begin Form2.StringGrid1.Cells[i,j]:=' '; // StringGrid1.Cells[i,j]:=' '; end; end; //************************************************ procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin DeleteFile('text.dat'); DeleteFile('text2.dat'); end; procedure TForm1.MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin case (Sender as TComponent).Tag of 1: Panel1.Caption:='Количество шагов по пространству'; 2: Panel1.Caption:='Количество шагов по времени'; 3: Panel1.Caption:='Коэффициент диффузии'; 4: Panel1.Caption:='Функция'; 5: Panel1.Caption:='Функция'; 6: Panel1.Caption:='Длина отрезка по x'; 7: Panel1.Caption:='Начальное условие'; 8: Panel1.Caption:='Длина отрезка по t'; end; end; procedure TForm1.GroupBox2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Panel1.Caption:=''; end; procedure TForm1.Button1Click(Sender: TObject); begin ExcelApplication1.Workbooks.Add(EmptyParam,0); ExcelApplication1.EnableEvents := false; n:=StrToint(Form1.Edit1.Text); m:=StrToint(Form1.Edit2.Text); for j:=0 to m-1 do for i:=0 to n do begin ExcelApplication1.Cells.Item[j+11,i+2]:=u[i, j + 1]; end; // ExcelApplication1.Visible:=true; ExcelApplication1.Visible[0]:=true; end; end. |