//DAC control interrupt void tim2_isr(void){ if(timer_interrupt_source(TIM3, TIM_SR_CC1IF)){ gpio_set(GPIOA, GPIO12); //set the pin high. Must do this first for timing timer_clear_flag(TIM2, TIM_SR_CC1IF); //detect end of packet transmission /* if(end of packet){ currently_transmitting = false; if(buffers_full){ buffers_full=false; enable spi1 interrupts set 'full' pin low } timer_disable_counter(TIM2); timer_set_counter(TIM2, 0); gpio_clear(GPIOA, GPIO12); //set DAC-CLK low } */ } if(timer_interrupt_source(TIM3, TIM_SR_UIF)){ gpio_port_write(GPIOC, (next_transmit[1] | (next_transmit[0]<<8))); //set the dac-db pins gpio_clear(GPIOA, GPIO12); //set DAC-CLK low timer_clear_flag(TIM2, TIM_SR_UIF); //reset the interrupt flag generate_sample(); } return; }
void Maximize_method::run(Program_options & options, ostream & output) { Wavefunction * wf=NULL; Sample_point * sample=NULL; sys->generateSample(sample); wfdata->generateWavefunction(wf); sample->attachObserver(wf); int nconfig=100; Array1 <Config_save_point> config_pos(nconfig); Array1 <doublevar> epos(3); Primary guidewf; generate_sample(sample,wf,wfdata,&guidewf,nconfig,config_pos); int nelectrons=sample->electronSize(); Properties_gather mygather; string tablename=options.runid+".table"; ofstream tableout(tablename.c_str()); for(int e=0; e< nelectrons; e++) { sample->getElectronPos(e,epos); for(int d=0; d< 3; d++) { tableout << "e" << e << "_"<< d << " "; } } tableout << "elocal" << endl; for(int i=0; i < nconfig; i++) { maximize(sample,wf,config_pos(i)); for(int e=0; e< nelectrons; e++) { sample->getElectronPos(e,epos); for(int d=0; d< 3; d++) { tableout << epos(d) << " "; } } Properties_point pt; mygather.gatherData(pt, pseudo, sys, wfdata, wf, sample, &guidewf); tableout << pt.energy(0) << endl; config_pos(i).write(cout); } delete wf; delete sample; }
void tim2_isr(void){ if(timer_interrupt_source(TIM2, TIM_SR_CC1IF)){ gpio_set(GPIOA, GPIO14); timer_clear_flag(TIM2, TIM_SR_CC1IF); //now to generate the next sample generate_sample(); i++; if(i==n) i=0; } if(timer_interrupt_source(TIM2, TIM_SR_UIF)){ gpio_clear(GPIOA, GPIO14); //set DAC-CLK low gpio_port_write(GPIOC, (next_transmit[1] | (next_transmit[0]<<8))); //set the dac-db pins timer_clear_flag(TIM2, TIM_SR_UIF); } return; }
void Dmc_method::restorecheckpoint(string & filename, System * sys, Wavefunction_data * wfdata, Pseudopotential * pseudo) { ifstream is(filename.c_str()); if(is) { is.close(); read_configurations(filename, pts); } else { Array1 <Config_save_point> configs; generate_sample(sample,wf,wfdata,guidingwf,nconfig,configs); pts.Resize(nconfig); for(int i=0; i< nconfig; i++) pts(i).config_pos=configs(i); } int ncread=pts.GetDim(0); //cout << "ncread " << ncread << " nwread " << nwread << endl; if(nconfig < ncread) { Array1 <Dmc_point> tmp_pts(nconfig); for(int i=0; i< nconfig; i++) tmp_pts(i)=pts(i); pts=tmp_pts; } else if(nconfig > ncread) { error("Not enough configurations in ", filename); } for(int walker=0; walker < nconfig; walker++) { pts(walker).config_pos.restorePos(sample); mygather.gatherData(pts(walker).prop, pseudo, sys, wfdata, wf, sample, guidingwf); pts(walker).age.Resize(sys->nelectrons(0)+sys->nelectrons(1)); pts(walker).age=0; } find_cutoffs(); updateEtrial(start_feedback); }
void generate_page(char password[25], int sock_in, char *query, char *ip) { char *page = get_param(query, 0); char *ppass = get_param(query, "password"); if ( (ppass == 0) || (strcmp(password, ppass) != 0) ) { web_send(sock_in, html_header("Enter your password")); web_send(sock_in, "<H1>NOT LOGGED IN!</H1><form action=\"/\" method=\"GET\">\n"); web_send(sock_in, "Enter your password:<br>\n<input type=\"text\" name=\"password\">\n"); web_send(sock_in, "<input type=\"submit\" value=\"Login\">\n"); } else { //To make this simple, we will have a bunch of if statements //that then shoot out data off into functions. //The 'index' if ( strcmp(page, "/") == 0 ) generate_notdone(sock_in, query, ip); //About page: if ( strcmp(page, "/about.html") == 0 ) generate_about(sock_in, query, ip); //Test page: if ( strcmp(page, "/testing/") == 0 ) generate_sample(sock_in, query, ip); } }
/* ------------------------------------------ */ int test_filterNR(int argc, const char * argv[]) /* ------------------------------------------ */ { puts("====================="); puts("=== test_filterNR ==="); puts("====================="); generate_sample(); // guess test_gaussian_noise(); // fonctions de bruitage des images test_impulse_noise(); // tests unitaires test_kernel(); test_otsu(); test_histogram_equalization(); // fonctions de debruitage des images test_smooth_filter(); test_median_filter(); return 0; }
/*! */ void Reptation_method::runWithVariables(Properties_manager & prop, System * sys, Wavefunction_data * wfdata, Pseudopotential * psp, ostream & output) { allocateIntermediateVariables(sys, wfdata); prop.setSize(wf->nfunc(), nblock, nstep, 1, sys, wfdata); prop.initializeLog(average_var); Properties_manager prop_center; string logfile, label_temp; prop.getLog(logfile, label_temp); label_temp+="_cen"; prop_center.setLog(logfile, label_temp); prop_center.setSize(wf->nfunc(), nblock, nstep, 1, sys, wfdata); prop_center.initializeLog(average_var); cout.precision(10); output.precision(10); Sample_point * center_samp(NULL); sys->generateSample(center_samp); Reptile_point pt; Array1 <Reptile> reptiles; int nreptile=1; if(!readcheck(readconfig,reptiles)) { Array1 <Config_save_point> configs; generate_sample(sample,wf,wfdata,guidewf,nreptile,configs); reptiles.Resize(nreptile); for(int r=0; r< nreptile; r++) { reptiles[r].direction=1; configs(r).restorePos(sample); wf->notify(all_electrons_move,0); wf->updateLap(wfdata,sample); for(int i=0; i< reptile_length; i++) { doublevar main_diffusion; slither(1,reptiles[r].reptile, mygather,pt,main_diffusion); reptiles[r].reptile.push_back(pt); } } } nreptile=reptiles.GetDim(0); //assert(reptile.size()==reptile_length); //Branch limiting variables //we start off with no limiting, and establish the parameters after the //first block. This seems to be reasonably stable, since it's mostly //to keep the reptile from getting stuck. eref=0; energy_cutoff=1e16; //--------begin averaging.. Array3 <doublevar> derivatives_block(nblock, sys->nIons(), 3); for(int block=0; block< nblock; block++) { //clock_t block_start_time=clock(); doublevar avg_age=0; doublevar max_age=0; doublevar main_diff=0; double ntry=0, naccept=0; double nbounce=0; for(int r=0; r< nreptile; r++) { Reptile & curr_reptile=reptiles[r]; //Control variable that will be set to one when //we change direction, which signals to recalculate //the wave function int recalc=1; for(int step=0; step< nstep; step++) { psp->randomize(); if(recalc) { if(curr_reptile.direction==1) curr_reptile.reptile[reptile_length-1].restorePos(sample); else curr_reptile.reptile[0].restorePos(sample); } doublevar main_diffusion; doublevar accept=slither(curr_reptile.direction, curr_reptile.reptile,mygather, pt, main_diffusion); ntry++; if(accept+rng.ulec() > 1.0) { recalc=0; naccept++; main_diff+=main_diffusion; if(curr_reptile.direction==1) { curr_reptile.reptile.pop_front(); curr_reptile.reptile.push_back(pt); } else { curr_reptile.reptile.pop_back(); curr_reptile.reptile[0].branching=pt.branching; curr_reptile.reptile.push_front(pt); } } else { recalc=1; curr_reptile.direction*=-1; nbounce++; } for(deque<Reptile_point>::iterator i=curr_reptile.reptile.begin(); i!=curr_reptile.reptile.end(); i++) { i->age++; avg_age+=i->age/reptile_length; if(i->age > max_age) max_age=i->age; } Properties_point avgpt; get_avg(curr_reptile.reptile, avgpt); avgpt.parent=0; avgpt.nchildren=1; //just one walker avgpt.children(0)=0; prop.insertPoint(step, 0, avgpt); int cpt=reptile_length/2+1; Properties_point centpt; get_center_avg(curr_reptile.reptile, centpt); centpt.parent=0; centpt.nchildren=1; centpt.children(0)=0; prop_center.insertPoint(step, 0, centpt); curr_reptile.reptile[cpt].restorePos(center_samp); for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->accumulate(center_samp,1.0); if(center_trace != "" && (block*nstep+step)%trace_wait==0) { ofstream checkfile(center_trace.c_str(), ios::app); if(!checkfile)error("Couldn't open ", center_trace); checkfile << "SAMPLE_POINT { \n"; write_config(checkfile, sample); checkfile << "}\n\n"; } } //step } //reptile prop.endBlock(); prop_center.endBlock(); double ntot=parallel_sum(nstep); Properties_block lastblock; prop.getLastBlock(lastblock); eref=lastblock.avg(Properties_types::total_energy,0); energy_cutoff=10*sqrt(lastblock.var(Properties_types::total_energy,0)); nbounce=parallel_sum(nbounce); naccept=parallel_sum(naccept); ntry=parallel_sum(ntry); avg_age=parallel_sum(avg_age); for(int i=0; i< densplt.GetDim(0); i++) densplt(i)->write(); storecheck(reptiles, storeconfig); main_diff=parallel_sum(main_diff); if(output) { output << "****Block " << block << " acceptance " << naccept/ntry << " average steps before bounce " << ntot/nbounce << endl; output << "average age " << avg_age/ntot << " max age " << max_age << endl; output << "eref " << eref << " cutoff " << energy_cutoff << endl; output << "Green's function sampler:" << endl; sampler->showStats(output); prop.printBlockSummary(output); output << "Center averaging: " << endl; prop_center.printBlockSummary(output); } sampler->resetStats(); //clock_t block_end_time=clock(); //cout << mpi_info.node << ":CPU block time " //// << double(block_end_time-block_start_time)/double(CLOCKS_PER_SEC) // << endl; } //block if(output) { output << "############## Reptation Done ################\n"; output << "End averages " << endl; prop.printSummary(output,average_var); output << "Center averages " << endl; prop_center.printSummary(output,average_var); //Print out a PDB file with one of the reptiles, for visualization purposes if(print_pdb) { ofstream pdbout("rmc.pdb"); pdbout.precision(3); pdbout << "REMARK 4 Mode COMPLIES WITH FORMAT V. 2.0\n"; int nelectrons=sample->electronSize(); int counter=1; string name="H"; for(int e=0; e<nelectrons; e++) { for(deque<Reptile_point>::iterator i=reptiles[0].reptile.begin(); i!=reptiles[0].reptile.end(); i++) { pdbout<<"ATOM"<<setw(7)<< counter <<" " <<name<<" UNK 1" <<setw(12)<< i->electronpos[e][0] <<setw(8)<< i->electronpos[e][1] <<setw(8)<< i->electronpos[e][2] << " 1.00 0.00\n"; counter++; } } int nions=sys->nIons(); Array1 <doublevar> ionpos(3); vector <string> atomnames; sys->getAtomicLabels(atomnames); for(int i=0; i< nions; i++) { sys->getIonPos(i,ionpos); pdbout<<"ATOM"<<setw(7)<< counter <<" " <<atomnames[i]<<" UNK 1" <<setw(12)<< ionpos[0] <<setw(8)<< ionpos[1] <<setw(8)<< ionpos[2] << " 1.00 0.00\n"; } counter=1; for(int e=0; e<nelectrons; e++) { for(deque<Reptile_point>::iterator i=reptiles[0].reptile.begin(); i!=reptiles[0].reptile.end(); i++) { if(i != reptiles[0].reptile.begin()) { pdbout << "CONECT" << setw(5) << counter << setw(5) << counter-1 << endl; } counter++; } } } //------------Done PDB file } delete center_samp; wfdata->clearObserver(); deallocateIntermediateVariables(); }
pixelinfo_t * ri_sis(float *texels, int ngensamples, int width, int height) { int i; int maxlevel = 6; double m; double s; double v; double domega0; pixelinfo_t *info; pixelinfo_t **layer; pixelinfo_t *gensamples; FILE *fp; fp = fopen("gensamples.dat", "w"); if (!fp) exit(-1); printf("start sis\n"); gensamples = (pixelinfo_t *)malloc(sizeof(pixelinfo_t) * ngensamples); if (!gensamples) { printf("muda muda muda. gensamples = NULL\n"); exit(-1); } layer = (pixelinfo_t **)malloc(sizeof(pixelinfo_t *) * maxlevel); if (!layer) { printf("muda muda muda. layer = NULL\n"); exit(-1); } for (i = 0; i < maxlevel; i++) { layer[i] = (pixelinfo_t *)malloc(sizeof(pixelinfo_t) * width * height); } info = initpixelinfo(texels, width, height); mean(&m, info, width * height); sd (&s, info, width * height, m); assign_level(info, width * height, s, maxlevel); layerize(layer, maxlevel, info, width * height); //output_hdr(layer[1], 1, width, height); /* detect connected components each layer */ for (i = 0; i < maxlevel; i++) { connected_components(layer[i], width, height); //output_cc(layer[i], i, width, height); } domega0 = 0.01; gamma_4pi(&v, info, width * height, domega0); generate_sample(gensamples, ngensamples, v, layer, maxlevel, width, height); /* Output samples */ fprintf(fp, "%d\n", ngensamples); fprintf(fp, "%d %d\n", width, height); for (i = 0; i < ngensamples; i++) { fprintf(fp, "%d %d %f %f %f\n", gensamples[i].x, gensamples[i].y, gensamples[i].c[0], gensamples[i].c[1], gensamples[i].c[2]); } fclose(fp); return info; }