项目作者: LLNL

项目描述 :
A tool for filling C/C++ or Fortran data structures from Lua input tables
高级语言: Lua
项目地址: git://github.com/LLNL/irep.git
创建时间: 2016-09-06T19:03:42Z
项目社区:https://github.com/LLNL/irep

开源协议:MIT License

下载


IREP

linux builds
Documentation Status

IREP is a tool that enables mixed-language simulation codes to use a
common, Lua-based format for their input decks. Essentially, the input
format is a set of tables — Lua’s
one (and only?) data structure. IREP is an intermediate representation
that is used to generate plain-old-data (POD) structures in C, C++,
Fortran, and Lua.

Documentation

There are some high-level docs here to get you started, but you can find
more in the full IREP Documentation.

Installation

To build IREP, run make in the root directory. This will create
libIR.a. IREP does not (yet) have a proper installation target.

Building with IREP

IREP has integration for both CMake and gmake-based builds. You can find
more about how to intgrate IREP into your project here:

You can build and run the examples by running running make test in the
root of this repository.

Basics

To use IREP, you can write a header, like this one for defining a
very simple structured mesh. Let’s call it wkt_mesh.h:

  1. #ifndef wkt_mesh_h
  2. #define wkt_mesh_h
  3. #include "ir_start.h"
  4. Beg_struct(irt_box)
  5. ir_int(nx, 1) Doc(( Number of grid cells in 1st dimension ))
  6. ir_int(ny, 1) Doc(( Number of grid cells in 2nd dimension ))
  7. ir_int(nz, 1) Doc(( Number of grid cells in 3rd dimension ))
  8. ir_dbl(xmin, 0.0) Doc(( Location of left-most cell face ))
  9. ir_dbl(xmax, 1.0) Doc(( Location of right-most cell face ))
  10. ir_dbl(ymin, 0.0) Doc(( Location of nearest cell face ))
  11. ir_dbl(ymax, 1.0) Doc(( Location of farthest cell face ))
  12. ir_dbl(zmin, 0.0) Doc(( Location of lowest cell face ))
  13. ir_dbl(zmax, 1.0) Doc(( Location of highest cell face ))
  14. End_struct(irt_box)
  15. Beg_struct(irt_mesh)
  16. ir_str(file, FILENAMESIZE, 'none') Doc(( Name of mesh ))
  17. ir_int(refinement_level, 0)
  18. ir_log(amr, false) Doc(( Use amr? ))
  19. Structure(irt_box,box)
  20. End_struct(irt_mesh)
  21. // Declare the structure
  22. ir_wkt(irt_mesh, mesh)
  23. #include "ir_end.h"
  24. #endif // wkt_mesh_h

In IREP, headers like this are called “Well Known Tables”, or “WKTs”. WKT
headers are includable directly into C and C++ code, and you can refer to
elements of the defined structures like this:

  1. #include "wkt_mesh.h"
  2. void do_something() {
  3. double xrange = mesh.box.xmax - mesh.xmin;
  4. double yrange = mesh.box.ymax - mesh.ymin;
  5. double zrange = mesh.box.zmax - mesh.zmin;
  6. }

IREP can also be used to generate Fortran modules and Lua code for WKTs,
and you can refer to their elements in a similarly direct way in those
languages, e.g.:

  1. mesh.box.xmax // C, C++
  2. mesh.box.xmax -- Lua C
  3. mesh.box.xmax ! Fortran

Using IREP for input decks

IREP’s main use is to allow multi-language (usually C, C++, and Fortran)
integrated codes to read Lua input files (“input decks” for those of use
who’ve been in the simulation field for a while). With the wkt_mesh.h
we’ve seen so far, we could write an input file like this:

  1. mesh = {
  2. file = 'my_mesh',
  3. refinement_level = 1,
  4. amr = true,
  5. box = {
  6. nx = 100,
  7. ny = 100,
  8. nz = 100,
  9. },
  10. }

Note that the xmin, xmax, ymin, ymax, zmin, and zmax fields
in box are not defined in the input, but they will take on the default
values from the wkt_mesh.h header.

If you want to read this input file from C, you could write some code
like this:

  1. #include "ir_extern.h"
  2. #include "wkt_mesh.h"
  3. #include "lua.h"
  4. int main(int argc, char **argv) {
  5. // set up lua and load some lua code
  6. lua_State *L = luaL_newstate();
  7. luaL_openlibs(L);
  8. luaL_loadfile(L, "mesh_example.lua");
  9. ir_read(L, "mesh");
  10. printf("mesh.box.xmax = %d\n", mesh.box.xmax);
  11. printf("mesh.box.ymax = %d\n", mesh.box.ymax);
  12. printf("mesh.box.zmax = %d\n", mesh.box.zmax);

This sets up an embedded Lua interpreter, loads the Lua input file, and
then reads WKT values out of the native Lua tables and into a global
mesh structure that can be accessed from C.

Authors

IREP was created by Lee Busby, busby1@llnl.gov.

Thanks also to irep‘s
contributors!.

License

IREP is distributed under the terms of the MIT license. Copyrights in the
IREP project are retained by contributors. No copyright assignment is
required to contribute to IREP. All new contributions must be made under
the MIT license.

See LICENSE and
NOTICE for details.

SPDX-License-Identifier: MIT

LLNL-CODE-702338