Skip to content
This repository has been archived by the owner on Aug 12, 2021. It is now read-only.

Commit

Permalink
numpy->generic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mzszym committed Mar 23, 2019
1 parent 94f8756 commit 08288c4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions oedes/fvm/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def _getIdx(self):
def _getOtherIdx(self):
return _boundaryIdx(self.other_eq, self.other_boundary)

def loadSolutionValue(self, state):
return state[self._getIdx()]

def init(self, builder):
if self.other_eq_lookup is None:
self.other_eq = None
Expand Down
8 changes: 4 additions & 4 deletions oedes/models/equations/boltzmann.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

__all__ = ['BoltzmannDOS']

from oedes.ad import where, nvalue
from oedes.ad import where, nvalue, exp, log
import logging
import numpy as np
from oedes import logs
from .dos import DOS
import numpy as np


class BoltzmannDOS(DOS):
Expand All @@ -45,7 +45,7 @@ def Ef(self, ctx, eq):
(eq.prefix, self.c_eps, np.amin(
nvalue(c_raw))))
N0 = self.N0(ctx, eq)
return ctx.varsOf(eq.thermal)['Vt'] * np.log(c / N0)
return ctx.varsOf(eq.thermal)['Vt'] * log(c / N0)

def Ef_correction(self, ctx, eq):
return 0.
Expand Down Expand Up @@ -76,7 +76,7 @@ def c(self, ctx, eq, Ef, numeric_parameters=False):
'c(%r): clipping Ef/kT>0, max(Ef/kT)=%r' %
(eq.prefix, np.amax(
nvalue(v_raw))))
c = np.exp(v) * N0
c = exp(v) * N0
return c

def D_mu(self, parent_eq, ctx, eq):
Expand Down
2 changes: 1 addition & 1 deletion oedes/models/equations/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def evaluate(self, ctx, eq):
if ctx.solver.poissonOnly and not isinstance(
self.owner_eq, PoissonEquation):
return
yield eq._getDof(), ctx.varsOf(eq.owner_eq)['x'][eq._getIdx()] - self.value(ctx, eq)
yield eq._getDof(), eq.loadSolutionValue(ctx.varsOf(eq.owner_eq)['x']) - self.value(ctx, eq)

def value(self, ctx, eq):
raise NotImplementedError()
Expand Down
4 changes: 2 additions & 2 deletions oedes/models/equations/conserved.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def load(self, ctx, eq):
def calculate_fluxes(self, ctx, eq, v, D):
c = ctx.varsOf(eq)['c']
if not ctx.wants_output:
return eq.faceflux(c=c, v=v, D=D, full_output=False)
f = eq.faceflux(c=c, v=v, D=D, full_output=True)
return eq.faceflux(c, v, D, full_output=False)
f = eq.faceflux(c, v, D, full_output=True)
ctx.outputFace([eq, 'j'], f['flux'], unit=ctx.units.flux)
ctx.outputFace([eq, 'jdrift'], f['flux_v'],
unit=ctx.units.flux)
Expand Down
4 changes: 2 additions & 2 deletions oedes/utils/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def build(self, builder, args):

def load(self, ctx, eq):
vars = ctx.newVars(eq)
vars['x'] = ctx.gvars['x'][eq.idx]
vars['xt'] = ctx.gvars['xt'][eq.idx]
vars['x'] = ctx.loadForEquation(eq, ctx.gvars['x'])
vars['xt'] = ctx.loadForEquation(eq, ctx.gvars['xt'])

def evaluate(self, ctx, eq):
pass
Expand Down
3 changes: 3 additions & 0 deletions oedes/utils/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def newVars(self, obj, varobj=None):
self._vardict[k] = varobj
return varobj

def loadForEquation(self, equation, variable):
return variable[equation.idx]

def varsOf(self, obj):
assert not isinstance(obj, Computation)
return self._vardict[id(obj)]
Expand Down

0 comments on commit 08288c4

Please sign in to comment.