Lattice1D::Lattice1D(int dim, double length, bool periodic_x_axis, string _coordinate_system) { if (_coordinate_system != "cartesian" && _coordinate_system != "cylindrical") { my_abort("The coordinate system you have chosen is not implemented."); } if (_coordinate_system == "cylindrical" && periodic_x_axis == true) { my_abort("You cannot choose periodic boundary on the radial axis."); } coordinate_system = _coordinate_system; length_x = length; length_y = 0; if (_coordinate_system == "cylindrical") { dim += 1; delta_x = length_x / (double(dim) - 0.5); } else { delta_x = length_x / double(dim); } delta_y = 1.0; periods[0] = 0; periods[1] = (int) periodic_x_axis; #ifdef HAVE_MPI MPI_Comm_size(MPI_COMM_WORLD, &mpi_procs); mpi_dims[0] = mpi_procs; mpi_dims[1] = 1; MPI_Dims_create(mpi_procs, 2, mpi_dims); //partition all the processes (the size of MPI_COMM_WORLD's group) into an 2-dimensional topology MPI_Cart_create(MPI_COMM_WORLD, 2, mpi_dims, periods, 0, &cartcomm); MPI_Comm_rank(cartcomm, &mpi_rank); MPI_Cart_coords(cartcomm, mpi_rank, 2, mpi_coords); #else mpi_procs = 1; mpi_rank = 0; mpi_dims[0] = mpi_dims[1] = 1; mpi_coords[0] = mpi_coords[1] = 0; #endif halo_x = 4; halo_y = 0; global_dim_x = dim + periods[1] * 2 * halo_x; global_dim_y = 1; global_no_halo_dim_x = dim; global_no_halo_dim_y = 1; //set dimension of tiles and offsets calculate_borders(mpi_coords[0], mpi_dims[0], &start_x, &end_x, &inner_start_x, &inner_end_x, dim, halo_x, periods[1]); if (coordinate_system == "cylindrical" && mpi_coords[1] == 0) { inner_start_x += 1; } dim_x = end_x - start_x; start_y = 0; end_y = 1; inner_start_y = 0; inner_end_y = 1; dim_y = 1; }
void Lattice2D::init(int _dim_x, double _length_x, int _dim_y, double _length_y, bool periodic_x_axis, bool periodic_y_axis, double angular_velocity, string _coordinate_system) { if (_coordinate_system != "cartesian" && _coordinate_system != "cylindrical") { my_abort("The coordinate system you have chosen is not implemented."); } if (_coordinate_system == "cylindrical" && periodic_x_axis == true) { my_abort("You cannot choose periodic boundary on the radial axis."); } length_x = _length_x; length_y = _length_y; if (_coordinate_system == "cylindrical") { _dim_x += 1; delta_x = length_x / (double(_dim_x) - 0.5); } else { delta_x = length_x / double(_dim_x); } delta_y = length_y / double(_dim_y); coordinate_system = _coordinate_system; periods[0] = (int) periodic_y_axis; periods[1] = (int) periodic_x_axis; mpi_dims[0] = mpi_dims[1] = 0; #ifdef HAVE_MPI MPI_Comm_size(MPI_COMM_WORLD, &mpi_procs); MPI_Dims_create(mpi_procs, 2, mpi_dims); //partition all the processes (the size of MPI_COMM_WORLD's group) into an 2-dimensional topology MPI_Cart_create(MPI_COMM_WORLD, 2, mpi_dims, periods, 0, &cartcomm); MPI_Comm_rank(cartcomm, &mpi_rank); MPI_Cart_coords(cartcomm, mpi_rank, 2, mpi_coords); #else mpi_procs = 1; mpi_rank = 0; mpi_dims[0] = mpi_dims[1] = 1; mpi_coords[0] = mpi_coords[1] = 0; #endif halo_x = (angular_velocity == 0. ? 4 : 8); halo_y = (angular_velocity == 0. ? 4 : 8); global_dim_x = _dim_x + periods[1] * 2 * halo_x; global_dim_y = _dim_y + periods[0] * 2 * halo_y; global_no_halo_dim_x = _dim_x; global_no_halo_dim_y = _dim_y; //set dimension of tiles and offsets calculate_borders(mpi_coords[1], mpi_dims[1], &start_x, &end_x, &inner_start_x, &inner_end_x, _dim_x, halo_x, periods[1]); if (coordinate_system == "cylindrical" && mpi_coords[1] == 0) { inner_start_x += 1; } calculate_borders(mpi_coords[0], mpi_dims[0], &start_y, &end_y, &inner_start_y, &inner_end_y, _dim_y, halo_y, periods[0]); dim_x = end_x - start_x; dim_y = end_y - start_y; }
double bessel_j_zeros(int l, int x) { // l goes from 0 to 19; x from 0 to 19 double zeros[] = {2.40482556, 5.52007811, 8.65372791, 11.79153444, 14.93091771, 18.07106397, 21.21163663, 24.35247153, 27.49347913, 30.63460647, 33.77582021, 36.91709835, 40.05842576, 43.19979171, 46.34118837, 49.48260990, 52.62405184, 55.76551076, 58.90698393, 62.04846919, 3.83170597, 7.01558667, 10.17346814, 13.32369194, 16.47063005, 19.61585851, 22.76008438, 25.90367209, 29.04682853, 32.18967991, 35.33230755, 38.47476623, 41.61709421, 44.75931900, 47.90146089, 51.04353518, 54.18555364, 57.32752544, 60.46945785, 63.61135670, 5.13562230, 8.41724414, 11.61984117, 14.79595178, 17.95981949, 21.11699705, 24.27011231, 27.42057355, 30.56920450, 33.71651951, 36.86285651, 40.00844673, 43.15345378, 46.29799668, 49.44216411, 52.58602351, 55.72962705, 58.87301577, 62.01622236, 65.15927319, 6.38016190, 9.76102313, 13.01520072, 16.22346616, 19.40941523, 22.58272959, 25.74816670, 28.90835078, 32.06485241, 35.21867074, 38.37047243, 41.52071967, 44.66974312, 47.81778569, 50.96502991, 54.11161557, 57.25765160, 60.40322414, 63.54840218, 66.69324167, 7.58834243, 11.06470949, 14.37253667, 17.61596605, 20.82693296, 24.01901952, 27.19908777, 30.37100767, 33.53713771, 36.69900113, 39.85762730, 43.01373772, 46.16785351, 49.32036069, 52.47155140, 55.62165091, 58.77083574, 61.91924620, 65.06699526, 68.21417486, 8.77148382, 12.33860420, 15.70017408, 18.98013388, 22.21779990, 25.43034115, 28.62661831, 31.81171672, 34.98878129, 38.15986856, 41.32638325, 44.48931912, 47.64939981, 50.80716520, 53.96302656, 57.11730278, 60.27024507, 63.42205405, 66.57289189, 69.72289116, 9.93610952, 13.58929017, 17.00381967, 20.32078921, 23.58608444, 26.82015198, 30.03372239, 33.23304176, 36.42201967, 39.60323942, 42.77848161, 45.94901600, 49.11577372, 52.27945390, 55.44059207, 58.59960563, 61.75682490, 64.91251478, 68.06689027, 71.22012770, 11.08637002, 14.82126873, 18.28758283, 21.64154102, 24.93492789, 28.19118846, 31.42279419, 34.63708935, 37.83871738, 41.03077369, 44.21540851, 47.39416576, 50.56818468, 53.73832537, 56.90524999, 60.06947700, 63.23141837, 66.39140576, 69.54970927, 72.70655117, 12.22509226, 16.03777419, 19.55453643, 22.94517313, 26.26681464, 29.54565967, 32.79580004, 36.02561506, 39.24044800, 42.44388774, 45.63844418, 48.82593038, 52.00769146, 55.18474794, 58.35788903, 61.52773517, 64.69478124, 67.85942699, 71.02199904, 74.18276693, 13.35430048, 17.24122038, 20.80704779, 24.23388526, 27.58374896, 30.88537897, 34.15437792, 37.40009998, 40.62855372, 43.84380142, 47.04870074, 50.24532696, 53.43522716, 56.61958027, 59.79930163, 62.97511353, 66.14759402, 69.31721152, 72.48434982, 75.64932654, 14.47550069, 18.43346367, 22.04698536, 25.50945055, 28.88737506, 32.21185620, 35.49990921, 38.76180702, 42.00419024, 45.23157410, 48.44715139, 51.65325167, 54.85161908, 58.04358793, 61.23019798, 64.41227241, 67.59047207, 70.76533400, 73.93729938, 77.10673425, 15.58984788, 19.61596690, 23.27585373, 26.77332255, 30.17906118, 33.52636408, 36.83357134, 40.11182327, 43.36836095, 46.60813268, 49.83465351, 53.05049896, 56.25760472, 59.45745691, 62.65121739, 65.83980880, 69.02397393, 72.20431796, 75.38133933, 78.55545246, 16.69824993, 20.78990636, 24.49488504, 28.02670995, 31.45996004, 34.82998699, 38.15637750, 41.45109231, 44.72194354, 47.97429353, 51.21196700, 54.43777693, 57.65384481, 60.86180468, 64.06293782, 67.25826456, 70.44860840, 73.63464196, 76.81692044, 79.99590644, 17.80143515, 21.95624407, 25.70510305, 29.27063044, 32.73105331, 36.12365767, 39.46920683, 42.78043927, 46.06571091, 49.33078010, 52.57976906, 55.81571988, 59.04093404, 62.25718939, 65.46588380, 68.66813322, 71.86484051, 75.05674474, 78.24445722, 81.42848829, 18.89999795, 23.11577835, 26.90736898, 30.50595016, 33.99318498, 37.40818513, 40.77282785, 44.10059057, 47.40034778, 50.67823695, 53.93866621, 57.18489860, 60.41940985, 63.64411751, 66.86053301, 70.06986583, 73.27309662, 76.47102976, 79.66433188, 82.85356054, 19.99443063, 24.26918003, 28.10241523, 31.73341334, 35.24708679, 38.68427639, 42.06791700, 45.41218961, 48.72646412, 52.01724128, 55.28920415, 58.54582890, 61.78975990, 65.02305025, 68.24732200, 71.46387589, 74.67376871, 77.87786897, 81.07689772, 84.27145907, 21.08514611, 25.41701901, 29.29087070, 32.95366489, 36.49339791, 39.95255349, 43.35507320, 46.71580944, 50.04460602, 53.34831233, 56.63187594, 59.89897873, 63.15242819, 66.39440904, 69.62665088, 72.85054351, 76.06721817, 79.27760620, 82.48248211, 85.68249584, 22.17249462, 26.55978414, 30.47327995, 34.16726785, 37.73268052, 41.21356706, 44.63482975, 48.01196294, 51.35526465, 54.67191918, 57.96712883, 61.24477410, 64.50782040, 67.75858011, 70.99888749, 74.23021912, 77.45377900, 80.67055998, 83.88138905, 87.08696117, 23.25677609, 27.69789835, 31.65011815, 35.37471722, 38.96543205, 42.46780721, 45.90766387, 49.30111134, 52.65888365, 55.98848722, 59.29536994, 62.58360418, 65.85630828, 69.11591850, 72.36437087, 75.60322657, 78.83376063, 82.05702611, 85.27390141, 88.48512576, 24.33824962, 28.83173035, 32.82180276, 36.57645076, 40.19209510, 43.71571242, 47.17400457, 50.58367114, 53.95586528, 57.29840365, 60.61697113, 63.91582558, 67.19823350, 70.46675142, 73.72341433, 76.96986585, 80.20745037, 83.43727983, 86.66028299, 89.87724253, 25.41714081, 29.96160379, 33.98870279, 37.77285784, 41.41306551, 44.95767675, 48.43423920, 51.86001993, 55.24657561, 58.60202207, 61.93227307, 65.24176599, 68.53391094, 71.81138120, 75.07630808, 78.33041549, 81.57511555, 84.81157774, 88.04078020, 91.26354816 }; if (l < 20 && l >= 0 && x >= 0 && x < 20) { return zeros[x + l * 20]; } else { my_abort("bessel_j_zeros takes integer numbers from 0 to 19"); } return std::numeric_limits<double>::quiet_NaN(); }
// Return a pointer to a FunctionExecutionState which contains the address // specified by "a" in its stack frame // Assumes: The stack grows DOWNWARD on all supported platforms so this // returns the function entry with the smallest FP that is HIGHER // than "a" and a lowestSP that is LOWER than "a" // Returns 0 if no function found static FunctionExecutionState* returnFunctionExecutionStateWithAddress(Addr a) { Int i; ThreadId tid = VG_(get_running_tid)(); FunctionExecutionState* cur_fn = 0; FunctionExecutionState* next_fn = 0; FJALAR_DPRINTF("Looking for function corresponding " "to stack variable 0x%p\n", (void *)a); // Traverse the function stack from the function with // the highest ESP to the one with the lowest ESP // but DON'T LOOK at the function that's the most // recent one on the stack yet - hence 0 <= i <= (fn_stack_first_free_index - 2) for (i = 0; i <= fn_stack_first_free_index[tid] - 2; i++) { cur_fn = &FunctionExecutionStateStack[tid][i]; next_fn = &FunctionExecutionStateStack[tid][i + 1]; if (!cur_fn || !next_fn) { printf( "Error in returnFunctionExecutionStateWithAddress()"); my_abort(); } FJALAR_DPRINTF("cur_fn->FP: %p\n", (void *)cur_fn->FP); FJALAR_DPRINTF("next_fn->FP: %p\n", (void *)next_fn->FP); // If it is not the most recent function pushed on the stack, // then the stack frame of this function lies in between // the EBP of that function and the function immediately // following it on the stack if ((cur_fn->FP >= a) && (next_fn->FP <= a)) { FJALAR_DPRINTF("Returning functionEntry: %p\n", cur_fn); return cur_fn; } } // If a function hasn't been found yet, now // look at the most recent function on the stack: // If it is the most recent function on the stack, // then the stack frame can only be approximated to lie // in between its FP and lowestSP // (this isn't exactly accurate because there are issues // with lowestSP, but at least it'll give us some info.) cur_fn = fnStackTop(tid); if ((cur_fn->FP >= a) && (cur_fn->lowestSP <= a)) { FJALAR_DPRINTF("Returning functionEntry: %zx\n", (ptrdiff_t)cur_fn); return cur_fn; } FJALAR_DPRINTF(" EXIT FAILURE returnFunctionExecutionStateWithAddress\n"); return 0; }
int sw2(int a) { switch(a) { case 0: my_abort(); case 1: return 2; case 2: return getpid(); default: break; } return 1; }
void bvshoot(double *y, double *yend, double err, double eps, int maxit, int *iret, int n, int ishow, int iper, int ipar, int ivar, double sect) { double *jac, *f, *fdev, *y0, *y1; double dev, error, ytemp; int ntot = n; int i, istart = 1, j; int ipvt[MAXODE1]; char esc; int info, niter = 0; double dt = DELTA_T, t; double t0 = T0; double t1 = T0 + TEND * dt / fabs(dt); if (iper) ntot = n + 1; jac = (double *)malloc(ntot * ntot * sizeof(double)); f = (double *)malloc(ntot * sizeof(double)); fdev = (double *)malloc(ntot * sizeof(double)); y0 = (double *)malloc(ntot * sizeof(double)); y1 = (double *)malloc(ntot * sizeof(double)); for (i = 0; i < n; i++) y0[i] = y[i]; if (iper) get_val(upar_names[ipar], &y0[n]); /* dt=(t1-t0)/nt; */ while (1) { esc = my_abort(); { if (esc == ESC) { *iret = ABORT; break; } if (esc == '/') { *iret = ABORT_ALL; break; } } t = t0; istart = 1; if (iper) set_val(upar_names[ipar], y0[n]); if (ishow) { integrate(&t, y, TEND, DELTA_T, 1, NJMP, &istart); } else { if (ode_int(y, &t, &istart) == 0) { *iret = -4; goto bye; } } for (i = 0; i < n; i++) { y1[i] = y[i]; /* plintf("%f \n",y[i]); */ } do_bc(y0, t0, y1, t1, f, n); if (iper) f[n] = y1[ivar] - sect; error = 0.0; for (i = 0; i < ntot; i++) error += fabs(f[i]); if (error < err) { for (i = 0; i < n; i++) y[i] = y0[i]; /* Good values .... */ if (iper) { set_val(upar_names[ipar], y0[n]); redraw_params(); } for (i = 0; i < n; i++) yend[i] = y1[i]; *iret = GOODSHOT; goto bye; } /* plintf("err1 = %f tol= %f \n",error,err); */ niter++; if (niter > maxit) { *iret = -2; goto bye; } /* Too many iterates */ /* create the Jacobian matrix ... */ for (j = 0; j < ntot; j++) { for (i = 0; i < n; i++) y[i] = y0[i]; if (fabs(y0[j]) < eps) dev = eps * eps; else dev = eps * fabs(y0[j]); if (j < n) y[j] = y[j] + dev; ytemp = y0[j]; y0[j] = y0[j] + dev; if (j == n) set_val(upar_names[ipar], y0[j]); t = t0; istart = 1; if (ode_int(y, &t, &istart) == 0) { *iret = -4; goto bye; } do_bc(y0, t0, y, t1, fdev, n); if (iper) fdev[n] = y[ivar] - sect; y0[j] = ytemp; for (i = 0; i < ntot; i++) jac[j + i * ntot] = (fdev[i] - f[i]) / dev; } sgefa(jac, ntot, ntot, ipvt, &info); if (info != -1) { *iret = -3; goto bye; } for (i = 0; i < ntot; i++) fdev[i] = f[i]; sgesl(jac, ntot, ntot, ipvt, fdev, 0); error = 0.0; for (i = 0; i < ntot; i++) { y0[i] = y0[i] - fdev[i]; error += fabs(fdev[i]); } for (i = 0; i < n; i++) y[i] = y0[i]; /* plintf("error2 = %f \n",error); */ if (error < 1.e-10) { for (i = 0; i < n; i++) yend[i] = y1[i]; *iret = 2; goto bye; } } bye: free(f); free(y1); free(y0); free(jac); free(fdev); }
void CALLBACK TimeProc( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 ) { /* we timed out */ my_abort( 0 ); }
void my_assert(bool cond) { if (!cond) my_abort(); }
void abort_if(bool cond) { if (cond) my_abort(); }