File: OpmGrid.cmake

package info (click to toggle)
opm-common 2022.10%2Bds-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 78,468 kB
  • sloc: cpp: 164,554; python: 2,872; sh: 216; xml: 174; ansic: 149; pascal: 136; makefile: 12
file content (81 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# - Recreate grid selection macros from DUNE
#
# If anyone requires Dune::GridSelector::GridType, they must call this
# macro in *their* project, to add this information to config.h. (In
# the autotools version, dunecontrol will automatically include m4
# scripts that does this).
#
# Example:
#	opm_cornerpoint_grid (${CONFIG_H})

include (CMakeParseArguments)
function (opm_grid_type)
  cmake_parse_arguments (a "" "FILENAME;SYMBOL;TYPE;CONDITION" "HEADERS" ${ARGN})

  # write prelude of a condition to use this particular grid, an inclusion guard,
  # and checks to see if the number of dimensions fits for this type of grid
  file (APPEND ${a_FILENAME}
"/* add GRIDTYPE typedef for grid implementation ${a_TYPE}:
    defining ${a_SYMBOL} during compilation typedefs this grid implementation as GridType
    in namespace Dune::GridSelector;
    also integer constants dimgrid and dimworld are set in this namespace.
    The required headers for this grid implementation are also included.
  */
#if defined ${a_SYMBOL} && ! defined USED_${a_SYMBOL}_GRIDTYPE
  /* someone else has already defined a gridtype */
  #if HAVE_GRIDTYPE
    #error \"Ambigious definition of GRIDTYPE\"
  #endif

  #ifndef WORLDDIM
    #define WORLDDIM GRIDDIM
  #endif
  #if not (WORLDDIM >= GRIDDIM)
    #error \"WORLDDIM < GRIDDIM does not make sense.\"
  #endif

  #if ! (${a_CONDITION})
    #error \"Preprocessor assertion ${a_CONDITION} failed.\"
  #endif

")

  # write headers which are capable of defining the type. this should
  # really just have consisted of a forward declaration, but the damage
  # is done: clients expect to just pull in config.h and have the
  # proper type available.
  foreach (header IN LISTS a_HEADERS)
	file (APPEND ${a_FILENAME}
	  "#include <${header}>\n"
	  )
  endforeach (header)

  # main part which does the typedef and then a postlude which marks
  # the grid as "taken" and make sure that no one else does the same
  file (APPEND ${a_FILENAME}
"
  namespace Dune {
    namespace GridSelector {
      const int dimgrid = GRIDDIM;
      const int worldgrid = WORLDDIM;
      typedef ${a_TYPE} GridType;
    }
  }

  #define HAVE_GRIDTYPE 1
  #define USED_${a_SYMBOL}_GRIDTYPE 1
#endif
")
  
endfunction (opm_grid_type)

# write the grid type for opm-grid
function (opm_cornerpoint_grid config_h)
  opm_grid_type (
	FILENAME ${CONFIG_H}
	SYMBOL CPGRID
	HEADERS "dune/grid/CpGrid.hpp" "dune/grid/cpgrid/dgfparser.hh"
	TYPE Dune::CpGrid
	CONDITION "(GRIDDIM == 3) && (WORLDDIM == 3)"
	)
endfunction (opm_cornerpoint_grid config_h)