mardi 15 avril 2014

Building OpenFOAM on OS X

NB. Updated versions of the patches are on Github.

Previous patches I've posted in this blog (#1, #2, #3) have certain mistakes. Mainly because I forgot about DYLD_LIBRARY_PATH environment variable and did not test parallel execution of the solvers. Recently I've decided it is time to fix it. Also that tiny feedback I had, showed that there is two common errors during compilation: people create disk images with case insensitive file system and they try to apply patches in an arbitrary folders. The second problem is hard to solve by a blog post, while the first one can be solved if we change the process of disk image creation. Go from error-prone GUI way to just one command executed in terminal window. And here goes the guide.
Build process was tested on OS X version 10.9.2 with clang --version: Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn).

Before we start

I've made certain assumptions about the software you have on your Mac:
  • Homebrew is used as a package manager to install open source software. If not, you can install it following instructions on the site.
  • All software from ThirdParty source pack will be installed using Homebrew.
  • All commands are executed in Terminal application (usually it is called Terminal.app).
  • $ in the beginning of the lines is a shell prompt and you don't need to copy it, if you're copy/pasting commands from the post. In general commands should be executed in the sequence shown in the post.
  • You've downloaded Paraview application from paraview.org and installed it in /Applications.
To install dependencies you can use the following set of commands:
$ brew tap homebrew/science
$ brew install open-mpi
$ brew install scotch
$ brew install boost --without-single --with-mpi
$ brew install cgal
The last command will also install cmake, gmp, and mpfr as dependencies.

Downloading necessary pieces

At this point it is time to decide what version of OpenFOAM you'd like to build. As 2.3.0 introduced certain backward incompatible changes, I've made patches for 2.2.2 and 2.3.0. Further in the guide I assume you've downloaded source pack and patch into ~/Downloads/OpenFOAM folder.

OpenFOAM 2.2.2

Download source pack. Either following link on the OpenFOAM web site http://www.openfoam.org/archive/2.2.2/download/source.php, or by executing the following commands in in Terminal:
$ cd Downloads
$ mkdir OpenFOAM && cd OpenFOAM
$ curl -L http://downloads.sourceforge.net/foam/OpenFOAM-2.2.2.tgz > OpenFOAM-2.2.2.tgz
Download patch using following link https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.2.2.patch, or if you still have terminal opened, issue the command:
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.2.2.patch > OpenFOAM-2.2.2.patch

OpenFOAM 2.3.0

Download source pack. Either following link on the OpenFOAM web site - http://www.openfoam.org/download/source.php, or just executing this in Terminal:
$ cd Downloads
$ mkdir OpenFOAM && cd OpenFOAM
$ curl -L http://downloads.sourceforge.net/foam/OpenFOAM-2.3.0.tgz > OpenFOAM-2.3.0.tgz
Download patch using following link https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.3.0.patch, or if you still have terminal opened issue the command:
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-2.3.0.patch > OpenFOAM-2.3.0.patch
After this you're ready to proceed to the actual build process.

Building OpenFOAM

!!! Cause certain file names in this part depend on the version of OpenFOAM you're building, I use N and M variables in the file names. For OpenFOAM version 2.2.2: N=2, M=2; for OpenFOAM version 2.3.0: N=3, M=0.

Also it is possible that you already have disk image with the same name in your home folder. Correct the names accordingly.


To build OpenFOAM first you need to create disk image with case sensitive file system. You can either follow the guide from OpenFOAM wiki, or just issue these commands in your terminal:
$ cd
$ hdiutil create -size 4.4g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle
Last command will create disk image with the name OpenFOAM.sparsebundle with estimated size 4.4 G (as it is the sparse image, after creation the size of the file will be different), create HFS+ file system with a volume name OpenFOAM in the image. Finally -fsargs -s will instruct newfs_hfs utility to create case sensitive file system.
After the image was created you can mount it, I will assume it is mounted in $HOME/OpenFOAM
$ mkdir OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle
After you extract source pack, copy patch to the created folder, and apply patch (remember, you've downloaded the source pack and the patch into ~/Downloads/OpenFOAM):
$ cd OpenFOAM
$ tar xzf ~/Downloads/OpenFOAM/OpenFOAM-2.N.M.tgz
$ cd OpenFOAM-2.N.M
$ cp ~/Downloads/OpenFOAM/OpenFOAM-2.N.M.patch .
$ git apply OpenFOAM-2.N.M.patch
At this point maybe you'll need to edit etc/bashrc file. But since compiler settings are fixed (it is Clang), OpenMPI and other libraries settings are fixed (they are installed with Homebrew), in fact the only thing worth editing is path settings and only in case if you're installing OpenFOAM elsewhere (i.e. not in $HOME/OpenFOAM). Now you're more-or-less ready to compile.
$ source etc/bashrc
$ ./Allwmake > log.Allwmake 2>&1
The last command executes Allwmake script and redirects its output to log.Allwmake file; just in case, if anything goes wrong, it'll be easy to locate the source of error having this log file.
After Allwmake execution is finished, you can test the build with:
$ mkdir -p $FOAM_RUN
$ run
$ cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
$ cd cavity
$ blockMesh
$ icoFoam
If you'd like to test parallel run, it is necessary to do:
$ cat > system/decomposeParDict
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

numberOfSubdomains 4;

method          scotch;
^D
$ decomposePar
$ mpiexec -np 4 icoFoam -parallel
(^D is entered with Ctrl and D keys pressed together)

Post-configuration

There are several ways of managing mounting disk image and sourcing etc/bashrc file.
The first one is to define alias in your $HOME/.profile:
alias of2NM='hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle; sleep 1; source $HOME/OpenFOAM/OpenFOAM-2.N.M/etc/bashrc'
The second one is to create $HOME/.OpenFOAM-release file with a version of OpenFOAM you'd like to use:
$ echo '2.N.M' > $HOME/.OpenFOAM-release
and then add the following lines to your $HOME/.profile:
if [ -f $HOME/.OpenFOAM-release ]; then
        OF_VER=$(cat $HOME/.OpenFOAM-release)
        if [ ! -f $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc ]; then
                hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle && . $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
        else
                . $HOME/OpenFOAM/OpenFOAM-$OF_VER/etc/bashrc
        fi
fi
And finally third one is to transform second version in the set of functions. I.e. instead of automatic attachment of disk image upon terminal start, you'll need to execute function which will mount necessary disk image and source bashrc:

of2xx() {
    local version=$1
    if [ ! -f $HOME/OpenFOAM/OpenFOAM-$version/etc/bashrc ]; then
        hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle &&
            . $HOME/OpenFOAM/OpenFOAM-$version/etc/bashrc
    else
        . $HOME/OpenFOAM/OpenFOAM-$version/etc/bashrc
    fi
}

of2NM() {
    of2xx '2.N.M'
}
Add this code to your $HOME/.profile and use of2NM command to setup environment.

And that's it.

49 commentaires:

  1. Hi, thank you for your posting. Do you have patch for OF-2.1.0?? Is there any difference for OF-2.1 installation?

    RépondreSupprimer
    Réponses
    1. Hi,

      Unfortunately no, I don't have patch for 2.1.0 as I don't use this version. There are patches (http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/95763-1-9-aka-2-1-mac-os-x.html) by Bernhard Gschaider, though for them you need to install Macports and gcc 4.6.

      Supprimer
    2. Thank you for your response. I heard it's not good to have Macport and Homebrew together. I have installed OF 2.3 with homebrew but need 2.1 as well. I have to remove homebrew to install Gcc 4.6, right?

      Supprimer
    3. Well, I've never tried to mix Homebrew and Macports but I guess there will be a mess cause both use /use/local for installation of software (well, technically Homebrew just creates symlinks).

      You've got plenty of possibilities for installation of 2.3 and 2.1. a) Remove Homebrew, install both versions with Macports and Bernhard Gschaider's patches, b) Adapt Bernhard Gschaider's patches for 2.1 to use clang & Homebrew yourself, c) Wait till somebody creates patches for compilation of 2.1 with clang & Homebrew as package manager, d) Install gcc using Homebrew and try to use available patches for 2.1, e) Something else (buy separate Mac for 2.1 ;), run it in VM under Linux, adapt your software to use version 2.2.2)

      My set of patches was a result of scratching my itch (like almost everywhere in OSS world), I didn't want to use Macports as a package manager, so I've adapted existing patches to compile OF with clang.

      Supprimer
    4. I would go for (e) buying another Mac for 2.1 if I am rich enough. :-) So I will try (d). Hopefully it would work for OF2.1. Cheers - Youngkook Kim

      Supprimer
  2. Hi, Mr Matveichev. Thank you very much for this article. It is very helpful. When I try to brew install scotch it suggested that there's no formula. So the first time I tried to compile without scotch. But blockMesh and icoFoam prompted error "can not find run/system/controlDict at line 0." and exited. Now I've remove the image and installed scotch from a github repo and I am compiling it again. Do you think that problem can be solved this way? Thanks for your time.

    Best
    Congfan Zhu

    RépondreSupprimer
    Réponses
    1. Hi,

      sorry about scotch, I forgot that it is from science repository (so before installing scotch with 'brew install scotch' you need to do 'brew tap homebrew/science').

      And I'm sorry about the error you've got, I forgot to add 'cd cavity' command after 'cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .'. As you've run blockMesh utility in just $FOAM_RUN folder (and not in $FOAM_RUN/cavity), it wasn't able to find necessary dictionaries.

      I'll fix these things in the post.

      Supprimer
    2. Mr. Matveiche,

      Thank you very much. The compilation has just finished and I followed your instructions to run the tests and they worked perfectly. Your article is of tremendous help and I really appreciate your patience when answering my "beginner questions". It's very kind of you.

      Congfan

      Supprimer
    3. Bonjour Monsieur Matveichev,

      j ais essayer de suivre votre tutorial et malheuresement j obtiens l erreur suivant en compilant.

      /Users/Mowa/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/line.H:39:10: fatal error: 'PointHit.H' file not found
      #include "PointHit.H"
      ^

      le disque est monte en case sesible. et mon ordinateur a un systeme de fichier insensible.

      quand je tape diskutil info disk0s2 j obtiens:

      Device Identifier: disk0s2
      Device Node: /dev/disk0s2
      Part of Whole: disk0
      Device / Media Name: Customer

      Volume Name: Macintosh HD
      Escaped with Unicode: Macintosh%FF%FE%20HD

      Mounted: Yes
      Mount Point: /
      Escaped with Unicode: /

      File System Personality: Journaled HFS+
      Type (Bundle): hfs
      Name (User Visible): Mac OS Extended (Journaled)
      Journal: Journal size 81920 KB at offset 0x1b218000
      Owners: Enabled

      Partition Type: Apple_HFS
      OS Can Be Installed: Yes
      Media Type: Generic
      Protocol: SATA
      SMART Status: Verified
      Volume UUID: DFF93DBF-7DE1-3DE9-B4D7-3C79C898CBF5

      Total Size: 999.9 GB (999860912128 Bytes) (exactly 1952853344 512-Byte-Units)
      Volume Free Space: 886.6 GB (886602743808 Bytes) (exactly 1731645984 512-Byte-Units)
      Device Block Size: 512 Bytes

      Read-Only Media: No
      Read-Only Volume: No
      Ejectable: No

      Whole: No
      Internal: Yes
      Solid State: No



      Supprimer
    4. Hi,

      disk0s2 is a HDD of your Mac, FS there is case insensible. I will surely recheck the guide as soon as I will be at my Mac but according to previous comments (and also comments from my colleagues), it's possible to build OpenFOAM using the guide without much problems. So I guess you've missed certain point (unfortunately I can't guess which one).

      Supprimer
  3. Hi , Thanks for the post. I face the following error :

    /Users/balkrishna/OpenFOAM/OpenFOAM-2.2.2/bin/paraFoam: line 267: paraview: command not found

    Although paraview is installed on my system.

    How should I crossover this ?

    RépondreSupprimer
    Réponses
    1. Hi,

      go to $WM_PROJECT_DIR/etc/config folder, open paraview.sh in editor, on line 137 there will be "if [ $WM_ARCH_BASE=="darwin" ]", change lines between this if and corresponding fi to:

      if [ $WM_ARCH_BASE=="darwin" ]
      then
      : ${PARAVIEW_APP_DIR:="/Applications/paraview.app"}; export PARAVIEW_APP_DIR
      if [ -d $PARAVIEW_APP_DIR -a ! -r $ParaView_DIR ]
      then
      echo "Using paraview in directory $PARAVIEW_APP_DIR"
      unset ParaView_VERSION ParaView_MAJOR ParaView_DIR
      paraview () {
      $PARAVIEW_APP_DIR/Contents/MacOS/paraview "$@"
      }
      export -f paraview
      fi
      fi

      (commenting system has eaten all indentation though it's not critical to have this part indented)

      Supprimer
  4. Hi Matveichev,

    Thanks a lot for your post. I followed the instruction step by step but unfortunately when I try to compile I get the following error:


    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:129:9: error: no member named 'vwprintf' in the global namespace
    using ::vwprintf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:131:9: error: no member named 'swscanf' in the global namespace
    using ::swscanf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:132:9: error: no member named 'vfwscanf' in the global namespace
    using ::vfwscanf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:133:9: error: no member named 'vswscanf' in the global namespace
    using ::vswscanf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:134:9: error: no member named 'vwscanf' in the global namespace
    using ::vwscanf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:136:9: error: no member named 'wprintf' in the global namespace
    using ::wprintf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:137:9: error: no member named 'wscanf' in the global namespace
    using ::wscanf;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:138:9: error: no member named 'fgetwc' in the global namespace
    using ::fgetwc;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:139:9: error: no member named 'fgetws' in the global namespace
    using ::fgetws;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:140:9: error: no member named 'fputwc' in the global namespace
    using ::fputwc;
    ~~^
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:141:9: error: no member named 'fputws' in the global namespace
    using ::fputws;

    any idea of what that could be?

    Cheers,

    Marco

    RépondreSupprimer
    Réponses
    1. Hello,

      The error looks similar to one people usually get when they create disk image with case insensitive file system (as in this case compiler will include char.H from OpenFOAM instead of char.h from system include folder).

      Supprimer
  5. Hi
    This seems great! Exactly what I need. However, I have followed the steps, and every step is completed without any error messages, but when I am ready to test OpenFOAM, with the blockMesh command, I get "command not found". The same is the case for the icoFoam command, while the paraFoam command seems to work, as paraview is launched. Do you/anybody know whats wrong? Any help is greatly appreciated!

    RépondreSupprimer
    Réponses
    1. Hi,

      well, as paraFoam seems to be working and blockMesh is not, are you sure that compilation process was finished successfully? paraFoam is just a wrapper around paraview command which is available without compilation, while blockMesh requires compilation.

      You need to check log.Allwmake file for errors during compilation to figure out what's gone wrong.

      Supprimer
    2. Hm, okei, so it seems OpenFOAM has not been compiled correctly after all. Lots of error messages, where the first ones seems to be connected to open-mpi. messages like "could not open file ompi/mpi/cxx/pmpicxx.h for source file UOPwrite.C due to No such file or directory", any many similar ones. I have tried re-installing open-mpi, and then performing the steps once more, without success. I have installed open-mpi through homebrew, as described, and the homebrew instalation process seems to complete without any errors, but they might be located somewhere else as well. Any tips? :S

      Supprimer
    3. These errors are not fatal for the compilation and in fact you can ignore them.

      Do you have 'platforms' folder after compilation? you can go to 'platforms/darwinIntel64ClangDPOpt/bin' and check if blockMesh is there. And if it is actually there, then compilation is successful but something mess up environment variables.

      Also you can upload your log.Allwmake somewhere (pastebin.com for example) so I can check if it contains any fatal errors.

      Supprimer
    4. The platforms/../bin folder contains some files, such as the mesh converter applications, "kivaToFoam", "cfx4ToFoam", etc, but not much else (i.e. no blockMesh). My log.Allwmake file is really long, so pastebin would not take it without a pro account. I uploaded it to dropbox, if that is okey? here's the link: https://www.dropbox.com/s/15ewmtcb3ewkzc6/log.Allwmake?dl=0

      Supprimer
    5. In fact there are two errors like this:

      Make/darwinIntel64ClangDPOpt/STLsurfaceFormatASCII.C:5981:18: error: out-of-line definition of 'LexerInput' does not match any declaration in 'yyFlexLexer'
      int yyFlexLexer::LexerInput( char* buf, int max_size )

      And they lead to the failure to build almost everything. Maybe the latest Xcode updates have broken something, I'll check it this evening. Maybe the patches need to be updated.

      Supprimer
    6. Hi,

      unfortunately I wasn't able to reproduce your error, on my laptop STLsurfaceFormatASCII.C builds fine. Can you post the output of the following commands:

      $ sw_vers
      $ flex --version
      $ clang++ --version

      (maybe you've got very special flex or clang++)

      Supprimer
    7. Ok
      sw_vers:
      ProductName: Mac OS X
      ProductVersion: 10.9.4
      BuildVersion: 13E28
      flex --version:
      flex 2.5.37
      clang++ --version:
      Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
      Target: x86_64-apple-darwin13.3.0
      Thread model: posix

      Supprimer
    8. The only difference from my configuration is in flex:

      flex --version
      flex 2.5.35 Apple(flex-31)

      And I guess this is the reason (as clang++ uses FlexLexer.h from SDK while your version of the flex utility can be incompatible with it).

      As a variant you can correct OpenFOAM-2.3.0/wmake/rules/General/flex and OpenFOAM-2.3.0/wmake/rules/General/flex++ files to explicitly use /usr/bin/flex instead of the one from $PATH variable (though if you installed flex in /usr/bin I don't know what to suggest).

      Supprimer
    9. Hi

      It was the flex thing that was the problem. I actually have no idea how I have managed to install a different version of flex, so I decided to revert back to the default version, i.e. the one you have. This worked fine! OpenFOAM is now running :)

      Thanks a lot, the help is greatly appreciated!

      Supprimer
  6. Hi Mr Alexey Matveichev,

    If I type blockMesh or IcoFoam after compiling I receive the error: -bash: blockMesh: command not found

    In the log.Allwmake file are a LOT of errors but always the same three:



    Make/darwinIntel64ClangDPOpt/chemkinLexer.C:37628:19: error: out-of-line definition of 'LexerOutput' does not match any declaration in 'yyFlexLexer'
    void yyFlexLexer::LexerOutput( const char* buf, int size )

    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[3]: *** [/Users/gregorholzner/OpenFOAM/OpenFOAM-2.2.2/platforms/darwinIntel64ClangDPOpt/bin/refineWallLayer] Error 1
    make[2]: *** [refineWallLayer] Error 2
    Making dependency list for source file refinementLevel.C

    2 errors generated.
    make[3]: *** [Make/darwinIntel64ClangDPOpt/ansysToFoam.o] Error 1
    make[3]: Target `/Users/gregorholzner/OpenFOAM/OpenFOAM-2.2.2/platforms/darwinIntel64ClangDPOpt/bin/ansysToFoam' not remade because of errors.
    make[2]: *** [ansysToFoam] Error 2

    darwinIntel64ClangDPOpt/bin/flattenMesh] Error 1
    make[2]: *** [flattenMesh] Error 2


    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [/Users/gregorholzner/OpenFOAM/OpenFOAM-2.2.2/platforms/darwinIntel64ClangDPOpt/bin/solidEquilibriumDisplacementFoam] Error 1
    make[1]: *** [solidEquilibriumDisplacementFoam] Error 2
    make[1]: Target `application' not remade because of errors.
    make: *** [stressAnalysis] Error 2
    make: Target `application' not remade because of errors.


    What could cause this errors?

    My versions are:

    $ sw_vers:

    ProductName: Mac OS X
    ProductVersion: 10.9.4
    BuildVersion: 13E28

    $flex --version:

    flex 2.5.37

    $ clang++ --version

    Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
    Target: x86_64-apple-darwin13.3.0
    Thread model: posix

    Thank you for this great site!

    Cheers,

    Greg

    RépondreSupprimer
    Réponses
    1. Hi,

      your error is the same as in Jarle Andre Kramer's comment. So can you please post output of the command:

      $ which flex

      ?

      We've got the same OS X version, the same clang version but for some reason you've got strange version of flex utility.

      Supprimer
  7. Réponses
    1. And I guess you've also go Macports installed?

      Edit $HOME/OpenFOAM/OpenFOAM-2.2.2/wmake/rules/General/flex and $HOME/OpenFOAM/OpenFOAM-2.2.2/wmake/rules/General/flex++ files (I guess you're building version 2.2.2). Change there flex to /usr/bin/flex, after that wmake will use Apple version of flex, and with this version everything builds fine.

      Supprimer
    2. Hi,
      sorry for the question but I'm a bloody beginner, the flex file look like this:

      .SUFFIXES: .l

      ltoo = flex -o$*.c $$SOURCE ; $(cc) $(cFLAGS) -c $*.c -o $@

      .l.dep:
      $(MAKE_DEP)


      and the flex ++ file:

      .SUFFIXES: .L

      Ltoo = flex -+ -o$*.C -f $$SOURCE ; $(CC) $(c++FLAGS) -c $*.C -o $@

      .L.dep:
      $(MAKE_DEP)

      What I have to change to 'usr/bin/flex' ?

      Supprimer
    3. Well, maybe I should also try to explain why you're doing it. If you just type flex on the command prompt shell will look to executable flex in PATH environment variable, and it will find it in '/opt/local/bin/' as it seems your Macports installation requires this path supersede '/usr/bin'.

      So first of all you should change 'flex' to exactly '/usr/bin/flex'. I.e. you need all these slashes.

      As you can see inside these files only one string 'flex' is present, so you should change the line

      'ltoo = flex -o$*.c $$SOURCE ; $(cc) $(cFLAGS) -c $*.c -o $@'

      to

      'ltoo = /usr/bin/flex -o$*.c $$SOURCE ; $(cc) $(cFLAGS) -c $*.c -o $@'

      for the flex file.

      Also I'm not quite sure it'll help, maybe there will be more problems, as I've never mixed Homebrew and Macports in one installation.

      Supprimer
  8. Hi Alexey, I have done all the steps as described in the article but when compiled several errors appear. The latter is the following:

    ld: library not found for -lfiniteVolume
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [/Users/huguito/OpenFOAM/OpenFOAM-2.3.0/platforms/darwinIntel64ClangDPOpt/bin/solidEquilibriumDisplacementFoam] Error 1
    make[1]: *** [solidEquilibriumDisplacementFoam] Error 2
    make[1]: Target `application' not remade because of errors.
    make: *** [stressAnalysis] Error 2
    make: Target `application' not remade because of errors.

    I have the log file where I could send it?

    Cheers

    Hugo

    RépondreSupprimer
    Réponses
    1. Hi,

      well, wherever you'd like in fact ;) if you have Dropbox, you can put it in Public folder and post a link here; there's pastebin.com (though I think your log-file is rather large so pastebin will reject it); if you have account on bitbucket.org, you can create repository for the file and post if there; if you have account on github.com, you can create repository for the file and post it there; there's SpiderOak, there's Wuala, there's Windows Live, there's Yandex Disk... finally, you can burn it to CD and send it via post to l'Institute Jean Lamour in Nancy.

      Along with a link to your log-file please post the output, of:
      $ sw_vers
      $ flex --version
      $ which flex
      $ clang++ --version

      I guess, you've got custom version of flex utility installed, and this causes problems during compilation.

      Regards,

      Alexey

      Supprimer
    2. Thanks Alexey; I'm considering sending the CD to this address: haha ​​joke
      I think the problem was that from a previous article I used macports to install packages and then fell into this using homebrew; I will uninstall macports and try again; if I have no succeed I'll upload the logfile to my github account for you to look.

      Again many thanks for all

      Hugo

      Supprimer
    3. The dates you request me: (after uninstall macports)

      ProductName: Mac OS X
      ProductVersion: 10.9.4
      BuildVersion: 13E28

      flex 2.5.35 Apple(flex-31)
      /usr/bin/flex

      Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
      Target: x86_64-apple-darwin13.3.0
      Thread model: posix

      Supprimer
    4. Uninstalling macports fix everything; ALL IS WORKING FINE
      Thanks for this excellent post !!!

      cheers

      Hugo

      Supprimer
    5. Good.

      Maybe it's worth updating the post to mention about the problem with Macports. I thought Macports users usually use Bernhard Gschaider's patch (https://sourceforge.net/p/openfoam-extend/svn/HEAD/tree/trunk/Breeder_2.3/distroPatches/MacPatch/)

      Supprimer
    6. Hey Alexey, here you have the log file when Macport and Homebrew was installed and got the errors:

      https://github.com/hballesteros/OpenFoam-Notes

      Thanks again

      Supprimer
    7. Thanks for the log-file. The error that caused all others is the same as in the comments by Jarle Andre Kramer and hans gusseisen:

      ...
      Make/darwinIntel64ClangDPOpt/STLsurfaceFormatASCII.C:5981:18: error: out-of-line definition of 'LexerInput' does not match any declaration in 'yyFlexLexer'
      int yyFlexLexer::LexerInput( char* buf, int max_size )
      ^~~~~~~~~~
      Make/darwinIntel64ClangDPOpt/STLsurfaceFormatASCII.C:6008:19: error: out-of-line definition of 'LexerOutput' does not match any declaration in 'yyFlexLexer'
      void yyFlexLexer::LexerOutput( const char* buf, int size )
      ^~~~~~~~~~~
      2 errors generated.
      make: *** [Make/darwinIntel64ClangDPOpt/STLsurfaceFormatASCII.o] Error 1
      ...

      And it is caused by non-standard flex installation (while clang++ tries to use FlexLexer.h from Apple distribution).

      Supprimer
  9. Thank you so much for such a fantastic post.

    I managed to install OpenFOAM 2.3.1 using (https://github.com/mrklein/openfoam-os-x/wiki/OpenFOAM%20release%20&%20Homebrew) on Yosemite. Everything works fine but I am struggling to work on the post-configuration.

    When I type in $HOME /.profile, I get the following message: -bash: /Users/Jiho/.profile: Permission denied

    Could you be able to help me on this? I am only using the 2.3.1 version and I wish it to be good to go once I open my terminal.app.

    Also, what happens if I eject the OpenFOAM folder? Would the post-configuration be able to mount it back automatically as long as my source file is available?

    I am very new to all this and your help will be greatly appreciated.

    Thanks

    RépondreSupprimer
    Réponses
    1. Why do you "type in $HOME /.profile"? This file is executed automatically every time you open Terminal.app. Since in general it does not have execution permission, you get the error from your message. If you would like to run commands from this file, you should use either "source $HOME/.profile" or ". $HOME/.profile" (there is a space between first dot and $HOME).

      Concerning disk image mount. If you have chosen to use openfoam-env-setup.sh, then it will try to mount disk image if it can not find OpenFOAM's bashrc file (and this is the case if either you have ejected OpenFOAM folder, or deleted bashrc file).

      Unfortunately I was not able to deduce from your comment, where did you stuck in Post-configuration phase, so my answer could be irrelevant.

      Supprimer
  10. Hi, thank you for your reply.

    Right.. I am very new to OpenFOAM, Linux and even to OS X so I am very ignorant in all this. If I wish to follow your first method for post-configuration (defining alias), do I just type in "source $HOME/.profile" and then "alias of2NM='hdiutil attach -quiet -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle; sleep 1; source $HOME/OpenFOAM/OpenFOAM-2.N.M/etc/bashrc' " on my terminal ??

    Again, thank you so much for your help

    RépondreSupprimer
    Réponses
    1. Hi,

      I would suggest you this: https://github.com/mrklein/openfoam-os-x/wiki/Post-configuration#combining-two-approaches

      I.e.
      1. start Terminal.app
      2. Enter the following commands (or copy-paste them from here):
      2.1. cd $HOME
      2.2. curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/files/openfoam-env-setup.sh > .openfoam-env-setup.sh
      2.3. printf "\nsource \$HOME/.openfoam-env-setup.sh\n\n" >> .profile
      2.4. mkdir -p .OpenFOAM
      2.5. echo '2.3.1' > $HOME/.OpenFOAM/OpenFOAM-release
      3. close Terminal.app

      After these steps every time you start Terminal.app environment will be preconfigured for version 2.3.1.

      Alias approach, described in the post, is somewhat outdated and buggy.

      Supprimer
    2. It works! I can't thank you more :) Thank you so much you made my day!

      Regarding to disk image mount, do I have to leave the OpenFOAM disk mounted at all times? Is there a way to make it to be mounted automatically whenever I wish to use OpenFOAM instead of having it always mounted?

      Thanks

      Supprimer
    3. You can unmount disk image (though I do not see the point), .openfoam-env-setup.sh tries to mount disk image if it can not find bashrc file.

      Supprimer
    4. Everything's working fine now! Thank you !

      Supprimer
    5. Hi,

      I'm just wondring if there's a way to execute openfoam by entering some command (say, of230) like you would in Linux instead of automatically mounting the disk image every time I open the terminal?

      Thank you for your help!

      Supprimer
    6. Well - "...like you would in Linux..." - I have never done this. I always have default version and environment is automatically set up for this version.

      You can use this file: https://github.com/mrklein/openfoam-os-x/blob/master/files/openfoam-env-setup.sh (download it, add 'source /path/to/the/openfoam-env-setup.sh' to your profile). Then after if you have ~/.OpenFOAM/OpenFOAM-release file with version inside, disk i automatically mounted, environment is set up. Otherwise you get of22x, of231, etc functions to set up environment. Also it is explained in wiki: https://github.com/mrklein/openfoam-os-x/wiki/Post-configuration.

      Supprimer
  11. Hi Alexey!

    I am trying to compile OpenFOAM-3.0.0 following your guidelines and your newly posted patch for OF3.0.0 on your repository https://github.com/mrklein/openfoam-os-x. I tried both with macports and homebrew, and I managed to compile it both without any bad issues. However when I run the cavity case I always have this issue:

    Code:
    Starting time loop

    Time = 0.005

    Courant Number mean: 0 max: 0
    smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 8.90511e-06, No Iterations 19
    smoothSolver: Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
    DICPCG: Solving for p, Initial residual = 1, Final residual = 7.55423e-07, No Iterations 35
    time step continuity errors : sum local = 5.03808e-09, global = -7.94093e-21, cumulative = -7.94093e-21
    DICPCG: Solving for p, Initial residual = 0.523588, Final residual = 9.72371e-07, No Iterations 34
    time step continuity errors : sum local = 1.07766e-08, global = 2.00426e-19, cumulative = 1.92485e-19
    dyld: lazy symbol binding failed: Symbol not found: __ZN4FoamlsERNS_7OstreamEl
    Referenced from: /Users/oleg/OpenFOAM/OpenFOAM-3.0.x/platforms/darwin64ClangDPInt32Opt/bin/icoFoam
    Expected in: flat namespace

    dyld: Symbol not found: __ZN4FoamlsERNS_7OstreamEl
    Referenced from: /Users/oleg/OpenFOAM/OpenFOAM-3.0.x/platforms/darwin64ClangDPInt32Opt/bin/icoFoam
    Expected in: flat namespace

    Trace/BPT trap: 5
    Basically, I didn't create a new sparse image for particularly this OF version, because I used 2.1 before. So i compiled on the disk image I had created before.

    I posted the same thing on cfd-online :)
    Thank you in advance!
    Oleg

    RépondreSupprimer