Commit 8db1fdc8 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding the Navier-Stokes example.

parent f088f731
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
add_subdirectory( make-project )
add_subdirectory( simple-solver )
add_subdirectory( navier-stokes )
 No newline at end of file
+60 −0
Original line number Diff line number Diff line
TNL_VERSION=0.1
TNL_INSTALL_DIR=${HOME}/local/lib
TNL_INCLUDE_DIR=${HOME}/local/include/tnl-${TNL_VERSION}
#TNL_INCLUDE_DIR=${HOME}/workspace/tnl/src

TARGET = navier-stokes
CONFIG_FILE = $(TARGET).cfg.desc
INSTALL_DIR = ${HOME}/local
CXX = g++
CUDA_CXX = nvcc
OMP_FLAGS = -DHAVE_OPENMP -fopenmp 
#CXX_FLAGS = -std=gnu++0x -I$(TNL_INCLUDE_DIR) -O0 -g -DDEBUG $(OMP_FLAGS)
#CXX_FLAGS = -std=gnu++0x -I$(TNL_INCLUDE_DIR) -O3 $(OMP_FLAGS)
CXX_FLAGS = -DHAVE_NOT_CXX11 -I$(TNL_INCLUDE_DIR) -O3 $(OMP_FLAGS)
LD_FLAGS = -L$(TNL_INSTALL_DIR) -ltnl-0.1 -lgomp

SOURCES = main.cpp
HEADERS = navierStokesSetter.h \
          navierStokesSetter_impl.h \
          navierStokesSolver.h \
          navierStokesSolver_impl.h \
          navierStokesSolverMonitor.h \
          navierStokesSolverMonitor_impl.h          
OBJECTS = main.o
DIST = $(SOURCES) $(HEADERS) $(CONFIG_FILE) Makefile

all: $(TARGET)

clean: 
	rm -f $(OBJECTS)
	rm -f $(TARGET)-conf.h	

dist: $(DIST)
	tar zcvf $(TARGET).tgz $(DIST) 

install: $(TARGET)
	cp $(TARGET) $(INSTALL_DIR)/bin
	cp $(CONFIG_FILE) $(INSTALL_DIR)/share
	cp -rv share/* $(INSTALL_DIR)/share/$(TARGET)
	cp make-png-from-gnuplot $(INSTALL_DIR)/bin
	cp merge-figures $(INSTALL_DIR)/bin
	chmod +x $(INSTALL_DIR)/bin/make-png-from-gnuplot
	chmod +x $(INSTALL_DIR)/bin/merge-figures

uninstall: $(TARGET)
	rm -f $(INSTALL_DIR)/bin/$(TARGET) 
	rm -f $(CONFIG_FILE) $(INSTALL_DIR)/share
	rm -rf $(INSTALL_DIR)/share/$(TARGET)
	rm -rf $(INSTALL_DIR)/bin/make-png-from-gnuplot
	rm -rf $(INSTALL_DIR)/bin/merge-figures	

$(TARGET): $(OBJECTS)
	$(CXX) -o $(TARGET) $(OBJECTS) $(LD_FLAGS)

%.o: %.cpp $(TARGET)-conf.h  $(HEADERS)
	$(CXX) -c -o $@ $(CXX_FLAGS) $<

$(TARGET)-conf.h:
	echo "#define CONFIG_FILE \"${INSTALL_DIR}/share/${CONFIG_FILE}\" " > $(TARGET)-conf.h 
+92 −0
Original line number Diff line number Diff line
/***************************************************************************
                          laxFridrichs.h  -  description
                             -------------------
    begin                : Mar 1, 2013
    copyright            : (C) 2013 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef LAXFRIDRICHS_H_
#define LAXFRIDRICHS_H_

template< typename MeshType >
class laxFridrichs
{
   public:

   typedef typename MeshType :: RealType RealType;
   typedef typename MeshType :: DeviceType DeviceType;
   typedef typename MeshType :: IndexType IndexType;

   template< typename ConservativeVector,
             typename VelocityVector >
//             typename PressureVector >
   void getExplicitRhs( const MeshType& mesh,
                        const IndexType centralVolume,
                        const ConservativeVector& rho,
                        const ConservativeVector& rho_u1,
                        const ConservativeVector& rho_u2,
                        const VelocityVector& u1,
                        const VelocityVector& u2,
//                        const PressureVector& p,
                        ConservativeVector& rho_t,
                        ConservativeVector& rho_u1_t,
                        ConservativeVector& rho_u2_t,
                        const typename MeshType :: RealType viscosityCoeff = 1.0 ) const;
};

template< typename MeshType >
   template< typename ConservativeVector,
             typename VelocityVector >
//             typename PressureVector >
void laxFridrichs< MeshType > :: getExplicitRhs( const MeshType& mesh,
                                                 const IndexType centralVolume,
                                                 const ConservativeVector& rho,
                                                 const ConservativeVector& rho_u1,
                                                 const ConservativeVector& rho_u2,
                                                 const VelocityVector& u1,
                                                 const VelocityVector& u2,
                                                 ConservativeVector& rho_t,
                                                 ConservativeVector& rho_u1_t,
                                                 ConservativeVector& rho_u2_t,
                                                 const typename MeshType :: RealType viscosityCoeff ) const
{
   const IndexType& xSize = mesh. getDimensions(). x();
   const IndexType& ySize = mesh. getDimensions(). y();
   const RealType hx = mesh. getSpaceStep(). x();
   const RealType hy = mesh. getSpaceStep(). y();

   const IndexType& c = centralVolume;
   const IndexType e = mesh. getNodeNeighbour( centralVolume,  0,  1 );
   const IndexType w = mesh. getNodeNeighbour( centralVolume,  0, -1 );
   const IndexType n = mesh. getNodeNeighbour( centralVolume,  1,  0 );
   const IndexType s = mesh. getNodeNeighbour( centralVolume, -1,  0 );

   /****
    * rho_t + ( rho u_1 )_x + ( rho u_2 )_y =  0
    */
   rho_t[ c ]= viscosityCoeff * 0.25 * ( rho[ e ] + rho[ w ] + rho[ s ] + rho[ n ] - 4.0 * rho[ c ] )
                - ( rho[ e ] * u1[ e ] - rho[ w ] * u1[ w ] ) / ( 2.0 * hx )
                - ( rho[ n ] * u2[ n ] - rho[ s ] * u2[ s ] ) / ( 2.0 * hy );

    /****
     * ( rho * u1 )_t + ( rho * u1 * u1 )_x + ( rho * u1 * u2 )_y =  0
     */
    rho_u1_t[ c ] = viscosityCoeff * 0.25 * ( rho_u1[ e ] + rho_u1[ w ] + rho_u1[ s ] + rho_u1[ n ] - 4.0 * rho_u1[ c ] )
                    - ( rho_u1[ e ] * u1[ e ] - rho_u1[ w ] * u1[ w ] ) / ( 2.0 * hx )
                    - ( rho_u1[ n ] * u2[ n ] - rho_u1[ s ] * u2[ s ] ) / ( 2.0 * hy );
    rho_u2_t[ c ] = viscosityCoeff * 0.25 * ( rho_u2[ e ] + rho_u2[ w ] + rho_u2[ s ] + rho_u2[ n ] - 4.0 * rho_u2[ c ] )
                    - ( rho_u2[ e ] * u1[ e ] - rho_u2[ w ] * u1[ w ] ) / ( 2.0 * hx )
                    - ( rho_u2[ n ] * u2[ n ] - rho_u2[ s ] * u2[ s ] ) / ( 2.0 * hy );
}

#endif
+31 −0
Original line number Diff line number Diff line
/***************************************************************************
                          main.cpp  -  description
                             -------------------
    begin                : Jan 12, 2013
    copyright            : (C) 2013 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <cstdlib>
#include "navier-stokes-conf.h"
#include "navierStokesSetter.h"
#include <solvers/tnlSolver.h>

int main( int argc, char* argv[] )
{
   tnlSolver< navierStokesSetter > solver;
   if( ! solver. run( CONFIG_FILE, argc, argv ) )
      return EXIT_FAILURE;
   return EXIT_SUCCESS;
}

+38 −0
Original line number Diff line number Diff line
#!/bin/bash

function processFile()
{
   file=${1}
         
   gnuplotcommand="
   set terminal png giant size 1280,1280 crop;
   set output '`basename $file ".gplt"`.png';
   set pm3d map;
   set palette defined(0.0 0.5 1.0 0, 0.02 \"light-goldenrod\", 0.04 \"yellow\", 0.08 \"red\", 0.4 \"light-blue\", 1.0 \"blue\");
   unset key;
   set size ratio -1;
   set pointsize 0.4;"
    
   if ! test x$2 = x;
   then
     gnuplotcommand="${gnuplotcommand} set xrange [0:$2];"
   fi
   if ! test x$3 = x;
   then
     gnuplotcommand="${gnuplotcommand} set yrange [0:$3];"
   fi
   if ! test x$4 = x;
   then
     gnuplotcommand="${gnuplotcommand} set cbrange [0:$4];"
   fi
   
   gnuplotcommand="${gnuplotcommand} splot '$file' w pm3d title '${1}';"
   
   echo ${gnuplotcommand} | gnuplot
}  

for file in ${1}*.gplt
do
   echo -ne "Creating: `basename $file ".gplt"`.png     \r"
   processFile ${file} ${2} ${3} ${4}
done
Loading