@@ -10190,16 +10190,17 @@ protected
1019010190 array<Integer> varIndices;
1019110191 list<String> tmpVarIndexListNew = {};
1019210192 list<DAE.Subscript> arraySubscripts;
10193- list<Integer> arrayDimensions;
10193+ list<Integer> arrayDimensions, arrayDimensions0 ;
1019410194algorithm
1019510195 arraySubscripts := ComponentReference.crefLastSubs(varName);
1019610196 varName := ComponentReference.crefStripLastSubs(varName);//removeSubscripts(varName);
1019710197 if(BaseHashTable.hasKey(varName, iVarToArrayIndexMapping)) then
10198- ((arrayDimensions,varIndices)) := BaseHashTable.get(varName, iVarToArrayIndexMapping);
10198+ ((arrayDimensions0,varIndices)) := BaseHashTable.get(varName, iVarToArrayIndexMapping); //varIndices are rowMajorOrder!
10199+ arrayDimensions := arrayDimensions0;
1019910200 arraySize := arrayLength(varIndices);
1020010201 if(iColumnMajor) then
1020110202 arraySubscripts := listReverse(arraySubscripts);
10202- arrayDimensions := listReverse(arrayDimensions );
10203+ arrayDimensions := listReverse(arrayDimensions0 );
1020310204 end if;
1020410205 concreteVarIndex := getUnrolledArrayIndex(arraySubscripts,arrayDimensions);
1020510206 //print("SimCodeUtil.getVarIndexInfosByMapping: Found variable index for '" + ComponentReference.printComponentRefStr(iVarName) + "'. The value is " + intString(concreteVarIndex) + "\n");
@@ -10216,7 +10217,12 @@ algorithm
1021610217 end if;
1021710218 end if;
1021810219 end for;
10219- oConcreteVarIndex := listGet(tmpVarIndexListNew, concreteVarIndex + 1);
10220+ if iColumnMajor then
10221+ oConcreteVarIndex := listGet(tmpVarIndexListNew,convertFlattenedIndexToRowMajor(concreteVarIndex + 1, arrayDimensions0));
10222+ //oConcreteVarIndex := listGet(tmpVarIndexListNew, concreteVarIndex + 1);
10223+ else
10224+ oConcreteVarIndex := listGet(tmpVarIndexListNew, concreteVarIndex + 1);
10225+ end if;
1022010226 end if;
1022110227 if(listEmpty(tmpVarIndexListNew)) then
1022210228 Error.addMessage(Error.INTERNAL_ERROR, {"GetVarIndexListByMapping: No Element for " + ComponentReference.printComponentRefStr(varName) + " found!"});
@@ -10227,6 +10233,24 @@ algorithm
1022710233 oVarIndexList := tmpVarIndexListNew;
1022810234end getVarIndexInfosByMapping;
1022910235
10236+ protected function convertFlattenedIndexToRowMajor
10237+ "author: waurich TUD 03/2015"
10238+ input Integer idx; //1-based, column major ordered
10239+ input list<Integer> rowMajorDimensions;
10240+ output Integer idxOut;//1-based, row major ordered
10241+ protected
10242+ Integer dimRow,dimCol,col,row;
10243+ algorithm
10244+ if intEq(listLength(rowMajorDimensions),2) then
10245+ {dimRow,dimCol} := rowMajorDimensions;
10246+ col := intDiv(idx-1,dimRow);//in which col?(0-based)
10247+ row := idx - col*dimRow; // in which row (1-based)
10248+ idxOut := (row-1)*dimCol + (col+1);
10249+ else
10250+ idxOut := idx;
10251+ end if;
10252+ end convertFlattenedIndexToRowMajor;
10253+
1023010254public function isVarIndexListConsecutive "author: marcusw
1023110255 Check if all variable indices of the given variables, stored in the hash table, are consecutive."
1023210256 input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
0 commit comments