G4tgbMaterialMixtureByVolume.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4tgbMaterialMixtureByVolume.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgbMaterialMixtureByVolume
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgbMaterialMixtureByVolume.hh"
00037 
00038 #include "G4SystemOfUnits.hh"
00039 #include "G4tgbMaterial.hh"
00040 #include "G4tgbMaterialMgr.hh"
00041 #include "G4tgrMessenger.hh"
00042 
00043 // -------------------------------------------------------------------------
00044 G4tgbMaterialMixtureByVolume::G4tgbMaterialMixtureByVolume()
00045 {
00046 }
00047 
00048 
00049 // -------------------------------------------------------------------------
00050 G4tgbMaterialMixtureByVolume::~G4tgbMaterialMixtureByVolume()
00051 {
00052 }
00053 
00054 
00055 // -------------------------------------------------------------------------
00056 G4tgbMaterialMixtureByVolume::G4tgbMaterialMixtureByVolume( G4tgrMaterial* hg )
00057 {
00058   theTgrMate = hg;
00059 }
00060 
00061 
00062 // -------------------------------------------------------------------------
00063 G4Material* G4tgbMaterialMixtureByVolume::BuildG4Material()
00064 {
00065  
00066   //----- construct new G4Material with components materials (a mixture)
00067   G4Material* mate = new G4Material( theTgrMate->GetName(),
00068                                      theTgrMate->GetDensity(),
00069                                      theTgrMate->GetNumberOfComponents(),
00070                                      theTgrMate->GetState(),
00071                                      theTgrMate->GetTemperature(),
00072                                      theTgrMate->GetPressure() );
00073 #ifdef G4VERBOSE
00074   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00075   {
00076     G4cout << " G4tgbMaterialMixtureByVolume::buildG4Material() -"
00077            << " Constructing new G4Material:"
00078            << " " << theTgrMate->GetName() 
00079            << " " << theTgrMate->GetDensity()/g*cm3
00080            << " " << theTgrMate->GetNumberOfComponents()
00081            << " " << theTgrMate->GetState()
00082            << " " << theTgrMate->GetTemperature()
00083            << " " << theTgrMate->GetPressure() << G4endl;
00084   }
00085 #endif
00086  
00087   //----- Transform fractions by volume to fractions by weight
00088   TransformToFractionsByWeight();
00089 
00090   //----- Add components
00091   G4Material* compMate = 0;
00092   G4tgbMaterialMgr* mf = G4tgbMaterialMgr::GetInstance();
00093   for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++)
00094   {
00095     // Look if this component is a material
00096     compMate = mf->FindOrBuildG4Material( GetComponent(ii) );
00097     if( compMate != 0 )
00098     { 
00099       // If it is a material add it by weight fraction 
00100       mate->AddMaterial( compMate, theFractionsByWeight[ii] );
00101     }
00102     else
00103     {
00104       G4String ErrMessage = "Component " + GetComponent(ii)
00105                           + " of material " + theTgrMate->GetName()
00106                           + "\n" + "is not an element nor a material !";
00107       G4Exception("G4tgbMaterialMixtureByVolume::BuildG4Material()",
00108                   "InvalidSetup", FatalException, ErrMessage);
00109     }
00110   } 
00111 
00112 #ifdef G4VERBOSE
00113   if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00114   {
00115     G4cout << " Constructing new G4Material by volume: " << *mate << G4endl; 
00116   }
00117 #endif      
00118 
00119   return mate;
00120 }
00121 
00122 
00123 // -------------------------------------------------------------------------
00124 void G4tgbMaterialMixtureByVolume::TransformToFractionsByWeight() 
00125 { 
00126   G4tgbMaterialMgr* mf = G4tgbMaterialMgr::GetInstance();
00127   G4Material* compMate = 0;
00128   G4double totalfd = 0.;
00129   for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++ )
00130   {
00131     compMate = mf->FindOrBuildG4Material( GetComponent(ii) );
00132     if( compMate != 0 )
00133     {
00134       // If it is a material add it by weight fraction 
00135       theFractionsByWeight.push_back( GetFraction(ii)*compMate->GetDensity() );
00136       totalfd += theFractionsByWeight[ii];
00137     }
00138     else
00139     {
00140       G4String ErrMessage = "Component " + GetComponent(ii)
00141                           + " of material " + theTgrMate->GetName()
00142                           + "\n" + "is not a material !";
00143       G4Exception("G4tgbMaterialMixtureByVolume::BuildG4Material()",
00144                   "InvalidSetup", FatalException, ErrMessage);
00145     }   
00146   }
00147   for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++ )
00148   {
00149     theFractionsByWeight[ii] /= totalfd;
00150 #ifdef G4VERBOSE
00151     if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00152     {
00153       G4cout << " G4tgbMaterialMixtureByVolume::TransformToFractionsByWeight()"
00154              << " Component " << ii  << " : "
00155              << mf->FindOrBuildG4Material( GetComponent(ii) )->GetName()
00156              << " FractionByVolume= " << GetFraction(ii)
00157              << " FractionByWeight= " << theFractionsByWeight[ii] 
00158              << G4endl;
00159     }
00160 #endif
00161   }
00162 }

Generated on Mon May 27 17:49:58 2013 for Geant4 by  doxygen 1.4.7