// This file contains the necessary class definitions for the percolation program. // There are two classes that need to be defined; The Cluster class and the Site class. // The Cluster class in addition to storing the necessary cluster statistics it is also // a bidirectional linked list. The Site class contains the molecule statistics. // This file will also include the relevant files for manipulating the list. // Author: Riyad Chetram Raghu Date: November 9th 2001 // Copyright (c) 2002-2003 Riyad Chetram Raghu // Version 1.0 of January 13, 2003. #include #include #include int L=100; class Cluster { public: // There is no need for private variables except for the pointers which are best // handled by accessor functions. long label; // The numerical cluster label. long members; // The number of molecules in the cluster. double rsquared; // The sum of the sqaure of the distance from the origin to // each member of the cluster. double xsum; // The sum of the x coordinate of each member of the cluster double ysum; // The sum of the y coordinate of each member of the cluster double zsum; // The sum of the z coordinate of each member of the cluster int x[3]; // The x coordinate of the root molecule, the min and max x values int y[3]; // The y coordinate of the root molecule, the min and max y values int z[3]; // The z coordinate of the root molecule, the min and max z values Cluster *getnext() {return next;} // Function to recover the address in next Cluster *getprev() {return prev;} // Function to recover the address in prev void setnext(Cluster *cluster) // Function to change the address in next { next=cluster; return; } void setprev(Cluster *cluster) // Function to change the address in prev { prev=cluster; return; } private: Cluster *next; // The next cluster in the list Cluster *prev; // The previous cluster in the list }; Cluster nill; Cluster *pnill=&nill; class Site // Declaration of the Site Class { public: // due to the need for variable updating all of the variables are public short bondcount; // The number of available bonds Cluster *cluster; // Pointer to the cluster this site belongs to. bool checkbond(short int sitenum) // Function to get a value from the bond bitfield. { if (sitenum==1) return bond1; if (sitenum==2) return bond2; if (sitenum==3) return bond3; if (sitenum==4) return bond4; if (sitenum==5) return bond5; if (sitenum==6) return bond6; if (sitenum==7) return bond7; if (sitenum==8) return bond8; if (sitenum==9) return bond9; if (sitenum==10) return bond10; if (sitenum==11) return bond11; if (sitenum==12) return bond12; if (sitenum==13) return bond13; if (sitenum==14) return bond14; if (sitenum==15) return bond15; if (sitenum==16) return bond16; if (sitenum==17) return bond17; if (sitenum==18) return bond18; if (sitenum==19) return bond19; if (sitenum==20) return bond20; if (sitenum==21) return bond21; if (sitenum==22) return bond22; if (sitenum==23) return bond23; if (sitenum==24) return bond24; if (sitenum==25) return bond25; if (sitenum==26) return bond26; cout << "Error: Illegal value fed to checkbond\n"; // error handling return false; } bool checkvert(short int vertnum) // Function to get a value from the vertex bitfield. { if (vertnum==1) return vertex1; if (vertnum==2) return vertex2; if (vertnum==3) return vertex3; if (vertnum==4) return vertex4; if (vertnum==5) return vertex5; if (vertnum==6) return vertex6; if (vertnum==7) return vertex7; if (vertnum==8) return vertex8; cout << "Error: Illegal value fed to checkvert\n"; // Error handling return 0; } void changebond(short int sitenum,bool value) // Function to change a value in the bond bitfield. { if (sitenum==1) bond1=value; if (sitenum==2) bond2=value; if (sitenum==3) bond3=value; if (sitenum==4) bond4=value; if (sitenum==5) bond5=value; if (sitenum==6) bond6=value; if (sitenum==7) bond7=value; if (sitenum==8) bond8=value; if (sitenum==9) bond9=value; if (sitenum==10) bond10=value; if (sitenum==11) bond11=value; if (sitenum==12) bond12=value; if (sitenum==13) bond13=value; if (sitenum==14) bond14=value; if (sitenum==15) bond15=value; if (sitenum==16) bond16=value; if (sitenum==17) bond17=value; if (sitenum==18) bond18=value; if (sitenum==19) bond19=value; if (sitenum==20) bond20=value; if (sitenum==21) bond21=value; if (sitenum==22) bond22=value; if (sitenum==23) bond23=value; if (sitenum==24) bond24=value; if (sitenum==25) bond25=value; if (sitenum==26) bond26=value; if (sitenum<1|sitenum>26) cout << "Error: Illegal value fed to changebond\n"; // Error handling return; } void changevert(short int vertnum,bool value) // Function to change a value in the vertex bitfield. { if (vertnum==1) vertex1=value; if (vertnum==2) vertex2=value; if (vertnum==3) vertex3=value; if (vertnum==4) vertex4=value; if (vertnum==5) vertex5=value; if (vertnum==6) vertex6=value; if (vertnum==7) vertex7=value; if (vertnum==8) vertex8=value; if (vertnum<1|vertnum>8) cout << "Error: Illegal value fed to Changevert\n"; // Error handling return; } void initsite() // Function to set the vertex and bond bitfields equals to zero { for (short n=1;n<8;n++) changevert(n,false); for (n=1;n<26;n++) changebond(n,false); } private: // The bitfield which keeps track of whether a molecule has been bonded to the molecule // or not. bool bond1:1; bool bond2:1; bool bond3:1; bool bond4:1; bool bond5:1; bool bond6:1; bool bond7:1; bool bond8:1; bool bond9:1; bool bond10:1; bool bond11:1; bool bond12:1; bool bond13:1; bool bond14:1; bool bond15:1; bool bond16:1; bool bond17:1; bool bond18:1; bool bond19:1; bool bond20:1; bool bond21:1; bool bond22:1; bool bond23:1; bool bond24:1; bool bond25:1; bool bond26:1; // The bitfield which keeps track of whether an attempt has been made to bond at a // vertex. bool vertex1:1; bool vertex2:1; bool vertex3:1; bool vertex4:1; bool vertex5:1; bool vertex6:1; bool vertex7:1; bool vertex8:1; }; class BondObj // This is the class which stores the molecules that have to have the bonding algorithm run on them { public: // Accessor funnctions short getx() // Accessor function to retrieve the x value of the root site { return pos[0]; } short gety() // Accessor function to retrieve the y value of the root site { return pos[1]; } short getz() // Accessor function to retrieve the z value of the root site { return pos[2]; } void setx(short ex) // Accessor function to change the x value of the root site { pos[0]=ex; } void sety(short why) // Accessor function to change the y value of the root site { pos[1]=why; } void setz(short zee) // Accessor function to change the z value of the root site { pos[2]=zee; } bool getneighbour(short neighbour) //Accessor function to retrieve the value of a neighbour bitfield member { if (neighbour==0) return neighbour0; if (neighbour==1) return neighbour1; if (neighbour==2) return neighbour2; if (neighbour==3) return neighbour3; if (neighbour==4) return neighbour4; if (neighbour==5) return neighbour5; if (neighbour==6) return neighbour6; if (neighbour==7) return neighbour7; if (neighbour==8) return neighbour8; if (neighbour==9) return neighbour9; if (neighbour==10) return neighbour10; if (neighbour==11) return neighbour11; if (neighbour==12) return neighbour12; if (neighbour==13) return neighbour13; if (neighbour==14) return neighbour14; if (neighbour==15) return neighbour15; if (neighbour==16) return neighbour16; if (neighbour==17) return neighbour17; if (neighbour==18) return neighbour18; if (neighbour==19) return neighbour19; if (neighbour==20) return neighbour20; if (neighbour==21) return neighbour21; if (neighbour==22) return neighbour22; if (neighbour==23) return neighbour23; if (neighbour==24) return neighbour24; if (neighbour==25) return neighbour25; cout << "Error: Illegal value fed to getneighbour\n" << flush; // error handling return false; } void setneighbour(short neighbour, bool value) //Accessor function to change the value of a neighbour bitfield member { if (neighbour==0) neighbour0=value; if (neighbour==1) neighbour1=value; if (neighbour==2) neighbour2=value; if (neighbour==3) neighbour3=value; if (neighbour==4) neighbour4=value; if (neighbour==5) neighbour5=value; if (neighbour==6) neighbour6=value; if (neighbour==7) neighbour7=value; if (neighbour==8) neighbour8=value; if (neighbour==9) neighbour9=value; if (neighbour==10) neighbour10=value; if (neighbour==11) neighbour11=value; if (neighbour==12) neighbour12=value; if (neighbour==13) neighbour13=value; if (neighbour==14) neighbour14=value; if (neighbour==15) neighbour15=value; if (neighbour==16) neighbour16=value; if (neighbour==17) neighbour17=value; if (neighbour==18) neighbour18=value; if (neighbour==19) neighbour19=value; if (neighbour==20) neighbour20=value; if (neighbour==21) neighbour21=value; if (neighbour==22) neighbour22=value; if (neighbour==23) neighbour23=value; if (neighbour==24) neighbour24=value; if (neighbour==25) neighbour25=value; if (neighbour<0||neighbour>25) cout << "Error: Illegal value fed to setneighbour\n" <(*newcluster).x[2]) (*newcluster).x[2]=(*oldcluster).x[2]; // if the maximum value in oldcluster is // greater than the minimum value in newcluster, the maximum value in oldcluster becomes the maximum value in newcluster if ((*oldcluster).y[2]>(*newcluster).y[2]) (*newcluster).y[2]=(*oldcluster).y[2]; if ((*oldcluster).z[2]>(*newcluster).z[2]) (*newcluster).z[2]=(*oldcluster).z[2]; DelCluster(oldcluster); // oldcluster is deleted return; }