meta-data

that’s when tian becomes protian

Archive for February 2008

question during the development of 3D CaMRL hybrid code

without comments

1. writedata_bd and writedata_cut not implemented yet

2. why the turbulent source term is not called? sourcet

Written by protian

February 20, 2008 at 10:29 pm

Posted in Uncategorized

python, sort a list

with 2 comments

'my283.jpg'
'my23i.jpg'
'web7-s.jpg'
'fris88large.jpg'
...

You want to sort them by the number embedded in them. What you have to do, is to provide sort() method a order-deciding function, that takes two strings, and compares the integer inside the string. Here’s the solution:

li=[
'my283.jpg',
'my23i.jpg',
'web7-s.jpg',
'fris88large.jpg',
]

def myComp (x,y):
    import re
    def getNum(str): return float(re.findall(r'\d+',str)[0])
    return cmp(getNum(x),getNum(y))

li.sort(myComp)
print li # returns ['web7-s.jpg', 'my23i.jpg', 'fris88large.jpg', 'my283.jpg']

Here, we defined a function myComp to tell sort about the ordering. Normally, one would use the “lambda” construct, but Python’s lambda construct cannot be used to define any function that takes more than one Python-line to express.

re — Regular expression operations

here is the solution for sorting a list of class instances:

class Spam:

def _int_(self, spam, eggs):

self.spam = spam

self.eggs = eggs

a = [Spam(1,4), Spam(9,3), Spam(4,6)]

a.sort( lambda x, y: cmp(  x.eggs(), y,eggs() )  )

Written by protian

February 15, 2008 at 3:28 pm

Posted in Uncategorized

python, declare your own class.

without comments

well, it is ashamed to say that after 2 years of using python, I only use its text-processing ability. Now is its object-oriented part:

 class MyClass:

“A simple example class”

i = 12345

def f(self):

return ‘hello world’

and

x = MyClass()

ok

Written by protian

February 15, 2008 at 2:38 pm

Posted in python script

node reordering technique

without comments

today officially starts CFD code development for ngc

under /Volumes/Work/tian/stu_source/FEMFreesurf/CaMEL_Twofluid_v1.1.1_mac/node_elem_align.c

call in subroutine hypo in hypo.f

call node_elem_align(ien, rng, d, x, df, id, nmap, ibuff, nbuff, nnc, nec, nn_loc, nen, nef, nsd, ndf)

in node_elem_align.c:

void node_elem_align_(int *ien, int *rng,
double *d, double *x, double *f, double *id, int *npoint,
int *ibuff, int *tnbuff,
int *tnnc, int *tnec, int *tnnp, int *tNEN, int *tNFC,
int *tNSD, int *tNDF)

allocate (ien(nen*ebuff))

allocate (rng(nef*ebuff))

ebuff = 2.5 * nec

nnc = (nn-1)/numproc +1

maxnnc = nnc

if (myid.eq.numproc-1) nnc = nn – (numproc -1)*maxnnc

allocate(nnpl(numproc+1))

nnpl(myid+1) stores how many nodes are in the processes up to myid

in hypo.f, call ncommsetup(ien, nec, nen, ndf, nnpl, nn_loc, ntag)

in ncommsetup.f

subroutine ncommsetup(ien, nec, nen, ndf, nnpl, nnp, ntag)

nn_loc is the number of local nodes in a processor.

allocate( d(nn_loc*ndf) ) : flow arrays

allocate( x(nn_loc*ndf) ) : mesh arrays

allocate(df(nn_loc)) : interface arrays

allocate(nmap(nn_loc))

emap = (TempE *) malloc(sizeof(TempE) *nec);

emap[i].xx is the coordinate of the centroid

emap[i].ie = i

qsort(emap, nec, sizeof(TempE), &compTE) sort emap according to xx in ascending order.

Written by protian

February 14, 2008 at 11:37 am

Posted in Uncategorized

katrina simulation

without comments

http://www.worldwindsinc.com/techpapers.htm

a lot of paper here, good

Written by protian

February 14, 2008 at 8:38 am

Posted in Uncategorized

WRF – ADCIRC coupling

without comments

search for paper and forward to Lily Sheng and Prof. Liu.

WRF output wind stress for ADCIRC,

output u10/v10 for SWAN

Written by protian

February 12, 2008 at 12:48 pm

Posted in Uncategorized

run swan again with dense adcirc output

without comments

will the accuracy be improved?

let’s see..

from katrina_dense1:

create a new folder called katrina_dense1_swan

fort.15_nostation

station.info

addstation.py

adcprep

mpirun

after finishing, station2swan.py

copy bot, buoys.loc file, then swanrun

running

Written by protian

February 12, 2008 at 11:12 am

Posted in Uncategorized

2d is so 10 years ago, let’s make it 3D!!!!!

without comments

let’s bake a 3D movie out of those data.

writing scripts ..

well, turns out paraview pvd file can not take wrl files.

fine, let’s rewrite them into paraview polydata file format

writing a script: filter_swanvtr2vtp.py which basically does the same thing as filter_swanvtr.py, only outputting data as paraview polydata format .vtp.

vtpmovie.py: generate a pvd movie file using vtp files.

Written by protian

February 11, 2008 at 7:13 pm

Posted in Uncategorized

meeting 02/11/2008

without comments

per meeting this morning, task for the week:

1. create a movie of net water height, using water elevation and wave height

2. compare speed of wave and speed of current at the shore

3. generate wave profile

4. node re-ordering built in

5. cooperate with Lily Sheng and Heping Liu on WRF model

6. begin code development

Written by protian

February 11, 2008 at 5:43 pm

Posted in Uncategorized

paraview programmable filter

without comments

Trying to add an array to the VRML scene and color by it. not successful yet

http://www.vtk.org/doc/nightly/html/classvtkDataArray.html#ad0e8ab37eacfb957845c1ee962edc6b

http://www.vtk.org/doc/nightly/html/classvtkAbstractArray.html#5c37ed79c3cb07dbc970e2579685de30

http://paraview.org/Wiki/Python_Programmable_Filter

pdi = self.GetInput()
print pdi.GetClassName()
print pdi.GetNumberOfPoints()
print pdi.GetNumberOfVerts()
print pdi.GetNumberOfLines()
print pdi.GetNumberOfPolys()
print pdi.GetNumberOfStrips()

pdo = self.GetOutput()
ivals = pdi.GetPointData().GetScalars()
ntuple = ivals.GetNumberOfTuples()

print ivals.GetComponent(100,0)
print ivals.GetComponent(100,1)
print ivals.GetComponent(100,2)
ca = paraview.vtkFloatArray()
ca.SetName(“height”)
ca.SetNumberOfComponents(1)

————————————————————————————-

start over.

1. print self

vtkPythonProgrammableFilter (0×1cba5270)
Debug: Off
Modified Time: 139840
Reference Count: 5
Registered Events:
Registered Observers:
vtkObserver (0×20dc2e20)
Event: 3
EventName: StartEvent
Command: 0×20dc2da0
Priority: 0
Tag: 2
vtkObserver (0×20dc12f0)
Event: 4
EventName: EndEvent
Command: 0×20dc2d80
Priority: 0
Tag: 3
vtkObserver (0×1cba09b0)
Event: 6
EventName: ProgressEvent
Command: 0×6e4eb60
Priority: 0
Tag: 1
Executive: 0×1c750a00
ErrorCode: Unknown error: 0
Information: 0×1cba5310
AbortExecute: Off
Progress: 0
Progress Text: (None)
OutputDataSetType: 8

2. print self.GetInput()

vtkPolyData (0×1fc78960)
Debug: Off
Modified Time: 59104
Reference Count: 6
Registered Events: (none)
Source: (none)
Information: 0×1fcc14c0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Release Data: Off
UpdateExtent: Not Initialized
MaximumNumberOfPieces: 1
RequestExactExtent: Off
Field Data:
Debug: Off
Modified Time: 59087
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Points: 56018
Number Of Cells: 109496
Cell Data:
Debug: Off
Modified Time: 59098
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 )
Pass Through Flags: ( 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds: (none)
PedigreeIds: (none)
Point Data:
Debug: Off
Modified Time: 59104
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 2
Array 0 name = VRMLArray1
Array 1 name = VRMLColor
Number Of Components: 4
Number Of Tuples: 56018
Copy Tuple Flags: ( 0 1 1 1 1 0 1 )
Interpolate Flags: ( 0 1 1 1 1 0 0 )
Pass Through Flags: ( 0 1 1 1 1 1 1 )
Scalars:
Debug: Off
Modified Time: 59058
Reference Count: 1
Registered Events: (none)
Name: VRMLColor
Data type: unsigned char
Size: 168054
MaxId: 168053
NumberOfComponents: 3
Name: VRMLColor
Number Of Components: 3
Number Of Tuples: 56018
Size: 168054
MaxId: 168053
LookupTable: (none)
Array: 0×20678000
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds: (none)
PedigreeIds: (none)
Bounds:
Xmin,Xmax: (-92, -80)
Ymin,Ymax: (24, 32.5667)
Zmin,Zmax: (-0.84625, 8.8772)
Compute Time: 59243
Number Of Points: 56018
Point Coordinates: 0×1fcf6760
Locator: 0
Number Of Vertices: 0
Number Of Lines: 0
Number Of Polygons: 109496
Number Of Triangle Strips: 0
Number Of Pieces: 1
Piece: 0
Ghost Level: 0

3. print self.GetInput().GetPointData()

vtkPointData (0×1cb81240)
Debug: Off
Modified Time: 59104
Reference Count: 3
Registered Events: (none)
Number Of Arrays: 2
Array 0 name = VRMLArray1
Array 1 name = VRMLColor
Number Of Components: 4
Number Of Tuples: 56018
Copy Tuple Flags: ( 0 1 1 1 1 0 1 )
Interpolate Flags: ( 0 1 1 1 1 0 0 )
Pass Through Flags: ( 0 1 1 1 1 1 1 )
Scalars:
Debug: Off
Modified Time: 59058
Reference Count: 1
Registered Events: (none)
Name: VRMLColor
Data type: unsigned char
Size: 168054
MaxId: 168053
NumberOfComponents: 3
Name: VRMLColor
Number Of Components: 3
Number Of Tuples: 56018
Size: 168054
MaxId: 168053
LookupTable: (none)
Array: 0×20678000
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds: (none)
PedigreeIds: (none)

4. found the data at the fourth attempt. print self.GetInput().GetPoints()

vtkPoints (0×1fcf6760)
Debug: Off
Modified Time: 59042
Reference Count: 4
Registered Events: (none)
Data: 0×20732240
Data Array Name: (none)
Number Of Points: 56018
Bounds:
Xmin,Xmax: (-92, -80)
Ymin,Ymax: (24, 32.6333)
Zmin,Zmax: (-0.84625, 8.8772)

the reason is vtkPoints and vtkPointData are totally different.

SUCCESS declared. This script does the trick:

pdi = self.GetInput()
pdo = self.GetOutput()

pts = pdi.GetPoints()
npt = pts.GetNumberOfPoints()
height = paraview.vtkFloatArray()
height.SetName(“absolute water level”)
height.SetNumberOfComponents(1)
height.SetNumberOfTuples(npt)

pdo.GetPointData().AddArray(height)

for i in range(0, npt):
coor = pts.GetPoint(i)
height.SetValue(i, coor[2])

isosurface_color.png

Written by protian

February 11, 2008 at 1:29 pm

Posted in Uncategorized