import buckinghampy
from buckinghampy.parameters import *

"""
Explanation: To begin, we import the package, buckinghampy.
I know, the name is terrible.
There is also a submodule of buckinghampy which as a lot of commonly used parameters, though nothing stops you from defining your own parameters.
Finally, we import some IPython display functions which will help with rendering the results.
End of explanation
"""


parameters = [density, length, velocity, viscosity]
nondimensional_numbers = buckinghampy.find_nondimensional_numbers(parameters)

"""
Explanation: As a first application, we would like to find the nondimnensionalization of the basic Navier-Stokes equation:
\begin{equation}
\frac{\partial {\bf u}}{\partial t} + {\bf u} \cdot \nabla {\bf u} = - \nabla P + \eta \nabla^2 {\bf u}
\end{equation}
Here the fluid has density $\rho$, viscosity $\eta$, and we imagine that it is being driven by some velocity $u$ over some lengthscale $L$.
This is a total of four paramters, which we can put into a list and give to buckinghampy:
End of explanation
"""


nondimensional_numbers

"""
Explanation: The function buckinghampy.find_nondimensional_numbers() takes a list of parameters and returns an appropriate set of nondimensional numbers for those parameters.  These numbers are returned as strings which can be output to LaTeX in IPython:
End of explanation
"""


parameters = [boltzmann,temperature, planck, speed_of_light, frequency]
nondimensional_numbers = buckinghampy.find_nondimensional_numbers(parameters)

nondimensional_numbers

"""
Explanation: You may recognize this as the the inverse of the Reynolds number. This brings us to an important point: in general, the nondimensionalization of a set of parameters is nonunique. There are some groupings which are conventional, but buckinghampy might not find those. For problems with more than one nondimensional number, the problem becomes harder: not only are inverses and powers of nondimensional numbers allowed, but so are any multiplicative combinations of the different numbers.
We can look at another example from radiative physics. Consider the blackbody radiation spectrum of an object. We expect this problem to depend on the light frequency, the speed of light, Planck's constant, the Boltzmann constant, and the temperature:
End of explanation
"""


buoyancy_parameter = Parameter( '\\rho_0 \\alpha g', {'kg' :  1,\
                                                      'm'  : -2,\
                                                      's'  : -2,\
                                                      'K'  : -1})
delta_T = Parameter( '\\Delta T', {'K' : 1})

"""
Explanation: The nondimensionalization recovers the argument of the exponential in a Boltzmann distribution.
As an example of a more complicated system, consider the equations for Rayleigh-Bernard convection in a Boussinesq fluid:
\begin{equation}
-\nabla P + \eta \nabla^2 {\bf u} + \delta \rho {\bf g} = 0
\end{equation}
\begin{equation}
\nabla \cdot {\bf u} = 0
\end{equation}
\begin{equation}
\frac{\partial T}{\partial t} + {\bf u} \cdot \nabla T = \kappa \nabla^2 T
\end{equation}
where $T$ is temperature, $\kappa$ is the thermal diffusivity, $g$ is gravity, $\delta \rho = -\rho_0 \alpha T$ is the density variations driving buoyancy, $L$ is the layer depth, and $\Delta T$ is the temperature drop across the convecting layer.
An accounting of the paramters in the set of equations finds $\Delta T$, $\rho_0$, $g$, $\alpha$, $\kappa$, $\eta$, and $L$.  However in the governing equations $\rho_0$, $g$, and $\alpha$ only appear when multiplied together, so they should really only count for one parameter, which we will define as the "buoyancy parameter."
Using the Parameter class in buckinghampy.parameters we can define new paramters for $\Delta T$ and the buoyancy paramter (which are not predefined in the module)
End of explanation
"""


parameters = [buoyancy_parameter, delta_T, length, thermal_diffusivity, viscosity]
nondimensional_numbers = buckinghampy.find_nondimensional_numbers(parameters)

nondimensional_numbers

"""
Explanation: We can now create a paramters object for this system and find the nondimensional numbers:
End of explanation
"""


parameters = [thermal_expansivity, gravity, density, delta_T, length, thermal_diffusivity, viscosity]
nondimensional_numbers = buckinghampy.find_nondimensional_numbers(parameters)

nondimensional_numbers

"""
Explanation: Hey, would you look at that, it's one over the Rayleigh number! As a side note, if we had not combined some parameters into the buoyancy parameter, we would have gotten some extra nondimensional numbers:
End of explanation
"""


