Skip to content

Commit

Permalink
Merge pull request #924 from svalinn/fix-geant4-build
Browse files Browse the repository at this point in the history
Geant4 v11 update
  • Loading branch information
pshriwise authored Dec 7, 2023
2 parents 1186825 + b1e0091 commit c82b52d
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/actions/upstream-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
geant_version:
description: Version of Geant4
required: false
default: 10.7.4
default: 11.1.2
ubuntu_version:
description: Underlying OS version
required: false
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
]
geant_version : [
10.7.4,
11.1.2
]

name: Installing Dependencies, Building DAGMC and running tests
Expand Down Expand Up @@ -94,6 +95,7 @@ jobs:
]
geant_version : [
10.7.4,
11.1.2
]

name: Pushing final images
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_upstream_test_geant4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
uses: ./.github/actions/upstream-test
with:
token: ${{ secrets.GITHUB_TOKEN }}
geant_version: 11.1.1
geant_version: 11.1.2

2 changes: 1 addition & 1 deletion .github/workflows/mac_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Initial setup
shell: bash -l {0}
run: |
brew install eigen gcc@6 hdf5
brew install eigen hdf5
- name: Environment Variables
shell: bash -l {0}
Expand Down
2 changes: 1 addition & 1 deletion CI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Global ARGS set before the first build stage are accessable by all build stages
ARG EMBREE_BRANCH='v3.6.1'
ARG geant4_version=10.7.4
ARG geant4_version=11.1.2
ARG UBUNTU_VERSION=20.04
ARG MOAB_BRANCH=5.3.0
ARG double_down=OFF
Expand Down
21 changes: 11 additions & 10 deletions cmake/FindGeant4.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Find Geant4 cmake config file
set(Geant4_SEARCH_DIRS)
# Is this line necessary?
set(PACKAGE_FIND_VERSION ${Geant4_FIND_VERSION})
file(GLOB Geant4_SEARCH_DIRS "${GEANT4_DIR}/lib*/Geant4-*")

file(GLOB Geant4_SEARCH_DIRS "${GEANT4_DIR}/lib*/Geant4*")
string(REPLACE "\n" ";" Geant4_SEARCH_DIRS ${Geant4_SEARCH_DIRS})
list(APPEND Geant4_SEARCH_DIRS "${GEANT4_DIR}/lib/cmake/Geant4")

find_path(Geant4_CMAKE_CONFIG
NAMES Geant4Config.cmake
PATHS ${Geant4_SEARCH_DIRS}
NO_DEFAULT_PATH
)

find_path(Geant4_CMAKE_CONFIG_VERSION
NAMES Geant4ConfigVersion.cmake
PATHS ${Geant4_SEARCH_DIRS}
PATHS ${Geant4_CMAKE_CONFIG}
NO_DEFAULT_PATH
)

Expand All @@ -21,11 +27,6 @@ else ()
message(FATAL_ERROR "Could not find Geant4")
endif ()

find_path(Geant4_CMAKE_CONFIG
NAMES Geant4Config.cmake
PATHS ${Geant4_SEARCH_DIRS}
NO_DEFAULT_PATH
)
if (Geant4_CMAKE_CONFIG)
set(Geant4_CMAKE_CONFIG ${Geant4_CMAKE_CONFIG}/Geant4Config.cmake)
message(STATUS "Geant4_CMAKE_CONFIG: ${Geant4_CMAKE_CONFIG}")
Expand Down Expand Up @@ -58,7 +59,7 @@ include(${Geant4_USE_FILE})
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS_SAVE})

message(STATUS "Geant4 version: ${Geant4_VERSION}")
message(STATUS "Geant4 version required: ${PACKAGE_FIND_VERSION}")
message(STATUS "Geant4 version required: ${Geant4_FIND_VERSION}")
message(STATUS "Geant4 version compatible: ${PACKAGE_VERSION_COMPATIBLE}")
message(STATUS "Geant4 version exact: ${PACKAGE_VERSION_EXACT}")
message(STATUS "Geant4_INCLUDE_DIRS: ${Geant4_INCLUDE_DIRS}")
Expand Down
2 changes: 1 addition & 1 deletion doc/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Next version
* Adding const identifier to cross-reference methods (#906)

**Fixed:**
* Patch to compile with Geant4 10.6 (#803)
* Patch to compile with Geant4 11.x (#803 #907)
* Patched cmake-search paths for double-down and MOAB (#878)
* Patch to compile with gcc-13 (#882)
* Tweak conda environment for Windows build to avoid conflicting gtest headers (#888)
Expand Down
6 changes: 5 additions & 1 deletion src/geant4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ message("")

find_package(Geant4 10.4.2 REQUIRED)

if ( Geant4_VERSION GREATER_EQUAL 10.6 )
if ( Geant4_VERSION GREATER_EQUAL 11.0 )
message(STATUS "Configuring DAGMC for Geant4 version >= 11.0")
add_compile_definitions(GEANT4_GT_10_6=1)
add_compile_definitions(GEANT4_GT_11=1)
elseif( Geant4_VERSION GREATER_EQUAL 10.6 )
message(STATUS "Configuring DAGMC for Geant4 version >= 10.6")
add_compile_definitions(GEANT4_GT_10_6=1)
endif()
Expand Down
4 changes: 4 additions & 0 deletions src/geant4/app/include/ExN01Analysis.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifndef ExN01Analysis_h
#define ExN01Analysis_h 1

#ifdef GEANT4_GT_11
#include "G4AnalysisManager.hh"
#else
#include "g4root.hh"
#endif

#endif
5 changes: 4 additions & 1 deletion src/geant4/app/src/ExN01DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ G4VPhysicalVolume* ExN01DetectorConstruction::Construct() {
// load the material from the UW^2 library
std::map<std::string, G4Material*> material_lib;
material_lib = load_uwuw_materials(workflow_data);

#ifdef GEANT4_GT_11
G4VisAttributes* invis = new G4VisAttributes(G4VisAttributes::GetInvisible());
#else
G4VisAttributes* invis = new G4VisAttributes(G4VisAttributes::Invisible);
#endif

//------------------------------------------------------ volumes
// -- World Volume in which we place other volumes
Expand Down
90 changes: 17 additions & 73 deletions src/geant4/generate_geant4
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from optparse import OptionParser
import os,errno
from itaps import iMesh,iBase
import sys
# for material handling
from pyne.material import Material,MaterialLibrary
from pyne.material import Material
from pyne.material_library import MaterialLibrary
from pyne.nucname import name, znum, anum, id, alara
from pyne.data import atomic_mass
from pyne import dagmc

# for coloring the volumes
import colorsys
Expand Down Expand Up @@ -69,10 +71,9 @@ def parse_arguments():
if options.dag_file:
try:
fh = open(options.dag_file, "r")
except IOError:
print "Error: can\'t find DAG file"
else:
fh.close()
except IOError:
print("Error: can't find DAG file: '{} ".format(options.dag_file))
if not options.directory:
options.directory = os.getcwd()
else:
Expand All @@ -90,69 +91,17 @@ dag_filename : h5m filename
Returns
---------
dag_volnames : dictionary of volume names
dag_vol_names : list of volume names
dag_materials : dictionary of material assignments
"""

def _get_dag_info(dag_filename):
dag_vol_names = [] # list of dag volume names (Cubit id)
dag_materials = {} # list of material assignments from group

# create imesh instance
dag_geom = iMesh.Mesh()
# load the file
dag_geom.load(dag_filename)

# get all entities
ents = dag_geom.getEntities()

# create a mesh set
mesh_set = dag_geom.getEntSets()
# list of volume ent handles

mat_list = []
# get all geom_dimension ents
geom_list = []

cat_list = []

vol_tag = dag_geom.getTagHandle('GEOM_DIMENSION')

name_tag = dag_geom.getTagHandle('GLOBAL_ID')

mat_tag = dag_geom.getTagHandle('NAME')
dag_materials = dagmc.cell_material_assignments(dag_filename)

cat_tag = dag_geom.getTagHandle('CATEGORY')
dag_vol_names = list(dag_materials.keys())

# get the list we need
for i in mesh_set:
tags = dag_geom.getAllTags(i)
for tag in tags:
if tag == vol_tag:
geom_list.append(i)
if tag == mat_tag:
mat_list.append(i)
if tag == cat_tag:
cat_list.append(i)

# for the 3d entities
for entity in geom_list:
if vol_tag[entity] == 3:
dag_vol_names.append(str(name_tag[entity]))


# loop over all the volumes
for entity in geom_list:
# loop over the material sets
for meshset in mat_list:
# if volume in set
if meshset.contains(entity):
mat_name = mat_tag[meshset]
volume_name = name_tag[entity]
dag_materials[volume_name]="".join( chr( val ) for val in mat_name )


return dag_vol_names,dag_materials
return dag_vol_names, dag_materials

"""
Function to pull out the pyne materials from the h5m file
Expand All @@ -179,8 +128,8 @@ def _get_material_info(dag_file):
mat_lib.from_hdf5(dag_file)
materials = mat_lib.keys()
except:
print "!! There are no materials in the h5m file !!"
print " Assuming all volumes contain vacuum "
print("There are no materials in the h5m file.\n"
"Assuming all volumes contain vacuum")
materials = {}

nuclides = set()
Expand Down Expand Up @@ -534,7 +483,7 @@ dag_volume_names : list or dictionary of volume names
def _setup_dagspecific_headers(dag_volume_names, tallies_needed):

if not dag_volume_names:
print "dag volume names not assigned", sys.exc_info()[0]
print("DAGMC volume names are not assigned", sys.exc_info()[0])
raise

headers = {}
Expand Down Expand Up @@ -1679,12 +1628,11 @@ def _write_files(path, dictionary_files):
for key in dictionary_files:
try:
fh = open(path+'/'+key, "w")
except IOError:
print "Error: "+file+" file exists"
else:
for line in dictionary_files[key]:
fh.write(line)
fh.close
except IOError:
print("Error: '{}' file exists".format(key))


"""
Expand All @@ -1707,10 +1655,6 @@ def _create_directory_structure(directory):
_mkdir_p(directory+'/src')
return

def _dagmc_volume_material(dagmc_h5m, index):

return material_name

"""
Function from http://stackoverflow.com/questions
/600268/mkdir-p-functionality-in-python, to create
Expand All @@ -1724,7 +1668,7 @@ def _mkdir_p(path):
try:
os.makedirs(path)
except OSError:
print "Error: can\'t create directory, "+path
print("Error: can't create directory '{}' ".format(path))
raise


Expand Down

0 comments on commit c82b52d

Please sign in to comment.