Skip to content

Handling sources in the python interface #202

Open
jmllorens wants to merge 6 commits intoHomerReid:masterfrom
jmllorens:Solver_PW
Open

Handling sources in the python interface #202
jmllorens wants to merge 6 commits intoHomerReid:masterfrom
jmllorens:Solver_PW

Conversation

@jmllorens
Copy link
Copy Markdown

In issue #195 I found some problems to get the same results between GetPFT and scuff-scatter. After digging into the problem, the current fix ensures the same result for dipoles and plane wave sources.

Description of the main changes:

  1. libs/libIncField/IncField.cc

    1. Create the copy method for the base class: IncField::IncField(const IncField &IF)
    2. There was a problem in the copy of IF to CachedIF in scuffSolver.cc The attributes of the base class IncField where not copied when new PlaneWave(*PW) or new PointSource(*PS).
    3. Another difficulty I found while fixing this is that the attribute RegionLabel of the new object created by new PlaneWave or new PointSource was not initialized to a NULL pointer as the IncField constructor demands, but was pointing to random memory positions. Therefore line IncField.cc:89 contains the assignment RegionLabel=NULL.
  2. libs/libIncField/PointSource.cc

    1. Call the copy method of the base class: PointSource::PointSource(const PointSource &PS) : IncField(PS)
  3. libs/libIncField/PlaneWave.cc

    1. Call the copy method of the base class: PlaneWave::PlaneWave(const PlaneWave &PW) : IncField(PW)
    2. Comment SetRegionLabel as RegionLabel is an attribute of IncField
  4. libs/libIncField/libIncField.h

    1. Added the copy method IncField(const IncField &IF);
  5. libs/libscuff/AssembleRHSVector.cc

    1. PointSource requires to know the RegionLabel if the dipole is inside of a scatterer: IF->RegionLabel = strdupEC(RegionLabels[IF->RegionIndex]);
  6. libs/libscuffSolver/scuffSolver.cc

    1. With this code, CachedIF ends up always being a PointSource

           PlaneWave *PW = (PlaneWave *) IF;
           if (PW) CachedIF=new PlaneWave(*PW);
           PointSource *PS = (PointSource *) IF;
           if (PS) CachedIF=new PointSource(*PS);
    2. The way I found to fix the copy of the source type is through dynamic casting:

       if (dynamic_cast<PlaneWave*>(IF) != nullptr)
           {
            PlaneWave *PW = (PlaneWave *) IF;
            CachedIF=new PlaneWave(*PW);
           } 
           if (dynamic_cast<PointSource*>(IF) != nullptr)
           {
            PointSource *PS = (PointSource *) IF;
            CachedIF=new PointSource(*PS);
           }

The compiled binaries passes the Mie test.

Solves the problem of CachedIF to get a copy of PW and the Omega from the parent class IncField.
Use dynamic cast to determine whether IF is PW or PS.
Now the results of a PointSource in an interior domain are the same
for python and for scatter-scuff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant