Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module contacts
- integer, parameter :: c_dbl = KIND(1d0)
- integer, parameter :: max_size = 3600;
- type :: contactside
- INTEGER :: n ! size of data in arrays
- REAL(c_dbl) :: elasticity, poisson
- REAL(c_dbl) :: radius(max_size), crown(max_size)
- end type
- contains
- ! FUNCTIONS/SUBROUTINES exported from dll:
- subroutine Hertz(load, side1, side2) BIND(C)
- implicit none
- !DEC$ ATTRIBUTES DLLEXPORT::Hertz
- ! Arguments
- REAL(8),value :: load
- TYPE(contactside) :: side1, side2
- ! Implementation omitted
- end subroutine Hertz
- end module
- public unsafe struct ContactSide
- {
- const int MaxSize = 3600;
- int size;
- double elasticity, poisson;
- fixed double radius[MaxSize], crown[MaxSize];
- public ContactSide(double radius, double crown) : this(new double[] { radius }, crown) { }
- public ContactSide(double[] radius, double crown)
- {
- this.size=radius.Length;
- fixed (double* ptr1 = this.radius, ptr2 = this.crown)
- {
- for(int i = 0; i<size; i++)
- {
- ptr1[i]=radius[i];
- ptr2[i]=crown;
- }
- }
- this.elasticity=DefaultElasticity;
- this.poisson=DefaultPoisson;
- }
- public static double DefaultElasticity = 200000;
- public static double DefaultPoisson = 0.3;
- }
- class Program
- {
- [DllImport("FortranContacts.dll", EntryPoint = "hertz", CallingConvention = CallingConvention.Cdecl)]
- public extern static void Hertz(double load, ref ContactSide side1, ref ContactSide side2);
- static void Main(string[] args)
- {
- ContactSide side1 = new ContactSide(8.0, 1200);
- ContactSide side2 = new ContactSide(new double[] { 22, 22.2, 22.8, 24.6, 25.8, 29.3 }, 10000);
- Hertz(1000, ref side1, ref side2);
- }
- }
- public struct ContactSide
- {
- int size;
- double elasticity, poisson;
- double[] radius, crown;
- public ContactSide(double radius, double crown) : this(new double[] { radius }, crown) { }
- public ContactSide(double[] radius, double crown)
- {
- this.size=radius.Length;
- this.radius=new double[size];
- this.crown=new double[size];
- radius.CopyTo(this.radius, 0);
- this.crown= Enumerable.Repeat(crown, size).ToArray();
- this.elasticity=DefaultElasticity;
- this.poisson=DefaultPoisson;
- }
- public static double DefaultElasticity = 200000;
- public static double DefaultPoisson = 0.3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement