SetFactory("OpenCASCADE");
clw=0.03;	clf=0.1;	clv=0.006;
Mesh.CharacteristicLengthMin = clv;
Mesh.CharacteristicLengthMax = clf;

Wvessel=0.8;    bb = 0.01*Wvessel;  Thick = 0.1*Wvessel;
GAP = 3*bb;

Point(1) = {0, 0, 1.0, clf};
Point(2) = {0.8, 0, 1.0, clw};
Point(6) = {0.8, 0, -3, clw};
Point(7) = {0, 0, -3, clf};
Point(8) = {0.8, 0, -0.5, clw};
Point(9) = {1.14, 0, -1.58, clw};
Point(10) = {0.8, 0, -2, clw};
//+
Line(1) = {1, 7};
//+
Point(11) = {0.8, 0, -0.2, clf};
//+
Point(12) = {0.8, 0, -2.2, clf};
//+
Point(13) = { 1.14, 0, -1.5, clw};
//+
Point(14) = { 1.14, 0, -1.6, clw};

//+
Bezier(4) = {2, 11, 8, 13, 9, 14, 10, 12, 6};

//+
Translate {Thick, 0, 0} {
  Duplicata { Line{4}; }
}
//+
Translate {-0.16, 0, 0} {
  Line{5}; 
}
//+
Line(6) = {2, 15};
//+
Line(7) = {15, 1};
//+
Line(8) = {6, 16};
//+
Line(9) = {16, 7};
//+
Line Loop(1) = {5, -8, -4, 6};
//+
Plane Surface(1) = {1};
//+
Line Loop(2) = {1, -9, -5, 7};
//+
Plane Surface(2) = {2};
//+

//+
Extrude {{0, 0, 1}, {0, 0, 1}, Pi} {
  Surface{2}; Surface{1};
}

//+
Circle(20) = { 0.0, 0.0, 4.0, 1.0, Pi/2, Pi};
//+
Point(23) = {0, 1.0+2*bb, 4, clv};
//+
Point(24) = {0, 0, 4, clv};
//+
Point(25) = {-1.0-6*bb, 0, 4, clv};
//+
Ellipse(21) = {25, 24, 25, 23};
//+
Point(26) = {0, 1.0+bb, 4, clv};
//+
Point(27) = {bb, 1.0+bb, 4, clv};
//+
Circle(22) = {22, 26, 27};
//+
Circle(23) = {27, 26, 23};
//+
Line(24) = {25, 21};
//+
Line Loop(11) = {21, -23, -22, -20, -24};
//+
Line Loop(12) = {24, 20, 22, 23, -21};
//+
Plane Surface(11) = {11, 12};
//+
Rotate {{0, 1, 0}, {0, 1, 0}, 3*Pi/2} {
  Surface{11}; 
}
//+
Rotate {{0, 0, 1}, {0, 0, 1}, Pi} {
  Surface{11}; 
}

//+
Translate {-7, 1.0 + GAP + 2*bb, -1.1 }{
  Surface{11}; 
}

//+
Extrude {6, 0, 0} {
  Surface{11};
}

//+
BooleanUnion{ Volume{1}; }{ Volume{2}; Delete; }//Output volume4
//+
BooleanFragments{ Volume{4}; Delete; }{ Volume{1}; Delete; }


//+
BooleanFragments{ Volume{1}; Delete; }{ Volume{3}; Delete; }
//+
Recursive Delete {
  Volume{7}; 
}
//+
Recursive Delete {
  Volume{8}; 
}
//+
BooleanUnion{ Volume{4}; Volume{5}; }{ Volume{6}; Delete; }
//+
BooleanFragments{ Volume{4}; Volume{5}; Delete; }{ Volume{6}; Delete; }

Characteristic Length{ PointsOf{ Volume{5}; } } = clf;
Characteristic Length{ PointsOf{ Volume{4}; } } = clw;
Characteristic Length{ PointsOf{ Volume{6}; } } = clv;

//+
Physical Volume("FLUID") = {5};
//+
Physical Volume("VALVE") = {6};
//+
Physical Volume("WALL") = {4};
//+
Physical Surface("inlet") = {23};
//+
Physical Surface("outlet") = {27};
//+
Physical Surface("wfix") = {22, 18};
//+
Physical Surface("wall") = {19, 33, 30};
//+
Physical Surface("move") = {28, 32, 29, 31};
//+
Physical Surface("CENTER") = {20, 25, 26, 21};

/*
Field[1] = MathEval;
Field[1].F = "0.03";

Field[2] = Restrict;
Field[2].IField = 1;
Field[2].FacesList = {28, 32, 29, 31, 30};

Background Field = 2;
*/
