Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » ALAIN_2
  • » Profile

Posts

Posts

Jul-10-15 12:50:38
Enumeration - MOF file - OMC 1.9.2 (r7)
Category: Developer

Hello,

  I don't know if the compilation and generation of C code for this following test are correct
           model TestEnumeration1
                  type Size = enumeration(small, medium, large, xlarge);
                   parameter Size t_shirt_size = Size.medium;
             end TestEnumeration1;

  because if I examine the MOF associated generated file, according to me, there is one mistake :
           class TestEnumeration1
                parameter enumeration(small, medium, large, xlarge) t_shirt_size = TestEnumeration1.Size.medium;
          end TestEnumeration1;

the defdinition of the type Size is not included

Thanks

Regards

ALAIN_2

Jul-08-15 15:12:58
Translation of algebraic variabe into constant
Category: Developer

Hello,

  I take into account this kind of MODELICA model "TestCeil.mo" defined such as  :

  model TestCeil
      Real x;
equation
       x = ceil(4.5);
end TestCeil;


The TestCeil.mof associated flattened  file is then  the following one:

  c lass TestCeil
      Real x;
    equation
         x = 5.0;
  end TestCeil;

and the associated  generated XML file TestCeil_init.xml contains :

<ScalarVariable
  name = "x"
  valueReference = "1000"
  variability = "continuous" isDiscrete = "false"
  causality = "internal" isValueChangeable = "false"
  alias = "noAlias"
  classIndex = "0" classType = "rAlg"
  isProtected = "false"
  fileName = "TestCeil.mo" startLine = "3" startColumn = "3" endLine = "3" endColumn = "9" fileWritable = "true">
  <Real useStart="false" fixed="false" useNominal="false" />
  </ScalarVariable>

=>
       I would like to know why the x variable is always an algebraic variable of the model ?
     
      the x variable has not to become a constant ?

Thanks;

regards;

ALAIN_2

Jun-22-15 15:13:34
Category: Developer



It give you only a part of code belonging to a shell script
You must include it in ,for instance, lance_omc.sh,

#!/bin/bash
#set -x

test=$1
if [ ! -f ${test} ]; then
   echo "%% Error : le fichier de donnees \"$test\" n'existe pas."
   exit
fi
BIN_OPENMODELICA=$INSTALL_OPENMODELICA/bin  <= Put the place where omc is installed

....


Best regards

ALAIN_2

Jun-22-15 15:13:30
Category: Developer



It give you only a part of code belonging to a shell script
You must include it in ,for instance, lance_omc.sh,

#!/bin/bash
#set -x

test=$1
if [ ! -f ${test} ]; then
   echo "%% Error : le fichier de donnees \"$test\" n'existe pas."
   exit
fi
BIN_OPENMODELICA=$INSTALL_OPENMODELICA/bin  <= Put the place where omc is installed

....


Best regards

ALAIN_2

Jun-22-15 15:13:26
Category: Developer



It give you only a part of code belonging to a shell script
You must include it in ,for instance, lance_omc.sh,

#!/bin/bash
#set -x

test=$1
if [ ! -f ${test} ]; then
   echo "%% Error : le fichier de donnees \"$test\" n'existe pas."
   exit
fi
BIN_OPENMODELICA=$INSTALL_OPENMODELICA/bin  <= Put the place where omc is installed

....


Best regards

ALAIN_2

Jun-22-15 13:20:02
Category: Developer

Hello

I generate C code associated to a MODELICA file nammed for instance "test.mo" with a shell sccript with the simCodeTarget option

#... Executables
omcCompiler="omc"
exeCompil=$BIN_OPENMODELICA/$omcCompiler

options="+noSimplify +showErrorMessages +d=failtrace +d=disableSingleFlowEq +g=Modelica +d=initialization +d=debugAlias +d=checkSimplify"
options2="+postOptModules=generateSymbolicJacobian"

$exeCompil $options $options2 +simCodeTarget=C   +s "test.mo"

Best regards

ALAIN_2

Jun-18-15 11:12:33
what happens during Parameters Init ? _ Adding a new state variable ?
Category: Developer

Thanks for your quick answer. I understand your explanations

I  wrote the second test where I give of a value of p1 master parameter , the compiler works correctly

but really if I compil my first test alone , the results of the compiler (version 1.9.2)  disturb me !!

Best regards

ALAIN_2


class TestParameterInit
parameter Real p1(fixed=false);
parameter Real p11 = 100.0;
parameter Real p12(start=33.,fixed=true);

parameter Real p2 = if p1 > 0 then p11 else p12;
parameter Real p3 = 3*p1^2;
end TestParameterInit;

model TestParameterInit2
extends TestParameterInit(p1=2,p11=1000.);
Real x(start=-1, fixed=true);
equation
  der(x) = p3 *x^2 - p2 *x;
end TestParameterInit2;

Jun-18-15 09:28:07
what happens during Parameters Init ? _ Adding a new state variable ?
Category: Developer


Hi,

Is someBody can explain me why the new version of openModelica compiler  in comparison to the previous one add an additional state variable to my own model
during the step of parameter initialization ? 

why the compiler changes ther priority order  of the present parameters ?
where I  can find the definitron of the $_initialGuess function ?

My model is this one and the parameter p1 is the master of the parameters :  what happens in the generated file nammed TestParameterInit_06inz.c ?

model TestParameterInit
parameter Real p1(fixed=false);
parameter Real p11 = 100.0;
parameter Real p12(start=33.,fixed=true);

parameter Real p2 = if p1 > 0 then p11 else p12;
parameter Real p3 = 3*p1^2;
Real x(start=-1, fixed=true);
equation
  der(x) = p3 *x^2 - p2 *x;
end TestParameterInit;

Thanks in advance for your help ane your explantion

Best regards

ALIAN_2

Jun-12-15 07:51:11
Category: Developer

Dear Sir,

   I  try to use external functions in a Modelica model and to compile it with the new version 1.9.2 of OpenModelica. 

   It  seems to me that for instance,in the joined example, users lost at the end of compilation its own external function.

Best regards,

ALAIN_2

function f2
  input  Real x;
  output Real y;
external "C" y=f2(x) annotation(Library = "f2.o");
end f2;

model TestExternalFunction2
  constant Real x=5;
  Real y;
equation
  y = f2(x);
end TestExternalFunction2;

Dear Sir,

    When we generate the C target output with openModelica compiler, (version 1.9.2)  on a Model containing an array x[n] , it seems to me that the resulting new file
nammed _info.json does not contain the definition of the following variable : x[2]

Best regards;

ALAIN_2

model TestNonLinearSystem2
     parameter Integer N = 10;
    Real x[N];
    Real y(start=-1);
  equation
    x[N] = 1 - x[1];
    for i in 2:N loop
      y = 10*(x[i]-x[i-1]^2);
    end for;
    der(y) = 1;
end TestNonLinearSystem2;

Dear Sir
  Is it possible when we generate the output target C file with openModelica compiler (version 1.9.2)  to choose for the resulting file nammed  _init.xml  the "fmi version 2.0" description ?

  Thanks;

Best regards

Alain_2

Jun-27-14 14:05:09
Error during execution of a API openModelica
Category: Developer

Nowly, I don't consider <list<list<String> so that my problem is written like that :

But I have alaways a mistake for the line which computes the elemPosition1,


Regards

Alain

//-------------------------------------
public function countStrCref "Specific count about StrCref."
  input  list<String> inList;
  input  list<Integer> indexList;
  output list<Integer> outList;
algorithm
  outList := matchcontinue(inList,indexList)
    local
       String elem;
       list<String> tail;

       Integer nbCref,nbCrefPrevious,elemPosition1;
       list<Integer> nbCrefIndex;
       list<String> inList2;
    case({},_)
       then {};
    case(elem :: tail,_)
     equation
       nbCrefPrevious = getCountBefore(indexList);

       print("3\n");
       elemPosition1 = List.position(elem,tail);

       print("4\n");
       elemPosition1 = elemPosition1 + 1;

       //inList2  = Util.if_(elemPosition1>listLength(tail),{},List.lastN(tail,elemPosition1));

       inList2  = Util.if_(stringEqual(elem,List.last(tail)),{},List.lastN(tail,elemPosition1));

       print("4.1\n");
       nbCrefIndex = count3(inList2,elem,{});

       nbCref = count2(nbCrefPrevious,nbCrefIndex);
       print("5\n");
     then
        countStrCref(tail,listAppend(indexList,{nbCref}));
  end matchcontinue;
end countStrCref;
public function count2
  input Integer nbCrefPrevious;
  input list<Integer> nbCrefIndex;
  output Integer nbCref;
algorithm
   nbCref := matchcontinue(nbCrefPrevious,nbCrefIndex)
      local
         Integer n,nout;
    case(n,{})
      then 1;
    case(n,_)
      equation
       print("4.2\n");
       nout = Util.if_(n > 1,-n+1,
                 Util.if_(n < 0 and n != -1,n+1,
                      Util.if_(n == 1 or n == -1,List.reduce(nbCrefIndex,intAdd), 1)));
       print("4.3\n");
      then
         nout;
    end matchcontinue;
end count2;

public function count3
   input  list<String> inList;
   input  String strCrefToCompare;
   input  list<Integer> nbCrefLst;
   output list<Integer> nbCref;
algorithm
  nbCref := matchcontinue(inList,strCrefToCompare,nbCrefLst)
     local
        Integer nbFirstCref;
        list<String> strCrefIndxLst;
        String  strCrefIndx,elem;
        list<String> tail;
    case({},_,_)
        then {};
    case(elem :: tail,_,_)
     equation
       print("4.1.1\n");
       //strCrefIndx = listGet(elem,1);
       strCrefIndxLst = Util.stringSplitAtChar(elem,".");
       strCrefIndx = listGet(strCrefIndxLst,1);
       print("4.1.2\n");
       nbFirstCref = Util.if_(stringEqual(strCrefToCompare,strCrefIndx),1,0);
       print("4.1.3\n");
     then count3(tail,strCrefToCompare,listAppend(nbCrefLst,{nbFirstCref}));
end matchcontinue;
end count3;
/-------------------------------------
public function getCountBefore
  input  list<Integer> indexList;
  output Integer nbCrefPrevious;
algorithm
nbCrefPrevious := matchcontinue(indexList)
  case({}) then 1;
  case(_)  then List.last(indexList);
end matchcontinue;
end getCountBefore;

Jun-26-14 17:50:56
Error during execution of a API openModelica
Category: Developer

I just replace this line

    nbCrefPrevious = Util.if_(List.isEmpty(indexList),1,List.last(indexList));

by this :   nbCrefPrevious = count4(indexList);
with
public function count4
  input  list<Integer> indexList;
  output Integer nbCrefPrevious;
algorithm
nbCrefPrevious := matchcontinue(indexList)
  case({}) then 1;
  case(_) then List.last(indexList);
end matchcontinue;
end count4;

But I does not run correctly ,  something happens in count3 method !!

Alain

Jun-26-14 17:22:48
Error during execution of a API openModelica
Category: Developer

Hi every one,

First, thank you for the attention and help you'll give to this post.

My API openModelica function fails when I introduce this following
computation :

   I try to calculate from a list of Component Ref or String
   defined such as :
              list1 = { a.b, b.d, c.f, c.d, c.h, g.h }
a integer list equal to
               List2 = { 1  , 1,    3, -2,   -1,  1 }

because there is three terms with the same prefix c.


  I try to write recursive program but I a beginner and I
don't understand where I make the mistake(s) ...

  My master function is :
      list<list<String>>     connectorCref2;
      list<Integer>          subNodeCref;
      subNodeCref = countStrCref(connectorCref2,{});

  With these slave functions :

//-------------------------------------
public function countStrCref "Specific count about StrCref."
  input  list<list<String>> inList;
  input  list<Integer> indexList;
  output list<Integer> outList;
algorithm
  outList := matchcontinue(inList,indexList)
    local
       list<String> elem;
       list<list<String>> tail;

       String  strFirst;
       Integer nbCref,nbCrefPrevious;
       list<list<String>> inList2;
    case({},_)
       then {};
    case(elem :: tail,_)
     equation
       strFirst = listGet(elem,1);
       inList2  = List.deleteMember(tail,elem);

       nbCrefPrevious = Util.if_(List.isEmpty(indexList),1,List.last(indexList));
       print("4\n");

       nbCref = count2(nbCrefPrevious,strFirst,inList2);
       print("5\n");
     then
        countStrCref(tail,listAppend(indexList,{nbCref}));
  end matchcontinue;
end countStrCref;

//-------------------------------------
public function count2
  input Integer nbCrefPrevious;
  input String  strFirst;
  input list<list<String>> inList2;
  output Integer nbCref;
algorithm
   nbCref := matchcontinue(nbCrefPrevious,strFirst,inList2)
      local
         Integer n,nout;
         list<Integer> nbCrefIndex;
    case(n,_,_)
      equation
       print("4.1\n");
       nbCrefIndex = count3(strFirst,inList2,{});
       print("4.2\n");
       nout = Util.if_(n > 1,-n+1,
                 Util.if_(n < 0 and n != -1,n+1,
                      Util.if_(n == 1 or n == -1,List.reduce(nbCrefIndex,intAdd), 1)));
       print("4.3\n");
      then
         nout;
    end matchcontinue;
end count2;

//-------------------------------------
public function count3
   input  String strCrefToCompare;
   input  list<list<String>> inList;
   input  list<Integer> nbCrefLst;
   output list<Integer> nbCref;
algorithm
  nbCref := matchcontinue(strCrefToCompare,inList,nbCrefLst)
     local
        Integer nbFirstCref;
        String  strCrefIndx;
        list<String>       elem;
        list<list<String>> tail;
    case(_,elem :: tail,_)
     equation
       print("4.1.1\n");
       strCrefIndx = listGet(elem,1);
       print("4.1.2\n");
       nbFirstCref = Util.if_(stringEq(strCrefToCompare,strCrefIndx),1,0);
       print("4.1.3\n");
     then count3(strCrefToCompare,tail,listAppend(nbCrefLst,{nbFirstCref}));
end matchcontinue;
end count3;


Thanks

Regards

Alain

Jun-25-14 18:55:20
Decomposition of the variable names in a XML file generated by an API
Category: Developer

Thanks

I am a beginner concerning development in MetaModelica Language.

Nowly, I try to calculate from a list of Component Ref or String
defined such as :
    list = { a.b, b.d, c.f, c.d, c.h, g.h }
a integer list equal to outList = { 1, 1, 3, 0, 0, 1 }
because there is three terms with the same prefix c.


But for me, it is a little difficult!!!

//-------------------------------------
inList = split(list,1)

public function countStrCref "Specific count about StrCref."
  input  list<list<String>> inList;
  input  Integer indx;
  output list<Integer> outList;
algorithm
  outList := matchcontinue (inList,indx)
    local
       list<Integer> nbCrefList;

       Integer index1;
       list<String> firstLst,secondLst;
       String strFirst,strSecond;
    case({},_) then {}
    case(_,_)
     equation
       indx1 = indx+1;

       firstLst = listGet(inList,indx);
       strFirst = listGet(firstLst,1);

       secondLst = listGet(inList,indx1);
       strSecond = listGet(secondLst,2);

       //ilen1    = stringLength(strFirst);
       //ilen2    = stringLength(strSecond);
       //isLength = intEq(ilen1,ilen2);

       nbSameCref = Util.if_(stringEq(strFirst,strSecond),nbSameCref+1,nbSameCref);
       nbCrefList = List.insert(nbCrefList,indx,nbSameCref)
     then
        nbCrefList;
  end matchcontinue;
end countStrCref;

Jun-25-14 14:59:04
Decomposition of the variable names in a XML file generated by an API
Category: Developer

I replace the previous problem by this one less difficult :

  //-------------------------------------
protected function sortCrefs
  input  list<BackendDAE.Var> inVars;
  input  list<String> inStrCR;
  output list<String> outStrConnectorCref;
algorithm
  outStrConnectorCref := matchcontinue (inVars,inStrCR)
     local
      BackendDAE.Var v1;
      list<BackendDAE.Var> tail1;
      DAE.ComponentRef cr1;
      String selectCR;
    case ({},_) then inStrCR;
    case (v1 :: tail1,_)
      equation
       cr1 = BackendVariable.varCref(v1);
       selectCR = Util.if_(BackendVariable.isVarConnector(v1),ComponentReference.printComponentRefStr(cr1),"");
      then sortCrefs(tail1,listAppend(inStrCR,{selectCR}));
  end matchcontinue;
end sortCrefs;

Jun-24-14 18:07:12
Use of Util.if_
Category: Developer

According to me,  this next development  can be used

Regards

Alain

vars_cref = getCrefs(vars,vars_cref);

//-------------------------------------
protected function getCrefs
  input list<BackendDAE.Var> inVars;
  input  list<DAE.ComponentRef> inCR;
  output list<DAE.ComponentRef> outCR;
algorithm
  outCR := match(inVars,inCR)
    local
      BackendDAE.Var v1;
      list<BackendDAE.Var> tail;
      DAE.ComponentRef lCR;
    case ({},_) then inCR;
    case (v1 :: tail,_)
    equation
      lCR = BackendVariable.varCref(v1);
      then getCrefs(tail,listAppend(inCR,{lCR}));
  end match;
end getCrefs;

Jun-24-14 12:12:22
Use of Util.if_
Category: Developer

Hi every one,

First, thank you for the attention and help you'll give to this post.

I don't succed to use the function "Util.if_ "  in the following exemple ,  I don't know how to initialize the list<DAE.ComponentRef> connectorCref. !!

Thanks for your help

Regards

Alain


/-------------------------------------
protected function sortVars_ALAIN
  input  list<BackendDAE.Var> inVars;
  input  list<DAE.ComponentRef> inConnectorCref;
  output list<DAE.ComponentRef> outConnectorCref;
protected
   list<DAE.ComponentRef> outCref;
algorithm
   outCref := sortConnectorVars(inVars,1);
   outConnectorCref := listAppend(inConnectorCref,outCref);
end sortVars_ALAIN
//-----------------------------------------------------------------------------------------------
protected function sortConnectorVars
"Sort the variables keeping their componentReference."
  input list<BackendDAE.Var> inVarLst;
  input Integer inInteger;
  output list<DAE.ComponentRef> outConnectorCref;
algorithm
  outConnectorCref :=
    matchcontinue (inVarLst,inInteger)
     local
      Integer varno;
      list<DAE.ComponentRef> outCRLst;

      Integer var_1;
      list<DAE.ComponentRef> connectorCref;

      BackendDAE.Var v;
      DAE.ComponentRef cr;
      DAE.ConnectorType ct;
      list<BackendDAE.Var> xs;

    case ({},_) then {};
    case (((v as BackendDAE.VAR(varName=cr,connectorType=ct))::xs),varno)
      equation
        connectorCref = Util.if_(BackendVariable.isVarConnector(v),listAppend(connectorCref,{BackendVariable.varCref(v)}),connectorCref);   <========= ?????

        //connectorCref = ListAppend(Util.if_(BackendVariable.isVarConnector(v),BackendVariable.varCref(v),{}), connectorCref);
        //connectorCref = List.fold(,addVcref,{});

        var_1 = varno+1;
        outCRLst = sortConnectorVars(xs,var_1);
      then
        outCRLst;
  end matchcontinue;
end sortConnectorVars;

Jun-20-14 19:04:16
Decomposition of the variable names in a XML file generated by an API
Category: Developer

Hi every one,

First, thank you for the attention and help you'll give to this post.


  I wrote an openModelica API named "createXML" which creates from a modelica model
a specific XML file which contains all definitions of variables.
The start point of my development was the "dumpXMLDAE" API function for
openModelica version 1.9.1_Beta1.

This openModelica API "createXML" works and generates a XML file
such as:
        <?xml version="1.0" encoding="UTF-8"?>
        <model>
        <name> modelName <\name>
        <variables dimension="52">
        <elements>
        <terminal>
        <name> output_tetaInterne.value <\name>
        <kind> continuous <\kind>
        <id> 1 <\id>
        <type> Real <\type>
        <direction> output <\direction>
        <fixed> false <\fixed>
        <connector> Potential <\connector>
        <className>
        <element>
        modelName
        </element>
        <element>
        OutPin
        </element>
        <element>
        Real
        </element>
        </className>
        </terminal>
         .....
        <terminal>
        <name> teta <\name>
        <kind> continuous <\kind>
        <id> 42 <\id>
        <type> Real <\type>
        <direction> none <\direction>
        <fixed> false <\fixed>
        <connector> Non_Connector <\connector>
        <className>
        <element>
        DYNModelM1S
        </element>
        <element>
        Real
        </element>
        </className>
        <attributesValues>
        <initialValue string="teta0">
        </initialValue>
        </attributesValues>
        </terminal>
        ...

This openModelica API "createXML" works from "FrontEnd DAE"  only on the first DAE lower
      (dlow = BackendDAECreate.lower(dae,cache,env,BackendDAE.EXTRA_INFO(cname_str)); )
without any optimization.

Yet, the shape of my resulting XML file is not sufficient.

I must change its form for the variables which the name (DAE.ComponentRef) is equal to a designation
like that "name1.name2".

   like the previous variable 'output_tetaInterne.value"

  and so I must replace these lines :
       <terminal>
        <name> output_tetaInterne.value <\name>

by these ones :

       <struct>
         <name> output_tetaInterne </name>
         <subnodes>
           <terminal>
              <name> value </name>
                 ....
           </terminal>
         </subnodes>
        </struct>

I thought to split the DAE.ComponentRef of each Variable before to call a programm such as the "dumpVariable" one

but I do not manage to find how to realize it.

   Perhaps, somebody can help me and tell me the correct method

Thanks

  • Index
  • » Users
  • » ALAIN_2
  • » Profile
You are here: