Skip to content

Commit

Permalink
elabField function - converts field into array. Not finished yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Šilar authored and OpenModelica-Hudson committed Feb 10, 2016
1 parent 01c0933 commit 1ab7965
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -3546,8 +3546,7 @@ algorithm
is_function_input = InstUtil.isFunctionInput(ci_state, dir);
(cache, dims) = InstUtil.elabArraydim(cache, env2, own_cref, t, ad, eq, impl,
NONE(), true, is_function_input, pre, info, inst_dims);

dims = InstUtil.elabField(attr, dims);
(dims, mod_1) = InstUtil.elabField(attr, dims, mod_1);

// adrpo: 2011-11-18: see if the component is an INPUT or OUTPUT and class is a record
// and add it to the cache!
Expand Down
54 changes: 47 additions & 7 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -4602,25 +4602,65 @@ algorithm
end elabArraydimType2;

public function elabField
//For field variables: finds the "domain" modifier,
//finds domain.N - length of discretized field array
//and removes "domain" from the modifiers list.
input SCode.Attributes attr;
input DAE.Dimensions inDims;
input DAE.Mod inMod;
output DAE.Dimensions outDims;
algorithm
outDims := match(attr)
local
DAE.Dimension dim_f;
output DAE.Mod outMod;
protected DAE.Dimension dim_f;
protected SCode.Final finalPrefix;
protected SCode.Each eachPrefix;
protected list<DAE.SubMod> subModLst;
protected Option<DAE.EqMod> eqModOption;
protected Integer N;
algorithm
(outDims, outMod) := match(attr)
case(SCode.ATTR(isField=Absyn.NONFIELD()))
//TODO: check that the domain attribute (modifier) is not present.
then
inDims;
(inDims,inMod);
case(SCode.ATTR(isField=Absyn.FIELD()))
equation
dim_f = DAE.DIM_INTEGER(4);
DAE.MOD(finalPrefix = finalPrefix, eachPrefix = eachPrefix, subModLst = subModLst, eqModOption = eqModOption) = inMod;
//get N from the domain and remove domain from the subModLst:
(N, subModLst) = List.fold20(subModLst,domainSearchFun,-1,{});
subModLst = listReverse(subModLst);
outMod = DAE.MOD(finalPrefix, eachPrefix, subModLst, eqModOption);
dim_f = DAE.DIM_INTEGER(N);
then
dim_f::inDims;
(dim_f::inDims, outMod);
end match;
end elabField;

public function domainSearchFun
input DAE.SubMod subMod;
input Integer inN;
input list<DAE.SubMod> inSubModLst;
output Integer outN;
output list<DAE.SubMod> outSubModLst;
algorithm
(outSubModLst,outN) := match subMod
local
DAE.Mod mod;
// SCode.Final finalPrefix;
// SCode.Each eachPrefix;
list<DAE.SubMod> subModLst;
Option<DAE.EqMod> eqModOption;
case DAE.NAMEMOD(ident="domain", mod=mod)
equation
DAE.MOD(subModLst=subModLst,eqModOption=eqModOption)=mod;

//TODO: finish it - find and set domain.N

then (inSubModLst,44);
else (subMod::inSubModLst,inN);
end match;
end domainSearchFun;


public function addFunctionsToDAE
"@author: adrpo
we might need to intantiate partial functions, but we should NOT add them to the DAE!"
Expand Down
24 changes: 24 additions & 0 deletions Compiler/Util/List.mo
Expand Up @@ -3429,6 +3429,30 @@ algorithm
end for;
end fold43;

public function fold20<T, FT1, FT2>
"Takes a list and a function operating on list elements having two extra
arguments that are 'updated', thus returned from the function. fold will call
the function for each element in a sequence, updating the start value."
input list<T> inList;
input FoldFunc inFoldFunc;
input FT1 inStartValue1;
input FT2 inStartValue2;
output FT1 outResult1 = inStartValue1;
output FT2 outResult2 = inStartValue2;

partial function FoldFunc
input T inElement;
input FT1 inFoldArg1;
input FT2 inFoldArg2;
output FT1 outFoldArg1;
output FT2 outFoldArg2;
end FoldFunc;
algorithm
for e in inList loop
(outResult1, outResult2) := inFoldFunc(e, outResult1,outResult2);
end for;
end fold20;

public function fold5<T, FT, ArgT1, ArgT2, ArgT3, ArgT4, ArgT5>
"Takes a list and a function operating on list elements having an extra
argument that is 'updated', thus returned from the function, and five constant
Expand Down

0 comments on commit 1ab7965

Please sign in to comment.