PINN for Laplace eq in a rectangular geometry

49 ビュー (過去 30 日間)
sepideh
sepideh 2024 年 12 月 4 日 15:11
編集済み: sepideh 2024 年 12 月 9 日 9:18
Hello Dear Community
I am trying to re-write and change this code https://it.mathworks.com/help/pde/ug/solve-poisson-equation-on-unit-disk-using-pinn.html for solving the Laplace equation in a rectangular geometry.
Everything is ok up to the "Model loss function" section where I got an error about the "size" which stating that : "Not enough input arguments"
I really do not understand what this "size" in the "for loop" refers to in this code to change it in a way that code will work correctly:
function [loss,gradients] = modelLoss(model,net,XY,pdeCoeffs)
dim = 2;
[U,~] = forward(net,XY);
% Compute gradients of U and Laplacian of U.
gradU = dlgradient(sum(U,
"all" ),XY,EnableHigherDerivatives=true);
Laplacian = 0;
for i=1:size
gradU2 = dlgradient(sum(pdeCoeffs.c.*gradU(i,:),
"all" ), ...
XY,EnableHigherDerivatives=true);
Laplacian = gradU2(i,:)+Laplacian;
end

回答 (1 件)

Abhinav Aravindan
Abhinav Aravindan 2024 年 12 月 9 日 7:14
In the "Model Loss Function" for computing gradients and the Laplacian of "U" in "Solve Poisson Equation on Unit Disk Using Physics-Informed Neural Networks" example, the "for" loop is as follows:
for i=1:dim
gradU2 = dlgradient(sum(pdeCoeffs.c.*gradU(i,:),"all"), ...
XY,EnableHigherDerivatives=true);
Laplacian = gradU2(i,:)+Laplacian;
end
It appears that "dim" has been replaced with "size" in your code. The "size" function in MATLAB is used to determine the dimensions of an array and requires input arguments. Since, there are no input arguments give to “size”, this results in an error. You may refer to the below documentation for more detail:
I assume you intended to use "size" as a variable name. However, it is not recommended to use the names of MATLAB functions as variable names, as this can lead to "overshadowing".
Please refer to the below links for more information on “overshadowing”:
  1 件のコメント
sepideh
sepideh 2024 年 12 月 9 日 9:18
編集済み: sepideh 2024 年 12 月 9 日 9:18
Thank you very much.
I did not change the code,
I put it here as is in the link I attached
in the website , they wrote like this. when I run the original code (with size in the for loop) it works.
but when I use the same structure and I only change the geometry and equation, MATLAB gives me an error based on this "size" in the for loop.
So I was wondering what does it represent in the code

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by