Skip to content

Commit

Permalink
make things work today with up-to-date libs and compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
rboman committed Nov 10, 2023
1 parent 92a55ec commit ecdb8e4
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 237 deletions.
8 changes: 0 additions & 8 deletions classes/sph0/louis/devenv-vs2012.bat

This file was deleted.

35 changes: 19 additions & 16 deletions classes/sph0/louis/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# -*- coding: utf-8 -*-

# Copyright 2020 University of Liège
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# runs a test as if it was installed
# runs a test as if it was installed
# - fixes the python path in a dev environment
# - creates a workspace folder

Expand All @@ -25,56 +25,59 @@ class DupStream:
def __init__(self, stream1, stream2):
self.stream1 = stream1
self.stream2 = stream2

def write(self, data):
self.stream1.write(data)
self.stream2.write(data)

def flush(self):
self.stream1.flush()
self.stream2.flush()


class Tee:
import sys

def __init__(self, name):
import sys
self.file = open(name, 'w')
self.stdoutbak = sys.stdout
self.stderrbak = sys.stderr
sys.stdout = DupStream(sys.stdout, self.file)
sys.stderr = DupStream(sys.stderr, self.file)

def __del__(self):
import sys
sys.stdout = self.stdoutbak
sys.stderr = self.stderrbak
self.file.close()

if __name__=="__main__":

if __name__ == "__main__":
import sys, os
# adds "." to the pythonpath
thisdir = os.path.split(__file__)[0]
sys.path.append(thisdir)
import sph.wutils as wu

# parse args
args = wu.parseargs()

# run all tests sequentially
for testname in args.file:
for testname in args.file:
testname = os.path.abspath(testname)
if not os.path.isfile(testname):
raise Exception("file not found: %s" % testname)

wu.setupwdir(testname)
__file__ = testname

# split streams
tee = Tee('stdout.txt')

# start test
import time, platform
print('-'*80)
print('-' * 80)
print("starting test", testname)
print("time:", time.strftime("%c"))
print("hostname:", platform.node())
print('-'*80)
print('-' * 80)
exec(open(testname, 'r', encoding='utf8').read())
135 changes: 60 additions & 75 deletions classes/sph0/louis/sph/gui.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,77 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2020 University of Liège
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# converts .res files to Paraview (VTK)





import vtk
version=vtk.vtkVersion().GetVTKMajorVersion()
import glob
import vtk
version = vtk.vtkVersion().GetVTKMajorVersion()


class ToParaview:
def __init__(self, verb = False):
def __init__(self, verb=False):
self.verb = verb

def convertall(self, pattern='*MP*.res'):
print("converting grid to VTK")
self.convertGrid()
print("converting %s to VTK" % pattern)
for f in glob.glob(pattern):
self.convertParts(f)

def convertGrid(self, fname='grid.out'):
if self.verb: print('converting', fname)

if self.verb:
print('converting', fname)

# read file
file = open(fname)
line = file.readline()
nx, dx = line.strip().split()
nx = int(nx)
dx = float(dx)
#print 'nx=%d, dx=%f' % (nx,dx)
# print 'nx=%d, dx=%f' % (nx,dx)
file.close()

# build a sgrid
grid = vtk.vtkStructuredGrid()
grid = vtk.vtkStructuredGrid()
points = vtk.vtkPoints()
grid.SetPoints(points)
for k in range(nx+1):
for j in range(nx+1):
for i in range(nx+1):
points.InsertNextPoint(i*dx,j*dx,k*dx)
grid.SetDimensions(nx+1,nx+1,nx+1)
grid.SetPoints(points)

for k in range(nx + 1):
for j in range(nx + 1):
for i in range(nx + 1):
points.InsertNextPoint(i * dx, j * dx, k * dx)
grid.SetDimensions(nx + 1, nx + 1, nx + 1)

writer = vtk.vtkXMLStructuredGridWriter()
compressor = vtk.vtkZLibDataCompressor()
writer.SetCompressor(compressor)
writer.SetDataModeToBinary()
if version>5:
if version > 5:
writer.SetInputData(grid)
else:
writer.SetInput(grid)
writer.SetFileName(fname.replace('.out','.vts'))
writer.Write()
writer.SetFileName(fname.replace('.out', '.vts'))
writer.Write()

def convertParts(self, fname):
#if self.verb:

# if self.verb:
print('converting', fname)
file = open(fname)
ugrid = vtk.vtkUnstructuredGrid()

ugrid = vtk.vtkUnstructuredGrid()
points = vtk.vtkPoints()
ugrid.SetPoints(points)
codes = {'p': (1, "Pressure"),
'rho': (1, "Mass density"),
'v' : (3, "Velocity"),
'm': (1, "Mass"),

codes = {'p': (1, "Pressure"),
'rho': (1, "Mass density"),
'v': (3, "Velocity"),
'm': (1, "Mass"),
'c': (1, "Speed of sound"),
'h': (1, "Smoothing length"),
'mu': (1, "max(mu_ab)"),
'nv': (1, "Nb of neighbours") }
'h': (1, "Smoothing length"),
'mu': (1, "max(mu_ab)"),
'nv': (1, "Nb of neighbours")}
results = {}
for c in codes:
scalars = vtk.vtkFloatArray()
Expand All @@ -97,50 +80,52 @@ def convertParts(self, fname):
scalars.SetName(fullname)
ugrid.GetPointData().AddArray(scalars)
results[c] = scalars
i=0

i = 0
for line in file:
#x,y,z, vx,vy,vz, m, p = map(float, line.strip().split())
# x,y,z, vx,vy,vz, m, p = map(float, line.strip().split())
try:
x,y,z, vx,vy,vz, rho, p, m, c, h, mu, nv = list(map(float, line.strip().split()))
x, y, z, vx, vy, vz, rho, p, m, c, h, mu, nv = list(map(float, line.strip().split()))
except:
print("**ERROR while reading file %s!\n\tline=\"%s\"" % (fname,line))
print("**ERROR while reading file %s!\n\tline=\"%s\"" % (fname, line))
break
points.InsertPoint(i, x,y,z)
results['v'].InsertNextTuple3(vx,vy,vz)
points.InsertPoint(i, x, y, z)
results['v'].InsertNextTuple3(vx, vy, vz)
results['p'].InsertNextValue(p)
results['rho'].InsertNextValue(rho)
results['m'].InsertNextValue(m)
results['c'].InsertNextValue(c)
results['h'].InsertNextValue(h)
results['mu'].InsertNextValue(mu)
results['nv'].InsertNextValue(nv)
i+=1
i += 1
file.close()

ntot=i
if self.verb: print("\t%d lines read. Converting grid to VTK..." % ntot)


ntot = i
if self.verb:
print("\t%d lines read. Converting grid to VTK..." % ntot)

for i in range(ntot):
vertex = vtk.vtkVertex()
ids = vertex.GetPointIds()
ids = vertex.GetPointIds()
ids.SetId(0, i)
ugrid.InsertNextCell(vertex.GetCellType(), ids)
if self.verb:
print("\t...", ugrid.GetNumberOfPoints(), 'points and', \
ugrid.GetNumberOfCells(), 'cells converted')

if self.verb:
print("\t...", ugrid.GetNumberOfPoints(), 'points and',
ugrid.GetNumberOfCells(), 'cells converted')

writer = vtk.vtkXMLUnstructuredGridWriter()
compressor = vtk.vtkZLibDataCompressor()
writer.SetCompressor(compressor)
writer.SetDataModeToBinary()
if version>5:
if version > 5:
writer.SetInputData(ugrid)
else:
writer.SetInput(ugrid)
writer.SetFileName(fname.replace('.res','.vtu'))
writer.SetFileName(fname.replace('.res', '.vtu'))
writer.Write()

if __name__=="__main__":
ToParaview(verb=True).convertall()

if __name__ == "__main__":
ToParaview(verb=True).convertall()
Loading

0 comments on commit ecdb8e4

Please sign in to comment.