main.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // This code simulates the static mechanical deflection of a 3D disk when a volume
  2. // force is applied. The disk is clamped at its outer face.
  3. #include "sparselizardbase.h"
  4. using namespace mathop;
  5. void sparselizard(void)
  6. {
  7. // The domain regions as defined in 'disk.geo':
  8. int vol = 1, sur = 2, top = 3;
  9. // The mesh can be curved!
  10. mesh mymesh("disk.msh");
  11. // Nodal shape functions 'h1' with 3 components.
  12. // Field u is the membrane deflection.
  13. field u("h1xyz");
  14. // Use interpolation order 3 on 'vol', the whole domain:
  15. u.setorder(vol, 3);
  16. // Clamp on surface 'sur' (i.e. 0 valued-Dirichlet conditions):
  17. u.setconstraint(sur);
  18. // E is Young's modulus. nu is Poisson's ratio.
  19. parameter E, nu;
  20. E|vol = 150e9; nu|vol = 0.3;
  21. formulation elasticity;
  22. // The linear elasticity formulation is classical and thus predefined:
  23. elasticity += integral(vol, predefinedelasticity(dof(u), tf(u), E, nu));
  24. // Add a volumic force in the -z direction:
  25. elasticity += integral(vol, array1x3(0,0,-10)*tf(u));
  26. elasticity.generate();
  27. vec solu = solve(elasticity.A(), elasticity.b());
  28. // Transfer the data from the solution vector to the u field:
  29. u.setdata(vol, solu);
  30. // Write the deflection on the top surface of the membrane.
  31. // Write with an order 3 interpolation. Exaggerate the deflection by a factor 1e9.
  32. (0.5e9*u).write(top, "u.pos", 3);
  33. // Code validation line. Can be removed.
  34. std::cout << (compz(u).integrate(vol, u, 5) < -1.24111e-10 && compz(u).integrate(vol, u, 5) > -1.24113e-10);
  35. }
  36. int main(void)
  37. {
  38. SlepcInitialize(0,{},0,0);
  39. sparselizard();
  40. SlepcFinalize();
  41. return 0;
  42. }