Change the FlowField state to Physical (i.e. do the inverse transforms so that the data arrays stores the gridpoint values as opposed to the spectral coefficients).
Loop over the gridpoints, evaluate the function, and assign into the FlowField
Transform back to Spectral
#include <iostream>#include "channelflow/flowfield.h"
using namespace std;
using namespace channelflow;
Real f(Real x, Real y, Real z, int i){if(i==0)return sin(x)*(1-y*y)*cos(z);
elsereturn0.0;
}int main(){int Nx=32;
int Ny=33;
int Nx=32;
int Nd=3;
FlowField u(Nx,Ny,Nz,Nd,2*pi,2*pi,-1,1);
u.makePhysical();
for(int i=0; i<Nd; ++i)for(int ny=0; ny<Ny; ++ny){
Real y = u.y(ny);
for(int nz=0; nz<Nz; ++nz){
Real z = u.z(nz);
for(int nx=0; nx<Nx; ++nx){
Real x = u.x(nx);
u(nx,ny,nz,i)= f(x,y,z,i);
}}}
u.makeSpectral();
}
programming/example_q_a_how_do_i_access_the_data_in_a_flowfield.txt · Last modified: 2010-02-02 07:55 (external edit)
Discussion