Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClaRa: Array dimensions not equal #9017

Closed
AnHeuermann opened this issue May 25, 2022 · 5 comments · Fixed by #9023
Closed

ClaRa: Array dimensions not equal #9017

AnHeuermann opened this issue May 25, 2022 · 5 comments · Fixed by #9023
Assignees
Labels
COMP/OMC/Frontend Issue and pull request related to the frontend
Projects

Comments

@AnHeuermann
Copy link
Member

Description

For the developer version of ClaRa the model ClaRa.Components.Furnace.Check.Test_CombustionChamber fails at simulation during initialization while copying an array, because of unequal dimension sizes.

Steps to Reproduce

Load TILMedia and ClaRa dev version and simulate ClaRa.Components.Furnace.Check.Test_CombustionChamber

loadFile("/path/to/TILMediaClaRa/TILMedia/package.mo"); getErrorString();
loadFile("/path/to/clara_om/ClaRa/package.mo"); getErrorString();

simulate(ClaRa.Components.Furnace.Check.Test_CombustionChamber); getErrorString();
record SimulationResult
    resultFile = "",
    simulationOptions = "startTime = 0.0, stopTime = 10.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'ClaRa.Components.Furnace.Check.Test_CombustionChamber', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "Simulation execution failed for model: ClaRa.Components.Furnace.Check.Test_CombustionChamber
src->dim_size[0] != dst->dim_size[0], 4 != 6
assert            | debug   | Failed to copy array. Dimension sizes are not equal and destination array is not flexible.
assert            | info    | simulation terminated by an assertion at initialization
",
    timeFrontend = 0.358399402,
    timeBackend = 1.038850344,
    timeSimCode = 0.09468953200000001,
    timeTemplates = 0.07566574500000001,
    timeCompile = 0.880901788,
    timeSimulation = 0.128206954,
    timeTotal = 2.576885568
end SimulationResult;

Expected Behavior

The dimensions of the arrays should align.

Version and OS

  • OpenModelica Version: v1.20.0-dev-103-ge4e4270543
  • OS: Ubuntu Focal
  • Versions of used Modelica libraries: ClaRa dev version @ d931ea39e5a56704911d2d4fb78d4386e13ec553
@AnHeuermann AnHeuermann added the COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime). label May 25, 2022
@AnHeuermann AnHeuermann self-assigned this May 25, 2022
@AnHeuermann AnHeuermann added this to To do in PHyMoS May 25, 2022
@AnHeuermann
Copy link
Member Author

We are failing in function omc_ClaRa_Basics_Media_FuelFunctions_massFraction__i__xi when doing

real_array_copy_data(tmp2, _xi_elements);

The Modelica function is ClaRa.Basics.Media.FuelFunctions.massFraction_i_xi.

tmp2 has the correct size 4, coming from fuelType.N_e - 1, but _xi_elements has always 6 elements, but should have fuelType.N_e - 1 elements.

@AnHeuermann
Copy link
Member Author

An MWE

model Example

  record BaseRecord
    constant Integer nx = 4;
  end BaseRecord;

  record ExtendRecord
    extends BaseRecord(nx=6);
  end ExtendRecord;

  function initArr
    input BaseRecord r = ExtendRecord();
    output Real x_1;
  protected
    Real x[r.nx-1];
  algorithm
    x := zeros(r.nx - 1);
    x_1 := x[1];
  end initArr;

  BaseRecord r = ExtendRecord();
  Real x_1;
equation
  x_1 = initArr(r);
end Example;

@AnHeuermann AnHeuermann moved this from To do to In progress in PHyMoS May 25, 2022
@AnHeuermann
Copy link
Member Author

It seems that the frontend replaces protected Real x[r.nx-1] with protected Real[5] x, probably because r.nx is constant.

Flat Modelica:

function Example.initArr
  input Example.BaseRecord r = Example.ExtendRecord(6);
  output Real x_1;
  protected Real[5] x;
algorithm
  x := fill(0.0, r.nx - 1);
  x_1 := x[1];
end Example.initArr;

@perost Could you have a look?

@AnHeuermann AnHeuermann added COMP/OMC/Frontend Issue and pull request related to the frontend and removed COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime). labels May 25, 2022
perost added a commit to perost/OpenModelica that referenced this issue May 25, 2022
@perost
Copy link
Member

perost commented May 25, 2022

Fixed in #9023 by making sure we don't evaluate dimensions that contain references to function inputs. I guess we might still get issues if someone mixes function inputs and package constants in a dimension expression, so don't do that 😓

@AnHeuermann AnHeuermann moved this from In progress to Done in PHyMoS May 25, 2022
@AnHeuermann
Copy link
Member Author

One issue is solved and I can directly open the next one. But this time a minimal working example could be harder to create.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP/OMC/Frontend Issue and pull request related to the frontend
Projects
Development

Successfully merging a pull request may close this issue.

2 participants