code does not call a designed function that works in other program
Mostrar comentarios más antiguos
Hello and sorry for this long query. I am not very good at this , I have to admit it.
I am encountering an issue when trying to apply custom boundary conditions in a PDE model using MATLAB. Specifically, I have a custom boundary condition function mybc1 that works correctly in another code when using structuralBC to apply displacement conditions to vertices. However, in my current code, when I try to use applyBoundaryCondition to set mixed boundary conditions on specific faces, it seems that the solver does not enter the custom boundary condition function mybc1.
Here's a brief description of what I am trying to do:
- Model Definition: I have defined a PDE model with certain geometry and mesh.
- Boundary Condition Application: I attempt to apply mixed boundary conditions on specific faces using applyBoundaryCondition with the u parameter set to a custom function handle @(location, state)mybc1(location, state, dis, ts, in).
- Issue: It appears that the solver does not call the mybc1 function during the solution process. I verified this by setting breakpoints inside mybc1, which are never hit.
The mybc1 function interpolates the acceleration data (dis) at the times specified by the solver (state.time) and returns the corresponding values. This function has been tested and works correctly in another program with structuralBC.
code as follows:
%____________Define dimensions of the plate________________________________
len = 1.22; % length in x direction
width = 1.22; % Width in y direction
sq_side = 0.10; % Side length of the squares in corners
% Create the geometry description matrix___________________________________
% -----Define the outer boundary-------------------------------------------
outer_boundary = [3, 4, 0, len, len, 0, 0, 0, width, width]';
%------Define squares in the corners---------------------------------------
square_1 = [3, 4, 0, sq_side, sq_side, 0, 0, 0, sq_side, sq_side]';
square_2 = [3, 4, len - sq_side, len, len, len - sq_side, 0, 0, sq_side, sq_side]';
square_3 = [3, 4, len - sq_side, len, len, len - sq_side, width - sq_side, width - sq_side, width, width]';
square_4 = [3, 4, 0, sq_side, sq_side, 0, width - sq_side, width - sq_side, width, width]';
%------Combine all the geometries------------------------------------------
gdm = [outer_boundary, square_1, square_2, square_3, square_4];
%------Define the names for each region------------------------------------
ns = (char('R1','R2','R3','R4','R5'))';
sf = 'R1+R2+R3+R4+R5';
%-------Create the geometry------------------------------------------------
model = createpde(2);
geometryFromEdges(model, decsg(gdm, sf, ns));
%-------Generate the mesh and plot the geometry----------------------------
msh = generateMesh(model, 'Hmax', 0.1); % Use 'Hmax' to control mesh density
figure
pdemesh(model)
%_____________Create the different regions of the model___________________
% Obtain nodes and elements of the mesh
[p,e,t] = meshToPet(model.Mesh);
% ----------Plot with Faces labels----------------------------------------
figure;
pdegplot(model, 'FaceLabels', 'on', 'FaceAlpha', 0.5);
figure
pdemesh(model, 'NodeLabels', 'on');
% Definition of the constants
E = 4E9;
h_thick = 0.05;
nu = 0.3;
mass = 100;
D = E*h_thick^3/(12*(1-nu)^2);
% Now we create the PDE systems as symbolic equations_____________________
syms pres
syms u1(x,y,t) u2(x,y,t)
pdeeq = [-laplacian(u1,[x y])+u2; D*laplacian(u2,[x y])+ mass*diff(u1,t,t)-pres];
symcoeffs = pdeCoefficients(pdeeq,[u1,u2],'Symbolic',true);
c2=symcoeffs.c;
m2=symcoeffs.m;
%------Display the symbolic coefficients-----------------------------------
structfun(@disp,symcoeffs);
symcoeffs=subs(symcoeffs,pres,1);
coeffs=pdeCoefficientsToDouble(symcoeffs);
%------pass these coefficients to the pde model----------------------------
specifyCoefficients(model,'m',coeffs.m,'d',coeffs.d,'c',...
coeffs.c,'a',coeffs.a,'f',coeffs.f);
% INITIAL CONDITIONS ------------------------------------------------------
setInitialConditions(model,[0;0],[0;0]);
%USE THE DATA FROM ASHMOLEAN AS BOUNDARY CONDITIONS------------------------
%load the vector containing the acceleration values
load(totaldata.mat', 'DATA',...
'TIME','fs');
ac=DATA;
% -------Create vector time, not starting in 0
num_samples = size(DATA, 1);
dt = 1 / fs; % interval between measurements
t = (1:num_samples) * dt; % vector of times
% TRANSFORM ACCELERATIONS INTO DISPLACEMENTS_______________________________
acvedi=AccVelDis(962.54,1005.11,992.35,ac,fs,t);
dis=acvedi{3};
t=[0,t]; % I start the time at 0
% Boundary conditions in the faces using the displacement vectors
in=0; %counter variable
Faces=[1,2,3,5]; %Vector with faces numbers
for jk = 1:numel(Faces)
in=in+1;%add 1 in every loop to access the different measurmentes contained in the matrix acceleration
face= Faces(jk);
dis1=dis(:,in);
applyBoundaryCondition(model,"mixed","Face",[face,face],"u",@(location,state)mybc1(location,state,dis1,t),"EquationIndex",1,"q",[0 0],"g",0);
%applyBoundaryCondition(model,"dirichlet","Face",face,"h",[0 0 ; 0 1],"r",bcfunc)
end
in=0;
tim=[t(2) t(3)]; %tim represents the time of interest to solve the pde
res=solvepde(model, tim);
% Access the solution at the nodal locations
sol=res.NodalSolution;
And this is the function that works in another code:
function bcMatrix = mybc1(location,state,acs,ti)
%This function is use to extrapolate the values of acceleration for the
%time instances chosen by the system to do the integration of the system.
%as imput it requires the measurements matrix and the corresponding time
%measurements. As output, it provices the extrapoleted values for the state
%time
T=state.time;
% Check if T is NaN and assign the previous value if true
if isnan(T)
vq = NaN(size(location.x)); %this is what documentation says????
else
ac = acs; %gets the value of the corresponding acceleration
vq = interp1(ti, ac, T); %interpolates it
end
bcMatrix = vq;
end
I would really appreciate any help/guidance
12 comentarios
Jorge Garcia Garcia
el 1 de Ag. de 2024
Walter Roberson
el 1 de Ag. de 2024
load(totaldata.mat', 'DATA',...
'TIME','fs');
bad quoting: you need
load('totaldata.mat', 'DATA',...
'TIME','fs');
Unfortunately you did not happen to include that file for us to test with.
Sergio E. Obando
el 1 de Ag. de 2024
You have a 2D problem, I think the boundary conditions should be set at the edges rather than the faces. Not all edges in F1-F5 are exterior boundaries.
Jorge Garcia Garcia
el 2 de Ag. de 2024
Editada: Walter Roberson
el 20 de Ag. de 2024
Sergio E. Obando
el 2 de Ag. de 2024
If there is an issue around a particular time step, you could use a coarse time step for certain parts of the solution. E.g. say the issue is around tk = 5; then run the problem tI_1= 0:0.1:4.9., and then use the solution as the initial conditions and solve with tI_2 = 4.9:0.01:6
Jorge Garcia Garcia
el 20 de Ag. de 2024
Steven Lord
el 20 de Ag. de 2024
The documentation page for the interpolateSolution function states that the first input argument must be "specified as a StationaryResults object, a TimeDependentResults object, or an EigenResults object". Can you confirm that res is one of those types of objects? What does these commands show when run on the res variable?
class(res)
isa(res, 'pde.StationaryResults')
isa(res, 'pde.TimeDependentResults')
isa(res, 'pde.EigenResults')
If none of those isa calls return true, your res variable isn't of a type that interpolateSolution can handle. For example, if you tried to call interpolateSolution(1, 2, 3) you'd likely receive the same type of error.
intervalue=interpolateSolution(res, 0.5, 0.5, :,1);
I doubt that : as fourth argument is a legal call to interpolateSolution.
Jorge Garcia Garcia
el 21 de Ag. de 2024
Look at the example "Interpolate Time Dependent System" under
on how to call "'interpolateSolution" for a time-dependent system.
Here is the essence:
yy = 0:0.2:10;
zz = 0.5*ones(size(yy));
xx = 10*zz;
component = 3;
uintrp = interpolateSolution(results,xx,yy,zz, ...
component,1:length(tlist));
Since your problem is 2d, zz should not appear in your input list to "interpolateSolution".
Jorge Garcia Garcia
el 22 de Ag. de 2024
Respuestas (0)
Categorías
Más información sobre General PDEs en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



