Skip to content

Commit

Permalink
Merge pull request #204 from prabhuramachandran/remove-pi-as-predefin…
Browse files Browse the repository at this point in the history
…ed-quantity

Remove pi as predefined quantity
  • Loading branch information
prabhuramachandran committed Apr 20, 2019
2 parents b93fc78 + edf3e48 commit ae947b3
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 30 deletions.
29 changes: 22 additions & 7 deletions docs/source/design/equations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,31 @@ following:
destination particle with index, ``d_idx``.



.. note::

Note that all standard functions and constants in ``math.h`` are available
for use in the equations. ``pi`` is defined. Please avoid using functions
from ``numpy`` as these are Python functions and are slow. They also will
not allow PySPH to be run with OpenMP. Similarly, do not use functions or
constants from ``sympy`` and other libraries inside the equation methods as
these will significantly slow down your code.

for use in the equations. The value of :math:`\pi` is available as
``M_PI``. Please avoid using functions from ``numpy`` as these are Python
functions and are slow. They also will not allow PySPH to be run with
OpenMP. Similarly, do not use functions or constants from ``sympy`` and
other libraries inside the equation methods as these will significantly
slow down your code.

In addition, these constants from the math library are available:

- ``M_E``: value of e
- ``M_LOG2E``: value of log2e
- ``M_LOG10E``: value of log10e
- ``M_LN2``: value of loge2
- ``M_LN10``: value of loge10
- ``M_PI``: value of pi
- ``M_PI_2``: value of pi / 2
- ``M_PI_4``: value of pi / 4
- ``M_1_PI``: value of 1 / pi
- ``M_2_PI``: value of 2 / pi
- ``M_2_SQRTPI``: value of 2 / (square root of pi)
- ``M_SQRT2``: value of square root of 2
- ``M_SQRT1_2``: value of square root of 1/2

In an equation, any undeclared variables are automatically declared to be
doubles in the high-performance Cython code that is generated. In addition
Expand Down
27 changes: 22 additions & 5 deletions docs/source/design/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,28 @@ the following may be passed into any of the methods of an equation:
.. note::

Note that all standard functions and constants in ``math.h`` are available
for use in the equations. ``pi`` is defined. Please avoid using functions
from ``numpy`` as these are Python functions and are slow. They also will
not allow PySPH to be run with OpenMP. Similarly, do not use functions or
constants from ``sympy`` and other libraries inside the equation methods as
these will significantly slow down your code.
for use in the equations. The value of :math:`\pi` is available in
``M_PI``. Please avoid using functions from ``numpy`` as these are Python
functions and are slow. They also will not allow PySPH to be run with
OpenMP. Similarly, do not use functions or constants from ``sympy`` and
other libraries inside the equation methods as these will significantly
slow down your code.

In addition, these constants from the math library are available:

- ``M_E``: value of e
- ``M_LOG2E``: value of log2e
- ``M_LOG10E``: value of log10e
- ``M_LN2``: value of loge2
- ``M_LN10``: value of loge10
- ``M_PI``: value of pi
- ``M_PI_2``: value of pi / 2
- ``M_PI_4``: value of pi / 4
- ``M_1_PI``: value of 1 / pi
- ``M_2_PI``: value of 2 / pi
- ``M_2_SQRTPI``: value of 2 / (square root of pi)
- ``M_SQRT2``: value of square root of 2
- ``M_SQRT1_2``: value of square root of 1/2

In an equation, any undeclared variables are automatically declared to be
doubles in the high-performance Cython code that is generated. In addition
Expand Down
19 changes: 16 additions & 3 deletions docs/source/reference/solver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ Module solver tools
.. automodule:: pysph.solver.tools
:members:

Module simple_inlet_outlet
==========================
Module boundary conditions
===========================

.. automodule:: pysph.sph.simple_inlet_outlet
.. automodule:: pysph.sph.bc.inlet
:members:
:undoc-members:

.. automodule:: pysph.sph.bc.outlet
:members:
:undoc-members:

.. automodule:: pysph.sph.bc.inlet_outlet_manager
:members:
:undoc-members:

.. automodule:: pysph.sph.bc.simple_inlet_outlet
:members:
:undoc-members:
1 change: 0 additions & 1 deletion pysph/sph/acceleration_eval_cython.mako
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ ${indent(helper.get_post_call(group), 0)}
from libc.stdio cimport printf
from libc.math cimport *
from libc.math cimport fabs as abs
from libc.math cimport M_PI as pi
cimport numpy
import numpy
% if not helper.config.use_openmp:
Expand Down
1 change: 0 additions & 1 deletion pysph/sph/acceleration_eval_opencl.mako
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ ${helper.get_post_loop_kernel(g_idx, sg_idx, group, dest, all_eqs)}
#define NORM2(X, Y, Z) ((X)*(X) + (Y)*(Y) + (Z)*(Z))
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))

__constant double pi=M_PI;
${helper.get_header()}
#######################################################################
## Iterate over groups
Expand Down
2 changes: 2 additions & 0 deletions pysph/sph/bc/inlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


class Inlet(object):
"""Defines an inlet object.
"""
def __init__(self, inlet_pa, dest_pa, inletinfo, kernel, dim,
active_stages=[1], callback=None):
"""An API to add/delete particle when moving between inlet-fluid
Expand Down
6 changes: 0 additions & 6 deletions pysph/sph/bc/inlet_outlet_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""
Inlet Outlet Manager
"""
# Copyright (c) 2015-2017, Prabhu Ramachandran
# License: BSD

from pysph.sph.equation import Equation


Expand Down
1 change: 0 additions & 1 deletion pysph/sph/integrator_cython.mako
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ${' '*4*level}${l}
</%def>

from libc.math cimport *
from libc.math cimport M_PI as pi

from pysph.base.nnps_base cimport NNPS

Expand Down
9 changes: 6 additions & 3 deletions pysph/sph/misc/advection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
"""

from pysph.sph.equation import Equation
from numpy import cos, pi
from numpy import cos
from numpy import pi as M_PI


class Advect(Equation):
def loop(self, d_idx, d_ax, d_ay, d_u, d_v):
d_ax[d_idx] = d_u[d_idx]
d_ay[d_idx] = d_v[d_idx]


class MixingVelocityUpdate(Equation):
def __init__(self, dest, sources, T):
self.T = T
super(MixingVelocityUpdate, self).__init__(dest, sources)

def loop(self, d_idx, d_u, d_v, d_u0, d_v0, t=0.1):
d_u[d_idx] = cos(pi*t/self.T) * d_u0[d_idx]
d_v[d_idx] = -cos(pi*t/self.T) * d_v0[d_idx]
d_u[d_idx] = cos(M_PI*t/self.T) * d_u0[d_idx]
d_v[d_idx] = -cos(M_PI*t/self.T) * d_v0[d_idx]
6 changes: 3 additions & 3 deletions pysph/sph/wc/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ def gj_solve(m=[1., 0.], n=3, nb=1, result=[0.0, 0.0]):
else:
for backColr in range(rb, augCol):
backCol = rb + augCol - backColr - 1
m[nt*rb + backCol] = float(m[nt*rb + backCol]) / m[nt*rb + rb]
m[nt*rb + backCol] = m[nt*rb + backCol] / m[nt*rb + rb]
if not (rb == 0):
for kupr in range(rb):
kup = rb - kupr - 1
for kleftr in range(rb, augCol):
kleft = rb + augCol - kleftr - 1
kk = -float(m[nt*kup + rb]) / float(m[nt*rb + rb])
kk = -m[nt*kup + rb] / m[nt*rb + rb]
m[nt*kup + kleft] = (m[nt*kup + kleft] +
kk * float(m[nt*rb + kleft]))
kk * m[nt*rb + kleft])

for i in range(n):
for j in range(nb):
Expand Down

0 comments on commit ae947b3

Please sign in to comment.