Organizing Modelica code...

4 posts / 0 new
Last post
janpeter
Offline
Joined: 2010-09-11
Organizing Modelica code...

Hi

 

So far I have had my library of Modelica models in a single file and the content enclosed by package PROCESS_LIB….. end PROCESS_LIB; 

 

Part of of the code is now within a sub-package called package CUSTOMER_LIB…. end CUSTOMER_LIB; 

 

The python-script to administrate this use the following code to compile:

model_name = ‘PROCESS_LIB.CUSTOMER.Batch’

mobile = “PROCESS_LIB_v1’

fmu_model = compile_fmu(model_name,mofile)

 

(And here Batch is customer model that combines different sub-models to run the process in batch mode).

 

This works as expected.

 

Now I would like split this file into two parts.

One general part for PROCESS_LIB and one CUSTOMER_LIB part.

 

How should this be done?

What should be added in the code?

 

I have read about Modelica concepts like MODELICAPATH, WITHIN, IMPORT etc, but I find it difficult to make it work and also wonder if here is some special limitations around the compile_fmu command.

 

I also read in the JModelica manual section 4.2.3 and try to make compile_fmu to search in a folder for a model instead of giving a file for it. Did not work.

 

I also looked at earlier thread http://www.jmodelica.org/5104 and found that my MODELICAPATH did not exist at all. Still I can compile MSL model as described in section 4.2.3. Something wrong in my installation?

 

Would appreciate some input.

 

Jan Peter

 

PS I run JModelica ver 2.0 in Windows 10 as virtual machine on a Mac.

janpeter
Offline
Joined: 2010-09-11
Hi, I have got some better

Hi,

I have got some better insight into structuring Modelica code in the post "Modelica in Action: How to structure models in packges" by Marco Bonvini https://marcobonvini.com/posts/. But there is more to learn here.

I also found it useful to address other directoreis not in the MODELICAPATH explaing here http://www.jmodelica.org/4320

Still I would like to be able to update my MODELICAPATH. As said above the post http://www.jmodelica.org/5104 does not seem relevant for JModelica ver 2.0. 

In Windows 10 (latest update) it is somewhat involved to set the MODELICAPATH and I have looked around "Envirnoment Variables" but cannot find the current MODELICAPATH, see enclosed screenshot. Where is it? and how do I modify it?

Would appreicate some help

Jan Peter

AttachmentSize
Screen Shot 2017-10-10 at 11.36.48.png 41.23 KB
janpeter
Offline
Joined: 2010-09-11
Hi, I just want to report

Hi,

I just want to report that I have come to terms with the Modelica way to structure code in a "library part" and an "application part”. There are some material in Tillers book from 2001 but this time I learnt more from studying parts of Fritzons book from 2004 and especially chapter 4-5. In section 4.4.5 it is well described how to parameterise modules with “formal connector” that can be redeclared. Very useful. Also note that in 4.5.2 is also described how you can have a class that contain both declarations and equations as your formal parameter and possible to redeclare. This is to take the concept of “formal parameter” of a model one step further than found in Tillers book, see 4.8.1.

In general one can learn something about the structuring of Modelica code by looking at the MSL-code, but good to have read the textbooks with simple examples first.

The problem with the MODELICAPATH in Windows 10 described in previous post remains however.

Jan Peter

hubertus
Offline
Joined: 2009-04-24
MODELICAPATH

Many tools and JModelica is no exception, do not need a MODELICAPATH environment variable unless the user needs libraries to be loaded from a non-default place. However, if the variable is defined, it will be used. I would have to test whether the MODELICAPATH, once it is set, would have to also include the path to the install directory of the MSL, C:\JModelica.org-2.0\install\ThirdParty\MSL in my case. That is very easy to test though, and JModelica could do this addition by itself during startup. So, everything is just fine as is. 

Login or register to post comments