[Commits] [svn:einsteintoolkit] GRHydro/trunk/src/ (Rev. 626)
rhaas at tapir.caltech.edu
rhaas at tapir.caltech.edu
Tue Apr 15 14:49:31 CDT 2014
User: rhaas
Date: 2014/04/15 02:49 PM
Added:
/trunk/src/
GRHydro_TVDReconstruct.cc, GRHydro_TVDReconstruct.hh
Modified:
/trunk/src/
GRHydro_Reconstruct.cc, make.code.defn
Log:
GRHydro: add TVD reconstruct
File Changes:
Directory: /trunk/src/
======================
File [modified]: GRHydro_Reconstruct.cc
Delta lines: +3 -3
===================================================================
--- trunk/src/GRHydro_Reconstruct.cc 2014-04-15 19:49:28 UTC (rev 625)
+++ trunk/src/GRHydro_Reconstruct.cc 2014-04-15 19:49:31 UTC (rev 626)
@@ -187,15 +187,15 @@
if (CCTK_EQUALS(tvd_limiter, "minmod")) {
- reconstruct<GRHydro_TVDReconstruct1d<0> >::select(do_mhd, do_Ye, do_temp, reconstruct_Wv, clean_divergence, cctkGH);
+ reconstruct<GRHydro_TVDReconstruct1d<tvd::minmod> >::select(do_mhd, do_Ye, do_temp, reconstruct_Wv, clean_divergence, cctkGH);
} else if (CCTK_EQUALS(tvd_limiter, "vanleerMC2")) {
- reconstruct<GRHydro_TVDReconstruct1d<1> >::select(do_mhd, do_Ye, do_temp, reconstruct_Wv, clean_divergence, cctkGH);
+ reconstruct<GRHydro_TVDReconstruct1d<tvd::mc2> >::select(do_mhd, do_Ye, do_temp, reconstruct_Wv, clean_divergence, cctkGH);
} else if (CCTK_EQUALS(tvd_limiter, "superbee")) {
- reconstruct<GRHydro_TVDReconstruct1d<2> >::select(do_mhd, do_Ye, do_temp, reconstruct_Wv, clean_divergence, cctkGH);
+ reconstruct<GRHydro_TVDReconstruct1d<tvd::superbee> >::select(do_mhd, do_Ye, do_temp, reconstruct_Wv, clean_divergence, cctkGH);
} else {
CCTK_ERROR("TVD limiter not recognized!");
File [added]: GRHydro_TVDReconstruct.cc
Delta lines: +97 -0
===================================================================
--- trunk/src/GRHydro_TVDReconstruct.cc (rev 0)
+++ trunk/src/GRHydro_TVDReconstruct.cc 2014-04-15 19:49:31 UTC (rev 626)
@@ -0,0 +1,97 @@
+#include <cmath>
+#include "cctk.h"
+#include "cctk_Parameters.h"
+#include "cctk_Arguments.h"
+#include "cctk_Functions.h"
+
+#include "GRHydro_TVDReconstruct.hh"
+#include "GRHydro_Reconstruct_drv_impl.hh"
+
+
+using namespace std;
+
+/**
+ TVD reconstruction operator.
+ limiter_type: 0 = minmod
+ 1 = mc2
+ 2 = superbee
+*/
+template <tvd::limiter_type limiter>
+CCTK_REAL GRHydro_TVDReconstruct1d<limiter>::
+minmod_func(const CCTK_REAL dupw, const CCTK_REAL dloc)
+{
+ return 0.5 * (copysign(1.0,dupw) + copysign(1.0,dloc)) *
+ fmin(fabs(dupw),fabs(dloc));
+}
+
+template <tvd::limiter_type limiter>
+CCTK_REAL GRHydro_TVDReconstruct1d<limiter>::
+min3(const CCTK_REAL a, const CCTK_REAL b, const CCTK_REAL c)
+{
+ return fmin(a,fmin(b,c));
+}
+
+template <tvd::limiter_type limiter>
+template <int dir>
+void GRHydro_TVDReconstruct1d<limiter>::
+apply(const int nx, const CCTK_REAL* const restrict a,
+ CCTK_REAL* const restrict aminus, CCTK_REAL* const restrict aplus,
+ const cGH* const cctkGH, const int j, const int k)
+{
+ DECLARE_CCTK_PARAMETERS;
+
+#define A(i_) (a[ijk[i_]])
+#define Aplus(i_) (aplus[ijk[i_]])
+#define Aminus(i_) (aminus[ijk[i_]])
+
+
+ for (int i=GRHydro_stencil-1; i < nx-GRHydro_stencil + 1; ++i)
+ {
+
+ const int ijk[3] = {
+ dir ==0 ? CCTK_GFINDEX3D(cctkGH, i-1, j, k) : dir ==1 ? CCTK_GFINDEX3D(cctkGH, j, i-1, k) : CCTK_GFINDEX3D(cctkGH, j, k, i-1),
+ dir ==0 ? CCTK_GFINDEX3D(cctkGH, i , j, k) : dir ==1 ? CCTK_GFINDEX3D(cctkGH, j, i , k) : CCTK_GFINDEX3D(cctkGH, j, k, i ),
+ dir ==0 ? CCTK_GFINDEX3D(cctkGH, i+1, j, k) : dir ==1 ? CCTK_GFINDEX3D(cctkGH, j, i+1, k) : CCTK_GFINDEX3D(cctkGH, j, k, i+1),
+ };
+
+ const CCTK_REAL dupw = A(1)-A(0);
+ const CCTK_REAL dloc = A(2)-A(1);
+ CCTK_REAL delta = 0.0;
+
+ static_assert(limiter >= tvd::minmod && limiter < tvd::numlimiters,
+ "Unknown limiter");
+ if(limiter == tvd::minmod) {
+ // minmod
+ delta = minmod_func(dupw,dloc);
+ } else if (limiter == tvd::mc2) {
+ // Van Leer MC slope limiter (mc2)
+ if(dupw*dloc < 0.0)
+ delta = 0.0;
+ else
+ delta = copysign(min3(2.0*fabs(dupw),2.0*fabs(dloc),
+ 0.5*(fabs(dupw)+fabs(dloc))),dupw+dloc);
+
+ } else if (limiter == tvd::superbee) {
+ // superbee
+ if(dupw*dloc < 0.0)
+ delta = 0.0;
+ else
+ delta = copysign(fmax(fmin(2.0*fabs(dupw),fabs(dloc)),
+ fmin(2.0*fabs(dloc),fabs(dupw))),dupw+dloc);
+
+ }
+ Aminus(1) = A(1) - 0.5*delta;
+ Aplus(1) = A(1) + 0.5*delta;
+ }
+}
+
+// instantiate all copies we need, this way different operators can be compiled
+// in parallel. This must match the select routine in GRHydro_Reconstruct.cc
+template class GRHydro_TVDReconstruct1d<tvd::minmod>;
+template class GRHydro_TVDReconstruct1d<tvd::mc2>;
+template class GRHydro_TVDReconstruct1d<tvd::superbee>;
+
+INSTANTIATE_RECONSTRUCTION_OPERATOR(GRHydro_TVDReconstruct1d<tvd::minmod>)
+INSTANTIATE_RECONSTRUCTION_OPERATOR(GRHydro_TVDReconstruct1d<tvd::mc2>)
+INSTANTIATE_RECONSTRUCTION_OPERATOR(GRHydro_TVDReconstruct1d<tvd::superbee>)
+
File [added]: GRHydro_TVDReconstruct.hh
Delta lines: +33 -0
===================================================================
--- trunk/src/GRHydro_TVDReconstruct.hh (rev 0)
+++ trunk/src/GRHydro_TVDReconstruct.hh 2014-04-15 19:49:31 UTC (rev 626)
@@ -0,0 +1,33 @@
+#ifndef _GRHYDRO_TVDRECONSTRUCT_HH
+#define _GRHYDRO_TVDRECONSTRUCT_HH
+
+#include "cctk.h"
+
+/**
+ TVD reconstruction operator.
+ limiter_type: 0 = minmod
+ 1 = mc2
+ 2 = superbee
+*/
+namespace tvd {
+ enum limiter_type {minmod = 0, mc2 = 1, superbee = 2, numlimiters};
+}
+template <tvd::limiter_type limiter>
+struct GRHydro_TVDReconstruct1d {
+
+ static inline CCTK_REAL minmod_func(const CCTK_REAL dupw,
+ const CCTK_REAL dloc);
+ static inline CCTK_REAL min3(const CCTK_REAL a,
+ const CCTK_REAL b,
+ const CCTK_REAL c);
+ template <int dir>
+ static inline void apply(const int nx,
+ const CCTK_REAL* const restrict a,
+ CCTK_REAL* const restrict aminus,
+ CCTK_REAL* const restrict aplus,
+ const cGH* const cctkGH,
+ const int j, const int k
+ );
+}; // end struct
+
+#endif // _GRHYDRO_TVDRECONSTRUCT_HH
File [modified]: make.code.defn
Delta lines: +1 -0
===================================================================
--- trunk/src/make.code.defn 2014-04-15 19:49:28 UTC (rev 625)
+++ trunk/src/make.code.defn 2014-04-15 19:49:31 UTC (rev 626)
@@ -88,6 +88,7 @@
GRHydro_ePPM.cc \
GRHydro_PPMReconstruct_drv_opt.cc \
GRHydro_WENOReconstruct.cc \
+ GRHydro_TVDReconstruct.cc \
GRHydro_TrivialReconstruct.cc \
GRHydro_MP5Reconstruct.cc \
GRHydro_Wrappers.F90 \
More information about the Commits
mailing list