Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

how to write a linear combination of operators? #275

@JianghuiDu

Description

@JianghuiDu
L = 50.0 # domain in depth cm
N = 5000 # number of grid cells, all species are defined at the center of the cells,
h = L/(N+1) # spatial steps
x = range(h, step=h, length=N)

u=0.25
D=0.0

Pe=u.*h/(D);
σ=1.0./tanh.(Pe).- 1.0./Pe;

Δ1 = CenteredDifference(1, 2,h, N);
Δ_up = UpwindDifference(1, 1,h, N,1.0); #forward 
Δ_down = UpwindDifference(1, 1,h, N,-1.0); #backward

bcAge = RobinBC((u,-D,0.0),(0.0,1.0,4.0),h,1);

I want a weighted average of centered and backward differences based on σ. This new operator should equal the centered difference when σ=0 and backward difference when σ=1
This works

#σ=1
Age = exp.(x)
# should equal backward difference
Δ1*bcAge*Age + -σ/2.0*(Δ_up*bcAge*Age) + -σ/2.0*(Δ_down*bcAge*Age)

but not

# I thought this would be the same as above
Δ1*bcAge*Age .+ -σ/2.0*Δ_up*bcAge*Age .+ -σ/2.0*Δ_down*bcAge*Age

Why do the brackets matter?
I thought I could write in a format like this

Δ=Δ1 + -σ/2.0*Δ_up+ -σ/2.0*Δ_down

and do Δ*bcAge*Age but that doesn't work.

I also noticed that sometimes . is needed before "+/- etc. but other times not...
What are the format required to do DiffEqOperatorCombination and DiffEqScaledOperator?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions