Пример #1
0
int main(){


  Lgm_Vector      a, b, z1, z2;
    Lgm_SlerpInfo   s;
    double          alpha;

    a.x = 1.0; a.y = 1.0; a.z = 1.0;
    b.x = 0.0; b.y = -1.0; b.z = 1.0;

    Lgm_NormalizeVector( &a );
    Lgm_NormalizeVector( &b );

    Lgm_InitSlerp( &a, &b, &s );
    

    alpha = 0.1;
    Lgm_Slerp( &a, &b, &z1, alpha, &s );

    printf("Results of slerping:\n");
    Lgm_PrintVector(&a);
    Lgm_PrintVector(&b);
    Lgm_PrintVector(&z1);

    z2.x = (1.0-alpha)*a.x + alpha*b.x;
    z2.y = (1.0-alpha)*a.y + alpha*b.y;
    z2.z = (1.0-alpha)*a.z + alpha*b.z;
    Lgm_NormalizeVector( &z2 );

    printf("Results of interpolating components (and re-normalizing):\n");
    Lgm_PrintVector(&a);
    Lgm_PrintVector(&b);
    Lgm_PrintVector(&z2);

    Lgm_VecSub(&a, &z1, &z2); 
    printf("\nThey are different by:\n");
    Lgm_PrintVector(&a);

    return(0);


}
Пример #2
0
int main(){


    long int            Date;
    double              UTC;
    Lgm_Vector          u, B, CurlB;
    Lgm_MagModelInfo    *mInfo;
    int                 i, j;


    Date = 20050831;
    UTC  = 9.0;

    mInfo = Lgm_InitMagInfo( );
    Lgm_Set_Coord_Transforms( Date, UTC, mInfo->c );

   mInfo->Bfield = Lgm_B_TS04;
//mInfo->Bfield = Lgm_B_OP77;
//mInfo->Bfield = Lgm_B_T89;
    mInfo->Bfield = Lgm_B_TS04;
    mInfo->Bfield = Lgm_B_igrf;
    mInfo->Bfield = Lgm_B_cdip;
    mInfo->Bfield = Lgm_B_edip;
    mInfo->Bfield = Lgm_B_T89;
    mInfo->P      = 4.1011111111111118;
    mInfo->Dst    = 7.7777777777777777;
    mInfo->By     = 3.7244444444444444;
    mInfo->Bz     = -0.12666666666666665;
    mInfo->W[0]   = 0.12244444444444445;
    mInfo->W[1]   = 0.2514;
    mInfo->W[2]   = 0.089266666666666661;
    mInfo->W[3]   = 0.047866666666666668;
    mInfo->W[4]   = 0.22586666666666666;
    mInfo->W[5]   = 1.0461333333333334;


    printf("%13s", "Kp");
    printf(" %13s", "Ux (Re)");
    printf(" %13s", "Uy (Re)");
    printf(" %13s", "Uz (Re)");
    printf(" %13s", "Bx (nT)");
    printf(" %13s", "By (nT)");
    printf(" %13s", "Bz (nT)");
    printf(" %13s", "Bmag (nT)");
    printf(" %16s", "CurlB_x (nT/Re)");
    printf(" %16s", "CurlB_y (nT/Re)");
    printf(" %16s", "CurlB_z (nT/Re)\n");


    for (i=0; i<=5; i++) {
        mInfo->Kp = i;
        u.x = -6.6; u.y =  0.0;  u.z =  0.0;
        mInfo->Bfield( &u, &B, mInfo );
        Lgm_CurlB( &u, &CurlB, LGM_DERIV_SIX_POINT, 1e-3, mInfo );
        printf( "%13i", mInfo->Kp);
        printf( " %13g %13g %13g", u.x, u.y, u.z );
        printf( " %13g %13g %13g", B.x, B.y, B.z );
        printf( " %13g", Lgm_Magnitude( &B ) );
        printf( " %16g %16g %16g \n", CurlB.x, CurlB.y, CurlB.z );
    }

    for (j=0; j<100; j++){
        mInfo->Kp = 3;
        for (i=0; i<13; i++) {
            u.x = -1. - (double)i * 0.5;
            u.y =  1.0;  u.z =  -1.0;
            mInfo->Bfield( &u, &B, mInfo );
            Lgm_CurlB( &u, &CurlB, LGM_DERIV_SIX_POINT, 1e-3, mInfo );
            printf( "%13i", mInfo->Kp);
            printf( " %13g %13g %13g", u.x, u.y, u.z );
            printf( " %13g %13g %13g", B.x, B.y, B.z );
            printf( " %13g", Lgm_Magnitude( &B ) );
            printf( " %16g %16g %16g \n", CurlB.x, CurlB.y, CurlB.z );
        }
    }



    {
      Lgm_Vector v;

      mInfo->Lgm_VelStep_T = 100e-3; // 100keV
      mInfo->Lgm_VelStep_q = -LGM_e; // electron change
      mInfo->Lgm_VelStep_E0 = LGM_Ee0; // electron mass
      mInfo->Lgm_VelStep_Bm = sqrt(B.x*B.x + B.y*B.y + B.z*B.z);  // b mirror [nT]
      mInfo->Lgm_VelStep_h = 1e-3;  // step size in Re
      mInfo->Lgm_VelStep_DerivScheme = LGM_DERIV_FOUR_POINT;

      printf("\nT=%lf q=%lf E0=%lf Bm=%lf h=%lf DerivScheme=%d\n", 
	     mInfo->Lgm_VelStep_T, 
	     mInfo->Lgm_VelStep_q, mInfo->Lgm_VelStep_E0, mInfo->Lgm_VelStep_Bm, mInfo->Lgm_VelStep_h, 
	     mInfo->Lgm_VelStep_DerivScheme );


      Lgm_GradAndCurvDriftVel(&u, &v, mInfo);
      printf("\nThe drift velocity [km/s in GSM] for a locally mirroring 100 keV electron is:\n");
      Lgm_PrintVector(&v);
    }


    Lgm_FreeMagInfo( mInfo );


    exit(0);
}
Пример #3
0
int main( ) {

    Lgm_CTrans        *c = Lgm_init_ctrans( 0 ); 
    Lgm_JPLephemInfo  *jpl = Lgm_InitJPLephemInfo( 421, LGM_DE_SUN|LGM_DE_EARTHMOON|LGM_DE_OUTERPLANETS, 1);
    Lgm_Vector        Uicrf, pyResult1, pyResult2, pyResult3;
    long int          Date;
    double            UTC, JD;
    
    Date = 20170101;              // Jan 1, 2017
    UTC  = 12.0+0.0/60.0;         // Universal Time Coordinated (in decimal hours)
    pyResult1.x =  506274.15309483; //Sun (wrt solar sys barycenter)
    pyResult1.y =  550063.81126863; 
    pyResult1.z =  213030.58611033;
    pyResult2.x =  -27645517.94343229; //Earth-Moon barycenter (wrt solar sys barycenter)
    pyResult2.y =  133019570.59230532;
    pyResult2.z =  57639804.30457275;
    pyResult3.x =  1445862314.051871; //Pluto
    pyResult3.y =  -4400572504.816436;
    pyResult3.z =  -1808918123.981852;

    // Set up all the necessary variables to do transformations for this Date and UTC
    Lgm_Set_Coord_Transforms( Date, UTC, c );
    JD = Lgm_Date_to_JD( Date, UTC, c);
    Lgm_ReadJPLephem( jpl );
    Lgm_JPLephem_position( JD, LGM_DE_SUN, jpl, &Uicrf);

    // Test a few planets for this time
    printf("DE %d\n",jpl->DEnum);
    printf("Date, UTC = %8ld %lf\n", Date, UTC);
    printf("JD  = %lf\n", JD);
    printf("Sun Position (ICRF): ");
    Lgm_PrintVector(&Uicrf);
    printf("Difference from expected result = %g %g %g\n\n", Uicrf.x-pyResult1.x, Uicrf.y-pyResult1.y, Uicrf.z-pyResult1.z);

    Lgm_JPLephem_position( JD, LGM_DE_EARTHMOON, jpl, &Uicrf);
    printf("Earth-Moon Barycenter Position (ICRF): ");
    Lgm_PrintVector(&Uicrf);
    printf("Difference from expected result = %g %g %g\n\n", Uicrf.x-pyResult2.x, Uicrf.y-pyResult2.y, Uicrf.z-pyResult2.z);
//    Lgm_JPL_getSunVector( JD, jpl, &Uicrf);
//    printf("Earth-Sun Vector: ");
//    Lgm_PrintVector(&Uicrf);


    Lgm_JPLephem_position( JD, LGM_DE_PLUTO, jpl, &Uicrf);
    printf("Pluto Position (ICRF): ");
    Lgm_PrintVector(&Uicrf);
    printf("Difference from expected result = %g %g %g\n\n", Uicrf.x-pyResult3.x, Uicrf.y-pyResult3.y, Uicrf.z-pyResult3.z);

    //Test Sun position for different time
    Date = 19821111;              // Jan 1, 2017
    UTC  = 11.0+0.0/60.0;         // Universal Time Coordinated (in decimal hours)
    pyResult1.x =  922949.0261094079; //Sun (wrt solar sys barycenter)
    pyResult1.y = 1047536.3872436787;
    pyResult1.z =  414153.2146306878;

    Lgm_Set_Coord_Transforms( Date, UTC, c );
    JD = Lgm_Date_to_JD( Date, UTC, c);
    Lgm_JPLephem_position( JD, LGM_DE_SUN, jpl, &Uicrf);

    printf("Date, UTC = %8ld %lf\n", Date, UTC);
    printf("JD  = %lf\n", JD);
    printf("Sun Position (ICRF): ");
    Lgm_PrintVector(&Uicrf);
    printf("Difference from expected result = %g %g %g\n\n", Uicrf.x-pyResult1.x, Uicrf.y-pyResult1.y, Uicrf.z-pyResult1.z);

    Lgm_free_ctrans( c ); // free the structure
    Lgm_FreeJPLephemInfo( jpl ); // free the structure

    return(0);
    }
Пример #4
0
int main(void) {
  Lgm_Vector *v, *v2;
  double Lat, Lon, r, ang;
  double Arr[3];

  printf("Make a Vector:\n");
  v = Lgm_CreateVector(1,2,3);
  Lgm_PrintVector(v);

  printf("Normalize it:\n");
  Lgm_NormalizeVector(v);
  Lgm_PrintVector(v);

  printf("Force it to have a magnitude:\n");
  Lgm_ForceMagnitude(v, 2);
  Lgm_PrintVector(v);

  printf("Set its value:\n");
  Lgm_SetVecVal(v, 3);
  Lgm_PrintVector(v);

  printf("Set its elements:\n");
  Lgm_SetVecElements(v, 1,2,3);
  Lgm_PrintVector(v);

  printf("Change it to spherical:\n");
  Lgm_CartToSphCoords(v, &Lat, &Lon, &r);
  printf("Lat:%lf Lon:%lf r:%lf\n", Lat, Lon, r);

  printf("And back to Cart:\n");
  Lgm_SphToCartCoords(Lat, Lon, r, v );
  Lgm_PrintVector(v);

  printf("Make it an array:\n");
  Lgm_VecToArr(v, Arr);
  printf("Arr[0]:%lf Arr[1]:%lf Arr[2]:%lf\n", Arr[0], Arr[1], Arr[2]);

  printf("Edit the array and make it a vector:\n");
  Arr[0] = -1;
  Lgm_ArrToVec(Arr, v);
  Lgm_PrintVector(v);

  printf("Divide it by a scalar:\n");
  Lgm_VecDivideScalar(v, 2);
  Lgm_PrintVector(v);

  printf("Multiply by a scalar:\n");
  Lgm_VecMultiplyScalar(v, 2);
  Lgm_PrintVector(v);

  printf("Make a new vector and get the angle between them:\n");
  v2 = Lgm_CreateVector(1,0,0);
  Lgm_SetVecElements(v, 0, 1, 0);
  ang = Lgm_VectorAngle(v, v2);
  printf("Angle:%lf\n", ang);

  printf("Make a new vector and get the angle between them:\n");
  Lgm_SetVecElements(v, 0, 1, 0);
  Lgm_SetVecElements(v2, 0, 1, 0);
  ang = Lgm_VectorAngle(v, v2);
  printf("Angle:%lf\n", ang);

  Lgm_FreeVector(v);
  Lgm_FreeVector(v2);
  return(0);
}