Geant4  10.02.p02
G4gsmixt.cc
Go to the documentation of this file.
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: G4gsmixt.cc 67982 2013-03-13 10:36:03Z gcosmo $
28 //
29 // by I.Hrivnacova, 27 Sep 99
30 
31 #include <iomanip>
32 #include <iomanip>
33 
34 #include "globals.hh"
35 #include "G4SystemOfUnits.hh"
36 
37 #include "G3toG4.hh"
38 #include "G3EleTable.hh"
39 #include "G3MatTable.hh"
40 #include "G4Material.hh"
41 #include "G4Isotope.hh"
42 
43 void PG4gsmixt(G4String *tokens)
44 {
45  // fill the parameter containers
46  G3fillParams(tokens,PTgsmixt);
47 
48  // interpret the parameters
49  G4String name = Spar[0].data();
50  G4int imate = Ipar[0];
51  G4int nlmat = Ipar[1];
52  //G4double dens = Rpar[0]*g/cm3;
53  G4double dens = Rpar[0];
54  G4double *a = Rpar + 1;
55  G4double *z = Rpar + 1+std::abs(nlmat);
56  G4double *wmat = Rpar + 1 + 2*std::abs(nlmat);
57 /*
58  for (int i=0; i<std::abs(nlmat); i++){
59  //Rpar[i]=Rpar[i]*g/mole;
60  Rpar[i]=Rpar[i];
61  };
62 */
63  G4gsmixt(imate,name,a,z,dens,nlmat,wmat);
64 }
65 
66 // replaced with G3EleTable
67 // only used G4Elements are created;
68 // !! no checking of given A of the element;
69 //
70 // extern G4Element* CreateElement(G4double zeff, G4double aeff, G4String matName);
71 
72 
74  G4double dens, G4int nlmat, G4double* wmat)
75 {
76  // in Geant3:
77  // After a call with ratios by number (negative number of elements),
78  // the ratio array is changed to the ratio by weight, so all successive
79  // calls with the same array must specify the number of elements as
80  // positive
81  G4int i=0;
82  if (nlmat<0) {
83  // in case of proportions given in atom counts (nlmat<0),
84  // the wmat[i] are converted to weight fractions
85  G4double aMol = 0.;
86  for (i=0; i<std::abs(nlmat); i++) {
87  // total molecular weight
88  aMol += wmat[i]*a[i];
89  }
90  if (aMol == 0.) {
91  G4String text = "G4mixt: Total molecular weight in " + name + " = 0.";
92  G4Exception("G4gsmixt()", "G3toG40016", FatalException, text);
93  return;
94  }
95  for (i=0; i<std::abs(nlmat); i++) {
96  // weight fractions
97  wmat[i] = wmat[i]*a[i]/aMol;
98  }
99  }
100 
101  // create material with given number of components
102  // (elements)
103 
104  G4Material* material
105  = new G4Material(name, dens*g/cm3, std::abs(nlmat));
106  for (i=0; i<std::abs(nlmat); i++) {
107  // add units
108  // G4Element* element = G4Element(z[i], a[i]*g/mole, name);
109  G4Element* element = G3Ele.GetEle(z[i]);
110  material->AddElement(element, wmat[i]);
111  }
112 
113  // add the material to the List
114  G3Mat.put(imate, material);
115 }
116 
117 /*
118 void G4gsmixt(G4int imate, G4String name, G4double a[], G4double z[],
119  G4double dens, G4int nlmat, G4double wmat[]){
120  G4int nmate = std::abs(nlmat);
121  G4String sname = name.strip(G4String::both);
122  G4double theDensity = dens*g/cm3;
123 
124  G4Material* theMixture = new G4Material(name, dens, nmate);
125  G4bool ok=true;
126  for (int i=0; i< nmate; i++){
127  G4Element* theElement = G3Ele.GetEle(z[i]);
128  if (nlmat>0) {
129  G4double fractionmass = wmat[i];
130  ok = ok && std::abs(fractionmass)<=1.;
131  theMixture->AddElement(theElement, fractionmass);
132  } else if (nlmat<0) {
133  G4int natoms = wmat[i];
134  ok = ok && wmat[i] == natoms;
135  theMixture->AddElement(theElement, natoms);
136  } else {
137  ok=false;
138  }
139  }
140  if (ok) {
141  G3Mat.put(imate, theMixture);
142  } else {
143  if (nlmat>0) {
144  G4cerr << "G4gsmixt: for mixture '" << name
145  << "' some |weights|>1 : " << G4endl;
146  for (G4int i=0;i<nlmat; i++) {
147  G4cerr << "Component " << std::setw(3) << i+1 << " fraction: "
148  << std::setw(10) << wmat[i] << G4endl;
149  }
150  } else if (nlmat<0) {
151  G4cerr << "G4gsmixt: for mixture '" << name
152  << "' some #natoms are non-integer: " << G4endl;
153  for (G4int i=0;i<nlmat; i++) {
154  G4cerr << "Component " << std::setw(3) << i+1 << " #atoms "
155  << std::setw(10) << wmat[i] << G4endl;
156  }
157  } else {
158  G4cerr << "G4gsmixt: Number of components for mixture '"
159  << name << "' (" << nlmat << ") not allowed." << G4endl;
160  }
161  }
162 }
163 */
164 
165 
166 
G3G4DLL_API G4double Rpar[1000]
Definition: clparse.cc:67
G4Element * GetEle(G4double Z)
Definition: G3EleTable.cc:52
G4double z
Definition: TRTMaterials.hh:39
G4String name
Definition: TRTMaterials.hh:40
void put(G4int id, G4Material *material)
Definition: G3MatTable.cc:53
G3G4DLL_API G3MatTable G3Mat
Definition: clparse.cc:55
G4double a
Definition: TRTMaterials.hh:39
void G3fillParams(G4String *tokens, const char *ptypes)
Definition: clparse.cc:219
int G4int
Definition: G4Types.hh:78
void G4gsmixt(G4int imate, G4String name, G4double *a, G4double *z, G4double dens, G4int nlmat, G4double *wmat)
Definition: G4gsmixt.cc:73
G3G4DLL_API G3EleTable G3Ele
Definition: clparse.cc:60
G3G4DLL_API G4String Spar[1000]
Definition: clparse.cc:68
static const double cm3
Definition: G4SIunits.hh:120
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G3G4DLL_API G4int Ipar[1000]
Definition: clparse.cc:66
const char * data() const
static const double g
Definition: G4SIunits.hh:180
void PG4gsmixt(G4String *tokens)
Definition: G4gsmixt.cc:43
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:364
double G4double
Definition: G4Types.hh:76
#define PTgsmixt
Definition: G3toG4.hh:64