Determine locations struct used in PDE solver
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Roberto Brenes
am 28 Aug. 2019
Bearbeitet: Ravi Kumar
am 29 Aug. 2019
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!
0 Kommentare
Akzeptierte Antwort
Ravi Kumar
am 28 Aug. 2019
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 Kommentare
Ravi Kumar
am 29 Aug. 2019
Bearbeitet: Ravi Kumar
am 29 Aug. 2019
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 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Boundary Conditions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!