Skip to content

Commit

Permalink
Apply clang format.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkestene committed Feb 18, 2024
1 parent 041867b commit 7515194
Show file tree
Hide file tree
Showing 186 changed files with 26,935 additions and 23,752 deletions.
15 changes: 8 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@
#include "shared/SolverFactory.h"

#ifdef USE_MPI
#include "utils/mpiUtils/GlobalMpiSession.h"
#include <mpi.h>
# include "utils/mpiUtils/GlobalMpiSession.h"
# include <mpi.h>
#endif // USE_MPI

#ifdef USE_HDF5
#include "utils/io/IO_HDF5.h"
# include "utils/io/IO_HDF5.h"
#endif // USE_HDF5

// banner
#include "ppkMHD_version.h"

#ifdef USE_FPE_DEBUG
// for catching floating point errors
#include <fenv.h>
#include <signal.h>
# include <fenv.h>
# include <signal.h>

// signal handler for catching floating point errors
void fpehandler(int sig_num)
void
fpehandler(int sig_num)
{
signal(SIGFPE, fpehandler);
printf("SIGFPE: floating point exception occured of type %d, exiting.\n",sig_num);
printf("SIGFPE: floating point exception occured of type %d, exiting.\n", sig_num);
abort();
}
#endif // USE_FPE_DEBUG
Expand Down
58 changes: 34 additions & 24 deletions src/mood/Binomial.h
Original file line number Diff line number Diff line change
@@ -1,65 +1,75 @@
/**
* Compute binomial coefficients C_n^k = n! / k! / (n-k)!
*
* Adapted from
* Adapted from
* http://go-lambda.blogspot.fr/2012/02/template-for-binomial-coefficients-in-c.html
*/
#ifndef BINOMIAL_H_
#define BINOMIAL_H_

namespace mood {
namespace mood
{

template<int n, int k>
template <int n, int k>
struct Binomial
{
const static int value = (Binomial<n-1,k-1>::value + Binomial<n-1,k>::value);
const static int value = (Binomial<n - 1, k - 1>::value + Binomial<n - 1, k>::value);
};

template<>
struct Binomial<0,0>
template <>
struct Binomial<0, 0>
{
const static int value = 1;
};

template<int n>
struct Binomial<n,0>
template <int n>
struct Binomial<n, 0>
{
const static int value = 1;
};

template<int n>
struct Binomial<n,n>
template <int n>
struct Binomial<n, n>
{
const static int value = 1;
};

template<int n, int k>
inline constexpr int binomial()
template <int n, int k>
inline constexpr int
binomial()
{
return Binomial<n,k>::value;
return Binomial<n, k>::value;
}

/**
* binomial coefficients without templates.
*/
inline int binom(int n, int k)
inline int
binom(int n, int k)
{

if (n < k) return 0;
if (k == 0 || n == 1) return 1;
if (n == 2 && k == 1) return 2;
if (n == 2 && k == 2) return 1;
if (n == k) return 1;
if (n < k)
return 0;
if (k == 0 || n == 1)
return 1;
if (n == 2 && k == 1)
return 2;
if (n == 2 && k == 2)
return 1;
if (n == k)
return 1;

int res = 1;

if ( k > n - k ) k = n - k;
for( int i = 0; i < k; ++i ) {
res *= ( n - i );
res /= ( i + 1 );
if (k > n - k)
k = n - k;
for (int i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}
return res;

} // binom

} // namespace mood
Expand Down
62 changes: 28 additions & 34 deletions src/mood/GeometricTerms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "GeometricTerms.h"
#include "Binomial.h"

namespace mood {
namespace mood
{

// =======================================================
// ==== Class GeometricTerms IMPL ========================
Expand All @@ -13,71 +14,64 @@ namespace mood {

// =======================================================
// =======================================================
GeometricTerms::GeometricTerms(real_t dx,
real_t dy,
real_t dz) :
dx(dx), dy(dy), dz(dz)
GeometricTerms::GeometricTerms(real_t dx, real_t dy, real_t dz)
: dx(dx)
, dy(dy)
, dz(dz)
{

// assumes that stencil_radius is in [1,6]
// so we just need to instanciate the maximun value



} // GeometricTerms::GeometricTerms


// =======================================================
// =======================================================
GeometricTerms::~GeometricTerms()
{

} // GeometricTerms::~GeometricTerms
GeometricTerms::~GeometricTerms() {} // GeometricTerms::~GeometricTerms

// =======================================================
// =======================================================
real_t GeometricTerms::eval_moment(int i, int j,
int n, int m)
real_t
GeometricTerms::eval_moment(int i, int j, int n, int m)
{

return 1.0/dx/dy *
pow(dx,n+1) / (n+1) * ( pow(i+0.5, n+1) - pow(i-0.5, n+1) ) *
pow(dy,m+1) / (m+1) * ( pow(j+0.5, m+1) - pow(j-0.5, m+1) );


return 1.0 / dx / dy * pow(dx, n + 1) / (n + 1) * (pow(i + 0.5, n + 1) - pow(i - 0.5, n + 1)) *
pow(dy, m + 1) / (m + 1) * (pow(j + 0.5, m + 1) - pow(j - 0.5, m + 1));

} // GeometricTerms::eval_moment

// =======================================================
// =======================================================
real_t GeometricTerms::eval_moment(int i, int j, int k,
int n, int m, int l)
real_t
GeometricTerms::eval_moment(int i, int j, int k, int n, int m, int l)
{
return 1.0/dx/dy/dz *
pow(dx,n+1) / (n+1) * ( pow(i+0.5, n+1) - pow(i-0.5, n+1) ) *
pow(dy,m+1) / (m+1) * ( pow(j+0.5, m+1) - pow(j-0.5, m+1) ) *
pow(dz,l+1) / (l+1) * ( pow(k+0.5, l+1) - pow(k-0.5, l+1) );

return 1.0 / dx / dy / dz * pow(dx, n + 1) / (n + 1) *
(pow(i + 0.5, n + 1) - pow(i - 0.5, n + 1)) * pow(dy, m + 1) / (m + 1) *
(pow(j + 0.5, m + 1) - pow(j - 0.5, m + 1)) * pow(dz, l + 1) / (l + 1) *
(pow(k + 0.5, l + 1) - pow(k - 0.5, l + 1));

} // GeometricTerms::eval_moment

// =======================================================
// =======================================================
real_t GeometricTerms::eval_hat(int i, int j,
int n, int m)
real_t
GeometricTerms::eval_hat(int i, int j, int n, int m)
{

return eval_moment(i,j, n,m) - eval_moment(0,0, n,m);
return eval_moment(i, j, n, m) - eval_moment(0, 0, n, m);

} // GeometricTerms::eval_hat

// =======================================================
// =======================================================
real_t GeometricTerms::eval_hat(int i, int j, int k,
int n, int m, int l)
real_t
GeometricTerms::eval_hat(int i, int j, int k, int n, int m, int l)
{

return eval_moment(i,j,k, n,m,l) - eval_moment(0,0,0, n,m,l);
return eval_moment(i, j, k, n, m, l) - eval_moment(0, 0, 0, n, m, l);

} // GeometricTerms::eval_hat

} // namespace mood

62 changes: 32 additions & 30 deletions src/mood/GeometricTerms.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,92 @@

#include "shared/real_type.h"

namespace mood {
namespace mood
{

/**
* \class GeometricTerms GeometricTerms.h
*
* \brief This class is a helper to compute geometric terms found
* in the 2D/3D MOOD numerical scheme.
* in the 2D/3D MOOD numerical scheme.
*
* The reconstruction polynomial
* is the solution of a linear system whose coefficients are
* is the solution of a linear system whose coefficients are
* purely geometric.
*
* Most of the code written here is adapted from reference:
* Ollivier-Gooch, Quasi-ENO schemes for unstructured meshes based
* on unlimited data-dependent least-squares reconstruction, JCP,
* on unlimited data-dependent least-squares reconstruction, JCP,
* vol 133, 6-17, 1997.
* http://www.sciencedirect.com/science/article/pii/S0021999196955849
*/
class GeometricTerms {
class GeometricTerms
{

public:

/**
*
*/
GeometricTerms(real_t dx,
real_t dy,
real_t dz);
GeometricTerms(real_t dx, real_t dy, real_t dz);
~GeometricTerms();

//! size of a cell (assumes here regular cartesian mesh)
real_t dx, dy, dz;

/**
* computes volume average of x^n y^m z^l inside
* computes volume average of x^n y^m z^l inside
* cell i (chosen to be the origin).
*
* In 2D:
* \f$ \overline{x^n y^m}_i = \frac{1}{V_i} \int_{\mathcal{V}_i} (x-x_i)^n (y-y_i)^m dv \f$
* with x_i = 0 and y_i = 0.
*
*/
real_t eval_moment(int i, int j,
int n, int m);
real_t
eval_moment(int i, int j, int n, int m);

/**
* computes volume average of x^n y^m z^l inside
* computes volume average of x^n y^m z^l inside
* cell i (chosen to be the origin).
*
* In 3D:
* \f$ \overline{x^n y^m z^l}_i = \frac{1}{V_i} \int_{\mathcal{V}_i} (x-x_i)^n (y-y_i)^m (z-z_i)^l dv \f$
* with x_i = 0, y_i = 0 and z_i = 0.
* \f$ \overline{x^n y^m z^l}_i = \frac{1}{V_i} \int_{\mathcal{V}_i} (x-x_i)^n (y-y_i)^m (z-z_i)^l
* dv \f$ with x_i = 0, y_i = 0 and z_i = 0.
*
*/
real_t eval_moment(int i, int j, int k,
int n, int m, int l);
real_t
eval_moment(int i, int j, int k, int n, int m, int l);

/**
* In 2D, this is formula from Ollivier-Gooch, 1997
*
* For structured grid, it returns the following
* \f$ \widehat{x^n y^m}_{i,j} =\frac{1}{V_j} \int_{\mathcal{V}_j} \left( (x-x_j)+(x_j-x_i) \right)^n \left( (y-y_j)+(y_j-y_i) \right)^m \dif v - \overline{x^n y^m}_i \f$
* which can be computed exactly on regular cartesian grid.
* \f$ \widehat{x^n y^m}_{i,j} =\frac{1}{V_j} \int_{\mathcal{V}_j} \left( (x-x_j)+(x_j-x_i)
* \right)^n \left( (y-y_j)+(y_j-y_i) \right)^m \dif v - \overline{x^n y^m}_i \f$ which can be
* computed exactly on regular cartesian grid.
*
* For unstructured grid, it can be developped into
*
* \f$ \widehat{x^n y^m}_{i,j} = \sum_{a=0}^{n} \sum_{b=0}^{m} \binom{n}{a} \binom{m}{b} (x_j-x_i)^a (y_j-y_i)^b \overline{x^{n-a} y^{m-b}}_j \; - \; \overline{x^n y^m}_i \f$
*
* \f$ \widehat{x^n y^m}_{i,j} = \sum_{a=0}^{n} \sum_{b=0}^{m} \binom{n}{a} \binom{m}{b}
* (x_j-x_i)^a (y_j-y_i)^b \overline{x^{n-a} y^{m-b}}_j \; - \; \overline{x^n y^m}_i \f$
*
*
* \param[in] xj coordinate (integers) of the target point.
* \param[in] n
* \param[in] m
*
* \return \f$ \widehat{x^n y^m}_{i,j} \f$
*/
real_t eval_hat(int i, int j,
int n, int m);
real_t
eval_hat(int i, int j, int n, int m);

/**
* In 3D the formula is slightly adapted from the 2D version:
*
* By definition, we need to compute
* \f$ \widehat{x^n y^m z^l}_{i,j} = \frac{1}{V_j} \int_{\mathcal{V}_j} \left( (x-x_j)+(x_j-x_i) \right)^n \left( (y-y_j)+(y_j-y_i) \right)^m \left( (z-z_j)+(z_j-z_i) \right)^l \dif v - \overline{x^n y^m z^l}_i\f$
* which can be obtained analytically for a structured cartesian grid:
* \f$ \widehat{x^n y^m z^l}_{i,j} = \frac{1}{V_j} \int_{\mathcal{V}_j} \left( (x-x_j)+(x_j-x_i)
* \right)^n \left( (y-y_j)+(y_j-y_i) \right)^m \left( (z-z_j)+(z_j-z_i) \right)^l \dif v -
* \overline{x^n y^m z^l}_i\f$ which can be obtained analytically for a structured cartesian grid:
*
* \f$ \widehat{x^n y^m z^l}_{i,j} = ... \f$
*
Expand All @@ -100,10 +102,10 @@ class GeometricTerms {
* \return \f$ \widehat{x^n y^m z^l}_{i,j} \f$
*
*/
real_t eval_hat(int i, int j, int k,
int n, int m, int l);
real_t
eval_hat(int i, int j, int k, int n, int m, int l);



}; // class GeometricTerms

} // namespace mood
Expand Down
Loading

0 comments on commit 7515194

Please sign in to comment.