/cfd-mpc-wecs

A model predictive control (MPC) integrated multiphase immersed boundary (IB) framework for simulating wave energy converters (WECs)

Primary LanguageC++GNU General Public License v3.0GPL-3.0

cfd-mpc-wecs

A model predictive control (MPC) integrated multiphase immersed boundary (IB) framework for simulating wave energy converters (WECs) as described in https://doi.org/10.1016/j.oceaneng.2022.111908

Citing

If you are using MATLAB or CFD codes from this repository in your work, please consider citing the following

@article{khedkar2022model,
  title={{A model predictive control (MPC)-integrated multiphase immersed boundary (IB) framework for simulating wave energy converters (WECs)}},
  author={Khedkar, Kaustubh and Bhalla, Amneet Pal Singh},
  journal={Ocean Engineering},
  volume={260},
  pages={111908},
  year={2022},
  publisher={Elsevier},
  doi = {10.1016/j.oceaneng.2022.111908},
  URL = {https://www.sciencedirect.com/science/article/pii/S0029801822012471}
}

Clone the repository

git clone https://github.com/IBAMR/cfd-mpc-wecs.git

This will clone the default branch main. The main branch does not use any libMesh constructs and hence it is not necesary to build IBAMR with libMesh. The branch with-libmesh-construct uses the libMesh library, which can potentially allow for constructing an arbitrary shaped WEC geometry (e.g., from a CAD geometry). To switch to the other branch do:

git clone https://github.com/IBAMR/cfd-mpc-wecs.git
git checkout with-libmesh-construct

Build PETSc with MATLAB

Refer https://petsc.org/main/docs/manual/matlab/ (See also the Licensing the MATLAB Compute Engine on a cluster section). We used the following configure options when building PETSc

export PETSC_DIR=$PWD
export PETSC_ARCH=linux-opt
./configure \
--CC=/path/to/mpicc \ 
--CXX=/path/to/mpicxx \ 
--FC=/path/to/mpif90  \
--COPTFLAGS=-O3 --CXXOPTFLAGS=-O3 --FOPTFLAGS=-O3 --PETSC_ARCH=linux-opt --with-debugging=0 --download-hypre=1 --with-x=0 --download-fblaslapack=1 \
--with-matlab-dir=/path/to/Matlab_2020b/ --with-matlab-engine=1 --with-matlab-engine-dir=/path/to/Matlab_2020b/extern/engines/

Build IBAMR with PETSc (and other libraries)

Building IBAMR using autotools

cd $HOME/sfw
git clone https://github.com/IBAMR/IBAMR.git IBAMR

mkdir objs-opt
cd objs-opt

../IBAMR/configure \
CFLAGS="-g -O3 -Wall" \
CXXFLAGS="-g -O3 -Wall" \
FCFLAGS="-g -O3 -Wall" \
CC=mpicc \
CXX=mpicxx \
FC=mpif90 \
--with-samrai=$HOME/sfw/SAMRAI/linux-opt \
--with-hdf5=$HOME/sfw/HDF5 \
--with-silo=$HOME/sfw/SILO \ 
--with-boost=$HOME/sfw/boost/1.67.0 \ 
PETSC_DIR=$HOME/sfw/PETSc-MATLAB \
PETSC_ARCH=linux-opt 

make -j56

It is also possible to build IBAMR using CMake (Refer https://ibamr.github.io/building)

Steps to execute the CFD+MPC solver:

  1. Generate BEM_data.mat file: Go to the BEM_data directory. Execute the MATLAB script process_bem_data.m to generate the BEM_data.mat file. The directory also contains the output from the ANSYS AQWA software for the 1:20 scaled cylinder: AQWA_ANALYSIS.AH and AQWA_ANALYSIS.LIS. Some files in the BEM_data directory are obtained from the WEC-Sim or rather BEMIO GitHub https://github.com/WEC-Sim/WEC-Sim. These files are distributed under the WEC-Sim Apache License (Version 2.0) that can be found in the BEM_data directory. Note that we are not using the most updated version of the BEMIO files. The most recent version of the files can be downloaded (as raw files) directly from https://github.com/WEC-Sim/WEC-Sim/tree/master/source/functions/BEMIO. The newer version of the BEMIO scripts may require some API changes to the process_bem_data.m script. A user may need to use the updated BEMIO scripts to parse the outfile files generated by the newer versions of the AQWA software. The AQWA files in BEM_data directory correspond to the 19.2 version.

  2. Input files: The CFD solver requires an input file. Two sample input files are provided in the main directory with the names input3d.cyl for first-order order regular waves and input3d_irregwave.cyl for irregular waves. The input files are set to simulate the AR-enabled CFD cases given in Sec. 9.2 of the paper.

  3. C++ driver code (main.cpp): The BEM data and the MPC parameters are loaded by the load_mpc_paramters.m MATLAB script called within main.cpp. Currently, load_mpc_paramters.m corresponds to regular waves of Sec. 9.2. Similarly, the MATLAB MPC routines contained in the MPC_matlab_code directory are also called within the C++ driver code.

  4. Building and linking the executable: If IBAMR is built using autotools then: (1) Copy Makefile.autotools to a new file named Makefile in the same directory. Modify the IBAMR source and build directory paths at top of the file. (2) Use the command make -j8 main3d to compile the CFD code and link it with IBAMR.

    If IBAMR is built using CMake, then the CMakeLists.txt should be used instead. The CMake project can be configured using the command cmake -DIBAMR_ROOT=/path/to/ibamr-install -S ./ and then built using make -j8 main3d.

    The linking of IBAMR based applications using autotools and CMake are explained here https://ibamr.github.io/linking

  5. Run the simulation: Use the command mpirun -np 128 ./main3d input3d.cyl to run the simulation with 128 processors (number of processors can be adjusted here).

  6. Output data: The following output files are generated by the code

     rbd.curve                : Contains the simulation time, WEC heave displacement, and velocity.
     hydro_force_torque.curve : Contains the simulation time and the hydrodynamic forces acting on the device.
     mpc_control_force.curve  : Contains the simulation time and the control force.

Steps to execute the BEM+MPC solver:

  1. Generate BEM_data.mat file: See step 1 of the above section.

  2. Input file: The BEM code does not require an input file. Instead, the load_mpc_parameters.m script should be modified directly to adjust the MPC paramaters.

  3. Running the simulation: The MATLAB driver script for the BEM solver is vcyl_driving_script.m. Set the solver and wave parameters in this file and run the script.

  4. Output data: Results are saved in BEM_results.mat file. This includes the simulation time, WEC displacement and velocity, wave excitation and control force.