-- FreeFem++ v4.14 (mer. 06 mars 2024 16:59:04 CET - git v4.14-1-g2b2052ae) file : microwave.edp Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // microwave.edp 2 : // 3 : // Discussion: 4 : // 5 : // This example solves equations related to a model of a microwave cooker. 6 : // 7 : // Licensing: 8 : // 9 : // This code is distributed under the MIT license. 10 : // 11 : // Modified: 12 : // 13 : // 18 February 2015 14 : // 15 : // Author: 16 : // 17 : // An example from the FreeFem++ manual. 18 : // Modifications and comments by John Burkardt. 19 : // 20 : // Reference: 21 : // 22 : // Frederic Hecht, 23 : // Freefem++, 24 : // Third Edition, version 3.22 25 : // 26 : cout << "\n"; 27 : cout << "microwave():\n"; 28 : cout << " FreeFem++ version\n"; 29 : cout << " Simulation of a microwave food processor.\n"; 30 : // 31 : // These parameters are used to define the boundaries. 32 : // 33 : real a = 20.0; 34 : real b = 20.0; 35 : real c = 15.0; 36 : real d = 8.0; 37 : real e = 2.0; 38 : real l = 12.0; 39 : real f = 2.0; 40 : real g = 2.0; 41 : // 42 : // Define the line segments A0, A1, A2, A3, A4, A5 of the external boundary. 43 : // Segment A4 (label = 2 ) is where the nonzero wave will be emitted. 44 : // 45 : // Y 46 : // | 47 : // 20 +--------A2------------+ 48 : // | | | 49 : // | A3 | 50 : // | | | 51 : // | A4 A1 52 : // | | | 53 : // | A5 | 54 : // | | | 55 : // 0 +--------A0------------+ 56 : // | 57 : // +--0---------------------20----X 58 : // 59 : border a0 (t=0,1) { x=a*t; y=0.0; label=1; } 60 : border a1 (t=1,2) { x=a; y=b*(t-1.0); label=1; } 61 : border a2 (t=2,3) { x=a*(3.0-t); y=b; label=1; } 62 : border a3 (t=3,4) { x=0.0; y=b-(b-c)*(t-3.0); label=1; } 63 : border a4 (t=4,5) { x=0.0; y=c-(c-d)*(t-4.0); label=2; } 64 : border a5 (t=5,6) { x=0.0; y=d*(6.0-t); label=1; } 65 : // 66 : // Define the line segments B0, B1, B2, B3, of the internal interface. 67 : // 68 : // Y 69 : // | 70 : // 20 +----------------------+ 71 : // | | | 72 : // | | | 73 : // 14 | +B2+ | 74 : // | | B3 | | 75 : // | | | B1 | 76 : // 2 | +B0+ | 77 : // | | | 78 : // 0 +----------------------+ 79 : // | 80 : // +--0---------------16-18-20----X 81 : // 82 : border b0 (t=0,1) { x=a-f+e*(t-1.0); y=g; label=3; } 83 : border b1 (t=1,4) { x=a-f; y=g+l*(t-1.0)/3.0; label=3; } 84 : border b2 (t=4,5) { x=a-f-e*(t-4.0); y=l+g; label=3; } 85 : border b3 (t=5,8) { x=a-e-f; y= l+g-l*(t-5.0)/3.0; label=3; } 86 : // 87 : // Compute a mesh by filling in the line segments with a given number of 88 : // points. The value of N controls how fine the lines are. 89 : // 90 : int n = 2; 91 : mesh Th = buildmesh ( 92 : a0 ( 10 * n ) + a1 ( 10 * n) + a2 ( 10 * n ) + a3 ( 10 * n ) 93 : + a4 ( 10 * n ) + a5 ( 10 * n ) 94 : + b0 ( 5 * n ) + b1 ( 10 * n ) + b2 ( 5 * n ) + b3 ( 10 * n ) ); 95 : // 96 : // Plot the mesh. 97 : // 98 : plot ( Th, ps = "microwave_mesh.ps", cmm = "microwave: mesh", wait = true ); 99 : // 100 : // Use a finite element space of piecewise linear functions on mesh Th. 101 : // 102 : fespace Vh ( Th, P1 ); 103 : // 104 : // The mesh is naturally divided into two regions. 105 : // We can request a "label" for a region by specifying a point inside that region. 106 : // The command 107 : // "meat = Th ( xm, ym ).region" 108 : // returns, as the value "meat", the label that FreeFem++ uses to identify 109 : // the portion of the mesh that contains (xm,ym), which happens to be the 110 : // region we think of as the meat. Similarly, we can choose a point (xa,ya) 111 : // that lies in the other region, to get the label for the "air" portion 112 : // of our problem. 113 : // 114 : real xm = 17.0; 115 : real ym = 8.0; 116 : real meat = Th ( xm, ym ).region; 117 : 118 : real xa = 0.01; 119 : real ya = 0.01; 120 : real air = Th ( xa, ya ).region; 121 : // 122 : // Now that we have the numeric labels "meat" and "air", we can 123 : // define R, a finite element interpolant function, which will be 124 : // 1 in the meat region and 0 in the air region: 125 : // 126 : Vh R = ( region - air ) / ( meat - air ); 127 : // 128 : // Our unknown electromagnetic function is complex valued. 129 : // U1 will be our solution function, and V1 our test function. 130 : // 131 : Vh u1; 132 : Vh v1; 133 : // 134 : // Solve for the electromagnetic function U1, using test function V1. 135 : // 136 : // The boundary condition is mostly zero, but over the boundary segment 137 : // with label 2, there is a real-valued sinusoidal boundary condition. 138 : // 139 : solve muwave ( u1, v1 ) = 140 : int2d(Th) ( u1 * v1 * ( 1.0 + R ) 141 : - ( dx(u1)*dx(v1)+dy(u1)*dy(v1)) * ( 1.0 - 0.5i ) ) 142 : + on ( 1, u1 = 0.0 ) 143 : + on ( 2, u1 = sin(pi*(y-c)/(c-d)) ); 144 : // 145 : // Define the real and imaginary parts of U1, so we can plot them, 146 : // and so we can write a formula for the magnitude of the signal. 147 : // 148 : Vh u1r = real ( u1 ); 149 : Vh u1i = imag ( u1 ); 150 : Vh u1mag; 151 : // 152 : // Plot the real and imaginary portions of the solution. 153 : // 154 : u1mag = sqrt ( u1r^2 + u1i^2 ); 155 : 156 : plot ( u1r, wait = true, cmm = "microwave: real part of signal", 157 : ps = "microwave_r.ps", fill = true ); 158 : plot ( u1i, wait = true, cmm = "microwave: imaginary part of signal", 159 : ps = "microwave_i.ps", fill = true ); 160 : plot ( u1mag, wait = true, cmm = "microwave: signal magnitude", 161 : ps = "microwave_mag.ps", fill = true ); 162 : // 163 : // Now we use the microwave solution (u1r,u1i) to solve the second problem, 164 : // for the temperature distribution U2 over the region. 165 : // 166 : fespace Uh ( Th, P1 ); 167 : // 168 : // U2 is our solution (a real valued function), and V2 is our test function. 169 : // 170 : Uh u2; 171 : Uh v2; 172 : // 173 : // The right hand side of the equations is FF, which is proportional to 174 : // the square of the signal intensity. However, we want FF to only be 175 : // nonzero within the meat region, so we multiply by R, the function 176 : // that is 0 outside the meat. 177 : // 178 : Uh ff = 100000.0 * ( u1r^2 + u1i^2 ) * R; 179 : // 180 : // Now we can solve the usual heat equation for the temperature U2, 181 : // using test function V2, over the whole microwave region, 182 : // using a right hand side FF that is zero outside the meat region. 183 : // 184 : solve temperature ( u2, v2 ) = 185 : int2d(Th) ( dx(u2)* dx(v2) + dy(u2)* dy(v2) ) 186 : - int2d(Th) ( ff * v2 ) 187 : + on ( 1, u2 = 0.0 ) 188 : + on ( 2, u2 = 0.0 ); 189 : // 190 : // Plot the temperature. 191 : // 192 : plot ( u2, wait = true, cmm = "microwave: temperature", ps = "microwave_t.ps", fill = true ); 193 : // 194 : // Terminate. 195 : // 196 : cout << "\n"; 197 : cout << "microwave():\n"; 198 : cout << " Normal end of execution.\n"; 199 : 200 : exit ( 0 ); 201 : 202 : sizestack + 1024 =5016 ( 3992 ) microwave(): FreeFem++ version Simulation of a microwave food processor. -- mesh: Nb of Triangles = 2622, Nb of Vertices 1372 -- Solve : min (-0.999958,-0.612153) max (0.353414,0.211093) -- Solve : min 2.37625e-62 max 13.8706 microwave(): Normal end of execution. current line = 200 exit(0) err code 0 , mpirank 0 CodeAlloc : nb ptr 4444, size :545560 mpirank: 0 Ok: Normal End