programming

Example Q&A: How do I set a FlowField to a prescribed function?

John F. Gibson, 2009-01-09 10:15

I want to set a FlowField to a prescribed function of (x,y,z). How do I do that?

Discussion

John F. Gibson, 2009-01-09 10:27
  1. 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).
  2. Loop over the gridpoints, evaluate the function, and assign into the FlowField
  3. 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);
  else
    return 0.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)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki