main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // This code simulates the Stokes flow of a viscous fluid (water) in a microvalve.
  2. // Reynold's number rho*v*L/mu is very low so that the inertia terms can be neglected.
  3. // The fluid is considered incompressible.
  4. //
  5. // This code can be validated with analytical solutions of a flow between two
  6. // infinite parallel plates with a thin gap. Only the geometry has to be adapted.
  7. #include "sparselizardbase.h"
  8. using namespace mathop;
  9. mesh createmesh(void);
  10. void sparselizard(void)
  11. {
  12. // Define the physical regions that will be used:
  13. int support = 1, fluid = 2, pillar = 3, membrane = 4, inlet = 7, outlet = 8;
  14. // Create the geometry and the mesh:
  15. mesh mymesh = createmesh();
  16. // Write the mesh for display:
  17. mymesh.write("microvalve.msh");
  18. // Define the fluid boundary as the intersection between the solid and the fluid regions:
  19. int solid = regionunion({pillar,support,membrane});
  20. int fluidboundary = regionintersection({fluid,solid});
  21. // Dynamic viscosity of water [Pa.s] and density [kg/m3]:
  22. double mu = 8.9e-4, rho = 1000;
  23. // Field v is the flow velocity. It uses nodal shape functions "h1" with two components.
  24. // Field p is the relative pressure.
  25. field v("h1xy"), p("h1");
  26. // Force the flow velocity to 0 at the solid interface:
  27. v.setconstraint(fluidboundary);
  28. // Set a relative pressure of 100 Pa at the valve inlet and 0 at the outlet:
  29. p.setconstraint(inlet, 100);
  30. p.setconstraint(outlet);
  31. // Use an order 1 interpolation for p and 2 for v on the fluid region:
  32. p.setorder(fluid, 1);
  33. v.setorder(fluid, 2);
  34. // Define the weak formulation of the Stokes flow problem.
  35. // The strong form can be found at https://en.wikipedia.org/wiki/Stokes_flow
  36. formulation viscousflow;
  37. viscousflow += integral(fluid, predefinedstokes(dof(v), tf(v), dof(p), tf(p), mu, rho, 0, 0) );
  38. // Generate, solve and save:
  39. solve(viscousflow);
  40. // Write the p and v fields to file. Write v with an order 2 interpolation.
  41. p.write(fluid, "p.vtk");
  42. v.write(fluid, "v.vtk", 2);
  43. // Output the flowrate for a unit width:
  44. double flowrate = (normal(inlet)*v).integrate(inlet, 4);
  45. std::cout << std::endl << "Flowrate for a unit width: " << flowrate << " m^3/s" << std::endl;
  46. // Code validation line. Can be removed.
  47. std::cout << (flowrate < 1.4845e-7 && flowrate > 1.4844e-7);
  48. }
  49. mesh createmesh(void)
  50. {
  51. // Give names to the physical region numbers:
  52. int support = 1, fluid = 2, pillar = 3, membrane = 4, inlet = 7, outlet = 8;
  53. // Define the x and y geometrical dimensions:
  54. double y1 = 15e-6, y2 = 25e-6, y3 = 30e-6;
  55. double x1 = -100e-6, x2 = -50e-6, x3 = -25e-6, x4 = 25e-6, x5 = 50e-6, x6 = 100e-6;
  56. // Define the mesh finesse:
  57. int n = 10;
  58. shape q1("quadrangle", support, {x1,0,0, x2,0,0, x2,y1,0, x1,y1,0}, {n,n,n,n});
  59. shape q2("quadrangle", support, {x5,0,0, x6,0,0, x6,y1,0, x5,y1,0}, {n,n,n,n});
  60. shape q3("quadrangle", fluid, {x2,0,0, x3,0,0, x3,y1,0, x2,y1,0}, {n,n,n,n});
  61. shape q4("quadrangle", fluid, {x4,0,0, x5,0,0, x5,y1,0, x4,y1,0}, {n,n,n,n});
  62. shape q5("quadrangle", pillar, {x3,0,0, x4,0,0, x4,y1,0, x3,y1,0}, {n,n,n,n});
  63. shape q6("quadrangle", support, {x1,y1,0, x2,y1,0, x2,y2,0, x1,y2,0}, {n,n,n,n});
  64. shape q7("quadrangle", support, {x5,y1,0, x6,y1,0, x6,y2,0, x5,y2,0}, {n,n,n,n});
  65. shape q8("quadrangle", fluid, {x2,y1,0, x3,y1,0, x3,y2,0, x2,y2,0}, {n,n,n,n});
  66. shape q9("quadrangle", fluid, {x4,y1,0, x5,y1,0, x5,y2,0, x4,y2,0}, {n,n,n,n});
  67. shape q10("quadrangle", fluid, {x3,y1,0, x4,y1,0, x4,y2,0, x3,y2,0}, {n,n,n,n});
  68. shape q11("quadrangle", membrane, {x1,y2,0, x2,y2,0, x2,y3,0, x1,y3,0}, {n,n,n,n});
  69. shape q12("quadrangle", membrane, {x5,y2,0, x6,y2,0, x6,y3,0, x5,y3,0}, {n,n,n,n});
  70. shape q13("quadrangle", membrane, {x2,y2,0, x3,y2,0, x3,y3,0, x2,y3,0}, {n,n,n,n});
  71. shape q14("quadrangle", membrane, {x4,y2,0, x5,y2,0, x5,y3,0, x4,y3,0}, {n,n,n,n});
  72. shape q15("quadrangle", membrane, {x3,y2,0, x4,y2,0, x4,y3,0, x3,y3,0}, {n,n,n,n});
  73. // Get the inlet and outlet lines:
  74. shape l1 = q3.getsons()[0];
  75. shape l2 = q4.getsons()[0];
  76. l1.setphysicalregion(inlet);
  77. l2.setphysicalregion(outlet);
  78. // Provide to the mesh all shapes of interest:
  79. mesh mymesh({q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15,l1,l2});
  80. return mymesh;
  81. }
  82. int main(void)
  83. {
  84. SlepcInitialize(0,{},0,0);
  85. sparselizard();
  86. SlepcFinalize();
  87. return 0;
  88. }