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

API Value for FMI 2 #130

Open
SudeepGhoshIN opened this issue Jul 16, 2024 · 5 comments
Open

API Value for FMI 2 #130

SudeepGhoshIN opened this issue Jul 16, 2024 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@SudeepGhoshIN
Copy link

Hi Team,

I have a requirement of passing start value for Measurment and Outputs in FMI2.0.
As part of this , I am trying to utilize fmi2_import_get_variable_has_start(fmi2_import_variable_t*) API to check if the variable contains start. But unfortunately, above mentioned API is not returning value , so I could not proceed further for retrieving the start value.

Though I am getting proper value for Calibration and Inport value while trying to read from Parameters and Inputs variable.

Many Thanks,
Sudeepp

@PeterMeisrimelModelon PeterMeisrimelModelon self-assigned this Jul 16, 2024
@PeterMeisrimelModelon PeterMeisrimelModelon added the question Further information is requested label Jul 16, 2024
@PeterMeisrimelModelon
Copy link
Contributor

Hi SudeepGhoshIN,

you retrieve the start value via fmi2_import_get_real_variable_start, note that this will instead return the nominal if there is no start value, so you should still check if there is a start value first.

If this does not answer the question, please provide a minimal reproducer.

/Peter

@SudeepGhoshIN
Copy link
Author

  Not able to get value for this 2 
    <ScalarVariable name="Constant4.Constant4" valueReference="50">
      <Integer start="3"/>
    </ScalarVariable>
        <ScalarVariable name="Out1" valueReference="28" causality="output">
      <Real start="1.0"/>
    </ScalarVariable>
    
    able to get value for 
        <ScalarVariable name="Parameters.FixPtConstant_Value_i" valueReference="16" causality="parameter" variability="tunable">
      <Real start="1.0"/>
    </ScalarVariable>

@PeterMeisrimelModelon
Copy link
Contributor

Can you provide the corresponding C code for retrieving the start values?

/Peter

@SudeepGhoshIN
Copy link
Author

fmi2_import_variable_t* var = fmi2_import_get_variable(varList, i);
baseType = fmi2_import_get_variable_base_type(var);
VariableType = fmi2_base_type_to_string(baseType);
if (VariableType == "Real")
{
fmi2_import_real_variable_t* rv = fmi2_import_get_variable_as_real(var);                    
fmi2_real_t StartValue = fmi2_import_get_real_variable_start(rv);  
}

@PeterMeisrimelModelon
Copy link
Contributor

First off, there are couple of issues in your modelDescription.xml:

  1. The first scalar variable does not specify a variability and thus fmi-library defaults to continuous. This conflicts with the variable being an Integer. Are you missing a variability="constant" here?
  2. The second scalar variable does not specify variability or initial. Again, variability defaults to continuous and we take the default initial calculated (based on the variability + causality combination, see specification). initial="calculated" does not allow start values. There are multiple possible choices for initial here, but fmi-library does not perform checks to determine if any legal ones come without errors, it simply takes the default. You might want to specify a variability and possibly initial="exact" here?

As for the code, you'll want to obtain the type via fmi2_base_type_enu_t base_type = fmi2_import_get_variable_base_type(var); and use the enum for type checks and then pick the correct get_variable_as_* and get_*_variable_start functions based on the type.

/Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants