boundary conditions and solvepde

2 次查看(过去 30 天)
Hello again and hope someone can guide me.
I have different edges of a plate, and those edges have different boundary conditions depending on the time (i extrapolate the values)
I have this code:
in=0;
tim=[ts(5) ts(10) ts(15)];
for t = 1:numel(tim)
currentTime = tim(t);
for k = 1:numel(perimeter)
edge = perimeter(k);
in=in+1;
applyBoundaryCondition(model,"dirichlet","Edge",edge,"u",1,"EquationIndex",1);
%applyBoundaryCondition(modelTwoDomain,"mixed","Edge",[edge,edge],"u",bcfunc,"EquationIndex",2,"q",[0 0],"g",0);
end
in=0;
end
When I debug I can see the the boundry values are store correctly in modeltwodomain (name of my model).boundaryconditions.
The problem appears when I go to solve the system:
res=solvepde(modelTwoDomain,tim);
% Access the solution at the nodal locations
sol=res.NodalSolution;
and I check the value of sol(65,1,1); 65 being a node in my first edge. It should give me the value I extrapolated with the first time value, but seems just to keep the third value.
Is there anyway that I can somehow store the n different values for the n time instances when I solve the pde system?
Hope someone read me and can help. I would really appreciate any guidance.

采纳的回答

Mrutyunjaya Hiremath
Based on your description, it seems like the issue is with how you are applying and updating the boundary conditions for different time instances. The 'applyBoundaryCondition' function applies boundary conditions to the model you provided (modelTwoDomain) and overwrites the existing boundary conditions each time you call it within the loop. As a result, only the boundary conditions corresponding to the last time instance (tim(t)) are active when you call 'solvepde'.
  • To apply different boundary conditions for different time instances and solve the PDE system with those conditions, you can follow these steps:
  1. Create a new PDE model for each time instance with the appropriate boundary conditions using 'createpde' and 'applyBoundaryCondition'.
  2. Solve the PDE system for each model using solvepde separately.
  3. Store the solutions for each time instance separately.
  • Here's an outline of how you can modify your code to achieve this:
tim = [ts(5) ts(10) ts(15)];
numTimeInstances = numel(tim);
% Create an empty array to store the solutions for each time instance
solutions = cell(numTimeInstances, 1);
% Loop through each time instance
for t = 1:numTimeInstances
currentTime = tim(t);
% Create a new PDE model for each time instance
modelTwoDomain = createpde();
% Apply the appropriate boundary conditions for this time instance
for k = 1:numel(perimeter)
edge = perimeter(k);
applyBoundaryCondition(modelTwoDomain, "dirichlet", "Edge", edge, "u", 1, "EquationIndex", 1);
end
% Solve the PDE system for this time instance
res = solvepde(modelTwoDomain, currentTime);
% Store the solution in the solutions array
solutions{t} = res.NodalSolution;
end
% Now you have the solutions for each time instance stored in the 'solutions' cell array.
% You can access the solution at a specific node and time instance like this:
nodeIndex = 65; % Replace with the index of the desired node
timeInstance = 1; % Replace with the desired time instance (1, 2, or 3 in your case)
value = solutions{timeInstance}(nodeIndex, 1); % Access the solution at the given node and time instance
  • By following these steps, you should be able to store and access the solutions for each time instance separately. The solutions cell array will contain the nodal solutions for each time instance, and you can access the values at specific nodes and time instances as needed.

更多回答(0 个)

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by