-
-
Notifications
You must be signed in to change notification settings - Fork 129
AxialGeoMultiscale Tutorial #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ezonta
wants to merge
20
commits into
precice:develop
Choose a base branch
from
ezonta:GeoMultiScaleTutorial
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bc4de13
Add first try at GeoMultiScale tutorial
ezonta dca346c
Delete config.pdf
ezonta 6253047
Remove results VTK
ezonta 4e7b216
Clean tutorial case
ezonta d0e455b
Add working runFluid3D script and clean up
ezonta 4edcd6e
Rename folders and participants and clean up
ezonta eb65306
Add Nutils script and format files
ezonta aa8fe2f
Remove old 1D script
ezonta 158047e
Update partitioned-pipe-multiscale/fluid3d-openfoam/constant/transpor…
MakisH 20a6ead
Merge branch 'develop' into GeoMultiScaleTutorial
MakisH c44b28d
Remove stray log file
MakisH 88d3ada
Update run.sh and clean.sh scripts
MakisH 8b256a3
Port precice-config.xml to v3
MakisH 7bbaba6
Nutils: Add a venv and a requirements.txt
MakisH 3d70e46
Add clean-tutorial.sh
MakisH 05d1667
Rename .gitkeep to .gitignore
MakisH 2612a99
Port Fluid1D.py to preCICE v3
MakisH 6462bd8
Update config visualization
MakisH 6e622a9
Fix shape of wrte_vel
MakisH 06b72de
Remove duplicate .foam file
MakisH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| title: Partitioned Pipe Multiscale | ||
| permalink: tutorials-partitioned-pipe-multiscale.html | ||
| keywords: OpenFOAM, python | ||
| summary: The 1D-3D Partitioned Pipe is a simple geometric multiscale case, that consists of flow between two pipes with heterogeneous dimensionality. The flow is incompressible and laminar. This tutorial contains an OpenFOAM case for the 3D participant and Python solver for the 1D participant. | ||
| --- | ||
|
|
||
| {% note %} | ||
| Get the [case files of this tutorial](https://github.com/ezonta/tutorials/tree/GeoMultiScaleTutorial/1D-3D-partitioned-pipe). Read how in the [tutorials introduction](https://www.precice.org/tutorials.html). | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {% endnote %} | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - preCICE | ||
| - Python bindings of preCICE | ||
| - OpenFOAM together with the OpenFOAM adapter of preCICE | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Setup | ||
|
|
||
| We exchange velocity data from the 1D to the 3D participant and for the pressure data vice versa. The config looks as follows: | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## How to run | ||
|
|
||
| In two different terminals execute | ||
|
|
||
| ```bash | ||
| cd fluid1d-python && ./run.sh | ||
ezonta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ```bash | ||
| cd fluid3d-openfoam && ./run.sh | ||
| ``` | ||
|
|
||
| ## Results | ||
|
|
||
| You should be able to see an established laminar profile at the inlet of the 3D participant. | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| from numpy.core.fromnumeric import reshape | ||
| # TODO: uncomment for vtk output | ||
| # from evtk.hl import pointsToVTK | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import numpy as np | ||
| import precice | ||
|
|
||
| def main(): | ||
|
|
||
| # number of nodes, length of domain and space interval | ||
|
|
||
| length = 10 | ||
MakisH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| n = 20 | ||
| h = 1 / n | ||
| t = 0 | ||
| counter = 0 | ||
|
|
||
| # generate mesh | ||
|
|
||
| x = np.zeros(n+1) | ||
| y = np.zeros(n+1) | ||
| z = np.linspace(0,length,n+1) | ||
|
|
||
| # initial data | ||
|
|
||
| u = np.zeros((n+1,3)) | ||
| p = np.zeros(n+1) | ||
| rhs = np.zeros(n+1) | ||
|
|
||
| # preCICE setup | ||
|
|
||
| participant_name = "Fluid1D" | ||
| config_file_name = "./precice-config.xml" | ||
MakisH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| solver_process_index = 0 | ||
| solver_process_size = 1 | ||
| interface = precice.Interface(participant_name, config_file_name, solver_process_index, solver_process_size) | ||
|
|
||
| mesh_name = "Fluid1D-Mesh" | ||
| mesh_id = interface.get_mesh_id(mesh_name) | ||
|
|
||
| velocity_name = "Velocity" | ||
| velocity_id = interface.get_data_id(velocity_name, mesh_id) | ||
|
|
||
| pressure_name = "Pressure" | ||
| pressure_id = interface.get_data_id(pressure_name, mesh_id) | ||
|
|
||
| positions = [0, 0, 0] | ||
|
|
||
| vertex_ids = interface.set_mesh_vertex(mesh_id, positions) | ||
|
|
||
| precice_dt = interface.initialize() | ||
|
|
||
|
|
||
| while interface.is_coupling_ongoing(): | ||
| if interface.is_action_required( | ||
| precice.action_write_iteration_checkpoint()): | ||
|
|
||
| u_iter = u | ||
| p_iter = p | ||
| t_iter = t | ||
| counter_iter = counter | ||
|
|
||
| interface.mark_action_fulfilled( | ||
| precice.action_write_iteration_checkpoint()) | ||
|
|
||
| # determine time step size | ||
|
|
||
| dt = 0.025 | ||
| dt = np.minimum(dt,precice_dt) | ||
|
|
||
| # set boundary conditions | ||
|
|
||
| u[0,2] = 1 | ||
| # u[1,2] = 1 # dirichlet velocity inlet | ||
|
|
||
| u[-1,2] = u[-2,2] # neumann velocity outlet | ||
|
|
||
| p[0] = p[1] # neumann pressure inlet | ||
| # p[-1] = 0 # dirichlet pressure outlet | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if interface.is_read_data_available(): # get dirichlet pressure outlet value from 3D solver | ||
| p_read_in = interface.read_scalar_data(pressure_id, vertex_ids) | ||
| p[-1] = p_read_in | ||
| else: | ||
| p[-1] = 0 | ||
|
|
||
| # compute right-hand side of 1D PPE | ||
|
|
||
| for i in range(n-1): | ||
|
|
||
| rhs[i+1] = (1 / dt) * ((u[i+2,2] - u[i,2]) / 2*h) | ||
|
|
||
| # solve the PPE using a SOR solver | ||
|
|
||
| tolerance = 0.001 | ||
| error = 1 | ||
| omega = 1.7 | ||
| max_iter = 1000 | ||
| iter = 0 | ||
|
|
||
| while error >= tolerance: | ||
|
|
||
| p[0] = p[1] # renew neumann pressure inlet | ||
|
|
||
| for i in range(n-1): | ||
| p[i+1] = (1-omega) * p[i+1] + ((omega * h**2) / 2) * (((p[i] + p[i+2]) / h**2) - rhs[i+1]) | ||
|
|
||
| sum = 0 | ||
| for i in range(n-1): | ||
| val = ((p[i] - 2*p[i+1] + p[i+2]) / h**2) - rhs[i+1] | ||
| sum += val*val | ||
|
|
||
| error = np.sqrt(sum/n) | ||
|
|
||
| iter += 1 | ||
| if iter >= max_iter: | ||
| print("SOR solver did not converge.\n") | ||
| break | ||
|
|
||
|
|
||
| # calculate new velocities | ||
|
|
||
| for i in range(n-1): | ||
| u[i+1,2] = u[i+1,2] - dt * ((p[i+2] - p[i+1]) / h) | ||
|
|
||
|
|
||
| # write velocity to 3D solver | ||
|
|
||
| write_vel = u[-2,:] | ||
|
|
||
| if interface.is_write_data_required(dt): # write new velocities to 3D solver | ||
| interface.write_vector_data( | ||
| velocity_id, vertex_ids, write_vel) | ||
|
|
||
| # transform data and write output data to vtk files | ||
|
|
||
| u_print = np.reshape(u[:,2], n+1) | ||
| p_print = np.reshape(p, n+1) | ||
|
|
||
| u_print = np.ascontiguousarray(u_print, dtype=np.float32) | ||
| p_print = np.ascontiguousarray(p_print, dtype=np.float32) | ||
|
|
||
| filename = "./results/Fluid1D_" + str(counter) | ||
|
|
||
| # TODO: uncomment if pyEVTK is installed and vtk output of 1D participant is wanted | ||
| # pointsToVTK(filename, x, y, z, data = {"U" : u_print, "p" : p_print}) | ||
|
|
||
| # advance simulation time | ||
|
|
||
| dt = interface.advance(dt) | ||
| t = t + dt | ||
| counter += 1 | ||
|
|
||
| if interface.is_action_required( | ||
| precice.action_read_iteration_checkpoint()): | ||
|
|
||
| u = u_iter | ||
| p = p_iter | ||
| t = t_iter | ||
| counter = counter_iter | ||
|
|
||
| interface.mark_action_fulfilled( | ||
| precice.action_read_iteration_checkpoint()) | ||
|
|
||
| interface.finalize() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/sh | ||
|
|
||
| rm ./results/Fluid1D_* |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/sh | ||
|
|
||
| cd .. | ||
| ./fluid1d-python/Fluid1D.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class volVectorField; | ||
| location "0"; | ||
ezonta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| object U; | ||
| } | ||
|
|
||
| dimensions [0 1 -1 0 0 0 0]; | ||
|
|
||
| internalField uniform (0 0 0); | ||
|
|
||
| boundaryField | ||
| { | ||
| inlet | ||
| { | ||
| type fixedValue; | ||
| value $internalField; | ||
| } | ||
| outlet | ||
| { | ||
| type fixedGradient; | ||
| gradient uniform (0 0 0); | ||
| } | ||
| fixedWalls | ||
| { | ||
| type noSlip; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class volScalarField; | ||
| object p; | ||
| } | ||
|
|
||
| dimensions [0 2 -2 0 0 0 0]; | ||
|
|
||
| internalField uniform 0; | ||
|
|
||
| boundaryField | ||
| { | ||
| inlet | ||
| { | ||
| type fixedGradient; | ||
| gradient uniform 0; | ||
| } | ||
|
|
||
| outlet | ||
| { | ||
| type fixedValue; | ||
| value uniform 0; | ||
| } | ||
|
|
||
| fixedWalls | ||
| { | ||
| type zeroGradient; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...-pipe-multiscale/fluid3d-openfoam/0.orig/uniform/functionObjects/functionObjectProperties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /*--------------------------------*- C++ -*----------------------------------*\ | ||
| | ========= | | | ||
| | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | ||
| | \\ / O peration | Version: 2106 | | ||
| | \\ / A nd | Website: www.openfoam.com | | ||
| | \\/ M anipulation | | | ||
| \*---------------------------------------------------------------------------*/ | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| arch "LSB;label=32;scalar=64"; | ||
| class dictionary; | ||
| location "0/uniform/functionObjects"; | ||
| object functionObjectProperties; | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
|
||
|
|
||
|
|
||
| // ************************************************************************* // | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/bin/sh | ||
| cd ${0%/*} || exit 1 # Run from this directory | ||
|
|
||
| echo "Cleaning..." | ||
ezonta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Source tutorial clean functions | ||
| . $WM_PROJECT_DIR/bin/tools/CleanFunctions | ||
|
|
||
| Participant2="Fluid3D" | ||
|
|
||
| # Clean the case | ||
| cleanCase | ||
| rm -rfv 0 | ||
| # Create an empty .foam file for ParaView | ||
| # Note: ".foam" triggers the native OpenFOAM reader of ParaView. | ||
| # Change to ".OpenFOAM" to use the OpenFOAM reader provided with OpenFOAM. | ||
| touch ${Participant2}.foam | ||
| cd .. | ||
| # Remove the log files | ||
| rm -fv ${Participant2}_blockMesh.log | ||
| rm -fv ${Participant2}_checkMesh.log | ||
| rm -fv ${Participant2}_potentialFoam.log | ||
| rm -fv ${Participant2}_decomposePar.log | ||
| rm -fv ${Participant2}.log | ||
| rm -fv ${Participant2}_reconstructPar.log | ||
|
|
||
|
|
||
| # Remove the preCICE-related log files | ||
| echo "Deleting the preCICE log files..." | ||
| rm -fv \ | ||
| precice-*.log \ | ||
| precice-*.json \ | ||
|
|
||
| # Output files for preCICE versions before 1.2: | ||
| rm -fv \ | ||
| iterations-${Participant1}.txt iterations-${Participant2}.txt \ | ||
| convergence-${Participant1}.txt convergence-${Participant2}.txt \ | ||
| Events-${Participant1}.log Events-${Participant2}.log \ | ||
| EventTimings-${Participant1}.log EventTimings-${Participant2}.log | ||
|
|
||
| rm -fv .*.address | ||
|
|
||
| rm -fv watchpointLeft.txt | ||
|
|
||
| echo "Cleaning complete!" | ||
| #------------------------------------------------------------------------------ | ||
12 changes: 12 additions & 0 deletions
12
partitioned-pipe-multiscale/fluid3d-openfoam/constant/transportProperties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class dictionary; | ||
| location "constant"; | ||
| object transportProperties; | ||
| } | ||
|
|
||
| transportModel Newtonian; | ||
|
|
||
| nu nu [ 0 2 -1 0 0 0 0 ] 1e1; | ||
MakisH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
10 changes: 10 additions & 0 deletions
10
partitioned-pipe-multiscale/fluid3d-openfoam/constant/turbulenceProperties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class dictionary; | ||
| location "constant"; | ||
| object turbulenceProperties; | ||
| } | ||
|
|
||
| simulationType laminar; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.