COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2...

31
COMSOL Tutorial Saurav Z.K. Sajib Impedance Imaging Research Center (IIRC)

Transcript of COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2...

Page 1: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

COMSOL TutorialSaurav Z.K. Sajib

Impedance Imaging Research Center (IIRC)

Page 2: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Ohm’s Law 𝑉 = 𝐼𝑅

Ω

𝜕Ω

𝐹1 𝐹2

Case-1 Case-2

𝛻 −𝜎𝛻𝑢 = 0 𝑖𝑛𝑠𝑖𝑑𝑒Ω−𝜎𝛻𝑢. 𝑛 = 0 𝑜𝑛 𝜕Ω\ 𝐹1𝑈𝐹2

𝑢 = Φ0 𝑜𝑛 𝐹1𝑢 = 0 𝑜𝑛 𝐹2

𝛻 −𝜎𝛻𝑢 = 0 𝑖𝑛𝑠𝑖𝑑𝑒Ω𝑢 = Φ0 𝑜𝑛 𝐹1

𝑢 = 0 𝑜𝑛 (𝜕Ω𝑈𝐹2)\ 𝐹1

%% Geometry

geom2D = rect2('0.5','0.25','base','center','pos',{'0','0'},'rot','0');

clear s;

s.objs = {geom2D};

s.name = {'geom2D'};

s.tags = {'geom2D'};

fem.draw = struct('s',s);

fem.geom = geomcsg(fem);

%% Meshing

fem.mesh = meshinit(fem,'hauto',5);

fem.mesh = meshrefine(fem,'mcase',0,'rmethod','regular');

Page 3: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

𝑉 = 𝐼𝑅0

5.0

[V]

Case-1

Case-2

Page 4: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

𝑉 = 𝐼𝑅

𝑅 = 2.00[Ω] 𝑅 = 0.14[Ω]

Page 5: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Calculating Capacitance

For the parallel plate capacitance, 𝐶 = 0 𝑟𝐴

𝑑

𝑖 𝑡 = 𝐶𝑑𝑣

𝑑𝑡⇒ 𝐼 𝜔 = 𝑗𝜔𝐶𝑉 𝜔

⇒ 𝐶 =𝐼(𝜔)

2𝜋𝑓𝑉(𝜔)

𝜀𝑟(𝜔)

𝑑

𝐴

Page 6: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Calculating Capacitance

C vs. d C vs. A

Page 7: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Maxwell’s equations

∇. 𝐸 =𝜌

𝜖∇. 𝐵 = 0

∇ × 𝐸 = −𝑗𝜔𝐵𝐽 = ∇ × 𝐻

Supplementary relations 𝐵 = 𝛻 × 𝐴

𝐵 = 𝜇𝐻 ; 𝐷 = 𝜖𝐸𝐸 = −𝛻𝑢 − 𝑗𝜔𝐴

𝐽 = 𝜎 + 𝑗𝜔𝜖 𝐸 + 𝑣 × 𝐵 + 𝐽𝑒∇. 𝐽 = 0

Domain equations (assuming Coulomb gauge)

𝑗𝜔𝜎 − 𝜔2𝜀 𝐴 + 𝛻 ×1

𝜇𝛻 × 𝐴 − 𝜎𝑣 × 𝛻 × 𝐴 + 𝜎 + 𝑗𝜔𝜀 𝛻𝑢 = 𝐽𝑒

𝛻. 𝑗𝜔𝜎 − 𝜔2𝜀 𝐴 − 𝜎𝑣 × 𝛻 × 𝐴 + 𝜎 + 𝑗𝜔𝜀 𝛻𝑢 − 𝐽𝑒) = 0

Electrical boundary conditions𝐽. 𝑛 = 𝑔 𝑁𝑒𝑢𝑚𝑎𝑛𝑢 = 𝜑0 𝐷𝑟𝑖𝑐ℎ𝑙𝑒𝑡

COMSOL Quasi-static Electromagnetic (AC/DC Module)

Page 8: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Domain and mesh generation%% Making Phantom Geometry

cylin = cylinder3('0.0500','0.14','pos',{'0','0','0'},'axis',{'0','0','1'},'rot','45');

cylin1 = cylinder3('0.055','0.14','pos',{'0','0','0'},'axis',{'0','0','1'},'rot','45');

surf = geomcomp({cylin1,cylin},'ns',{'cylin1','cylin'},'sf','cylin1-cylin','face','none','edge','all');

clear cylin1;

blck1 = block3('0.15','0.05','0.05','base','center','pos',{'0','0','0.14/2'},'axis',{'0','0','1'},'rot','0');

blck2 = rotate(blck1,pi/2,[0,0,1],[0,0,0]);

ele1 = geomcomp({surf,blck1},'ns',{'surf','blck1'},'sf','surf*blck1','face','none','edge','all');

ele2 = geomcomp({surf,blck2},'ns',{'surf','blck2'},'sf','surf*blck2','face','none','edge','all');

phantom = geomcomp({cylin,ele1,ele2},'ns',{'cylin','ele1','ele2'},'sf','cylin+ele1+ele2','face','none','edge','all');

clear blck1 blck2 surf ele1 ele2 cylin;

phantom = geomdel(phantom);

%% Adding anomaly

GeomObj = rect2('0.03','0.03','base','center','pos',{'0','0'},'rot','0');

GeomObj = fillet(GeomObj,'radii',0.0050,'point',[1,2,3,4]);

GeomObj = extrude(GeomObj,'distance',0.05,'scale',[1;1],'displ',[0;0],'twist',0,'face','none','wrkpln',[0 1 0;0 0 1;0 0 0]);

GeomObj = move(GeomObj,[0,0,0.14/2-.05/2]);

phantom = geomcomp({phantom,GeomObj},'ns',{'phantom','GeomObj'},'sf','phantom+GeomObj','face','none','edge','all');

%% Making structure for geometry

clear s;

s.objs={phantom};

s.name={'phantom'};

s.tags={'phantom'};

fem.draw=struct('s',s);

fem.geom=geomcsg(fem);

%% Mesh

fem.mesh=meshinit(fem,'hauto',3,'point',[],'edge',[],'face',[],'subdomain',2);

fem.mesh=meshinit(fem,'hauto',4,'point',[],'edge',[],'face',[],'subdomain',1,'meshstart',fem.mesh);

Page 9: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

List of useful functions for COMSOL Modeling

Description Mat lab function Example

Block block3 block3(lx,ly,lz,'base','center','pos',{x,y,z},'axis',{'0','0','1'},'rot','0')

Sphere sphere3 sphere3(rd,'pos',{x,y,z},'axis',{'0','0','1'},'rot','0')

Cylinder cylinder3 cylinder3(rd,ht,'pos',{x,y,z},'axis',{'0','0','1'},'rot','0')

Cone cone3 cone3(rd,l,alpha,'pos',{x,y,z},'axis',{'0','0','1'},'rot','0')

Ellipsoid ellipsoid3 ellipsoid3(ax,ay,az,'pos',{x,y,z},'axis',{'0','0','1'},'rot','0')

Line curve3 curve3([x1,x2],[y1,y2],[z1,z2])

Point in 3D point3 point3(x,y,z)

2D Block rect2 rect2(length,width,'base','center','pos',[x,y])

2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y])

Move Move the object move(geom,[x,y,z])

Scale Scale the object scale(geom,x_scale,y_scale,z_scale,x,y,z)

Mirror Mirror the object mirror(geom,[x,y,z],[Xn,Yn,Zn])

Union Addition of two or more objects geom1+geom2

Substraction Substruction betwen two objects geom1-geom2

Intersection Intesection of the two objects geom1*geom2

Rotation Rotation of the objects rotate(geom,alpha,[0,1,0],[0,0,0]);

Revolution Revolve 2D object into 3D space revolve(geom,'angles',[0,angle],'revaxis',[1 0;0 1],'wrkpln',[0 1 0;0 0 1;0 0 0])

Extrude Extrude the 2D object to 3D extrude(geom,'distance',distance,'scale',[1;1],'displ',[0;0],'twist',[twist_angle],'face','none','wrkpln',[0 1 0;0 0 1;0 0 0])

Coerce to curve Edges from the solid object geomcoerce('curve',{geom})

Page 10: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

clear all; clc; close all;

load mri;

i = [2 6 12 17 22 27]; %slices to make the model

th = [1 1 1 1 1 1]; %image binarization

kf = [0.11 0.10 0.112 0.115 0.129 0.165];

% Calculating the contour

for k = 1:6

[c{k},r] = flim2curve(D(:,:,1,i(k)),{th(k),[]},'KeepFrac',kf(k));

end

%Making 2D solid object

for k = 1:6

c{k} = solid2(c{k});

end

s = c{3};

e1 = {1 1 1 1 1 1}; %analyzing the connective component map

dvr = {repmat(12.5,1,5),zeros(2,6),zeros(6)};

%Stack the 2D geometry and loft them to make 3D geometry

geom = loft(c,'loftedge',e1,'loftsecpos',dvr,'loftSecPos',...

{[0 4 8 12 16 20;0 4 8 12 16 20;0 4 8 12 16 …

20],[],[]},'loftweights',repmat(0.1,2,5));

%scale them in order to make proper dimension

geom = scale(geom,0.008,0.008,0.008,0,0,0);

Example of lofting geometry in COMSOL

Page 11: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

• In order to solve linear system COMSOL has several solvers:

Direct Solver

Conjugate gradient solver (CGS)

GMRES Solver

FGMRES Solver

BiCGStab

Geometric Multi-grid (GMG)

• An example of GMG Solver

fem.sol=femstatic(fem,'solcomp',{'V'}, ...

'outcomp',{'V'},'blocksize','auto','linsolver','gmg','mgcycle','f','presmooth','vanka', ...

'presmoothpar',{'vankasolv','direct','vankarelax',0.9,'seconditer',2,'vankavars',{'psi','V'}},...

'postsmooth','vanka','postsmoothpar',{'vankasolv','direct','vankarelax',0.9, ...

'seconditer',2,'vankavars', {'psi','V'}}, 'csolver','pardiso','mcase',[0 1]);

COMSOL Solver

Page 12: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

EIT Forward Problem

Ω

𝜕Ω

𝑬𝟏

𝑬𝟐

𝑬𝟑

𝑬𝟒

𝑬𝟓𝑬𝟔

𝑬𝟕

𝑬𝟖

𝑬𝟏𝟏

𝑬𝟏𝟐𝑬𝟏𝟑

𝑬𝟏𝟒

𝑬𝟏𝟓

𝑬𝟏𝟔 𝑬𝟏𝟎

𝑬𝟗

Neighboring injection Diagonal injection

𝛻 −𝜎𝛻𝑢 = 0 𝑖𝑛𝑠𝑖𝑑𝑒Ω−𝜎𝛻𝑢. 𝑛 = 0 𝑜𝑛 𝜕Ω𝑔𝑖 = 𝐼 𝑜𝑛 𝐸𝑗

𝑔𝑖 = −𝐼 𝑜𝑛 𝐸𝑗+𝑘𝑘 = 1

𝛻 −𝜎𝛻𝑢 = 0 𝑖𝑛𝑠𝑖𝑑𝑒Ω−𝜎𝛻𝑢. 𝑛 = 0 𝑜𝑛 𝜕Ω𝑔𝑖 = 𝐼 𝑜𝑛 𝐸𝑗

𝑔𝑖 = −𝐼 𝑜𝑛 𝐸𝑗+𝑘𝑘 = 8

%% Finding the topology of the boundary point electrodes

toplogical_Info = flgeomse(fem.geom);

updown_Info = flgeomud(fem.geom);

[~, col1] = find(updown_Info==0);

[~, col2] = find(updown_Info==2);

topology = toplogical_Info(:,col1);

updown = updown_Info(:,col1);

clear updown_Info;

indx1 = updown(1,:) == 0; indx2 = updown(1,:) == 1;

pnt_num1 = topology(1,indx1); pnt_num2 = topology(1,indx2);

pnt_numbers = [pnt_num1,20,fliplr(pnt_num2(2:end))];

clear indx1 indx2 pnt_num1 pnt_num2;

%% Defining the current injection patterns for neighboring injection

InjEleNum = (circshift(pnt_numbers',-k))'; % Injection electrode number

pnt_grp1 = InjEleNum(1); % +ve injection

pnt_grp2 = InjEleNum(2); % -ve injection

pnt_grp3 = InjEleNum(3:end); % no injection

pnt_grp4 = toplogical_Info(:,col2); pnt_grp4 = unique(pnt_grp4(:)); pnt_grp4 = pnt_grp4';

pnt_ind = ones(1,20);

pnt_ind(pnt_grp1) = 2; pnt_ind(pnt_grp2) = 3; pnt_ind(pnt_grp3) = 1; pnt_ind(pnt_grp4) = 1;

clear pnt_grp1 pnt_grp2 pnt_grp3 pnt_grp4 InjEleNum;

%% Defining the current injection patterns for diagonal injection

InjEleNum = (circshift(pnt_numbers',-k))'; % Injection electrode number

pnt_grp1 = InjEleNum(1); % +ve injection

pnt_grp2 = InjEleNum(end/2+1); % -ve injection

pnt_grp3 = InjEleNum(2:end/2,end/2+1:end); % no injection

pnt_grp4 = toplogical_Info(:,col2); pnt_grp4 = unique(pnt_grp4(:)); pnt_grp4 = pnt_grp4';

pnt_ind = ones(1,20);

pnt_ind(pnt_grp1) = 2; pnt_ind(pnt_grp2) = 3; pnt_ind(pnt_grp3) = 1; pnt_ind(pnt_grp4) = 1;

clear pnt_grp1 pnt_grp2 pnt_grp3 pnt_grp4 InjEleNum;

%% Defining the boundary conditions

bnd_ind = ones(1,20);

bnd_ind(col2) = 2;

clear col1 col2;

Page 13: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Neighboring injection Diagonal injection

Voltage distribution

Page 14: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Measured boundary voltages (Neighboring injection)[μV]

Page 15: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Difference boundary voltages (Neighboring injection)[μV]

Page 16: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Measured boundary voltages (Diagonal injection)[μV]

Page 17: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Difference boundary voltages (Diagonal injection)[μV]

Page 18: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Sensitivity on anomaly conductivity changesN

eig

hb

ori

ng

Dia

go

na

l

𝜎𝑎𝑛𝑜 = 0.5 𝜎𝑎𝑛𝑜 ≈ 0

Page 19: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

MREIT Forward Problem

•The MREIT forward model is subject to following mixed boundary value

problem,

• The current density then can be obtain as,

𝐽𝑖 = −𝜎𝛻𝑢𝑖

• Magnetic flux density inside domain is given by Bi-Savart’s Law,

𝐵𝑖 𝑟′ =1

4𝜋 Ω 𝐽𝑖(𝑟′) ×

𝑟−𝑟′

𝑟−𝑟′ 3 𝑑𝑟′

Ω

𝜕Ω

𝐹1 𝐹2

𝛻 −𝜎𝛻𝑢𝑖 = 0 𝑖𝑛𝑠𝑖𝑑𝑒Ω

−𝜎𝛻𝑢𝑖 . 𝑛 = 0 𝑜𝑛 𝜕Ω\ 𝐹1𝑈𝐹2−𝜎𝛻𝑢𝑖 . 𝑛 = 𝐼𝑖 𝑜𝑛 𝐹1

𝑢𝑖 = 0 𝑜𝑛 𝐹2

Page 20: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

MREIT Forward Problem

%% Some input parameters for interpolating the solution

imSize = 128; slices = 5;

%% Post-process the data over a "mesh" for multiple slices

fov = 0.12;

x1 = -fov/2 +(0:imSize-1)*fov/imSize;

y1 = -fov/2 +(0:imSize-1)*fov/imSize; y1=rot90(y1,1);

ht = 0.5;

z1 = (1:slices)*ht/(slices);

[x1,y1,z1]=meshgrid(x1,y1,z1);

xx=[x1(:),y1(:),z1(:)]';

%% Interpolation of COMSOL solution

vol=postinterp(fem,'V',xx,'ext',0);

u = reshape(vol,imSize,imSize,slices); u(isnan(u)) = 0

𝐼1

𝐼2

Current density calculation

Mag

net

ic f

lux

den

sity

calc

ula

tion

system('F:\FFT_Bz_Code\CRHABSLaw.exe .\Tem

0.12 128 0.0105 5 3');

Page 21: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Distribution of voltage, current density and Bz

Voltage Current density Bz

Page 22: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Alternative approach to calculate Bz

Page 23: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

• The k-space MREIT signal due to current injection I is given by,

𝑆 𝑚, 𝑛 = −∞

𝑀 𝑥, 𝑦 𝑒𝑗𝛿(𝑥,𝑦)𝑒𝑗𝛾𝐵𝑧𝑇𝑐𝑒𝑗(𝑥𝑚∆𝑘𝑥+𝑦𝑛∆𝑘𝑦)𝑑𝑥𝑑𝑦

⇒ 𝑆 𝑚, 𝑛 = 𝐹𝑇{𝑀(𝑥, 𝑦)𝑒𝑗𝛿(𝑥,𝑦)𝑒𝑗𝛾𝐵𝑧𝑇𝑐}

⇒ 𝑀(𝑥, 𝑦)𝑒𝑗𝛿(𝑥,𝑦)𝑒𝑗𝛾𝐵𝑧𝑇𝑐 = 𝐹𝑇−1{𝑆(𝑚, 𝑛)}

• In order to remove the effect of transverse magnetization and systematic phase artifact in MREIT two opposite polar

ity current is injected during both injection (either H or V)

𝑀(𝑥, 𝑦)𝑒𝑗𝛿(𝑥,𝑦)𝑒±𝑗𝛾𝐵𝑧𝑇𝑐 = 𝐹𝑇−1{𝑆± 𝑚, 𝑛 }

⇒ 𝐵𝑧 𝑥, 𝑦 =1

2𝛾𝑇𝑐𝑎𝑟𝑔(

𝐹𝑇−1{𝑆+(𝑚, 𝑛)}

𝐹𝑇−1{𝑆−(𝑚, 𝑛)})

• The generated transverse magnetization Mi(x,y) is given by,

𝑀𝑖 𝑥, 𝑦 = 𝛺𝑖(𝑥, 𝑦)(1 − 𝑒−𝑇𝑅𝑇1 )𝑒

−𝑇𝐸𝑇2

𝛺𝑖 𝑥, 𝑦 = = 1 𝑖𝑛𝑠𝑖𝑑𝑒 𝛺𝑖

= 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

MREIT Simulator

Page 24: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

MREIT Simulator

Simulation of MREIT Bz measurement process using MREITSim. (a) Noisy MR magnitude image, (b) and (c) are the magnetic flux density images for positive and

negative current injection in horizontal direction, respectively. (d) and (e) are real and imaginary parts of the k-space image for positive current injection. (f) and (g)

are the magnitude and phase parts of the complex image after inverse Fourier transform. The corresponding images for negative current injection are shown from (h)

to (k). The simulated noisy Bz image given as output by MREITSim is shown in (l).Minhas et al , (2011) ,“Three-dimensional MREIT Simulator of Static Bioelectromagnetism and MRI”

Page 25: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

MREIT Simulator

TE = 20ms TE = 50ms TE = 80ms TE = 110ms

Page 26: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

200

0

50

0

WM

GM

CSF

Skull

Scalp

Location of DBS

electrode

-0.0750

0.2

[S/m]

0.075

[S/m]

σ11 σ22 σ33 σ12 σ13 σ23

Study on Deep Brain Stimulation (DBS)

x

z

1

2

3

4Insulator

Conductor

𝜎 =𝜎𝑖𝑠𝑜

𝜈=13 𝜆𝑑

𝜈 1 3 𝐷

Page 27: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

function [] = fx_wrt_tensor_data(Data,FOV,slice_thickness)

%% Imaging parameters and constants

imSize = size(Data,1);

number_of_slices = size(Data,4);

model_ht = slice_thickness*(number_of_slices-1);

%% Generate Meshes

x = -(FOV/2)+(0:imSize-1)*(FOV/imSize);

y = -(FOV/2)+(0:imSize-1)*(FOV/imSize);

y=rot90(y,1);

z = (0:number_of_slices-1)*(model_ht/number_of_slices);

[X Y Z]=meshgrid(x,y,z);

%%

Data11 = squeeze(Data(:,:,1,:)); Data12 = squeeze(Data(:,:,2,:)); Data13 =

squeeze(Data(:,:,3,:));

Data22 = squeeze(Data(:,:,4,:)); Data23 = squeeze(Data(:,:,5,:)); Data33 =

squeeze(Data(:,:,6,:));

fun1(:,1) = X(:); fun1(:,2) = Y(:); fun1(:,3) = Z(:);fun1(:,4) = Data11(:);

fun2(:,1) = X(:); fun2(:,2) = Y(:); fun2(:,3) = Z(:);fun2(:,4) = Data12(:);

fun3(:,1) = X(:); fun3(:,2) = Y(:); fun3(:,3) = Z(:);fun3(:,4) = Data13(:);

fun4(:,1) = X(:); fun4(:,2) = Y(:); fun4(:,3) = Z(:);fun4(:,4) = Data22(:);

fun5(:,1) = X(:); fun5(:,2) = Y(:); fun5(:,3) = Z(:);fun5(:,4) = Data23(:);

fun6(:,1) = X(:); fun6(:,2) = Y(:); fun6(:,3) = Z(:);fun6(:,4) = Data33(:);

data_loc = 'Data\';

save(strcat(data_loc,'sigma11.txt'),'fun1', '-ascii');

save(strcat(data_loc,'sigma12.txt'),'fun2', '-ascii');

save(strcat(data_loc,'sigma13.txt'),'fun3', '-ascii');

save(strcat(data_loc,'sigma22.txt'),'fun4', '-ascii');

save(strcat(data_loc,'sigma23.txt'),'fun5', '-ascii');

save(strcat(data_loc,'sigma33.txt'),'fun6', '-ascii');

Conductivity modeling in DBS% This code implementing the linear conductivity to diffusivity relation

% together with the volume constrain proposed by Tuch et al. 2001 at PANS

function [Sigma_tensor] = fx_get_conductivity_tensor_map(D,sigma_iso)

D = squeeze(D);

for x = 1:size(D,1)

for y = 1:size(D,2)

DTI = [D(x,y,1),D(x,y,2),D(x,y,3);...

D(x,y,2),D(x,y,4),D(x,y,5);...

D(x,y,3),D(x,y,5),D(x,y,6)];

lamda = eig(DTI); lamda = abs(lamda);

eta = sigma_iso/((lamda(1)*lamda(2)*lamda(3))^(1/3));

eta(isnan(eta)|isinf(eta)) = 0;

ECDR(x,y) = eta;

clear lamda eta DTI;

end

end

D_tem = D; clear D;

D(:,:,1) = abs(squeeze(D_tem(:,:,1))); D(:,:,4) = abs(squeeze(D_tem(:,:,4))); D(:,:,6) =

abs(squeeze(D_tem(:,:,6)));

D(:,:,2) = squeeze(D_tem(:,:,2)); D(:,:,3) = squeeze(D_tem(:,:,3)); D(:,:,5) = squeeze(D_tem(:,:,5));

clear D_tem;

for i = 1:size(D,3)

Sigma_tensor(:,:,i) = ECDR.*D(:,:,i);

end

clear i;

Sigma_tensor(isnan(Sigma_tensor)|isinf(Sigma_tensor)) = 0;

Page 28: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Comparison of voltage distribution DBS

0

0.3

[V]

10 15 20 25

-12

-10

-8

-6

-4

-2

0

2

4

Isotropic homogeneous

10 15 20 25

-12

-10

-8

-6

-4

-2

0

2

4

Isotropic inhomogeneous

10 15 20 25

-12

-10

-8

-6

-4

-2

0

2

4

Anisotropic (Realistic)

Page 29: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

Non-Linear Problem Electroporation

𝜎 = 𝜎( 𝑟, 𝐸)𝐸 = 𝐸( 𝑟, 𝜎) 𝜎=𝜎0 +

𝜎1−𝜎0

1+𝐷𝑒𝑥𝑝{−𝐸−𝐴

𝐵}

+ -

x

y

Page 30: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

function [sigma] = FxGetSigma(E)

%% Model parameters

sigma0 = 0.067; % Initial conductivity distribution

sigma1 = 0.241; % Final conductivity distribution

C = 8; D = 10; % Empirically determined sigmoidal functional

values

E0 = 460; % [V/cm]

E1 = 700; % [V/cm]

E0 = E0*1e2; % [V/m]

E1 = E1*1e2; % [V/m]

A = 0.5*(E1+E0);

B = (1/C)*(E1-E0);

delSigma = sigma1-sigma0;

%% Calculating the electric field depended conductivity sigma = sigma(E)

[nrows , ncols , nslcs] = size(E);

sigma = sigma0+(delSigma./(1+D*exp(-((E(:)-A)/B))));

sigma = reshape(sigma, nrows, ncols, nslcs);

mask = double(E==0);

sigma = sigma0*mask + sigma;

clear mask;

function [] = FxWrt3DData(data, FOV)

[nrows , ncols] = size(data);

%% Generate Meshes

x = -FOV/2+(0:imSize-1)*(FOV/nrows);

y = -FOV/2+(0:imSize-1)*(FOV/ncols);

y = rot90(y,1);

[X Y] = meshgrid(x,y);

%% Writing the data

DataLoc = ‘Data\';

fun(:,1) = X(:); fun(:,2) = Y(:); fun(:,3) =

data(:);

save(strcat(DataLoc,'cnd.txt'),'fun','-ascii');

clear DataLoc;

Conductivity modeling during electroporation

Page 31: COMSOL Tutorial - IIRC · 2019. 11. 23. · 2D Block rect2 rect2(length,width,'base','center','pos',[x,y]) 2D ellipsoid ellip2 ellip2(0.4,0.2,'base','center','pos',[x,y]) Move Move

U = 500 [V]

U = 1000 [V]

U = 1500 [V]

0

1.5

[kV/cm]

Electric field distribution during electroporation