Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify external object initialization #1907

Closed
modelica-trac-importer opened this issue Nov 4, 2018 · 13 comments
Closed

Clarify external object initialization #1907

modelica-trac-importer opened this issue Nov 4, 2018 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@modelica-trac-importer
Copy link
Collaborator

Reported by hansolsson on 12 Feb 2016 15:18 UTC
Based on #1899

In 12.9.7 External Objects
add bullet with:

The constructor shall initialize the object, and not rely on other calls for this (in particular not any initial algorithm or initial equation). The destructor shall delete the object - and not rely on other calls (in particular not 'when terminal()...').


Migrated-From: https://trac.modelica.org/Modelica/ticket/1907

@modelica-trac-importer
Copy link
Collaborator Author

Modified by beutlich on 12 Feb 2016 15:22 UTC

@modelica-trac-importer
Copy link
Collaborator Author

Comment by jmattsson on 18 Feb 2016 08:37 UTC
I find "rely on other calls" unclear - this could be taken as meaning that the constructor is not allowed to call other C functions.

How about this?
The constructor shall initialize the object, and must not require any other calls to be made for the initialization to be complete (e.g., from an initial algorithm or initial equation). The destructor shall delete the object, and must not require any other calls to be made for the deletion to be complete (e.g., from a 'when terminal()' clause).

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 18 Feb 2016 09:35 UTC
Replying to [comment:2 jmattsson]:

I find "rely on other calls" unclear - this could be taken as meaning that the constructor is not allowed to call other C functions.

How about this?
The constructor shall initialize the object, and must not require any other calls to be made for the initialization to be complete (e.g., from an initial algorithm or initial equation). The destructor shall delete the object, and must not require any other calls to be made for the deletion to be complete (e.g., from a 'when terminal()' clause).

The constructor part seems good. For the destructor the order is a bit different (when terminal would be run before the destructor). I don't know exactly how to formulate that, but would write:

The destructor shall completely delete the object, and must not require any preceding calls to be made (e.g., from a 'when terminal()' clause).

@modelica-trac-importer
Copy link
Collaborator Author

Comment by jmattsson on 18 Feb 2016 10:02 UTC
Replying to [comment:3 hansolsson]:

The destructor shall completely delete the object, and must not require any preceding calls to be made (e.g., from a 'when terminal()' clause).

Looks good to me.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by stefanv on 18 Feb 2016 14:37 UTC
I prefer Jesper's original version from comment 2 above, since the destructor must not rely on any additional calls at all, regardless of when they are made. Specifying "preceding" suggests that later calls can be used (e.g. calls made by another object's destructor).

@modelica-trac-importer
Copy link
Collaborator Author

Comment by beutlich on 23 Jun 2016 21:51 UTC
See #1705 for an example.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by M.Arzt on 4 Jul 2016 17:11 UTC
What if I had a simulation model, containing an external object. When starting the simulation, the following happens:

step A: The external objects constructor is called.
step B: A function is called that modifies the state of the external object.

I may say: "The external object is initialized by step A and later its internal data is modified by step B."
Therefore it satisfies your requirement: "The constructor shall initialize the object, and must not require any other calls to be made for the initialization to be complete (e.g., from an initial algorithm or initial equation)."

But I guess, it's not what you meant. To clarify your intention, it is important to answer the question: "What makes an initialization complete?"

@modelica-trac-importer
Copy link
Collaborator Author

Comment by jmattsson on 5 Jul 2016 07:11 UTC
Replying to [comment:7 M.Arzt <arzt@…>]:

step A: The external objects constructor is called.
step B: A function is called that modifies the state of the external object.

If we also have:
step C: Calculate some data using the external object.
Then the object must also handle that C is called before B, and should give the same result for both cases (otherwise different Modelica tools could give very different simulation results and still both be correct).

But I guess, it's not what you meant. To clarify your intention, it is important to answer the question: "What makes an initialization complete?"

If the external object is prepared to handle any other function that uses it, then its initialization is complete. Generally the only assumption you can make on the order functions for external objects is called is that the constructor is first and the destructor is last.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by choeger on 5 Jul 2016 07:48 UTC
Replying to [comment:7 M.Arzt <arzt@…>]:

But I guess, it's not what you meant. To clarify your intention, it is important to answer the question: "What makes an initialization complete?"

My take on this is rather pragmatic: Initialization (of an object) is complete iff it is in a consistent state, i.e. all (external) procedures can work with that object.

@modelica-trac-importer
Copy link
Collaborator Author

Modified by beutlich on 5 Aug 2016 08:41 UTC

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 12 Sep 2016 15:30 UTC
Would need to update MSL if added in 3.4.
Variant 1:
The constructor shall initialize the object, and must not require any other calls to be made for the initialization to be complete (e.g., from an initial algorithm or initial equation). The destructor shall delete the object, and must not require any other calls to be made for the deletion to be complete (e.g., from a 'when terminal()' clause).

Variant 2:
The constructor shall initialize the object, and must not require any other calls to be made for the initialization to be complete (e.g., from an initial algorithm or initial equation). The destructor shall completely delete the object, and must not require any preceding calls to be made (e.g., from a 'when terminal()' clause).

What does it mean for initialization to be complete? (The intent was to avoid reading data after initialization.)
After some discussion 'Variant 2' was withdrawn.

Poll about proposal:
In 3.4: 5
Later: 1
Against: 1 (matter of using it in a sensible way - but hard to exactly define what is proper use)
Rest abstain.

@modelica-trac-importer
Copy link
Collaborator Author

Modified by hansolsson on 14 Sep 2016 12:31 UTC

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 23 Sep 2016 15:15 UTC
Resolved in r9491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests