Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/csdms/bmi-example-cxx
An example of wrapping a model written in C++ with a BMI
https://github.com/csdms/bmi-example-cxx
bmi csdms cxx
Last synced: 3 days ago
JSON representation
An example of wrapping a model written in C++ with a BMI
- Host: GitHub
- URL: https://github.com/csdms/bmi-example-cxx
- Owner: csdms
- License: mit
- Created: 2019-11-07T23:57:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-02T21:04:55.000Z (about 1 year ago)
- Last Synced: 2024-01-26T00:38:05.313Z (12 months ago)
- Topics: bmi, csdms, cxx
- Language: C++
- Homepage: https://bmi.readthedocs.io
- Size: 65.4 KB
- Stars: 2
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Basic Model Interface](https://img.shields.io/badge/CSDMS-Basic%20Model%20Interface-green.svg)](https://bmi.readthedocs.io/)
[![Build/Test](https://github.com/csdms/bmi-example-cxx/actions/workflows/test.yml/badge.svg)](https://github.com/csdms/bmi-example-cxx/actions/workflows/test.yml)# bmi-example-cxx
An example of implementing the
[C++ bindings](https://github.com/csdms/bmi-cxx)
for the CSDMS
[Basic Model Interface](https://bmi.readthedocs.io) (BMI).## Overview
This is an example of implementing a BMI for a simple model
that solves the diffusion equation
on a uniform rectangular plate
with Dirichlet boundary conditions.
The model and its BMI are written in C++.
Tests of the BMI are provided.This repository is organized with the following directories:
- heat
- Holds the model, the BMI for the model, and a sample main program
- testing
- Tests that cover the BMI of the model
## Build/Install
This example can be built on Linux, macOS, and Windows.
**Prerequisites:**
* A C++ compiler
* CMake
* pkg-config
* The C++ BMI bindings. Follow the build and install directions
given in the
[README](https://github.com/csdms/bmi-cxx/blob/master/README.md)
in that repository. You can choose to install them from source or
through a conda binary.
### Linux and macOS
To build and install this example from source with cmake,
using the current C++ BMI version, run
mkdir _build && cd _build
export PKG_CONFIG_PATH= # optional: only needed for non-standard install location
cmake .. -DCMAKE_INSTALL_PREFIX=
make
make install
where `` is the base directory
in which the C++ BMI bindings have been installed
(`/usr/local` is the default).
When installing into a conda environment,
use the `$CONDA_PREFIX` environment variable.
The installation will look like
(on macOS, using v2.0 of the BMI specification):
```bash
.
|-- bin
| `-- run_bmiheatcxx
|-- include
| |-- bmi.hxx
| |-- heat.hxx
| `-- bmi_heat.hxx
`-- lib
|-- libbmiheatcxx.dylib
|-- libheatcxx.dylib
`-- pkgconfig
|-- bmicxx.pc
|-- heatcxx.pc
`-- bmiheatcxx.pc
4 directories, 9 files
```
From the build directory,
run unit tests on the sample implementation with
ctest
### Windows
An additional prerequisite is needed for Windows:
* Microsoft Visual Studio 2017 or Microsoft Build Tools for Visual Studio 2017
To configure this example from source with cmake
using the current C++ BMI version,
run the following in a [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)
mkdir _build && cd _build
set "PKG_CONFIG_PATH=" &:: optional: only needed for non-standard install location
cmake .. ^
-G "NMake Makefiles" ^
-DCMAKE_INSTALL_PREFIX= ^
-DCMAKE_BUILD_TYPE=Release
where `` is the base directory
in which the C++ BMI bindings have been installed.
The default is `"C:\Program Files (x86)"`.
Note that quotes and an absolute path are needed.
When using a conda environment, use `"%CONDA_PREFIX%\Library"`.
Then, to build and install:
cmake --build . --target install --config Release
From the build directory,
run unit tests on the sample implementation with
ctest
## Use
Run the heat model through its BMI with the `run_bmiheatcxx` program,
which takes a model configuration file
(see the [testing](./testing) directory for a sample)
as a required parameter.
If `run_bmiheatcxx` is in your path, run it with
run_bmiheatcxx config.txt
Output from the model is written to the file **bmiheatcxx.out**
in the current directory.