Mesh.Algorithm3D = 4;
// General.RotationCenterX=270;
// General.RotationCenterY=0;
// General.RotationCenterX=360;
freq=50;// frequenz
curr=4242*Sqrt(2);// Stromstärke
eps=1.e-6;

xs1=0.25;// Radius Schmelze unter der Schräge
xs2=0.325;// großer Radius Schmelze
y_nenn=1;// Nennhöhe
ys1=0.180;// höhe der Schräge

wz=1;// windungszahl
wd=0.004;// windungsabstand
xw1=0.425;// innenradius ind
xw11=xw1+0.00825;// außenradius eckiger teil
hw=0.0195;// höhe ind
rw1=0.0065;// innenradius runder teil
rw2=rw1+0.00325;// außenradius runder teil
h1=0;// untere Z- Position der ersten Windung
h2=hw;// obere Z- Position der ersten Windung
phi=Pi/100;// Rotationswinkel


rair=3*y_nenn;// Radius Airbox
rinf=4*y_nenn;// Radius Infinity

Einsatz = 10000;
Induktor = 20000;
Air = 30000;

SKIN_Einsatz = 11000;
Einsatz_OUT = 12000;
Einsatz_IN = 13000;
SKIN_Induktor = 22000;
OUT = 220000;
IN = 200002;
Inf_Air = 33000;
Air_IN=34000;
Air_OUT=35000;

Point(1)={0,0 ,0, 0.01};
Point(2)={xs2,0 ,0, 0.01};
Point(3)={0,0 ,y_nenn, 0.01};
Point(4)={xs2,0 ,y_nenn, 0.01};



// Einsatz
einsatz_in[]={};
einsatz_out[]={};
vol_Einsatz[] = {};

Line(1) = {1,2};
Line(2) = {2,4};
Line(3) = {3,4};
Line(4) = {1,3};

Line Loop(5) = {1,2,-3,-4} ;
Plane Surface(1) = {5} ;
tmp[] = {1};
einsatz_in[]=tmp[0];

tmp[] = Extrude { {0,0,y_nenn}, {0,0,0} ,  phi}{ Surface {tmp[0]}; Layers {0.02}; };
vol_Einsatz[] = tmp[1];
einsatz_out[]=tmp[0];

// Induktor
wz=20;// windungszahl
wd=0.004;// windungsabstand
xw1=0.425;// innenradius ind
xw11=xw1+0.00825;// außenradius eckiger teil
hw=0.0195;// höhe ind
rw1=0.0065;// innenradius runder teil
rw2=rw1+0.00325;// außenradius runder teil
wg=0;

// coil winding
in[]={};
out[]={};
vol_Induktor[] = {};
loop[]={};
For t In {1:wz}

p=newp;
Point(p+1)={xw1,0 ,wg, 0.005};
Point(p+2)={xw11,0 ,wg, 0.005};
Point(p+3)={xw1,0 ,hw+wg, 0.005};
Point(p+4)={xw11,0 ,hw+wg, 0.005};

l=newl;
Line(l+1) = {p+1,p+2};
Line(l+2) = {p+3,p+4};
Line(l+3) = {p+1,p+3};
Line(l+4) = {p+2,p+4};

ll=newll;
Line Loop(ll)={l+1, l+4, -(l+2), -(l+3)};


s=news;

Plane Surface(s) = {ll};
tmp[] = {s};
in[]+=tmp[0];


tmp[] = Extrude { {0,0,y_nenn}, {0,0,0} ,  phi}{ Surface {tmp[0]}; Layers {0.02}; };
vol_Induktor[] += tmp[1];
Physical Volume(Induktor+t) = {tmp[1]};
out[]+=tmp[0];

wg = t*(hw+wd);
loop[]+={ll};
EndFor


// Air
air_in[] = {};
air_out[] = {};
vol_air[] = {};

p=newp;

Point(p+1)={0,0 ,-3*y_nenn, 0.5};
Point(p+2)={4*y_nenn,0 ,-3*y_nenn, 0.5};
Point(p+3)={0,0 ,4*y_nenn, 0.5};
Point(p+4)={4*y_nenn,0 ,4*y_nenn, 0.5};

l=newl;
Line(l+1) = {p+1,p+2};
Line(l+2) = {p+3,p+4};
Line(l+3) = {p+1,1};
Line(l+4) = {3,p+3};
Line(l+5) = {p+2,p+4};

ll=newll;
Line Loop(ll)={l+3, 1, 2, -3, l+4, l+2, -(l+5), -(l+1)};

Line Loop(ll+2)={l+3, 4, l+4, l+2, -(l+5), -(l+1)};
s=news;
loop[]+=ll;
Plane Surface(s) = loop[];

tmp[] = {s};
air_in[]+=tmp[0];

tmp[] = Extrude { {0,0,y_nenn}, {0,0,0} ,  phi}{ Surface {tmp[0]}; Layers {0.02}; };
vol_air[] += tmp[1];
air_out[]+=tmp[0];


Physical Volume(Induktor) = {vol_Induktor[]};
Physical Volume(Einsatz) = {vol_Einsatz[]};
Physical Volume(Air) = {vol_air};

Physical Surface(IN)= in[];
Physical Surface(OUT)= out[];
skin_induktor[]={};
skin_induktor[]=CombinedBoundary{ Volume{vol_Induktor[]}; };
skin_induktor[] -= {in[], out[]};
Physical Surface(SKIN_Induktor) = skin_induktor[];
skin_einsatz[] = {};
skin_einsatz[] = Boundary { Volume{vol_Einsatz[]}; };
skin_einsatz[] -= {einsatz_in[], einsatz_out[]};
Physical Surface(Einsatz_IN)= einsatz_in[];
Physical Surface(Einsatz_OUT)= einsatz_out[];
Physical Surface(SKIN_Einsatz) = skin_einsatz[];

Physical Line(999999) = {84,4, 85};
// axis[]={56, 4, 55};

Physical Surface(Inf_Air) = {1024, 1028, 1031};


Physical Surface(Air_IN)= air_in[];
Physical Surface(Air_OUT)= air_out[];


// Cohomology computation for the A-V method
Cohomology(1) {{Induktor},{IN,OUT}};

// Cohomology computation for the T-O method
// one computation for each winding in order to make each
// cohomology basis function to correspond the current in just one winding
For t In {1:wz}
domain[] = {Induktor+1:Induktor+wz};
domain[] -= Induktor+t;
domain[] += Air;
Cohomology(1) {domain[],{}};
EndFor
