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

Add support for component array in @mtkmodel #2368

Merged
merged 5 commits into from
Mar 4, 2024

Conversation

ven-k
Copy link
Member

@ven-k ven-k commented Dec 4, 2023

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the ScioML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

  • for loop or a list comprehension can be used to declare component arrays
@mtkmodel Component begin
        @structural_parameters begin
            N = 2
        end
        @components begin
            comprehension = [SubComponent(sc = i) for i in 1:N]
            written_out_for = for i in 1:N
                sc = i + 1
                SubComponent(; sc)
            end
            single_sub_component = SubComponent()
        end
    end
  • Extend Base.parentmodule for Model

@ven-k ven-k force-pushed the vkb/component-arrays branch 2 times, most recently from 71ecbf4 to 3335751 Compare December 5, 2023 10:05
Comment on lines 550 to 721
module GetParentModule

using ModelingToolkit

@mtkmodel Component begin end

end

@testset "Parent module of Models" begin
@test parentmodule(GetParentModule.Component) == GetParentModule
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: As of ce7eed0, we have a MyMockModule module (with a component in it) defined, which could be used for this test.

module MyMockModule
using ..ModelingToolkit, ..Unitful
export Pin
@connector Pin begin
v(t), [unit = u"V"] # Potential at the pin [V]
i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A]
@icon "pin.png"
end
@mtkmodel Ground begin
@components begin
g = Pin()
end
@icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
@equations begin
g.v ~ 0
end
end
end
using .MyMockModule

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I noticed that PR got merged. Will be using that while rebasing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved: a4a79ce

@ven-k ven-k force-pushed the vkb/component-arrays branch from 3335751 to 46df8a4 Compare January 4, 2024 15:16
@ven-k ven-k force-pushed the vkb/component-arrays branch from 46df8a4 to 7bc67ba Compare January 16, 2024 07:07
@ven-k ven-k force-pushed the vkb/component-arrays branch from 7bc67ba to a9991dd Compare February 26, 2024 04:47
@ven-k
Copy link
Member Author

ven-k commented Feb 26, 2024

@YingboMa I've rebased to post v9 main.

@ChrisRackauckas
Copy link
Member

Rebase?

@ven-k ven-k force-pushed the vkb/component-arrays branch from a9991dd to 763f6df Compare March 4, 2024 06:50
@ven-k ven-k force-pushed the vkb/component-arrays branch from 763f6df to e324633 Compare March 4, 2024 07:08
@ven-k
Copy link
Member Author

ven-k commented Mar 4, 2024

In addition to above mentioned details, new tests are added to check that conditionally component arrays can be defined: e324633.

@ven-k
Copy link
Member Author

ven-k commented Mar 4, 2024

@ChrisRackauckas ChrisRackauckas merged commit a64aad8 into SciML:master Mar 4, 2024
20 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants