lundi 12 novembre 2012

Fun with OpenFOAM and meandering channel

This post is the result of my TA activities. So this time I've decided to show students how to make curved meshes and how to run free surface simulations with OpenFOAM.

Cause all students are from Civil and Environmental Engineering department typical curved mesh is necessary for meandering channels simulation. Surely there're another types of flumes with curved parts (rising sector weir gate for ex.) but with meandering channels we'll have more fun.

Scheme of the channel are shown on Fig. 1. We've got 270 degree meandering part with centerline radius of 1.5 m which is connected to straight 1 m inlet and outlet channels with two small curved parts of smaller radius.

Figure 1
Progress on mesh creation is shown on Figs. 2-5. First mesh without curved edges is built, then arc edges are added, then density of mesh increased, and at last upper part (where air is located) of the channel added.

Figure 2

Figure 3

Figure 4

Figure 5
Figure 6
Boundary conditions are rather usual for this type of simulations. We have constant discharge at the inlet and outlet (though maybe it'll be better to set zero gradient BC at the outlet). Then it is possible to run simulation. On the video first 200 s from the start are shown.




Most of the time when comparing simulation results with experiment it is necessary to get some more of less steady flow in the flume. Usually it is achieved by running simulation for rather long time (as an estimation we can take the time necessary to refill the channel, i.e. channel length / inlet velocity). With initially still fluid in the channel it'll take rather long time to settle all the oscillations of the free surface. So it's better to get some initial estimation of the velocity distribution in the channel. For the straight channel this first estimation (constant velocity along the channel) can be set with setFields utility, in case of more complex channel shapes we can use pimpleFoam where fluid free surface do not move and actually is wall with slip BC. So in this case I took mesh from Fig. 5, ran pimpleFoam with the same inlet and outlet BCs and then used mapFields for initial flow field setup.

Video of the free surface evolution in this new simulation is shown below.


As in the previous case in the video around 200 seconds from the start of simulation are shown. And this time we get almost steady flow during this time.

OpenFOAM files for the cases can be found at https://bitbucket.org/mrklein/openfoam-course/src/9f9c41fdb851125a6a4bedb56dd3b8fd67c37330/meandering?at=master.

dimanche 21 octobre 2012

Fun with OpenFOAM and turbulence models

Creation of these movies was a part of sudden teaching assistance duties. In the beginning the idea was to just reproduce Kármán vortex street. And then it evolved to the comparison of vortex street simulation results with different turbulence models. Case files for the LES simulations can be found at https://bitbucket.org/mrklein/openfoam-ravings.

Channels and meshes

We have simple straight channel with two bodies of different shape put inside the channels. Simple schemes of the channels are shown on the figures below.


"Circle" channel scheme

jeudi 11 octobre 2012

This saved my evening ;)

Initially I've got points from OpenFOAM sample in the plane, then I collected all Xes and Ys, and then (cause there was also fluid with channel involved and velocities was not available at every point and when data is not available then it's zero)...

>> vels = importdata('vels.dat');
>> I = ~(vels(:, 3) == 0 & vels(:, 4) == 0);
>> quiver(vels(I, 1), vels(I, 2), vels(I, 3), vels(I, 4))


As all these points for zero values gone, figures look much clearer.

jeudi 27 septembre 2012

Strange number 123456

To exclude I/O from this post I've modified code. So now it not only calculates factorials but also sums their digits and at last sums the sums of digits and as a result there's on one I/O operation. Lisp as usual behaving quite good. And a result of this code: is
Evaluation took:
  7.762 seconds of real time
  7.565354 seconds of total run time (7.363660 user, 0.201694 system)
  [ Run times consist of 0.399 seconds GC time, and 7.167 seconds non-GC time. ]
  97.46% CPU
  17,812,436,719 processor cycles
  177 page faults
  15,624,347,568 bytes consed
  
2652733
Almost similar results I've got from Go program:
Elapsed time: 4.509443s
2652733
But strangely Clojure, Haskell and Julia have got some very strange behavior. Till 12345! everything seems to be ok (though for Clojure it takes almost 1.5 sec to calculate while Lisp done it in 0.091 seconds of real time). But when we get 123456! Clojure needs almost 1 minute, Haskell and Julia just plainly refused to calculate. Even in case of Julia it was not so plainly cause it decided to eat almost all memory.

Euler #125

The palindromic number 595 is interesting because it can be written as the sum of consecutive squares: 62 + 72 + 82 + 92 + 102 + 112 + 122...

dimanche 16 septembre 2012

What's wrong with the code?

Decided to take naive implementation of factorial in Racket and Lisp:
and

And even after
raco exe test.rkt
timing is as follows:
raco exe test.rkt
time ./test

real 0m0.697s
user 0m0.581s
sys 0m0.092s
time sbcl --script test.lisp

real 0m0.139s
user 0m0.085s
sys 0m0.049s
Maybe I/O in Racket is rather slow?

mardi 19 juin 2012

Choosing flash cards application

After 8 months in Korea at last I’ve decided to start learning language. I’ve got Korean language textbook which I bought as soon as I came here. With my colleague we arranged language exchange lessons. English for Korean. So the time for learning words came.
I the very beginning of my life here I bought paper flip-cards to learn alphabet. This time I’ve decided to be more technological and use iPad and iPhone. Surely there are lots of flip card sets on the Internet but they are just abstract flip cards: korean numbers, colors, verbs etc. I needed special sets of flip cards linked to the lessons in my textbook. So there appeared necessity for creation of flip cards. For this activity iPad with its onscreen keyboard was perfect. And for word learning I planned to use iPhone. And final procedure for learning became:
  1. Create flip cards for the lesson on iPad
  2. Export it somewhere
  3. Import them on iPhone
  4. Learn words

mercredi 2 mai 2012

Euler #64

All square roots are periodic when written as continued fractions and can be written in the form...

Method for calculation of square root continued fraction is taken from  http://web.math.princeton.edu/mathlab/jr02fall/Periodicity/mariusjp.pdf

Brute-forcing Eurler #70

Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, φ(9)=6....

First I was trying to  brute-force the solution using FT of Euler totient function (http://en.wikipedia.org/wiki/Euler%27s_totient_function#Fourier_transform), than through the definition but all these solutions was too long to wait. In the end finished with product formula.

In the process of solution found quite faster recipe from ActiveState on generating prime numbers (http://code.activestate.com/recipes/366178-a-fast-prime-number-list-generator/).

Also used multiprocessing module to speed up solution.

And after...
$ time ./70.py 
(8319823, 8313928, 1.0007090511248113)

real    235m23.873s
user    1644m0.217s
sys     0m36.206s

mercredi 4 janvier 2012

Euler #80

It is well known that if the square root of a natural number is not an integer, then it is irrational.

from decimal import *
from math import sqrt

getcontext().prec = 105

reduce(int.__add__, 
       map(lambda a: \
           reduce(lambda x,y: int(x)+int(y), 
                  str(a.sqrt()).replace('.', '')[:100], 
                  0), 
           map(lambda n: Decimal(str(n)), 
               map(lambda k: \
                   0 if int(sqrt(k)) ** 2 == k else k, 
                   range(100))
              )
          ), 
       0)

Surely it's cheating ;)