Skip to content

Commit

Permalink
Merge pull request open-atmos#489 from slayoo/koehler_refactor
Browse files Browse the repository at this point in the history
formulae refactors
  • Loading branch information
slayoo authored May 8, 2021
2 parents 9a1f616 + cd275e8 commit f3e02ab
Show file tree
Hide file tree
Showing 174 changed files with 3,562 additions and 1,871 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/julia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PySDM-readme.jl

defaults:
run:
shell: bash

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 13 * * 4'

jobs:
julia:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- run: pip install -e .
- run: pip install exdown pytest
- run: python -c "import exdown; code=exdown.extract('README.md'); f=open('readme.jl', 'w'); f.writelines(block.code for block in code if block.syntax=='Julia'); f.close()"
- uses: julia-actions/setup-julia@v1
- run: julia readme.jl
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Status
name: PySDM

defaults:
run:
Expand Down Expand Up @@ -32,9 +32,14 @@ jobs:
- run: |
python -We -c "import PySDM"
# note: this installs PySDM-examples including its dependencies which inclde PySDM itself...
- run: |
pip install -r requirements.txt
# note: ... hence reverting to the currently tested version
- run: |
pip install -e .
# TODO #184 (https://github.com/numba/numba/issues/6350#issuecomment-728174860)
- if: matrix.platform == 'ubuntu-latest'
env:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PySDM-readme.m

defaults:
run:
shell: bash

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 13 * * 4'

jobs:
matlab:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
- run: pip install -e .
- run: pip install exdown pytest
- run: python -c "import exdown; code=exdown.extract('README.md'); f=open('readme.m', 'w'); f.writelines(block.code for block in code if block.syntax=='Matlab'); f.close()"
- uses: matlab-actions/setup-matlab@v0
- uses: matlab-actions/run-command@v0
with:
command: readme
24 changes: 24 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PySDM-readme.py

defaults:
run:
shell: bash

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: '0 13 * * 4'

jobs:
python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- run: pip install -e .
- run: pip install exdown pytest
- run: python -c "import exdown; code=exdown.extract('README.md'); f=open('readme.py', 'w'); f.writelines(block.code for block in code if block.syntax=='Python'); f.close()"
- run: python readme.py
2 changes: 1 addition & 1 deletion PySDM/attributes/chemistry/pH.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PySDM.attributes.impl.intensive_attribute import DerivedAttribute
from PySDM.dynamics.aqueous_chemistry.support import AQUEOUS_COMPOUNDS
from PySDM.physics.aqueous_chemistry.support import AQUEOUS_COMPOUNDS


class pH(DerivedAttribute):
Expand Down
1 change: 1 addition & 0 deletions PySDM/attributes/impl/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, builder, name, dtype=float, size=0):
self.dtype = dtype
self.size = size
self.name = name
self.formulae = self.core.formulae

def allocate(self, idx):
if self.size >= 1:
Expand Down
4 changes: 2 additions & 2 deletions PySDM/attributes/impl/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from PySDM.attributes.physics.dry_volume import DryVolume
from PySDM.attributes.physics.radius import Radius
from PySDM.attributes.physics.dry_radius import DryRadius
from PySDM.attributes.physics.terminal_velocity.terminal_velocity import TerminalVelocity
from PySDM.attributes.physics.terminal_velocity import TerminalVelocity
from PySDM.attributes.numerics.cell_id import CellID
from PySDM.attributes.numerics.cell_origin import CellOrigin
from PySDM.attributes.numerics.position_in_cell import PositionInCell
Expand All @@ -17,7 +17,7 @@
from PySDM.attributes.chemistry.mole_amount import MoleAmount
from PySDM.attributes.chemistry.concentration import Concentration
from PySDM.attributes.chemistry.pH import pH
from PySDM.dynamics.aqueous_chemistry.support import AQUEOUS_COMPOUNDS
from PySDM.physics.aqueous_chemistry.support import AQUEOUS_COMPOUNDS

attributes = {
'n': Multiplicities,
Expand Down
19 changes: 14 additions & 5 deletions PySDM/attributes/physics/critical_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
"""

from PySDM.attributes.impl.derived_attribute import DerivedAttribute
from PySDM.physics import formulae as phys
from PySDM.physics import constants as const
import numpy as np


class CriticalVolume(DerivedAttribute):
def __init__(self, builder):
self.cell_id = builder.get_attribute('cell id')
self.r_dry = builder.get_attribute('dry radius')
self.v_dry = builder.get_attribute('dry volume')
self.v_wet = builder.get_attribute('volume')
self.environment = builder.core.environment
self.particles = builder.core
dependencies = [self.r_dry, self.cell_id]
dependencies = [self.v_dry, self.v_wet, self.cell_id]
super().__init__(builder, name='critical volume', dependencies=dependencies)

def recalculate(self):
kappa = self.particles.dynamics['Condensation'].kappa
r_d = self.r_dry.get().data
v_dry = self.v_dry.get().data
v_wet = self.v_wet.get().data
T = self.environment['T'].data
cell = self.cell_id.get().data
for i in range(len(self.data)): # TODO #347 move to backend
self.data.data[i] = phys.volume(phys.r_cr(kp=kappa, rd=r_d[i], T=T[cell[i]]))
sigma = self.formulae.surface_tension.sigma(T[cell[i]], v_wet[i], v_dry[i])
self.data.data[i] = self.formulae.trivia.volume(self.formulae.hygroscopicity.r_cr(
kp=kappa,
rd3=v_dry[i] / const.pi_4_3,
T=T[cell[i]],
sgm=sigma
))
4 changes: 2 additions & 2 deletions PySDM/attributes/physics/dry_radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from PySDM.attributes.impl.derived_attribute import DerivedAttribute
from PySDM.physics.formulae import volume
from PySDM.physics import constants as const


class DryRadius(DerivedAttribute):
Expand All @@ -14,5 +14,5 @@ def __init__(self, builder):

def recalculate(self):
self.data.idx = self.volume_dry.data.idx
self.data.product(self.volume_dry.get(), 1/volume(1))
self.data.product(self.volume_dry.get(), 1/const.pi_4_3)
self.data **= 1/3
4 changes: 2 additions & 2 deletions PySDM/attributes/physics/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from PySDM.attributes.impl.derived_attribute import DerivedAttribute
from PySDM.physics.formulae import volume
from PySDM.physics import constants as const


class Radius(DerivedAttribute):
Expand All @@ -17,5 +17,5 @@ def __init__(self, builder):

def recalculate(self):
self.data.idx = self.volume.data.idx
self.data.product(self.volume.get(), 1/volume(1))
self.data.product(self.volume.get(), 1/const.pi_4_3)
self.data **= 1/3
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from PySDM.attributes.impl.derived_attribute import DerivedAttribute
from .gunn_and_kinzer import Interpolation
from PySDM.physics.terminal_velocity.gunn_and_kinzer import Interpolation


class TerminalVelocity(DerivedAttribute):
Expand Down
3 changes: 0 additions & 3 deletions PySDM/attributes/physics/terminal_velocity/__init__.py

This file was deleted.

5 changes: 2 additions & 3 deletions PySDM/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def cuda_is_available():
if cuda_is_available() or cuda.is_available():
from .thrustRTC.thrustRTC import ThrustRTC
else:
from .thrustRTC.fakeThrustRTC import _flag
from .thrustRTC.test_helpers import _flag

_flag.fakeThrustRTC = True

Expand All @@ -49,9 +49,8 @@ def cuda_is_available():
ThrustRTC.ENABLE = False

class Random:
def __init__(self, size, seed=None):
def __init__(self, size, seed):
self.size = size
seed = seed or np.random.randint(0, 2 * 16)
self.generator = np.random.default_rng(seed)

def __call__(self, storage):
Expand Down
152 changes: 0 additions & 152 deletions PySDM/backends/numba/bdf.py

This file was deleted.

Loading

0 comments on commit f3e02ab

Please sign in to comment.