How can i define PDE coefficient which is scalar matrix inside the boundary
1 次查看(过去 30 天)
显示 更早的评论
Hello wonderful people in the MathWorks!!
I'm relativelly new to this, so forgive me if I'm missing the basics.
I'm trying to solve a 2D PDE problem, which is defined as follows, described in PDE model coefficients .
specifyCoefficients(model, 'm', 0, 'd', 0, 'c', @cfunc, 'a', 0, 'f', @ffunc);
So it is a (time independent) elliptic 2nd order PDE.
So my problem is defining cfunc and ffunc.
c and f are time-independent scalar field, mapped inside the boundaries as a matrix.
They are not caculated values which can be described as f(location.x, location.y), but obseved values. (c requires information from 2 matrices)
How can i define c and f in this case?
Here are the schematics of codes I've been trying to pull off
NoE=1; % number of equation
% generate boundary
R= [2; 4; min(xv); max(xv); max(xv); min(xv); max(-yv); max(-yv); min(-yv); min(-yv)]; % 4 rectangular edges, xv and yv are vectors for points
g= decsg(R, 'R', 'R');
%generate mesh: I need to designate specific mesh that suits my interest, since diff(xv) << diff(yv)
[mesh_p, mesh_e, mesh_t]=poimesh(g, length(xv)-1, length(yv)-1);
% create pdemodel
model=createpde(NoE)
%set mesh
mesh_t(4, :)=[]; %for some reason the supproted format seems to be different
[geomet2, mesh]=geometryFromMesh(model, mesh_p, mesh_t);
%boundary condition
applyBoundaryCondition(model,'dirichlet','Edge',[1 2 3 4],'u',0);
%specify coefficients
specifyCoefficients(model, 'm', 0, 'd', 0, 'c', @cfunc, 'a', 0, 'f', @ffunc);
%solve, but neither works, displaying error messages that differs accoding to cfunc and ffunc i make
result1=assembleFEMatrices(model, 'nullspace')
result2=solvepde(model)
for specify coefficients, I tried various functions, ex)
I tried scatteredInterpolant function inside cffunc, (and ffunc)
function ccoeff=cfunc(location, status)
ccoeff=zeros(4*NoE,numel(location.x));
ccoeff(1, :)=N2scat(location.x, location.y); %N2scat and f2scat is scatteredInterpolant object, global
ccoeff(4, :)=f2scat(location.x, location.y);
end
or
it1=mesh_t(1,:);
it2=mesh_t(2,:);
it3=mesh_t(3,:);
xpts = (mesh_p(1,it1) + mesh_p(1,it2) + mesh_p(1,it3))/3;
ypts = (mesh_p(2,it1) + mesh_p(2,it2) + mesh_p(2,it3))/3;
for i=1:length(location.x)
[~, id(i)]=min((location.x(i)-xpts).^2 +(location.y(i)-ypts).^2);
end
N2inside=N2scat(xpts, ypts);
f2inside=f2scat(xpts, ypts);
ccoeff(1, :)=N2inside(id);
ccoeff(4, :)=f2inside(id);
returns error
================================================
Warning: Matrix is singular to working precision.
> In pde.EquationModel/solveStationaryNonlinear (line 21)
In pde.PDEModel/solvepde (line 77)
Error using pde.EquationModel/solveStationaryNonlinear (line 27)
Unsuitable initial guess U0 (default: U0=0).
Error in pde.PDEModel/solvepde (line 77)
u = self.solveStationaryNonlinear(coefstruct, u0);
=================================================
or
=================================================
Error using pde.EquationModel/assembleFEMatricesInternal (line 22)
PDE coefficients cannot be function of solution or time.
Error in assembleFEMatrices (line 73)
FEMatricesOut = assembleFEMatricesInternal(pdem,BCEnforcementOption);
=================================================
I'm not sure where this errors come from, or have i completely gone sidetrack?
any suggestions?
Thanks in advance,
SJ Kim
0 个评论
回答(1 个)
Ravi Kumar
2019-5-22
Hi Kim,
Is your ffunc depends on solution, i.e., using state.u? Can you provide sample data, also xv and yv?
Regards,
Ravi
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geometry and Mesh 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!