Determine locations struct used in PDE solver

5 ビュー (過去 30 日間)
Roberto Brenes
Roberto Brenes 2019 年 8 月 28 日
編集済み: Ravi Kumar 2019 年 8 月 29 日
Hi,
I'm trying to solve a 2D PDE where the 'c' coefficient is a function of the (x,y) coordinate. In order to specify this coefficient, I'm trying to create a matrix that is of length N by M where N are the number of x points and M the number of y points used to solve the PDE. I can then pass this matrix to the PDE solver by calling a function that returns the value of the coefficient at (x,y).
Unfortunately I need to populate the matrix outside of the function call, since I am using the PDE solver to fit for some data so I need to be able to modify it in between function calls. Therefore, I need to know how many points I need to fit for.
I noticed I cannot access the locations struct before calling solvepde and that the number of (x,y) points is larger than the number of nodes in my mesh, so I can't form the matrix needed or find the value for the (x,y) pair for the C coefficient. Is it somehow possible to pre-compute the coordinates and number of points that will be used in the PDE solver?
Thanks in advance!

採用された回答

Ravi Kumar
Ravi Kumar 2019 年 8 月 28 日
You can write that code that you indented to use to "create a matrix that is of length N by M where ..." in the function itself. These points are Gauss point coordinates, you don't need to know them in advance, your funcion should use them to create the value of c at those points.
  5 件のコメント
Ravi Kumar
Ravi Kumar 2019 年 8 月 29 日
編集済み: Ravi Kumar 2019 年 8 月 29 日
Thanks for the additional info.
The sample code indicates that you are solving a single PDE in 2-D domain. You are trying to find 'c' as a matrix in a pre-defined 2-D space (the geometric domain). That is, your final outcome would be a matrix of c at known x and y locations. If this is your goal, then the following approach might work for you.
For simplicity, lets say you are working with a unit square domain with original as one of its corner. Define in initial c value with, independent of PDE solvers call location. Say you have grid of 0.1, that is xg = 0:0.1:1, yg = 0:0.1:1, the define c0 as:
c0 = 5*ones(numel(xg));
The optimizer, fminsearch, calls simulatePDE with an updated cmat in each iteration, use this cmat and the KNOWN (xg,yg) to construct a gridded interpolant:
[xg,yg] = ndgrid(0:0.1:1);
cInterpolant = griddedInterpolant(xg,yg,cmat);
Then construct the c-coefficient function handle to interpolate and find the values of c at the points requested by solver (location.x,location.y):
c = @(locations,~) cInterpolant(location.x,location.y)
This should set up the problem the way you want.
Note 1: If your domain is not suitable to gridded data, then you can use the scatteredInterpolant.
Note 2: The way you have set the optimization problem might not be ideal, you have as many parameters as elements in cmat. I think a better option would be to define a function with undermined coefficient and optimize to determine the coefficient.
Regards,
Ravi
Roberto Brenes
Roberto Brenes 2019 年 8 月 29 日
Thanks so much for your reply! This makes sense and it should work for my problem. I wanted to determine whether 'c' varies spatially for my data, which is why I planned on having a coefficient for each location. I'll play around with the optimization to see whether this is feasible or to follow your tip.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBoundary Conditions についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by