Skip to content

Easily creating model variants #3791

@cstjean

Description

@cstjean

Is your feature request related to a problem? Please describe.

Where I work, we deliver chemical plants. Each client's plant might be a bit different (eg. the pump type changes), but they're always connected in the same way.

I have my models like

@mtkmodel SchmidtPump begin
    ...
end

@mtkmodel ManualPump begin
   ...
end

and my client models

@mtkmodel ClientInSpain begin
    @components begin
        pump = SchmidtPump(eta=20)
    end
    @equations begin
        connect(...)
    end
end

@mtkmodel ClientInFrance begin
    @components begin
        pump = ManualPump(operator_strength=3)
    end
    @equations begin
        connect(...)
    end
end

Since the @equations block is always exactly the same, this is rather redundant and verbose. What I'd like is to be able to write a vanilla function like client_in_france = create_plant(pump=ManualPump(operator_strength=3), ...). This would also cover another important use case, that of figuring out which pump is best for a particular client:

best_pump, _ = findmax([simulate_cost(create_plant(pump=pump) for pump in available_pumps])

Is it possible to write create_plant in MTK? Feels like at the moment it isn't, but maybe I've missed something.

Describe the solution you’d like

I would like to be able to write ManualPump(operator_strength=3) without getting a keyword argument name not assigned error. Would it be possible to have a default name=nothing kwarg, and have MTK assign each component a name later (at building/compiling time)?

Feels like in MTK one can talk about "the plant's operating_room's pump", but one cannot talk about "a ManualPump of operator_strength=30" as a fungible object / platonic ideal.

This would also (help to) solve

@components begin
    pumps = [ManualPump(operator_strength=3), ManualPump(operator_strength=7)] 
end

which is another use case we've had.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions