# Fourier Coefficients in y

**URL:** <https://discourse.channelflow.ch/t/fourier-coefficients-in-y/98>\
**Category:** Programming\
**Created:** [June 4, 2020, 9:54am UTC](https://discourse.channelflow.ch/t/fourier-coefficients-in-y/98 "2020-06-04T09:54:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chihin](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.channelflow.ch/chihin/32/26_2.png) [@chihin](https://discourse.channelflow.ch/u/chihin)\
**Post date:** [June 4, 2020, 9:54am UTC](https://discourse.channelflow.ch/t/fourier-coefficients-in-y/98/1 "2020-06-04T09:54:28Z")

</div>

Hi all,

I am new to both c++ and channelflow so I would advice some patience. I am trying to extract the fourier coefficients in both x and z direction ( \hat u(kx,y,kz) ) which are function of y.

On channelflow 1.0, I think it would be u.makeState(spectral,physical), how can I achieve this in channelflow 2.0?

On Matlab, this would be equivalent to taking a 2D FFT of each slice of velocity in the y direction, but I would like to utilise channelflow 2.0 more and learn more about c++.

Cheers!

Chi Hin

---

<div class="post-metadata">

**Author:** ![jlangham](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jlangham](https://discourse.channelflow.ch/u/jlangham)\
**Post date:** [June 10, 2020, 7:07am UTC](https://discourse.channelflow.ch/t/fourier-coefficients-in-y/98/2 "2020-06-10T07:07:25Z")

</div>

> [@chihin](#):
>
> On channelflow 1.0, I think it would be u.makeState(spectral,physical), how can I achieve this in channelflow 2.0?

Hi Chi Hin,

This looks fine and should still work in Channelflow 2.0.

-Jake

---

<div class="post-metadata">

**Author:** ![chihin](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.channelflow.ch/chihin/32/26_2.png) [@chihin](https://discourse.channelflow.ch/u/chihin)\
**Post date:** [June 12, 2020, 6:52am UTC](https://discourse.channelflow.ch/t/fourier-coefficients-in-y/98/3 "2020-06-12T06:52:09Z")

</div>

Thank you Jake,

I make the following edits in simulateflow.cpp but I still get physical velocities at gridpoints in my output files from u0.nc to u100.nc. Here’s a snippet from simulateflow.cpp which I added fields[0].makeSpectral\_xz() before saving.

```
    if (saveint != 0 && i % saveint == 0) {
        fields[0].makeSpectral_xz();
        fields[0].save(outdir + label + t2s(t, inttime));
        if (savep)
            fields[1].save(outdir + "p" + t2s(t, inttime));
    }
    i++;

```

Since I am writing my files in .nc format (NetCDF), I have also seen that the writeNetCDF function in flowfield.cpp only allows for physical numbers, it that the reason why I can’t output fourier coefficents?

Regards  
Chi Hin

---

<div class="post-metadata">

**Author:** ![jlangham](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jlangham](https://discourse.channelflow.ch/u/jlangham)\
**Post date:** [June 12, 2020, 7:36am UTC](https://discourse.channelflow.ch/t/fourier-coefficients-in-y/98/4 "2020-06-12T07:36:59Z")

</div>

> [@chihin](#):
>
> Since I am writing my files in .nc format (NetCDF), I have also seen that the writeNetCDF function in flowfield.cpp only allows for physical numbers, it that the reason why I can’t output fourier coefficents?

That’s right - it transforms back to physical space before it writes. You can try writing in ascii (.asc) or .ff (the old channelflow format) which I think should work in spectral or physical. There is a `saveSpectrum` function too, which I’ve not used but you might want to look at.
