From c7e3f5fb1ed8e68b8d0a7ce3a1b73b7d325f04ce Mon Sep 17 00:00:00 2001 From: Anne de Jong Date: Tue, 10 Feb 2015 08:17:40 +0100 Subject: [PATCH] We give Swig a try --- CMakeLists.txt | 27 +++++++--- Plot data.ipynb | 75 +++++++++++++++++++++++++++ main.cpp | 106 +++++++++++++++++++++++++++++++++++++++ pmovie.py | 50 ++++++++++++++++++ ptime.py | 13 +++++ src/solution.cpp | 54 -------------------- src/solution.h | 61 ---------------------- src/solutionatgp.cpp | 32 ++++++++++++ src/solutionatgp.h | 36 +++++++++++++ src/solutioninstance.cpp | 44 ++++++++++++++++ src/solutioninstance.h | 30 +++++++++++ src/tube.cpp | 18 ++----- src/tube.h | 10 ++-- timedomain.cpp | 73 --------------------------- timedomain.i | 52 +++++++++++++++++++ 15 files changed, 469 insertions(+), 212 deletions(-) create mode 100644 Plot data.ipynb create mode 100644 main.cpp create mode 100755 pmovie.py create mode 100755 ptime.py delete mode 100644 src/solution.cpp delete mode 100644 src/solution.h create mode 100644 src/solutionatgp.cpp create mode 100644 src/solutionatgp.h create mode 100644 src/solutioninstance.cpp create mode 100644 src/solutioninstance.h delete mode 100644 timedomain.cpp create mode 100644 timedomain.i diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d5067b..ad8436e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,18 @@ # CMakeList.txt for linear code -cmake_minimum_required (VERSION 2.8.9) - +cmake_minimum_required (VERSION 3.1) project(Timedomain1DEuler) -add_definitions(-DTRACERNAME=timedomaineuler -DARMA_USE_BLAS -DARMA_USE_LAPACK) +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) +FIND_PACKAGE(PythonLibs) + +INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(CMAKE_SWIG_FLAGS "-Wall") + + +add_definitions(-DTRACERNAME=timedomaineulertracer -DARMA_USE_BLAS -DARMA_USE_LAPACK) ############################## Not so often changed @@ -15,7 +24,7 @@ add_definitions(-DTRACERNAME=timedomaineuler -DARMA_USE_BLAS -DARMA_USE_LAPACK) set (CMAKE_GCC " -Wno-unused-function -ffunction-sections -fdata-sections -Wno-unused-local-typedefs -Wno-empty-body") -set (CMAKE_GENERAL "${CMAKE_GENERAL} -std=c++11 -pipe -O2 -fPIC -Wall \ +set (CMAKE_GENERAL "${CMAKE_GENERAL} -march=native -std=c++11 -pipe -O2 -fPIC -Wall \ -Wextra -Wno-unused-parameter \ -Wno-unused-variable -Wno-unused-but-set-variable \ -Wno-return-local-addr -Wno-cpp -Wno-address") @@ -25,6 +34,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_GENERAL} ${CMAKE_GCC}") # link_directories(${link_directories} /usr/local/lib) set (tdir /home/anne/wip/tmtubes/src) include_directories( + # ${PYTHON_INCLUDE} ${tdir}/nonlinear/sys ${tdir}/nonlinear/seg ${tdir}/nonlinear/geom @@ -36,9 +46,14 @@ include_directories( ) AUX_SOURCE_DIRECTORY(src src) link_directories(/home/anne/bin/lib) -add_executable(timedomaineuler timedomain.cpp ${src}) -target_link_libraries(timedomaineuler nonlin armadillo boost_program_options) +add_library(sources ${src}) +set_source_files_properties(timedomain.i PROPERTIES CPLUSPLUS ON) +set_source_files_properties(timedomain.i PROPERTIES SWIG_FLAGS "-py3") +set_source_files_properties(timedomain.i PROPERTIES SWIG_FLAGS "-Wextra") + +swig_add_module(timedomaineuler python timedomain.i) +swig_link_libraries(timedomaineuler sources nonlin armadillo ${PYTHON_LIBRARIES}) diff --git a/Plot data.ipynb b/Plot data.ipynb new file mode 100644 index 0000000..697d32f --- /dev/null +++ b/Plot data.ipynb @@ -0,0 +1,75 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:cf9769ed030dba90588e4e94007d226dd2897d23c8792fd8974c73bb04381b2c" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from tmtubes import gas\n", + "air=gas('air')\n", + "L=1.\n", + "c0=air.cm(293.15)\n", + "fres=c0/(4*L)\n", + "print(\"fres:\",fres)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "fres: 85.7847876535731\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "plot(x,u)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 3, + "text": [ + "[]" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEACAYAAABCl1qQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYVNWZx/Hva7MKDEQwbN0KDqiAhEHC4kqrqIgIokZB\nExQ1kCFEHaOCOiYYYzYNMYgSY9ThGQVEQUAF2aTVRyNEYAC1UVEhLBGXSFSEh+2dP85tu23pqqK3\nW8vv8zz3oerWubfeutr11jnnnnPM3REREUnkkLgDEBGR9KdkISIiSSlZiIhIUkoWIiKSlJKFiIgk\npWQhIiJJJU0WZtbfzNaZ2TtmNraCMhOj11ebWfdkx5rZXWZWHJWfZWZNo/3tzGynma2Ktvur40OK\niEjVJEwWZpYHTAL6A52BYWbWqVyZAUAHd+8IjAQmp3DsQqCLu3cD3gZuLnPK9e7ePdpGV/UDiohI\n1SWrWfQifHlvcPc9wHRgcLkyg4ApAO6+DGhmZq0SHevui9x9f3T8MiC/Wj6NiIjUiGTJoi2wqczz\nzdG+VMq0SeFYgCuBeWWet4+aoIrM7OQk8YmISC2ok+T1VOcCscq8uZndCux296nRrq1Agbt/ambH\nA7PNrIu7f16Z84uISPVIliy2AAVlnhcQagiJyuRHZeomOtbMrgAGAGeU7HP33cDu6PFKM3sX6Ais\nLPuGZ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7ha/Ff0d/HWjObamb1c+VamNnDZrbNzNaW\n2VdtA6AzJlmkMkAwy+0B/svduxBuHvhx9PkPOMAxR1xLaLIsqR7n6rX4IzDP3TsB3yHcQJJz18LM\n2gI/AXq4e1dC8/dQcudaPEL4fiyr2gZAZ0yyILUBglnL3T9w9/+LHn8BFBNuAqhogGNWM7N8YADw\nF0pv3c65a2FmTYFT3P1hCH2F7v4vcvBaROoAh5pZHeBQws01OXEt3P0l4NNyu6ttAHQmJYtUBgjm\nhOgOs+7AMioe4Jjt/gDcCOwvsy8Xr0V74CMze8TMVprZg2bWiBy8Fu6+Bfg98HdCktju7ovIwWtR\nRrUNgM6kZKGeeMDMGgMzgWvd/fOyr6UwwDErmNlA4EN3X0UFA0Jz5VoQfkkfD9zv7scT7kj8WjNL\nrlwLM/sW4Zd0O8KXYWMz+37ZMrlyLQ6kqgOgMylZbAEKyjwv4OuZMeuZWV1Covhfdy8Zm7ItmosL\nM2sNfBhXfLXoRGCQmb0PTANON7P/JTevxWZgs7v/LXr+JCF5fJCD16If8L67f+Lue4FZwAnk5rUo\nUdHfRPnv0/xoX4UyKVl8NUDQzOoROmfmxhxTrTEzAx4C3nT3e8q8VDLAEb4+wDFrufst7l7g7u0J\nHZjPu/sPyM1r8QGwycyOjnb1A94AnibHrgWwEehjZg2jv5d+hBsgcvFalKjob2IuMNTM6plZeyoY\nAF1WRo3O/megAAAAsElEQVSzMLNzgHsoHeT365hDqjVmdjLwIrCG0urizYT/wDOAI4gGOLp7LSzf\nnh7MrC/wU3cfZGaHkYPXwsy6ETr66wHvEgbG5pGb12I84YfkXmAlcDXQhBy4FmY2DegLtCD0T/wM\nmEMFn93MbgGuJFyra919QcLzZ1KyEBGReGRSM5SIiMREyUJERJJSshARkaSULEREJCklCxERSUrJ\nQkREklKyEBGRpJQsREQkqf8HcogznVYp2ycAAAAASUVORK5CYII=\n", + "text": [ + "" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6a8491a --- /dev/null +++ b/main.cpp @@ -0,0 +1,106 @@ +#include "tube.h" +#include "tracer.h" + +#include +#include +#include +#include +TRACETHIS; + +using geom::Geom; +using geom::Grid; +namespace po = boost::program_options; +using namespace td; +SPOILNAMESPACE; + +// Directory for storage +const char* dir="results"; + + +inline double min(d x,d y){return x(&f)->default_value(100)) + ; + d T=1/f; + d L=1; + us gp=500; + + d dx=L/(gp-1); // One left and right gp, so + d CFL=0.95; + // This is questionable + d dt=min(CFL*dx/gc.c0(),T/50); + cout << "dt:" << dt <<"\n"; + cout << "dx:" << dx <<"\n"; + + td::gc=tasystem::Globalconf::airSTP(0,f,1); + cout << "omg:" << td::gc.getomg() << endl; + inittrace(loglevel); + initothertrace(loglevel,nltracer); + + + // Create results dir, put all stuff in + mkdir(dir,S_IRWXU | S_IRWXG); + // Empty this directory + + td::Tube t(L,gp); + + + int nsaves_per_period=50; + + int approx_instances_per_period=round(T/dt); + if(nsaves_per_period>approx_instances_per_period){ // Not good.. + WARN("Error: to many saves for number of time instances available. Try adjusting nsaves_per_period Exiting.."); + exit(192); + } + + + d time=0; + + us loopnr=1; + us savenr=0; + us saves_per_period=20; + + d tbetweensaves=T/saves_per_period; + + d tlastsave=0; + + std::stringstream pfilename,ufilename; + pfilename << dir; ufilename << dir; + pfilename << "/p.dat"; + ufilename << "/u.dat"; + std::ofstream p(pfilename.str()); + std::ofstream u(ufilename.str()); + p << "#Pressure data vs gridpoint. gp=" << gp << "\n"; + u << "#Velocity data vs gridpoint. gp=" << gp << "\n"; + + t.getSol().save(p,data::p); + t.getSol().save(u,data::u); + const clock_t begin_time = std::clock(); + while(time<180*T){ + t.DoIntegration(dt); + time=t.getTime(); + + if(time-tlastsave>tbetweensaves){ + tlastsave=time; + savenr++; + t.getSol().save(p,data::p); + t.getSol().save(u,data::u); + cout << "Saving for t= " << time << " s.\n"; + } // ti%10 + loopnr++; + } + d comptime=std::clock()-begin_time; + p << "#Total time required to obtain solution: " << comptime/CLOCKS_PER_SEC <<" \n"; + return 0; +} + + + diff --git a/pmovie.py b/pmovie.py new file mode 100755 index 0000000..82e5474 --- /dev/null +++ b/pmovie.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + +from numpy import * +from matplotlib.pyplot import * +from matplotlib import animation +import sys + + +inst=0 +print("Loading data...") +pdat=loadtxt('results/p.dat') +# save(pdat,'p.npy') + +gp=300 # Need to be taken from file + +xmax=pdat[-1,0] +x=linspace(0,1,300) + +fig = figure(figsize=(12,8)) +ax = axes(xlim=(0,1),ylim=(-180,180)) +grid('on') +line, = plot([],[],lw=2) + +ponly=pdat[:,1] +imax=int(floor(pdat.shape[0]/gp)) + +p=array_split(ponly,imax) + +def init(): + line.set_data([], []) + return line, + + +# print(imax) +def update_progress(progress): + sys.stdout.write('\r[{0}{1}] {2}%'.format('#'*int(floor(progress)),' '*int(ceil((100-progress))),progress)) + +def animate(i): + update_progress(int(round(100*i/imax))) + line.set_data(x,p[i]) + return line, +print("Creating animation...") +anim = animation.FuncAnimation(fig, animate, init_func=init, + frames=imax, interval=20, blit=True) +# print("Saving animation...") +# anim.save('p.mp4', fps=20, extra_args=['-vcodec', 'libx264']) + +print("Showing animation...") +show() + diff --git a/ptime.py b/ptime.py new file mode 100755 index 0000000..02e6920 --- /dev/null +++ b/ptime.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +from numpy import * +from matplotlib.pyplot import * + +pfile=loadtxt('results/p.dat') +gp=300 +pend=zeros(floor(pfile.shape[0]/gp)) +for i in range(pend.size): + pend[i]=pfile[(i+1)*gp-1,1] + +plot(pend) +show() diff --git a/src/solution.cpp b/src/solution.cpp deleted file mode 100644 index 502b5d0..0000000 --- a/src/solution.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "solution.h" -#include "geom.h" -#include "tube.h" - - - -namespace td{ - SolutionAtGp::SolutionAtGp() { - rho_=gc.rho0(); - } - SolutionInstance::SolutionInstance(d time,int gp): - time(time) - { - TRACE(15,"SolutionInstance::SolutionInstance()"); - gps.resize(gp); - } - void SolutionInstance::setrho(d rho) { - TRACE(15,"SolutionInstance::setrho()"); - - for(auto gp=gps.begin();gp!=gps.end();gp++){ - gp->set(rho); - } - } // setrho() - int SolutionInstance::safe(const char* dir){ - TRACE(15,"SolutionInstance::safe()"); - std::stringstream pfilename,ufilename,rhofilename; - pfilename.str(""); ufilename.str(""); rhofilename.str(""); - pfilename << dir; - ufilename << dir; - rhofilename << dir; - - pfilename << "/p" << nr << ".dat"; - ufilename << "/u" << nr << ".dat"; - rhofilename << "/rho" << nr << ".dat"; - cout << pfilename.str() << "\n"; - - std::ofstream p(pfilename.str()); - std::ofstream u(ufilename.str()); - std::ofstream rho(rhofilename.str()); - - // Writing results for pressure to file - p << "#Pressure data vs gridpoint: t=" << time << "\n"; - u << "#Velocity data vs gridpoint: t=" << time << "\n"; - rho << "#Density data vs gridpoint: t=" << time << "\n"; - for(us j=0;j gps; - d time=0; - int nr=0; - public: - SolutionInstance(d TimeInstance,int gp); - ~SolutionInstance(){} - d getTime() const {return time;} - void setTime(d t) {time=t;} - void set(us i,SolutionAtGp& sol){ gps.at(i)=sol;} - SolutionAtGp& get(us i){ return gps.at(i); } - - void setrho(d rho); - int safe(const char* dir); - }; - -} // namespace td -#endif /* _SOLUTION_H_ */ - diff --git a/src/solutionatgp.cpp b/src/solutionatgp.cpp new file mode 100644 index 0000000..ced3dce --- /dev/null +++ b/src/solutionatgp.cpp @@ -0,0 +1,32 @@ +#include "solutionatgp.h" +#include "globalconf.h" + + +TRACETHIS + +namespace td{ + + extern tasystem::Globalconf gc; + + SolutionAtGp::SolutionAtGp() { + rho_=gc.rho0(); + } + d SolutionAtGp::u() const {return m()/rho();} + d SolutionAtGp::ekin() const {return 0.5*rho()*pow(u(),2);} + d SolutionAtGp::estat() const {return rhoE()-ekin();} + d SolutionAtGp::p() const {return estat()*(gc.gas.gamma(gc.T0)-1);} + + d SolutionAtGp::Cflux() const {return m();} + d SolutionAtGp::Mflux() const {return pow(m(),2)/rho()+p();} + d SolutionAtGp::Eflux() const {return (rhoE()+gc.p0/(gc.gas.gamma(gc.T0)-1)+p()+gc.p0)*u();} + +} // namespace td + + + + + + + + + diff --git a/src/solutionatgp.h b/src/solutionatgp.h new file mode 100644 index 0000000..2bb5e37 --- /dev/null +++ b/src/solutionatgp.h @@ -0,0 +1,36 @@ +#pragma once + +namespace td{ + + typedef double d; + class SolutionAtGp { + d rho_,m_=0,rhoE_=0; + public: + // Dependent variables + const d& rho() const {return rho_;} + const d& m() const {return m_;} // which is rho*u + const d& rhoE() const {return rhoE_;} // which is rho*E + // Derived from dependent + d u() const; + d ekin() const; + d estat() const; + d p() const; + + d Cflux() const; + d Mflux() const; + d Eflux() const; + SolutionAtGp(); + ~SolutionAtGp(){} + void setData(d rho,d m=0,d rhoE=0){ + rho_=rho; + m_=m; + rhoE_=rhoE; + } + }; +} // namespace td + + + + + + diff --git a/src/solutioninstance.cpp b/src/solutioninstance.cpp new file mode 100644 index 0000000..0213e8d --- /dev/null +++ b/src/solutioninstance.cpp @@ -0,0 +1,44 @@ +#include "solutioninstance.h" +#include "tube.h" + + + +namespace td{ + + SolutionInstance::SolutionInstance(int gp) + { + TRACE(12,"SolutionInstance::SolutionInstance()"); + gps.resize(gp); + } + void SolutionInstance::setrho(d rho) { + TRACE(15,"SolutionInstance::setrho()"); + + for(auto gp=gps.begin();gp!=gps.end();gp++){ + gp->set(rho); + } + } // setrho() + int SolutionInstance::save(std::ofstream& str,data d){ + TRACE(15,"SolutionInstance::save()"); + if(d==data::p) + for(us j=0;j gps; + d time=0; + public: + SolutionInstance(int gp); + ~SolutionInstance(){} + d getTime() const {return time;} + void setTime(d t) {time=t;} + void set(us i,SolutionAtGp& sol){ gps.at(i)=sol;} + SolutionAtGp& get(us i){ return gps.at(i); } + + void setrho(d rho); + int save(std::ofstream&,data d); + }; + +} // namespace td + diff --git a/src/tube.cpp b/src/tube.cpp index 5183536..3ddaac5 100644 --- a/src/tube.cpp +++ b/src/tube.cpp @@ -12,7 +12,7 @@ namespace td{ return pleft; } - Tube::Tube(d L,int gp): L(L),gp(gp),sol(SolutionInstance(0,gp)) { + Tube::Tube(d L,int gp): L(L),gp(gp),sol(SolutionInstance(gp)) { TRACE(15,"Tube::Tube()"); dx=L/(gp-1); VARTRACE(15,gp); @@ -26,13 +26,11 @@ namespace td{ d newt=t+dt; // Define new solutioninstance - SolutionInstance newsol=sol; - + SolutionInstance newsol(gp); + newsol.setTime(newt); SolutionAtGp newsolgp; d rho,m,rhoE; - newsol.setTime(newt); - int i=0; // Left boundary { @@ -43,16 +41,13 @@ namespace td{ d momfluxl=ip0.rho()*pow(ip0.u(),2)+pleft(t); m=ip0.m()-la*(ip1.Mflux()-momfluxl); rhoE=ip0.rhoE()-la*(ip1.Eflux()-ip0.Eflux()); - // rhoE=ip0.rhoE()-la*(ip1.Eflux()-.rhoE()*ip0.u()-ip0.u()*(gc.p0+pleft(t))); newsolgp.set(rho,m,rhoE); - // cout << "pleft: " << pleft(t) <<"\n"; - // cout << "pleft: " << newsolgp.p() <<"\n"; newsol.set(i,newsolgp); } // Leftmost node // TRACE(15,"leftmost done"); // Inner nodes - for(i=1;isol=sol;} void DoIntegration(d dt); diff --git a/timedomain.cpp b/timedomain.cpp deleted file mode 100644 index 2a0bf40..0000000 --- a/timedomain.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "tube.h" -#include "tracer.h" - -#include -#include -#include -TRACETHIS; - -using geom::Geom; -using geom::Grid; -namespace po = boost::program_options; -using namespace td; -SPOILNAMESPACE; - -// Directory for storage -const char* dir="results"; - - - -inline double min(d x,d y){return x(&f)->default_value(100)) - ; - d T=1/f; - d L=0.01; - us gp=10; - - d dx=L/gp; - d CFL=0.5; - // This is questionable - d dt=min(CFL*dx/gc.c0(),T/50); - cout << "dt:" << dt <<"\n"; - cout << "dx:" << dx <<"\n"; - - td::gc=tasystem::Globalconf::airSTP(0,f,1); - cout << "omg:" << td::gc.getomg() << endl; - inittrace(15); - initothertrace(10,nltracer); - - - // Create results dir, put all stuff in - mkdir(dir,S_IRWXU | S_IRWXG); - // Empty this directory - system("rm results/*"); - - td::Tube t(L,gp); - - - int nsaves_per_period=50; - int nr=0; - d time=0; - - while(time<2*T){ - t.DoIntegration(dt); - time=t.getTime(); - // cout << "Iteration done. Saving data...\n"; - if(true){ - // Create filename to store data to - } // ti%10 - } - return 0; -} - - - diff --git a/timedomain.i b/timedomain.i new file mode 100644 index 0000000..6383816 --- /dev/null +++ b/timedomain.i @@ -0,0 +1,52 @@ +%module timedomaineuler +%{ + #include "solutionatgp.h" + #include "test.h" + #include "tube.h" +%} + +typedef double d; + +namespace td{ + class SolutionAtGp { + d rho_,m_=0,rhoE_=0; + public: + // Dependent variables + const d& rho() const; + const d& m() const; + const d& rhoE() const; + // Derived from dependent + d u() const; + d ekin() const; + d estat() const; + d p() const; + + d Cflux() const; + d Mflux() const; + d Eflux() const; + SolutionAtGp(); + ~SolutionAtGp(){} + void setData(d rho,d m=0,d rhoE=0); + }; + class SolutionInstance{ + public: + SolutionInstance(int gp); + ~SolutionInstance(){} + d getTime() const; + void setTime(d t); + void set(us i,SolutionAtGp& sol); + SolutionAtGp& get(us i); + void setrho(d rho); + }; + + class Tube{ + public: + Tube(double L,int gp); + ~Tube(){} + SolutionInstance& getSol() { return sol;} + void setSol(const SolutionInstance& sol) {this->sol=sol;} + void DoIntegration(d dt); + d getTime(){return t;} + }; +} +