simulationmodelicadymola

How to correctly pass externally defined material and insulation without "non-fixed condition" error?


I am working on a Modelica model where I want to dynamically assign materials and insulation based on parameters set in a .mos script. I define materials as parameters using a function that depends on a String input:

parameter String insulationType annotation (Evaluate=false); 
parameter String materialType annotation (Evaluate=false);
function selectMaterial 
    input String materialType; 
    output IDEAS.Buildings.Data.Interfaces.Material selectedMaterial; 
    algorithm 
        if materialType == "Brick" 
            then selectedMaterial := IDEAS.Buildings.Data.Interfaces.Material( d=0.08, k=0.89, c=800, rho=1920, epsLw=0.88, epsSw=0.55); 
            else selectedMaterial := IDEAS.Buildings.Data.Interfaces.Material( d=0.15, k=1.4, c=900, rho=2240, epsLw=0.88, epsSw=0.55); 
        end if; 
end selectMaterial;

parameter IDEAS.Buildings.Data.Interfaces.Material selectedMaterial = selectMaterial(materialType);

Problem: When I try to use selectedMaterial and selectedInsulation in a wall construction like this:

conTypA(mats={selectedMaterial, selectedInsulation, IDEAS.Buildings.Data.Materials.BrickHollow(d=0.14), IDEAS.Buildings.Data.Materials.Gypsum(d=0.015)})

I get the following error:

Current version of the Modelica translator can only handle conditional components with fixed condition. But component zone.outA.layMul.monLay[1].monLayDyn had non-fixed condition if isDynamic.

However, when I use hardcoded materials, I don’t get an error. It seems Modelica struggles with selectedMaterial as a parameter.

My questions:

How can I correctly pass selectedMaterial and selectedInsulation without this error? Do I need to force fixed=true, and if so, how? Is there an alternative approach to implementing this in Modelica?


Solution

  • As indicated in mail the current solution is:

      constant IDEAS.Buildings.Data.Interfaces.Material selectedMaterial =
          IDEAS.Buildings.Data.Interfaces.Material(
            d=if materialType == "Brick" then 0.08 else 0.15,
            k=if materialType == "Brick" then 0.89 else 1.4,
            c=if materialType == "Brick" then 800 else 900,
            rho=if materialType == "Brick" then 1920 else 2240,
            epsLw=if materialType == "Brick" then 0.88 else 0.88,
            epsSw=if materialType == "Brick" then 0.55 else 0.55);