main.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // This example shows how to set up a piezoresistive - elasticity simulation for a given silicon crystal orientation.
  2. // As the silicon cantilever deflects the conduction current adapts due to a piezoresistive-induced change of the resistivity.
  3. // The example also shows how to perform a field interpolation between two non-matching meshes.
  4. //
  5. // The piezoresistivity matrix was obtained from paper "Review: Semiconductor Piezoresistance for Microsystems", A. Barlian et al.
  6. //
  7. // Taking care of geometric nonlinearity (not needed here) and prestress can be easily done by calling the appropriate
  8. // 'predefinedelasticity' function, creating a nonlinear iteration to solve the mechanical problem and using the
  9. // 'greenlagrangestrain' function instead of the 'strain' function to correctly compute the strains (see documentation and examples).
  10. #include "sparselizardbase.h"
  11. using namespace mathop;
  12. // First arguments give the geometry size, last arguments give the number of nodes for meshing.
  13. mesh createmesh(double length, double width, double thsi, double tracetilt, double ltrace, double wtrace, double rtrace, double thtrace, int numtraces, int nx, int ny, int nz, int nltrace, int nwtrace, int nthtrace);
  14. void sparselizard(void)
  15. {
  16. int silicon = 1, trace = 2, electrode = 3, ground = 4, clamp = 5;
  17. // Create the two non-matching meshes:
  18. mesh mymesh = createmesh(200e-6, 100e-6, 10e-6, 30, 60e-6, 2e-6, 1e-6, 2e-6, 6, 20, 10, 5, 10, 4, 3);
  19. mymesh.write("straingauge.msh");
  20. // Nodal shape functions 'h1' for v (the electric potential) and u
  21. // (the mechanical displacement). Three components are used for u. Field u is
  22. // the displacement field in the silicon, field ugauge in the strain gauge.
  23. field u("h1xyz"), ugauge("h1xyz"), v("h1");
  24. // Use interpolation order 2 for u and for v:
  25. u.setorder(silicon, 2);
  26. u.setorder(trace, 2);
  27. ugauge.setorder(trace, 2);
  28. v.setorder(trace, 2);
  29. // Clamp on surface 'clamp' (i.e. 0 valued-Dirichlet conditions):
  30. u.setconstraint(clamp);
  31. v.setconstraint(electrode, 10);
  32. v.setconstraint(ground, 0);
  33. // Piezoresistivity 'Pi' [1/Pa] matrix aligned with the silicon crystal.
  34. // In this case it is symmetric and thus only the lower triangular part is provided:
  35. expression Pi(6,6,{6.6, -1.1,6.6, -1.1,-1.1,6.6, 0,0,0,138.1, 0,0,0,0,138.1, 0,0,0,0,0,138.1});
  36. Pi = Pi * 1e-11;
  37. // Multiply Pi by the unstressed resistivity to have an equation for the resistivity variation (and not the relative change).
  38. // The unstressed resistivity is 7.8e-2 Ohm*m. Pi has now units m^4/(s*A^2) or Ohm*m/Pa.
  39. double rhounstressed = 7.8e-2;
  40. Pi = Pi * rhounstressed;
  41. // Bring the Pi matrix to a 45 degrees crystal orientation.
  42. // Refer to the documentation to make sure you understand how to use 'rotate'!
  43. Pi.rotate(0,0,45,"K","K-1");
  44. // Anisotropic elasticity matrix [Pa] for silicon. Ordering is [exx,eyy,ezz,gyz,gxz,gxy] (Voigt form).
  45. // Only the lower triangular part (top to bottom and left to right) is provided since it is symmetric.
  46. expression H(6,6, {194.5e9, 35.7e9,194.5e9, 64.1e9,64.1e9,165.7e9, 0,0,0,79.6e9, 0,0,0,0,79.6e9, 0,0,0,0,0,50.9e9});
  47. // Resistivity change for the stressed silicon crystal (piezoelectric):
  48. expression deltarho = Pi * H*strain(ugauge);
  49. // Add the unstressed diagonal resistivity tensor in Voigt form:
  50. expression rhos = deltarho + expression(6,1,{rhounstressed,rhounstressed,rhounstressed,0,0,0});
  51. // Bring the resistivity from Voigt to 3x3 tensor form for inversion.
  52. // Only the lower triangular part is provided since the tensor is here symmetric.
  53. expression rho = expression(3,3, {rhos.at(0,0),rhos.at(5,0),rhos.at(1,0),rhos.at(4,0),rhos.at(3,0),rhos.at(2,0)});
  54. // The conductivity sigma [S/m] is the inverse of the resistivity:
  55. expression sigma = inverse(rho);
  56. // Mechanical formulation:
  57. formulation elasticity;
  58. // Orthotropic elasticity in the silicon:
  59. elasticity += integral(silicon, predefinedelasticity(dof(u), tf(u), H) );
  60. // Add a volume force [N/m^3] to deflect the cantilever:
  61. elasticity += integral(silicon, -1e11*compz(tf(u)) );
  62. // Define the weak formulation for the conduction current flow.
  63. //
  64. // The strong form is:
  65. //
  66. // div(1/rho * grad(v)) = 0
  67. //
  68. // with E = -grad(v)
  69. //
  70. formulation currentflow;
  71. currentflow += integral(trace, grad(tf(v))*(sigma*grad(dof(v))));
  72. // First solve the mechanic problem to get the stresses:
  73. solve(elasticity);
  74. // Transfer the deflection u to the ugauge field using mesh-to-mesh interpolation:
  75. ugauge.setvalue(trace, on(silicon, u));
  76. // Solve the DC current flow problem:
  77. solve(currentflow);
  78. // Expression for the electric field E [V/m] and current density j [A/m^2]:
  79. expression E = -grad(v);
  80. expression j = sigma * E;
  81. // Write the fields to file:
  82. u.write(silicon, "u.vtk", 2);
  83. ugauge.write(trace, "ugauge.vtk", 2);
  84. v.write(trace, ugauge, "v.vtk", 2);
  85. // Output the total current [A] flowing through the electrode.
  86. // The normal current density must be integrated on the whole electrode surface.
  87. // Since j requires calculating volume derivatives its evaluation must be performed on the 'trace' volume region.
  88. double I = (-normal(electrode)*on(trace, j)).integrate(electrode, 4);
  89. std::cout << "Input current = " << I << " A at a peak deflection of " << norm(u).max(silicon,3)[0]*1e6 << " um" << std::endl;
  90. // Code validation line. Can be removed.
  91. std::cout << (I < 6.10165e-07 && I > 6.10163e-07);
  92. }
  93. mesh createmesh(double length, double width, double thsi, double tracetilt, double ltrace, double wtrace, double rtrace, double thtrace, int numtraces, int nx, int ny, int nz, int nltrace, int nwtrace, int nthtrace)
  94. {
  95. int silicon = 1, trace = 2, electrode = 3, ground = 4, clamp = 5;
  96. // Create the cantilever:
  97. shape footprint("quadrangle", -1, {0,0,0, length,0,0, length,width,0, 0,width,0}, {nx,ny,nx,ny});
  98. shape si = footprint.extrude(silicon, thsi, nz);
  99. shape clmp = si.getsons()[4];
  100. clmp.setphysicalregion(clamp);
  101. // Create the strain gauge:
  102. shape q("quadrangle", -1, {0,0,0, ltrace,0,0, ltrace,wtrace,0, 0,wtrace,0}, {nltrace,nwtrace,nltrace,nwtrace});
  103. shape ain("arc", -1, {ltrace,wtrace,0, ltrace,wtrace+2.0*rtrace,0, ltrace,wtrace+rtrace,0}, nltrace);
  104. shape aout("arc", -1, {ltrace,0,0, ltrace,2.0*wtrace+2.0*rtrace,0, ltrace,wtrace+rtrace,0}, nltrace);
  105. shape ln("line", -1, {ltrace,wtrace+2.0*rtrace,0, ltrace,2.0*wtrace+2.0*rtrace,0}, nwtrace);
  106. shape qcurve("quadrangle", -1, {q.getsons()[1],aout,ln,ain});
  107. shape oneside("union", -1, {q,qcurve});
  108. shape otherside = oneside.duplicate();
  109. otherside.scale(-1,1,1);
  110. otherside.shift(ltrace, wtrace+2.0*rtrace,0);
  111. shape tracepiece("union", -1, {oneside, otherside});
  112. std::vector<shape> pieces(numtraces);
  113. for (int i = 0; i < numtraces; i++)
  114. {
  115. pieces[i] = tracepiece.duplicate();
  116. pieces[i].shift(0,2.0*(wtrace+2.0*rtrace)*i,0);
  117. }
  118. shape tracefootprint("union", -1, pieces);
  119. // Center:
  120. tracefootprint.shift(-ltrace/2,-numtraces/2*(4*rtrace+2*wtrace),0);
  121. shape trc = tracefootprint.extrude(trace, thtrace, nthtrace);
  122. trc.rotate(0,0,tracetilt);
  123. trc.shift(length/2, width/2, thsi-thtrace);
  124. // Get the electrode and ground faces:
  125. shape el = trc.getsons()[0].getsons()[0].getsons()[0].getsons()[4];
  126. el.setphysicalregion(electrode);
  127. shape gr = trc.getsons()[numtraces-1].getsons()[1].getsons()[1].getsons()[3];
  128. gr.setphysicalregion(ground);
  129. mesh mymesh({si,clmp,trc,el,gr});
  130. return mymesh;
  131. }
  132. int main(void)
  133. {
  134. SlepcInitialize(0,{},0,0);
  135. sparselizard();
  136. SlepcFinalize();
  137. return 0;
  138. }