最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

simulation - How to correctly pass externally defined material and insulation without "non-fixed condition" er

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Mar 14 at 6:34 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Mar 14 at 6:15 StanStan 133 bronze badges 7
  • An alternative approach to implement this functionality could be replaceable records. mbe.modelica.university/components/architectures/replaceable – Priyanka Commented Mar 14 at 10:02
  • Hi @Priyanka, I've tried doing it that way but got even more errors... I edited the code a bit: constant IDEAS.Buildings.Data.Interfaces.Material selectedMaterial= if materialType == "Brick" then IDEAS.Buildings.Data.Interfaces.Material(...) else IDEAS.Buildings.Data.Interfaces.Material(...); new err:Failed to expand the variable zone.int.layMul.monLay[1].monLayDyn.G and its definition equation: fill(zone.int.layMul.monLay[1].monLayDyn.nRes*zone.int.layMul.monLay[1].monLayDyn.A /zone.int.layMul.monLay[1].monLayDyn.R, zone.int.layMul.monLay[1].monLayDyn.nRes) – Stan Commented Mar 14 at 17:29
  • Do you have any specific reason for adding annotation (Evaluate=false) in the definition of the parameter? – Markus A. Commented Mar 18 at 7:44
  • @MarkusA. In my understanding: by using annotation(Evaluate=false), you ensure that the parameter is not fixed during model translation, allowing you to modify it externally before running the simulation. This is what I'm also trying to do by running an external script (.mos) where I choose which materials I use. – Stan Commented Mar 21 at 15:17
  • Your understanding is correct. But sometimes, e.g. for structural parameters, it is necessary to evaluate it. So - even if it does not make sense in the final stage - it could help to remove the annotation(Evaluate=false) to see if that fixes the error. Should be a pretty quick test. – Markus A. Commented Mar 24 at 8:41
 |  Show 2 more comments

1 Answer 1

Reset to default 0

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);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论