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
  • » McBain
  • » Profile

Posts

Posts

Aug-31-11 05:40:50
flattening O.K. but not compiling if index is variable

I wanted to implement an object using an array indexed by an enumeration value, as described in Section 10.5.1 of the Modelica Language Specification (`Indexing with Boolean or Enumeration Values'), but I couldn't quite get it to work.

That is, this works:


type Sizes = enumeration (small, medium);

model Test
  constant Real[Sizes] sz = {1.2, 3.5};
  parameter Real x0 = sz[Sizes.small];
  Real x;
equation
  x = x0;
end Test;



but it's not very interesting, since what I'd like to be able to do is instantiate a "Test" that is either small or medium (i.e. in the instantiation override the index to sz which goes into x0, not the value of x0 directly), but how I thought to do this fails:



type Sizes = enumeration (small, medium);

model Test
  constant Real[Sizes] sz = {1.2, 3.5};
  //parameter Real x0 = sz[Sizes.small];
  parameter Sizes size = Sizes.small;
  parameter Real x0 = sz[size];
  Real x;
equation
  x = x0;
end Test;



This does flatten happily enough (or is there already a sign of the problem in that the indices in the definition of the array have been converted to integers but the ones pertaining to accessing the array during the assignment to x0 haven't?):


class Test
  constant Real sz[1] = 1.2;
  constant Real sz[2] = 3.5;
  parameter enumeration(small, medium) size = Sizes.small;
  Real x;
  parameter Real x0 = sz[Sizes.small];
equation
  x = x0;
end Test;



but then compiling gives an error:


Test.c: In function ‘bound_parameters’:
Test.c:309:10: error: ‘$Psz$lBUNKNOWN_SUBSCRIPT$rB’ undeclared (first use in this function)



Since I actually only have two states in the enumeration in my application, I then tried to use a Boolean instead, again following the same section of the Specification, but


Real[Boolean] bb = {10.0, 11.0};



wouldn't even flatten:


[Test.mo:2:3-2:34:writable] Error: Variable Boolean not found in scope Test



Have I misunderstood the Modelica Language Specification, or is Indexing with Boolean and Enumeration Values not yet completely supported by OpenModelica? In the latter case, could anyone suggest a convenient workaround?

Thanks.

Aug-24-11 10:12:37
I'd like to resimulate a model after modifying its parameters.

O.K. then.

I guess there's not much point using CORBA system to edit init.txt and then CORBA system to run the old executable.

Thanks for the tip about sed.  It's a nice program.  I've been using awk for the same purpose.  Ultimately though I'll be doing it in Python, which shouldn't be very difficult.

Thanks too for the notice about the switch to XML for init.txt.  I won't bother writing an init.txt pyparser then.

I guess my immediate plan then will be to update my OpenModelica to get the init.xml behaviour, set up init.xml reading, modifying, and writing in Python, and then call the simulator with os.popen (or rather subprocess.check_call since os.popen is deprecated).

Thank you again for the prompt and clear responses.

Aug-24-11 09:47:14
I'd like to resimulate a model after modifying its parameters.

Oh, but if I want to modify parameters between simulations, such as those appearing in the MyModel_init.txt, the OMShell/CORBA way is to use e.g. setComponentModifierValue, but these modifications won't be made known to the precompiled simulator binary MyModel; if I simply follow the calls to setComponentModifierValue by a call

    system("./MyModel")

it will just read the old MyModel_init.txt and my modifications will have been in vain.  Is that right?

What I want to do is compile once and then run many times with slightly different parameters.  I can do this via tinkering with MyModel_init.txt, but I wonder if it is possible via OMShell/CORBA.

Aug-24-11 09:14:34
I'd like to resimulate a model after modifying its parameters.

Hey, that's easy. Thank you very much for the prompt response!

Aug-24-11 08:38:38
I'd like to resimulate a model after modifying its parameters.

Hello.  I'm running an OpenModelica simulation from Python, much along the lines of `Python interoperability' in the `OpenModelica Users Guide'.  In particular, following the `second option', after having built the binary executable, I tinker with the parameters in *_init.txt and rerun using

   os.popen ('./CalledbyPython').read ()

What I wonder though is how to do this using the `third option' (`to use the Corba interface for invoking the compiler and then just use the scripting interface to send commands to the compiler via this interface').  I have this working, but in order to run a simulation after having modified the parameters (via Corba, using setComponentModifierValue, etc.), I can only find the `simulate' command which seems to involve (a) recompiling the Modelica model from .mo to .c, (b) compiling the .c program to an executable, and (c) running the executable.  I know I can do (a) and (b) with buildModel (either in OMshell or via Corba), but how do I do (c) without (a) and (b)?

In my case, I want to run the same model dozens or hundreds of times with different values in the _init.txt file, but no structural changes to the model, so recompilation should not be required; indeed it's not as I can do this via the OS shell.  The question is, can this also be done via the OMShell/Corba?

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