1

有一个复杂的连接器,在传播它时,我只想修改一组变量中的一个变量,而不必为其他变量显式编写所有等式方程。

理想的将是一个连接语句和一个特定变量的覆盖。

    class FluidClass
        String name(start="name")"name";
        Real fl(start=1000)"flow [l/h]";
        Real p(start=1)"pressure [bar]";
        Real T(start=25)"temperature [degC]";
        Real DS(start=80)"dry substance [%]";
        Real rho(start=100)"viscosity [mPas]";
    end FluidClass;

    connector fl "flow"
        extends FluidClass;
    end fl;

        model setParam "set parameter"
        fl fli annotation(Placement(
            transformation(extent={{-5,-5},{5,5}}),
            iconTransformation(extent={{-105,-5},{-95,5}})));
        fl flo "flow output" annotation(Placement(
            transformation(extent={{-50,0},{-40,10}}),
            iconTransformation(extent={{95,-5},{105,5}})));
        input Modelica.Blocks.Interfaces.RealInput u "set value";
        parameter EnumType1 var "variable to change";
        type EnumType1 = enumeration( 
            fl "Flow rate", 
            p "Pressure", 
            T "Temperature", 
            DS "Dry substance", 
            rho "Viscosity");
        equation
            // enter your equations here
            if var ==1 then //flow
            flo.name=fli.name;
            flo.fl=u;
            flo.p=fli.p;
            flo.T=fli.T;
            flo.DS=fli.DS;
            flo.rho=fli.rho;
            end if;

            if var ==2 then //pressure
            flo.name=fli.name;
            flo.fl=fli.fl;
            flo.p=u;
            flo.T=fli.T;
            flo.DS=fli.DS;
            flo.rho=fli.rho;
            end if;

            if var ==3 then //temperature
            flo.name=fli.name;
            flo.fl=fli.fl;
            flo.p=fli.p;
            flo.T=u;
            flo.DS=fli.DS;
            flo.rho=fli.rho;
            end if;

            if var ==4 then //DS
            flo.name=fli.name;
            flo.fl=fli.fl;
            flo.p=fli.p;
            flo.T=fli.T;
            flo.DS=u;
            flo.rho=fli.rho;
            end if;

            if var ==5 then //viscosity
            flo.name=fli.name;
            flo.fl=fli.fl;
            flo.p=fli.p;
            flo.T=fli.T;
            flo.DS=fli.DS;
            flo.rho=u;
            end if;
    end setParam;

我非常感谢您的帮助。

4

1 回答 1

2

Unfortunately, this is not a very Modelica-ish way to build such models. There seem to be several things going on in this model. First, it appears that you are trying to specify the type of fluid through this "name" parameter. You are also propagating information through these connectors but you are propagating different types of information. Things like pressure, temperature and mass fractions (p, T, DS) should really be across variables, things like fluid flow (fl) should be through variables and density (rho) should be a fluid property.

There are facilities in Modelica for handling all of these cases but you are not utilizing them in your example. Furthermore, the approach you are using will not really scale very well because you don't have sufficient information in your flow path (you don't track energy being convected by the fluid nor differentiate how much of your flow is "dry" (dry air vs water vapor?).

You should really have a look at some fluid examples (for example, the Modelica.Fluid library or the examples in my book, "Introduction to Physical Modeling with Modelica") because once you take into account these design changes, your question will be moot (hence my non-answer).

I am sorry about the non-answer here, but I hope you find the information constructive enough to point you in the right direction. If not, feel free to ask other questions or add comments and I'll try to make it clearer.

于 2012-07-03T15:09:30.533 回答