Closed glwagner closed 5 years ago
I think that particular softmax function can still go negative except for large values of a/b. An alternative is softmax(x, b) = b * np.log(1 + np.exp(x/b))
, but this can have numerical issues for x/w > a few hundred.
Hm!
We could make softmax a kwarg that the user may change if they desire?
w=b
in what you've written, right?
An alternative way of writing your function is
softmax(x, a) = x + a*np.log(1 + np.exp(-x/a))
would that have fewer issues for large x/a
?
Yeah sorry, w=b (fixed). Sure we could make it an option. The issue is the exponential can underflow or overflow if abs(x/a) is out of the exponent range of doubles.
Here we go: softmax(x, a) = a * np.logaddexp(0, x/a)
.
Nice find!
If you think that's better than x + a*np.log(1 + np.exp(-x/a))
, I'm good with it.
It seems that the parameter a
should be a "small" fraction of the molecular viscosity or diffusivity: the error at x=0
is 0.7a, which is a sizeable fraction of a? So with a=nu/100
, you'll incurr an effective error in your molecular diffusivity of 0.7% everywhere; perhaps acceptable. Or do we think that creates too-sharp a cut-off? The more turbulent the flow, the larger value of a
you can accommodate.
Closed by #23.
We need a
softmax
:This may help address some of the problems discussed in #20.
@kburns and I talked about this a while ago and we did not settle on a solution, though I cannot remember why.
I propose that we add parameters either to each closure individually or to
EddyViscosityClosure
, perhaps calledν_soft
andκ_soft
(better names welcome). We could then write (either inadd_substitutions_subgrid_stress
inEddyViscosityClosure
or inadd_substitutions
in each closure individually):(And similarly for
κ_sgs
.)As written above,
a
insoftmax
is a displacement andb
is a width. The appropriate relative values ofa
andb
can be debated --- perhaps a more conservative choice isa=2*b
? We can also add two parameters for thesoftmax
to__init__
; maybe with a sensible default. That'd give users full flexibility.We should also change
zero_max
tohardmax
in AMD?A good value for
ν_soft
is probably the molecularν
, or perhaps2*ν
.