diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 495f7e6e2ac6adb284ce8addbfb3cdd9d5168a15..80e1cf9833e94a871c812d04cc1ede21ab3ebaa3 100755 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory( heat-equation ) add_subdirectory( navier-stokes ) +add_subdirectory( mean-curvature-flow ) diff --git a/examples/mean-curvature-flow/CMakeLists.txt b/examples/mean-curvature-flow/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..be359c10fd7f6983ae7d77e7192c402f5dc73763 --- /dev/null +++ b/examples/mean-curvature-flow/CMakeLists.txt @@ -0,0 +1,29 @@ +set( tnl_mean_curvature_flow_SOURCES + tnl-mean-curvature-flow.cpp + tnl-mean-curvature-flow-eoc.cpp + tnl-mean-curvature-flow.cu + tnl-mean-curvature-flow-eoc.cu ) + +IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE(tnl-mean-curvature-flow${debugExt} tnl-mean-curvature-flow.cu) + CUDA_ADD_EXECUTABLE(tnl-mean-curvature-flow-eoc-test${debugExt} tnl-mean-curvature-flow-eoc.cu) + target_link_libraries (tnl-mean-curvature-flow${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) + target_link_libraries (tnl-mean-curvature-flow-eoc-test${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) +ELSE( BUILD_CUDA ) + ADD_EXECUTABLE(tnl-mean-curvature-flow${debugExt} tnl-mean-curvature-flow.cpp) + ADD_EXECUTABLE(tnl-mean-curvature-flow-eoc-test${debugExt} tnl-mean-curvature-flow-eoc.cpp) + target_link_libraries (tnl-mean-curvature-flow${debugExt} tnl${debugExt}-${tnlVersion} ) + target_link_libraries (tnl-mean-curvature-flow-eoc-test${debugExt} tnl${debugExt}-${tnlVersion} ) +ENDIF( BUILD_CUDA ) + +INSTALL( TARGETS tnl-mean-curvature-flow${debugExt} + tnl-mean-curvature-flow-eoc-test${debugExt} + RUNTIME DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) + +INSTALL( FILES tnl-run-mean-curvature-flow-eoc-test + tnl-run-mean-curvature-flow + tnl-run-mean-curvature-flow-contour-video + tnl-run-mean-curvature-flow-videos + ${tnl_mean_curvature_flow_SOURCES} + DESTINATION share/tnl-${tnlVersion}/examples/mean-curvature-flow ) \ No newline at end of file diff --git a/examples/mean-curvature-flow/Makefile b/examples/mean-curvature-flow/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..71873be3fbafbf131bd8b092c7078a9dea9b167d --- /dev/null +++ b/examples/mean-curvature-flow/Makefile @@ -0,0 +1,36 @@ +TNL_VERSION=0.1 +TNL_INSTALL_DIR=${HOME}/local/lib +TNL_INCLUDE_DIR=${HOME}/local/include/tnl-${TNL_VERSION} + +TARGET = mean-curvature-flow-eoc +INSTALL_DIR = ${HOME}/local +CXX = g++ +CUDA_CXX = nvcc +CXX_FLAGS = -std=gnu++0x -I$(TNL_INCLUDE_DIR) -O0 -g +LD_FLAGS = -L$(TNL_INSTALL_DIR) -ltnl-dbg-0.1 + +SOURCES = tnl-mean-curvature-flow-eoc.cpp +HEADERS = +OBJECTS = tnl-mean-curvature-flow-eoc.o +DIST = $(SOURCES) Makefile + +all: $(TARGET) +clean: + rm -f $(OBJECTS) + +dist: $(DIST) + tar zcvf $(TARGET).tgz $(DIST) + +install: $(TARGET) + cp $(TARGET) $(INSTALL_DIR)/bin + cp $(INSTALL_DIR)/share/tnl-0.1/examples/mean-curvature-flow + +uninstall: $(TARGET) + rm -f $(INSTALL_DIR)/bin/$(TARGET) + rm -f $(INSTALL_DIR)/share/tnl-0.1/examples/mean-curvature-flow + +$(TARGET): $(OBJECTS) + $(CXX) -o $(TARGET) $(OBJECTS) $(LD_FLAGS) + +%.o: %.cpp $(HEADERS) + $(CXX) -c -o $@ $(CXX_FLAGS) $< diff --git a/examples/mean-curvature-flow/tnl-mean-curvature-flow-eoc.cpp b/examples/mean-curvature-flow/tnl-mean-curvature-flow-eoc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..256e235dc7fb854dcacbbba29ee8e99e8dadb721 --- /dev/null +++ b/examples/mean-curvature-flow/tnl-mean-curvature-flow-eoc.cpp @@ -0,0 +1,20 @@ +/*************************************************************************** + tnl-heat-equation-eoc.cpp - description + ------------------- + begin : Sep 7, 2014 + copyright : (C) 2014 by 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 "tnl-mean-curvature-flow-eoc.h" + + diff --git a/examples/mean-curvature-flow/tnl-mean-curvature-flow-eoc.h b/examples/mean-curvature-flow/tnl-mean-curvature-flow-eoc.h new file mode 100644 index 0000000000000000000000000000000000000000..f49752e25117eae07e4c73b2d5ad5dee32269595 --- /dev/null +++ b/examples/mean-curvature-flow/tnl-mean-curvature-flow-eoc.h @@ -0,0 +1,95 @@ +/*************************************************************************** + tnl-heat-equation-eoc.h - description + ------------------- + begin : Nov 29, 2014 + copyright : (C) 2014 by 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 TNL_MEAN_CURVATURE_FLOW_EOC_H_ +#define TNL_MEAN_CURVATURE_FLOW_EOC_H_ + +#include <solvers/tnlSolver.h> +#include <solvers/tnlFastBuildConfigTag.h> +#include <solvers/tnlBuildConfigTags.h> +#include <functions/tnlTestFunction.h> +#include <operators/tnlAnalyticDirichletBoundaryConditions.h> +#include <operators/tnlAnalyticNeumannBoundaryConditions.h> +#include <problems/tnlMeanCurvatureFlowEocRhs.h> +#include <problems/tnlMeanCurvatureFlowEocProblem.h> +#include <operators/diffusion/tnlExactNonlinearDiffusion.h> +#include <operators/diffusion/tnlNonlinearDiffusion.h> +#include <operators/operator-Q/tnlOneSideDiffOperatorQ.h> +#include <operators/operator-Q/tnlFiniteVolumeOperatorQ.h> +#include <operators/diffusion/tnlExactNonlinearDiffusion.h> +#include <operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h> +#include <operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h> +#include <operators/operator-Q/tnlExactOperatorQ.h> + +//typedef tnlDefaultConfigTag BuildConfig; +typedef tnlFastBuildConfig BuildConfig; + +template< typename ConfigTag > +class meanCurvatureFlowEocConfig +{ + public: + static void configSetup( tnlConfigDescription& config ) + { + config.addDelimiter( "Mean Curvature Flow EOC settings:" ); + config.addEntry< double >( "eps", "This sets a eps in operator Q.", 1.0 ); + config.addDelimiter( "Tests setting::" ); + tnlTestFunction< 3, double >::configSetup( config ); + } +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter > +class meanCurvatureFlowEocSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef tnlStaticVector< MeshType::Dimensions, Real > Vertex; + + static bool run( const tnlParameterContainer& parameters ) + { + enum { Dimensions = MeshType::Dimensions }; + typedef tnlFiniteVolumeOperatorQ<MeshType, Real, Index, 0> OperatorQ; + typedef tnlFiniteVolumeNonlinearOperator<MeshType, OperatorQ, Real, Index > NonlinearOperator; + typedef tnlNonlinearDiffusion< MeshType, NonlinearOperator, Real, Index > ApproximateOperator; + typedef tnlExactNonlinearDiffusion< tnlExactOperatorQ<Dimensions>, Dimensions > ExactOperator; + typedef tnlTestFunction< MeshType::Dimensions, Real, Device > TestFunction; + typedef tnlMeanCurvatureFlowEocRhs< ExactOperator, TestFunction > RightHandSide; + typedef tnlStaticVector < MeshType::Dimensions, Real > Vertex; + typedef tnlAnalyticDirichletBoundaryConditions< MeshType, TestFunction, Real, Index > BoundaryConditions; + typedef tnlMeanCurvatureFlowEocProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Solver; + SolverStarter solverStarter; + return solverStarter.template run< Solver >( parameters ); + }; +}; + +int main( int argc, char* argv[] ) +{ + tnlSolver< meanCurvatureFlowEocSetter, meanCurvatureFlowEocConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} + +#endif /* TNL_MEAN_CURVATURE_FLOW_EOC_H_ */ diff --git a/examples/mean-curvature-flow/tnl-mean-curvature-flow.cpp b/examples/mean-curvature-flow/tnl-mean-curvature-flow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78dc54d4cdad74eb75b7881fce6f274d9b7c6874 --- /dev/null +++ b/examples/mean-curvature-flow/tnl-mean-curvature-flow.cpp @@ -0,0 +1,18 @@ +/*************************************************************************** + tnl-heat-equation.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 "tnl-mean-curvature-flow.h" diff --git a/examples/mean-curvature-flow/tnl-mean-curvature-flow.h b/examples/mean-curvature-flow/tnl-mean-curvature-flow.h new file mode 100644 index 0000000000000000000000000000000000000000..dfc56557759ea5091f9bb8b67df79784523f371a --- /dev/null +++ b/examples/mean-curvature-flow/tnl-mean-curvature-flow.h @@ -0,0 +1,120 @@ +/*************************************************************************** + tnl-heat-equation.h - description + ------------------- + begin : Nov 29, 2014 + copyright : (C) 2014 by 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 TNL_MEAN_CURVATIVE_FLOW_H_ +#define TNL_MEAN_CURVATIVE_FLOW_H_ + +#include <solvers/tnlSolver.h> +#include <solvers/tnlFastBuildConfigTag.h> +#include <operators/diffusion/tnlLinearDiffusion.h> +#include <operators/tnlDirichletBoundaryConditions.h> +#include <operators/tnlNeumannBoundaryConditions.h> +#include <functions/tnlConstantFunction.h> +#include <problems/tnlMeanCurvatureFlowProblem.h> +#include <operators/diffusion/tnlNonlinearDiffusion.h> +#include <operators/operator-Q/tnlOneSideDiffOperatorQ.h> +#include <operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h> +#include <functions/tnlMeshFunction.h> + +//typedef tnlDefaultConfigTag BuildConfig; +typedef tnlFastBuildConfig BuildConfig; + +template< typename ConfigTag > +class meanCurvatureFlowConfig +{ + public: + static void configSetup( tnlConfigDescription& config ) + { + config.addDelimiter( "Mean Curvature Flow settings:" ); + config.addEntry< tnlString >( "boundary-conditions-type", "Choose the boundary conditions type.", "dirichlet"); + config.addEntryEnum< tnlString >( "dirichlet" ); + config.addEntryEnum< tnlString >( "neumann" ); + + config.addEntry< tnlString >( "boundary-conditions-file", "File with the values of the boundary conditions.", "boundary.tnl" ); + config.addEntry< double >( "boundary-conditions-constant", "This sets a value in case of the constant boundary conditions." ); + config.addEntry< tnlString >( "initial-condition", "File with the initial condition.", "initial.tnl"); + config.addEntry< double >( "right-hand-side-constant", "This sets a value in case of the constant right hand side.", 0.0 ); + config.addEntry< double >( "eps", "This sets a eps in operator Q.", 1.0 ); + }; +}; + +template< typename Real, + typename Device, + typename Index, + typename MeshType, + typename ConfigTag, + typename SolverStarter > +class meanCurvatureFlowSetter +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + typedef tnlStaticVector< MeshType::meshDimensions, Real > Vertex; + + static bool run( const tnlParameterContainer& parameters ) + { + enum { Dimensions = MeshType::meshDimensions }; + typedef tnlOneSideDiffOperatorQ<MeshType, Real, Index, 0> OperatorQ; + typedef tnlOneSideDiffNonlinearOperator<MeshType, OperatorQ, Real, Index > NonlinearOperator; + typedef tnlNonlinearDiffusion< MeshType, NonlinearOperator, Real, Index > ApproximateOperator; + typedef tnlConstantFunction< Dimensions, Real > RightHandSide; + typedef tnlStaticVector< MeshType::meshDimensions, Real > Vertex; + + tnlString boundaryConditionsType = parameters.getParameter< tnlString >( "boundary-conditions-type" ); + if( parameters.checkParameter( "boundary-conditions-constant" ) ) + { + typedef tnlConstantFunction< Dimensions, Real > ConstantFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef tnlDirichletBoundaryConditions< MeshType, ConstantFunction, Real, Index > BoundaryConditions; + typedef tnlMeanCurvatureFlowProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Solver; + SolverStarter solverStarter; + return solverStarter.template run< Solver >( parameters ); + } + typedef tnlNeumannBoundaryConditions< MeshType, ConstantFunction, Real, Index > BoundaryConditions; + typedef tnlMeanCurvatureFlowProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Solver; + SolverStarter solverStarter; + return solverStarter.template run< Solver >( parameters ); + } + //typedef tnlVector< Real, Device, Index > VectorType; + typedef tnlMeshFunction< MeshType > MeshFunction; + if( boundaryConditionsType == "dirichlet" ) + { + typedef tnlDirichletBoundaryConditions< MeshType, MeshFunction, Real, Index > BoundaryConditions; + typedef tnlMeanCurvatureFlowProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Solver; + SolverStarter solverStarter; + return solverStarter.template run< Solver >( parameters ); + } + typedef tnlNeumannBoundaryConditions< MeshType, MeshFunction, Real, Index > BoundaryConditions; + typedef tnlMeanCurvatureFlowProblem< MeshType, BoundaryConditions, RightHandSide, ApproximateOperator > Solver; + SolverStarter solverStarter; + return solverStarter.template run< Solver >( parameters ); + }; +}; + +int main( int argc, char* argv[] ) +{ + tnlSolver< meanCurvatureFlowSetter, meanCurvatureFlowConfig, BuildConfig > solver; + if( ! solver. run( argc, argv ) ) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} + +#endif /* TNL_MEAN_CURVATIVE_FLOW_H_ */ diff --git a/examples/mean-curvature-flow/tnl-run-mean-curvature-flow b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow new file mode 100644 index 0000000000000000000000000000000000000000..c44ad55786ea7790f1e9bacc670b917cb1faacf7 --- /dev/null +++ b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow @@ -0,0 +1,90 @@ +#!/bin/bash + +dofSize=64 +dimension=2; +proportions=1 + +analyticFunction="exp-bump" +timeFunction="cosinus" + +amplitude=1.0 +waveLength=1.0 +waveLengthX=1.0 +waveLengthY=1.0 +waveLengthZ=1.0 +wavesNumber=0.0 +wavesNumberX=0.0 +wavesNumberY=0.0 +wavesNumberZ=0.0 +phase=0.0 +phaseX=0.0 +phaseY=0.0 +phaseZ=0.0 +sigma=1.0 + +tnl-grid-setup --dimensions ${dimension} \ + --proportions-x ${proportions} \ + --proportions-y ${proportions} \ + --proportions-z ${proportions} \ + --origin-x 0 \ + --origin-y 0 \ + --origin-z 0 \ + --size-x ${dofSize} \ + --size-y ${dofSize} \ + --size-z ${dofSize} \ + +tnl-init --mesh mesh.tnl \ + --test-function ${analyticFunction} \ + --output-file initial.tnl \ + --amplitude ${amplitude} \ + --wave-length ${waveLength} \ + --wave-length-x ${waveLengthX} \ + --wave-length-y ${waveLengthY} \ + --wave-length-z ${waveLengthZ} \ + --waves-number ${wavesNumber} \ + --waves-number-x ${wavesNumberX} \ + --waves-number-y ${wavesNumberY} \ + --waves-number-z ${wavesNumberZ} \ + --phase ${phase} \ + --phase-x ${phaseX} \ + --phase-y ${phaseY} \ + --phase-z ${phaseZ} \ + --sigma ${sigma} \ + +tnl-mean-curvature-flow --time-discretisation explicit \ + --boundary-conditions-type dirichlet \ + --boundary-conditions-constant 0.5 \ + --discrete-solver merson \ + --snapshot-period 0.0005 \ + --final-time 0.1 \ + +tnl-view --mesh mesh.tnl \ + --input-files *.tnl \ + +seznam=`ls u-*.gplt` + +for fname in $seznam ; do + echo "Drawing $fname" +gnuplot << EOF + set terminal unknown + #set view 33,33 #3D + #unset xtics + #unset ytics + #unset ztics + unset border + set output '$fname.png' + set yrange [-1.2:1.2] + set zrange [0.4:1.1] + set terminal png + set title "Numerical solution" + splot '$fname' with line +EOF +done + + +mencoder "mf://u-*.png" -mf fps=22 -o diffusion.avi -ovc lavc -lavcopts vcodec=mpeg4 + +#rm *.png +#rm *.tnl +#rm *.gplt + diff --git a/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-contour-video b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-contour-video new file mode 100755 index 0000000000000000000000000000000000000000..d4d1784c7a6e51945f2659d60d5dce413d508acc --- /dev/null +++ b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-contour-video @@ -0,0 +1,184 @@ +#!/bin/bash + +device="host" +sizes="16" +initFunctions="sin-bumps" +snapshotPeriod=0.001 +finalTime=0.15 +solverName="mean-curvature-flow" +boundaryCondition="neumann" +boundaryValue=0 +minZ=-1 +maxZ=1 +contourHeight=0.3 + +spaceStep=$(expr 1/($sizes-2) | bc | sed 's/^\./0./') + +setupInitFunction() +{ + initFunction=$1 + origin=0 + proportions=1 + amplitude=1.0 + waveLength=1.0 + waveLengthX=1.0 + waveLengthY=1.0 + waveLengthZ=1.0 + wavesNumber=0.0 + wavesNumberX=0.0 + wavesNumberY=0.0 + wavesNumberZ=0.0 + phase=0.0 + phaseX=0.0 + phaseY=0.0 + phaseZ=0.0 + sigma=1 +} + +setupGrid() +{ + gridSize=$1 + tnl-grid-setup --dimensions 2 \ + --origin-x ${origin} \ + --origin-y ${origin} \ + --origin-z ${origin} \ + --proportions-x ${proportions} \ + --proportions-y ${proportions} \ + --proportions-z ${proportions} \ + --size-x ${gridSize} \ + --size-y ${gridSize} \ + --size-z ${gridSize} +} + +setInitialCondition() +{ + initFunction=$1 + tnl-init --test-function ${initFunction} \ + --output-file initial.tnl \ + --amplitude ${amplitude} \ + --wave-length ${waveLength} \ + --wave-length-x ${waveLengthX} \ + --wave-length-y ${waveLengthY} \ + --wave-length-z ${waveLengthZ} \ + --waves-number ${wavesNumber} \ + --waves-number-x ${wavesNumberX} \ + --waves-number-y ${wavesNumberY} \ + --waves-number-z ${wavesNumberZ} \ + --phase ${phase} \ + --phase-x ${phaseX} \ + --phase-y ${phaseY} \ + --phase-z ${phaseZ} \ + --sigma ${sigma} \ + --time-dependence none +} + +solve() +{ + timeDiscretisation=$1 + discreteSolver=$2 + ${solverName} --device ${device} \ + --mesh mesh.tnl \ + --initial-condition initial.tnl \ + --snapshot-period ${snapshotPeriod} \ + --time-discretisation ${timeDiscretisation} \ + --time-step 1 \ + --time-step-order 2 \ + --discrete-solver ${discreteSolver} \ + --merson-adaptivity 1.0e-7 \ + --sor-omega 1.95 \ + --gmres-restarting 20 \ + --min-iterations 20 \ + --convergence-residue 1.0e-12 \ + --boundary-conditions-type ${boundaryCondition} \ + --boundary-conditions-constant ${boundaryValue} \ + --final-time ${finalTime} +} + +view() +{ + tnl-view --input-files u-*.tnl + tnl-view --input-files initial.tnl +} + +generate3DVid() +{ +seznam=`ls u-*.gplt` +step=0 +for fname in $seznam ; do +step=$((${step}+1)) +time=$(expr $step*$snapshotPeriod | bc | sed 's/^\./0./') +echo "Drawing contour $fname" +gnuplot << EOF +set output '${fname}.png' +set xrange [${1}:${proportions}] +set yrange [${1}:${proportions}] +set zrange [${minZ}:${maxZ}] +unset surface +set terminal png size 1200,600 +set view map +set title 'Numerical solution - contour in height ${contourHeight} - T: ${time}' +set pm3d interpolate 100,100 +set size square +set contour base +unset colorbox +set cntrparam levels discrete ${contourHeight} +splot '$fname' with pm3d notitle +EOF +done + +mencoder "mf://u-*.png" -mf fps=4 -o mean_curvature_contour_${contourHeight}_$size.avi -ovc lavc -lavcopts vcodec=mpeg4 + +rm *.png +rm *.tnl +rm *.gplt +rm mesh.asy +rm computation-done + +} + +runTest() +{ + for initFunction in ${initFunctions}; + do + cd ${initFunction}-videos + setupInitFunction ${initFunction} + + for size in $sizes; + do + cd $size + echo "" + echo "" + echo "" + if test ! -f computation-done; + then + touch computation-in-progress + echo "=========================================================================" + echo "=== SETTING UP THE GRID ===" + echo "=========================================================================" + setupGrid $size + echo "=========================================================================" + echo "=== WRITING THE EXACT SOLUTION ===" + echo "=========================================================================" + setInitialCondition $initFunction + echo "=========================================================================" + echo "=== STARTING THE SOLVER ===" + echo "=========================================================================" + solve explicit merson + #solve semi-implicit gmres + mv computation-in-progress computation-done + echo "=========================================================================" + echo "=== COMPUTATION DONE ===" + echo "=========================================================================" + view + generate3DVid $origin $proportions + cd .. + lastSize=$size + fi + cd .. + done + cd .. + done +} + +runTest + diff --git a/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-eoc-test b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-eoc-test new file mode 100755 index 0000000000000000000000000000000000000000..c4b9057e6c0d9c598e0af8a39f07692a3c7f97a4 --- /dev/null +++ b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-eoc-test @@ -0,0 +1,198 @@ +#!/bin/bash + +device="host" +dimensions="3D" +sizes3D="16 32 64" +testFunctions="exp-bump sin-wave sin-bumps" +snapshotPeriod=0.001 +finalTime=0.01 +timeDependence="cosine" +solverName="mean-curvature-flow-eoc" +#solverName="gdb --args tnl-heat-equation-eoc-test-dbg" + +setupTestFunction() +{ + testFunction=$1 +# if test x${testFunction} = "xexp-bump"; +# then + origin=2 + proportions=2 + amplitude=1.0 + waveLength=1.0 + waveLengthX=1.0 + waveLengthY=1.0 + waveLengthZ=1.0 + wavesNumber=0.0 + wavesNumberX=0.0 + wavesNumberY=0.0 + wavesNumberZ=0.0 + phase=0.0 + phaseX=0.0 + phaseY=0.0 + phaseZ=0.0 + sigma=1 +# fi +} + +setupGrid() +{ + dimensions=$1 + gridSize=$2 + tnl-grid-setup --dimensions ${dimensions} \ + --origin-x ${origin} \ + --origin-y ${origin} \ + --origin-z ${origin} \ + --proportions-x ${proportions} \ + --proportions-y ${proportions} \ + --proportions-z ${proportions} \ + --size-x ${gridSize} \ + --size-y ${gridSize} \ + --size-z ${gridSize} +} + +setInitialCondition() +{ + testFunction=$1 + tnl-init --test-function ${testFunction} \ + --output-file exact-u.tnl \ + --amplitude ${amplitude} \ + --wave-length ${waveLength} \ + --wave-length-x ${waveLengthX} \ + --wave-length-y ${waveLengthY} \ + --wave-length-z ${waveLengthZ} \ + --waves-number ${wavesNumber} \ + --waves-number-x ${wavesNumberX} \ + --waves-number-y ${wavesNumberY} \ + --waves-number-z ${wavesNumberZ} \ + --phase ${phase} \ + --phase-x ${phaseX} \ + --phase-y ${phaseY} \ + --phase-z ${phaseZ} \ + --sigma ${sigma} \ + --time-dependence ${timeDependence} \ + --snapshot-period ${snapshotPeriod} \ + --final-time ${finalTime} +} + +solve() +{ + timeDiscretisation=$1 + discreteSolver=$2 + ${solverName} --device ${device} \ + --mesh mesh.tnl \ + --initial-condition exact-u-00000.tnl \ + --time-discretisation ${timeDiscretisation} \ + --time-step 1 \ + --time-step-order 2 \ + --discrete-solver ${discreteSolver} \ + --merson-adaptivity 1.0e-10 \ + --sor-omega 1.95 \ + --gmres-restarting 20 \ + --min-iterations 50 \ + --convergence-residue 1.0e-14 \ + --test-function ${testFunction}\ + --amplitude ${amplitude} \ + --wave-length ${waveLength} \ + --wave-length-x ${waveLengthX} \ + --wave-length-y ${waveLengthY} \ + --wave-length-z ${waveLengthZ} \ + --waves-number ${wavesNumber} \ + --waves-number-x ${wavesNumberX} \ + --waves-number-y ${wavesNumberY} \ + --waves-number-z ${wavesNumberZ} \ + --phase ${phase} \ + --phase-x ${phaseX} \ + --phase-y ${phaseY} \ + --phase-z ${phaseZ} \ + --sigma ${sigma} \ + --time-dependence ${timeDependence} \ + --snapshot-period ${snapshotPeriod} \ + --final-time ${finalTime} +} + +computeError() +{ + tnl-diff --mesh mesh.tnl \ + --input-files exact-u-*.tnl u-*.tnl \ + --mode halves \ + --snapshot-period ${snapshotPeriod} \ + --output-file errors.txt \ + --write-difference yes +} + +runTest() +{ + for testFunction in ${testFunctions}; + do + mkdir -p ${testFunction} + cd ${testFunction} + setupTestFunction ${testFunction} + + for dim in ${dimensions}; + do + mkdir -p $dim + cd ${dim} + if test $dim = 1D; + then + sizes=$sizes1D + fi + if test $dim = 2D; + then + sizes=$sizes2D + fi + if test $dim = 3D; + then + sizes=$sizes3D + fi + + lastSize="" + for size in $sizes; + do + mkdir -p $size + cd $size + echo "" + echo "" + echo "" + if test ! -f computation-done; + then + touch computation-in-progress + echo "=========================================================================" + echo "=== SETTING UP THE GRID ===" + echo "=========================================================================" + setupGrid $dim $size + echo "=========================================================================" + echo "=== WRITING THE EXACT SOLUTION ===" + echo "=========================================================================" + setInitialCondition $testFunction + echo "=========================================================================" + echo "=== STARTING THE SOLVER ===" + echo "=========================================================================" + #solve explicit merson + solve semi-implicit gmres + mv computation-in-progress computation-done + fi + echo "=========================================================================" + echo "=== COMPUTING THE ERROR ===" + echo "=========================================================================" + computeError + echo "=========================================================================" + echo "=== COMPUTING THE EOC ===" + echo "=========================================================================" + if test ! x$lastSize = x; + then + tnl-err2eoc ../$lastSize/errors.txt errors.txt + fi + echo "=========================================================================" + echo "=== COMPUTATION DONE ===" + echo "=========================================================================" + cd .. + lastSize=$size + done + + cd .. + done + cd .. + done +} + +runTest diff --git a/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-videos b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-videos new file mode 100755 index 0000000000000000000000000000000000000000..a64efdcb9611bd8852fc45ea1a29d05073e31937 --- /dev/null +++ b/examples/mean-curvature-flow/tnl-run-mean-curvature-flow-videos @@ -0,0 +1,247 @@ +#!/bin/bash + +device="host" +sizes="64" +initFunctions="pseudoSquare" +snapshotPeriod=0.001 +finalTime=0.1 +solverName="mean-curvature-flow" +boundaryCondition="neumann" +boundaryValue=0 +minZ=-3 +maxZ=6 +contourHeight=0 +numberOfContours=8 +numberOfInterpolations=10 +eps=0.00001 + +setupInitFunction() +{ + initFunction=$1 + origin=-2 + proportions=4 + amplitude=1.0 + waveLength=1.0 + waveLengthX=1.0 + waveLengthY=1.0 + waveLengthZ=1.0 + wavesNumber=0.0 + wavesNumberX=0.0 + wavesNumberY=0.0 + wavesNumberZ=0.0 + phase=0.0 + phaseX=0.0 + phaseY=0.0 + phaseZ=0.0 + sigma=1.0 + diameter=0.6 + height=1.2 +} + +setupGrid() +{ + gridSize=$1 + tnl-grid-setup --dimensions 2 \ + --origin-x ${origin} \ + --origin-y ${origin} \ + --origin-z ${origin} \ + --proportions-x ${proportions} \ + --proportions-y ${proportions} \ + --proportions-z ${proportions} \ + --size-x ${gridSize} \ + --size-y ${gridSize} \ + --size-z ${gridSize} +} + +setInitialCondition() +{ + initFunction=$1 + tnl-init --test-function ${initFunction} \ + --output-file initial.tnl \ + --amplitude ${amplitude} \ + --wave-length ${waveLength} \ + --wave-length-x ${waveLengthX} \ + --wave-length-y ${waveLengthY} \ + --wave-length-z ${waveLengthZ} \ + --waves-number ${wavesNumber} \ + --waves-number-x ${wavesNumberX} \ + --waves-number-y ${wavesNumberY} \ + --waves-number-z ${wavesNumberZ} \ + --phase ${phase} \ + --phase-x ${phaseX} \ + --phase-y ${phaseY} \ + --phase-z ${phaseZ} \ + --sigma ${sigma} \ + --diameter ${diameter} \ + --height ${height} \ + --time-dependence none +} + +solve() +{ + timeDiscretisation=$1 + discreteSolver=$2 + ${solverName} --device ${device} \ + --mesh mesh.tnl \ + --initial-condition initial.tnl \ + --snapshot-period ${snapshotPeriod} \ + --time-discretisation ${timeDiscretisation} \ + --time-step 1 \ + --time-step-order 2 \ + --discrete-solver ${discreteSolver} \ + --merson-adaptivity 1.0e-7 \ + --sor-omega 1.95 \ + --gmres-restarting 20 \ + --min-iterations 20 \ + --convergence-residue 1.0e-12 \ + --boundary-conditions-type ${boundaryCondition} \ + --boundary-conditions-constant ${boundaryValue} \ + --eps ${eps} \ + --final-time ${finalTime} +} + +view() +{ + tnl-view --input-files u-*.tnl + tnl-view --input-files initial.tnl +} + +generate3DVid() +{ +domainEnd=$( expr ${origin}+${proportions} | bc | sed 's/^\./0./' | sed 's/^-\./-0./' ) + +seznam=`ls u-*.gplt` +step=0 +for fname in $seznam ; do +time=$(expr $step*$snapshotPeriod | bc | sed 's/^\./0./') +echo "Drawing $fname" +gnuplot << EOF +set output '$fname.png' +set xrange [${1}:${domainEnd}] +set yrange [${1}:${domainEnd}] +set zrange [${minZ}:${maxZ}] +set pm3d +unset surface +set terminal png size 1200,600 +set cbrange [-1:1] +set view 22,33,0.8,3 +set title 'Numerical solution - T: ${time}' +set pm3d interpolate ${numberOfInterpolations},${numberOfInterpolations} +splot '$fname' with pm3d notitle +EOF +step=$((${step}+1)) +done + +mencoder "mf://u-*.png" -mf fps=4 -o mean_curvature_$size.avi -ovc lavc -lavcopts vcodec=mpeg4 +rm *.png + +seznam=`ls u-*.gplt` +step=0 +for fname in $seznam ; do +time=$(expr $step*$snapshotPeriod | bc | sed 's/^\./0./') +echo "Drawing map $fname" +gnuplot << EOF +set output '${fname}.png' +set xrange [${1}:${domainEnd}] +set yrange [${1}:${domainEnd}] +set zrange [${minZ}:${maxZ}] +set pm3d +unset surface +set terminal png size 1200,600 +set cbrange [-1:1] +set view map +set title 'Numerical solution - map - T: ${time}' +set pm3d interpolate 100,100 +set size square +set contour base +set cntrparam levels ${numberOfContours} +splot '$fname' with pm3d notitle +EOF +step=$((${step}+1)) +done + +mencoder "mf://u-*.png" -mf fps=4 -o mean_curvature_map_$size.avi -ovc lavc -lavcopts vcodec=mpeg4 +rm *.png + +seznam=`ls u-*.gplt` +step=0 +for fname in $seznam ; do +time=$(expr $step*$snapshotPeriod | bc | sed 's/^\./0./') +echo "Drawing contour $fname" +gnuplot << EOF +set output '${fname}.png' +set xrange [${1}:${domainEnd}] +set yrange [${1}:${domainEnd}] +set zrange [${minZ}:${maxZ}] +unset surface +set terminal png size 1200,600 +set view map +set title 'Numerical solution - contour in height ${contourHeight} - T: ${time}' +set pm3d interpolate 100,100 +set size square +set contour base +unset colorbox +set cntrparam levels discrete ${contourHeight} +splot '$fname' with pm3d notitle +EOF +step=$((${step}+1)) +done + +mencoder "mf://u-*.png" -mf fps=4 -o mean_curvature_contour_${contourHeight}_$size.avi -ovc lavc -lavcopts vcodec=mpeg4 + +rm *.png +rm *.tnl +rm *.gplt +rm mesh.asy +rm computation-done + +} + +runTest() +{ + for initFunction in ${initFunctions}; + do + mkdir -p ${initFunction}-videos + cd ${initFunction}-videos + setupInitFunction ${initFunction} + + for size in $sizes; + do + mkdir -p $size + cd $size + echo "" + echo "" + echo "" + if test ! -f computation-done; + then + touch computation-in-progress + echo "=========================================================================" + echo "=== SETTING UP THE GRID ===" + echo "=========================================================================" + setupGrid $size + echo "=========================================================================" + echo "=== WRITING THE EXACT SOLUTION ===" + echo "=========================================================================" + setInitialCondition $initFunction + echo "=========================================================================" + echo "=== STARTING THE SOLVER ===" + echo "=========================================================================" + solve explicit merson + #solve semi-implicit gmres + mv computation-in-progress computation-done + echo "=========================================================================" + echo "=== COMPUTATION DONE ===" + echo "=========================================================================" + view + generate3DVid $origin $proportions + cd .. + lastSize=$size + fi + cd .. + done + cd .. + done +} + +runTest + diff --git a/src/functions/CMakeLists.txt b/src/functions/CMakeLists.txt index 16b7e41311036d2f1f5cc25efae3127b97fe2422..9d221788e599fd3d0607c11c4e82b6fd6691d65a 100755 --- a/src/functions/CMakeLists.txt +++ b/src/functions/CMakeLists.txt @@ -1,3 +1,5 @@ +ADD_SUBDIRECTORY( initial_conditions ) + SET( headers tnlFunctionDiscretizer.h tnlFunctionDiscretizer_impl.h tnlFunctionEnumerator.h @@ -30,4 +32,4 @@ set( tnl_functions_SOURCES ${common_SOURCES} PARENT_SCOPE ) -INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/functions ) \ No newline at end of file +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/functions ) diff --git a/src/functions/initial_conditions/CMakeLists.txt b/src/functions/initial_conditions/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..461bde7bceb385b74b0d264953ce9fb7f289ec18 --- /dev/null +++ b/src/functions/initial_conditions/CMakeLists.txt @@ -0,0 +1,11 @@ +ADD_SUBDIRECTORY( level_set_functions ) + +SET( headers tnlCylinderFunction.h + tnlCylinderFunction_impl.h + tnlFlowerpotFunction.h + tnlFlowerpotFunction_impl.h + tnlTwinsFunction.h + tnlTwinsFunction_impl.h + ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/functors/initial_conditions ) diff --git a/src/functions/initial_conditions/CMakeLists.txt~ b/src/functions/initial_conditions/CMakeLists.txt~ new file mode 100755 index 0000000000000000000000000000000000000000..fcfe293ea4d8d756d7bb371b56a6088166554123 --- /dev/null +++ b/src/functions/initial_conditions/CMakeLists.txt~ @@ -0,0 +1,5 @@ +SET( headers tnlCylinderFunction.h + tnlCylinderFunction_impl.h + ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/problems ) diff --git a/src/functions/initial_conditions/level_set_functions/CMakeLists.txt b/src/functions/initial_conditions/level_set_functions/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..45ab723961fa2421b0824db1550f22b6643998d0 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/CMakeLists.txt @@ -0,0 +1,7 @@ +SET( headers tnlBlobFunction.h + tnlBlobFunction_impl.h + tnlPseudoSquareFunction.h + tnlPseudoSquareFunction_impl.h + ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/functors/initial_conditions/level_set_functions ) diff --git a/src/functions/initial_conditions/level_set_functions/CMakeLists.txt~ b/src/functions/initial_conditions/level_set_functions/CMakeLists.txt~ new file mode 100755 index 0000000000000000000000000000000000000000..aaac57306c17920568010efc120817e452c73af3 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/CMakeLists.txt~ @@ -0,0 +1,11 @@ +ADD_SUBDIRECTORY( level_set_conditions ) + +SET( headers tnlCylinderFunction.h + tnlCylinderFunction_impl.h + tnlFlowerpotFunction.h + tnlFlowerpotFunction_impl.h + tnlTwinsFunction.h + tnlTwinsFunction_impl.h + ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/functions/initial_conditions ) diff --git a/src/functions/initial_conditions/level_set_functions/tnlBlobFunction.h b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..b19b19ebec8cb71246c9cbbebe13f29fd118f411 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction.h @@ -0,0 +1,146 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLBLOBFUNCTION_H_ +#define TNLBLOBFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functions/tnlFunction.h> +#include <core/tnlCuda.h> + +template< typename Real, + int Dimensions > +class tnlBlobFunctionBase : public tnlFunction< Dimensions, AnalyticFunction > +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + protected: + + RealType height; +}; + +template< int Dimensions, + typename Real > +class tnlBlobFunction +{ +}; + +template< typename Real > +class tnlBlobFunction< 1, Real > : public tnlBlobFunctionBase< Real, 1 > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlBlobFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlBlobFunction< 2, Real > : public tnlBlobFunctionBase< Real, 2 > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlBlobFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlBlobFunction< 3, Real > : public tnlBlobFunctionBase< Real, 3 > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlBlobFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlBlobFunction< Dimensions, Real >& f ) +{ + str << "Level-set pseudo square function."; + return str; +} + +#include <functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h> + + +#endif /* TNLBLOBFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlBlobFunction.h~ b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction.h~ new file mode 100644 index 0000000000000000000000000000000000000000..c085289494fb4d25b5e0abe78e707d266f833be2 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction.h~ @@ -0,0 +1,160 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLBLOBFUNCTION_H_ +#define TNLBLOBFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functors/tnlFunctionType.h> + +template< typename Real > +class tnlBlobFunctionBase +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + protected: + + RealType height; +}; + +template< int Dimensions, + typename Real > +class tnlBlobFunction +{ +}; + +template< typename Real > +class tnlBlobFunction< 1, Real > : public tnlBlobFunctionBase< Real > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlBlobFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlBlobFunction< 2, Real > : public tnlBlobFunctionBase< Real > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlBlobFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlBlobFunction< 3, Real > : public tnlBlobFunctionBase< Real > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlBlobFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlBlobFunction< Dimensions, Real >& f ) +{ + str << "Level-set pseudo square function."; + return str; +} + +template< int FunctionDimensions, + typename Real > +class tnlFunctionType< tnlBlobFunction< FunctionDimensions, Real > > +{ + public: + + enum { Type = tnlAnalyticFunction }; +}; + + +#include <functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h> + + +#endif /* TNLBLOBFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..62a359b1331def865d52be2b5c1572bb114c85e5 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h @@ -0,0 +1,140 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLBLOBFUNCTION_IMPL_H_ +#define TNLBLOBFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/level_set_functions/tnlBlobFunction.h> + +template< typename Real, + int Dimensions > +bool +tnlBlobFunctionBase< Real, Dimensions >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->height = parameters.getParameter< double >( prefix + "height" ); + + return true; +} + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlBlobFunction< 1, Real >::getType() +{ + return "tnlBlobFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlBlobFunction< 1, Real >::tnlBlobFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlBlobFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlBlobFunction< 2, Real >::getType() +{ + return tnlString( "tnlBlobFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlBlobFunction< 2, Real >::tnlBlobFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlBlobFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return x * x + y * y - this->height - sin( cos ( 2 * x + y ) * sin ( 2 * x + y ) ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlBlobFunction< 3, Real >::getType() +{ + return tnlString( "tnlBlobFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlBlobFunction< 3, Real >::tnlBlobFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlBlobFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +#endif /* TNLBLOBFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h~ b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h~ new file mode 100644 index 0000000000000000000000000000000000000000..6e05320396a2f903146eb82e44730ca8c2a349b7 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlBlobFunction_impl.h~ @@ -0,0 +1,147 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLBLOBFUNCTION_IMPL_H_ +#define TNLBLOBFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/level_set_functions/tnlBlobFunction.h> + +template< typename Real > +bool +tnlBlobFunctionBase< Real >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->height = parameters.getParameter< double >( prefix + "height" ); + + return true; +} + + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlBlobFunction< 1, Real >::getType() +{ + return "tnlBlobFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlBlobFunction< 1, Real >::tnlBlobFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlBlobFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlBlobFunction< 2, Real >::getType() +{ + return tnlString( "tnlBlobFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlBlobFunction< 2, Real >::tnlBlobFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlBlobFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return x * x + y * y - this->height - sin( cos ( 2 * x + y ) * sin ( 2 * x + y ) ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlBlobFunction< 3, Real >::getType() +{ + return tnlString( "tnlBlobFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlBlobFunction< 3, Real >::tnlBlobFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlBlobFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return 0.0; + return 0.0; +} + + +#endif /* TNLBLOBFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..9b71ed062c33f4861bfbeae182890836d1807b82 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h @@ -0,0 +1,146 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLPSEUDOSQUAREFUNCTION_H_ +#define TNLPSEUDOSQUAREFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functions/tnlFunction.h> +#include <core/tnlCuda.h> + +template< typename Real, + int Dimensions > +class tnlPseudoSquareFunctionBase : public tnlFunction< Dimensions, AnalyticFunction > +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + protected: + + RealType height; +}; + +template< int Dimensions, + typename Real > +class tnlPseudoSquareFunction +{ +}; + +template< typename Real > +class tnlPseudoSquareFunction< 1, Real > : public tnlPseudoSquareFunctionBase< Real, 1 > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlPseudoSquareFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlPseudoSquareFunction< 2, Real > : public tnlPseudoSquareFunctionBase< Real, 2 > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlPseudoSquareFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlPseudoSquareFunction< 3, Real > : public tnlPseudoSquareFunctionBase< Real, 3 > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlPseudoSquareFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlPseudoSquareFunction< Dimensions, Real >& f ) +{ + str << "Level-set pseudo square function."; + return str; +} + +#include <functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h> + + +#endif /* TNLPSEUDOSQUAREFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h~ b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h~ new file mode 100644 index 0000000000000000000000000000000000000000..5c2350e9bbbbd2cd01834d99ffc4589b85b21913 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h~ @@ -0,0 +1,160 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLPSEUDOSQUAREFUNCTION_H_ +#define TNLPSEUDOSQUAREFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functors/tnlFunctionType.h> + +template< typename Real > +class tnlPseudoSquareFunctionBase +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + protected: + + RealType height; +}; + +template< int Dimensions, + typename Real > +class tnlPseudoSquareFunction +{ +}; + +template< typename Real > +class tnlPseudoSquareFunction< 1, Real > : public tnlPseudoSquareFunctionBase< Real > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlPseudoSquareFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlPseudoSquareFunction< 2, Real > : public tnlPseudoSquareFunctionBase< Real > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlPseudoSquareFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlPseudoSquareFunction< 3, Real > : public tnlPseudoSquareFunctionBase< Real > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlPseudoSquareFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlPseudoSquareFunction< Dimensions, Real >& f ) +{ + str << "Level-set pseudo square function."; + return str; +} + +template< int FunctionDimensions, + typename Real > +class tnlFunctionType< tnlPseudoSquareFunction< FunctionDimensions, Real > > +{ + public: + + enum { Type = tnlAnalyticFunction }; +}; + + +#include <functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h> + + +#endif /* TNLPSEUDOSQUAREFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0705654429455592c3b7cec437e6f86304c2683a --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h @@ -0,0 +1,142 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLPSEUDOSQUAREFUNCTION_IMPL_H_ +#define TNLPSEUDOSQUAREFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h> + +template< typename Real, + int Dimensions > +bool +tnlPseudoSquareFunctionBase< Real, Dimensions >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->height = parameters.getParameter< double >( prefix + "height" ); + + return true; +} + + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlPseudoSquareFunction< 1, Real >::getType() +{ + return "tnlPseudoSquareFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlPseudoSquareFunction< 1, Real >::tnlPseudoSquareFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlPseudoSquareFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlPseudoSquareFunction< 2, Real >::getType() +{ + return tnlString( "tnlPseudoSquareFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlPseudoSquareFunction< 2, Real >::tnlPseudoSquareFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlPseudoSquareFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return x * x + y * y - this->height - cos( 2 * x * y ) * cos( 2 * x * y ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlPseudoSquareFunction< 3, Real >::getType() +{ + return tnlString( "tnlPseudoSquareFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlPseudoSquareFunction< 3, Real >::tnlPseudoSquareFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlPseudoSquareFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return 0.0; + return 0.0; +} + + +#endif /* TNLPSEUDOSQUAREFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h~ b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h~ new file mode 100644 index 0000000000000000000000000000000000000000..7fb79c33ca0d36b38daf76c49cfbda89a9878b42 --- /dev/null +++ b/src/functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction_impl.h~ @@ -0,0 +1,147 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLPSEUDOSQUAREFUNCTION_IMPL_H_ +#define TNLPSEUDOSQUAREFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h> + +template< typename Real > +bool +tnlPseudoSquareFunctionBase< Real >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->height = parameters.getParameter< double >( prefix + "height" ); + + return true; +} + + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlPseudoSquareFunction< 1, Real >::getType() +{ + return "tnlPseudoSquareFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlPseudoSquareFunction< 1, Real >::tnlPseudoSquareFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlPseudoSquareFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlPseudoSquareFunction< 2, Real >::getType() +{ + return tnlString( "tnlPseudoSquareFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlPseudoSquareFunction< 2, Real >::tnlPseudoSquareFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlPseudoSquareFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return x * x + y * y - this->height - cos( 2 * x * y ) * cos( 2 * x * y ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlPseudoSquareFunction< 3, Real >::getType() +{ + return tnlString( "tnlPseudoSquareFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlPseudoSquareFunction< 3, Real >::tnlPseudoSquareFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlPseudoSquareFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return 0.0; + return 0.0; +} + + +#endif /* TNLPSEUDOSQUAREFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/tnlCylinderFunction.h b/src/functions/initial_conditions/tnlCylinderFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..4274a45499b4e716655294ee0eb3f4a55d433959 --- /dev/null +++ b/src/functions/initial_conditions/tnlCylinderFunction.h @@ -0,0 +1,150 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLCYLINDERFUNCTION_H_ +#define TNLCYLINDERFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functions/tnlFunction.h> +#include <core/tnlCuda.h> + +template< typename Real, + int Dimensions > +class tnlCylinderFunctionBase : public tnlFunction< Dimensions, AnalyticFunction > +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + void setDiameter( const RealType& sigma ); + + const RealType& getDiameter() const; + + protected: + + RealType diameter; +}; + +template< int Dimensions, + typename Real > +class tnlCylinderFunction +{ +}; + +template< typename Real > +class tnlCylinderFunction< 1, Real > : public tnlCylinderFunctionBase< Real, 1 > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlCylinderFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlCylinderFunction< 2, Real > : public tnlCylinderFunctionBase< Real, 2 > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlCylinderFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlCylinderFunction< 3, Real > : public tnlCylinderFunctionBase< Real, 3 > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlCylinderFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlCylinderFunction< Dimensions, Real >& f ) +{ + str << "Cylinder function."; + return str; +} + +#include <functions/initial_conditions/tnlCylinderFunction_impl.h> + + +#endif /* TNLEXPBUMPFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/tnlCylinderFunction.h~ b/src/functions/initial_conditions/tnlCylinderFunction.h~ new file mode 100644 index 0000000000000000000000000000000000000000..ce90d3f447ebc63929ca07dbdd0c03193d159a8d --- /dev/null +++ b/src/functions/initial_conditions/tnlCylinderFunction.h~ @@ -0,0 +1,164 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLCYLINDERFUNCTION_H_ +#define TNLCYLINDERFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functors/tnlFunctionType.h> + +template< typename Real > +class tnlCylinderFunctionBase +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + void setDiameter( const RealType& sigma ); + + const RealType& getDiameter() const; + + protected: + + RealType diameter; +}; + +template< int Dimensions, + typename Real > +class tnlCylinderFunction +{ +}; + +template< typename Real > +class tnlCylinderFunction< 1, Real > : public tnlCylinderFunctionBase< Real > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlCylinderFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlCylinderFunction< 2, Real > : public tnlCylinderFunctionBase< Real > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlCylinderFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlCylinderFunction< 3, Real > : public tnlCylinderFunctionBase< Real > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlCylinderFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlCylinderFunction< Dimensions, Real >& f ) +{ + str << "Cylinder function."; + return str; +} + +template< int FunctionDimensions, + typename Real > +class tnlFunctionType< tnlCylinderFunction< FunctionDimensions, Real > > +{ + public: + + enum { Type = tnlAnalyticFunction }; +}; + + +#include <functions/initial_conditions/tnlCylinderFunction_impl.h> + + +#endif /* TNLEXPBUMPFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/tnlCylinderFunction_impl.h b/src/functions/initial_conditions/tnlCylinderFunction_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..8e080023343b70ac216220f58aabaf56162562a5 --- /dev/null +++ b/src/functions/initial_conditions/tnlCylinderFunction_impl.h @@ -0,0 +1,156 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLCYLINDERFUNCTION_IMPL_H_ +#define TNLCYLINDERFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/tnlCylinderFunction.h> + +template< typename Real, + int Dimensions > +bool +tnlCylinderFunctionBase< Real, Dimensions >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->diameter = parameters.getParameter< double >( prefix + "diameter" ); + return true; +} + +template< typename Real, + int Dimensions > +void +tnlCylinderFunctionBase< Real, Dimensions >:: +setDiameter( const Real& sigma ) +{ + this->diameter = diameter; +} + +template< typename Real, + int Dimensions > +const Real& tnlCylinderFunctionBase< Real, Dimensions >::getDiameter() const +{ + return this->diameter; +} + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlCylinderFunction< 1, Real >::getType() +{ + return "tnlCylinderFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlCylinderFunction< 1, Real >::tnlCylinderFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlCylinderFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return ( ( x*x - this->diameter ) < 0 ) - ( ( x*x - this->diameter ) > 0 ) + 1; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlCylinderFunction< 2, Real >::getType() +{ + return tnlString( "tnlCylinderFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlCylinderFunction< 2, Real >::tnlCylinderFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlCylinderFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return ( ( x*x + y*y - this->diameter ) < 0 ) - ( ( x*x + y*y - this->diameter ) > 0 ) + 1; + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlCylinderFunction< 3, Real >::getType() +{ + return tnlString( "tnlCylinderFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlCylinderFunction< 3, Real >::tnlCylinderFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlCylinderFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return ( ( x*x + y*y + z*z - this->diameter ) < 0 ) - ( ( x*x + y*y + z*z - this->diameter ) > 0 ) + 1; + return 0.0; +} + + +#endif /* TNLCYLINDERFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/tnlCylinderFunction_impl.h~ b/src/functions/initial_conditions/tnlCylinderFunction_impl.h~ new file mode 100644 index 0000000000000000000000000000000000000000..90c250ad33356cabe14f004e60aeb771256c1612 --- /dev/null +++ b/src/functions/initial_conditions/tnlCylinderFunction_impl.h~ @@ -0,0 +1,157 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLCYLINDERFUNCTION_IMPL_H_ +#define TNLCYLINDERFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/tnlCylinderFunction.h> + +template< typename Real > +bool +tnlCylinderFunctionBase< Real >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->diameter = parameters.getParameter< double >( prefix + "diameter" ); + return true; +} + +template< typename Real > +void tnlCylinderFunctionBase< Real >::setDiameter( const Real& sigma ) +{ + this->diameter = diameter; +} + +template< typename Real > +const Real& tnlCylinderFunctionBase< Real >::getDiameter() const +{ + return this->diameter; +} + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlCylinderFunction< 1, Real >::getType() +{ + return "tnlCylinderFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlCylinderFunction< 1, Real >::tnlCylinderFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlCylinderFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return ( ( x*x - this->diameter ) < 0 ) - ( ( x*x - this->diameter ) > 0 ) + 1; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlCylinderFunction< 2, Real >::getType() +{ + return tnlString( "tnlCylinderFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlCylinderFunction< 2, Real >::tnlCylinderFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlCylinderFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return ( ( x*x + y*y - this->diameter ) < 0 ) - ( ( x*x + y*y - this->diameter ) > 0 ) + 1; + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlCylinderFunction< 3, Real >::getType() +{ + return tnlString( "tnlCylinderFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlCylinderFunction< 3, Real >::tnlCylinderFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlCylinderFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return ( ( x*x + y*y + z*z - this->diameter ) < 0 ) - ( ( x*x + y*y + z*z - this->diameter ) > 0 ) + 1; + return 0.0; +} + + +#endif /* TNLCYLINDERFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/tnlFlowerpotFunction.h b/src/functions/initial_conditions/tnlFlowerpotFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..430016baf1b58e05f41e9b6c42e8a6d211c245f2 --- /dev/null +++ b/src/functions/initial_conditions/tnlFlowerpotFunction.h @@ -0,0 +1,150 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLFLOWERPOTFUNCTION_H_ +#define TNLFLOWERPOTFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functions/tnlFunction.h> +#include <core/tnlCuda.h> + +template< typename Real, + int Dimensions > +class tnlFlowerpotFunctionBase : public tnlFunction< Dimensions, AnalyticFunction > +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + void setDiameter( const RealType& sigma ); + + const RealType& getDiameter() const; + + protected: + + RealType diameter; +}; + +template< int Dimensions, + typename Real > +class tnlFlowerpotFunction +{ +}; + +template< typename Real > +class tnlFlowerpotFunction< 1, Real > : public tnlFlowerpotFunctionBase< Real, 1 > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlFlowerpotFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlFlowerpotFunction< 2, Real > : public tnlFlowerpotFunctionBase< Real, 2 > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlFlowerpotFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlFlowerpotFunction< 3, Real > : public tnlFlowerpotFunctionBase< Real, 3 > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlFlowerpotFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlFlowerpotFunction< Dimensions, Real >& f ) +{ + str << "Flowerpot function."; + return str; +} + +#include <functions/initial_conditions/tnlFlowerpotFunction_impl.h> + + +#endif /* TNLFLOWERPOTFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/tnlFlowerpotFunction.h~ b/src/functions/initial_conditions/tnlFlowerpotFunction.h~ new file mode 100644 index 0000000000000000000000000000000000000000..04fc344a6d61112bb15b6b807edc90ed60871de6 --- /dev/null +++ b/src/functions/initial_conditions/tnlFlowerpotFunction.h~ @@ -0,0 +1,164 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLFLOWERPOTFUNCTION_H_ +#define TNLFLOWERPOTFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functors/tnlFunctionType.h> + +template< typename Real > +class tnlFlowerpotFunctionBase +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); + + void setDiameter( const RealType& sigma ); + + const RealType& getDiameter() const; + + protected: + + RealType diameter; +}; + +template< int Dimensions, + typename Real > +class tnlFlowerpotFunction +{ +}; + +template< typename Real > +class tnlFlowerpotFunction< 1, Real > : public tnlFlowerpotFunctionBase< Real > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlFlowerpotFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlFlowerpotFunction< 2, Real > : public tnlFlowerpotFunctionBase< Real > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlFlowerpotFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlFlowerpotFunction< 3, Real > : public tnlFlowerpotFunctionBase< Real > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlFlowerpotFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlFlowerpotFunction< Dimensions, Real >& f ) +{ + str << "Flowerpot function."; + return str; +} + +template< int FunctionDimensions, + typename Real > +class tnlFunctionType< tnlFlowerpotFunction< FunctionDimensions, Real > > +{ + public: + + enum { Type = tnlAnalyticFunction }; +}; + + +#include <functions/initial_conditions/tnlFlowerpotFunction_impl.h> + + +#endif /* TNLFLOWERPOTFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/tnlFlowerpotFunction_impl.h b/src/functions/initial_conditions/tnlFlowerpotFunction_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..5c36afaecc18f4cbdbfe19cb067a41e8610120dd --- /dev/null +++ b/src/functions/initial_conditions/tnlFlowerpotFunction_impl.h @@ -0,0 +1,154 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLFLOWERPOTFUNCTION_IMPL_H_ +#define TNLFLOWERPOTFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/tnlFlowerpotFunction.h> + +template< typename Real, + int Dimensions > +bool +tnlFlowerpotFunctionBase< Real, Dimensions >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->diameter = parameters.getParameter< double >( prefix + "diameter" ); + return true; +} + +template< typename Real, + int Dimensions > +void tnlFlowerpotFunctionBase< Real, Dimensions >::setDiameter( const Real& sigma ) +{ + this->diameter = diameter; +} + +template< typename Real, + int Dimensions > +const Real& tnlFlowerpotFunctionBase< Real, Dimensions >::getDiameter() const +{ + return this->diameter; +} + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlFlowerpotFunction< 1, Real >::getType() +{ + return "tnlFlowerpotFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlFlowerpotFunction< 1, Real >::tnlFlowerpotFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlFlowerpotFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return sin( M_PI * tanh( 5 * ( x * x - this->diameter ) ) ); + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlFlowerpotFunction< 2, Real >::getType() +{ + return tnlString( "tnlFlowerpotFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlFlowerpotFunction< 2, Real >::tnlFlowerpotFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlFlowerpotFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return sin( M_PI * tanh( 5 * ( x * x + y * y - this->diameter ) ) ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlFlowerpotFunction< 3, Real >::getType() +{ + return tnlString( "tnlFlowerpotFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlFlowerpotFunction< 3, Real >::tnlFlowerpotFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlFlowerpotFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return sin( M_PI * tanh( 5 * ( x * x + y * y + z * z - 0.25 ) ) ); + return 0.0; +} + + +#endif /* TNLFLOWERPOTFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/tnlFlowerpotFunction_impl.h~ b/src/functions/initial_conditions/tnlFlowerpotFunction_impl.h~ new file mode 100644 index 0000000000000000000000000000000000000000..9cf6f58945596a4246186da0ea6364fc91bf41bc --- /dev/null +++ b/src/functions/initial_conditions/tnlFlowerpotFunction_impl.h~ @@ -0,0 +1,157 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLFLOWERPOTFUNCTION_IMPL_H_ +#define TNLFLOWERPOTFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/tnlFlowerpotFunction.h> + +template< typename Real > +bool +tnlFlowerpotFunctionBase< Real >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + this->diameter = parameters.getParameter< double >( prefix + "diameter" ); + return true; +} + +template< typename Real > +void tnlFlowerpotFunctionBase< Real >::setDiameter( const Real& sigma ) +{ + this->diameter = diameter; +} + +template< typename Real > +const Real& tnlFlowerpotFunctionBase< Real >::getDiameter() const +{ + return this->diameter; +} + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlFlowerpotFunction< 1, Real >::getType() +{ + return "tnlFlowerpotFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlFlowerpotFunction< 1, Real >::tnlFlowerpotFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlFlowerpotFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return sin( M_PI * tanh( 5 * ( x * x - this->diameter ) ) ); + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlFlowerpotFunction< 2, Real >::getType() +{ + return tnlString( "tnlFlowerpotFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlFlowerpotFunction< 2, Real >::tnlFlowerpotFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlFlowerpotFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return sin( M_PI * tanh( 5 * ( x * x + y * y - this->diameter ) ) ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlFlowerpotFunction< 3, Real >::getType() +{ + return tnlString( "tnlFlowerpotFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlFlowerpotFunction< 3, Real >::tnlFlowerpotFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlFlowerpotFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return sin( M_PI * tanh( 5 * ( x * x + y * y + z * z - 0.25 ) ) ); + return 0.0; +} + + +#endif /* TNLFLOWERPOTFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/tnlTwinsFunction.h b/src/functions/initial_conditions/tnlTwinsFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..5c1155c338fcea498f2987ad76f77252523dac53 --- /dev/null +++ b/src/functions/initial_conditions/tnlTwinsFunction.h @@ -0,0 +1,142 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLTWINSFUNCTION_H_ +#define TNLTWINSFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functions/tnlFunction.h> +#include <core/tnlCuda.h> + +template< typename Real, + int Dimensions > +class tnlTwinsFunctionBase : public tnlFunction< Dimensions, AnalyticFunction > +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); +}; + +template< int Dimensions, + typename Real > +class tnlTwinsFunction +{ +}; + +template< typename Real > +class tnlTwinsFunction< 1, Real > : public tnlTwinsFunctionBase< Real, 1 > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlTwinsFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlTwinsFunction< 2, Real > : public tnlTwinsFunctionBase< Real, 2 > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlTwinsFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlTwinsFunction< 3, Real > : public tnlTwinsFunctionBase< Real, 3 > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlTwinsFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif + __cuda_callable__ + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlTwinsFunction< Dimensions, Real >& f ) +{ + str << "Twins function."; + return str; +} + +#include <functions/initial_conditions/tnlTwinsFunction_impl.h> + + +#endif /* TNLTWINSFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/tnlTwinsFunction.h~ b/src/functions/initial_conditions/tnlTwinsFunction.h~ new file mode 100644 index 0000000000000000000000000000000000000000..e91c1f0e998689a657417f96d7907cb50d7c9716 --- /dev/null +++ b/src/functions/initial_conditions/tnlTwinsFunction.h~ @@ -0,0 +1,156 @@ +/*************************************************************************** + tnlExpBumpFunction.h - description + ------------------- + begin : Dec 5, 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 TNLTWINSFUNCTION_H_ +#define TNLTWINSFUNCTION_H_ + +#include <config/tnlParameterContainer.h> +#include <core/vectors/tnlStaticVector.h> +#include <functors/tnlFunctionType.h> + +template< typename Real > +class tnlTwinsFunctionBase +{ + public: + + typedef Real RealType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ); +}; + +template< int Dimensions, + typename Real > +class tnlTwinsFunction +{ +}; + +template< typename Real > +class tnlTwinsFunction< 1, Real > : public tnlTwinsFunctionBase< Real > +{ + public: + + enum { Dimensions = 1 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlTwinsFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlTwinsFunction< 2, Real > : public tnlTwinsFunctionBase< Real > +{ + public: + + enum { Dimensions = 2 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlTwinsFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< typename Real > +class tnlTwinsFunction< 3, Real > : public tnlTwinsFunctionBase< Real > +{ + public: + + enum { Dimensions = 3 }; + typedef Real RealType; + typedef tnlStaticVector< Dimensions, Real > VertexType; + + static tnlString getType(); + + tnlTwinsFunction(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#else + template< int XDiffOrder = 0, + int YDiffOrder = 0, + int ZDiffOrder = 0, + typename Vertex = VertexType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + RealType getValue( const Vertex& v, + const Real& time = 0.0 ) const; +}; + +template< int Dimensions, + typename Real > +ostream& operator << ( ostream& str, const tnlTwinsFunction< Dimensions, Real >& f ) +{ + str << "Twins function."; + return str; +} + +template< int FunctionDimensions, + typename Real > +class tnlFunctionType< tnlTwinsFunction< FunctionDimensions, Real > > +{ + public: + + enum { Type = tnlAnalyticFunction }; +}; + + +#include <functions/initial_conditions/tnlTwinsFunction_impl.h> + + +#endif /* TNLTWINSFUNCTION_H_ */ diff --git a/src/functions/initial_conditions/tnlTwinsFunction_impl.h b/src/functions/initial_conditions/tnlTwinsFunction_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..04dc50b99d692d7647a46747b8cce5927fa4c8e8 --- /dev/null +++ b/src/functions/initial_conditions/tnlTwinsFunction_impl.h @@ -0,0 +1,139 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLTWINSFUNCTION_IMPL_H_ +#define TNLTWINSFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/tnlTwinsFunction.h> + +template< typename Real, + int Dimensions > +bool +tnlTwinsFunctionBase< Real, Dimensions >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + return true; +} + + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlTwinsFunction< 1, Real >::getType() +{ + return "tnlTwinsFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlTwinsFunction< 1, Real >::tnlTwinsFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlTwinsFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlTwinsFunction< 2, Real >::getType() +{ + return tnlString( "tnlTwinsFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlTwinsFunction< 2, Real >::tnlTwinsFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlTwinsFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return -0.5 * sin( M_PI * x) * sin( M_PI * x) * ( 1 - ( y - 2 ) * ( y - 2 ) ) * ( 1 - tanh ( 10 * ( sqrt( x * x + y * y ) - 0.6 ) ) ); + return 0.0; +} + +/**** + * 3D + */ +template< typename Real > +tnlString +tnlTwinsFunction< 3, Real >::getType() +{ + return tnlString( "tnlTwinsFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlTwinsFunction< 3, Real >::tnlTwinsFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +__cuda_callable__ +Real +tnlTwinsFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return 0.0; + return 0.0; +} + + +#endif /* TNLTWINSFUNCTION_IMPL_H_ */ diff --git a/src/functions/initial_conditions/tnlTwinsFunction_impl.h~ b/src/functions/initial_conditions/tnlTwinsFunction_impl.h~ new file mode 100644 index 0000000000000000000000000000000000000000..a89dd007fe5ec0fc6665c69a9f2ef2521f1c8dea --- /dev/null +++ b/src/functions/initial_conditions/tnlTwinsFunction_impl.h~ @@ -0,0 +1,145 @@ +/*************************************************************************** + tnlExpBumpFunction_impl.h - description + ------------------- + begin : Dec 5, 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 TNLTWINSFUNCTION_IMPL_H_ +#define TNLTWINSFUNCTION_IMPL_H_ + +#include <functions/initial_conditions/tnlTwinsFunction.h> + +template< typename Real > +bool +tnlTwinsFunctionBase< Real >:: +setup( const tnlParameterContainer& parameters, + const tnlString& prefix ) +{ + return true; +} + + +/*** + * 1D + */ + +template< typename Real > +tnlString +tnlTwinsFunction< 1, Real >::getType() +{ + return "tnlTwinsFunction< 1, " + ::getType< Real >() + tnlString( " >" ); +} + +template< typename Real > +tnlTwinsFunction< 1, Real >::tnlTwinsFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlTwinsFunction< 1, Real >::getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 ) + return 0.0; + return 0.0; +} + +/**** + * 2D + */ + +template< typename Real > +tnlString +tnlTwinsFunction< 2, Real >::getType() +{ + return tnlString( "tnlTwinsFunction< 2, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlTwinsFunction< 2, Real >::tnlTwinsFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlTwinsFunction< 2, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + if( ZDiffOrder != 0 ) + return 0.0; + if( XDiffOrder == 0 && YDiffOrder == 0 ) + return -0.5 * sin( M_PI * x) * sin( M_PI * x) * ( 1 - ( y - 2 ) * ( y - 2 ) ) * ( 1 - tanh ( 10 * ( sqrt( x * x + y * y ) - 0.6 ) ) ); + return 0.0; +} + +/**** + * 3D + */ + +template< typename Real > +tnlString +tnlTwinsFunction< 3, Real >::getType() +{ + return tnlString( "tnlTwinsFunction< 3, " ) + ::getType< Real >() + " >"; +} + +template< typename Real > +tnlTwinsFunction< 3, Real >::tnlTwinsFunction() +{ +} + +template< typename Real > + template< int XDiffOrder, + int YDiffOrder, + int ZDiffOrder, + typename Vertex > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlTwinsFunction< 3, Real >:: +getValue( const Vertex& v, + const Real& time ) const +{ + const RealType& x = v.x(); + const RealType& y = v.y(); + const RealType& z = v.z(); + if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return 0.0; + return 0.0; +} + + +#endif /* TNLTWINSFUNCTION_IMPL_H_ */ diff --git a/src/functions/tnlExpBumpFunction_impl.h b/src/functions/tnlExpBumpFunction_impl.h index 3990902b860eeaf98281781b22d42ff98073237e..f59868023d542a159cddc8678fad5ce170ba9c7c 100644 --- a/src/functions/tnlExpBumpFunction_impl.h +++ b/src/functions/tnlExpBumpFunction_impl.h @@ -132,6 +132,8 @@ getValue( const VertexType& v, return -2.0 * y / ( this->sigma * this->sigma ) * this->amplitude * exp( (-x * x - y * y)/ ( this->sigma * this->sigma ) ); if( XDiffOrder == 0 && YDiffOrder == 2 ) return -2.0 / ( this->sigma * this->sigma ) * this->amplitude * exp( (-x*x - y*y) / ( this->sigma * this->sigma ) ) + 4.0 * y * y / ( this->sigma * this->sigma * this->sigma * this->sigma ) * this->amplitude * exp( (-x*x - y*y) / ( this->sigma * this->sigma ) ); + if( XDiffOrder == 1 && YDiffOrder == 1 ) + return 4.0 * x * y / ( ( this->sigma * this->sigma ) * ( this->sigma * this->sigma ) ) * this->amplitude * exp( (-x * x - y * y)/ ( this->sigma * this->sigma ) ); return 0.0; } @@ -178,6 +180,12 @@ getValue( const VertexType& v, return -2.0 * z / ( this->sigma * this->sigma ) * this->amplitude * exp( ( -x*x - y*y -z*z ) / ( this->sigma * this->sigma ) ); if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 2 ) return -2.0 / ( this->sigma * this->sigma ) * this->amplitude * exp( ( -x*x - y*y -z*z ) / ( this->sigma * this->sigma ) ) + 4.0 * z * z / ( this->sigma * this->sigma * this->sigma * this->sigma ) * this->amplitude * exp( ( -x*x - y*y -z*z ) / ( this->sigma * this->sigma ) ); + if( XDiffOrder == 1 && YDiffOrder == 1 && ZDiffOrder == 0 ) + return 4.0 * x * y / ( ( this->sigma * this->sigma ) * ( this->sigma * this->sigma ) ) * this->amplitude * exp( ( -x*x - y*y -z*z ) / ( this->sigma * this->sigma ) ); + if( XDiffOrder == 1 && YDiffOrder == 0 && ZDiffOrder == 1 ) + return 4.0 * x * z / ( ( this->sigma * this->sigma ) * ( this->sigma * this->sigma ) ) * this->amplitude * exp( ( -x*x - y*y -z*z ) / ( this->sigma * this->sigma ) ); + if( XDiffOrder == 0 && YDiffOrder == 1 && ZDiffOrder == 1 ) + return 4.0 * y * z / ( ( this->sigma * this->sigma ) * ( this->sigma * this->sigma ) ) * this->amplitude * exp( ( -x*x - y*y -z*z ) / ( this->sigma * this->sigma ) ); return 0.0; } diff --git a/src/functions/tnlSinBumpsFunction_impl.h b/src/functions/tnlSinBumpsFunction_impl.h index 308ff76f9754238dc55a6ba0f3b8276e329e5fae..d6deed25a2b7c4564b6d6412d87d0fac18c2a94e 100644 --- a/src/functions/tnlSinBumpsFunction_impl.h +++ b/src/functions/tnlSinBumpsFunction_impl.h @@ -146,6 +146,8 @@ getValue( const VertexType& v, return 2.0 * M_PI / this->waveLength.y() * this->amplitude * cos( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * sin( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ); if( XDiffOrder == 0 && YDiffOrder == 2 ) return -4.0 * M_PI * M_PI / ( this->waveLength.y() * this->waveLength.y() ) * this->amplitude * sin( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * sin( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ); + if( XDiffOrder == 1 && YDiffOrder == 1 ) + return 4.0 * M_PI * M_PI / ( this->waveLength.x() * this->waveLength.y() ) * this->amplitude * cos( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * cos( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ); return 0.0; } @@ -203,6 +205,12 @@ getValue( const VertexType& v, return 2.0 * M_PI / this->waveLength.z() * this->amplitude * cos( this->phase.z() + 2.0 * M_PI * z / this->waveLength.z() ) * sin( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * sin( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ); if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 2) return -4.0 * M_PI * M_PI / ( this->waveLength.z() * this->waveLength.z() ) * this->amplitude * sin( this->phase.z() + 2.0 * M_PI * z / this->waveLength.z() ) * sin( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * sin( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ); + if( XDiffOrder == 1 && YDiffOrder == 1 && ZDiffOrder == 0) + return 4.0 * M_PI * M_PI / ( this->waveLength.x() * this->waveLength.y() ) * this->amplitude * cos( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ) * cos( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * sin( this->phase.z() + 2.0 * M_PI * z / this->waveLength.z() ); + if( XDiffOrder == 1 && YDiffOrder == 0 && ZDiffOrder == 1) + return 4.0 * M_PI * M_PI / ( this->waveLength.x() * this->waveLength.z() ) * this->amplitude * cos( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ) * sin( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * cos( this->phase.z() + 2.0 * M_PI * z / this->waveLength.z() ); + if( XDiffOrder == 0 && YDiffOrder == 1 && ZDiffOrder == 1) + return 4.0 * M_PI * M_PI / ( this->waveLength.y() * this->waveLength.z() ) * this->amplitude * sin( this->phase.x() + 2.0 * M_PI * x / this->waveLength.x() ) * cos( this->phase.y() + 2.0 * M_PI * y / this->waveLength.y() ) * cos( this->phase.z() + 2.0 * M_PI * z / this->waveLength.z() ); return 0.0; } diff --git a/src/functions/tnlSinWaveFunction_impl.h b/src/functions/tnlSinWaveFunction_impl.h index 14e7976f2bfc8864529e176c64eb9497a2ca51f0..47ee683d2c94c1b0accc1dd12179d2d6e6f976ea 100644 --- a/src/functions/tnlSinWaveFunction_impl.h +++ b/src/functions/tnlSinWaveFunction_impl.h @@ -136,6 +136,9 @@ getValue( const VertexType& v, return 2.0 * M_PI * y / ( this->waveLength * sqrt( x * x + y * y ) ) * this->amplitude * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y ) / this->waveLength ); if( XDiffOrder == 0 && YDiffOrder == 2 ) return 2.0 * M_PI * y * y / ( this->waveLength * sqrt( x * x + y * y ) * sqrt( x * x + y * y ) * sqrt( x * x + y * y ) ) * this->amplitude * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y ) / this->waveLength ) - 4.0 * M_PI * M_PI * y * y / ( this->waveLength * this->waveLength * ( x * x + y * y ) ) * this->amplitude * sin( this->phase + 2.0 * M_PI * sqrt( x * x + y * y ) / this->waveLength ); + if( XDiffOrder == 1 && YDiffOrder == 1 ) + return -4.0 * M_PI * M_PI * x * y / ( this->waveLength * this->waveLength * (x * x + y * y ) )* this->amplitude * sin( this->phase + 2.0 * M_PI * sqrt( x * x + y * y ) / this->waveLength ) + - 2.0 * M_PI * this->amplitude * x * y * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y ) / this->waveLength ) / ( this->waveLength * sqrt( (x * x + y * y ) * (x * x + y * y ) * (x * x + y * y ) ) ); return 0.0; } @@ -168,6 +171,15 @@ getValue( const VertexType& v, return 2.0 * M_PI * z / ( this->waveLength * sqrt( x * x + y * y + z * z ) ) * this->amplitude * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ); if( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 2 ) return 2.0 * M_PI * ( x * x + y * y ) / ( this->waveLength * sqrt( x * x + y * y + z * z ) * sqrt( x * x + y * y + z * z ) * sqrt( x * x + y * y + z * z ) ) * this->amplitude * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) - 4.0 * M_PI * M_PI * z * z / ( this->waveLength * this->waveLength * ( x * x + y * y + z * z ) ) * this->amplitude * sin( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ); + if( XDiffOrder == 1 && YDiffOrder == 1 && ZDiffOrder == 0 ) + return -4.0 * M_PI * M_PI * x * y / ( this->waveLength * this->waveLength * (x * x + y * y + z * z ) )* this->amplitude * sin( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) + - 2.0 * M_PI * this->amplitude * x * y * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) / ( this->waveLength * sqrt( (x * x + y * y + z * z ) * (x * x + y * y + z * z ) * (x * x + y * y + z * z ) ) ); + if( XDiffOrder == 1 && YDiffOrder == 0 && ZDiffOrder == 1 ) + return -4.0 * M_PI * M_PI * x * z / ( this->waveLength * this->waveLength * (x * x + y * y + z * z ) )* this->amplitude * sin( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) + - 2.0 * M_PI * this->amplitude * x * z * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) / ( this->waveLength * sqrt( (x * x + y * y + z * z ) * (x * x + y * y + z * z ) * (x * x + y * y + z * z ) ) ); + if( XDiffOrder == 0 && YDiffOrder == 1 && ZDiffOrder == 1 ) + return -4.0 * M_PI * M_PI * z * y / ( this->waveLength * this->waveLength * (x * x + y * y + z * z ) )* this->amplitude * sin( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) + - 2.0 * M_PI * this->amplitude * z * y * cos( this->phase + 2.0 * M_PI * sqrt( x * x + y * y + z * z ) / this->waveLength ) / ( this->waveLength * sqrt( (x * x + y * y + z * z ) * (x * x + y * y + z * z ) * (x * x + y * y + z * z ) ) ); return 0.0; } diff --git a/src/functions/tnlTestFunction.h b/src/functions/tnlTestFunction.h index 6684bd23a5abdb0406f77baebf91ea6d09a01a9f..71aa9067b1c44f05bc9547f8db07272feae8fd30 100644 --- a/src/functions/tnlTestFunction.h +++ b/src/functions/tnlTestFunction.h @@ -34,7 +34,12 @@ class tnlTestFunction : public tnlFunction< FunctionDimensions, AnalyticFunction enum TestFunctions{ constant, expBump, sinBumps, - sinWave }; + sinWave, + cylinder, + flowerpot, + twins, + pseudoSquare, + blob }; enum TimeDependence { none, linear, diff --git a/src/functions/tnlTestFunction_impl.h b/src/functions/tnlTestFunction_impl.h index 5609a46a1f8a2ab04a57530b1554dba843a7ad71..4c3f624563cd55e30cc8f080fea2938760bdf03e 100644 --- a/src/functions/tnlTestFunction_impl.h +++ b/src/functions/tnlTestFunction_impl.h @@ -24,6 +24,17 @@ #include <functions/tnlSinBumpsFunction.h> #include <functions/tnlSinWaveFunction.h> +// This is from origin/mean-curvature +#include <functions/tnlConstantFunction.h> +#include <functions/tnlExpBumpFunction.h> +#include <functions/tnlSinBumpsFunction.h> +#include <functions/tnlSinWaveFunction.h> +#include <functions/initial_conditions/tnlCylinderFunction.h> +#include <functions/initial_conditions/tnlFlowerpotFunction.h> +#include <functions/initial_conditions/tnlTwinsFunction.h> +#include <functions/initial_conditions/level_set_functions/tnlBlobFunction.h> +#include <functions/initial_conditions/level_set_functions/tnlPseudoSquareFunction.h> + template< int FunctionDimensions, typename Real, typename Device > @@ -48,6 +59,11 @@ configSetup( tnlConfigDescription& config, config.addEntryEnum( "exp-bump" ); config.addEntryEnum( "sin-wave" ); config.addEntryEnum( "sin-bumps" ); + config.addEntryEnum( "cylinder" ); + config.addEntryEnum( "flowerpot" ); + config.addEntryEnum( "twins" ); + config.addEntryEnum( "pseudoSquare" ); + config.addEntryEnum( "blob" ); config.addEntry < double >( prefix + "constant", "Value of the constant function.", 0.0 ); config.addEntry < double >( prefix + "wave-length", "Wave length of the sine based test functions.", 1.0 ); config.addEntry < double >( prefix + "wave-length-x", "Wave length of the sine based test functions.", 1.0 ); @@ -63,6 +79,8 @@ configSetup( tnlConfigDescription& config, config.addEntry < double >( prefix + "waves-number-y", "Cut-off for the sine based test functions.", 0.0 ); config.addEntry < double >( prefix + "waves-number-z", "Cut-off for the sine based test functions.", 0.0 ); config.addEntry < double >( prefix + "sigma", "Sigma for the exp based test functions.", 1.0 ); + config.addEntry < double >( prefix + "diameter", "Diameter for the cylinder, flowerpot test functions.", 1.0 ); + config.addEntry < double >( prefix + "height", "Height of zero-level-set function for the blob, pseudosquare test functions.", 1.0 ); config.addEntry < tnlString >( prefix + "time-dependence", "Time dependence of the test function.", "none" ); config.addEntryEnum( "none" ); config.addEntryEnum( "linear" ); @@ -153,6 +171,36 @@ setup( const tnlParameterContainer& parameters, functionType = sinWave; return setupFunction< FunctionType >( parameters ); } + if( testFunction == "cylinder" ) + { + typedef tnlCylinderFunction< Dimensions, Real > FunctionType; + functionType = cylinder; + return setupFunction< FunctionType >( parameters ); + } + if( testFunction == "flowerpot" ) + { + typedef tnlFlowerpotFunction< Dimensions, Real > FunctionType; + functionType = flowerpot; + return setupFunction< FunctionType >( parameters ); + } + if( testFunction == "twins" ) + { + typedef tnlTwinsFunction< Dimensions, Real > FunctionType; + functionType = twins; + return setupFunction< FunctionType >( parameters ); + } + if( testFunction == "pseudoSquare" ) + { + typedef tnlPseudoSquareFunction< Dimensions, Real > FunctionType; + functionType = pseudoSquare; + return setupFunction< FunctionType >( parameters ); + } + if( testFunction == "blob" ) + { + typedef tnlBlobFunction< Dimensions, Real > FunctionType; + functionType = blob; + return setupFunction< FunctionType >( parameters ); + } cerr << "Unknown function " << testFunction << endl; return false; } @@ -188,6 +236,21 @@ operator = ( const tnlTestFunction& function ) case sinWave: this->copyFunction< tnlSinWaveFunction< FunctionDimensions, Real > >( function.function ); break; + case cylinder: + this->copyFunction< tnlCylinderFunction< FunctionDimensions, Real > >( function.function ); + break; + case flowerpot: + this->copyFunction< tnlFlowerpotFunction< FunctionDimensions, Real > >( function.function ); + break; + case twins: + this->copyFunction< tnlTwinsFunction< FunctionDimensions, Real > >( function.function ); + break; + case pseudoSquare: + this->copyFunction< tnlPseudoSquareFunction< FunctionDimensions, Real > >( function.function ); + break; + case blob: + this->copyFunction< tnlBlobFunction< FunctionDimensions, Real > >( function.function ); + break; default: tnlAssert( false, ); break; @@ -238,6 +301,21 @@ getValue( const VertexType& vertex, case sinWave: return scale * ( ( tnlSinWaveFunction< Dimensions, Real >* ) function )-> getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + case cylinder: + return scale * ( ( tnlCylinderFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + case flowerpot: + return scale * ( ( tnlFlowerpotFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + case twins: + return scale * ( ( tnlTwinsFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + case pseudoSquare: + return scale * ( ( tnlPseudoSquareFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + case blob: + return scale * ( ( tnlBlobFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); default: return 0.0; } @@ -284,6 +362,27 @@ getTimeDerivative( const VertexType& vertex, case sinWave: return scale * ( ( tnlSinWaveFunction< Dimensions, Real >* ) function )-> getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + break; + case cylinder: + return scale * ( ( tnlCylinderFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + break; + case flowerpot: + return scale * ( ( tnlFlowerpotFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + break; + case twins: + return scale * ( ( tnlTwinsFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + break; + case pseudoSquare: + return scale * ( ( tnlPseudoSquareFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + break; + case blob: + return scale * ( ( tnlBlobFunction< Dimensions, Real >* ) function )-> + getValue< XDiffOrder, YDiffOrder, ZDiffOrder >( vertex, time ); + break; default: return 0.0; } @@ -330,6 +429,21 @@ deleteFunctions() case sinWave: deleteFunction< tnlSinWaveFunction< Dimensions, Real> >(); break; + case cylinder: + deleteFunction< tnlCylinderFunction< Dimensions, Real> >(); + break; + case flowerpot: + deleteFunction< tnlFlowerpotFunction< Dimensions, Real> >(); + break; + case twins: + deleteFunction< tnlTwinsFunction< Dimensions, Real> >(); + break; + case pseudoSquare: + deleteFunction< tnlPseudoSquareFunction< Dimensions, Real> >(); + break; + case blob: + deleteFunction< tnlBlobFunction< Dimensions, Real> >(); + break; } } @@ -395,6 +509,16 @@ print( ostream& str ) const return printFunction< tnlSinBumpsFunction< Dimensions, Real> >( str ); case sinWave: return printFunction< tnlSinWaveFunction< Dimensions, Real> >( str ); + case cylinder: + return printFunction< tnlCylinderFunction< Dimensions, Real> >( str ); + case flowerpot: + return printFunction< tnlFlowerpotFunction< Dimensions, Real> >( str ); + case twins: + return printFunction< tnlTwinsFunction< Dimensions, Real> >( str ); + case pseudoSquare: + return printFunction< tnlPseudoSquareFunction< Dimensions, Real> >( str ); + case blob: + return printFunction< tnlBlobFunction< Dimensions, Real> >( str ); } return str; } diff --git a/src/matrices/tnlMatrixSetter.h b/src/matrices/tnlMatrixSetter.h index 516c86a54e491c87ff1646aa604e768ef8575485..0a9989bb04d3c34d696ab6fe21f88f5ddd698ea0 100644 --- a/src/matrices/tnlMatrixSetter.h +++ b/src/matrices/tnlMatrixSetter.h @@ -137,30 +137,6 @@ class tnlMatrixSetter< tnlGrid< Dimensions, Real, Device, Index >, userData.boundaryConditions->getLinearSystemRowLength( mesh, entity.getIndex(), entity ); } - - /* - __cuda_callable__ - static void processCell( const MeshType& mesh, - TraversalUserData& userData, - const IndexType index, - const CoordinatesType& coordinates ) - { - ( *userData.rowLengths )[ index ] = - userData.boundaryConditions->getLinearSystemRowLength( mesh, index, coordinates ); - } - - __cuda_callable__ - static void processFace( const MeshType& mesh, - TraversalUserData& userData, - const IndexType index, - const CoordinatesType& coordinates ) - { - //printf("Matrix setter: Index = %d \n", index ); - ( *userData.rowLengths )[ index ] = - userData.boundaryConditions->getLinearSystemRowLength( mesh, index, coordinates ); - }*/ - - }; class TraversalInteriorEntitiesProcessor @@ -176,30 +152,6 @@ class tnlMatrixSetter< tnlGrid< Dimensions, Real, Device, Index >, ( *userData.rowLengths )[ entity.getIndex() ] = userData.differentialOperator->getLinearSystemRowLength( mesh, entity.getIndex(), entity ); } - - - /*__cuda_callable__ - static void processCell( const MeshType& mesh, - TraversalUserData& userData, - const IndexType index, - const CoordinatesType& coordinates ) - { - ( *userData.rowLengths )[ index ] = - userData.differentialOperator->getLinearSystemRowLength( mesh, index, coordinates ); - } - - __cuda_callable__ - static void processFace( const MeshType& mesh, - TraversalUserData& userData, - const IndexType index, - const CoordinatesType& coordinates ) - { - // printf("Matrix setter: Index = %d \n", index ); - ( *userData.rowLengths )[ index ] = - userData.differentialOperator->getLinearSystemRowLength( mesh, index, coordinates ); - }*/ - - }; }; diff --git a/src/operators/CMakeLists.txt b/src/operators/CMakeLists.txt index f03203db39ba607c03ab96d63838a48af4928a17..8fe15811af6bc62d50b0d0888a645932a001da08 100755 --- a/src/operators/CMakeLists.txt +++ b/src/operators/CMakeLists.txt @@ -1,6 +1,8 @@ ADD_SUBDIRECTORY( gradient ) ADD_SUBDIRECTORY( diffusion ) ADD_SUBDIRECTORY( euler ) +ADD_SUBDIRECTORY( operator-Q ) +ADD_SUBDIRECTORY( operator-curvature ) SET( headers tnlFiniteDifferences.h tnlFiniteDifferences_impl.h @@ -30,4 +32,4 @@ set( tnl_operators_SOURCES ${common_SOURCES} PARENT_SCOPE ) -INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/operators ) \ No newline at end of file +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/operators ) diff --git a/src/operators/diffusion/CMakeLists.txt b/src/operators/diffusion/CMakeLists.txt index cd9601b16a9b4459368b76351a5bef6c931b9ff4..7ab4da55c65507e22a6ce23bc8efd1d551343f16 100755 --- a/src/operators/diffusion/CMakeLists.txt +++ b/src/operators/diffusion/CMakeLists.txt @@ -1,7 +1,13 @@ +ADD_SUBDIRECTORY( nonlinear-diffusion-operators ) + SET( headers tnlLinearDiffusion.h tnlLinearDiffusion_impl.h tnlExactLinearDiffusion.h - tnlExactLinearDiffusion_impl.h ) + tnlExactLinearDiffusion_impl.h + tnlNonlinearDiffusion.h + tnlNonlinearDiffusion_impl.h + tnlExactNonlinearDiffusion.h + tnlExactNonlinearDiffusion_impl.h ) SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/operators/diffusion ) diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/CMakeLists.txt b/src/operators/diffusion/nonlinear-diffusion-operators/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..41886e78d4458c607924b2aecd40e554c497ee4e --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/CMakeLists.txt @@ -0,0 +1,6 @@ +SET( headers tnlOneSideDiffNonlinearOperator.h + tnlOneSideDiffNonlinearOperator_impl.h + tnlFiniteVolumeNonlinearOperator.h + tnlFiniteVolumeNonlinearOperator_impl.h ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/operators/diffusion/nonlinear-diffusion-operators ) diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h new file mode 100644 index 0000000000000000000000000000000000000000..3229d0d51484e0024d603a8828931f752358ff87 --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator.h @@ -0,0 +1,181 @@ +#ifndef TNLFINITEVOLUMENONLINEAROPERATOR_H +#define TNLFINITEVOLUMENONLINEAROPERATOR_H + +#include <core/vectors/tnlVector.h> +#include <mesh/tnlGrid.h> + +template< typename Mesh, + typename NonlinearDiffusionOperator, + typename OperatorQ, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class tnlFiniteVolumeNonlinearOperator +{ + +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlFiniteVolumeNonlinearOperator< tnlGrid< 1,MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + static tnlString getType(); + + template< typename Vector, + typename MeshEntity > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename Vector, + typename MeshEntity, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + OperatorQ operatorQ; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + + static tnlString getType(); + + template< typename Vector, + typename MeshEntity > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename Vector, + typename MeshEntity, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + OperatorQ operatorQ; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + static tnlString getType(); + + template< typename Vector > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename Vector, + typename MeshEntity, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + OperatorQ operatorQ; +}; + + +#include "tnlFiniteVolumeNonlinearOperator_impl.h" + + +#endif /* TNLFINITEVOLUMENONLINEAROPERATOR_H */ diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..ad8f53ba4549fd746645abe86743cbd76180d7ae --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlFiniteVolumeNonlinearOperator_impl.h @@ -0,0 +1,302 @@ + +#ifndef TNLFINITEVOLUMENONLINEAROPERATOR__IMPL_H +#define TNLFINITEVOLUMENONLINEAROPERATOR__IMPL_H + +#include "tnlFiniteVolumeNonlinearOperator.h" + +#include <mesh/tnlGrid.h> + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlFiniteVolumeNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlFiniteVolumeNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity > +__cuda_callable__ +Real +tnlFiniteVolumeNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlFiniteVolumeNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return 1; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity, + typename MatrixRow > +__cuda_callable__ +void +tnlFiniteVolumeNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlFiniteVolumeNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity > +__cuda_callable__ +Real +tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + const typename EntityType::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); + return operatorQ.getValue( mesh, entity, u, time ) * + ( ( u[ neighbourEntities.template getEntityIndex< 1, 0 >() ] - u[ cellIndex ] ) * mesh.getHxSquareInverse() / operatorQ.getValue( mesh, entity, u, time, 1 ) + + ( u[ neighbourEntities.template getEntityIndex< 0, 1 >() ] - u[ cellIndex ] ) * mesh.getHySquareInverse() / operatorQ.getValue( mesh, entity, u, time, 0, 1 ) + - ( -u[ neighbourEntities.template getEntityIndex< -1, 0 >() ] + u[ cellIndex ] ) * mesh.getHxSquareInverse() / operatorQ.getValue( mesh, entity, u, time, -1) + - ( -u[ neighbourEntities.template getEntityIndex< 0,-1 >() ] + u[ cellIndex ] ) * mesh.getHySquareInverse() / operatorQ.getValue( mesh, entity, u, time, 0, -1) ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return 5; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity, + typename MatrixRow > +__cuda_callable__ +void +tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + const typename EntityType::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); + const RealType aCoef = - tau * operatorQ.getValue(mesh, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, entity, u, time, 0, -1 ); + const RealType bCoef = - tau * operatorQ.getValue(mesh, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, entity, u, time, -1 ); + const RealType cCoef = tau * operatorQ.getValue(mesh, entity, u, time ) * ( mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, entity, u, time, 1 ) + mesh.getHySquareInverse() / + operatorQ.getValue(mesh, entity, u, time, 0, 1 ) + + mesh.getHxSquareInverse() / operatorQ.getValue(mesh, entity, u, time, -1 ) + + mesh.getHySquareInverse() / operatorQ.getValue(mesh, entity, u, time, 0, -1 ) ); + const RealType dCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 1 ); + const RealType eCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 0, 1 ); + matrixRow.setElement( 0, mesh.template getCellNextToCell< 0,-1 >( index ), aCoef ); + matrixRow.setElement( 1, mesh.template getCellNextToCell< -1,0 >( index ), bCoef ); + matrixRow.setElement( 2, index , cCoef ); + matrixRow.setElement( 3, mesh.template getCellNextToCell< 1,0 >( index ), dCoef ); + matrixRow.setElement( 4, mesh.template getCellNextToCell< 0,1 >( index ), eCoef ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlFiniteVolumeNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity > +__cuda_callable__ +Real +tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + const typename EntityType::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); + return operatorQ.getValue( mesh, entity, u, time ) * + ( (u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHxSquareInverse() / operatorQ.getValue(mesh,cellIndex, entity, u, time, 1 ) + + ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ]) * mesh.getHySquareInverse()/ + operatorQ.getValue(mesh,cellIndex, entity, u, time, 0, 1 ) + + ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ]) * mesh.getHzSquareInverse()/ + operatorQ.getValue(mesh,cellIndex, entity, u, time, 0, 0, 1 ) + - ( - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] + u[ cellIndex ]) + * mesh.getHxSquareInverse()/operatorQ.getValue(mesh,cellIndex, entity, u, time, -1) + -( - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHySquareInverse() + /operatorQ.getValue(mesh,cellIndex,entity, u, time, 0, -1) + -( - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHzSquareInverse() + /operatorQ.getValue(mesh,cellIndex,entity, u, time, 0, 0, -1) ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return 7; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity, + typename MatrixRow > +#ifdef HAVE_CUDA +__cuda_callable__ +#endif +void +tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + const typename EntityType::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); + const RealType aCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHzSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 0, 0, -1 ); + const RealType bCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 0, -1, 0 ); + const RealType cCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, -1, 0, 0 ); + const RealType dCoef = tau * operatorQ.getValue(mesh, index, entity, u, time ) * ( mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 1, 0, 0 ) + mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 0, 1, 0 ) + + mesh.getHzSquareInverse() / operatorQ.getValue(mesh, index, entity, u, time, 0, 0, 1 ) + + mesh.getHxSquareInverse() / operatorQ.getValue(mesh, index, entity, u, time, -1, 0, 0 ) + + mesh.getHySquareInverse() / operatorQ.getValue(mesh, index, entity, u, time, 0, -1, 0 ) + + mesh.getHzSquareInverse() / operatorQ.getValue(mesh, index, entity, u, time, 0, 0, -1 ) ); + const RealType eCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 1, 0, 0 ); + const RealType fCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 0, 1, 0 ); + const RealType gCoef = - tau * operatorQ.getValue(mesh, index, entity, u, time ) * mesh.getHzSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time, 0, 0, 1 ); + matrixRow.setElement( 0, mesh.template getCellNextToCell< 0,0,-1 >( index ), aCoef ); + matrixRow.setElement( 1, mesh.template getCellNextToCell< 0,-1,0 >( index ), bCoef ); + matrixRow.setElement( 2, mesh.template getCellNextToCell< -1,0,0 >( index ), cCoef ); + matrixRow.setElement( 3, index, dCoef ); + matrixRow.setElement( 4, mesh.template getCellNextToCell< 1,0,0 >( index ), eCoef ); + matrixRow.setElement( 5, mesh.template getCellNextToCell< 0,1,0 >( index ), fCoef ); + matrixRow.setElement( 6, mesh.template getCellNextToCell< 0,0,1 >( index ), gCoef ); +} +#endif /* TNLFINITEVOLUMENONLINEAROPERATOR__IMPL_H */ diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h new file mode 100644 index 0000000000000000000000000000000000000000..6f3b4df579d7e7c064657218e0c3c13678d20c36 --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h @@ -0,0 +1,182 @@ +#ifndef TNLONESIDEDIFFNONLINEAROPERATOR_H +#define TNLONESIDEDIFFNONLINEAROPERATOR_H + +#include <core/vectors/tnlVector.h> +#include <mesh/tnlGrid.h> + +template< typename Mesh, + typename NonlinearDiffusionOperator, + typename OperatorQ, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class tnlOneSideDiffNonlinearOperator +{ + +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlOneSideDiffNonlinearOperator< tnlGrid< 1,MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + static tnlString getType(); + + template< typename Vector, + typename MeshEntity > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename Vector, + typename MeshEntity, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + OperatorQ operatorQ; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlOneSideDiffNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + + static tnlString getType(); + + template< typename Vector, + typename MeshEntity > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename Vector, + typename MeshEntity, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + OperatorQ operatorQ; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlOneSideDiffNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + static tnlString getType(); + + template< typename Vector, + typename MeshEntity > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename Vector, + typename MeshEntity, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + OperatorQ operatorQ; +}; + + +#include "tnlOneSideDiffNonlinearOperator_impl.h" + + +#endif /* TNLONESIDEDIFFNONLINEAROPERATOR_H */ diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h~ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h~ new file mode 100644 index 0000000000000000000000000000000000000000..041307fa9a7e284a398ef402020bc02efb0a5e9e --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h~ @@ -0,0 +1,194 @@ +#ifndef TNLONESIDEDIFFNONLINEAROPERATOR_H +#define TNLONESIDEDIFFNONLINEAROPERATOR_H + +#include <core/vectors/tnlVector.h> +#include "tnlForwardFiniteDifference.h" +#include "tnlBackwardFiniteDifference.h" +#include <mesh/tnlGrid.h> + +template< typename Mesh, + typename NonlinearDiffusionOperator, + typename OperatorQ, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class tnlOneSideDiffNonlinearOperator +{ + +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlOneSideDiffNonlinearOperator< tnlGrid< 1,MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef OperatorQ OperatorQType; + + static tnlString getType(); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const RealType& time) const; + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const CoordinatesType& coordinates ) const + {} + + template< typename Vector, typename MatrixRow > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const CoordinatesType& coordinates, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const + {} + + + private: + + OperatorQ operatorQ; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlOneSideDiffNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedej OperatorQ OperatorQType: + + + static tnlString getType(); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const RealType& time) const; + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const CoordinatesType& coordinates ) const + {} + + template< typename Vector, typename MatrixRow > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const CoordinatesType& coordinates, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const + {} + + private: + + OperatorQ operatorQ; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +class tnlOneSideDiffNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedej OperatorQ OperatorQType; + + static tnlString getType(); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const RealType& time) const + {} + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const CoordinatesType& coordinates ) const + {} + + template< typename Vector, typename MatrixRow > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const CoordinatesType& coordinates, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const + {} + +}; + + +#include "tnlOneSideDiffNonlinearOperator_impl.h" + + +#endif /* TNLONESIDEDIFFNONLINEAROPERATOR_H */ diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator_impl.h b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..721c009eb7babb5d5abeaf4e39defe45ea9b7e6f --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator_impl.h @@ -0,0 +1,320 @@ + +#ifndef TNLONESIDEDIFFNONLINEAROPERATOR_IMPL_H +#define TNLONESIDEDIFFNONLINEAROPERATOR_IMPL_H + +#include "tnlOneSideDiffNonlinearOperator.h" + +#include <mesh/tnlGrid.h> + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlOneSideDiffNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlOneSideDiffNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity > +__cuda_callable__ +Real +tnlOneSideDiffNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + const typename EntityType::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); + return operatorQ.getValueStriped(mesh,cellIndex, entity, u, time)*((( u[ mesh.template getCellNextToCell< 1 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHxInverse() / operatorQ.getValue(mesh,cellIndex, entity, u, time) - ( - u[ mesh.template getCellNextToCell< -1>( cellIndex ) ] + + u[ cellIndex ] ) * mesh.getHxInverse() / operatorQ.getValue(mesh,mesh.template getCellNextToCell<-1>(cellIndex), entity, u, time)) + *mesh.getHxInverse()); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlOneSideDiffNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return 3; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity, + typename MatrixRow > +__cuda_callable__ +void +tnlOneSideDiffNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + const typename EntityType::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); + const RealType aCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< -1 >( index ), entity, u, time ); + const RealType bCoef = tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * ( mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ) + mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< -1 >( index ), entity, u, time ) ); + const RealType cCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ); + matrixRow.setElement( 0, mesh.template getCellNextToCell< -1 >( index ), aCoef ); + matrixRow.setElement( 1, index, bCoef ); + matrixRow.setElement( 2, mesh.template getCellNextToCell< 1 >( index ), cCoef ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlOneSideDiffNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlOneSideDiffNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity > +__cuda_callable__ +Real +tnlOneSideDiffNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + const typename EntityType::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); + return operatorQ.getValueStriped(mesh,cellIndex, entity, u, time)*(((u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHxInverse()/operatorQ.getValue(mesh,cellIndex, entity, u, time) + -( - u[ mesh.template getCellNextToCell< -1,0 >( cellIndex ) ]+ u[ cellIndex ]) * mesh.getHxInverse()/ + operatorQ.getValue(mesh,mesh.template getCellNextToCell<-1,0>(cellIndex), entity, u, time)) + *mesh.getHxInverse()+(( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHyInverse()/operatorQ.getValue(mesh,cellIndex, entity, u, time) + -( - u[ mesh.template getCellNextToCell< 0,-1 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHyInverse() + /operatorQ.getValue(mesh,mesh.template getCellNextToCell<0,-1>(cellIndex),entity, u, time))*mesh.getHyInverse()); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlOneSideDiffNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return 5; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity, + typename MatrixRow > +__cuda_callable__ +void +tnlOneSideDiffNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + const typename EntityType::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities(); + const RealType aCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< 0,-1 >( index ), entity, u, time ); + const RealType bCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< -1,0 >( index ), entity, u, time ); + const RealType cCoef = tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * ( mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ) + mesh.getHySquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< 0,-1 >( index ), entity, u, time ) + + mesh.getHxSquareInverse() / operatorQ.getValue(mesh, index, entity, u, time ) + + mesh.getHxSquareInverse() / operatorQ.getValue(mesh, mesh.template getCellNextToCell< -1,0 >( index ), entity, u, time ) ); + const RealType dCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ); + const RealType eCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ); + matrixRow.setElement( 0, mesh.template getCellNextToCell< 0,-1 >( index ), aCoef ); + matrixRow.setElement( 1, mesh.template getCellNextToCell< -1,0 >( index ), bCoef ); + matrixRow.setElement( 2, index , cCoef ); + matrixRow.setElement( 3, mesh.template getCellNextToCell< 1,0 >( index ), dCoef ); + matrixRow.setElement( 4, mesh.template getCellNextToCell< 0,1 >( index ), eCoef ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlOneSideDiffNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlOneSideDiffNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity > +__cuda_callable__ +Real +tnlOneSideDiffNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + const typename EntityType::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); + return operatorQ.getValueStriped(mesh,cellIndex, entity, u, time)*(((u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHxInverse()/operatorQ.getValue(mesh,cellIndex, entity, u, time) + -( - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ]+ u[ cellIndex ]) * mesh.getHxInverse()/ + operatorQ.getValue(mesh,mesh.template getCellNextToCell<-1,0,0>(cellIndex), entity, u, time)) + *mesh.getHxInverse()+(( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHyInverse()/operatorQ.getValue(mesh,cellIndex, entity, u, time) + -( - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHyInverse() + /operatorQ.getValue(mesh,mesh.template getCellNextToCell<0,-1,0>(cellIndex),entity, u, time))*mesh.getHyInverse() + +(( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ]) + * mesh.getHzInverse()/operatorQ.getValue(mesh,cellIndex, entity, u, time) + -( - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHzInverse() + /operatorQ.getValue(mesh,mesh.template getCellNextToCell<0,0,-1>(cellIndex),entity, u, time))*mesh.getHzInverse()); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlOneSideDiffNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return 7; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector, + typename MeshEntity, + typename MatrixRow > +__cuda_callable__ +void +tnlOneSideDiffNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + const typename EntityType::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities(); + const RealType aCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHzSquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< 0,0,-1 >( index ), entity, u, time ); + const RealType bCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< 0,-1,0 >( index ), entity, u, time ); + const RealType cCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< -1,0,0 >( index ), entity, u, time ); + const RealType dCoef = tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * ( mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ) + mesh.getHySquareInverse() / + operatorQ.getValue(mesh, mesh.template getCellNextToCell< 0,-1,0 >( index ), entity, u, time ) + + mesh.getHxSquareInverse() / operatorQ.getValue(mesh, index, entity, u, time ) + + mesh.getHxSquareInverse() / operatorQ.getValue(mesh, mesh.template getCellNextToCell< -1,0,0 >( index ), entity, u, time ) + + mesh.getHzSquareInverse() / operatorQ.getValue(mesh, index, entity, u, time ) + + mesh.getHzSquareInverse() / operatorQ.getValue(mesh, mesh.template getCellNextToCell< 0,0,-1 >( index ), entity, u, time ) ); + const RealType eCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHxSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ); + const RealType fCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHySquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ); + const RealType gCoef = - tau * operatorQ.getValueStriped(mesh, index, entity, u, time ) * mesh.getHzSquareInverse() / + operatorQ.getValue(mesh, index, entity, u, time ); + matrixRow.setElement( 0, mesh.template getCellNextToCell< 0,0,-1 >( index ), aCoef ); + matrixRow.setElement( 1, mesh.template getCellNextToCell< 0,-1,0 >( index ), bCoef ); + matrixRow.setElement( 2, mesh.template getCellNextToCell< -1,0,0 >( index ), cCoef ); + matrixRow.setElement( 3, index, dCoef ); + matrixRow.setElement( 4, mesh.template getCellNextToCell< 1,0,0 >( index ), eCoef ); + matrixRow.setElement( 5, mesh.template getCellNextToCell< 0,1,0 >( index ), fCoef ); + matrixRow.setElement( 6, mesh.template getCellNextToCell< 0,0,1 >( index ), gCoef ); +} +#endif /* TNLONESIDEDIFFNONLINEAROPERATOR_IMPL_H */ diff --git a/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator_impl.h~ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator_impl.h~ new file mode 100644 index 0000000000000000000000000000000000000000..1bbd523ee06371fe7537b096d8c93217a2deae55 --- /dev/null +++ b/src/operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator_impl.h~ @@ -0,0 +1,84 @@ + +#ifndef TNLONESIDEDIFFNONLINEAROPERATOR_IMPL_H +#define TNLONESIDEDIFFNONLINEAROPERATOR_IMPL_H + +#include "tnlOneSideDiffNonlinearOperator.h" + +#include <mesh/tnlGrid.h> + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlOneSideDiffNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlOneSideDiffNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlOneSideDiffNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return operatorQ.getValueStriped(mesh,cellIndex,u)*((fDifference.getValueX(mesh,cellIndex,u)/operatorQ.getValue(mesh,cellIndex,u) + -bDifference.getValueX(mesh,cellIndex,u)/operatorQ.getValue(mesh,mesh.template getCellNextToCell<-1,0>(cellIndex),u)) + *mesh.getHxInverse()+(fDifference.getValueY(mesh,cellIndex,u)/operatorQ.getValue(mesh,cellIndex,u) + -bDifference.getValueY(mesh,cellIndex,u)/operatorQ.getValue(mesh,mesh.template getCellNextToCell<0,-1>(cellIndex),u))*mesh.getHyInverse()); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename OperatorQ > +tnlString +tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >:: +getType() +{ + return tnlString( "tnlOneSideDiffNonlinearOperator< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", " + + OperatorQ::getType() + " >"; +} + +#endif /* TNLONESIDEDIFFNONLINEAROPERATOR_IMPL_H */ diff --git a/src/operators/diffusion/tnlExactNonlinearDiffusion.h b/src/operators/diffusion/tnlExactNonlinearDiffusion.h new file mode 100644 index 0000000000000000000000000000000000000000..4526b0ea3554b2c20023e5bf166f6d31a7370674 --- /dev/null +++ b/src/operators/diffusion/tnlExactNonlinearDiffusion.h @@ -0,0 +1,102 @@ +/*************************************************************************** + tnlExactLinearDiffusion.h - description + ------------------- + begin : Aug 8, 2014 + copyright : (C) 2014 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 TNLEXACTNONLINEARDIFFUSION_H_ +#define TNLEXACTNONLINEARDIFFUSION_H_ + +#include <functions/tnlFunction.h> + +template< typename OperatorQ, int Dimensions > +class tnlExactNonlinearDiffusion +{}; + +template< typename OperatorQ > +class tnlExactNonlinearDiffusion< OperatorQ, 1 > +{ + public: + + enum { Dimensions = 1 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< typename Function, typename Vertex, typename Real > +#else + template< typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0 ); +}; + +template< typename OperatorQ > +class tnlExactNonlinearDiffusion< OperatorQ, 2 > +{ + public: + + enum { Dimensions = 2 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< typename Function, typename Vertex, typename Real > +#else + template< typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0 ); +}; + +template< typename OperatorQ > +class tnlExactNonlinearDiffusion< OperatorQ, 3 > +{ + public: + + enum { Dimensions = 3 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< typename Function, typename Vertex, typename Real > +#else + template< typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0 ); +}; + +template< typename OperatorQ, int Dimensions > +class tnlFunctionType< tnlExactNonlinearDiffusion< OperatorQ, Dimensions > > +{ + public: + enum { Type = tnlAnalyticFunction }; +}; + +#include "tnlExactNonlinearDiffusion_impl.h" + +#endif /* TNLEXACTNONLINEARDIFFUSION_H_ */ diff --git a/src/operators/diffusion/tnlExactNonlinearDiffusion_impl.h b/src/operators/diffusion/tnlExactNonlinearDiffusion_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..b1554d13d486bb8330c03ab36ce5839d82fc74a9 --- /dev/null +++ b/src/operators/diffusion/tnlExactNonlinearDiffusion_impl.h @@ -0,0 +1,96 @@ +/*************************************************************************** + tnlExactLinearDiffusion_impl.h - description + ------------------- + begin : Aug 8, 2014 + copyright : (C) 2014 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 TNLEXACTNONLINEARDIFFUSION_IMPL_H_ +#define TNLEXACTNONLINEARDIFFUSION_IMPL_H_ + +template< typename OperatorQ > +tnlString +tnlExactNonlinearDiffusion< OperatorQ, 1 >:: +getType() +{ + return "tnlExactNonlinearDiffusion< " + OperatorQ::getType() + ", 1 >"; +} + +template< typename OperatorQ > +template< typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactNonlinearDiffusion< OperatorQ, 1 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time ) +{ + return function.template getValue< 2, 0, 0, Vertex >( v, time ) - function.template getValue< 1, 0, 0, Vertex >( v, time ) + * OperatorQ::template getValue<1, 0, 0>(function, v, time ) / OperatorQ::template getValue<0, 0, 0>(function, v, time ); +} + +template< typename OperatorQ > +tnlString +tnlExactNonlinearDiffusion< OperatorQ, 2 >:: +getType() +{ + return "tnlExactNonlinearDiffusion< " + OperatorQ::getType() + ", 2 >"; +} + +template< typename OperatorQ > +template< typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactNonlinearDiffusion< OperatorQ, 2 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time ) +{ + return function.template getValue< 2, 0, 0, Vertex >( v, time ) + function.template getValue< 0, 2, 0, Vertex >( v, time ) + -( OperatorQ::template getValue<1, 0, 0> (function, v, time) * function.template getValue< 1, 0, 0, Vertex >( v, time ) + + OperatorQ::template getValue<0, 1, 0> (function, v, time) * function.template getValue< 0, 1, 0, Vertex >( v, time ) ) + / OperatorQ::template getValue<0, 0, 0> (function, v, time); +} + +template< typename OperatorQ > +tnlString +tnlExactNonlinearDiffusion< OperatorQ, 3 >:: +getType() +{ + return "tnlExactNonlinearDiffusion< " + OperatorQ::getType() + ", 3 >"; +} + +template< typename OperatorQ > +template< typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactNonlinearDiffusion< OperatorQ, 3 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time ) +{ + return function.template getValue< 2, 0, 0, Vertex >( v, time ) + function.template getValue< 0, 2, 0, Vertex >( v, time ) + + function.template getValue< 0, 0, 2, Vertex >( v, time ) + -( OperatorQ::template getValue<1, 0, 0> (function, v, time) * function.template getValue< 1, 0, 0, Vertex >( v, time ) + + OperatorQ::template getValue<0, 1, 0> (function, v, time) * function.template getValue< 0, 1, 0, Vertex >( v, time ) + + OperatorQ::template getValue<0, 0, 1> (function, v, time) * function.template getValue< 0, 0, 1, Vertex >( v, time ) ) + / OperatorQ::template getValue<0, 0, 0> (function, v, time); +} + +#endif /* TNLEXACTNONLINEARDIFFUSION_IMPL_H_ */ diff --git a/src/operators/diffusion/tnlLinearDiffusion.h b/src/operators/diffusion/tnlLinearDiffusion.h index c416c922435c363863031722785a781f64231e88..ddce731ea6230682a751671c46120072d2080f36 100644 --- a/src/operators/diffusion/tnlLinearDiffusion.h +++ b/src/operators/diffusion/tnlLinearDiffusion.h @@ -43,31 +43,34 @@ class tnlLinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index typedef typename MeshType::CoordinatesType CoordinatesType; typedef Real RealType; typedef Device DeviceType; - typedef Index IndexType; - typedef typename MeshType::template GridEntity< MeshType::meshDimensions > CellType; + typedef Index IndexType; enum { Dimensions = MeshType::meshDimensions }; static tnlString getType(); - template< typename Vector > + template< typename MeshEntity, + typename Vector > __cuda_callable__ inline Real getValue( const MeshType& mesh, - const CellType& cell, + const MeshEntity& entity, const Vector& u, const RealType& time ) const; + template< typename MeshEntity > __cuda_callable__ inline Index getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, - const CellType& cell ) const; + const MeshEntity& entity ) const; - template< typename Vector, typename MatrixRow > + template< typename MeshEntity, + typename Vector, + typename MatrixRow > __cuda_callable__ inline void updateLinearSystem( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, - const CellType& cell, + const MeshEntity& entity, Vector& u, Vector& b, MatrixRow& matrixRow ) const; @@ -93,8 +96,8 @@ class tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index static tnlString getType(); - template< typename Vector, - typename EntityType > + template< typename EntityType, + typename Vector > __cuda_callable__ inline Real getValue( const MeshType& mesh, const EntityType& entity, @@ -140,8 +143,8 @@ class tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index static tnlString getType(); - template< typename Vector, - typename EntityType > + template< typename EntityType, + typename Vector > __cuda_callable__ inline Real getValue( const MeshType& mesh, const EntityType& entity, diff --git a/src/operators/diffusion/tnlLinearDiffusion_impl.h b/src/operators/diffusion/tnlLinearDiffusion_impl.h index 32bf945ff68fddcb3c80fe47949822f1d573ada5..60ade49ff983f2fbfe7dc0bca62cceff69a8ba43 100644 --- a/src/operators/diffusion/tnlLinearDiffusion_impl.h +++ b/src/operators/diffusion/tnlLinearDiffusion_impl.h @@ -41,20 +41,21 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > -template< typename Vector > +template< typename MeshEntity, + typename Vector > __cuda_callable__ inline Real tnlLinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: getValue( const MeshType& mesh, - const CellType& cell, + const MeshEntity& entity, const Vector& u, const Real& time ) const { - const typename CellType::template NeighbourEntities< 1 >& neighbourEntities = cell.getNeighbourEntities(); + const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); const RealType& hxSquareInverse = mesh.template getSpaceStepsProducts< - 2 >(); return ( u[ neighbourEntities.template getEntityIndex< -1 >() ] - - 2.0 * u[ cell.getIndex() ] + - 2.0 * u[ entity.getIndex() ] + u[ neighbourEntities.template getEntityIndex< 1 >() ] ) * hxSquareInverse; } @@ -63,13 +64,14 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > + template< typename MeshEntity > __cuda_callable__ inline Index tnlLinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index >:: getLinearSystemRowLength( const MeshType& mesh, const IndexType& index, - const CellType& cell ) const + const MeshEntity& entity ) const { return 3; } @@ -79,7 +81,9 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > - template< typename Vector, typename Matrix > + template< typename MeshEntity, + typename Vector, + typename Matrix > __cuda_callable__ inline void @@ -88,12 +92,12 @@ updateLinearSystem( const RealType& time, const RealType& tau, const MeshType& mesh, const IndexType& index, - const CellType& cell, + const MeshEntity& entity, Vector& u, Vector& b, Matrix& matrix ) const { - const typename CellType::template NeighbourEntities< 1 >& neighbourEntities = cell.getNeighbourEntities(); + const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities(); typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2 >(); matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< -1 >(), - lambdaX ); @@ -139,8 +143,8 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > -template< typename Vector, - typename EntityType > +template< typename EntityType, + typename Vector > __cuda_callable__ inline Real @@ -213,8 +217,8 @@ template< typename MeshReal, typename MeshIndex, typename Real, typename Index > -template< typename Vector, - typename EntityType > +template< typename EntityType, + typename Vector > __cuda_callable__ inline Real @@ -279,7 +283,7 @@ updateLinearSystem( const RealType& time, typename Matrix::MatrixRow matrixRow = matrix.getRow( index ); const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2, 0, 0 >(); const RealType lambdaY = tau * mesh.template getSpaceStepsProducts< 0, -2, 0 >(); - const RealType lambdaZ = tau * mesh.template getSpaceStepsProducts< 0, 0, -2 >(); + const RealType lambdaZ = tau * mesh.template getSpaceStepsProducts< 0, 0, -2 >(); matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, 0, -1 >(), -lambdaZ ); matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 0, -1, 0 >(), -lambdaY ); matrixRow.setElement( 2, neighbourEntities.template getEntityIndex< -1, 0, 0 >(), -lambdaX ); diff --git a/src/operators/diffusion/tnlNonlinearDiffusion.h b/src/operators/diffusion/tnlNonlinearDiffusion.h new file mode 100644 index 0000000000000000000000000000000000000000..fdd76331e7eaf9c04e3e3ca0732f8afec61463f3 --- /dev/null +++ b/src/operators/diffusion/tnlNonlinearDiffusion.h @@ -0,0 +1,180 @@ +#ifndef TNLNONLINEARDIFFUSION_H +#define TNLNONLINEARDIFFUSION_H + +#include <core/vectors/tnlVector.h> +#include <mesh/tnlGrid.h> + +template< typename Mesh, + typename NonlinearDiffusionOperator, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType > +class tnlNonlinearDiffusion +{ + +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +class tnlNonlinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef NonlinearDiffusionOperator NonlinearDiffusionOperatorType; + typedef typename MeshType::template GridEntity< MeshType::meshDimensions > CellType; + + static tnlString getType(); + + template< typename MeshEntity, + typename Vector > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + template< typename MeshEntity > + __cuda_callable__ + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, + typename Vector, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + NonlinearDiffusionOperator nonlinearDiffusionOperator; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +class tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef NonlinearDiffusionOperator NonlinearDiffusionOperatorType; + + + static tnlString getType(); + + template< typename MeshEntity, + typename Vector > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + __cuda_callable__ + template< typename MeshEntity > + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, + typename Vector, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + NonlinearDiffusionOperator nonlinearDiffusionOperator; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +class tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef NonlinearDiffusionOperator NonlinearDiffusionOperatorType; + + static tnlString getType(); + + template< typename MeshEntity, + typename Vector > + __cuda_callable__ + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const RealType& time) const; + + __cuda_callable__ + template< typename MeshEntity > + Index getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const; + + template< typename MeshEntity, + typename Vector, + typename MatrixRow > + __cuda_callable__ + void updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const; + + public: + + NonlinearDiffusionOperator nonlinearDiffusionOperator; +}; + + +#include "tnlNonlinearDiffusion_impl.h" + + +#endif /* TNLNONLINEARDIFFUSION_H */ diff --git a/src/operators/diffusion/tnlNonlinearDiffusion_impl.h b/src/operators/diffusion/tnlNonlinearDiffusion_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..e6f307c763cfad7820944d3ab48d90c56e55db93 --- /dev/null +++ b/src/operators/diffusion/tnlNonlinearDiffusion_impl.h @@ -0,0 +1,242 @@ + +#ifndef TNLNONLINEARDIFFUSION_IMPL_H +#define TNLNONLINEARDIFFUSION_IMPL_H + +#include "tnlNonlinearDiffusion.h" + +#include <mesh/tnlGrid.h> + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +tnlString +tnlNonlinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getType() +{ + return tnlString( "tnlNonlinearDiffusion< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + "," + + NonlinearDiffusionOperator::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +template< typename MeshEntity, + typename Vector > +__cuda_callable__ +Real +tnlNonlinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getValue( const MeshType& mesh, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + return nonlinearDiffusionOperator.getValue( mesh, entity, u, time ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlNonlinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return nonlinearDiffusionOperator.getLinearSystemRowLength( mesh, index, entity ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +template< typename MeshEntity, + typename Vector, + typename MatrixRow > +__cuda_callable__ +void +tnlNonlinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + nonlinearDiffusionOperator.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrixRow ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +tnlString +tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getType() +{ + return tnlString( "tnlNonlinearDiffusion< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + "," + + NonlinearDiffusionOperator::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +template< typename MeshEntity, + typename Vector > +__cuda_callable__ +Real +tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + return nonlinearDiffusionOperator.getValue( mesh, cellIndex, entity, u, time ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return nonlinearDiffusionOperator.getLinearSystemRowLength( mesh, index, entity ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +template< typename MeshEntity, + typename Vector, + typename MatrixRow > +__cuda_callable__ +void +tnlNonlinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + nonlinearDiffusionOperator.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrixRow ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +tnlString +tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getType() +{ + return tnlString( "tnlNonlinearDiffusion< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + "," + + NonlinearDiffusionOperator::getType() + " >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +template< typename MeshEntity, + typename Vector > +__cuda_callable__ +Real +tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const MeshEntity& entity, + const Vector& u, + const Real& time ) const +{ + return nonlinearDiffusionOperator.getValue( mesh, cellIndex, entity, u, time ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > + template< typename MeshEntity > +__cuda_callable__ +Index +tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +getLinearSystemRowLength( const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity ) const +{ + return nonlinearDiffusionOperator.getLinearSystemRowLength( mesh, index, entity ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index, + typename NonlinearDiffusionOperator > +template< typename MeshEntity, + typename Vector, + typename MatrixRow > +__cuda_callable__ +void +tnlNonlinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, NonlinearDiffusionOperator, Real, Index >:: +updateLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + const IndexType& index, + const MeshEntity& entity, + Vector& u, + Vector& b, + MatrixRow& matrixRow ) const +{ + nonlinearDiffusionOperator.updateLinearSystem( time, tau, mesh, index, entity, u, b, matrixRow ); +} + +#endif /* TNLNONLINEARDIFFUSION_IMPL_H */ diff --git a/src/operators/operator-Q/CMakeLists.txt b/src/operators/operator-Q/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..192c55d961b738b25f95adcd0935d3ea4a2df1c7 --- /dev/null +++ b/src/operators/operator-Q/CMakeLists.txt @@ -0,0 +1,8 @@ +SET( headers tnlExactOperatorQ.h + tnlExactOperatorQ_impl.h + tnlOneSideDiffOperatorQ.h + tnlOneSideDiffOperatorQ_impl.h + tnlFiniteVolumeOperatorQ.h + tnlFiniteVolumeOperatorQ_impl.h ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/operators/operator-Q ) diff --git a/src/operators/operator-Q/tnlExactOperatorQ.h b/src/operators/operator-Q/tnlExactOperatorQ.h new file mode 100644 index 0000000000000000000000000000000000000000..7caf1635aa56a6d6638f3d21f80cfe5aac2b1c04 --- /dev/null +++ b/src/operators/operator-Q/tnlExactOperatorQ.h @@ -0,0 +1,90 @@ +#ifndef TNLEXACTOPERATORQ_H +#define TNLEXACTOPERATORQ_H + +#include <core/vectors/tnlVector.h> +#include <core/vectors/tnlSharedVector.h> +#include <mesh/tnlGrid.h> +#include <functions/tnlFunction.h> + +template< int Dimensions > +class tnlExactOperatorQ +{}; + +template<> +class tnlExactOperatorQ< 1 > +{ + public: + + enum { Dimensions = 1 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real > +#else + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0, const Real& eps = 1.0 ); + +}; + +template<> +class tnlExactOperatorQ< 2 > +{ + public: + + enum { Dimensions = 2 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real > +#else + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0, const Real& eps = 1.0 ); +}; + +template<> +class tnlExactOperatorQ< 3 > +{ + public: + + enum { Dimensions = 3 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real > +#else + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0, const Real& eps = 1.0 ); +}; + +template< int Dimensions > +class tnlFunctionType< tnlExactOperatorQ< Dimensions > > +{ + public: + enum { Type = tnlAnalyticFunction }; +}; + +#include <operators/operator-Q/tnlExactOperatorQ_impl.h> + + +#endif /* TNLEXACTOPERATORQ_H */ diff --git a/src/operators/operator-Q/tnlExactOperatorQ_impl.h b/src/operators/operator-Q/tnlExactOperatorQ_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..2aaa77f2ec14b60c5054967c6cecca0b4f86457d --- /dev/null +++ b/src/operators/operator-Q/tnlExactOperatorQ_impl.h @@ -0,0 +1,116 @@ +/*************************************************************************** + tnlExactLinearDiffusion_impl.h - description + ------------------- + begin : Aug 8, 2014 + copyright : (C) 2014 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 TNLEXACTOPERATORQ_IMPL_H_ +#define TNLEXACTOPERATORQ_IMPL_H_ + +#include <operators/operator-Q/tnlExactOperatorQ.h> + +tnlString +tnlExactOperatorQ< 1 >:: +getType() +{ + return "tnlExactOperatorQ< 1 >"; +} + +template< int XDiffOrder, int YDiffOrder, int ZDiffOrder, typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactOperatorQ< 1 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time, const Real& eps ) +{ + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if (XDiffOrder == 0) + return sqrt(eps * eps + function.template getValue< 1, 0, 0, Vertex >( v, time ) * function.template getValue< 1, 0, 0, Vertex >( v, time ) ); + if (XDiffOrder == 1) + return (function.template getValue< 1, 0, 0 >( v, time ) * function.template getValue< 2, 0, 0 >( v, time ) ) / getValue( function, v, time, eps); + return 0; +} + +tnlString +tnlExactOperatorQ< 2 >:: +getType() +{ + return "tnlExactOperatorQ< 2 >"; +} + +template< int XDiffOrder, int YDiffOrder, int ZDiffOrder, typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactOperatorQ< 2 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time, const Real& eps ) +{ + if( ZDiffOrder != 0 ) + return 0.0; + if (XDiffOrder == 0 && YDiffOrder == 0 ) + return sqrt(eps * eps + function.template getValue< 1, 0, 0, Vertex >( v, time ) * function.template getValue< 1, 0, 0, Vertex >( v, time ) + + function.template getValue< 0, 1, 0, Vertex >( v, time ) * function.template getValue< 0, 1, 0, Vertex >( v, time ) ); + if (XDiffOrder == 1 && YDiffOrder == 0 ) + return (function.template getValue< 1, 0, 0 >( v, time ) * function.template getValue< 2, 0, 0 >( v, time ) + + function.template getValue< 0, 1, 0 >( v, time ) * function.template getValue< 1, 1, 0 >( v, time )) / getValue( function, v, time, eps); + if (XDiffOrder == 0 && YDiffOrder == 1 ) + return (function.template getValue< 0, 1, 0 >( v, time ) * function.template getValue< 0, 2, 0 >( v, time ) + + function.template getValue< 1, 0, 0 >( v, time ) * function.template getValue< 1, 1, 0 >( v, time )) / getValue( function, v, time, eps); + return 0; +} + +tnlString +tnlExactOperatorQ< 3 >:: +getType() +{ + return "tnlExactOperatorQ< 3 >"; +} + +template< int XDiffOrder, int YDiffOrder, int ZDiffOrder, typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactOperatorQ< 3 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time, const Real& eps ) +{ + if ( XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return sqrt(eps * eps + function.template getValue< 1, 0, 0, Vertex >( v, time ) * function.template getValue< 1, 0, 0, Vertex >( v, time ) + + function.template getValue< 0, 1, 0, Vertex >( v, time ) * function.template getValue< 0, 1, 0, Vertex >( v, time ) + + function.template getValue< 0, 0, 1, Vertex >( v, time ) * function.template getValue< 0, 0, 1, Vertex >( v, time ) ); + if (XDiffOrder == 1 && YDiffOrder == 0 && ZDiffOrder == 0 ) + return (function.template getValue< 1, 0, 0 >( v, time ) * function.template getValue< 2, 0, 0 >( v, time ) + + function.template getValue< 0, 1, 0 >( v, time ) * function.template getValue< 1, 1, 0 >( v, time ) + + function.template getValue< 0, 0, 1 >( v, time ) * function.template getValue< 1, 0, 1 >( v, time )) / getValue( function, v, time, eps); + if (XDiffOrder == 0 && YDiffOrder == 1 && ZDiffOrder == 0 ) + return (function.template getValue< 1, 0, 0 >( v, time ) * function.template getValue< 1, 1, 0 >( v, time ) + + function.template getValue< 0, 1, 0 >( v, time ) * function.template getValue< 0, 2, 0 >( v, time ) + + function.template getValue< 0, 0, 1 >( v, time ) * function.template getValue< 0, 1, 1 >( v, time )) / getValue( function, v, time, eps); + if (XDiffOrder == 0 && YDiffOrder == 0 && ZDiffOrder == 1 ) + return (function.template getValue< 1, 0, 0 >( v, time ) * function.template getValue< 1, 0, 1 >( v, time ) + + function.template getValue< 0, 1, 0 >( v, time ) * function.template getValue< 0, 1, 1 >( v, time ) + + function.template getValue< 0, 0, 1 >( v, time ) * function.template getValue< 0, 0, 2 >( v, time )) / getValue( function, v, time, eps); + return 0; +} + +#endif /* TNLEXACTOPERATORQ_IMPL_H_ */ diff --git a/src/operators/operator-Q/tnlFiniteVolumeOperatorQ.h b/src/operators/operator-Q/tnlFiniteVolumeOperatorQ.h new file mode 100644 index 0000000000000000000000000000000000000000..a3188559e282a52ccc6fd9a23834396ddee54d79 --- /dev/null +++ b/src/operators/operator-Q/tnlFiniteVolumeOperatorQ.h @@ -0,0 +1,387 @@ +#ifndef TNLFINITEVOLUMEOPERATORQ_H +#define TNLFINITEVOLUMEOPERATORQ_H + +#include <core/vectors/tnlVector.h> +#include <core/vectors/tnlSharedVector.h> +#include <mesh/tnlGrid.h> + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType, + int Precomputation = 0 > +class tnlFiniteVolumeOperatorQ +{ + +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlFiniteVolumeOperatorQ< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index, 0 > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + IndexType bind( Vector& u) + { return 0; } + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ) + {} + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + bool setEps(const Real& eps); + + private: + + template< typename Vector, int AxeX = 0, int AxeY = 0, int AxeZ = 0 > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlFiniteVolumeOperatorQ< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index, 0 > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + IndexType bind( Vector& u) + { return 0; } + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ) + {} + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + bool setEps(const Real& eps); + + private: + + template< typename Vector, int AxeX = 0, int AxeY = 0, int AxeZ = 0 > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlFiniteVolumeOperatorQ< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index, 0 > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + IndexType bind( Vector& u) + { return 0; } + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ) + {} + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + bool setEps(const Real& eps); + + private: + + template< typename Vector, int AxeX = 0, int AxeY = 0, int AxeZ = 0 > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlFiniteVolumeOperatorQ< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index, 1 > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + Index bind( Vector& u); + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + bool setEps(const Real& eps); + + private: + + template< typename Vector, int AxeX = 0, int AxeY = 0, int AxeZ = 0 > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + tnlSharedVector< RealType, DeviceType, IndexType > u; + tnlVector< RealType, DeviceType, IndexType> q; + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlFiniteVolumeOperatorQ< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index, 1 > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef tnlSharedVector< RealType, DeviceType, IndexType > DofVectorType; + + static tnlString getType(); + + template< typename Vector > + Index bind( Vector& u); + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + bool setEps(const Real& eps); + + private: + + template< typename Vector, int AxeX = 0, int AxeY = 0, int AxeZ = 0 > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + tnlSharedVector< RealType, DeviceType, IndexType > u; + tnlVector< RealType, DeviceType, IndexType> q; + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlFiniteVolumeOperatorQ< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index, 1 > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + Index bind( Vector& u); + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + bool setEps(const Real& eps); + + private: + + template< typename Vector, int AxeX = 0, int AxeY = 0, int AxeZ = 0 > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx = 0, + const IndexType& dy = 0, + const IndexType& dz = 0 ) const; + + tnlSharedVector< RealType, DeviceType, IndexType > u; + tnlVector< RealType, DeviceType, IndexType> q; + RealType eps; +}; + +#include <operators/operator-Q/tnlFiniteVolumeOperatorQ_impl.h> + + +#endif /* TNLFINITEVOLUMEOPERATORQ_H */ diff --git a/src/operators/operator-Q/tnlFiniteVolumeOperatorQ_impl.h b/src/operators/operator-Q/tnlFiniteVolumeOperatorQ_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..4021fd9c2a8cd0a6fb3daf83b8dd26059e62ea57 --- /dev/null +++ b/src/operators/operator-Q/tnlFiniteVolumeOperatorQ_impl.h @@ -0,0 +1,636 @@ + +#ifndef TNLFINITEVOLUMEOPERATORQ_IMPL_H +#define TNLFINITEVOLUMEOPERATORQ_IMPL_H + +#include <operators/operator-Q/tnlFiniteVolumeOperatorQ.h> +#include <mesh/tnlGrid.h> + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getType() +{ + return tnlString( "tnlFiniteVolumeOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 0 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getType() +{ + return tnlString( "tnlFiniteVolumeOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 1 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +void +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +update( const MeshType& mesh, const RealType& time ) +{ +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector, int AxeX, int AxeY, int AxeZ > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector, int AxeX, int AxeY, int AxeZ > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getType() +{ + return tnlString( "tnlFiniteVolumeOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 0 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getType() +{ + return tnlString( "tnlFiniteVolumeOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 1 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +Index +tnlFiniteVolumeOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +bind( Vector& u) +{ + return 0; +} + +#ifdef HAVE_CUDA + __device__ __host__ +#endif +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +void +tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +update( const MeshType& mesh, const RealType& time ) +{ + CoordinatesType dimensions = mesh.getDimensions(); + CoordinatesType coordinates; + + for( coordinates.x()=1; coordinates.x() < dimensions.x()-1; coordinates.x()++ ) + for( coordinates.y()=1; coordinates.y() < dimensions.y()-1; coordinates.y()++ ) + { + q.setElement( mesh.getCellIndex(coordinates), getValue( mesh, mesh.getCellIndex(coordinates), coordinates, u, time ) ); + } +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector, int AxeX, int AxeY, int AxeZ > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + if ( ( AxeX == 1 ) && ( AxeY == 0 ) && ( AxeZ == 0 ) ) + { + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * ( u[ cellIndex ] - u[ mesh.template getCellNextToCell< -1,0 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< -1,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,1 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,-1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< -1,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,-1 >( cellIndex ) ] ); + } + if ( ( AxeX == 0 ) && ( AxeY == 1 ) && ( AxeZ == 0 ) ) + { + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * ( u[ cellIndex ] - u[ mesh.template getCellNextToCell< 0,-1 >( cellIndex ) ] ); + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,-1 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 1,-1 >( cellIndex ) ] ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< -1,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,-1 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,-1 >( cellIndex ) ] ); + } + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == 0 ) ) + return sqrt( this->eps + ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ) * + ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHyInverse() * mesh.getHyInverse() + ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ) + * ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHxInverse() * mesh.getHxInverse() ); + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, 1, 0 ) * + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, 1, 0 ) + + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, 1, 0 ) * + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, 1, 0 ) ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, -1, 0 ) * + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, -1, 0 ) + + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, -1, 0 ) * + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, -1, 0 ) ); + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 1 ) * + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 1 ) + + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 1 ) * + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 1 ) ); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, 0, -1 ) * + this->template boundaryDerivative< Vector,1,0 >( mesh, cellIndex, coordinates, u, time, 0, -1 ) + + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, 0, -1 ) * + this->template boundaryDerivative< Vector,0,1 >( mesh, cellIndex, coordinates, u, time, 0, -1 ) ); + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + return q.getElement(cellIndex); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getType() +{ + return tnlString( "tnlFiniteVolumeOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 0 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getType() +{ + return tnlString( "tnlFiniteVolumeOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 1 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +Index +tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +bind( Vector& u) +{ + this->u.bind(u); + if(q.setSize(u.getSize())) + return 1; + q.setValue(0); + return 0; +} + +#ifdef HAVE_CUDA + __device__ __host__ +#endif +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +void +tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +update( const MeshType& mesh, const RealType& time ) +{ + CoordinatesType dimensions = mesh.getDimensions(); + CoordinatesType coordinates; + + for( coordinates.x()=1; coordinates.x() < dimensions.x()-1; coordinates.x()++ ) + for( coordinates.y()=1; coordinates.y() < dimensions.y()-1; coordinates.y()++ ) + for( coordinates.z()=1; coordinates.z() < dimensions.z()-1; coordinates.z()++ ) + q.setElement( mesh.getCellIndex(coordinates), getValue( mesh, mesh.getCellIndex(coordinates), coordinates, u, time ) ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector, int AxeX, int AxeY, int AxeZ > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +boundaryDerivative( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + if ( ( AxeX == 1 ) && ( AxeY == 0 ) && ( AxeZ == 0 ) ) + { + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * ( u[ cellIndex ] - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,1,0 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,1,0 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return mesh.getHxInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,-1,0 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,-1,0 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == 1 ) ) + return mesh.getHxInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,0,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,0,1 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == -1 ) ) + return mesh.getHxInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,0,-1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,0,-1 >( cellIndex ) ] ); + } + if ( ( AxeX == 0 ) && ( AxeY == 1 ) && ( AxeZ == 0 ) ) + { + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * ( u[ cellIndex ] - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] ); + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,1,0 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 1,-1,0 >( cellIndex ) ] ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHyInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< -1,1,0 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,-1,0 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == 1 ) ) + return mesh.getHyInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 0,1,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 0,-1,1 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == -1 ) ) + return mesh.getHyInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 0,1,-1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 0,-1,-1 >( cellIndex ) ] ); + } + if ( ( AxeX == 0 ) && ( AxeY == 0 ) && ( AxeZ == 1 ) ) + { + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == 1 ) ) + return mesh.getHzInverse() * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == -1 ) ) + return mesh.getHzInverse() * ( u[ cellIndex ] - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] ); + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHzInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 1,0,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 1,0,-1 >( cellIndex ) ] ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return mesh.getHzInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< -1,0,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< -1,0,-1 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return mesh.getHzInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 0,1,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 0,1,-1 >( cellIndex ) ] ); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return mesh.getHzInverse() * 0.25 * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] + + u[ mesh.template getCellNextToCell< 0,-1,1 >( cellIndex ) ] - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] - + u[ mesh.template getCellNextToCell< 0,-1,-1 >( cellIndex ) ] ); + } + return 0.0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlFiniteVolumeOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time, + const IndexType& dx, + const IndexType& dy, + const IndexType& dz ) const +{ + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == 0 ) ) + return sqrt( this->eps + ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ) * + ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHyInverse() * mesh.getHyInverse() + ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ) + * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHxInverse() * mesh.getHxInverse() + + ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ) + * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHzInverse() * mesh.getHzInverse() ); + if ( ( dx == 1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 1, 0, 0 ) * + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 1, 0, 0 ) + + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 1, 0, 0 ) * + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 1, 0, 0 ) + + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 1, 0, 0 ) * + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 1, 0, 0 ) ); + if ( ( dx == -1 ) && ( dy == 0 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, -1, 0, 0 ) * + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, -1, 0, 0 ) + + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, -1, 0, 0 ) * + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, -1, 0, 0 ) + + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, -1, 0, 0 ) * + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, -1, 0, 0 ) ); + if ( ( dx == 0 ) && ( dy == 1 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, 1, 0 ) * + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, 1, 0 ) + + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 1, 0 ) * + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 1, 0 ) + + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 1, 0 ) * + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 1, 0 )); + if ( ( dx == 0 ) && ( dy == -1 ) && ( dz == 0 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, -1, 0 ) * + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, -1, 0 ) + + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, -1, 0 ) * + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, -1, 0 ) + + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, -1, 0 ) * + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, -1, 0 ) ); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == 1 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, 1 ) * + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, 1 ) + + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, 1 ) * + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, 1 ) + + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 0, 1 ) * + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 0, 1 )); + if ( ( dx == 0 ) && ( dy == 0 ) && ( dz == -1 ) ) + return sqrt( this->eps + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, -1 ) * + this->template boundaryDerivative< Vector,1,0,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, -1 ) + + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, -1 ) * + this->template boundaryDerivative< Vector,0,1,0 >( mesh, cellIndex, coordinates, u, time, 0, 0, -1 ) + + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 0, -1 ) * + this->template boundaryDerivative< Vector,0,0,1 >( mesh, cellIndex, coordinates, u, time, 0, 0, -1 ) ); + return 0.0; +} +#endif /* TNLFINITEVOLUMEOPERATORQ_IMPL_H */ diff --git a/src/operators/operator-Q/tnlOneSideDiffOperatorQ.h b/src/operators/operator-Q/tnlOneSideDiffOperatorQ.h new file mode 100644 index 0000000000000000000000000000000000000000..954152b9a163c9a382752cd5a80145f61e275945 --- /dev/null +++ b/src/operators/operator-Q/tnlOneSideDiffOperatorQ.h @@ -0,0 +1,354 @@ +#ifndef TNLONESIDEDIFFOPERATORQ_H +#define TNLONESIDEDIFFOPERATORQ_H + +#include <core/vectors/tnlVector.h> +#include <core/vectors/tnlSharedVector.h> +#include <mesh/tnlGrid.h> + +template< typename Mesh, + typename Real = typename Mesh::RealType, + typename Index = typename Mesh::IndexType, + int Precomputation = 0 > +class tnlOneSideDiffOperatorQ +{ + +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlOneSideDiffOperatorQ< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index, 0 > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + IndexType bind( Vector& u) + { return 0; } + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ) + {} + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time )const; + + bool setEps(const Real& eps); + + private: + + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlOneSideDiffOperatorQ< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index, 0 > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + IndexType bind( Vector& u) + { return 0; } + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ) + {} + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time )const; + + bool setEps(const Real& eps); + + private: + + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlOneSideDiffOperatorQ< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index, 0 > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + IndexType bind( Vector& u) + { return 0; } + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ) + {} + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + bool setEps(const Real& eps); + + private: + + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlOneSideDiffOperatorQ< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index, 1 > +{ + public: + + typedef tnlGrid< 1, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + Index bind( Vector& u); + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + bool setEps(const Real& eps); + + private: + + tnlSharedVector< RealType, DeviceType, IndexType > u; + tnlVector< RealType, DeviceType, IndexType> q; + tnlVector< RealType, DeviceType, IndexType> qStriped; + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlOneSideDiffOperatorQ< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index, 1 > +{ + public: + + typedef tnlGrid< 2, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + typedef tnlSharedVector< RealType, DeviceType, IndexType > DofVectorType; + + static tnlString getType(); + + template< typename Vector > + Index bind( Vector& u); + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time )const; + + bool setEps(const Real& eps); + + private: + + tnlSharedVector< RealType, DeviceType, IndexType > u; + tnlVector< RealType, DeviceType, IndexType> q; + tnlVector< RealType, DeviceType, IndexType> qStriped; + RealType eps; +}; + + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +class tnlOneSideDiffOperatorQ< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index, 1 > +{ + public: + + typedef tnlGrid< 3, MeshReal, Device, MeshIndex > MeshType; + typedef typename MeshType::CoordinatesType CoordinatesType; + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + static tnlString getType(); + + template< typename Vector > + Index bind( Vector& u); + +#ifdef HAVE_CUDA + __device__ __host__ +#endif + void update( const MeshType& mesh, const RealType& time ); + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const; + + template< typename Vector > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time )const; + + bool setEps(const Real& eps); + + private: + + tnlSharedVector< RealType, DeviceType, IndexType > u; + tnlVector< RealType, DeviceType, IndexType> q; + tnlVector< RealType, DeviceType, IndexType> qStriped; + RealType eps; +}; + +#include <operators/operator-Q/tnlOneSideDiffOperatorQ_impl.h> + + +#endif /* TNLONESIDEDIFFOPERATORQ_H */ diff --git a/src/operators/operator-Q/tnlOneSideDiffOperatorQ_impl.h b/src/operators/operator-Q/tnlOneSideDiffOperatorQ_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..eba301d2baaceaa9353358dfe5541379226e06b8 --- /dev/null +++ b/src/operators/operator-Q/tnlOneSideDiffOperatorQ_impl.h @@ -0,0 +1,522 @@ + +#ifndef TNLONESIDEDIFFOPERATORQ_IMPL_H +#define TNLONESIDEDIFFOPERATORQ_IMPL_H + +#include <operators/operator-Q/tnlOneSideDiffOperatorQ.h> +#include <mesh/tnlGrid.h> + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getType() +{ + return tnlString( "tnlOneSideDiffOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 0 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getType() +{ + return tnlString( "tnlOneSideDiffOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 1 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +Index +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +bind( Vector& u ) +{ + this->u.bind(u); + if(q.setSize(u.getSize())) + return 1; + if(qStriped.setSize(u.getSize())) + return 1; + q.setValue(0); + qStriped.setValue(0); + return 0; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +void +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +update( const MeshType& mesh, const RealType& time ) +{ + CoordinatesType dimensions = mesh.getDimensions(); + CoordinatesType coordinates; + for( coordinates.x()=1; coordinates.x() < dimensions.x()-1; coordinates.x()++ ) + { + q.setElement( coordinates.x(), getValue( mesh, mesh.getCellIndex(coordinates), coordinates, u, time ) ); + } +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return sqrt( this->eps + ( u[ mesh.template getCellNextToCell< 1 >( cellIndex ) ] - u[ cellIndex ]) * + ( u[ mesh.template getCellNextToCell< 1 >( cellIndex ) ] - u[ cellIndex ]) * + mesh.getHxInverse() * mesh.getHxInverse() ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return q.getElement(cellIndex); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return sqrt( this->eps + 0.5*( ( u[ mesh.template getCellNextToCell< 1 >( cellIndex ) ] - u[ cellIndex ]) * + ( u[ mesh.template getCellNextToCell< 1 >( cellIndex ) ] - u[ cellIndex ]) * + mesh.getHxInverse() * mesh.getHxInverse() + ( - u[ mesh.template getCellNextToCell< -1 >( cellIndex ) ] + u[ cellIndex ] ) + * ( - u[ mesh.template getCellNextToCell< -1 >( cellIndex ) ] + u[ cellIndex ] ) * mesh.getHxInverse() * mesh.getHxInverse() ) ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return qStriped.getElement(cellIndex); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getType() +{ + return tnlString( "tnlOneSideDiffOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 0 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getType() +{ + return tnlString( "tnlOneSideDiffOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 1 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +Index +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +bind( Vector& u) +{ + this->u.bind(u); + if(q.setSize(u.getSize())) + return 1; + if(qStriped.setSize(u.getSize())) + return 1; + q.setValue(0); + qStriped.setValue(0); + return 0; +} + +#ifdef HAVE_CUDA + __device__ __host__ +#endif +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +void +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +update( const MeshType& mesh, const RealType& time ) +{ + CoordinatesType dimensions = mesh.getDimensions(); + CoordinatesType coordinates; + + for( coordinates.x()=1; coordinates.x() < dimensions.x()-1; coordinates.x()++ ) + for( coordinates.y()=1; coordinates.y() < dimensions.y()-1; coordinates.y()++ ) + { + q.setElement( mesh.getCellIndex(coordinates), getValue( mesh, mesh.getCellIndex(coordinates), coordinates, u, time ) ); + } +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return sqrt( this->eps + ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ) * + ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHyInverse() * mesh.getHyInverse() + ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ) + * ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHxInverse() * mesh.getHxInverse() ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return q.getElement(cellIndex); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return sqrt( this->eps + 0.5*( ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ) * + ( u[ mesh.template getCellNextToCell< 0,1 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHyInverse() * mesh.getHyInverse() + ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ) + * ( u[ mesh.template getCellNextToCell< 1,0 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHxInverse() * mesh.getHxInverse() + + ( - u[ mesh.template getCellNextToCell< -1,0 >( cellIndex ) ] + u[ cellIndex ]) * ( - u[ mesh.template getCellNextToCell< -1,0 >( cellIndex ) ] + u[ cellIndex ]) + * mesh.getHxInverse() * mesh.getHxInverse() + + ( - u[ mesh.template getCellNextToCell< 0,-1 >( cellIndex ) ] + u[ cellIndex ]) * ( - u[ mesh.template getCellNextToCell< 0,-1 >( cellIndex ) ] + u[ cellIndex ]) * + mesh.getHyInverse() * mesh.getHyInverse() ) ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return qStriped.getElement(cellIndex); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getType() +{ + return tnlString( "tnlOneSideDiffOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 0 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +tnlString +tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +getType() +{ + return tnlString( "tnlOneSideDiffOperatorQ< " ) + + MeshType::getType() + ", " + + ::getType< Real >() + ", " + + ::getType< Index >() + ", 1 >"; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +bool tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >::setEps( const Real& eps ) +{ + this->eps = eps; + + return true; +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +Index +tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +bind( Vector& u) +{ + this->u.bind(u); + if(q.setSize(u.getSize())) + return 1; + if(qStriped.setSize(u.getSize())) + return 1; + q.setValue(0); + qStriped.setValue(0); + return 0; +} + +#ifdef HAVE_CUDA + __device__ __host__ +#endif +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +void +tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 1 >:: +update( const MeshType& mesh, const RealType& time ) +{ + CoordinatesType dimensions = mesh.getDimensions(); + CoordinatesType coordinates; + + for( coordinates.x()=1; coordinates.x() < dimensions.x()-1; coordinates.x()++ ) + for( coordinates.y()=1; coordinates.y() < dimensions.y()-1; coordinates.y()++ ) + for( coordinates.z()=1; coordinates.z() < dimensions.z()-1; coordinates.z()++ ) + q.setElement( mesh.getCellIndex(coordinates), getValue( mesh, mesh.getCellIndex(coordinates), coordinates, u, time ) ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValue( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return sqrt( 1.0 + ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ) * + ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHyInverse() * mesh.getHyInverse() + ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ) + * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHxInverse() * mesh.getHxInverse() + + ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ) * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHzInverse() * mesh.getHzInverse() ); +} + +template< typename MeshReal, + typename Device, + typename MeshIndex, + typename Real, + typename Index > +template< typename Vector > +#ifdef HAVE_CUDA +__device__ __host__ +#endif +Real +tnlOneSideDiffOperatorQ< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index, 0 >:: +getValueStriped( const MeshType& mesh, + const IndexType cellIndex, + const CoordinatesType& coordinates, + const Vector& u, + const Real& time ) const +{ + return sqrt( this->eps + 0.5*( ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ) * + ( u[ mesh.template getCellNextToCell< 0,1,0 >( cellIndex ) ] - u[ cellIndex ] ) * mesh.getHyInverse() * mesh.getHyInverse() + + ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ) * ( u[ mesh.template getCellNextToCell< 1,0,0 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHxInverse() * mesh.getHxInverse() + ( - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] + u[ cellIndex ]) + * ( - u[ mesh.template getCellNextToCell< -1,0,0 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHxInverse() * mesh.getHxInverse() + + ( - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] + u[ cellIndex ]) * + ( - u[ mesh.template getCellNextToCell< 0,-1,0 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHyInverse() * mesh.getHyInverse() + + ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ) * ( u[ mesh.template getCellNextToCell< 0,0,1 >( cellIndex ) ] - u[ cellIndex ] ) + * mesh.getHzInverse() * mesh.getHzInverse() + ( - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] + u[ cellIndex ]) * + ( - u[ mesh.template getCellNextToCell< 0,0,-1 >( cellIndex ) ] + u[ cellIndex ]) * mesh.getHzInverse() * mesh.getHzInverse() + ) ); +} +#endif /* TNLONESIDEDIFFOPERATORQ_IMPL_H */ diff --git a/src/operators/operator-curvature/CMakeLists.txt b/src/operators/operator-curvature/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..7a877b91de5f8c353593c36068b382e3291ccb50 --- /dev/null +++ b/src/operators/operator-curvature/CMakeLists.txt @@ -0,0 +1,4 @@ +SET( headers tnlExactOperatorCurvature.h + tnlExactOperatorCurvature_impl.h ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/operators/operator-curvature ) diff --git a/src/operators/operator-curvature/tnlExactOperatorCurvature.h b/src/operators/operator-curvature/tnlExactOperatorCurvature.h new file mode 100644 index 0000000000000000000000000000000000000000..c2035d3db2941d852faf2fbe1728ea6e96137b8a --- /dev/null +++ b/src/operators/operator-curvature/tnlExactOperatorCurvature.h @@ -0,0 +1,93 @@ +#ifndef TNLEXACTOPERATORCURVATURE_H +#define TNLEXACTOPERATORCURVATURE_H + +#include <core/vectors/tnlVector.h> +#include <core/vectors/tnlSharedVector.h> +#include <mesh/tnlGrid.h> +#include <functions/tnlFunction.h> + +template< typename ExactOperatorQ, int Dimensions > +class tnlExactOperatorCurvature +{}; + +template< typename ExactOperatorQ > +class tnlExactOperatorCurvature< OperatorQ, 1 > +{ + public: + + enum { Dimensions = 1 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real > +#else + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0, const Real& eps = 1.0 ); + +}; + +template< typename ExactOperatorQ > +class tnlExactOperatorCurvature< ExactOperatorQ, 2 > +{ + public: + + enum { Dimensions = 2 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real > +#else + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0, const Real& eps = 1.0 ); +}; + +template< typename ExactOperatorQ > +class tnlExactOperatorCurvature< ExactOperatorQ, 3 > +{ + public: + + enum { Dimensions = 3 }; + + static tnlString getType(); + +#ifdef HAVE_NOT_CXX11 + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real > +#else + template< int XDiffOrder = 0, int YDiffOrder = 0, int ZDiffOrder = 0, typename Function, typename Vertex, typename Real = typename Vertex::RealType > +#endif +#ifdef HAVE_CUDA + __device__ __host__ +#endif + static Real getValue( const Function& function, + const Vertex& v, + const Real& time = 0.0, const Real& eps = 1.0 ) + { + return 0; + } +}; + +template< typename ExactOperatorQ, int Dimensions > +class tnlFunctionType< tnlExactOperatorCurvature< ExactOperatorQ, Dimensions > > +{ + public: + enum { Type = tnlAnalyticFunction }; +}; + +#include <operators/operator-curvature/tnlExactOperatorCurvature_impl.h> + + +#endif /* TNLEXACTOPERATORCURVATURE_H */ diff --git a/src/operators/operator-curvature/tnlExactOperatorCurvature_impl.h b/src/operators/operator-curvature/tnlExactOperatorCurvature_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..f09f59bd835afc9eddd78b5eb8d52e5702b3873d --- /dev/null +++ b/src/operators/operator-curvature/tnlExactOperatorCurvature_impl.h @@ -0,0 +1,88 @@ +/*************************************************************************** + tnlExactLinearDiffusion_impl.h - description + ------------------- + begin : Aug 8, 2014 + copyright : (C) 2014 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 TNLEXACTOPERATORCURVATURE_IMPL_H_ +#define TNLEXACTOPERATORCURVATURE_IMPL_H_ + +#include <operators/operator-curvature/tnlExactOperatorCurvature.h> + +template< typename ExactOperatorQ > +tnlString +tnlExactOperatorCurvature< ExactOperatorQ, 1 >:: +getType() +{ + return "tnlExactOperatorCurvature< " + ExactOperatorQ::getType() + ",1 >"; +} + +template< typename OperatorQ > +template< int XDiffOrder, int YDiffOrder, int ZDiffOrder, typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactOperatorQ< 1 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time, const Real& eps ) +{ + if( YDiffOrder != 0 || ZDiffOrder != 0 ) + return 0.0; + if (XDiffOrder == 0) + return function.template getValue< 2, 0, 0, Vertex >( v, time )/ExactOperatorQ::template getValue< 0, 0, 0 >( function, v, time, eps ) - + ( function.template getValue< 1, 0, 0, Vertex >( v, time ) * ExactOperatorQ::template getValue< 1, 0, 0 >( function, v, time, eps ) ) + / ( ExactOperatorQ::template getValue< 0, 0, 0 >( function, v, time, eps ) * ExactOperatorQ::template getValue< 0, 0, 0 >( function, v, time, eps ) ); + return 0; +} + +template< typename ExactOperatorQ > +tnlString +tnlExactOperatorCurvature< ExactOperatorQ, 2 >:: +getType() +{ + return "tnlExactOperatorCurvature< " + ExactOperatorQ::getType() + ",2 >"; +} + +template< int XDiffOrder, int YDiffOrder, int ZDiffOrder, typename Function, typename Vertex, typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif +Real +tnlExactOperatorQ< 2 >:: +getValue( const Function& function, + const Vertex& v, + const Real& time, const Real& eps ) +{ + if( ZDiffOrder != 0 ) + return 0.0; + if (XDiffOrder == 0 && YDiffOrder == 0 ) + return ( function.template getValue< 2, 0, 0, Vertex >( v, time ) * function.template getValue< 0, 2, 0, Vertex >( v, time ) ) + /ExactOperatorQ::template getValue< 0, 0, 0 >( function, v, time, eps ) - ( function.template getValue< 1, 0, 0, Vertex >( v, time ) * + ExactOperatorQ::template getValue< 1, 0, 0 >( function, v, time, eps ) + function.template getValue< 0, 1, 0, Vertex >( v, time ) * + ExactOperatorQ::template getValue< 0, 1, 0 >( function, v, time, eps ) ) + / ( ExactOperatorQ::template getValue< 0, 0, 0 >( function, v, time, eps ) * ExactOperatorQ::template getValue< 0, 0, 0 >( function, v, time, eps ) ); + return 0; +} + +template< typename ExactOperatorQ > +tnlString +tnlExactOperatorCurvature< ExactOperatorQ, 3 >:: +getType() +{ + return "tnlExactOperatorCurvature< " + ExactOperatorQ::getType() + ",3 >"; +} + +#endif /* TNLEXACTOPERATORCURVATURE_IMPL_H_ */ diff --git a/src/problems/CMakeLists.txt b/src/problems/CMakeLists.txt index f64f63997d219f8e70f1e07452525e606dad70e5..44bc4b55b6b2ffd9c38d19882e6731766d5c8672 100755 --- a/src/problems/CMakeLists.txt +++ b/src/problems/CMakeLists.txt @@ -5,7 +5,12 @@ SET( headers tnlProblem.h tnlHeatEquationProblem_impl.h tnlHeatEquationEocProblem.h tnlHeatEquationEocProblem_impl.h - tnlHeatEquationEocRhs.h + tnlHeatEquationEocRhs.h + tnlMeanCurvatureFlowEocProblem.h + tnlMeanCurvatureFlowEocProblem_impl.h + tnlMeanCurvatureFlowEocRhs.h + tnlMeanCurvatureFlowProblem.h + tnlMeanCurvatureFlowProblem_impl.h ) INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/problems ) diff --git a/src/problems/tnlMeanCurvatureFlowEocProblem.h b/src/problems/tnlMeanCurvatureFlowEocProblem.h new file mode 100644 index 0000000000000000000000000000000000000000..3bb2c5deb51ea53815063b9296a744cbb033608c --- /dev/null +++ b/src/problems/tnlMeanCurvatureFlowEocProblem.h @@ -0,0 +1,42 @@ +/*************************************************************************** + tnlHeatEquationEocProblem.h - description + ------------------- + begin : Nov 22, 2014 + copyright : (C) 2014 by 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 TNLMEANCURVATUREFLOWEOCPROBLEM_H_ +#define TNLMEANCURVATUREFLOWEOCPROBLEM_H_ + +#include <problems/tnlMeanCurvatureFlowProblem.h> +#include <operators/operator-Q/tnlOneSideDiffOperatorQ.h> + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator = tnlNonlinearDiffusion< Mesh, + tnlOneSideDiffNonlinearOperator< Mesh, tnlOneSideDiffOperatorQ<Mesh, typename BoundaryCondition::RealType, + typename BoundaryCondition::IndexType, 0>, typename BoundaryCondition::RealType, typename BoundaryCondition::IndexType >, + typename BoundaryCondition::RealType, typename BoundaryCondition::IndexType > > +class tnlMeanCurvatureFlowEocProblem : public tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator > +{ + public: + + static tnlString getTypeStatic(); + + bool setup( const tnlParameterContainer& parameters ); +}; + +#include <problems/tnlMeanCurvatureFlowEocProblem_impl.h> + +#endif /* TNLMEANCURVATUREFLOWEOCPROBLEM_H_ */ diff --git a/src/problems/tnlMeanCurvatureFlowEocProblem_impl.h b/src/problems/tnlMeanCurvatureFlowEocProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..50c4ddcd7dfbd4554cba0da08262b41b67e06087 --- /dev/null +++ b/src/problems/tnlMeanCurvatureFlowEocProblem_impl.h @@ -0,0 +1,48 @@ +/*************************************************************************** + tnlHeatEquationEocProblem_impl.h - description + ------------------- + begin : Nov 22, 2014 + copyright : (C) 2014 by 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 TNLMEANCURVATUREFLOWEOCPROBLEM_IMPL_H_ +#define TNLMEANCURVATUREFLOWEOCPROBLEM_IMPL_H_ + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +tnlString +tnlMeanCurvatureFlowEocProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +getTypeStatic() +{ + return tnlString( "tnlHeatEquationEocProblem< " ) + Mesh :: getTypeStatic() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +bool +tnlMeanCurvatureFlowEocProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +setup( const tnlParameterContainer& parameters ) +{ + if( ! this->boundaryCondition.setup( parameters ) || + ! this->rightHandSide.setup( parameters ) || + ! this->differentialOperator.nonlinearDiffusionOperator.operatorQ.setEps(parameters.getParameter< double >("eps")) ) + return false; + + return true; +} + +#endif /* TNLMEANCURVATUREFLOWEOCPROBLEM_IMPL_H_ */ diff --git a/src/problems/tnlMeanCurvatureFlowEocRhs.h b/src/problems/tnlMeanCurvatureFlowEocRhs.h new file mode 100644 index 0000000000000000000000000000000000000000..6988b93ac5f33a29eb4624745b91908b24ed595b --- /dev/null +++ b/src/problems/tnlMeanCurvatureFlowEocRhs.h @@ -0,0 +1,67 @@ +/*************************************************************************** + tnlHeatEquationEocRhs.h - description + ------------------- + begin : Sep 8, 2014 + copyright : (C) 2014 by 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 TNLMEANCURVATUREFLOWEOCRHS_H_ +#define TNLMEANCURVATUREFLOWEOCRHS_H_ + +#include <functions/tnlFunction.h> + +template< typename ExactOperator, + typename TestFunction > +class tnlMeanCurvatureFlowEocRhs +{ + public: + + typedef ExactOperator ExactOperatorType; + typedef TestFunction TestFunctionType; + + bool setup( const tnlParameterContainer& parameters, + const tnlString& prefix = "" ) + { + if( ! testFunction.setup( parameters, prefix ) ) + return false; + return true; + }; + + template< typename Vertex, + typename Real > +#ifdef HAVE_CUDA + __device__ __host__ +#endif + Real getValue( const Vertex& vertex, + const Real& time ) const + { + return testFunction.getTimeDerivative( vertex, time ) + - exactOperator.getValue( testFunction, vertex, time ); + }; + + protected: + ExactOperator exactOperator; + + TestFunction testFunction; +}; + +template< typename ExactOperator, + typename TestFunction > +class tnlFunctionType< tnlMeanCurvatureFlowEocRhs< ExactOperator, TestFunction > > +{ + public: + + enum { Type = tnlAnalyticFunction }; +}; + +#endif /* TNLMEANCURVATUREFLOWEOCRHS_H_ */ diff --git a/src/problems/tnlMeanCurvatureFlowProblem.h b/src/problems/tnlMeanCurvatureFlowProblem.h new file mode 100644 index 0000000000000000000000000000000000000000..4c09ad5bd359710101c678c4c58c7120b0173ac4 --- /dev/null +++ b/src/problems/tnlMeanCurvatureFlowProblem.h @@ -0,0 +1,110 @@ +/*************************************************************************** + tnlHeatEquationProblem.h - description + ------------------- + begin : Feb 23, 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 TNLMEANCURVATUREFLOWPROBLEM_H_ +#define TNLMEANCURVATUREFLOWPROBLEM_H_ + +#include <operators/diffusion/tnlNonlinearDiffusion.h> +#include <operators/diffusion/nonlinear-diffusion-operators/tnlOneSideDiffNonlinearOperator.h> +#include <problems/tnlPDEProblem.h> +#include <operators/operator-Q/tnlOneSideDiffOperatorQ.h> +#include <matrices/tnlCSRMatrix.h> + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator = tnlNonlinearDiffusion< Mesh, + tnlOneSideDiffNonlinearOperator< Mesh, tnlOneSideDiffOperatorQ<Mesh, typename Mesh::RealType, + typename Mesh::IndexType, 0>, typename Mesh::RealType, typename Mesh::IndexType >, + typename Mesh::RealType, typename Mesh::IndexType > > +class tnlMeanCurvatureFlowProblem : public tnlPDEProblem< Mesh, + typename DifferentialOperator::RealType, + typename Mesh::DeviceType, + typename DifferentialOperator::IndexType > +{ + public: + + typedef typename DifferentialOperator::RealType RealType; + typedef typename Mesh::DeviceType DeviceType; + typedef typename DifferentialOperator::IndexType IndexType; + typedef tnlPDEProblem< Mesh, RealType, DeviceType, IndexType > BaseType; + typedef tnlCSRMatrix< RealType, DeviceType, IndexType> MatrixType; + + using typename BaseType::MeshType; + using typename BaseType::DofVectorType; + using typename BaseType::MeshDependentDataType; + + static tnlString getTypeStatic(); + + tnlString getPrologHeader() const; + + void writeProlog( tnlLogger& logger, + const tnlParameterContainer& parameters ) const; + + bool setup( const tnlParameterContainer& parameters ); + + bool setInitialCondition( const tnlParameterContainer& parameters, + const MeshType& mesh, + DofVectorType& dofs, + MeshDependentDataType& meshDependentData ); + + template< typename Matrix > + bool setupLinearSystem( const MeshType& mesh, + Matrix& matrix ); + + bool makeSnapshot( const RealType& time, + const IndexType& step, + const MeshType& mesh, + DofVectorType& dofs, + MeshDependentDataType& meshDependentData ); + + IndexType getDofs( const MeshType& mesh ) const; + + void bindDofs( const MeshType& mesh, + DofVectorType& dofs ); + + void getExplicitRHS( const RealType& time, + const RealType& tau, + const MeshType& mesh, + DofVectorType& _u, + DofVectorType& _fu, + MeshDependentDataType& meshDependentData ); + + template< typename Matrix > + void assemblyLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + DofVectorType& dofs, + Matrix& matrix, + DofVectorType& rightHandSide, + MeshDependentDataType& meshDependentData ); + + + protected: + + tnlSharedVector< RealType, DeviceType, IndexType > solution; + + DifferentialOperator differentialOperator; + + BoundaryCondition boundaryCondition; + + RightHandSide rightHandSide; +}; + +#include "tnlMeanCurvatureFlowProblem_impl.h" + +#endif /* TNLMEANCURVATUREFLOWPROBLEM_H_ */ diff --git a/src/problems/tnlMeanCurvatureFlowProblem_impl.h b/src/problems/tnlMeanCurvatureFlowProblem_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0be5299ac6033b89d65f6c4759c08f52bde8cafb --- /dev/null +++ b/src/problems/tnlMeanCurvatureFlowProblem_impl.h @@ -0,0 +1,262 @@ +/*************************************************************************** + tnlHeatEquationProblem_impl.h - description + ------------------- + begin : Mar 10, 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 TNLMEANCURVATUREFLOWPROBLEM_IMPL_H_ +#define TNLMEANCURVATUREFLOWPROBLEM_IMPL_H_ + +#include <core/mfilename.h> +#include <matrices/tnlMatrixSetter.h> +#include <matrices/tnlMultidiagonalMatrixSetter.h> +#include <core/tnlLogger.h> +#include <solvers/pde/tnlExplicitUpdater.h> +#include <solvers/pde/tnlLinearSystemAssembler.h> +#include <solvers/pde/tnlBackwardTimeDiscretisation.h> + +#include "tnlMeanCurvatureFlowProblem.h" + + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +tnlString +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +getTypeStatic() +{ + return tnlString( "tnlMeanCurvativeFlowProblem< " ) + Mesh :: getTypeStatic() + " >"; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +tnlString +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +getPrologHeader() const +{ + return tnlString( "Mean Curvative Flow" ); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +void +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const +{ +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +bool +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +setup( const tnlParameterContainer& parameters ) +{ + if( ! this->boundaryCondition.setup( parameters, "boundary-conditions-" ) || + ! this->rightHandSide.setup( parameters, "right-hand-side-" ) || + ! this->differentialOperator.nonlinearDiffusionOperator.operatorQ.setEps( parameters.getParameter< double >( "eps" ) ) ) + return false; + + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +typename tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::IndexType +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +getDofs( const MeshType& mesh ) const +{ + /**** + * Set-up DOFs and supporting grid functions + */ + return mesh.template getEntitiesCount< typename Mesh::Cell >(); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +void +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +bindDofs( const MeshType& mesh, + DofVectorType& dofVector ) +{ + const IndexType dofs = mesh.template getEntitiesCount< typename Mesh::Cell >(); + this->solution.bind( dofVector.getData(), dofs ); + differentialOperator.nonlinearDiffusionOperator.operatorQ.bind(solution); +// this->differentialOperator.setupDofs(mesh); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +bool +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +setInitialCondition( const tnlParameterContainer& parameters, + const MeshType& mesh, + DofVectorType& dofs, + MeshDependentDataType& meshDependentData ) +{ + this->bindDofs( mesh, dofs ); + const tnlString& initialConditionFile = parameters.getParameter< tnlString >( "initial-condition" ); + if( ! this->solution.load( initialConditionFile ) ) + { + cerr << "I am not able to load the initial condition from the file " << initialConditionFile << "." << endl; + return false; + } + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +template< typename Matrix > +bool +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +setupLinearSystem( const MeshType& mesh, + Matrix& matrix ) +{ + const IndexType dofs = this->getDofs( mesh ); + typedef typename MatrixType::CompressedRowsLengthsVector CompressedRowsLengthsVectorType; + CompressedRowsLengthsVectorType rowLengths; + if( ! rowLengths.setSize( dofs ) ) + return false; + tnlMatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowsLengthsVectorType > matrixSetter; + matrixSetter.template getCompressedRowsLengths< typename Mesh::Cell >( + mesh, + differentialOperator, + boundaryCondition, + rowLengths + ); + matrix.setDimensions( dofs, dofs ); + if( ! matrix.setCompressedRowsLengths( rowLengths ) ) + return false; + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +bool +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +makeSnapshot( const RealType& time, + const IndexType& step, + const MeshType& mesh, + DofVectorType& dofs, + MeshDependentDataType& meshDependentData ) +{ + cout << endl << "Writing output at time " << time << " step " << step << "." << endl; + + this->bindDofs( mesh, dofs ); + //cout << "dofs = " << dofs << endl; + tnlString fileName; + FileNameBaseNumberEnding( "u-", step, 5, ".tnl", fileName ); + if( ! this->solution.save( fileName ) ) + return false; + return true; +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +void +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +getExplicitRHS( const RealType& time, + const RealType& tau, + const MeshType& mesh, + DofVectorType& u, + DofVectorType& fu, + MeshDependentDataType& meshDependentData ) +{ + /**** + * If you use an explicit solver like tnlEulerSolver or tnlMersonSolver, you + * need to implement this method. Compute the right-hand side of + * + * d/dt u(x) = fu( x, u ) + * + * You may use supporting vectors again if you need. + */ + +// this->differentialOperator.computeFirstGradient(mesh,time,u); + + //cout << "u = " << u << endl; + this->bindDofs( mesh, u ); + differentialOperator.nonlinearDiffusionOperator.operatorQ.update( mesh, time ); + tnlExplicitUpdater< Mesh, DofVectorType, DifferentialOperator, BoundaryCondition, RightHandSide > explicitUpdater; + explicitUpdater.template update< typename Mesh::Cell >( + time, + mesh, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + fu ); + //cout << "u = " << u << endl; + //cout << "fu = " << fu << endl; + //_u.save( "u.tnl" ); + //_fu.save( "fu.tnl" ); + //getchar(); +} + +template< typename Mesh, + typename BoundaryCondition, + typename RightHandSide, + typename DifferentialOperator > +template< typename Matrix > +void +tnlMeanCurvatureFlowProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >:: +assemblyLinearSystem( const RealType& time, + const RealType& tau, + const MeshType& mesh, + DofVectorType& u, + Matrix& matrix, + DofVectorType& b, + MeshDependentDataType& meshDependentData ) +{ + tnlLinearSystemAssembler< Mesh, + DofVectorType, + DifferentialOperator, + BoundaryCondition, + RightHandSide, + tnlBackwardTimeDiscretisation, + MatrixType > systemAssembler; + systemAssembler.template assembly< typename Mesh::Cell >( + time, + tau, + mesh, + this->differentialOperator, + this->boundaryCondition, + this->rightHandSide, + u, + matrix, + b ); + /*matrix.print( cout ); + cout << endl << b << endl; + cout << endl << u << endl; + abort();*/ +} + +#endif /* TNLMEANCURVATUREFLOWPROBLEM_IMPL_H_ */