main(int argc, char *argv[]){ int array[MAX]; int i = 0; if(argc < 2){ fprintf(stderr, "Usage: <binary> <size of array>\n"); exit(0); } int size = atoi(argv[1]); GenerateDataAndInsert(array, size); //for(i = 0; i < size; i++) //printf("%d ", array[i]); int elem = -99; clock_t begin, end; double time_spent; begin = clock(); int flag = 0; for(i = 0; i < 10000; i++) flag = SearchArray(array, size, elem); end = clock(); time_spent = (end - begin) / CLOCKS_PER_SEC ; if(flag == -1){ printf("search unsuccessful, size: %d \t time taken: %lf\n", size, time_spent); } }
void ScoreICMTrk(long part, double x0, double y0, double z0, double u, double v, double w, double lmax, double E, double wgt, long id) { long icm, ntot, nmu0, nmu1, nmu2, nseg, surf, type, ptr, np, in0, in1; long idx, ng, ncross, icm0, icm1, idx0, idx1, ng0, ng1; long mua, mus, mua0, mus0, mua1, mus1; long s0, s1, s2; double d, l, x, y, z, un0, vn0, wn0, un1, vn1, wn1, un2, vn2, wn2; double wgt0, wgt1, mu0, mu1, mu2; const double *params; /* Check mode */ if ((long)RDB[DATA_ICM_CALC] == NO) return; /* Get sizes */ ntot = (long)RDB[DATA_ICM_NG0]; nmu0 = (long)RDB[DATA_ICM_NMU0]; nmu1 = (long)RDB[DATA_ICM_NMU1]; nmu2 = (long)RDB[DATA_ICM_NMU2]; nseg = (long)RDB[DATA_ICM_NSEG]; /* Get pointer to few-group structure */ ptr = (long)RDB[DATA_ICM_PTR_ENE0]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get few-group index */ if ((ng = GridSearch(ptr, E)) < 0) return; /* Convert index */ ng = ntot - ng - 1; CheckValue(FUNCTION_NAME, "ng1", "", ng, 0, ntot - 1); /* Reset new data */ icm1 = -1; idx1 = -1; mua1 = -1; mus1 = -1; ng1 = -1; wgt1 = -1; /* Loop over data */ icm = (long)RDB[DATA_PTR_ICM0]; while (icm > VALID_PTR) { /* Get original particle Albedo data */ icm0 = (long)RDB[part + PARTICLE_ICM_PTR_ICM]; idx0 = (long)RDB[part + PARTICLE_ICM_IDX]; mua0 = (long)RDB[part + PARTICLE_ICM_MUA]; mus0 = (long)RDB[part + PARTICLE_ICM_MUS]; ng0 = (long)RDB[part + PARTICLE_ICM_G]; wgt0 = RDB[part + PARTICLE_ICM_WGT]; /* Get surface pointer */ surf = (long)RDB[icm + ICM_PTR_SURF]; CheckPointer(FUNCTION_NAME, "(surf)", DATA_ARRAY, surf); /* Get surface type */ type = (long)RDB[surf + SURFACE_TYPE]; /* Get number of parameters */ np = (long)RDB[surf + SURFACE_N_PARAMS]; /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); params = &RDB[ptr]; /* Move to starting position */ /* Toi ekstrapolointi lienee turhaa sen jälkeen kun */ /* trackin.c:tä muutettiin 14.8.2014 / 2.1.22 */ Die(FUNCTION_NAME, "HUOM!!!"); x = x0 - 2.0*EXTRAP_L*u; y = y0 - 2.0*EXTRAP_L*v; z = z0 - 2.0*EXTRAP_L*w; /* Reset total distance and number of crossings */ l = 0.0; ncross = 0; /* Get initial position */ in0 = TestSurface(surf, x, y, z, NO, id); in1 = -1; /* Loop over all surfaces in track */ while (l < lmax) { /* Get distance */ d = SurfaceDistance(surf, params, type, np, x, y, z, u, v, w, id); /* Extrapolate */ d = d + EXTRAP_L; /* Update coordinates */ x = x + d*u; y = y + d*v; z = z + d*w; /* Test position */ in1 = TestSurface(surf, x, y, z, NO, id); /* Check with maximum */ if (l + d > lmax) { /* Go back to collision site (for debugging) */ x = x0 + lmax*u; y = y0 + lmax*v; z = z0 + lmax*w; /* Cancel crossing */ in1 = in0; /* Break loop */ break; } else { /* Update distance */ l = l + d; } /* Check if surface was crossed */ if (in0 != in1) { /* Add counter */ ncross++; /* Get surface index */ if ((idx = ICMIdx(surf, x, y, z, &un0, &vn0, &wn0, &un1, &vn1, &wn1, &un2, &vn2, &wn2)) > -1) { /* Calculate cosines */ mu0 = un0*u + vn0*v + wn0*w; mu1 = un1*u + vn1*v + wn1*w; mu2 = un2*u + vn2*v + wn2*w; /* Get bins */ ptr = (long)RDB[DATA_ICM_PTR_MU0]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); s0 = SearchArray(&RDB[ptr], fabs(mu0), nmu0 + 1); CheckValue(FUNCTION_NAME, "s0", "", s0, 0, nmu0 - 1); ptr = (long)RDB[DATA_ICM_PTR_MU1]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); s1 = SearchArray(&RDB[ptr], mu1, nmu1 + 1); CheckValue(FUNCTION_NAME, "s1", "", s1, 0, nmu1 - 1); ptr = (long)RDB[DATA_ICM_PTR_MU2]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); s2 = SearchArray(&RDB[ptr], mu2, nmu2 + 1); CheckValue(FUNCTION_NAME, "s2", "", s2, 0, nmu2 - 1); /* Calculate asymmetric and symmetric part */ mua = s1; mus = s0*nmu2 + s2; /* Check direction */ if ((in0 == NO) && (in1 == YES)) { /* Check bins */ CheckValue(FUNCTION_NAME, "idx", "(1)", idx, 0, nseg - 1); CheckValue(FUNCTION_NAME, "mua", "(1)", mua, 0, nmu1 - 1); CheckValue(FUNCTION_NAME, "mus", "(1)", mus, 0, nmu0*nmu2 - 1); CheckValue(FUNCTION_NAME, "ng", "(1)", ng, 0, ntot - 1); /* Score inward current */ if (RDB[DATA_CYCLE_IDX] > RDB[DATA_CRIT_SKIP] - 1.0) { ptr = (long)RDB[icm + ICM_RES_CURR0]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); AddBuf(1.0, wgt, ptr, id, -1, idx, mua, mus, ng); } /* Put new data and reset weight */ icm0 = icm; idx0 = idx; mua0 = mua; mus0 = mus; ng0 = ng; wgt0 = 1.0; } else if ((in0 == YES) && (in1 == NO)) { /* Check active cycles */ if (RDB[DATA_CYCLE_IDX] > RDB[DATA_CRIT_SKIP] - 1.0) { /* Check index, group and angular bins */ if ((idx0 > -1) && (ng0 > -1) && (mua0 > -1) && (mus0 > -1)) { /* Check bins */ CheckValue(FUNCTION_NAME, "idx0", "(2)", idx0, 0, nseg - 1); CheckValue(FUNCTION_NAME, "mua0", "(2)", mua0, 0, nmu1 - 1); CheckValue(FUNCTION_NAME, "mus0", "(2)", mus0, 0, nmu0*nmu2 - 1); CheckValue(FUNCTION_NAME, "ng0", "(2)", ng0, 0, ntot - 1); CheckValue(FUNCTION_NAME, "idx", "(2)", idx, 0, nseg - 1); CheckValue(FUNCTION_NAME, "mua", "(2)", mua, 0, nmu1 - 1); CheckValue(FUNCTION_NAME, "mus", "(2)", mus, 0, nmu0*nmu2 - 1); /* Score outward current */ ptr = (long)RDB[icm + ICM_RES_CC1]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); AddBuf(1.0, wgt, ptr, id, -1, idx0, mua0, mus0, ng0, idx, mua, mus, ng); ptr = (long)RDB[icm + ICM_RES_CC2]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); AddBuf(wgt0, wgt, ptr, id, -1, idx0, mua0, mus0, ng0, idx, mua, mus, ng); } else if ((ng0 > -1) && (RDB[DATA_CYCLE_IDX] > RDB[DATA_CRIT_SKIP] + 20.0)) Warn(FUNCTION_NAME, "Problem in geometry?"); } /* Reset values */ icm0 = -1; idx0 = -1; mua0 = -1; mus0 = -1; ng0 = -1; wgt0 = 1.0; } } } /* Put previous position */ in0 = in1; } /* Check if particle is in */ if (in1 == YES) { /* Update new values */ if (icm1 > VALID_PTR) Die(FUNCTION_NAME, "Point (%E, %E, %E) is in multiple regions", x, y, z); else { icm1 = icm0; idx1 = idx0; mua1 = mua0; mus1 = mus0; ng1 = ng0; wgt1 = wgt0; } /* Check number of crossings */ if (ncross == 0) { /* Surface index cannot have changed */ if (idx0 != (long)RDB[part + PARTICLE_ICM_IDX]) Die(FUNCTION_NAME, "This is impossible"); /* No other crossings are possible, add to counter */ ptr = (long)RDB[icm + ICM_BREAK_PTR_COUNT]; CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr); AddPrivateData(ptr, 1, id); /* Break loop */ break; } } /* Next */ icm = NextItem(icm); } /* Store values */ WDB[part + PARTICLE_ICM_PTR_ICM] = (double)icm1; WDB[part + PARTICLE_ICM_IDX] = (double)idx1; WDB[part + PARTICLE_ICM_MUA] = (double)mua1; WDB[part + PARTICLE_ICM_MUS] = (double)mus1; WDB[part + PARTICLE_ICM_G] = (double)ng1; WDB[part + PARTICLE_ICM_WGT] = wgt1; }
double NearestBoundary(long id) { long lvl0, lvl, reg, cell, pbd, pbl, surf, type, n, np, ptr, loc0, ltype; long surflist, ownrlist, nbrlist, facelist, sidelist, nf, side, k, j, pt; long nbhr, uni, ifc, ncol, tbi, ang, i, cgns, loc1, nt; double min, d, x, y, z, u, v, w, y2, z2, params[MAX_SURFACE_PARAMS]; double t, phi, phi2; /* Reset minimum distance */ min = INFTY; /* Pointer to first level */ lvl0 = (long)RDB[DATA_PTR_LVL0]; CheckPointer(FUNCTION_NAME, "(lvl0)", DATA_ARRAY, lvl0); /* Loop over levels */ while (lvl0 > VALID_PTR) { /* Pointer to private data */ lvl = (long)RDB[lvl0 + LVL_PTR_PRIVATE_DATA]; CheckPointer(FUNCTION_NAME, "(lvl)", PRIVA_ARRAY, lvl); /* Get coordinates */ x = GetPrivateData(lvl + LVL_PRIV_X, id); y = GetPrivateData(lvl + LVL_PRIV_Y, id); z = GetPrivateData(lvl + LVL_PRIV_Z, id); /* Get direction cosines */ u = GetPrivateData(lvl + LVL_PRIV_U, id); v = GetPrivateData(lvl + LVL_PRIV_V, id); w = GetPrivateData(lvl + LVL_PRIV_W, id); /* Check coordinates and direction cosines */ CheckValue(FUNCTION_NAME, "x", "", x, -INFTY, INFTY); CheckValue(FUNCTION_NAME, "y", "", y, -INFTY, INFTY); CheckValue(FUNCTION_NAME, "z", "", z, -INFTY, INFTY); CheckValue(FUNCTION_NAME, "u", "", u, -1.0, 1.0); CheckValue(FUNCTION_NAME, "v", "", v, -1.0, 1.0); CheckValue(FUNCTION_NAME, "w", "", w, -1.0, 1.0); /* Pointer to universe */ uni = (long)GetPrivateData(lvl + LVL_PRIV_PTR_UNIV, id); CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Get time */ ptr = RDB[uni + UNIVERSE_PTR_PRIVA_T]; CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr); t = GetPrivateData(ptr, id); /* Check for symmetry */ if ((ptr = (long)RDB[uni + UNIVERSE_PTR_SYM]) > VALID_PTR) if ((d = SymmetryBoundary(ptr, x, y, z, u, v, w)) < min) min = d; /* Get level type */ ltype = (long)GetPrivateData(lvl + LVL_PRIV_TYPE, id); /* Check type */ switch (ltype) { case UNIVERSE_TYPE_NEST: { /*****************************************************************/ /***** Nest ******************************************************/ /* Check for fuel performance interface */ if ((loc0 = (long)RDB[uni + UNIVERSE_PTR_IFC_FUEP]) > VALID_PTR) { /* First check nest boundaries */ /* Check nest region surfaces */ /* Pointer to nest region */ reg = (long)GetPrivateData(lvl + LVL_PRIV_PTR_NEST_REG, id); CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg); /* First surface */ if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_IN]) > VALID_PTR) { /* Get type */ type = (long)RDB[surf + SURFACE_TYPE]; /* Die on non-cylindrical */ if(type != SURF_CYL) Die(FUNCTION_NAME,"Non-cylindrical surface"); /* Get number of parameters */ np = (long)RDB[surf + SURFACE_N_PARAMS]; /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Copy surface parameters */ memcpy(¶ms,&RDB[ptr],np*sizeof(double)); y2 = 0.0; z2 = z; /* Cold to hot expansion of cylinder radius */ /* (params[2]) */ CoordExpans(loc0,¶ms[2],&y2,&z2,t,2); /* Get distance */ d = SurfaceDistance(-1, params, type, np, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "1", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } /* Second surface */ if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_OUT]) > VALID_PTR) { /* Get type */ type = (long)RDB[surf + SURFACE_TYPE]; /* Die on non-cylindrical */ if(type != SURF_CYL) Die(FUNCTION_NAME,"Non-cylindrical surface"); /* Get number of parameters */ np = (long)RDB[surf + SURFACE_N_PARAMS]; /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Copy surface parameters */ memcpy(¶ms,&RDB[ptr],np*sizeof(double)); y2 = 0.0; z2 = z; /* Cold to hot expansion of cylinder radius */ /* (params[2]) */ CoordExpans(loc0,¶ms[2],&y2,&z2,t,2); /* Get distance */ d = SurfaceDistance(-1, params, type, np, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "2", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } /* Check the interface input boundaries, */ /* Find time interval */ tbi = (long)RDB[loc0 + IFC_FUEP_PTR_T]; /* Get pointer to limits */ ptr = (long)RDB[loc0 + IFC_FUEP_LIM_PTR_T]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get number of time bins */ nt = (long)RDB[loc0 + IFC_FUEP_N_T]; /* Find bin*/ i = SearchArray(&RDB[ptr], t, nt + 1); /* Check if found */ if (i < 0) break; /* Get direct pointer to time bin */ tbi = ListPtr(tbi, i); /* Find axial zone */ loc1 = (long)RDB[tbi + IFC_FUEP_T_PTR_AX]; while (loc1 > VALID_PTR) { /* Compare coordinates */ if ((z >= RDB[loc1 + IFC_FUEP_AX_ZMIN]) && (z < RDB[loc1 + IFC_FUEP_AX_ZMAX])) { /* Break loop */ break; } /* Next */ loc1 = NextItem(loc1); } /* Break case if not found*/ if (loc1 < VALID_PTR) break; /* Only check axial boundaries in 3D calculation */ if ((long)RDB[DATA_GEOM_DIM] == 3) { /* Distance to lower boundary */ params[0] = RDB[loc1 + IFC_FUEP_AX_ZMIN]; d = SurfaceDistance(-1, params, SURF_PZ, 1, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "3", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; /* Distance to upper boundary */ params[0] = RDB[loc1 + IFC_FUEP_AX_ZMAX]; d = SurfaceDistance(-1, params, SURF_PZ, 1, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "4", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } /* Get the correct angular segment */ ang = (long)RDB[loc1 + IFC_FUEP_AX_PTR_ANG]; /* Get polar angle */ phi = PolarAngle(x,y); while (ang > VALID_PTR) { /* Rotate if needed */ if(phi > 2.0*PI+RDB[ang + IFC_FUEP_ANG_AMIN]) phi2 = phi - 2.0*PI; else phi2 = phi; /* Compare coordinates */ if ((phi2 >= RDB[ang + IFC_FUEP_ANG_AMIN]) && (phi2 < RDB[ang + IFC_FUEP_ANG_AMAX])) break; /* Next */ ang = NextItem(ang); } /* Break case if not found */ if (ang < VALID_PTR) break; /* Calculate distance to angular zone boundaries */ /* Tää ei huomioi että rajoittava taso on vain puoliääretön */ /* (Tulee ylimääräisiä pysäytyksiä, jos kulmasegmenttejä */ /* on pariton määrä) */ params[0] = RDB[ang + IFC_FUEP_ANG_CMIN]; params[1] = 1.0; params[2] = 0.0; params[3] = 0.0; d = SurfaceDistance(-1, params, SURF_PLANE, 4, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "5", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; params[0] = RDB[ang + IFC_FUEP_ANG_CMAX]; d = SurfaceDistance(-1, params, SURF_PLANE, 4, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "6", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } else { /* Pointer to nest region */ reg = (long)GetPrivateData(lvl + LVL_PRIV_PTR_NEST_REG, id); CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg); /* First surface */ if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_IN]) > VALID_PTR) { /* Get type */ type = (long)RDB[surf + SURFACE_TYPE]; /* Get number of parameters */ np = (long)RDB[surf + SURFACE_N_PARAMS]; /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get distance */ d = SurfaceDistance(-1, &RDB[ptr], type, np, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "10", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } /* Second surface */ if ((surf = (long)RDB[reg + NEST_REG_PTR_SURF_OUT]) > VALID_PTR) { /* Get type */ type = (long)RDB[surf + SURFACE_TYPE]; /* Get number of parameters */ np = (long)RDB[surf + SURFACE_N_PARAMS]; /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get distance */ d = SurfaceDistance(-1, &RDB[ptr], type, np, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "11", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } } /* Break case */ break; /*****************************************************************/ } case UNIVERSE_TYPE_LATTICE: { /*****************************************************************/ /***** Lattice ***************************************************/ /* Check pointer to lattice */ if ((long)GetPrivateData(lvl + LVL_PRIV_PTR_LAT, id) < VALID_PTR) Die(FUNCTION_NAME, "No lattice pointer"); /* Get surface type */ type = (long)GetPrivateData(lvl + LVL_PRIV_LAT_SURF_TYPE, id); /* Get number of surface parameters */ np = (long)GetPrivateData(lvl + LVL_PRIV_LAT_SURF_NP, id); /* Get parameters (noiden kerrointen pitää olla peräkkäin) */ for (n = 0; n < np; n++) params[n] = GetPrivateData(lvl + LVL_PRIV_LAT_SURF_C0 + n, id); /* Get distance */ d = SurfaceDistance(-1, params, type, np, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "12", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; /* Check if type is vertical stack */ if (type == SURF_PZ) { /* Put parameter for second surface */ params[0] = GetPrivateData(lvl + LVL_PRIV_LAT_SURF_C1, id); /* Get distance (ei tarkisteta, reunimmaiset pinnat voi */ /* olla +/- INFTY) */ d = SurfaceDistance(-1, params, type, np, x, y, z, u, v, w, id); /* Compare to minimum */ if (d < min) min = d; } /* Break case */ break; /*****************************************************************/ } case UNIVERSE_TYPE_CELL: { /*****************************************************************/ /***** Cell ******************************************************/ /* Pointer to cell */ cell = (long)GetPrivateData(lvl + LVL_PRIV_PTR_CELL, id); CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell); /* Pointer to surface list */ loc0 = (long)RDB[cell + CELL_PTR_SURF_LIST]; CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Loop over list */ while ((surf = (long)RDB[loc0++]) > VALID_PTR) { /* Get type */ type = (long)RDB[surf + SURFACE_TYPE]; /* Check infinite */ if (type != SURF_INF) { /* Get number of parameters */ np = (long)RDB[surf + SURFACE_N_PARAMS]; /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get distance */ d = SurfaceDistance(surf, &RDB[ptr], type, np, x, y, z, u, v, w, id); if (d < 0.0) printf("%s %ld: x = %1.14E; y = %1.14E; z = %1.14E; u = %1.14E; v = %1.14E; w = %1.14E;\n", GetText(surf + SURFACE_PTR_NAME), type, x, y, z, u, v, w); CheckValue(FUNCTION_NAME, "d", "14", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) min = d; } } /* Break case */ break; /*****************************************************************/ } case UNIVERSE_TYPE_UMSH: { /*****************************************************************/ /***** Unstructured mesh based geometry **************************/ /* Pointer to cell */ if ((cell = (long)GetPrivateData(lvl + LVL_PRIV_PTR_CELL, id)) > VALID_PTR) { /* Get current tetra-cell (set in whereami.c) */ ptr = (long)RDB[cell + CELL_PTR_PREV_TET]; if ((cgns = (long)GetPrivateData(ptr, id)) < VALID_PTR) Die(FUNCTION_NAME, "UMSH tet was not stored"); /* Reset pointer to neighbour */ nbhr = -1; /* Get pointer to UMSH structure */ ptr = (long)RDB[uni + UNIVERSE_PTR_UMSH]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get pointer to UMSH interface */ ifc = (long)RDB[ptr + UMSH_PTR_IFC]; CheckPointer(FUNCTION_NAME, "(ifc)", DATA_ARRAY, ifc); /* Get pointer to interface surface list */ surflist = (long)RDB[ifc + IFC_PTR_SURF_LIST]; CheckPointer(FUNCTION_NAME, "(surflist)", DATA_ARRAY, surflist); /* Get pointer to interface owner list */ ownrlist = (long)RDB[ifc + IFC_PTR_OWNR_LIST]; CheckPointer(FUNCTION_NAME, "(ownrlist)", DATA_ARRAY, ownrlist); /* Get pointer to interface neighbour list */ nbrlist = (long)RDB[ifc + IFC_PTR_NBR_LIST]; CheckPointer(FUNCTION_NAME, "(nbrlist)", DATA_ARRAY, nbrlist); /* Get pointer to cell's face list */ facelist = (long)RDB[cgns + IFC_TET_MSH_PTR_FACES]; CheckPointer(FUNCTION_NAME, "(facelist)", DATA_ARRAY, facelist); /* Get pointer to cell's side list */ sidelist = (long)RDB[cgns + IFC_TET_MSH_PTR_SIDES]; CheckPointer(FUNCTION_NAME, "(sidelist)", DATA_ARRAY, sidelist); /* Loop over cell faces */ nf = (long)RDB[cgns + IFC_TET_MSH_NF]; CheckValue(FUNCTION_NAME, "nf", "", nf, 4, 4); for (i = 0; i < nf; i++) { /* Get index of face */ n = (long)RDB[facelist + i]; /* Get side for face */ side = (long)RDB[sidelist + i]; /* Get pointer to face surface */ surf = ListPtr(surflist, n); /* Get pointer to surface parameters */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get number of points on the face */ np = (long)RDB[surf + SURFACE_N_PARAMS]; CheckValue(FUNCTION_NAME, "np", "", np, 3, 3); /* Copy points to params */ k = 0; for (j = 0; j < np; j++) { /* Get pointer to beginning of point coordinates */ pt = (long)RDB[ptr + j]; /* Store coordinates to params */ params[k++] = RDB[pt + 0]; params[k++] = RDB[pt + 1]; params[k++] = RDB[pt + 2]; } /* Get distance */ d = SurfaceDistance(surf, params, SURF_PLANE, 9, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "15", d, 0.0, INFTY); /* Compare to minimum */ if (d < min) { min = d; /* Get neighbour */ if (side == -1) nbhr = (long)RDB[nbrlist + n]; else nbhr = (long)RDB[ownrlist + n]; } } /* Get collision count */ ptr = (long)RDB[DATA_PTR_COLLISION_COUNT]; ncol = GetPrivateData(ptr, id); /* Store value */ StoreValuePair(uni + UNIVERSE_PTR_NEXT_CELL, ncol, nbhr, id); } else { /* Point is in background universe, get distance to search */ /* mesh boundaries. */ /* Pointer to geometry */ loc0 = (long)GetPrivateData(lvl + LVL_PRIV_PTR_UMSH, id); CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Pointer to interaface structure */ loc0 = (long)RDB[loc0 + UMSH_PTR_IFC]; CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Get minimum distance */ d = NearestUMSHSurf(loc0, x, y, z, u, v, w, id); /* Compare to minimum */ if (d < min) min = d; } /* Break case */ break; /*****************************************************************/ } case UNIVERSE_TYPE_STL: { /*****************************************************************/ /***** STL based geometry ****************************************/ /* Pointer to geometry */ loc0 = (long)GetPrivateData(lvl + LVL_PRIV_PTR_STL, id); CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Get minimum distance */ d = NearestSTLSurf(loc0, x, y, z, u, v, w, id); /* Compare to minimum */ if (d < min) min = d; /* Break case */ break; /*****************************************************************/ } case UNIVERSE_TYPE_PBED: { /*****************************************************************/ /***** Explicit stochastic geometry ******************************/ /* Check direct pointer to pebble */ if ((pbl = (long)GetPrivateData(lvl + LVL_PRIV_PTR_PEBBLE, id)) > VALID_PTR) { /* Put surface parameters */ params[0] = RDB[pbl + PEBBLE_X0]; params[1] = RDB[pbl + PEBBLE_Y0]; params[2] = RDB[pbl + PEBBLE_Z0]; params[3] = RDB[pbl + PEBBLE_RAD]; if ((x - params[0])*(x - params[0]) + (y - params[1])*(y - params[1]) + (z - params[2])*(z - params[2]) > params[3]*params[3]) Die(FUNCTION_NAME, "not inside"); /* Get distance */ d = SurfaceDistance(-1, params, SURF_SPH, 4, x, y, z, u, v, w, id); CheckValue(FUNCTION_NAME, "d", "16", d, 0.0, 2.0*params[3]); } else { /* Pointer to PB geometry */ pbd = (long)GetPrivateData(lvl + LVL_PRIV_PTR_PBED, id); CheckPointer(FUNCTION_NAME, "(pbd)", DATA_ARRAY, pbd); /* Get minimum distance */ d = NearestPBSurf(pbd, x, y, z, u, v, w, id); } /* Compare to minimum */ if (d < min) min = d; /* Break case */ break; /*****************************************************************/ } default: { /* Invalid type */ Die(FUNCTION_NAME, "Invalid universe type"); } } /* Break loop if level is last */ if ((long)GetPrivateData(lvl + LVL_PRIV_LAST, id) == YES) break; /* Next level */ lvl0 = NextItem(lvl0); } /* Return shortest distance */ return min; }
double TTB(long mat, long part, double Te, double x, double y, double z, double u, double v, double w, double wgt, double t, long pflag, long id) { long ptd, ptr, nTe0, new1, brcdfptr, brpdfptr, Ncdf, Nk, idx, i; double sumEk, lTe, Yk, rcdf, Ek, cdfmax, a, Ed; const double *Ted, *lTed, *lYkd, *brcdf, *brpdf; if ((Te < RDB[DATA_PHOTON_EMIN]) || (RDB[DATA_PHOTON_USE_TTB] == NO)) { /* Electron/positron energy is deposited locally */ /* TODO: (!RDB[DATA_PHOTON_USE_TTB]) vois siirtää rutiineihin, joissa elektroneja luodaan */ return Te; } CheckPointer(FUNCTION_NAME, "(mat)", DATA_ARRAY, mat); CheckPointer(FUNCTION_NAME, "(part)", DATA_ARRAY, part); ptd = (long)RDB[mat + MATERIAL_PTR_TTB]; CheckPointer(FUNCTION_NAME, "(ptd)", DATA_ARRAY, ptd); nTe0 = (long)RDB[ptd + TTB_NE]; ptr = (long)RDB[ptd + TTB_E]; CheckPointer(FUNCTION_NAME, "(Te0)", DATA_ARRAY, ptr); Ted = &RDB[ptr]; ptr = (long)RDB[ptd + TTB_LE]; CheckPointer(FUNCTION_NAME, "(lTe0)", DATA_ARRAY, ptr); lTed = &RDB[ptr]; /* Select positron or electron data */ if (pflag && ((long)RDB[DATA_PHOTON_TTBPM] == YES)) { /* Positron */ ptr = (long)RDB[ptd + TTB_LYP]; CheckPointer(FUNCTION_NAME, "(lYph0)", DATA_ARRAY, ptr); lYkd = &RDB[ptr]; ptr = (long)RDB[ptd + TTB_BRPCDF]; CheckPointer(FUNCTION_NAME, "(brpcdf)", DATA_ARRAY, ptr); brcdfptr = ptr; ptr = (long)RDB[ptd + TTB_BRPPDF]; CheckPointer(FUNCTION_NAME, "(brppdf", DATA_ARRAY, ptr); brpdfptr = ptr; } else { /* Electron */ ptr = (long)RDB[ptd + TTB_LYE]; CheckPointer(FUNCTION_NAME, "(lYph0)", DATA_ARRAY, ptr); lYkd = &RDB[ptr]; ptr = (long)RDB[ptd + TTB_BRECDF]; CheckPointer(FUNCTION_NAME, "(brecdf)", DATA_ARRAY, ptr); brcdfptr = ptr; ptr = (long)RDB[ptd + TTB_BREPDF]; CheckPointer(FUNCTION_NAME, "(brepdf)", DATA_ARRAY, ptr); brpdfptr = ptr; } /* Find log energy NOTE: assuming log interpolated energy array */ lTe = log(Te); idx = (long)((lTe - lTed[0])/(lTed[1] - lTed[0])); /* Check index and energy TODO: Nämä vois laittaa checkeiksi */ if ((idx < 0) || (idx > nTe0)) Die(FUNCTION_NAME, "Electron/positron energy not found for index %ld", idx); if ((Te < Ted[idx]) || (Te > Ted[idx+1])) Die(FUNCTION_NAME, "Energy not found in the interval: Ted[%ld] = %.5E, Te = %.5E, Ted[%ld] = %.5E", idx, Ted[idx], Te, idx+1, Ted[idx+1]); /* Interpolate photon yield */ Yk = exp(lYkd[idx] + (lYkd[idx+1] - lYkd[idx])*(lTe - lTed[idx]) /(lTed[idx+1] - lTed[idx])); /* Sample number of photons */ Nk = (long)(Yk + RandF(id)); CheckValue(FUNCTION_NAME, "Nk", "", Nk, 0, INFTY); if (Nk == 0) { /* No bremsstrahlung photons created, deposit energy locally */ return Te; } /* Set bremsstrahlung energy cdf and pdf, the grid is selected using * interpolation weights */ if ((idx == 0) || (lTed[idx] + RandF(id)*(lTed[idx+1] - lTed[idx]) <= lTe)) { brcdf = &RDB[(long)RDB[brcdfptr + idx + 1]]; brpdf = &RDB[(long)RDB[brpdfptr + idx + 1]]; Ncdf = idx + 2; /* +2 due to the index change */ /* Interpolate the maximum cdf assuming the cdf is integrated from linearly * interpolated pdf (pdf(x) = ax + b) */ a = (brpdf[idx+1] - brpdf[idx]) / (Ted[idx+1] - Ted[idx]); cdfmax = brcdf[idx] + 0.5*(2.0*brpdf[idx] + a*(Te - Ted[idx]))*(Te - Ted[idx]); } else { /* NOTE: The lower index is selected, meaning that the maximum photon energy * will be below the electron energy */ brcdf = &RDB[(long)RDB[brcdfptr + idx]]; brpdf = &RDB[(long)RDB[brpdfptr + idx]]; Ncdf = idx + 1; cdfmax = brcdf[idx]; } /***** Sample photon energies **********************************************/ sumEk = 0; for (i = 0; i < Nk; i++) { /* Sample from */ rcdf = RandF(id)*cdfmax; idx = SearchArray(brcdf, rcdf, Ncdf); if (idx == -1) Die(FUNCTION_NAME, "rcdf not found"); /* Solve the photon energy assuming linearly interpolated pdf */ a = (brpdf[idx+1] - brpdf[idx]) / (Ted[idx+1] - Ted[idx]); Ek = Ted[idx] + (sqrt(brpdf[idx]*brpdf[idx] + 2.0*a*(rcdf - brcdf[idx])) - brpdf[idx])/a; /* Check Ek limits */ CheckValue(FUNCTION_NAME, "bremsstrahlung photon energy", "", Ek, Ted[idx], Ted[idx+1]); if (Ek < RDB[DATA_PHOTON_EMIN]) Die(FUNCTION_NAME, "Photon energy %.5E smaller than DATA_PHOTON_EMIN", Ek); if (Ek > Te) Die(FUNCTION_NAME, "Photon energy %.5E larger than electron/positron energy", Ek); sumEk += Ek; if ((sumEk > Te) && ((long)RDB[DATA_PHOTON_TTBEC] == YES)) { /* Sum of photon energies is above the electron energy. Sampling is stopped */ /* Residual energy */ sumEk -= Ek; Ek = Te - sumEk; if (Ek < RDB[DATA_PHOTON_EMIN]) { /* The last photon is not created */ Nk = i; } else { /* Create a new photon having the residual energy */ sumEk = Te; /* Correct the number of photons */ Nk = i+1; new1 = DuplicateParticle(part, id); WDB[new1 + PARTICLE_X] = x; WDB[new1 + PARTICLE_Y] = y; WDB[new1 + PARTICLE_Z] = z; WDB[new1 + PARTICLE_WGT] = wgt; /*TODO: Onko oikein? */ WDB[new1 + PARTICLE_T] = t; WDB[new1 + PARTICLE_E] = Ek; WDB[new1 + PARTICLE_U] = u; WDB[new1 + PARTICLE_V] = v; WDB[new1 + PARTICLE_W] = w; ToQue(new1, id); } break; } /* Create new photon */ new1 = DuplicateParticle(part, id); WDB[new1 + PARTICLE_X] = x; WDB[new1 + PARTICLE_Y] = y; WDB[new1 + PARTICLE_Z] = z; WDB[new1 + PARTICLE_WGT] = wgt; /*TODO: Onko oikein? */ WDB[new1 + PARTICLE_T] = t; WDB[new1 + PARTICLE_E] = Ek; /* NOTE: Photon direction is not sampled */ WDB[new1 + PARTICLE_U] = u; WDB[new1 + PARTICLE_V] = v; WDB[new1 + PARTICLE_W] = w; ToQue(new1, id); } /***************************************************************************/ /* Locally deposited energy */ Ed = Te - sumEk; /* Ed can be negative if RDB[DATA_PHOTON_TTBEC]==NO. * TODO: Should energy deposition be used only when RDB[DATA_PHOTON_TTBEC]==YES? * */ if (Ed < 0.0) Ed = 0.0; /* TODO: Statistics: Total number of bremsstrahlung photons created */ /* WDB[DATA_PHOTON_BREM_TOT] += Nk; */ return Ed; }
static UWORD ParseWord(BSTR textData, UWORD col, UWORD linelength, UBYTE *el) { UBYTE *_ctype = ctype; WCHAR* c = &textData[col]; UBYTE ctyp = ctype[*c]; UWORD wordlen; WCHAR* p; UBYTE element; ATLASSERT(*c < 256); p = c+1; if (_ctype[*c] & N) /* It's a number of some kind */ { if ((*c == '0') && ((*p == 'x') || (*p == 'X'))) /* Hexadecimal */ { p++; /* Skip the x */ while (_ctype[*p] & X) p++; element = EL_HEX; } else if ((*c == '0') && (_ctype[*p] & N)) /* Octal */ { while (_ctype[*p] & O) p++; element = EL_OCTAL; } else /* Either integer or float */ { /* TODO: interpret e (exponent) */ while (_ctype[*p] & N) p++; if (*p == '.') /* Float number, the decimal part comes now */ { p++; while (_ctype[*p] & N) p++; element = EL_FLOAT; } else element = EL_INTEGER; } /* Check for l/u modifiers after numbers */ /* NOTE: float cannot have unsigned modifier */ if ((*p == 'l') || (*p == 'L')) { p++; if ((element != EL_FLOAT) && ((*p == 'u') || (*p == 'U'))) p++; } else if ((element != EL_FLOAT) && ((*p == 'u') || (*p == 'U'))) { p++; if ((*p == 'l') || (*p == 'L')) p++; } wordlen = p-c; /* Check if the following char makes this number illegal */ if (_ctype[*p] & A) element = EL_ILLEGAL_CHAR; /* If this element isn't active set it to ANYTEXT */ if (!(ElementArray[element].Flags & ELFL_ACTIVE)) element = EL_IDENTIFIER; } else { while ((_ctype[*p] & ctyp)) p++; wordlen = p-c; if (ctyp & W) { /* Always active */ element = EL_WHITESPACE; } else if (ctyp & S) { if (ElementArray[EL_SYMBOL].Flags & ELFL_ACTIVE) element = EL_SYMBOL; else element = EL_IDENTIFIER; } else if (ctyp & A) { if ((ElementArray[EL_KEYWORD].Flags & ELFL_ACTIVE) && (SearchArray(KeywordsTab, KEYWORDSCOUNT, c, wordlen) != (UWORD)~0)) { element = EL_KEYWORD; } /* else if ((ElementArray[EL_CPPKEYWORD].Flags & ELFL_ACTIVE) && (SearchArray(HighCPPTab, c, wordlen) != (UWORD)~0)) { element = EL_CPPKEYWORD; } else if ((ElementArray[EL_USERWORD].Flags & ELFL_ACTIVE) && (SearchArray(UserTab, c, wordlen) != (UWORD)~0)) { element = EL_USERWORD; } */ else { element = EL_IDENTIFIER; } } else { if (ElementArray[EL_ILLEGAL_CHAR].Flags & ELFL_ACTIVE) element = EL_ILLEGAL_CHAR; else element = EL_IDENTIFIER; } } *el = element; return wordlen; }
void ProcessPhotonAtt() { long mat, iso, nuc, Z, ne, n, N, i0, i, ptr; double Ei[100], fi[100], *E, *f, mdens, mfrac, val; /* Avoid compiler warning (photon_attenuation.h sisältää dataa jota */ /* käytetään useammassa aliohjelmassa) */ n = idx1[0][0]; val = dat1[0][0]; /* Adjust coincident points */ ne = (long)idx0[91][0] + (long)idx0[91][1]; for (n = 1; n < ne; n++) if (dat0[n][1] == dat0[n - 1][1]) dat0[n][1] = dat0[n][1] + 1E-11; fprintf(out, "Processing reponse functions for photon dose rates...\n"); /* Loop over materials */ mat = (long)RDB[DATA_PTR_M0]; while (mat > VALID_PTR) { /***********************************************************************/ /***** Unionize energy grid ********************************************/ /* Reset pointer */ E = NULL; N = 0; /* Get mass density */ if ((mdens = RDB[mat + MATERIAL_MDENS]) == 0.0) { /* Skip zero-density material */ mat = NextItem(mat); /* Cycle loop */ continue; } /* Loop over composition */ iso = (long)RDB[mat + MATERIAL_PTR_COMP]; while (iso > VALID_PTR) { /* Pointer to nuclide */ nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE]; CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc); /* Get Z */ Z = (long)RDB[nuc + NUCLIDE_Z]; /* Data only goes up to 92 */ if (Z > 92) { /* Skip */ iso = NextItem(iso); /* Cycle loop */ continue; } /* Get index to data array and number of points */ i0 = (long)idx0[Z - 1][0]; ne = (long)idx0[Z - 1][1]; /* Check first and last energy point */ if (dat0[i0][1] != 1E-3) Die(FUNCTION_NAME, "Mismatch in first energy point"); else if (dat0[i0 + ne - 1][1] != 20.0) Die(FUNCTION_NAME, "Mismatch in last energy point"); /* Read data */ for (n = 0; n < ne; n++) { /* Check Z and read value */ if (dat0[i0 + n][0] != Z) Die(FUNCTION_NAME, "Mismatch in Z"); else Ei[n] = dat0[i0 + n][1]; } /* Add points to main array */ E = AddPts(E, &N, Ei, ne); /* Next */ iso = NextItem(iso); } /* Check order */ for (n = 1; n < N; n++) if (E[n] <= E[n - 1]) Die(FUNCTION_NAME, "Error in order"); /***********************************************************************/ /***** Reconstruct data ************************************************/ /* Put number of points */ WDB[mat + MATERIAL_PHOTON_ATT_NE] = (double)N; /* Put energy array in material structure */ ptr = ReallocMem(DATA_ARRAY, N); WDB[mat + MATERIAL_PTR_PHOTON_ATT_E] = (double)ptr; for (n = 0; n < N; n++) WDB[ptr++] = E[n]; /* Allocate memory for data array */ ptr = ReallocMem(DATA_ARRAY, N); WDB[mat + MATERIAL_PTR_PHOTON_ATT_F] = (double)ptr; f = &WDB[ptr]; /* Reset vector (just to be safe) */ memset(f, 0.0, N*sizeof(double)); /* Loop over composition */ iso = (long)RDB[mat + MATERIAL_PTR_COMP]; while (iso > VALID_PTR) { /* Pointer to nuclide */ nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE]; CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc); /* Calculate mass fraction */ mfrac = RDB[nuc + NUCLIDE_AW]*RDB[iso + COMPOSITION_ADENS]/ mdens/N_AVOGADRO; /* Get Z */ Z = (long)RDB[nuc + NUCLIDE_Z]; /* Data only goes up to 92 */ if (Z > 92) { /* Skip */ iso = NextItem(iso); /* Cycle loop */ continue; } /* Get index to data array and number of points */ i0 = (long)idx0[Z - 1][0]; ne = (long)idx0[Z - 1][1]; /* Read data */ for (n = 0; n < ne; n++) { Ei[n] = dat0[i0 + n][1]; fi[n] = dat0[i0 + n][3]; } /* Loop over unionized grid */ for (n = 0; n < N - 1; n++) { /* Find index */ if ((i = SearchArray(Ei, E[n], ne)) < 0) Die(FUNCTION_NAME, "Point not in grid: %ld %E", n, E[n]); /* Interpolate */ val = ENDFInterp(5, E[n], Ei[i], Ei[i + 1], fi[i], fi[i + 1]); /* Add to data */ f[n] = f[n] + val*mfrac; } /* Add last point */ f[N - 1] = f[N -1] + fi[ne - 1]*mfrac; /* Next */ iso = NextItem(iso); } /***********************************************************************/ /* Free memory */ if (E != NULL) Mem(MEM_FREE, E); /* Next material */ mat = NextItem(mat); } /* Exit OK */ fprintf(out, "OK.\n\n"); }
void ScoreInterfacePower(double fissE, double wgt, double x, double y, double z, double t, long id) { long loc0, loc1, ptr, ncol, idx, nz, nr, i, j, k, uni, na, nt, l; double zmin, zmax, x0, y0, r0, r, f, r2, phi; /* Check that interfaces are defined */ if ((loc0 = (long)RDB[DATA_PTR_IFC0]) < VALID_PTR) return; /***************************************************************************/ /***** Interface to thermal hydraulics *************************************/ /* Get zone index */ ptr = (long)RDB[DATA_PTR_ZONE_IDX]; idx = (long)GetPrivateData(ptr, id); /* Loop over interfaces */ while (loc0 > VALID_PTR) { /* Check flag and type */ if (((long)RDB[loc0 + IFC_CALC_OUTPUT] == YES) && (((long)RDB[loc0 + IFC_TYPE] < IFC_TYPE_FUEP) || ((long)RDB[loc0 + IFC_TYPE] > IFC_TYPE_FPIP))) { /* Get pointer to statistics */ ptr = (long)RDB[loc0 + IFC_PTR_STAT]; CheckPointer(FUNCTION_NAME, "ptr", DATA_ARRAY, ptr); /* Check type */ if ((long)RDB[loc0 + IFC_TYPE] == IFC_TYPE_TET_MESH) { /* Get collision number */ ncol = (long)RDB[DATA_PTR_COLLISION_COUNT]; ncol = (long)GetPrivateData(ncol, id); /* Get pointer to tet cell (set in ifcpoint.c) */ if ((loc1 = TestValuePair(loc0 + IFC_PTR_PREV_COL_CELL, ncol, id)) > VALID_PTR) { /* Get index to statistics and score */ if ((i = (long)RDB[loc1 + IFC_TET_MSH_STAT_IDX]) > -1) AddBuf1D(fissE, wgt, ptr, id, i); } } else { /* Other types, get axial boundaries and number of bins */ zmin = RDB[loc0 + IFC_ZMIN]; zmax = RDB[loc0 + IFC_ZMAX]; nz = (long)RDB[loc0 + IFC_NZ]; nr = (long)RDB[loc0 + IFC_NR]; /* Find region (toi z-tarkistus tarvitaan että indeksi menee */ /* alarajalla oikein) */ if ((z >= zmin) && (z < zmax)) if ((loc1 = (long)RDB[loc0 + IFC_PTR_SCORE]) > VALID_PTR) if ((loc1 = SeekList(loc1, IFC_SCORE_REG_IDX, idx, SORT_MODE_ASCEND)) > VALID_PTR) { /* Get stat index */ i = (long)RDB[loc1 + IFC_SCORE_STAT_IDX]; CheckValue(FUNCTION_NAME, "i", "", i, 0, (long)RDB[loc0 + IFC_STAT_NREG]); /* Get pointer to output data */ loc1 = (long)RDB[loc1 + IFC_SCORE_PTR_OUT]; CheckPointer(FUNCTION_NAME, "(loc1)", DATA_ARRAY, loc1); /* Calculate axial bin */ j = (long)((z - zmin)/(zmax - zmin)*((double)nz)); CheckValue(FUNCTION_NAME, "j", "", j, 0, nz - 1); /* Get center coordinates and radius */ x0 = RDB[loc1 + IFC_OUT_X0]; y0 = RDB[loc1 + IFC_OUT_Y0]; r0 = RDB[loc1 + IFC_OUT_R]; /* Check for zero radius */ if (r0 < ZERO) Die(FUNCTION_NAME, "Zero radius"); /* Get square radius */ r = (x - x0)*(x - x0) + (y - y0)*(y - y0); /* Calculate radial zone (typerä toi jälkimmäinen) */ if ((f = r/r0/r0) > 1.0) Die(FUNCTION_NAME, "Point is not inside %E %E : %E %E : %E", x, y, x0, y0, r0); else if (f == 1.0) f = 0.999999; /* Index */ k = (long)(f*nr); CheckValue(FUNCTION_NAME, "k", "", k, 0, nr - 1); /* Score */ AddBuf(fissE, wgt, ptr, id, -1, i, j, k); } } } /* Next interface */ loc0 = NextItem(loc0); } /***************************************************************************/ /***** Interface to fuel performance codes *********************************/ /* Get collision universe */ ptr = (long)RDB[DATA_PTR_COLLISION_UNI]; uni = GetPrivateData(ptr, id); /* Check pointer */ CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Check pointer to interface */ if ((loc1 = (long)RDB[uni + UNIVERSE_PTR_IFC_FUEP]) > VALID_PTR) { /* Get coordinates */ ptr = RDB[uni + UNIVERSE_PTR_PRIVA_X]; CheckPointer(FUNCTION_NAME, "(xptr)", PRIVA_ARRAY, ptr); x = GetPrivateData(ptr, id); ptr = RDB[uni + UNIVERSE_PTR_PRIVA_Y]; CheckPointer(FUNCTION_NAME, "(yptr)", PRIVA_ARRAY, ptr); y = GetPrivateData(ptr, id); ptr = RDB[uni + UNIVERSE_PTR_PRIVA_Z]; CheckPointer(FUNCTION_NAME, "(zptr)", PRIVA_ARRAY, ptr); z = GetPrivateData(ptr, id); ptr = RDB[uni + UNIVERSE_PTR_PRIVA_T]; CheckPointer(FUNCTION_NAME, "(ptr)", PRIVA_ARRAY, ptr); t = GetPrivateData(ptr, id); /* Coordinate transformation to cold system */ CoordExpans(loc1, &x, &y, &z, t, 1); /* Get the size of the statistics */ ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_LIM]; CheckPointer(FUNCTION_NAME, "(limptr)", DATA_ARRAY, ptr); nz = (long)RDB[ptr + FUEP_NZ]; na = (long)RDB[ptr + FUEP_NA]; nr = (long)RDB[ptr + FUEP_NR]; nt = (long)RDB[ptr + FUEP_NT]; /* Get pointer to axial output zones */ ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_Z]; CheckPointer(FUNCTION_NAME, "(zptr)", DATA_ARRAY, ptr); /* Find interval */ i = SearchArray(&RDB[ptr], z, nz + 1); /* Check */ if (i < 0) { Warn(FUNCTION_NAME,"Outside of axial zone"); return; } /* Calculate angle */ phi = PolarAngle(x, y); /* Check phi */ CheckValue(FUNCTION_NAME, "phi", "", phi, 0.0, 2.0*PI); /* Get pointer to angular output zones */ ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_PHI]; CheckPointer(FUNCTION_NAME, "(aptr)", DATA_ARRAY, ptr); /* Rotate if needed */ if (phi > 2.0*PI+RDB[ptr]) phi -= 2.0*PI; /* Find interval */ j = SearchArray(&RDB[ptr], phi, na + 1); /* Check */ if (j < 0) { Warn(FUNCTION_NAME,"Outside of angular zone"); return; } /* Calculate square radius */ r2 = x*x + y*y; /* Get pointer to radial output zones */ ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_R2]; CheckPointer(FUNCTION_NAME, "(rptr)", DATA_ARRAY, ptr); /* Find interval */ k = SearchArray(&RDB[ptr], r2, nr + 1); /* Check */ if (k < 0) { Warn(FUNCTION_NAME,"Outside of radial zone"); return; } /* Find time bin */ ptr = (long)RDB[loc1 + IFC_FUEP_OUT_PTR_TB]; CheckPointer(FUNCTION_NAME, "(TBptr)", DATA_ARRAY, ptr); /* Find bin*/ l = SearchArray(&RDB[ptr], t, nt + 1); /* Check */ if (l < 0) return; /* Score */ ptr = (long)RDB[loc1 + IFC_FUEP_PTR_POWER]; CheckPointer(FUNCTION_NAME, "(Pptr)", DATA_ARRAY, ptr); AddBuf(fissE, wgt, ptr, id, -1, i, j, k, l); } /***************************************************************************/ }