Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:45:16+00:00 2026-06-18T09:45:16+00:00

I am trying to build a model that will have slightly different equations based

  • 0

I am trying to build a model that will have slightly different equations based on whether or not certain components exist (in my case, fluid ports).

A code like the following will not work:

parameter Boolean use_component=false;
Component component if use_component;
equation
if use_component then
  component.x = 0;
end if;

How can I work around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:45:17+00:00Added an answer on June 18, 2026 at 9:45 am

    If you want to use condition components, there are some restrictions you need to be aware of. Section 4.4.5 of the Modelica 3.3 specification sums it up nicely. It says “If the condition is false, the component, its modifiers, and any connect equations
    involving the component, are removed”. I’ll show you how to use this to solve your problem in just a second, but first I want to explain why your solution doesn’t work.

    The issue has to do with checking the model. In your case, it is obvious that the equation component.x and the component component either both exist or neither exist. That is because you have tied them to the same Boolean variable. But what if you had don’t this:

    parameter Real some_number;
    Component component if some_number*some_number>4.0;
    equation
    if some_number>=-2 and some_number<=2 then
      component.x = 0;
    end if;
    

    We can see that this logically identical to your case. There is no chance for component.x to exist when component is absent. But can we prove such things in general? No.

    So, when conditional components were introduced, conservative semantics were implemented which can always trivially ensure that the sets of variables and equations involved never get “out of sync”.

    Let us to return to what the specification says: “If the condition is false, the component, its modifiers, and any connect equations
    involving the component, are removed”

    For your case, the solution could potentially be quite simple. Depending on how you declare “x”, you could just add a modification to component, i.e.

    parameter Boolean use_component=false;
    Component component(x=0) if use_component;
    

    The elegance of this is that the modification only applies to component and if component isn’t present, neither is the modification (equation). So the variable x and its associated equation are “in sync”. But this doesn’t work for all cases (IIRC, x has to have an input qualifier for this to work…maybe that is possible in your case?).

    There are two remaining alternatives. First, put the equation component.x inside component. The second is to introduce a connector on component that, if connected, will generate the equation you want. As with the modification case (this is not a coincidence), you could associate x with an input connector of some kind and then do this:

    parameter Boolean use_component;
    Component component if use_component;
    Constant zero(k=0);
    equation
    connect(k.y, component.x);
    

    Now, I could imagine that after considering all three cases (modification, internalize equation and use connect), you come to the conclusion that none of them will work. If this is the case, then I would humbly suggest that you have an issue with how you have designed the component. The reason these restrictions arise is related to the necessity to check components by themselves for correctness. This requires that the component be complete (“balanced” in the terminology of the specification).

    If you cannot solve the problem with approaches I mentioned above, then I suspect you really have a balancing issue and that you probably need to redefine the boundaries of your component somehow. If this is the case, I would suggest you open another question here with details of what you are trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a domain model that will allow me to manage
I am trying to build a registration form. I have a model for all
I'm trying to build a miniature engine that will allow a search query to
I'm trying to do a script in WWW::Mechanize that will build a job in
I am trying to build an html helper that would have access to modelmetadata.
I am trying to build a program using model-view-controller. Specifically: I have a state
I am trying to add a new model. The new model will have one
I am trying to build an application that can search the database for different
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
I am trying to build an application that converts my old custom Ethernet logs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.