Skip to content

Commit

Permalink
Channel transport with OpenFOAM (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirgendetwas authored Aug 15, 2023
1 parent bddfd5e commit 1a1f2d5
Show file tree
Hide file tree
Showing 15 changed files with 497 additions and 24 deletions.
2 changes: 2 additions & 0 deletions channel-transport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Fluid participant:

* Nutils. For more information, have a look at the [Nutils adapter documentation](https://www.precice.org/adapter-nutils.html). This Nutils solver requires at least Nutils v7.0.

* OpenFOAM (pimpleFoam). For more information, have a look at the [OpenFOAM adapter documentation](https://precice.org/adapter-openfoam-overview.html).

Transport participant:

* Nutils. For more information, have a look at the [Nutils adapter documentation](https://www.precice.org/adapter-nutils.html). This Nutils solver requires at least Nutils v7.0.
Expand Down
25 changes: 13 additions & 12 deletions channel-transport/fluid-nutils/fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def main():

print("Running utils")
print("Running Nutils")

# define the Nutils mesh
nx = 48
Expand Down Expand Up @@ -55,18 +55,18 @@ def main():
cons = solver.optimize(["u"], sqr, droptol=1e-15)

# preCICE setup
interface = precice.Interface("Fluid", "../precice-config.xml", 0, 1)
participant = precice.Participant("Fluid", "../precice-config.xml", 0, 1)

# define coupling mesh
mesh_name = "Fluid-Mesh"
mesh_id = interface.get_mesh_id(mesh_name)
vertices = gauss.eval(ns.x)
vertex_ids = interface.set_mesh_vertices(mesh_id, vertices)
vertex_ids = participant.set_mesh_vertices(mesh_name, vertices)

# coupling data
velocity_id = interface.get_data_id("Velocity", mesh_id)
data_name = "Velocity"

precice_dt = interface.initialize()
participant.initialize()
precice_dt = participant.get_max_time_step_size()

timestep = 0
dt = 0.005
Expand All @@ -76,14 +76,16 @@ def main():
# add convective term and time derivative for Navier-Stokes
ures += gauss.integral("ubasis_ni (dudt_i + μ (u_i u_j)_,j) d:x" @ ns)

while interface.is_coupling_ongoing():
while participant.is_coupling_ongoing():

if timestep % 1 == 0: # visualize
bezier = domain.sample("bezier", 2)
x, u, p = bezier.eval(["x_i", "u_i", "p"] @ ns, **state)
with log.add(log.DataLog()):
export.vtk("Fluid_" + str(timestep), bezier.tri, x, u=u, p=p)

precice_dt = participant.get_max_time_step_size()

# potentially adjust non-matching timestep sizes
dt = min(dt, precice_dt)

Expand All @@ -92,17 +94,16 @@ def main():
state["dt"] = dt
state = solver.newton(("u", "p"), (ures, pres), constrain=cons, arguments=state).solve(1e-10)

if interface.is_write_data_required(dt):
velocity_values = gauss.eval(ns.u, **state)
interface.write_block_vector_data(velocity_id, vertex_ids, velocity_values)
velocity_values = gauss.eval(ns.u, **state)
participant.write_data(mesh_name, data_name, vertex_ids, velocity_values)

# do the coupling
precice_dt = interface.advance(dt)
participant.advance(dt)

# advance variables
timestep += 1

interface.finalize()
participant.finalize()


if __name__ == "__main__":
Expand Down
39 changes: 39 additions & 0 deletions channel-transport/fluid-openfoam/0/U
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}

dimensions [0 1 -1 0 0 0 0];
internalField uniform (10 0 0);

boundaryField
{
inlet
{
type fixedValue;
value $internalField;
}
outlet
{
type zeroGradient;
}
obstacle
{
type noSlip;
}
upperWall
{
type noSlip;
}
lowerWall
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
45 changes: 45 additions & 0 deletions channel-transport/fluid-openfoam/0/p
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}

dimensions [0 2 -2 0 0 0 0];

internalField uniform 0;

boundaryField
{
inlet
{
type zeroGradient;
}

outlet
{
type fixedValue;
value uniform 0;
}

obstacle
{
type zeroGradient;
}

upperWall
{
type zeroGradient;
}

lowerWall
{
type zeroGradient;
}

frontAndBack
{
type empty;
}
}
6 changes: 6 additions & 0 deletions channel-transport/fluid-openfoam/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e -u

. ../../tools/cleaning-tools.sh

clean_openfoam .
11 changes: 11 additions & 0 deletions channel-transport/fluid-openfoam/constant/transportProperties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object transportProperties;
}

transportModel Newtonian;

nu nu [ 0 2 -1 0 0 0 0 ] 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object turbulenceProperties;
}

simulationType laminar;
8 changes: 8 additions & 0 deletions channel-transport/fluid-openfoam/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e -u

blockMesh
touch fluid-openfoam.foam

../../tools/run-openfoam.sh "$@"
. ../../tools/openfoam-remove-empty-dirs.sh && openfoam_remove_empty_dirs
146 changes: 146 additions & 0 deletions channel-transport/fluid-openfoam/system/blockMeshDict
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}

x0 0.;
x1 2.;
x2 3.;
x3 6.;

y0 0.;
y1 1.;
y2 2.;

z0 0;
z1 1;

vertices
(
($x0 $y0 $z0 ) // 0
($x1 $y0 $z0 ) // 1
($x2 $y0 $z0 ) // 2
($x3 $y0 $z0 ) // 3
($x0 $y1 $z0 ) // 4
($x1 $y1 $z0 ) // 5
($x2 $y1 $z0 ) // 6
($x3 $y1 $z0 ) // 7
($x0 $y2 $z0 ) // 8
($x1 $y2 $z0 ) // 9
($x2 $y2 $z0 ) // 10
($x3 $y2 $z0 ) // 11

($x0 $y0 $z1 ) // 12
($x1 $y0 $z1 ) // 13
($x2 $y0 $z1 ) // 14
($x3 $y0 $z1 ) // 15
($x0 $y1 $z1 ) // 16
($x1 $y1 $z1 ) // 17
($x2 $y1 $z1 ) // 18
($x3 $y1 $z1 ) // 19
($x0 $y2 $z1 ) // 20
($x1 $y2 $z1 ) // 21
($x2 $y2 $z1 ) // 22
($x3 $y2 $z1 ) // 23
);


// Grading
h1 16;
h2 8;
h3 24;
v1 8;

blocks
(
hex ( 0 1 5 4 12 13 17 16 )
($h1 $v1 1 )
simpleGrading (1 1 1)

hex ( 2 3 7 6 14 15 19 18 )
($h3 $v1 1)
simpleGrading (1 1 1)

hex ( 4 5 9 8 16 17 21 20 )
($h1 $v1 1)
simpleGrading (1 1 1)

hex ( 5 6 10 9 17 18 22 21 )
($h2 $v1 1)
simpleGrading (1 1 1)

hex ( 6 7 11 10 18 19 23 22 )
($h3 $v1 1 )
simpleGrading (1 1 1)
);

boundary
(
inlet
{
type patch;
faces
(
( 0 4 16 12 )
( 4 8 20 16 )
);
}
outlet
{
type patch;
faces
(
( 3 7 19 15 )
( 7 11 23 19 )
);
}
obstacle
{
type wall;
faces
(
( 1 5 17 13 )
( 5 6 18 17 )
( 6 2 14 18 )
);
}
upperWall
{
type wall;
faces
(
( 8 9 21 20 )
( 9 10 22 21 )
( 10 11 23 22 )
);
}
lowerWall
{
type wall;
faces
(
( 0 1 13 12 )
( 2 3 15 14 )
);
}
frontAndBack
{
type empty;
faces
(
( 0 1 5 4 )
( 2 3 7 6 )
( 4 5 9 8 )
( 5 6 10 9 )
( 6 7 11 10 )
( 12 13 17 16 )
( 14 15 19 18 )
( 16 17 21 20 )
( 17 18 22 21 )
( 18 19 23 22 )
);
}
);
44 changes: 44 additions & 0 deletions channel-transport/fluid-openfoam/system/controlDict
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}

application pimpleFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

endTime 1.0;

deltaT 0.005;

writeControl adjustableRunTime;

writeInterval 0.005;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression off;

timeFormat general;

timePrecision 6;

functions
{
preCICE_Adapter
{
type preciceAdapterFunctionObject;
libs ("libpreciceAdapterFunctionObject.so");
}
}
Loading

0 comments on commit 1a1f2d5

Please sign in to comment.