Difference between revisions of "Installation/Mac OS/OpenFOAM 2.2.2"

From OpenFOAMWiki
(Final Steps)
m (Removed old source for patches not available anymore)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
== Known Guides For Building OpenFOAM 2.2.2 on Mac OS X ==
 +
The known guides for building OpenFOAM 2.2.2 on Mac OS X are as follows:
 +
* The current one you're reading: [[Installation/Mac OS/OpenFOAM 2.2.2#Introduction and Notes|Installation/Mac OS/OpenFOAM 2.2.2]] - which explains how to build using GCC 4.6 from Macports.
 +
* From Alexey Matveichev's  blog: [http://matveichev.blogspot.com/2014/04/building-openfoam-on-os-x.html Building OpenFOAM on OS X], tested on OS X 10.9.3 with clang 5.1.
  
 
== Introduction and Notes ==
 
== Introduction and Notes ==
  
This guide is derived from <span class="plainlinks">[http://openfoamwiki.net/index.php/Installation/Mac_OS/OpenFOAM_2.1.x OpenFOAM 2.1.x Installation]</span> with some modifications derived thanks to the help provided on [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x-5.html#post461727 this thread] of [http://www.cfd-online.com CFD Online Forum ].
+
This guide is derived from [[Installation/Mac_OS/OpenFOAM_2.1.x|OpenFOAM 2.1.x Installation]] with some modifications, thanks to the help provided on [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x-5.html#post461727 this thread] at [http://www.cfd-online.com/Forums/ CFD-Online's Forums].
  
  
Line 9: Line 13:
 
  Intel Core i7 2.66Ghz
 
  Intel Core i7 2.66Ghz
 
  Mac OS X Mavericks (version 10.9)
 
  Mac OS X Mavericks (version 10.9)
These instructions may need to be tailored as required to fit your specific system if they deviate from the above; you would be able to ask support on [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x-5.html#post461727 this thread] if you needed it.
+
These instructions may need to be tailored to fit your specific system if they deviate from the above; you should be able to ask support on [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x-5.html#post461727 this thread] if you needed it.
  
Many thanks go to Bernhard Gschaider (a.k.a. [http://www.cfd-online.com/Forums/members/gschaider.html gschaider]) of CFD Online for maintaining the latest OpenFOAM Mac OS X patches and for the big help he provided me.
+
Many thanks go to Bernhard Gschaider (a.k.a. [http://www.cfd-online.com/Forums/members/gschaider.html gschaider] at CFD-Online's Forums) for maintaining the latest OpenFOAM Mac OS X patches and for the big help he provided [[User:Tidusuper91|me]].
  
 
__TOC__
 
__TOC__
Line 20: Line 24:
  
 
To install Macports you need to install <b>xCode</b>, you can find it on the App Store.  
 
To install Macports you need to install <b>xCode</b>, you can find it on the App Store.  
After XCode you need to install the <b>Command Line Tools</b>. Installing Command Line Tools for Mavericks is different from what you would do with previous OSX versions.
+
After xCode you need to install the <b>Command Line Tools</b>. Installing Command Line Tools for Mavericks is different from what you would do with previous OSX versions, as explained in the following subsections:
 +
* [[#Command Line Tools for OSX 10.9 "Mavericks"|Command Line Tools for OSX 10.9 "Mavericks"]]
 +
* [[#Command Line Tools for OSX version < 10.9|Command Line Tools for OSX version < 10.9]]
 +
 
 
==== Command Line Tools for OSX 10.9 "Mavericks" ====
 
==== Command Line Tools for OSX 10.9 "Mavericks" ====
To install CLT on OSX 10.9 open a terminal application (for example <i>Terminal.app</i>) and run<pre>
+
To install CLT on OSX 10.9 open a terminal application (for example <i>Terminal.app</i>) and run:
xcode-select --install
+
<bash>xcode-select --install</bash>
</pre>
+
 
a window will be prompted where you can confirm installation.
 
a window will be prompted where you can confirm installation.
  
 
==== Command Line Tools for OSX version < 10.9 ====
 
==== Command Line Tools for OSX version < 10.9 ====
In previous versions of OSX (and of xCode) you can download CLT directly from xCode Preferences > Downloads > Components
+
In previous versions of OSX (and of xCode) you can download CLT directly from xCode {{tt|Preferences > Downloads > Components}}.
  
 
==== xCode License ====  
 
==== xCode License ====  
Now you should accept the xCode License so run, always in the Terminal (this could be needed only on OSX 10.9)<pre>
+
Now you should accept the xCode License so run, always in the Terminal (this could be needed only on OSX 10.9):
sudo xcodebuild -license
+
<bash>sudo xcodebuild -license</bash>
</pre>
+
 
and when asked type "agree" to accept the license. Now xCode "things" should work correctly.
 
and when asked type "agree" to accept the license. Now xCode "things" should work correctly.
  
 
==== MacPorts Installation ====
 
==== MacPorts Installation ====
Now to install Macports you can download the pre-compiled package from the [http://www.macports.org/install.php#pkg Official Website].
+
Now to install Macports you can download the pre-compiled package from the [http://www.macports.org/install.php#pkg Official Macports Website].
  
 
=== Build and Install the necessary software ===
 
=== Build and Install the necessary software ===
To install all the tools we'll need run in Terminal:<pre>sudo port selfupdate</pre>
+
To install all the tools we'll need run in Terminal:
Wait for the end of all operations then do:<pre>sudo port install gcc46 openmpi boost cgal ccache flex bison
+
<bash>sudo port selfupdate</bash>
</pre>
+
Wait for the end of all operations then do:
 +
<bash>sudo port install gcc46 openmpi boost cgal ccache flex bison</bash>
  
 
Now wait (a bit...)
 
Now wait (a bit...)
Line 48: Line 54:
 
== OpenFOAM Building ==
 
== OpenFOAM Building ==
  
=== Creation of Case Sensitive .sparseimage ===
+
=== Creation of Case Sensitive {{tt|.sparseimage}} ===
  
'''Note:''' Images here shown are taken from [[Installation/Mac_OS/OpenFOAM_2.1.x]], you could change the name of the sparseimage from '''OpenFOAM-v2.1''' to '''OpenFOAM-v2.2.2''' (and this will be assumed from here on)
+
'''Note:''' Images here shown are taken from [[Installation/Mac_OS/OpenFOAM_2.1.x]], you could change the name of the sparse-image from '''OpenFOAM-v2.1''' to '''OpenFOAM-v2.2.2''' (and this will be assumed from here on).
  
  
Line 61: Line 67:
  
 
=== OpenFOAM sources and patches ===
 
=== OpenFOAM sources and patches ===
'''Note:''' Rember that when you're inside the terminal you can auto-complete your commands pressing the '''TAB''' button
+
'''Note:''' Remember that when you're inside the terminal you can auto-complete your commands pressing the '''TAB''' button.
  
  
Download OpenFOAM 2.2.2 sources from [http://www.openfoam.org/download/source.php here] and patches ([http://tidusuper91.altervista.org/blog/download/mac/OpenFOAM-2.2.x_Mac-20130309.patch OpenFOAM-2.2.2 Patch] || [http://tidusuper91.altervista.org/blog/download/mac/SurfaceCGALFix.patch  SurfaceCGAL Fix] || [http://tidusuper91.altervista.org/blog/download/mac/ThirdParty-2.2_Mac-20130309.patch ThirdParty Patch]) <ref>More updated patches could be possibly found on [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/ this CFD Online Thread]</ref> and put everything inside the .sparseimage (you probably saved in ~/Documents).  
+
Download OpenFOAM 2.2.2 sources from [http://openfoam.org/download/2-2-2-source/ here] and the 3 necessary patch files from one of the following places:
 +
# From the original forum posts, download the patch files {{tt|OpenFOAM-2.2.x-Mac_2014-02-17.patch}} and {{tt|ThirdParty-2.2.x-Mac_2014-02-17.patch}} from [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x-6.html#post475723 post #108] ({{tt|SurfaceCGALFix.patch}} from [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x-3.html#post438525 post #54] should not be longer needed with last updated patches).
 +
# More updated patches could be possibly found on [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/114265-patches-compile-openfoam-2-2-mac-os-x.html this CFD Online Thread].
  
Open a Terminal, create a symlink to the OF image:<pre> ln -s /Volumes/OpenFOAM-v2.2.2 OpenFOAM </pre>now we can go to OF directory just doing (from home directory)<pre>cd OpenFOAM</pre>
+
 
Let's extract the two archives:<pre>tar -xvf OpenFOAM-2.2.2.tgz
+
Put everything inside the {{tt|.sparseimage}} (you probably saved in ~/Documents).
tar -xvf ThirdParty-2.2.2.tgz</pre>
+
 
Now your OF directory should look like this<pre>****@mbp-di-ruben: ~/OpenFOAM$ ls -al
+
<ol>
 +
<li>Open a Terminal, create a ''symlink'' to the OF image:
 +
<bash>ln -s /Volumes/OpenFOAM-v2.2.2 OpenFOAM</bash>
 +
</li>
 +
<li>Now we can go to OF directory just doing (from home directory):
 +
<bash>cd OpenFOAM</bash>
 +
</li>
 +
<li>Let's extract the two archives:  
 +
<bash>tar -xvf OpenFOAM-2.2.2.tgz
 +
tar -xvf ThirdParty-2.2.2.tgz</bash>
 +
</li>
 +
<li>Now your OF directory should look like this:
 +
<bash>****@mbp-di-ruben: ~/OpenFOAM$ ls -al
 
total 182688
 
total 182688
 
drwxr-xr-x  8 ****  staff      612 13 Nov 02:49 .
 
drwxr-xr-x  8 ****  staff      612 13 Nov 02:49 .
Line 85: Line 105:
 
-rw-r--r--@  1 ****  staff  58193818 12 Nov 21:09 ThirdParty-2.2.2.tgz
 
-rw-r--r--@  1 ****  staff  58193818 12 Nov 21:09 ThirdParty-2.2.2.tgz
 
-rw-r--r--@  1 ****  staff      2686 12 Nov 21:12 ThirdParty-2.2_patch
 
-rw-r--r--@  1 ****  staff      2686 12 Nov 21:12 ThirdParty-2.2_patch
</pre>
+
</bash>
 
+
</li>
Let's move the patches inside the right folders<pre># Current Folder: ~/OpenFOAM$  
+
<li>Let's move the patches inside the right folders:
mv OpenFOAM-2.2.x_Mac-20130309 OpenFOAM-2.2.2
+
<bash># Current Folder: ~/OpenFOAM$  
 +
mv OpenFOAM-2.2.x_Mac-20130309.patch OpenFOAM-2.2.2
 
mv SurfaceCGALFix.patch OpenFOAM-2.2.2
 
mv SurfaceCGALFix.patch OpenFOAM-2.2.2
mv ThirdParty-2.2_Mac-20130309.patch Thirdparty-2.2.2</pre>
+
mv ThirdParty-2.2_Mac-20130309.patch Thirdparty-2.2.2</bash>
 
+
</li>
Let's apply them<pre>#Current Folder: ~/OpenFOAM
+
<li>Let's apply them:
 +
<bash>#Current Folder: ~/OpenFOAM
 
cd OpenFOAM-2.2.2
 
cd OpenFOAM-2.2.2
 
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
 
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
Line 103: Line 125:
 
patch -p1<ThirdParty-2.2_patch
 
patch -p1<ThirdParty-2.2_patch
 
cd ..
 
cd ..
#Current Folder: ~/OpenFOAM/</pre>
+
#Current Folder: ~/OpenFOAM/</bash>
 
+
</li>
OpenFoam patch badly writes compilers symlinks so we have to fix:<pre>#Current Folder: ~/OpenFOAM/
+
<li>OpenFoam patch badly writes compilers ''symlinks'' so we have to fix:
 +
<bash>#Current Folder: ~/OpenFOAM/
 
cd OpenFOAM-2.2.2
 
cd OpenFOAM-2.2.2
 
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
 
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
Line 113: Line 136:
 
ln -s darwinIntel64Gcc/ darwinIntel64Gcc46
 
ln -s darwinIntel64Gcc/ darwinIntel64Gcc46
 
cd ../..
 
cd ../..
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2</pre>
+
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2</bash>
 +
</li>
 +
</ol>
  
 
=== Final Steps ===
 
=== Final Steps ===
  
Let's give write permission to '''addr2line4Mac.py'''<pre>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
+
<ol>
chmod a+x bin/addr2line4Mac.py</pre>
+
<li>Let's give write permission to {{tt|addr2line4Mac.py}}:
 
+
<bash>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
Now we have to edit the bashrc file<pre>sudo nano etc/bashrc</pre>
+
chmod a+x bin/addr2line4Mac.py</bash>
Use '''CTRL+W''' to find those lines<bash>export WM_COMPILER=Gcc
+
</li>
export WM_MPLIB=OPENMPI</bash> and change them with<bash>export WM_COMPILER=Gcc46
+
<li>Now we have to edit the bashrc file:
 +
<bash>sudo nano etc/bashrc</bash>
 +
</li>
 +
<li>Use '''CTRL+W''' to find these lines:
 +
<bash>export WM_COMPILER=Gcc
 +
export WM_MPLIB=OPENMPI</bash>
 +
and change them to:
 +
<bash>export WM_COMPILER=Gcc46
 
export WM_MPLIB=SYSTEMOPENMPI</bash>
 
export WM_MPLIB=SYSTEMOPENMPI</bash>
 
+
</li>
at the end of this file, add <bash>
+
<li>At the end of this file, add:
export WM_CC='gcc-mp-4.6'
+
<bash>export WM_CC='gcc-mp-4.6'
 
export WM_CXX='g++-mp-4.6'
 
export WM_CXX='g++-mp-4.6'
 
export WM_NCOMPPROCS=4
 
export WM_NCOMPPROCS=4
 
ulimit -n 1024</bash>
 
ulimit -n 1024</bash>
Save ('''CTRL+O''' and exit '''CTRL+X''')
+
A few notes about the last two lines<ref>From [[Installation/Mac_OS/OpenFOAM_2.1.x]]</ref>:
 
+
A few notes about these two lines<ref>From [[Installation/Mac_OS/OpenFOAM_2.1.x]]</ref>
+
 
* Apparently it's best that you manually write these two lines instead of copy-pasting, because apparently some ''weird characters'' will show up on your file ([http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/95763-1-9-aka-2-1-mac-os-x-4.html#post358504 source]).
 
* Apparently it's best that you manually write these two lines instead of copy-pasting, because apparently some ''weird characters'' will show up on your file ([http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/95763-1-9-aka-2-1-mac-os-x-4.html#post358504 source]).
* The first entry is to increase the number of files which one process may open at a time;
+
* The first entry you should set to the number of processes your CPU could manage in parallel, e.g. 4, 8 or 16.
* The second entry you should set to the number of processes your CPU could manage in parallel, e.g. 4, 8, 16, ...
+
** If you don't know how many your machine can handle, then run: <pre>sysctl -n hw.ncpu</pre>
* If you don't know how many your machine can handle, then run: <pre>sysctl -n hw.ncpu</pre>
+
* The second entry is to increase the number of files which one process may open at a time.
 
+
</li>
Now we need a symlink for openmpirun (this can be useful with snappyHexMesh)<pre>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
+
<li>Save ('''CTRL+O''' and exit '''CTRL+X''')</li>
 +
</li>
 +
<li>Now we need a ''symlink'' for {{tt|openmpirun}} (this can be useful with {{tt|snappyHexMesh}}):
 +
<bash>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
 
cd OpenFOAM/OpenFOAM-2.2.2/bin
 
cd OpenFOAM/OpenFOAM-2.2.2/bin
 
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2/bin
 
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2/bin
 
ln -s /opt/local/bin/openmpirun mpirun
 
ln -s /opt/local/bin/openmpirun mpirun
 
cd ..  
 
cd ..  
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2</pre>
+
#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2</bash>
 +
</li>
 +
<li>There's some hard-coding to do on a file:
 +
<bash>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
 +
sudo nano src/renumber/SloanRenumber/Make/options</bash>
 +
</li>
 +
<li>Change this line:
 +
<bash>-L$(BOOST_ARCH_PATH)/lib -lboost_thread \</bash>
 +
into this:
 +
<bash>-L$(BOOST_ARCH_PATH)/lib -lboost_thread-mt \</bash> save and exit.
 +
</li>
 +
<li>Source the bashrc file:
 +
<bash>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
 +
. etc/bashrc</bash>
 +
</li>
 +
<li>Now we're ready to compile. Cross your fingers and do:
 +
<bash>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
 +
./Allwmake 2>&1 | tee logName.log</bash>
 +
where <tt>logName</tt> should be replaced by a name for your log :P. Now take your time, call your mum, cook, take a shower and then come back to see if something went wrong.</li>
 +
</ol>
  
There's some hardcoding to do on a file<pre>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
+
== Diagnosis and Problems<ref>From [[Installation/Mac_OS/OpenFOAM_2.1.x]]</ref> ==
sudo nano src/renumber/SloanRenumber/Make/options</pre>
+
You can check if there are any errors by opening the file <tt>nameLog.log</tt> with a text editor and search for lines have the expression "Error " (including the space after the word "Error").<br>
 +
Keep in mind that if your terminal is returning error messages in another language, then you should search for the respective word for "Error".
  
Change this line:<bash> -L$(BOOST_ARCH_PATH)/lib -lboost_thread \</bash>
+
If you do find errors, the first one is usually the one to blame for all of the other errors.
into this:<bash>-L$(BOOST_ARCH_PATH)/lib -lboost_thread-mt \</bash> save and exit.
+
  
 
+
If you are still unable to figure out what's wrong, then:
Source the bashrc file:<pre>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
+
<ol>
. etc/bashrc </pre>
+
<li>Edit the file <tt>nameLog.log</tt> with a text editor, search and replace any sensitive information, such as user names and folder paths.</li>
 
+
<li>Rename the log file so that it is unique, preferably with data and user-name. For instance: <tt>log_20130401_bgschaid.log</tt></li>
Now we're ready to compile. Cross your fingers and do:<pre>#Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
+
<li>Pack the log file. For instance with [http://www.gzip.org/ GNU zip] if it is only a single file: <bash>gzip log_20130401_bgschaid.log</bash>
./Allwmake 2>&1 | tee logName.log</pre>
+
Only ''tarball'' it if there are additional files required to diagnose the problem:
where <tt>logName</tt> you should be replaced by a name for your log :P. Now take your time, call your mum, cook, take a shower and then come back to see if something went wrong.
+
<bash>tar -czf make.log_20130401_bgschaid.tar.gz make_20130401_bgschaid.log wmake/rules/darwinModified</bash></li>
 +
<li>Post the log in [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/ this forum], along with your question(s).</li>
 +
</ol>
  
 
== Paraview Installation ==  
 
== Paraview Installation ==  
  
Download the right package from [http://paraview.org/paraview/resources/software.php official Paraview website] and install it.
+
<ol>
 +
<li>Download the right package from [http://paraview.org/paraview/resources/software.php official Paraview website] and install it.
 +
</li>
 +
<li>Let's create a ''symlink'' to paraview executable in OpenFOAM to the one installed:
 +
<bash>#Current Folder ~/
 +
#NOTE: OpenFOAM {{tt|.sparseimage}} must be mounted and the etc/bashrc file sourced
  
Let's create a symlink to paraview executable in OpenFOAM to the one installed<pre>
+
ln -s /Applications/paraview/Contents/MacOS/paraview $WM_PROJECT_DIR/bin/paraview</bash>
#Current Folder ~/
+
</li>
#NOTE: OpenFOAM sparseimage must be mounted and the etc/bashrc file sourced
+
<li>The following command creates a file <tt>.alias</tt> where you can store aliases for commands:
 
+
<bash>#Current Folder ~/
ln -s /Applications/paraview/Contents/MacOS/paraview $WM_PROJECT_DIR/bin/paraview</pre>
+
sudo nano .alias</bash>
 
+
</li>
The following command creates a file <tt>.alias</tt> where you can store aliases for commands:<pre>
+
<li>Add the following lines to it:
#Current Folder ~/
+
<bash>alias paraFoam="paraFoam -builtin"</bash>
sudo nano .alias</pre>
+
</li>
 
+
<li>To auto-source the '''.alias''' at terminal start-up, edit the ''profile'' file:
Add the following lines to it,<bash>alias paraFoam="paraFoam -builtin"</bash>
+
<bash>#Current Folder ~/
 
+
To auto-source the '''.alias''' at terminal startup,<pre>#Current Folder ~/
+
 
sudo nano .profile  
 
sudo nano .profile  
#Or .bash_profile can work too</pre>
+
#Or .bash_profile can work too</bash>
 
+
</li>
add at the end of the file<bash>source ~/.alias</bash>
+
<li>Add the following line at the end of that file:
 
+
<bash>source ~/.alias</bash>
then save and exit.
+
</li>
 
+
<li>Then save and exit.
 +
</li>
 +
</ol>
  
 
== ''Permanent'' Installation ==  
 
== ''Permanent'' Installation ==  
You can set a terminal command to auto-mount the .sparseimage and auto-source the OF's bashrc this way <pre>
+
You can set a terminal command to auto-mount the {{tt|.sparseimage}} and auto-source the OF's bashrc this way:
#Current Folder ~/
+
sudo nano .alias
+
</pre>
+
 
+
add at the end of it:
+
<bash>
+
alias of222="/usr/bin/open ~/Documents/OpenFOAM-v2.2.2.sparseimage; sleep 1; . ~/OpenFOAM/OpenFOAM-2.2.2/etc/bashrc; . ~/.alias";
+
</bash>
+
 
+
Now, '''if your sparseimage is not mounted''' simply doing <pre> of222 </pre> will mount the OpenFOAM environment.
+
 
+
== Diagnosis and Problems<ref>From [[Installation/Mac_OS/OpenFOAM_2.1.x]]</ref> ==
+
You can check if there are any errors by opening the file <tt>nameLog.log</tt> with a text editor and search for lines have the expression "Error " (including the space after the word "Error").<br>
+
Keep in mind that if your terminal is returning error messages in another language, then you should search for the respective word for "Error".
+
 
+
If you do find errors, the first one is usually the one to blame for all of the other errors.
+
 
+
If you are still unable to figure out what's wrong, then:
+
 
<ol>
 
<ol>
<li>Edit the file <tt>nameLog.log</tt> with a text editor, search and replace any sensitive information, such as user names and folder paths.</li>
+
<li>Edit the {{tt|.alias}} file:
<li>Rename the log-file so that it is unique (preferable with data and unsername. For instance: <tt>log_20130401_bgschaid.log</tt>)</li>
+
<bash>#Current Folder ~/
<li>Pack the log file. For instance with GnuZIP if it is only a single file:<pre>gzip log_20130401_bgschaid.log</pre>
+
sudo nano .alias</bash>
Only ''tarball'' it if there are additional files required to diagnose the probelm:
+
</li>
<pre>tar -czf make.log_20130401_bgschaid.tar.gz make_20130401_bgschaid.log wmake/rules/darwinModified</pre></li>
+
<li>Add at the end of it:
<li> Post the log in [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/ this forum thread], along with your question(s).</li>
+
<bash>alias of222="/usr/bin/open ~/Documents/OpenFOAM-v2.2.2.sparseimage; sleep 1; . ~/OpenFOAM/OpenFOAM-2.2.2/etc/bashrc; . ~/.alias";</bash>
 +
</li>
 +
<li>Now, '''if your {{tt|.sparseimage}} is not mounted''', then simply doing:
 +
<bash>of222</bash>
 +
will mount the OpenFOAM environment.
 +
</li>
 
</ol>
 
</ol>
  
Line 216: Line 262:
 
----
 
----
 
<references/>
 
<references/>
 +
 +
[[Category:Installing OpenFOAM on Mac OS]]

Latest revision as of 12:53, 14 November 2016

1 Known Guides For Building OpenFOAM 2.2.2 on Mac OS X

The known guides for building OpenFOAM 2.2.2 on Mac OS X are as follows:

2 Introduction and Notes

This guide is derived from OpenFOAM 2.1.x Installation with some modifications, thanks to the help provided on this thread at CFD-Online's Forums.


These compiling instructions have only been tested on the following system:

Macbook (version 6,2)
Intel Core i7 2.66Ghz
Mac OS X Mavericks (version 10.9)

These instructions may need to be tailored to fit your specific system if they deviate from the above; you should be able to ask support on this thread if you needed it.

Many thanks go to Bernhard Gschaider (a.k.a. gschaider at CFD-Online's Forums) for maintaining the latest OpenFOAM Mac OS X patches and for the big help he provided me.

3 Prepare your Mac OS X Environment

3.1 Macports

To install Macports you need to install xCode, you can find it on the App Store. After xCode you need to install the Command Line Tools. Installing Command Line Tools for Mavericks is different from what you would do with previous OSX versions, as explained in the following subsections:

3.1.1 Command Line Tools for OSX 10.9 "Mavericks"

To install CLT on OSX 10.9 open a terminal application (for example Terminal.app) and run:

xcode-select --install

a window will be prompted where you can confirm installation.

3.1.2 Command Line Tools for OSX version < 10.9

In previous versions of OSX (and of xCode) you can download CLT directly from xCode Preferences > Downloads > Components.

3.1.3 xCode License

Now you should accept the xCode License so run, always in the Terminal (this could be needed only on OSX 10.9):

sudo xcodebuild -license

and when asked type "agree" to accept the license. Now xCode "things" should work correctly.

3.1.4 MacPorts Installation

Now to install Macports you can download the pre-compiled package from the Official Macports Website.

3.2 Build and Install the necessary software

To install all the tools we'll need run in Terminal:

sudo port selfupdate

Wait for the end of all operations then do:

sudo port install gcc46 openmpi boost cgal ccache flex bison

Now wait (a bit...)

4 OpenFOAM Building

4.1 Creation of Case Sensitive .sparseimage

Note: Images here shown are taken from Installation/Mac_OS/OpenFOAM_2.1.x, you could change the name of the sparse-image from OpenFOAM-v2.1 to OpenFOAM-v2.2.2 (and this will be assumed from here on).


First, we create a disk image with the Apple Disk Utility. Open /Applications/Utilities/Disk Utility. Click New Image:

Howto install OpenFOAM v21 Mac-images-010.ppm.png

It is important to set as Format: Mac OS Extended (Case-sensitive,Journaled). The sparse image will grow with the place used inside the image. Create a sparse image with the following settings (examples, you could change the values):

Howto install OpenFOAM v21 Mac-images-012.ppm.png


4.2 OpenFOAM sources and patches

Note: Remember that when you're inside the terminal you can auto-complete your commands pressing the TAB button.


Download OpenFOAM 2.2.2 sources from here and the 3 necessary patch files from one of the following places:

  1. From the original forum posts, download the patch files OpenFOAM-2.2.x-Mac_2014-02-17.patch and ThirdParty-2.2.x-Mac_2014-02-17.patch from post #108 (SurfaceCGALFix.patch from post #54 should not be longer needed with last updated patches).
  2. More updated patches could be possibly found on this CFD Online Thread.


Put everything inside the .sparseimage (you probably saved in ~/Documents).

  1. Open a Terminal, create a symlink to the OF image:
    ln -s /Volumes/OpenFOAM-v2.2.2 OpenFOAM
  2. Now we can go to OF directory just doing (from home directory):
    cd OpenFOAM
  3. Let's extract the two archives:
    tar -xvf OpenFOAM-2.2.2.tgz
    tar -xvf ThirdParty-2.2.2.tgz
  4. Now your OF directory should look like this:
    ****@mbp-di-ruben: ~/OpenFOAM$ ls -al
    total 182688
    drwxr-xr-x   8 ****  staff       612 13 Nov 02:49 .
    drwxrwxrwt@  5 root             admin       170 15 Nov 15:40 ..
    -rw-r--r--@  1 ****  staff     12292 13 Nov 03:13 .DS_Store
    d--x--x--x   6 ****  staff       238 15 Nov 15:40 .DocumentRevisions-V100
    drwxrwxrwt@  3 ****  staff       102 12 Nov 23:29 .TemporaryItems
    d-wx-wx-wt   2 ****  staff        68 12 Nov 14:43 .Trashes
    drwx------   2 ****  staff      2822 15 Nov 12:03 .fseventsd
    drwxr-xr-x@ 10 ****  staff       680 13 Nov 02:55 OpenFOAM-2.2.2
    -rw-r--r--@  1 ****  staff  32536146 12 Nov 21:09 OpenFOAM-2.2.2.tgz
    -rw-r--r--@  1 ****  staff     41620 13 Nov 02:49 OpenFOAM-2.2.x_Mac-20130309.patch
    -rw-r--r--@  1 ****  staff       691 13 Nov 02:49 SurfaceCGALFix.patch
    drwxr-x---@  7 ****  staff       782 13 Nov 02:54 ThirdParty-2.2.2
    -rw-r--r--@  1 ****  staff  58193818 12 Nov 21:09 ThirdParty-2.2.2.tgz
    -rw-r--r--@  1 ****  staff      2686 12 Nov 21:12 ThirdParty-2.2_patch
  5. Let's move the patches inside the right folders:
    # Current Folder: ~/OpenFOAM$ 
    mv OpenFOAM-2.2.x_Mac-20130309.patch OpenFOAM-2.2.2
    mv SurfaceCGALFix.patch OpenFOAM-2.2.2
    mv ThirdParty-2.2_Mac-20130309.patch Thirdparty-2.2.2
  6. Let's apply them:
    #Current Folder: ~/OpenFOAM
    cd OpenFOAM-2.2.2
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    patch -p1<OpenFOAM-2.2.x_Mac-20130309.patch
    patch -p1<SurfaCGALFix.patch
    cd ..
    #Current Folder: ~/OpenFOAM/
    cd ThirdParty-2.2.2
    #Current Folder: ~/OpenFOAM/ThirdParty-2.2.2
    patch -p1<ThirdParty-2.2_patch
    cd ..
    #Current Folder: ~/OpenFOAM/ 
     
  7. OpenFoam patch badly writes compilers symlinks so we have to fix:
    #Current Folder: ~/OpenFOAM/
    cd OpenFOAM-2.2.2
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    rm wmake/rules/darwinIntel64Gcc4*
    cd wmake/rules
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2/wmake/rules
    ln -s darwinIntel64Gcc/ darwinIntel64Gcc46
    cd ../..
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2 
     

4.3 Final Steps

  1. Let's give write permission to addr2line4Mac.py:
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    chmod a+x bin/addr2line4Mac.py
  2. Now we have to edit the bashrc file:
    sudo nano etc/bashrc
  3. Use CTRL+W to find these lines:
    export WM_COMPILER=Gcc
    export WM_MPLIB=OPENMPI

    and change them to:

    export WM_COMPILER=Gcc46
    export WM_MPLIB=SYSTEMOPENMPI
  4. At the end of this file, add:
    export WM_CC='gcc-mp-4.6'
    export WM_CXX='g++-mp-4.6'
    export WM_NCOMPPROCS=4
    ulimit -n 1024

    A few notes about the last two lines[1]:

    • Apparently it's best that you manually write these two lines instead of copy-pasting, because apparently some weird characters will show up on your file (source).
    • The first entry you should set to the number of processes your CPU could manage in parallel, e.g. 4, 8 or 16.
      • If you don't know how many your machine can handle, then run:
        sysctl -n hw.ncpu
    • The second entry is to increase the number of files which one process may open at a time.
  5. Save (CTRL+O and exit CTRL+X)
  6. Now we need a symlink for openmpirun (this can be useful with snappyHexMesh):
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    cd OpenFOAM/OpenFOAM-2.2.2/bin
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2/bin
    ln -s /opt/local/bin/openmpirun mpirun
    cd .. 
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2 
     
  7. There's some hard-coding to do on a file:
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    sudo nano src/renumber/SloanRenumber/Make/options
  8. Change this line:
    -L$(BOOST_ARCH_PATH)/lib -lboost_thread \

    into this:

    -L$(BOOST_ARCH_PATH)/lib -lboost_thread-mt \
    save and exit.
  9. Source the bashrc file:
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    . etc/bashrc
  10. Now we're ready to compile. Cross your fingers and do:
    #Current Folder: ~/OpenFOAM/OpenFOAM-2.2.2
    ./Allwmake 2>&1 | tee logName.log
    where logName should be replaced by a name for your log :P. Now take your time, call your mum, cook, take a shower and then come back to see if something went wrong.

5 Diagnosis and Problems[2]

You can check if there are any errors by opening the file nameLog.log with a text editor and search for lines have the expression "Error " (including the space after the word "Error").
Keep in mind that if your terminal is returning error messages in another language, then you should search for the respective word for "Error".

If you do find errors, the first one is usually the one to blame for all of the other errors.

If you are still unable to figure out what's wrong, then:

  1. Edit the file nameLog.log with a text editor, search and replace any sensitive information, such as user names and folder paths.
  2. Rename the log file so that it is unique, preferably with data and user-name. For instance: log_20130401_bgschaid.log
  3. Pack the log file. For instance with GNU zip if it is only a single file:
    gzip log_20130401_bgschaid.log

    Only tarball it if there are additional files required to diagnose the problem:

    tar -czf make.log_20130401_bgschaid.tar.gz make_20130401_bgschaid.log wmake/rules/darwinModified
  4. Post the log in this forum, along with your question(s).

6 Paraview Installation

  1. Download the right package from official Paraview website and install it.
  2. Let's create a symlink to paraview executable in OpenFOAM to the one installed:
    #Current Folder ~/
    #NOTE: OpenFOAM {{tt|.sparseimage}} must be mounted and the etc/bashrc file sourced
     
    ln -s /Applications/paraview/Contents/MacOS/paraview $WM_PROJECT_DIR/bin/paraview
  3. The following command creates a file .alias where you can store aliases for commands:
    #Current Folder ~/
    sudo nano .alias
  4. Add the following lines to it:
    alias paraFoam="paraFoam -builtin"
  5. To auto-source the .alias at terminal start-up, edit the profile file:
    #Current Folder ~/
    sudo nano .profile 
    #Or .bash_profile can work too 
     
  6. Add the following line at the end of that file:
    source ~/.alias
  7. Then save and exit.

7 Permanent Installation

You can set a terminal command to auto-mount the .sparseimage and auto-source the OF's bashrc this way:

  1. Edit the .alias file:
    #Current Folder ~/
    sudo nano .alias
  2. Add at the end of it:
    alias of222="/usr/bin/open ~/Documents/OpenFOAM-v2.2.2.sparseimage; sleep 1; . ~/OpenFOAM/OpenFOAM-2.2.2/etc/bashrc; . ~/.alias";
  3. Now, if your .sparseimage is not mounted, then simply doing:
    of222

    will mount the OpenFOAM environment.



  1. From Installation/Mac_OS/OpenFOAM_2.1.x
  2. From Installation/Mac_OS/OpenFOAM_2.1.x