Kaynağa Gözat

Found memory leak, in a cycle of shared_ptr, hence the existence of weak_ptr....

enhancement_3
Trevor Irons 8 yıl önce
ebeveyn
işleme
6d6b66f69b

+ 1
- 1
Modules/FDEM1D/include/DipoleSource.h Dosyayı Görüntüle

@@ -250,7 +250,7 @@ namespace Lemma {
250 250
             Real                         c2p;
251 251
             Real                         kernelFreq;
252 252
 
253
-            FIELDCALCULATIONS            FieldsToCalculate;
253
+            FIELDCALCULATIONS            FieldsToCalculate = BOTH;
254 254
 
255 255
             VectorXcr                    f;
256 256
             VectorXi                     ik;

+ 5
- 0
Modules/FDEM1D/include/EMEarth1D.h Dosyayı Görüntüle

@@ -138,6 +138,11 @@ namespace Lemma {
138 138
                     const Real &wavef, const int &ifreq,
139 139
                     DipoleSource* tDipole);
140 140
 
141
+//             void SolveSingleTxRxPair(const int &irec,
142
+//                     std::shared_ptr<HankelTransform> Hankel,
143
+//                     const Real &wavef, const int &ifreq,
144
+//                     std::shared_ptr<DipoleSource> tDipole);
145
+
141 146
             /** Used internally, this is the innermost loop of the MakeCalc3,
142 147
              *  and CalculateWireAntennaField routines.
143 148
              */

+ 3
- 3
Modules/FDEM1D/include/KernelEM1DManager.h Dosyayı Görüntüle

@@ -110,7 +110,7 @@ namespace Lemma {
110 110
             void SetEarth( std::shared_ptr<LayeredEarthEM>   Earth);
111 111
 
112 112
             /** Sets the source of the kernels */
113
-            void SetDipoleSource( std::shared_ptr<DipoleSource> Dipole, const int& ifreq, const Real& rx_zin);
113
+            void SetDipoleSource( DipoleSource* Dipole, const int& ifreq, const Real& rx_zin);
114 114
 
115 115
             /** Returns pointer to specified kernel indice. Indices are assigned in the same
116 116
                 order as they are created by AddKernel.
@@ -124,7 +124,7 @@ namespace Lemma {
124 124
 
125 125
             /** Returns pointer to connected dipole.
126 126
              */
127
-            std::shared_ptr<DipoleSource>    GetDipole( );
127
+            DipoleSource*                      GetDipole( );
128 128
 
129 129
             inline std::vector< std::shared_ptr<KernelEM1DBase> >  GetSTLVector() {
130 130
                 return KernelVec;
@@ -156,7 +156,7 @@ namespace Lemma {
156 156
             std::shared_ptr<LayeredEarthEM>            Earth;
157 157
 
158 158
             /** EM dipole souce */
159
-            std::shared_ptr<DipoleSource>              Dipole;
159
+            DipoleSource*                              Dipole;
160 160
 
161 161
             /** Frequency index for the sources */
162 162
             int                                        ifreq;

+ 1
- 1
Modules/FDEM1D/include/KernelEM1DReflBase.h Dosyayı Görüntüle

@@ -85,7 +85,7 @@ namespace Lemma {
85 85
 
86 86
             }
87 87
 
88
-            void SetUpSource( std::shared_ptr<DipoleSource> Dipole, const int &ifreq ) {
88
+            void SetUpSource( DipoleSource* Dipole, const int &ifreq ) {
89 89
 
90 90
                 zh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*MU0);
91 91
                 yh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*EPSILON0);

+ 5
- 5
Modules/FDEM1D/src/DipoleSource.cpp Dosyayı Görüntüle

@@ -35,6 +35,7 @@ namespace Lemma {
35 35
 
36 36
     DipoleSource::DipoleSource( const ctor_key& ) : LemmaObject( ),
37 37
                     Type(NOSOURCETYPE),
38
+                    irec(-1),
38 39
                     Phase(0),
39 40
                     Moment(1),
40 41
                     KernelManager(nullptr),
@@ -220,15 +221,12 @@ namespace Lemma {
220 221
         if (Receivers != ReceiversIn) {
221 222
             Receivers = ReceiversIn;
222 223
         }
223
-
224 224
         if (Earth != EarthIn) {
225 225
             Earth = EarthIn;
226 226
         }
227
-
228 227
         if (irecin != irec) {
229 228
             irec = irecin;
230 229
         }
231
-
232 230
         if (FieldsToCalculate != Fields) {
233 231
             FieldsToCalculate = Fields;
234 232
         }
@@ -252,8 +250,10 @@ namespace Lemma {
252 250
 
253 251
         KernelManager = KernelEM1DManager::NewSP();
254 252
             KernelManager->SetEarth(Earth);
255
-            KernelManager->SetDipoleSource(shared_from_this(), ifreq, Receivers->GetLocation(irec)[2]);
256
-        kernelFreq = Freqs(ifreq); // this is never used
253
+            // alternative is to use weak_ptr here, this is deep and internal, and we are safe.
254
+            KernelManager->SetDipoleSource( shared_from_this().get() , ifreq, Receivers->GetLocation(irec)[2]);
255
+            kernelFreq = Freqs(ifreq); // this is never used
256
+
257 257
         ReSetKernels( ifreq, Fields, Receivers, irec, Earth );
258 258
 
259 259
         return;

+ 9
- 6
Modules/FDEM1D/src/EMEarth1D.cpp Dosyayı Görüntüle

@@ -737,14 +737,21 @@ namespace Lemma {
737 737
     void EMEarth1D::SolveSingleTxRxPair (const int &irec, HankelTransform *Hankel, const Real &wavef, const int &ifreq,
738 738
                    DipoleSource *tDipole) {
739 739
         ++icalcinner;
740
-
741 740
         Real rho = (Receivers->GetLocation(irec).head<2>() - tDipole->GetLocation().head<2>()).norm();
742
-
743 741
         tDipole->SetKernels(ifreq, FieldsToCalculate, Receivers, irec, Earth);
744 742
         Hankel->ComputeRelated( rho, tDipole->GetKernelManager() );
745 743
         tDipole->UpdateFields( ifreq,  Hankel, wavef );
746 744
     }
747 745
 
746
+//     void EMEarth1D::SolveSingleTxRxPair (const int &irec, std::shared_ptr<HankelTransform> Hankel, const Real &wavef, const int &ifreq,
747
+//                    std::shared_ptr<DipoleSource> tDipole) {
748
+//         ++icalcinner;
749
+//         Real rho = (Receivers->GetLocation(irec).head<2>() - tDipole->GetLocation().head<2>()).norm();
750
+//         tDipole->SetKernels(ifreq, FieldsToCalculate, Receivers, irec, Earth);
751
+//         //Hankel->ComputeRelated( rho, tDipole->GetKernelManager() );
752
+//         //tDipole->UpdateFields( ifreq,  Hankel, wavef );
753
+//     }
754
+
748 755
     void EMEarth1D::SolveLaggedTxRxPair(const int &irec, FHTAnderson801* Hankel,
749 756
                     const Real &wavef, const int &ifreq, PolygonalWireAntenna* antenna) {
750 757
 
@@ -813,7 +820,6 @@ namespace Lemma {
813 820
         #pragma omp parallel
814 821
         #endif
815 822
         { // OpenMP Parallel Block
816
-
817 823
             #ifdef LEMMAUSEOMP
818 824
             int tid = omp_get_thread_num();
819 825
             int nthreads = omp_get_num_threads();
@@ -821,9 +827,7 @@ namespace Lemma {
821 827
             int tid=0;
822 828
             int nthreads=1;
823 829
             #endif
824
-
825 830
             auto tDipole = Dipole->Clone();
826
-
827 831
             std::shared_ptr<HankelTransform> Hankel;
828 832
             switch (HankelType) {
829 833
                 case ANDERSON801:
@@ -848,7 +852,6 @@ namespace Lemma {
848 852
                     std::cerr << "Hankel transform cannot be created\n";
849 853
                     exit(EXIT_FAILURE);
850 854
             }
851
-
852 855
             if ( tDipole->GetNumberOfFrequencies() < Receivers->GetNumberOfPoints() ) {
853 856
                 for (int ifreq=0; ifreq<tDipole->GetNumberOfFrequencies(); ++ifreq) {
854 857
                     // Propogation constant in free space being input to Hankel

+ 2
- 2
Modules/FDEM1D/src/KernelEM1DManager.cpp Dosyayı Görüntüle

@@ -43,7 +43,7 @@ namespace Lemma {
43 43
         Earth = Earthin;
44 44
     }
45 45
 
46
-    void KernelEM1DManager::SetDipoleSource( std::shared_ptr<DipoleSource> DipoleIn, const int& ifreqin,
46
+    void KernelEM1DManager::SetDipoleSource( DipoleSource* DipoleIn, const int& ifreqin,
47 47
             const Real& rx_zin) {
48 48
         Dipole = DipoleIn;
49 49
 
@@ -59,7 +59,7 @@ namespace Lemma {
59 59
         return KernelVec[ik].get();
60 60
     }
61 61
 
62
-    std::shared_ptr<DipoleSource> KernelEM1DManager::GetDipole( ) {
62
+    DipoleSource* KernelEM1DManager::GetDipole( ) {
63 63
         return Dipole;
64 64
     }
65 65
 

Loading…
İptal
Kaydet