double m2sim_minimum_courant_time(m2sim *m2) { int n, err; int *L = m2->local_grid_size; double dt, mindt = -1.0; m2vol *V; double globalmindt = mindt; #ifdef _OPENMP #pragma omp parallel private(V,dt) firstprivate(mindt) default(shared) #endif { #ifdef _OPENMP #pragma omp for #endif for (n=0; n<L[0]; ++n) { V = m2->volumes + n; if (V->zone_type != M2_ZONE_TYPE_FULL) { continue; } dt = m2vol_minimum_dimension(V) / m2aux_maximum_wavespeed(&V->aux, &err); if (err) { MSG(INFO, "got bad wavespeed"); m2_print_state(NULL, &V->aux, NULL); MSGF(FATAL, "at global index [%d %d %d]", V->global_index[1], V->global_index[2], V->global_index[3]); } if (dt < mindt || mindt < 0.0) { mindt = dt; } } #ifdef _OPENMP #pragma omp critical #endif { if (mindt < globalmindt || globalmindt < 0.0) { globalmindt = mindt; } } } #if M2_HAVE_MPI if (m2->cart_comm) { MPI_Comm cart_comm = *((MPI_Comm *) m2->cart_comm); MPI_Allreduce(MPI_IN_PLACE, &globalmindt, 1, MPI_DOUBLE, MPI_MIN, cart_comm); } #endif return globalmindt; }
static void debug_tag_spec_flags(lame_internal_flags * gfc, const char* info) { MSGF(gfc, "%s\n", info); MSGF(gfc, "CHANGED_FLAG : %d\n", test_tag_spec_flags(gfc, CHANGED_FLAG )); MSGF(gfc, "ADD_V2_FLAG : %d\n", test_tag_spec_flags(gfc, ADD_V2_FLAG )); MSGF(gfc, "V1_ONLY_FLAG : %d\n", test_tag_spec_flags(gfc, V1_ONLY_FLAG )); MSGF(gfc, "V2_ONLY_FLAG : %d\n", test_tag_spec_flags(gfc, V2_ONLY_FLAG )); MSGF(gfc, "SPACE_V1_FLAG : %d\n", test_tag_spec_flags(gfc, SPACE_V1_FLAG)); MSGF(gfc, "PAD_V2_FLAG : %d\n", test_tag_spec_flags(gfc, PAD_V2_FLAG )); }
int lame_encode_ogg_init(lame_global_flags *gfp) { lame_internal_flags *gfc=gfp->internal_flags; char comment[MAX_COMMENT_LENGTH+1]; /********** Encode setup ************/ /* choose an encoding mode */ /* (mode 0: 44kHz stereo uncoupled, roughly 128kbps VBR) */ if (gfp->compression_ratio < 5.01) { memcpy(&vi2,&info_E,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_E \n" ); } else if (gfp->compression_ratio < 6) { memcpy(&vi2,&info_D,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_D \n" ); } else if (gfp->compression_ratio < 8) { memcpy(&vi2,&info_C,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_C \n" ); } else if (gfp->compression_ratio < 10) { memcpy(&vi2,&info_B,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_B \n" ); } else if (gfp->compression_ratio < 12) { memcpy(&vi2,&info_A,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_A \n" ); } else { memcpy(&vi2,&info_A,sizeof(vi2)); MSGF( gfc, "Encoding with Vorbis mode info_A \n" ); } vi2.channels = gfc->channels_out; vi2.rate = gfp->out_samplerate; /* add a comment */ vorbis_comment_init(&vc2); vorbis_comment_add(&vc2,"Track encoded using L.A.M.E. libvorbis interface."); /* Add ID3-style comments to the output using (for the time being) the "private data members" in the "id3tag_spec" data structure. This was from a patch by Ralph Giles <*****@*****.**> */ #ifdef THIS_CODE_IS_NOT_BROKEN_ANYMORE if(gfp->tag_spec.title) { strcpy(comment,"TITLE="); strncat(comment,gfp->tag_spec.title,MAX_COMMENT_LENGTH-strlen(comment)); vorbis_comment_add(&vc2,comment); } if(gfp->tag_spec.artist) { strcpy(comment,"ARTIST="); strncat(comment,gfp->tag_spec.artist,MAX_COMMENT_LENGTH-strlen(comment)); vorbis_comment_add(&vc2,comment); } if(gfp->tag_spec.album) { strcpy(comment,"ALBUM="); strncat(comment,gfp->tag_spec.album,MAX_COMMENT_LENGTH-strlen(comment)); vorbis_comment_add(&vc2,comment); } /* pretend that the ID3 fields are equivalent to the Vorbis fields */ if(gfp->tag_spec.year) { sprintf(comment, "DATE=%d", gfp->tag_spec.year); vorbis_comment_add(&vc2,comment); } if(gfp->tag_spec.comment) { strcpy(comment,"DESCRIPTION="); strncat(comment,gfp->tag_spec.comment,MAX_COMMENT_LENGTH-strlen(comment)); vorbis_comment_add(&vc2,comment); } /* TODO -- support for track and genre */ #endif /* set up the analysis state and auxiliary encoding storage */ vorbis_analysis_init(&vd2,&vi2); vorbis_block_init(&vd2,&vb2); /* set up our packet->stream encoder */ /* pick a random serial number; that way we can more likely build chained streams just by concatenation */ srand(time(NULL)); ogg_stream_init(&os2,rand()); /* Vorbis streams begin with three headers; the initial header (with most of the codec setup parameters) which is mandated by the Ogg bitstream spec. The second header holds any comment fields. The third header holds the bitstream codebook. We merely need to make the headers, then pass them to libvorbis one at a time; libvorbis handles the additional Ogg bitstream constraints */ { ogg_packet header; ogg_packet header_comm; ogg_packet header_code; vorbis_analysis_headerout(&vd2,&vc2,&header,&header_comm,&header_code); ogg_stream_packetin(&os2,&header); /* automatically placed in its own page */ ogg_stream_packetin(&os2,&header_comm); ogg_stream_packetin(&os2,&header_code); /* no need to write out here. We'll get to that in the main loop */ } return 0; }
static void riemann_solver(m2vol *VL, m2vol *VR, int axis, double *F, int suppress_extrapolation) { int q; m2riemann_problem R = { .m2 = VL->m2 }; double *UL = R.Ul; double *UR = R.Ur; double *FL = R.Fl; double *FR = R.Fr; double *lamL = R.lamL; double *lamR = R.lamR; double yl[8], yr[8]; /* cell-centered left/right interpolation variables */ double yL[8], yR[8]; /* face-centered left/right interpolation variables */ double xL = m2vol_coordinate_centroid(VL, axis); double xR = m2vol_coordinate_centroid(VR, axis); double *n = R.nhat; m2prim *PL = &R.Pl; m2prim *PR = &R.Pr; m2aux *AL = &R.Al; m2aux *AR = &R.Ar; int err[6]; int E = 1; if (suppress_extrapolation) E = 0; if (VL->m2->suppress_extrapolation_at_unhealthy_zones) { if (VL->zone_health != 0) E = 0; if (VR->zone_health != 0) E = 0; } if (VL->zone_type == M2_ZONE_TYPE_SHELL || VR->zone_type == M2_ZONE_TYPE_SHELL) { return; } n[0] = 0.0; n[1] = 0.0; n[2] = 0.0; n[3] = 0.0; n[axis] = 1.0; m2vol_to_interpolated(VL, yl, 1); m2vol_to_interpolated(VR, yr, 1); switch (axis) { case 1: for (q=0; q<8; ++q) yL[q] = yl[q] + E*VL->grad1[q] * (VL->x1[1] - xL); for (q=0; q<8; ++q) yR[q] = yr[q] + E*VR->grad1[q] * (VR->x0[1] - xR); break; case 2: for (q=0; q<8; ++q) yL[q] = yl[q] + E*VL->grad2[q] * (VL->x1[2] - xL); for (q=0; q<8; ++q) yR[q] = yr[q] + E*VR->grad2[q] * (VR->x0[2] - xR); break; case 3: for (q=0; q<8; ++q) yL[q] = yl[q] + E*VL->grad3[q] * (VL->x1[3] - xL); for (q=0; q<8; ++q) yR[q] = yr[q] + E*VR->grad3[q] * (VR->x0[3] - xR); break; } m2sim_from_interpolated(VL->m2, yL, PL); m2sim_from_interpolated(VR->m2, yR, PR); UL[B11] = PL->B1; UL[B22] = PL->B2; UL[B33] = PL->B3; UR[B11] = PR->B1; UR[B22] = PR->B2; UR[B33] = PR->B3; switch (axis) { case 1: UL[B11] = UR[B11] = PL->B1 = PR->B1 = VL->Bflux1A / VL->area1; break; case 2: UL[B22] = UR[B22] = PL->B2 = PR->B2 = VL->Bflux2A / VL->area2; break; case 3: UL[B33] = UR[B33] = PL->B3 = PR->B3 = VL->Bflux3A / VL->area3; break; } err[0] = m2sim_from_primitive(VL->m2, PL, NULL, NULL, 1.0, UL, AL); err[1] = m2sim_from_primitive(VR->m2, PR, NULL, NULL, 1.0, UR, AR); err[2] = m2aux_eigenvalues(AL, n, lamL); err[3] = m2aux_eigenvalues(AR, n, lamR); err[4] = m2aux_fluxes(AL, n, FL); err[5] = m2aux_fluxes(AR, n, FR); if (err[2]) VL->zone_health |= (1<<M2_BIT_BAD_EIGENVALUES); if (err[3]) VR->zone_health |= (1<<M2_BIT_BAD_EIGENVALUES); if (err[2] || err[3]) { if (suppress_extrapolation) { MSGF(INFO, "eigenvalues for %d-interface [%d %d %d] could not be found", axis, VL->global_index[1], VL->global_index[2], VL->global_index[3]); lamL[0] = -1.0; lamL[7] = +1.0; lamR[0] = -1.0; lamR[7] = +1.0; } else { riemann_solver(VL, VR, axis, F, 1); return; } } R.Sl = M2_MIN3(lamL[0], lamR[0], 0.0); R.Sr = M2_MAX3(lamL[7], lamR[7], 0.0); switch (VL->m2->riemann_solver) { case M2_RIEMANN_HLLE: riemann_solver_hlle(&R); break; case M2_RIEMANN_HLLC: riemann_solver_hllc(&R); break; default: MSG(FATAL, "invalid riemann solver"); break; } memcpy(F, R.F_hat, 8 * sizeof(double)); } static double plm_gradient(double *xs, double *fs, double plm) { #define minval3(a,b,c) ((a<b) ? ((a<c) ? a : c) : ((b<c) ? b : c)) #define sign(x) ((x > 0.0) - (x < 0.0)) double xL = xs[0]; double x0 = xs[1]; double xR = xs[2]; double yL = fs[0]; double y0 = fs[1]; double yR = fs[2]; double a = (yL - y0) / (xL - x0) * plm; double b = (yL - yR) / (xL - xR); double c = (y0 - yR) / (x0 - xR) * plm; double sa = sign(a), sb = sign(b), sc = sign(c); double fa = fabs(a), fb = fabs(b), fc = fabs(c); double g = 0.25 * fabs(sa + sb) * (sa + sc) * minval3(fa, fb, fc); if (g != g) { MSGF(FATAL, "got NAN gradient: [%f %f %f] [%f %f %f]", xs[0], xs[1], xs[2], fs[0], fs[1], fs[2]); } return g; #undef minval3 #undef sign }