Import Geant4 11.4.0 source tree
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Structs used by G4QSStepper
|
||||
//
|
||||
// Author: Mattias Portnoy (Univ. Buenos Aires), 2024
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline Substep::Substep()
|
||||
{
|
||||
for (G4int i = 1; i < MAX_QSS_ORDER; ++i)
|
||||
{
|
||||
std::fill_n(state_x[i], NUMBER_OF_VARIABLES_QSS, 0.0);
|
||||
std::fill_n(state_q[i], NUMBER_OF_VARIABLES_QSS, 0.0);
|
||||
}
|
||||
std::fill_n(state_x[MAX_QSS_ORDER], NUMBER_OF_VARIABLES_QSS, 0.0);
|
||||
|
||||
std::fill_n(state_tx, NUMBER_OF_VARIABLES_QSS, 0.0);
|
||||
std::fill_n(state_tq, NUMBER_OF_VARIABLES_QSS, 0.0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline Substeps::Substeps()
|
||||
{
|
||||
_substeps = static_cast<Substep *>(malloc((_arrlength) * sizeof(Substep)));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline Substeps::~Substeps()
|
||||
{
|
||||
free(_substeps);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Mimics the functionality of GNU method reallocarray
|
||||
inline void* Substeps::safe_reallocarray(void* ptr, size_t numMembers, size_t size)
|
||||
{
|
||||
if (size != 0 && numMembers > std::numeric_limits<size_t>::max() / size)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return realloc(ptr, numMembers * size);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline void Substeps::resize()
|
||||
{
|
||||
_arrlength = std::fmax(_arrlength*2, 1500);
|
||||
_substeps = static_cast<Substep *>(safe_reallocarray(_substeps, _arrlength, sizeof(Substep)));
|
||||
if( _substeps == nullptr )
|
||||
{
|
||||
G4ExceptionDescription ermsg;
|
||||
ermsg << "QSS2: Size of state exceed available memory : number of elemets = " << _arrlength
|
||||
<< " size of each element= " << sizeof(Substep) << G4endl;
|
||||
G4Exception( "G4QSSubstepStruct::resize", "GeomField0008", FatalException, ermsg );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline Substep* Substeps::create_substep()
|
||||
{
|
||||
current_substep_index++;
|
||||
|
||||
if (unlikely( current_substep_index >= _arrlength ))
|
||||
{
|
||||
resize();
|
||||
}
|
||||
return &(_substeps[current_substep_index]);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline void Substeps::save_substep(Substep* substep)
|
||||
{
|
||||
memcpy(create_substep(), substep, sizeof(Substep));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline void Substeps::reset()
|
||||
{
|
||||
current_substep_index = -1;
|
||||
}
|
||||
Reference in New Issue
Block a user