clagms / synchronous-clock-fmus

1 stars 1 forks source link

Importer to simulate these FMUs? #1

Open chrbertsch opened 4 months ago

chrbertsch commented 4 months ago

Is there a freely available importer or example c-code available to simulate these FMUs?

clagms commented 4 months ago

Yes i plan to include that as well here, just for illustration and testing of the FMUs :)

clagms commented 1 month ago

Added now in https://github.com/clagms/synchronous-clock-fmus/commit/386081fb79af4ea0231637c382d60a3025c7c40b but still needs to be tested.

chrbertsch commented 1 month ago

Added now in 386081f but still needs to be tested.

Thanks, @clagms ! Do you want to present this in tomorrow's FMI Design webmeeting?

clagms commented 1 month ago

It's not yet ready unfortunately. But when it is ready, then I would be more than happy to do so 🙂

-- Claudio


From: Christian Bertsch @.> Sent: Monday, August 26, 2024 9:24 AM To: clagms/synchronous-clock-fmus @.> Cc: Cláudio Ângelo Gonçalves Gomes @.>; Mention @.> Subject: Re: [clagms/synchronous-clock-fmus] Importer to simulate these FMUs? (Issue #1)

Added now in 386081fhttps://github.com/clagms/synchronous-clock-fmus/commit/386081fb79af4ea0231637c382d60a3025c7c40b but still needs to be tested.

Thanks, @clagmshttps://github.com/clagms ! Do you want to present this in tomorrow's FMI Design webmeeting?

— Reply to this email directly, view it on GitHubhttps://github.com/clagms/synchronous-clock-fmus/issues/1#issuecomment-2309521635, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAGUVPZH5KLYECY4MBWM6GLZTLJ3HAVCNFSM6AAAAABILTLFBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBZGUZDCNRTGU. You are receiving this because you were mentioned.Message ID: @.***>

clagms commented 1 month ago

PS - I cannot attend any of the design meetings unless they happen at days other than Tuesday after 1200. I'm teaching at that time 🙁

-- Claudio


From: Cláudio Ângelo Gonçalves Gomes @.> Sent: Monday, August 26, 2024 9:56 AM To: clagms/synchronous-clock-fmus @.>; clagms/synchronous-clock-fmus @.> Cc: Mention @.> Subject: Re: [clagms/synchronous-clock-fmus] Importer to simulate these FMUs? (Issue #1)

It's not yet ready unfortunately. But when it is ready, then I would be more than happy to do so 🙂

-- Claudio


From: Christian Bertsch @.> Sent: Monday, August 26, 2024 9:24 AM To: clagms/synchronous-clock-fmus @.> Cc: Cláudio Ângelo Gonçalves Gomes @.>; Mention @.> Subject: Re: [clagms/synchronous-clock-fmus] Importer to simulate these FMUs? (Issue #1)

Added now in 386081fhttps://github.com/clagms/synchronous-clock-fmus/commit/386081fb79af4ea0231637c382d60a3025c7c40b but still needs to be tested.

Thanks, @clagmshttps://github.com/clagms ! Do you want to present this in tomorrow's FMI Design webmeeting?

— Reply to this email directly, view it on GitHubhttps://github.com/clagms/synchronous-clock-fmus/issues/1#issuecomment-2309521635, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAGUVPZH5KLYECY4MBWM6GLZTLJ3HAVCNFSM6AAAAABILTLFBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBZGUZDCNRTGU. You are receiving this because you were mentioned.Message ID: @.***>

chrbertsch commented 1 week ago

@masoud-najafi : can you run these FMUs?

clagms commented 1 week ago

It’s not yet ready unfortunately. The porting from the original branch has lefts the fmus void of behavior. I still need to port that part. The older fmus from the referencefmus repo were tested by Masoud.

— Claudio


From: Christian Bertsch @.> Sent: Thursday, September 19, 2024 3:36:04 PM To: clagms/synchronous-clock-fmus @.> Cc: Cláudio Ângelo Gonçalves Gomes @.>; Mention @.> Subject: Re: [clagms/synchronous-clock-fmus] Importer to simulate these FMUs? (Issue #1)

@masoud-najafihttps://github.com/masoud-najafi : can you run these FMUs?

— Reply to this email directly, view it on GitHubhttps://github.com/clagms/synchronous-clock-fmus/issues/1#issuecomment-2361010062, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAGUVP4BYVYPE5SPZKNAJZ3ZXLHMJAVCNFSM6AAAAABILTLFBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRRGAYTAMBWGI. You are receiving this because you were mentioned.Message ID: @.***>

clagms commented 1 week ago

Now it is ready :). @masoud-najafi could you kindly run them resulting fmus by your tool? Let me know if you want me to build them. The sparse instructions are available in the readme.md file at the root of the repo.

@chrbertsch after I get confirmation from @masoud-najafi , I am more than happy to present the work to the rest :)

masoud-najafi commented 1 week ago

Hi Claudio, @clagms . Sure, where can I find them?

clagms commented 1 week ago

You can either build them following the instructions on the readme, or download them from here: https://filesender.deic.dk/?s=download&token=f60f1766-2ff9-4fd9-a268-7dee3a55ca84

masoud-najafi commented 1 week ago

Thanks, I got the binaries. Where can I get The FMUs with the source code?

masoud-najafi commented 1 week ago

There are a few fixes that should be done, for example the FMUs fail to retrieve the shift decimal variable values through APIs (mandatory I think).

masoud-najafi commented 1 week ago

@clagms: There is one thing else: Since all FMUs has direct feed-throgh, at clock instants, the FMUs create an algenraic loop. I'm not sure if the Supervisor and the Controller should have the direct-dependency. Please confirm this.

clagms commented 1 week ago

Thanks, I got the binaries. Where can I get The FMUs with the source code?

In the repository: https://github.com/clagms/synchronous-clock-fmus The readme file contains the instructions.

There are a few fixes that should be done, for example the FMUs fail to retrieve the shift decimal variable values through APIs (mandatory I think).

Fixing this at the moment. Thanks for catching it!

@clagms: There is one thing else: Since all FMUs has direct feed-throgh, at clock instants, the FMUs create an algenraic loop. I'm not sure if the Supervisor and the Controller should have the direct-dependency. Please confirm this.

No this should not be the case. Maybe there's something wrong in the model description xmls? There's no feedthrough in the Plant, nor the supervisor FMU. The controller has direct feedthrough when the clock is active. Is it the tool you're using that's highlighting the algebraic loop?

clagms commented 1 week ago

The getintervalfraction function is now implemented @masoud-najafi :)

clagms commented 1 week ago

FMUs available at: https://filesender.deic.dk/?s=download&token=32910819-8348-45fd-9772-cd8857617f3e

masoud-najafi commented 1 week ago

include

is missing in the three source files: Controller.c Supervisor.c and Plant.c. You need this include to let the source file compiled.

masoud-najafi commented 1 week ago

shift decimal is still missing in binaries as awell as in the C codes. Maybe I'm missing something.

clagms commented 1 week ago

You're right on the functions that are missing. I'm fixing those now. Sorry about that.

Regarding the stdio, I think you need to compile the whole thing, using cmake. First make sure to install cmake.

To build the FMUs run

cmake -B build .
cmake --build build

The FMUs will be created in build/fmus.

masoud-najafi commented 1 week ago

Thanks, I got the binaries. Where can I get The FMUs with the source code?

In the repository: https://github.com/clagms/synchronous-clock-fmus The readme file contains the instructions.

There are a few fixes that should be done, for example the FMUs fail to retrieve the shift decimal variable values through APIs (mandatory I think).

Fixing this at the moment. Thanks for catching it!

@clagms: There is one thing else: Since all FMUs has direct feed-throgh, at clock instants, the FMUs create an algenraic loop. I'm not sure if the Supervisor and the Controller should have the direct-dependency. Please confirm this.

No this should not be the case. Maybe there's something wrong in the model description xmls? There's no feedthrough in the Plant, nor the supervisor FMU. The controller has direct feedthrough when the clock is active. Is it the tool you're using that's highlighting the algebraic loop? The in the Plant the structure should be

**< Output valueReference="1" dependencies=""  />**
masoud-najafi commented 1 week ago

You're right on the functions that are missing. I'm fixing those now. Sorry about that.

Regarding the stdio, I think you need to compile the whole thing, using cmake. First make sure to install cmake.

To build the FMUs run

cmake -B build .
cmake --build build

The FMUs will be created in build/fmus.

cmake raised this error message:

D:\Private_F\pyco\XC_gits\Caludio\synchronous-clock-fmus>cmake -B build . -- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22631. FMI_PLATFORM: x86_64-windows -- Configuring done -- Generating done -- Build files have been written to: D:/XC_gits/Caludio/synchronous-clock-fmus/build

D:\XC_gits\Caludio\synchronous-clock-fmus>cmake --build build Microsoft (R) Build Engine version 16.8.2+25e4d540b pour .NET Framework Copyright (C) Microsoft Corporation. Tous droits réservés.

Checking Build System Building Custom Rule D:/XC_gits/Caludio/synchronous-clock-fmus/CMakeLists.txt Création de la bibliothÚque D:/XC_gits/Caludio/synchronous-clock-fmus/build/temp/Controller/binarie s/x86_64-windows/Controller.lib et de l'objet D:/XC_gits/Caludio/synchronous-clock-fmus/build/temp/Con troller/binaries/x86_64-windows/Controller.exp Controller.obj : error LNK2019: symbole externe non résolu snprintf référencé dans la fonction fmi3GetFloat64 [D:\XC_gits\Caludio\synchronous-clock-fmus\build\Controller.vcxproj] D:\XC_gits\Caludio\synchronous-clock-fmus\build\temp\Controller\binaries\x86_64-windows\Controller.dll : fatal error LNK1120: 1 externes non résolus [D:\XC_gits\Caludio\synchronous-clock-fmus\build\Controller .vcxproj]

masoud-najafi commented 1 week ago

Also please include this in the plant and Supervisor xml files to declare no-feed-through on outputs. < Output valueReference="xxx" dependencies=""/ >

clagms commented 1 week ago

Ok I think I fixed all of the above. Thank you SO much :). New fmus: https://filesender.deic.dk/?s=download&token=8b95a494-4aa7-41f2-b03c-cd29a1e3063e Hopefully you can rerun cmake and get them as well?

masoud-najafi commented 1 week ago

Hi @clagms The following changes were necessary in Supervisor.c to make the whole system work. Please check them and let me know, if there are fine for you. Thanks Masoud

fmi3Status fmi3ExitInitializationMode(fmi3Instance instance) { SupervisorInstance comp = (SupervisorInstance)instance; comp->data.pz = comp->data.z; return fmi3OK; }

fmi3Status fmi3GetEventIndicators(fmi3Instance instance, if (nEventIndicators == 0) return status; //comp->data.pz = comp->data.z; comp->data.z = 2.0 - comp->data.x;

fmi3GetFloat64(fmi3Instance instance, snprintf(msg_buff, MAX_MSG_SIZE, "Value of clock s being observed outside of event mode."); comp->logMessage(comp->componentEnvironment, status, "Warning", msg_buff); s = fmi3Warning; // values[i] = comp->data.as_previous; values[i] = comp->data.as; }

fmi3Status fmi3UpdateDiscreteStates(fmi3Instance instance, if (comp->data.s == true) { comp->data.as_previous = comp->data.as; comp->data.as = comp->data.as_previous * -1.0; comp->data.s = false; } comp->data.pz = comp->data.z;

clagms commented 1 week ago

Thanks @masoud-najafi . Yeah this works fine, and the changes have been committed. Did you get a result similar to the one below?

masoud-najafi commented 1 week ago

I got this with a fixed step solver, H=0.001 image

In order to make the supervisor model more robust to work with variable-step solvers, I made this change. fmi3Status fmi3EnterEventMode(fmi3Instance instance) { SupervisorInstance comp = (SupervisorInstance)instance; int isZC = 0; comp->state = EventMode; isZC = comp->data.pz * comp->data.z < 0.0; isZC |= comp->data.pz != 0 && comp->data.z == 0; if (isZC) { // Clock s is ticking comp->data.s = true; } return fmi3OK; } Please share your final FMUs and let me test YOUR Fmus. Then I think we are fine.

clagms commented 6 days ago

Thank you very much @masoud-najafi ! The results look exactly what they should look like!

Here are the final FMUs, with the changes proposed above: https://filesender.deic.dk/?s=download&token=105bb061-918f-4d2f-83f3-0fb6f8acbb3b

@chrbertsch I think we're ready with this. I think I can join for half hour on the 8th of Oct meeting and present this. Would that be ok with you?

Thanks!

chrbertsch commented 6 days ago

Thanks, @clagms and @masoud-najafi ! I set this on the agenda for Oct 8th.

clagms commented 6 days ago

Co-simulation is now supported :).

masoud-najafi commented 6 days ago

Thank you very much @masoud-najafi ! The results look exactly what they should look like!

Here are the final FMUs, with the changes proposed above: https://filesender.deic.dk/?s=download&token=105bb061-918f-4d2f-83f3-0fb6f8acbb3b

@chrbertsch I think we're ready with this. I think I can join for half hour on the 8th of Oct meeting and present this. Would that be ok with you?

Thanks!

Worked fine without any change.