CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

ElevationVsTime OpenFOAM Sloshing motion Graph

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 24, 2020, 08:09
Default ElevationVsTime OpenFOAM Sloshing motion Graph
  #1
New Member
 
borA
Join Date: Dec 2019
Posts: 6
Rep Power: 2
kaboka is on a distinguished road
Hello everyone,

I have sloshing case inside the 3D container. I got the values with .vtk code as follows. I wrote that code inside the controlDict and it worked.
PHP Code:
functions
{
   
freeSurface
   
{   
       
type            surfaces;
       
functionObjectLibs
       
(   
           
"libsampling.so" 
       
);  
       
outputControl   outputTime;
       
outputInterval  1;  
       
surfaceFormat  vtk;
       
fields
       
(   
           
alpha.water
       
);  
       
surfaces
       
(   
           
freeSurface
           
{   
               
type        isoSurfaceCell;
               
isoField    alpha.water;
               
isoValue    0.5;
               
interpolate false;
               
regularise  false;
           }   
       );  
       
interpolationScheme cell;
   }  
); 
Now based on this website:
HTML Code:
https://openfoamwiki.net/index.php/Tip_Surface_elevation_in_time
I would like to plot the specific point in the free surface.
PHP Code:
#!/usr/bin/python

# elevationVsTime
# Read VTK files with isosurface 
# Track one (x,z) coordinate in time

import os
import re
from vtk import 
*
from optparse import OptionParser
from numpy import 
*

print (
"elevationVsTime")

# Read command line arguments
parser OptionParser()

parser.add_option("-f","--input-file",dest="coords",type="string",help="Filename containing coordinates",metavar="FILE",default="coords")

(
optionsargs) = parser.parse_args()

print (
"Reading coordinates from file \"",options.coords,"\"")

loadtxt(options.coords)


#- Search starting point
f[:,0]
x*0+0.7
f[:,1]

points len(x)

print (
points," points found")

#- List input points
for i in range(0points-1):
 print (
"Point ",i," (",x[i],",",z[i],")")

# Import timedirectories
# read the vtk directory and get all the time steps and return list 
basedir "freeSurface/"

timesteps=[]
for 
root,dir,file in os.walk(basedir,True):
 
p,time os.path.split(root)
 if (
bool(re.search("^[0-9.]",time))):
  
timesteps.append(time)


filename file[0]
basename 'elevationVsTime'
timesteps sorted(timesteps# This sorts alphabetically

# "Progress-bar" necessity - 
Ntimes len(timesteps)
frac round(Ntimes/10.0);
counter 0

#- Time-info - known bug here
print ("Timerange: [",timesteps[0],",",timesteps[Ntimes-1],"]")

## Read
for ts in timesteps:
  
#- Counter info -- this info is approximate
  
counter counter+1
  
if ( counter%frac == ):
   print (
round(counter/frac)*10,"%")

  
#- Read VTK file 
  
readfile basedir ts "/" filename
  reader 
vtkPolyDataReader() 
  
reader.SetFileName(readfile)
  
reader.Update() 
  
output reader.GetOutput()

  
#- For each timestep, find the closest coordinate on the 0/ plane
  
for i in range(points):
   
writefile basename str(i)
   
file open(writefile,'a+')

   
#- Coordinate to find closest point
   
xfind = [x[i], y[i], z[i]]

   
#- Find point
   
output.FindPoint(xfind)
   
   
#- Coordinate of point
   
xfound output.GetPoint(p)
   
y[i] = xfound[1]

   
#- Write to file
   
print >> filetsy[i]
   
file.close() 
I'm using this code but I am getting an OSError: coords not found.
Could anyone help me how to create the coordinate file and plot it in the python, please ?

Best regards
kaboka is offline   Reply With Quote

Reply

Tags
elevation, postprocess, python, sloshing, time

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Partitioning Error on HPC: ***Cannot bisect a graph with 0 vertices! MJM FLUENT 0 November 28, 2019 05:21
Getting Started with OpenFOAM wyldckat OpenFOAM 24 October 2, 2019 21:35
Wiper motion in OpenFOAM KartikU OpenFOAM 0 February 25, 2019 12:19
[OpenFOAM] How to plot alpha vs time graph in multiphase solver of openFOAM shipman ParaView 6 August 5, 2018 23:22
Lateral sloshing OpenFoam sloshing tank 2D case FTasnim OpenFOAM 2 February 24, 2017 06:12


All times are GMT -4. The time now is 01:10.