Hello everyone:(adsbygoogle = window.adsbygoogle || []).push({});

I am a C++ newbie; I am interesting in using C++ in my work on coupled fluid flow-chemical reaction problems. I apologize in advance for what is probably a very simple question. I would very much appreciate any help to get me on the right track!

My goal is to come up with C++ code for solving a finite difference problem. To do this, I need to (1) construct a 2-D grid and (2) link a struct of data (fluid properties, like density) to the grid. At some point, as I become more experienced, I'd like to learn how to use pointers and iterators, etc, but for now I would like to keep things as simple as possible.

Using some examples, I have come up with a way of constructing a grid that mostly makes sense.But I cannot figure out how to link the grid with a struct of fluid properties.Sorry--I'm certain this is a simple thing to do. If anyone has any suggestions, I would love to hear them. Once I have this problem sorted out, I have a couple of further questions about the grid construction. Thanks a lot.

Here is my grid:

template <typename T>

class Grid2D

{

public:

Grid() : xsize_(0), ysize_(0), grid_(0) { }

Grid(double xsize, double ysize) : xsize_(xsize), ysize_(ysize), grid_(new T[ xsize_ * ysize_ ]) { }

~Grid() { delete[ ] grid_; }

Create(double xsize, double ysize)

{

xsize_ = xsize;

ysize_ = ysize;

grid_ = new T[ xsize_ * ysize_ ];

}

Resize(double xsize, double ysize)

{

xsize_ = xsize;

ysize_ = ysize;

delete[ ] grid_;

grid_ = new T[ xsize_ * ysize_ ];

}

Delete()

{

xsize_ = 0;

ysize_ = 0;

delete[ ] grid_;

grid_ = 0;

}

double xsize() const { return xsize_; }

double ysize() const { return ysize_; }

T& operator(double x, double y) { return grid_[ y*xsize_ + x ]; }

const T& operator(double x, double y) const { return grid_[ y*xsize_ + x ]; }

private:

double xsize_, ysize_;

T* grid_;

}

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C++ newbie qu: grid construction for finite difference

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - newbie grid construction | Date |
---|---|

Finite differencing on non-uniform grids | Oct 20, 2015 |

Finite Difference Method for non-square grid | Sep 14, 2015 |

Mehrstellenverfahren for different grid spacing along the three space directions | Oct 13, 2014 |

Numerical solution of continuity equation, implicit scheme, staggered grid | Nov 29, 2011 |

Newbie question | Nov 30, 2009 |

**Physics Forums - The Fusion of Science and Community**