# FAST\_SFunc

**URL:** <https://forums.nlr.gov/t/fast-sfunc/2308>\
**Category:** Controls\
**Created:** [July 29, 2020, 4:25am UTC](https://forums.nlr.gov/t/fast-sfunc/2308 "2020-07-29T04:25:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sina.Ameli](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/sina.ameli/32/3203_2.png) [@Sina.Ameli](https://forums.nlr.gov/u/Sina.Ameli)\
**Post date:** [July 29, 2020, 4:25am UTC](https://forums.nlr.gov/t/fast-sfunc/2308/1 "2020-07-29T04:25:57Z")

</div>

Dear all,

Does anybody has the source code of “FAST\_SFunc” block in Simulink for FAST v8 ? My problem is that when I want to open it, Matlab says that the S-Function source file cannot be found even though the simulation runs well.

Thank you

Best,  
Sina

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [July 31, 2020, 4:56pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/2 "2020-07-31T16:56:42Z")

</div>

Dear Sina,

The source code for the FAST S-Function (FAST\_SFunc) in the interface between Simulink and FAST v8 is written in C. The source file FAST\_SFunc.c is included in the Simulink/Source directory of the FAST v8 archive.

Best regards,

---

<div class="post-metadata">

**Author:** ![Sina.Ameli](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/sina.ameli/32/3203_2.png) [@Sina.Ameli](https://forums.nlr.gov/u/Sina.Ameli)\
**Post date:** [August 4, 2020, 9:51pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/3 "2020-08-04T21:51:45Z")

</div>

Dear Dr. Jonkman,

Thanks for your response. Yes, I found this source code but it seems it is not a true/actual source code. If I don’t set the path to the address you mentioned, then I cannot open the FAST\_SFunc.c in Simulink; on the other hand, when I set path to this address, I can open it but it seems this file does not have to anything with the simulation. It seems, it is a template file. I also wrote something wrong in it, then the simulation still runs well! Am I missing something?

Thanks  
Best regards,  
Sina

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [August 4, 2020, 10:16pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/4 "2020-08-04T22:16:12Z")

</div>

Dear Sina,

The FAST\_SFunc.c source code is compiled into FAST\_SFunc.mexw32 or FAST\_SFunc.mexw64 (for 32-bit or 64-bit Windows versions of MATLAB, respectively), which ends up as the FAST S-Function block in Simulink.

Best regards,

---

<div class="post-metadata">

**Author:** ![Ali.Rouhbakhsh](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ali.Rouhbakhsh](https://forums.nlr.gov/u/Ali.Rouhbakhsh)\
**Post date:** [May 2, 2022, 10:01pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/5 "2022-05-02T22:01:04Z")

</div>

hi  
when we connect FAST to Simulink i want to know what S-Function does on parameters like Electrical Power or GenTrq,  
Is there a theory for the S-Function in FAST 7? How can I find its source so that I can understand what is being done to the input and output parameters of the S-Function?

---

<div class="post-metadata">

**Author:** ![Ali.Rouhbakhsh](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ali.Rouhbakhsh](https://forums.nlr.gov/u/Ali.Rouhbakhsh)\
**Post date:** [May 2, 2022, 10:23pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/6 "2022-05-02T22:23:18Z")

</div>

I have another question  
When I run FAST via Simulink, I take the RotorTorque from the given outputs as feedback for the control loop and enter this parameter into the generator and then take the rotor speed from the generator. Can I enter this rotational speed into S-Function?  
Is this method correct?

 ![OpenLoop _ - Simulink 5_3_2022 2_52_43 AM](https://europe1.discourse-cdn.com/nrel/original/2X/b/b455493e883fda06f168b3039969c0f73fd8d96c.png)

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [May 2, 2022, 10:57pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/7 "2022-05-02T22:57:32Z")

</div>

Dear @Ali.Rouhbakhsh,

The generator torque input to the FAST S-Function from Simulink is the torque that will be applied to the generator (on the high-speed shaft side), and equally and oppositely applied to the nacelle (the torque applied to the nacelle is multiplied by the the gearbox ratio, `GBRatio`). If this torque does not balance with the torque applied through the rotor (aerodynamic torque), the drivetrain will accelerate or decelerate.

The electrical power input to the FAST S-Function from Simulink is not really used by the FAST S-Function other than to be included in the OutList if output `GenPwr` is selected.

Simulink cannot directly prescribe the rotor speed as an input to the FAST S-Function.

Best regards,

---

<div class="post-metadata">

**Author:** ![Ali.Rouhbakhsh](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ali.Rouhbakhsh](https://forums.nlr.gov/u/Ali.Rouhbakhsh)\
**Post date:** [May 3, 2022, 6:52pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/8 "2022-05-03T18:52:12Z")

</div>

Does this mean generator is inside the S-Function ?

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [May 3, 2022, 7:06pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/9 "2022-05-03T19:06:25Z")

</div>

Dear @Ali.Rouhbakhsh,

The rigid-body rotation degree of freedom of the generator, and the associated generator inertia, are in within the FAST S-Function. The calculation of the generator torque (and power) should be implemented in Simulink.

Best regards,

---

<div class="post-metadata">

**Author:** ![Ali.Rouhbakhsh](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ali.Rouhbakhsh](https://forums.nlr.gov/u/Ali.Rouhbakhsh)\
**Post date:** [May 3, 2022, 7:16pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/10 "2022-05-03T19:16:55Z")

</div>

I have a Simulink file that simulates the whole turbine and has nothing to do with FAST and is not connected to FAST. And I want to connect this Simulink file to FAST via S-Function.

Can you help me which parts of the attached Simulink file to transfer to the Simulink file linked to FAST (via S-Function)?

 ![aerotest5kwraheno _ - Simulink 5_3_2022 11_45_52 PM](https://europe1.discourse-cdn.com/nrel/original/2X/e/e7a844c4f1f417651f8f7d50e7eb9873c43d47af.png)  
 ![aerotest5kwraheno _ - Simulink 5_3_2022 11_46_20 PM](https://europe1.discourse-cdn.com/nrel/original/2X/4/441c905571b1fcdf808944ae139eb8843e4b5cb2.png)

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [May 3, 2022, 7:46pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/11 "2022-05-03T19:46:14Z")

</div>

Dear @Ali.Rouhbakhsh,

I can’t fully interpret your Simulink model. Regardless, I would say any structural or aerodynamic parts of the model should be handled by the FAST S-Function and the electrical and control aspects of the model should be implemented in Simulink.

Best regards,

---

<div class="post-metadata">

**Author:** ![Ali.Rouhbakhsh](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ali.Rouhbakhsh](https://forums.nlr.gov/u/Ali.Rouhbakhsh)\
**Post date:** [May 3, 2022, 7:56pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/12 "2022-05-03T19:56:11Z")

</div>

hank you  
I have another question  
When I connect FAST to Simulink and get the GenPwr output, it looks like the attached image  
I think this output is problematic because the power is negative  
What is the problem?  
(vertical axis=GenPwr Horizontal axis=time)

 ![Figure 1 5_4_2022 12_22_08 AM](https://europe1.discourse-cdn.com/nrel/original/2X/a/a6401eb3a22aa792089e9ab6e08e7367cb862d93.png)

---

<div class="post-metadata">

**Author:** ![Sina.Ameli](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/sina.ameli/32/3203_2.png) [@Sina.Ameli](https://forums.nlr.gov/u/Sina.Ameli)\
**Post date:** [May 3, 2022, 8:06pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/13 "2022-05-03T20:06:01Z")

</div>

Dear Ali,

I have a Simulink model calculating the generator torque (input to the FAST). You can find the run file and Simulink in my Github:

> **[GitHub -...](https://github.com/Sina-eng/Robust-control-and-estimator-for-Wind-Turbine-with-Actuator-Fault-Simulation-FAST-NREL-)**
>
> Robust adaptive control for wind turbine with actuator faults FAST simulator (NREL) - GitHub - Sina-eng/Robust-control-and-estimator-for-Wind-Turbine-with-Actuator-Fault-Simulation-FAST-NREL-: Robu...

Best regards,  
Sina

---

<div class="post-metadata">

**Author:** ![Ali.Rouhbakhsh](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ali.Rouhbakhsh](https://forums.nlr.gov/u/Ali.Rouhbakhsh)\
**Post date:** [May 3, 2022, 8:10pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/14 "2022-05-03T20:10:05Z")

</div>

Thank you very much Mr. Ameli

Can I email you if I have any other questions?

---

<div class="post-metadata">

**Author:** ![Sina.Ameli](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/sina.ameli/32/3203_2.png) [@Sina.Ameli](https://forums.nlr.gov/u/Sina.Ameli)\
**Post date:** [May 3, 2022, 8:18pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/15 "2022-05-03T20:18:40Z")

</div>

Dear Ali,

You are welcome! Sure. Hope this will help you.

Best regards,  
Sina

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [May 3, 2022, 8:56pm UTC](https://forums.nlr.gov/t/fast-sfunc/2308/16 "2022-05-03T20:56:10Z")

</div>

Dear @Ali.Rouhbakhsh,

Again the generator power is computed within Simulink and input to the FAST S-Function, but the generator power is not used or modified by the S-Function other to output it. So, if the generator power output is not what you expect, I would ensure that it is computed as you want within Simulink.

Best regards,
