Spaces:
Sleeping

File size: 7,147 Bytes
39e01c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
//  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 Code=code_generation(rdnom,equations,eq_pts_mes,flag_type,h,CI,CI1,a,..
    N,Ninitiale,impl_type,type_meth,oper)
    // Cette fonction conserne la génération du code de la la fonction de calcul du bloc EDP //
    // entrées :                                                                             //
    //           - equations : vecteurs de chaine de caractères corespond aux équation ODE   //
    //                         ou DAE générées selon les différentes méthodes de             //
    //                         discrétisation.                                               //
    //           - impl_type : entier correspond au type des équations DAE (implicites)       //
    //                         ( -1 pour les systèmes algébriques, 1 pour les systèmes       //
    //                         algébro-différentiels).                                       //
    // sortie :                                                                              //
    //           - Code : vecteur de chaine de caratères qui renvoie le code du bloc à        //
    //                    imprimer par la suite dans le fichier .c                           //
    // pour plus d'information voir les fonctions de calcul des blocs Scicos de type 4       //
    // (explicite) et de type 10004 (implicite).                                             //
    //---------------------------------------------------------------------------------------//

    Code=["#include <scicos_block.h>"
    "#include <math.h>"
    " "
    "void  "+rdnom+"(scicos_block *block,int flag)"
    "{"
    " "
    " double **inptr = block->inptr;"
    " double **outptr = block->outptr;"
    " double *x = block->x;"
    " int nx = block->nx;"
    " double *xd = block->xd;"]
    if (flag_type == 2) then
        Code=[Code
        " double *res = block->res;"]
        if (type_meth == 3 & (find(oper == 2) ~= [] | find(oper == 4) ~= [])) then
            if (find(oper == 1) ~= []) then
                Code=[Code
                " int property["+string(3*N)+"];"]
            else
                Code=[Code
                " int property["+string(2*N)+"];"]
            end
        elseif (find(oper == 1) ~= []) then
            Code=[Code
            " int property["+string(2*N)+"];"]
        else
            Code=[Code
            " int property["+string(N)+"];"]
        end
    end
    Code=[Code
    " "
    " int i;"
    " double t = get_scicos_time();"
    " "
    " if (flag == 0){"
    equations
    " }else if (flag == 1){"];
    if (type_meth == 3 & (find(oper == 2) ~= [] | find(oper == 4) ~= [])) then
        sorties1=[_("   /* First output */ ")
        "   for (i=0;i<"+string(N)+";i++){"
        "     outptr[0][i]=x[i+"+string(N)+"];"
        "   }"];
        sorties2=[_("   /* Second output */ ")];
        for i=1:size(eq_pts_mes,"*")
            sorties2=[sorties2
            "   outptr[1]["+string(i-1)+"]="+eq_pts_mes(i)+";"];
        end
    else
        if (kbc(1) == 1) & (DF_type == 0 | DF_type == 1) then
            sorties1=[_("   /* Fist output */ ")
            "   for (i=1;i<"+string(Ninitiale)+";i++){"
            "     outptr[0][i]=x[i];"
            "   }"];
        else
            sorties1=[_("   /* Fist output */ ")
            "   for (i=0;i<"+string(Ninitiale)+";i++){"
            "     outptr[0][i]=x[i];"
            "   }"];
        end
        sorties2=[_("   /* Second output */ ")];
        for i=1:size(eq_pts_mes,"*")
            sorties2=[sorties2
            "   outptr[1]["+string(i-1)+"]="+eq_pts_mes(i)+";"];
        end
    end
    Code=[Code
    sorties1
    sorties2
    " }else if (flag == 4){"];
    condini=[];
    x=a;
    // si on a un systeme algebrique on a pas besoin des conditions initiales.
    if (impl_type ~= -1) then
        if (find(oper == 1) == []) then
            for i=1:N
                condini=[condini
                "   x["+string(i-1)+"]="+msprintf("%.16g",evstr(CI))+";"];
                x=x+h;
            end
        else
            for i=1:N
                condini=[condini
                "   x["+string(i-1)+"]="+msprintf("%.16g",evstr(CI))+";";
                "   x["+string(i+N-1)+"]="+msprintf("%.16g",evstr(CI1))+";"];
                x=x+h;
            end
        end
    end
    Code=[Code
    condini
    "/* }else if (flag == 5){ */"];
    final=[];
    Code=[Code
    final]
    if (flag_type == 2) then
        property=[];
        if (find(oper == 1) ~= []) then
            if (impl_type == 0) then
                for i=1:N
                    property=[property
                    "   property["+string(i-1)+"]=-1;";
                    "   property["+string(i+N-1)+"]=1;";
                    "   property["+string(i+2*N-1)+"]=1;"];
                end
            else
                for i=1:2*N
                    property=[property
                    "   property["+string(i-1)+"]="+string(impl_type)+";"];
                end
                property(N+1)="   property["+string(N)+"]="+string(-1)+";";
                property($)="   property["+string(2*N-1)+"]="+string(-1)+";";
            end
        else
            if (impl_type == 0) then
                for i=1:N
                    property=[property
                    "   property["+string(i-1)+"]=-1;";
                    "   property["+string(i+N-1)+"]=1;"];
                end
            else
                if (type_meth ==3 & (find(oper == 2) ~= [] | find(oper == 4) ~= [])) then
                    for i=1:2*N
                        property=[property
                        "   property["+string(i-1)+"]="+string(impl_type)+";"];
                    end
                else
                    property=[property
                    "   property["+string(0)+"]="+string(-1)+";"];
                    for i=2:N-1
                        property=[property
                        "   property["+string(i-1)+"]="+string(impl_type)+";"];
                    end
                    property=[property
                    "   property["+string(N-1)+"]="+string(-1)+";"];
                end
            end
        end

        Code=[Code
        " }else if (flag == 7){"
        property
        "  set_pointer_xproperty(property);"]
    end
    Code=[Code
    " }"
    " return;"
    "}"];

endfunction