Skip to content

ErikNij/EddyCurrentFoam-5.0

Repository files navigation

How to install eddyCurrentFoam

This guide will walk you through the intallation of eddyCurrentFoam

  1. Install and open multipass
  • spin up a ubuntu 22.04 instance with something like:
 multipass launch 22.04 --cpus 24 --disk 100G --memory 64G
  • open the instance
multipass shell instace-name 
  • you may choose to create a folder share, however it is not needed. Further tips on using multipass are shown in a later section.
  1. Follow the installion instruction for foam-extend 5.0 from this

  2. Now we will install eddyCurrentFoam (User folder setup)

cd $HOME/foam 
git clone https://github.com/ErikNij/EddyCurrentFoam-5.0.git
mkdir "$USER-5.0"
mv EddyCurrentSolver/* "$USER-5.0"
rm -r EddyCurrentSolver/

Now we need to setup before instaliation

export FE50_FOAM_INST_DIR="$HOME/foam"
export FE50_FOAM_ETC="$FE50_FOAM_INST_DIR/foam-extend-5.0/etc"
export FE50_FOAM_USER_ETC="$HOME/foam/$USER-5.0/etc"
source "$FE50_FOAM_USER_ETC/bashrc"

fe50user
  1. Now we will complie the user folder
cd "$HOME/foam/$USER-5.0"

./Allwmake.firstInstall | tee 'Allwmake.firstInstall.log'
./Allwmake

Note: Depending on your exact version of foam-extend 5, you might need to change one thing in the core foam-extend libary. Follow the steps below if you get an error that looks like the one shown in Appendix 1, then should should follow the steps. This is a bug that I found and is explained in more detail here However it is fixed in the current release.

  1. Go to foam/foam-extend-5.0/src/foam/lnInclude/FieldField.C
  2. Go to line ~line 321
  3. Change forAll (this, i) to forAll (*this, i)
  4. Save and recomplie

At this point, you should have a working foam-extend instaliation! You can test this by running eddyCurrentFoam you should see it start, but of course error because we are not in a file.

How to use eddyCurrentFoam

Before we can use eddyCurrentFoam, we need to do a few other things.

Installing another version of OpenFOAM

To create the meshes, some snappyHexMesh features that are only avaible in OpenFOAM (.org and .com) are used. So we will have to get one of those as well. For this instillation guide, we will get .com.

Simply follow the instruction at the top of this page. In short, we will install the precompiled version with the following command

# Add the repository
curl https://dl.openfoam.com/add-debian-repo.sh | sudo bash

# Update the repository information
sudo apt-get update

# Install preferred package. Eg,
sudo apt-get install openfoam2406-default

We don't want to use a shell enviornment, instead, we want to switch in and out quickly, so will just source it.

source /usr/lib/openfoam/openfoam2406/etc/bashrc

You can see if the instailation was succesful by doing something like simpleFoam, and checking to see if it is running OpenFOAM.com or foam-extend.

There is one thing that we need to add to this version of OpenFOAM, and that is a short script to convert compactFace to Face, as compact faces are the norm in this version of OpenFOAM, however they do not exist in foam-extend. To this we need to make the user folder, and get the code.

mkdir $FOAM_USER_APPBIN -p
cd $FOAM_USER_APPBIN/../../../
git clone https://github.com/petebachant/compactFaceToFace.git

Then we need to make the new tool.

cd compactFaceToFace
wmake

Furthermore, we need to setup the python enviornment. First, let us ensure that pip is installed and up-to-date. After that, we will need to install PyFoam and scipy

sudo apt install python3-pip
python3 -m pip install PyFoam scipy

Now we have everything installed!

Running the tutorial case

Whenever you restart your terminal, you will need to re-source foam-extend, this is done with he following commands. You may consider creating a script to do this.

export FE50_FOAM_INST_DIR="$HOME/foam"
export FE50_FOAM_ETC="$FE50_FOAM_INST_DIR/foam-extend-5.0/etc"
export FE50_FOAM_USER_ETC="$HOME/foam/$USER-5.0/etc"
source "$FE50_FOAM_USER_ETC/bashrc"

fe50user

Then we can copy the tutorial case to your home folder to run it.

cd $FOAM_RUN
mkdir eddyCurrentSimulations
cd eddyCurrentSimulations
cp -r $FOAM_USER_TUTORIALS/electromagnetics/inductionHeating .
cd inductionHeating

Then we can clean the case (although it should already be cleaned) and create the coil.

./Allclean
./Allrun.coil

In the following section, we will create the mesh. This is done with OpenFOAM, so we need to source it, and then run the meshing script. You may also consider creating an alis for the sourcing.

source /usr/lib/openfoam/openfoam2406/etc/bashrc
./Allrun.mesh

After the mesh has been created, we need to go back to foam-extend, which we can do with the end of the sourcing command. Then we can prepare and run the case.

source "$FE50_FOAM_USER_ETC/bashrc"
fe50user

./Allrun prepare
eddyCurrentFoam

Understanding and using eddyCurrentFoam

In general, eddyCurrentFoam works similar to any other OpenFOAM solver, however there are many other quirks about the solver. This section details what you can change in the solver, and how to change it.

Changing the background mesh

Instead of changing the blockMeshDict, go to constant/polyMesh.org/blockMeshDict.py Here you can change the size of the background.

Changing the accuracy level

If you want to add or remove cells to make the simulation, good news, I am writing/ have written an entire paper about this. The tl;dr is that to increase accuracy you should increment "nCellsBetweenLevels" and the maximum refinement amount by 1. For the case of a skin depth of 1.15 mm n=3 and l=4 is a good starting point. If your simulation has a differnt skin depth (as calculated by 503sqrt(1/F/sigma) then you need to adjust the "ideal" mesh. If your skin depth is equal to 2^x1.15 mm then your l = 4 - x. n should remain the same! (Unless you also want to change the accuracy.)

Changing the coil

To change the induction coil, go to constant/featureEdgeMesh.org/coil.py. Here you can change the number of turns, the wire radius, the coild radius, as well as change if the coil is conneccted or seperate loops. Furthermore, the coil radius does not need to be constant, it can be sqaure. The coil can also be shfted in any direction. The exact way to achive these effects are mentioned in the file itself. It is worth noting if you change the number of loops, you also need to change edgeBiotSavartProperties file. You simply need to copy + paste the coil object, and rename it from coil0 to coiln. The frequency and current in the coil can also be changed in the edgeBiotSavartProperties file.

Creating a custom mesh

This method will use blender to prepare a given workpeice STL for use in eddyCurrentFoam. The STL can come from any source, including blender itself. EddyCurrentFoam requires the workpeice (WP) itself, as well as an inverse of the STL in a small region around the WP. This is not strictly nessarcy, and can be removed by editing the snappyHexMeshDict, however it helps add some refinement around WP, where the magnetic feild has a large gradient.

To obtain the inverse, simply load the WP STL in blender, add a cube or cylinder that encompasses the space around the WP. The boolean modifer can be used to create the inverse. To do this, go to modifers > boolean. Ensure that difference is selected, and that the target object is the WP. Now you simply need to export the "buffer" as an STL. This can be done by selecting the buffer, file > export as > stl.

The WP and buffer should be named geometry_conductor.stl and geometry_buffer.stl respectively and should be put in constant > trimesh folder.

It is worth noting that the WP must be manifold for snappyHexMesh to work. If your WP is not manifold, there are 2 things that you can do to make it manifold. Firstly, you can apply the remesh modifer, and decrease the voxel size untill you are satisfied with the result. However, this method might decrease mesh quality in snappyHexMesh. Another possiblity is to use the 3D print toolbox to make the STL hollow and make it manifold, however I have not tried this.

Tips, tricks, and runtime debugging

If the solver fails, here are some things to check.

  1. If it fails around the trying to calculate the A0, then your coil could be ill defined. Make sure that the coil r is slightly greater than x & y.

  2. If the snappyHexMesh fails saying: --> FOAM FATAL ERROR: (openfoam-2212) Shell geometry_buffer.stl does not support testing for inside Probably it is not closed.

    Then, you either have an open mesh, or overlapping meshs. Open meshs can be fixed by looking up online, however this is rarly the problem. Often, your mesh have overlapping sections. To fix this, load up the stl of your workpeice, and in blender choose the remesh modifer under generate. Keep the mode on voxel, and decrease the voxel size until you are happy with the result. Note: make sure to do this before doing the boolean with the buffer, as remeshing while having the boolean on takes a lot more computing power.

  3. If your resulting WP mesh is not smooth when you expect it to be, like this, then it could be a problem with the set mesh region. Instead of only looking at the conductor in paraview, look at the entire internal mesh, you will see your WP, however the conductivity is not set correctly. If this is the case, then it is a problem with setSetBatch. This sets the regions that are used later to set the conductivity and split the domain. If you open setSetBatch in the system folder, you will see the pointSet command, this is where points get assigned to a region. All you have to do it set the tolerance to be lower. The tolerance should be a bit lowerer then the size of a cell at the edge (in the r direction). Note: the tolerance can also be set too low, it has to just be a bit lower than the cell size.

How to work on multipass

Multipass is really nice, but it is sometimes hard to use your work flow, as it does not have a dedicated ip. The solution that I have found it to foward a port to the machine. This is only needed if there are 3 machines.

  1. the access computer (a students laptop with wsl, linux, mobaXTerm)
  2. the workstation where the multipass is installed that is hosting the VM
  3. The Multipass instace that we want to access

Students or users can of course ssh into the workstation, and then ssh into the multipass instace, however for other applications like VSCode, MobaXTerm, and paraview, this might not work. To solve this, we will foward some ports from the workstation to the instace.

To do this, follow these steps.

1. Log into the workstation and get the ip of the multipass instace, which should look something like this:

erik@tue123456:~$ multipass list
Name                    State             IPv4             Image

fancy-peccary           Running           10.215.150.200   Ubuntu 22.04 LTS

2. Foward a port to the default ssh port of the VM

ssh -L 2222:localhost:22 -N -o GatewayPorts=yes ubuntu@10.215.150.200

Here, the fowarded port is 2222, however it can be any port that is not in use. Ports that are in use can be seen with ss -tulpn.

22 is the destianation port, in this case the defualt port for ssh.

ubuntu@10.215.150.200 is the username of the VM, and the ip adreeses that was recvied eariler.

To verify your implimentation, you can do ss -tulpn, and you should see the mentioned ports on listnen and fowarding. You can also do ssh ubuntu@localhost -p 2222, and you should reach the VM

With multipass, the users do not have a password, which might make connecting to an ssh client not possible. To solve this issue, you can add a password, and/or use ssh keys.

To use ssh keys, you need to generate an ssh on the connecting machine, and put the public key into the trusted machine.

To do this, do the following steps on the workstation and the access computer.

Only do the following step if the workstation or access computer does not already have a rsa key! Generate a key with:

ssh-keygen

press enter a few times and a key will be generated.

Obtain that key with:

cat ~/.ssh/id_rsa.pub

should return a long key, copy that and go to the multipass instance (via multipass shell instance-name)

Input that key into trusted key on the multipass instance.

nano ~/.ssh/authorized_keys

and paste the key into the end of the file.

Now you should be able to access the multipass instance without a password.

3. Access the VM from an external computer

From here, we can use what we have setup. Firstly, from your access computer, you can should be able to do the following.

ssh ubuntu@tue123456.chem.tue.nl -p 2222

This should put you directly into the multipass instance. Of course you could have just ssh'ed into the workstation and then done multipass shell, however now all sorts of software can connect to the VM. For example, you can simply copy the previous command gain access with VSCode, as it operates via normal ssh. Something similar can be done for paraview, however for this, the target port should be 1111, as that is the default port for a pv server. Furthermore, one should make sure to not reuse the exposed port of 2222 again.

You can also add this location to your file explorer, for example by adding a new server with the location of ssh://ubuntu@tue123456.chem.tue.nl:2222

Setting up paraview server

First, install paraview. Do this on the multipass instance and local computer.

sudo apt install paraview

On the host workstation, foward a port (in this case 12345) to the default port of paraview, 1111, on the multipass instace, for example:

ssh -L 12345:localhost:11111 -N -o GatewayPorts=yes ubuntu@10.215.150.200

You can make this persistent with by prefixing nohup, and appending it with &.

Now, start the paraview server on the multipass instance with pvserver and launch the client on your machine with paraview. From here, you can add a server. The host will look like 10.215.150.200 and the port should be whatever port you are fowarding 12345.

Note: when the screen saying connecing shows up, you might need to click the x in the top right before it connects. This seems like a bug.

To view the case, open and navigate to the .foam file by going the top left>open then navigate to the folder, and open the .foam file. Before clicking apply, I suggest that you only render the workpeice. This can be done by going the mesh regions on the left side, deslecting everything, and only selecting the region_conductor.

Appendix

Appendix 1

Error messgae that indiates that you should change a line in FieldField.c

In file included from /home/ubuntu/foam/foam-extend-5.0/src/foam/lnInclude/List.H:43,
                 from /home/ubuntu/foam/foam-extend-5.0/src/foam/lnInclude/HashTable.C:30,
                 from /home/ubuntu/foam/foam-extend-5.0/src/foam/lnInclude/HashTable.H:557,
                 from eddyCurrentApp/eddyCurrentAppInclude.H:36,
                 from eddyCurrentApp/eddyCurrentApp.H:35,
                 from eddyCurrentFoam.C:35:
/home/ubuntu/foam/foam-extend-5.0/src/foam/lnInclude/FieldField.C: In instantiation of ‘void Foam::FieldField<Field, Type>::operator=(const Foam::tmp<Foam::FieldField<Field, Type> >&) [with Field = Foam::Field; Type = double]’:
include/AVLoop_AEqn.H:150:81:   required from here
/home/ubuntu/foam/foam-extend-5.0/src/foam/lnInclude/UList.H:411:36: error: request for member ‘size’ in ‘(Foam::FieldField<Foam::Field, double>*)this’, which is of pointer type ‘Foam::FieldField<Foam::Field, double>*’ (maybe you meant to use ‘->?)
  411 |     for (Foam::label i=0; i<(list).size(); i++)
      |                             ~~~~~~~^~~~
/home/ubuntu/foam/foam-extend-5.0/src/foam/lnInclude/FieldField.C:321:5: note: in expansion of macro ‘forAll’
  321 |     forAll (this, i)
      |     ^~~~~~
make[1]: *** [eddyCurrentFoam.dep:874: Make/linux64GccDPInt32Opt/eddyCurrentFoam.o] Error 1
make[1]: Target '/home/ubuntu/foam/ubuntu-5.0/applications/bin/linux64GccDPInt32Opt/eddyCurrentFoam' not remade because of errors.
make: *** [/home/ubuntu/foam/foam-extend-5.0/wmake/MakefileApps:39: eddyCurrentFoam] Error 2
make: Target 'application' not remade because of errors.
+ exit 1
+ exit 1

About

eddyCurrentFoam updated for fe50

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors