Skip to content

Commit

Permalink
Merge pull request #9 from Bruno02468/main
Browse files Browse the repository at this point in the history
MYSTRAN 15.0 Update
  • Loading branch information
MYSTRANsolver committed Dec 19, 2023
2 parents 5b6fe96 + d31a1a6 commit d909724
Show file tree
Hide file tree
Showing 55 changed files with 631 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Configure CMake "Unix Makefiles" .
run: |
cmake "Unix Makefiles" .
cmake -G "Unix Makefiles" .
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
#run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ f2c

# IDE stuff
.vscode
.cmake
build.ninja
.ninja*

# autogenerated .mod files
*.mod

# what follows is github's recommendation for CMake projects
CMakeLists.txt.user
Expand Down
4 changes: 3 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[submodule "superlu"]
path = superlu
url = https://github.com/xiaoyeli/superlu
ignore = dirty
ignore = all
update = checkout
branch = master
154 changes: 112 additions & 42 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,104 @@
# Building MYSTRAN with CMake
# Building MYSTRAN from source

###### Last updated 2022-09-12.
###### Last updated 2023-12-18.

## Setting up a build environment

In order to build (compile) MYSTRAN using CMake, you first have to set up a proper build environment (i.e. toolchain and required programs/libraries).
In order to build (compile) MYSTRAN using CMake, you first have to set up a
proper build environment (i.e. toolchain and required programs/libraries).

You can skip this part if you've done it already (or if you really know what you're doing).
You can skip this part if you've done it already (or if you really know what
you're doing).

### Steps for Windows (x86_64)

First, download and install MSYS2 from the [official site](https://www.msys2.org/).
First, download and install MSYS2 from the
[official site](https://www.msys2.org/).

Open the MSYS2 terminal and run the following commands:

1. **`pacman -Syu`**
This updates repository information and installed packages.
2. **`pacman -S mingw-w64-x86_64-gcc-fortran mingw-w64-x86_64-cmake mingw-w64-x86_64-make git`**
This installs the required compilers (the GNU C and Fortran compilers), CMake itself, and `git` (optional, you can omit it and download the repository .zip yourself)
3. **`export PATH="/mingw64/bin:$PATH"`**
This makes the MinGW toolchain programs (such as `make` and the compilers) visible so CMake can find them more easily. Note that this command's effects are lost when you reopen the terminal, so you might want to append it to your `~/.bashrc` to save time.
This updates repository information and installed packages, and might require
you close and reopen MSYS2 terminals.
1. **`pacman -S mingw-w64-x86_64-gcc-fortran mingw-w64-x86_64-cmake mingw-w64-x86_64-make git`**
This installs the required compilers (the GNU C and Fortran compilers), CMake
itself, and `git`.
1. **`export PATH="/mingw64/bin:$PATH"`**
This makes the MinGW toolchain programs (such as `make` and the compilers)
visible so CMake can find them more easily. Note that this command's effects
are lost when you reopen the terminal, so you might want to append it to your
`~/.bashrc` to save time.

### Steps for Linux (any)

Follow your distribution's steps to install the following programs/libraries:
- **`gcc`**
- **`g++`**
- **`gfortran`**
- **`make`**
- **`cmake`** (version 3.18 or above)
- **`git`** (optional, you can also download the source .zip from GitHub)
- **`cmake`**
- **`git`**

All of those are fairly common, so get in touch in the MYSTRAN Forums or MYSTRAN Discord if you have trouble installing any of them. Also, note that most distros have a "base" package group for developers (e.g. Arch's `base-devel` or Ubuntu's `build-essential`) that includes necessary tooling such as `gcc` and `make`. If that's the case, install it!
All of those are fairly common, so get in touch in the MYSTRAN Forums or
MYSTRAN Discord if you have trouble installing any of them. Also, note that
most distros have a "base" package group for developers (e.g. Arch's
`base-devel` or Ubuntu's `build-essential`) that includes necessary tooling
such as `gcc` and `make`. If that's the case, install it!

If your distribution doesn't ship CMake 3.18+ yet, check if your distro has a some sort of testing/unstable channel before attempting to [install it manually](https://cmake.org/install/).
If your distribution doesn't ship CMake 3.18+ yet, check if your distro has a
some sort of testing/unstable channel before attempting to
[install it manually](https://cmake.org/install/).

---

## Building MYSTRAN

If your build environment is already set up, building MYSTRAN is quite straightforward.
If your build environment is already set up, building MYSTRAN is quite
straightforward.

### Steps for Windows (any)

1. Open the MSYS2 shell.
2. Re-run step #3 of the previous section if needed.
3. Fetch the source code if you haven't already. If you're using Git, you can clone the repo with **`git clone https://github.com/MYSTRANsolver/MYSTRAN.git`**.
4. Move the terminal to the MYSTRAN folder. If you've just run `git clone`, just do a **`cd MYSTRAN`**.
3. Fetch the source code if you haven't already. If you're using Git, you can
clone the repo with
**`git clone https://github.com/MYSTRANsolver/MYSTRAN.git`**.
4. Move the terminal to the MYSTRAN folder. If you've just run `git clone`,
just do a **`cd MYSTRAN`**.
5. Generate the build scripts by running **`cmake -G "MinGW Makefiles" .`**.
6. Compile with **`mingw32-make`**. If you have an N-core processor, running **`mingw32-make -jN`** will probably be much faster. A good choice of N is printed in the previous step, right before the end.
6. Compile with **`mingw32-make`**. If you have an N-core processor, running
**`mingw32-make -jN`** will probably be much faster. A good choice of N is
printed in the previous step, right before the end.
7. The executable will reside at **`Binaries/mystran.exe`**.

### Steps for Linux (any)

1. Open a terminal.
2. Fetch the source code if you haven't already. If you're using Git, you can clone the repo with **`git clone https://github.com/MYSTRANsolver/MYSTRAN.git`**.
3. Move the terminal to the MYSTRAN folder. If you've just run `git clone`, just do a **`cd MYSTRAN`**.
4. Generate the build scripts by running **`cmake .`**.
5. Compile with **`make`**. If you have an N-core processor, running **`make -jN`** will probably me much faster. A good choice of N is printed in the previous step, right before the end. You can also find the number of cores/threads with the `nproc` command (not all distros ship it out-of-the-box though).
6. The executable will reside at **`Binaries/mystran`**.
2. Fetch the source code if you haven't already. If you're using Git, you can
clone the repo with
**`git clone https://github.com/MYSTRANsolver/MYSTRAN.git`**.
3. Move the terminal to the MYSTRAN folder. If you've just run `git clone`,
just do a **`cd MYSTRAN`**.
1. Generate the build scripts by running **`cmake .`**.
2. Compile with **`make`**. If you have an N-core processor, running
**`make -jN`** will probably me much faster. A good choice of N is printed in
the previous step, right before the end. You can also find the number of
cores/threads with the `nproc` command (not all distros ship it
out-of-the-box though).
1. The executable will reside at **`Binaries/mystran`**.

---

## Troubleshooting

While this process is meant to be straightforward, here is a list of some of the more common issues that can arise. Other issues users find might be added here if it's not too specific.
While this process is meant to be straightforward, here is a list of some of
the more common issues that can arise. Other issues users find might be added
here if they're not too specific.

If your issue isn't here, you can always ask for help at the
[MYSTRAN forums](https://www.mystran.com/forums/) or the
[Discord server](https://discord.gg/9k76SkHpHM)

If your issue isn't here, you can always ask for help at the [MYSTRAN forum](https://www.mystran.com/forums/) or [Discord Chat](https://discord.gg/9k76SkHpHM)
---

### "I'm getting "file not found" errors when running the step #2 setup command!"
Expand All @@ -76,44 +109,81 @@ Run a **`pacman -Syyu`** (note the two 'y's) and try again.

### "CMake is complaining about not being able to find the toolchain or the Fortran compiler or the "make" command!"

Try running the commands `make`, `gcc`, and `gfortran`. If any of these comes up as a "command not found", make sure they've been installed. If you're **sure** they are, they might not be in the PATH.
Try running the commands `make`/`mingw32-make`, `gcc`, and `gfortran`. If any
of these comes up as a "command not found", make sure they've been installed.
If you're **sure** they are, they might not be in the PATH.

Windows users, have a look at step #3 of the setup. Linux users, check out your distro documentation, because whatever's happening should not be happening at all.
Windows users, have a look at step #3 of the setup. Linux users, check out your
distro documentation, because whatever's happening should not be happening at
all.

---

### "CMake complains about ARCHIVE_EXTRACT!" (aka "I got CMake 3.17 or older!" or "I _really_ can't install CMake 3.18+, is there another way?")
### "CMake complains about `ARCHIVE_EXTRACT`!"

Check out the output of `cmake --version`. You must have version 3.18 or newer. If you don't, first ensure it's up to date -- perform a system-wide update. Windows users should not find this issue relevant -- MSYS2 ships CMake 3.19.3 as of this writing. Linux users should use their own package manager.
Check out the output of `cmake --version`. You must have version 3.18 or newer.
If you don't, first ensure it's up to date -- perform a system-wide update.
Windows users should not find this issue relevant -- MSYS2 ships CMake 3.27.1
as of this writing. Linux users should use their own package manager.

If your system is up to date and you still run into this issue, that means your distro ships CMake 3.17 or older. Bad luck there. Here's what you can do:
If your system is up to date and you still run into this issue, that means your
distro ships CMake 3.17 or older. Bad luck there. Here's what you can do:

1. Enable a testing/unstable package channel (not all distros have one)
2. Install the latest CMake [manually](https://cmake.org/install/) (might piss off your package manager)
3. Try the ugly hack below
2. Install the latest CMake [manually](https://cmake.org/install/)
(might piss off your package manager)
1. Download and extract `libf2c.zip` yourself, and comment out the
`ARCHIVE_EXTRACT` stuff in `CMakeLists.txt`.

Option 3 is your last resort. Only do this if you not only really know what you're doing, but you also _really_ don't want to (or can't) give options 1 and 2 a shot.
---

In order to do it, download the SuperLU tarball manually (if it hasn't been downloaded already) to the repo base folder and extract it with `tar -xvzf superlu_x.y.z.tar.gz`). Once that's done, edit `CMakeLists.txt` and comment out the one line that contains the term `ARCHIVE_EXTRACT`, and try again.
### "I'm getting random SuperLU build errors!"

As I said before, it's an ugly hack. Shoot me an e-mail if it works though!
SuperLU is included as a submodule. A recent update to the submodule might
require a clean build. Run `make clean` and delete the `superlu` subdirectory
and run the appropriate `cmake` command again.

---

### "CMake complains about a "superlu"-related file or directory being absent/corrupted!"
### "I'm getting cryptic linker errors related to BLAS!"

SuperLU requires BLAS. Its build script can look for and link against your
system's installed BLAS implementation (we recommend OpenBLAS). However, your
install might be lacking the appropriate static (`.a`) library files.

If you don't know how to fix that and just want to build, you can use the
integrated BLAS subroutines bundled with the SuperLU source. To do that, run
the appropriate `cmake` command with the extra option
`-Denable_internal_blaslib=YES` *before* the `.` argument.

The build script automatically downloads and extracts the SuperLU source code for you. If it fails at doing that, you can force it to retry by deleting the SuperLU tarball and directory in the repo base folder.
Please be aware that the bundled CBLAS might be slow when compared to a proper
BLAS install. That might have an impact on the time it takes to run larger
models.

If it still fails, you can always try a similarly ugly hack. Download the correct SuperLU source and extract it yourself. The correct version is specified in the `CMakeLists.txt` file as `SUPERLU_VERSION`. Just Ctrl-F that, first result's the prize. Don't forget to name it `superlu_x.y.z.tar.gz` though, or the download will be attempted again.
---

### "I want to build offline, but the CMake script attempts to download stuff!"

Download the `superlu` submodule and `libf2c.zip` beforehand, and you should be
fine.

---

### "I want to build offline, but your CMake script attempts to download stuff!"
### "The terminal output is garbled during compilation!"

Multiple threads are printing to standard output simultaneously. That issue can
sometimes happen as a result of running `make` instead of `mingw32-make` on
Windows, but it can affect both. It's annoying, but harmless.

Download the `superlu_x.y.z.tar.gz` file beforehand and place it in the repo base dir. The script only attempts to download the tarball if it's absent.
However, if you *really* need compiler output to be readable, ensure `make`
only runs with one thread by passing the option `-j1`. This will make
compilation slower, but at least you'll be able to read the output.

Make sure to get the exact required version and name it accordingly. Check out the steps in the last paragraph of the previous issue for details.
And if it's errors you're looking for, you can build fast with `-j[number]`,
and then `-j1` just to see the error again.

---

If your issue isn't here, you can always ask for help at the [MYSTRAN forum](https://www.mystran.com/forums/) or [Discord Chat](https://discord.gg/9k76SkHpHM)
If your issue isn't here, you can always ask for help at the
[MYSTRAN forums](https://www.mystran.com/forums/) or the
[Discord server](https://discord.gg/9k76SkHpHM)
34 changes: 25 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ enable_language(Fortran)
project(Mystran)

# basic compiler and output options
set(CMAKE_SOURCE_DIR "Source")
set(PROJECT_BINARY_DIR "Binaries")
set(CMAKE_SOURCE_DIR "${PROJECT_SOURCE_DIR}/Source")
set(PROJECT_BINARY_DIR "${PROJECT_SOURCE_DIR}/Binaries")
set(CMAKE_FLAGS "-c -fbacktrace")
# set(CMAKE_BUILD_TYPE Debug)

Expand All @@ -26,28 +26,35 @@ if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
endif()

# recommend the appropriate make command
if(WIN32)
set(RECOMMENDED_MAKE "mingw32-make")
else()
set(RECOMMENDED_MAKE "make")
endif()

# submodules (i.e. SuperLU)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Updating submodules")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --force
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT
)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(
FATAL_ERROR
"git submodule update --init --recursive failed"
"git submodule update --init --recursive --force failed"
)
endif()
endif()
endif()

# check for SuperLU
set(SUPERLU_DIR "superlu")
set(SUPERLU_DIR "${PROJECT_SOURCE_DIR}/superlu")
include_directories("${SUPERLU_DIR}/SRC")
if(NOT EXISTS "${SUPERLU_DIR}/CMakeLists.txt")
message(
Expand All @@ -58,10 +65,10 @@ endif()


# f2c stuff
set(F2C_DIR "f2c")
set(F2C_DIR "${PROJECT_SOURCE_DIR}/f2c")
set(F2C_INCLUDE_DIR "${F2C_DIR}/include")
set(F2C_FN "${F2C_DIR}/libf2c.zip")
set(F2C_URL "https://www.netlib.org/${F2C_FN}")
set(F2C_URL "https://www.netlib.org/f2c/libf2c.zip")

# download f2c
if(NOT EXISTS ${F2C_DIR})
Expand Down Expand Up @@ -175,11 +182,20 @@ target_link_libraries(mystran dgssv superlu f2c)
set_target_properties(
mystran PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
)
if (CMAKE_COMPILER_IS_GNUCC)
target_compile_options(
mystran PRIVATE
-Wall -Wextra
-Wno-unused-variable -Wno-unused-label -Wno-unused-parameter -Wno-tabs
-Wno-compare-reals -Wno-character-truncation -Wno-unused-dummy-argument
-Wmaybe-uninitialized -Wrealloc-lhs -fcheck=all
)
endif()

# issue a couple messages about compilation
include(ProcessorCount)
ProcessorCount(NCPU)
message(STATUS "You can now compile MYSTRAN with make.")
message(STATUS "You can now compile MYSTRAN with ${RECOMMENDED_MAKE}.")
if (NOT NCPU EQUAL 0)
message(STATUS "Compile faster by passing -j${NCPU} to make.")
message(STATUS "Compile faster by passing -j${NCPU} to ${RECOMMENDED_MAKE}.")
endif()
28 changes: 16 additions & 12 deletions Source/EMG/EMG1/ELMDAT1.f90
Original file line number Diff line number Diff line change
Expand Up @@ -734,19 +734,23 @@ SUBROUTINE ELMDAT1 ( INT_ELEM_ID, WRITE_WARN )
ELSE IF (TYPE(1:4) == 'BUSH') THEN
IROW = EDAT(EPNTK + 8)
IF (IROW > 0) THEN
EOFF(INT_ELEM_ID) = 'Y'

IF(BUSH_OCID == -1) THEN ! Offsets are along line GA-GB and use only S

OFFDIS(1,1) = ELEM_LEN_12*BUSHOFF(IROW,1)
OFFDIS(1,2) = ELEM_LEN_12*BUSHOFF(IROW,2)
OFFDIS(1,3) = ELEM_LEN_12*BUSHOFF(IROW,3)

OFFDIS(2,1) =-ELEM_LEN_12*(ONE - BUSHOFF(IROW,1))
OFFDIS(2,2) = ELEM_LEN_12*BUSHOFF(IROW,2)
OFFDIS(2,3) = ELEM_LEN_12*BUSHOFF(IROW,3)

ELSE ! Offsets are 3 dimensional and we can't get OFFDIS for grid GB yet
IF (ELEM_LEN_12 >= .0001) THEN
! Offsets require an axis, so nonzero length
EOFF(INT_ELEM_ID) = 'Y' ! is needed since we can't use GA-GB when OCID=-1
OFFDIS(1,1) = ELEM_LEN_12*BUSHOFF(IROW,1)
OFFDIS(1,2) = ELEM_LEN_12*BUSHOFF(IROW,2)
OFFDIS(1,3) = ELEM_LEN_12*BUSHOFF(IROW,3)

OFFDIS(2,1) =-ELEM_LEN_12*(ONE - BUSHOFF(IROW,1))
OFFDIS(2,2) = ELEM_LEN_12*BUSHOFF(IROW,2)
OFFDIS(2,3) = ELEM_LEN_12*BUSHOFF(IROW,3)
ELSE
EOFF(INT_ELEM_ID) = 'N' ! No axis, no OCID, no offset.
END IF
ELSE
! Offsets are 3 dimensional and we can't get OFFDIS for grid GB yet
EOFF(INT_ELEM_ID) = 'Y' ! is required since we can't use GA-GB (OCID=-1)

OFFDIS(1,1) = BUSHOFF(IROW,1)
OFFDIS(1,2) = BUSHOFF(IROW,2)
Expand Down
Loading

0 comments on commit d909724

Please sign in to comment.