/source/pressureMStar.c

https://github.com/EyNuel/cTraceo · C · 158 lines · 56 code · 15 blank · 87 comment · 5 complexity · aeeb38d45935bbe1c8ce604fad40f601 MD5 · raw file

  1. /****************************************************************************************
  2. * pressureMStar.c *
  3. * (formerly "mstar.for") *
  4. * Determines the star pressure contributions for particle velocity components of a *
  5. * specific ray at a specify coordinate for rays that bounce back ("returning rays"). *
  6. * *
  7. * When rays return they may influence a hydrophone more than once, hence we need to *
  8. * use eBracket to find all indices at which the ray passes the hydrophone. *
  9. * *
  10. * ------------------------------------------------------------------------------------ *
  11. * Website: *
  12. * https://github.com/EyNuel/cTraceo/wiki *
  13. * *
  14. * License: This file is part of the cTraceo Raytracing Model and is released under the *
  15. * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License *
  16. * http://creativecommons.org/licenses/by-nc-sa/3.0/ *
  17. * *
  18. * NOTE: cTraceo is research code under active development. *
  19. * The code may contain bugs and updates are possible in the future. *
  20. * *
  21. * Written for project SENSOCEAN by: *
  22. * Emanuel Ey *
  23. * emanuel.ey@gmail.com *
  24. * Copyright (C) 2011 - 2013 *
  25. * Signal Processing Laboratory *
  26. * Universidade do Algarve *
  27. * *
  28. * cTraceo is the C port of the FORTRAN 77 TRACEO code written by: *
  29. * Orlando Camargo Rodriguez: *
  30. * Copyright (C) 2010 *
  31. * Orlando Camargo Rodriguez *
  32. * orodrig@ualg.pt *
  33. * Universidade do Algarve *
  34. * Physics Department *
  35. * Signal Processing Laboratory *
  36. * *
  37. * ------------------------------------------------------------------------------------ *
  38. * Inputs: *
  39. * settings: Pointer to structure containing all input info. *
  40. * ray: Pointer the the ray, who's influence we are determining. *
  41. * rHyd: Range coordinate of the hydrophone. *
  42. * zHyd: Depth coordinate of the hydrophone. *
  43. * q0: Value of q at beginning of ray. *
  44. * *
  45. * Outputs: *
  46. * pressure_H: A 3 element array containing the horizontal *
  47. * pressure components ( LEFT, CENTER, RIGHT). *
  48. * pressure_V: A 3 element array containing the vertical *
  49. * pressure components ( TOP, CENTER, BOTTOM). *
  50. * NOTE: there is redundacy in the above arrays: the center *
  51. * component is repeated for performance reasons. *
  52. * *
  53. * Return Value: *
  54. * 0: At least one of the star coordinates (rLeft, rRight, zBottom, *
  55. * zTop) is outside the rays' range or rBox. *
  56. * Do not use the outputs -doing so will result in a segfault *
  57. * 1: Outputs are valid. *
  58. * *
  59. ****************************************************************************************/
  60. #pragma once
  61. #include "globals.h"
  62. #include <complex.h>
  63. #include "eBracket.c"
  64. uintptr_t pressureMStar(settings_t*, ray_t*, double, double, double, complex double*, complex double[]);
  65. uintptr_t pressureMStar( settings_t* settings, ray_t* ray, double rHyd, double zHyd, double q0, complex double* pressure_H, complex double* pressure_V){
  66. double rLeft, rRight, zTop, zBottom;
  67. uintptr_t i, jj;
  68. double dzdr, tauRay, zRay, qRay, width;
  69. complex double ampRay;
  70. uintptr_t nRet;
  71. uintptr_t iRet[51];
  72. complex double tempPressure[3];
  73. /* start with determining the coordinates for which we will need to calculate
  74. * acoustic pressure.
  75. */
  76. rLeft = rHyd - settings->output.dr;
  77. rRight = rHyd + settings->output.dr;
  78. zBottom = zHyd - settings->output.dz;
  79. zTop = zHyd + settings->output.dz;
  80. //we have to check that these points are within the rBox:
  81. if( rLeft < settings->source.rbox1 ||
  82. rRight >= settings->source.rbox2 ){
  83. DEBUG(8, "Either rLeft or rRight are outside rBox\n");
  84. return 0;
  85. }
  86. //set pressure contributions to 0;
  87. for(i=0; i<3; i++){
  88. pressure_H[i] = 0;
  89. pressure_V[i] = 0;
  90. }
  91. //if(eBracket(ray->nCoords, ray[i].r, rLeft, &nRet, iRet)){
  92. eBracket(ray->nCoords, ray->r, rLeft, &nRet, iRet);
  93. DEBUG(8,"nRet: %u\n", (uint32_t)nRet);
  94. // NOTE: this block will not be run if the index returned by bracket() is out of bounds.
  95. for(jj=0; jj<nRet; jj++){
  96. getRayParameters(ray, iRet[jj], q0, rLeft, &dzdr, &tauRay, &zRay, &ampRay, &qRay, &width);
  97. DEBUG(8, "dzdr: %e, tauRay: %e, zRay: %e, ampRay: %e, qRay: %e, w: %e\n", dzdr, tauRay, zRay, cabs(ampRay), qRay, width);
  98. getRayPressureExplicit(settings, ray, iRet[jj], zHyd, tauRay, zRay, dzdr, ampRay, width, &tempPressure[LEFT]);
  99. pressure_H[LEFT] += tempPressure[LEFT];
  100. }
  101. /*
  102. }else{
  103. DEBUG(6, "rLeft (%lf) can not be bracketed.\n", rLeft);
  104. return 0;
  105. }
  106. */
  107. //if(eBracket(ray->nCoords, ray[i].r, rHyd, &nRet, iRet)){
  108. eBracket(ray->nCoords, ray->r, rHyd, &nRet, iRet);
  109. DEBUG(8,"nRet: %u\n", (uint32_t)nRet);
  110. for(jj=0; jj<nRet; jj++){
  111. getRayParameters(ray, iRet[jj], q0, rHyd, &dzdr, &tauRay, &zRay, &ampRay, &qRay, &width);
  112. DEBUG(1, "dzdr: %e, tau: %e, amp: %e\n", dzdr, tauRay, ampRay);
  113. getRayPressureExplicit(settings, ray, iRet[jj], zTop, tauRay, zRay, dzdr, ampRay, width, &tempPressure[TOP]);
  114. getRayPressureExplicit(settings, ray, iRet[jj], zHyd, tauRay, zRay, dzdr, ampRay, width, &tempPressure[CENTER]);
  115. getRayPressureExplicit(settings, ray, iRet[jj], zBottom, tauRay, zRay, dzdr, ampRay, width, &tempPressure[BOTTOM]);
  116. pressure_V[TOP] += tempPressure[TOP];
  117. pressure_V[CENTER] += tempPressure[CENTER];
  118. pressure_H[CENTER] += tempPressure[CENTER];
  119. pressure_V[BOTTOM] += tempPressure[BOTTOM];
  120. }
  121. /*
  122. }else{
  123. DEBUG(6, "rHyd (%lf) can not be bracketed.\n", rHyd);
  124. return 0;
  125. }
  126. */
  127. //if(eBracket(ray->nCoords, ray[i].r, rRight, &nRet, iRet)){
  128. eBracket(ray->nCoords, ray->r, rRight, &nRet, iRet);
  129. DEBUG(8,"nRet: %u\n", (uint32_t)nRet);
  130. for(jj=0; jj<nRet; jj++){
  131. getRayParameters(ray, iRet[jj], q0, rRight, &dzdr, &tauRay, &zRay, &ampRay, &qRay, &width);
  132. getRayPressureExplicit(settings, ray, iRet[jj], zHyd, tauRay, zRay, dzdr, ampRay, width, &tempPressure[RIGHT]);
  133. pressure_H[RIGHT] += tempPressure[RIGHT];
  134. }
  135. /*
  136. }else{
  137. DEBUG(6, "rRight (%lf) can not be bracketed.\n", rRight);
  138. return 0;
  139. }
  140. */
  141. //success
  142. return 1;
  143. }