00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 static char const Id[] = "$Id: hext_kq.c 3024 2010-03-28 17:17:35Z scholz $\n\n";
00047 static char const Td[] = "$Today: " __FILE__ " " __DATE__ " " __TIME__ " $\n\n";
00048
00049 #include "griddata.h"
00050
00051 static int doinit=1;
00052 static int fieldon=0;
00053 static Vec VHthis;
00054 static PetscReal hextamp;
00055
00056 int Hext_kq_Init(GridData *gdata)
00057 {
00058 MagparFunctionLogBegin;
00059
00060 PetscTruth flg;
00061 ierr = PetscOptionsGetInt(PETSC_NULL,"-hext_kq",(PetscInt*)&fieldon,&flg);CHKERRQ(ierr);
00062 if (flg!=PETSC_TRUE) {
00063 fieldon=0;
00064 PetscPrintf(PETSC_COMM_WORLD,
00065 "Option -hext_kq not found, using default value: %i (field off)\n",
00066 fieldon
00067 );
00068 }
00069
00070 if (!fieldon) {
00071 PetscPrintf(PETSC_COMM_WORLD,"Hext_kq off\n");
00072 MagparFunctionLogReturn(0);
00073 }
00074 PetscPrintf(PETSC_COMM_WORLD,"Hext_kq on\n");
00075
00076 PetscReal hgapini;
00077 ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_gapini",&hgapini,&flg);CHKERRQ(ierr);
00078 if (flg!=PETSC_TRUE) {
00079 hgapini=50.0;
00080 PetscPrintf(PETSC_COMM_WORLD,
00081 "Option -hext_kq_gapini not found. Using default value %g\n",
00082 hgapini
00083 );
00084 }
00085 PetscPrintf(PETSC_COMM_WORLD,"hext_kq_gapini %g\n",hgapini);
00086
00087 PetscReal gapsize;
00088 ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_gapsize",&gapsize,&flg);CHKERRQ(ierr);
00089 if (flg!=PETSC_TRUE) {
00090 gapsize=25.0;
00091 PetscPrintf(PETSC_COMM_WORLD,
00092 "Option -hext_kq_gapsize not found. Using default value %g\n",
00093 gapsize
00094 );
00095 }
00096 PetscPrintf(PETSC_COMM_WORLD,"kq_gap_size %g\n",gapsize);
00097
00098 PetscReal x_offset;
00099 ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_x_offset",&x_offset,&flg);CHKERRQ(ierr);
00100 if (flg!=PETSC_TRUE) {
00101 x_offset=0.0;
00102 PetscPrintf(PETSC_COMM_WORLD,
00103 "Option -hext_kq_x_offset not found. Using default value %g\n",
00104 x_offset
00105 );
00106 }
00107 PetscPrintf(PETSC_COMM_WORLD,"kq_value of x_offset %g\n",x_offset);
00108
00109 PetscReal z_offset;
00110 ierr = PetscOptionsGetReal(PETSC_NULL,"-hext_kq_z_offset",&z_offset,&flg);CHKERRQ(ierr);
00111 if (flg!=PETSC_TRUE) {
00112 z_offset=0.0;
00113 PetscPrintf(PETSC_COMM_WORLD,
00114 "Option -hext_kq_z_offset not found. Using default value %g\n",
00115 z_offset
00116 );
00117 }
00118 PetscPrintf(PETSC_COMM_WORLD,"kq_z_offset %g\n",z_offset);
00119
00120 ierr = VecDuplicate(gdata->M,&VHthis);CHKERRQ(ierr);
00121
00122
00123
00124
00125 PetscReal *ta_Hext;
00126 ierr = VecGetArray(VHthis,&ta_Hext);CHKERRQ(ierr);
00127
00128 hgapini *=1000.0;
00129 hgapini /= gdata->hscale/MU0;
00130 hextamp=hgapini;
00131
00132 for (int j=0; j<gdata->ln_vert; j++) {
00133 PetscReal x,y,z;
00134 x = gdata->vertxyz[ND*gdata->vertl2g[j]+0];
00135 y = gdata->vertxyz[ND*gdata->vertl2g[j]+1];
00136 z = gdata->vertxyz[ND*gdata->vertl2g[j]+2];
00137
00138
00139
00140 PetscReal x_coord, z_coord;
00141
00142 x_coord = x_offset*1e-9 + x*gdata->lenscale;
00143
00144 z_coord = z_offset*1e-9 + z*gdata->lenscale;
00145
00146 PetscReal hx,hy,hz;
00147 hx = (hgapini/PETSC_PI)*
00148 (atan(((gapsize*1e-9)/2.0 + x_coord)/z_coord) +
00149 atan(((gapsize*1e-9)/2.0 - x_coord)/z_coord));
00150 hy = 0;
00151 hz = -(hgapini/(2*PETSC_PI))*
00152 log((((gapsize*1e-9)/2.0 + x_coord)*((gapsize*1e-9)/2.0 + x_coord) + z_coord*z_coord)/
00153 (((gapsize*1e-9)/2.0 - x_coord)*((gapsize*1e-9)/2.0 - x_coord) + z_coord*z_coord)
00154 );
00155
00156 PetscPrintf(PETSC_COMM_WORLD,"Coordinates: (%g,%g,%g)\n",x,y,z);
00157 PetscPrintf(PETSC_COMM_WORLD,"Field: (%g,%g,%g)\n",hx,hy,hz);
00158
00159 ta_Hext[ND*j+0]= hx;
00160 ta_Hext[ND*j+1]= hy;
00161 ta_Hext[ND*j+2]= hz;
00162 }
00163 ierr = VecRestoreArray(VHthis,&ta_Hext);CHKERRQ(ierr);
00164
00165 ierr = VecScale(gdata->VHext,hextamp);CHKERRQ(ierr);
00166
00167 MagparFunctionLogReturn(0);
00168 }
00169
00170
00171 int Hext_kq(GridData *gdata,Vec VHextsum,PetscReal *hext)
00172 {
00173 MagparFunctionInfoBegin;
00174
00175 if (doinit) {
00176 ierr = Hext_kq_Init(gdata);CHKERRQ(ierr);
00177 doinit=0;
00178 }
00179 if (!fieldon) {
00180 MagparFunctionInfoReturn(0);
00181 }
00182
00183 ierr = VecAXPY(VHextsum,1.0,VHthis);CHKERRQ(ierr);
00184
00185 *hext=hextamp;
00186
00187 MagparFunctionProfReturn(0);
00188 }
00189