Advertisement
Guest User

Untitled

a guest
May 4th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. module contacts
  2. integer, parameter :: c_dbl = KIND(1d0)
  3. integer, parameter :: max_size = 3600;
  4. type :: contactside
  5. INTEGER :: n ! size of data in arrays
  6. REAL(c_dbl) :: elasticity, poisson
  7. REAL(c_dbl) :: radius(max_size), crown(max_size)
  8. end type
  9.  
  10. contains
  11. ! FUNCTIONS/SUBROUTINES exported from dll:
  12. subroutine Hertz(load, side1, side2) BIND(C)
  13. implicit none
  14. !DEC$ ATTRIBUTES DLLEXPORT::Hertz
  15. ! Arguments
  16. REAL(8),value :: load
  17. TYPE(contactside) :: side1, side2
  18.  
  19. ! Implementation omitted
  20. end subroutine Hertz
  21.  
  22. end module
  23.  
  24. public unsafe struct ContactSide
  25. {
  26. const int MaxSize = 3600;
  27. int size;
  28. double elasticity, poisson;
  29. fixed double radius[MaxSize], crown[MaxSize];
  30. public ContactSide(double radius, double crown) : this(new double[] { radius }, crown) { }
  31. public ContactSide(double[] radius, double crown)
  32. {
  33. this.size=radius.Length;
  34. fixed (double* ptr1 = this.radius, ptr2 = this.crown)
  35. {
  36. for(int i = 0; i<size; i++)
  37. {
  38. ptr1[i]=radius[i];
  39. ptr2[i]=crown;
  40. }
  41. }
  42. this.elasticity=DefaultElasticity;
  43. this.poisson=DefaultPoisson;
  44. }
  45.  
  46. public static double DefaultElasticity = 200000;
  47. public static double DefaultPoisson = 0.3;
  48. }
  49.  
  50. class Program
  51. {
  52. [DllImport("FortranContacts.dll", EntryPoint = "hertz", CallingConvention = CallingConvention.Cdecl)]
  53. public extern static void Hertz(double load, ref ContactSide side1, ref ContactSide side2);
  54.  
  55. static void Main(string[] args)
  56. {
  57. ContactSide side1 = new ContactSide(8.0, 1200);
  58. ContactSide side2 = new ContactSide(new double[] { 22, 22.2, 22.8, 24.6, 25.8, 29.3 }, 10000);
  59.  
  60. Hertz(1000, ref side1, ref side2);
  61.  
  62. }
  63. }
  64.  
  65. public struct ContactSide
  66. {
  67. int size;
  68. double elasticity, poisson;
  69. double[] radius, crown;
  70.  
  71. public ContactSide(double radius, double crown) : this(new double[] { radius }, crown) { }
  72. public ContactSide(double[] radius, double crown)
  73. {
  74. this.size=radius.Length;
  75. this.radius=new double[size];
  76. this.crown=new double[size];
  77. radius.CopyTo(this.radius, 0);
  78. this.crown= Enumerable.Repeat(crown, size).ToArray();
  79. this.elasticity=DefaultElasticity;
  80. this.poisson=DefaultPoisson;
  81. }
  82.  
  83. public static double DefaultElasticity = 200000;
  84. public static double DefaultPoisson = 0.3;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement