Message: Re: Using density to define geometry Not Logged In (login)

## Re: Using density to define geometry

Forum: Geometry
Re: Using density to define geometry (Steven Walton)
Re: Re: Using density to define geometry (Michael H. Kelsey)
Re: Re: Using density to define geometry (Steven Walton)
Re: Re: Using density to define geometry (Michael H. Kelsey)
Re: Re: Using density to define geometry (Steven Walton)
Date: 03 Aug, 2015
From: Michael H. Kelsey <Michael H. Kelsey>

 ```Steven Walton writes: > Yes, I am trying to vary a box to have constant mass. And I am switching > materials. I want the box to just be changing in thickness and > everything else to be constant. That's a very sensible request, and the G4 units system should handle it. > I am still at a loss here. Because if we look back to what I wrote in > the OP I had > > G4double density = kevlarDensity; // 1.44 * g/cm3 from above > G4double mass = 1. * g; > G4double Box_y, Box_z = 1. * cm; > G4double thickness = mass/(density * Box_y * Box_z); > > So all of these have their correct units. (kevlarDensity was defined in > the DefineMaterials() function to be 1.44*g/cm3) So we are correctly > multiplying and dividing units. Or if I am not, I do not see where. > Because in thickness I essentially have > > G4double thickness = (1.*g)/((1.44*g/cm3) * (1.*cm) * (1.*cm)); > > Which should result in 0.694444 * cm. I think there must be an error somewhere else in your code; perhaps you've not assigned units properly to some other quantity in your computations. I wrote a very simple test program to run exactly your numbers above. Here is the output: Testing G4 internal vs. dimensioned units... density set to 1.44*g/cm3: 8.98777e+18 (internal) 1.44 g/cm3 = 1.44 g/cm3 (best) length 1 cm = 10 (internal) width 1 cm = 10 (internal) mass 1 g = 0.001 kg = 6.24151e+21 (internal) computed thickness 6.94444 mm = 0.694444 cm The values I've marked "internal" are what you get if you dump the G4double without doing any unit division; notice that both density and mass are huge, because we (actually, CLHEP) use MeV as our internal unit for energy, and mass is derived from it (see CLHEP/include/Units/SystemOfUnits.h). Here is the code for my test program. You can see where I assign specific units to each value when it is declared, and I don't use any units explicitly when computing the thickness. I divide out the units (or call G4BestUnit()) when I want to print values that are understandable. #include #include #include int main() { G4cout << "Testing G4 internal vs. dimensioned units..." << G4endl; G4double density = 1.44*g/cm3; G4cout << " density set to 1.44*g/cm3: " << density << " (internal) " << "\n " << density/(g/cm3) << " g/cm3 = " << G4BestUnit(density,"Volumic Mass") << " (best)" << G4endl; G4double length = 1*cm; G4double width = 1*cm; G4double mass = 1*g; G4cout << " length " << G4BestUnit(length,"Length") << " = " << length << " (internal)" << "\n width " << G4BestUnit(width,"Length") << " = " << width << " (internal)" << "\n mass " << G4BestUnit(mass,"Mass") << " = " << mass/kg << " kg" << " = " << mass << " (internal)" << G4endl; G4double thickness = mass/(density*length*width); G4cout << " computed thickness " << G4BestUnit(thickness,"Length") << " = " << thickness/cm << " cm" << G4endl; } ```

1 Re: Using density to define geometry   (Steven Walton - 04 Aug, 2015)  Re: Using density to define geometry   (Mike Kelsey - 04 Aug, 2015)  Re: Using density to define geometry   (Steven Walton - 04 Aug, 2015)  Re: Using density to define geometry   (Michael H. Kelsey - 04 Aug, 2015)  Re: Using density to define geometry   (Steven Walton - 05 Aug, 2015)  Re: Using density to define geometry   (Michael H. Kelsey - 05 Aug, 2015)
 to: "Re: Using density to define geometry"
This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]