Giter Club home page Giter Club logo

Comments (4)

ShaoChangk avatar ShaoChangk commented on August 24, 2024

And this is the code of plot field
`function plot_field(ax,simulation,component,fieldType,GIFoutputname)

hold(ax,'on')

pArr = simulation.input.particles.positionArray;
rArr = simulation.input.particles.radiusArray;
dims = simulation.output.fieldPointsArrayDims;

switch lower(fieldType)
case 'total field'
E = simulation.output.totalField;
case 'scattered field'
E = simulation.output.scatteredField + simulation.output.internalField;
case 'initial field'
E = simulation.output.initialField;
end

switch lower(component)
case 'real ex'
fld = reshape(gather(E(:,1)), dims);
case 'real ey'
fld = reshape(gather(E(:,2)), dims);
case 'real ez'
fld = reshape(gather(E(:,3)), dims);
case 'abs e'
fld = reshape(gather(sqrt(sum(abs(E).^2,2))), dims);
end

if exist('GIFoutputname','var')
t = linspace(0,2*pi,26); t(end) = []; % 25 frames
cmap = interp1(1:3,[0 0 1; 1 1 1; 1 0 0],linspace(1,3,256-32));
gifcmap = [cmap; gray(32)]; % add some grayscale colors for the gif colormap
caxislim = [-max(abs(fld(:))), max(abs(fld(:)))];
else
t = 0;
cmap = parula(256);
caxislim = [0, max(abs(fld(:)))];
end

fldPnts = reshape([simulation.output.fieldPoints(:,1), ...
simulation.output.fieldPoints(:,2), ...
simulation.output.fieldPoints(:,3)], [dims,3]);

if all(fldPnts(:,:,1) == fldPnts(1,1,1)) % fldPoints are on the yz plane
perpdim = 1; % 1->x is the perp. direction
elseif all(fldPnts(:,:,2) == fldPnts(1,1,2))% fldPoints are on the xz plane
perpdim = 2; % 2->y is the perp. direction
elseif all(fldPnts(:,:,3) == fldPnts(1,1,3))% fldPoints are on the xy plane
perpdim = 3; % 3->z is the perp. direction
else
error('fieldPoint must define an xy, xz or yz-like plane')
end

xy = setdiff([1,2,3], perpdim); % here xy are the in-plane dimensions
x = fldPnts(:,:,xy(1));
y = fldPnts(:,:,xy(2));

dist = abs(pArr(:,perpdim) - fldPnts(1,1,perpdim));% particle distances from xy plane
idx = find(dist<rArr); % find particles intersecting the plane
rArr(idx) = sqrt(rArr(idx).^2 - dist(idx).^2); % overwrite radius of the intersection circle

if exist('GIFoutputname','var') % initialize imind array
f = getframe(gcf);
imind = rgb2ind(f.cdata,gifcmap,'nodither');
imind(1,1,1,numel(t)) = 0;
end

for ti=1:numel(t)
imagesc(x(1,:), y(:,1), real(fldexp(-1it(ti))))% plot field on a xy plane
colormap(cmap)
for i=1:length(idx)
rectangle(ax, ...
'Position', [pArr(idx(i),xy)-rArr(idx(i)), [2,2]*rArr(idx(i))], ...
'Curvature', [1 1], ...
'FaceColor', 'none', ...
'EdgeColor', [0,0,0], ...
'LineWidth', 0.75)
end
axis([min(x(:)),max(x(:)),min(y(:)),max(y(:))]) % set axis tight to fldPoints

labels = ['x'; 'y'; 'z'];
xlabel(labels(xy(1)))
ylabel(labels(xy(2)))

ax.DataAspectRatio = [1,1,1];
title([fieldType,', ',component])
caxis(caxislim)
colorbar
drawnow

if exist('GIFoutputname','var')
    f = getframe(gcf);
    imind(:,:,1,ti) = rgb2ind(f.cdata,gifcmap,'nodither');
end

end

hold(ax,'off')

if exist('GIFoutputname','var')
imwrite(imind,gifcmap,GIFoutputname,'DelayTime',0,'Loopcount',inf)
end

end
`

from celes.

lpattelli avatar lpattelli commented on August 24, 2024

Hi,
the error you get is due to the fact that the simulation did not return a valid field array (simul.output.totalField is an empty array which cannot be reshaped into its intended shape). The reason why you get an invalid output is that your particle configuration comprises overlapping spheres, which is not allowed in the T-matrix approach used by CELES. Your script runs fine if you reduce the particle radii up to a point where they do not intersect each other.

Perhaps we should think about throwing an error if the user provides an input file with overlapping spheres, but that sounds computationally expensive as one should loop through several pairs of particles to check that no sphere is overlapping with any other sphere.

from celes.

ShaoChangk avatar ShaoChangk commented on August 24, 2024

from celes.

ShaoChangk avatar ShaoChangk commented on August 24, 2024

Hi,
the error you get is due to the fact that the simulation did not return a valid field array (simul.output.totalField is an empty array which cannot be reshaped into its intended shape). The reason why you get an invalid output is that your particle configuration comprises overlapping spheres, which is not allowed in the T-matrix approach used by CELES. Your script runs fine if you reduce the particle radii up to a point where they do not intersect each other.
Perhaps we should think about throwing an error if the user provides an input file with overlapping spheres, but that sounds computationally expensive as one should loop through several pairs of particles to check that no sphere is overlapping with any other sphere.

thank you very much!!!

from celes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.