Own component creating - How to add model constraints?

Hello everybody, i am pretty new in oemof and i have a question.

I have created a new component based on the “GenericStorage” component (through inheritance). So far everything is clear.

I now want to add further restrictions (pyomo constraints) to my new component like this:

def _my_function(energy_system_model):
        for timestep in energy_system_model.TIMESTEPS:
                .....
                .....

setattr(energy_system_model, "myconstraint", pyomo.Constraint(energy_system_model.TIMESTEPS, noruleinit=True))
setattr(energy_system_model, "myconstraint_build", pyomo.BuildAction(rule=_my_function))

Previously i always added these constraints at the end, before solving the model and after creating the pyomo model. Like the following:

energy_system_model = oemof.solph.Model(energy_system)

add_all_model_constraints()

energy_system_model.solve('cbc', ....)

But now i want to add these restrictions automatically to the model when i create the model with the first instruction above.

How can i realize this?

Is there a special function for every component that is called automatically when the model is created?

Try to understand the existing storage. Add a new class and follow the same structure as the existing components. Do not forget the grouping. You need to create a group for each new component and than write a new Block-class for the group. If you just want to change the constraints but keep the attributes you can inherit from the GenericStorage, change the group and add a new Block-class.

Hi @uwe.krien,
sorry for my late respone and thanks for your answer.

I think your answer has already helped me. I’ll try it, thanks.