HOME | DD
Published: 2017-11-05 16:13:58 +0000 UTC; Views: 889; Favourites: 7; Downloads: 10
Redirect to original
Related content
Comments: 2
JaguarFacedMan [2017-11-05 20:25:11 +0000 UTC]
So... I don't speak C++. So if its not to much to ask could you outline whats going on?
👍: 0 ⏩: 1
Mathness In reply to JaguarFacedMan [2017-11-05 21:25:59 +0000 UTC]
If you chuck out the class line, { after it, all the lines ending with :, and all rd. in main, you can compile it as regular C.
Staying with the C++ code, think of class{ } as a structure/sub-programme that is accessed with various methods (Setup, Iterate, essential like functions). First you have to create/construct it, that is done with 'ReactionDiffusion rd', first part is the class, second bit is the name we use to access it (similar to float x). That means we can run the methods in the public: part of the class, rd.Setup(...) for instance. The stuff in private: and protected: can only be accessed by methods in the class.
The Laplacian takes a point on a grid ( x , y ) as input. It takes the sum of the eight points around it and multiply with a weight (0.2 for direct neighbours, 0.05 for the corners) minus itself, and returns that. The AVX2 code is a speed up to calculate the eight points, since 256 bit is 8 floats (32bit each).
rd.Iterate is done 10k times, and each time all grid points (except edges) are used to calculate the new values, then new values are swapped to be the current ones ( std::swap( a , a_next ) just swaps the pointers).
If you can not compile AVX2 code, the following code does the same, although slower.
const float Laplacian_grid_weights[ 3 ][ 3 ] = { { 0.05f , 0.2f , 0.05f } , { 0.2f , -1.f , 0.2f } , { 0.05f , 0.2f , 0.05f } } ;
float Laplacian_Operator( int32_t x , int32_t y , float *read_data )
{
float value = 0.f ;
for ( int32_t dy = -1 ; dy <= 1 ; dy++ )
{
for ( int32_t dx = -1 ; dx <= 1 ; dx++ )
{
int32_t px = x + dx ;
int32_t py = y + dy ;
value += read_data[ px + py * data_width ] * Laplacian_grid_weights[ dx + 1 ][ dy + 1 ] ;
}
}
return value ;
}
I hope that helps.
👍: 0 ⏩: 0





















