-
Notifications
You must be signed in to change notification settings - Fork 17
Cavity flow PINNs example #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
physics-informed-neural-networks-for-steady-cavity-flow/README.md
Outdated
Show resolved
Hide resolved
physics-informed-neural-networks-for-steady-cavity-flow/README.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Conor, thank you for putting this together!
My biggest suggestion is to add more description/explanation of what is happening in the architecture setup. The rest are smaller comments for your consideration.
|
||
% Add anchor functions to strictly enforce boundary conditions on the | ||
% streamfunction. | ||
net = addLayers(net, [functionLayer(@(x)4.*x.*(1-x), Name="anchorX", Acceleratable=true); multiplicationLayer(3, Name="psi")]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here, I think this needs some more explanation. This function is chosen to satisfy the boundary conditions? Can you give a short description about what the multiplicationLayer and connectLayers do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'll add some more explanation here. The main idea is to ensure that the boundary conditions for psi
are always satisfied.
|
||
% Compute gradients. | ||
psisum = sum(psi,1); | ||
u = dlgradient(psisum, yeq, EnableHigherDerivatives=true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use dljacobian?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it would mean you'd need at least R2024b. Otherwise I expect it should be ok - it'll do the sum(psi,1)
line and the EnableHigherDerivatives=true
by default, at the expense of the extra dimension argument dljacobian(psi,yeq,2)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think dljacobian
is cleaner here -- I'll switch to that.
physics-informed-neural-networks-for-steady-cavity-flow/images/figure_0.png
Outdated
Show resolved
Hide resolved
physics-informed-neural-networks-for-steady-cavity-flow/README.md
Outdated
Show resolved
Hide resolved
physics-informed-neural-networks-for-steady-cavity-flow/README.md
Outdated
Show resolved
Hide resolved
u = dlgradient(psisum, y); | ||
v = -1.*dlgradient(psisum, x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be worth making this one dlgradient
call, something like
[u,v] = dlgradient(psisum,y,x);
v = -v;
I had some feeling this was faster, although I'm not completely confident. I'm sure I found it faster when I did something like batching the interior points and boundary points together and performing one dlgradient
, then splitting the output back into interior and boundary gradients. There could be a few places to try that out in the loss above.
Or maybe it was the forward pass, so something like:
allx = cat(1, xeq, xyBoundary(:,1));
ally = cat(1,yeq,xyBoundary(:,2));
psi = forward(net,allx,ally);
psibd = psi(size(xeq,1)+1:end,:);
psi = psi(1:size(xeq,1), :);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting -- I like both of these ideas. I think it is best practice to mimimize the number of network executions where possible, though it comes at the expense of readability.
I'll toy around with this, but I'd like to make the loss function nice and easy to read.
Thanks Mae! |
|
||
|
||
In order to automatically satisfy the continuity equation we use the stream function psi such that `u=psi_y` and `v=-psi_x`. The boundary conditions are `(u,v)=(1,0)` and the top boundary and `(u,v)=(0,0)` at the other boundaries. The Reynolds number `Re=100`. | ||
In order to automatically satisfy the continuity equation we use the stream function $\psi$, such that $u=\partial \psi /\partial y$ and $v=-\partial \psi /\partial x$. The boundary conditions are $(u,v)=(1,0)$ at the top boundary and $(u,v)=(0,0)$ at the other boundaries. Additionally, $\psi =0$ is assumed on all the boundaries. The Reynolds number is $Re=100$. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should say something like "the domain is
psum = sum(p,1); | ||
px = dlgradient(psum, xeq, EnableHigherDerivatives=true); | ||
py = dlgradient(psum, yeq, EnableHigherDerivatives=true); | ||
u = dljacobian(psi', yeq, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If psi
and yeq
are both "batch x features" I think u = dljacobian(psi, yeq, 2)
would work here. But then u
is "hidden x batch x features" where hidden==size(psi,2)
, and since you end up wanting more derivatives along that "hidden" dimension, I guess you have to permute or swap to dljacobian(u,xeq,1)
anyway. I think having stuff as "features x batch" works out more nicely for me typically, which means replacing featureInputLayer
with inputLayer
if you want to use unlabelled dlarray
.
No description provided.