00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <time.h> 00004 #include <string.h> 00005 00006 #include "cmlfile.h" 00007 #include "optim_driver.h" 00008 00009 enum problem_type { optimization=1 } ; 00010 00011 #include "cr.h" 00012 #include "csv.h" 00013 00014 //int main (int argc,char *argv[]) 00015 int main (int argc, const char *argv[]) 00016 { 00017 /* 00018 if ( argc<2 ) { 00019 printf( "usage: gefel <filename> \n" ) ; 00020 exit( 0 ) ; 00021 } 00022 00023 time_t bt,et; 00024 long hod,min; 00025 double sec = clock(); 00026 00027 bt = time (NULL); 00028 00029 // program initiation and data reading 00030 long temp ; 00031 problem_type pt ; 00032 cmlfile *f ; 00033 00034 f = new cmlfile( argv[1] ) ; 00035 f->set_labels( 6 ) ; 00036 f->set_label_string( 0,"Problem" ) ; 00037 f->set_label_string( 1,"Algorithm" ) ; 00038 f->set_label_string( 2,"CallsLimit" ) ; 00039 f->set_label_string( 3,"Dim" ) ; 00040 f->set_label_string( 4,"Precision" ) ; 00041 f->set_label_string( 5,"ReturnToDomain" ) ; 00042 00043 f->set_sections( 1 ) ; 00044 f->set_section_string( 0,"Domain" ) ; 00045 00046 f->get_value( 0L, temp ) ; 00047 pt = ( problem_type ) temp ; 00048 fprintf (stdout,"\n Type of problem: %d\n", pt ); 00049 00050 switch (pt) 00051 { 00052 case optimization: 00053 { 00054 long calls_limit ; 00055 long dim ; 00056 algorithm_type at ; 00057 optim_driver *od ; 00058 00059 f->get_value( 1, temp ) ; 00060 at = ( algorithm_type ) temp ; 00061 f->get_value( 2, calls_limit ) ; 00062 f->get_value( 3, dim ) ; 00063 fprintf (stdout," Type of algorithm : %d \n", at ) ; 00064 fprintf (stdout," Function calls limit: %ld \n", calls_limit ) ; 00065 fprintf (stdout," Number of variables : %ld \n", dim ) ; 00066 00067 obj_funct F( dim ) ; 00068 00069 long lines ; 00070 f->find_section( 0, lines ) ; 00071 if ( lines != dim ) { 00072 fprintf (stderr,"\n\n Mismatch in definition of Domain") ; 00073 fprintf (stderr,"\n main (file %s, line %d).\n", 00074 __FILE__,__LINE__) ; 00075 exit ( 1 ) ; 00076 } 00077 00078 for ( long i=0 ; i<dim ; i++ ) { 00079 f->get_section_value ( 0, i, 0, F.Domain[i][0] ) ; 00080 f->get_section_value ( 0, i, 1, F.Domain[i][1] ) ; 00081 f->get_section_value ( 0, i, 2, F.Domain[i][2] ) ; 00082 } 00083 f->end_reading_section() ; 00084 00085 f->get_value( 4, F.precision ) ; 00086 f->get_value( 5, F.Return_to_domain ) ; 00087 00088 fprintf (stdout," Precision of optimization is: %f \n",\ 00089 F.precision ) ; 00090 fprintf (stdout," Return_to_domain is set to: %ld \n",\ 00091 F.Return_to_domain ) ; 00092 00093 od = new optim_driver( at, &F ) ; 00094 od->run( calls_limit ) ; 00095 break ; 00096 } 00097 default: 00098 fprintf (stderr,"\n\n unknown type of problem in"); 00099 fprintf (stderr,"\n main (file %s, line %d).\n", 00100 __FILE__,__LINE__); 00101 exit ( 1 ) ; 00102 } 00103 00104 f->close() ; 00105 delete f ; 00106 00107 00108 // solution of the problem 00109 // the most important function in the code 00110 00111 00112 et = time (NULL); 00113 fprintf (stdout,"\n\n\n Data about computation time \n"); 00114 fprintf (stdout,"\n\n Total time of computation %ld",et-bt); 00115 00116 sec = (clock() - sec) / (double)CLOCKS_PER_SEC; 00117 hod = (long)sec/3600; sec -= hod*3600; 00118 min = (long)sec/60; sec -= min*60; 00119 fprintf (stdout,"\n ----------------------------------"); 00120 fprintf (stdout,"\n Consumed time by GEFEL %2ld:%02ld:%05.2f",hod,min,sec); 00121 fprintf (stdout,"\n ----------------------------------\n"); 00122 00123 fprintf (stdout,"\n\n"); fprintf (stderr,"\n\n"); fprintf (stdout,"\n"); 00124 */ 00125 00126 00127 00128 /* 00129 toto jsou testovaci casti od JK 00130 comprow *crm; 00131 compvect *cvi,*cvo; 00132 00133 crm = new comprow; 00134 cvi = new compvect; 00135 cvo = new compvect; 00136 00137 crm->n=5; 00138 crm->negm=15; 00139 crm->a=new double [15]; 00140 crm->ci=new long [15]; 00141 crm->adr=new long[6]; 00142 00143 crm->a[0]=1.0; 00144 crm->a[1]=2.0; 00145 crm->a[2]=3.0; 00146 crm->a[3]=4.0; 00147 crm->a[4]=5.0; 00148 crm->a[5]=6.0; 00149 crm->a[6]=7.0; 00150 crm->a[7]=1.0; 00151 crm->a[8]=2.0; 00152 crm->a[9]=3.0; 00153 crm->a[10]=4.0; 00154 crm->a[11]=5.0; 00155 crm->a[12]=6.0; 00156 crm->a[13]=7.0; 00157 crm->a[14]=8.0; 00158 00159 crm->ci[0]=0; 00160 crm->ci[1]=1; 00161 crm->ci[2]=3; 00162 crm->ci[3]=4; 00163 crm->ci[4]=0; 00164 crm->ci[5]=2; 00165 crm->ci[6]=4; 00166 crm->ci[7]=0; 00167 crm->ci[8]=1; 00168 crm->ci[9]=2; 00169 crm->ci[10]=3; 00170 crm->ci[11]=4; 00171 crm->ci[12]=1; 00172 crm->ci[13]=2; 00173 crm->ci[14]=3; 00174 00175 crm->adr[0]=0; 00176 crm->adr[1]=2; 00177 crm->adr[2]=4; 00178 crm->adr[3]=7; 00179 crm->adr[4]=12; 00180 crm->adr[5]=15; 00181 00182 cvi->n=5; 00183 cvi->nz=2; 00184 00185 cvi->a = new double [2]; 00186 cvi->a[0]=3.0; 00187 cvi->a[1]=1.0; 00188 00189 cvi->ind = new long [2]; 00190 cvi->ind[0]=0; 00191 cvi->ind[1]=3; 00192 00193 crm->crxcv_cv (cvi,cvo); 00194 00195 long *li; 00196 long nsub=3; 00197 comprow *sm; 00198 00199 sm = new comprow; 00200 li=new long[3]; 00201 li[0]=1; 00202 li[1]=3; 00203 li[2]=4; 00204 00205 crm->select_submatrix (li,nsub,sm); 00206 */ 00207 00208 long i,j,nn,ne,nne,ndofe; 00209 gelemtype get; 00210 gtopology *gtm; 00211 XFILE *in; 00212 FILE *out; 00213 00214 out = fopen ("vysl.txt","w"); 00215 in = xfopen(argv[1],"r"); 00216 in->warning = 1; 00217 in->kwdmode = ignore; 00218 in->ignorecase = 1; 00219 00220 00221 gtm = new gtopology; 00222 00223 xfscanf (in,"%k%ld","number_of_nodes",&nn); 00224 fprintf (stdout,"\n number of nodes %ld",nn); 00225 gtm->alloc_nodes (nn); 00226 00227 for (i=0;i<nn;i++){ 00228 xfscanf (in,"%ld",&j); 00229 gtm->gnodes[j-1].read (in); 00230 } 00231 00232 xfscanf (in,"%k%ld","number_of_elements",&ne); 00233 fprintf (stdout,"\n number of elements %ld",ne); 00234 gtm->alloc_elements (ne); 00235 00236 for (i=0;i<ne;i++){ 00237 xfscanf (in,"%ld",&j); 00238 ndofe=24; 00239 nne=8; 00240 get = linhexa; 00241 gtm->gelements[i].read (in,nne,ndofe,get); 00242 } 00243 00244 gtm->adjacnodes (out); 00245 gtm->adjacelem (out); 00246 00247 fclose (out); 00248 fprintf (stdout,"\n"); 00249 return 0; 00250 }