Problem 2291 - Segmentation fault after changing Material of a volume back to the first defined material for this volume
Summary: Segmentation fault after changing Material of a volume back to the first defi...
Status: RESOLVED INVALID
Alias: None
Product: Geant4
Classification: Unclassified
Component: processes/electromagnetic (show other problems)
Version: 10.6
Hardware: All All
: P4 normal
Assignee: Vladimir.Ivantchenko
URL:
Depends on:
Blocks:
 
Reported: 2020-11-15 11:20 CET by David Platten
Modified: 2020-11-23 11:06 CET (History)
1 user (show)

See Also:


Attachments
Macro, detector construction and output files to run with TestEm1 (9.47 KB, application/zip)
2020-11-15 11:20 CET, David Platten
Details

Note You need to log in before you can comment on or make changes to this problem.
Description David Platten 2020-11-15 11:20:07 CET
Created attachment 644 [details]
Macro, detector construction and output files to run with TestEm1

A detailed description is on the Geant4 forum here: https://geant4-forum.web.cern.ch/t/segmentation-fault-after-changing-material-of-a-volume-back-to-the-first-defined-material-for-this-volume/3267


A segmentation fault takes place when an object's material is changed, and then changed back to the original material.


The problem can be reproduced by using TestEm1 with the attached files:

After some time I tried to reproduce my problem using the TestEm1 example and finally I got it. But it is a mistery to me. I describe it below in four runs:

Description:

I used the version 10.06.p02 with your mac file: moralles.mac.txt
RESULT: OK, no errors.

I changed from emstandard_opt0 to emstandard_opt4.
RESULT: OK, no errors.

After this I have changed the SetMaterial method to reproduce the way I do it in my code:

I have commented
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
and I have included
G4RunManager::GetRunManager()->ReinitializeGeometry();

So, the Construct() will be called again after material changes.

I used your mac file: moralles.mac.txt
RESULT: OK, no errors.

I changed from emstandard_opt0 to emstandard_opt4.
RESULT: SEGMENTAION FAULT when the material come back to G4_Al.

So, there is a combination to produce the error:
G4RunManager::GetRunManager()->ReinitializeGeometry();
with
emstandard_opt4
with
material change.

I hope someone can explain what what happens in this case.
Comment 1 Vladimir.Ivantchenko 2020-11-15 13:21:10 CET
Hello,

problem is in your modification inside DetectorConstruction.cc - the line you commented out is needed.

In the example itself I do not see any crash if in several runs for this example the 1st material is set  (I have checked this with candidate version of Geant4 cand01). 

VI
Comment 2 Vladimir.Ivantchenko 2020-11-23 10:55:51 CET
Hello,

to say more: when a material is changed it is not "geometry change" but is "physics change" situation in Geant4, because change of material means different cross sections, dEdx, other values, which should be prepared for the new run.

VI
Comment 3 David Platten 2020-11-23 11:06:59 CET
(In reply to Vladimir.Ivantchenko from comment #2)
> Hello,
> 
> to say more: when a material is changed it is not "geometry change" but is
> "physics change" situation in Geant4, because change of material means
> different cross sections, dEdx, other values, which should be prepared for
> the new run.
> 
> VI

Dear Vladimir,

Many thanks for your input. My code is now working following the addition of G4RunManager::GetRunManager()->PhysicsHasBeenModified(); before the G4RunManager::GetRunManager()->ReinitializeGeometry(); line.

Kind regards,

David