can't run applyBoundaryCondition

5 次查看(过去 30 天)
Laila
Laila 2025-3-12
编辑: Torsten 2025-3-12
I'm trying to run the following code to solve 3D PDE on a unit cube usind pdetool functions. I've got two error messeges
1- Error using pde.ThermalMaterialAssignment/checkThermalConductivitySize
Incorrect ThermalConductivity size.
2- Unrecognized function or variable 'applyBoundaryCondition'.
% 1. Define the Geometry of the Unit Cube
model = createpde('thermal', 'steadystate');
L = 1; % Length of the unit cube
gm = multicuboid(L, L, L); % Create a unit cube geometry
model.Geometry = gm;
pdegplot(model,"FaceLabels","on","FaceAlpha",0.5)
% 2. Define the Anisotropic Poisson Equation
% Define anisotropic conductivity matrix (3x3 tensor)
K = [2 1 0; 1 3 0; 0 0 1]; % Example anisotropic conductivity tensor
% Define the source term f(x, y, z)
f = @(location, state) 1; % Constant source term for simplicity
% Set thermal properties for the Poisson equation
thermalProperties(model, 'ThermalConductivity', K);
% Solver options
model.SolverOptions.RelativeTolerance = 1e-6;
model.SolverOptions.AbsoluteTolerance = 1e-6;
% 3. Apply Boundary Conditions (Dirichlet u = 0 on all boundaries)
% 3. Apply Boundary Conditions (Dirichlet u = 0 on all boundaries)
applyBoundaryCondition(model,"dirichlet", ...
"Face",1:6,"u",0);
Unrecognized function or variable 'applyBoundaryCondition'.
% 4. Mesh the Geometry
generateMesh(model, 'Hmax', 0.1); % Adjust Hmax for finer or coarser mesh
% 5. Solve the Poisson Equation
result = solve(model);
% 6. Postprocessing and Visualization
u = result.NodalSolution
figure
pdeplot3D(model, 'ColorMapData', u);
title('Solution to the 3D Anisotropic Poisson Equation');
xlabel('X');
ylabel('Y');
zlabel('Z');
colorbar;

回答(1 个)

Torsten
Torsten 2025-3-12
编辑:Torsten 2025-3-12
"applyBoundaryConditions" is used for general PDE models. You want to use the "thermal" model.
The available properties and object functions are listed here:
I think the keyword is "thermalBC" in this case.

类别

Help CenterFile Exchange 中查找有关 Geometry and Mesh 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by