release_atom21/atom_support.c /* atom_support.c #include #include #include #include #include "datatypes.h" #include "list.h" #include "atom_support.h" #define FALSE 0 #define TRUE 1 // private...

see attachments



release_atom21/atom_support.c /* atom_support.c<-- a="" template="" *="" prof.="" calhoun=""><-- many="" updates="" required="" *="" jonccal="" *="" ece="" 2230="" spring="" 2021="" *="" mp2="" *="" *="" propose:="" a="" template="" for="" mp2="" *="" *="" assumptions:="" *="" *="" bugs:="" *="" *="" you="" can="" modify="" the="" interface="" for="" any="" of="" the="" atom_="" functions="" if="" you="" like="" *="" but="" you="" must="" clearly="" document="" your="" changes.="" *="" *="" (you="" cannot="" modify="" any="" of="" the="" details="" of="" the="" list.h="" interface,="" or="" use="" any="" *="" of="" the="" private="" variables="" outside="" of="" list.c.)="" */="" #include=""> #include #include #include #include #include "datatypes.h" #include "list.h" #include "atom_support.h" #define FALSE 0 #define TRUE 1 // private functions for use in atom_support.c only void fill_atom_record(atom_t *new); // collect input void print_atom_rec_short(atom_t *rec); // print one record void print_atom_rec_long(atom_t *rec) ; // print one record void get_bounding_box(float* minX, float* maxX, float* minY, float* maxY); int determine_inside_box(data_t* atom_ptr, float x_min, float x_max, float y_min, float y_max); /* atom_compare is required by the list ADT for sorted lists. * * This function returns * 1 if rec_a should be closer to the head than rec_b, * -1 if rec_b is to be considered closer to the head, and * 0 if the records are equal. * * For the atom data we want to sort from lowest atom ID up, so * closer to the front means a smaller atom ID. * * The function expects pointers to two record structures, and it is an error * if either is NULL * * THIS FUNCTION SHOULD NOT BE CHANGED */ int atom_compare(const atom_t *record_a, const atom_t *record_b) { assert(record_a != NULL && record_b !=NULL); if (record_a->atom_id < record_b-="">atom_id) return 1; else if (record_a->atom_id > record_b->atom_id) return -1; else return 0; } /* Function to pass into List ADT during construction to free the memory * associate with a atom record. This hides the details of how the record * is defined from the List ADT. */ void atom_rec_cleanup(atom_t *rec) { if (rec != NULL) { free(rec); } } /* This creates a list and it can be either a sorted or unsorted list * * This function is provided to you as an example of how to use * function pointers. */ list_t * atom_list_create(void) { return list_construct(atom_compare, atom_rec_cleanup); } /* this function frees the memory for either a sorted or unsorted list. */ void atom_list_cleanup(list_t * list_ptr) { /* TODO */ } /* print one of the atom record lists * * inputs: * list_ptr: a list_t * pointer to either sorted or unsorted list * * type_of_list: a charter string that must be either "List" or "Queue" * * output: prints the list in the format required for grading. * Do not change any of these lines (i.e. printfs && print_atom_rec_short() */ void atom_list_print(list_t * list_ptr, char *list_type) { assert(strcmp(list_type, "List")==0 || strcmp(list_type, "Queue")==0); int i, num_in_list; num_in_list = 0; // fix atom_t *rec_ptr = NULL; // fix if (num_in_list == 0) { printf("%s empty\n", list_type); } else { printf("%s has %d record%s\n", list_type, num_in_list, num_in_list==1 ? "." : "s"); for (i = 0; i < num_in_list;="" i++)="" {="" printf("%4d:="" ",="" i);="" rec_ptr="NULL;" fix="" to="" use="" list_access(ptr,="" i)!="" print_atom_rec_short(rec_ptr);="" }="" }="" rec_ptr="NULL;" }="" *="" the="" function="" takes="" a="" pointer="" to="" each="" list="" and="" prints="" the="" *="" number="" of="" items="" in="" each="" list="" */="" void="" atom_list_stats(list_t="" *="" sorted,="" list_t="" *="" unsorted)="" {="" todo:="" get="" the="" number="" in="" list="" and="" size="" of="" the="" list="" int="" num_in_sorted_list="-1;" int="" num_in_unsorted_list="-1;" int="" order_of_list="1024;" fix="" printf("number="" records:="" %d,="" order:="" %s\n",="" num_in_sorted_list,="" order_of_list="=" 1="" "ascending"="" :="" "descending");="" printf("number="" records="" in="" queue:="" %d\n",="" num_in_unsorted_list);="" }="" *="" this="" function="" adds="" an="" atom="" to="" the="" list.="" *="" *="" otherwise,="" if="" the="" list="" is="" full="" the="" atom="" is="" rejected.="" */="" void="" atom_list_add(list_t="" *="" list_ptr,="" int="" max_list_size)="" {="" atom_t="" *rec_ptr="NULL;" fix="" fill_atom_record(rec_ptr);="" todo:="" determine="" the="" correct="" return="" value="" int="" added_return="-2;" if="" (added_return="=" 1)="" {="" printf("inserted:="" %d\n",="" rec_ptr-="">atomic_num); } else if (added_return == -1) { printf("Rejected: %d\n", rec_ptr->atomic_num); } else { printf("Error with return value! Fix your code.\n"); } //TODO: cleanup rec_ptr = NULL; } /* This function prints the first atom with the matching potential energy in * the list. */ void atom_list_lookup_potential_energy(list_t * list_ptr, float e_pot) { int index = -1; atom_t *rec_ptr = NULL; // fix to use /* TODO */ if (rec_ptr == NULL) { printf("Did not find: %e\n", e_pot); } else { printf("Found: %e at index %d\n", e_pot, index); print_atom_rec_long(rec_ptr); } } /* This function removes the first atom from the list with the matching * potential energy */ void atom_list_remove_potential_energy(list_t * list_ptr, float e_pot) { atom_t *rec_ptr = NULL; // TODO: fix if (rec_ptr == NULL) { printf("Did not remove: %e\n", e_pot); } else { //TODO: remove printf("Removed: %e\n", e_pot); print_atom_rec_long(rec_ptr); //TODO: cleanup } } /* creates and displays the list of atoms to migrate */ void atom_list_migrate(list_t* list_ptr) { int i, count; float minX, maxX, minY, maxY = 0.0; list_t* migrate_list = NULL; //TODO data_t* rec_ptr = NULL; get_bounding_box(&minX, &maxX, &minY, &maxY); /* TODO: build migrate list */ count = list_size(migrate_list); if (count == 0) { printf("Did not find atoms to migrate in : %e %e %e %e\n", minX, maxX, minY, maxY); } else { /* print items in structure */ printf("Found atoms to migrate:\n"); for (i=0; i < count; i++) { rec_ptr = list_access(migrate_list, i); if (rec_ptr != null) { print_atom_rec_long(rec_ptr); } else { printf("error in migrate list: null value\n"); break; } } } atom_list_cleanup(migrate_list); rec_ptr = null; migrate_list = null; } /* simulates the computation in a single time-step for a md simulation */ void atom_list_update(list_t* list_ptr, float dt) { //using the formulas from mp1 //advance forces //advace momenta //advance position } int determine_inside_box(data_t* rec_ptr, float x_min, float x_max, float y_min, float y_max) { assert(rec_ptr != null && "atom null in box check\n"); //todo return true; } /* this function reverses the order of the items in the list */ void atom_list_reverse(list_t * list_ptr) { list_reverse(list_ptr); count;="" i++)="" {="" rec_ptr="list_access(migrate_list," i);="" if="" (rec_ptr="" !="NULL)" {="" print_atom_rec_long(rec_ptr);="" }="" else="" {="" printf("error="" in="" migrate="" list:="" null="" value\n");="" break;="" }="" }="" }="" atom_list_cleanup(migrate_list);="" rec_ptr="NULL;" migrate_list="NULL;" }="" *="" simulates="" the="" computation="" in="" a="" single="" time-step="" for="" a="" md="" simulation="" */="" void="" atom_list_update(list_t*="" list_ptr,="" float="" dt)="" {="" using="" the="" formulas="" from="" mp1="" advance="" forces="" advace="" momenta="" advance="" position="" }="" int="" determine_inside_box(data_t*="" rec_ptr,="" float="" x_min,="" float="" x_max,="" float="" y_min,="" float="" y_max)="" {="" assert(rec_ptr="" !="NULL" &&="" "atom="" null="" in="" box="" check\n");="" todo="" return="" true;="" }="" *="" this="" function="" reverses="" the="" order="" of="" the="" items="" in="" the="" list="" */="" void="" atom_list_reverse(list_t="" *="" list_ptr)="" {="">
Jul 05, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here