ソースを参照

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

enhancement_3
Trevor Irons 7年前
コミット
6d6b66f69b

+ 1
- 1
Modules/FDEM1D/include/DipoleSource.h ファイルの表示

250
             Real                         c2p;
250
             Real                         c2p;
251
             Real                         kernelFreq;
251
             Real                         kernelFreq;
252
 
252
 
253
-            FIELDCALCULATIONS            FieldsToCalculate;
253
+            FIELDCALCULATIONS            FieldsToCalculate = BOTH;
254
 
254
 
255
             VectorXcr                    f;
255
             VectorXcr                    f;
256
             VectorXi                     ik;
256
             VectorXi                     ik;

+ 5
- 0
Modules/FDEM1D/include/EMEarth1D.h ファイルの表示

138
                     const Real &wavef, const int &ifreq,
138
                     const Real &wavef, const int &ifreq,
139
                     DipoleSource* tDipole);
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
             /** Used internally, this is the innermost loop of the MakeCalc3,
146
             /** Used internally, this is the innermost loop of the MakeCalc3,
142
              *  and CalculateWireAntennaField routines.
147
              *  and CalculateWireAntennaField routines.
143
              */
148
              */

+ 3
- 3
Modules/FDEM1D/include/KernelEM1DManager.h ファイルの表示

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

+ 1
- 1
Modules/FDEM1D/include/KernelEM1DReflBase.h ファイルの表示

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
                 zh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*MU0);
90
                 zh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*MU0);
91
                 yh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*EPSILON0);
91
                 yh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*EPSILON0);

+ 5
- 5
Modules/FDEM1D/src/DipoleSource.cpp ファイルの表示

35
 
35
 
36
     DipoleSource::DipoleSource( const ctor_key& ) : LemmaObject( ),
36
     DipoleSource::DipoleSource( const ctor_key& ) : LemmaObject( ),
37
                     Type(NOSOURCETYPE),
37
                     Type(NOSOURCETYPE),
38
+                    irec(-1),
38
                     Phase(0),
39
                     Phase(0),
39
                     Moment(1),
40
                     Moment(1),
40
                     KernelManager(nullptr),
41
                     KernelManager(nullptr),
220
         if (Receivers != ReceiversIn) {
221
         if (Receivers != ReceiversIn) {
221
             Receivers = ReceiversIn;
222
             Receivers = ReceiversIn;
222
         }
223
         }
223
-
224
         if (Earth != EarthIn) {
224
         if (Earth != EarthIn) {
225
             Earth = EarthIn;
225
             Earth = EarthIn;
226
         }
226
         }
227
-
228
         if (irecin != irec) {
227
         if (irecin != irec) {
229
             irec = irecin;
228
             irec = irecin;
230
         }
229
         }
231
-
232
         if (FieldsToCalculate != Fields) {
230
         if (FieldsToCalculate != Fields) {
233
             FieldsToCalculate = Fields;
231
             FieldsToCalculate = Fields;
234
         }
232
         }
252
 
250
 
253
         KernelManager = KernelEM1DManager::NewSP();
251
         KernelManager = KernelEM1DManager::NewSP();
254
             KernelManager->SetEarth(Earth);
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
         ReSetKernels( ifreq, Fields, Receivers, irec, Earth );
257
         ReSetKernels( ifreq, Fields, Receivers, irec, Earth );
258
 
258
 
259
         return;
259
         return;

+ 9
- 6
Modules/FDEM1D/src/EMEarth1D.cpp ファイルの表示

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

+ 2
- 2
Modules/FDEM1D/src/KernelEM1DManager.cpp ファイルの表示

43
         Earth = Earthin;
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
             const Real& rx_zin) {
47
             const Real& rx_zin) {
48
         Dipole = DipoleIn;
48
         Dipole = DipoleIn;
49
 
49
 
59
         return KernelVec[ik].get();
59
         return KernelVec[ik].get();
60
     }
60
     }
61
 
61
 
62
-    std::shared_ptr<DipoleSource> KernelEM1DManager::GetDipole( ) {
62
+    DipoleSource* KernelEM1DManager::GetDipole( ) {
63
         return Dipole;
63
         return Dipole;
64
     }
64
     }
65
 
65
 

読み込み中…
キャンセル
保存