# Coupling DirichletCondition of one dependent variable to the value of the second

Maybe due to my limited experience with PDEs solving I could not find the answer to the following issue. Let's say we have a simple advection along a line:

ClearAll[f1, sol]

line = NDSolveFEMToElementMesh[FullRegion[1], {{0, 500}}]

sol=NDSolveValue[
{ D[f1[x, t], t] + 10 D[f1[x, t], x] == 0
, f1[x, 0] == 95 + 20 Exp[-(x-100)^2/50^2]
, DirichletCondition[ f1[x, t] == 95  , x == 0]
}
, f1
, {t, 0, 100}, x ∈ line
]

Manipulate[ Plot[sol[x, t], {x, 0, 500}, PlotRange -> {80, 120}], {t, 0, 100}]


I want to 'connect' an identical but independent second 'return line' so that the boundary condition is the value of f1[500, t]. Let's start with connecting at one place at the moment though at the end I want to create a loop.

Probably a loop case can be solved with a dedicated setup but the point here is to learn how to connect evolution of different variable on different meshes.

Anyway, I started with just saying that f2 will travel in a opposite direction but I failed to connect its boundary condition to f1[500,t]:

ClearAll[f1, f2, sol]

sol=NDSolveValue[
{ D[f1[x, t], t] + 10 D[f1[x, t], x] == 0
, D[f2[x, t], t] - 10 D[f2[x, t], x] == 0
, f1[x, 0] == 95 + 20 Exp[-(x-100)^2/50^2]
, f2[x, 0] == 95
, DirichletCondition[f1[x,t]==95, x==0]
, DirichletCondition[f2[x,t]==f1[x,t], x==500]
}
, {f1, f2}
, {t, 0, 100}, x \[Element] line
]


NDSolveValue::fembdcc: Cross-coupling of dependent variables in DirichletCondition[f2==f1,x==500] is not supported in this version.

I am fully aware that my approach could just be wrong. Or that it is fundamentally not possible (yet). It is hard to know when one just starts exploring NDSolve capabilities, thus the question.

So can this be solved and if so, how?

## 1 Answer

If I understand you correctly you can decouple the equations and do them sequentially. Start with your first equation:

line = NDSolveFEMToElementMesh[FullRegion[1], {{0, 500}}]
sol = NDSolveValue[{D[f1[x, t], t] + 10 D[f1[x, t], x] == 0,
f1[x, 0] == 95 + 20 Exp[-(x - 100)^2/50^2],
DirichletCondition[f1[x, t] == 95, x == 0]}, f1, {t, 0, 100},
x \[Element] line]
Manipulate[
Plot[sol[x, t], {x, 0, 500}, PlotRange -> {80, 120}], {t, 0, 100}]


Now use the result as a DirichletCondition:

sol2 = NDSolveValue[{D[f2[x, t], t] - 10 D[f2[x, t], x] == 0,
f2[x, 0] == 95,
DirichletCondition[f2[x, t] == sol[x, t], x == 500]},
f2, {t, 0, 100}, x \[Element] line]
Manipulate[
Plot[sol2[x, t], {x, 0, 500}, PlotRange -> {80, 120}], {t, 0, 100}]


This equation is convection dominated and you'd need to take care of that, but that is another issue. Are you maybe looking for a wave equation?

• This unfortunately is a specific solution. It will not work when I will try to connect f1(0, t)==f2(0,t). So the case is that equations are not coupled but boundary conditions may be.
– Kuba
Sep 18, 2019 at 15:31
• I am not sure I understand 100%, why could you not use DirichletCondition[f2[x, t] == sol[x, t], x == 0] in that case? Sep 20, 2019 at 7:54
• In this case yes I could but I can't go further: the loop case is DirichletCondition[f1[x,t]==f2[x,t], x==0] , DirichletCondition[f2[x,t]==f1[x,t], x==500] so they need to be solved/iterated simultaneously. There of course is a possibility that I am confused about something.
– Kuba
Sep 20, 2019 at 8:34
• Additionally, if the velocity is replaced with a function that can be negative then I will need info about f2[500,t] to propagate f1[500,t] in a 'left' direction.
– Kuba
Sep 20, 2019 at 8:36