static void init_volume(void) { int i; fprintf(stderr, "\n"); for(i=0; i<MW_N_DECIBEL; i++) { Db_alone[i] = calc_volume(-i,256<<MW_MIX_FIX); Db_mix[i] = calc_volume(-i,MW_STE_MULT*256); Db_mix12[i] = calc_volume(-i-12,MW_STE_MULT*256); fprintf(stderr, "AAA:%x\n", Db_alone[i]); fprintf(stderr, "BBB:%x\n", Db_mix[i]); fprintf(stderr, "CCC:%x\n", Db_mix12[i]); } }
int trap(int A[], int n) { stack<pair<int, int> > ranges; stack<int> bar_positions; for (int i = 0; i < n; ++i) { if (bar_positions.empty()) { bar_positions.push(i); } else { if (A[i] < A[bar_positions.top()]) { // 比栈顶元素小,继续压入。 bar_positions.push(i); } else { int start; pair<int, int> range; while (!bar_positions.empty()) { start = bar_positions.top(); if (A[start] > A[i]) { break; } // 弹出所有小于等于A[i]的元素 bar_positions.pop(); } // 注意,这里要分两种情况: // 1. A[start]被弹出,那么[start, i]正好构成一个区间,并且这之间的数一定小于A[start]。 // 2. A[start]没有被弹出,[start, i]构成一个区间,并且有可能合并更多区间。 bar_positions.push(i); range.first = start; range.second = i; while (!ranges.empty()) { // 可重叠的子区间弹出 if (is_in_range(range, ranges.top())) { ranges.pop(); } else { break; } } ranges.push(range); } } } int volume = 0; while (!ranges.empty()) { volume += calc_volume(A, ranges.top()); ranges.pop(); } return volume; }
void set_mod_volume (int volume) { int chn; if (volume < 0) volume = 0; else if (volume > 255) volume = 255; mod_volume = volume; for (chn=0; chn<mi.max_chn ; chn++) voice_set_volume (voice_table[chn], calc_volume(chn)); }
int main(int argc, char *argv[]) { int i, j, k;//-- counters HashTable* BT_Node_Ptr; HashTable* BT_Elem_Ptr; //-- MPI int myid, numprocs; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); #ifdef DEBUG if (myid==0){ int w; printf("type in a number: \n"); (void) scanf ("%d", &w); } // MPI_Barrier(MPI_COMM_WORLD); #endif /* create new MPI datastructures for class objects */ MPI_New_Datatype(); /* read original data from serial preprocessing code and then initialize element stiffness routines info */ double epsilon = 1., intfrictang = 1, bedfrictang = 1, gamma = 1; double frict_tiny = 0.1, mu = .0001, rho = 2200, porosity = 1; MatProps matprops(intfrictang, bedfrictang, porosity, mu, rho, epsilon, gamma, frict_tiny, (double) 1, (double) 1, (double) 1); int max_time_steps = 3000, numoutput = 1, adaptflag; double end_time = 10000.0; /* * viz_flag is used to determine which viz output to use * viz_flag%2 == 0 means output tecplotxxxx.plt * viz_flag%3 == 0 means output mshplotxxxx.plt * viz_flag%5 == 0 means output pady's stuff (viz_filenames.out and viz_outputxxx.plt) * viz_flag%7 == 0 means output hdf stuff (not implemented yet) */ int viz_flag = 0; int order_flag = 0; //order flag for time stepping scheme -- not used as of 6/19/03 Read_data(&BT_Node_Ptr, myid, &BT_Elem_Ptr, &matprops, &max_time_steps, &end_time, &numoutput, &adaptflag, &viz_flag, &order_flag); printf("bed friction angle is %e and internal friction angle is %e, epsilon is %e\n", (double) (matprops.bedfrict*180./PI), (double) (matprops.intfrict*180./PI), (double) (matprops.epsilon)); printf("METHOD ORDER %d \n",ORDER); double dummyt=-100.; double maxFluxIntegral=0; //overall maximum of the integral of the //flux on the element boundary int h_c=0; // H_adapt(BT_Elem_Ptr, BT_Node_Ptr, h_c, dummyt, &matprops); //H_adapt(BT_Elem_Ptr, BT_Node_Ptr, h_c, dummyt, &matprops); if(viz_flag%3==0) meshplotter(BT_Elem_Ptr, BT_Node_Ptr, 0,&matprops); /* cccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccc Time Stepping Loop cccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccc */ int time_step = 0; double time = 0; while(time_step <= max_time_steps && time < end_time) { //if(myid ==0) // printf("doing time_step = %d and time is %e\n",time_step, // time*sqrt(matprops.LENGTH_SCALE/matprops.GRAVITY_SCALE)); /* * mesh adaption routines */ double TARGET = 0.005; double UNREFINE_TARGET=GEOFLOW_TINY; int h_count = 0; if (time_step < 0) matprops.frict_tiny=0.1; else if (time_step >= 0) matprops.frict_tiny=0.000001; if(adaptflag != 0) { if(time_step%4 == 0 ) { H_adapt(BT_Elem_Ptr, BT_Node_Ptr, h_count, TARGET, &matprops, &maxFluxIntegral); } else if(time_step%4 == 2 ) { unrefine(BT_Elem_Ptr, BT_Node_Ptr, UNREFINE_TARGET, myid, numprocs, time_step, &matprops); } //P_adapt(BT_Elem_Ptr, BT_Node_Ptr, TARGET); //CN if(viz_flag%3==0) //CN meshplotter(BT_Elem_Ptr, BT_Node_Ptr, time_step+1,&matprops); /* * mesh repartitioning routines */ if(time_step % 10 == 1 && numprocs > 1) { delete_ghost_elms(BT_Elem_Ptr, myid); repartition(BT_Elem_Ptr, BT_Node_Ptr, time_step); // move_data(numprocs, myid, BT_Elem_Ptr, BT_Node_Ptr); } } step(BT_Elem_Ptr, BT_Node_Ptr, myid, numprocs, end_time, &time, &matprops, time_step, &maxFluxIntegral,numoutput); // printf(" maxFluxIntegral %e in hpfem.C \n ",maxFluxIntegral); // exit(0); calc_volume(BT_Elem_Ptr, BT_Node_Ptr, myid, numprocs, &matprops); /* * output results to file */ if(time_step % numoutput == 0) { move_data(numprocs, myid, BT_Elem_Ptr, BT_Node_Ptr); if(viz_flag%3==0) meshplotter(BT_Elem_Ptr, BT_Node_Ptr, time_step+1,&matprops); } time_step++; } move_data(numprocs, myid, BT_Elem_Ptr, BT_Node_Ptr); if(viz_flag%3==0) meshplotter(BT_Elem_Ptr, BT_Node_Ptr, time_step+1,&matprops); printf("%d Finished -- Final simulation time %e\n",myid,time); MPI_Finalize(); return(0); }
void force_calc() { espressoSystemInterface.update(); #ifdef LB_GPU #ifdef SHANCHEN if (lattice_switch & LATTICE_LB_GPU && this_node == 0) lattice_boltzmann_calc_shanchen_gpu(); #endif // SHANCHEN // transfer_momentum_gpu check makes sure the LB fluid doesn't get updated on integrate 0 // this_node==0 makes sure it is the master node where the gpu exists if (lattice_switch & LATTICE_LB_GPU && transfer_momentum_gpu && this_node==0 ) lb_calc_particle_lattice_ia_gpu(); #endif // LB_GPU #ifdef ELECTROSTATICS if (iccp3m_initialized && iccp3m_cfg.set_flag) iccp3m_iteration(); else #endif init_forces(); switch (cell_structure.type) { case CELL_STRUCTURE_LAYERED: layered_calculate_ia(); break; case CELL_STRUCTURE_DOMDEC: if(dd.use_vList) { if (rebuild_verletlist) build_verlet_lists_and_calc_verlet_ia(); else calculate_verlet_ia(); } else calc_link_cell(); break; case CELL_STRUCTURE_NSQUARE: nsq_calculate_ia(); } #ifdef VOLUME_FORCE double volume=0.; for (int i=0;i< MAX_OBJECTS_IN_FLUID;i++){ calc_volume(&volume,i); if (volume<1e-100) break; add_volume_force(volume,i); } #endif #ifdef AREA_FORCE_GLOBAL double area=0.; for (int i=0;i< MAX_OBJECTS_IN_FLUID;i++){ calc_area_global(&area,i); if (area<1e-100) break; add_area_global_force(area,i); } #endif calc_long_range_forces(); #ifdef LB if (lattice_switch & LATTICE_LB) calc_particle_lattice_ia() ; #endif #ifdef COMFORCE calc_comforce(); #endif #ifdef METADYNAMICS /* Metadynamics main function */ meta_perform(); #endif #if defined(LB_GPU) || (defined(ELECTROSTATICS) && defined(CUDA)) copy_forces_from_GPU(); #endif }
/** Calculate forces. * * A short list, what the function is doing: * <ol> * <li> Initialize forces with: \ref friction_thermo_langevin (ghost forces with zero). * <li> Calculate bonded interaction forces:<br> * Loop all local particles (not the ghosts). * <ul> * <li> FENE * <li> ANGLE (cos bend potential) * </ul> * <li> Calculate non-bonded short range interaction forces:<br> * Loop all \ref IA_Neighbor::vList "verlet lists" of all \ref #cells. * <ul> * <li> Lennard-Jones. * <li> Buckingham. * <li> Real space part: Coulomb. * <li> Ramp. * </ul> * <li> Calculate long range interaction forces:<br> Uses <a href=P3M_calc_kspace_forces> P3M_calc_kspace_forces </a> * </ol> */ inline void force_calc() { // Communication step: distribute ghost positions cells_update_ghosts(); // VIRTUAL_SITES pos (and vel for DPD) update for security reason !!! #ifdef VIRTUAL_SITES update_mol_vel_pos(); ghost_communicator(&cell_structure.update_ghost_pos_comm); #endif #if defined(VIRTUAL_SITES_RELATIVE) && defined(LB) // This is on a workaround stage: // When using virtual sites relative and LB at the same time, it is necessary // to reassemble the cell lists after all position updates, also of virtual // particles. if ((lattice_switch & LATTICE_LB) && cell_structure.type == CELL_STRUCTURE_DOMDEC && (!dd.use_vList) ) cells_update_ghosts(); #endif #ifdef COLLISION_DETECTION prepare_collision_queue(); #endif espressoSystemInterface.update(); // Compute the forces from the force objects for (ActorList::iterator actor = forceActors.begin(); actor != forceActors.end(); ++actor) (*actor)->computeForces(espressoSystemInterface); #ifdef LB_GPU #ifdef SHANCHEN if (lattice_switch & LATTICE_LB_GPU && this_node == 0) lattice_boltzmann_calc_shanchen_gpu(); #endif // SHANCHEN // transfer_momentum_gpu check makes sure the LB fluid doesn't get updated on integrate 0 // this_node==0 makes sure it is the master node where the gpu exists if (lattice_switch & LATTICE_LB_GPU && transfer_momentum_gpu && (this_node == 0) ) lb_calc_particle_lattice_ia_gpu(); #endif // LB_GPU #ifdef ELECTROSTATICS if (iccp3m_initialized && iccp3m_cfg.set_flag) iccp3m_iteration(); #endif init_forces(); switch (cell_structure.type) { case CELL_STRUCTURE_LAYERED: layered_calculate_ia(); break; case CELL_STRUCTURE_DOMDEC: if(dd.use_vList) { if (rebuild_verletlist) build_verlet_lists_and_calc_verlet_ia(); else calculate_verlet_ia(); } else calc_link_cell(); break; case CELL_STRUCTURE_NSQUARE: nsq_calculate_ia(); } #ifdef VOLUME_FORCE double volume=0.; for (int i=0;i< MAX_OBJECTS_IN_FLUID;i++){ calc_volume(&volume,i); if (volume<1e-100) break; add_volume_force(volume,i); } #endif #ifdef AREA_FORCE_GLOBAL double area=0.; for (int i=0;i< MAX_OBJECTS_IN_FLUID;i++){ calc_area_global(&area,i); if (area<1e-100) break; add_area_global_force(area,i); } #endif calc_long_range_forces(); #ifdef LB if (lattice_switch & LATTICE_LB) calc_particle_lattice_ia() ; #endif #ifdef COMFORCE calc_comforce(); #endif #ifdef METADYNAMICS /* Metadynamics main function */ meta_perform(); #endif #ifdef CUDA copy_forces_from_GPU(); #endif // VIRTUAL_SITES distribute forces #ifdef VIRTUAL_SITES ghost_communicator(&cell_structure.collect_ghost_force_comm); init_forces_ghosts(); distribute_mol_force(); #endif // Communication Step: ghost forces ghost_communicator(&cell_structure.collect_ghost_force_comm); // apply trap forces to trapped molecules #ifdef MOLFORCES calc_and_apply_mol_constraints(); #endif // should be pretty late, since it needs to zero out the total force #ifdef COMFIXED calc_comfixed(); #endif // mark that forces are now up-to-date recalc_forces = 0; #ifdef COLLISION_DETECTION handle_collisions(); #endif }