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

ElevationVsTime OpenFOAM Sloshing motion

Register Blogs Community New Posts Updated Threads Search

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

I got my free surface elevation values with the following code:
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;
   }  
); 
I wrote this code in controlDict and it worked. However, when I tried to plot the graph in python with the following code I'm getting OSError: coords not found. Could anyone tell me how can I add the coordinates in python. Reference website is:
HTML Code:
https://openfoamwiki.net/index.php/Tip_Surface_elevation_in_time
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() 
Best regards
kaboka is offline   Reply With Quote

Reply


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
Dynamic Meshing in OpenFOAM for Fish Motion aero_cfd OpenFOAM Running, Solving & CFD 3 October 19, 2022 03:12
Sloshing tank with OpenFOAM recif CFD Freelancers 5 May 19, 2016 03:44
New OpenFOAM Forum Structure jola OpenFOAM 2 October 19, 2011 06:55
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 06:25
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56


All times are GMT -4. The time now is 23:09.