source: trunk/source/persistency/ascii/src/G4tgbMaterialMixtureByVolume.cc@ 1127

Last change on this file since 1127 was 1035, checked in by garnier, 17 years ago

dossiers oublies

File size: 5.8 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4tgbMaterialMixtureByVolume.cc,v 1.8 2008/12/18 12:59:32 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31// class G4tgbMaterialMixtureByVolume
32
33// History:
34// - Created. P.Arce, CIEMAT (November 2007)
35// -------------------------------------------------------------------------
36
37#include "G4tgbMaterialMixtureByVolume.hh"
38#include "G4tgbMaterial.hh"
39#include "G4tgbMaterialMgr.hh"
40#include "G4tgrMessenger.hh"
41
42// -------------------------------------------------------------------------
43G4tgbMaterialMixtureByVolume::G4tgbMaterialMixtureByVolume()
44{
45}
46
47
48// -------------------------------------------------------------------------
49G4tgbMaterialMixtureByVolume::~G4tgbMaterialMixtureByVolume()
50{
51}
52
53
54// -------------------------------------------------------------------------
55G4tgbMaterialMixtureByVolume::G4tgbMaterialMixtureByVolume( G4tgrMaterial* hg )
56{
57 theTgrMate = hg;
58}
59
60
61// -------------------------------------------------------------------------
62G4Material* G4tgbMaterialMixtureByVolume::BuildG4Material()
63{
64
65 //----- construct new G4Material with components materials (a mixture)
66 G4Material* mate = new G4Material( theTgrMate->GetName(),
67 theTgrMate->GetDensity(),
68 theTgrMate->GetNumberOfComponents(),
69 kStateUndefined, STP_Temperature );
70#ifdef G4VERBOSE
71 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
72 {
73 G4cout << " G4tgbMaterialMixtureByVolume::buildG4Material() -"
74 << " Constructing new G4Material:"
75 << " " << theTgrMate->GetName()
76 << " " << theTgrMate->GetDensity()/g*cm3 << G4endl;
77 }
78#endif
79
80 //----- Transform fractions by volume to fractions by weight
81 TransformToFractionsByWeight();
82
83 //----- Add components
84 G4Material* compMate = 0;
85 G4tgbMaterialMgr* mf = G4tgbMaterialMgr::GetInstance();
86 for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++)
87 {
88 // Look if this component is a material
89 compMate = mf->FindOrBuildG4Material( GetComponent(ii) );
90 if( compMate != 0 )
91 {
92 // If it is a material add it by weight fraction
93 mate->AddMaterial( compMate, theFractionsByWeight[ii] );
94 }
95 else
96 {
97 G4String ErrMessage = "Component " + GetComponent(ii)
98 + " of material " + theTgrMate->GetName()
99 + "\n" + "is not an element nor a material !";
100 G4Exception("G4tgbMaterialMixtureByVolume::BuildG4Material()",
101 "InvalidSetup", FatalException, ErrMessage);
102 }
103 }
104
105#ifdef G4VERBOSE
106 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
107 {
108 G4cout << " Constructing new G4Material by volume: " << *mate << G4endl;
109 }
110#endif
111
112 return mate;
113}
114
115
116// -------------------------------------------------------------------------
117void G4tgbMaterialMixtureByVolume::TransformToFractionsByWeight()
118{
119 G4tgbMaterialMgr* mf = G4tgbMaterialMgr::GetInstance();
120 G4Material* compMate = 0;
121 G4double totalfd = 0.;
122 for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++ )
123 {
124 compMate = mf->FindOrBuildG4Material( GetComponent(ii) );
125 if( compMate != 0 )
126 {
127 // If it is a material add it by weight fraction
128 theFractionsByWeight.push_back( GetFraction(ii)*compMate->GetDensity() );
129 totalfd += theFractionsByWeight[ii];
130 }
131 else
132 {
133 G4String ErrMessage = "Component " + GetComponent(ii)
134 + " of material " + theTgrMate->GetName()
135 + "\n" + "is not a material !";
136 G4Exception("G4tgbMaterialMixtureByVolume::BuildG4Material()",
137 "InvalidSetup", FatalException, ErrMessage);
138 }
139 }
140 for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++ )
141 {
142 theFractionsByWeight[ii] /= totalfd;
143#ifdef G4VERBOSE
144 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
145 {
146 G4cout << " G4tgbMaterialMixtureByVolume::TransformToFractionsByWeight()"
147 << " Component " << ii << " : "
148 << mf->FindOrBuildG4Material( GetComponent(ii) )->GetName()
149 << " FractionByVolume= " << GetFraction(ii)
150 << " FractionByWeight= " << theFractionsByWeight[ii]
151 << G4endl;
152 }
153#endif
154 }
155}
Note: See TracBrowser for help on using the repository browser.