Browse Source

Fix bug in QWEKey related to array bounds

add-code-of-conduct-1
Trevor Irons 6 years ago
parent
commit
d4eba3abbe
3 changed files with 16 additions and 9 deletions
  1. 1
    1
      CMakeLists.txt
  2. 11
    6
      Modules/FDEM1D/src/EMEarth1D.cpp
  3. 4
    2
      Modules/FDEM1D/src/QWEKey.cpp

+ 1
- 1
CMakeLists.txt View File

10
 # Lemma versioning, set Major, minor, and patch here                                               #
10
 # Lemma versioning, set Major, minor, and patch here                                               #
11
 set(LEMMA_VERSION_MAJOR "0")                                                                       #
11
 set(LEMMA_VERSION_MAJOR "0")                                                                       #
12
 set(LEMMA_VERSION_MINOR "2")                                                                       #
12
 set(LEMMA_VERSION_MINOR "2")                                                                       #
13
-set(LEMMA_VERSION_PATCH "2")                                                                       #
13
+set(LEMMA_VERSION_PATCH "3")                                                                       #
14
 set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"")      #
14
 set(LEMMA_VERSION "\"${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}\"")      #
15
 set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}") #
15
 set(LEMMA_VERSION_NOQUOTES "${LEMMA_VERSION_MAJOR}.${LEMMA_VERSION_MINOR}.${LEMMA_VERSION_PATCH}") #
16
 ####################################################################################################
16
 ####################################################################################################

+ 11
- 6
Modules/FDEM1D/src/EMEarth1D.cpp View File

232
             icalc += 1;
232
             icalc += 1;
233
             // Check to see if they are all on a plane? If so we can do this fast
233
             // Check to see if they are all on a plane? If so we can do this fast
234
             if (Antenna->IsHorizontallyPlanar() && ( HankelType == ANDERSON801 || HankelType== FHTKEY201 || HankelType==FHTKEY101 ||
234
             if (Antenna->IsHorizontallyPlanar() && ( HankelType == ANDERSON801 || HankelType== FHTKEY201 || HankelType==FHTKEY101 ||
235
-                                                     HankelType == FHTKEY51 || HankelType == FHTKONG61 || FHTKONG121 || FHTKONG241 || IRONS )) {
235
+                                                     HankelType == FHTKEY51 || HankelType == FHTKONG61 || HankelType == FHTKONG121 ||
236
+                                                     HankelType == FHTKONG241 || HankelType == IRONS )) {
236
                 #ifdef HAVE_BOOST_PROGRESS
237
                 #ifdef HAVE_BOOST_PROGRESS
237
                 if (progressbar) {
238
                 if (progressbar) {
238
                     disp = new boost::progress_display( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies() );
239
                     disp = new boost::progress_display( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies() );
260
                     }
261
                     }
261
                     #endif
262
                     #endif
262
                 }
263
                 }
263
-            } else
264
-            if (Receivers->GetNumberOfPoints() > Antenna->GetNumberOfFrequencies()) {
264
+            } else if (Receivers->GetNumberOfPoints() > Antenna->GetNumberOfFrequencies()) {
265
 
265
 
266
-                //std::cout << "freq parallel #1" << std::endl;
266
+                std::cout << "freq parallel #1" << std::endl;
267
                 //** Progress display bar for long calculations */
267
                 //** Progress display bar for long calculations */
268
                 #ifdef HAVE_BOOST_PROGRESS
268
                 #ifdef HAVE_BOOST_PROGRESS
269
                 if (progressbar) {
269
                 if (progressbar) {
279
                     // Since these antennas change we need a local copy for each
279
                     // Since these antennas change we need a local copy for each
280
                     // thread.
280
                     // thread.
281
                     auto AntCopy = static_cast<PolygonalWireAntenna*>(Antenna.get())->ClonePA();
281
                     auto AntCopy = static_cast<PolygonalWireAntenna*>(Antenna.get())->ClonePA();
282
-
282
+                    auto Hankel = HankelTransformFactory::NewSP( HankelType );
283
+/*
283
                     std::shared_ptr<HankelTransform> Hankel;
284
                     std::shared_ptr<HankelTransform> Hankel;
284
                     switch (HankelType) {
285
                     switch (HankelType) {
285
                         case ANDERSON801:
286
                         case ANDERSON801:
304
                             Hankel = FHT<FHTKONG121>::NewSP();
305
                             Hankel = FHT<FHTKONG121>::NewSP();
305
                             break;
306
                             break;
306
                         case QWEKEY:
307
                         case QWEKEY:
308
+                            std::cout << "QWEKEY" << std::endl;
307
                             Hankel = QWEKey::NewSP();
309
                             Hankel = QWEKey::NewSP();
308
                             break;
310
                             break;
309
                         default:
311
                         default:
310
                             std::cerr << "Hankel transform cannot be created\n";
312
                             std::cerr << "Hankel transform cannot be created\n";
311
                             exit(EXIT_FAILURE);
313
                             exit(EXIT_FAILURE);
312
                     }
314
                     }
313
-
315
+*/
314
                     //for (int irec=tid; irec<Receivers->GetNumberOfPoints(); irec+=nthreads) {
316
                     //for (int irec=tid; irec<Receivers->GetNumberOfPoints(); irec+=nthreads) {
315
                     #ifdef LEMMAUSEOMP
317
                     #ifdef LEMMAUSEOMP
316
                     #pragma omp for schedule(static, 1) //nowait
318
                     #pragma omp for schedule(static, 1) //nowait
753
 
755
 
754
     void EMEarth1D::SolveSingleTxRxPair (const int &irec, HankelTransform *Hankel, const Real &wavef, const int &ifreq,
756
     void EMEarth1D::SolveSingleTxRxPair (const int &irec, HankelTransform *Hankel, const Real &wavef, const int &ifreq,
755
                    DipoleSource *tDipole) {
757
                    DipoleSource *tDipole) {
758
+        //std::cout << "SolveSingleTxRxPair" << std::endl;
756
         ++icalcinner;
759
         ++icalcinner;
757
         Real rho = (Receivers->GetLocation(irec).head<2>() - tDipole->GetLocation().head<2>()).norm();
760
         Real rho = (Receivers->GetLocation(irec).head<2>() - tDipole->GetLocation().head<2>()).norm();
758
         tDipole->SetKernels(ifreq, FieldsToCalculate, Receivers, irec, Earth);
761
         tDipole->SetKernels(ifreq, FieldsToCalculate, Receivers, irec, Earth);
772
     void EMEarth1D::SolveLaggedTxRxPair(const int &irec, HankelTransform* Hankel,
775
     void EMEarth1D::SolveLaggedTxRxPair(const int &irec, HankelTransform* Hankel,
773
                     const Real &wavef, const int &ifreq, PolygonalWireAntenna* antenna) {
776
                     const Real &wavef, const int &ifreq, PolygonalWireAntenna* antenna) {
774
 
777
 
778
+        //std::cout << "SolveLaggedTxRxPair" << std::endl;
779
+
775
         antenna->ApproximateWithElectricDipoles(Receivers->GetLocation(irec));
780
         antenna->ApproximateWithElectricDipoles(Receivers->GetLocation(irec));
776
 
781
 
777
         // Determine the min and max arguments
782
         // Determine the min and max arguments

+ 4
- 2
Modules/FDEM1D/src/QWEKey.cpp View File

141
     //--------------------------------------------------------------------------------------
141
     //--------------------------------------------------------------------------------------
142
     void QWEKey::ComputeRelated ( const Real& rho, std::shared_ptr<KernelEM1DManager> KernelManagerIn ) {
142
     void QWEKey::ComputeRelated ( const Real& rho, std::shared_ptr<KernelEM1DManager> KernelManagerIn ) {
143
         KernelManager = KernelManagerIn;  // OK becauase this is internal and we know what we are doing
143
         KernelManager = KernelManagerIn;  // OK becauase this is internal and we know what we are doing
144
-
145
         Lambda = Bx.array()/rho;
144
         Lambda = Bx.array()/rho;
146
         Intervals = xInt.array()/rho;
145
         Intervals = xInt.array()/rho;
147
         int nrel = (int)(KernelManager->GetSTLVector().size());
146
         int nrel = (int)(KernelManager->GetSTLVector().size());
270
                     }
269
                     }
271
 
270
 
272
                     // The extrapolated result plus the prev integration term:
271
                     // The extrapolated result plus the prev integration term:
273
-                    Textrap(j,n) = TS(j, (n-1)%2)+prev(0, j);
272
+                    if (n>0) {
273
+                        Textrap(j,n) = TS(j, (n-1)%2)+prev(0, j); // WAS  BUG
274
+                    }
275
+                    //Textrap(j,n) = TS(j, (n-1)%2 + 1)+prev(0, j);
274
                     //Textrap(j,n) = TS(j, n%2 + 1)+prev(0, j);
276
                     //Textrap(j,n) = TS(j, n%2 + 1)+prev(0, j);
275
 
277
 
276
                     // Step 3: Analyze for convergence:
278
                     // Step 3: Analyze for convergence:

Loading…
Cancel
Save