| 1 | <?php
|
|---|
| 2 | class Unit
|
|---|
| 3 | {
|
|---|
| 4 | var $name;
|
|---|
| 5 | var $num_name;
|
|---|
| 6 | //Multiple existing value by scale to get num_name
|
|---|
| 7 | var $scale;
|
|---|
| 8 | function Unit($name,$num_name,$scale)
|
|---|
| 9 | {
|
|---|
| 10 | $this->name=$name;
|
|---|
| 11 | $this->num_name=$num_name;
|
|---|
| 12 | $this->scale=$scale;
|
|---|
| 13 | }
|
|---|
| 14 | function name_split()
|
|---|
| 15 | {
|
|---|
| 16 | $ret=explode("/",$this->name);
|
|---|
| 17 | if(!isset($ret[1]))
|
|---|
| 18 | $ret[1]='1';
|
|---|
| 19 | return $ret;
|
|---|
| 20 | }
|
|---|
| 21 | function name_mul($a,$b)
|
|---|
| 22 | {
|
|---|
| 23 | if($a=='1')
|
|---|
| 24 | return $b;
|
|---|
| 25 | else if($b=='1')
|
|---|
| 26 | return $a;
|
|---|
| 27 | return "$a-$b";
|
|---|
| 28 | }
|
|---|
| 29 | function div($other)
|
|---|
| 30 | {
|
|---|
| 31 | $mine=$this->name_split();
|
|---|
| 32 | $eirs=$other->name_split();
|
|---|
| 33 | $mine[0]=$this->name_mul($mine[0],$eirs[1]);
|
|---|
| 34 | $mine[1]=$this->name_mul($mine[1],$eirs[0]);
|
|---|
| 35 |
|
|---|
| 36 | if($mine[1]=='1')
|
|---|
| 37 | $name=$mine[0];
|
|---|
| 38 | else
|
|---|
| 39 | $name="$mine[0]/$mine[1]";
|
|---|
| 40 | $ret=new Unit(
|
|---|
| 41 | $name,
|
|---|
| 42 | $this->num_name/$other->num_name,
|
|---|
| 43 | $this->scale/$other->scale
|
|---|
| 44 | );
|
|---|
| 45 | return $ret;
|
|---|
| 46 | }
|
|---|
| 47 | function mul($other)
|
|---|
| 48 | {
|
|---|
| 49 | $mine=$this->name_split();
|
|---|
| 50 | $eirs=$other->name_split();
|
|---|
| 51 | $mine[0]=$this->name_mul($mine[0],$eirs[0]);
|
|---|
| 52 | $mine[1]=$this->name_mul($mine[1],$eirs[1]);
|
|---|
| 53 |
|
|---|
| 54 | if($mine[1]=='1')
|
|---|
| 55 | $name=$mine[0];
|
|---|
| 56 | else
|
|---|
| 57 | $name="$mine[0]/$mine[1]";
|
|---|
| 58 | $ret=new Unit(
|
|---|
| 59 | "$name",
|
|---|
| 60 | $this->num_name*$other->num_name,
|
|---|
| 61 | $this->scale*$other->scale
|
|---|
| 62 | );
|
|---|
| 63 | return $ret;
|
|---|
| 64 | }
|
|---|
| 65 | function pow($power)
|
|---|
| 66 | {
|
|---|
| 67 |
|
|---|
| 68 | // Write the actual POW function
|
|---|
| 69 |
|
|---|
| 70 | $mine=$this->name_split();
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | if($power < 0){
|
|---|
| 74 | $temp = $mine[0];
|
|---|
| 75 | $mine[0]= $mine[1];
|
|---|
| 76 | $mine[1]= $temp;
|
|---|
| 77 | $namepower=-$power;
|
|---|
| 78 | }
|
|---|
| 79 | else
|
|---|
| 80 | $namepower=$power;
|
|---|
| 81 |
|
|---|
| 82 | if( $namepower > 1){
|
|---|
| 83 | if($mine[0]!='1')
|
|---|
| 84 | {
|
|---|
| 85 | $mine[0].="^$namepower";
|
|---|
| 86 | }
|
|---|
| 87 | if($mine[1]!='1')
|
|---|
| 88 | {
|
|---|
| 89 | $mine[1].="^$namepower";
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | elseif($namepower == 1){
|
|---|
| 93 | //Do nothing
|
|---|
| 94 | }
|
|---|
| 95 | elseif( $namepower == 0){
|
|---|
| 96 | $mine[0]="1";
|
|---|
| 97 | $mine[1]="1";
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | if($mine[1]=='1')
|
|---|
| 101 | $name=$mine[0];
|
|---|
| 102 | else
|
|---|
| 103 | $name="$mine[0]/$mine[1]";
|
|---|
| 104 | $ret=new Unit(
|
|---|
| 105 | "$name",
|
|---|
| 106 | pow($this->num_name,$power),
|
|---|
| 107 | pow($this->scale,$power)
|
|---|
| 108 | );
|
|---|
| 109 | return $ret;
|
|---|
| 110 | }
|
|---|
| 111 | function equals($other)
|
|---|
| 112 | {
|
|---|
| 113 | if(is_object($other))
|
|---|
| 114 | $num_name=$other->num_name;
|
|---|
| 115 | else
|
|---|
| 116 | $num_name=$other;
|
|---|
| 117 | return abs($this->num_name-$num_name)<.00000001;
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | $unit_infos=array(
|
|---|
| 122 | "g"=>new Unit("g",2,1),
|
|---|
| 123 | "m"=>new Unit("m",3,1),
|
|---|
| 124 | "K"=>new Unit("K",5,1),
|
|---|
| 125 | "s"=>new Unit("s",7,1),
|
|---|
| 126 | "°C"=>new Unit("°C",11,1),
|
|---|
| 127 | "lb"=>new Unit("lb",13,1),
|
|---|
| 128 | "°F"=>new Unit("°F",17,1),
|
|---|
| 129 | //kg m s2
|
|---|
| 130 | "N"=>new Unit("N",2*3/(7*7),1000),
|
|---|
| 131 | //1 pound = 4.44822162 Newtons
|
|---|
| 132 | "p"=>new Unit("p",2*3/(7*7),4.44822162*1000),
|
|---|
| 133 | "in"=>new Unit("in",3,0.0254),
|
|---|
| 134 | "cm"=>new Unit("cm",3,.01),
|
|---|
| 135 | //kg*m*m/(s^3)
|
|---|
| 136 | "W"=>new Unit("W",2*3*3/(7*7*7),1000),
|
|---|
| 137 | //N m-2
|
|---|
| 138 | "Pa"=>new Unit("Pa",2*3/(7*7)/(3*3),1000),
|
|---|
| 139 | "MPa"=>new Unit("MPa",2*3/(7*7)/(3*3),1000000*1000),
|
|---|
| 140 | "cc"=>new Unit("cc",3*3*3,.01*.01*.01),
|
|---|
| 141 | //1 kg × 1 m2 × 1 s-2
|
|---|
| 142 | "J"=>new Unit("J",2*3*3/(7*7),1000),
|
|---|
| 143 | "BTU"=>new Unit("BTU",2*3*3/(7*7),1055*1000),
|
|---|
| 144 | "hr"=>new Unit("hr",7,60*60),
|
|---|
| 145 | "ft"=>new Unit("ft",3,12*0.0254)
|
|---|
| 146 | );
|
|---|
| 147 |
|
|---|
| 148 | class PropertyData
|
|---|
| 149 | {
|
|---|
| 150 | //average value out of all the matches
|
|---|
| 151 | var $avg_value;
|
|---|
| 152 | var $unit;
|
|---|
| 153 | //number of matches
|
|---|
| 154 | var $count;
|
|---|
| 155 | function PropertyData()
|
|---|
| 156 | {
|
|---|
| 157 | $this->avg_value=0;
|
|---|
| 158 | $this->unit=0;
|
|---|
| 159 | $this->count=0;
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | function parse_units($units_element)
|
|---|
| 164 | {
|
|---|
| 165 | global $unit_infos;
|
|---|
| 166 | global $dom;
|
|---|
| 167 | if(get_class($units_element)=="DOMNodeList")
|
|---|
| 168 | $units_element=$units_element->item(0);
|
|---|
| 169 | if($units_element)
|
|---|
| 170 | {
|
|---|
| 171 | $return_unit=new Unit(
|
|---|
| 172 | "",
|
|---|
| 173 | 1,
|
|---|
| 174 | 1
|
|---|
| 175 | );
|
|---|
| 176 | $factor=$units_element->getAttribute("factor");
|
|---|
| 177 | if($factor)
|
|---|
| 178 | $return_unit->scale*=$factor;
|
|---|
| 179 | //$units=$units_element->get_elements_by_tagname("Unit");
|
|---|
| 180 | $units=$units_element->getElementsByTagName("Unit");
|
|---|
| 181 | foreach($units as $unit)
|
|---|
| 182 | {
|
|---|
| 183 | $name=$unit->getElementsByTagName("Name");
|
|---|
| 184 | $name=$name->item(0);
|
|---|
| 185 | $name=$name->nodeValue;
|
|---|
| 186 | $power=$unit->getAttribute("power");
|
|---|
| 187 | if(!$power)
|
|---|
| 188 | $power=1;
|
|---|
| 189 | $unit_info=$unit_infos[$name];
|
|---|
| 190 | if(!$unit_info)
|
|---|
| 191 | echo "Error: unknown unit $name\n";
|
|---|
| 192 | $return_unit=$return_unit->mul($unit_info->pow($power));
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 | else
|
|---|
| 196 | $return_unit=null;
|
|---|
| 197 | return $return_unit;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | function get_property_data($filename,$property_names)
|
|---|
| 201 | {
|
|---|
| 202 | global $dom;
|
|---|
| 203 | $dom=new DOMDocument;
|
|---|
| 204 | $dom->loadXML(file_get_contents($filename));
|
|---|
| 205 | $context=new DOMXPath($dom);
|
|---|
| 206 |
|
|---|
| 207 | $equivalencies=array(
|
|---|
| 208 | array_flip(array("Young's Modulus","Youngs Modulus","Modulus of Elasticity","Tensile Modulus")),
|
|---|
| 209 | array_flip(array("Tensile Strength, Yield","Yield Strength","Tensile Strength @ Yield")),
|
|---|
| 210 | array_flip(array("Heat Capacity","Specific Heat"))
|
|---|
| 211 | );
|
|---|
| 212 |
|
|---|
| 213 | $translation_string="\"abcdefghijklmnopqrstuvwxyz'\",'ABCDEFGHIJKLMNOPQRSTUVWXYZ'";
|
|---|
| 214 | $ret=array();
|
|---|
| 215 | $details=$context->query("/MatML_Doc/Material/BulkDetails/Name/text()");
|
|---|
| 216 | $item=$details->item(0);
|
|---|
| 217 | $Matid=$item->nodeValue;
|
|---|
| 218 | foreach($property_names as $key=>$property_name)
|
|---|
| 219 | {
|
|---|
| 220 | $found=false;
|
|---|
| 221 | foreach($equivalencies as $equivalency)
|
|---|
| 222 | {
|
|---|
| 223 | if(array_key_exists($property_name,$equivalency))
|
|---|
| 224 | {
|
|---|
| 225 | $name_condition="";
|
|---|
| 226 | foreach($equivalency as $equiv=>$value)
|
|---|
| 227 | {
|
|---|
| 228 | if($name_condition!="")
|
|---|
| 229 | $name_condition.=" or ";
|
|---|
| 230 | $name_condition.="translate(Name,$translation_string)='".strtoupper(strtr($equiv,array("'"=>"")))."'";
|
|---|
| 231 | }
|
|---|
| 232 | $found=true;
|
|---|
| 233 | break;
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 | if($property_name=="Material Name")
|
|---|
| 237 | {
|
|---|
| 238 | $ret[$key]=$Matid;
|
|---|
| 239 | continue;
|
|---|
| 240 | }
|
|---|
| 241 | else if($property_name=="Material Categories")
|
|---|
| 242 | {
|
|---|
| 243 | $categories=array();
|
|---|
| 244 | $queried=$context->query("/MatML_Doc/Material/BulkDetails/Class/Name/text()");
|
|---|
| 245 | foreach($queried as $category)
|
|---|
| 246 | {
|
|---|
| 247 | $categories[]=$category->nodeValue;
|
|---|
| 248 | }
|
|---|
| 249 | $queried=$context->query("/MatML_Doc/Material/BulkDetails/Subclass/Name/text()");
|
|---|
| 250 | foreach($queried as $category)
|
|---|
| 251 | {
|
|---|
| 252 | $categories[]=$category->nodeValue;
|
|---|
| 253 | }
|
|---|
| 254 | $ret[$key]=$categories;
|
|---|
| 255 | continue;
|
|---|
| 256 | }
|
|---|
| 257 | else if(!$found)
|
|---|
| 258 | {
|
|---|
| 259 | $name_condition="translate(Name,$translation_string)='".strtoupper($property_name)."'";
|
|---|
| 260 | }
|
|---|
| 261 | $details=$context->query("/MatML_Doc/Metadata/PropertyDetails[$name_condition]");
|
|---|
| 262 | $data=new PropertyData;
|
|---|
| 263 | if(!$details->length)
|
|---|
| 264 | continue;
|
|---|
| 265 | foreach($details as $detail)
|
|---|
| 266 | {
|
|---|
| 267 | $units=$detail->getElementsByTagName("Units");
|
|---|
| 268 | $unit=parse_units($units);
|
|---|
| 269 | if(!$data->unit)
|
|---|
| 270 | $data->unit=$unit;
|
|---|
| 271 | else
|
|---|
| 272 | {
|
|---|
| 273 | force_unit_match($Matid,$unit,$data);
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | $propid=$detail->getAttribute("id");
|
|---|
| 277 | $property_datas=$context->query("/MatML_Doc/Material/BulkDetails/PropertyData[@property='$propid']/Data");
|
|---|
| 278 | foreach($property_datas as $property_data)
|
|---|
| 279 | {
|
|---|
| 280 | $data->count++;
|
|---|
| 281 | $data->avg_value+=$property_data->nodeValue*$unit->scale;
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 | if($data->count)
|
|---|
| 285 | $data->avg_value/=$data->count;
|
|---|
| 286 | $ret[$key]=$data;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | // echo "<br><br>";
|
|---|
| 290 | // print_r($ret);
|
|---|
| 291 |
|
|---|
| 292 | return $ret;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | function fractionalize($number)
|
|---|
| 296 | {
|
|---|
| 297 | $integer=floor($number);
|
|---|
| 298 | $decimal=$number-$integer;
|
|---|
| 299 | if($decimal<.00000001)
|
|---|
| 300 | return array($integer,1);
|
|---|
| 301 | if($decimal>.99999999)
|
|---|
| 302 | return array($integer+1,1);
|
|---|
| 303 | $denominator=fractionalize(1/$decimal);
|
|---|
| 304 | $denominator=$denominator[0];
|
|---|
| 305 | return array(round($number*$denominator),$denominator);
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | function get_factor_power($number,$factor)
|
|---|
| 309 | {
|
|---|
| 310 | $power=0;
|
|---|
| 311 | list($numerator,$denominator)=fractionalize($number);
|
|---|
| 312 | if($numerator==0)
|
|---|
| 313 | return 0;
|
|---|
| 314 | list($fn,$fd)=fractionalize($factor);
|
|---|
| 315 | while(($numerator % $fn)==0 && ($denominator % $fd) == 0)
|
|---|
| 316 | {
|
|---|
| 317 | $numerator/=$fn;
|
|---|
| 318 | $denominator/=$fd;
|
|---|
| 319 | $power++;
|
|---|
| 320 | }
|
|---|
| 321 | if($power||$denominator==1)
|
|---|
| 322 | return $power;
|
|---|
| 323 | while(($numerator % $fd)==0 && ($denominator % $fn) == 0)
|
|---|
| 324 | {
|
|---|
| 325 | $numerator/=$fd;
|
|---|
| 326 | $denominator/=$fn;
|
|---|
| 327 | $power--;
|
|---|
| 328 | }
|
|---|
| 329 | return $power;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | function force_unit_match($material,$unit,&$property_data)
|
|---|
| 333 | {
|
|---|
| 334 | global $unit_infos;
|
|---|
| 335 | //Convert BTUs per degree F to Joules per degree C
|
|---|
| 336 | $BTUs_per_degree_F=$unit_infos['BTU']->div($unit_infos['°F']);
|
|---|
| 337 | $Joules_per_degree_C=$unit_infos['J']->div($unit_infos['°C']);
|
|---|
| 338 | $power=get_factor_power($property_data->unit->num_name,$BTUs_per_degree_F->num_name);
|
|---|
| 339 | $BTUs_to_Joules=$Joules_per_degree_C->div($BTUs_per_degree_F);
|
|---|
| 340 | $BTUs_to_Joules->scale=1899.1009999999999/1000;
|
|---|
| 341 | $property_data->unit=$property_data->unit->mul($BTUs_to_Joules->pow($power));
|
|---|
| 342 | $property_data->avg_value*=pow(
|
|---|
| 343 | $BTUs_to_Joules->scale,$power);
|
|---|
| 344 |
|
|---|
| 345 | //Convert all negative powers of degree F and degree C to Kelvin
|
|---|
| 346 | $degreeF_to_Kelvin=$unit_infos['K']->div($unit_infos['°F']);
|
|---|
| 347 | $degreeF_to_Kelvin->scale=5.0/9.0;
|
|---|
| 348 | $degreeC_to_Kelvin=$unit_infos['K']->div($unit_infos['°C']);
|
|---|
| 349 | $degreeC_to_Kelvin->scale=1;
|
|---|
| 350 |
|
|---|
| 351 | $power=get_factor_power($property_data->unit->num_name,$unit_infos['°F']->num_name);
|
|---|
| 352 | if($power>0)
|
|---|
| 353 | $power=0;
|
|---|
| 354 | $property_data->unit=$property_data->unit->mul($degreeF_to_Kelvin->pow($power));
|
|---|
| 355 | $property_data->avg_value*=pow(
|
|---|
| 356 | $degreeF_to_Kelvin->scale,$power);
|
|---|
| 357 |
|
|---|
| 358 | $power=get_factor_power($property_data->unit->num_name,$unit_infos['°C']->num_name);
|
|---|
| 359 | if($power>0)
|
|---|
| 360 | $power=0;
|
|---|
| 361 | $property_data->unit=$property_data->unit->mul($degreeC_to_Kelvin->pow($power));
|
|---|
| 362 | $property_data->avg_value*=pow(
|
|---|
| 363 | $degreeC_to_Kelvin->scale,$power);
|
|---|
| 364 |
|
|---|
| 365 | //Now convert negative powers of Kelvin to degree C and degree F as needed
|
|---|
| 366 | $power=get_factor_power($unit->num_name,$unit_infos['°F']->num_name);
|
|---|
| 367 | if($power>0)
|
|---|
| 368 | $power=0;
|
|---|
| 369 | $property_data->unit=$property_data->unit->div($degreeF_to_Kelvin->pow($power));
|
|---|
| 370 | $property_data->avg_value/=pow(
|
|---|
| 371 | $degreeF_to_Kelvin->scale,$power);
|
|---|
| 372 |
|
|---|
| 373 | $power=get_factor_power($unit->num_name,$unit_infos['°C']->num_name);
|
|---|
| 374 | if($power>0)
|
|---|
| 375 | $power=0;
|
|---|
| 376 | $property_data->unit=$property_data->unit->div($degreeC_to_Kelvin->pow($power));
|
|---|
| 377 | $property_data->avg_value/=pow(
|
|---|
| 378 | $degreeC_to_Kelvin->scale,$power);
|
|---|
| 379 |
|
|---|
| 380 | if(!$unit->equals($property_data->unit))
|
|---|
| 381 | {
|
|---|
| 382 | $power=get_factor_power($property_data->unit->num_name,13);
|
|---|
| 383 | if($unit->equals($property_data->unit->num_name*pow(13,-$power)*pow(2*3/(7*7),$power)))
|
|---|
| 384 | {
|
|---|
| 385 | //it uses pound as a force
|
|---|
| 386 | $newtons_per_pound=$unit_infos['N']->div($unit_infos['lb']);
|
|---|
| 387 | $newtons_per_pound->scale=4.44822162*1000;
|
|---|
| 388 | $newtons_per_pound=$newtons_per_pound->pow($power);
|
|---|
| 389 |
|
|---|
| 390 | $property_data->unit=$property_data->unit->mul($newtons_per_pound);
|
|---|
| 391 | $property_data->avg_value*=$newtons_per_pound->scale;
|
|---|
| 392 | return true;
|
|---|
| 393 | }
|
|---|
| 394 | if($unit->equals($property_data->unit->num_name*pow(13,-$power)*pow(2,$power)))
|
|---|
| 395 | {
|
|---|
| 396 | //it uses pound as a mass
|
|---|
| 397 | $grams_per_pound=$unit_infos['g']->div($unit_infos['lb']);
|
|---|
| 398 | $grams_per_pound->scale=453.59237;
|
|---|
| 399 | $grams_per_pound=$grams_per_pound->pow($power);
|
|---|
| 400 | $property_data->unit=$property_data->unit->mul($grams_per_pound);
|
|---|
| 401 | $property_data->avg_value*=$grams_per_pound->scale;
|
|---|
| 402 | return true;
|
|---|
| 403 | }
|
|---|
| 404 | echo "Error: unit mismatch ($unit->name vs ".$property_data->unit->name.") and ($unit->num_name vs ".$property_data->unit->num_name.") in $material\n";
|
|---|
| 405 | return false;
|
|---|
| 406 | }
|
|---|
| 407 | return true;
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | function db_get_plot_values($plottype, $log, $category_options){
|
|---|
| 411 | global $unit_infos;
|
|---|
| 412 |
|
|---|
| 413 | // So far only 4 plot types
|
|---|
| 414 | // EvsYield
|
|---|
| 415 | // EovDvsYieldovD
|
|---|
| 416 | // EvsD
|
|---|
| 417 | // KvsDCp
|
|---|
| 418 |
|
|---|
| 419 | // Unit selection
|
|---|
| 420 |
|
|---|
| 421 | //$utsys = "0";
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 | switch($plottype){
|
|---|
| 425 |
|
|---|
| 426 | case "EvsYield":
|
|---|
| 427 | $query=array(
|
|---|
| 428 | "Yquery"=>"Young's Modulus",
|
|---|
| 429 | "Xquery"=>"Tensile Strength, Yield",
|
|---|
| 430 | "Matid"=>"Material Name"
|
|---|
| 431 | );
|
|---|
| 432 | $final_units=array(
|
|---|
| 433 | "Yquery"=>$unit_infos["MPa"],
|
|---|
| 434 | "Xquery"=>$unit_infos["MPa"]
|
|---|
| 435 | );
|
|---|
| 436 | break;
|
|---|
| 437 |
|
|---|
| 438 | case "EovDvsYieldovD":
|
|---|
| 439 | $query=array(
|
|---|
| 440 | "Yquery"=>"Young's Modulus",
|
|---|
| 441 | "Xquery"=>"Tensile Strength, Yield",
|
|---|
| 442 | "extra"=>"Density",
|
|---|
| 443 | "Matid"=>"Material Name"
|
|---|
| 444 | );
|
|---|
| 445 | $final_units=array(
|
|---|
| 446 | "Yquery"=>$unit_infos["MPa"],
|
|---|
| 447 | "Xquery"=>$unit_infos["MPa"],
|
|---|
| 448 | "extra"=>$unit_infos["g"]->div($unit_infos["cc"])
|
|---|
| 449 | );
|
|---|
| 450 | break;
|
|---|
| 451 |
|
|---|
| 452 | case "EvsD":
|
|---|
| 453 | $query=array(
|
|---|
| 454 | "Yquery"=>"Young's Modulus",
|
|---|
| 455 | "Xquery"=>"Density",
|
|---|
| 456 | "Matid"=>"Material Name"
|
|---|
| 457 | );
|
|---|
| 458 | $final_units=array(
|
|---|
| 459 | "Yquery"=>$unit_infos["MPa"],
|
|---|
| 460 | "Xquery"=>$unit_infos["g"]->div($unit_infos["cc"])
|
|---|
| 461 | );
|
|---|
| 462 | break;
|
|---|
| 463 |
|
|---|
| 464 | case "KvsDCp":
|
|---|
| 465 | $query=array(
|
|---|
| 466 | "Yquery"=>"Thermal Conductivity",
|
|---|
| 467 | "Xquery"=>"Heat Capacity",
|
|---|
| 468 | "extra"=>"Density",
|
|---|
| 469 | "Matid"=>"Material Name"
|
|---|
| 470 | );
|
|---|
| 471 | $final_units=array(
|
|---|
| 472 | "Yquery"=>$unit_infos["W"]->div($unit_infos["m"]->mul($unit_infos["K"])),
|
|---|
| 473 | "Xquery"=>$unit_infos["J"]->div($unit_infos["g"]->mul($unit_infos["°C"])),
|
|---|
| 474 | "extra"=>$unit_infos["g"]->div($unit_infos["cc"])
|
|---|
| 475 | );
|
|---|
| 476 | break;
|
|---|
| 477 | }
|
|---|
| 478 | $query["categories"]="Material Categories";
|
|---|
| 479 |
|
|---|
| 480 | $valuesY = array();
|
|---|
| 481 | $valuesX = array();
|
|---|
| 482 | $valuese = array();
|
|---|
| 483 | $categories = array();
|
|---|
| 484 | $filenames = array();
|
|---|
| 485 |
|
|---|
| 486 | $handle = opendir('materials');
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 | // echo "<br><br>Begin Query <br>";
|
|---|
| 490 | // print_r($query);
|
|---|
| 491 | // echo "<br>End Query<br>";
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 | while (false !== ($file = readdir($handle))) {
|
|---|
| 495 | if(preg_match("/\.xml?$/",$file)==1)
|
|---|
| 496 | {
|
|---|
| 497 | // Fetch values from DB and sort them in an array (actually 3 arrays)
|
|---|
| 498 | $values=get_property_data("materials/$file",$query);
|
|---|
| 499 |
|
|---|
| 500 | // echo "<br><br>Begin Values <br>";
|
|---|
| 501 | // print_r($values);
|
|---|
| 502 | // echo "End Values <br>";
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 | If(isset($values["Xquery"])&&
|
|---|
| 506 | isset($values["Yquery"])
|
|---|
| 507 | )
|
|---|
| 508 | {
|
|---|
| 509 | $values_categories=$values["categories"];
|
|---|
| 510 | $values_categories[]="";
|
|---|
| 511 | foreach($values_categories as $category)
|
|---|
| 512 | {
|
|---|
| 513 | if(isset($category_options[$category]))
|
|---|
| 514 | break;
|
|---|
| 515 | }
|
|---|
| 516 | if(!isset($category_options[$category]))
|
|---|
| 517 | continue;
|
|---|
| 518 | $category=$category_options[$category];
|
|---|
| 519 | force_unit_match($values["Matid"],$final_units["Xquery"],$values["Xquery"]);
|
|---|
| 520 | force_unit_match($values["Matid"],$final_units["Yquery"],$values["Yquery"]);
|
|---|
| 521 | if(isset($query["extra"]))
|
|---|
| 522 | {
|
|---|
| 523 | if(isset($values["extra"]))
|
|---|
| 524 | {
|
|---|
| 525 | force_unit_match($values["Matid"],$final_units["extra"],$values["extra"]);
|
|---|
| 526 | $valuesX[]=($values["Xquery"]->avg_value/$final_units["Xquery"]->scale);
|
|---|
| 527 | $valuesY[]=($values["Yquery"]->avg_value/$final_units["Yquery"]->scale);
|
|---|
| 528 | $valuese[]=$values["extra"]->avg_value/$final_units["extra"]->scale;
|
|---|
| 529 | $names[]=$values["Matid"];
|
|---|
| 530 | $categories[]=$category;
|
|---|
| 531 | }
|
|---|
| 532 | }
|
|---|
| 533 | else
|
|---|
| 534 | {
|
|---|
| 535 | $valuesX[]=($values["Xquery"]->avg_value/$final_units["Xquery"]->scale);
|
|---|
| 536 | $valuesY[]=($values["Yquery"]->avg_value/$final_units["Yquery"]->scale);
|
|---|
| 537 | $names[]=$values["Matid"];
|
|---|
| 538 | $categories[]=$category;
|
|---|
| 539 |
|
|---|
| 540 | }
|
|---|
| 541 | $filenames[]="materials/$file";
|
|---|
| 542 | }
|
|---|
| 543 | }
|
|---|
| 544 | }
|
|---|
| 545 | closedir($handle);
|
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 | // Assign the actual useful data
|
|---|
| 549 |
|
|---|
| 550 | // Labels and Units
|
|---|
| 551 | //$xlabel = "Density (lb/cu in.)";
|
|---|
| 552 | //$ylabel = "Electrical Conductivity (ohm-cir mil/ft)";
|
|---|
| 553 |
|
|---|
| 554 | switch($plottype){
|
|---|
| 555 |
|
|---|
| 556 | case "EvsYield":
|
|---|
| 557 | $ylabel = "Young's Modulus (".$final_units["Yquery"]->name.")";
|
|---|
| 558 | $xlabel = "Yield Strength (".$final_units["Xquery"]->name.")";
|
|---|
| 559 | break;
|
|---|
| 560 |
|
|---|
| 561 | case "EvsD":
|
|---|
| 562 | $ylabel = "Young's Modulus (".$final_units["Yquery"]->name.")";
|
|---|
| 563 | $xlabel = "Density (".$final_units["Xquery"]->name.")";
|
|---|
| 564 | break;
|
|---|
| 565 |
|
|---|
| 566 | case "EovDvsYieldovD":
|
|---|
| 567 | $ylabel = "Young's Modulus / Density (".$final_units["Yquery"]->name." / ".$final_units["extra"]->name.")";
|
|---|
| 568 | $xlabel = "Yield Strength / Density (".$final_units["Xquery"]->name." / ".$final_units["extra"]->name.")";
|
|---|
| 569 | $valuesY = array_div($valuesY,$valuese);
|
|---|
| 570 | $valuesX = array_div($valuesX,$valuese);
|
|---|
| 571 | break;
|
|---|
| 572 |
|
|---|
| 573 | case "KvsDCp":
|
|---|
| 574 | $ylabel = "Thermal Conductivity (".$final_units["Yquery"]->name.")";
|
|---|
| 575 | $xlabel = "Heat Capacity * Density (".$final_units["Xquery"]->name." * ".$final_units["extra"]->name.")";
|
|---|
| 576 | $valuesX = array_mult($valuesX,$valuese);
|
|---|
| 577 | break;
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | $ret=array(&$valuesX, &$valuesY, &$names, $xlabel, $ylabel, $categories);
|
|---|
| 581 | $ret["filenames"]=$filenames;
|
|---|
| 582 | return $ret;
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | function db_get_plot_single_values($property_listx, $property_listy, $log, $category_options){
|
|---|
| 586 |
|
|---|
| 587 | global $unit_infos;
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 | // Prepare Array list
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 | $query = array("Matid"=>"Material Name");
|
|---|
| 594 | $power = array();
|
|---|
| 595 | $NXqueries = array();
|
|---|
| 596 | $NYqueries = array();
|
|---|
| 597 |
|
|---|
| 598 | $prop_units = array(
|
|---|
| 599 | "Density" => $unit_infos["g"]->div($unit_infos["cc"]),
|
|---|
| 600 | "Young's Modulus" => $unit_infos["MPa"],
|
|---|
| 601 | "Youngs Modulus" => $unit_infos["MPa"],
|
|---|
| 602 | "Yield Strength" => $unit_infos["MPa"],
|
|---|
| 603 | "Heat Capacity" => $unit_infos["J"]->div($unit_infos["g"]->mul($unit_infos["K"])),
|
|---|
| 604 | "Thermal Conductivity" => $unit_infos["W"]->div($unit_infos["m"]->mul($unit_infos["K"])),
|
|---|
| 605 | );
|
|---|
| 606 |
|
|---|
| 607 | $index = 0;
|
|---|
| 608 | $xlabel_num ="";
|
|---|
| 609 | $ylabel_num ="";
|
|---|
| 610 | $xlabel_den ="";
|
|---|
| 611 | $ylabel_den ="";
|
|---|
| 612 |
|
|---|
| 613 | foreach( $property_listx as $property=>$pow){
|
|---|
| 614 | $index++;
|
|---|
| 615 | $query["Xquery$index"]=$property;
|
|---|
| 616 | $power["Xquery$index"]= $pow;
|
|---|
| 617 | $final_units["Xquery$index"] = $prop_units["$property"];
|
|---|
| 618 |
|
|---|
| 619 | if( $pow > 1){
|
|---|
| 620 | $xlabel_num = "$property^$pow *";
|
|---|
| 621 | }
|
|---|
| 622 | elseif($pow == 1){
|
|---|
| 623 | $xlabel_num = "$property*";
|
|---|
| 624 | }
|
|---|
| 625 | elseif($pow == -1){
|
|---|
| 626 | $xlabel_den = "$property*";
|
|---|
| 627 | }
|
|---|
| 628 | elseif($pow < -1){
|
|---|
| 629 | $xlabel_den = "$property^".abs($pow)."*";
|
|---|
| 630 | }
|
|---|
| 631 |
|
|---|
| 632 | array_push($NXqueries, "Xquery$index");
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | $index = 0;
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 | foreach( $property_listy as $property=>$pow){
|
|---|
| 639 | $index++;
|
|---|
| 640 | $query["Yquery$index"]=$property;
|
|---|
| 641 | $power["Yquery$index"]= $pow;
|
|---|
| 642 | $final_units["Yquery$index"] = $prop_units["$property"];
|
|---|
| 643 |
|
|---|
| 644 | if( $pow > 1){
|
|---|
| 645 | $ylabel_num = "$property^$pow *";
|
|---|
| 646 | }
|
|---|
| 647 | elseif($pow == 1){
|
|---|
| 648 | $ylabel_num = "$property*";
|
|---|
| 649 | }
|
|---|
| 650 | elseif($pow == -1){
|
|---|
| 651 | $ylabel_den = "$property*";
|
|---|
| 652 | }
|
|---|
| 653 | elseif($pow < -1){
|
|---|
| 654 | $ylabel_den = "$property^".abs($pow)."*";
|
|---|
| 655 | }
|
|---|
| 656 |
|
|---|
| 657 | array_push($NYqueries, "Yquery$index");
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | $ALLqueries = array_merge($NXqueries,$NYqueries);
|
|---|
| 661 |
|
|---|
| 662 | // Prepare final units
|
|---|
| 663 |
|
|---|
| 664 | $first = 0;
|
|---|
| 665 | foreach($NXqueries as $Nquery){
|
|---|
| 666 |
|
|---|
| 667 | if($first){
|
|---|
| 668 | $Xunits = $Xunits->mul($final_units["$Nquery"]->pow($power["$Nquery"]));
|
|---|
| 669 | }
|
|---|
| 670 | else{
|
|---|
| 671 | $Xunits = $final_units["$Nquery"]->pow($power["$Nquery"]);
|
|---|
| 672 | $first = 1;
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | $first = 0;
|
|---|
| 678 | foreach($NYqueries as $Nquery){
|
|---|
| 679 |
|
|---|
| 680 | if($first){
|
|---|
| 681 | $Yunits = $Yunits->mul($final_units["$Nquery"]->pow($power["$Nquery"]));
|
|---|
| 682 | }
|
|---|
| 683 | else{
|
|---|
| 684 | $Yunits = $final_units["$Nquery"]->pow($power["$Nquery"]);
|
|---|
| 685 | $first = 1;
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | }
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 | // Prepare final labels
|
|---|
| 693 |
|
|---|
| 694 | $xlabel_num = substr($xlabel_num,0,-1);
|
|---|
| 695 | $xlabel_den = substr($xlabel_den,0,-1);
|
|---|
| 696 | $ylabel_num = substr($ylabel_num,0,-1);
|
|---|
| 697 | $ylabel_den = substr($ylabel_den,0,-1);
|
|---|
| 698 |
|
|---|
| 699 | $xlabel_num = ($xlabel_num != "")?"$xlabel_num":1;
|
|---|
| 700 | $ylabel_num = ($ylabel_num != "")?"$ylabel_num":1;
|
|---|
| 701 |
|
|---|
| 702 | $xlabel = ($xlabel_den != "")?"$xlabel_num / $xlabel_den":"$xlabel_num";
|
|---|
| 703 | $ylabel = ($ylabel_den != "")?"$ylabel_num / $ylabel_den":"$ylabel_num";
|
|---|
| 704 |
|
|---|
| 705 | $xlabel .= " (".$Xunits->name.")";
|
|---|
| 706 | $ylabel .= " (".$Yunits->name.")";
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 | $query["categories"]="Material Categories";
|
|---|
| 710 |
|
|---|
| 711 | $valuesY = array();
|
|---|
| 712 | $valuesX = array();
|
|---|
| 713 | $valuese = array();
|
|---|
| 714 | $categories = array();
|
|---|
| 715 | $filenames = array();
|
|---|
| 716 |
|
|---|
| 717 | $handle = opendir('materials');
|
|---|
| 718 |
|
|---|
| 719 | // echo "<br><br>Begin Query <br>";
|
|---|
| 720 | // print_r($query);
|
|---|
| 721 | // echo "End Query<br>";
|
|---|
| 722 |
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 | while (false !== ($file = readdir($handle))) {
|
|---|
| 726 | if(preg_match("/\.xml?$/",$file)==1)
|
|---|
| 727 | {
|
|---|
| 728 | // Fetch values from DB and sort them in an array (actually 3 arrays)
|
|---|
| 729 | $values=get_property_data("materials/$file",$query);
|
|---|
| 730 |
|
|---|
| 731 |
|
|---|
| 732 | // echo "<br><br>Begin Values <br>";
|
|---|
| 733 | // print_r($values);
|
|---|
| 734 | // echo "End Values <br>";
|
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 | // If isset (for all values)
|
|---|
| 739 |
|
|---|
| 740 | $allset = 1;
|
|---|
| 741 |
|
|---|
| 742 | foreach( $ALLqueries as $Nquery){
|
|---|
| 743 | if(isset($values["$Nquery"]))
|
|---|
| 744 | $allset *= 1;
|
|---|
| 745 | else
|
|---|
| 746 | $allset *= 0;
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 | if( $allset )
|
|---|
| 751 | {
|
|---|
| 752 |
|
|---|
| 753 | // Category part, deal with it later
|
|---|
| 754 | $values_categories=$values["categories"];
|
|---|
| 755 | $values_categories[]="";
|
|---|
| 756 | foreach($values_categories as $category)
|
|---|
| 757 | {
|
|---|
| 758 | if(isset($category_options[$category]))
|
|---|
| 759 | break;
|
|---|
| 760 | }
|
|---|
| 761 | if(!isset($category_options[$category]))
|
|---|
| 762 | continue;
|
|---|
| 763 | $category=$category_options[$category];
|
|---|
| 764 | // Category part, deal with it later
|
|---|
| 765 |
|
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 | //Force unit match for all queries
|
|---|
| 770 |
|
|---|
| 771 | foreach( $NXqueries as $Nquery){
|
|---|
| 772 | force_unit_match($values["Matid"],$final_units["$Nquery"],$values["$Nquery"]);
|
|---|
| 773 | }
|
|---|
| 774 |
|
|---|
| 775 | foreach( $NYqueries as $Nquery){
|
|---|
| 776 | force_unit_match($values["Matid"],$final_units["$Nquery"],$values["$Nquery"]);
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | //Scale units
|
|---|
| 780 | //and add them to the array
|
|---|
| 781 |
|
|---|
| 782 | $cont = 1;
|
|---|
| 783 |
|
|---|
| 784 | // And the Power?
|
|---|
| 785 |
|
|---|
| 786 | foreach( $NXqueries as $Nquery){
|
|---|
| 787 | $final_unit=$final_units["$Nquery"]->pow($power["$Nquery"]);
|
|---|
| 788 | $cont *= ( pow($values["$Nquery"]->avg_value,$power["$Nquery"]) /$final_unit->scale);
|
|---|
| 789 | }
|
|---|
| 790 | $valuesX[]=$cont;
|
|---|
| 791 |
|
|---|
| 792 | $cont = 1;
|
|---|
| 793 |
|
|---|
| 794 | foreach( $NYqueries as $Nquery){
|
|---|
| 795 | $final_unit=$final_units["$Nquery"]->pow($power["$Nquery"]);
|
|---|
| 796 | $cont *= ( pow($values["$Nquery"]->avg_value,$power["$Nquery"]) /$final_unit->scale);
|
|---|
| 797 | }
|
|---|
| 798 | $valuesY[]=$cont;
|
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 | // print_r($valuesX);
|
|---|
| 802 | // echo "<br>";
|
|---|
| 803 | // print_r($valuesY);
|
|---|
| 804 | // echo "<br>";
|
|---|
| 805 |
|
|---|
| 806 |
|
|---|
| 807 | // Add Matid
|
|---|
| 808 | $names[]=$values["Matid"];
|
|---|
| 809 |
|
|---|
| 810 | // Something else for category
|
|---|
| 811 | $categories[]=$category;
|
|---|
| 812 | $filenames[]="materials/$file";
|
|---|
| 813 |
|
|---|
| 814 | }
|
|---|
| 815 | }
|
|---|
| 816 | }
|
|---|
| 817 | closedir($handle);
|
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 | //assing label
|
|---|
| 821 |
|
|---|
| 822 | // $ylabel = "$property_listy[0]";
|
|---|
| 823 | // $xlabel = "$property_listx[0]";
|
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 |
|
|---|
| 827 | $ret=array(&$valuesX, &$valuesY, &$names, $xlabel, $ylabel, $categories);
|
|---|
| 828 | $ret["filenames"]=$filenames;
|
|---|
| 829 | return $ret;
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 |
|
|---|
| 835 |
|
|---|
| 836 | //var_dump(db_get_plot_values("EvsD",""));
|
|---|
| 837 | ?>
|
|---|