Use PDE toolbox to model 2-D diffusion-reaction of solutes released from surface of a cylinder
    5 views (last 30 days)
  
       Show older comments
    
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);
% 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
  Torsten
      
      
 on 23 Nov 2024
				I'd suggest importing the geometry from a CAD program in a format accepted by the PDE Toolbox.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
