Commit ecf1f314 authored by novatig's avatar novatig

bugfix sinusoidal mesh grid kernel

parent 39badfaa
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <limits> #include <limits>
#include <vector> #include <vector>
#include <string> #include <string>
#include <iostream> //#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <random> // C++11 #include <random> // C++11
...@@ -536,42 +536,41 @@ public: ...@@ -536,42 +536,41 @@ public:
const unsigned int ghostS=0, const unsigned int ghostE=0, double* const ghost_spacing=NULL) const const unsigned int ghostS=0, const unsigned int ghostE=0, double* const ghost_spacing=NULL) const
{ {
const unsigned int total_cells = ncells + ghostE + ghostS; const unsigned int total_cells = ncells + ghostE + ghostS;
double* const buf = new double[total_cells]; double* const DH = new double[total_cells];
double* const Yface = new double[ncells+1];
double sumDH = 0;
// interior // interior
const unsigned int nhalf = ncells/2 + ncells%2; for (unsigned int i = 0; i <= ncells; ++i)
const double h = 2.0 / ncells;
double ducky = 0.0;
for (unsigned int i = 0; i < nhalf; ++i)
{ {
const double x = h*(i+0.5) - 1.0; const double x = 2*i / (double) ncells - 1.0;// maps i to -1 : 1
const double dh = std::sin(0.5*eta*x*M_PI) / std::sin(0.5*eta*M_PI) + 1.0; // both x and y are mapped to -1 : 1, but one is refined @ edges
buf[i+ghostS] = dh; Yface[i] = std::sin(.5*eta*x*M_PI) / std::sin(.5*eta*M_PI);
buf[ncells-1-i+ghostS] = dh; // sum grid spacing together in order to enforce sumDH == extent
if(i == 0) continue; // skip first face
ducky += 2*dh; assert(Yface[i]-Yface[i-1]>0 && "Requires posdef grid spacing");
DH[i-1+ghostS] = Yface[i] - Yface[i-1];
sumDH += Yface[i] - Yface[i-1];
} }
if (ncells%2 == 1)
ducky -= buf[ghostS+nhalf-1];
const double scale = (xE-xS)/ducky; const double scale = (xE-xS)/sumDH;
for (unsigned int i = 0; i < ncells; ++i) for (unsigned int i = 0; i < ncells; ++i)
buf[i+ghostS] *= scale; DH[i+ghostS] *= scale;
for (unsigned int i = 0; i < ncells; ++i) for (unsigned int i = 0; i < ncells; ++i)
ary[i] = buf[i+ghostS]; ary[i] = DH[i+ghostS];
assert(ghostS == ghostE); assert(ghostS == ghostE);
if (ghost_spacing) if (ghost_spacing)
{ {
for (unsigned int i = 0; i < ghostS; ++i) for (unsigned int i = 0; i < ghostS; ++i)
ghost_spacing[ghostS-1-i] = buf[ghostS+i]; ghost_spacing[ghostS-1-i] = DH[ghostS+i];
for (unsigned int i = 0; i < ghostE; ++i) for (unsigned int i = 0; i < ghostE; ++i)
ghost_spacing[i+ghostS] = buf[ncells-1+ghostS-i]; ghost_spacing[i+ghostS] = DH[ncells-1+ghostS-i];
} }
// clean up // clean up
delete[] buf; delete[] DH;
delete[] Yface;
} }
virtual std::string name() const { return std::string("SinusoidalDensity"); } virtual std::string name() const { return std::string("SinusoidalDensity"); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment