Retrieving indices of times for a time-dependent system of PDEs within applyBoundaryCondition()

1 view (last 30 days)
I am using the Partial Differential tool box to resolve a time dependent system of N=3 equations. I am using the following code (please suggest improvements when needed, or corrections)
applyBoundaryCondition(model, 'EquationIndex', 2, 'Edge', 3, 'q', 0, 'g', @gBc_coeffunc_Cf);
.....where
function gBc = gBc_coeffunc_Cf(region,state)
% N-by-M matrix, where each column corresponds to one evaluation point,
% and M is the number of evaluation points.
nr = length(region.x);
gBc = zeros(N_EQ,nr);
st = state.time;
if (not(isnan(st)))
for r = 1:nr
gBc(1,r) = 5 * Cf_Nz(r, ??)
end
end
end
... where I have previously obtained Cf_Nz from a solution given by a previous, different system of PDE´s, of also N=3.
Nodes_at_edge_bottom = findNodes(mesh, 'region', 'Edge', 3);
Cf_Nz = squeeze(solution.NodalSolution(Nodes_at_edge_bottom, EQ_Cf, :));
I expect this Cf_Nz to be a matrix which colums are indexed by the iT (which contains the indices of times ' for a time-dependent problem, as mentioned here:
...and use this matrix values to be retrieved from the ?? above. (I know that state.time contains the time at evaluation points. state.time is a scalar, that might be used here somehow, but I do not need the time, but the indices of times). Which should be the function ?? that should be used ?
Also, as a different but somehow related question, region.subdomain() can not be used within gBc_coeffunc_Cf() ? Thank you

Answers (2)

Ravi Kumar
Ravi Kumar on 15 May 2019
You need to create an interpolant object, see for example, griddedInterpolant. Construct interpolant (may be one for each N), and then query it with the time value passed in state.time.
Yes you can use region.subdomain in your funciton.
Regards,
Ravi
  1 Comment
Miguel Angel Arnedo
Miguel Angel Arnedo on 16 May 2019
Edited: Miguel Angel Arnedo on 16 May 2019
Thank you Ravi, very kind !
In order to implement your solution, I have first logged the returned values of st by removing the ";" in my code, in the line
st = state.time
and the only two different values that is displaying are st =NaN, and the extrange value st = 2.2204e-16
What is wrong ? I was expecting st to return many different values, in between the range that I have defined with linspace, and also being multiples of 0.05
M = round(120 / 0.05 ) +1;
t = linspace(0,120,M);
...
solution = solvepde(model,t)
for nn = 1:M
time_curr = num2str(solution.SolutionTimes(nn)) % This correctly returns 0, 0.05, ...
end
Also, when adding subdomain within that function, the error below appears. I am using the same syntax, without error, in other functions that refer to PDE coefficients a,d ... however this function refers to the g parameter. Any suggestions ?
function gBc = gBc_coeffunc_Cf(region,state)
...
rsd = region.subdomain(1)
end
error ---> Reference to non-existent field 'subdomain'.

Sign in to comment.


Miguel Angel Arnedo
Miguel Angel Arnedo on 18 May 2019
Edited: Miguel Angel Arnedo on 18 May 2019
I resolved it.
...
if (isnan(st)
gBc(1,:) = NaN(nr);
else
...
end

Community Treasure Hunt

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

Start Hunting!