NMPB08 Shared Libraries
|
00001 00008 #include "PropagationNMPB08.h" 00009 #include "CalculPropagation.h" 00010 #include "SousCalculs/ElementaryPath.h" 00011 #include <vector> 00012 #include <math.h> 00013 #include <stdio.h> 00014 using namespace std; 00015 using namespace CalculPropagationNMPB; 00016 using namespace ElementaryPathNMPB; 00017 00025 bool CheckPath(PathID path) 00026 { 00027 if(path == NULE) 00028 { 00029 printf ("ERROR : Chemin non initialise \n") ; 00030 return false; 00031 } 00032 00033 return true; 00034 } 00035 00041 PathID NMPB08_CreatePath() 00042 { 00043 try 00044 { 00045 PropagationPath* path = new PropagationPath; 00046 00047 // Default frequencies : 18 nominal median frequencies : 00048 double NominalMedianFrequency[] = {100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000}; 00049 const int frequencyNumber = 18; 00050 path->SetFrequencies(frequencyNumber, NominalMedianFrequency); 00051 00052 return path; 00053 } 00054 catch ( const int *) 00055 { 00056 return NULE; 00057 } 00058 catch (const std::exception& e) 00059 { 00060 printf ("ERROR : %s \n", e.what()) ; 00061 return NULE; 00062 } 00063 } 00064 00074 PathID NMPB08_CreatePathEx(int nbFreq, double const* freq) 00075 { 00076 try 00077 { 00078 PropagationPath* path = new PropagationPath(); 00079 path->SetFrequencies(nbFreq, freq); 00080 return path; 00081 } 00082 catch ( const int * ) 00083 { 00084 return NULE; 00085 } 00086 catch (const std::exception& e) 00087 { 00088 printf ("ERROR : %s \n", e.what()) ; 00089 return NULE; 00090 } 00091 } 00092 00104 bool NMPB08_SetOption(PathID path, Option option, bool on_off) 00105 { 00106 try 00107 { 00108 if(!CheckPath(path)) return false; 00109 00110 PropagationPath* propagationPath = (PropagationPath*) path; 00111 propagationPath->SetOption(option, on_off); 00112 return true; 00113 } 00114 catch ( const int * ) 00115 { 00116 return false; 00117 } 00118 catch (const std::exception& e) 00119 { 00120 printf ("ERROR : %s \n", e.what()) ; 00121 return false; 00122 } 00123 } 00124 00132 int NMPB08_GetNbFrequencies (PathID path) 00133 { 00134 try 00135 { 00136 if(!CheckPath( path)) return 0; 00137 00138 PropagationPath* propagationPath = (PropagationPath*) path; 00139 return propagationPath->GetNbFrequencies(); 00140 } 00141 catch ( const int * ) 00142 { 00143 return 0; 00144 } 00145 catch (const std::exception& e) 00146 { 00147 printf ("ERROR : %s \n", e.what()) ; 00148 return 0; 00149 } 00150 } 00151 00159 double const* NMPB08_GetFrequencies (PathID path) 00160 { 00161 try 00162 { 00163 if(!CheckPath( path)) return 0; 00164 00165 PropagationPath* propagationPath = (PropagationPath*) path; 00166 return propagationPath->GetFrequencies(); 00167 } 00168 catch ( const int * ) 00169 { 00170 return 0; 00171 } 00172 catch (const std::exception& e) 00173 { 00174 printf ("ERROR : %s \n", e.what()) ; 00175 return 0; 00176 } 00177 } 00178 00186 bool NMPB08_DeletePath (PathID path) 00187 { 00188 try 00189 { 00190 if(!CheckPath( path)) return false; 00191 00192 PropagationPath* propagationPath = (PropagationPath*) path; 00193 delete propagationPath; 00194 return true; 00195 } 00196 catch ( const int * ) 00197 { 00198 return false; 00199 } 00200 catch (const std::exception& e) 00201 { 00202 printf ("ERROR : %s \n", e.what()) ; 00203 return false; 00204 } 00205 } 00206 00214 bool NMPB08_ClearPath (PathID path) 00215 { 00216 try 00217 { 00218 if(!CheckPath( path)) return false; 00219 00220 PropagationPath* propagationPath = (PropagationPath*) path; 00221 propagationPath->ClearPath(); 00222 00223 return true; 00224 } 00225 catch ( const int * ) 00226 { 00227 return false; 00228 } 00229 catch (const std::exception& e) 00230 { 00231 printf ("ERROR : %s \n", e.what()) ; 00232 return false; 00233 } 00234 } 00235 00247 bool NMPB08_ExtendPath (PathID path, Position3D const* point3D, double g) 00248 { 00249 try 00250 { 00251 if(!CheckPath( path)) return false; 00252 00253 PropagationPath* thePath = (PropagationPath*) path; 00254 thePath->ExtendPath(point3D, g); 00255 return true; 00256 } 00257 catch ( const int * ) 00258 { 00259 return false; 00260 } 00261 catch (const std::exception& e) 00262 { 00263 printf ("ERROR : %s \n", e.what()) ; 00264 return false; 00265 } 00266 } 00267 00281 bool NMPB08_ExtendPathExt (PathID path, Position3D const* point3D, double g, ExtensionNMPB const* ext) 00282 { 00283 try 00284 { 00285 if(!CheckPath( path)) return false; 00286 00287 PropagationPath* thePath = (PropagationPath*) path; 00288 thePath->ExtendPathExt(point3D, g, ext); 00289 return true; 00290 } 00291 catch ( const int * ) 00292 { 00293 return false; 00294 } 00295 catch (const std::exception& e) 00296 { 00297 printf ("ERROR : %s \n", e.what()) ; 00298 return false; 00299 } 00300 } 00301 00311 int NMPB08_SetSourceHeight (PathID path, double h) 00312 { 00313 try 00314 { 00315 if(!CheckPath( path)) return ERRNullPath; 00316 00317 PropagationPath* thePath = (PropagationPath*) path; 00318 thePath->SetSourceHeight(h); 00319 return ERRNone; 00320 } 00321 catch ( const int * e ) 00322 { 00323 return *e; 00324 } 00325 catch (const std::exception& e) 00326 { 00327 printf ("ERROR : %s \n", e.what()) ; 00328 return ERRUnknown; 00329 } 00330 } 00331 00341 int NMPB08_SetReceiverHeight (PathID path, double h) 00342 { 00343 try 00344 { 00345 if(!CheckPath( path)) return ERRNullPath; 00346 00347 PropagationPath* thePath = (PropagationPath*) path; 00348 thePath->SetReceiverHeight(h); 00349 return ERRNone; 00350 } 00351 catch ( const int * e ) 00352 { 00353 return *e; 00354 } 00355 catch (const std::exception& e) 00356 { 00357 printf ("ERROR : %s \n", e.what()) ; 00358 return false; 00359 } 00360 } 00361 /* 00362 double MeanAttenuation (double const* attenuations, int nbAtt) 00363 { 00364 try 00365 { 00366 if (nbAtt <= 0) 00367 { 00368 return 0; 00369 } 00370 00371 double meanAtt = 0; 00372 for (int i = 0 ; i < nbAtt ; i++) 00373 { 00374 meanAtt += attenuations[i]; 00375 } 00376 00377 return (meanAtt / nbAtt); 00378 } 00379 catch ( const int * ) 00380 { 00381 return 0; 00382 } 00383 catch (const std::exception& e) 00384 { 00385 printf ("ERROR : %s \n", e.what()) ; 00386 return 0; 00387 } 00388 } 00389 */ 00390 00398 int NMPB08_DoCalculation (PathID path) 00399 { 00400 try 00401 { 00402 if(!CheckPath( path)) return ERRNullPath; 00403 00404 PropagationPath* propagationPath = (PropagationPath*) path; 00405 propagationPath->favorableAttenuations = 0 ; 00406 propagationPath->homogeneousAttenuations = 0 ; 00407 00408 // Calculate elementary paths between source and receiver : 00409 SetElementaryPath(propagationPath); 00410 if(propagationPath->GetOption(TRACE_DETAILS)) 00411 { 00412 printf("Distance SR : %7.3f \n", propagationPath->distSR); 00413 } 00414 00415 const int frequencyNumber = (int) propagationPath->frequencies.size(); 00416 double* favorableAttenuations = new double[frequencyNumber]; 00417 double* homogeneousAttenuations = new double[frequencyNumber]; 00418 00419 double* divergenceAttenuations = new double[frequencyNumber]; 00420 double* atmosphericAbsorptions = new double[frequencyNumber]; 00421 double* boundaryAttenuations_h = new double[frequencyNumber]; 00422 double* boundaryAttenuations_f = new double[frequencyNumber]; 00423 double* groundAttenuations_h = new double[frequencyNumber]; 00424 double* groundAttenuations_f = new double[frequencyNumber]; 00425 double* diffractionAttenuations_h = new double[frequencyNumber]; 00426 double* diffractionAttenuations_f = new double[frequencyNumber]; 00427 00428 for(int i = 0 ; i < frequencyNumber ; i++) 00429 { 00430 //total attenuation along the propagation path 00431 Attenuation pathAttenuation(propagationPath, propagationPath->frequencies[i]); 00432 pathAttenuation.AttenuationCalculation(); 00433 //Ai,F 00434 favorableAttenuations[i] = pathAttenuation.getFavorableAttenuation(); 00435 //Ai,H 00436 homogeneousAttenuations[i] = pathAttenuation.getHomogeneousAttenuation(); 00437 00438 // used values : 00439 divergenceAttenuations[i] = pathAttenuation.getDivergenceAttenuation(); 00440 atmosphericAbsorptions[i] = pathAttenuation.getAtmosphericAbsorption(); 00441 boundaryAttenuations_h[i] = pathAttenuation.getBoundaryAttenuation_h(); 00442 boundaryAttenuations_f[i] = pathAttenuation.getBoundaryAttenuation_f(); 00443 groundAttenuations_h[i] = pathAttenuation.getGroundAttenuation_h() + pathAttenuation.getEmbankmentAttenuation(); 00444 groundAttenuations_f[i] = pathAttenuation.getGroundAttenuation_f() + pathAttenuation.getEmbankmentAttenuation(); 00445 diffractionAttenuations_h[i] = pathAttenuation.getDiffractionAttenuation_h(); 00446 diffractionAttenuations_f[i] = pathAttenuation.getDiffractionAttenuation_f(); 00447 } 00448 00449 propagationPath->favorableAttenuations = favorableAttenuations; 00450 propagationPath->homogeneousAttenuations = homogeneousAttenuations; 00451 00452 // Sum on frequencies : 00453 /* 00454 double Adiv_sum = MeanAttenuation(divergenceAttenuations, frequencyNumber); 00455 double Aatm_sum = MeanAttenuation(atmosphericAbsorptions, frequencyNumber); 00456 double Asol_h_sum = MeanAttenuation(groundAttenuations_h, frequencyNumber); 00457 double Adif_h_sum = MeanAttenuation(diffractionAttenuations_h, frequencyNumber); 00458 double Att_h_sum = MeanAttenuation(homogeneousAttenuations, frequencyNumber); 00459 double Asol_f_sum = MeanAttenuation(groundAttenuations_f, frequencyNumber); 00460 double Adif_f_sum = MeanAttenuation(diffractionAttenuations_f, frequencyNumber); 00461 double Att_f_sum = MeanAttenuation(favorableAttenuations, frequencyNumber); 00462 */ 00463 00464 // write data : 00465 if(propagationPath->GetOption(TRACE_DETAILS)) 00466 { 00467 printf("Conditions homogenes : \n"); 00468 printf(" f; Adiv; Aatm; Asol; Adif; Ah\n"); 00469 //printf(" A;%7.1f;%7.1f;%7.1f;%7.1f;%7.1f \n", Adiv_sum, Aatm_sum, Asol_h_sum, Adif_h_sum, Att_h_sum); 00470 for (int i = 0 ; i < frequencyNumber ; i++) 00471 { 00472 printf ("%7.0f;%7.1f;%7.1f;", propagationPath->frequencies[i], divergenceAttenuations[i], atmosphericAbsorptions[i]) ; 00473 printf ("%7.1f;%7.1f;%7.1f", groundAttenuations_h[i], diffractionAttenuations_h[i], homogeneousAttenuations[i]) ; 00474 printf(" \n"); 00475 } 00476 printf(" \n"); 00477 printf("Conditions favorables : \n"); 00478 printf(" f; Adiv; Aatm; Asol; Adif; Af\n"); 00479 // printf(" A;%7.1f;%7.1f;%7.1f;%7.1f;%7.1f \n", Adiv_sum, Aatm_sum, Asol_f_sum, Adif_f_sum, Att_f_sum); 00480 for (int i = 0 ; i < frequencyNumber ; i++) 00481 { 00482 printf ("%7.0f;%7.1f;%7.1f;", propagationPath->frequencies[i], divergenceAttenuations[i], atmosphericAbsorptions[i]) ; 00483 printf ("%7.1f;%7.1f;%7.1f", groundAttenuations_f[i], diffractionAttenuations_f[i], favorableAttenuations[i]) ; 00484 printf(" \n"); 00485 } 00486 printf(" \n"); 00487 } 00488 00489 00490 delete [] divergenceAttenuations; 00491 delete [] atmosphericAbsorptions; 00492 delete [] boundaryAttenuations_h; 00493 delete [] boundaryAttenuations_f; 00494 delete [] groundAttenuations_h; 00495 delete [] groundAttenuations_f; 00496 delete [] diffractionAttenuations_h; 00497 delete [] diffractionAttenuations_f; 00498 00499 return ERRNone; 00500 } 00501 catch ( const int * e ) 00502 { 00503 return *e; 00504 } 00505 catch (const std::exception& e) 00506 { 00507 printf ("ERROR : %s \n", e.what()) ; 00508 return ERRUnknown; 00509 } 00510 } 00511 00519 double const* NMPB08_GetAttF (PathID path) 00520 { 00521 try 00522 { 00523 if(!CheckPath( path)) return 0; 00524 00525 PropagationPath* propagPath = (PropagationPath*) path; 00526 return propagPath->favorableAttenuations; 00527 } 00528 catch ( const int * ) 00529 { 00530 return 0; 00531 } 00532 catch (const std::exception& e) 00533 { 00534 printf ("ERROR : %s \n", e.what()) ; 00535 return 0; 00536 } 00537 } 00538 00546 double const* NMPB08_GetAttH (PathID path) 00547 { 00548 try 00549 { 00550 if(!CheckPath( path)) return 0; 00551 00552 PropagationPath* propagPath = (PropagationPath*) path; 00553 return propagPath->homogeneousAttenuations; 00554 } 00555 catch ( const int * ) 00556 { 00557 return 0; 00558 } 00559 catch (const std::exception& e) 00560 { 00561 printf ("ERROR : %s \n", e.what()) ; 00562 return 0; 00563 } 00564 } 00565 00577 double NMPB08_Leq_LT(double soundLevel_h, double soundLevel_f, double p) 00578 { 00579 try 00580 { 00581 return SoundLevelForPath(soundLevel_h, soundLevel_f, p); 00582 } 00583 catch ( const int * ) 00584 { 00585 return 0; 00586 } 00587 catch (const std::exception& e) 00588 { 00589 printf ("ERROR : %s \n", e.what()) ; 00590 return 0; 00591 } 00592 } 00593 00605 double NMPB08_SumLevels(int n, double const* levels) 00606 { 00607 try 00608 { 00609 return SumLevels(n, levels); 00610 } 00611 catch ( const int * ) 00612 { 00613 return 0; 00614 } 00615 catch (const std::exception& e) 00616 { 00617 printf ("ERROR : %s \n", e.what()) ; 00618 return 0; 00619 } 00620 } 00621 00637 double NMPB08_GetFavorableConditionProbability(Position3D const* source, Position3D const* receiver, int nbAngles, const double* fcpAngles, double angleNorth) 00638 { 00639 try 00640 { 00641 if (nbAngles != 18) 00642 { 00643 printf (".ERROR: NMPB requires fpc tables in steps of 20° \n") ; 00644 return 0; 00645 } 00646 00647 return GetFavorableConditionProbability(source, receiver, nbAngles, fcpAngles, angleNorth); 00648 } 00649 catch ( const int * ) 00650 { 00651 return 0; 00652 } 00653 catch (const std::exception& e) 00654 { 00655 printf ("ERROR : %s \n", e.what()) ; 00656 return 0; 00657 } 00658 } 00659 00682 int NMPB08_CalculateLeqLT(int nbFreq, double const* Lw, double const* attH, double const* attF, double fcp, double* LeqH, double* LeqF, double* LeqLT) 00683 { 00684 try 00685 { 00686 CalculateLeqLT(nbFreq, Lw, attH, attF, fcp, LeqH, LeqF, LeqLT); 00687 return ERRNone; 00688 } 00689 catch ( const int * e ) 00690 { 00691 return *e; 00692 } 00693 catch (const std::exception& e) 00694 { 00695 printf ("ERROR : %s \n", e.what()) ; 00696 return ERRUnknown; 00697 } 00698 }