Comments (4)
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.
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.
from celes.
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)
- Save / Load method in simulation class HOT 4
- Animations HOT 1
- Interface to SMARTIES
- FFT acceleration through translation to grid
- Non-CUDA alternatives HOT 4
- Double precision
- Dipole sources
- Error: complex refractive index of medium HOT 3
- celes_initialField: pol index doesn't update when polarization changes HOT 8
- catch case of few spheres before calling convHull HOT 2
- Bug in `compute_maximal_particle_distance` HOT 5
- Scattered field PWP is overwritten by total field PWP
- Nested Spheres HOT 3
- Celes: solve "periodic particle array" problem with "plane wave sources". HOT 2
- For-Loops HOT 1
- Environment issue HOT 5
- Questions about CELES HOT 3
- Analysis of multiple wavelengths HOT 3
- Is this project maintaining? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from celes.