Use PDE toolbox to model 2-D diffusion-reaction of solutes released from surface of a cylinder

5 views (last 30 days)
Dear colleagues:
I would like to use matlab pde toolbox to model a 2-d diffusion-reaction system, with two reacting solutes (c1 and c2) released from the surface of a cylinder in the middle of the 2-d domain. The 2-d domain is 5 x 5, and the radius of the cylinder is 1. Solute c1 is consumed via a first-order reaction as it diffuses away from the cylinder surface; c2 is produced via the first-order consumption of c1. Both c1 and c2 have a fixed concentration boundary condition at the surface of the cylinder, and a zero-gradient far-field boundary condition.
I entered this system into the AI Chat Playground, which produced the code contained in the attached script file. Unfortunately this code produced the error message listed immediately below. I put this error message into the chat, and it produced some proposed fixes, but they all resulted in the same error message listed below. I realize this could be a pretty big ask, but might someone with expertise in the pde toolbox be able to diagnose what's happening here?
Many thanks, Eric
PS - I would eventually like to add mutiple cylinders to this simulation, with the goal of depicting how release of oxygen (nominally solute c1 in the system described here) from of aquatic plant roots (depicted here a the cylinders) growing in otherwise oxygen-free sediment might be expected to influence sediment chemistry.
Error using pde.AnalyticGeometry
Decomposed geometry matrix must have at least 7 rows.
Error in pde.EquationModel/geometryFromEdges (line 48)
gm = pde.AnalyticGeometry(gedges);
Error in cylinder_diffusion_reaction_2d_matlab (line 6)
geometryFromEdges(model, cylinder);
% Define the geometry
model = createpde(2); % Create a PDE model with 2 equations
R = 1; % Radius of the cylinder
cylinder = [2; 1; 0; 0; R; 0; 0; R; 0; 0; R; 0; R; R; R; R]; % Cylinder geometry
geometryFromEdges(model, cylinder);
Error using pde.AnalyticGeometry (line 92)
Decomposed geometry matrix must have at least 7 rows.

Error in pde.EquationModel/geometryFromEdges (line 48)
gm = pde.AnalyticGeometry(gedges);
% Define the coefficients for the PDEs
d1 = 1; % Diffusion coefficient for c1
d2 = 1; % Diffusion coefficient for c2
k1 = 0.1; % Reaction rate for c1 consumption
k2 = 0.1; % Reaction rate for c2 production
% Specify the PDE equations
specifyCoefficients(model, 'm', 0, 'd', [d1; d2], 'c', [0; 0], 'a', [k1; -k2], 'f', [0; 0]);
% Set boundary conditions
applyBoundaryCondition(model, 'dirichlet', 'Edge', 1:4, 'u', [1; 0]); % Fixed concentration at the cylinder surface
applyBoundaryCondition(model, 'neumann', 'Edge', 5:8, 'g', 0); % Zero-gradient far-field condition
% Generate the mesh
generateMesh(model, 'Hmax', 0.2);
% Solve the PDE
results = solvepde(model);
% Extract the solution
c1 = results.NodalSolution(1, :); % Concentration of c1
c2 = results.NodalSolution(2, :); % Concentration of c2
% Plot the results
figure;
pdeplot(model, 'XYData', c1, 'ZData', c2, 'Mesh', 'on');
title('Concentration of c1 and c2');
xlabel('X-axis');
ylabel('Y-axis');
colorbar;
  2 Comments
Eric Roden
Eric Roden on 23 Nov 2024
Dear Torsten:
No doubt that's a good idea, and I guess I could get access to a CAD program in due course. But in the meantime, I was hoping to get something simple to execute in the PDE toolbox so that I can see how it works, and also compare the results to those that I have generated using the 1-D PDE function pdepe, which due to the symmetry of the cylindrical coordinates can be used to depict a 2-D cross-section. I'm sure that the PDE toolbox will work, but figure it would be a reasonable thing to do so compare the actual 2-D solution to the 1-D projection, and along the way learn something about how the toolbox functions. I would of course be very gratefu if you (or anyone) could help me to understant the problem with the toolbox code produced by the Matlab AI Chat Playground
Kind regards, Eric

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!