Skip to content

Commit

Permalink
Fixed bug with missing delete for A and b arrays for linear equation …
Browse files Browse the repository at this point in the history
…systems.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2481 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Aug 24, 2006
1 parent b93a43f commit 9e49dc2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
42 changes: 39 additions & 3 deletions Compiler/SimCodegen.mo
Expand Up @@ -3654,8 +3654,8 @@ algorithm
(outCFunction,outInteger,outCFunctionLst):=
matchcontinue (inDAELow,inTplIntegerIntegerDAELowEquationLstOption,inJacobianType,inInteger)
local
Codegen.CFunction s1,s2,s3,s4,s;
Integer cg_id_1,cg_id,eqn_size,unique_id,cg_id1,cg_id2,cg_id3,cg_id4;
Codegen.CFunction s1,s2,s3,s4,s5,s;
Integer cg_id_1,cg_id,eqn_size,unique_id,cg_id1,cg_id2,cg_id3,cg_id4,cg_id5;
list<CFunction> f1;
DAELow.DAELow dae,d;
Option<list<tuple<Integer, Integer, DAELow.Equation>>> jac;
Expand Down Expand Up @@ -3707,7 +3707,8 @@ algorithm
(s2,cg_id2) = generateOdeSystem2PopulateAb(jac, v, eqn, unique_id, cg_id1);
(s3,cg_id3) = generateOdeSystem2SolveCall(eqn_size, unique_id, cg_id2);
(s4,cg_id4) = generateOdeSystem2CollectResults(v, unique_id, cg_id3);
s = Codegen.cMergeFns({s1,s2,s3,s4});
(s5,cg_id5) = generateOdeSystem2Cleanup(eqn_size, unique_id, cg_id4);
s = Codegen.cMergeFns({s1,s2,s3,s4,s5});
then
(s,cg_id4,{});
case (DAELow.DAELOW(orderedVars = v,knownVars = kv,orderedEqs = eqn,arrayEqs=ae),SOME(jac),DAELow.JAC_NONLINEAR(),cg_id) /* Time varying nonlinear jacobian. Non-linear system of equations */
Expand Down Expand Up @@ -4498,6 +4499,41 @@ algorithm
end matchcontinue;
end generateOdeSystem2Declaration;

protected function generateOdeSystem2Cleanup "
Generates code for the cleanups (delete) of A and b when
solving linear systems of equations.
inputs: (size: int, unique_id: int)
outputs: (fcn : CFunction)
"
input Integer inInteger1;
input Integer inInteger2;
input Integer inInteger3;
output CFunction outCFunction;
output Integer outInteger;
algorithm
(outCFunction,outInteger):=
matchcontinue (inInteger1,inInteger2,inInteger3)
local
String size_str,id_str,stmt1,stmt2;
Codegen.CFunction res;
Integer size,unique_id,cg_id;
case (size,unique_id,cg_id) /* size unique_id cg var_id cg var_id */
equation
size_str = intString(size);
id_str = intString(unique_id);
stmt1 = Util.stringAppendList({"free_matrix(A",id_str,");"});
stmt2 = Util.stringAppendList({"free_vector(b",id_str,");"});
res = Codegen.cAddStatements(Codegen.cEmptyFunction, {stmt1,stmt2});
then
(res,cg_id);
case (size,unique_id,cg_id)
equation
Debug.fprint("failtrace", "generateOdeSystem2Cleanup failed\n");
then
fail();
end matchcontinue;
end generateOdeSystem2Cleanup;

protected function generateOdeSystem2PopulateAb "function: generateOdeSystem2PopulateAb
author: PA
Expand Down
3 changes: 3 additions & 0 deletions c_runtime/matrix.h
Expand Up @@ -31,6 +31,9 @@ void hybrd_(void (*) (int*, double *, double*, int*),
assert(A!=0); \
for (int i=0;i<nrows*ncols;i++) A[i]=0.0;

#define free_matrix(A) delete []A;
#define free_vector(A) delete []A;

#define declare_vector(v,nelts) double *v=new double[nelts];\
assert(v!=0); \
for (int i=0;i<nelts;i++) v[i]=0.0;
Expand Down

0 comments on commit 9e49dc2

Please sign in to comment.