Spaces:
Sleeping
Sleeping
File size: 10,038 Bytes
3d893c2 | 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 230 231 232 | // Scicos
//
// Copyright (C) INRIA - Author : EADS-CCR
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See the file ../license.txt
//
function [equations,flag_type,impl_type]=gen_code_FVM(a1,b1,a2,b2,a3,b3,a4,b4,..
a5,b5,a6,b6,a7,b7,N,oper,vbc,xn,xw)
// Cette fonction est pour la g�n�ration des �quations ODE ou DAE du bloc //
// sorties : //
// - equations (String) : vecteur qui contient le code C des �quations //
// d'etat (DAE) //
// - impl_type (Entier) : indique si le type des �tats //
// (diff�rentiels 1 ou alg�brique -1) //
// - flag_type (Entier) : 1 : explicie, 2 : implicite //
// entr�es : //
// - ai, bi (String) : les differents coeficients des op�rateurs //
// (ai(x) et bi(t)) //
// - a, b (Double) : limites du domaine [a b] //
// - N (Entier) : est le nombre de noeuds //
// - oper (Entier) : vecteur des op�rateurs selectionnes de 1 � 7 //
// - vbc (String) : vecteur des conditions aux limites en a et b //
// - xn (Double) : vecteur colonne representant les noeuds //
// - xw (Double) : vecteur colonne representant les cellules //
//----------------------------------------------------------------------- ---//
flag_type=1; // 1 : explicie, 2 : implicite
impl_type=1; // 1 pour syst�me d'�tat, -1 pour le syst�me alg�brique
sep=[",","*","/"];
coef51=[];
coef52=[];
coef1=[];
coef2=[];
cla=[];
clb=[];
clua=[];
club=[];
for i=1:size(xn,1)
x=xn(i);
a1_ev(i)=evstr(a1);
a2_ev(i)=evstr(a2);
a3_ev(i)=evstr(a3);
a4_ev(i)=evstr(a4);
a5_ev(i)=evstr(a5);
a6_ev(i)=evstr(a6);
a7_ev(i)=evstr(a7);
end
if ((find(oper == 2) ==[]) & (find(oper == 4) ==[]) ) then
// cas oper5 sans oper2 et oper4
if (find(oper == 5) ~=[] ) then
[coef51,coef52,coef21,coef22]=Disc2_5_FVM1d(h,kbc,5,N,xn,xw,a5);
cla=mulfv(msprintfv(full(coef52(1)/h)),vbc(1));
clb=mulfv(msprintfv(full(coef52(N)/h)),vbc(2));
end
if ( find(oper == 1) ~= []) then
// cas d2u/dt2
equations=emptystr(2*N,1);
vec2=equations;
for i=1:2*N
vec2(i)="x["+string(i-1)+"]";
end
for i=1:N
equations(i)=" xd["+string(i-1)+"]= "+vec2(i+N)+";";
F=mulfv(msprintfv(a7_ev(i)),b7);
if (i == 1) then
F=subfv(F,mulfv(cla,b5));
elseif (i == N) then
F=subfv(F,mulfv(clb,b5));
end
B=mulfv(mulfv(msprintfv(a3_ev(i)),b3),vec2(i+N));
C=addfv(mulfv(multMatVect(coef51(i,:)/h,vec2(1:N)),b5),mulf3v(msprintfv(a6_ev(i)),b6,vec2(i)));
A=mulfv(msprintfv(a1_ev(i)),b1);
equations(i+N)=" xd["+string(i+N-1)+"]=("+subfv(subfv(F,B),C)+")/"+A+";";
end
elseif ( find(oper == 3) ~= []) then
// cas du/dt (oper 3)
equations=emptystr(N,1);
vec2=equations;
for i=1:N
vec2(i)="x["+string(i-1)+"]";
end
for i=1:N
F=mulfv(msprintfv(a7_ev(i)),b7);
if (i == 1) then
F=subfv(F,mulfv(cla,b5));
elseif (i == N) then
F=subfv(F,mulfv(clb,b5));
end
B=mulfv(msprintfv(a3_ev(i)),b3);
C=addfv(mulfv(multMatVect(coef51(i,:)/h,vec2(1:N)),b5),mulf3v(msprintfv(a6_ev(i)),b6,vec2(i)));
equations(i)=" xd["+string(i+N-1)+"]=("+subfv(F,C)+")/"+B+";";
end
else
// cas alg�brique ==> implicite
flag_type=2;
impl_type=-1;
equations=emptystr(N,1);
vec2=equations;
for i=1:N
vec2(i)="x["+string(i-1)+"]";
end
if ( find(oper == 5) ~= []) then
cla=mulfv(msprintfv(full(coef52(1))),vbc(1));
clb=mulfv(msprintfv(full(coef52(N))),vbc(2));
end
for i=1:N
F=mulfv(msprintfv(h*a7_ev(i)),b7);
if (i == 1) then
F=subfv(F,mulfv(cla,b5));
elseif (i == N) then
F=subfv(F,mulfv(clb,b5));
end
C=addfv(mulfv(multMatVect(coef51(i,:),vec2(1:N)),b5),mulf3v(msprintfv(h*a6_ev(i)),b6,vec2(i)));
equations(i)=" res["+string(i-1)+"]="+subfv(F,C)+";";
end
end
else
// cas oper2 ou oper4
if (find(oper == 2) ~=[] ) then
[coef1,coef2,coef21,coef22]=Disc2_5_FVM1d(h,kbc,2,N,xn,xw,a2);
clua=mulfv(msprintfv(full(coef22(1))),vbc(1));
club=mulfv(msprintfv(full(coef22(N))),vbc(2));
end
if ( find(oper == 1) ~= []) then
// cas d2u/dt2
flag_type=2;
impl_type=0;
equations=emptystr(3*N,1);
vec2=equations; dvec2=vec2;
for i=1:3*N
vec2(i)="x["+string(i-1)+"]";
dvec2(i)="xd["+string(i-1)+"]";
end
for i=1:N
F=mulfv(vec2(i),msprintfv(h));
if (i == 1) then
F=subfv(F,mulfv(clua,b2));
elseif (i == N) then
F=subfv(F,mulfv(club,b2));
end
C=mulfv(multMatVect(coef21(i,:),vec2(N+1:2*N)),b2);
equations(i)=" res["+string(i-1)+"]="+subfv(F,C)+";";
equations(i+N)=" res["+string(i+N-1)+"]="+subfv(vec2(i+2*N),dvec2(i+N))+";";
F=mulfv(msprintfv(h*a7_ev(i)),b7);
if (i ~= 1 & i ~= N) then
B=addfv(mulfv(mulfv(msprintfv(h*a1_ev(i)),b1),dvec2(i+2*N)),mulfv(mulfv(msprintfv(h*a4_ev(i)),b4),dvec2(i)));
C=addfv(addfv(mulfv(multMatVect(coef1(i,:),vec2(1:N)),b2),mulf3v(msprintfv(h*a5_ev(i)),b5,vec2(i))),..
mulf3v(msprintfv(h*a6_ev(i)),b6,vec2(i+N)));
equations(i+2*N)=" res["+string(i+2*N-1)+"]="+subfv(subfv(F,B),C)+";";
end
end
elseif ( find(oper == 3) ~= [] | find(oper == 4) ~= []) then
// cas du/dt (oper 3)
flag_type=2;
impl_type=0;
equations=emptystr(2*N,1);
vec2=equations; dvec2=vec2;
for i=1:2*N
vec2(i)="x["+string(i-1)+"]";
dvec2(i)="xd["+string(i-1)+"]";
end
for i=1:N
F=mulfv(vec2(i),msprintfv(h));
if (i == 1) then
F=subfv(F,mulfv(clua,b2));
elseif (i == N) then
F=subfv(F,mulfv(club,b2));
end
C=mulfv(multMatVect(coef21(i,:),vec2(N+1:2*N)),b2);
equations(i)=" res["+string(i-1)+"]="+subfv(F,C)+";";
F=mulfv(msprintfv(h*a7_ev(i)),b7);
if (i ~= 1 & i ~= N) then
B=addfv(mulfv(mulfv(msprintfv(h*a3_ev(i)),b3),dvec2(i+N)),mulfv(mulfv(msprintfv(h*a4_ev(i)),b4),dvec2(i)));
C=addfv(addfv(mulfv(multMatVect(coef1(i,:),vec2(1:N)),b2),mulf3v(msprintfv(h*a5_ev(i)),b5,vec2(i))),..
mulf3v(msprintfv(h*a6_ev(i)),b6,vec2(i+N)));
equations(i+N)=" res["+string(i+N-1)+"]="+subfv(subfv(F,B),C)+";";
end
end
else
// cas alg�brique ==> implicite
flag_type=2;
impl_type=-1;
equations=emptystr(2*N,1);
vec2=equations;
for i=1:2*N
vec2(i)="x["+string(i-1)+"]";
end
for i=1:N
F=mulfv(vec2(i),msprintfv(h));
if (i == 1) then
F=subfv(F,mulfv(clua,b2));
elseif (i == N) then
F=subfv(F,mulfv(club,b2));
end
C=mulfv(multMatVect(coef21(i,:),vec2(N+1:2*N)),b2);
equations(i)=" res["+string(i-1)+"]="+subfv(F,C)+";";
F=mulfv(msprintfv(h*a7_ev(i)),b7);
if (i ~= 1 & i ~= N) then
C=addfv(addfv(mulfv(multMatVect(coef1(i,:),vec2(1:N)),b2),mulf3v(msprintfv(h*a5_ev(i)),b5,vec2(i))),..
mulf3v(msprintfv(h*a6_ev(i)),b6,vec2(i+N)));
equations(i+N)=" res["+string(i+N-1)+"]="+subfv(F,C)+";";
end
end
end
end
endfunction
|