From 7bd3d2be080720a5b40b6898e6588e937497201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= Date: Mon, 16 Dec 2019 15:51:02 +0100 Subject: Mantaflow [Part 5]: Update other /intern packages Cycles needs some smaller updates so that the up-res smoke wavelet noise and the liquid mesh speed vector export work correctly. Reviewed By: mont29 Maniphest Tasks: T59995 Differential Revision: https://developer.blender.org/D3854 --- intern/elbeem/CMakeLists.txt | 130 -- intern/elbeem/COPYING | 358 --- intern/elbeem/COPYING_trimesh2 | 303 --- intern/elbeem/extern/LBM_fluidsim.h | 35 - intern/elbeem/extern/elbeem.h | 273 --- intern/elbeem/intern/attributes.cpp | 362 --- intern/elbeem/intern/attributes.h | 248 -- intern/elbeem/intern/controlparticles.cpp | 1465 ------------ intern/elbeem/intern/controlparticles.h | 327 --- intern/elbeem/intern/elbeem.cpp | 430 ---- intern/elbeem/intern/elbeem_control.cpp | 28 - intern/elbeem/intern/elbeem_control.h | 65 - intern/elbeem/intern/globals.h | 10 - intern/elbeem/intern/isosurface.cpp | 1122 --------- intern/elbeem/intern/isosurface.h | 244 -- intern/elbeem/intern/loop_tools.h | 186 -- intern/elbeem/intern/mcubes_tables.h | 300 --- intern/elbeem/intern/mvmcoords.cpp | 205 -- intern/elbeem/intern/mvmcoords.h | 108 - intern/elbeem/intern/ntl_blenderdumper.cpp | 270 --- intern/elbeem/intern/ntl_blenderdumper.h | 42 - intern/elbeem/intern/ntl_bsptree.cpp | 945 -------- intern/elbeem/intern/ntl_bsptree.h | 135 -- intern/elbeem/intern/ntl_geometryclass.h | 127 -- intern/elbeem/intern/ntl_geometrymodel.cpp | 477 ---- intern/elbeem/intern/ntl_geometrymodel.h | 104 - intern/elbeem/intern/ntl_geometryobject.cpp | 806 ------- intern/elbeem/intern/ntl_geometryobject.h | 255 --- intern/elbeem/intern/ntl_geometryshader.h | 73 - intern/elbeem/intern/ntl_lighting.cpp | 184 -- intern/elbeem/intern/ntl_lighting.h | 254 --- intern/elbeem/intern/ntl_matrices.h | 790 ------- intern/elbeem/intern/ntl_ray.cpp | 915 -------- intern/elbeem/intern/ntl_ray.h | 438 ---- intern/elbeem/intern/ntl_vector3dim.h | 1105 --------- intern/elbeem/intern/ntl_world.cpp | 934 -------- intern/elbeem/intern/ntl_world.h | 411 ---- intern/elbeem/intern/paraloopend.h | 45 - intern/elbeem/intern/parametrizer.cpp | 597 ----- intern/elbeem/intern/parametrizer.h | 322 --- intern/elbeem/intern/particletracer.cpp | 470 ---- intern/elbeem/intern/particletracer.h | 296 --- intern/elbeem/intern/simulation_object.cpp | 471 ---- intern/elbeem/intern/simulation_object.h | 206 -- intern/elbeem/intern/solver_adap.cpp | 1281 ----------- intern/elbeem/intern/solver_class.h | 1036 --------- intern/elbeem/intern/solver_control.cpp | 876 ------- intern/elbeem/intern/solver_control.h | 199 -- intern/elbeem/intern/solver_init.cpp | 2396 -------------------- intern/elbeem/intern/solver_interface.cpp | 753 ------ intern/elbeem/intern/solver_interface.h | 639 ------ intern/elbeem/intern/solver_main.cpp | 1723 -------------- intern/elbeem/intern/solver_relax.h | 1169 ---------- intern/elbeem/intern/solver_util.cpp | 1753 -------------- intern/elbeem/intern/utilities.cpp | 498 ---- intern/elbeem/intern/utilities.h | 205 -- intern/smoke/CMakeLists.txt | 99 - intern/smoke/extern/smoke_API.h | 111 - intern/smoke/intern/EIGENVALUE_HELPER.cpp | 888 -------- intern/smoke/intern/EIGENVALUE_HELPER.h | 77 - intern/smoke/intern/FFT_NOISE.h | 183 -- intern/smoke/intern/FLUID_3D.cpp | 1792 --------------- intern/smoke/intern/FLUID_3D.h | 269 --- intern/smoke/intern/FLUID_3D_SOLVERS.cpp | 328 --- intern/smoke/intern/FLUID_3D_STATIC.cpp | 646 ------ intern/smoke/intern/IMAGE.h | 289 --- intern/smoke/intern/INTERPOLATE.h | 230 -- intern/smoke/intern/LICENSE.txt | 674 ------ intern/smoke/intern/LU_HELPER.cpp | 139 -- intern/smoke/intern/LU_HELPER.h | 54 - intern/smoke/intern/MERSENNETWISTER.h | 432 ---- intern/smoke/intern/Makefile.FFT | 22 - intern/smoke/intern/Makefile.cygwin | 23 - intern/smoke/intern/Makefile.linux | 23 - intern/smoke/intern/Makefile.mac | 35 - intern/smoke/intern/OBSTACLE.h | 46 - intern/smoke/intern/SPHERE.cpp | 53 - intern/smoke/intern/SPHERE.h | 44 - intern/smoke/intern/VEC3.h | 991 -------- intern/smoke/intern/WAVELET_NOISE.h | 519 ----- intern/smoke/intern/WTURBULENCE.cpp | 1198 ---------- intern/smoke/intern/WTURBULENCE.h | 150 -- intern/smoke/intern/smoke_API.cpp | 495 ---- intern/smoke/intern/tnt/jama_eig.h | 1053 --------- intern/smoke/intern/tnt/jama_lu.h | 322 --- intern/smoke/intern/tnt/tnt.h | 67 - intern/smoke/intern/tnt/tnt_array1d.h | 281 --- intern/smoke/intern/tnt/tnt_array1d_utils.h | 233 -- intern/smoke/intern/tnt/tnt_array2d.h | 318 --- intern/smoke/intern/tnt/tnt_array2d_utils.h | 290 --- intern/smoke/intern/tnt/tnt_array3d.h | 299 --- intern/smoke/intern/tnt/tnt_array3d_utils.h | 239 -- intern/smoke/intern/tnt/tnt_cmat.h | 583 ----- intern/smoke/intern/tnt/tnt_fortran_array1d.h | 270 --- .../smoke/intern/tnt/tnt_fortran_array1d_utils.h | 245 -- intern/smoke/intern/tnt/tnt_fortran_array2d.h | 228 -- .../smoke/intern/tnt/tnt_fortran_array2d_utils.h | 239 -- intern/smoke/intern/tnt/tnt_fortran_array3d.h | 226 -- .../smoke/intern/tnt/tnt_fortran_array3d_utils.h | 252 -- intern/smoke/intern/tnt/tnt_i_refvec.h | 246 -- intern/smoke/intern/tnt/tnt_math_utils.h | 35 - intern/smoke/intern/tnt/tnt_sparse_matrix_csr.h | 106 - intern/smoke/intern/tnt/tnt_stopwatch.h | 98 - intern/smoke/intern/tnt/tnt_subscript.h | 57 - intern/smoke/intern/tnt/tnt_vec.h | 407 ---- intern/smoke/intern/tnt/tnt_version.h | 42 - 106 files changed, 45345 deletions(-) delete mode 100644 intern/elbeem/CMakeLists.txt delete mode 100644 intern/elbeem/COPYING delete mode 100644 intern/elbeem/COPYING_trimesh2 delete mode 100644 intern/elbeem/extern/LBM_fluidsim.h delete mode 100644 intern/elbeem/extern/elbeem.h delete mode 100644 intern/elbeem/intern/attributes.cpp delete mode 100644 intern/elbeem/intern/attributes.h delete mode 100644 intern/elbeem/intern/controlparticles.cpp delete mode 100644 intern/elbeem/intern/controlparticles.h delete mode 100644 intern/elbeem/intern/elbeem.cpp delete mode 100644 intern/elbeem/intern/elbeem_control.cpp delete mode 100644 intern/elbeem/intern/elbeem_control.h delete mode 100644 intern/elbeem/intern/globals.h delete mode 100644 intern/elbeem/intern/isosurface.cpp delete mode 100644 intern/elbeem/intern/isosurface.h delete mode 100644 intern/elbeem/intern/loop_tools.h delete mode 100644 intern/elbeem/intern/mcubes_tables.h delete mode 100644 intern/elbeem/intern/mvmcoords.cpp delete mode 100644 intern/elbeem/intern/mvmcoords.h delete mode 100644 intern/elbeem/intern/ntl_blenderdumper.cpp delete mode 100644 intern/elbeem/intern/ntl_blenderdumper.h delete mode 100644 intern/elbeem/intern/ntl_bsptree.cpp delete mode 100644 intern/elbeem/intern/ntl_bsptree.h delete mode 100644 intern/elbeem/intern/ntl_geometryclass.h delete mode 100644 intern/elbeem/intern/ntl_geometrymodel.cpp delete mode 100644 intern/elbeem/intern/ntl_geometrymodel.h delete mode 100644 intern/elbeem/intern/ntl_geometryobject.cpp delete mode 100644 intern/elbeem/intern/ntl_geometryobject.h delete mode 100644 intern/elbeem/intern/ntl_geometryshader.h delete mode 100644 intern/elbeem/intern/ntl_lighting.cpp delete mode 100644 intern/elbeem/intern/ntl_lighting.h delete mode 100644 intern/elbeem/intern/ntl_matrices.h delete mode 100644 intern/elbeem/intern/ntl_ray.cpp delete mode 100644 intern/elbeem/intern/ntl_ray.h delete mode 100644 intern/elbeem/intern/ntl_vector3dim.h delete mode 100644 intern/elbeem/intern/ntl_world.cpp delete mode 100644 intern/elbeem/intern/ntl_world.h delete mode 100644 intern/elbeem/intern/paraloopend.h delete mode 100644 intern/elbeem/intern/parametrizer.cpp delete mode 100644 intern/elbeem/intern/parametrizer.h delete mode 100644 intern/elbeem/intern/particletracer.cpp delete mode 100644 intern/elbeem/intern/particletracer.h delete mode 100644 intern/elbeem/intern/simulation_object.cpp delete mode 100644 intern/elbeem/intern/simulation_object.h delete mode 100644 intern/elbeem/intern/solver_adap.cpp delete mode 100644 intern/elbeem/intern/solver_class.h delete mode 100644 intern/elbeem/intern/solver_control.cpp delete mode 100644 intern/elbeem/intern/solver_control.h delete mode 100644 intern/elbeem/intern/solver_init.cpp delete mode 100644 intern/elbeem/intern/solver_interface.cpp delete mode 100644 intern/elbeem/intern/solver_interface.h delete mode 100644 intern/elbeem/intern/solver_main.cpp delete mode 100644 intern/elbeem/intern/solver_relax.h delete mode 100644 intern/elbeem/intern/solver_util.cpp delete mode 100644 intern/elbeem/intern/utilities.cpp delete mode 100644 intern/elbeem/intern/utilities.h delete mode 100644 intern/smoke/CMakeLists.txt delete mode 100644 intern/smoke/extern/smoke_API.h delete mode 100644 intern/smoke/intern/EIGENVALUE_HELPER.cpp delete mode 100644 intern/smoke/intern/EIGENVALUE_HELPER.h delete mode 100644 intern/smoke/intern/FFT_NOISE.h delete mode 100644 intern/smoke/intern/FLUID_3D.cpp delete mode 100644 intern/smoke/intern/FLUID_3D.h delete mode 100644 intern/smoke/intern/FLUID_3D_SOLVERS.cpp delete mode 100644 intern/smoke/intern/FLUID_3D_STATIC.cpp delete mode 100644 intern/smoke/intern/IMAGE.h delete mode 100644 intern/smoke/intern/INTERPOLATE.h delete mode 100644 intern/smoke/intern/LICENSE.txt delete mode 100644 intern/smoke/intern/LU_HELPER.cpp delete mode 100644 intern/smoke/intern/LU_HELPER.h delete mode 100644 intern/smoke/intern/MERSENNETWISTER.h delete mode 100644 intern/smoke/intern/Makefile.FFT delete mode 100644 intern/smoke/intern/Makefile.cygwin delete mode 100644 intern/smoke/intern/Makefile.linux delete mode 100644 intern/smoke/intern/Makefile.mac delete mode 100644 intern/smoke/intern/OBSTACLE.h delete mode 100644 intern/smoke/intern/SPHERE.cpp delete mode 100644 intern/smoke/intern/SPHERE.h delete mode 100644 intern/smoke/intern/VEC3.h delete mode 100644 intern/smoke/intern/WAVELET_NOISE.h delete mode 100644 intern/smoke/intern/WTURBULENCE.cpp delete mode 100644 intern/smoke/intern/WTURBULENCE.h delete mode 100644 intern/smoke/intern/smoke_API.cpp delete mode 100644 intern/smoke/intern/tnt/jama_eig.h delete mode 100644 intern/smoke/intern/tnt/jama_lu.h delete mode 100644 intern/smoke/intern/tnt/tnt.h delete mode 100644 intern/smoke/intern/tnt/tnt_array1d.h delete mode 100644 intern/smoke/intern/tnt/tnt_array1d_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_array2d.h delete mode 100644 intern/smoke/intern/tnt/tnt_array2d_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_array3d.h delete mode 100644 intern/smoke/intern/tnt/tnt_array3d_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_cmat.h delete mode 100644 intern/smoke/intern/tnt/tnt_fortran_array1d.h delete mode 100644 intern/smoke/intern/tnt/tnt_fortran_array1d_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_fortran_array2d.h delete mode 100644 intern/smoke/intern/tnt/tnt_fortran_array2d_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_fortran_array3d.h delete mode 100644 intern/smoke/intern/tnt/tnt_fortran_array3d_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_i_refvec.h delete mode 100644 intern/smoke/intern/tnt/tnt_math_utils.h delete mode 100644 intern/smoke/intern/tnt/tnt_sparse_matrix_csr.h delete mode 100644 intern/smoke/intern/tnt/tnt_stopwatch.h delete mode 100644 intern/smoke/intern/tnt/tnt_subscript.h delete mode 100644 intern/smoke/intern/tnt/tnt_vec.h delete mode 100644 intern/smoke/intern/tnt/tnt_version.h (limited to 'intern') diff --git a/intern/elbeem/CMakeLists.txt b/intern/elbeem/CMakeLists.txt deleted file mode 100644 index 63a6af84323..00000000000 --- a/intern/elbeem/CMakeLists.txt +++ /dev/null @@ -1,130 +0,0 @@ -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# 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. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2006, Blender Foundation -# All rights reserved. -# ***** END GPL LICENSE BLOCK ***** - -set(INC - extern - ../guardedalloc -) - -set(INC_SYS - ${PNG_INCLUDE_DIRS} - ${ZLIB_INCLUDE_DIRS} -) - -set(SRC - intern/attributes.cpp - intern/controlparticles.cpp - intern/elbeem.cpp - intern/elbeem_control.cpp - intern/isosurface.cpp - intern/mvmcoords.cpp - intern/ntl_blenderdumper.cpp - intern/ntl_bsptree.cpp - intern/ntl_geometrymodel.cpp - intern/ntl_geometryobject.cpp - intern/ntl_lighting.cpp - intern/ntl_ray.cpp - intern/ntl_world.cpp - intern/parametrizer.cpp - intern/particletracer.cpp - intern/simulation_object.cpp - intern/solver_adap.cpp - intern/solver_control.cpp - intern/solver_init.cpp - intern/solver_interface.cpp - intern/solver_main.cpp - intern/solver_util.cpp - intern/utilities.cpp - - extern/LBM_fluidsim.h - extern/elbeem.h - intern/attributes.h - intern/controlparticles.h - intern/elbeem_control.h - intern/isosurface.h - intern/loop_tools.h - intern/mcubes_tables.h - intern/mvmcoords.h - intern/ntl_blenderdumper.h - intern/ntl_bsptree.h - intern/ntl_geometryclass.h - intern/ntl_geometrymodel.h - intern/ntl_geometryobject.h - intern/ntl_geometryshader.h - intern/ntl_lighting.h - intern/ntl_matrices.h - intern/ntl_ray.h - intern/ntl_vector3dim.h - intern/ntl_world.h - intern/paraloopend.h - intern/parametrizer.h - intern/particletracer.h - intern/simulation_object.h - intern/solver_class.h - intern/solver_control.h - intern/solver_interface.h - intern/solver_relax.h - intern/utilities.h - intern/globals.h -) - -set(LIB -) - -# elbeem has some harmless UNUSED warnings -remove_strict_flags() - -add_definitions( - -DNOGUI - -DELBEEM_BLENDER=1 -) - -# not essential but quiet gcc's -Wundef -add_definitions( - -DLBM_PRECISION=1 - -DLBM_INCLUDE_TESTSOLVERS=0 - -DFSGR_STRICT_DEBUG=0 - -DELBEEM_MPI=0 - -DNEWDIRVELMOTEST=0 -) - -if(WIN32) - # We need BLI_gzopen on win32 for unicode paths - add_definitions( - -DLBM_GZIP_OVERRIDE_H="${CMAKE_SOURCE_DIR}/source/blender/blenlib/BLI_fileops.h" - -D LBM_GZIP_OPEN_FN="\(gzFile\)BLI_gzopen" - ) -endif() - -if(WITH_OPENMP) - add_definitions(-DPARALLEL=1) -else() - add_definitions(-DPARALLEL=0) -endif() - -# Work around hang with GCC and ASAN. -if(WITH_COMPILER_ASAN) - if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-sanitize=vptr") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-sanitize=vptr") - endif() -endif() - -blender_add_lib_nolist(bf_intern_elbeem "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/intern/elbeem/COPYING b/intern/elbeem/COPYING deleted file mode 100644 index 2600c731161..00000000000 --- a/intern/elbeem/COPYING +++ /dev/null @@ -1,358 +0,0 @@ - All code distributed as part of El'Beem is covered by the following - version of the GNU General Public License. - - 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. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - Copyright (c) 2003-2005 Nils Thuerey. All rights reserved. - - - - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/intern/elbeem/COPYING_trimesh2 b/intern/elbeem/COPYING_trimesh2 deleted file mode 100644 index a214195fd60..00000000000 --- a/intern/elbeem/COPYING_trimesh2 +++ /dev/null @@ -1,303 +0,0 @@ -This distribution includes source to "miniball", "freeGLUT", -and "GLUI", which are covered under their own licenses. - -All other code distributed as part of trimesh2 is covered -by the following license: - - -Copyright (c) 2004 Szymon Rusinkiewicz. -All rights reserved. - -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. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - - - - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS diff --git a/intern/elbeem/extern/LBM_fluidsim.h b/intern/elbeem/extern/LBM_fluidsim.h deleted file mode 100644 index 256d8c59daa..00000000000 --- a/intern/elbeem/extern/LBM_fluidsim.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) Blender Foundation. - * All rights reserved. - */ - -/** \file - * \ingroup elbeem - */ - -#ifndef LBM_FLUIDSIM_H -#define LBM_FLUIDSIM_H - -/* note; elbeem.h was exported all over, should only expose LBM_fluidsim.h */ -#include "elbeem.h" - -/* run simulation with given config file */ -// implemented in intern/elbeem/blendercall.cpp -int performElbeemSimulation(char *cfgfilename); - - -#endif diff --git a/intern/elbeem/extern/elbeem.h b/intern/elbeem/extern/elbeem.h deleted file mode 100644 index 073055cf562..00000000000 --- a/intern/elbeem/extern/elbeem.h +++ /dev/null @@ -1,273 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * All code distributed as part of El'Beem is covered by the version 2 of the - * GNU General Public License. See the file COPYING for details. - * Copyright 2003-2006 Nils Thuerey - * - * API header - */ -#ifndef ELBEEM_API_H -#define ELBEEM_API_H - - -// simulation run callback function type (elbeemSimulationSettings->runsimCallback) -// best use with FLUIDSIM_CBxxx defines below. -// >parameters -// return values: 0=continue, 1=stop, 2=abort -// data pointer: user data pointer from elbeemSimulationSettings->runsimUserData -// status integer: 1=running simulation, 2=new frame saved -// frame integer: if status is 1, contains current frame number -typedef int (*elbeemRunSimulationCallback)(void *data, int status, int frame); -#define FLUIDSIM_CBRET_CONTINUE 0 -#define FLUIDSIM_CBRET_STOP 1 -#define FLUIDSIM_CBRET_ABORT 2 -#define FLUIDSIM_CBSTATUS_STEP 1 -#define FLUIDSIM_CBSTATUS_NEWFRAME 2 - - -// global settings for the simulation -typedef struct elbeemSimulationSettings { - /* version number */ - short version; - /* id number of simulation domain, needed if more than a - * single domain should be simulated */ - short domainId; // unused within blender - - /* geometrical extent */ - float geoStart[3], geoSize[3]; - - /* resolutions */ - short resolutionxyz; - short previewresxyz; - /* size of the domain in real units (meters along largest resolution x,y,z extent) */ - float realsize; - - /* fluid properties */ - double viscosity; - /* gravity strength */ - float gravity[3]; - /* anim start end time */ - float animStart, aniFrameTime; - /* no. of frames to simulate & output */ - short noOfFrames; - /* g star param (LBM compressibility) */ - float gstar; - /* activate refinement? */ - short maxRefine; - /* probability for surface particle generation (0.0=off) */ - float generateParticles; - /* amount of tracer particles to generate (0=off) */ - int numTracerParticles; - - /* store output path, and file prefix for baked fluid surface */ - char outputPath[160+80]; - - /* channel for frame time, visc & gravity animations */ - int channelSizeFrameTime; - float *channelFrameTime; - int channelSizeViscosity; - float *channelViscosity; - int channelSizeGravity; - float *channelGravity; // vector - - /* boundary types and settings for domain walls */ - short domainobsType; - float domainobsPartslip; - - /* what surfaces to generate */ - int mFsSurfGenSetting; - - /* generate speed vectors for vertices (e.g. for image based motion blur)*/ - short generateVertexVectors; - /* strength of surface smoothing */ - float surfaceSmoothing; - /* no. of surface subdivisions */ - int surfaceSubdivs; - - /* global transformation to apply to fluidsim mesh */ - float surfaceTrafo[4*4]; - - /* development variables, testing for upcoming releases...*/ - float farFieldSize; - - /* callback function to notify calling program of performed simulation steps - * or newly available frame data, if NULL it is ignored */ - elbeemRunSimulationCallback runsimCallback; - /* pointer passed to runsimCallback for user data storage */ - void* runsimUserData; - /* simulation threads used by omp */ - int threads; - -} elbeemSimulationSettings; - - -// defines for elbeemMesh->type below -/* please keep in sync with DNA_object_fluidsim_types.h */ -#define OB_FLUIDSIM_FLUID 4 -#define OB_FLUIDSIM_OBSTACLE 8 -#define OB_FLUIDSIM_INFLOW 16 -#define OB_FLUIDSIM_OUTFLOW 32 -#define OB_FLUIDSIM_PARTICLE 64 -#define OB_FLUIDSIM_CONTROL 128 - -// defines for elbeemMesh->obstacleType below (low bits) high bits (>=64) are reserved for mFsSurfGenSetting flags which are defined in solver_class.h -#define FLUIDSIM_OBSTACLE_NOSLIP 1 -#define FLUIDSIM_OBSTACLE_PARTSLIP 2 -#define FLUIDSIM_OBSTACLE_FREESLIP 3 -#define FLUIDSIM_FSSG_NOOBS 64 - - -#define OB_VOLUMEINIT_VOLUME 1 -#define OB_VOLUMEINIT_SHELL 2 -#define OB_VOLUMEINIT_BOTH (OB_VOLUMEINIT_SHELL|OB_VOLUMEINIT_VOLUME) - -// a single mesh object -typedef struct elbeemMesh { - /* obstacle,fluid or inflow or control ... */ - short type; - /* id of simulation domain it belongs to */ - short parentDomainId; - - /* vertices */ - int numVertices; - float *vertices; // = float[n][3]; - /* animated vertices */ - int channelSizeVertices; - float *channelVertices; // = float[channelSizeVertices* (n*3+1) ]; - - /* triangles */ - int numTriangles; - int *triangles; // = int[][3]; - - /* animation channels */ - int channelSizeTranslation; - float *channelTranslation; - int channelSizeRotation; - float *channelRotation; - int channelSizeScale; - float *channelScale; - - /* active channel */ - int channelSizeActive; - float *channelActive; - /* initial velocity channel (e.g. for inflow) */ - int channelSizeInitialVel; - float *channelInitialVel; // vector - /* use initial velocity in object coordinates? (e.g. for rotation) */ - short localInivelCoords; - /* boundary types and settings */ - short obstacleType; - float obstaclePartslip; - /* amount of force transfer from fluid to obj, 0=off, 1=normal */ - float obstacleImpactFactor; - /* init volume, shell or both? use OB_VOLUMEINIT_xxx defines above */ - short volumeInitType; - - /* name of the mesh, mostly for debugging */ - const char *name; - - /* fluid control settings */ - float cpsTimeStart; - float cpsTimeEnd; - float cpsQuality; - - int channelSizeAttractforceStrength; - float *channelAttractforceStrength; - int channelSizeAttractforceRadius; - float *channelAttractforceRadius; - int channelSizeVelocityforceStrength; - float *channelVelocityforceStrength; - int channelSizeVelocityforceRadius; - float *channelVelocityforceRadius; -} elbeemMesh; - -// API functions - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - - -// reset elbeemSimulationSettings struct with defaults -void elbeemResetSettings(struct elbeemSimulationSettings*); - -// start fluidsim init (returns !=0 upon failure) -int elbeemInit(void); - -// frees fluidsim -int elbeemFree(void); - -// start fluidsim init (returns !=0 upon failure) -int elbeemAddDomain(struct elbeemSimulationSettings*); - -// get failure message during simulation or init -// if an error occured (the string is copied into buffer, -// max. length = 256 chars ) -void elbeemGetErrorString(char *buffer); - -// reset elbeemMesh struct with zeroes -void elbeemResetMesh(struct elbeemMesh*); - -// add mesh as fluidsim object -int elbeemAddMesh(struct elbeemMesh*); - -// do the actual simulation -int elbeemSimulate(void); - -// continue a previously stopped simulation -int elbeemContinueSimulation(void); - - -// helper functions - -// simplify animation channels -// returns if the channel and its size changed -int elbeemSimplifyChannelFloat(float *channel, int *size); -int elbeemSimplifyChannelVec3(float *channel, int *size); - -// helper functions implemented in utilities.cpp - -/* set elbeem debug output level (0=off to 10=full on) */ -void elbeemSetDebugLevel(int level); -/* elbeem debug output function, prints if debug level >0 */ -void elbeemDebugOut(char *msg); - -/* estimate how much memory a given setup will require */ -double elbeemEstimateMemreq(int res, - float sx, float sy, float sz, - int refine, char *retstr); - - - -#ifdef __cplusplus -} -#endif // __cplusplus - - - -/******************************************************************************/ -// internal defines, do not use for initializing elbeemMesh -// structs, for these use OB_xxx defines above - -/*! fluid geometry init types */ -// type "int" used, so max is 8 -#define FGI_FLAGSTART 16 -#define FGI_FLUID (1<<(FGI_FLAGSTART+ 0)) -#define FGI_NO_FLUID (1<<(FGI_FLAGSTART+ 1)) -#define FGI_BNDNO (1<<(FGI_FLAGSTART+ 2)) -#define FGI_BNDFREE (1<<(FGI_FLAGSTART+ 3)) -#define FGI_BNDPART (1<<(FGI_FLAGSTART+ 4)) -#define FGI_NO_BND (1<<(FGI_FLAGSTART+ 5)) -#define FGI_MBNDINFLOW (1<<(FGI_FLAGSTART+ 6)) -#define FGI_MBNDOUTFLOW (1<<(FGI_FLAGSTART+ 7)) -#define FGI_CONTROL (1<<(FGI_FLAGSTART+ 8)) - -// all boundary types at once -#define FGI_ALLBOUNDS ( FGI_BNDNO | FGI_BNDFREE | FGI_BNDPART | FGI_MBNDINFLOW | FGI_MBNDOUTFLOW ) - - -#endif // ELBEEM_API_H diff --git a/intern/elbeem/intern/attributes.cpp b/intern/elbeem/intern/attributes.cpp deleted file mode 100644 index beebc459c1a..00000000000 --- a/intern/elbeem/intern/attributes.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * DEPRECATED - replaced by elbeem API, only channels are still used - * - *****************************************************************************/ - -#include "attributes.h" -#include "ntl_matrices.h" -#include "elbeem.h" - - - -/****************************************************************************** - * attribute conversion functions - *****************************************************************************/ - -bool Attribute::initChannel(int elemSize) { - elemSize=0; // remove warning - return false; -} -string Attribute::getAsString(bool debug) { - debug=false; // remove warning - return string(""); -} -int Attribute::getAsInt() { - return 0; -} -bool Attribute::getAsBool() { - return false; -} -double Attribute::getAsFloat() { - return 0.; -} -ntlVec3d Attribute::getAsVec3d() { - return ntlVec3d(0.); -} -void Attribute::getAsMat4Gfx(ntlMat4Gfx *mat) { - mat=NULL; // remove warning -} -string Attribute::getCompleteString() { - return string(""); -} - - -/****************************************************************************** - * channel returns - *****************************************************************************/ - -AnimChannel Attribute::getChannelFloat() { - return AnimChannel(); -} -AnimChannel Attribute::getChannelInt() { - return AnimChannel(); -} -AnimChannel Attribute::getChannelVec3d() { - return AnimChannel(); -} -AnimChannel -Attribute::getChannelSetVec3f() { - return AnimChannel(); -} - -/****************************************************************************** - * check if there were unknown params - *****************************************************************************/ -bool AttributeList::checkUnusedParams() { - return false; -} -void AttributeList::setAllUsed() { -} - -/****************************************************************************** - * Attribute list read functions - *****************************************************************************/ -int AttributeList::readInt(string name, int defaultValue, string source,string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return defaultValue; -} -bool AttributeList::readBool(string name, bool defaultValue, string source,string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return defaultValue; -} -double AttributeList::readFloat(string name, double defaultValue, string source,string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return defaultValue; -} -string AttributeList::readString(string name, string defaultValue, string source,string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return defaultValue; -} -ntlVec3d AttributeList::readVec3d(string name, ntlVec3d defaultValue, string source,string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return defaultValue; -} - -void AttributeList::readMat4Gfx(string name, ntlMat4Gfx defaultValue, string source,string target, bool needed, ntlMat4Gfx *mat) { - *mat = defaultValue; - name=source=target=string(""); needed=false; mat=NULL; // remove warning -} - -// set that a parameter can be given, and will be ignored... -bool AttributeList::ignoreParameter(string name, string source) { - name = source = (""); - return false; -} - -// read channels -AnimChannel AttributeList::readChannelInt(string name, int defaultValue, string source, string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return AnimChannel(defaultValue); -} -AnimChannel AttributeList::readChannelFloat(string name, double defaultValue, string source, string target, bool needed ) { - name=source=target=string(""); needed=false; // remove warning - return AnimChannel(defaultValue); -} -AnimChannel AttributeList::readChannelVec3d(string name, ntlVec3d defaultValue, string source, string target, bool needed ) { - name=source=target=string(""); needed=false; // remove warning - return AnimChannel(defaultValue); -} -AnimChannel AttributeList::readChannelSetVec3f(string name, ntlSetVec3f defaultValue, string source, string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return AnimChannel(defaultValue); -} -AnimChannel AttributeList::readChannelSinglePrecFloat(string name, float defaultValue, string source, string target, bool needed ) { - name=source=target=string(""); needed=false; // remove warning - return AnimChannel(defaultValue); -} -AnimChannel AttributeList::readChannelVec3f(string name, ntlVec3f defaultValue, string source, string target, bool needed) { - name=source=target=string(""); needed=false; // remove warning - return AnimChannel(defaultValue); -} - -/****************************************************************************** - * destructor - *****************************************************************************/ -AttributeList::~AttributeList() { -}; - - -/****************************************************************************** - * debugging - *****************************************************************************/ - -//! debug function, prints value -void Attribute::print() { -} - -//! debug function, prints all attribs -void AttributeList::print() { -} - - -/****************************************************************************** - * import attributes from other attribute list - *****************************************************************************/ -void AttributeList::import(AttributeList *oal) { - oal=NULL; // remove warning -} - - -/****************************************************************************** - * channel max finding - *****************************************************************************/ -ntlVec3f channelFindMaxVf (AnimChannel channel) { - ntlVec3f ret(0.0); - float maxLen = 0.0; - for(size_t i=0; imaxLen) { ret=channel.accessValues()[i]; maxLen=nlen; } - } - return ret; -} -ntlVec3d channelFindMaxVd (AnimChannel channel) { - ntlVec3d ret(0.0); - float maxLen = 0.0; - for(size_t i=0; imaxLen) { ret=channel.accessValues()[i]; maxLen=nlen; } - } - return ret; -} -int channelFindMaxi (AnimChannel channel) { - int ret = 0; - float maxLen = 0.0; - for(size_t i=0; imaxLen) { ret= (int)channel.accessValues()[i]; maxLen=nlen; } - } - return ret; -} -float channelFindMaxf (AnimChannel channel) { - float ret = 0.0; - float maxLen = 0.0; - for(size_t i=0; imaxLen) { ret=channel.accessValues()[i]; maxLen=nlen; } - } - return ret; -} -double channelFindMaxd (AnimChannel channel) { - double ret = 0.0; - float maxLen = 0.0; - for(size_t i=0; imaxLen) { ret=channel.accessValues()[i]; maxLen=nlen; } - } - return ret; -} - -/****************************************************************************** - // unoptimized channel simplification functions, use elbeem.cpp functions - // warning - currently only with single precision - *****************************************************************************/ - -template -static bool channelSimplifyScalarT(AnimChannel &channel) { - int size = channel.getSize(); - if(size<=1) return false; - float *nchannel = new float[2*size]; - // convert to array - for(size_t i=0; i vals; - vector times; - for(int i=0; i(vals, times); - } - delete [] nchannel; - return ret; -} -bool channelSimplifyi (AnimChannel &channel) { return channelSimplifyScalarT(channel); } -bool channelSimplifyf (AnimChannel &channel) { return channelSimplifyScalarT(channel); } -bool channelSimplifyd (AnimChannel &channel) { return channelSimplifyScalarT(channel); } -template -static bool channelSimplifyVecT(AnimChannel &channel) { - int size = channel.getSize(); - if(size<=1) return false; - float *nchannel = new float[4*size]; - // convert to array - for(size_t i=0; i vals; - vector times; - for(int i=0; i(vals, times); - } - delete [] nchannel; - return ret; -} -bool channelSimplifyVf (AnimChannel &channel) { - return channelSimplifyVecT(channel); -} -bool channelSimplifyVd (AnimChannel &channel) { - return channelSimplifyVecT(channel); -} - -//! debug function, prints channel as string -template -string AnimChannel::printChannel() { - std::ostringstream ostr; - ostr << " CHANNEL #"<< mValue.size() <<" = { "; - for(size_t i=0;i tmp1; - AnimChannel< double > tmp2; - AnimChannel< string > tmp3; - AnimChannel< ntlVector3Dim > tmp4; - AnimChannel< ntlVector3Dim > tmp5; - tmp1.debugPrintChannel(); - tmp2.debugPrintChannel(); - tmp3.debugPrintChannel(); - tmp4.debugPrintChannel(); - tmp5.debugPrintChannel(); -} - - -ntlSetVec3f::ntlSetVec3f(double v ) { - mVerts.clear(); - mVerts.push_back( ntlVec3f(v) ); -} -const ntlSetVec3f& -ntlSetVec3f::operator=(double v ) { - mVerts.clear(); - mVerts.push_back( ntlVec3f(v) ); - return *this; -} - -std::ostream& operator<<( std::ostream& os, const ntlSetVec3f& vs ) { - os<< "{"; - for(int j=0;j<(int)vs.mVerts.size();j++) os< class ntlMatrix4x4; -class ntlSetVec3f; -std::ostream& operator<<( std::ostream& os, const ntlSetVec3f& i ); - - - -//! An animated attribute channel -template -class AnimChannel -{ - public: - // default constructor - AnimChannel() : - mValue(), mTimes() { mInited = false; debugPrintChannel(); } - - // null init constructor - AnimChannel(Scalar null) : - mValue(1), mTimes(1) { mValue[0]=null; mTimes[0]=0.0; mInited = true; debugPrintChannel(); } - - // proper init - AnimChannel(vector &v, vector &t) : - mValue(v), mTimes(t) { mInited = true; debugPrintChannel(); } - - // desctructor, nothing to do - ~AnimChannel() { }; - - // get interpolated value at time t - Scalar get(double t) const { - if(!mInited) { Scalar null; null=(Scalar)(0.0); return null; } - if(t<=mTimes[0]) { return mValue[0]; } - if(t>=mTimes[mTimes.size()-1]) { return mValue[mTimes.size()-1]; } - for(size_t i=0; it)) { - // interpolate - double d = mTimes[i+1]-mTimes[i]; - double f = (t-mTimes[i])/d; - //return (Scalar)(mValue[i] * (1.0-f) + mValue[i+1] * f); - Scalar ret,tmp; - ret = mValue[i]; - ret *= 1.-f; - tmp = mValue[i+1]; - tmp *= f; - ret += tmp; - return ret; - } - } - // whats this...? - return mValue[0]; - }; - - // get uninterpolated value at time t - Scalar getConstant(double t) const { - //errMsg("DEBB","getc"<=mTimes[mTimes.size()-1]) { return mValue[mTimes.size()-1]; } - for(size_t i=0; it)) { return mValue[i]; } - } - // whats this...? - return mValue[0]; - }; - - // reset to null value - void reset(Scalar null) { - mValue.clear(); - mTimes.clear(); - mValue.push_back(null); - mTimes.push_back(0.0); - } - - //! debug function, prints channel as string - string printChannel(); - //! debug function, prints to stdout if DEBUG_CHANNELS flag is enabled, used in constructors - void debugPrintChannel(); - //! valid init? - bool isInited() const { return mInited; } - - //! get number of entries (value and time sizes have to be equal) - int getSize() const { return mValue.size(); }; - //! raw access of value vector - vector &accessValues() { return mValue; } - //! raw access of time vector - vector &accessTimes() { return mTimes; } - - protected: - - /*! inited at least once? */ - bool mInited; - /*! anim channel attribute values */ - vector mValue; - /*! anim channel attr times */ - vector mTimes; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:AnimChannel") -#endif -}; - - -// helper class (not templated) for animated meshes -class ntlSetVec3f { - public: - ntlSetVec3f(): mVerts() {}; - ntlSetVec3f(double v); - ntlSetVec3f(vector &v) { mVerts = v; }; - - const ntlSetVec3f& operator=(double v ); - ntlSetVec3f& operator+=( double v ); - ntlSetVec3f& operator+=( const ntlSetVec3f &v ); - ntlSetVec3f& operator*=( double v ); - ntlSetVec3f& operator*=( const ntlSetVec3f &v ); - - vector mVerts; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlSetVec3f") -#endif -}; - - -// warning: DEPRECATED - replaced by elbeem API -class Attribute -{ - public: - Attribute(string mn, vector &value, int setline,bool channel) { - mn = string(""); setline=0; channel=false; value.clear(); // remove warnings - }; - Attribute(Attribute &a) { a.getCompleteString(); }; - ~Attribute() { }; - - void setUsed(bool set){ set=false; } - bool getUsed() { return true; } - void setIsChannel(bool set){ set=false; } - bool getIsChannel() { return false; } - - string getAsString(bool debug=false); - int getAsInt(); - bool getAsBool(); - double getAsFloat(); - ntlVec3d getAsVec3d(); - void getAsMat4Gfx(ntlMatrix4x4 *mat); - - AnimChannel getChannelInt(); - AnimChannel getChannelFloat(); - AnimChannel getChannelVec3d(); - AnimChannel getChannelSetVec3f(); - - string getCompleteString(); - void print(); - - protected: - - bool initChannel(int elemSize); - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:Attribute") -#endif -}; - - -// warning: DEPRECATED - replaced by elbeem API -//! The list of configuration attributes -class AttributeList -{ - public: - AttributeList(string name) { name=string(""); }; - ~AttributeList(); - void addAttr(string name, vector &value, int line, bool isChannel) { - name=string(""); value.clear(); line=0; isChannel=false; // remove warnings - }; - bool exists(string name) { name=string(""); return false; } - void setAllUsed(); - bool checkUnusedParams(); - void import(AttributeList *oal); - int readInt(string name, int defaultValue, string source,string target, bool needed); - bool readBool(string name, bool defaultValue, string source,string target, bool needed); - double readFloat(string name, double defaultValue, string source,string target, bool needed); - string readString(string name, string defaultValue, string source,string target, bool needed); - ntlVec3d readVec3d(string name, ntlVec3d defaultValue, string source,string target, bool needed); - void readMat4Gfx(string name, ntlMatrix4x4 defaultValue, string source,string target, bool needed, ntlMatrix4x4 *mat); - AnimChannel readChannelInt( string name, int defaultValue=0, string source=string("src"), string target=string("dst"), bool needed=false ); - AnimChannel readChannelFloat( string name, double defaultValue=0, string source=string("src"), string target=string("dst"), bool needed=false ); - AnimChannel readChannelVec3d( string name, ntlVec3d defaultValue=ntlVec3d(0.), string source=string("src"), string target=string("dst"), bool needed=false ); - AnimChannel readChannelSetVec3f(string name, ntlSetVec3f defaultValue=ntlSetVec3f(0.), string source=string("src"), string target=string("dst"), bool needed=false ); - AnimChannel readChannelVec3f( string name, ntlVec3f defaultValue=ntlVec3f(0.), string source=string("src"), string target=string("dst"), bool needed=false ); - AnimChannel readChannelSinglePrecFloat( string name, float defaultValue=0., string source=string("src"), string target=string("dst"), bool needed=false ); - bool ignoreParameter(string name, string source); - void print(); - protected: - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:AttributeList") -#endif -}; - -ntlVec3f channelFindMaxVf (AnimChannel channel); -ntlVec3d channelFindMaxVd (AnimChannel channel); -int channelFindMaxi (AnimChannel channel); -float channelFindMaxf (AnimChannel channel); -double channelFindMaxd (AnimChannel channel); - -// unoptimized channel simplification functions, use elbeem.cpp functions -bool channelSimplifyVf (AnimChannel &channel); -bool channelSimplifyVd (AnimChannel &channel); -bool channelSimplifyi (AnimChannel &channel); -bool channelSimplifyf (AnimChannel &channel); -bool channelSimplifyd (AnimChannel &channel); - -//! output channel values? on=1/off=0 -#define DEBUG_PCHANNELS 0 - -//! debug function, prints to stdout if DEBUG_PCHANNELS flag is enabled, used in constructors -template -void AnimChannel::debugPrintChannel() { } - - -#define NTL_ATTRIBUTES_H -#endif - diff --git a/intern/elbeem/intern/controlparticles.cpp b/intern/elbeem/intern/controlparticles.cpp deleted file mode 100644 index efecb354890..00000000000 --- a/intern/elbeem/intern/controlparticles.cpp +++ /dev/null @@ -1,1465 +0,0 @@ -/** \file - * \ingroup elbeem - */ -// -------------------------------------------------------------------------- -// -// El'Beem - the visual lattice boltzmann freesurface simulator -// All code distributed as part of El'Beem is covered by the version 2 of the -// GNU General Public License. See the file COPYING for details. -// -// Copyright 2008 Nils Thuerey , Richard Keiser, Mark Pauly, Ulrich Ruede -// -// implementation of control particle handling -// -// -------------------------------------------------------------------------- - -// indicator for LBM inclusion -#include "ntl_geometrymodel.h" -#include "ntl_world.h" -#include "solver_class.h" -#include "controlparticles.h" -#include "mvmcoords.h" -#include - -#ifndef sqrtf -#define sqrtf sqrt -#endif - -// brute force circle test init in initTimeArray -// replaced by mDebugInit -//#define CP_FORCECIRCLEINIT 0 - - -void ControlParticles::initBlenderTest() { - mPartSets.clear(); - - ControlParticleSet cps; - mPartSets.push_back(cps); - int setCnt = mPartSets.size()-1; - ControlParticle p; - - // set for time zero - mPartSets[setCnt].time = 0.; - - // add single particle - p.reset(); - p.pos = LbmVec(0.5, 0.5, -0.5); - mPartSets[setCnt].particles.push_back(p); - - // add second set for animation - mPartSets.push_back(cps); - setCnt = mPartSets.size()-1; - mPartSets[setCnt].time = 0.15; - - // insert new position - p.reset(); - p.pos = LbmVec(-0.5, -0.5, 0.5); - mPartSets[setCnt].particles.push_back(p); - - // applyTrafos(); - initTime(0. , 1.); -} - -// blender control object gets converted to mvm flui control object -int ControlParticles::initFromObject(ntlGeometryObjModel *model) { - vector triangles; - vector vertices; - vector normals; - - /* - model->loadBobjModel(string(infile)); - - model->setLoaded(true); - - model->setGeoInitId(gid); - - - printf("a animated? %d\n", model->getIsAnimated()); - printf("b animated? %d\n", model->getMeshAnimated()); - */ - - model->setGeoInitType(FGI_FLUID); - - model->getTriangles(mCPSTimeStart, &triangles, &vertices, &normals, 1 ); - // model->applyTransformation(mCPSTimeStart, &vertices, &normals, 0, vertices.size(), true); - - // valid mesh? - if(triangles.size() <= 0) { - return 0; - } - - ntlRenderGlobals *glob = new ntlRenderGlobals; - ntlScene *genscene = new ntlScene( glob, false ); - genscene->addGeoClass(model); - genscene->addGeoObject(model); - genscene->buildScene(0., false); - char treeFlag = (1<<(4+model->getGeoInitId())); - - ntlTree *tree = new ntlTree( - 15, 8, // TREEwarning - fixed values for depth & maxtriangles here... - genscene, treeFlag ); - - // TODO? use params - ntlVec3Gfx start,end; - model->getExtends(start,end); - /* - printf("start - x: %f, y: %f, z: %f\n", start[0], start[1], start[2]); - printf("end - x: %f, y: %f, z: %f\n", end[0], end[1], end[2]); - printf("mCPSWidth: %f\n"); -*/ - LbmFloat width = mCPSWidth; - if(width<=LBM_EPSILON) { errMsg("ControlParticles::initFromMVMCMesh","Invalid mCPSWidth! "< inspos; - - // printf("distance: %f, width: %f\n", distance, width); - - while(org[2] ninspos; - mvm.transfer(vertices, ninspos); - - // init first set, check dist - ControlParticleSet firstcps; //T - mPartSets.push_back(firstcps); - mPartSets[mPartSets.size()-1].time = mCPSTimeStart; - vector useCP; - - for(int i=0; i<(int)inspos.size(); i++) { - ControlParticle p; p.reset(); - p.pos = vec2L(inspos[i]); - - bool usecpv = true; - - mPartSets[mPartSets.size()-1].particles.push_back(p); - useCP.push_back(usecpv); - } - - // init further sets, temporal mesh sampling - double tsampling = mCPSTimestep; - // printf("tsampling: %f, ninspos.size(): %d, mCPSTimeEnd: %f\n", tsampling, ninspos.size(), mCPSTimeEnd); - - int tcnt=0; - for(double t=mCPSTimeStart+tsampling; ((t0.)); t+=tsampling) { - ControlParticleSet nextcps; //T - mPartSets.push_back(nextcps); - mPartSets[mPartSets.size()-1].time = (gfxReal)t; - - vertices.clear(); triangles.clear(); normals.clear(); - model->getTriangles(t, &triangles, &vertices, &normals, 1 ); - mvm.transfer(vertices, ninspos); - - tcnt++; - for(size_t i=0; i < ninspos.size(); i++) { - - if(useCP[i]) { - ControlParticle p; p.reset(); - p.pos = vec2L(ninspos[i]); - mPartSets[mPartSets.size()-1].particles.push_back(p); - } - } - } - - model->setGeoInitType(FGI_CONTROL); - - delete tree; - delete genscene; - delete glob; - - // do reverse here - if(model->getGeoPartSlipValue()) - { - mirrorTime(); - } - - return 1; -} - - -// init all zero / defaults for a single particle -void ControlParticle::reset() { - pos = LbmVec(0.,0.,0.); - vel = LbmVec(0.,0.,0.); - influence = 1.; - size = 1.; -#ifndef LBMDIM -#ifdef MAIN_2D - rotaxis = LbmVec(0.,1.,0.); // SPH xz -#else // MAIN_2D - // 3d - roate in xy plane, vortex - rotaxis = LbmVec(0.,0.,1.); - // 3d - rotate for wave - //rotaxis = LbmVec(0.,1.,0.); -#endif // MAIN_2D -#else // LBMDIM - rotaxis = LbmVec(0.,1.,0.); // LBM xy , is swapped afterwards -#endif // LBMDIM - - density = 0.; - densityWeight = 0.; - avgVelAcc = avgVel = LbmVec(0.); - avgVelWeight = 0.; -} - - -// default preset/empty init -ControlParticles::ControlParticles() : - _influenceTangential(0.f), - _influenceAttraction(0.f), - _influenceVelocity(0.f), - _influenceMaxdist(0.f), - _radiusAtt(1.0f), - _radiusVel(1.0f), - _radiusMinMaxd(2.0f), - _radiusMaxd(3.0f), - _currTime(-1.0), _currTimestep(1.), - _initTimeScale(1.), - _initPartOffset(0.), _initPartScale(1.), - _initLastPartOffset(0.), _initLastPartScale(1.), - _initMirror(""), - _fluidSpacing(1.), _kernelWeight(-1.), - _charLength(1.), _charLengthInv(1.), - mvCPSStart(-10000.), mvCPSEnd(10000.), - mCPSWidth(0.1), mCPSTimestep(0.02), // was 0.05 - mCPSTimeStart(0.), mCPSTimeEnd(0.5), mCPSWeightFac(1.), - mDebugInit(0) -{ - _radiusAtt = 0.15f; - _radiusVel = 0.15f; - _radiusMinMaxd = 0.16f; - _radiusMaxd = 0.3; - - _influenceAttraction = 0.f; - _influenceTangential = 0.f; - _influenceVelocity = 0.f; - // 3d tests */ -} - - - -ControlParticles::~ControlParticles() { - // nothing to do... -} - -LbmFloat ControlParticles::getControlTimStart() { - if(mPartSets.size()>0) { return mPartSets[0].time; } - return -1000.; -} -LbmFloat ControlParticles::getControlTimEnd() { - if(mPartSets.size()>0) { return mPartSets[mPartSets.size()-1].time; } - return -1000.; -} - -// calculate for delta t -void ControlParticles::setInfluenceVelocity(LbmFloat set, LbmFloat dt) { - const LbmFloat dtInter = 0.01; - LbmFloat facFv = 1.-set; //cparts->getInfluenceVelocity(); - // mLevel[mMaxRefine].timestep - LbmFloat facNv = (LbmFloat)( 1.-pow( (double)facFv, (double)(dt/dtInter)) ); - //errMsg("vwcalc","ts:"<1) && (line[0]=='/' && line[1]=='/')) continue; - - // debug remove newline - if((len>=1)&&(line[len-1]=='\n')) line[len-1]='\0'; - - switch(line[0]) { - - case 'N': { // total number of particles, more for debugging... - noParts = atoi(line+2); - if(noParts<=0) { - errMsg("ControlParticles::initFromTextFile","file '"<=noParts) { - if(debugRead) printf("CPDEBUG%d partset done \n",lineCnt); - haveTime = false; - } else { - ControlParticle p; p.reset(); - mPartSets[setCnt].particles.push_back(p); - } - } - // only new part, or new with pos? - if(line[0] == 'n') break; - - // particle properties - - case 'p': { // new particle set at time T - if((!haveTime)||(setCnt<0)||(mPartSets[setCnt].particles.size()<1)) { fprintf(stdout,"ControlParticles::initFromTextFile - line %d ,error|p: particle missing!\n",lineCnt); abortParse=true; break; } - float px=0.,py=0.,pz=0.; - if( sscanf(line+2,"%f %f %f",&px,&py,&pz) != 3) { - fprintf(stdout,"CPDEBUG%d, unable to parse position!\n",lineCnt); abortParse=true; break; - } - if(!(finite(px)&&finite(py)&&finite(pz))) { px=py=pz=0.; } - LASTCP.pos[0] = px; - LASTCP.pos[1] = py; - LASTCP.pos[2] = pz; - if(debugRead) printf("CPDEBUG%d part%d,%d: position %f,%f,%f \n",lineCnt,setCnt,partCnt, px,py,pz); - } break; - - case 's': { // particle size - if((!haveTime)||(setCnt<0)||(mPartSets[setCnt].particles.size()<1)) { fprintf(stdout,"ControlParticles::initFromTextFile - line %d ,error|s: particle missing!\n",lineCnt); abortParse=true; break; } - float ps=1.; - if( sscanf(line+2,"%f",&ps) != 1) { - fprintf(stdout,"CPDEBUG%d, unable to parse size!\n",lineCnt); abortParse=true; break; - } - if(!(finite(ps))) { ps=0.; } - LASTCP.size = ps; - if(debugRead) printf("CPDEBUG%d part%d,%d: size %f \n",lineCnt,setCnt,partCnt, ps); - } break; - - case 'i': { // particle influence - if((!haveTime)||(setCnt<0)||(mPartSets[setCnt].particles.size()<1)) { fprintf(stdout,"ControlParticles::initFromTextFile - line %d ,error|i: particle missing!\n",lineCnt); abortParse=true; break; } - float pinf=1.; - if( sscanf(line+2,"%f",&pinf) != 1) { - fprintf(stdout,"CPDEBUG%d, unable to parse size!\n",lineCnt); abortParse=true; break; - } - if(!(finite(pinf))) { pinf=0.; } - LASTCP.influence = pinf; - if(debugRead) printf("CPDEBUG%d part%d,%d: influence %f \n",lineCnt,setCnt,partCnt, pinf); - } break; - - case 'a': { // rotation axis - if((!haveTime)||(setCnt<0)||(mPartSets[setCnt].particles.size()<1)) { fprintf(stdout,"ControlParticles::initFromTextFile - line %d ,error|a: particle missing!\n",lineCnt); abortParse=true; break; } - float px=0.,py=0.,pz=0.; - if( sscanf(line+2,"%f %f %f",&px,&py,&pz) != 3) { - fprintf(stdout,"CPDEBUG%d, unable to parse rotaxis!\n",lineCnt); abortParse=true; break; - } - if(!(finite(px)&&finite(py)&&finite(pz))) { px=py=pz=0.; } - LASTCP.rotaxis[0] = px; - LASTCP.rotaxis[1] = py; - LASTCP.rotaxis[2] = pz; - if(debugRead) printf("CPDEBUG%d part%d,%d: rotaxis %f,%f,%f \n",lineCnt,setCnt,partCnt, px,py,pz); - } break; - - - default: - if(debugRead) printf("CPDEBUG%d ignored: '%s'\n",lineCnt, line ); - break; - } - } - if(debugRead && abortParse) printf("CPDEBUG aborted parsing after set... %d\n",(int)mPartSets.size() ); - - // sanity check - for(int i=0; i<(int)mPartSets.size(); i++) { - if( (int)mPartSets[i].particles.size()!=noParts) { - fprintf(stdout,"ControlParticles::initFromTextFile (%s) - invalid no of particles in set %d, is:%d, shouldbe:%d \n",filename.c_str() ,i,(int)mPartSets[i].particles.size(), noParts); - mPartSets.clear(); - fclose(infile); - return 0; - } - } - - // print stats - printf("ControlParticles::initFromTextFile (%s): Read %d sets, each %d particles\n",filename.c_str() , - (int)mPartSets.size(), noParts ); - if(mPartSets.size()>0) { - printf("ControlParticles::initFromTextFile (%s): Time: %f,%f\n",filename.c_str() ,mPartSets[0].time, mPartSets[mPartSets.size()-1].time ); - } - - // done... - fclose(infile); - applyTrafos(); - */ - return 1; -} - - -int ControlParticles::initFromTextFileOld(string filename) -{ - /* - const bool debugRead = false; - char line[LINE_LEN]; - line[LINE_LEN-1] = '\0'; - mPartSets.clear(); - if(filename.size()<1) return 0; - - FILE *infile = fopen(filename.c_str(), "r"); - if(!infile) { - fprintf(stdout,"ControlParticles::initFromTextFileOld - unable to open '%s'\n",filename.c_str() ); - return 0; - } - - int haveNo = false; - int haveScale = false; - int haveTime = false; - int noParts = -1; - int coordCnt = 0; - int partCnt = 0; - int setCnt = 0; - ControlParticle p; p.reset(); - // scale times by constant factor while reading - LbmFloat timeScale= 1.0; - int lineCnt = 0; - - while(!feof(infile)) { - lineCnt++; - fgets(line, LINE_LEN, infile); - - if(debugRead) printf("\nDEBUG%d r '%s'\n",lineCnt, line); - - if(!line) continue; - size_t len = strlen(line); - - // skip empty lines and comments (#,//) - if(len<1) continue; - if( (line[0]=='#') || (line[0]=='\n') ) continue; - if((len>1) && (line[0]=='/' && line[1]=='/')) continue; - - // debug remove newline - if((len>=1)&&(line[len-1]=='\n')) line[len-1]='\0'; - - // first read no. of particles - if(!haveNo) { - noParts = atoi(line); - if(noParts<=0) { - fprintf(stdout,"ControlParticles::initFromTextFileOld - invalid no of particles %d\n",noParts); - mPartSets.clear(); - fclose(infile); - return 0; - } - if(debugRead) printf("DEBUG%d noparts '%d'\n",lineCnt, noParts ); - haveNo = true; - } - - // then read time scale - else if(!haveScale) { - timeScale *= (LbmFloat)atof(line); - if(debugRead) printf("DEBUG%d tsc '%f', org %f\n",lineCnt, timeScale , _initTimeScale); - haveScale = true; - } - - // then get set time - else if(!haveTime) { - ControlParticleSet cps; - mPartSets.push_back(cps); - setCnt = (int)mPartSets.size()-1; - - LbmFloat val = (LbmFloat)atof(line); - mPartSets[setCnt].time = val * timeScale; - if(debugRead) printf("DEBUG%d time '%f', %d\n",lineCnt, mPartSets[setCnt].time, setCnt ); - haveTime = true; - } - - // default read all parts - else { - LbmFloat val = (LbmFloat)atof(line); - if(debugRead) printf("DEBUG: l%d s%d,particle%d '%f' %d,%d/%d\n",lineCnt,(int)mPartSets.size(),(int)mPartSets[setCnt].particles.size(), val ,coordCnt,partCnt,noParts); - p.pos[coordCnt] = val; - coordCnt++; - if(coordCnt>=3) { - mPartSets[setCnt].particles.push_back(p); - p.reset(); - coordCnt=0; - partCnt++; - } - if(partCnt>=noParts) { - partCnt = 0; - haveTime = false; - } - //if(debugRead) printf("DEBUG%d par2 %d,%d/%d\n",lineCnt, coordCnt,partCnt,noParts); - } - //read pos, vel ... - } - - // sanity check - for(int i=0; i<(int)mPartSets.size(); i++) { - if( (int)mPartSets[i].particles.size()!=noParts) { - fprintf(stdout,"ControlParticles::initFromTextFileOld - invalid no of particles in set %d, is:%d, shouldbe:%d \n",i,(int)mPartSets[i].particles.size(), noParts); - mPartSets.clear(); - fclose(infile); - return 0; - } - } - // print stats - printf("ControlParticles::initFromTextFileOld: Read %d sets, each %d particles\n", - (int)mPartSets.size(), noParts ); - if(mPartSets.size()>0) { - printf("ControlParticles::initFromTextFileOld: Time: %f,%f\n",mPartSets[0].time, mPartSets[mPartSets.size()-1].time ); - } - - // done... - fclose(infile); - applyTrafos(); - */ - return 1; -} - -// load positions & timing from gzipped binary file -int ControlParticles::initFromBinaryFile(string filename) { - mPartSets.clear(); - if(filename.size()<1) return 0; - int fileNotFound=0; - int fileFound=0; - char ofile[256]; - - for(int set=0; ((set<10000)&&(fileNotFound<10)); set++) { - snprintf(ofile,256,"%s%04d.gz",filename.c_str(),set); - //errMsg("ControlParticle::initFromBinaryFile","set"<intersectX(ray,distance,normal, triIns, flags, true); - if(triIns) { - ntlVec3Gfx norg = ray.getOrigin() + ray.getDirection()*distance; - LbmFloat orientation = dot(normal, dir); - OId = triIns->getObjectId(); - if(orientation<=0.0) { - // outside hit - normal *= -1.0; - mGiObjInside++; - if(giObjFirstHistSide==0) giObjFirstHistSide = 1; - if(globGeoInitDebug) errMsg("IIO"," oid:"<0) { - bool mess = false; - if((mGiObjInside%2)==1) { - if(giObjFirstHistSide != -1) mess=true; - } else { - if(giObjFirstHistSide != 1) mess=true; - } - if(mess) { - // ? - //errMsg("IIIproblem","At "<0.0)) { - if( (distance<0.0) || // first intersection -> good - ((distance>0.0)&&(distance>mGiObjDistance)) // more than one intersection -> use closest one - ) { - distance = mGiObjDistance; - OId = 0; - inside = true; - } - } - - if(!inside) { - distance = firstHit; - OId = firstOId; - } - if(globGeoInitDebug) errMsg("CHIII","ins"< triangles; - vector vertices; - vector normals; - snprintf(infile,256,"%s.bobj.gz", filename.c_str() ); - model->loadBobjModel(string(infile)); - model->setLoaded(true); - model->setGeoInitId(gid); - model->setGeoInitType(FGI_FLUID); - debMsgStd("ControlParticles::initFromMVMCMesh",DM_MSG,"infile:"< *triangles, vector *vertices, vector *normals, int objectId ); - model->getTriangles(mCPSTimeStart, &triangles, &vertices, &normals, 1 ); - debMsgStd("ControlParticles::initFromMVMCMesh",DM_MSG," tris:"<addGeoClass(model); - genscene->addGeoObject(model); - genscene->buildScene(0., false); - char treeFlag = (1<<(4+gid)); - - ntlTree *tree = new ntlTree( - 15, 8, // TREEwarning - fixed values for depth & maxtriangles here... - genscene, treeFlag ); - - // TODO? use params - ntlVec3Gfx start,end; - model->getExtends(start,end); - - LbmFloat width = mCPSWidth; - if(width<=LBM_EPSILON) { errMsg("ControlParticles::initFromMVMCMesh","Invalid mCPSWidth! "< inspos; - int approxmax = (int)( ((end[0]-start[0])/width)*((end[1]-start[1])/width)*((end[2]-start[2])/width) ); - - debMsgStd("ControlParticles::initFromMVMCMesh",DM_MSG,"start"< ninspos; - mvm.transfer(vertices, ninspos); - - // init first set, check dist - ControlParticleSet firstcps; //T - mPartSets.push_back(firstcps); - mPartSets[mPartSets.size()-1].time = (gfxReal)0.; - vector useCP; - bool debugPos=false; - - for(int i=0; i<(int)inspos.size(); i++) { - ControlParticle p; p.reset(); - p.pos = vec2L(inspos[i]); - //errMsg("COMP "," "<0.)); t+=tsampling) { - ControlParticleSet nextcps; //T - mPartSets.push_back(nextcps); - mPartSets[mPartSets.size()-1].time = (gfxReal)t; - - vertices.clear(); triangles.clear(); normals.clear(); - model->getTriangles(t, &triangles, &vertices, &normals, 1 ); - mvm.transfer(vertices, ninspos); - if(tcnt%(totcnt/10)==1) debMsgStd("MeanValueMeshCoords::calculateMVMCs",DM_MSG,"Transferring animation, frame: "< swap Y and Z components everywhere -void ControlParticles::swapCoords(int a, int b) { - //return; - for(int i=0; i<(int)mPartSets.size(); i++) { - for(int j=0; j<(int)mPartSets[i].particles.size(); j++) { - TRISWAPALL( mPartSets[i].particles[j],a,b ); - } - } -} - -// helper function for LBM 2D -> mirror time -void ControlParticles::mirrorTime() { - LbmFloat maxtime = mPartSets[mPartSets.size()-1].time; - const bool debugTimeswap = false; - - for(int i=0; i<(int)mPartSets.size(); i++) { - mPartSets[i].time = maxtime - mPartSets[i].time; - } - - for(int i=0; i<(int)mPartSets.size()/2; i++) { - ControlParticleSet cps = mPartSets[i]; - if(debugTimeswap) errMsg("TIMESWAP", " s"< swap Y and Z components everywhere - //? } -#endif - - initTime(0.f, 0.f); -} - -#undef TRISWAP - -// -------------------------------------------------------------------------- -// init for a given time -void ControlParticles::initTime(LbmFloat t, LbmFloat dt) -{ - //fprintf(stdout, "CPINITTIME init %f\n",t); - _currTime = t; - if(mPartSets.size()<1) return; - - // init zero velocities - initTimeArray(t, _particles); - - // calculate velocities from prev. timestep? - if(dt>0.) { - _currTimestep = dt; - std::vector prevparts; - initTimeArray(t-dt, prevparts); - LbmFloat invdt = 1.0/dt; - for(size_t j=0; j<_particles.size(); j++) { - ControlParticle &p = _particles[j]; - ControlParticle &prevp = prevparts[j]; - for(int k=0; k<3; k++) { - p.pos[k] *= _initPartScale[k]; - p.pos[k] += _initPartOffset[k]; - prevp.pos[k] *= _initLastPartScale[k]; - prevp.pos[k] += _initLastPartOffset[k]; - } - p.vel = (p.pos - prevp.pos)*invdt; - } - - if(0) { - LbmVec avgvel(0.); - for(size_t j=0; j<_particles.size(); j++) { - avgvel += _particles[j].vel; - } - avgvel /= (LbmFloat)_particles.size(); - //fprintf(stdout," AVGVEL %f,%f,%f \n",avgvel[0],avgvel[1],avgvel[2]); // DEBUG - } - } -} - -// helper, init given array -void ControlParticles::initTimeArray(LbmFloat t, std::vector &parts) { - if(mPartSets.size()<1) return; - - if(parts.size()!=mPartSets[0].particles.size()) { - //fprintf(stdout,"PRES \n"); - parts.resize(mPartSets[0].particles.size()); - // TODO reset all? - for(size_t j=0; jt)) { - LbmFloat d = mPartSets[i+1].time-mPartSets[i].time; - LbmFloat f = (t-mPartSets[i].time)/d; - LbmFloat omf = 1.0f - f; - - for(size_t j=0; jpos * omf + src2->pos *f; - p.vel = LbmVec(0.); // reset, calculated later on src1->vel * omf + src2->vel *f; - p.rotaxis = src1->rotaxis * omf + src2->rotaxis *f; - p.influence = src1->influence * omf + src2->influence *f; - p.size = src1->size * omf + src2->size *f; - // dont modify: density, densityWeight - } - } - } - - // after last? - if(t>=mPartSets[ mPartSets.size() -1 ].time) { - //parts = mPartSets[ mPartSets.size() -1 ].particles; - const int i= (int)mPartSets.size() -1; - for(size_t j=0; jgetInfluenceAttraction()<0.) { - cp->density= - cp->densityWeight = 1.0; - continue; - } - - // normalize by kernel - //cp->densityWeight = (1.0 - (cp->density / _kernelWeight)); // store last -#if (CP_PROJECT2D==1) && (defined(MAIN_2D) || LBMDIM==2) - cp->densityWeight = (1.0 - (cp->density / (_kernelWeight*cp->size*cp->size) )); // store last -#else // 2D - cp->densityWeight = (1.0 - (cp->density / (_kernelWeight*cp->size*cp->size*cp->size) )); // store last -#endif // MAIN_2D - - if(i<10) debMsgStd("ControlParticle::prepareControl",DM_MSG,"kernelDebug i="<density,cp->densityWeight); } - avgdw /= (LbmFloat)(_particles.size()); - //if(motion) { printf("ControlParticle::kernel: avgdw:%f, kw%f, sp%f \n", avgdw, _kernelWeight, _fluidSpacing); } - - //if((simtime>=0.) && (simtime != _currTime)) - initTime(simtime, dt); - - if((motion) && (motion->getSize()>0)){ - ControlParticle *motionp = motion->getParticle(0); - //printf("ControlParticle::prepareControl motion: pos[%f,%f,%f] vel[%f,%f,%f] \n", motionp->pos[0], motionp->pos[1], motionp->pos[2], motionp->vel[0], motionp->vel[1], motionp->vel[2] ); - for(size_t i=0; i<_particles.size(); i++) { - ControlParticle *cp = &_particles[i]; - cp->pos = cp->pos + motionp->pos; - cp->vel = cp->vel + motionp->vel; - cp->size = cp->size * motionp->size; - cp->influence = cp->size * motionp->influence; - } - } - - // reset to radiusAtt by default - if(_radiusVel==0.) _radiusVel = _radiusAtt; - if(_radiusMinMaxd==0.) _radiusMinMaxd = _radiusAtt; - if(_radiusMaxd==0.) _radiusMaxd = 2.*_radiusAtt; - // has to be radiusVel_radiusAtt) _radiusVel = _radiusAtt; - if(_radiusAtt>_radiusMinMaxd) _radiusAtt = _radiusMinMaxd; - if(_radiusMinMaxd>_radiusMaxd) _radiusMinMaxd = _radiusMaxd; - - //printf("ControlParticle::radii vel:%f att:%f min:%f max:%f \n", _radiusVel,_radiusAtt,_radiusMinMaxd,_radiusMaxd); - // prepareControl done -} - -void ControlParticles::finishControl(std::vector &forces, LbmFloat iatt, LbmFloat ivel, LbmFloat imaxd) { - - //const LbmFloat iatt = this->getInfluenceAttraction() * this->getCurrTimestep(); - //const LbmFloat ivel = this->getInfluenceVelocity(); - //const LbmFloat imaxd = this->getInfluenceMaxdist() * this->getCurrTimestep(); - // prepare for usage - iatt *= this->getCurrTimestep(); - ivel *= 1.; // not necessary! - imaxd *= this->getCurrTimestep(); - - // skip when size=0 - for(int i=0; i<(int)forces.size(); i++) { - if(DEBUG_MODVEL) fprintf(stdout, "CPFORGF %d , wf:%f,f:%f,%f,%f , v:%f,%f,%f \n",i, forces[i].weightAtt, forces[i].forceAtt[0],forces[i].forceAtt[1],forces[i].forceAtt[2], forces[i].forceVel[0], forces[i].forceVel[1], forces[i].forceVel[2] ); - LbmFloat cfweight = forces[i].weightAtt; // always normalize - if((cfweight!=0.)&&(iatt!=0.)) { - // multiple kernels, normalize - note this does not normalize in d>r/2 region - if(ABS(cfweight)>1.) { cfweight = 1.0/cfweight; } - // multiply iatt afterwards to allow stronger force - cfweight *= iatt; - forces[i].forceAtt *= cfweight; - } else { - forces[i].weightAtt = 0.; - forces[i].forceAtt = LbmVec(0.); - } - - if( (cfweight==0.) && (imaxd>0.) && (forces[i].maxDistance>0.) ) { - forces[i].forceMaxd *= imaxd; - } else { - forces[i].maxDistance= 0.; - forces[i].forceMaxd = LbmVec(0.); - } - - LbmFloat cvweight = forces[i].weightVel; // always normalize - if(cvweight>0.) { - forces[i].forceVel /= cvweight; - forces[i].compAv /= cvweight; - // now modify cvweight, and write back - // important, cut at 1 - otherwise strong vel. influences... - if(cvweight>1.) { cvweight = 1.; } - // thus cvweight is in the range of 0..influenceVelocity, currently not normalized by numCParts - cvweight *= ivel; - if(cvweight<0.) cvweight=0.; - if(cvweight>1.) cvweight=1.; - // LBM, FIXME todo use relaxation factor - //pvel = (cvel*0.5 * cvweight) + (pvel * (1.0-cvweight)); - forces[i].weightVel = cvweight; - - //errMsg("COMPAV","i"<density,cp->densityWeight, (1.0 - (12.0*cp->densityWeight))); } - //fprintf(stdout,"\n\nCP DONE \n\n\n"); -} - - -// -------------------------------------------------------------------------- -// calculate forces at given position, and modify velocity -// according to timestep -void ControlParticles::calculateCpInfluenceOpt(ControlParticle *cp, LbmVec fluidpos, LbmVec fluidvel, ControlForces *force, LbmFloat fillFactor) { - // dont reset, only add... - // test distance, simple squared distance reject - const LbmFloat cpfo = _radiusAtt*cp->size; - - LbmVec posDelta; - if(DEBUG_MODVEL) fprintf(stdout, "CP at %f,%f,%f bef fw:%f, f:%f,%f,%f , vw:%f, v:%f,%f,%f \n",fluidpos[0],fluidpos[1],fluidpos[2], force->weightAtt, force->forceAtt[0], force->forceAtt[1], force->forceAtt[2], force->weightVel, force->forceVel[0], force->forceVel[1], force->forceVel[2]); - posDelta = cp->pos - fluidpos; -#if LBMDIM==2 && (CP_PROJECT2D==1) - posDelta[2] = 0.; // project to xy plane, z-velocity should already be gone... -#endif - - const LbmFloat distsqr = posDelta[0]*posDelta[0]+posDelta[1]*posDelta[1]+posDelta[2]*posDelta[2]; - if(DEBUG_MODVEL) fprintf(stdout, " Pd at %f,%f,%f d%f \n",posDelta[0],posDelta[1],posDelta[2], distsqr); - // cut at influence=0.5 , scaling not really makes sense - if(cpfo*cpfo < distsqr) { - /*if(cp->influence>0.5) { - if(force->weightAtt == 0.) { - if(force->maxDistance*force->maxDistance > distsqr) { - const LbmFloat dis = sqrtf((float)distsqr); - const LbmFloat sc = dis-cpfo; - force->maxDistance = dis; - force->forceMaxd = (posDelta)*(sc/dis); - } - } } */ - return; - } - force->weightAtt += 1e-6; // for distance - force->maxDistance = 0.; // necessary for SPH? - - const LbmFloat pdistance = MAGNITUDE(posDelta); - LbmFloat pdistinv = 0.; - if(ABS(pdistance)>0.) pdistinv = 1./pdistance; - posDelta *= pdistinv; - - LbmFloat falloffAtt = 0.; //CPKernel::kernel(cpfo * 1.0, pdistance); - const LbmFloat qac = pdistance / cpfo ; - if (qac < 1.0){ // return 0.; - if(qac < 0.5) falloffAtt = 1.0f; - else falloffAtt = (1.0f - qac) * 2.0f; - } - - // vorticity force: - // - //LbmVec forceVort; - // - //CROSS(forceVort, posDelta, cp->rotaxis); - // - //NORMALIZE(forceVort); - // - if(falloffAtt>1.0) falloffAtt=1.0; - -#if (CP_PROJECT2D==1) && (defined(MAIN_2D) || LBMDIM==2) - // fillFactor *= 2.0 *0.75 * pdistance; // 2d>3d sampling -#endif // (CP_PROJECT2D==1) && (defined(MAIN_2D) || LBMDIM==2) - - LbmFloat signum = getInfluenceAttraction() > 0.0 ? 1.0 : -1.0; - cp->density += falloffAtt * fillFactor; - force->forceAtt += posDelta *cp->densityWeight *cp->influence *signum; - force->weightAtt += falloffAtt*cp->densityWeight *cp->influence; - - LbmFloat falloffVel = 0.; //CPKernel::kernel(cpfo * 1.0, pdistance); - const LbmFloat cpfv = _radiusVel*cp->size; - if(cpfv*cpfv < distsqr) { return; } - const LbmFloat qvc = pdistance / cpfo ; - //if (qvc < 1.0){ - //if(qvc < 0.5) falloffVel = 1.0f; - //else falloffVel = (1.0f - qvc) * 2.0f; - //} - falloffVel = 1.-qvc; - - LbmFloat pvWeight; // = (1.0-cp->densityWeight) * _currTimestep * falloffVel; - pvWeight = falloffVel *cp->influence; // std, without density influence - //pvWeight *= (1.0-cp->densityWeight); // use inverse density weight - //pvWeight *= cp->densityWeight; // test, use density weight - LbmVec modvel(0.); - modvel += cp->vel * pvWeight; - //pvWeight = 1.; modvel = partVel; // DEBUG!? - - if(pvWeight>0.) { - force->forceVel += modvel; - force->weightVel += pvWeight; - - cp->avgVelWeight += falloffVel; - cp->avgVel += fluidvel; - } - if(DEBUG_MODVEL) fprintf(stdout, "CP at %f,%f,%f aft fw:%f, f:%f,%f,%f , vw:%f, v:%f,%f,%f \n",fluidpos[0],fluidpos[1],fluidpos[2], force->weightAtt, force->forceAtt[0], force->forceAtt[1], force->forceAtt[2], force->weightVel, force->forceVel[0], force->forceVel[1], force->forceVel[2]); - return; -} - -void ControlParticles::calculateMaxdForce(ControlParticle *cp, LbmVec fluidpos, ControlForces *force) { - if(force->weightAtt != 0.) return; // maxd force off - if(cp->influence <= 0.5) return; // ignore - - LbmVec posDelta; - //if(DEBUG_MODVEL) fprintf(stdout, "CP at %f,%f,%f bef fw:%f, f:%f,%f,%f , vw:%f, v:%f,%f,%f \n",fluidpos[0],fluidpos[1],fluidpos[2], force->weightAtt, force->forceAtt[0], force->forceAtt[1], force->forceAtt[2], force->weightVel, force->forceVel[0], force->forceVel[1], force->forceVel[2]); - posDelta = cp->pos - fluidpos; -#if LBMDIM==2 && (CP_PROJECT2D==1) - posDelta[2] = 0.; // project to xy plane, z-velocity should already be gone... -#endif - - // dont reset, only add... - // test distance, simple squared distance reject - const LbmFloat distsqr = posDelta[0]*posDelta[0]+posDelta[1]*posDelta[1]+posDelta[2]*posDelta[2]; - - // closer cp found - if(force->maxDistance*force->maxDistance < distsqr) return; - - const LbmFloat dmin = _radiusMinMaxd*cp->size; - if(distsqrsize; - if(distsqr>dmax*dmax) return; // outside - - - if(DEBUG_MODVEL) fprintf(stdout, " Pd at %f,%f,%f d%f \n",posDelta[0],posDelta[1],posDelta[2], distsqr); - // cut at influence=0.5 , scaling not really makes sense - const LbmFloat dis = sqrtf((float)distsqr); - //const LbmFloat sc = dis - dmin; - const LbmFloat sc = (dis-dmin)/(dmax-dmin); // scale from 0-1 - force->maxDistance = dis; - force->forceMaxd = (posDelta/dis) * sc; - //debug errMsg("calculateMaxdForce","pos"<maxDistance <<" fmd"<forceMaxd ); - return; -} - diff --git a/intern/elbeem/intern/controlparticles.h b/intern/elbeem/intern/controlparticles.h deleted file mode 100644 index 37b694f7cf2..00000000000 --- a/intern/elbeem/intern/controlparticles.h +++ /dev/null @@ -1,327 +0,0 @@ -/** \file - * \ingroup elbeem - */ -// -------------------------------------------------------------------------- -// -// El'Beem - the visual lattice boltzmann freesurface simulator -// All code distributed as part of El'Beem is covered by the version 2 of the -// GNU General Public License. See the file COPYING for details. -// -// Copyright 2008 Nils Thuerey , Richard Keiser, Mark Pauly, Ulrich Ruede -// -// control particle classes -// -// -------------------------------------------------------------------------- - -#ifndef CONTROLPARTICLES_H -#define CONTROLPARTICLES_H - -#include "ntl_geometrymodel.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -// indicator for LBM inclusion -//#ifndef LBMDIM - -//#include -//#include -//class MultisphGUI; -//#define NORMALIZE(a) a.normalize() -//#define MAGNITUDE(a) a.magnitude() -//#define CROSS(a,b,c) a.cross(b,c) -//#define ABS(a) (a>0. ? (a) : -(a)) -//#include "cpdefines.h" - -//#else // LBMDIM - -// use compatibility defines -//#define NORMALIZE(a) normalize(a) -//#define MAGNITUDE(a) norm(a) -//#define CROSS(a,b,c) a=cross(b,c) - -//#endif // LBMDIM - -#define MAGNITUDE(a) norm(a) - -// math.h compatibility -#define CP_PI ((LbmFloat)3.14159265358979323846) - -// project 2d test cases onto plane? -// if not, 3d distance is used for 2d sim as well -#define CP_PROJECT2D 1 - - -// default init for mincpdist, ControlForces::maxDistance -#define CPF_MAXDINIT 10000. - -// storage of influence for a fluid cell/particle in lbm/sph -class ControlForces -{ -public: - ControlForces() { }; - ~ControlForces() {}; - - // attraction force - LbmFloat weightAtt; - LbmVec forceAtt; - // velocity influence - LbmFloat weightVel; - LbmVec forceVel; - // maximal distance influence, - // first is max. distance to first control particle - // second attraction strength - LbmFloat maxDistance; - LbmVec forceMaxd; - - LbmFloat compAvWeight; - LbmVec compAv; - - void resetForces() { - weightAtt = weightVel = 0.; - maxDistance = CPF_MAXDINIT; - forceAtt = forceVel = forceMaxd = LbmVec(0.,0.,0.); - compAvWeight=0.; compAv=LbmVec(0.); - }; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ControlForces") -#endif -}; - - -// single control particle -class ControlParticle -{ -public: - ControlParticle() { reset(); }; - ~ControlParticle() {}; - - // control parameters - - // position - LbmVec pos; - // size (influences influence radius) - LbmFloat size; - // overall strength of influence - LbmFloat influence; - // rotation axis - LbmVec rotaxis; - - // computed values - - // velocity - LbmVec vel; - // computed density - LbmFloat density; - LbmFloat densityWeight; - - LbmVec avgVel; - LbmVec avgVelAcc; - LbmFloat avgVelWeight; - - // init all zero / defaults - void reset(); - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ControlParticle") -#endif -}; - - -// container for a particle configuration at time t -class ControlParticleSet -{ -public: - - // time of particle set - LbmFloat time; - // particle positions - std::vector particles; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ControlParticleSet") -#endif -}; - - -// container & management of control particles -class ControlParticles -{ -public: - ControlParticles(); - ~ControlParticles(); - - // reset datastructures for next influence step - // if motion object is given, particle 1 of second system is used for overall - // position and speed offset - void prepareControl(LbmFloat simtime, LbmFloat dt, ControlParticles *motion); - // post control operations - void finishControl(std::vector &forces, LbmFloat iatt, LbmFloat ivel, LbmFloat imaxd); - // recalculate - void calculateKernelWeight(); - - // calculate forces at given position, and modify velocity - // according to timestep (from initControl) - void calculateCpInfluenceOpt (ControlParticle *cp, LbmVec fluidpos, LbmVec fluidvel, ControlForces *force, LbmFloat fillFactor); - void calculateMaxdForce (ControlParticle *cp, LbmVec fluidpos, ControlForces *force); - - // no. of particles - inline int getSize() { return (int)_particles.size(); } - int getTotalSize(); - // get particle [i] - inline ControlParticle* getParticle(int i){ return &_particles[i]; } - - // set influence parameters - void setInfluenceTangential(LbmFloat set) { _influenceTangential=set; } - void setInfluenceAttraction(LbmFloat set) { _influenceAttraction=set; } - void setInfluenceMaxdist(LbmFloat set) { _influenceMaxdist=set; } - // calculate for delta t - void setInfluenceVelocity(LbmFloat set, LbmFloat dt); - // get influence parameters - inline LbmFloat getInfluenceAttraction() { return _influenceAttraction; } - inline LbmFloat getInfluenceTangential() { return _influenceTangential; } - inline LbmFloat getInfluenceVelocity() { return _influenceVelocity; } - inline LbmFloat getInfluenceMaxdist() { return _influenceMaxdist; } - inline LbmFloat getCurrTimestep() { return _currTimestep; } - - void setRadiusAtt(LbmFloat set) { _radiusAtt=set; } - inline LbmFloat getRadiusAtt() { return _radiusAtt; } - void setRadiusVel(LbmFloat set) { _radiusVel=set; } - inline LbmFloat getRadiusVel() { return _radiusVel; } - void setRadiusMaxd(LbmFloat set) { _radiusMaxd=set; } - inline LbmFloat getRadiusMaxd() { return _radiusMaxd; } - void setRadiusMinMaxd(LbmFloat set) { _radiusMinMaxd=set; } - inline LbmFloat getRadiusMinMaxd() { return _radiusMinMaxd; } - - LbmFloat getControlTimStart(); - LbmFloat getControlTimEnd(); - - // set/get characteristic length (and inverse) - void setCharLength(LbmFloat set) { _charLength=set; _charLengthInv=1./_charLength; } - inline LbmFloat getCharLength() { return _charLength;} - inline LbmFloat getCharLengthInv() { return _charLengthInv;} - - // set init parameters - void setInitTimeScale(LbmFloat set) { _initTimeScale = set; }; - void setInitMirror(string set) { _initMirror = set; }; - string getInitMirror() { return _initMirror; }; - - void setLastOffset(LbmVec set) { _initLastPartOffset = set; }; - void setLastScale(LbmVec set) { _initLastPartScale = set; }; - void setOffset(LbmVec set) { _initPartOffset = set; }; - void setScale(LbmVec set) { _initPartScale = set; }; - - // set/get cps params - void setCPSWith(LbmFloat set) { mCPSWidth = set; }; - void setCPSTimestep(LbmFloat set) { mCPSTimestep = set; }; - void setCPSTimeStart(LbmFloat set) { mCPSTimeStart = set; }; - void setCPSTimeEnd(LbmFloat set) { mCPSTimeEnd = set; }; - void setCPSMvmWeightFac(LbmFloat set) { mCPSWeightFac = set; }; - - LbmFloat getCPSWith() { return mCPSWidth; }; - LbmFloat getCPSTimestep() { return mCPSTimestep; }; - LbmFloat getCPSTimeStart() { return mCPSTimeStart; }; - LbmFloat getCPSTimeEnd() { return mCPSTimeEnd; }; - LbmFloat getCPSMvmWeightFac() { return mCPSWeightFac; }; - - void setDebugInit(int set) { mDebugInit = set; }; - - // set init parameters - void setFluidSpacing(LbmFloat set) { _fluidSpacing = set; }; - - // load positions & timing from text file - int initFromTextFile(string filename); - int initFromTextFileOld(string filename); - // load positions & timing from gzipped binary file - int initFromBinaryFile(string filename); - int initFromMVCMesh(string filename); - // init an example test case - int initExampleSet(); - - // init for a given time - void initTime(LbmFloat t, LbmFloat dt); - - // blender test init - void initBlenderTest(); - - int initFromObject(ntlGeometryObjModel *model); - -protected: - // sets influence params - friend class MultisphGUI; - - // tangential and attraction influence - LbmFloat _influenceTangential, _influenceAttraction; - // direct velocity influence - LbmFloat _influenceVelocity; - // maximal distance influence - LbmFloat _influenceMaxdist; - - // influence radii - LbmFloat _radiusAtt, _radiusVel, _radiusMinMaxd, _radiusMaxd; - - // currently valid time & timestep - LbmFloat _currTime, _currTimestep; - // all particles - std::vector _particles; - - // particle sets - std::vector mPartSets; - - // additional parameters for initing particles - LbmFloat _initTimeScale; - LbmVec _initPartOffset; - LbmVec _initPartScale; - LbmVec _initLastPartOffset; - LbmVec _initLastPartScale; - // mirror particles for loading? - string _initMirror; - - // row spacing paramter, e.g. use for approximation of kernel area/volume - LbmFloat _fluidSpacing; - // save current kernel weight - LbmFloat _kernelWeight; - // charateristic length in world coordinates for normalizatioon of forces - LbmFloat _charLength, _charLengthInv; - - - /*! do ani mesh CPS */ - void calculateCPS(string filename); - //! ani mesh cps params - ntlVec3Gfx mvCPSStart, mvCPSEnd; - gfxReal mCPSWidth, mCPSTimestep; - gfxReal mCPSTimeStart, mCPSTimeEnd; - gfxReal mCPSWeightFac; - - int mDebugInit; - - -protected: - // apply init transformations - void applyTrafos(); - - // helper function for init -> swap components everywhere - void swapCoords(int a,int b); - // helper function for init -> mirror time - void mirrorTime(); - - // helper, init given array - void initTimeArray(LbmFloat t, std::vector &parts); - - bool checkPointInside(ntlTree *tree, ntlVec3Gfx org, gfxReal &distance); - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ControlParticles") -#endif -}; - - - -#endif - diff --git a/intern/elbeem/intern/elbeem.cpp b/intern/elbeem/intern/elbeem.cpp deleted file mode 100644 index 01e4801fed2..00000000000 --- a/intern/elbeem/intern/elbeem.cpp +++ /dev/null @@ -1,430 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * All code distributed as part of El'Beem is covered by the version 2 of the - * GNU General Public License. See the file COPYING for details. - * Copyright 2003-2006 Nils Thuerey - * - * Main program functions - */ - -#include "elbeem.h" -#include "ntl_blenderdumper.h" -extern "C" void elbeemCheckDebugEnv(void); - -#include "ntl_world.h" -#include "ntl_geometrymodel.h" - -/*****************************************************************************/ -// region of interest global vars -// currently used by e.g. fsgr solver -double guiRoiSX = 0.0; -double guiRoiSY = 0.0; -double guiRoiSZ = 0.0; -double guiRoiEX = 1.0; -double guiRoiEY = 1.0; -double guiRoiEZ = 1.0; -int guiRoiMaxLev=6, guiRoiMinLev=0; - -//! global raytracer pointer (=world) -ntlWorld *gpWorld = NULL; - - - -// API - -// reset elbeemSimulationSettings struct with defaults -extern "C" -void elbeemResetSettings(elbeemSimulationSettings *set) { - if(!set) return; - set->version = 3; - set->domainId = 0; - for(int i=0 ; i<3; i++) set->geoStart[i] = 0.0; - for(int i=0 ; i<3; i++) set->geoSize[i] = 1.0; - set->resolutionxyz = 64; - set->previewresxyz = 24; - set->realsize = 1.0; - set->viscosity = 0.000001; - - for(int i=0 ; i<2; i++) set->gravity[i] = 0.0; - set->gravity[2] = -9.81; - - set->animStart = 0; - set->aniFrameTime = 0.01; - set->noOfFrames = 10; - set->gstar = 0.005; - set->maxRefine = -1; - set->generateParticles = 0.0; - set->numTracerParticles = 0; - strcpy(set->outputPath,"./elbeemdata_"); - - set->channelSizeFrameTime=0; - set->channelFrameTime=NULL; - set->channelSizeViscosity=0; - set->channelViscosity=NULL; - set->channelSizeGravity=0; - set->channelGravity=NULL; - - set->domainobsType= FLUIDSIM_OBSTACLE_NOSLIP; - set->domainobsPartslip= 0.; - set->generateVertexVectors = 0; - set->surfaceSmoothing = 1.; - set->surfaceSubdivs = 1; - - set->farFieldSize = 0.; - set->runsimCallback = NULL; - set->runsimUserData = NULL; - - // init identity - for(int i=0; i<16; i++) set->surfaceTrafo[i] = 0.0; - for(int i=0; i<4; i++) set->surfaceTrafo[i*4+i] = 1.0; -} - -// start fluidsim init -extern "C" -int elbeemInit() { - setElbeemState( SIMWORLD_INITIALIZING ); - setElbeemErrorString("[none]"); - resetGlobalColorSetting(); - - elbeemCheckDebugEnv(); - debMsgStd("performElbeemSimulation",DM_NOTIFY,"El'Beem Simulation Init Start as Plugin, debugLevel:"<addDomain(settings); - return 0; -} - -// error message access -extern "C" -void elbeemGetErrorString(char *buffer) { - if(!buffer) return; - strncpy(buffer,getElbeemErrorString(),256); -} - -// reset elbeemMesh struct with zeroes -extern "C" -void elbeemResetMesh(elbeemMesh *mesh) { - if(!mesh) return; - // init typedef struct elbeemMesh - mesh->type = 0; - - mesh->parentDomainId = 0; - - /* vertices */ - mesh->numVertices = 0; - mesh->vertices = NULL; - - mesh->channelSizeVertices = 0; - mesh->channelVertices = NULL; - - /* triangles */ - mesh->numTriangles = 0; - mesh->triangles = NULL; - - /* animation channels */ - mesh->channelSizeTranslation = 0; - mesh->channelTranslation = NULL; - mesh->channelSizeRotation = 0; - mesh->channelRotation = NULL; - mesh->channelSizeScale = 0; - mesh->channelScale = NULL; - - /* active channel */ - mesh->channelSizeActive = 0; - mesh->channelActive = NULL; - - mesh->channelSizeInitialVel = 0; - mesh->channelInitialVel = NULL; - - mesh->localInivelCoords = 0; - - mesh->obstacleType= FLUIDSIM_OBSTACLE_NOSLIP; - mesh->obstaclePartslip= 0.; - mesh->obstacleImpactFactor= 1.; - - mesh->volumeInitType= OB_VOLUMEINIT_VOLUME; - - /* name of the mesh, mostly for debugging */ - mesh->name = "[unnamed]"; - - /* fluid control settings */ - mesh->cpsTimeStart = 0; - mesh->cpsTimeEnd = 0; - mesh->cpsQuality = 0; - - mesh->channelSizeAttractforceStrength = 0; - mesh->channelAttractforceStrength = NULL; - mesh->channelSizeAttractforceRadius = 0; - mesh->channelAttractforceRadius = NULL; - mesh->channelSizeVelocityforceStrength = 0; - mesh->channelVelocityforceStrength = NULL; - mesh->channelSizeVelocityforceRadius = 0; - mesh->channelVelocityforceRadius = NULL; -} - -int globalMeshCounter = 1; -// add mesh as fluidsim object -extern "C" -int elbeemAddMesh(elbeemMesh *mesh) { - int initType; - if(getElbeemState() != SIMWORLD_INITIALIZING) { errFatal("elbeemAddMesh","World and domain not initialized, call elbeemInit and elbeemAddDomain before...", SIMWORLD_INITERROR); } - - switch(mesh->type) { - case OB_FLUIDSIM_OBSTACLE: - if (mesh->obstacleType==FLUIDSIM_OBSTACLE_PARTSLIP) initType = FGI_BNDPART; - else if(mesh->obstacleType==FLUIDSIM_OBSTACLE_FREESLIP) initType = FGI_BNDFREE; - else /*if(mesh->obstacleType==FLUIDSIM_OBSTACLE_NOSLIP)*/ initType = FGI_BNDNO; - break; - case OB_FLUIDSIM_FLUID: initType = FGI_FLUID; break; - case OB_FLUIDSIM_INFLOW: initType = FGI_MBNDINFLOW; break; - case OB_FLUIDSIM_OUTFLOW: initType = FGI_MBNDOUTFLOW; break; - case OB_FLUIDSIM_CONTROL: initType = FGI_CONTROL; break; - default: return 1; // invalid type - } - - ntlGeometryObjModel *obj = new ntlGeometryObjModel( ); - gpWorld->getRenderGlobals()->getSimScene()->addGeoClass( obj ); - gpWorld->getRenderGlobals()->getRenderScene()->addGeoClass(obj); - obj->initModel( - mesh->numVertices, mesh->vertices, mesh->numTriangles, mesh->triangles, - mesh->channelSizeVertices, mesh->channelVertices ); - if(mesh->name) obj->setName(string(mesh->name)); - else { - char meshname[100]; - snprintf(meshname,100,"mesh%04d",globalMeshCounter); - obj->setName(string(meshname)); - } - globalMeshCounter++; - obj->setGeoInitId( mesh->parentDomainId+1 ); - obj->setGeoInitIntersect(true); - obj->setGeoInitType(initType); - - // abuse partslip value for control fluid: reverse control keys or not - if(initType == FGI_CONTROL) - obj->setGeoPartSlipValue(mesh->obstacleType); - else - obj->setGeoPartSlipValue(mesh->obstaclePartslip); - - obj->setGeoImpactFactor(mesh->obstacleImpactFactor); - - /* fluid control features */ - obj->setCpsTimeStart(mesh->cpsTimeStart); - obj->setCpsTimeEnd(mesh->cpsTimeEnd); - obj->setCpsQuality(mesh->cpsQuality); - - if((mesh->volumeInitTypevolumeInitType>VOLUMEINIT_BOTH)) mesh->volumeInitType = VOLUMEINIT_VOLUME; - obj->setVolumeInit(mesh->volumeInitType); - // use channel instead, obj->setInitialVelocity( ntlVec3Gfx(mesh->iniVelocity[0], mesh->iniVelocity[1], mesh->iniVelocity[2]) ); - - obj->initChannels( - mesh->channelSizeTranslation, mesh->channelTranslation, - mesh->channelSizeRotation, mesh->channelRotation, - mesh->channelSizeScale, mesh->channelScale, - mesh->channelSizeActive, mesh->channelActive, - mesh->channelSizeInitialVel, mesh->channelInitialVel, - mesh->channelSizeAttractforceStrength, mesh->channelAttractforceStrength, - mesh->channelSizeAttractforceRadius, mesh->channelAttractforceRadius, - mesh->channelSizeVelocityforceStrength, mesh->channelVelocityforceStrength, - mesh->channelSizeVelocityforceRadius, mesh->channelVelocityforceRadius - ); - obj->setLocalCoordInivel( mesh->localInivelCoords ); - - debMsgStd("elbeemAddMesh",DM_MSG,"Added elbeem mesh: "<getName()<<" type="<getIsAnimated(), 9 ); - return 0; -} - -// do the actual simulation -extern "C" -int elbeemSimulate(void) { - if(!gpWorld) return 1; - - gpWorld->finishWorldInit(); - if( isSimworldOk() ) { - myTime_t timestart = getTime(); - gpWorld->renderAnimation(); - myTime_t timeend = getTime(); - - if(getElbeemState() != SIMWORLD_STOP) { - // ok, we're done... - delete gpWorld; - - gpWorld = NULL; - debMsgStd("elbeemSimulate",DM_NOTIFY, "El'Beem simulation done, time: "<renderAnimation(); - myTime_t timeend = getTime(); - - if(getElbeemState() != SIMWORLD_STOP) { - // ok, we're done... - delete gpWorld; - gpWorld = NULL; - debMsgStd("elbeemContinueSimulation",DM_NOTIFY, "El'Beem simulation done, time: "< gKeepVal; - -#define SIMPLIFY_FLOAT_EPSILON (1e-6f) -#define SIMPLIFY_DOUBLE_EPSILON (1e-12f) -#define SFLOATEQ(x,y) (ABS((x)-(y)) < SIMPLIFY_FLOAT_EPSILON) -#define SDOUBLEEQ(x,y) (ABS((x)-(y)) < SIMPLIFY_DOUBLE_EPSILON) -#define SVECFLOATEQ(x,y) ( \ - (ABS((x)[0]-(y)[0]) < SIMPLIFY_FLOAT_EPSILON) && \ - (ABS((x)[1]-(y)[1]) < SIMPLIFY_FLOAT_EPSILON) && \ - (ABS((x)[2]-(y)[2]) < SIMPLIFY_FLOAT_EPSILON) ) - -// helper function - simplify animation channels -extern "C" -int elbeemSimplifyChannelFloat(float *channel, int* size) { - bool changed = false; - int nsize = *size; - int orgsize = *size; - if(orgsize<1) return false; - gKeepVal.resize( orgsize ); - for(int i=0; i -#include -#include - -#ifdef sun -#include "ieeefp.h" -#endif - -// just use default rounding for platforms where its not available -#ifndef round -#define round(x) (x) -#endif - -using std::isfinite; - -/****************************************************************************** - * Constructor - *****************************************************************************/ -IsoSurface::IsoSurface(double iso) : - ntlGeometryObject(), - mSizex(-1), mSizey(-1), mSizez(-1), - mpData(NULL), - mIsoValue( iso ), - mPoints(), - mUseFullEdgeArrays(false), - mpEdgeVerticesX(NULL), mpEdgeVerticesY(NULL), mpEdgeVerticesZ(NULL), - mEdgeArSize(-1), - mIndices(), - - mStart(0.0), mEnd(0.0), mDomainExtent(0.0), - mInitDone(false), - mSmoothSurface(0.0), mSmoothNormals(0.0), - mAcrossEdge(), mAdjacentFaces(), - mCutoff(-1), mCutArray(NULL), // off by default - mpIsoParts(NULL), mPartSize(0.), mSubdivs(0), - mFlagCnt(1), - mSCrad1(0.), mSCrad2(0.), mSCcenter(0.) -{ -} - - -/****************************************************************************** - * The real init... - *****************************************************************************/ -void IsoSurface::initializeIsosurface(int setx, int sety, int setz, ntlVec3Gfx extent) -{ - // range 1-10 (max due to subd array in triangulate) - if(mSubdivs<1) mSubdivs=1; - if(mSubdivs>10) mSubdivs=10; - - // init solver and size - mSizex = setx; - mSizey = sety; - if(setz == 1) {// 2D, create thin 2D surface - setz = 5; - } - mSizez = setz; - mDomainExtent = extent; - - /* check triangulation size (for raytraing) */ - if( ( mStart[0] >= mEnd[0] ) && ( mStart[1] >= mEnd[1] ) && ( mStart[2] >= mEnd[2] ) ){ - // extent was not set, use normalized one from parametrizer - mStart = ntlVec3Gfx(0.0) - extent*0.5; - mEnd = ntlVec3Gfx(0.0) + extent*0.5; - } - - // init - mIndices.clear(); - mPoints.clear(); - - int nodes = mSizez*mSizey*mSizex; - mpData = new float[nodes]; - for(int i=0;i0) && (kmSizex-2-coAdd-mCutoff) || - (j>mSizey-2-coAdd-mCutoff) ) { - if(mCutArray) { - if(k < mCutArray[j*this->mSizex+i]) continue; - } else { continue; } - } - - // Create the triangles... - for(int e=0; mcTriTable[cubeIndex][e]!=-1; e+=3) { - mIndices.push_back( triIndices[ mcTriTable[cubeIndex][e+0] ] ); - mIndices.push_back( triIndices[ mcTriTable[cubeIndex][e+1] ] ); - mIndices.push_back( triIndices[ mcTriTable[cubeIndex][e+2] ] ); - } - - }//i - }// j - - // copy edge arrays - if(!mUseFullEdgeArrays) { - for(int j=0;j<(mSizey-0);j++) - for(int i=0;i<(mSizex-0);i++) { - //int edgek = 0; - const int dst = ISOLEVEL_INDEX( i+0, j+0, 0); - const int src = ISOLEVEL_INDEX( i+0, j+0, 1); - mpEdgeVerticesX[ dst ] = mpEdgeVerticesX[ src ]; - mpEdgeVerticesY[ dst ] = mpEdgeVerticesY[ src ]; - mpEdgeVerticesZ[ dst ] = mpEdgeVerticesZ[ src ]; - mpEdgeVerticesX[ src ]=-1; - mpEdgeVerticesY[ src ]=-1; - mpEdgeVerticesZ[ src ]=-1; - } - } // */ - - } // k - - // precalculate normals using an approximation of the scalar field gradient - for(int ni=0;ni<(int)mPoints.size();ni++) { normalize( mPoints[ni].n ); } - - } else { // subdivs - -#define EDGEAR_INDEX(Ai,Aj,Ak, Bi,Bj) ((mSizex*mSizey*mSubdivs*mSubdivs*(Ak))+\ - (mSizex*mSubdivs*((Aj)*mSubdivs+(Bj)))+((Ai)*mSubdivs)+(Bi)) - -#define ISOTRILININT(fi,fj,fk) ( \ - (1.-(fi))*(1.-(fj))*(1.-(fk))*orgval[0] + \ - ( (fi))*(1.-(fj))*(1.-(fk))*orgval[1] + \ - ( (fi))*( (fj))*(1.-(fk))*orgval[2] + \ - (1.-(fi))*( (fj))*(1.-(fk))*orgval[3] + \ - (1.-(fi))*(1.-(fj))*( (fk))*orgval[4] + \ - ( (fi))*(1.-(fj))*( (fk))*orgval[5] + \ - ( (fi))*( (fj))*( (fk))*orgval[6] + \ - (1.-(fi))*( (fj))*( (fk))*orgval[7] ) - - // use subdivisions - gfxReal subdfac = 1./(gfxReal)(mSubdivs); - gfxReal orgGsx = gsx; - gfxReal orgGsy = gsy; - gfxReal orgGsz = gsz; - gsx *= subdfac; - gsy *= subdfac; - gsz *= subdfac; - if(mUseFullEdgeArrays) { - errMsg("IsoSurface::triangulate","Disabling mUseFullEdgeArrays!"); - } - - // subdiv local arrays - gfxReal orgval[8]; - gfxReal subdAr[2][11][11]; // max 10 subdivs! - ParticleObject* *arppnt = new ParticleObject*[mSizez*mSizey*mSizex]; - - // construct pointers - // part test - int pInUse = 0; - int pUsedTest = 0; - // reset particles - // reset list array - for(int k=0;k<(mSizez);k++) - for(int j=0;j<(mSizey);j++) - for(int i=0;i<(mSizex);i++) { - arppnt[ISOLEVEL_INDEX(i,j,k)] = NULL; - } - if(mpIsoParts) { - for(vector::iterator pit= mpIsoParts->getParticlesBegin(); - pit!= mpIsoParts->getParticlesEnd(); pit++) { - if( (*pit).getActive()==false ) continue; - if( (*pit).getType()!=PART_DROP) continue; - (*pit).setNext(NULL); - } - // build per node lists - for(vector::iterator pit= mpIsoParts->getParticlesBegin(); - pit!= mpIsoParts->getParticlesEnd(); pit++) { - if( (*pit).getActive()==false ) continue; - if( (*pit).getType()!=PART_DROP) continue; - // check lifetime ignored here - ParticleObject *p = &(*pit); - const ntlVec3Gfx ppos = p->getPos(); - const int pi= (int)round(ppos[0])+0; - const int pj= (int)round(ppos[1])+0; - int pk= (int)round(ppos[2])+0;// no offset necessary - // 2d should be handled by solver. if(LBMDIM==2) { pk = 0; } - - if(pi<0) continue; - if(pj<0) continue; - if(pk<0) continue; - if(pi>mSizex-1) continue; - if(pj>mSizey-1) continue; - if(pk>mSizez-1) continue; - ParticleObject* &pnt = arppnt[ISOLEVEL_INDEX(pi,pj,pk)]; - if(pnt) { - // append - ParticleObject* listpnt = pnt; - while(listpnt) { - if(!listpnt->getNext()) { - listpnt->setNext(p); listpnt = NULL; - } else { - listpnt = listpnt->getNext(); - } - } - } else { - // start new list - pnt = p; - } - pInUse++; - } - } // mpIsoParts - - debMsgStd("IsoSurface::triangulate",DM_MSG,"Starting. Parts in use:"<=mSizez-1) continue; - for(int poj=-poDistOffset; poj<1+poDistOffset; poj++) { - if(j+poj<0) continue; - if(j+poj>=mSizey-1) continue; - for(int poi=-poDistOffset; poi<1+poDistOffset; poi++) { - if(i+poi<0) continue; - if(i+poi>=mSizex-1) continue; - ParticleObject *p; - p = arppnt[ISOLEVEL_INDEX(i+poi,j+poj,k+pok)]; - while(p) { // */ - /* - for(vector::iterator pit= mpIsoParts->getParticlesBegin(); - pit!= mpIsoParts->getParticlesEnd(); pit++) { { { { - // debug test! , full list slow! - if(( (*pit).getActive()==false ) || ( (*pit).getType()!=PART_DROP)) continue; - ParticleObject *p; - p = &(*pit); // */ - - pUsedTest++; - ntlVec3Gfx ppos = p->getPos(); - const int spi= (int)round( (ppos[0]+1.-(gfxReal)i) *(gfxReal)mSubdivs-1.5); - const int spj= (int)round( (ppos[1]+1.-(gfxReal)j) *(gfxReal)mSubdivs-1.5); - const int spk= (int)round( (ppos[2]+1.-(gfxReal)k) *(gfxReal)mSubdivs-1.5)-sdkOffset; // why -2? - // 2d should be handled by solver. if(LBMDIM==2) { spk = 0; } - - gfxReal pfLen = p->getSize()*1.5*mPartSize; // test, was 1.1 - const gfxReal minPfLen = subdfac*0.8; - if(pfLengetSize()<<" ps"< 1) { continue; } // */ - for(int swj=-icellpsize; swj<=icellpsize; swj++) { - if(spj+swj< 0) { continue; } - if(spj+swj>mSubdivs+0) { continue; } // */ - for(int swi=-icellpsize; swi<=icellpsize; swi++) { - if(spi+swi< 0) { continue; } - if(spi+swi>mSubdivs+0) { continue; } // */ - ntlVec3Gfx cellp = ntlVec3Gfx( - (1.5+(gfxReal)(spi+swi)) *subdfac + (gfxReal)(i-1), - (1.5+(gfxReal)(spj+swj)) *subdfac + (gfxReal)(j-1), - (1.5+(gfxReal)(spk+swk)+sdkOffset) *subdfac + (gfxReal)(k-1) - ); - //if(swi==0 && swj==0 && swk==0) subdAr[spk][spj][spi] = 1.; // DEBUG - // clip domain boundaries again - if(cellp[0]<1.) { continue; } - if(cellp[1]<1.) { continue; } - if(cellp[2]<1.) { continue; } - if(cellp[0]>(gfxReal)mSizex-3.) { continue; } - if(cellp[1]>(gfxReal)mSizey-3.) { continue; } - if(cellp[2]>(gfxReal)mSizez-3.) { continue; } - gfxReal len = norm(cellp-ppos); - gfxReal isoadd = 0.; - const gfxReal baseIsoVal = mIsoValue*1.1; - if(len1.) { continue; } - subdAr[spk+swk][spj+swj][spi+swi] = arval + isoadd; - } } } - - p = p->getNext(); - } - } } } // poDist loops */ - - py = mStart[1]+(((double)j-0.5)*orgGsy)-gsy; - for(int sj=0;sj 0) { - - // where to look up if this point already exists - const int edgek = 0; - const int baseIn = EDGEAR_INDEX( i+0, j+0, edgek+0, si,sj); - eVert[ 0] = &mpEdgeVerticesX[ baseIn ]; - eVert[ 1] = &mpEdgeVerticesY[ baseIn + 1 ]; - eVert[ 2] = &mpEdgeVerticesX[ EDGEAR_INDEX( i, j, edgek+0, si+0,sj+1) ]; - eVert[ 3] = &mpEdgeVerticesY[ baseIn ]; - - eVert[ 4] = &mpEdgeVerticesX[ EDGEAR_INDEX( i, j, edgek+1, si+0,sj+0) ]; - eVert[ 5] = &mpEdgeVerticesY[ EDGEAR_INDEX( i, j, edgek+1, si+1,sj+0) ]; // with subdivs - eVert[ 6] = &mpEdgeVerticesX[ EDGEAR_INDEX( i, j, edgek+1, si+0,sj+1) ]; - eVert[ 7] = &mpEdgeVerticesY[ EDGEAR_INDEX( i, j, edgek+1, si+0,sj+0) ]; - - eVert[ 8] = &mpEdgeVerticesZ[ baseIn ]; - eVert[ 9] = &mpEdgeVerticesZ[ EDGEAR_INDEX( i, j, edgek+0, si+1,sj+0) ]; // with subdivs - eVert[10] = &mpEdgeVerticesZ[ EDGEAR_INDEX( i, j, edgek+0, si+1,sj+1) ]; - eVert[11] = &mpEdgeVerticesZ[ EDGEAR_INDEX( i, j, edgek+0, si+0,sj+1) ]; - - // grid positions - pos[0] = ntlVec3Gfx(px ,py ,pz); - pos[1] = ntlVec3Gfx(px+gsx,py ,pz); - pos[2] = ntlVec3Gfx(px+gsx,py+gsy,pz); // with subdivs - pos[3] = ntlVec3Gfx(px ,py+gsy,pz); - pos[4] = ntlVec3Gfx(px ,py ,pz+gsz); - pos[5] = ntlVec3Gfx(px+gsx,py ,pz+gsz); - pos[6] = ntlVec3Gfx(px+gsx,py+gsy,pz+gsz); // with subdivs - pos[7] = ntlVec3Gfx(px ,py+gsy,pz+gsz); - - // check all edges - for(int e=0;e<12;e++) { - if (mcEdgeTable[cubeIndex] & (1<0) { - //smoSubdfac = 1./(float)(mSubdivs); - smoSubdfac = pow(0.55,(double)mSubdivs); // slightly stronger - } - if(mSmoothSurface>0. || mSmoothNormals>0.) debMsgStd("IsoSurface::triangulate",DM_MSG,"Smoothing...",10); - if(mSmoothSurface>0.0) { - smoothSurface(mSmoothSurface*smoSubdfac, (mSmoothNormals<=0.0) ); - } - if(mSmoothNormals>0.0) { - smoothNormals(mSmoothNormals*smoSubdfac); - } - - myTime_t tritimeend = getTime(); - debMsgStd("IsoSurface::triangulate",DM_MSG,"took "<< getTimeString(tritimeend-tritimestart)<<", S("<getNumParticles(), 10); -} - - - - - -/****************************************************************************** - * Get triangles for rendering - *****************************************************************************/ -void IsoSurface::getTriangles(double t, vector *triangles, - vector *vertices, - vector *normals, int objectId ) -{ - if(!mInitDone) { - debugOut("IsoSurface::getTriangles warning: Not initialized! ", 10); - return; - } - t = 0.; - //return; // DEBUG - - /* triangulate field */ - triangulate(); - //errMsg("TRIS"," "<size()<<" ns"<size()<<" ts"<size() ); - //errMsg("NM"," ovs"<push_back( mPoints[i].v ); - } - for(int i=0;i<(int)mPoints.size();i++) { - normals->push_back( mPoints[i].n ); - } - - //errMsg("N2"," ivi"<size()<<" ns"<size()<<" ts"<size() ); - //errMsg("N2"," ovs"< 0) { - flag |= (1<< (geoiId+4)); - flag |= mGeoInitType; - } - - tri.setFlags( flag ); - - /* triangle normal missing */ - tri.setNormal( ntlVec3Gfx(0.0) ); - tri.setSmoothNormals( smooth ); - tri.setObjectId( objectId ); - triangles->push_back( tri ); - } - //errMsg("N3"," ivi"<size()<<" ns"<size()<<" ts"<size() ); - return; -} - - - -inline ntlVec3Gfx IsoSurface::getNormal(int i, int j,int k) { - // WARNING - this requires a security boundary layer... - ntlVec3Gfx ret(0.0); - ret[0] = *getData(i-1,j ,k ) - - *getData(i+1,j ,k ); - ret[1] = *getData(i ,j-1,k ) - - *getData(i ,j+1,k ); - ret[2] = *getData(i ,j ,k-1 ) - - *getData(i ,j ,k+1 ); - return ret; -} - - - - -/****************************************************************************** - * - * Surface improvement, inspired by trimesh2 library - * (http://www.cs.princeton.edu/gfx/proj/trimesh2/) - * - *****************************************************************************/ - -void IsoSurface::setSmoothRad(float radi1, float radi2, ntlVec3Gfx mscc) { - mSCrad1 = radi1*radi1; - mSCrad2 = radi2*radi2; - mSCcenter = mscc; -} - -// compute normals for all generated triangles -void IsoSurface::computeNormals() { - for(int i=0;i<(int)mPoints.size();i++) { - mPoints[i].n = ntlVec3Gfx(0.); - } - - for(int i=0;i<(int)mIndices.size();i+=3) { - const int t1 = mIndices[i]; - const int t2 = mIndices[i+1]; - const int t3 = mIndices[i+2]; - const ntlVec3Gfx p1 = mPoints[t1].v; - const ntlVec3Gfx p2 = mPoints[t2].v; - const ntlVec3Gfx p3 = mPoints[t3].v; - const ntlVec3Gfx n1=p1-p2; - const ntlVec3Gfx n2=p2-p3; - const ntlVec3Gfx n3=p3-p1; - const gfxReal len1 = normNoSqrt(n1); - const gfxReal len2 = normNoSqrt(n2); - const gfxReal len3 = normNoSqrt(n3); - const ntlVec3Gfx norm = cross(n1,n2); - mPoints[t1].n += norm * (1./(len1*len3)); - mPoints[t2].n += norm * (1./(len1*len2)); - mPoints[t3].n += norm * (1./(len2*len3)); - } - - for(int i=0;i<(int)mPoints.size();i++) { - normalize(mPoints[i].n); - } -} - -// Diffuse a vector field at 1 vertex, weighted by -// a gaussian of width 1/sqrt(invsigma2) -bool IsoSurface::diffuseVertexField(ntlVec3Gfx *field, const int pointerScale, int src, float invsigma2, ntlVec3Gfx &target) -{ - if((neighbors[src].size()<1) || (pointareas[src]<=0.0)) return 0; - const ntlVec3Gfx srcp = mPoints[src].v; - const ntlVec3Gfx srcn = mPoints[src].n; - if(mSCrad1>0.0 && mSCrad2>0.0) { - ntlVec3Gfx dp = mSCcenter-srcp; dp[2] = 0.0; // only xy-plane - float rd = normNoSqrt(dp); - if(rd > mSCrad2) { - return 0; - } else if(rd > mSCrad1) { - // optimize? - float org = 1.0/sqrt(invsigma2); - org *= (1.0- (rd-mSCrad1) / (mSCrad2-mSCrad1)); - invsigma2 = 1.0/(org*org); - //errMsg("TRi","p"<= 9.0f) continue; - - // aggressive smoothing factor - float smstr = nvdot * pointareas[bbn]; - // Accumulate weight times field at neighbor - target += *(field+pointerScale*bbn)*smstr; - smstrSum += smstr; - - for(int i = 0; i < (int)neighbors[bbn].size(); i++) { - const int nn = neighbors[bbn][i]; - if (flags[nn] == flag) continue; - mDboundary.push_back(nn); - } - } - target /= smstrSum; - return 1; -} - - -// perform smoothing of the surface (and possible normals) -void IsoSurface::smoothSurface(float sigma, bool normSmooth) -{ - int nv = mPoints.size(); - if ((int)flags.size() != nv) flags.resize(nv); - int nf = mIndices.size()/3; - - { // need neighbors - vector numneighbors(mPoints.size()); - int i; - for (i = 0; i < (int)mIndices.size()/3; i++) { - numneighbors[mIndices[i*3+0]]++; - numneighbors[mIndices[i*3+1]]++; - numneighbors[mIndices[i*3+2]]++; - } - - neighbors.clear(); - neighbors.resize(mPoints.size()); - for (i = 0; i < (int)mPoints.size(); i++) { - neighbors[i].clear(); - neighbors[i].reserve(numneighbors[i]+2); // Slop for boundaries - } - - for (i = 0; i < (int)mIndices.size()/3; i++) { - for (int j = 0; j < 3; j++) { - vector &me = neighbors[ mIndices[i*3+j]]; - int n1 = mIndices[i*3+((j+1)%3)]; - int n2 = mIndices[i*3+((j+2)%3)]; - if (std::find(me.begin(), me.end(), n1) == me.end()) - me.push_back(n1); - if (std::find(me.begin(), me.end(), n2) == me.end()) - me.push_back(n2); - } - } - } // need neighbor - - { // need pointarea - pointareas.clear(); - pointareas.resize(nv); - cornerareas.clear(); - cornerareas.resize(nf); - - for (int i = 0; i < nf; i++) { - // Edges - ntlVec3Gfx e[3] = { - mPoints[mIndices[i*3+2]].v - mPoints[mIndices[i*3+1]].v, - mPoints[mIndices[i*3+0]].v - mPoints[mIndices[i*3+2]].v, - mPoints[mIndices[i*3+1]].v - mPoints[mIndices[i*3+0]].v }; - - // Compute corner weights - float area = 0.5f * norm( cross(e[0], e[1])); - float l2[3] = { normNoSqrt(e[0]), normNoSqrt(e[1]), normNoSqrt(e[2]) }; - float ew[3] = { l2[0] * (l2[1] + l2[2] - l2[0]), - l2[1] * (l2[2] + l2[0] - l2[1]), - l2[2] * (l2[0] + l2[1] - l2[2]) }; - if (ew[0] <= 0.0f) { - cornerareas[i][1] = -0.25f * l2[2] * area / - dot(e[0] , e[2]); - cornerareas[i][2] = -0.25f * l2[1] * area / - dot(e[0] , e[1]); - cornerareas[i][0] = area - cornerareas[i][1] - - cornerareas[i][2]; - } else if (ew[1] <= 0.0f) { - cornerareas[i][2] = -0.25f * l2[0] * area / - dot(e[1] , e[0]); - cornerareas[i][0] = -0.25f * l2[2] * area / - dot(e[1] , e[2]); - cornerareas[i][1] = area - cornerareas[i][2] - - cornerareas[i][0]; - } else if (ew[2] <= 0.0f) { - cornerareas[i][0] = -0.25f * l2[1] * area / - dot(e[2] , e[1]); - cornerareas[i][1] = -0.25f * l2[0] * area / - dot(e[2] , e[0]); - cornerareas[i][2] = area - cornerareas[i][0] - - cornerareas[i][1]; - } else { - float ewscale = 0.5f * area / (ew[0] + ew[1] + ew[2]); - for (int j = 0; j < 3; j++) - cornerareas[i][j] = ewscale * (ew[(j+1)%3] + - ew[(j+2)%3]); - } - - // FIX T50887: ensure pointareas are finite - if (!isfinite(cornerareas[i][0])) cornerareas[i][0] = 1e-6; - if (!isfinite(cornerareas[i][1])) cornerareas[i][1] = 1e-6; - if (!isfinite(cornerareas[i][2])) cornerareas[i][2] = 1e-6; - - pointareas[mIndices[i*3+0]] += cornerareas[i][0]; - pointareas[mIndices[i*3+1]] += cornerareas[i][1]; - pointareas[mIndices[i*3+2]] += cornerareas[i][2]; - } - - } // need pointarea - // */ - - float invsigma2 = 1.0f / (sigma*sigma); - - vector dflt(nv); - for (int i = 0; i < nv; i++) { - if(diffuseVertexField( &mPoints[0].v, 2, - i, invsigma2, dflt[i])) { - // Just keep the displacement - dflt[i] -= mPoints[i].v; - } else { dflt[i] = 0.0; } //?mPoints[i].v; } - } - - // Slightly better small-neighborhood approximation - for (int i = 0; i < nf; i++) { - ntlVec3Gfx c = mPoints[mIndices[i*3+0]].v + - mPoints[mIndices[i*3+1]].v + - mPoints[mIndices[i*3+2]].v; - c /= 3.0f; - for (int j = 0; j < 3; j++) { - int v = mIndices[i*3+j]; - ntlVec3Gfx d =(c - mPoints[v].v) * 0.5f; - dflt[v] += d * (cornerareas[i][j] / - pointareas[mIndices[i*3+j]] * - exp(-0.5f * invsigma2 * normNoSqrt(d)) ); - } - } - - // Filter displacement field - vector dflt2(nv); - for (int i = 0; i < nv; i++) { - if(diffuseVertexField( &dflt[0], 1, - i, invsigma2, dflt2[i])) { } - else { /*mPoints[i].v=0.0;*/ dflt2[i] = 0.0; }//dflt2[i]; } - } - - // Update vertex positions - for (int i = 0; i < nv; i++) { - mPoints[i].v += dflt[i] - dflt2[i]; // second Laplacian - } - - // when normals smoothing off, this cleans up quite well - // costs ca. 50% additional time though - float nsFac = 1.5f; - if(normSmooth) { float ninvsigma2 = 1.0f / (nsFac*nsFac*sigma*sigma); - for (int i = 0; i < nv; i++) { - if( diffuseVertexField( &mPoints[0].n, 2, i, ninvsigma2, dflt[i]) ) { - normalize(dflt[i]); - } else { - dflt[i] = mPoints[i].n; - } - } - for (int i = 0; i < nv; i++) { - mPoints[i].n = dflt[i]; - } - } // smoothNormals copy */ - - //errMsg("SMSURF","done v:"< numneighbors(mPoints.size()); - int i; - for (i = 0; i < (int)mIndices.size()/3; i++) { - numneighbors[mIndices[i*3+0]]++; - numneighbors[mIndices[i*3+1]]++; - numneighbors[mIndices[i*3+2]]++; - } - - neighbors.clear(); - neighbors.resize(mPoints.size()); - for (i = 0; i < (int)mPoints.size(); i++) { - neighbors[i].clear(); - neighbors[i].reserve(numneighbors[i]+2); // Slop for boundaries - } - - for (i = 0; i < (int)mIndices.size()/3; i++) { - for (int j = 0; j < 3; j++) { - vector &me = neighbors[ mIndices[i*3+j]]; - int n1 = mIndices[i*3+((j+1)%3)]; - int n2 = mIndices[i*3+((j+2)%3)]; - if (std::find(me.begin(), me.end(), n1) == me.end()) - me.push_back(n1); - if (std::find(me.begin(), me.end(), n2) == me.end()) - me.push_back(n2); - } - } - } // need neighbor - - { // need pointarea - int nf = mIndices.size()/3, nv = mPoints.size(); - pointareas.clear(); - pointareas.resize(nv); - cornerareas.clear(); - cornerareas.resize(nf); - - for (int i = 0; i < nf; i++) { - // Edges - ntlVec3Gfx e[3] = { - mPoints[mIndices[i*3+2]].v - mPoints[mIndices[i*3+1]].v, - mPoints[mIndices[i*3+0]].v - mPoints[mIndices[i*3+2]].v, - mPoints[mIndices[i*3+1]].v - mPoints[mIndices[i*3+0]].v }; - - // Compute corner weights - float area = 0.5f * norm( cross(e[0], e[1])); - float l2[3] = { normNoSqrt(e[0]), normNoSqrt(e[1]), normNoSqrt(e[2]) }; - float ew[3] = { l2[0] * (l2[1] + l2[2] - l2[0]), - l2[1] * (l2[2] + l2[0] - l2[1]), - l2[2] * (l2[0] + l2[1] - l2[2]) }; - if (ew[0] <= 0.0f) { - cornerareas[i][1] = -0.25f * l2[2] * area / - dot(e[0] , e[2]); - cornerareas[i][2] = -0.25f * l2[1] * area / - dot(e[0] , e[1]); - cornerareas[i][0] = area - cornerareas[i][1] - - cornerareas[i][2]; - } else if (ew[1] <= 0.0f) { - cornerareas[i][2] = -0.25f * l2[0] * area / - dot(e[1] , e[0]); - cornerareas[i][0] = -0.25f * l2[2] * area / - dot(e[1] , e[2]); - cornerareas[i][1] = area - cornerareas[i][2] - - cornerareas[i][0]; - } else if (ew[2] <= 0.0f) { - cornerareas[i][0] = -0.25f * l2[1] * area / - dot(e[2] , e[1]); - cornerareas[i][1] = -0.25f * l2[0] * area / - dot(e[2] , e[0]); - cornerareas[i][2] = area - cornerareas[i][0] - - cornerareas[i][1]; - } else { - float ewscale = 0.5f * area / (ew[0] + ew[1] + ew[2]); - for (int j = 0; j < 3; j++) - cornerareas[i][j] = ewscale * (ew[(j+1)%3] + - ew[(j+2)%3]); - } - - // FIX T50887: ensure pointareas are finite - if (!isfinite(cornerareas[i][0])) cornerareas[i][0] = 1e-6; - if (!isfinite(cornerareas[i][1])) cornerareas[i][1] = 1e-6; - if (!isfinite(cornerareas[i][2])) cornerareas[i][2] = 1e-6; - - pointareas[mIndices[i*3+0]] += cornerareas[i][0]; - pointareas[mIndices[i*3+1]] += cornerareas[i][1]; - pointareas[mIndices[i*3+2]] += cornerareas[i][2]; - } - - } // need pointarea - - int nv = mPoints.size(); - if ((int)flags.size() != nv) flags.resize(nv); - float invsigma2 = 1.0f / (sigma*sigma); - - vector nflt(nv); - for (int i = 0; i < nv; i++) { - if(diffuseVertexField( &mPoints[0].n, 2, i, invsigma2, nflt[i])) { - normalize(nflt[i]); - } else { nflt[i]=mPoints[i].n; } - } - - // copy results - for (int i = 0; i < nv; i++) { mPoints[i].n = nflt[i]; } -} - - diff --git a/intern/elbeem/intern/isosurface.h b/intern/elbeem/intern/isosurface.h deleted file mode 100644 index 93ea5ecb108..00000000000 --- a/intern/elbeem/intern/isosurface.h +++ /dev/null @@ -1,244 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Marching Cubes "displayer" - * - *****************************************************************************/ - -#ifndef ISOSURFACE_H - -#include "ntl_geometryobject.h" -#include "ntl_bsptree.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -#define ISO_STRICT_DEBUG 0 -#define ISOSTRICT_EXIT *((int *)0)=0; - -/* access some 3d array */ -#define ISOLEVEL_INDEX(ii,ij,ik) ((mSizex*mSizey*(ik))+(mSizex*(ij))+((ii))) - -class ParticleTracer; - -/* struct for a small cube in the scalar field */ -typedef struct { - ntlVec3Gfx pos[8]; - double value[8]; - int i,j,k; -} IsoLevelCube; - - -typedef struct { - ntlVec3Gfx v; // vertex - ntlVec3Gfx n; // vertex normal -} IsoLevelVertex; - -//! class to triangulate a scalar field, e.g. for -// the fluid surface, templated by scalar field access object -class IsoSurface : - public ntlGeometryObject //, public S -{ - - public: - - /*! Constructor */ - IsoSurface(double iso); - /*! Destructor */ - virtual ~IsoSurface(); - - /*! Init ararys etc. */ - virtual void initializeIsosurface(int setx, int sety, int setz, ntlVec3Gfx extent); - - /*! Reset all values */ - void resetAll(gfxReal val); - - /*! triangulate the scalar field given by pointer*/ - void triangulate( void ); - - /*! set particle pointer */ - void setParticles(ParticleTracer *pnt,float psize){ mpIsoParts = pnt; mPartSize=psize; }; - /*! set # of subdivisions, this has to be done before init! */ - void setSubdivs(int s) { - if(mInitDone) errFatal("IsoSurface::setSubdivs","Changing subdivs after init!", SIMWORLD_INITERROR); - if(s<1) s=1; - if(s>10) s=10; - mSubdivs = s; - } - int getSubdivs() { return mSubdivs;} - /*! set full edge settings, this has to be done before init! */ - void setUseFulledgeArrays(bool set) { - if(mInitDone) errFatal("IsoSurface::setUseFulledgeArrays","Changing usefulledge after init!", SIMWORLD_INITERROR); - mUseFullEdgeArrays = set;} - - protected: - - /* variables ... */ - - //! size - int mSizex, mSizey, mSizez; - - //! data pointer - float *mpData; - - //! Level of the iso surface - double mIsoValue; - - //! Store all the triangles vertices - vector mPoints; - - //! use full arrays? (not for farfield) - bool mUseFullEdgeArrays; - //! Store indices of calculated points along the cubie edges - int *mpEdgeVerticesX; - int *mpEdgeVerticesY; - int *mpEdgeVerticesZ; - int mEdgeArSize; - - - //! vector for all the triangles (stored as 3 indices) - vector mIndices; - - //! start and end vectors for the triangulation region to create triangles in - ntlVec3Gfx mStart, mEnd; - - //! normalized domain extent from parametrizer/visualizer - ntlVec3Gfx mDomainExtent; - - //! initialized? - bool mInitDone; - - //! amount of surface smoothing - float mSmoothSurface; - //! amount of normal smoothing - float mSmoothNormals; - - //! grid data - vector mAcrossEdge; - vector< vector > mAdjacentFaces; - - //! cutoff border area - int mCutoff; - //! cutoff height values - int *mCutArray; - //! particle pointer - ParticleTracer *mpIsoParts; - //! particle size - float mPartSize; - //! no of subdivisions - int mSubdivs; - - //! trimesh vars - vector flags; - int mFlagCnt; - vector cornerareas; - vector pointareas; - vector< vector > neighbors; - - public: - // miscelleanous access functions - - //! set geometry start (for renderer) - void setStart(ntlVec3Gfx set) { mStart = set; }; - ntlVec3Gfx getStart() { return mStart; }; - //! set geometry end (for renderer) - void setEnd(ntlVec3Gfx set) { mEnd = set; }; - ntlVec3Gfx getEnd() { return mEnd; }; - //! set iso level value for surface reconstruction - inline void setIsolevel(double set) { mIsoValue = set; }; - //! set loop subdiv num - inline void setSmoothSurface(float set) { mSmoothSurface = set; }; - inline void setSmoothNormals(float set) { mSmoothNormals = set; }; - inline float getSmoothSurface() { return mSmoothSurface; } - inline float getSmoothNormals() { return mSmoothNormals; } - - // geometry object functions - virtual void getTriangles(double t, vector *triangles, - vector *vertices, - vector *normals, int objectId ); - - //! for easy GUI detection get start of axis aligned bounding box, return NULL of no BB - virtual inline ntlVec3Gfx *getBBStart() { return &mStart; } - virtual inline ntlVec3Gfx *getBBEnd() { return &mEnd; } - - //! access data array - inline float* getData(){ return mpData; } - inline float* getData(int ii, int jj, int kk){ -#if ISO_STRICT_DEBUG==1 - if(ii<0){ errMsg("IsoStrict"," invX- |"<mSizex-1){ errMsg("IsoStrict"," invX+ |"<mSizey-1){ errMsg("IsoStrict"," invY+ |"<mSizez-1){ errMsg("IsoStrict"," invZ+ |"<mSizex-1){ errMsg("IsoStrict"," invX+ |"<mSizey-1){ errMsg("IsoStrict"," invY+ |"<mSizez-1){ errMsg("IsoStrict"," invZ+ |"< mDboundary; - float mSCrad1, mSCrad2; - ntlVec3Gfx mSCcenter; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:IsoSurface") -#endif -}; - - -#define ISOSURFACE_H -#endif - - diff --git a/intern/elbeem/intern/loop_tools.h b/intern/elbeem/intern/loop_tools.h deleted file mode 100644 index d1ef03d6667..00000000000 --- a/intern/elbeem/intern/loop_tools.h +++ /dev/null @@ -1,186 +0,0 @@ -/** \file - * \ingroup elbeem - */ - -// advance pointer in main loop -#define ADVANCE_POINTERS(p) \ - ccel += (QCELLSTEP*(p)); \ - tcel += (QCELLSTEP*(p)); \ - pFlagSrc+= (p); \ - pFlagDst+= (p); \ - i+= (p); - -#define MAX_CALC_ARR 4 - -// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -// init region vars -#define GRID_REGION_INIT() \ - const int istart = -1+gridLoopBound; \ - const int iend = mLevel[mMaxRefine].lSizex-1-gridLoopBound; \ - LbmFloat calcCurrentMass=0; \ - LbmFloat calcCurrentVolume=0; \ - int calcCellsFilled=0; \ - int calcCellsEmptied=0; \ - int calcNumUsedCells=0; \ - /* This is a generic macro, and now all it's users are using all variables. */ \ - (void)calcCurrentMass; \ - (void)calcCellsFilled \ - - - - -// ----------------------------------------------------------------------------------- -// serial stuff -#if PARALLEL!=1 - -#define PERFORM_USQRMAXCHECK USQRMAXCHECK(usqr,ux,uy,uz, mMaxVlen, mMxvx,mMxvy,mMxvz); -#define LIST_EMPTY(x) mListEmpty.push_back( x ); -#define LIST_FULL(x) mListFull.push_back( x ); -#define FSGR_ADDPART(x) mpParticles->addFullParticle( x ); - -// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -#define GRID_REGION_START() \ - { /* main_region */ \ - int kstart=getForZMinBnd(), kend=getForZMaxBnd(mMaxRefine); \ - if(gridLoopBound>0){ kstart=getForZMin1(), kend=getForZMax1(mMaxRefine); } \ - int kdir = 1; \ - int jstart = gridLoopBound; \ - int jend = mLevel[mMaxRefine].lSizey-gridLoopBound; \ - const int id=0; \ - LbmFloat *ccel = NULL, *tcel = NULL; \ - CellFlagType *pFlagSrc=NULL, *pFlagDst=NULL; \ - if(mLevel[mMaxRefine].setCurr==1) { \ - kdir = -1; \ - int temp = kend; \ - kend = kstart-1; \ - kstart = temp-1; \ - temp = id; /* dummy remove warning */ \ - } \ - - - - - -// ----------------------------------------------------------------------------------- -#else // PARALLEL==1 - -//#include "paraloop.h" -#define PERFORM_USQRMAXCHECK USQRMAXCHECK(usqr,ux,uy,uz, calcMaxVlen, calcMxvx,calcMxvy,calcMxvz); -#define LIST_EMPTY(x) calcListEmpty.push_back( x ); -#define LIST_FULL(x) calcListFull.push_back( x ); -#define FSGR_ADDPART(x) calcListParts.push_back( x ); - - -// parallel region -//was: # pragma omp parallel default(shared) -#if COMPRESSGRIDS!=1 - // requires compressed grids...! - ERROR! -#endif - -// loop start -#define GRID_REGION_START() \ - { \ - \ - \ - if(mSizez<2) { \ - mPanic = 1; \ - errFatal("ParaLoop::2D","Not valid...!", SIMWORLD_GENERICERROR); \ - } \ - \ - \ - vector calcListFull; \ - vector calcListEmpty; \ - vector calcListParts; \ - LbmFloat calcMxvx, calcMxvy, calcMxvz, calcMaxVlen; \ - calcMxvx = calcMxvy = calcMxvz = calcMaxVlen = 0.0; \ - calcListEmpty.reserve(mListEmpty.capacity() / omp_get_num_threads() ); \ - calcListFull.reserve( mListFull.capacity() / omp_get_num_threads() ); \ - calcListParts.reserve(mSizex); \ - \ - \ - const int id = omp_get_thread_num(); \ - const int Nthrds = omp_get_num_threads(); \ - \ - \ - \ - \ - \ - int kdir = 1; \ - \ - int kstart=getForZMinBnd(), kend=getForZMaxBnd(mMaxRefine); \ - if(gridLoopBound>0){ kstart=getForZMin1(); kend=getForZMax1(mMaxRefine); } \ - LbmFloat *ccel = NULL, *tcel = NULL; \ - CellFlagType *pFlagSrc=NULL, *pFlagDst=NULL; \ - \ - \ - if(mLevel[mMaxRefine].setCurr==1) { \ - kdir = -1; \ - int temp = kend; \ - kend = kstart-1; \ - kstart = temp-1; \ - } \ - \ - const int Nj = mLevel[mMaxRefine].lSizey; \ - int jstart = 0+( (id * Nj ) / Nthrds ); \ - int jend = 0+(((id+1) * Nj ) / Nthrds ); \ - if( ((Nj/Nthrds) *Nthrds) != Nj) { \ - errMsg("LbmFsgrSolver","Invalid domain size Nj="<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -#define GRID_LOOP_START() \ - for(int k=kstart;k!=kend;k+=kdir) { \ - pFlagSrc = &RFLAG(lev, istart, jstart, k, SRCS(lev)); \ - pFlagDst = &RFLAG(lev, istart, jstart, k, TSET(lev)); \ - ccel = RACPNT(lev, istart, jstart, k, SRCS(lev)); \ - tcel = RACPNT(lev, istart, jstart, k, TSET(lev)); \ - for(int j=jstart;j!=jend;++j) { \ - /* for(int i=0;i>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -#define GRID_LOOPREG_END() \ - \ - } /* i */ \ - int i=0; \ - ADVANCE_POINTERS(2*gridLoopBound); \ - } /* j */ \ - /* COMPRESSGRIDS!=1 */ \ - /* int i=0; */ \ - /* ADVANCE_POINTERS(mLevel[lev].lSizex*2); */ \ - } /* all cell loop k,j,i */ \ - if(doReduce) { } /* dummy remove warning */ \ - } /* main_region */ \ - \ - - - - -// old loop for COMPRESSGRIDS==0 -#define old__GRID_LOOP_START() \ - for(int k=kstart;k -#include - -#if defined(_MSC_VER) && _MSC_VER > 1600 -// std::greater -#include -#endif - - -using std::vector; -using std::isfinite; - -void MeanValueMeshCoords::clear() -{ - mVertices.resize(0); - mNumVerts = 0; -} - -void MeanValueMeshCoords::calculateMVMCs(vector &reference_vertices, vector &tris, - vector &points, gfxReal numweights) -{ - clear(); - mvmTransferPoint tds; - int mem = 0; - int i = 0; - - mNumVerts = (int)reference_vertices.size(); - - for (vector::iterator iter = points.begin(); iter != points.end(); ++iter, ++i) { - /* - if(i%(points.size()/10)==1) debMsgStd("MeanValueMeshCoords::calculateMVMCs",DM_MSG,"Computing weights, points: "< &reference_vertices, vector& tris, - mvmTransferPoint& tds, gfxReal numweights) -{ - const bool mvmFullDebug=false; - //const ntlVec3Gfx cEPS = 1.0e-6; - const mvmFloat cEPS = 1.0e-14; - - //mvmFloat d[3], s[3], phi[3],c[3]; - ntlVec3d u[3],c,d,s,phi; - int indices[3]; - - for (int i = 0; i < (int)reference_vertices.size(); ++i) { - tds.weights.push_back(mvmIndexWeight(i, 0.0)); - } - - // for each triangle - //for (vector::iterator iter = tris.begin(); iter != tris.end();) { - for(int t=0; t<(int)tris.size(); t++) { - - for (int i = 0; i < 3; ++i) { //, ++iter) { - indices[i] = tris[t].getPoints()[i]; - u[i] = vec2D(reference_vertices[ indices[i] ]-tds.lastpos); - d[i] = normalize(u[i]); //.normalize(); - //assert(d[i] != 0.); - if(mvmFullDebug) errMsg("MeanValueMeshCoords::computeWeights","t"< ignore it"); - continue; - } - const mvmFloat u0x = u[0][0]; - const mvmFloat u0y = u[0][1]; - const mvmFloat u0z = u[0][2]; - const mvmFloat u1x = u[1][0]; - const mvmFloat u1y = u[1][1]; - const mvmFloat u1z = u[1][2]; - const mvmFloat u2x = u[2][0]; - const mvmFloat u2y = u[2][1]; - const mvmFloat u2z = u[2][2]; - mvmFloat det = u0x*u1y*u2z - u0x*u1z*u2y + u0y*u1z*u2x - u0y*u1x*u2z + u0z*u1x*u2y - u0z*u1y*u2x; - //assert(det != 0.); - if (det < 0.) { - s[0] = -s[0]; - s[1] = -s[1]; - s[2] = -s[2]; - } - - tds.weights[indices[0]].weight += (phi[0]-c[1]*phi[2]-c[2]*phi[1])/(d[0]*sin(phi[1])*s[2]); - tds.weights[indices[1]].weight += (phi[1]-c[2]*phi[0]-c[0]*phi[2])/(d[1]*sin(phi[2])*s[0]); - tds.weights[indices[2]].weight += (phi[2]-c[0]*phi[1]-c[1]*phi[0])/(d[2]*sin(phi[0])*s[1]); - if(mvmFullDebug) { errMsg("MeanValueMeshCoords::computeWeights","i"<0.)&& (numweights<1.) ) { - //if( ((int)tds.weights.size() > maxNumWeights) && (maxNumWeights > 0) ) { - int maxNumWeights = (int)(tds.weights.size()*numweights); - if(maxNumWeights<=0) maxNumWeights = 1; - std::sort(tds.weights.begin(), tds.weights.end(), std::greater()); - // only use maxNumWeights-th largest weights - tds.weights.resize(maxNumWeights); - } - - // normalize weights - mvmFloat totalWeight = 0.; - for (vector::const_iterator witer = tds.weights.begin(); - witer != tds.weights.end(); ++witer) { - totalWeight += witer->weight; - } - mvmFloat invTotalWeight; - if (totalWeight == 0.) { - if(mvmFullDebug) errMsg("MeanValueMeshCoords::computeWeights","totalWeight == 0"); - invTotalWeight = 0.0; - } else { - invTotalWeight = 1.0/totalWeight; - } - - for (vector::iterator viter = tds.weights.begin(); - viter != tds.weights.end(); ++viter) { - viter->weight *= invTotalWeight; - //assert(isfinite(viter->weight) != 0); - if(!isfinite(viter->weight)) viter->weight=0.; - } -} - -void MeanValueMeshCoords::transfer(vector &vertices, vector& displacements) -{ - displacements.resize(0); - - //debMsgStd("MeanValueMeshCoords::transfer",DM_MSG,"vertices:"<::iterator titer = mVertices.begin(); titer != mVertices.end(); ++titer) { - mvmTransferPoint &tds = *titer; - ntlVec3Gfx newpos(0.0); - - for (vector::iterator witer = tds.weights.begin(); - witer != tds.weights.end(); ++witer) { - newpos += vertices[witer->index] * witer->weight; - //errMsg("transfer","np"<index]<<" w"<< witer->weight); - } - - displacements.push_back(newpos); - //displacements.push_back(newpos - tds.lastpos); - //tds.lastpos = newpos; - } -} - diff --git a/intern/elbeem/intern/mvmcoords.h b/intern/elbeem/intern/mvmcoords.h deleted file mode 100644 index d00215ebd0e..00000000000 --- a/intern/elbeem/intern/mvmcoords.h +++ /dev/null @@ -1,108 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * -// El'Beem - the visual lattice boltzmann freesurface simulator -// All code distributed as part of El'Beem is covered by the version 2 of the -// GNU General Public License. See the file COPYING for details. -// -// Copyright 2008 Nils Thuerey , Richard Keiser, Mark Pauly, Ulrich Ruede -// - * - * Mean Value Mesh Coords class - * - *****************************************************************************/ - -#ifndef MVMCOORDS_H -#define MVMCOORDS_H - -#include "utilities.h" -#include "ntl_ray.h" -#include -#define mvmFloat double - -#ifdef WIN32 -#include "float.h" -#define isnan(n) _isnan(n) -#define finite _finite -#endif - -#ifdef sun -#include "ieeefp.h" -#endif - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -// weight and triangle index -class mvmIndexWeight { - public: - - mvmIndexWeight() : weight(0.0) {} - - mvmIndexWeight(int const& i, mvmFloat const& w) : - weight(w), index(i) {} - - // for sorting - bool operator> (mvmIndexWeight const& w) const { return this->weight > w.weight; } - bool operator< (mvmIndexWeight const& w) const { return this->weight < w.weight; } - - mvmFloat weight; - int index; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:mvmIndexWeight") -#endif -}; - -// transfer point with weights -class mvmTransferPoint { - public: - //! position of transfer point - ntlVec3Gfx lastpos; - //! triangle weights - std::vector weights; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:mvmTransferPoint") -#endif -}; - - -//! compute mvmcs -class MeanValueMeshCoords { - - public: - - MeanValueMeshCoords() {} - ~MeanValueMeshCoords() { - clear(); - } - - void clear(); - - void calculateMVMCs(std::vector &reference_vertices, - std::vector &tris, std::vector &points, gfxReal numweights); - - void transfer(std::vector &vertices, std::vector& displacements); - - protected: - - void computeWeights(std::vector &reference_vertices, - std::vector &tris, mvmTransferPoint& tds, gfxReal numweights); - - std::vector mVertices; - int mNumVerts; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:MeanValueMeshCoords") -#endif -}; - -#endif - diff --git a/intern/elbeem/intern/ntl_blenderdumper.cpp b/intern/elbeem/intern/ntl_blenderdumper.cpp deleted file mode 100644 index eca184ae717..00000000000 --- a/intern/elbeem/intern/ntl_blenderdumper.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Replaces std. raytracer, and only dumps time dep. objects to disc - * - *****************************************************************************/ - -#include -#include - -#include "utilities.h" -#include "ntl_matrices.h" -#include "ntl_blenderdumper.h" -#include "ntl_world.h" -#include "solver_interface.h" -#include "globals.h" - -#include - -#ifdef LBM_GZIP_OVERRIDE_H -# include LBM_GZIP_OVERRIDE_H -#else -# define LBM_GZIP_OPEN_FN(a, b) gzopen(a, b) -#endif - -/****************************************************************************** - * Constructor - *****************************************************************************/ -ntlBlenderDumper::ntlBlenderDumper() : ntlWorld() -{ - // same as normal constructor here -} -ntlBlenderDumper::ntlBlenderDumper(string filename, bool commandlineMode) : - ntlWorld(filename,commandlineMode) -{ - // init world -} - - - -/****************************************************************************** - * Destructor - *****************************************************************************/ -ntlBlenderDumper::~ntlBlenderDumper() -{ - debMsgStd("ntlBlenderDumper",DM_NOTIFY, "ntlBlenderDumper done", 10); -} - -/****************************************************************************** - * Only dump time dep. objects to file - *****************************************************************************/ -int ntlBlenderDumper::renderScene( void ) -{ - char nrStr[5]; /* nr conversion */ - ntlRenderGlobals *glob = mpGlob; - ntlScene *scene = mpGlob->getSimScene(); - bool debugOut = false; - bool debugRender = false; -#if ELBEEM_PLUGIN==1 - debugOut = false; -#endif // ELBEEM_PLUGIN==1 - - vector gmName; // gm names - vector gmMat; // materials for gm - int numGMs = 0; // no. of .obj models created - - if(debugOut) debMsgStd("ntlBlenderDumper::renderScene",DM_NOTIFY,"Dumping geometry data", 1); - long startTime = getTime(); - snprintf(nrStr, 5, "%04d", glob->getAniCount() ); - - // local scene vars - vector Triangles; - vector Vertices; - vector VertNormals; - - // check geo objects - int idCnt = 0; // give IDs to objects - for (vector::iterator iter = scene->getGeoClasses()->begin(); - iter != scene->getGeoClasses()->end(); iter++) { - if(!(*iter)->getVisible()) continue; - int tid = (*iter)->getTypeId(); - - if(tid & GEOCLASSTID_OBJECT) { - // normal geom. objects -> ignore - } - if(tid & GEOCLASSTID_SHADER) { - ntlGeometryShader *geoshad = (ntlGeometryShader*)(*iter); //dynamic_cast(*iter); - string outname = geoshad->getOutFilename(); - if(outname.length()<1) outname = mpGlob->getOutFilename(); - geoshad->notifyShaderOfDump(DUMP_FULLGEOMETRY, glob->getAniCount(),nrStr,outname); - - for (vector::iterator siter = geoshad->getObjectsBegin(); - siter != geoshad->getObjectsEnd(); - siter++) { - if(debugOut) debMsgStd("ntlBlenderDumper::BuildScene",DM_MSG,"added shader geometry "<<(*siter)->getName(), 8); - - (*siter)->notifyOfDump(DUMP_FULLGEOMETRY, glob->getAniCount(),nrStr,outname, this->mSimulationTime); - bool doDump = false; - bool isPreview = false; - // only dump final&preview surface meshes - if( (*siter)->getName().find( "final" ) != string::npos) { - doDump = true; - } else if( (*siter)->getName().find( "preview" ) != string::npos) { - doDump = true; - isPreview = true; - } - if(!doDump) continue; - - // dont quit, some objects need notifyOfDump call - if((glob_mpactive) && (glob_mpindex>0)) { - continue; //return 0; - } - - // only dump geo shader objects - Triangles.clear(); - Vertices.clear(); - VertNormals.clear(); - (*siter)->initialize( mpGlob ); - (*siter)->getTriangles(this->mSimulationTime, &Triangles, &Vertices, &VertNormals, idCnt); - idCnt ++; - - // WARNING - this is dirty, but simobjs are the only geoshaders right now - SimulationObject *sim = (SimulationObject *)geoshad; - LbmSolverInterface *lbm = sim->getSolver(); - - - // always dump mesh, even empty ones... - - // dump to binary file - std::ostringstream boutfilename(""); - //boutfilename << ecrpath.str() << outname <<"_"<< (*siter)->getName() <<"_" << nrStr << ".obj"; - boutfilename << outname <<"_"<< (*siter)->getName() <<"_" << nrStr; - if(debugOut) debMsgStd("ntlBlenderDumper::renderScene",DM_MSG,"B-Dumping: "<< (*siter)->getName() - <<", triangles:"<getDumpVelocities())) { - std::ostringstream bvelfilename; - bvelfilename << boutfilename.str(); - bvelfilename << ".bvel.gz"; - /* wraps gzopen */ - gzf = LBM_GZIP_OPEN_FN(bvelfilename.str().c_str(), "wb9"); - if(gzf) { - int numVerts; - if(sizeof(numVerts)!=4) { errMsg("ntlBlenderDumper::renderScene","Invalid int size"); return 1; } - numVerts = Vertices.size(); - gzwrite(gzf, &numVerts, sizeof(numVerts)); - for(size_t i=0; igetVelocityAt( Vertices[i][0], Vertices[i][1], Vertices[i][2] ); - // translation not necessary, test rotation & scaling? - for(int j=0; j<3; j++) { - float vertp = v[j]; - //if(i<20) errMsg("ntlBlenderDumper","DUMP_VEL final "< *trafo; - trafo = lbm->getDomainTrafo(); - if(trafo) { - // transform into source space - for(size_t i=0; i rottrafo; - rottrafo.initId(); - if(lbm->getDomainTrafo()) { - // dont modifiy original! - rottrafo = *lbm->getDomainTrafo(); - ntlVec3Gfx rTrans,rScale,rRot,rShear; - rottrafo.decompose(rTrans,rScale,rRot,rShear); - rottrafo.initRotationXYZ(rRot[0],rRot[1],rRot[2]); - // only rotate here... - for(size_t i=0; i0) { - if(debugOut) debMsgStd("ntlBlenderDumper::renderScene",DM_MSG,"Objects dumped: "<0)) { - // ok, nothing to do anyway... - } else { - errFatal("ntlBlenderDumper::renderScene","No objects to dump! Aborting...",SIMWORLD_INITERROR); - return 1; - } - } - - // debug timing - long stopTime = getTime(); - debMsgStd("ntlBlenderDumper::renderScene",DM_MSG,"Scene #"<setAniCount( glob->getAniCount() +1 ); - } - - return 0; -} - - - diff --git a/intern/elbeem/intern/ntl_blenderdumper.h b/intern/elbeem/intern/ntl_blenderdumper.h deleted file mode 100644 index e3c0e3df12b..00000000000 --- a/intern/elbeem/intern/ntl_blenderdumper.h +++ /dev/null @@ -1,42 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Replaces std. raytracer, and only dumps time dep. objects to disc, header - * - *****************************************************************************/ -#ifndef NTL_BLENDERDUMPER_H -#include "ntl_world.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -class ntlBlenderDumper : - public ntlWorld -{ -public: - /*! Constructor */ - ntlBlenderDumper(); - ntlBlenderDumper(string filename, bool commandlineMode); - /*! Destructor */ - virtual ~ntlBlenderDumper( void ); - - /*! render scene (a single pictures) */ - virtual int renderScene( void ); - -protected: - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlBlenderDumper") -#endif -}; - -#define NTL_BLENDERDUMPER_H -#endif - diff --git a/intern/elbeem/intern/ntl_bsptree.cpp b/intern/elbeem/intern/ntl_bsptree.cpp deleted file mode 100644 index 8d589e50cb4..00000000000 --- a/intern/elbeem/intern/ntl_bsptree.cpp +++ /dev/null @@ -1,945 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Tree container for fast triangle intersects - * - *****************************************************************************/ - - -#include "ntl_bsptree.h" -#include "utilities.h" - -#include - -/*! Static global variable for sorting direction */ -int globalSortingAxis; -/*! Access to points array for sorting */ -vector *globalSortingPoints; - -#define TREE_DOUBLEI 300 - -/* try axis selection? */ -bool chooseAxis = 0; -/* do median search? */ -int doSort = 0; - - -//! struct for a single node in the bsp tree -class BSPNode { - public: - BSPNode() {}; - - ntlVec3Gfx min,max; /* AABB for node */ - vector *members; /* stored triangles */ - BSPNode *child[2]; /* pointer to children nodes */ - char axis; /* division axis */ - char cloneVec; /* is this vector a clone? */ - - //! check if node is a leaf - inline bool isLeaf() const { - return (child[0] == NULL); - } -}; - - -//! an element node stack -class BSPStackElement { - public: - //! tree node - BSPNode *node; - //! min and maximum distance along axis - gfxReal mindist, maxdist; -}; - -//! bsp tree stack -class BSPStack { - public: - //! current stack element - int stackPtr; - //! stack storage - BSPStackElement elem[ BSP_STACK_SIZE ]; -}; - -//! triangle bounding box for quick tree subdivision -class TriangleBBox { - public: - //! start and end of triangle bounding box - ntlVec3Gfx start, end; -}; - - -/****************************************************************************** - * calculate tree statistics - *****************************************************************************/ -void calcStats(BSPNode *node, int depth, int &noLeafs, gfxReal &avgDepth, gfxReal &triPerLeaf,int &totalTris) -{ - if(node->members != NULL) { - totalTris += node->members->size(); - } - //depth = 15; // DBEUG! - - if( (node->child[0]==NULL) && (node->child[1]==NULL) ) { - // leaf - noLeafs++; - avgDepth += depth; - triPerLeaf += node->members->size(); - } else { - for(int i=0;i<2;i++) - calcStats(node->child[i], depth+1, noLeafs, avgDepth, triPerLeaf, totalTris); - } -} - - - -/****************************************************************************** - * triangle comparison function for median search - *****************************************************************************/ -bool lessTriangleAverage(const ntlTriangle *x, const ntlTriangle *y) -{ - return x->getAverage(globalSortingAxis) < y->getAverage(globalSortingAxis); -} - - -/****************************************************************************** - * triangle AABB intersection - *****************************************************************************/ -bool ntlTree::checkAABBTriangle(ntlVec3Gfx &min, ntlVec3Gfx &max, ntlTriangle *tri) -{ - // test only BB of triangle - TriangleBBox *bbox = &mpTBB[ tri->getBBoxId() ]; - if( bbox->end[0] < min[0] ) return false; - if( bbox->start[0] > max[0] ) return false; - if( bbox->end[1] < min[1] ) return false; - if( bbox->start[1] > max[1] ) return false; - if( bbox->end[2] < min[2] ) return false; - if( bbox->start[2] > max[2] ) return false; - return true; -} - - - - - - - -/****************************************************************************** - * Default constructor - *****************************************************************************/ -ntlTree::ntlTree() : - mStart(0.0), mEnd(0.0), mMaxDepth( 5 ), mMaxListLength( 5 ), mpRoot( NULL) , - mpNodeStack( NULL), mpVertices( NULL ), mpVertNormals( NULL ), mpTriangles( NULL ), - mCurrentDepth(0), mCurrentNodes(0), mTriDoubles(0) -{ - errFatal( "ntlTree","Uninitialized BSP Tree!\n",SIMWORLD_INITERROR ); - return; -} - - -/****************************************************************************** - * Constructor with init - *****************************************************************************/ -//ntlTree::ntlTree(int depth, int objnum, vector *vertices, vector *normals, vector *trilist) : -ntlTree::ntlTree(int depth, int objnum, ntlScene *scene, int triFlagMask) : - mStart(0.0), mEnd(0.0), mMaxDepth( depth ), mMaxListLength( objnum ), mpRoot( NULL) , - mpNodeStack( NULL), mpTBB( NULL ), - mTriangleMask( 0xFFFF ), - mCurrentDepth(0), mCurrentNodes(0), mTriDoubles(0) -{ - // init scene data pointers - mpVertices = scene->getVertexPointer(); - mpVertNormals = scene->getVertexNormalPointer(); - mpTriangles = scene->getTrianglePointer(); - mTriangleMask = triFlagMask; - - if(mpTriangles == NULL) { - errFatal( "ntlTree Cons","no triangle list!\n",SIMWORLD_INITERROR); - return; - } - if(mpTriangles->size() == 0) { - warnMsg( "ntlTree::ntlTree","No triangles ("<< mpTriangles->size() <<")!\n"); - mStart = mEnd = ntlVec3Gfx(0,0,0); - return; - } - if(depth>=BSP_STACK_SIZE) { - errFatal( "ntlTree::ntlTree","Depth to high ("<< mMaxDepth <<")!\n", SIMWORLD_INITERROR ); - return; - } - - /* check triangles (a bit inefficient, but we dont know which vertices belong - to this tree), and generate bounding boxes */ - mppTriangles = new vector; - int noOfTriangles = mpTriangles->size(); - mpTBB = new TriangleBBox[ noOfTriangles ]; - int bbCount = 0; - mStart = mEnd = (*mpVertices)[ mpTriangles->front().getPoints()[0] ]; - //errMsg("TreeDebug","Start"); - for (vector::iterator iter = mpTriangles->begin(); - iter != mpTriangles->end(); - iter++ ) { - //errorOut(" d "<< convertFlags2String((int)(*iter).getFlags()) <<" "<< convertFlags2String( (int)mTriangleMask)<<" add? "<<( ((int)(*iter).getFlags() & (int)mTriangleMask) != 0 ) ); - // discard triangles that dont match mask - if( ((int)(*iter).getFlags() & (int)mTriangleMask) == 0 ) { - continue; - } - - // test? TODO - ntlVec3Gfx tnormal = (*mpVertNormals)[ (*iter).getPoints()[0] ]+ - (*mpVertNormals)[ (*iter).getPoints()[1] ]+ - (*mpVertNormals)[ (*iter).getPoints()[2] ]; - ntlVec3Gfx triangleNormal = (*iter).getNormal(); - if( equal(triangleNormal, ntlVec3Gfx(0.0)) ) continue; - if( equal( tnormal, ntlVec3Gfx(0.0)) ) continue; - // */ - - ntlVec3Gfx bbs, bbe; - //errMsg("TreeDebug","Triangle"); - for(int i=0;i<3;i++) { - int index = (*iter).getPoints()[i]; - ntlVec3Gfx tp = (*mpVertices)[ index ]; - //errMsg("TreeDebug"," Point "< mEnd[0]) mEnd[0]= tp[0]; - if(tp[1] < mStart[1]) mStart[1]= tp[1]; - if(tp[1] > mEnd[1]) mEnd[1]= tp[1]; - if(tp[2] < mStart[2]) mStart[2]= tp[2]; - if(tp[2] > mEnd[2]) mEnd[2]= tp[2]; - if(i==0) { - bbs = bbe = tp; - } else { - if( tp[0] < bbs[0] ) bbs[0] = tp[0]; - if( tp[0] > bbe[0] ) bbe[0] = tp[0]; - if( tp[1] < bbs[1] ) bbs[1] = tp[1]; - if( tp[1] > bbe[1] ) bbe[1] = tp[1]; - if( tp[2] < bbs[2] ) bbs[2] = tp[2]; - if( tp[2] > bbe[2] ) bbe[2] = tp[2]; - } - } - mppTriangles->push_back( &(*iter) ); - //errMsg("TreeDebug","Triangle "<<(*mpVertices)[(*iter).getPoints()[0]]<<" "<<(*mpVertices)[(*iter).getPoints()[1]]<<" "<<(*mpVertices)[(*iter).getPoints()[2]]<<" "); - - // add BB - mpTBB[ bbCount ].start = bbs; - mpTBB[ bbCount ].end = bbe; - (*iter).setBBoxId( bbCount ); - bbCount++; - } - - - - /* slighlty enlarge bounding tolerance for tree - to avoid problems with triangles paralell to slabs */ - mStart -= ntlVec3Gfx( getVecEpsilon() ); - mEnd += ntlVec3Gfx( getVecEpsilon() ); - - /* init root node and stack */ - mpNodeStack = new BSPStack; - mpRoot = new BSPNode; - mpRoot->min = mStart; - mpRoot->max = mEnd; - mpRoot->axis = AXIS_X; - mpRoot->members = mppTriangles; - mpRoot->child[0] = mpRoot->child[1] = NULL; - mpRoot->cloneVec = 0; - globalSortingPoints = mpVertices; - mpTriDist = new char[ mppTriangles->size() ]; - mNumNodes = 1; - mAbortSubdiv = 0; - - /* create tree */ - debugOutInter( "Generating BSP Tree... (Nodes "<< mCurrentNodes << - ", Depth "<members->size() <<" "<min<<" - "<max ); - - if(depth>mCurrentDepth) mCurrentDepth = depth; - node->child[0] = node->child[1] = NULL; - if( ( (int)node->members->size() > mMaxListLength) && - (depth < mMaxDepth ) - && (node->cloneVec<10) - && (!mAbortSubdiv) - ) { - - gfxReal planeDiv = 0.499999; // position of plane division - - // determine next subdivision axis - int newaxis = 0; - gfxReal extX = node->max[0]-node->min[0]; - gfxReal extY = node->max[1]-node->min[1]; - gfxReal extZ = node->max[2]-node->min[2]; - - if( extY>extX ) { - if( extZ>extY ) { - newaxis = 2; - } else { - newaxis = 1; - } - } else { - if( extZ>extX ) { - newaxis = 2; - } else { - newaxis = 0; - } - } - axis = node->axis = newaxis; - - // init child nodes - for( int i=0; i<2; i++) { - /* status output */ - mCurrentNodes++; - if(mCurrentNodes % 13973 ==0) { - debugOutInter( "NTL Generating BSP Tree ("<child[i] = new BSPNode; - node->child[i]->min = node->min; - node->child[i]->max = node->max; - node->child[i]->max = node->max; - node->child[i]->child[0] = NULL; - node->child[i]->child[1] = NULL; - node->child[i]->members = NULL; - nextAxis = (axis+1)%3; - node->child[i]->axis = nextAxis; - mNumNodes++; - // abort when using 256MB only for tree... - if(mNumNodes*sizeof(BSPNode)> 1024*1024*512) mAbortSubdiv = 1; - - /* current division plane */ - if(!i) { - node->child[i]->min[axis] = node->min[axis]; - node->child[i]->max[axis] = node->min[axis] + planeDiv* - (node->max[axis]-node->min[axis]); - } else { - node->child[i]->min[axis] = node->min[axis] + planeDiv* - (node->max[axis]-node->min[axis]); - node->child[i]->max[axis] = node->max[axis]; - } - } - - - /* process the two children */ - int thisTrisFor[2] = {0,0}; - int thisTriDoubles[2] = {0,0}; - for(int t=0;t<(int)node->members->size();t++) mpTriDist[t] = 0; - for( int i=0; i<2; i++) { - /* distribute triangles */ - int t = 0; - for (vector::iterator iter = node->members->begin(); - iter != node->members->end(); iter++ ) { - - /* add triangle, check bounding box axis */ - TriangleBBox *bbox = &mpTBB[ (*iter)->getBBoxId() ]; - bool isintersect = true; - if( bbox->end[axis] < node->child[i]->min[axis] ) isintersect = false; - else if( bbox->start[axis] > node->child[i]->max[axis] ) isintersect = false; - if(isintersect) { - // add flag to vector - mpTriDist[t] |= (1<child[i]->members = new vector( thisTrisFor[i] ); - node->child[i]->cloneVec = 0; - } - - int tind0 = 0; - int tind1 = 0; - if( (!haveCloneVec[0]) || (!haveCloneVec[1]) ){ - int t = 0; // triangle index counter - for (vector::iterator iter = node->members->begin(); - iter != node->members->end(); iter++ ) { - if(!haveCloneVec[0]) { - if( (mpTriDist[t] & 1) == 1) { - (*node->child[0]->members)[tind0] = (*iter); // dont use push_back for preinited size! - tind0++; - } - } - if(!haveCloneVec[1]) { - if( (mpTriDist[t] & 2) == 2) { - (*node->child[1]->members)[tind1] = (*iter); // dont use push_back for preinited size! - tind1++; - } - } - t++; - } /* end of loop over all triangles */ - } - - // subdivide children - for( int i=0; i<2; i++) { - /* recurse */ - subdivide( node->child[i], depth+1, nextAxis ); - } - - /* if we are here, this are childs, so we dont need the members any more... */ - /* delete unecessary members */ - if( (!haveCloneVec[0]) && (!haveCloneVec[1]) && (node->cloneVec == 0) ){ - delete node->members; - } - node->members = NULL; - - } /* subdivision necessary */ -} - -/****************************************************************** - * triangle intersection with triangle pointer, - * returns t,u,v by references - */ -#if GFX_PRECISION==1 -// float values -//! the minimal triangle determinant length -#define RAY_TRIANGLE_EPSILON (1e-07) - -#else -// double values -//! the minimal triangle determinant length -#define RAY_TRIANGLE_EPSILON (1e-15) - -#endif - - -/****************************************************************************** - * intersect ray with BSPtree - *****************************************************************************/ -inline void ntlRay::intersectTriangle(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const -{ - /* (cf. moeller&haines, page 305) */ - t = GFX_REAL_MAX; - ntlVec3Gfx e0 = (*mpV)[ tri->getPoints()[0] ]; - ntlVec3Gfx e1 = (*mpV)[ tri->getPoints()[1] ] - e0; - ntlVec3Gfx e2 = (*mpV)[ tri->getPoints()[2] ] - e0; - ntlVec3Gfx p = cross( mDirection, e2 ); - gfxReal divisor = dot(e1, p); - if((divisor > -RAY_TRIANGLE_EPSILON)&&(divisor < RAY_TRIANGLE_EPSILON)) return; - - gfxReal invDivisor = 1/divisor; - ntlVec3Gfx s = mOrigin - e0; - u = invDivisor * dot(s, p); - if( (u<0.0-RAY_TRIANGLE_EPSILON) || (u>1.0+RAY_TRIANGLE_EPSILON) ) return; - - ntlVec3Gfx q = cross( s,e1 ); - v = invDivisor * dot(mDirection, q); - if( (v<0.0-RAY_TRIANGLE_EPSILON) || ((u+v)>1.0+RAY_TRIANGLE_EPSILON) ) return; - - t = invDivisor * dot(e2, q); -} -void ntlTree::intersect(const ntlRay &ray, gfxReal &distance, - ntlVec3Gfx &normal, - ntlTriangle *&tri, - int flags, bool forceNonsmooth) const -{ - gfxReal mint = GFX_REAL_MAX; /* current minimal t */ - ntlVec3Gfx retnormal; /* intersection (interpolated) normal */ - gfxReal mintu=0.0, mintv=0.0; /* u,v for min t intersection */ - - BSPNode *curr, *nearChild, *farChild; /* current node and children */ - gfxReal planedist, mindist, maxdist; - ntlVec3Gfx pos; - - ntlTriangle *hit = NULL; - tri = NULL; - - ray.intersectCompleteAABB(mStart,mEnd,mindist,maxdist); - - if((maxdist < 0.0) || - (!mpRoot) || - (mindist == GFX_REAL_MAX) || - (maxdist == GFX_REAL_MAX) ) { - distance = -1.0; - return; - } - mindist -= getVecEpsilon(); - maxdist += getVecEpsilon(); - - /* stack init */ - mpNodeStack->elem[0].node = NULL; - mpNodeStack->stackPtr = 1; - - curr = mpRoot; - mint = GFX_REAL_MAX; - while(curr != NULL) { - - while( !curr->isLeaf() ) { - planedist = distanceToPlane(curr, curr->child[0]->max, ray ); - getChildren(curr, ray.getOrigin(), nearChild, farChild ); - - // check ray direction for small plane distances - if( (planedist>-getVecEpsilon() )&&(planedist< getVecEpsilon() ) ) { - // ray origin on intersection plane - planedist = 0.0; - if(ray.getDirection()[curr->axis]>getVecEpsilon() ) { - // larger coords - curr = curr->child[1]; - } else if(ray.getDirection()[curr->axis]<-getVecEpsilon() ) { - // smaller coords - curr = curr->child[0]; - } else { - // paralell, order doesnt really matter are min/max/plane ok? - mpNodeStack->elem[ mpNodeStack->stackPtr ].node = curr->child[0]; - mpNodeStack->elem[ mpNodeStack->stackPtr ].mindist = planedist; - mpNodeStack->elem[ mpNodeStack->stackPtr ].maxdist = maxdist; - (mpNodeStack->stackPtr)++; - curr = curr->child[1]; - maxdist = planedist; - } - } else { - // normal ray - if( (planedist>maxdist) || (planedist<0.0-getVecEpsilon() ) ) { - curr = nearChild; - } else if(planedist < mindist) { - curr = farChild; - } else { - mpNodeStack->elem[ mpNodeStack->stackPtr ].node = farChild; - mpNodeStack->elem[ mpNodeStack->stackPtr ].mindist = planedist; - mpNodeStack->elem[ mpNodeStack->stackPtr ].maxdist = maxdist; - (mpNodeStack->stackPtr)++; - - curr = nearChild; - maxdist = planedist; - } - } - } - - - /* intersect with current node */ - for (vector::iterator iter = curr->members->begin(); - iter != curr->members->end(); iter++ ) { - - /* check for triangle flags before intersecting */ - if((!flags) || ( ((*iter)->getFlags() & flags) > 0 )) { - - if( ((*iter)->getLastRay() == ray.getID() )&&((*iter)->getLastRay()>0) ) { - // was already intersected... - } else { - // we still need to intersect this triangle - gfxReal u=0.0,v=0.0, t=-1.0; - ray.intersectTriangle( mpVertices, (*iter), t,u,v); - (*iter)->setLastRay( ray.getID() ); - - if( (t > 0.0) && (t0.0) && (mint < GFX_REAL_MAX) ) { - pos = ray.getOrigin() + ray.getDirection()*mint; - - if( (pos[0] >= curr->min[0]) && (pos[0] <= curr->max[0]) && - (pos[1] >= curr->min[1]) && (pos[1] <= curr->max[1]) && - (pos[2] >= curr->min[2]) && (pos[2] <= curr->max[2]) ) - { - - if(forceNonsmooth) { - // calculate triangle normal - ntlVec3Gfx e0,e1,e2; - e0 = (*mpVertices)[ hit->getPoints()[0] ]; - e1 = (*mpVertices)[ hit->getPoints()[1] ]; - e2 = (*mpVertices)[ hit->getPoints()[2] ]; - retnormal = cross( -(e2-e0), (e1-e0) ); - } else { - // calculate interpolated normal - retnormal = (*mpVertNormals)[ hit->getPoints()[0] ] * (1.0-mintu-mintv)+ - (*mpVertNormals)[ hit->getPoints()[1] ]*mintu + - (*mpVertNormals)[ hit->getPoints()[2] ]*mintv; - } - normalize(retnormal); - normal = retnormal; - distance = mint; - tri = hit; - return; - } - } - - (mpNodeStack->stackPtr)--; - curr = mpNodeStack->elem[ mpNodeStack->stackPtr ].node; - mindist = mpNodeStack->elem[ mpNodeStack->stackPtr ].mindist; - maxdist = mpNodeStack->elem[ mpNodeStack->stackPtr ].maxdist; - } /* traverse tree */ - - if(mint == GFX_REAL_MAX) { - distance = -1.0; - } else { - // intersection outside the BSP bounding volumes might occur due to roundoff... - //retnormal = (*mpVertNormals)[ hit->getPoints()[0] ] * (1.0-mintu-mintv)+ (*mpVertNormals)[ hit->getPoints()[1] ]*mintu + (*mpVertNormals)[ hit->getPoints()[2] ]*mintv; - if(forceNonsmooth) { - // calculate triangle normal - ntlVec3Gfx e0,e1,e2; - e0 = (*mpVertices)[ hit->getPoints()[0] ]; - e1 = (*mpVertices)[ hit->getPoints()[1] ]; - e2 = (*mpVertices)[ hit->getPoints()[2] ]; - retnormal = cross( -(e2-e0), (e1-e0) ); - } else { - // calculate interpolated normal - retnormal = (*mpVertNormals)[ hit->getPoints()[0] ] * (1.0-mintu-mintv)+ - (*mpVertNormals)[ hit->getPoints()[1] ]*mintu + - (*mpVertNormals)[ hit->getPoints()[2] ]*mintv; - } - - normalize(retnormal); - normal = retnormal; - distance = mint; - tri = hit; - } - return; -} - -inline void ntlRay::intersectTriangleX(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const -{ - /* (cf. moeller&haines, page 305) */ - t = GFX_REAL_MAX; - ntlVec3Gfx e0 = (*mpV)[ tri->getPoints()[0] ]; - ntlVec3Gfx e1 = (*mpV)[ tri->getPoints()[1] ] - e0; - ntlVec3Gfx e2 = (*mpV)[ tri->getPoints()[2] ] - e0; - - //ntlVec3Gfx p = cross( mDirection, e2 ); - //ntlVector3Dim cp( (-), (- (1.0 *v[2])), ((1.0 *v[1]) -) ); - ntlVec3Gfx p(0.0, -e2[2], e2[1]); - - gfxReal divisor = dot(e1, p); - if((divisor > -RAY_TRIANGLE_EPSILON)&&(divisor < RAY_TRIANGLE_EPSILON)) return; - - gfxReal invDivisor = 1/divisor; - ntlVec3Gfx s = mOrigin - e0; - u = invDivisor * dot(s, p); - if( (u<0.0-RAY_TRIANGLE_EPSILON) || (u>1.0+RAY_TRIANGLE_EPSILON) ) return; - - ntlVec3Gfx q = cross( s,e1 ); - //v = invDivisor * dot(mDirection, q); - v = invDivisor * q[0]; - if( (v<0.0-RAY_TRIANGLE_EPSILON) || ((u+v)>1.0+RAY_TRIANGLE_EPSILON) ) return; - - t = invDivisor * dot(e2, q); -} -void ntlTree::intersectX(const ntlRay &ray, gfxReal &distance, - ntlVec3Gfx &normal, - ntlTriangle *&tri, - int flags, bool forceNonsmooth) const -{ - gfxReal mint = GFX_REAL_MAX; /* current minimal t */ - ntlVec3Gfx retnormal; /* intersection (interpolated) normal */ - gfxReal mintu=0.0, mintv=0.0; /* u,v for min t intersection */ - - BSPNode *curr, *nearChild, *farChild; /* current node and children */ - gfxReal planedist, mindist, maxdist; - ntlVec3Gfx pos; - - ntlTriangle *hit = NULL; - tri = NULL; - - ray.intersectCompleteAABB(mStart,mEnd,mindist,maxdist); // +X - - if((maxdist < 0.0) || - (!mpRoot) || - (mindist == GFX_REAL_MAX) || - (maxdist == GFX_REAL_MAX) ) { - distance = -1.0; - return; - } - mindist -= getVecEpsilon(); - maxdist += getVecEpsilon(); - - /* stack init */ - mpNodeStack->elem[0].node = NULL; - mpNodeStack->stackPtr = 1; - - curr = mpRoot; - mint = GFX_REAL_MAX; - while(curr != NULL) { // +X - - while( !curr->isLeaf() ) { - planedist = distanceToPlane(curr, curr->child[0]->max, ray ); - getChildren(curr, ray.getOrigin(), nearChild, farChild ); - - // check ray direction for small plane distances - if( (planedist>-getVecEpsilon() )&&(planedist< getVecEpsilon() ) ) { - // ray origin on intersection plane - planedist = 0.0; - if(ray.getDirection()[curr->axis]>getVecEpsilon() ) { - // larger coords - curr = curr->child[1]; - } else if(ray.getDirection()[curr->axis]<-getVecEpsilon() ) { - // smaller coords - curr = curr->child[0]; - } else { - // paralell, order doesnt really matter are min/max/plane ok? - mpNodeStack->elem[ mpNodeStack->stackPtr ].node = curr->child[0]; - mpNodeStack->elem[ mpNodeStack->stackPtr ].mindist = planedist; - mpNodeStack->elem[ mpNodeStack->stackPtr ].maxdist = maxdist; - (mpNodeStack->stackPtr)++; - curr = curr->child[1]; - maxdist = planedist; - } - } else { - // normal ray - if( (planedist>maxdist) || (planedist<0.0-getVecEpsilon() ) ) { - curr = nearChild; - } else if(planedist < mindist) { - curr = farChild; - } else { - mpNodeStack->elem[ mpNodeStack->stackPtr ].node = farChild; - mpNodeStack->elem[ mpNodeStack->stackPtr ].mindist = planedist; - mpNodeStack->elem[ mpNodeStack->stackPtr ].maxdist = maxdist; - (mpNodeStack->stackPtr)++; - - curr = nearChild; - maxdist = planedist; - } - } - } // +X - - - /* intersect with current node */ - for (vector::iterator iter = curr->members->begin(); - iter != curr->members->end(); iter++ ) { - - /* check for triangle flags before intersecting */ - if((!flags) || ( ((*iter)->getFlags() & flags) > 0 )) { - - if( ((*iter)->getLastRay() == ray.getID() )&&((*iter)->getLastRay()>0) ) { - // was already intersected... - } else { - // we still need to intersect this triangle - gfxReal u=0.0,v=0.0, t=-1.0; - ray.intersectTriangleX( mpVertices, (*iter), t,u,v); - (*iter)->setLastRay( ray.getID() ); - - if( (t > 0.0) && (t0.0) && (mint < GFX_REAL_MAX) ) { - pos = ray.getOrigin() + ray.getDirection()*mint; - - if( (pos[0] >= curr->min[0]) && (pos[0] <= curr->max[0]) && - (pos[1] >= curr->min[1]) && (pos[1] <= curr->max[1]) && - (pos[2] >= curr->min[2]) && (pos[2] <= curr->max[2]) ) - { - - if(forceNonsmooth) { - // calculate triangle normal - ntlVec3Gfx e0,e1,e2; - e0 = (*mpVertices)[ hit->getPoints()[0] ]; - e1 = (*mpVertices)[ hit->getPoints()[1] ]; - e2 = (*mpVertices)[ hit->getPoints()[2] ]; - retnormal = cross( -(e2-e0), (e1-e0) ); - } else { - // calculate interpolated normal - retnormal = (*mpVertNormals)[ hit->getPoints()[0] ] * (1.0-mintu-mintv)+ - (*mpVertNormals)[ hit->getPoints()[1] ]*mintu + - (*mpVertNormals)[ hit->getPoints()[2] ]*mintv; - } - normalize(retnormal); - normal = retnormal; - distance = mint; - tri = hit; - return; - } - } // +X - - (mpNodeStack->stackPtr)--; - curr = mpNodeStack->elem[ mpNodeStack->stackPtr ].node; - mindist = mpNodeStack->elem[ mpNodeStack->stackPtr ].mindist; - maxdist = mpNodeStack->elem[ mpNodeStack->stackPtr ].maxdist; - } /* traverse tree */ - - if(mint == GFX_REAL_MAX) { - distance = -1.0; - } else { - - // intersection outside the BSP bounding volumes might occur due to roundoff... - if(forceNonsmooth) { - // calculate triangle normal - ntlVec3Gfx e0,e1,e2; - e0 = (*mpVertices)[ hit->getPoints()[0] ]; - e1 = (*mpVertices)[ hit->getPoints()[1] ]; - e2 = (*mpVertices)[ hit->getPoints()[2] ]; - retnormal = cross( -(e2-e0), (e1-e0) ); - } else { - // calculate interpolated normal - retnormal = (*mpVertNormals)[ hit->getPoints()[0] ] * (1.0-mintu-mintv)+ - (*mpVertNormals)[ hit->getPoints()[1] ]*mintu + - (*mpVertNormals)[ hit->getPoints()[2] ]*mintv; - } - - normalize(retnormal); - normal = retnormal; - distance = mint; - tri = hit; - } // +X - return; -} - - - -/****************************************************************************** - * distance to plane function for nodes - *****************************************************************************/ -gfxReal ntlTree::distanceToPlane(BSPNode *curr, ntlVec3Gfx plane, ntlRay ray) const -{ - return ( (plane[curr->axis]-ray.getOrigin()[curr->axis]) / ray.getDirection()[curr->axis] ); -} - - -/****************************************************************************** - * return ordering of children nodes relatice to origin point - *****************************************************************************/ -void ntlTree::getChildren(BSPNode *curr, ntlVec3Gfx origin, BSPNode *&node_near, BSPNode *&node_far) const -{ - if(curr->child[0]->max[ curr->axis ] >= origin[ curr->axis ]) { - node_near = curr->child[0]; - node_far = curr->child[1]; - } else { - node_near = curr->child[1]; - node_far = curr->child[0]; - } -} - - -/****************************************************************************** - * delete a node of the tree with all sub nodes - * dont delete root members - *****************************************************************************/ -void ntlTree::deleteNode(BSPNode *curr) -{ - if(!curr) return; - - if(curr->child[0] != NULL) - deleteNode(curr->child[0]); - if(curr->child[1] != NULL) - deleteNode(curr->child[1]); - - if(curr->members != NULL) delete curr->members; - delete curr; -} - - - -/****************************************************************** - * intersect only front or backsides - * currently unused - */ -inline void ntlRay::intersectTriangleFront(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const -{ - t = GFX_REAL_MAX; - ntlVec3Gfx e0 = (*mpV)[ tri->getPoints()[0] ]; - ntlVec3Gfx e1 = (*mpV)[ tri->getPoints()[1] ] - e0; - ntlVec3Gfx e2 = (*mpV)[ tri->getPoints()[2] ] - e0; - ntlVec3Gfx p = cross( mDirection, e2 ); - gfxReal a = dot(e1, p); - //if((a > -RAY_TRIANGLE_EPSILON)&&(a < RAY_TRIANGLE_EPSILON)) return; - if(a < RAY_TRIANGLE_EPSILON) return; // cull backsides - - gfxReal f = 1/a; - ntlVec3Gfx s = mOrigin - e0; - u = f * dot(s, p); - if( (u<0.0-RAY_TRIANGLE_EPSILON) || (u>1.0+RAY_TRIANGLE_EPSILON) ) return; - - ntlVec3Gfx q = cross( s,e1 ); - v = f * dot(mDirection, q); - if( (v<0.0-RAY_TRIANGLE_EPSILON) || ((u+v)>1.0+RAY_TRIANGLE_EPSILON) ) return; - - t = f * dot(e2, q); -} -inline void ntlRay::intersectTriangleBack(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const -{ - t = GFX_REAL_MAX; - ntlVec3Gfx e0 = (*mpV)[ tri->getPoints()[0] ]; - ntlVec3Gfx e1 = (*mpV)[ tri->getPoints()[1] ] - e0; - ntlVec3Gfx e2 = (*mpV)[ tri->getPoints()[2] ] - e0; - ntlVec3Gfx p = cross( mDirection, e2 ); - gfxReal a = dot(e1, p); - //if((a > -RAY_TRIANGLE_EPSILON)&&(a < RAY_TRIANGLE_EPSILON)) return; - if(a > -RAY_TRIANGLE_EPSILON) return; // cull frontsides - - gfxReal f = 1/a; - ntlVec3Gfx s = mOrigin - e0; - u = f * dot(s, p); - if( (u<0.0-RAY_TRIANGLE_EPSILON) || (u>1.0+RAY_TRIANGLE_EPSILON) ) return; - - ntlVec3Gfx q = cross( s,e1 ); - v = f * dot(mDirection, q); - if( (v<0.0-RAY_TRIANGLE_EPSILON) || ((u+v)>1.0+RAY_TRIANGLE_EPSILON) ) return; - - t = f * dot(e2, q); -} - - - diff --git a/intern/elbeem/intern/ntl_bsptree.h b/intern/elbeem/intern/ntl_bsptree.h deleted file mode 100644 index f6eaee069a9..00000000000 --- a/intern/elbeem/intern/ntl_bsptree.h +++ /dev/null @@ -1,135 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Tree container for fast triangle intersects - * - *****************************************************************************/ -#ifndef NTL_TREE_H -#define NTL_TREE_H - -#include "ntl_vector3dim.h" -#include "ntl_ray.h" - - -#define AXIS_X 0 -#define AXIS_Y 1 -#define AXIS_Z 2 - -#define BSP_STACK_SIZE 50 - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -//! bsp tree stack classes, defined in ntl_bsptree.cpp, -// detailed definition unnecesseary here -class BSPNode; -class BSPStackElement; -class BSPStack; -class TriangleBBox; -class ntlScene; -class ntlTriangle; - - -//! Class for a bsp tree for triangles -class ntlTree -{ - public: - - //! Default constructor - ntlTree(); - //! Constructor with init - ntlTree(int depth, int objnum, ntlScene *scene, int triFlagMask); - //! Destructor - ~ntlTree(); - - //! subdivide tree - void subdivide(BSPNode *node, int depth, int axis); - - //! intersect ray with BSPtree - void intersect(const ntlRay &ray, gfxReal &distance, ntlVec3Gfx &normal, ntlTriangle *&tri, int flags, bool forceNonsmooth) const; - //! intersect along +X ray - void intersectX(const ntlRay &ray, gfxReal &distance, ntlVec3Gfx &normal, ntlTriangle *&tri, int flags, bool forceNonsmooth) const; - - //! Returns number of nodes - int getCurrentNodes( void ) { return mCurrentNodes; } - - protected: - - // check if a triangle is in a node - bool checkAABBTriangle(ntlVec3Gfx &min, ntlVec3Gfx &max, ntlTriangle *tri); - - - // VARs - - //! distance to plane function for nodes - gfxReal distanceToPlane(BSPNode *curr, ntlVec3Gfx plane, ntlRay ray) const; - - //! return ordering of children nodes relatice to origin point - void getChildren(BSPNode *curr, ntlVec3Gfx origin, BSPNode *&node_near, BSPNode *&node_far) const; - - //! delete a node of the tree with all sub nodes, dont delete root members - void deleteNode(BSPNode *curr); - - //inline bool isLeaf(BSPNode *node) const { return (node->child[0] == NULL); } - - - //! AABB for tree - ntlVec3Gfx mStart,mEnd; - - //! maximum depth of tree - int mMaxDepth; - - //! maximum number of objects in one node - int mMaxListLength; - - //! root node pointer - BSPNode *mpRoot; - //! count no. of node - int mNumNodes; - int mAbortSubdiv; - - //! stack for the node pointers - BSPStack *mpNodeStack; - //stack nodestack; - - //! pointer to vertex array - vector *mpVertices; - - //! pointer to vertex array - vector *mpVertNormals; - - //! vector for all the triangles - vector *mpTriangles; - vector *mppTriangles; - - //! temporary array for triangle distribution to nodes - char *mpTriDist; - - //! temporary array for triangle bounding boxes - TriangleBBox *mpTBB; - - //! triangle mask - include only triangles that match mask - int mTriangleMask; - - //! Status vars (max depth, # of current nodes) - int mCurrentDepth, mCurrentNodes; - - //! duplicated triangles, inited during subdivide - int mTriDoubles; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlTree") -#endif -}; - - -#endif - - diff --git a/intern/elbeem/intern/ntl_geometryclass.h b/intern/elbeem/intern/ntl_geometryclass.h deleted file mode 100644 index a5d44ad477a..00000000000 --- a/intern/elbeem/intern/ntl_geometryclass.h +++ /dev/null @@ -1,127 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Base class for geometry shaders and objects - * - *****************************************************************************/ - - -#ifndef NTL_GEOMETRYCLASS_H -#define NTL_GEOMETRYCLASS_H - -#include "attributes.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -//! geometry class type ids -#define GEOCLASSTID_OBJECT 1 -#define GEOCLASSTID_SHADER 2 -#define GEOCLASSTID_BOX (GEOCLASSTID_OBJECT| 4) -#define GEOCLASSTID_OBJMODEL (GEOCLASSTID_OBJECT| 8) -#define GEOCLASSTID_SPHERE (GEOCLASSTID_OBJECT| 16) - -class ntlGeometryClass -{ - - public: - - //! Default constructor - inline ntlGeometryClass() : - mVisible( 1 ), mName( "[ObjNameUndef]" ), - mObjectId(-1), mpAttrs( NULL ), mGeoInitId(-1) - { - mpAttrs = new AttributeList("objAttrs"); - mpSwsAttrs = new AttributeList("swsAttrs"); - }; - - //! Default destructor - virtual ~ntlGeometryClass() { - delete mpAttrs; - delete mpSwsAttrs; - }; - - //! Return type id - virtual int getTypeId() = 0; - - /*! Set the object name */ - inline void setName(string set) { mName = set; } - /*! Get the object name */ - inline string getName( void ) { return mName; } - - /*! Sets the visibility attribute - * visibility can be determined at shader _and_ object level , hiding a shader - * means comepletely decativating it */ - inline void setVisible(int set) { mVisible=set; } - /*! Returns the visibility attribute */ - inline int getVisible() const { return mVisible; } - - /*! Sets the attribute list pointer */ - inline void setAttributeList(AttributeList *set) { mpAttrs=set; } - /*! Returns the attribute list pointer */ - inline AttributeList *getAttributeList() { return mpAttrs; } - - /*! Get/Sets the attribute list pointer */ - inline void setSwsAttributeList(AttributeList *set) { mpSwsAttrs=set; } - inline AttributeList *getSwsAttributeList() { return mpSwsAttrs; } - - /*! for easy GUI detection get start of axis aligned bounding box, return NULL of no BB */ - virtual inline ntlVec3Gfx *getBBStart() { return NULL; } - virtual inline ntlVec3Gfx *getBBEnd() { return NULL; } - - /*! Set/get the object id*/ - inline void setObjectId(int set) { mObjectId=set; } - inline int getObjectId() const { return mObjectId; } - - /*! GUI - this function is called for selected objects to display debugging information with OpenGL */ - virtual void drawDebugDisplay() { /* do nothing by default */ } - /*! GUI - this function is called for selected objects to display interactive information with OpenGL */ - virtual void drawInteractiveDisplay() { /* do nothing by default */ } - /*! GUI - handle mouse movement for selection */ - virtual void setMousePos(int ,int , ntlVec3Gfx , ntlVec3Gfx ) { /* do nothing by default */ } - /*! GUI - notify object that mouse was clicked at last pos */ - virtual void setMouseClick() { /* do nothing by default */ } - - /*! Returns the geo init id */ - inline void setGeoInitId(int set) { mGeoInitId=set; } - /*! Returns the geo init id */ - inline int getGeoInitId() const { return mGeoInitId; } - - protected: - - /*! Object visible on/off */ - int mVisible; - - /*! Name of this object */ - string mName; - - /*! global scene object id */ - int mObjectId; - - /*! configuration attributes */ - AttributeList *mpAttrs; - /*! sws configuration attributes */ - AttributeList *mpSwsAttrs; - - /* fluid init data */ - /*! id of fluid init (is used in solver initialization), additional data stored only for objects */ - int mGeoInitId; - - private: - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlGeometryClass") -#endif -}; - - - -#endif - diff --git a/intern/elbeem/intern/ntl_geometrymodel.cpp b/intern/elbeem/intern/ntl_geometrymodel.cpp deleted file mode 100644 index 989fcac599b..00000000000 --- a/intern/elbeem/intern/ntl_geometrymodel.cpp +++ /dev/null @@ -1,477 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * A simple box object - * - *****************************************************************************/ - -#include "ntl_geometrymodel.h" -#include "ntl_ray.h" -#include "ntl_world.h" -#include "zlib.h" - -#ifdef WIN32 -#ifndef strncasecmp -#define strncasecmp(a,b,c) strcmp(a,b) -#endif -#endif // WIN32 - - -/****************************************************************************** - * Default Constructor - *****************************************************************************/ -ntlGeometryObjModel::ntlGeometryObjModel( void ) : - ntlGeometryObject(), - mvStart( 0.0 ), mvEnd( 1.0 ), - mLoaded( false ), - mTriangles(), mVertices(), mNormals(), - mcAniVerts(), mcAniNorms(), - mcAniTimes(), mAniTimeScale(1.), mAniTimeOffset(0.) -{ -} - -/****************************************************************************** - * Destructor - *****************************************************************************/ -ntlGeometryObjModel::~ntlGeometryObjModel() -{ - if(!mLoaded) { - errMsg("ntlGeometryObjModel","delete obj..."); - } -} - - -/*! is the mesh animated? */ -bool ntlGeometryObjModel::getMeshAnimated() { - const bool ret = (mcAniVerts.getSize()>1); - //errMsg("getMeshAnimated","ret="< (*sverts)[i][j]) { start[j]= (*sverts)[i][j]; } - if(end[j] < (*sverts)[i][j]) { end[j] = (*sverts)[i][j]; } - } - //errMsg("getExtends","check "<getMaterials() ); - return; - } - - ntlGeometryObject::initialize(glob); - mFilename = mpAttrs->readString("filename", mFilename,"ntlGeometryObjModel", "mFilename", true); - - if(mFilename == "") { - errMsg("ntlGeometryObjModel::initialize","Filename not given!"); - return; - } - - const char *suffix = strrchr(mFilename.c_str(), '.'); - if (suffix) { - if (!strncasecmp(suffix, ".obj", 4)) { - errMsg("ntlGeometryObjModel::initialize",".obj files not supported!"); - return; - } else if (!strncasecmp(suffix, ".gz", 3)) { - //mType = 1; // assume its .bobj.gz - } else if (!strncasecmp(suffix, ".bobj", 5)) { - //mType = 1; - } - } - - if(getAttributeList()->exists("ani_times") || (!mcAniTimes.isInited()) ) { - mcAniTimes = mpAttrs->readChannelFloat("ani_times"); - } - mAniTimeScale = mpAttrs->readFloat("ani_timescale", mAniTimeScale,"ntlGeometryObjModel", "mAniTimeScale", false); - mAniTimeOffset = mpAttrs->readFloat("ani_timeoffset", mAniTimeOffset,"ntlGeometryObjModel", "mAniTimeOffset", false); - - // continue with standard obj - if(loadBobjModel(mFilename)==0) mLoaded=1; - if(!mLoaded) { - debMsgStd("ntlGeometryObjModel",DM_WARNING,"Unable to load object file '"<mIsAnimated = true; - } -} - -/****************************************************************************** - * init model from given vertex and triangle arrays - *****************************************************************************/ - -int ntlGeometryObjModel::initModel(int numVertices, float *vertices, int numTriangles, int *triangles, - int channelSize, float *channelVertices) -{ - mVertices.clear(); - mVertices.resize( numVertices ); - mNormals.resize( numVertices ); - for(int i=0; i=numVertices) { mTriangles[3*i+j]=0; triangleErrs++; } - } - } - if(triangleErrs>0) { - errMsg("ntlGeometryObjModel::initModel","Triangle errors occurred ("<0)) { - vector aniverts; - vector aninorms; - vector anitimes; - aniverts.clear(); - aninorms.clear(); - anitimes.clear(); - for(int frame=0; framemIsAnimated = true; - } - - // inited, no need to parse attribs etc. - mLoaded = 1; - return 0; -} - -/*! init triangle divisions */ -void ntlGeometryObjModel::calcTriangleDivs(vector &verts, vector &tris, gfxReal fsTri) { - // warning - copied from geomobj calc! - errMsg("ntlGeometryObjModel","calcTriangleDivs special!"); - mTriangleDivs1.resize( tris.size() ); - mTriangleDivs2.resize( tris.size() ); - for(size_t i=0; i fsTri*fsTri) { divs1 = (int)(norm(side1)/fsTri); } - if(normNoSqrt(side2) > fsTri*fsTri) { divs2 = (int)(norm(side2)/fsTri); } - - // special handling - // warning, requires objmodel triangle treatment (no verts dups) - if(getMeshAnimated()) { - vector &sverts = mcAniVerts.accessValues(); - for(int s=0; s<(int)sverts.size(); s++) { - p0 = sverts[s].mVerts[ tris[i].getPoints()[0] ]; - p1 = sverts[s].mVerts[ tris[i].getPoints()[1] ]; - p2 = sverts[s].mVerts[ tris[i].getPoints()[2] ]; - side1 = p1 - p0; side2 = p2 - p0; side3 = p1 - p2; - int tdivs1=0, tdivs2=0; - if(normNoSqrt(side1) > fsTri*fsTri) { tdivs1 = (int)(norm(side1)/fsTri); } - if(normNoSqrt(side2) > fsTri*fsTri) { tdivs2 = (int)(norm(side2)/fsTri); } - if(tdivs1>divs1) divs1=tdivs1; - if(tdivs2>divs2) divs2=tdivs2; - } - } // */ - mTriangleDivs1[i] = divs1; - mTriangleDivs2[i] = divs2; - } -} - - -/****************************************************************************** - * load model from .obj file - *****************************************************************************/ - -int ntlGeometryObjModel::loadBobjModel(string filename) -{ - bool haveAniSets=false; - vector aniverts; - vector aninorms; - vector anitimes; - - const bool debugPrint=false; - const bool debugPrintFull=false; - gzFile gzf; - gzf = gzopen(filename.c_str(), "rb"); - if (!gzf) { - errFatal("ntlGeometryObjModel::loadBobjModel","Reading GZ_BOBJ, Unable to open '"<< filename <<"'...\n", SIMWORLD_INITERROR ); - return 1; - } - - int numVerts; - if(sizeof(numVerts)!=4) { // paranoia check - errMsg("Reading GZ_BOBJ"," Invalid int size, check compiler settings: int has to be 4 byte long"); - goto gzreaderror; - } - gzread(gzf, &numVerts, sizeof(numVerts) ); - if(numVerts<0 || numVerts>1e9) { - errMsg("Reading GZ_BOBJ"," invalid num vertices "<< numVerts); - goto gzreaderror; - } - mVertices.clear(); - mVertices.resize( numVerts ); - for(int i=0; i1e9) { - errMsg("Reading GZ_BOBJ","invalid num normals "<< numVerts); - goto gzreaderror; - } - mNormals.clear(); - mNormals.resize( numVerts ); - for(int i=0; i1e9) { - errMsg("Reading GZ_BOBJ","invalid num normals "<< numTris); - goto gzreaderror; - } - mTriangles.resize( 3*numTris ); - for(int i=0; i0) { - // finally init channels and stop reading file - mcAniVerts = AnimChannel(aniverts,anitimes); - mcAniNorms = AnimChannel(aninorms,anitimes); - } - goto gzreaddone; - } - bytesRead += gzread(gzf, &numVerts2, sizeof(numVerts2) ); - haveAniSets=true; - // continue to read new set - vector vertset; - vector normset; - vertset.resize(numVerts); - normset.resize(numVerts); - //vertset[0] = check; - if(debugPrintFull) errMsg("FUL1V"," "<<0<<" "<< vertset[0] ); - - for(int i=0; i1) anitime = mcAniTimes.get(anitime); - anitime = anitime*mAniTimeScale+mAniTimeOffset; - - anitimes.push_back( anitime ); - aniverts.push_back( ntlSetVec3f(mVertices) ); - aninorms.push_back( ntlSetVec3f(mNormals) ); - if(debugPrint) errMsg("ANI_NV","new set "<1) anitime = mcAniTimes.get(anitime); - anitime = anitime*mAniTimeScale+mAniTimeOffset; - - anitimes.push_back( anitime ); - aniverts.push_back( ntlSetVec3f(vertset) ); - aninorms.push_back( ntlSetVec3f(normset) ); - if(debugPrint) errMsg("ANI_NV","new set "< *triangles, - vector *vertices, - vector *normals, int objectId ) -{ - if(!mLoaded) { // invalid type... - return; - } - if(mcAniVerts.getSize()>1) { mVertices = mcAniVerts.get(t).mVerts; } - if(mcAniNorms.getSize()>1) { mNormals = mcAniNorms.get(t).mVerts; } - - int startvert = vertices->size(); - vertices->resize( vertices->size() + mVertices.size() ); - normals->resize( normals->size() + mVertices.size() ); - for(int i=0; i<(int)mVertices.size(); i++) { - (*vertices)[startvert+i] = mVertices[i]; - (*normals)[startvert+i] = mNormals[i]; - } - - triangles->reserve(triangles->size() + mTriangles.size()/3 ); - for(int i=0; i<(int)mTriangles.size(); i+=3) { - int trip[3]; - trip[0] = startvert+mTriangles[i+0]; - trip[1] = startvert+mTriangles[i+1]; - trip[2] = startvert+mTriangles[i+2]; - - //sceneAddTriangle( - //mVertices[trip[0]], mVertices[trip[1]], mVertices[trip[2]], - //mNormals[trip[0]], mNormals[trip[1]], mNormals[trip[2]], - //ntlVec3Gfx(0.0), 1 , triangles,vertices,normals ); /* normal unused */ - sceneAddTriangleNoVert( trip, ntlVec3Gfx(0.0), 1 , triangles ); /* normal unused */ - } - objectId = -1; // remove warning - // bobj - return; -} - - - - - diff --git a/intern/elbeem/intern/ntl_geometrymodel.h b/intern/elbeem/intern/ntl_geometrymodel.h deleted file mode 100644 index a5f26ba17b8..00000000000 --- a/intern/elbeem/intern/ntl_geometrymodel.h +++ /dev/null @@ -1,104 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * A model laoded from Wavefront .obj file - * - *****************************************************************************/ -#ifndef NTL_GEOMODEL_H -#define NTL_GEOMODEL_H - -#include "ntl_geometryobject.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -/*! A simple box object generatedd by 12 triangles */ -class ntlGeometryObjModel : public ntlGeometryObject -{ - public: - /* Init constructor */ - ntlGeometryObjModel( void ); - /* Init constructor */ - //ntlGeometryObjModel( ntlVec3Gfx start, ntlVec3Gfx end ); - /* Destructor */ - virtual ~ntlGeometryObjModel( void ); - - //! Return type id - virtual int getTypeId() { return GEOCLASSTID_OBJMODEL; } - - /*! Filename setting etc. */ - virtual void initialize(ntlRenderGlobals *glob); - - /*! is the mesh animated? */ - virtual bool getMeshAnimated(); - - /* create triangles from obj */ - virtual void getTriangles(double t, vector *triangles, - vector *vertices, - vector *normals, int objectId ); - - /*! load model from .bobj file, returns !=0 upon error */ - int loadBobjModel(string filename); - /*! init model from given vertex and triangle arrays */ - int initModel(int numVertices, float *vertices, int numTriangles, int *triangles, - int channelSize, float *channelVertices); - /*! init triangle divisions */ - virtual void calcTriangleDivs(vector &verts, vector &tris, gfxReal fsTri); - - /*! calculate max extends of (ani) mesh */ - void getExtends(ntlVec3Gfx &start, ntlVec3Gfx &end); - - private: - - /*! Start and end points of box */ - ntlVec3Gfx mvStart, mvEnd; - - /*! was the model loaded? */ - bool mLoaded; - - /*! filename of the obj file */ - string mFilename; - - /*! for bobj models */ - vector mTriangles; - vector mVertices; - vector mNormals; - - /*! animated channels for vertices, if given will override getris by default */ - AnimChannel mcAniVerts; - AnimChannel mcAniNorms; - /*! map entrie of anim mesh to sim times */ - AnimChannel mcAniTimes; - /*! timing mapping & offset for config files */ - double mAniTimeScale, mAniTimeOffset; - - public: - - /* Access methods */ - /*! Access start vector */ - inline ntlVec3Gfx getStart( void ){ return mvStart; } - inline void setStart( const ntlVec3Gfx &set ){ mvStart = set; } - /*! Access end vector */ - inline ntlVec3Gfx getEnd( void ){ return mvEnd; } - inline void setEnd( const ntlVec3Gfx &set ){ mvEnd = set; } - - inline bool getLoaded( void ){ return mLoaded; } - inline void setLoaded( bool set ){ mLoaded = set; } - - /*! set data file name */ - inline void setFilename(string set) { mFilename = set; } - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlGeometryObjModel") -#endif -}; - -#endif - diff --git a/intern/elbeem/intern/ntl_geometryobject.cpp b/intern/elbeem/intern/ntl_geometryobject.cpp deleted file mode 100644 index 7eb2df4ad3f..00000000000 --- a/intern/elbeem/intern/ntl_geometryobject.cpp +++ /dev/null @@ -1,806 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * a geometry object - * all other geometry objects are derived from this one - * - *****************************************************************************/ - - -#include "ntl_geometryobject.h" -#include "ntl_world.h" -#include "ntl_matrices.h" - -// for FGI -#include "elbeem.h" - -#define TRI_UVOFFSET (1./4.) -//#define TRI_UVOFFSET (1./3.) - - -/*****************************************************************************/ -/* Default constructor */ -/*****************************************************************************/ -ntlGeometryObject::ntlGeometryObject() : - mIsInitialized(false), mpMaterial( NULL ), - mMaterialName( "default" ), - mCastShadows( 1 ), mReceiveShadows( 1 ), - mGeoInitType( 0 ), - mInitialVelocity(0.0), mcInitialVelocity(0.0), mLocalCoordInivel(false), - mGeoInitIntersect(false), - mGeoPartSlipValue(0.0), - mcGeoImpactFactor(1.), - mVolumeInit(VOLUMEINIT_VOLUME), - mInitialPos(0.), - mcTrans(0.), mcRot(0.), mcScale(1.), - mIsAnimated(false), - mMovPoints(), mMovNormals(), - mHaveCachedMov(false), - mCachedMovPoints(), mCachedMovNormals(), - mTriangleDivs1(), mTriangleDivs2(), - mMovPntsInited(-100.0), mMaxMovPnt(-1), - mcGeoActive(1.), - mCpsTimeStart(0.), mCpsTimeEnd(1.0), mCpsQuality(10.), - mcAttrFStr(0.),mcAttrFRad(0.), mcVelFStr(0.), mcVelFRad(0.) -{ -}; - - -/*****************************************************************************/ -/* Default destructor */ -/*****************************************************************************/ -ntlGeometryObject::~ntlGeometryObject() -{ -} - -/*! is the mesh animated? */ -bool ntlGeometryObject::getMeshAnimated() { - // off by default, on for e.g. ntlGeometryObjModel - return false; -} - -/*! init object anim flag */ -bool ntlGeometryObject::checkIsAnimated() { - if( (mcTrans.accessValues().size()>1) // VALIDATE - || (mcRot.accessValues().size()>1) - || (mcScale.accessValues().size()>1) - || (mcGeoActive.accessValues().size()>1) - // mcGeoImpactFactor only needed when moving - || (mcInitialVelocity.accessValues().size()>1) - ) { - mIsAnimated = true; - } - - // fluid objects always have static init! - if(mGeoInitType==FGI_FLUID) { - mIsAnimated=false; - } - //errMsg("ntlGeometryObject::checkIsAnimated","obj="<getMaterials() ); - - this->mGeoInitId = mpAttrs->readInt("geoinitid", this->mGeoInitId,"ntlGeometryObject", "mGeoInitId", false); - mGeoInitIntersect = mpAttrs->readInt("geoinit_intersect", mGeoInitIntersect,"ntlGeometryObject", "mGeoInitIntersect", false); - string ginitStr = mpAttrs->readString("geoinittype", "", "ntlGeometryObject", "mGeoInitType", false); - if(this->mGeoInitId>=0) { - bool gotit = false; - for(int i=0; ireadInt("geoinitactive", 1,"ntlGeometryObject", "geoActive", false); - if(!geoActive) { - // disable geo init again... - this->mGeoInitId = -1; - } - mInitialVelocity = vec2G( mpAttrs->readVec3d("initial_velocity", vec2D(mInitialVelocity),"ntlGeometryObject", "mInitialVelocity", false)); - if(getAttributeList()->exists("initial_velocity") || (!mcInitialVelocity.isInited()) ) { - mcInitialVelocity = mpAttrs->readChannelVec3f("initial_velocity"); - } - // always use channel - if(!mcInitialVelocity.isInited()) { mcInitialVelocity = AnimChannel(mInitialVelocity); } - mLocalCoordInivel = mpAttrs->readBool("geoinit_localinivel", mLocalCoordInivel,"ntlGeometryObject", "mLocalCoordInivel", false); - - mGeoPartSlipValue = mpAttrs->readFloat("geoinit_partslip", mGeoPartSlipValue,"ntlGeometryObject", "mGeoPartSlipValue", false); - bool mOnlyThinInit = false; // deprecated! - mOnlyThinInit = mpAttrs->readBool("geoinit_onlythin", mOnlyThinInit,"ntlGeometryObject", "mOnlyThinInit", false); - if(mOnlyThinInit) mVolumeInit = VOLUMEINIT_SHELL; - mVolumeInit = mpAttrs->readInt("geoinit_volumeinit", mVolumeInit,"ntlGeometryObject", "mVolumeInit", false); - if((mVolumeInitVOLUMEINIT_BOTH)) mVolumeInit = VOLUMEINIT_VOLUME; - - // moving obs correction factor - float impactfactor=1.; - impactfactor = (float)mpAttrs->readFloat("impactfactor", impactfactor,"ntlGeometryObject", "impactfactor", false); - if(getAttributeList()->exists("impactfactor") || (!mcGeoImpactFactor.isInited()) ) { - mcGeoImpactFactor = mpAttrs->readChannelSinglePrecFloat("impactfactor"); - } - - // override cfg types - mVisible = mpAttrs->readBool("visible", mVisible,"ntlGeometryObject", "mVisible", false); - mReceiveShadows = mpAttrs->readBool("recv_shad", mReceiveShadows,"ntlGeometryObject", "mReceiveShadows", false); - mCastShadows = mpAttrs->readBool("cast_shad", mCastShadows,"ntlGeometryObject", "mCastShadows", false); - - // read mesh animation channels - ntlVec3d translation(0.0); - translation = mpAttrs->readVec3d("translation", translation,"ntlGeometryObject", "translation", false); - if(getAttributeList()->exists("translation") || (!mcTrans.isInited()) ) { - mcTrans = mpAttrs->readChannelVec3f("translation"); - } - ntlVec3d rotation(0.0); - rotation = mpAttrs->readVec3d("rotation", rotation,"ntlGeometryObject", "rotation", false); - if(getAttributeList()->exists("rotation") || (!mcRot.isInited()) ) { - mcRot = mpAttrs->readChannelVec3f("rotation"); - } - ntlVec3d scale(1.0); - scale = mpAttrs->readVec3d("scale", scale,"ntlGeometryObject", "scale", false); - if(getAttributeList()->exists("scale") || (!mcScale.isInited()) ) { - mcScale = mpAttrs->readChannelVec3f("scale"); - } - - float geoactive=1.; - geoactive = (float)mpAttrs->readFloat("geoactive", geoactive,"ntlGeometryObject", "geoactive", false); - if(getAttributeList()->exists("geoactive") || (!mcGeoActive.isInited()) ) { - mcGeoActive = mpAttrs->readChannelSinglePrecFloat("geoactive"); - } - // always use channel - if(!mcGeoActive.isInited()) { mcGeoActive = AnimChannel(geoactive); } - - checkIsAnimated(); - - mIsInitialized = true; - debMsgStd("ntlGeometryObject::initialize",DM_MSG,"GeoObj '"<getName()<<"': visible="<mVisible<<" gid="<mGeoInitId<<" gtype="<getName()<<" frame:"< *mat) -{ - /* search the list... */ - int i=0; - for (vector::iterator iter = mat->begin(); - iter != mat->end(); iter++) { - if( mMaterialName == (*iter)->getName() ) { - //warnMsg("ntlGeometryObject::searchMaterial","for obj '"<getName()<<"' "< *triangles, - vector *vertices, - vector *normals) { - ntlTriangle tri; - int tempVert; - - if(normals->size() != vertices->size()) { - errFatal("ntlGeometryObject::sceneAddTriangle","For '"<mName<<"': Vertices and normals sizes to not match!!!",SIMWORLD_GENERICERROR); - - } else { - - vertices->push_back( p1 ); - normals->push_back( pn1 ); - tempVert = normals->size()-1; - tri.getPoints()[0] = tempVert; - - vertices->push_back( p2 ); - normals->push_back( pn2 ); - tempVert = normals->size()-1; - tri.getPoints()[1] = tempVert; - - vertices->push_back( p3 ); - normals->push_back( pn3 ); - tempVert = normals->size()-1; - tri.getPoints()[2] = tempVert; - - - /* init flags from ntl_ray.h */ - int flag = 0; - if(getVisible()){ flag |= TRI_GEOMETRY; } - if(getCastShadows() ) { - flag |= TRI_CASTSHADOWS; } - - /* init geo init id */ - int geoiId = getGeoInitId(); - //if((geoiId > 0) && (mVolumeInit&VOLUMEINIT_VOLUME) && (!mIsAnimated)) { - if((geoiId > 0) && (mVolumeInit&VOLUMEINIT_VOLUME)) { - flag |= (1<< (geoiId+4)); - flag |= mGeoInitType; - } - /*errMsg("ntlScene::addTriangle","DEBUG flag="<mObjectId ); - triangles->push_back( tri ); - } /* normals check*/ -} - -void ntlGeometryObject::sceneAddTriangleNoVert(int *trips, - ntlVec3Gfx trin, bool smooth, - vector *triangles) { - ntlTriangle tri; - - tri.getPoints()[0] = trips[0]; - tri.getPoints()[1] = trips[1]; - tri.getPoints()[2] = trips[2]; - - // same as normal sceneAddTriangle - - /* init flags from ntl_ray.h */ - int flag = 0; - if(getVisible()){ flag |= TRI_GEOMETRY; } - if(getCastShadows() ) { - flag |= TRI_CASTSHADOWS; } - - /* init geo init id */ - int geoiId = getGeoInitId(); - if((geoiId > 0) && (mVolumeInit&VOLUMEINIT_VOLUME)) { - flag |= (1<< (geoiId+4)); - flag |= mGeoInitType; - } - /*errMsg("ntlScene::addTriangle","DEBUG flag="<mObjectId ); - triangles->push_back( tri ); -} - - -/******************************************************************************/ -/* Init channels from float arrays (for elbeem API) */ -/******************************************************************************/ - -#define ADD_CHANNEL_VEC(dst,nvals,val) \ - vals.clear(); time.clear(); elbeemSimplifyChannelVec3(val,&nvals); \ - for(int i=0; i<(nvals); i++) { \ - vals.push_back(ntlVec3Gfx((val)[i*4+0], (val)[i*4+1],(val)[i*4+2] )); \ - time.push_back( (val)[i*4+3] ); \ - } \ - (dst) = AnimChannel< ntlVec3Gfx >(vals,time); - -#define ADD_CHANNEL_FLOAT(dst,nvals,val) \ - valsfloat.clear(); time.clear(); elbeemSimplifyChannelFloat(val,&nvals); \ - for(int i=0; i<(nvals); i++) { \ - valsfloat.push_back( (val)[i*2+0] ); \ - time.push_back( (val)[i*2+1] ); \ - } \ - (dst) = AnimChannel< float >(valsfloat,time); - -void ntlGeometryObject::initChannels( - int nTrans, float *trans, int nRot, float *rot, int nScale, float *scale, - int nAct, float *act, int nIvel, float *ivel, - int nAttrFStr, float *attrFStr, - int nAttrFRad, float *attrFRad, - int nVelFStr, float *velFStr, - int nVelFRad, float *velFRad - ) { - const bool debugInitc=true; - if(debugInitc) { debMsgStd("ntlGeometryObject::initChannels",DM_MSG,"nt:"< vals; - vector valsfloat; - vector time; - if((trans)&&(nTrans>0)) { ADD_CHANNEL_VEC(mcTrans, nTrans, trans); } - if((rot)&&(nRot>0)) { ADD_CHANNEL_VEC(mcRot, nRot, rot); } - if((scale)&&(nScale>0)) { ADD_CHANNEL_VEC(mcScale, nScale, scale); } - if((act)&&(nAct>0)) { ADD_CHANNEL_FLOAT(mcGeoActive, nAct, act); } - if((ivel)&&(nIvel>0)) { ADD_CHANNEL_VEC(mcInitialVelocity, nIvel, ivel); } - - /* fluid control channels */ - if((attrFStr)&&(nAttrFStr>0)) { ADD_CHANNEL_FLOAT(mcAttrFStr, nAttrFStr, attrFStr); } - if((attrFRad)&&(nAttrFRad>0)) { ADD_CHANNEL_FLOAT(mcAttrFRad, nAttrFRad, attrFRad); } - if((velFStr)&&(nVelFStr>0)) { ADD_CHANNEL_FLOAT(mcVelFStr, nAct, velFStr); } - if((velFRad)&&(nVelFRad>0)) { ADD_CHANNEL_FLOAT(mcVelFRad, nVelFRad, velFRad); } - - checkIsAnimated(); - - if(debugInitc) { - debMsgStd("ntlGeometryObject::initChannels",DM_MSG,getName()<< - " nt:"< *verts, vector *norms, int vstart, int vend, int forceTrafo) { - if( (mcTrans.accessValues().size()>1) // VALIDATE - || (mcRot.accessValues().size()>1) - || (mcScale.accessValues().size()>1) - || (forceTrafo) - || (!mHaveCachedMov) - ) { - // transformation is animated, continue - ntlVec3Gfx pos = getTranslation(t); - ntlVec3Gfx scale = mcScale.get(t); - ntlVec3Gfx rot = mcRot.get(t); - ntlMat4Gfx rotMat; - rotMat.initRotationXYZ(rot[0],rot[1],rot[2]); - pos += mInitialPos; - errMsg("ntlGeometryObject::applyTransformation","obj="< &verts, vector &tris, gfxReal fsTri) { - mTriangleDivs1.resize( tris.size() ); - mTriangleDivs2.resize( tris.size() ); - - //fsTri *= 2.; // DEBUG! , wrong init! - - for(size_t i=0; i fsTri*fsTri) { divs1 = (int)(norm(side1)/fsTri); } - if(normNoSqrt(side2) > fsTri*fsTri) { divs2 = (int)(norm(side2)/fsTri); } - - mTriangleDivs1[i] = divs1; - mTriangleDivs2[i] = divs2; - } -} - -/*! Prepare points for moving objects */ -void ntlGeometryObject::initMovingPoints(double time, gfxReal featureSize) { - if((mMovPntsInited==featureSize)&&(!getMeshAnimated())) return; - const bool debugMoinit=false; - - vector triangles; - vector vertices; - vector vnormals; - int objectId = 1; - this->getTriangles(time, &triangles,&vertices,&vnormals,objectId); - - mMovPoints.clear(); - mMovNormals.clear(); - if(debugMoinit) errMsg("ntlGeometryObject::initMovingPoints","Object "<maxpart) maxpart = ABS(maxscale[1]); - if(ABS(maxscale[2])>maxpart) maxpart = ABS(maxscale[2]); - float scaleFac = 1.0/(maxpart); - // TODO - better reinit from time to time? - const gfxReal fsTri = featureSize*0.5 *scaleFac; - if(debugMoinit) errMsg("ntlGeometryObject::initMovingPoints","maxscale:"< fsTri*fsTri) { divs1 = (int)(norm(side1)/fsTri); } - if(normNoSqrt(side2) > fsTri*fsTri) { divs2 = (int)(norm(side2)/fsTri); } - errMsg("ntlGeometryObject::initMovingPoints","tri:"< "< 0) { - for(int u=0; u<=divs1; u++) { - for(int v=0; v<=divs2; v++) { - const gfxReal uf = (gfxReal)(u+TRI_UVOFFSET) / (gfxReal)(divs1+0.0); - const gfxReal vf = (gfxReal)(v+TRI_UVOFFSET) / (gfxReal)(divs2+0.0); - if(uf+vf>1.0) continue; - countp+=2; - } - } - } - } - errMsg("ntlGeometryObject::initMovingPoints","Object "< 0) { - for(int u=0; u<=divs1; u++) { - for(int v=0; v<=divs2; v++) { - const gfxReal uf = (gfxReal)(u+TRI_UVOFFSET) / (gfxReal)(divs1+0.0); - const gfxReal vf = (gfxReal)(v+TRI_UVOFFSET) / (gfxReal)(divs2+0.0); - if(uf+vf>1.0) continue; - ntlVec3Gfx p = - vertices[ trips[0] ] * (1.0-uf-vf)+ - vertices[ trips[1] ] * uf + - vertices[ trips[2] ] * vf; - //ntlVec3Gfx n = vnormals[ - //trips[0] ] * (1.0-uf-vf)+ - //vnormals[ trips[1] ]*uf + - //vnormals[ trips[2] ]*vf; - //normalize(n); - // discard inflow backsides - - mMovPoints.push_back(p + trinorm); // NEW!? - mMovPoints.push_back(p - trinorm); - mMovNormals.push_back(trinormOrg); - mMovNormals.push_back(trinormOrg); - //errMsg("TRINORM","p"<dist) { - mMaxMovPnt = i; - dist = normNoSqrt(mMovPoints[0]); - } - } - - if( (this->getMeshAnimated()) - || (mcTrans.accessValues().size()>1) // VALIDATE - || (mcRot.accessValues().size()>1) - || (mcScale.accessValues().size()>1) - ) { - // also do trafo... - } else { - mCachedMovPoints = mMovPoints; - mCachedMovNormals = mMovNormals; - //applyTransformation(time, &mCachedMovPoints, &mCachedMovNormals, 0, mCachedMovPoints.size(), true); - applyTransformation(time, &mCachedMovPoints, NULL, 0, mCachedMovPoints.size(), true); - mHaveCachedMov = true; - debMsgStd("ntlGeometryObject::initMovingPoints",DM_MSG,"Object "<"< &srcmovPoints, - double dsttime, vector &dstmovPoints, - vector *dstmovNormals, - gfxReal featureSize, - ntlVec3Gfx geostart, ntlVec3Gfx geoend - ) { - const bool debugMoinit=false; - - vector srctriangles; - vector srcvertices; - vector unused_normals; - vector dsttriangles; - vector dstvertices; - vector dstnormals; - int objectId = 1; - // TODO optimize? , get rid of normals? - unused_normals.clear(); - this->getTriangles(srctime, &srctriangles,&srcvertices,&unused_normals,objectId); - unused_normals.clear(); - this->getTriangles(dsttime, &dsttriangles,&dstvertices,&dstnormals,objectId); - - srcmovPoints.clear(); - dstmovPoints.clear(); - if(debugMoinit) errMsg("ntlGeometryObject::initMovingPointsAnim","Object "<maxpart) maxpart = ABS(maxscale[1]); - if(ABS(maxscale[2])>maxpart) maxpart = ABS(maxscale[2]); - float scaleFac = 1.0/(maxpart); - // TODO - better reinit from time to time? - const gfxReal fsTri = featureSize*0.5 *scaleFac; - if(debugMoinit) errMsg("ntlGeometryObject::initMovingPointsAnim","maxscale:"< 0) { - int *srctrips = srctriangles[i].getPoints(); - int *dsttrips = dsttriangles[i].getPoints(); - const ntlVec3Gfx srcp0 = srcvertices[ srctrips[0] ]; - const ntlVec3Gfx srcside1 = srcvertices[ srctrips[1] ] - srcp0; - const ntlVec3Gfx srcside2 = srcvertices[ srctrips[2] ] - srcp0; - const ntlVec3Gfx dstp0 = dstvertices[ dsttrips[0] ]; - const ntlVec3Gfx dstside1 = dstvertices[ dsttrips[1] ] - dstp0; - const ntlVec3Gfx dstside2 = dstvertices[ dsttrips[2] ] - dstp0; - const ntlVec3Gfx src_trinorm = getNormalized(cross(srcside1,srcside2))*0.25*featureSize; - const ntlVec3Gfx dst_trinormOrg = getNormalized(cross(dstside1,dstside2)); - const ntlVec3Gfx dst_trinorm = dst_trinormOrg *0.25*featureSize; - //errMsg("ntlGeometryObject::initMovingPointsAnim","Tri1 "<1.0) continue; - ntlVec3Gfx srcp = - srcvertices[ srctrips[0] ] * (1.0-uf-vf)+ - srcvertices[ srctrips[1] ] * uf + - srcvertices[ srctrips[2] ] * vf; - ntlVec3Gfx dstp = - dstvertices[ dsttrips[0] ] * (1.0-uf-vf)+ - dstvertices[ dsttrips[1] ] * uf + - dstvertices[ dsttrips[2] ] * vf; - - // cutoffDomain - if((srcp[0]geoend[0] ) && (dstp[0]>geoend[0] )) continue; - if((srcp[1]>geoend[1] ) && (dstp[1]>geoend[1] )) continue; - if((srcp[2]>geoend[2] ) && (dstp[2]>geoend[2] )) continue; - - srcmovPoints.push_back(srcp+src_trinorm); // SURFENHTEST - srcmovPoints.push_back(srcp-src_trinorm); - - dstmovPoints.push_back(dstp+dst_trinorm); // SURFENHTEST - dstmovPoints.push_back(dstp-dst_trinorm); - if(dstmovNormals) { - (*dstmovNormals).push_back(dst_trinormOrg); - (*dstmovNormals).push_back(dst_trinormOrg); } - } - } - } - } - - // find max point not necessary - debMsgStd("ntlGeometryObject::initMovingPointsAnim",DM_MSG,"Object "<"< &ret, vector *norms) { - if(mHaveCachedMov) { - ret = mCachedMovPoints; - if(norms) { - *norms = mCachedMovNormals; - //errMsg("ntlGeometryObject","getMovingPoints - Normals currently unused!"); - } - //errMsg ("ntlGeometryObject::getMovingPoints","Object "< verts1,verts2; - verts1.push_back(mMovPoints[mMaxMovPnt]); - verts2 = verts1; - applyTransformation(t1,&verts1,NULL, 0,verts1.size(), true); - applyTransformation(t2,&verts2,NULL, 0,verts2.size(), true); - - vel = (verts2[0]-verts1[0]); // /(t2-t1); - //errMsg("ntlGeometryObject::calculateMaxVel","t1="<= 1.) ? 1.0 : 0.0; - return act; -} - -void ntlGeometryObject::setInitialVelocity(ntlVec3Gfx set) { - mInitialVelocity=set; - mcInitialVelocity = AnimChannel(set); -} -ntlVec3Gfx ntlGeometryObject::getInitialVelocity(double t) { - ntlVec3Gfx v = mcInitialVelocity.get(t); //return mInitialVelocity; - if(!mLocalCoordInivel) return v; - - ntlVec3Gfx rot = mcRot.get(t); - ntlMat4Gfx rotMat; - rotMat.initRotationXYZ(rot[0],rot[1],rot[2]); - v = rotMat * v; - return v; -} - - diff --git a/intern/elbeem/intern/ntl_geometryobject.h b/intern/elbeem/intern/ntl_geometryobject.h deleted file mode 100644 index 7e5e90d6493..00000000000 --- a/intern/elbeem/intern/ntl_geometryobject.h +++ /dev/null @@ -1,255 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * a geometry object - * all other geometry objects are derived from this one - * - *****************************************************************************/ -#ifndef NTL_GEOMETRYOBJECT_H -#define NTL_GEOMETRYOBJECT_H - -#include "ntl_geometryclass.h" -#include "ntl_lighting.h" -#include "ntl_ray.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -class ntlRenderGlobals; -class ntlTriangle; - -#define DUMP_FULLGEOMETRY 1 -#define DUMP_PARTIAL 2 - -#define VOLUMEINIT_VOLUME 1 -#define VOLUMEINIT_SHELL 2 -#define VOLUMEINIT_BOTH (VOLUMEINIT_SHELL|VOLUMEINIT_VOLUME) - -class ntlGeometryObject : public ntlGeometryClass -{ - - public: - //! Default constructor - ntlGeometryObject(); - //! Default destructor - virtual ~ntlGeometryObject(); - - //! Return type id - virtual int getTypeId() { return GEOCLASSTID_OBJECT; } - - /*! Init attributes etc. of this object */ - virtual void initialize(ntlRenderGlobals *glob); - - /*! Get the triangles from this object */ - virtual void getTriangles(double t, vector *triangles, - vector *vertices, - vector *normals, int objectId ) = 0; - - /*! notify object that dump is in progress (e.g. for particles) */ - virtual void notifyOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename, double simtime); - - /*! Search the material for this object from the material list */ - void searchMaterial(vector *mat); - - /* Acces methods */ - /*! Set the property of this object */ - inline void setMaterial(ntlMaterial *p) { mpMaterial = p; } - /*! Get the surface property of this object */ - inline ntlMaterial *getMaterial( void ) { return mpMaterial; } - /*! Set the object property name */ - inline void setMaterialName(string set) { mMaterialName = set; } - /*! Get the object property name */ - inline string getMaterialName( void ) { return mMaterialName; } - - /*! Sets the receive shadows attribute */ - inline void setReceiveShadows(int set) { mReceiveShadows=set; } - /*! Returns the receive shadows attribute */ - inline int getReceiveShadows() const { return mReceiveShadows; } - - /*! Sets the cast shadows attribute */ - inline void setCastShadows(int set) { mCastShadows=set; } - /*! Returns the cast shadows attribute */ - inline int getCastShadows() const { return mCastShadows; } - - /*! Returns the geo init typ */ - inline void setGeoInitType(int set) { mGeoInitType=set; } - /*! Returns the geo init typ */ - inline int getGeoInitType() const { return mGeoInitType; } - - /*! Set/get the intersect init flag */ - inline bool getGeoInitIntersect() const { return mGeoInitIntersect; } - inline void setGeoInitIntersect(bool set) { mGeoInitIntersect=set; } - - /*! Set/get the part slip value*/ - inline float getGeoPartSlipValue() const { return mGeoPartSlipValue; } - inline void setGeoPartSlipValue(float set) { mGeoPartSlipValue=set; } - - /*! Set/get the impact corr factor channel */ - inline float getGeoImpactFactor(double t) { return mcGeoImpactFactor.get(t); } - inline void setGeoImpactFactor(float set) { mcGeoImpactFactor = AnimChannel(set); } - - /*! Set/get the part slip value*/ - inline int getVolumeInit() const { return mVolumeInit; } - inline void setVolumeInit(int set) { mVolumeInit=set; } - - /*! Set/get the cast initial veocity attribute */ - void setInitialVelocity(ntlVec3Gfx set); - ntlVec3Gfx getInitialVelocity(double t); - - /*! Set/get the local inivel coords flag */ - inline bool getLocalCoordInivel() const { return mLocalCoordInivel; } - inline void setLocalCoordInivel(bool set) { mLocalCoordInivel=set; } - - /****************************************/ - /* fluid control features */ - /****************************************/ - /*! Set/get the particle control set attract force strength */ - inline float getCpsTimeStart() const { return mCpsTimeStart; } - inline void setCpsTimeStart(float set) { mCpsTimeStart=set; } - - /*! Set/get the particle control set attract force strength */ - inline float getCpsTimeEnd() const { return mCpsTimeEnd; } - inline void setCpsTimeEnd(float set) { mCpsTimeEnd=set; } - - /*! Set/get the particle control set quality */ - inline float getCpsQuality() const { return mCpsQuality; } - inline void setCpsQuality(float set) { mCpsQuality=set; } - - inline AnimChannel getCpsAttrFStr() const { return mcAttrFStr; } - inline AnimChannel getCpsAttrFRad() const { return mcAttrFRad; } - inline AnimChannel getCpsVelFStr() const { return mcVelFStr; } - inline AnimChannel getCpsVelFRad() const { return mcVelFRad; } - - /****************************************/ - - /*! Init channels from float arrays (for elbeem API) */ - void initChannels( - int nTrans, float *trans, int nRot, float *rot, int nScale, float *scale, - int nAct, float *act, int nIvel, float *ivel, - int nAttrFStr, float *attrFStr, - int nAttrFRad, float *attrFRad, - int nVelFStr, float *velFStr, - int nVelFRad, float *velFRad - ); - - /*! is the object animated? */ - inline bool getIsAnimated() const { return mIsAnimated; } - /*! init object anim flag */ - bool checkIsAnimated(); - /*! is the mesh animated? */ - virtual bool getMeshAnimated(); - /*! init triangle divisions */ - virtual void calcTriangleDivs(vector &verts, vector &tris, gfxReal fsTri); - - /*! apply object translation at time t*/ - void applyTransformation(double t, vector *verts, vector *norms, int vstart, int vend, int forceTrafo); - - /*! Prepare points for moving objects */ - void initMovingPoints(double time, gfxReal featureSize); - /*! Prepare points for animated objects */ - void initMovingPointsAnim( - double srctime, vector &srcpoints, - double dsttime, vector &dstpoints, - vector *dstnormals, - gfxReal featureSize, ntlVec3Gfx geostart, ntlVec3Gfx geoend ); - /*! Prepare points for moving objects (copy into ret) */ - void getMovingPoints(vector &ret, vector *norms = NULL); - /*! Calculate max. velocity on object from t1 to t2 */ - ntlVec3Gfx calculateMaxVel(double t1, double t2); - /*! get translation at time t*/ - ntlVec3Gfx getTranslation(double t); - /*! get active flag time t*/ - float getGeoActive(double t); - - /*! add triangle to scene and init flags */ - // helper function for getTriangles - void sceneAddTriangle( - ntlVec3Gfx p1,ntlVec3Gfx p2,ntlVec3Gfx p3, - ntlVec3Gfx pn1,ntlVec3Gfx pn2,ntlVec3Gfx pn3, - ntlVec3Gfx trin, bool smooth, - vector *triangles, - vector *vertices, - vector *vertNormals); - void sceneAddTriangleNoVert(int *trips, - ntlVec3Gfx trin, bool smooth, - vector *triangles); - - protected: - - /* initialized for scene? */ - bool mIsInitialized; - - /*! Point to a property object describing the surface of this object */ - ntlMaterial *mpMaterial; - - /*! Name of the surcace property */ - string mMaterialName; - - /*! Cast shadows on/off */ - int mCastShadows; - /*! REceive shadows on/off */ - int mReceiveShadows; - - /* fluid init data */ - /*! fluid object type (fluid, obstacle, accelerator etc.) */ - int mGeoInitType; - /*! initial velocity for fluid objects */ - ntlVec3Gfx mInitialVelocity; - AnimChannel mcInitialVelocity; - /*! use object local inflow? */ - bool mLocalCoordInivel; - /*! perform more accurate intersecting geo init for this object? */ - bool mGeoInitIntersect; - /*! part slip bc value */ - float mGeoPartSlipValue; - /*! obstacle impact correction factor */ - AnimChannel mcGeoImpactFactor; - /*! only init as thin object, dont fill? */ - int mVolumeInit; - - /*! initial offset for rot/scale */ - ntlVec3Gfx mInitialPos; - /*! animated channels for postition, rotation and scale */ - AnimChannel mcTrans, mcRot, mcScale; - /*! easy check for animation */ - bool mIsAnimated; - - /*! moving point/normal storage */ - vector mMovPoints; - vector mMovNormals; - /*! cached points for non moving objects/timeslots */ - bool mHaveCachedMov; - vector mCachedMovPoints; - vector mCachedMovNormals; - /*! precomputed triangle divisions */ - vector mTriangleDivs1,mTriangleDivs2; - /*! inited? */ - float mMovPntsInited; - /*! point with max. distance from center */ - int mMaxMovPnt; - - /*! animated channels for in/outflow on/off */ - AnimChannel mcGeoActive; - - /* fluid control settings */ - float mCpsTimeStart; - float mCpsTimeEnd; - float mCpsQuality; - AnimChannel mcAttrFStr, mcAttrFRad, mcVelFStr, mcVelFRad; - - public: - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlGeometryObject") -#endif -}; - -#endif - diff --git a/intern/elbeem/intern/ntl_geometryshader.h b/intern/elbeem/intern/ntl_geometryshader.h deleted file mode 100644 index 5400e05a27a..00000000000 --- a/intern/elbeem/intern/ntl_geometryshader.h +++ /dev/null @@ -1,73 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Interface for a geometry shader - * - *****************************************************************************/ -#ifndef NTL_GEOMETRYSHADER_H -#define NTL_GEOMETRYSHADER_H - -#include "ntl_geometryclass.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -class ntlGeometryObject; -class ntlRenderGlobals; - -class ntlGeometryShader : - public ntlGeometryClass -{ - - public: - - //! Default constructor - inline ntlGeometryShader() : - ntlGeometryClass(), mOutFilename("") - {}; - //! Default destructor - virtual ~ntlGeometryShader() {}; - - //! Return type id - virtual int getTypeId() { return GEOCLASSTID_SHADER; } - - /*! Initialize object, should return !=0 upon error */ - virtual int initializeShader() = 0; - - /*! Do further object initialization after all geometry has been constructed, should return !=0 upon error */ - virtual int postGeoConstrInit(ntlRenderGlobals *glob) { glob=NULL; /*unused*/ return 0; }; - - /*! Get start iterator for all objects */ - virtual vector::iterator getObjectsBegin() { return mObjects.begin(); } - /*! Get end iterator for all objects */ - virtual vector::iterator getObjectsEnd() { return mObjects.end(); } - - /*! notify object that dump is in progress (e.g. for field dump) */ - virtual void notifyShaderOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename) = 0; - - /*! get output filename, returns global render outfile if empty */ - string getOutFilename( void ) { return mOutFilename; } - - protected: - - //! vector for the objects - vector mObjects; - - - /*! surface output name for this simulation */ - string mOutFilename; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlGeometryShader") -#endif -}; - -#endif - diff --git a/intern/elbeem/intern/ntl_lighting.cpp b/intern/elbeem/intern/ntl_lighting.cpp deleted file mode 100644 index aef06f8f490..00000000000 --- a/intern/elbeem/intern/ntl_lighting.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * a light object - * - *****************************************************************************/ - - -#include "ntl_lighting.h" -#include "ntl_ray.h" -#include "ntl_world.h" - - -/****************************************************************************** - * Default Constructor - *****************************************************************************/ -ntlLightObject::ntlLightObject(ntlRenderGlobals *glob) : - mpGlob( glob ), - mActive( 1 ), - mCastShadows( 1 ), - mcColor( ntlColor(1.0) ), - mvPosition( ntlVec3Gfx(0.0) ) -{ - // nothing to do... -} - - -/****************************************************************************** - * Constructor with parameters - *****************************************************************************/ -ntlLightObject::ntlLightObject(ntlRenderGlobals *glob, const ntlColor& col) : - mpGlob( glob ), - mActive( 1 ), - mCastShadows( 1 ), - mcColor( col ) -{ - // nothing to do... -} - - - -/****************************************************************************** - * Destructor - *****************************************************************************/ -ntlLightObject::~ntlLightObject() -{ - // nothing to do... -} - - - -/****************************************************************************** - * Determine color contribution of a lightsource (Phong model) - * Specular part is returned in seperate parameter and added later - *****************************************************************************/ -const ntlColor -ntlLightObject::getShadedColor(const ntlRay &reflectedRay, const ntlVec3Gfx lightDir, - ntlMaterial *surf, ntlColor &highlight) const -{ - gfxReal ldot = dot(lightDir, reflectedRay.getNormal()); /* equals cos( angle(L,N) ) */ - ntlColor reflected_color = ntlColor(0.0); /* adds up to total reflected color */ - if(mpGlob->getDebugOut() > 5) errorOut("Lighting dir:"< 0.0) { - //ldot *= -1.0; - reflected_color += surf->getDiffuseRefl() * (getColor() * ldot ); - - /* specular part */ - /* specular reflection only makes sense, when the light is facing the surface, - as the highlight is supposed to be a reflection of the lightsource, it cannot - be reflected on surfaces with ldot<=0, as this means the arc between light - and normal is more than 90 degrees. If this isn't done, ugly moiree patterns appear - in the highlights, and refractions have strange patterns due to highlights on the - inside of the surface */ - gfxReal spec = dot(reflectedRay.getDirection(), lightDir); // equals cos( angle(R,L) ) - if((spec > 0.0) && (surf->getSpecular()>0)) { - spec = pow( spec, surf->getSpecExponent() ); /* phong exponent */ - highlight += getColor() * surf->getSpecular() * spec; - //errorOut( " "<< surf->getName() <<" S "<getSpecular()<<" "<getSpecExponent() ); - } - - } - - return ntlColor(reflected_color); -} - - -// omni light implementation - - -/****************************************************************************** - *! prepare shadow maps if necessary - *****************************************************************************/ -void ntlLightObject::prepare( bool doCaustics ) -{ - doCaustics = false; // unused - if(!mActive) { return; } -} - - -/****************************************************************************** - * Illuminate the given point on an object - *****************************************************************************/ -ntlColor ntlLightObject::illuminatePoint(ntlRay &reflectedRay, ntlGeometryObject *closest, - ntlColor &highlight ) -{ - /* is this light active? */ - if(!mActive) { return ntlColor(0.0); } - - gfxReal visibility = 1.0; // how much of light is visible - ntlVec3Gfx intersectionPos = reflectedRay.getOrigin(); - ntlColor current_color = ntlColor(0.0); - ntlMaterial *clossurf = closest->getMaterial(); - - ntlVec3Gfx lightDir = (mvPosition - intersectionPos); - gfxReal lightDirNorm = normalize(lightDir); - - // where is the lightsource ? - ntlRay rayOfLight(intersectionPos, lightDir, 0, 1.0, mpGlob ); - - if( (1) && (mCastShadows)&&(closest->getReceiveShadows()) ) { - ntlTriangle *tri; - ntlVec3Gfx triNormal; - gfxReal trit; - mpGlob->getRenderScene()->intersectScene(rayOfLight, trit, triNormal, tri, TRI_CASTSHADOWS); - if(( trit>0 )&&( tritgetDebugOut() > 5) errorOut("Omni lighting with "<0.0) { - ntlColor highTemp(0.0); // temporary highlight color to multiply highTemp with offFac - current_color = getShadedColor(reflectedRay, lightDir, clossurf, highTemp) * visibility; - highlight += highTemp * visibility; - if(mpGlob->getDebugOut() > 5) errorOut("Omni lighting color "< -class ntlMatrix4x4 -{ -public: - // Constructor - inline ntlMatrix4x4(void ); - // Copy-Constructor - inline ntlMatrix4x4(const ntlMatrix4x4 &v ); - // construct a vector from one Scalar - inline ntlMatrix4x4(Scalar); - // construct a vector from three Scalars - inline ntlMatrix4x4(Scalar, Scalar, Scalar); - - // Assignment operator - inline const ntlMatrix4x4& operator= (const ntlMatrix4x4& v); - // Assignment operator - inline const ntlMatrix4x4& operator= (Scalar s); - // Assign and add operator - inline const ntlMatrix4x4& operator+= (const ntlMatrix4x4& v); - // Assign and add operator - inline const ntlMatrix4x4& operator+= (Scalar s); - // Assign and sub operator - inline const ntlMatrix4x4& operator-= (const ntlMatrix4x4& v); - // Assign and sub operator - inline const ntlMatrix4x4& operator-= (Scalar s); - // Assign and mult operator - inline const ntlMatrix4x4& operator*= (const ntlMatrix4x4& v); - // Assign and mult operator - inline const ntlMatrix4x4& operator*= (Scalar s); - // Assign and div operator - inline const ntlMatrix4x4& operator/= (const ntlMatrix4x4& v); - // Assign and div operator - inline const ntlMatrix4x4& operator/= (Scalar s); - - - // unary operator - inline ntlMatrix4x4 operator- () const; - - // binary operator add - inline ntlMatrix4x4 operator+ (const ntlMatrix4x4&) const; - // binary operator add - inline ntlMatrix4x4 operator+ (Scalar) const; - // binary operator sub - inline ntlMatrix4x4 operator- (const ntlMatrix4x4&) const; - // binary operator sub - inline ntlMatrix4x4 operator- (Scalar) const; - // binary operator mult - inline ntlMatrix4x4 operator* (const ntlMatrix4x4&) const; - // binary operator mult - inline ntlVector3Dim operator* (const ntlVector3Dim&) const; - // binary operator mult - inline ntlMatrix4x4 operator* (Scalar) const; - // binary operator div - inline ntlMatrix4x4 operator/ (Scalar) const; - - // init function - //! init identity matrix - inline void initId(); - //! init rotation matrix - inline void initTranslation(Scalar x, Scalar y, Scalar z); - //! init rotation matrix - inline void initRotationX(Scalar rot); - inline void initRotationY(Scalar rot); - inline void initRotationZ(Scalar rot); - inline void initRotationXYZ(Scalar rotx,Scalar roty, Scalar rotz); - //! init scaling matrix - inline void initScaling(Scalar scale); - inline void initScaling(Scalar x, Scalar y, Scalar z); - //! from 16 value array (init id if all 0) - inline void initArrayCheck(Scalar *array); - - //! decompose matrix - void decompose(ntlVector3Dim &trans,ntlVector3Dim &scale,ntlVector3Dim &rot,ntlVector3Dim &shear); - - //! public to avoid [][] operators - Scalar value[4][4]; //< Storage of vector values - - -protected: - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlMatrix4x4") -#endif -}; - - - -//------------------------------------------------------------------------------ -// TYPEDEFS -//------------------------------------------------------------------------------ - -// a 3D vector for graphics output, typically float? -//typedef ntlMatrix4x4 ntlVec3Gfx; - -//typedef ntlMatrix4x4 ntlMat4d; -typedef ntlMatrix4x4 ntlMat4d; - -// a 3D vector with single precision -typedef ntlMatrix4x4 ntlMat4f; - -// a 3D vector with grafix precision -typedef ntlMatrix4x4 ntlMat4Gfx; - -// a 3D integer vector -typedef ntlMatrix4x4 ntlMat4i; - - - - - -//------------------------------------------------------------------------------ -// STREAM FUNCTIONS -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Outputs the object in human readable form using the format - [x,y,z] - */ -template -std::ostream& -operator<<( std::ostream& os, const ntlMatrix4x4& m ) -{ - for(int i=0; i<4; i++) { - os << '|' << m.value[i][0] << ", " << m.value[i][1] << ", " << m.value[i][2] << ", " << m.value[i][3] << '|'; - } - return os; -} - - - -/************************************************************************* - Reads the contents of the object from a stream using the same format - as the output operator. - */ -template -std::istream& -operator>>( std::istream& is, ntlMatrix4x4& m ) -{ - char c; - char dummy[3]; - - for(int i=0; i<4; i++) { - is >> c >> m.value[i][0] >> dummy >> m.value[i][1] >> dummy >> m.value[i][2] >> dummy >> m.value[i][3] >> c; - } - return is; -} - - -//------------------------------------------------------------------------------ -// VECTOR inline FUNCTIONS -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Constructor. - */ -template -inline ntlMatrix4x4::ntlMatrix4x4( void ) -{ -#ifdef MATRIX_INIT_ZERO - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] = 0.0; - } - } -#endif -} - - - -/************************************************************************* - Copy-Constructor. - */ -template -inline ntlMatrix4x4::ntlMatrix4x4( const ntlMatrix4x4 &v ) -{ - value[0][0] = v.value[0][0]; value[0][1] = v.value[0][1]; value[0][2] = v.value[0][2]; value[0][3] = v.value[0][3]; - value[1][0] = v.value[1][0]; value[1][1] = v.value[1][1]; value[1][2] = v.value[1][2]; value[1][3] = v.value[1][3]; - value[2][0] = v.value[2][0]; value[2][1] = v.value[2][1]; value[2][2] = v.value[2][2]; value[2][3] = v.value[2][3]; - value[3][0] = v.value[3][0]; value[3][1] = v.value[3][1]; value[3][2] = v.value[3][2]; value[3][3] = v.value[3][3]; -} - - - -/************************************************************************* - Constructor for a vector from a single Scalar. All components of - the vector get the same value. - \param s The value to set - \return The new vector - */ -template -inline ntlMatrix4x4::ntlMatrix4x4(Scalar s ) -{ - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] = s; - } - } -} - - - -/************************************************************************* - Copy a ntlMatrix4x4 componentwise. - \param v vector with values to be copied - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator=( const ntlMatrix4x4 &v ) -{ - value[0][0] = v.value[0][0]; value[0][1] = v.value[0][1]; value[0][2] = v.value[0][2]; value[0][3] = v.value[0][3]; - value[1][0] = v.value[1][0]; value[1][1] = v.value[1][1]; value[1][2] = v.value[1][2]; value[1][3] = v.value[1][3]; - value[2][0] = v.value[2][0]; value[2][1] = v.value[2][1]; value[2][2] = v.value[2][2]; value[2][3] = v.value[2][3]; - value[3][0] = v.value[3][0]; value[3][1] = v.value[3][1]; value[3][2] = v.value[3][2]; value[3][3] = v.value[3][3]; - return *this; -} - - -/************************************************************************* - Copy a Scalar to each component. - \param s The value to copy - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator=(Scalar s) -{ - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] = s; - } - } - return *this; -} - - -/************************************************************************* - Add another ntlMatrix4x4 componentwise. - \param v vector with values to be added - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator+=( const ntlMatrix4x4 &v ) -{ - value[0][0] += v.value[0][0]; value[0][1] += v.value[0][1]; value[0][2] += v.value[0][2]; value[0][3] += v.value[0][3]; - value[1][0] += v.value[1][0]; value[1][1] += v.value[1][1]; value[1][2] += v.value[1][2]; value[1][3] += v.value[1][3]; - value[2][0] += v.value[2][0]; value[2][1] += v.value[2][1]; value[2][2] += v.value[2][2]; value[2][3] += v.value[2][3]; - value[3][0] += v.value[3][0]; value[3][1] += v.value[3][1]; value[3][2] += v.value[3][2]; value[3][3] += v.value[3][3]; - return *this; -} - - -/************************************************************************* - Add a Scalar value to each component. - \param s Value to add - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator+=(Scalar s) -{ - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] += s; - } - } - return *this; -} - - -/************************************************************************* - Subtract another vector componentwise. - \param v vector of values to subtract - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator-=( const ntlMatrix4x4 &v ) -{ - value[0][0] -= v.value[0][0]; value[0][1] -= v.value[0][1]; value[0][2] -= v.value[0][2]; value[0][3] -= v.value[0][3]; - value[1][0] -= v.value[1][0]; value[1][1] -= v.value[1][1]; value[1][2] -= v.value[1][2]; value[1][3] -= v.value[1][3]; - value[2][0] -= v.value[2][0]; value[2][1] -= v.value[2][1]; value[2][2] -= v.value[2][2]; value[2][3] -= v.value[2][3]; - value[3][0] -= v.value[3][0]; value[3][1] -= v.value[3][1]; value[3][2] -= v.value[3][2]; value[3][3] -= v.value[3][3]; - return *this; -} - - -/************************************************************************* - Subtract a Scalar value from each component. - \param s Value to subtract - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator-=(Scalar s) -{ - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] -= s; - } - } - return *this; -} - - -/************************************************************************* - Multiply with another vector componentwise. - \param v vector of values to multiply with - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator*=( const ntlMatrix4x4 &v ) -{ - ntlMatrix4x4 nv(0.0); - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - - for(int k=0;k<4;k++) - nv.value[i][j] += (value[i][k] * v.value[k][j]); - } - } - *this = nv; - return *this; -} - - -/************************************************************************* - Multiply each component with a Scalar value. - \param s Value to multiply with - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator*=(Scalar s) -{ - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] *= s; - } - } - return *this; -} - - - -/************************************************************************* - Divide each component by a Scalar value. - \param s Value to divide by - \return Reference to self - */ -template -inline const ntlMatrix4x4& -ntlMatrix4x4::operator/=(Scalar s) -{ - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] /= s; - } - } - return *this; -} - - -//------------------------------------------------------------------------------ -// unary operators -//------------------------------------------------------------------------------ - - -/************************************************************************* - Build componentwise the negative this vector. - \return The new (negative) vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator-() const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = -value[i][j]; - } - } - return nv; -} - - - -//------------------------------------------------------------------------------ -// binary operators -//------------------------------------------------------------------------------ - - -/************************************************************************* - Build a vector with another vector added componentwise. - \param v The second vector to add - \return The sum vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator+( const ntlMatrix4x4 &v ) const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = value[i][j] + v.value[i][j]; - } - } - return nv; -} - - -/************************************************************************* - Build a vector with a Scalar value added to each component. - \param s The Scalar value to add - \return The sum vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator+(Scalar s) const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = value[i][j] + s; - } - } - return nv; -} - - -/************************************************************************* - Build a vector with another vector subtracted componentwise. - \param v The second vector to subtract - \return The difference vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator-( const ntlMatrix4x4 &v ) const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = value[i][j] - v.value[i][j]; - } - } - return nv; -} - - -/************************************************************************* - Build a vector with a Scalar value subtracted componentwise. - \param s The Scalar value to subtract - \return The difference vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator-(Scalar s ) const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = value[i][j] - s; - } - } - return nv; -} - - - -/************************************************************************* - Build a ntlMatrix4x4 with a Scalar value multiplied to each component. - \param s The Scalar value to multiply with - \return The product vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator*(Scalar s) const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = value[i][j] * s; - } - } - return nv; -} - - - - -/************************************************************************* - Build a vector divided componentwise by a Scalar value. - \param s The Scalar value to divide by - \return The ratio vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator/(Scalar s) const -{ - ntlMatrix4x4 nv; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - nv[i][j] = value[i][j] / s; - } - } - return nv; -} - - - - - -/************************************************************************* - Build a vector with another vector multiplied by componentwise. - \param v The second vector to muliply with - \return The product vector - */ -template -inline ntlMatrix4x4 -ntlMatrix4x4::operator*( const ntlMatrix4x4& v) const -{ - ntlMatrix4x4 nv(0.0); - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - - for(int k=0;k<4;k++) - nv.value[i][j] += (value[i][k] * v.value[k][j]); - } - } - return nv; -} - - -template -inline ntlVector3Dim -ntlMatrix4x4::operator*( const ntlVector3Dim& v) const -{ - ntlVector3Dim nvec(0.0); - for(int i=0; i<3; i++) { - for(int j=0; j<3; j++) { - nvec[i] += (v[j] * value[i][j]); - } - } - // assume normalized w coord - for(int i=0; i<3; i++) { - nvec[i] += (1.0 * value[i][3]); - } - return nvec; -} - - - -//------------------------------------------------------------------------------ -// Other helper functions -//------------------------------------------------------------------------------ - -//! init identity matrix -template -inline void ntlMatrix4x4::initId() -{ - (*this) = (Scalar)(0.0); - value[0][0] = - value[1][1] = - value[2][2] = - value[3][3] = (Scalar)(1.0); -} - -//! init rotation matrix -template -inline void ntlMatrix4x4::initTranslation(Scalar x, Scalar y, Scalar z) -{ - //(*this) = (Scalar)(0.0); - this->initId(); - value[0][3] = x; - value[1][3] = y; - value[2][3] = z; -} - -//! init rotation matrix -template -inline void -ntlMatrix4x4::initRotationX(Scalar rot) -{ - double drot = (double)(rot/360.0*2.0*M_PI); - //? while(drot < 0.0) drot += (M_PI*2.0); - - this->initId(); - value[1][1] = (Scalar) cos(drot); - value[1][2] = (Scalar) sin(drot); - value[2][1] = (Scalar)(-sin(drot)); - value[2][2] = (Scalar) cos(drot); -} -template -inline void -ntlMatrix4x4::initRotationY(Scalar rot) -{ - double drot = (double)(rot/360.0*2.0*M_PI); - //? while(drot < 0.0) drot += (M_PI*2.0); - - this->initId(); - value[0][0] = (Scalar) cos(drot); - value[0][2] = (Scalar)(-sin(drot)); - value[2][0] = (Scalar) sin(drot); - value[2][2] = (Scalar) cos(drot); -} -template -inline void -ntlMatrix4x4::initRotationZ(Scalar rot) -{ - double drot = (double)(rot/360.0*2.0*M_PI); - //? while(drot < 0.0) drot += (M_PI*2.0); - - this->initId(); - value[0][0] = (Scalar) cos(drot); - value[0][1] = (Scalar) sin(drot); - value[1][0] = (Scalar)(-sin(drot)); - value[1][1] = (Scalar) cos(drot); -} -template -inline void -ntlMatrix4x4::initRotationXYZ( Scalar rotx, Scalar roty, Scalar rotz) -{ - ntlMatrix4x4 val; - ntlMatrix4x4 rot; - this->initId(); - - // org - /*rot.initRotationX(rotx); - (*this) *= rot; - rot.initRotationY(roty); - (*this) *= rot; - rot.initRotationZ(rotz); - (*this) *= rot; - // org */ - - // blender - rot.initRotationZ(rotz); - (*this) *= rot; - rot.initRotationY(roty); - (*this) *= rot; - rot.initRotationX(rotx); - (*this) *= rot; - // blender */ -} - -//! init scaling matrix -template -inline void -ntlMatrix4x4::initScaling(Scalar scale) -{ - this->initId(); - value[0][0] = scale; - value[1][1] = scale; - value[2][2] = scale; -} -//! init scaling matrix -template -inline void -ntlMatrix4x4::initScaling(Scalar x, Scalar y, Scalar z) -{ - this->initId(); - value[0][0] = x; - value[1][1] = y; - value[2][2] = z; -} - - -//! from 16 value array (init id if all 0) -template -inline void -ntlMatrix4x4::initArrayCheck(Scalar *array) -{ - bool allZero = true; - for(int i=0; i<4; i++) { - for(int j=0; j<4; j++) { - value[i][j] = array[i*4+j]; - if(array[i*4+j]!=0.0) allZero=false; - } - } - if(allZero) this->initId(); -} - -//! decompose matrix -template -void -ntlMatrix4x4::decompose(ntlVector3Dim &trans,ntlVector3Dim &scale,ntlVector3Dim &rot,ntlVector3Dim &shear) { - ntlVec3Gfx row[3],temp; - - for(int i = 0; i < 3; i++) { - trans[i] = this->value[3][i]; - } - - for(int i = 0; i < 3; i++) { - row[i][0] = this->value[i][0]; - row[i][1] = this->value[i][1]; - row[i][2] = this->value[i][2]; - } - - scale[0] = norm(row[0]); - normalize (row[0]); - - shear[0] = dot(row[0], row[1]); - row[1][0] = row[1][0] - shear[0]*row[0][0]; - row[1][1] = row[1][1] - shear[0]*row[0][1]; - row[1][2] = row[1][2] - shear[0]*row[0][2]; - - scale[1] = norm(row[1]); - normalize (row[1]); - - if(scale[1] != 0.0) - shear[0] /= scale[1]; - - shear[1] = dot(row[0], row[2]); - row[2][0] = row[2][0] - shear[1]*row[0][0]; - row[2][1] = row[2][1] - shear[1]*row[0][1]; - row[2][2] = row[2][2] - shear[1]*row[0][2]; - - shear[2] = dot(row[1], row[2]); - row[2][0] = row[2][0] - shear[2]*row[1][0]; - row[2][1] = row[2][1] - shear[2]*row[1][1]; - row[2][2] = row[2][2] - shear[2]*row[1][2]; - - scale[2] = norm(row[2]); - normalize (row[2]); - - if(scale[2] != 0.0) { - shear[1] /= scale[2]; - shear[2] /= scale[2]; - } - - temp = cross(row[1], row[2]); - if(dot(row[0], temp) < 0.0) { - for(int i = 0; i < 3; i++) { - scale[i] *= -1.0; - row[i][0] *= -1.0; - row[i][1] *= -1.0; - row[i][2] *= -1.0; - } - } - - if(row[0][2] < -1.0) row[0][2] = -1.0; - if(row[0][2] > +1.0) row[0][2] = +1.0; - - rot[1] = asin(-row[0][2]); - - if(fabs(cos(rot[1])) > VECTOR_EPSILON) { - rot[0] = atan2 (row[1][2], row[2][2]); - rot[2] = atan2 (row[0][1], row[0][0]); - } - else { - rot[0] = atan2 (row[1][0], row[1][1]); - rot[2] = 0.0; - } - - rot[0] = (180.0/M_PI)*rot[0]; - rot[1] = (180.0/M_PI)*rot[1]; - rot[2] = (180.0/M_PI)*rot[2]; -} - -#define NTL_MATRICES_H -#endif - diff --git a/intern/elbeem/intern/ntl_ray.cpp b/intern/elbeem/intern/ntl_ray.cpp deleted file mode 100644 index 1acc8cdca12..00000000000 --- a/intern/elbeem/intern/ntl_ray.cpp +++ /dev/null @@ -1,915 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * main renderer class - * - *****************************************************************************/ - - -#include "utilities.h" -#include "ntl_ray.h" -#include "ntl_world.h" -#include "ntl_geometryobject.h" -#include "ntl_geometryshader.h" - - -/* Minimum value for refl/refr to be traced */ -#define RAY_THRESHOLD 0.001 - -#if GFX_PRECISION==1 -// float values -//! Minimal contribution for rays to be traced on -#define RAY_MINCONTRIB (1e-04) - -#else -// double values -//! Minimal contribution for rays to be traced on -#define RAY_MINCONTRIB (1e-05) - -#endif - - - - - -/****************************************************************************** - * Constructor - *****************************************************************************/ -ntlRay::ntlRay( void ) - : mOrigin(0.0) - , mDirection(0.0) - , mvNormal(0.0) - , mDepth(0) - , mpGlob(NULL) - , mIsRefracted(0) -{ - errFatal("ntlRay::ntlRay()","Don't use uninitialized rays !", SIMWORLD_GENERICERROR); - return; -} - - -/****************************************************************************** - * Copy - Constructor - *****************************************************************************/ -ntlRay::ntlRay( const ntlRay &r ) -{ - // copy it! initialization is not enough! - mOrigin = r.mOrigin; - mDirection = r.mDirection; - mvNormal = r.mvNormal; - mDepth = r.mDepth; - mIsRefracted = r.mIsRefracted; - mIsReflected = r.mIsReflected; - mContribution = r.mContribution; - mpGlob = r.mpGlob; - - // get new ID - if(mpGlob) { - mID = mpGlob->getCounterRays()+1; - mpGlob->setCounterRays( mpGlob->getCounterRays()+1 ); - } else { - mID = 0; - } -} - - -/****************************************************************************** - * Constructor with explicit parameters and global render object - *****************************************************************************/ -ntlRay::ntlRay(const ntlVec3Gfx &o, const ntlVec3Gfx &d, unsigned int i, gfxReal contrib, ntlRenderGlobals *glob) - : mOrigin( o ) - , mDirection( d ) - , mvNormal(0.0) - , mDepth( i ) - , mContribution( contrib ) - , mpGlob( glob ) - , mIsRefracted( 0 ) - , mIsReflected( 0 ) -{ - // get new ID - if(mpGlob) { - mID = mpGlob->getCounterRays()+1; - mpGlob->setCounterRays( mpGlob->getCounterRays()+1 ); - } else { - mID = 0; - } -} - - - -/****************************************************************************** - * Destructor - *****************************************************************************/ -ntlRay::~ntlRay() -{ - /* nothing to do... */ -} - - - -/****************************************************************************** - * AABB - *****************************************************************************/ -/* for AABB intersect */ -#define NUMDIM 3 -#define RIGHT 0 -#define LEFT 1 -#define MIDDLE 2 - -//! intersect ray with AABB -#ifndef ELBEEM_PLUGIN -void ntlRay::intersectFrontAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &t, ntlVec3Gfx &retnormal,ntlVec3Gfx &retcoord) const -{ - char inside = true; /* inside box? */ - char hit = false; /* ray hits box? */ - int whichPlane; /* intersection plane */ - gfxReal candPlane[NUMDIM]; /* candidate plane */ - gfxReal quadrant[NUMDIM]; /* quadrants */ - gfxReal maxT[NUMDIM]; /* max intersection T for planes */ - ntlVec3Gfx coord; /* intersection point */ - ntlVec3Gfx dir = mDirection; - ntlVec3Gfx origin = mOrigin; - ntlVec3Gfx normal(0.0, 0.0, 0.0); - - t = GFX_REAL_MAX; - - /* check intersection planes for AABB */ - for(int i=0;i mEnd[i]) { - quadrant[i] = RIGHT; - candPlane[i] = mEnd[i]; - inside = false; - } else { - quadrant[i] = MIDDLE; - } - } - - /* inside AABB? */ - if(!inside) { - /* get t distances to planes */ - /* treat too small direction components as paralell */ - for(int i=0;i getVecEpsilon()) ) { - maxT[i] = (candPlane[i] - origin[i]) / dir[i]; - } else { - maxT[i] = -1; - } - } - - /* largest max t */ - whichPlane = 0; - for(int i=1;i= 0.0) { - - for(int i=0;i mEnd[i] +getVecEpsilon() ) ) { - /* no hit... */ - hit = false; - } - } - else { - coord[i] = candPlane[i]; - } - } - - /* AABB hit... */ - if( hit ) { - t = maxT[whichPlane]; - if(quadrant[whichPlane]==RIGHT) normal[whichPlane] = 1.0; - else normal[whichPlane] = -1.0; - } - } - - - } else { - /* inside AABB... */ - t = 0.0; - coord = origin; - return; - } - - if(t == GFX_REAL_MAX) t = -1.0; - retnormal = normal; - retcoord = coord; -} - -//! intersect ray with AABB -void ntlRay::intersectBackAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &t, ntlVec3Gfx &retnormal,ntlVec3Gfx &retcoord) const -{ - char hit = false; /* ray hits box? */ - int whichPlane; /* intersection plane */ - gfxReal candPlane[NUMDIM]; /* candidate plane */ - gfxReal quadrant[NUMDIM]; /* quadrants */ - gfxReal maxT[NUMDIM]; /* max intersection T for planes */ - ntlVec3Gfx coord; /* intersection point */ - ntlVec3Gfx dir = mDirection; - ntlVec3Gfx origin = mOrigin; - ntlVec3Gfx normal(0.0, 0.0, 0.0); - - t = GFX_REAL_MAX; - for(int i=0;i mEnd[i]) { - quadrant[i] = RIGHT; - candPlane[i] = mStart[i]; - } else { - if(dir[i] > 0) { - quadrant[i] = LEFT; - candPlane [i] = mEnd[i]; - } else - if(dir[i] < 0) { - quadrant[i] = RIGHT; - candPlane[i] = mStart[i]; - } else { - quadrant[i] = MIDDLE; - } - } - } - - - /* get t distances to planes */ - /* treat too small direction components as paralell */ - for(int i=0;i getVecEpsilon()) ) { - maxT[i] = (candPlane[i] - origin[i]) / dir[i]; - } else { - maxT[i] = GFX_REAL_MAX; - } - } - - /* largest max t */ - whichPlane = 0; - for(int i=1;i maxT[i]) whichPlane = i; - } - - /* check final candidate */ - hit = true; - if(maxT[whichPlane] != GFX_REAL_MAX) { - - for(int i=0;i mEnd[i] +getVecEpsilon() ) ) { - /* no hit... */ - hit = false; - } - } - else { - coord[i] = candPlane[i]; - } - } - - /* AABB hit... */ - if( hit ) { - t = maxT[whichPlane]; - - if(quadrant[whichPlane]==RIGHT) normal[whichPlane] = 1.0; - else normal[whichPlane] = -1.0; - } - } - - - if(t == GFX_REAL_MAX) t = -1.0; - retnormal = normal; - retcoord = coord; -} -#endif // ELBEEM_PLUGIN - -//! intersect ray with AABB -void ntlRay::intersectCompleteAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &tmin, gfxReal &tmax) const -{ - // char inside = true; /* inside box? */ /* UNUSED */ - char hit = false; /* ray hits box? */ - int whichPlane; /* intersection plane */ - gfxReal candPlane[NUMDIM]; /* candidate plane */ - gfxReal quadrant[NUMDIM]; /* quadrants */ - gfxReal maxT[NUMDIM]; /* max intersection T for planes */ - ntlVec3Gfx coord; /* intersection point */ - ntlVec3Gfx dir = mDirection; - ntlVec3Gfx origin = mOrigin; - gfxReal t = GFX_REAL_MAX; - - /* check intersection planes for AABB */ - for(int i=0;i mEnd[i]) { - quadrant[i] = RIGHT; - candPlane[i] = mEnd[i]; - // inside = false; - } else { - /* intersect with backside */ - if(dir[i] > 0) { - quadrant[i] = LEFT; - candPlane [i] = mStart[i]; - } else - if(dir[i] < 0) { - quadrant[i] = RIGHT; - candPlane[i] = mEnd[i]; - } else { - quadrant[i] = MIDDLE; - } - } - } - - /* get t distances to planes */ - for(int i=0;i getVecEpsilon()) ) { - maxT[i] = (candPlane[i] - origin[i]) / dir[i]; - } else { - maxT[i] = GFX_REAL_MAX; - } - } - - /* largest max t */ - whichPlane = 0; - for(int i=1;i mEnd[i] +getVecEpsilon() ) ) { - /* no hit... */ - hit = false; - } - } - else { coord[i] = candPlane[i]; } - } - - /* AABB hit... */ - if( hit ) { - t = maxT[whichPlane]; - } - } - tmin = t; - - /* now the backside */ - t = GFX_REAL_MAX; - for(int i=0;i mEnd[i]) { - quadrant[i] = RIGHT; - candPlane[i] = mStart[i]; - } else { - if(dir[i] > 0) { - quadrant[i] = LEFT; - candPlane [i] = mEnd[i]; - } else - if(dir[i] < 0) { - quadrant[i] = RIGHT; - candPlane[i] = mStart[i]; - } else { - quadrant[i] = MIDDLE; - } - } - } - - - /* get t distances to planes */ - for(int i=0;i getVecEpsilon()) ) { - maxT[i] = (candPlane[i] - origin[i]) / dir[i]; - } else { - maxT[i] = GFX_REAL_MAX; - } - } - - /* smallest max t */ - whichPlane = 0; - for(int i=1;i maxT[i]) whichPlane = i; - } - - /* check final candidate */ - hit = true; - if(maxT[whichPlane] != GFX_REAL_MAX) { - - for(int i=0;i mEnd[i] +getVecEpsilon() ) ) { - /* no hit... */ - hit = false; - } - } - else { - coord[i] = candPlane[i]; - } - } - - /* AABB hit... */ - if( hit ) { - t = maxT[whichPlane]; - } - } - - tmax = t; -} - - - -/****************************************************************************** - * Determine color of this ray by tracing through the scene - *****************************************************************************/ -const ntlColor ntlRay::shade() //const -{ -#ifndef ELBEEM_PLUGIN - ntlGeometryObject *closest = NULL; - gfxReal minT = GFX_REAL_MAX; - vector *lightlist = mpGlob->getLightList(); - mpGlob->setCounterShades( mpGlob->getCounterShades()+1 ); - bool intersectionInside = 0; - if(mpGlob->getDebugOut() > 5) errorOut(std::endl<<"New Ray: depth "<getRenderScene()->intersectScene(*this, minT, normal, tri, 0); - if(minT>0) { - closest = mpGlob->getRenderScene()->getObject( tri->getObjectId() ); - } - - /* object hit... */ - if (closest != NULL) { - - ntlVec3Gfx triangleNormal = tri->getNormal(); - if( equal(triangleNormal, ntlVec3Gfx(0.0)) ) errorOut("ntlRay warning: trinagle normal= 0 "); // DEBUG - /* intersection on inside faces? if yes invert normal afterwards */ - gfxReal valDN; // = mDirection | normal; - valDN = dot(mDirection, triangleNormal); - if( valDN > 0.0) { - intersectionInside = 1; - normal = normal * -1.0; - triangleNormal = triangleNormal * -1.0; - } - - /* ... -> do reflection */ - ntlVec3Gfx intersectionPosition(mOrigin + (mDirection * (minT)) ); - ntlMaterial *clossurf = closest->getMaterial(); - /*if(mpGlob->getDebugOut() > 5) { - errorOut("Ray hit: at "<getRenderScene()->getVertex(tri->getPoints()[0])<<" t2:"<getRenderScene()->getVertex(tri->getPoints()[1])<<" t3:"<getScene()->getVertex(tri->getPoints()[2]) ); - errorOut(" trin:"<getNormal() ); - } // debug */ - - /* current transparence and reflectivity */ - gfxReal currTrans = clossurf->getTransparence(); - gfxReal currRefl = clossurf->getMirror(); - - /* correct intersectopm position */ - intersectionPosition += ( triangleNormal*getVecEpsilon() ); - /* reflection at normal */ - ntlVec3Gfx reflectedDir = getNormalized( reflectVector(mDirection, normal) ); - int badRefl = 0; - if(dot(reflectedDir, triangleNormal)<0.0 ) { - badRefl = 1; - if(mpGlob->getDebugOut() > 5) { errorOut("Ray Bad reflection...!"); } - } - - /* refraction direction, depending on in/outside hit */ - ntlVec3Gfx refractedDir; - int refRefl = 0; - /* refraction at normal is handled by inverting normal before */ - gfxReal myRefIndex = 1.0; - if((currTrans>RAY_THRESHOLD)||(clossurf->getFresnel())) { - if(intersectionInside) { - myRefIndex = 1.0/clossurf->getRefracIndex(); - } else { - myRefIndex = clossurf->getRefracIndex(); - } - - refractedDir = refractVector(mDirection, normal, myRefIndex , (gfxReal)(1.0) /* global ref index */, refRefl); - } - - /* calculate fresnel? */ - if(clossurf->getFresnel()) { - // for total reflection, just set trans to 0 - if(refRefl) { - currRefl = 1.0; currTrans = 0.0; - } else { - // calculate fresnel coefficients - clossurf->calculateFresnel( mDirection, normal, myRefIndex, currRefl,currTrans ); - } - } - - ntlRay reflectedRay(intersectionPosition, reflectedDir, mDepth+1, mContribution*currRefl, mpGlob); - reflectedRay.setNormal( normal ); - ntlColor currentColor(0.0); - ntlColor highlightColor(0.0); - - /* first add reflected ambient color */ - currentColor += (clossurf->getAmbientRefl() * mpGlob->getAmbientLight() ); - - /* calculate lighting, not on the insides of objects... */ - if(!intersectionInside) { - for (vector::iterator iter = lightlist->begin(); - iter != lightlist->end(); - iter++) { - - /* let light illuminate point */ - currentColor += (*iter)->illuminatePoint( reflectedRay, closest, highlightColor ); - - } // for all lights - } - - // recurse ? - if ((mDepth < mpGlob->getRayMaxDepth() )&&(currRefl>RAY_THRESHOLD)) { - - if(badRefl) { - ntlVec3Gfx intersectionPosition2; - ntlGeometryObject *closest2 = NULL; - gfxReal minT2 = GFX_REAL_MAX; - ntlTriangle *tri2 = NULL; - ntlVec3Gfx normal2; - - ntlVec3Gfx refractionPosition2(mOrigin + (mDirection * minT) ); - refractionPosition2 -= (triangleNormal*getVecEpsilon() ); - - ntlRay reflectedRay2 = ntlRay(refractionPosition2, reflectedDir, mDepth+1, mContribution*currRefl, mpGlob); - mpGlob->getRenderScene()->intersectScene(reflectedRay2, minT2, normal2, tri2, 0); - if(minT2>0) { - closest2 = mpGlob->getRenderScene()->getObject( tri2->getObjectId() ); - } - - /* object hit... */ - if (closest2 != NULL) { - ntlVec3Gfx triangleNormal2 = tri2->getNormal(); - gfxReal valDN2; - valDN2 = dot(reflectedDir, triangleNormal2); - if( valDN2 > 0.0) { - triangleNormal2 = triangleNormal2 * -1.0; - intersectionPosition2 = ntlVec3Gfx(intersectionPosition + (reflectedDir * (minT2)) ); - /* correct intersection position and create new reflected ray */ - intersectionPosition2 += ( triangleNormal2*getVecEpsilon() ); - reflectedRay = ntlRay(intersectionPosition2, reflectedDir, mDepth+1, mContribution*currRefl, mpGlob); - } else { - // ray seems to work, continue normally ? - } - - } - - } - - // add mirror color multiplied by mirror factor of surface - if(mpGlob->getDebugOut() > 5) errorOut("Reflected ray from depth "< RAY_THRESHOLD) { - /* position at the other side of the surface, along ray */ - ntlVec3Gfx refraction_position(mOrigin + (mDirection * minT) ); - refraction_position += (mDirection * getVecEpsilon()); - refraction_position -= (triangleNormal*getVecEpsilon() ); - ntlColor refracCol(0.0); /* refracted color */ - - /* trace refracted ray */ - ntlRay transRay(refraction_position, refractedDir, mDepth+1, mContribution*currTrans, mpGlob); - transRay.setRefracted(1); - transRay.setNormal( normal ); - if(mDepth < mpGlob->getRayMaxDepth() ) { - // full reflection should make sure refracindex&fresnel are on... - if((0)||(!refRefl)) { - if(mpGlob->getDebugOut() > 5) errorOut("Refracted ray from depth "<getDebugOut() > 5) errorOut("Fully reflected ray from depth "<getTransAttCol(); - kr = exp( attCol[0] * minT ); - kg = exp( attCol[1] * minT ); - kb = exp( attCol[2] * minT ); - currentColor = currentColor * ntlColor(kr,kg,kb); - } - - /* done... */ - if(mpGlob->getDebugOut() > 5) { errorOut("Ray "< ray goes to infinity */ - return mpGlob->getBackgroundCol(); -} - - - -/****************************************************************************** - ****************************************************************************** - ****************************************************************************** - * scene implementation - ****************************************************************************** - ****************************************************************************** - *****************************************************************************/ - - - -/****************************************************************************** - * Constructor - *****************************************************************************/ -ntlScene::ntlScene( ntlRenderGlobals *glob, bool del ) : - mpGlob( glob ), mSceneDel(del), - mpTree( NULL ), - mSceneBuilt( false ), mFirstInitDone( false ) -{ -} - - -/****************************************************************************** - * Destructor - *****************************************************************************/ -ntlScene::~ntlScene() -{ - if(mpTree != NULL) delete mpTree; - - // cleanup lists, only if this is the rendering cleanup scene - if(mSceneDel) - { - for (vector::iterator iter = mGeos.begin(); - iter != mGeos.end(); iter++) { - //errMsg("ntlScene::~ntlScene","Deleting obj "<<(*iter)->getName() ); - delete (*iter); - } - for (vector::iterator iter = mpGlob->getLightList()->begin(); - iter != mpGlob->getLightList()->end(); iter++) { - delete (*iter); - } - for (vector::iterator iter = mpGlob->getMaterials()->begin(); - iter != mpGlob->getMaterials()->end(); iter++) { - delete (*iter); - } - } - errMsg("ntlScene::~ntlScene","Deleted, ObjFree:"<::iterator iter = mGeos.begin(); - iter != mGeos.end(); iter++) { - bool geoinit = false; - int tid = (*iter)->getTypeId(); - if(tid & GEOCLASSTID_OBJECT) { - ntlGeometryObject *geoobj = (ntlGeometryObject*)(*iter); - geoinit = true; - mObjects.push_back( geoobj ); - if(buildInfo) debMsgStd("ntlScene::BuildScene",DM_MSG,"added GeoObj "<getName()<<" Id:"<getObjectId(), 5 ); - } - //if(geoshad) { - if(tid & GEOCLASSTID_SHADER) { - ntlGeometryShader *geoshad = (ntlGeometryShader*)(*iter); - geoinit = true; - if(!mFirstInitDone) { - // only on first init - geoshad->initializeShader(); - } - for (vector::iterator siter = geoshad->getObjectsBegin(); - siter != geoshad->getObjectsEnd(); - siter++) { - if(buildInfo) debMsgStd("ntlScene::BuildScene",DM_MSG,"added shader geometry "<<(*siter)->getName()<<" Id:"<<(*siter)->getObjectId(), 5 ); - mObjects.push_back( (*siter) ); - } - } - - if(!geoinit) { - errFatal("ntlScene::BuildScene","Invalid geometry class!", SIMWORLD_INITERROR); - return; - } - } - } - - // collect triangles - mTriangles.clear(); - mVertices.clear(); - mVertNormals.clear(); - - /* for test mode deactivate transparencies etc. */ - if( mpGlob->getTestMode() ) { - debugOut("ntlScene::buildScene : Test Mode activated!", 2); - // assign random colors to dark materials - int matCounter = 0; - ntlColor stdCols[] = { ntlColor(0,0,1.0), ntlColor(0,1.0,0), ntlColor(1.0,0.7,0) , ntlColor(0.7,0,0.6) }; - int stdColNum = 4; - for (vector::iterator iter = mpGlob->getMaterials()->begin(); - iter != mpGlob->getMaterials()->end(); iter++) { - (*iter)->setTransparence(0.0); - (*iter)->setMirror(0.0); - (*iter)->setFresnel(false); - // too dark? - if( norm((*iter)->getDiffuseRefl()) <0.01) { - (*iter)->setDiffuseRefl( stdCols[matCounter] ); - matCounter ++; - matCounter = matCounter%stdColNum; - } - } - - // restrict output file size to 400 - float downscale = 1.0; - if(mpGlob->getResX() > 400){ downscale = 400.0/(float)mpGlob->getResX(); } - if(mpGlob->getResY() > 400){ - float downscale2 = 400.0/(float)mpGlob->getResY(); - if(downscale2setResX( (int)(mpGlob->getResX() * downscale) ); - mpGlob->setResY( (int)(mpGlob->getResY() * downscale) ); - - } - - /* collect triangles from objects */ - int idCnt = 0; // give IDs to objects - bool debugTriCollect = false; - if(debugTriCollect) debMsgStd("ntlScene::buildScene",DM_MSG,"Start...",5); - for (vector::iterator iter = mObjects.begin(); - iter != mObjects.end(); - iter++) { - /* only add visible objects */ - if(firstInit) { - if(debugTriCollect) debMsgStd("ntlScene::buildScene",DM_MSG,"Collect init of "<<(*iter)->getName()<<" idCnt:"<initialize( mpGlob ); } - if(debugTriCollect) debMsgStd("ntlScene::buildScene",DM_MSG,"Collecting tris from "<<(*iter)->getName(), 4 ); - - int vstart = mVertNormals.size(); - (*iter)->setObjectId(idCnt); - (*iter)->getTriangles(time, &mTriangles, &mVertices, &mVertNormals, idCnt); - (*iter)->applyTransformation(time, &mVertices, &mVertNormals, vstart, mVertices.size(), false ); - - if(debugTriCollect) debMsgStd("ntlScene::buildScene",DM_MSG,"Done with "<<(*iter)->getName()<<" totTris:"<::iterator iter = mTriangles.begin(); - iter != mTriangles.end(); - iter++) { - - // calculate normal from triangle points - ntlVec3Gfx normal = - cross( (ntlVec3Gfx)( (mVertices[(*iter).getPoints()[2]] - mVertices[(*iter).getPoints()[0]]) *-1.0), // BLITZ minus sign right?? - (ntlVec3Gfx)(mVertices[(*iter).getPoints()[1]] - mVertices[(*iter).getPoints()[0]]) ); - normalize(normal); - (*iter).setNormal( normal ); - } - - - - // scene geometry built - mSceneBuilt = true; - - // init shaders that require complete geometry - if(!mFirstInitDone) { - // only on first init - for (vector::iterator iter = mGeos.begin(); - iter != mGeos.end(); iter++) { - if( (*iter)->getTypeId() & GEOCLASSTID_SHADER ) { - ntlGeometryShader *geoshad = (ntlGeometryShader*)(*iter); - if(geoshad->postGeoConstrInit( mpGlob )) { - errFatal("ntlScene::buildScene","Init failed for object '"<< (*iter)->getName() <<"' !", SIMWORLD_INITERROR ); - return; - } - } - } - mFirstInitDone = true; - } - - // check unused attributes (for classes and objects!) - for (vector::iterator iter = mObjects.begin(); iter != mObjects.end(); iter++) { - if((*iter)->getAttributeList()->checkUnusedParams()) { - (*iter)->getAttributeList()->print(); // DEBUG - errFatal("ntlScene::buildScene","Unused params for object '"<< (*iter)->getName() <<"' !", SIMWORLD_INITERROR ); - return; - } - } - for (vector::iterator iter = mGeos.begin(); iter != mGeos.end(); iter++) { - if((*iter)->getAttributeList()->checkUnusedParams()) { - (*iter)->getAttributeList()->print(); // DEBUG - errFatal("ntlScene::buildScene","Unused params for object '"<< (*iter)->getName() <<"' !", SIMWORLD_INITERROR ); - return; - } - } - -} - -/****************************************************************************** - * Prepare the scene triangles and maps for raytracing - *****************************************************************************/ -void ntlScene::prepareScene(double time) -{ - /* init triangles... */ - buildScene(time, false); - // what for currently not used ??? - if(mpTree != NULL) delete mpTree; - mpTree = new ntlTree( -# if FSGR_STRICT_DEBUG!=1 - mpGlob->getTreeMaxDepth(), mpGlob->getTreeMaxTriangles(), -# else - mpGlob->getTreeMaxDepth()/3*2, mpGlob->getTreeMaxTriangles()*2, -# endif - this, TRI_GEOMETRY ); - - //debMsgStd("ntlScene::prepareScene",DM_MSG,"Stats - tris:"<< (int)mTriangles.size()<<" verts:"<setCounterSceneInter( mpGlob->getCounterSceneInter()+1 ); - mpTree->intersect(r, distance, normal, tri, flags, false); -} - - - - - diff --git a/intern/elbeem/intern/ntl_ray.h b/intern/elbeem/intern/ntl_ray.h deleted file mode 100644 index 064fce27059..00000000000 --- a/intern/elbeem/intern/ntl_ray.h +++ /dev/null @@ -1,438 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * ray class - * - *****************************************************************************/ -#ifndef NTL_RAY_H -#define NTL_RAY_H - -#include -#include "ntl_vector3dim.h" -#include "ntl_lighting.h" -#include "ntl_geometryobject.h" -#include "ntl_bsptree.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -class ntlTriangle; -class ntlRay; -class ntlTree; -class ntlScene; -class ntlRenderGlobals; -class ntlGeometryObject; - -//! store data for an intersection of a ray and a triangle -// NOT YET USED -class ntlIntersection { - public: - - ntlIntersection() : - distance(-1.0), normal(0.0), - ray(NULL), tri(NULL), flags(0) { }; - - gfxReal distance; - ntlVec3Gfx normal; - ntlRay *ray; - ntlTriangle *tri; - char flags; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlIntersection") -#endif -}; - -//! the main ray class -class ntlRay -{ -public: - // CONSTRUCTORS - //! Initialize ray memebers, prints error message - ntlRay(); - //! Copy constructor, copy all members - ntlRay(const ntlRay &r); - //! Explicitly init member variables with global render object - ntlRay(const ntlVec3Gfx &o, const ntlVec3Gfx &d, unsigned int i, gfxReal contrib, ntlRenderGlobals *glob); - //! Destructor - ~ntlRay(); - - //! Set the refraction flag for refracted rays - inline void setRefracted(unsigned char set) { mIsRefracted = set; } - inline void setReflected(unsigned char set) { mIsReflected = set; } - - //! main ray recursion function - /*! - * First get closest object intersection, return background color if nothing - * was hit, else calculate shading and reflection components - * and return mixed color */ - const ntlColor shade() /*const*/; - - /*! Trace a photon through the scene */ - void tracePhoton(ntlColor) const; - - //! intersect ray with AABB - void intersectFrontAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &t, ntlVec3Gfx &normal, ntlVec3Gfx &retcoord) const; - void intersectBackAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &t, ntlVec3Gfx &normal, ntlVec3Gfx &retcoord) const; - void intersectCompleteAABB(ntlVec3Gfx mStart, ntlVec3Gfx mEnd, gfxReal &tmin, gfxReal &tmax) const; - // intersection routines in bsptree.cpp - //! optimized intersect ray with triangle - inline void intersectTriangle(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const; - //! optimized intersect ray with triangle along +X axis dir - inline void intersectTriangleX(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const; - //! intersect only with front side - inline void intersectTriangleFront(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const; - //! intersect ray only with backsides - inline void intersectTriangleBack(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v) const; - - // access methods - //! Returns the ray origin - inline ntlVec3Gfx getOrigin() const { return ntlVec3Gfx(mOrigin); } - //! Returns the ray direction - inline ntlVec3Gfx getDirection() const { return ntlVec3Gfx(mDirection); } - /*! Returns the ray relfection normal */ - inline ntlVec3Gfx getNormal() const { return ntlVec3Gfx(mvNormal); } - //! Is this ray refracted? - inline unsigned char getRefracted() const { return mIsRefracted; } - inline unsigned char getReflected() const { return mIsReflected; } - /*! Get position along ray */ - inline ntlVec3Gfx getPositionAt(gfxReal t) const { return (mOrigin+(mDirection*t)); } - /*! Get render globals pointer of this ray */ - inline ntlRenderGlobals *getRenderglobals( void ) const { return mpGlob; } - /*! get this ray's ID */ - inline int getID( void ) const { return mID; } - - /*! Set origin of this ray */ - inline void setOrigin(ntlVec3Gfx set) { mOrigin = set; } - /*! Set direction of this ray */ - inline void setDirection(ntlVec3Gfx set) { mDirection = set; } - /*! Set normal of this ray */ - inline void setNormal(ntlVec3Gfx set) { mvNormal = set; } - -protected: - /* Calulates the Lambertian and Specular color for - * the given reflection and returns it */ - const ntlColor getShadedColor(ntlLightObject *light, const ntlRay &reflectedray, - const ntlVec3Gfx &normal, ntlMaterial *surf) const; - -private: - /*! Origin of ray */ - ntlVec3Gfx mOrigin; - /*! Normalized direction vector of ray */ - ntlVec3Gfx mDirection; - /*! For reflected/refracted rays, the normal is stored here */ - ntlVec3Gfx mvNormal; - /*! recursion depth */ - unsigned int mDepth; - /*! How much does this ray contribute to the surface color? abort if too small */ - gfxReal mContribution; - - /*! Global rendering settings */ - ntlRenderGlobals *mpGlob; - - /*! If this ray is a refracted one, this flag has to be set - * This is necessary to for example also give the background color - * to refracted rays. Otherwise things may look strange... - */ - unsigned char mIsRefracted; - unsigned char mIsReflected; - - /*! ID of this ray (from renderglobals */ - int mID; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlRay") -#endif -}; - - -/****************************************************************************** - * - * a single triangle - * - *****************************************************************************/ - -// triangle intersection code in bsptree.cpp -// intersectTriangle(vector *mpV, ntlTriangle *tri, gfxReal &t, gfxReal &u, gfxReal &v); - -/*! Triangle flag defines */ -#define TRI_GEOMETRY (1<<0) -#define TRI_CASTSHADOWS (1<<1) - - -class ntlTriangle -{ -public: - /* CONSTRUCTORS */ - /*! Default constructor */ - inline ntlTriangle( void ); - /*! Constructor with parameters */ - inline ntlTriangle(int *p, bool smooth, int obj, ntlVec3Gfx norm, int setflags); - /*! Copy - Constructor */ - inline ntlTriangle(const ntlTriangle &tri); - /*! Destructor */ - inline ~ntlTriangle() {} - - /* Access methods */ - - /*! Acces to points of triangle */ - inline int *getPoints( void ) { return mPoints; } - /*! Acces normal smoothing */ - inline bool getSmoothNormals( void ) const { return mSmoothNormals; } - inline void setSmoothNormals( bool set){ mSmoothNormals = set; } - /*! Access object */ - inline int getObjectId( void ) const { return mObjectId; } - inline void setObjectId( int set) { mObjectId = set; } - /*! Acces normal index */ - inline ntlVec3Gfx getNormal( void ) const { return mNormal; } - inline void setNormal( ntlVec3Gfx set ) { mNormal = set; } - /*! Acces flags */ - inline int getFlags( void ) const { return mFlags; } - inline void setFlags( int set ) { mFlags = set; } - /*! Access last intersection ray ID */ - inline int getLastRay( void ) const { return mLastRay; } - inline void setLastRay( int set ) { mLastRay = set; } - /*! Acces bbox id */ - inline int getBBoxId( void ) const { return mBBoxId; } - inline void setBBoxId( int set ) { mBBoxId = set; } - - /*! Get average of the three points for this axis */ - inline gfxReal getAverage( int axis ) const; - - /*! operator < for sorting, uses global sorting axis */ - inline friend bool operator<(const ntlTriangle &lhs, const ntlTriangle &rhs); - /*! operator > for sorting, uses global sorting axis */ - inline friend bool operator>(const ntlTriangle &lhs, const ntlTriangle &rhs); - -protected: - -private: - - /*! indices to the three points of the triangle */ - int mPoints[3]; - - /*! bounding box id (for tree generation), -1 if invalid */ - int mBBoxId; - - /*! Should the normals of this triangle get smoothed? */ - bool mSmoothNormals; - - /*! Id of parent object */ - int mObjectId; - - /*! Index to normal (for not smooth triangles) */ - //int mNormalIndex; ?? - ntlVec3Gfx mNormal; - - /*! Flags for object attributes cast shadows */ - int mFlags; - - /*! ID of last ray that an intersection was calculated for */ - int mLastRay; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlTriangle") -#endif -}; - - - - -/****************************************************************************** - * Default Constructor - *****************************************************************************/ -ntlTriangle::ntlTriangle( void ) : - mBBoxId(-1), - mLastRay( 0 ) -{ - mPoints[0] = mPoints[1] = mPoints[2] = 0; - mSmoothNormals = 0; - mObjectId = 0; - mNormal = ntlVec3Gfx(0.0); - mFlags = 0; -} - - -/****************************************************************************** - * Constructor - *****************************************************************************/ -ntlTriangle::ntlTriangle(int *p, bool smooth, int obj, ntlVec3Gfx norm, int setflags) : - mBBoxId(-1), - mLastRay( 0 ) -{ - mPoints[0] = p[0]; - mPoints[1] = p[1]; - mPoints[2] = p[2]; - mSmoothNormals = smooth; - mObjectId = obj; - mNormal = norm; - mFlags = setflags; -} - - -/****************************************************************************** - * Copy Constructor - *****************************************************************************/ -ntlTriangle::ntlTriangle(const ntlTriangle &tri) : - mBBoxId(-1), - mLastRay( 0 ) -{ - mPoints[0] = tri.mPoints[0]; - mPoints[1] = tri.mPoints[1]; - mPoints[2] = tri.mPoints[2]; - mSmoothNormals = tri.mSmoothNormals; - mObjectId = tri.mObjectId; - mNormal = tri.mNormal; - mFlags = tri.mFlags; -} - - - - -/****************************************************************************** - * Triangle sorting functions - *****************************************************************************/ - -/* variables imported from ntl_bsptree.cc, necessary for using the stl sort funtion */ -/* Static global variable for sorting direction */ -extern int globalSortingAxis; -/* Access to points array for sorting */ -extern vector *globalSortingPoints; - - -gfxReal ntlTriangle::getAverage( int axis ) const -{ - return ( ( (*globalSortingPoints)[ mPoints[0] ][axis] + - (*globalSortingPoints)[ mPoints[1] ][axis] + - (*globalSortingPoints)[ mPoints[2] ][axis] )/3.0); -} - -bool operator<(const ntlTriangle &lhs,const ntlTriangle &rhs) -{ - return ( lhs.getAverage(globalSortingAxis) < - rhs.getAverage(globalSortingAxis) ); -} - -bool operator>(const ntlTriangle &lhs,const ntlTriangle &rhs) -{ - return ( lhs.getAverage(globalSortingAxis) > - rhs.getAverage(globalSortingAxis) ); -} - - - -/****************************************************************************** - * - * Scene object, that contains and manages all geometry objects - * - *****************************************************************************/ - - - -class ntlScene -{ -public: - /* CONSTRUCTORS */ - /*! Default constructor */ - ntlScene( ntlRenderGlobals *glob, bool del=true ); - /*! Default destructor */ - ~ntlScene(); - - /*! Add an object to the scene */ - inline void addGeoClass(ntlGeometryClass *geo) { - mGeos.push_back( geo ); - geo->setObjectId(mGeos.size()); - } - /*! Add a geo object to the scene, warning - only needed for hand init */ - inline void addGeoObject(ntlGeometryObject *geo) { mObjects.push_back( geo ); } - - /*! Acces a certain object */ - inline ntlGeometryObject *getObject(int id) { - if(!mSceneBuilt) { errFatal("ntlScene::getObject","Scene not inited!", SIMWORLD_INITERROR); } - return mObjects[id]; } - - /*! Acces object array */ - inline vector *getObjects() { - if(!mSceneBuilt) { errFatal("ntlScene::getObjects[]","Scene not inited!", SIMWORLD_INITERROR); } - return &mObjects; } - - /*! Acces geo class array */ - inline vector *getGeoClasses() { - if(!mSceneBuilt) { errFatal("ntlScene::getGeoClasses[]","Scene not inited!", SIMWORLD_INITERROR); } - return &mGeos; } - - /*! draw scene with opengl */ - //void draw(); - - /*! Build/first init the scene arrays */ - void buildScene(double time, bool firstInit); - - //! Prepare the scene triangles and maps for raytracing - void prepareScene(double time); - //! Do some memory cleaning, when frame is finished - void cleanupScene( void ); - - /*! Intersect a ray with the scene triangles */ - void intersectScene(const ntlRay &r, gfxReal &distance, ntlVec3Gfx &normal, ntlTriangle *&tri, int flags) const; - - /*! return a vertex */ - ntlVec3Gfx getVertex(int index) { return mVertices[index]; } - - // for tree generation - /*! return pointer to vertices vector */ - vector *getVertexPointer( void ) { return &mVertices; } - /*! return pointer to vertices vector */ - vector *getVertexNormalPointer( void ) { return &mVertNormals; } - /*! return pointer to vertices vector */ - vector *getTrianglePointer( void ) { return &mTriangles; } - -private: - - /*! Global settings */ - ntlRenderGlobals *mpGlob; - - /*! free objects? (only necessary for render scene, which contains all) */ - bool mSceneDel; - - /*! List of geometry classes */ - vector mGeos; - - /*! List of geometry objects */ - vector mObjects; - - /*! List of triangles */ - vector mTriangles; - /*! List of vertices */ - vector mVertices; - /*! List of normals */ - vector mVertNormals; - /*! List of triangle normals */ - vector mTriangleNormals; - - /*! Tree to store quickly intersect triangles */ - ntlTree *mpTree; - - /*! was the scene successfully built? only then getObject(i) requests are valid */ - bool mSceneBuilt; - - /*! shader/obj initializations are only done on first init */ - bool mFirstInitDone; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlScene") -#endif -}; - - -#endif - diff --git a/intern/elbeem/intern/ntl_vector3dim.h b/intern/elbeem/intern/ntl_vector3dim.h deleted file mode 100644 index 51e03e30dc8..00000000000 --- a/intern/elbeem/intern/ntl_vector3dim.h +++ /dev/null @@ -1,1105 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Basic vector class used everywhere, either blitz or inlined GRAPA class - * - *****************************************************************************/ -#ifndef NTL_VECTOR3DIM_H -#define NTL_VECTOR3DIM_H - -// this serves as the main include file -// for all kinds of stuff that might be required -// under windows there seem to be strange -// errors when including the STL header too -// late... - -#ifdef _MSC_VER -#define _USE_MATH_DEFINES 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -/* absolute value */ -template < class T > -inline T -ABS( T a ) -{ return (0 < a) ? a : -a ; } - -// hack for MSVC6.0 compiler -#ifdef _MSC_VER -#if _MSC_VER < 1300 -#define for if(false); else for -#define map std::map -#define vector std::vector -#define string std::string -// use this define for MSVC6 stuff hereafter -#define USE_MSVC6FIXES -#else // _MSC_VER < 1300 , 7.0 or higher -using std::map; -using std::vector; -using std::string; -#endif -#else // not MSVC6 -// for proper compilers... -using std::map; -using std::vector; -using std::string; -#endif // MSVC6 - -#ifdef __APPLE_CC__ -// apple -#else -#ifdef WIN32 - -// windows values missing, see below -#ifndef snprintf -#define snprintf _snprintf -#endif - -#ifdef _MSC_VER -#if _MSC_VER >= 1300 -#include -#endif -#endif - -#else // WIN32 - -// floating point limits for linux,*bsd etc... -#include - -#endif // WIN32 -#endif // __APPLE_CC__ - -// windows, hardcoded limits for now... -// for e.g. MSVC compiler... -// some of these defines can be needed -// for linux systems as well (e.g. FLT_MAX) -#ifndef __FLT_MAX__ -# ifdef FLT_MAX // try to use it instead -# define __FLT_MAX__ FLT_MAX -# else // FLT_MAX -# define __FLT_MAX__ 3.402823466e+38f -# endif // FLT_MAX -#endif // __FLT_MAX__ -#ifndef __DBL_MAX__ -# ifdef DBL_MAX // try to use it instead -# define __DBL_MAX__ DBL_MAX -# else // DBL_MAX -# define __DBL_MAX__ 1.7976931348623158e+308 -# endif // DBL_MAX -#endif // __DBL_MAX__ - -#ifndef M_PI -#define M_PI 3.1415926536 -#endif - -#ifndef M_E -#define M_E 2.7182818284 -#endif - -// make sure elbeem plugin def is valid -#if ELBEEM_BLENDER==1 -#ifndef ELBEEM_PLUGIN -#define ELBEEM_PLUGIN 1 -#endif // !ELBEEM_PLUGIN -#endif // ELBEEM_BLENDER==1 - -// make sure GUI support is disabled for plugin use -#if ELBEEM_PLUGIN==1 -#ifndef NOGUI -#define NOGUI 1 -#endif // !NOGUI -#endif // ELBEEM_PLUGIN==1 - - -// basic inlined vector class -template -class ntlVector3Dim -{ -public: - // Constructor - inline ntlVector3Dim(void ); - // Copy-Constructor - inline ntlVector3Dim(const ntlVector3Dim &v ); - inline ntlVector3Dim(const float *); - inline ntlVector3Dim(const double *); - // construct a vector from one Scalar - inline ntlVector3Dim(Scalar); - // construct a vector from three Scalars - inline ntlVector3Dim(Scalar, Scalar, Scalar); - - // get address of array for OpenGL - Scalar *getAddress() { return value; } - - // Assignment operator - inline const ntlVector3Dim& operator= (const ntlVector3Dim& v); - // Assignment operator - inline const ntlVector3Dim& operator= (Scalar s); - // Assign and add operator - inline const ntlVector3Dim& operator+= (const ntlVector3Dim& v); - // Assign and add operator - inline const ntlVector3Dim& operator+= (Scalar s); - // Assign and sub operator - inline const ntlVector3Dim& operator-= (const ntlVector3Dim& v); - // Assign and sub operator - inline const ntlVector3Dim& operator-= (Scalar s); - // Assign and mult operator - inline const ntlVector3Dim& operator*= (const ntlVector3Dim& v); - // Assign and mult operator - inline const ntlVector3Dim& operator*= (Scalar s); - // Assign and div operator - inline const ntlVector3Dim& operator/= (const ntlVector3Dim& v); - // Assign and div operator - inline const ntlVector3Dim& operator/= (Scalar s); - - - // unary operator - inline ntlVector3Dim operator- () const; - - // binary operator add - inline ntlVector3Dim operator+ (const ntlVector3Dim&) const; - // binary operator add - inline ntlVector3Dim operator+ (Scalar) const; - // binary operator sub - inline ntlVector3Dim operator- (const ntlVector3Dim&) const; - // binary operator sub - inline ntlVector3Dim operator- (Scalar) const; - // binary operator mult - inline ntlVector3Dim operator* (const ntlVector3Dim&) const; - // binary operator mult - inline ntlVector3Dim operator* (Scalar) const; - // binary operator div - inline ntlVector3Dim operator/ (const ntlVector3Dim&) const; - // binary operator div - inline ntlVector3Dim operator/ (Scalar) const; - - // Projection normal to a vector - inline ntlVector3Dim getOrthogonalntlVector3Dim() const; - // Project into a plane - inline const ntlVector3Dim& projectNormalTo(const ntlVector3Dim &v); - - // minimize - inline const ntlVector3Dim &minimize(const ntlVector3Dim &); - // maximize - inline const ntlVector3Dim &maximize(const ntlVector3Dim &); - - // access operator - inline Scalar& operator[](unsigned int i); - // access operator - inline const Scalar& operator[](unsigned int i) const; - -protected: - -private: - Scalar value[3]; //< Storage of vector values - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlVector3Dim") -#endif -}; - - - - -//------------------------------------------------------------------------------ -// STREAM FUNCTIONS -//------------------------------------------------------------------------------ - - - -//! global string for formatting vector output in utilities.cpp -extern const char *globVecFormatStr; - -/************************************************************************* - Outputs the object in human readable form using the format - [x,y,z] - */ -template -std::ostream& -operator<<( std::ostream& os, const ntlVector3Dim& i ) -{ - char buf[256]; - snprintf(buf,256,globVecFormatStr,i[0],i[1],i[2]); - os << string(buf); - //os << '[' << i[0] << ", " << i[1] << ", " << i[2] << ']'; - return os; -} - - - -/************************************************************************* - Reads the contents of the object from a stream using the same format - as the output operator. - */ -template -std::istream& -operator>>( std::istream& is, ntlVector3Dim& i ) -{ - char c; - char dummy[3]; - is >> c >> i[0] >> dummy >> i[1] >> dummy >> i[2] >> c; - return is; -} - - -//------------------------------------------------------------------------------ -// VECTOR inline FUNCTIONS -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Constructor. - */ -template -inline ntlVector3Dim::ntlVector3Dim( void ) -{ - value[0] = value[1] = value[2] = 0; -} - - - -/************************************************************************* - Copy-Constructor. - */ -template -inline ntlVector3Dim::ntlVector3Dim( const ntlVector3Dim &v ) -{ - value[0] = v.value[0]; - value[1] = v.value[1]; - value[2] = v.value[2]; -} -template -inline ntlVector3Dim::ntlVector3Dim( const float *fvalue) -{ - value[0] = (Scalar)fvalue[0]; - value[1] = (Scalar)fvalue[1]; - value[2] = (Scalar)fvalue[2]; -} -template -inline ntlVector3Dim::ntlVector3Dim( const double *fvalue) -{ - value[0] = (Scalar)fvalue[0]; - value[1] = (Scalar)fvalue[1]; - value[2] = (Scalar)fvalue[2]; -} - - - -/************************************************************************* - Constructor for a vector from a single Scalar. All components of - the vector get the same value. - \param s The value to set - \return The new vector - */ -template -inline ntlVector3Dim::ntlVector3Dim(Scalar s ) -{ - value[0]= s; - value[1]= s; - value[2]= s; -} - - -/************************************************************************* - Constructor for a vector from three Scalars. - \param s1 The value for the first vector component - \param s2 The value for the second vector component - \param s3 The value for the third vector component - \return The new vector - */ -template -inline ntlVector3Dim::ntlVector3Dim(Scalar s1, Scalar s2, Scalar s3) -{ - value[0]= s1; - value[1]= s2; - value[2]= s3; -} - - -/************************************************************************* - Compute the vector product of two 3D vectors - \param v Second vector to compute the product with - \return A new vector with the product values - */ -/*template -inline ntlVector3Dim -ntlVector3Dim::operator^( const ntlVector3Dim &v ) const -{ - return ntlVector3Dim(value[1]*v.value[2] - value[2]*v.value[1], - value[2]*v.value[0] - value[0]*v.value[2], - value[0]*v.value[1] - value[1]*v.value[0]); -}*/ - - -/************************************************************************* - Copy a ntlVector3Dim componentwise. - \param v vector with values to be copied - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator=( const ntlVector3Dim &v ) -{ - value[0] = v.value[0]; - value[1] = v.value[1]; - value[2] = v.value[2]; - return *this; -} - - -/************************************************************************* - Copy a Scalar to each component. - \param s The value to copy - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator=(Scalar s) -{ - value[0] = s; - value[1] = s; - value[2] = s; - return *this; -} - - -/************************************************************************* - Add another ntlVector3Dim componentwise. - \param v vector with values to be added - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator+=( const ntlVector3Dim &v ) -{ - value[0] += v.value[0]; - value[1] += v.value[1]; - value[2] += v.value[2]; - return *this; -} - - -/************************************************************************* - Add a Scalar value to each component. - \param s Value to add - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator+=(Scalar s) -{ - value[0] += s; - value[1] += s; - value[2] += s; - return *this; -} - - -/************************************************************************* - Subtract another vector componentwise. - \param v vector of values to subtract - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator-=( const ntlVector3Dim &v ) -{ - value[0] -= v.value[0]; - value[1] -= v.value[1]; - value[2] -= v.value[2]; - return *this; -} - - -/************************************************************************* - Subtract a Scalar value from each component. - \param s Value to subtract - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator-=(Scalar s) -{ - value[0]-= s; - value[1]-= s; - value[2]-= s; - return *this; -} - - -/************************************************************************* - Multiply with another vector componentwise. - \param v vector of values to multiply with - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator*=( const ntlVector3Dim &v ) -{ - value[0] *= v.value[0]; - value[1] *= v.value[1]; - value[2] *= v.value[2]; - return *this; -} - - -/************************************************************************* - Multiply each component with a Scalar value. - \param s Value to multiply with - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator*=(Scalar s) -{ - value[0] *= s; - value[1] *= s; - value[2] *= s; - return *this; -} - - -/************************************************************************* - Divide by another ntlVector3Dim componentwise. - \param v vector of values to divide by - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator/=( const ntlVector3Dim &v ) -{ - value[0] /= v.value[0]; - value[1] /= v.value[1]; - value[2] /= v.value[2]; - return *this; -} - - -/************************************************************************* - Divide each component by a Scalar value. - \param s Value to divide by - \return Reference to self - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::operator/=(Scalar s) -{ - value[0] /= s; - value[1] /= s; - value[2] /= s; - return *this; -} - - -//------------------------------------------------------------------------------ -// unary operators -//------------------------------------------------------------------------------ - - -/************************************************************************* - Build componentwise the negative this vector. - \return The new (negative) vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator-() const -{ - return ntlVector3Dim(-value[0], -value[1], -value[2]); -} - - - -//------------------------------------------------------------------------------ -// binary operators -//------------------------------------------------------------------------------ - - -/************************************************************************* - Build a vector with another vector added componentwise. - \param v The second vector to add - \return The sum vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator+( const ntlVector3Dim &v ) const -{ - return ntlVector3Dim(value[0]+v.value[0], - value[1]+v.value[1], - value[2]+v.value[2]); -} - - -/************************************************************************* - Build a vector with a Scalar value added to each component. - \param s The Scalar value to add - \return The sum vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator+(Scalar s) const -{ - return ntlVector3Dim(value[0]+s, - value[1]+s, - value[2]+s); -} - - -/************************************************************************* - Build a vector with another vector subtracted componentwise. - \param v The second vector to subtract - \return The difference vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator-( const ntlVector3Dim &v ) const -{ - return ntlVector3Dim(value[0]-v.value[0], - value[1]-v.value[1], - value[2]-v.value[2]); -} - - -/************************************************************************* - Build a vector with a Scalar value subtracted componentwise. - \param s The Scalar value to subtract - \return The difference vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator-(Scalar s ) const -{ - return ntlVector3Dim(value[0]-s, - value[1]-s, - value[2]-s); -} - - - -/************************************************************************* - Build a vector with another vector multiplied by componentwise. - \param v The second vector to muliply with - \return The product vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator*( const ntlVector3Dim& v) const -{ - return ntlVector3Dim(value[0]*v.value[0], - value[1]*v.value[1], - value[2]*v.value[2]); -} - - -/************************************************************************* - Build a ntlVector3Dim with a Scalar value multiplied to each component. - \param s The Scalar value to multiply with - \return The product vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator*(Scalar s) const -{ - return ntlVector3Dim(value[0]*s, value[1]*s, value[2]*s); -} - - -/************************************************************************* - Build a vector divided componentwise by another vector. - \param v The second vector to divide by - \return The ratio vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator/(const ntlVector3Dim& v) const -{ - return ntlVector3Dim(value[0]/v.value[0], - value[1]/v.value[1], - value[2]/v.value[2]); -} - - - -/************************************************************************* - Build a vector divided componentwise by a Scalar value. - \param s The Scalar value to divide by - \return The ratio vector - */ -template -inline ntlVector3Dim -ntlVector3Dim::operator/(Scalar s) const -{ - return ntlVector3Dim(value[0]/s, - value[1]/s, - value[2]/s); -} - - - - - -/************************************************************************* - Get a particular component of the vector. - \param i Number of Scalar to get - \return Reference to the component - */ -template -inline Scalar& -ntlVector3Dim::operator[]( unsigned int i ) -{ - return value[i]; -} - - -/************************************************************************* - Get a particular component of a constant vector. - \param i Number of Scalar to get - \return Reference to the component - */ -template -inline const Scalar& -ntlVector3Dim::operator[]( unsigned int i ) const -{ - return value[i]; -} - - - -//------------------------------------------------------------------------------ -// BLITZ compatibility functions -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Compute the scalar product with another vector. - \param v The second vector to work with - \return The value of the scalar product - */ -template -inline Scalar dot(const ntlVector3Dim &t, const ntlVector3Dim &v ) -{ - //return t.value[0]*v.value[0] + t.value[1]*v.value[1] + t.value[2]*v.value[2]; - return ((t[0]*v[0]) + (t[1]*v[1]) + (t[2]*v[2])); -} - - -/************************************************************************* - Calculate the cross product of this and another vector - */ -template -inline ntlVector3Dim cross(const ntlVector3Dim &t, const ntlVector3Dim &v) -{ - ntlVector3Dim cp( - ((t[1]*v[2]) - (t[2]*v[1])), - ((t[2]*v[0]) - (t[0]*v[2])), - ((t[0]*v[1]) - (t[1]*v[0])) ); - return cp; -} - - - - -/************************************************************************* - Compute a vector that is orthonormal to self. Nothing else can be assumed - for the direction of the new vector. - \return The orthonormal vector - */ -template -ntlVector3Dim -ntlVector3Dim::getOrthogonalntlVector3Dim() const -{ - // Determine the component with max. absolute value - int max= (fabs(value[0]) > fabs(value[1])) ? 0 : 1; - max= (fabs(value[max]) > fabs(value[2])) ? max : 2; - - /************************************************************************* - Choose another axis than the one with max. component and project - orthogonal to self - */ - ntlVector3Dim vec(0.0); - vec[(max+1)%3]= 1; - vec.normalize(); - vec.projectNormalTo(this->getNormalized()); - return vec; -} - - -/************************************************************************* - Projects the vector into a plane normal to the given vector, which must - have unit length. Self is modified. - \param v The plane normal - \return The projected vector - */ -template -inline const ntlVector3Dim& -ntlVector3Dim::projectNormalTo(const ntlVector3Dim &v) -{ - Scalar sprod = dot(*this,v); - value[0]= value[0] - v.value[0] * sprod; - value[1]= value[1] - v.value[1] * sprod; - value[2]= value[2] - v.value[2] * sprod; - return *this; -} - - - -//------------------------------------------------------------------------------ -// Other helper functions -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Minimize the vector, i.e. set each entry of the vector to the minimum - of both values. - \param pnt The second vector to compare with - \return Reference to the modified self - */ -template -inline const ntlVector3Dim & -ntlVector3Dim::minimize(const ntlVector3Dim &pnt) -{ - for (unsigned int i = 0; i < 3; i++) - value[i] = MIN(value[i],pnt[i]); - return *this; -} - - - -/************************************************************************* - Maximize the vector, i.e. set each entry of the vector to the maximum - of both values. - \param pnt The second vector to compare with - \return Reference to the modified self - */ -template -inline const ntlVector3Dim & -ntlVector3Dim::maximize(const ntlVector3Dim &pnt) -{ - for (unsigned int i = 0; i < 3; i++) - value[i] = MAX(value[i],pnt[i]); - return *this; -} - - - - -// ---- - -// a 3D vector with double precision -typedef ntlVector3Dim ntlVec3d; - -// a 3D vector with single precision -typedef ntlVector3Dim ntlVec3f; - -// a 3D integer vector -typedef ntlVector3Dim ntlVec3i; - -// Color uses single precision fp values -typedef ntlVec3f ntlColor; - -/* convert a float to double vector */ -template inline ntlVec3d vec2D(T v) { return ntlVec3d(v[0],v[1],v[2]); } -template inline ntlVec3f vec2F(T v) { return ntlVec3f(v[0],v[1],v[2]); } -template inline ntlColor vec2Col(T v) { return ntlColor(v[0],v[1],v[2]); } - - - -/************************************************************************/ -// graphics vector typing - - -// use which fp-precision for raytracing? 1=float, 2=double - -/* VECTOR_EPSILON is the minimal vector length - In order to be able to discriminate floating point values near zero, and - to be sure not to fail a comparison because of roundoff errors, use this - value as a threshold. */ - -// use which fp-precision for graphics? 1=float, 2=double -#ifdef PRECISION_GFX_SINGLE -#define GFX_PRECISION 1 -#else -#ifdef PRECISION_GFX_DOUBLE -#define GFX_PRECISION 2 -#else -// standard precision for graphics -#ifndef GFX_PRECISION -#define GFX_PRECISION 1 -#endif -#endif -#endif - -#if GFX_PRECISION==1 -typedef float gfxReal; -#define GFX_REAL_MAX __FLT_MAX__ -//#define vecF2Gfx(x) (x) -//#define vecGfx2F(x) (x) -//#define vecD2Gfx(x) vecD2F(x) -//#define vecGfx2D(x) vecF2D(x) -#define VECTOR_EPSILON (1e-5f) -#else -typedef double gfxReal; -#define GFX_REAL_MAX __DBL_MAX__ -//#define vecF2Gfx(x) vecD2F(x) -//#define vecGfx2F(x) vecF2D(x) -//#define vecD2Gfx(x) (x) -//#define vecGfx2D(x) (x) -#define VECTOR_EPSILON (1e-10) -#endif - -/* fixed double prec. type, for epxlicitly double values */ -typedef double gfxDouble; - -// a 3D vector for graphics output, typically float? -typedef ntlVector3Dim ntlVec3Gfx; - -template inline ntlVec3Gfx vec2G(T v) { return ntlVec3Gfx(v[0],v[1],v[2]); } - -/* get minimal vector length value that can be discriminated. */ -//inline double getVecEpsilon() { return (double)VECTOR_EPSILON; } -inline gfxReal getVecEpsilon() { return (gfxReal)VECTOR_EPSILON; } - -#define HAVE_GFXTYPES - - - - -/************************************************************************/ -// HELPER FUNCTIONS, independent of implementation -/************************************************************************/ - -#define VECTOR_TYPE ntlVector3Dim - - -/************************************************************************* - Compute the length (norm) of the vector. - \return The value of the norm - */ -template -inline Scalar norm( const VECTOR_TYPE &v) -{ - Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - return (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) ? 1. : sqrt(l); -} - - -/************************************************************************* - Same as getNorm but doesnt sqrt - */ -template -inline Scalar normNoSqrt( const VECTOR_TYPE &v) -{ - return v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; -} - - -/************************************************************************* - Compute a normalized vector based on this vector. - \return The new normalized vector - */ -template -inline VECTOR_TYPE getNormalized( const VECTOR_TYPE &v) -{ - Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - if (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) - return v; /* normalized "enough"... */ - else if (l > VECTOR_EPSILON*VECTOR_EPSILON) - { - Scalar fac = 1./sqrt(l); - return VECTOR_TYPE(v[0]*fac, v[1]*fac, v[2]*fac); - } - else - return VECTOR_TYPE((Scalar)0); -} - - -/************************************************************************* - Compute the norm of the vector and normalize it. - \return The value of the norm - */ -template -inline Scalar normalize( VECTOR_TYPE &v) -{ - Scalar norm; - Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - if (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) { - norm = 1.; - } else if (l > VECTOR_EPSILON*VECTOR_EPSILON) { - norm = sqrt(l); - Scalar fac = 1./norm; - v[0] *= fac; - v[1] *= fac; - v[2] *= fac; - } else { - v[0]= v[1]= v[2]= 0; - norm = 0.; - } - return (Scalar)norm; -} - - -/************************************************************************* - Compute a vector, that is self (as an incoming - vector) reflected at a surface with a distinct normal vector. Note - that the normal is reversed, if the scalar product with it is positive. - \param n The surface normal - \return The new reflected vector - */ -template -inline VECTOR_TYPE reflectVector(const VECTOR_TYPE &t, const VECTOR_TYPE &n) -{ - VECTOR_TYPE nn= (dot(t, n) > 0.0) ? (n*-1.0) : n; - return ( t - nn * (2.0 * dot(nn, t)) ); -} - - - -/************************************************************************* - * My own refraction calculation - * Taken from Glassner's book, section 5.2 (Heckberts method) - */ -template -inline VECTOR_TYPE refractVector(const VECTOR_TYPE &t, const VECTOR_TYPE &normal, Scalar nt, Scalar nair, int &refRefl) -{ - Scalar eta = nair / nt; - Scalar n = -dot(t, normal); - Scalar tt = 1.0 + eta*eta* (n*n-1.0); - if(tt<0.0) { - // we have total reflection! - refRefl = 1; - } else { - // normal reflection - tt = eta*n - sqrt(tt); - return( t*eta + normal*tt ); - } - return t; -} - /*double eta = nair / nt; - double n = -((*this) | normal); - double t = 1.0 + eta*eta* (n*n-1.0); - if(t<0.0) { - // we have total reflection! - refRefl = 1; - } else { - // normal reflection - t = eta*n - sqrt(t); - return( (*this)*eta + normal*t ); - } - return (*this);*/ - - -/************************************************************************* - Test two ntlVector3Dims for equality based on the equality of their - values within a small threshold. - \param c The second vector to compare - \return TRUE if both are equal - \sa getEpsilon() - */ -template -inline bool equal(const VECTOR_TYPE &v, const VECTOR_TYPE &c) -{ - return (ABS(v[0]-c[0]) + - ABS(v[1]-c[1]) + - ABS(v[2]-c[2]) < VECTOR_EPSILON); -} - - -/************************************************************************* - * Assume this vector is an RGB color, and convert it to HSV - */ -template -inline void rgbToHsv( VECTOR_TYPE &V ) -{ - Scalar h=0,s=0,v=0; - Scalar maxrgb, minrgb, delta; - // convert to hsv... - maxrgb = V[0]; - int maxindex = 1; - if(V[2] > maxrgb){ maxrgb = V[2]; maxindex = 2; } - if(V[1] > maxrgb){ maxrgb = V[1]; maxindex = 3; } - minrgb = V[0]; - if(V[2] < minrgb) minrgb = V[2]; - if(V[1] < minrgb) minrgb = V[1]; - - v = maxrgb; - delta = maxrgb-minrgb; - - if(maxrgb > 0) s = delta/maxrgb; - else s = 0; - - h = 0; - if(s > 0) { - if(maxindex == 1) { - h = ((V[1]-V[2])/delta) + 0.0; } - if(maxindex == 2) { - h = ((V[2]-V[0])/delta) + 2.0; } - if(maxindex == 3) { - h = ((V[0]-V[1])/delta) + 4.0; } - h *= 60.0; - if(h < 0.0) h += 360.0; - } - - V[0] = h; - V[1] = s; - V[2] = v; -} - -/************************************************************************* - * Assume this vector is HSV and convert to RGB - */ -template -inline void hsvToRgb( VECTOR_TYPE &V ) -{ - Scalar h = V[0], s = V[1], v = V[2]; - Scalar r=0,g=0,b=0; - Scalar p,q,t, fracth; - int floorh; - // ...and back to rgb - if(s == 0) { - r = g = b = v; } - else { - h /= 60.0; - floorh = (int)h; - fracth = h - floorh; - p = v * (1.0 - s); - q = v * (1.0 - (s * fracth)); - t = v * (1.0 - (s * (1.0 - fracth))); - switch (floorh) { - case 0: r = v; g = t; b = p; break; - case 1: r = q; g = v; b = p; break; - case 2: r = p; g = v; b = t; break; - case 3: r = p; g = q; b = v; break; - case 4: r = t; g = p; b = v; break; - case 5: r = v; g = p; b = q; break; - } - } - - V[0] = r; - V[1] = g; - V[2] = b; -} - - - - -#endif /* NTL_VECTOR3DIM_HH */ diff --git a/intern/elbeem/intern/ntl_world.cpp b/intern/elbeem/intern/ntl_world.cpp deleted file mode 100644 index 5f3d6e36b3b..00000000000 --- a/intern/elbeem/intern/ntl_world.cpp +++ /dev/null @@ -1,934 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Main renderer class - * - *****************************************************************************/ - - -#include -#include -#include "utilities.h" -#include "ntl_world.h" -#include "parametrizer.h" - -// for non-threaded renderViz -#ifndef NOGUI -#include "../gui/ntl_openglrenderer.h" -#include "../gui/guifuncs.h" -#include "../gui/frame.h" -#endif - - -/* external parser functions from cfgparser.cxx */ -#ifndef ELBEEM_PLUGIN -/* parse given file as config file */ -void parseFile(string filename); -/* set pointers for parsing */ -void setPointers( ntlRenderGlobals *setglob); -#endif // ELBEEM_PLUGIN - - -/****************************************************************************** - * Constructor - *****************************************************************************/ - -ntlWorld::ntlWorld() { - initDefaults(); -} - -ntlWorld::ntlWorld(string filename, bool commandlineMode) -{ -#ifndef ELBEEM_PLUGIN - - initDefaults(); -# ifdef NOGUI - commandlineMode = true; // remove warning... -# endif // NOGUI - - // load config - setPointers( getRenderGlobals() ); - parseFile( filename.c_str() ); -# ifndef NOGUI - // setup opengl display, save first animation step for start time - // init after parsing file... - if(!commandlineMode) { - mpOpenGLRenderer = new ntlOpenGLRenderer( mpGlob ); - } -# endif // NOGUI - finishWorldInit(); - -#else // ELBEEM_PLUGIN - errFatal("ntlWorld::init","Cfg file parsing not supported for API version! "<setName(string(simname)); - mpGlob->getSims()->push_back( sim ); - - // important - add to both, only render scene objects are free'd - mpGlob->getRenderScene()->addGeoClass( sim ); - mpGlob->getSimScene()->addGeoClass( sim ); - sim->setGeoStart(ntlVec3Gfx(settings->geoStart[0],settings->geoStart[1],settings->geoStart[2])); - sim->setGeoEnd(ntlVec3Gfx( - settings->geoStart[0]+settings->geoSize[0], - settings->geoStart[1]+settings->geoSize[1], - settings->geoStart[2]+settings->geoSize[2] )); - // further init in postGeoConstrInit/initializeLbmSimulation of SimulationObject - sim->copyElbeemSettings(settings); - - Parametrizer *param = sim->getParametrizer(); - param->setSize( settings->resolutionxyz ); - param->setDomainSize( settings->realsize ); - param->setAniStart( settings->animStart ); - param->setNormalizedGStar( settings->gstar ); - - // init domain channels - vector valf; - vector valv; - vector time; - -#define INIT_CHANNEL_FLOAT(channel,size) \ - valf.clear(); time.clear(); elbeemSimplifyChannelFloat(channel,&size); \ - for(int i=0; isetViscosity( settings->viscosity ); - if((settings->channelViscosity)&&(settings->channelSizeViscosity>0)) { - INIT_CHANNEL_FLOAT(settings->channelViscosity, settings->channelSizeViscosity); - param->initViscosityChannel(valf,time); } - - param->setGravity( ParamVec(settings->gravity[0], settings->gravity[1], settings->gravity[2]) ); - if((settings->channelGravity)&&(settings->channelSizeGravity>0)) { - INIT_CHANNEL_VEC(settings->channelGravity, settings->channelSizeGravity); - param->initGravityChannel(valv,time); } - - param->setAniFrameTimeChannel( settings->aniFrameTime ); - if((settings->channelFrameTime)&&(settings->channelSizeFrameTime>0)) { - INIT_CHANNEL_FLOAT(settings->channelFrameTime, settings->channelSizeFrameTime); - param->initAniFrameTimeChannel(valf,time); } - -#undef INIT_CHANNEL_FLOAT -#undef INIT_CHANNEL_VEC - - // might be set by previous domain - if(mpGlob->getAniFrames() < settings->noOfFrames) mpGlob->setAniFrames( settings->noOfFrames ); - // set additionally to SimulationObject->mOutFilename - mpGlob->setOutFilename( settings->outputPath ); - - return 0; -} - -void ntlWorld::initDefaults() -{ - mStopRenderVisualization = false; - mThreadRunning = false; - mSimulationTime = 0.0; - mFirstSim = 1; - mSingleStepDebug = false; - mFrameCnt = 0; - mSimFrameCnt = 0; - mpOpenGLRenderer = NULL; - - /* create scene storage */ - mpGlob = new ntlRenderGlobals(); - mpLightList = new vector; - mpPropList = new vector; - mpSims = new vector; - - mpGlob->setLightList(mpLightList); - mpGlob->setMaterials(mpPropList); - mpGlob->setSims(mpSims); - - /* init default material */ - ntlMaterial *def = GET_GLOBAL_DEFAULT_MATERIAL; - mpPropList->push_back( def ); - - /* init the scene object */ - ntlScene *renderscene = new ntlScene( mpGlob, true ); - mpGlob->setRenderScene( renderscene ); - // sim scene shouldnt delete objs, may only contain subset - ntlScene *simscene = new ntlScene( mpGlob, false ); - mpGlob->setSimScene( simscene ); -} - -void ntlWorld::finishWorldInit() -{ - if(! isSimworldOk() ) return; - - // init the scene for the first time - long sstartTime = getTime(); - - // first init sim scene for geo setup - mpGlob->getSimScene()->buildScene(0.0, true); - if(! isSimworldOk() ) return; - mpGlob->getRenderScene()->buildScene(0.0, true); - if(! isSimworldOk() ) return; - long sstopTime = getTime(); - debMsgStd("ntlWorld::ntlWorld",DM_MSG,"Scene build time: "<< getTimeString(sstopTime-sstartTime) <<" ", 10); - - // TODO check simulations, run first steps - mFirstSim = -1; - if(mpSims->size() > 0) { - - // use values from first simulation as master time scale - long startTime = getTime(); - - // remember first active sim - for(size_t i=0;isize();i++) { - if(!(*mpSims)[i]->getVisible()) continue; - if((*mpSims)[i]->getPanic()) continue; - - // check largest timestep - if(mFirstSim>=0) { - if( (*mpSims)[i]->getTimestep() > (*mpSims)[mFirstSim]->getTimestep() ) { - mFirstSim = i; - debMsgStd("ntlWorld::ntlWorld",DM_MSG,"First Sim changed: "<=0) { - debMsgStd("ntlWorld::ntlWorld",DM_MSG,"Anistart Time: "<<(*mpSims)[mFirstSim]->getStartTime() ,10); - while(mSimulationTime < (*mpSims)[mFirstSim]->getStartTime() ) { - debMsgStd("ntlWorld::ntlWorld",DM_MSG,"Anistart Time: "<<(*mpSims)[mFirstSim]->getStartTime()<<" simtime:"<getSingleFrameMode()) debMsgStd("ntlWorld::ntlWorld",DM_WARNING,"No active simulations!", 1); - } - } - - if(! isSimworldOk() ) return; - setElbeemState( SIMWORLD_INITED ); -} - - - -/****************************************************************************** - * Destructor - *****************************************************************************/ -ntlWorld::~ntlWorld() -{ - delete mpGlob->getRenderScene(); - delete mpGlob->getSimScene(); - - delete mpGlob; - - - // these get assigned to mpGlob but not freed there - delete mpLightList; - delete mpPropList; // materials - delete mpSims; - -#ifndef NOGUI - if(mpOpenGLRenderer) delete mpOpenGLRenderer; -#endif // NOGUI - debMsgStd("ntlWorld",DM_NOTIFY, "ntlWorld done", 10); -} - -/******************************************************************************/ -/*! set single frame rendering to filename */ -void ntlWorld::setSingleFrameOut(string singleframeFilename) { - mpGlob->setSingleFrameMode(true); - mpGlob->setSingleFrameFilename(singleframeFilename); -} - -/****************************************************************************** - * render a whole animation (command line mode) - *****************************************************************************/ - -int ntlWorld::renderAnimation( void ) -{ - // only single pic currently - //debMsgStd("ntlWorld::renderAnimation : Warning only simulating...",1); - if(mpGlob->getAniFrames() < 0) { - debMsgStd("ntlWorld::renderAnimation",DM_NOTIFY,"No frames to render... ",1); - return 1; - } - - if(mFirstSim<0) { - debMsgStd("ntlWorld::renderAnimation",DM_NOTIFY,"No reference animation found...",1); - return 1; - } - - mThreadRunning = true; // not threaded, but still use the same flags - if(getElbeemState() == SIMWORLD_INITED) { - renderScene(); - } else if(getElbeemState() == SIMWORLD_STOP) { - // dont render now, just continue - setElbeemState( SIMWORLD_INITED ); - mFrameCnt--; // counted one too many from last abort... - } else { - debMsgStd("ntlWorld::renderAnimation",DM_NOTIFY,"Not properly inited, stopping...",1); - return 1; - } - - if(mpSims->size() <= 0) { - debMsgStd("ntlWorld::renderAnimation",DM_NOTIFY,"No simulations found, stopping...",1); - return 1; - } - - bool simok = true; - for( ; ((mFrameCntgetAniFrames()) && (!getStopRenderVisualization() ) && (simok)); mFrameCnt++) { - if(!advanceSims(mFrameCnt)) { - renderScene(); - } // else means sim panicked, so dont render... - else { simok=false; } - } - mThreadRunning = false; - return 0; -} - -/****************************************************************************** - * render a whole animation (visualization mode) - * this function is run in another thread, and communicates - * with the parent thread via a mutex - *****************************************************************************/ -int ntlWorld::renderVisualization( bool multiThreaded ) -{ -#ifndef NOGUI - if(getElbeemState() != SIMWORLD_INITED) { return 0; } - - if(multiThreaded) mThreadRunning = true; - // TODO, check global state? - while(!getStopRenderVisualization()) { - - if(mpSims->size() <= 0) { - debMsgStd("ntlWorld::renderVisualization",DM_NOTIFY,"No simulations found, stopping...",1); - stopSimulationThread(); - break; - } - - // determine stepsize - if(!mSingleStepDebug) { - long startTime = getTime(); - advanceSims(mFrameCnt); - mFrameCnt++; - long stopTime = getTime(); - debMsgStd("ntlWorld::renderVisualization",DM_MSG,"Time for t="<getTimestep(); - singleStepSims(targetTime); - - // check paniced sims (normally done by advanceSims - bool allPanic = true; - for(size_t i=0;isize();i++) { - if(!(*mpSims)[i]->getPanic()) allPanic = false; - } - if(allPanic) { - warnMsg("ntlWorld::advanceSims","All sims panicked... stopping thread" ); - setStopRenderVisualization( true ); - } - if(! isSimworldOk() ) { - warnMsg("ntlWorld::advanceSims","World state error... stopping" ); - setStopRenderVisualization( true ); - } - } - - // save frame - if(mpOpenGLRenderer) mpOpenGLRenderer->saveAnimationFrame( mSimulationTime ); - - // for non-threaded check events - if(!multiThreaded) { - Fl::check(); - gpElbeemFrame->SceneDisplay->doOnlyForcedRedraw(); - } - - } - mThreadRunning = false; - stopSimulationRestoreGui(); -#else - multiThreaded = false; // remove warning -#endif - return 0; -} -/*! render a single step for viz mode */ -int ntlWorld::singleStepVisualization( void ) -{ - mThreadRunning = true; - double targetTime = mSimulationTime + (*mpSims)[mFirstSim]->getTimestep(); - singleStepSims(targetTime); - mSimulationTime = (*mpSims)[0]->getCurrentTime(); - -#ifndef NOGUI - if(mpOpenGLRenderer) mpOpenGLRenderer->saveAnimationFrame( mSimulationTime ); - Fl::check(); - gpElbeemFrame->SceneDisplay->doOnlyForcedRedraw(); - mThreadRunning = false; - stopSimulationRestoreGui(); -#else - mThreadRunning = false; -#endif // NOGUI - return 0; -} - -// dont use LBM_EPSILON here, time is always double-precision! -#define LBM_TIME_EPSILON 1e-10 - -/****************************************************************************** - * advance simulations by time t - *****************************************************************************/ -int ntlWorld::advanceSims(int framenum) -{ - bool done = false; - bool allPanic = true; - - // stop/quit (abort), dont display/render - if(!isSimworldOk()) { - return 1; - } - - for(size_t i=0;isize();i++) { (*mpSims)[i]->setFrameNum(framenum); } - - // time stopped? nothing else to do... - if( (*mpSims)[mFirstSim]->getFrameTime(framenum) <= 0.0 ){ - done=true; allPanic=false; - - /* DG: Need to check for user cancel here (fix for [#30298]) */ - (*mpSims)[mFirstSim]->checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0); - } - - // Prevent bug [#29186] Object contribute to fluid sim animation start earlier than keyframe - // Was: double targetTime = mSimulationTime + (*mpSims)[mFirstSim]->getFrameTime(framenum); - DG - double totalTime = 0.0, targetTime = 0.0; - for(size_t i = 0; i < mSimFrameCnt; i++) - { - /* We need an intermediate array "mSimFrameValue" because - otherwise if we don't start with starttime = 0, - the sim gets out of sync - DG */ - totalTime += (*mpSims)[mFirstSim]->getFrameTime(mSimFrameValue[i]); - } - targetTime = totalTime + (*mpSims)[mFirstSim]->getFrameTime(framenum); - - int gstate = 0; - myTime_t advsstart = getTime(); - - // step all the sims, and check for panic - debMsgStd("ntlWorld::advanceSims",DM_MSG, " sims "<size()<<" t"<getCurrentTime() + (*mpSims)[mFirstSim]->getTimestep(); - singleStepSims(nextTargetTime); - - // check target times - done = true; - allPanic = false; - - if((*mpSims)[mFirstSim]->getTimestep() <1e-9 ) { - // safety check, avoid timesteps that are too small - errMsg("ntlWorld::advanceSims","Invalid time step, causing panic! curr:"<<(*mpSims)[mFirstSim]->getCurrentTime()<<" next:"<getTimestep() ); - allPanic = true; - } else { - for(size_t i=0;isize();i++) { - if(!(*mpSims)[i]->getVisible()) continue; - if((*mpSims)[i]->getPanic()) allPanic = true; // do any panic now!? - debMsgStd("ntlWorld::advanceSims",DM_MSG, "Sim "<getCurrentTime()<<", nt:"<getPanic()<<", targett:"<getCurrentTime()) > LBM_TIME_EPSILON) done=false; - if(allPanic) done = true; - } - - if(allPanic) { - warnMsg("ntlWorld::advanceSims","All sims panicked... stopping thread" ); - setStopRenderVisualization( true ); - return 1; - } - - myTime_t advsend = getTime(); - debMsgStd("ntlWorld::advanceSims",DM_MSG,"Overall steps so far took:"<< getTimeString(advsend-advsstart)<<" for sim time "<size();i++) { - SimulationObject *sim = (*mpSims)[i]; - if(!sim->getVisible()) continue; - if(sim->getPanic()) continue; - sim->prepareVisualization(); - } - - mSimFrameValue.push_back(framenum); - mSimFrameCnt++; - - return 0; -} - -/* advance simulations by a single step */ -/* dont check target time, if *targetTime==NULL */ -void ntlWorld::singleStepSims(double targetTime) { - const bool debugTime = false; - //double targetTime = mSimulationTime + (*mpSims)[mFirstSim]->getTimestep(); - if(debugTime) errMsg("ntlWorld::singleStepSims","Target time: "<size();i++) { - SimulationObject *sim = (*mpSims)[i]; - if(!sim->getVisible()) continue; - if(sim->getPanic()) continue; - bool done = false; - while(!done) { - // try to prevent round off errs - if(debugTime) errMsg("ntlWorld::singleStepSims","Test sim "<getCurrentTime()<<" target:"<getCurrentTime())<<" stept:"<getTimestep()<<" leps:"<getCurrentTime()) > LBM_TIME_EPSILON) { - if(debugTime) errMsg("ntlWorld::singleStepSims","Stepping sim "<getCurrentTime()); // timedebug - sim->step(); - } else { - done = true; - } - } - } - - mSimulationTime = (*mpSims)[mFirstSim]->getCurrentTime(); -#ifndef NOGUI - if(mpOpenGLRenderer) mpOpenGLRenderer->notifyOfNextStep(mSimulationTime); -#endif // NOGUI -} - - - -/****************************************************************************** - * Render the current scene - * uses the global variables from the parser - *****************************************************************************/ -int ntlWorld::renderScene( void ) -{ -#ifndef ELBEEM_PLUGIN - char nrStr[5]; // nr conversion - std::ostringstream outfn_conv(""); // converted ppm with other suffix - ntlRenderGlobals *glob; // storage for global rendering parameters - myTime_t timeStart,totalStart,timeEnd; // measure user running time - myTime_t rendStart,rendEnd; // measure user rendering time - glob = mpGlob; - - // deactivate for all with index!=0 - if((glob_mpactive)&&(glob_mpindex>0)) return(0); - - /* check if picture already exists... */ - if(!glob->getSingleFrameMode() ) { - snprintf(nrStr, 5, "%04d", glob->getAniCount() ); - - if(glob_mpactive) { - outfn_conv << glob->getOutFilename() <<"_"<getOutFilename() <<"_" << nrStr << ".png"; - } - - //if((mpGlob->getDisplayMode() == DM_RAY)&&(mpGlob->getFrameSkip())) { - if(mpGlob->getFrameSkip()) { - struct stat statBuf; - if(stat(outfn_conv.str().c_str(),&statBuf) == 0) { - errorOut("ntlWorld::renderscene Warning: file "<setAniCount( glob->getAniCount() +1 ); - return(2); - } - } // RAY mode - } else { - // single frame rendering, overwrite if necessary... - outfn_conv << glob->getSingleFrameFilename(); - } - - /* start program */ - timeStart = getTime(); - - /* build scene geometry, calls buildScene(t,false) */ - glob->getRenderScene()->prepareScene(mSimulationTime); - - /* start program */ - totalStart = getTime(); - - - /* view parameters are currently not animated */ - /* calculate rays through projection plane */ - ntlVec3Gfx direction = glob->getLookat() - glob->getEye(); - /* calculate width of screen using perpendicular triangle diven by - * viewing direction and screen plane */ - gfxReal screenWidth = norm(direction)*tan( (glob->getFovy()*0.5/180.0)*M_PI ); - - /* calculate vector orthogonal to up and viewing direction */ - ntlVec3Gfx upVec = glob->getUpVec(); - ntlVec3Gfx rightVec( cross(upVec,direction) ); - normalize(rightVec); - - /* calculate screen plane up vector, perpendicular to viewdir and right vec */ - upVec = ntlVec3Gfx( cross(rightVec,direction) ); - normalize(upVec); - - /* check if vectors are valid */ - if( (equal(upVec,ntlVec3Gfx(0.0))) || (equal(rightVec,ntlVec3Gfx(0.0))) ) { - errMsg("ntlWorld::renderScene","Invalid viewpoint vectors! up="<getLookat() + upVec*((2.0*scanline-Yres)/Yres) - - rightVec; - - /* loop over all pixels in line */ - for (int sx=0 ; sx < Xres ; ++sx) { - - if((sx==glob->getDebugPixelX())&&(scanline==(Yres-glob->getDebugPixelY()) )) { - // DEBUG!!! - glob->setDebugOut(10); - } else glob->setDebugOut(0); - - /* compute ray from eye through current pixel into scene... */ - ntlColor col; - if(aaDepth<0) { - ntlVec3Gfx dir(screenPos - glob->getEye()); - ntlRay the_ray(glob->getEye(), getNormalized(dir), 0, 1.0, glob ); - - /* ...and trace it */ - col = the_ray.shade(); - } else { - /* anti alias */ - int ai,aj; /* position in grid */ - int aOrg = sx*aaLength; /* grid offset x */ - int currStep = aaLength; /* step size */ - char colDiff = 1; /* do colors still differ too much? */ - ntlColor minCol,maxCol; /* minimum and maximum Color Values */ - minCol = ntlColor(1.0,1.0,1.0); - maxCol = ntlColor(0.0,0.0,0.0); - - while((colDiff) && (currStep>0)) { - colDiff = 0; - - for(aj = 0;aj<=aaLength;aj+= currStep) { - for(ai = 0;ai<=aaLength;ai+= currStep) { - - /* shade pixel if not done */ - if(aaUse[aj*aaArrayX +ai +aOrg] == 0) { - aaUse[aj*aaArrayX +ai +aOrg] = 1; - ntlVec3Gfx aaPos( screenPos + - (rightStep * (ai- aaLength/2)/(gfxReal)aaLength ) + - (upStep * (aj- aaLength/2)/(gfxReal)aaLength ) ); - - ntlVec3Gfx dir(aaPos - glob->getEye()); - ntlRay the_ray(glob->getEye(), getNormalized(dir), 0, 1.0, glob ); - - /* ...and trace it */ - ntlColor newCol= the_ray.shade(); - aaCol[aj*aaArrayX +ai +aOrg]= newCol; - } /* not used? */ - - } - } - - /* check color differences */ - for(aj = 0;aj aaSensRed ) || - (fabs(aaCol[aj*aaArrayX +ai +aOrg][1] - - aaCol[(aj+0)*aaArrayX +(ai+currStep) +aOrg][1])> aaSensGreen ) || - (fabs(aaCol[aj*aaArrayX +ai +aOrg][2] - - aaCol[(aj+0)*aaArrayX +(ai+currStep) +aOrg][2])> aaSensBlue ) ) { - thisColDiff = 1; - } else - if( - (fabs(aaCol[aj*aaArrayX +ai +aOrg][0] - - aaCol[(aj+currStep)*aaArrayX +(ai+0) +aOrg][0])> aaSensRed ) || - (fabs(aaCol[aj*aaArrayX +ai +aOrg][1] - - aaCol[(aj+currStep)*aaArrayX +(ai+0) +aOrg][1])> aaSensGreen ) || - (fabs(aaCol[aj*aaArrayX +ai +aOrg][2] - - aaCol[(aj+currStep)*aaArrayX +(ai+0) +aOrg][2])> aaSensBlue ) ) { - thisColDiff = 1; - } else - if( - (fabs(aaCol[aj*aaArrayX +ai +aOrg][0] - - aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg][0])> aaSensRed ) || - (fabs(aaCol[aj*aaArrayX +ai +aOrg][1] - - aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg][1])> aaSensGreen ) || - (fabs(aaCol[aj*aaArrayX +ai +aOrg][2] - - aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg][2])> aaSensBlue ) ) { - thisColDiff = 1; - } - - //colDiff =1; - if(thisColDiff) { - /* set diff flag */ - colDiff = thisColDiff; - for(int bj=aj;bj<=aj+currStep;bj++) { - for(int bi=ai;bi<=ai+currStep;bi++) { - if(aaUse[bj*aaArrayX +bi +aOrg]==2) { - //if(showAAPic) - aaUse[bj*aaArrayX +bi +aOrg] = 0; - } - } - } - } else { - /* set all values */ - ntlColor avgCol = ( - aaCol[(aj+0 )*aaArrayX +(ai+0 ) +aOrg] + - aaCol[(aj+0 )*aaArrayX +(ai+currStep) +aOrg] + - aaCol[(aj+currStep)*aaArrayX +(ai+0 ) +aOrg] + - aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg] ) *0.25; - for(int bj=aj;bj<=aj+currStep;bj++) { - for(int bi=ai;bi<=ai+currStep;bi++) { - if(aaUse[bj*aaArrayX +bi +aOrg]==0) { - aaCol[bj*aaArrayX +bi +aOrg] = avgCol; - aaUse[bj*aaArrayX +bi +aOrg] = 2; - } - } - } - } /* smaller values set */ - - } - } - - /* half step size */ - currStep /= 2; - - } /* repeat until diff not too big */ - - /* get average color */ - gfxReal colNum = 0.0; - col = ntlColor(0.0, 0.0, 0.0); - for(aj = 0;aj<=aaLength;aj++) { - for(ai = 0;ai<=aaLength;ai++) { - col += aaCol[aj*aaArrayX +ai +aOrg]; - colNum += 1.0; - } - } - col /= colNum; - - } - - /* mark pixels with debugging */ - if( glob->getDebugOut() > 0) col = ntlColor(0,1,0); - - /* store pixel */ - if(!showAAPic) { - finalPic[(scanline-1)*picX+sx] = col; - } - screenPos += rightStep; - - } /* foreach x */ - - /* init aa array */ - if(showAAPic) { - for(int j=0;j<=aaArrayY-1;j++) { - for(int i=0;i<=aaArrayX-1;i++) { - if(aaUse[j*aaArrayX +i]==1) finalPic[((scanline-1)*aaLength +j)*picX+i][0] = 1.0; - } - } - } - - for(int i=0;i= 1.0) col[cc] = 1.0; - } - *filler = (unsigned char)( col[0]*255.0 ); - filler++; - *filler = (unsigned char)( col[1]*255.0 ); - filler++; - *filler = (unsigned char)( col[2]*255.0 ); - filler++; - *filler = (unsigned char)( 255.0 ); - filler++; // alpha channel - } - } - - for(int i = 0; i < h; i++) rows[i] = &screenbuf[ (h - i - 1)*rowbytes ]; - writePng(outfn_conv.str().c_str(), rows, w, h); - } - - - // next frame - glob->setAniCount( glob->getAniCount() +1 ); - - // done - timeEnd = getTime(); - - char resout[1024]; - snprintf(resout,1024, "NTL Done %s, frame %d/%d (took %s scene, %s raytracing, %s total, %d shades, %d i.s.'s)!\n", - outfn_conv.str().c_str(), (glob->getAniCount()), (glob->getAniFrames()+1), - getTimeString(totalStart-timeStart).c_str(), getTimeString(rendEnd-rendStart).c_str(), getTimeString(timeEnd-timeStart).c_str(), - glob->getCounterShades(), - glob->getCounterSceneInter() ); - debMsgStd("ntlWorld::renderScene",DM_MSG, resout, 1 ); - - /* clean stuff up */ - delete [] aaCol; - delete [] aaUse; - delete [] finalPic; - glob->getRenderScene()->cleanupScene(); - - if(mpGlob->getSingleFrameMode() ) { - debMsgStd("ntlWorld::renderScene",DM_NOTIFY, "Single frame mode done...", 1 ); - return 1; - } -#endif // ELBEEM_PLUGIN - return 0; -} - - -/****************************************************************************** - * renderglobals - *****************************************************************************/ - - -/*****************************************************************************/ -/* Constructor with standard value init */ -ntlRenderGlobals::ntlRenderGlobals() : - mpRenderScene(NULL), mpSimScene(NULL), - mpLightList( NULL ), mpMaterials( NULL ), mpSims( NULL ), - mResX(320), mResY(200), mAADepth(-1), mMaxColVal(255), - mRayMaxDepth( 5 ), - mvEye(0.0,0.0,5.0), mvLookat(0.0,0.0,0.0), mvUpvec(0.0,1.0,0.0), - mAspect(320.0/200.0), - mFovy(45), mcBackgr(0.0,0.0,0.0), mcAmbientLight(0.0,0.0,0.0), - mDebugOut( 0 ), - mAniStart(0), mAniFrames( -1 ), mAniCount( 0 ), - mFrameSkip( 0 ), - mCounterRays( 0 ), mCounterShades( 0 ), mCounterSceneInter( 0 ), - mOutFilename( "pic" ), - mTreeMaxDepth( 30 ), mTreeMaxTriangles( 30 ), - mpOpenGlAttr(NULL), - mpBlenderAttr(NULL), - mTestSphereEnabled( false ), - mDebugPixelX( -1 ), mDebugPixelY( -1 ), mTestMode(false), - mSingleFrameMode(false), mSingleFrameFilename("") - //,mpRndDirections( NULL ), mpRndRoulette( NULL ) -{ - // create internal attribute list for opengl renderer - mpOpenGlAttr = new AttributeList("__ntlOpenGLRenderer"); - mpBlenderAttr = new AttributeList("__ntlBlenderAttr"); -}; - - -/*****************************************************************************/ -/* Destructor */ -ntlRenderGlobals::~ntlRenderGlobals() { - if(mpOpenGlAttr) delete mpOpenGlAttr; - if(mpBlenderAttr) delete mpBlenderAttr; - - -} - - -/*****************************************************************************/ -//! get the next random photon direction -//ntlVec3Gfx ntlRenderGlobals::getRandomDirection( void ) { - //return ntlVec3Gfx( - //(mpRndDirections->getGfxReal()-0.5), - //(mpRndDirections->getGfxReal()-0.5), - //(mpRndDirections->getGfxReal()-0.5) ); -//} - - diff --git a/intern/elbeem/intern/ntl_world.h b/intern/elbeem/intern/ntl_world.h deleted file mode 100644 index 7851b783225..00000000000 --- a/intern/elbeem/intern/ntl_world.h +++ /dev/null @@ -1,411 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Main renderer class - * - *****************************************************************************/ -#ifndef NTL_RAYTRACER_HH -#define NTL_RAYTRACER_HH - -#include "ntl_vector3dim.h" -#include "ntl_ray.h" -#include "ntl_lighting.h" -#include "ntl_geometryobject.h" -#include "simulation_object.h" -#include "elbeem.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -class ntlOpenGLRenderer; -class ntlScene; -class SimulationObject; -class ntlRandomStream; - -class ntlWorld -{ - public: - /*! Constructor for API init */ - ntlWorld(); - /*! Constructor */ - ntlWorld(string filename, bool commandlineMode); - /*! Destructor */ - virtual ~ntlWorld( void ); - /*! default init for all contructors */ - void initDefaults(); - /*! common world contruction stuff once the scene is set up */ - void finishWorldInit(); - /*! add domain for API init */ - int addDomain(elbeemSimulationSettings *simSettings); - - /*! render a whole animation (command line mode) */ - int renderAnimation( void ); - /*! render a whole animation (visualization mode) */ - int renderVisualization( bool ); - /*! render a single step for viz mode */ - int singleStepVisualization( void ); - /*! advance simulations by time frame time */ - int advanceSims(int framenum); - /*! advance simulations by a single step */ - void singleStepSims(double targetTime); - - /*! set stop rend viz flag */ - void setStopRenderVisualization(bool set) { mStopRenderVisualization = set; } - /*! should the rendering viz thread be stopped? */ - bool getStopRenderVisualization() { return mStopRenderVisualization; } - - /*! render scene (a single pictures) */ - virtual int renderScene( void ); - - /*! set single frame rendering to filename */ - void setSingleFrameOut( string singleframeFilename ); - - /* access functions */ - - /*! set&get render globals */ - inline void setRenderGlobals( ntlRenderGlobals *set) { mpGlob = set; } - inline ntlRenderGlobals *getRenderGlobals( void ) { return mpGlob; } - - /*! set&get render globals */ - inline void setSimulationTime( double set) { mSimulationTime = set; } - inline double getSimulationTime( void ) { return mSimulationTime; } - - /*! set&get single step debug mode */ - inline void setSingleStepDebug( bool set) { mSingleStepDebug = set; } - inline bool getSingleStepDebug( void ) { return mSingleStepDebug; } - - /*! &get simulation object vector (debugging) */ - inline vector *getSimulations( void ) { return mpSims; } - - /*! get opengl renderer */ - inline ntlOpenGLRenderer *getOpenGLRenderer() { return mpOpenGLRenderer; } - - private: - - protected: - - /*! global render settings needed almost everywhere */ - ntlRenderGlobals *mpGlob; - - /*! a list of lights in the scene (geometry is store in ntl_scene) */ - vector *mpLightList; - /*! surface materials */ - vector *mpPropList; - /*! sims list */ - vector *mpSims; - - /*! opengl display */ - ntlOpenGLRenderer *mpOpenGLRenderer; - - /*! stop rend viz? */ - bool mStopRenderVisualization; - - /*! rend viz thread currently running? */ - bool mThreadRunning; - - /*! remember the current simulation time */ - double mSimulationTime; - - /*! first simulation that is valid */ - int mFirstSim; - - /*! single step mode for debugging */ - bool mSingleStepDebug; - - /*! count no. of frame for viz render */ - int mFrameCnt; - - /*! count no. of frame for correct sim time */ - int mSimFrameCnt; - vector mSimFrameValue; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlWorld") -#endif -}; - - -//! Class that handles global rendering parameters -class ntlRenderGlobals -{ - public: - //! Standard constructor - ntlRenderGlobals(); - //! Destructor - ~ntlRenderGlobals(); - - //! Returns the renderscene manager (scene changes for each frame) - inline ntlScene *getRenderScene(void) { return mpRenderScene; } - //! Set the renderscene manager - inline void setRenderScene(ntlScene *set) { mpRenderScene = set;} - - //! Returns the simulation scene manager (static scene with sim objects) - inline ntlScene *getSimScene(void) { return mpSimScene; } - //! Set the simulation scene manager - inline void setSimScene(ntlScene *set) { mpSimScene = set;} - - //! Returns the light object list - inline vector *getLightList(void) { return mpLightList; } - //! Set the light list - inline void setLightList(vector *set) { mpLightList = set;} - - //! Returns the property object list - inline vector *getMaterials(void) { return mpMaterials; } - //! Set the property list - inline void setMaterials(vector *set) { mpMaterials = set;} - - //! Returns the list of simulations - inline vector *getSims(void) { return mpSims; } - //! Set the pointer to the list of simulations - inline void setSims(vector *set) { mpSims = set;} - - //! Set the x resolution - inline void setResX(unsigned int set) { mResX = set; } - //! Set the y resolution - inline void setResY(unsigned int set) { mResY = set; } - //! Set the anti-aliasing depth - inline void setAADepth(int set) { mAADepth = set; } - //! Set the max color value - inline void setMaxColVal(unsigned int set) { mMaxColVal = set; } - //! Set the maximum ray recursion - inline void setRayMaxDepth(unsigned int set) { mRayMaxDepth = set; } - //! Set the eye point - inline void setEye(ntlVec3Gfx set) { mvEye = set; } - //! Set the look at vector - inline void setLookat(ntlVec3Gfx set) { mvLookat = set; } - //! Set the up vector - inline void setUpVec(ntlVec3Gfx set) { mvUpvec = set; } - //! Set the image aspect - inline void setAspect(float set) { mAspect = set; } - //! Set the field of view - inline void setFovy(float set) { mFovy = set; } - //! Set the background color - inline void setBackgroundCol(ntlColor set) { mcBackgr = set; } - //! Set the ambient lighting color - inline void setAmbientLight(ntlColor set) { mcAmbientLight = set; } - //! Set the debug output var - inline void setDebugOut(int set) { mDebugOut = set; } - - //! Set the animation start time - inline void setAniStart(int set) { mAniStart = set; } - //! Set the animation number of frames - inline void setAniFrames(int set) { mAniFrames = set; } - //! Set the animation - inline void setAniCount(int set) { mAniCount = set; } - //! Set the ray counter - inline void setCounterRays(int set) { mCounterRays = set; } - //! Set the ray shades counter - inline void setCounterShades(int set) { mCounterShades = set; } - //! Set the scenen intersection counter - inline void setCounterSceneInter(int set) { mCounterSceneInter = set; } - //! Set if existing frames should be skipped - inline void setFrameSkip(int set) { mFrameSkip = set; } - - //! Set the outfilename - inline void setOutFilename(string set) { mOutFilename = set; } - - //! get Maximum depth for BSP tree - inline void setTreeMaxDepth( int set ) { mTreeMaxDepth = set; } - //! get Maxmimum nr of triangles per BSP tree node - inline void setTreeMaxTriangles( int set ) { mTreeMaxTriangles = set; } - - //! set the enable flag of the test sphere - inline void setTestSphereEnabled( bool set ) { mTestSphereEnabled = set; } - //! set the center of the test sphere - inline void setTestSphereCenter( ntlVec3Gfx set ) { mTestSphereCenter = set; } - //! set the radius of the test sphere - inline void setTestSphereRadius( gfxReal set ) { mTestSphereRadius = set; } - //! set the material name of the test sphere - inline void setTestSphereMaterialName( char* set ) { mTestSphereMaterialName = set; } - //! set debugging pixel coordinates - inline void setDebugPixel( int setx, int sety ) { mDebugPixelX = setx; mDebugPixelY = sety; } - //! set test mode flag - inline void setTestMode( bool set ) { mTestMode = set; } - //! set single frame mode flag - inline void setSingleFrameMode(bool set) {mSingleFrameMode = set; }; - //! set single frame mode filename - inline void setSingleFrameFilename(string set) {mSingleFrameFilename = set; }; - - - //! Return the x resolution - inline unsigned int getResX(void) { return mResX; } - //! Return the y resolution - inline unsigned int getResY(void) { return mResY; } - //! Return the anti-aliasing depth - inline int getAADepth(void) { return mAADepth; } - //! Return the max color value for ppm - inline unsigned int getMaxColVal(void) { return mMaxColVal; } - //! Return the maximum ray recursion - inline unsigned int getRayMaxDepth(void) { return mRayMaxDepth; } - //! Return the eye point - inline ntlVec3Gfx getEye(void) { return mvEye; } - //! Return the look at vector - inline ntlVec3Gfx getLookat(void) { return mvLookat; } - //! Return the up vector - inline ntlVec3Gfx getUpVec(void) { return mvUpvec; } - //! Return the image aspect - inline float getAspect(void) { return mAspect; } - //! Return the field of view - inline float getFovy(void) { return mFovy; } - //! Return the background color - inline ntlColor getBackgroundCol(void) { return mcBackgr; } - //! Return the ambient color - inline ntlColor getAmbientLight(void) { return mcAmbientLight; } - //! Return the debug mode setting - inline int getDebugOut(void) { return mDebugOut; } - - //! Return the animation start time - inline int getAniStart(void) { return mAniStart; } - //! Return the animation frame number - inline int getAniFrames(void) { return mAniFrames; } - //! Return the animation counter - inline int getAniCount(void) { return mAniCount; } - //! Return the ray counter - inline int getCounterRays(void) { return mCounterRays; } - //! Return the ray shades counter - inline int getCounterShades(void) { return mCounterShades; } - //! Return the scene intersection counter - inline int getCounterSceneInter(void) { return mCounterSceneInter; } - //! Check if existing frames should be skipped - inline int getFrameSkip( void ) { return mFrameSkip; } - - - //! Return the outfilename - inline string getOutFilename(void) { return mOutFilename; } - - //! get Maximum depth for BSP tree - inline int getTreeMaxDepth( void ) { return mTreeMaxDepth; } - //! get Maxmimum nr of triangles per BSP tree node - inline int getTreeMaxTriangles( void ) { return mTreeMaxTriangles; } - - //! get open gl attribute list - inline AttributeList* getOpenGlAttributes( void ) { return mpOpenGlAttr; } - //! get blender output attribute list - inline AttributeList* getBlenderAttributes( void ) { return mpBlenderAttr; } - - //! is the test sphere enabled? - inline bool getTestSphereEnabled( void ) { return mTestSphereEnabled; } - //! get the center of the test sphere - inline ntlVec3Gfx getTestSphereCenter( void ) { return mTestSphereCenter; } - //! get the radius of the test sphere - inline gfxReal getTestSphereRadius( void) { return mTestSphereRadius; } - //! get the materialname of the test sphere - inline char *getTestSphereMaterialName( void) { return mTestSphereMaterialName; } - //! get the debug pixel coordinate - inline int getDebugPixelX( void ) { return mDebugPixelX; } - //! get the debug pixel coordinate - inline int getDebugPixelY( void ) { return mDebugPixelY; } - //! get test mode flag - inline bool getTestMode( void ) { return mTestMode; } - //! set single frame mode flag - inline bool getSingleFrameMode() { return mSingleFrameMode; }; - //! set single frame mode filename - inline string getSingleFrameFilename() { return mSingleFrameFilename; }; - - -private: - - /*! Scene storage (dynamic rendering scene) */ - ntlScene *mpRenderScene; - /*! Scene storage (static sim scene, inited only once) */ - ntlScene *mpSimScene; - - //! List of light objects - vector *mpLightList; - //! List of surface properties - vector *mpMaterials; - /*! storage for simulations */ - vector *mpSims; - - //! resolution of the picture - unsigned int mResX, mResY; - //! Anti-Aliasing depth - int mAADepth; - //! max color value for ppm - unsigned int mMaxColVal; - /* Maximal ray recursion depth */ - int mRayMaxDepth; - //! The eye point - ntlVec3Gfx mvEye; - //! The look at point - ntlVec3Gfx mvLookat; - //! The up vector - ntlVec3Gfx mvUpvec; - //! The image aspect = Xres/Yres - float mAspect; - //! The horizontal field of view - float mFovy; - //! The background color - ntlColor mcBackgr; - //! The ambient color - ntlColor mcAmbientLight; - //! how much debug output is needed? off by default - char mDebugOut; - - - //! animation properties, start time - int mAniStart; - //! animation properties, number of frames to render - int mAniFrames; - //! animation status, current frame number - int mAniCount; - /*! Should existing picture frames be skipped? */ - int mFrameSkip; - - - //! count the total number of rays created (also used for ray ID's) - int mCounterRays; - //! count the total number of rays shaded - int mCounterShades; - //! count the total number of scene intersections - int mCounterSceneInter; - - /*! filename of output pictures (without suffix or numbers) */ - string mOutFilename; - - //! get Maximum depth for BSP tree - int mTreeMaxDepth; - //! get Maxmimum nr of triangles per BSP tree node - int mTreeMaxTriangles; - - //! attribute list for opengl renderer - AttributeList *mpOpenGlAttr; - //! attribute list for blender output - AttributeList *mpBlenderAttr; - - - //! Enable test sphere? - bool mTestSphereEnabled; - //! Center of the test sphere - ntlVec3Gfx mTestSphereCenter; - //! Radius of the test sphere - gfxReal mTestSphereRadius; - //! Materialname of the test sphere - char *mTestSphereMaterialName; - //! coordinates of the debugging pixel - int mDebugPixelX, mDebugPixelY; - - //! test mode for quick rendering activated?, inited in ntl_scene::buildScene - bool mTestMode; - - //! single frame flag - bool mSingleFrameMode; - //! filename for single frame mode - string mSingleFrameFilename; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlRenderGlobals") -#endif -}; - - - -#endif diff --git a/intern/elbeem/intern/paraloopend.h b/intern/elbeem/intern/paraloopend.h deleted file mode 100644 index 6f321cd68b1..00000000000 --- a/intern/elbeem/intern/paraloopend.h +++ /dev/null @@ -1,45 +0,0 @@ -/** \file - * \ingroup elbeem - */ - -// same as grid loop_end + barrier - - } // i - int i=0; //dummy - ADVANCE_POINTERS(2*gridLoopBound); - } // j - -# if COMPRESSGRIDS==1 -# if PARALLEL==1 - //frintf(stderr," (id=%d k=%d) ",id,k); -#pragma omp barrier -# endif // PARALLEL==1 -# else // COMPRESSGRIDS==1 - int i=0; //dummy - ADVANCE_POINTERS(mLevel[lev].lSizex*2); -# endif // COMPRESSGRIDS==1 - -} // all cell loop k,j,i - -#pragma omp critical -{ - if(doReduce) { - // synchronize global vars - for(size_t j=0; jaddFullParticle( calcListParts[j] ); - if(calcMaxVlen>mMaxVlen) { - mMxvx = calcMxvx; - mMxvy = calcMxvy; - mMxvz = calcMxvz; - mMaxVlen = calcMaxVlen; - } - if(0) {debMsgStd("OMP_CRIT",DM_MSG, "reduce id"< -#include "parametrizer.h" - -// debug output flag, has to be off for win32 for some reason... -#define DEBUG_PARAMCHANNELS 0 - -/*! param seen debug string array */ -const char *ParamStrings[] = { - "RelaxTime", - "Reynolds", - "Viscosity", - "SoundSpeed", - "DomainSize", - "GravityForce", - "TimeLength", - "Timestep", - "Size", - "TimeFactor", - "AniFrames", - "AniFrameTime", - "AniStart", - "SurfaceTension", - "Density", - "CellSize", - "GStar", - "MaxSpeed", - "SimMaxSpeed", - "FluidVolHeight", - "NormalizedGStar", - "PSERR", "PSERR", "PSERR", "PSERR" -}; - - - -/****************************************************************************** - * Default constructor - *****************************************************************************/ -Parametrizer::Parametrizer( void ) : - mcViscosity( 8.94e-7 ), - mSoundSpeed( 1500 ), - mDomainSize( 0.1 ), mCellSize( 0.01 ), - mcGravity( ParamVec(0.0) ), - mTimestep(0.0001), mDesiredTimestep(-1.0), - mMaxTimestep(-1.0), - mMinTimestep(-1.0), - mSizex(50), mSizey(50), mSizez(50), - mTimeFactor( 1.0 ), - mcAniFrameTime(0.0001), - mTimeStepScale(1.0), - mAniStart(0.0), - //mExtent(1.0, 1.0, 1.0), //mSurfaceTension( 0.0 ), - mDensity(1000.0), mGStar(0.0001), mFluidVolumeHeight(0.0), - mSimulationMaxSpeed(0.0), - mTadapMaxOmega(2.0), mTadapMaxSpeed(0.1), mTadapLevels(1), - mFrameNum(0), - mSeenValues( 0 ), mCalculatedValues( 0 ) -{ -} - - -/****************************************************************************** - * Destructor - *****************************************************************************/ -Parametrizer::~Parametrizer() -{ - /* not much to do... */ -} - -/****************************************************************************** - * Init from attr list - *****************************************************************************/ -void Parametrizer::parseAttrList() -{ - if(!mpAttrs) { - errFatal("Parametrizer::parseAttrList", "mpAttrs pointer not initialized!", SIMWORLD_INITERROR); - return; - } - - // unused - string mSetupType = ""; - mSetupType = mpAttrs->readString("p_setup",mSetupType, "Parametrizer","mSetupType", false); - - // real params - if(getAttributeList()->exists("p_viscosity")) { - mcViscosity = mpAttrs->readChannelFloat("p_viscosity"); seenThis( PARAM_VISCOSITY ); } - - mSoundSpeed = mpAttrs->readFloat("p_soundspeed",mSoundSpeed, "Parametrizer","mSoundSpeed", false); - if(getAttributeList()->exists("p_soundspeed")) seenThis( PARAM_SOUNDSPEED ); - - mDomainSize = mpAttrs->readFloat("p_domainsize",mDomainSize, "Parametrizer","mDomainSize", false); - if(getAttributeList()->exists("p_domainsize")) seenThis( PARAM_DOMAINSIZE ); - if(mDomainSize<=0.0) { - errMsg("Parametrizer::parseAttrList","Invalid real world domain size:"<exists("p_gravity")) { // || (!mcGravity.isInited()) ) { - mcGravity = mpAttrs->readChannelVec3d("p_gravity"); seenThis( PARAM_GRAVITY ); - } - - mTimestep = mpAttrs->readFloat("p_steptime",mTimestep, "Parametrizer","mTimestep", false); - if(getAttributeList()->exists("p_steptime")) seenThis( PARAM_STEPTIME ); - - mTimeFactor = mpAttrs->readFloat("p_timefactor",mTimeFactor, "Parametrizer","mTimeFactor", false); - if(getAttributeList()->exists("p_timefactor")) seenThis( PARAM_TIMEFACTOR ); - - if(getAttributeList()->exists("p_aniframetime")) { //|| (!mcAniFrameTime.isInited()) ) { - mcAniFrameTime = mpAttrs->readChannelFloat("p_aniframetime");seenThis( PARAM_ANIFRAMETIME ); - } - mTimeStepScale = mpAttrs->readFloat("p_timestepscale",mTimeStepScale, "Parametrizer","mTimeStepScale", false); - - mAniStart = mpAttrs->readFloat("p_anistart",mAniStart, "Parametrizer","mAniStart", false); - if(getAttributeList()->exists("p_anistart")) seenThis( PARAM_ANISTART ); - if(mAniStart<0.0) { - errMsg("Parametrizer::parseAttrList","Invalid start time:"<readFloat("p_surfacetension",mSurfaceTension, "Parametrizer","mSurfaceTension", false); - //if(getAttributeList()->exists("p_surfacetension")) seenThis( PARAM_SURFACETENSION ); - - mDensity = mpAttrs->readFloat("p_density",mDensity, "Parametrizer","mDensity", false); - if(getAttributeList()->exists("p_density")) seenThis( PARAM_DENSITY ); - - ParamFloat cellSize = 0.0; // unused, deprecated - cellSize = mpAttrs->readFloat("p_cellsize",cellSize, "Parametrizer","cellSize", false); - - mGStar = mpAttrs->readFloat("p_gstar",mGStar, "Parametrizer","mGStar", false); - if(getAttributeList()->exists("p_gstar")) seenThis( PARAM_GSTAR ); - - mNormalizedGStar = mpAttrs->readFloat("p_normgstar",mNormalizedGStar, "Parametrizer","mNormalizedGStar", false); - if(getAttributeList()->exists("p_normgstar")) seenThis( PARAM_NORMALIZEDGSTAR ); - - mTadapMaxOmega = mpAttrs->readFloat("p_tadapmaxomega",mTadapMaxOmega, "Parametrizer","mTadapMaxOmega", false); - mTadapMaxSpeed = mpAttrs->readFloat("p_tadapmaxspeed",mTadapMaxSpeed, "Parametrizer","mTadapMaxSpeed", false); -} - -/****************************************************************************** - *! advance to next render/output frame - *****************************************************************************/ -void Parametrizer::setFrameNum(int frame) { - mFrameNum = frame; -#if DEBUG_PARAMCHANNELS>0 - errMsg("DEBUG_PARAMCHANNELS","setFrameNum frame-num="<0 -} -/*! get time of an animation frame (renderer) */ -// also used by: mpParam->getCurrentAniFrameTime() , e.g. for velocity dump -ParamFloat Parametrizer::getAniFrameTime( int frame ) { - double frametime = (double)frame; - ParamFloat anift = mcAniFrameTime.get(frametime); - if(anift<0.0) { - ParamFloat resetv = 0.; - errMsg("Parametrizer::setFrameNum","Invalid frame time:"<0 - if((0)|| (DEBUG_PARAMCHANNELS)) errMsg("DEBUG_PARAMCHANNELS","getAniFrameTime frame="<0 - return anift; -} - -/****************************************************************************** - * scale a given speed vector in m/s to lattice values - *****************************************************************************/ -ParamVec Parametrizer::calculateAddForce(ParamVec vec, string usage) -{ - ParamVec ret = vec * (mTimestep*mTimestep) /mCellSize; - debMsgStd("Parametrizer::calculateVector", DM_MSG, "scaled vector = "<0 - errMsg("DEBUG_PARAMCHANNELS","calculateLatticeViscosity viscStar="<0 - return viscStar; -} - -/*! get no of steps for the given length in seconds */ -int Parametrizer::calculateStepsForSecs( ParamFloat s ) { - return (int)(s/mTimestep); -} - -/*! get start time of animation */ -int Parametrizer::calculateAniStart( void ) { - return (int)(mAniStart/mTimestep); -} - -/*! get no of steps for a single animation frame */ -int Parametrizer::calculateAniStepsPerFrame(int frame) { - if(!checkSeenValues(PARAM_ANIFRAMETIME)) { - errFatal("Parametrizer::calculateAniStepsPerFrame", "Missing ani frame time argument!", SIMWORLD_INITERROR); - return 1; - } - int value = (int)(getAniFrameTime(frame)/mTimestep); - if((value<0) || (value>1000000)) { - errFatal("Parametrizer::calculateAniStepsPerFrame", "Invalid step-time (="< ani-frame-time ("<0.0) { gStar = mGStar/mFluidVolumeHeight; } - return gStar; -} - -/****************************************************************************** - * function that tries to calculate all the missing values from the given ones - * prints errors and returns false if thats not possible - *****************************************************************************/ -bool Parametrizer::calculateAllMissingValues( double time, bool silent ) -{ - bool init = false; // did we init correctly? - int valuesChecked = 0; - int reqValues; - - // we always need the sizes - reqValues = PARAM_SIZE; - valuesChecked |= reqValues; - if(!checkSeenValues(reqValues)) { - errMsg("Parametrizer::calculateAllMissingValues"," Missing size argument!"); - return false; - } - - if(!checkSeenValues(PARAM_DOMAINSIZE)) { - errMsg("Parametrizer::calculateAllMissingValues"," Missing domain size argument!"); - return false; - } - int maxsize = mSizex; // get max size - if(mSizey>maxsize) maxsize = mSizey; - if(mSizez>maxsize) maxsize = mSizez; - maxsize = mSizez; // take along gravity dir for now! - mCellSize = ( mDomainSize * calculateCellSize() ); // sets mCellSize - if(!silent) debMsgStd("Parametrizer::calculateAllMissingValues",DM_MSG," max domain resolution="<<(maxsize)<<" cells , cellsize="<0.0) { - debMsgStd("Parametrizer::calculateAllMissingValues",DM_MSG," height"<0.0) { - // explicitly set step time according to max velocity in sim - setDeltaT = mDesiredTimestep; - if(!silent) debMsgStd("Parametrizer::calculateAllMissingValues",DM_MSG," desired step time = "<0)) { - if(!silent) debMsgStd("Parametrizer::calculateAllMissingValues",DM_MSG," ani start steps = "<(set); - seenThis( PARAM_VISCOSITY ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcViscosity set = "<< mcViscosity.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} -void Parametrizer::initViscosityChannel(vector val, vector time) { - mcViscosity = AnimChannel(val,time); - seenThis( PARAM_VISCOSITY ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcViscosity initc = "<< mcViscosity.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} - -/*! set the external force */ -void Parametrizer::setGravity(ParamFloat setx, ParamFloat sety, ParamFloat setz) { - mcGravity = AnimChannel(ParamVec(setx,sety,setz)); - seenThis( PARAM_GRAVITY ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcGravity set = "<< mcGravity.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} -void Parametrizer::setGravity(ParamVec set) { - mcGravity = AnimChannel(set); - seenThis( PARAM_GRAVITY ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcGravity set = "<< mcGravity.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} -void Parametrizer::initGravityChannel(vector val, vector time) { - mcGravity = AnimChannel(val,time); - seenThis( PARAM_GRAVITY ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcGravity initc = "<< mcGravity.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} - -/*! set time of an animation frame (renderer) */ -void Parametrizer::setAniFrameTimeChannel(ParamFloat set) { - mcAniFrameTime = AnimChannel(set); - seenThis( PARAM_ANIFRAMETIME ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcAniFrameTime set = "<< mcAniFrameTime.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} -void Parametrizer::initAniFrameTimeChannel(vector val, vector time) { - mcAniFrameTime = AnimChannel(val,time); - seenThis( PARAM_ANIFRAMETIME ); -#if DEBUG_PARAMCHANNELS>0 - { errMsg("DebugChannels","Parametrizer::mcAniFrameTime initc = "<< mcAniFrameTime.printChannel() ); } -#endif // DEBUG_PARAMCHANNELS>0 -} - -// OLD interface stuff -// reactivate at some point? - - /*! surface tension, [kg/s^2] */ - //ParamFloat mSurfaceTension; - /*! set starting time of the animation (renderer) */ - //void setSurfaceTension(ParamFloat set) { mSurfaceTension = set; seenThis( PARAM_SURFACETENSION ); } - /*! get starting time of the animation (renderer) */ - //ParamFloat getSurfaceTension( void ) { return mSurfaceTension; } - /*if((checkSeenValues(PARAM_SURFACETENSION))&&(mSurfaceTension>0.0)) { - ParamFloat massDelta = 1.0; - ParamFloat densityStar = 1.0; - massDelta = mDensity / densityStar *mCellSize*mCellSize*mCellSize; - if(!silent) debMsgStd("Parametrizer::calculateAllMissingValues",DM_MSG," massDelta = "<0.0) { - ParamFloat maxSpeed = 1.0/6.0; // for rough reynolds approx - ParamFloat reynoldsApprox = -1.0; - ParamFloat gridSpeed = (maxSpeed*mCellSize/mTimestep); - reynoldsApprox = (mDomainSize*gridSpeed) / mViscosity; - if(!silent) debMsgStd("Parametrizer::calculateAllMissingValues",DM_MSG," reynolds number (D="<readFloat("p_relaxtime",mRelaxTime, "Parametrizer","mRelaxTime", false); - //if(getAttributeList()->exists("p_relaxtime")) seenThis( PARAM_RELAXTIME ); - //? mReynolds = mpAttrs->readFloat("p_reynolds",mReynolds, "Parametrizer","mReynolds", false); - //if(getAttributeList()->exists("p_reynolds")) seenThis( PARAM_REYNOLDS ); - - //mViscosity = mpAttrs->readFloat("p_viscosity",mViscosity, "Parametrizer","mViscosity", false); - //if(getAttributeList()->exists("p_viscosity") || (!mcViscosity.isInited()) ) { } - //if(getAttributeList()->exists("p_viscosity")) - - - //ParamFloat viscStar = calculateLatticeViscosity(time); - //RelaxTime = (6.0 * viscStar + 1) * 0.5; - - diff --git a/intern/elbeem/intern/parametrizer.h b/intern/elbeem/intern/parametrizer.h deleted file mode 100644 index bd7377b9fbd..00000000000 --- a/intern/elbeem/intern/parametrizer.h +++ /dev/null @@ -1,322 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Parameter calculator for the LBM Solver class - * - *****************************************************************************/ -#ifndef MFFSLBM_PARAMETRIZER -#define MFFSLBM_PARAMETRIZER - - -/* LBM Files */ -#include "utilities.h" -#include "attributes.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -/* parametrizer accuracy */ -typedef double ParamFloat; -typedef ntlVec3d ParamVec; - -/*! flags to check which values are known */ -#define PARAM_RELAXTIME (1<< 0) -#define PARAM_REYNOLDS (1<< 1) -#define PARAM_VISCOSITY (1<< 2) -#define PARAM_SOUNDSPEED (1<< 3) -#define PARAM_DOMAINSIZE (1<< 4) -#define PARAM_GRAVITY (1<< 5) -#define PARAM_STEPTIME (1<< 7) -#define PARAM_SIZE (1<< 8) -#define PARAM_TIMEFACTOR (1<< 9) -#define PARAM_ANIFRAMETIME (1<<11) -#define PARAM_ANISTART (1<<12) -#define PARAM_SURFACETENSION (1<<13) -#define PARAM_DENSITY (1<<14) -#define PARAM_GSTAR (1<<16) -#define PARAM_SIMMAXSPEED (1<<18) -#define PARAM_FLUIDVOLHEIGHT (1<<19) -#define PARAM_NORMALIZEDGSTAR (1<<20) -#define PARAM_NUMIDS 21 - -//! output parameter debug message? -//#define PARAM_DEBUG 1 - - - -/*! Parameter calculator for the LBM Solver class */ -class Parametrizer { - - public: - /*! default contructor */ - Parametrizer(); - - /*! destructor */ - ~Parametrizer(); - - /*! Initilize variables fom attribute list */ - void parseAttrList( void ); - - /*! function that tries to calculate all the missing values from the given ones - * prints errors and returns false if thats not possible - * currently needs time value as well */ - bool calculateAllMissingValues( double time, bool silent ); - /*! is the parametrizer used at all? */ - bool isUsed() { return true; } - - /*! add this flag to the seen values */ - void seenThis(int seen) { mSeenValues = (mSeenValues | seen); -#ifdef PARAM_DEBUG - errorOut(" seen "< val, vector time); - - /*! set the external force */ - void setGravity(ParamFloat setx, ParamFloat sety, ParamFloat setz); - void setGravity(ParamVec set); - void initGravityChannel(vector val, vector time); - ParamVec getGravity(double time) { return mcGravity.get( time ); } - - /*! set time of an animation frame (renderer) */ - void setAniFrameTimeChannel(ParamFloat set); - void initAniFrameTimeChannel(vector val, vector time); - - /*! set the length of a single time step */ - void setTimestep(ParamFloat set) { mTimestep = set; seenThis( PARAM_STEPTIME ); } - /*! get the length of a single time step */ - ParamFloat getTimestep( void); - /*! set a desired step time for rescaling/adaptive timestepping */ - void setDesiredTimestep(ParamFloat set) { mDesiredTimestep = set; } - /*! get the length of a single time step */ - ParamFloat getMaxTimestep( void ) { return mMaxTimestep; } - /*! get the length of a single time step */ - ParamFloat getMinTimestep( void ) { return mMinTimestep; } - - /*! set the time scaling factor */ - void setTimeFactor(ParamFloat set) { mTimeFactor = set; seenThis( PARAM_TIMEFACTOR ); } - /*! get the time scaling factor */ - ParamFloat getTimeFactor( void ) { return mTimeFactor; } - - /*! init domain resoultion */ - void setSize(int ijk) { mSizex = ijk; mSizey = ijk; mSizez = ijk; seenThis( PARAM_SIZE ); } - void setSize(int i,int j, int k) { mSizex = i; mSizey = j; mSizez = k; seenThis( PARAM_SIZE ); } - - /*! set starting time of the animation (renderer) */ - void setAniStart(ParamFloat set) { mAniStart = set; seenThis( PARAM_ANISTART ); } - /*! get starting time of the animation (renderer) */ - ParamFloat getAniStart( void ) { return mAniStart; } - - /*! set fluid density */ - void setDensity(ParamFloat set) { mDensity = set; seenThis( PARAM_DENSITY ); } - /*! get fluid density */ - ParamFloat getDensity( void ) { return mDensity; } - - /*! set g star value */ - void setGStar(ParamFloat set) { mGStar = set; seenThis( PARAM_GSTAR ); } - /*! get g star value */ - ParamFloat getGStar( void ) { return mGStar; } - /*! get g star value with fhvol calculations */ - ParamFloat getCurrentGStar( void ); - /*! set normalized g star value */ - void setNormalizedGStar(ParamFloat set) { mNormalizedGStar = set; seenThis( PARAM_NORMALIZEDGSTAR ); } - /*! get normalized g star value */ - ParamFloat getNormalizedGStar( void ) { return mNormalizedGStar; } - - /*! set g star value */ - void setFluidVolumeHeight(ParamFloat set) { mFluidVolumeHeight = set; seenThis( PARAM_FLUIDVOLHEIGHT ); } - /*! get g star value */ - ParamFloat getFluidVolumeHeight( void ) { return mFluidVolumeHeight; } - - /*! set the size of a single lbm cell */ - void setDomainSize(ParamFloat set) { mDomainSize = set; seenThis( PARAM_DOMAINSIZE ); } - /*! get the size of a single lbm cell */ - ParamFloat getDomainSize( void ) { return mDomainSize; } - - /*! set the size of a single lbm cell (dont use, normally set by domainsize and resolution) */ - void setCellSize(ParamFloat set) { mCellSize = set; } - /*! get the size of a single lbm cell */ - ParamFloat getCellSize( void ) { return mCellSize; } - - /*! set active flag for parametrizer */ - //void setActive(bool set) { mActive = set; } - - /*! set attr list pointer */ - void setAttrList(AttributeList *set) { mpAttrs = set; } - /*! Returns the attribute list pointer */ - inline AttributeList *getAttributeList() { return mpAttrs; } - - /*! set maximum allowed speed for maxspeed setup */ - void setSimulationMaxSpeed(ParamFloat set) { mSimulationMaxSpeed = set; seenThis( PARAM_SIMMAXSPEED ); } - /*! get maximum allowed speed for maxspeed setup */ - ParamFloat getSimulationMaxSpeed( void ) { return mSimulationMaxSpeed; } - - /*! set maximum allowed omega for time adaptivity */ - void setTadapMaxOmega(ParamFloat set) { mTadapMaxOmega = set; } - /*! get maximum allowed omega for time adaptivity */ - ParamFloat getTadapMaxOmega( void ) { return mTadapMaxOmega; } - - /*! set maximum allowed speed for time adaptivity */ - void setTadapMaxSpeed(ParamFloat set) { mTadapMaxSpeed = set; } - /*! get maximum allowed speed for time adaptivity */ - ParamFloat getTadapMaxSpeed( void ) { return mTadapMaxSpeed; } - - /*! set maximum allowed omega for time adaptivity */ - void setTadapLevels(int set) { mTadapLevels = set; } - /*! get maximum allowed omega for time adaptivity */ - int getTadapLevels( void ) { return mTadapLevels; } - - /*! set */ - // void set(ParamFloat set) { m = set; seenThis( PARAM_ ); } - /*! get */ - // ParamFloat get( void ) { return m; } - - - - private: - - /*! kinematic viscosity of the fluid [m^2/s] */ - AnimChannel mcViscosity; - - /*! speed of sound of the fluid [m/s] */ - ParamFloat mSoundSpeed; - - /*! size of the domain [m] */ - ParamFloat mDomainSize; - - /*! size of a single cell in the grid [m] */ - ParamFloat mCellSize; - - /*! time step length [s] */ - ParamFloat mTimeStep; - - /*! external force as acceleration [m/s^2] */ - AnimChannel mcGravity; - - /*! length of one time step in the simulation */ - ParamFloat mTimestep; - /*! desired step time for rescaling/adaptive timestepping, only regarded if >0.0, reset after usage */ - ParamFloat mDesiredTimestep; - /*! minimal and maximal step times for current setup */ - ParamFloat mMaxTimestep, mMinTimestep; - - /*! domain resoultion, the same values as in lbmsolver */ - int mSizex, mSizey, mSizez; - - /*! time scaling factor (auto calc from accel, or set), equals the delta t in LBM */ - ParamFloat mTimeFactor; - - /*! for renderer - length of an animation step [s] */ - AnimChannel mcAniFrameTime; - /*! time step scaling factor for testing/debugging */ - ParamFloat mTimeStepScale; - - /*! for renderer - start time of the animation [s] */ - ParamFloat mAniStart; - - /*! extent of the domain in meters */ - //ParamVec mExtent; - - /*! fluid density [kg/m^3], default 1.0 g/cm^3 */ - ParamFloat mDensity; - - /*! max difference due to gravity (for caro setup) */ - ParamFloat mGStar; - /*! set gstar normalized! */ - ParamFloat mNormalizedGStar; - /*! fluid volume/height multiplier for GStar */ - ParamFloat mFluidVolumeHeight; - - /*! current max speed of the simulation (for adaptive time steps) */ - ParamFloat mSimulationMaxSpeed; - /*! maximum omega (for adaptive time steps) */ - ParamFloat mTadapMaxOmega; - /*! maximum allowed speed in lattice units e.g. 0.1 (for adaptive time steps, not directly used in parametrizer) */ - ParamFloat mTadapMaxSpeed; - /*! no. of levels for max omega (set by fsgr, not in cfg file) */ - int mTadapLevels; - - /*! remember current frame number */ - int mFrameNum; - - /*! values that are seen for this simulation */ - int mSeenValues; - - /*! values that are calculated from the seen ones for this simulation */ - int mCalculatedValues; - - /*! pointer to the attribute list */ - AttributeList *mpAttrs; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:Parametrizer") -#endif -}; - - -#endif - diff --git a/intern/elbeem/intern/particletracer.cpp b/intern/elbeem/intern/particletracer.cpp deleted file mode 100644 index 7a0005f67ce..00000000000 --- a/intern/elbeem/intern/particletracer.cpp +++ /dev/null @@ -1,470 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Particle Viewer/Tracer - * - *****************************************************************************/ - -#include -//#include "../libs/my_gl.h" -//#include "../libs/my_glu.h" - -/* own lib's */ -#include "particletracer.h" -#include "ntl_matrices.h" -#include "ntl_ray.h" -#include "ntl_matrices.h" -#include "globals.h" - -#include - - -// particle object id counter -int ParticleObjectIdCnt = 1; - -/****************************************************************************** - * Standard constructor - *****************************************************************************/ -ParticleTracer::ParticleTracer() : - ntlGeometryObject(), - mParts(), - //mTrailLength(1), mTrailInterval(1),mTrailIntervalCounter(0), - mPartSize(0.01), - mStart(-1.0), mEnd(1.0), - mSimStart(-1.0), mSimEnd(1.0), - mPartScale(0.1) , mPartHeadDist( 0.1 ), mPartTailDist( -0.1 ), mPartSegments( 4 ), - mValueScale(0), - mValueCutoffTop(0.0), mValueCutoffBottom(0.0), - mDumpParts(0), //mDumpText(0), - mDumpTextFile(""), - mDumpTextInterval(0.), mDumpTextLastTime(0.), mDumpTextCount(0), - mShowOnly(0), - mNumInitialParts(0), mpTrafo(NULL), - mInitStart(-1.), mInitEnd(-1.), - mPrevs(), mTrailTimeLast(0.), mTrailInterval(-1.), mTrailLength(0) -{ - debMsgStd("ParticleTracer::ParticleTracer",DM_MSG,"inited",10); -}; - -ParticleTracer::~ParticleTracer() { - debMsgStd("ParticleTracer::~ParticleTracer",DM_MSG,"destroyed",10); - if(mpTrafo) delete mpTrafo; -} - -/*****************************************************************************/ -//! parse settings from attributes (dont use own list!) -/*****************************************************************************/ -void ParticleTracer::parseAttrList(AttributeList *att) -{ - AttributeList *tempAtt = mpAttrs; - mpAttrs = att; - - mNumInitialParts = mpAttrs->readInt("particles",mNumInitialParts, "ParticleTracer","mNumInitialParts", false); - //errMsg(" NUMP"," "<readFloat("part_scale",mPartScale, "ParticleTracer","mPartScale", false); - mPartHeadDist = mpAttrs->readFloat("part_headdist",mPartHeadDist, "ParticleTracer","mPartHeadDist", false); - mPartTailDist = mpAttrs->readFloat("part_taildist",mPartTailDist, "ParticleTracer","mPartTailDist", false); - mPartSegments = mpAttrs->readInt ("part_segments",mPartSegments, "ParticleTracer","mPartSegments", false); - mValueScale = mpAttrs->readInt ("part_valscale",mValueScale, "ParticleTracer","mValueScale", false); - mValueCutoffTop = mpAttrs->readFloat("part_valcutofftop",mValueCutoffTop, "ParticleTracer","mValueCutoffTop", false); - mValueCutoffBottom = mpAttrs->readFloat("part_valcutoffbottom",mValueCutoffBottom, "ParticleTracer","mValueCutoffBottom", false); - - mDumpParts = mpAttrs->readInt ("part_dump",mDumpParts, "ParticleTracer","mDumpParts", false); - // mDumpText deprecatd, use mDumpTextInterval>0. instead - mShowOnly = mpAttrs->readInt ("part_showonly",mShowOnly, "ParticleTracer","mShowOnly", false); - mDumpTextFile= mpAttrs->readString("part_textdumpfile",mDumpTextFile, "ParticleTracer","mDumpTextFile", false); - mDumpTextInterval= mpAttrs->readFloat("part_textdumpinterval",mDumpTextInterval, "ParticleTracer","mDumpTextInterval", false); - - string matPart; - matPart = mpAttrs->readString("material_part", "default", "ParticleTracer","material", false); - setMaterialName( matPart ); - - mInitStart = mpAttrs->readFloat("part_initstart",mInitStart, "ParticleTracer","mInitStart", false); - mInitEnd = mpAttrs->readFloat("part_initend", mInitEnd, "ParticleTracer","mInitEnd", false); - - // unused... - //int mTrailLength = 0; // UNUSED - //int mTrailInterval= 0; // UNUSED - mTrailLength = mpAttrs->readInt("traillength",mTrailLength, "ParticleTracer","mTrailLength", false); - mTrailInterval= mpAttrs->readFloat("trailinterval",mTrailInterval, "ParticleTracer","mTrailInterval", false); - - // restore old list - mpAttrs = tempAtt; -} - -/****************************************************************************** - * draw the particle array - *****************************************************************************/ -void ParticleTracer::draw() -{ -} - -/****************************************************************************** - * init trafo matrix - *****************************************************************************/ -void ParticleTracer::initTrafoMatrix() { - ntlVec3Gfx scale = ntlVec3Gfx( - (mEnd[0]-mStart[0])/(mSimEnd[0]-mSimStart[0]), - (mEnd[1]-mStart[1])/(mSimEnd[1]-mSimStart[1]), - (mEnd[2]-mStart[2])/(mSimEnd[2]-mSimStart[2]) - ); - ntlVec3Gfx trans = mStart; - if(!mpTrafo) mpTrafo = new ntlMat4Gfx(0.0); - mpTrafo->initId(); - for(int i=0; i<3; i++) { mpTrafo->value[i][i] = scale[i]; } - for(int i=0; i<3; i++) { mpTrafo->value[i][3] = trans[i]; } -} - -/****************************************************************************** - * adapt time step by rescaling velocities - *****************************************************************************/ -void ParticleTracer::adaptPartTimestep(float factor) { - for(size_t i=0; i0.) { errMsg("ParticleTracer::cleanup","Skipping cleanup due to text dump..."); return; } - - for(int i=0; i<=last; i++) { - if( mParts[i].getActive()==false ) { - ParticleObject *p = &mParts[i]; - ParticleObject *p2 = &mParts[last]; - *p = *p2; last--; mParts.pop_back(); - } - } -} - -/****************************************************************************** - *! dump particles if desired - *****************************************************************************/ -void ParticleTracer::notifyOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename, double simtime) { - debMsgStd("ParticleTracer::notifyOfDump",DM_MSG,"obj:"<getName()<<" frame:"<0)) { - // dump to binary file - std::ostringstream boutfilename(""); - boutfilename << outfilename <<"_particles_" << frameNrStr; - if(glob_mpactive) { - if(glob_mpindex>0) { boutfilename << "mp"<getName() <<", particles:"<getType(); // export whole type info - int type = p->getFlags(); // debug export whole type & status info - ntlVec3Gfx pos = p->getPos(); - float size = p->getSize(); - - if(type&PART_FLOAT) { // WARNING same handling for dump! - // add one gridcell offset - //pos[2] += 1.0; - } - // display as drop for now externally - //else if(type&PART_TRACER) { type |= PART_DROP; } - - pos = (*mpTrafo) * pos; - - ntlVec3Gfx v = p->getVel(); - v[0] *= mpTrafo->value[0][0]; - v[1] *= mpTrafo->value[1][1]; - v[2] *= mpTrafo->value[2][2]; - // FIXME check: pos = (*mpTrafo) * pos; - gzwrite(gzf, &type, sizeof(type)); - gzwrite(gzf, &size, sizeof(size)); - for(int j=0; j<3; j++) { gzwrite(gzf, &pos[j], sizeof(float)); } - for(int j=0; j<3; j++) { gzwrite(gzf, &v[j], sizeof(float)); } - } - gzclose( gzf ); - } - } // dump? -} - -void ParticleTracer::checkDumpTextPositions(double simtime) { - // dfor partial & full dump - if(mDumpTextInterval>0.) { - debMsgStd("ParticleTracer::checkDumpTextPositions",DM_MSG,"t="<0.) && (simtime>mDumpTextLastTime+mDumpTextInterval)) { - // dump to binary file - std::ostringstream boutfilename(""); - if(mDumpTextFile.length()>1) { - boutfilename << mDumpTextFile << ".cpart2"; - } else { - boutfilename << "_particles" << ".cpart2"; - } - debMsgStd("ParticleTracer::checkDumpTextPositions",DM_MSG,"T-Dumping: "<< this->getName() <<", particles:"<getPos(); - float size = p->getSize(); - float infl = 1.; - //if(!mParts[i].getActive()) { size=0.; } // switch "off" - if(!mParts[i].getActive()) { infl=0.; } // switch "off" - if(!mParts[i].getInFluid()) { infl=0.; } // switch "off" - if(mParts[i].getLifeTime()<0.) { infl=0.; } // not yet active... - - pos = (*mpTrafo) * pos; - ntlVec3Gfx v = p->getVel(); - v[0] *= mpTrafo->value[0][0]; - v[1] *= mpTrafo->value[1][1]; - v[2] *= mpTrafo->value[2][2]; - - fprintf( stf, "P %f %f %f \n", pos[0],pos[1],pos[2] ); - if(size!=1.0) fprintf( stf, "s %f \n", size ); - if(infl!=1.0) fprintf( stf, "i %f \n", infl ); - fprintf( stf, "\n" ); - } - - fprintf( stf, "# %d end ", mDumpTextCount ); - //gzclose( gzf ); - fclose( stf ); - - mDumpTextCount++; - } - - mDumpTextLastTime += mDumpTextInterval; - } - -} - - -void ParticleTracer::checkTrails(double time) { - if(mTrailLength<1) return; - if(time-mTrailTimeLast > mTrailInterval) { - - if( (int)mPrevs.size() < mTrailLength) mPrevs.resize( mTrailLength ); - for(int i=mPrevs.size()-1; i>0; i--) { - mPrevs[i] = mPrevs[i-1]; - //errMsg("TRAIL"," from "< *triangles, - vector *vertices, - vector *normals, int objectId ) -{ -#ifdef ELBEEM_PLUGIN - // suppress warnings... - vertices = NULL; triangles = NULL; - normals = NULL; objectId = 0; - time = 0.; -#else // ELBEEM_PLUGIN - int pcnt = 0; - // currently not used in blender - objectId = 0; // remove, deprecated - if(mDumpParts>1) { - return; // only dump, no tri-gen - } - - const bool debugParts = false; - int tris = 0; - int segments = mPartSegments; - ntlVec3Gfx scale = ntlVec3Gfx( (mEnd[0]-mStart[0])/(mSimEnd[0]-mSimStart[0]), (mEnd[1]-mStart[1])/(mSimEnd[1]-mSimStart[1]), (mEnd[2]-mStart[2])/(mSimEnd[2]-mSimStart[2])); - ntlVec3Gfx trans = mStart; - time = 0.; // doesnt matter - - for(size_t t=0; t *dparts; - if(t==0) { - dparts = &mParts; - } else { - dparts = &mPrevs[t-1]; - } - //errMsg("TRAILT","prevs"<size() ); - - gfxReal partscale = mPartScale; - if(t>1) { - partscale *= (gfxReal)(mPrevs.size()+1-t) / (gfxReal)(mPrevs.size()+1); - } - gfxReal partNormSize = 0.01 * partscale; - //for(size_t i=0; isize(); i++) { - ParticleObject *p = &( (*dparts)[i] ); // mParts[i]; - - if(mShowOnly!=10) { - // 10=show only deleted - if( p->getActive()==false ) continue; - } else { - if( p->getActive()==true ) continue; - } - int type = p->getType(); - if(mShowOnly>0) { - switch(mShowOnly) { - case 1: if(!(type&PART_BUBBLE)) continue; break; - case 2: if(!(type&PART_DROP)) continue; break; - case 3: if(!(type&PART_INTER)) continue; break; - case 4: if(!(type&PART_FLOAT)) continue; break; - case 5: if(!(type&PART_TRACER)) continue; break; - } - } else { - // by default dont display inter - if(type&PART_INTER) continue; - } - - pcnt++; - ntlVec3Gfx pnew = p->getPos(); - if(type&PART_FLOAT) { // WARNING same handling for dump! - if(p->getStatus()&PART_IN) { pnew[2] += 0.8; } // offset for display - // add one gridcell offset - //pnew[2] += 1.0; - } -#if LBMDIM==2 - pnew[2] += 0.001; // DEBUG - pnew[2] += 0.009; // DEBUG -#endif - - ntlVec3Gfx pdir = p->getVel(); - gfxReal plen = normalize( pdir ); - if( plen < 1e-05) pdir = ntlVec3Gfx(-1.0 ,0.0 ,0.0); - ntlVec3Gfx pos = (*mpTrafo) * pnew; - gfxReal partsize = 0.0; - if(debugParts) errMsg("DebugParts"," i"< class ntlMatrix4x4; - -// particle types -#define PART_BUBBLE (1<< 1) -#define PART_DROP (1<< 2) -#define PART_INTER (1<< 3) -#define PART_FLOAT (1<< 4) -#define PART_TRACER (1<< 5) - -// particle state -#define PART_IN (1<< 8) -#define PART_OUT (1<< 9) -#define PART_INACTIVE (1<<10) -#define PART_OUTFLUID (1<<11) - -// defines for particle movement -#define MOVE_FLOATS 1 -#define FLOAT_JITTER 0.03 -//#define FLOAT_JITTER 0.0 - -extern int ParticleObjectIdCnt; - -//! A single particle -class ParticleObject -{ - public: - //! Standard constructor - inline ParticleObject(ntlVec3Gfx mp) : - mPos(mp),mVel(0.0), mSize(1.0), mStatus(0),mLifeTime(0),mpNext(NULL) - { mId = ParticleObjectIdCnt++; }; - //! Copy constructor - inline ParticleObject(const ParticleObject &a) : - mPos(a.mPos), mVel(a.mVel), mSize(a.mSize), - mStatus(a.mStatus), - mLifeTime(a.mLifeTime), mpNext(NULL) - { mId = ParticleObjectIdCnt++; }; - //! Destructor - inline ~ParticleObject() { /* empty */ }; - - //! add vector to position - inline void advance(float vx, float vy, float vz) { - mPos[0] += vx; mPos[1] += vy; mPos[2] += vz; } - inline void advanceVec(ntlVec3Gfx v) { - mPos[0] += v[0]; mPos[1] += v[1]; mPos[2] += v[2]; } - //! advance with own velocity - inline void advanceVel() { mPos += mVel; } - //! add acceleration to velocity - inline void addToVel(ntlVec3Gfx acc) { mVel += acc; } - - //! get/set vector to position - inline ntlVec3Gfx getPos() { return mPos; } - inline void setPos(ntlVec3Gfx set) { mPos=set; } - //! set velocity - inline void setVel(ntlVec3Gfx set) { mVel = set; } - //! set velocity - inline void setVel(gfxReal x, gfxReal y, gfxReal z) { mVel = ntlVec3Gfx(x,y,z); } - //! get velocity - inline ntlVec3Gfx getVel() { return mVel; } - - //! get/set size value - inline gfxReal getSize() { return mSize; } - inline void setSize(gfxReal set) { mSize=set; } - - //! get/set next pointer - inline ParticleObject* getNext() { return mpNext; } - inline void setNext(ParticleObject* set) { mpNext=set; } - - //! get whole flags - inline int getFlags() const { return mStatus; } - //! get status (higher byte) - inline int getStatus() const { return (mStatus&0xFF00); } - //! set status (higher byte) - inline void setStatus(int set) { mStatus = set|(mStatus&0x00FF); } - //! get type (lower byte) - inline int getType() const { return (mStatus&0x00FF); } - //! set type (lower byte) - inline void setType(int set) { mStatus = set|(mStatus&0xFF00); } - //! get active flag - inline bool getActive() const { return ((mStatus&PART_INACTIVE)==0); } - //! set active flag - inline void setActive(bool set) { - if(set) mStatus &= (~PART_INACTIVE); - else mStatus |= PART_INACTIVE; - } - //! get influid flag - inline bool getInFluid() const { return ((mStatus&PART_OUTFLUID)==0); } - //! set influid flag - inline void setInFluid(bool set) { - if(set) mStatus &= (~PART_OUTFLUID); - else mStatus |= PART_OUTFLUID; - } - //! get/set lifetime - inline float getLifeTime() const { return mLifeTime; } - //! set type (lower byte) - inline void setLifeTime(float set) { mLifeTime = set; } - - inline int getId() const { return mId; } - - static inline float getMass(float size) { - return 4.0/3.0 * M_PI* (size)*(size)*(size); // mass: 4/3 pi r^3 rho - } - - protected: - - /*! only for debugging */ - int mId; - /*! the particle position */ - ntlVec3Gfx mPos; - /*! the particle velocity */ - ntlVec3Gfx mVel; - /*! size / mass of particle */ - gfxReal mSize; - /*! particle status */ - int mStatus; - /*! count survived time steps */ - float mLifeTime; - - /* for list constructions */ - ParticleObject *mpNext; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ParticleObject") -#endif -}; - - -//! A whole particle array -class ParticleTracer : - public ntlGeometryObject -{ - public: - //! Standard constructor - ParticleTracer(); - //! Destructor - ~ParticleTracer(); - - //! add a particle at this position - void addParticle(float x, float y, float z); - //! add/copy a particle from inited struct - void addFullParticle(ParticleObject &np); - - //! draw the particle array - void draw(); - - //! parse settings from attributes (dont use own list!) - void parseAttrList( AttributeList *att ); - - //! adapt time step by rescaling velocities - void adaptPartTimestep(float factor); - - // access funcs - - //! get the number of particles - inline int getNumParticles() { return mParts.size(); } - //! set/get the number of particles - inline void setNumInitialParticles(int set) { mNumInitialParts=set; } - inline int getNumInitialParticles() { return mNumInitialParts; } - - //! iterate over all newest particles (for advancing positions) - inline vector::iterator getParticlesBegin() { return mParts.begin(); } - //! end iterator for newest particles - inline vector::iterator getParticlesEnd() { return mParts.end(); } - //! end iterator for newest particles - inline ParticleObject* getLast() { return &(mParts[ mParts.size()-1 ]); } - - /*! set geometry start (for renderer) */ - inline void setStart(ntlVec3Gfx set) { mStart = set; initTrafoMatrix(); } - /*! set geometry end (for renderer) */ - inline void setEnd(ntlVec3Gfx set) { mEnd = set; initTrafoMatrix(); } - /*! get values */ - inline ntlVec3Gfx getStart() { return mStart; } - /*! set geometry end (for renderer) */ - inline ntlVec3Gfx getEnd() { return mEnd; } - - /*! set simulation domain start */ - inline void setSimStart(ntlVec3Gfx set) { mSimStart = set; initTrafoMatrix(); } - /*! set simulation domain end */ - inline void setSimEnd(ntlVec3Gfx set) { mSimEnd = set; initTrafoMatrix(); } - - /*! set/get dump flag */ - inline void setDumpParts(bool set) { mDumpParts = set; } - inline bool getDumpParts() { return mDumpParts; } - /*! set/get dump text file */ - inline void setDumpTextFile(string set) { mDumpTextFile = set; } - inline string getDumpTextFile() { return mDumpTextFile; } - /*! set/get dump text interval */ - inline void setDumpTextInterval(float set) { mDumpTextInterval = set; } - inline float getDumpTextInterval() { return mDumpTextInterval; } - /*! set/get init times */ - inline void setInitStart(float set) { mInitStart = set; } - inline float getInitStart() { return mInitStart; } - inline void setInitEnd(float set) { mInitEnd = set; } - inline float getInitEnd() { return mInitEnd; } - - //! set the particle scaling factor - inline void setPartScale(float set) { mPartScale = set; } - - //! called after each frame to check if positions should be dumped - void checkDumpTextPositions(double simtime); - - // NTL geometry implementation - /*! Get the triangles from this object */ - virtual void getTriangles(double t, vector *triangles, - vector *vertices, - vector *normals, int objectId ); - - virtual void notifyOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename,double simtime); - - // notify of next step for trails - void checkTrails(double time); - // free deleted particles - void cleanup(); - - protected: - - /*! the particle array (for multiple timesteps) */ - vector mParts; - - /*! size of the particles to display */ - float mPartSize; - - /*! start and end vectors for the triangulation region to create particles in */ - ntlVec3Gfx mStart, mEnd; - - /*! start and end vectors of the simulation domain */ - ntlVec3Gfx mSimStart, mSimEnd; - - /*! scaling param for particles */ - float mPartScale; - /*! head and tail distance for particle shapes */ - float mPartHeadDist, mPartTailDist; - /*! no of segments for particle cone */ - int mPartSegments; - /*! use length/absval of values to scale particles? */ - int mValueScale; - /*! value length maximal cutoff value, for mValueScale==2 */ - float mValueCutoffTop; - /*! value length minimal cutoff value, for mValueScale==2 */ - float mValueCutoffBottom; - - /*! dump particles (or certain types of) to disk? */ - int mDumpParts; - /*! text dump output file */ - string mDumpTextFile; - /*! text dump interval, start at t=0, dumping active if >0 */ - float mDumpTextInterval; - float mDumpTextLastTime; - int mDumpTextCount; - /*! show only a certain type (debugging) */ - int mShowOnly; - /*! no. of particles to init */ - int mNumInitialParts; - - //! transform matrix - ntlMatrix4x4 *mpTrafo; - /*! init sim/pos transformation */ - void initTrafoMatrix(); - - //! init time distribution start/end - float mInitStart, mInitEnd; - - /*! the particle array (for multiple timesteps) */ - vector< vector > mPrevs; - /* prev pos save interval */ - float mTrailTimeLast, mTrailInterval; - int mTrailLength; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ParticleTracer") -#endif -}; - -#define NTL_PARTICLETRACER_H -#endif - diff --git a/intern/elbeem/intern/simulation_object.cpp b/intern/elbeem/intern/simulation_object.cpp deleted file mode 100644 index bba202300e9..00000000000 --- a/intern/elbeem/intern/simulation_object.cpp +++ /dev/null @@ -1,471 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Basic interface for all simulation modules - * - *****************************************************************************/ - -#include "simulation_object.h" -#include "solver_interface.h" -#include "ntl_bsptree.h" -#include "ntl_ray.h" -#include "ntl_world.h" -#include "solver_interface.h" -#include "particletracer.h" -#include "elbeem.h" - -#if PARALLEL==1 -#include -#endif - -#ifdef _WIN32 -#else -#include -#endif - - -//! lbm factory functions -LbmSolverInterface* createSolver(); - -/****************************************************************************** - * Constructor - *****************************************************************************/ -SimulationObject::SimulationObject() : - ntlGeometryShader(), - mGeoStart(-100.0), mGeoEnd(100.0), - mpGiTree(NULL), mpGiObjects(NULL), - mpGlob(NULL), - mPanic( false ), - mDebugType( 1 /* =FLUIDDISPNothing*/ ), - mpLbm(NULL), mpParam( NULL ), - mShowSurface(true), mShowParticles(false), - mSelectedCid( NULL ), - mpElbeemSettings( NULL ) - -{ - mpParam = new Parametrizer(); - //for(int i=0; igetSimScene(); - mpGiObjects = scene->getObjects(); - - if(mpGiTree != NULL) delete mpGiTree; - char treeFlag = (1<<(mGeoInitId+4)); - mpGiTree = new ntlTree( 20, 4, // warning - fixed values for depth & maxtriangles here... - scene, treeFlag ); - // unused!! overriden by solver interface -} - -/*****************************************************************************/ -/*! destroy tree etc. when geometry init done */ -/*****************************************************************************/ -void SimulationObject::freeGeoTree() { - if(mpGiTree != NULL) delete mpGiTree; -} - - - -// copy & remember settings for later use -void SimulationObject::copyElbeemSettings(elbeemSimulationSettings *settings) { - mpElbeemSettings = new elbeemSimulationSettings; - *mpElbeemSettings = *settings; - - mGeoInitId = settings->domainId+1; - debMsgStd("SimulationObject",DM_MSG,"mGeoInitId="<readString("solver", mSolverType, "SimulationObject","mSolverType", false ); - - mpLbm = createSolver(); - /* check lbm pointer */ - if(mpLbm == NULL) { - errFatal("SimulationObject::initializeLbmSimulation","Unable to init LBM solver! ", SIMWORLD_INITERROR); - return 2; - } - debMsgStd("SimulationObject::initialized",DM_MSG,"IdStr:"<getIdString() <<" LBM solver! ", 2); - - mpParts = new ParticleTracer(); - - // for non-param simulations - mpLbm->setParametrizer( mpParam ); - mpParam->setAttrList( getAttributeList() ); - // not needed.. done in solver_init: mpParam->setSize ... in solver_interface - mpParam->parseAttrList(); - - mpLbm->setAttrList( getAttributeList() ); - mpLbm->setSwsAttrList( getSwsAttributeList() ); - mpLbm->parseAttrList(); - mpParts->parseAttrList( getAttributeList() ); - - if(! isSimworldOk() ) return 3; - mpParts->setName( getName() + "_part" ); - mpParts->initialize( glob ); - if(! isSimworldOk() ) return 4; - - // init material settings - string matMc("default"); - matMc = mpAttrs->readString("material_surf", matMc, "SimulationObject","matMc", false ); - mShowSurface = mpAttrs->readInt("showsurface", mShowSurface, "SimulationObject","mShowSurface", false ); - mShowParticles = mpAttrs->readInt("showparticles", mShowParticles, "SimulationObject","mShowParticles", false ); - - checkBoundingBox( mGeoStart, mGeoEnd, "SimulationObject::initializeSimulation" ); - mpLbm->setLbmInitId( mGeoInitId ); - mpLbm->setGeoStart( mGeoStart ); - mpLbm->setGeoEnd( mGeoEnd ); - mpLbm->setRenderGlobals( mpGlob ); - mpLbm->setName( getName() + "_lbm" ); - mpLbm->setParticleTracer( mpParts ); - if(mpElbeemSettings) { - // set further settings from API struct init - this->mOutFilename = string(mpElbeemSettings->outputPath); - mpLbm->initDomainTrafo( mpElbeemSettings->surfaceTrafo ); - mpLbm->setSmoothing(1.0 * mpElbeemSettings->surfaceSmoothing, 1.0 * mpElbeemSettings->surfaceSmoothing); - mpLbm->setIsoSubdivs(mpElbeemSettings->surfaceSubdivs); -#if PARALLEL==1 - mpLbm->setNumOMPThreads(mpElbeemSettings->threads); -#endif - mpLbm->setSizeX(mpElbeemSettings->resolutionxyz); - mpLbm->setSizeY(mpElbeemSettings->resolutionxyz); - mpLbm->setSizeZ(mpElbeemSettings->resolutionxyz); - mpLbm->setPreviewSize(mpElbeemSettings->previewresxyz); - mpLbm->setRefinementDesired(mpElbeemSettings->maxRefine); - mpLbm->setGenerateParticles(mpElbeemSettings->generateParticles); - // set initial particles - mpParts->setNumInitialParticles(mpElbeemSettings->numTracerParticles); - - // surface generation flag - mpLbm->setSurfGenSettings(mpElbeemSettings->mFsSurfGenSetting); - - string dinitType = string("no"); - if (mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_PARTSLIP) dinitType = string("part"); - else if(mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_FREESLIP) dinitType = string("free"); - else /*if(mpElbeemSettings->domainobsType==FLUIDSIM_OBSTACLE_NOSLIP)*/ dinitType = string("no"); - mpLbm->setDomainBound(dinitType); - mpLbm->setDomainPartSlip(mpElbeemSettings->domainobsPartslip); - mpLbm->setDumpVelocities(mpElbeemSettings->generateVertexVectors); - mpLbm->setFarFieldSize(mpElbeemSettings->farFieldSize); - debMsgStd("SimulationObject::initialize",DM_MSG,"Added domain bound: "<generateVertexVectors<<","<getDumpVelocities(), 9 ); - - debMsgStd("SimulationObject::initialize",DM_MSG,"Set ElbeemSettings values "<getGenerateParticles(),10); - } - - if(! mpLbm->initializeSolverMemory() ) { errMsg("SimulationObject::initialize","initializeSolverMemory failed"); mPanic=true; return 10; } - if(checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0)) { errMsg("SimulationObject::initialize","initializeSolverMemory status"); mPanic=true; return 11; } - if(! mpLbm->initializeSolverGrids() ) { errMsg("SimulationObject::initialize","initializeSolverGrids failed"); mPanic=true; return 12; } - if(checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0)) { errMsg("SimulationObject::initialize","initializeSolverGrids status"); mPanic=true; return 13; } - if(! mpLbm->initializeSolverPostinit() ) { errMsg("SimulationObject::initialize","initializeSolverPostin failed"); mPanic=true; return 14; } - if(checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0)) { errMsg("SimulationObject::initialize","initializeSolverPostin status"); mPanic=true; return 15; } - - // print cell type stats - bool printStats = true; - if(glob_mpnum>0) printStats=false; // skip in this case - if(printStats) { - const int jmax = sizeof(CellFlagType)*8; - int totalCells = 0; - int flagCount[jmax]; - for(int j=0; jgetFirstCell(); - for(; mpLbm->noEndCell( cid ); - mpLbm->advanceCell( cid ) ) { - int flag = mpLbm->getCellFlag(cid,0); - int flag2 = mpLbm->getCellFlag(cid,1); - if(flag != flag2) { - diffInits++; - } - for(int j=0; jdeleteCellIterator( &cid ); - - char charNl = '\n'; - debugOutNnl("SimulationObject::initializeLbmSimulation celltype stats: " <0) { - out<<"\t" << flagCount[j] <<" x "<< convertCellFlagType2String( (CellFlagType)(1< 0) { - debMsgStd("SimulationObject::initializeLbmSimulation",DM_MSG,"celltype Warning: Diffinits="<setStart( mGeoStart );? mpParts->setEnd( mGeoEnd );? - mpParts->setStart( mpLbm->getGeoStart() ); - mpParts->setEnd( mpLbm->getGeoEnd() ); - mpParts->setCastShadows( false ); - mpParts->setReceiveShadows( false ); - mpParts->searchMaterial( glob->getMaterials() ); - - // this has to be inited here - before, the values might be unknown - IsoSurface *surf = mpLbm->getSurfaceGeoObj(); - if(surf) { - surf->setName( "final" ); // final surface mesh - // warning - this might cause overwriting effects for multiple sims and geom dump... - surf->setCastShadows( true ); - surf->setReceiveShadows( false ); - surf->searchMaterial( glob->getMaterials() ); - if(mShowSurface) mObjects.push_back( surf ); - } - -#ifdef ELBEEM_PLUGIN - mShowParticles=1; // for e.g. dumping -#endif // ELBEEM_PLUGIN - if((mpLbm->getGenerateParticles()>0.0)||(mpParts->getNumInitialParticles()>0)) { - mShowParticles=1; - mpParts->setDumpParts(true); - } - //debMsgStd("SimulationObject::init",DM_NOTIFY,"Using envvar ELBEEM_DUMPPARTICLE to set mShowParticles, DEBUG!",1); - //} // DEBUG ENABLE!!!!!!!!!! - if(mShowParticles) { - mObjects.push_back(mpParts); - } - - // add objects to display for debugging (e.g. levelset particles) - vector debugObjs = mpLbm->getDebugObjects(); - for(size_t i=0;isetCastShadows( false ); - debugObjs[i]->setReceiveShadows( false ); - debugObjs[i]->searchMaterial( glob->getMaterials() ); - mObjects.push_back( debugObjs[i] ); - debMsgStd("SimulationObject::init",DM_NOTIFY,"Added debug obj "<getName(), 10 ); - } - return 0; -} - -/*! set current frame */ -void SimulationObject::setFrameNum(int num) { - // advance parametrizer - mpParam->setFrameNum(num); -} - -/****************************************************************************** - * simluation interface: advance simulation another step (whatever delta time that might be) - *****************************************************************************/ -void SimulationObject::step( void ) -{ - if(mpParam->getCurrentAniFrameTime()>0.0) { - // dont advance for stopped time - mpLbm->step(); - mTime += mpParam->getTimestep(); - //if(mTime>0.001) { errMsg("DEBUG!!!!!!!!","quit mlsu..."); xit(1); } // PROFILE DEBUG TEST! - } - if(mpLbm->getPanic()) mPanic = true; - - checkCallerStatus(FLUIDSIM_CBSTATUS_STEP, 0); - //if((mpElbeemSettings)&&(mpElbeemSettings->runsimCallback)) { - //int ret = (mpElbeemSettings->runsimCallback)(mpElbeemSettings->runsimUserData, FLUIDSIM_CBSTATUS_STEP, 0); - //errMsg("runSimulationCallback cbtest1"," "<getName()<<" ret="<prepareVisualization(); -} - - -/******************************************************************************/ -/* get current start simulation time */ -double SimulationObject::getStartTime( void ) { - //return mpParam->calculateAniStart(); - return mpParam->getAniStart(); -} -/* get time for a single animation frame */ -double SimulationObject::getFrameTime( int frame ) { - return mpParam->getAniFrameTime(frame); -} -/* get time for a single time step */ -double SimulationObject::getTimestep( void ) { - return mpParam->getTimestep(); -} - - -/****************************************************************************** - * return a pointer to the geometry object of this simulation - *****************************************************************************/ -//ntlGeometryObject *SimulationObject::getGeometry() { return mpMC; } -vector::iterator -SimulationObject::getObjectsBegin() -{ - return mObjects.begin(); -} -vector::iterator -SimulationObject::getObjectsEnd() -{ - return mObjects.end(); -} - - - - - -/****************************************************************************** - * GUI - display debug info - *****************************************************************************/ - -void SimulationObject::drawDebugDisplay() { -#ifndef NOGUI - if(!getVisible()) return; - - //if( mDebugType > (MAX_DEBDISPSET-1) ){ errFatal("SimulationObject::drawDebugDisplay","Invalid debug type!", SIMWORLD_GENERICERROR); return; } - //mDebDispSet[ mDebugType ].on = true; - //errorOut( mDebugType <<"//"<< mDebDispSet[mDebugType].type ); - mpLbm->debugDisplay( mDebugType ); - - //::lbmMarkedCellDisplay<>( mpLbm ); - mpLbm->lbmMarkedCellDisplay(); -#endif -} - -/* GUI - display interactive info */ -void SimulationObject::drawInteractiveDisplay() -{ -#ifndef NOGUI - if(!getVisible()) return; - if(mSelectedCid) { - // in debugDisplayNode if dispset is on is ignored... - mpLbm->debugDisplayNode( FLUIDDISPGrid, mSelectedCid ); - } -#endif -} - - -/*******************************************************************************/ -// GUI - handle mouse movement for selection -/*******************************************************************************/ -void SimulationObject::setMousePos(int x,int y, ntlVec3Gfx org, ntlVec3Gfx dir) -{ - normalize( dir ); - // assume 2D sim is in XY plane... - - double zplane = (mGeoEnd[2]-mGeoStart[2])*0.5; - double zt = (zplane-org[2]) / dir[2]; - ntlVec3Gfx pos( - org[0]+ dir[0] * zt, - org[1]+ dir[1] * zt, 0.0); - - mSelectedCid = mpLbm->getCellAt( pos ); - //errMsg("SMP ", mName<< x<<" "<( mpLbm, mSelectedCid, mpLbm->getNodeInfoString() ); - mpLbm->debugPrintNodeInfo( mSelectedCid ); - } -} - -/*! notify object that dump is in progress (e.g. for field dump) */ -void SimulationObject::notifyShaderOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename) { - if(!mpLbm) return; - - mpLbm->notifySolverOfDump(dumptype, frameNr,frameNrStr,outfilename); - checkCallerStatus(FLUIDSIM_CBSTATUS_NEWFRAME, frameNr); -} - -/*! check status (e.g. stop/abort) from calling program, returns !=0 if sth. happened... */ -int SimulationObject::checkCallerStatus(int status, int frame) { - //return 0; // DEBUG - int ret = 0; - if((mpElbeemSettings)&&(mpElbeemSettings->runsimCallback)) { - ret = (mpElbeemSettings->runsimCallback)(mpElbeemSettings->runsimUserData, status,frame); - if(ret!=FLUIDSIM_CBRET_CONTINUE) { - if(ret==FLUIDSIM_CBRET_STOP) { - debMsgStd("SimulationObject::notifySolverOfDump",DM_NOTIFY,"Got stop signal from caller",1); - setElbeemState( SIMWORLD_STOP ); - } - else if(ret==FLUIDSIM_CBRET_ABORT) { - errFatal("SimulationObject::notifySolverOfDump","Got abort signal from caller, aborting...", SIMWORLD_GENERICERROR ); - mPanic = 1; - } - else { - errMsg("SimulationObject::notifySolverOfDump","Invalid callback return value: "<getName()<<" ret="<::iterator getObjectsBegin(); - virtual vector::iterator getObjectsEnd(); - - - /*! simluation interface: advance simulation another step (whatever delta time that might be) */ - virtual void step( void ); - /*! prepare visualization of simulation for e.g. raytracing */ - virtual void prepareVisualization( void ); - - /*! GUI - display debug info */ - virtual void drawDebugDisplay(); - /*! GUI - display interactive info */ - virtual void drawInteractiveDisplay(); - /*! GUI - handle mouse movement for selection */ - virtual void setMousePos(int x,int y, ntlVec3Gfx org, ntlVec3Gfx dir); - virtual void setMouseClick(); - - /*! get current start simulation time */ - double getStartTime( void ); - /*! get time for a single animation frame */ - double getFrameTime( int frame ); - /*! get time for a single time step in the simulation */ - double getTimestep( void ); - - //! access solver - LbmSolverInterface *getSolver(){ return mpLbm; } - - protected: - - /*! current time in the simulation */ - double mTime; - - /*! for display - start and end vectors for geometry */ - ntlVec3Gfx mGeoStart, mGeoEnd; - - /*! geometry init id */ - //? int mGeoInitId; - /*! tree object for geomerty initialization */ - ntlTree *mpGiTree; - /*! object vector for geo init */ - vector *mpGiObjects; - /*! remember globals */ - ntlRenderGlobals *mpGlob; - - /*! simulation panic on/off */ - bool mPanic; - - /*! debug info to display */ - int mDebugType; - - /*! pointer to the lbm solver */ - LbmSolverInterface *mpLbm; - - /*! parametrizer for lbm solver */ - Parametrizer *mpParam; - - /*! particle tracing object */ - ParticleTracer *mpParts; - - /*! show parts of the simulation toggles */ - bool mShowSurface; - bool mShowParticles; - - /*! debug display settings */ - int mDebDispSetting; - - /*! pointer to identifier of selected node */ - CellIdentifierInterface *mSelectedCid; - - /*! storage of API settings */ - elbeemSimulationSettings *mpElbeemSettings; - - public: - - // debug display setting funtions - - /*! set type of info to display */ - inline void setDebugDisplay(int disp) { mDebugType = disp; } - inline int getDebugDisplay() { return mDebugType; } - - /* miscelleanous access functions */ - - /*! init parametrizer for anim step length */ - void initParametrizer(Parametrizer *set) { mpParam = set; } - /*! init parametrizer for anim step length */ - Parametrizer *getParametrizer() { return mpParam; } - - /*! check status (e.g. stop/abort) from calling program, returns !=0 if sth. happened... */ - // parameters same as elbeem runsimCallback - int checkCallerStatus(int status, int frame); - - /*! get bounding box of fluid for GUI */ - virtual inline ntlVec3Gfx *getBBStart() { return &mGeoStart; } - virtual inline ntlVec3Gfx *getBBEnd() { return &mGeoEnd; } - - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:SimulationObject") -#endif -}; - - -#endif - - - diff --git a/intern/elbeem/intern/solver_adap.cpp b/intern/elbeem/intern/solver_adap.cpp deleted file mode 100644 index 9e5619ca4a5..00000000000 --- a/intern/elbeem/intern/solver_adap.cpp +++ /dev/null @@ -1,1281 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Adaptivity functions - * - *****************************************************************************/ - -#include "solver_class.h" -#include "solver_relax.h" -#include "particletracer.h" - -#include - -using std::isfinite; - -/*****************************************************************************/ -//! coarse step functions -/*****************************************************************************/ - - - -void LbmFsgrSolver::coarseCalculateFluxareas(int lev) -{ - FSGR_FORIJK_BOUNDS(lev) { - if( RFLAG(lev, i,j,k,mLevel[lev].setCurr) & CFFluid) { - if( RFLAG(lev+1, i*2,j*2,k*2,mLevel[lev+1].setCurr) & CFGrFromCoarse) { - LbmFloat totArea = mFsgrCellArea[0]; // for l=0 - for(int l=1; lcDirNum; l++) { - int ni=(2*i)+this->dfVecX[l], nj=(2*j)+this->dfVecY[l], nk=(2*k)+this->dfVecZ[l]; - if(RFLAG(lev+1, ni,nj,nk, mLevel[lev+1].setCurr)& - (CFGrFromCoarse|CFUnused|CFEmpty) //? (CFBnd|CFEmpty|CFGrFromCoarse|CFUnused) - ) { - totArea += mFsgrCellArea[l]; - } - } // l - QCELL(lev, i,j,k,mLevel[lev].setCurr, dFlux) = totArea; - //continue; - } else - if( RFLAG(lev+1, i*2,j*2,k*2,mLevel[lev+1].setCurr) & (CFEmpty|CFUnused)) { - QCELL(lev, i,j,k,mLevel[lev].setCurr, dFlux) = 1.0; - //continue; - } else { - QCELL(lev, i,j,k,mLevel[lev].setCurr, dFlux) = 0.0; - } - //errMsg("DFINI"," at l"<mSilent){ debMsgStd("coarseCalculateFluxareas",DM_MSG,"level "<getName().c_str(),"Debug")){ errMsg("DEBUG","DEBUG!!!!!!!!!!!!!!!!!!!!!!!"); } - - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) { - for(int j=1;j remove - if( ((*pFlagSrc) & (CFGrFromCoarse)) ) { - bool invNb = false; - FORDF1 { if(RFLAG_NB(lev, i, j, k, SRCS(lev), l) & CFUnused) { invNb = true; } } - if(!invNb) { - // WARNING - this modifies source flag array... - *pFlagSrc = CFFluid|CFGrNorm; -#if ELBEEM_PLUGIN!=1 - errMsg("coarseAdvance","FC2NRM_CHECK Converted CFGrFromCoarse to Norm at "<mStepCnt & (1<<(mMaxRefine-lev)) ) ==1) { - FORDF0 { RAC(tcel,l) = RAC(ccel,l); } - } else { - interpolateCellFromCoarse( lev, i,j,k, TSET(lev), 0.0, CFFluid|CFGrFromCoarse, false); - this->mNumUsedCells++; - } - continue; // interpolateFineFromCoarse test! - } // interpolateFineFromCoarse test! old INTCFCOARSETEST==1 - - if( ((*pFlagSrc) & (CFFluid)) ) { - ccel = RACPNT(lev, i,j,k ,SRCS(lev)); - tcel = RACPNT(lev, i,j,k ,TSET(lev)); - - if( ((*pFlagSrc) & (CFGrFromFine)) ) { - FORDF0 { RAC(tcel,l) = RAC(ccel,l); } // always copy...? - continue; // comes from fine grid - } - // also ignore CFGrFromCoarse - else if( ((*pFlagSrc) & (CFGrFromCoarse)) ) { - FORDF0 { RAC(tcel,l) = RAC(ccel,l); } // always copy...? - continue; - } - - OPTIMIZED_STREAMCOLLIDE; - *pFlagDst |= CFNoBndFluid; // test? - calcCurrentVolume += RAC(ccel,dFlux); - calcCurrentMass += RAC(ccel,dFlux)*rho; - //ebugMarkCell(lev+1, 2*i+1,2*j+1,2*k ); -#if FSGR_STRICT_DEBUG==1 - if(rho<-1.0){ debugMarkCell(lev, i,j,k ); - errMsg("INVRHOCELL_CHECK"," l"<mNumUsedCells++; - - } - } - pFlagSrc+=2; // after x - pFlagDst+=2; // after x - ccel += (QCELLSTEP*2); - tcel += (QCELLSTEP*2); - } - pFlagSrc+= mLevel[lev].lSizex*2; // after y - pFlagDst+= mLevel[lev].lSizex*2; // after y - ccel += (QCELLSTEP*mLevel[lev].lSizex*2); - tcel += (QCELLSTEP*mLevel[lev].lSizex*2); - } // all cell loop k,j,i - - - //errMsg("coarseAdvance","level "<mSilent){ errMsg("coarseAdvance","level "<mNumUsedCells++; - } // from fine & fluid - else { - if(RFLAG(lev+1, 2*i,2*j,2*k,srcSet) & CFGrFromCoarse) { - RFLAG(lev, i,j,k,dstSet) |= CFGrToFine; - } else { - RFLAG(lev, i,j,k,dstSet) &= (~CFGrToFine); - } - } - } // & fluid - }}} - if(!this->mSilent){ errMsg("coarseRestrictFromFine"," from l"<<(lev+1)<<",s"<mMaxRefine)) return false; - bool change = false; - { // refinement, PASS 1-3 - - //bool nbsok; - // FIXME remove TIMEINTORDER ? - LbmFloat interTime = 0.0; - // update curr from other, as streaming afterwards works on curr - // thus read only from srcSet, modify other - const int srcSet = mLevel[lev].setOther; - const int dstSet = mLevel[lev].setCurr; - const int srcFineSet = mLevel[lev+1].setCurr; - const bool debugRefinement = false; - - // use //template functions for 2D/3D - /*if(strstr(this->getName().c_str(),"Debug")) - if(lev+1==mMaxRefine) { // mixborder - for(int l=0;((lcDirNum) && (!removeFromFine)); l++) { // FARBORD - int ni=2*i+2*this->dfVecX[l], nj=2*j+2*this->dfVecY[l], nk=2*k+2*this->dfVecZ[l]; - if(RFLAG(lev+1, ni,nj,nk, srcFineSet)&CFBnd) { // NEWREFT - removeFromFine=true; - } - } - } // FARBORD */ - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) { - for(int j=1;jcDirNum; l++) { - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - //errMsg("performRefinement","On lev:"< remove - - if(RFLAG(lev, i,j,k, srcSet) & CFGrFromCoarse) { - - // from coarse cells without unused nbs are not necessary...! -> remove - bool invNb = false; - bool fluidNb = false; - for(int l=1; lcDirNum; l++) { - if(RFLAG_NB(lev, i, j, k, srcSet, l) & CFUnused) { invNb = true; } - if(RFLAG_NB(lev, i, j, k, srcSet, l) & (CFGrNorm)) { fluidNb = true; } - } - if(!invNb) { - // no unused cells around -> calculate normally from now on - RFLAG(lev, i,j,k, dstSet) = CFFluid|CFGrNorm; - if((LBMDIM==2)&&(debugRefinement)) debugMarkCell(lev, i, j, k); - change=true; - mNumFsgrChanges++; - } // from advance - if(!fluidNb) { - // no fluid cells near -> no transfer necessary - RFLAG(lev, i,j,k, dstSet) = CFUnused; - //RFLAG(lev, i,j,k, mLevel[lev].setOther) = CFUnused; // FLAGTEST - if((LBMDIM==2)&&(debugRefinement)) debugMarkCell(lev, i, j, k); - change=true; - mNumFsgrChanges++; - } // from advance - - - // dont allow double transfer - // this might require fixing the neighborhood - if(RFLAG(lev+1, 2*i,2*j,2*k, srcFineSet)&(CFGrFromCoarse)) { - // dont turn CFGrFromFine above interface cells into CFGrNorm - //errMsg("performRefinement","Removing CFGrFromCoarse on lev"<0) RFLAG(lev-1, i/2,j/2,k/2, mLevel[lev-1].setCurr) &= (~CFGrToFine); // TODO add more of these? - if((LBMDIM==2)&&(debugRefinement)) debugMarkCell(lev, i, j, k); - change=true; - mNumFsgrChanges++; - for(int l=1; lcDirNum; l++) { - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if(RFLAG(lev, ni,nj,nk, srcSet)&(CFGrNorm)) { //ok - for(int m=1; mcDirNum; m++) { - int mi= ni +this->dfVecX[m], mj= nj +this->dfVecY[m], mk= nk +this->dfVecZ[m]; - if(RFLAG(lev, mi, mj, mk, srcSet)&CFUnused) { - // norm cells in neighborhood with unused nbs have to be new border... - RFLAG(lev, ni,nj,nk, dstSet) = CFFluid|CFGrFromCoarse; - if((LBMDIM==2)&&(debugRefinement)) debugMarkCell(lev,ni,nj,nk); - } - } - // these alreay have valid values... - } - else if(RFLAG(lev, ni,nj,nk, srcSet)&(CFUnused)) { //ok - // this should work because we have a valid neighborhood here for now - interpolateCellFromCoarse(lev, ni, nj, nk, dstSet, interTime, CFFluid|CFGrFromCoarse, false); - if((LBMDIM==2)&&(debugRefinement)) debugMarkCell(lev,ni,nj,nk); - mNumFsgrChanges++; - } - } // l - } // double transer - - } // from coarse - - } } } - // PASS 2 */ - - - // fix dstSet from fine cells here - // warning - checks CFGrFromFine on dstset changed before! - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) { // TEST - for(int j=1;jcDirNum; l++) { - int bi=(2*i)+this->dfVecX[l], bj=(2*j)+this->dfVecY[l], bk=(2*k)+this->dfVecZ[l]; - if(RFLAG(lev+1, bi, bj, bk, srcFineSet)&(CFGrFromCoarse)) { - //errMsg("performRefinement","Removing CFGrFromCoarse on lev"<<(lev+1)<<" "<cDirNum; l++) { - int bi=(2*i)+this->dfVecX[l], bj=(2*j)+this->dfVecY[l], bk=(2*k)+this->dfVecZ[l]; - if( (RFLAG(lev+1, bi, bj, bk, srcFineSet)&CFFluid ) && - (!(RFLAG(lev+1, bi, bj, bk, srcFineSet)&CFGrFromCoarse)) ) { - // all unused nbs now of coarse have to be from coarse - for(int m=1; mcDirNum; m++) { - int mi= bi +this->dfVecX[m], mj= bj +this->dfVecY[m], mk= bk +this->dfVecZ[m]; - if(RFLAG(lev+1, mi, mj, mk, srcFineSet)&CFUnused) { - //errMsg("performRefinement","Changing CFUnused on lev"<<(lev+1)<<" "<mSilent){ errMsg("performRefinement"," for l"<mInitDone) { - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) { - for(int j=1;j from fine conversion - bool changeToFromFine = false; - const CellFlagType notAllowed = (CFInter|CFGrFromFine|CFGrToFine); - CellFlagType reqType = CFGrNorm; - if(lev+1==mMaxRefine) reqType = CFNoBndFluid; - if( (RFLAG(lev+1, (2*i),(2*j),(2*k), dstFineSet) & reqType) && - (!(RFLAG(lev+1, (2*i),(2*j),(2*k), dstFineSet) & (notAllowed)) ) ){ - changeToFromFine=true; } - if(changeToFromFine) { - change = true; - mNumFsgrChanges++; - RFLAG(lev, i,j,k, srcSet) = CFFluid|CFGrFromFine; - if((LBMDIM==2)&&(debugCoarsening)) debugMarkCell(lev,i,j,k); - // same as restr from fine func! not necessary ?! - // coarseRestrictFromFine part - coarseRestrictCell(lev, i,j,k,srcSet, dstFineSet); - } - } // only check empty cells - }}} // TEST! - } // PASS 5 */ - - // use //template functions for 2D/3D - /*if(strstr(this->getName().c_str(),"Debug")) - if((nbsok)&&(lev+1==mMaxRefine)) { // mixborder - for(int l=0;((lcDirNum) && (nbsok)); l++) { // FARBORD - int ni=2*i+2*this->dfVecX[l], nj=2*j+2*this->dfVecY[l], nk=2*k+2*this->dfVecZ[l]; - if(RFLAG(lev+1, ni,nj,nk, dstFineSet)&CFBnd) { // NEWREFT - nbsok=false; - } - } - } // FARBORD */ - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) { - for(int j=1;j remove - // perform check from coarseAdvance here? - if(RFLAG(lev, i,j,k, srcSet) & CFGrFromFine) { - // remove from fine cells now that are completely in fluid - // FIXME? check that new from fine in performRefinement never get deleted here afterwards? - // or more general, one cell never changed more than once? - const CellFlagType notAllowed = (CFInter|CFGrFromFine|CFGrToFine); - //const CellFlagType notNbAllowed = (CFInter|CFBnd|CFGrFromFine); unused - CellFlagType reqType = CFGrNorm; - if(lev+1==mMaxRefine) reqType = CFNoBndFluid; - - nbsok = true; - for(int l=0; lcDirNum && nbsok; l++) { - int ni=(2*i)+this->dfVecX[l], nj=(2*j)+this->dfVecY[l], nk=(2*k)+this->dfVecZ[l]; - if( (RFLAG(lev+1, ni,nj,nk, dstFineSet) & reqType) && - (!(RFLAG(lev+1, ni,nj,nk, dstFineSet) & (notAllowed)) ) ){ - // ok - } else { - nbsok=false; - } - // FARBORD - } - // dont turn CFGrFromFine above interface cells into CFGrNorm - // now check nbs on same level - for(int l=1; lcDirNum && nbsok; l++) { - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if(RFLAG(lev, ni,nj,nk, srcSet)&(CFFluid)) { //ok - } else { - nbsok = false; - } - } // l - - if(nbsok) { - // conversion to coarse fluid cell - change = true; - mNumFsgrChanges++; - RFLAG(lev, i,j,k, srcSet) = CFFluid|CFGrNorm; - // dfs are already ok... - //if(this->mInitDone) errMsg("performCoarsening","CFGrFromFine changed to CFGrNorm at lev"<mInitDone) errMsg("performCoarsening","CFGrFromFine subcube init center unused set l"<cDirNum; l++) { - int dstni=dstx+this->dfVecX[l], dstnj=dsty+this->dfVecY[l], dstnk=dstz+this->dfVecZ[l]; - if(RFLAG(dstlev, dstni,dstnj,dstnk, dstFineSet)&(CFFluid)) { - RFLAG(dstlev, dstni,dstnj,dstnk, dstFineSet) = CFFluid|CFGrFromCoarse; - } - if(RFLAG(dstlev, dstni,dstnj,dstnk, dstFineSet)&(CFInter)) { - //if(this->mInitDone) errMsg("performCoarsening","CFGrFromFine subcube init CHECK Warning - deleting interface cell..."); - this->mFixMass += QCELL( dstlev, dstni,dstnj,dstnk, dstFineSet, dMass); - RFLAG(dstlev, dstni,dstnj,dstnk, dstFineSet) = CFFluid|CFGrFromCoarse; - } - } // l - - // again check nb flags of all surrounding cells to see if any from coarse - // can be convted to unused - for(int l=1; lcDirNum; l++) { - int dstni=dstx+this->dfVecX[l], dstnj=dsty+this->dfVecY[l], dstnk=dstz+this->dfVecZ[l]; - // have to be at least from coarse here... - //errMsg("performCoarsening","CFGrFromFine subcube init unused check l"<cDirNum; m++) { - int chkni=dstni+this->dfVecX[m], chknj=dstnj+this->dfVecY[m], chknk=dstnk+this->dfVecZ[m]; - if(RFLAG(dstlev, chkni,chknj,chknk, dstFineSet)&(CFUnused|CFGrFromCoarse)) { - // this nb cell is ok for deletion - } else { - delok=false; // keep it! - } - //errMsg("performCoarsening"," CHECK "<mInitDone) errMsg("performCoarsening","CFGrFromFine subcube init, dir:"<cDirNum; l++) { - int ni=(2*i)+this->dfVecX[l], nj=(2*j)+this->dfVecY[l], nk=(2*k)+this->dfVecZ[l]; - if(RFLAG(lev+1, ni,nj,nk, dstFineSet)& - (CFGrFromCoarse|CFUnused|CFEmpty) //? (CFBnd|CFEmpty|CFGrFromCoarse|CFUnused) - //(CFUnused|CFEmpty) //? (CFBnd|CFEmpty|CFGrFromCoarse|CFUnused) - ) { - //LbmFloat area = 0.25; if(this->dfVecX[l]!=0) area *= 0.5; if(this->dfVecY[l]!=0) area *= 0.5; if(this->dfVecZ[l]!=0) area *= 0.5; - totArea += mFsgrCellArea[l]; - } - } // l - QCELL(lev, i,j,k,mLevel[lev].setOther, dFlux) = - QCELL(lev, i,j,k,srcSet, dFlux) = totArea; - } else { - QCELL(lev, i,j,k,mLevel[lev].setOther, dFlux) = - QCELL(lev, i,j,k,srcSet, dFlux) = 1.0; - } - //errMsg("DFINI"," at l"<getName().c_str(),"Debug")) - if((changeToFromFine)&&(lev+1==mMaxRefine)) { // mixborder - for(int l=0;((lcDirNum) && (changeToFromFine)); l++) { // FARBORD - int ni=2*i+2*this->dfVecX[l], nj=2*j+2*this->dfVecY[l], nk=2*k+2*this->dfVecZ[l]; - if(RFLAG(lev+1, ni,nj,nk, dstFineSet)&CFBnd) { // NEWREFT - changeToFromFine=false; } - } - }// FARBORD */ - //if(!this->mInitDone) { - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) { - for(int j=1;j from fine conversion - bool changeToFromFine = false; - const CellFlagType notAllowed = (CFInter|CFGrFromFine|CFGrToFine); - CellFlagType reqType = CFGrNorm; - if(lev+1==mMaxRefine) reqType = CFNoBndFluid; - - if( (RFLAG(lev+1, (2*i),(2*j),(2*k), dstFineSet) & reqType) && - (!(RFLAG(lev+1, (2*i),(2*j),(2*k), dstFineSet) & (notAllowed)) ) ){ - // DEBUG - changeToFromFine=true; - } - - // FARBORD - - if(changeToFromFine) { - change = true; - mNumFsgrChanges++; - RFLAG(lev, i,j,k, srcSet) = CFFluid|CFGrFromFine; - if((LBMDIM==2)&&(debugCoarsening)) debugMarkCell(lev,i,j,k); - // same as restr from fine func! not necessary ?! - // coarseRestrictFromFine part - } - } // only check empty cells - - }}} // TEST! - //} // init done - // PASS 5 */ - } // coarsening, PASS 4,5 - - if(!this->mSilent){ errMsg("adaptGrid"," for l"<cDirNum); n++) { - int ni=2*i+1*this->dfVecX[n], nj=2*j+1*this->dfVecY[n], nk=2*k+1*this->dfVecZ[n]; - ccel = RACPNT(lev+1, ni,nj,nk,srcSet);// CFINTTEST - const LbmFloat weight = mGaussw[n]; - FORDF0{ - LbmFloat cdf = weight * RAC(ccel,l); -# if FSGR_STRICT_DEBUG==1 - if( cdf<-1.0 ){ errMsg("INVDFCREST_DFCHECK", PRINT_IJK<<" s"<dfDvecX[l]*cdf); - uy += (this->dfDvecY[l]*cdf); - uz += (this->dfDvecZ[l]*cdf); - } - - FORDF0{ feq[l] = this->getCollideEq(l, rho,ux,uy,uz); } - if(mLevel[lev ].lcsmago>0.0) { - const LbmFloat Qo = this->getLesNoneqTensorCoeff(df,feq); - omegaDst = this->getLesOmega(mLevel[lev ].omega,mLevel[lev ].lcsmago,Qo); - omegaSrc = this->getLesOmega(mLevel[lev+1].omega,mLevel[lev+1].lcsmago,Qo); - } else { - omegaDst = mLevel[lev+0].omega; /* NEWSMAGOT*/ - omegaSrc = mLevel[lev+1].omega; - } - dfScale = (mLevel[lev ].timestep/mLevel[lev+1].timestep)* (1.0/omegaDst-1.0)/ (1.0/omegaSrc-1.0); // yu - FORDF0{ - RAC(tcel, l) = feq[l]+ (df[l]-feq[l])*dfScale; - } -# else // OPT3D - // similar to OPTIMIZED_STREAMCOLLIDE_UNUSED - - //rho = ux = uy = uz = 0.0; - MSRC_C = CCELG_C(0) ; - MSRC_N = CCELG_N(0) ; - MSRC_S = CCELG_S(0) ; - MSRC_E = CCELG_E(0) ; - MSRC_W = CCELG_W(0) ; - MSRC_T = CCELG_T(0) ; - MSRC_B = CCELG_B(0) ; - MSRC_NE = CCELG_NE(0); - MSRC_NW = CCELG_NW(0); - MSRC_SE = CCELG_SE(0); - MSRC_SW = CCELG_SW(0); - MSRC_NT = CCELG_NT(0); - MSRC_NB = CCELG_NB(0); - MSRC_ST = CCELG_ST(0); - MSRC_SB = CCELG_SB(0); - MSRC_ET = CCELG_ET(0); - MSRC_EB = CCELG_EB(0); - MSRC_WT = CCELG_WT(0); - MSRC_WB = CCELG_WB(0); - for(int n=1;(ncDirNum); n++) { - ccel = RACPNT(lev+1, 2*i+1*this->dfVecX[n], 2*j+1*this->dfVecY[n], 2*k+1*this->dfVecZ[n] ,srcSet); - MSRC_C += CCELG_C(n) ; - MSRC_N += CCELG_N(n) ; - MSRC_S += CCELG_S(n) ; - MSRC_E += CCELG_E(n) ; - MSRC_W += CCELG_W(n) ; - MSRC_T += CCELG_T(n) ; - MSRC_B += CCELG_B(n) ; - MSRC_NE += CCELG_NE(n); - MSRC_NW += CCELG_NW(n); - MSRC_SE += CCELG_SE(n); - MSRC_SW += CCELG_SW(n); - MSRC_NT += CCELG_NT(n); - MSRC_NB += CCELG_NB(n); - MSRC_ST += CCELG_ST(n); - MSRC_SB += CCELG_SB(n); - MSRC_ET += CCELG_ET(n); - MSRC_EB += CCELG_EB(n); - MSRC_WT += CCELG_WT(n); - MSRC_WB += CCELG_WB(n); - } - rho = MSRC_C + MSRC_N + MSRC_S + MSRC_E + MSRC_W + MSRC_T - + MSRC_B + MSRC_NE + MSRC_NW + MSRC_SE + MSRC_SW + MSRC_NT - + MSRC_NB + MSRC_ST + MSRC_SB + MSRC_ET + MSRC_EB + MSRC_WT + MSRC_WB; - ux = MSRC_E - MSRC_W + MSRC_NE - MSRC_NW + MSRC_SE - MSRC_SW - + MSRC_ET + MSRC_EB - MSRC_WT - MSRC_WB; - uy = MSRC_N - MSRC_S + MSRC_NE + MSRC_NW - MSRC_SE - MSRC_SW - + MSRC_NT + MSRC_NB - MSRC_ST - MSRC_SB; - uz = MSRC_T - MSRC_B + MSRC_NT - MSRC_NB + MSRC_ST - MSRC_SB - + MSRC_ET - MSRC_EB + MSRC_WT - MSRC_WB; - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - \ - lcsmeq[dC] = EQC ; \ - COLL_CALCULATE_DFEQ(lcsmeq); \ - COLL_CALCULATE_NONEQTENSOR(lev+0, MSRC_ )\ - COLL_CALCULATE_CSMOMEGAVAL(lev+0, lcsmDstOmega); \ - COLL_CALCULATE_CSMOMEGAVAL(lev+1, lcsmSrcOmega); \ - \ - lcsmdfscale = (mLevel[lev+0].timestep/mLevel[lev+1].timestep)* (1.0/lcsmDstOmega-1.0)/ (1.0/lcsmSrcOmega-1.0); \ - RAC(tcel, dC ) = (lcsmeq[dC ] + (MSRC_C -lcsmeq[dC ] )*lcsmdfscale); - RAC(tcel, dN ) = (lcsmeq[dN ] + (MSRC_N -lcsmeq[dN ] )*lcsmdfscale); - RAC(tcel, dS ) = (lcsmeq[dS ] + (MSRC_S -lcsmeq[dS ] )*lcsmdfscale); - RAC(tcel, dE ) = (lcsmeq[dE ] + (MSRC_E -lcsmeq[dE ] )*lcsmdfscale); - RAC(tcel, dW ) = (lcsmeq[dW ] + (MSRC_W -lcsmeq[dW ] )*lcsmdfscale); - RAC(tcel, dT ) = (lcsmeq[dT ] + (MSRC_T -lcsmeq[dT ] )*lcsmdfscale); - RAC(tcel, dB ) = (lcsmeq[dB ] + (MSRC_B -lcsmeq[dB ] )*lcsmdfscale); - RAC(tcel, dNE) = (lcsmeq[dNE] + (MSRC_NE-lcsmeq[dNE] )*lcsmdfscale); - RAC(tcel, dNW) = (lcsmeq[dNW] + (MSRC_NW-lcsmeq[dNW] )*lcsmdfscale); - RAC(tcel, dSE) = (lcsmeq[dSE] + (MSRC_SE-lcsmeq[dSE] )*lcsmdfscale); - RAC(tcel, dSW) = (lcsmeq[dSW] + (MSRC_SW-lcsmeq[dSW] )*lcsmdfscale); - RAC(tcel, dNT) = (lcsmeq[dNT] + (MSRC_NT-lcsmeq[dNT] )*lcsmdfscale); - RAC(tcel, dNB) = (lcsmeq[dNB] + (MSRC_NB-lcsmeq[dNB] )*lcsmdfscale); - RAC(tcel, dST) = (lcsmeq[dST] + (MSRC_ST-lcsmeq[dST] )*lcsmdfscale); - RAC(tcel, dSB) = (lcsmeq[dSB] + (MSRC_SB-lcsmeq[dSB] )*lcsmdfscale); - RAC(tcel, dET) = (lcsmeq[dET] + (MSRC_ET-lcsmeq[dET] )*lcsmdfscale); - RAC(tcel, dEB) = (lcsmeq[dEB] + (MSRC_EB-lcsmeq[dEB] )*lcsmdfscale); - RAC(tcel, dWT) = (lcsmeq[dWT] + (MSRC_WT-lcsmeq[dWT] )*lcsmdfscale); - RAC(tcel, dWB) = (lcsmeq[dWB] + (MSRC_WB-lcsmeq[dWB] )*lcsmdfscale); -# endif // OPT3D==0 -} - -void LbmFsgrSolver::interpolateCellFromCoarse(int lev, int i, int j,int k, int dstSet, LbmFloat t, CellFlagType flagSet, bool markNbs) { - LbmFloat rho=0.0, ux=0.0, uy=0.0, uz=0.0; - LbmFloat intDf[19] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - -#if OPT3D==1 - // for macro add - LbmFloat addDfFacT, addVal, usqr; - LbmFloat *addfcel, *dstcell; - LbmFloat lcsmqadd, lcsmqo, lcsmeq[LBM_DFNUM]; - LbmFloat lcsmDstOmega, lcsmSrcOmega, lcsmdfscale; -#endif // OPT3D==true - - // SET required nbs to from coarse (this might overwrite flag several times) - // this is not necessary for interpolateFineFromCoarse - if(markNbs) { - FORDF1{ - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if(RFLAG(lev,ni,nj,nk,dstSet)&CFUnused) { - // parents have to be inited! - interpolateCellFromCoarse(lev, ni, nj, nk, dstSet, t, CFFluid|CFGrFromCoarse, false); - } - } } - - // change flag of cell to be interpolated - RFLAG(lev,i,j,k, dstSet) = flagSet; - mNumInterdCells++; - - // interpolation lines... - int betx = i&1; - int bety = j&1; - int betz = k&1; - - if((!betx) && (!bety) && (!betz)) { - ADD_INT_DFS(lev-1, i/2 ,j/2 ,k/2 , 0.0, 1.0); - } - else if(( betx) && (!bety) && (!betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D1); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2) ,(k/2) , t, WO1D1); - } - else if((!betx) && ( bety) && (!betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D1); - ADD_INT_DFS(lev-1, (i/2) ,(j/2)+1,(k/2) , t, WO1D1); - } - else if((!betx) && (!bety) && ( betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D1); - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2)+1, t, WO1D1); - } - else if(( betx) && ( bety) && (!betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2) ,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2) ,(j/2)+1,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2)+1,(k/2) , t, WO1D2); - } - else if((!betx) && ( bety) && ( betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2)+1, t, WO1D2); - ADD_INT_DFS(lev-1, (i/2) ,(j/2)+1,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2) ,(j/2)+1,(k/2)+1, t, WO1D2); - } - else if(( betx) && (!bety) && ( betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2) ,(k/2) , t, WO1D2); - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2)+1, t, WO1D2); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2) ,(k/2)+1, t, WO1D2); - } - else if(( betx) && ( bety) && ( betz)) { - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2) , t, WO1D3); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2) ,(k/2) , t, WO1D3); - ADD_INT_DFS(lev-1, (i/2) ,(j/2) ,(k/2)+1, t, WO1D3); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2) ,(k/2)+1, t, WO1D3); - ADD_INT_DFS(lev-1, (i/2) ,(j/2)+1,(k/2) , t, WO1D3); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2)+1,(k/2) , t, WO1D3); - ADD_INT_DFS(lev-1, (i/2) ,(j/2)+1,(k/2)+1, t, WO1D3); - ADD_INT_DFS(lev-1, (i/2)+1,(j/2)+1,(k/2)+1, t, WO1D3); - } - else { - CAUSE_PANIC; - errFatal("interpolateCellFromCoarse","Invalid!?", SIMWORLD_GENERICERROR); - } - - IDF_WRITEBACK; - return; -} - - - -#define MPTADAP_INTERV 4 - -/*****************************************************************************/ -/*! change the size of the LBM time step */ -/*****************************************************************************/ -void LbmFsgrSolver::adaptTimestep() { - LbmFloat massTOld=0.0, massTNew=0.0; - LbmFloat volTOld=0.0, volTNew=0.0; - - bool rescale = false; // do any rescale at all? - LbmFloat scaleFac = -1.0; // timestep scaling - if(mPanic) return; - - LbmFloat levOldOmega[FSGR_MAXNOOFLEVELS]; - LbmFloat levOldStepsize[FSGR_MAXNOOFLEVELS]; - for(int lev=mMaxRefine; lev>=0 ; lev--) { - levOldOmega[lev] = mLevel[lev].omega; - levOldStepsize[lev] = mLevel[lev].timestep; - } - - const LbmFloat reduceFac = 0.8; // modify time step by 20%, TODO? do multiple times for large changes? - LbmFloat diffPercent = 0.05; // dont scale if less than 5% - LbmFloat allowMax = mpParam->getTadapMaxSpeed(); // maximum allowed velocity - LbmFloat nextmax = mpParam->getSimulationMaxSpeed() + norm(mLevel[mMaxRefine].gravity); - - // sync nextmax -#if LBM_INCLUDE_TESTSOLVERS==1 - if(glob_mpactive) { - if(mLevel[mMaxRefine].lsteps % MPTADAP_INTERV != MPTADAP_INTERV-1) { - debMsgStd("LbmFsgrSolver::TAdp",DM_MSG, "mpact:"<getTimestep(); // newtr - if(nextmax > allowMax/reduceFac) { - mTimeMaxvelStepCnt++; } - else { mTimeMaxvelStepCnt=0; } - - // emergency, or 10 steps with high vel - if((mTimeMaxvelStepCnt>5) || (nextmax> (1.0/3.0)) || (mForceTimeStepReduce) ) { - newdt = mpParam->getTimestep() * reduceFac; - } else { - if(nextmaxgetTimestep() / reduceFac; - } - } // newtr - //errMsg("LbmFsgrSolver::adaptTimestep","nextmax="<getMaxTimestep()<<" min"<getMinTimestep()<<" diff"<getTimestep() ) // DEBUG - LbmFloat rhoAvg = mCurrentMass/mCurrentVolume; - if( (newdt<=mpParam->getMaxTimestep()) && (newdt>=mpParam->getMinTimestep()) - && (dtdiff>(mpParam->getTimestep()*diffPercent)) ) { - if((newdt>levOldStepsize[mMaxRefine])&&(mTimestepReduceLock)) { - // wait some more... - //debMsgNnl("LbmFsgrSolver::TAdp",DM_NOTIFY," Delayed... "<setDesiredTimestep( newdt ); - rescale = true; - if(!mSilent) { - debMsgStd("LbmFsgrSolver::TAdp",DM_NOTIFY,"\n\n\n\n",10); - debMsgStd("LbmFsgrSolver::TAdp",DM_NOTIFY,"Timestep changing: new="<getSimulationMaxSpeed()<<" next:"<getTimestep(); - mpParam->setDesiredTimestep( newdt ); - } else - if( ((mStepCnt% tadtogInter)== (tadtogInter/4*3)-1) || - ((mStepCnt% tadtogInter)== (tadtogInter/4*4)-1) ){ - rescale = true; minCutoff = false; - newdt = mpParam->getTimestep()/tadtogSwitch ; - mpParam->setDesiredTimestep( newdt ); - } else { - rescale = false; minCutoff = false; - } - // */ - - // test mass rescale - - scaleFac = newdt/mpParam->getTimestep(); - if(rescale) { - // perform acutal rescaling... - mTimeMaxvelStepCnt=0; - mForceTimeStepReduce = false; - - // FIXME - approximate by averaging, take gravity direction here? - //mTimestepReduceLock = 4*(mLevel[mMaxRefine].lSizey+mLevel[mMaxRefine].lSizez+mLevel[mMaxRefine].lSizex)/3; - // use z as gravity direction - mTimestepReduceLock = 4*mLevel[mMaxRefine].lSizez; - - mTimeSwitchCounts++; - mpParam->calculateAllMissingValues( mSimulationTime, mSilent ); - recalculateObjectSpeeds(); - // calc omega, force for all levels - mLastOmega=1e10; mLastGravity=1e10; - initLevelOmegas(); - if(mpParam->getTimestep()getTimestep(); - if(mpParam->getTimestep()>mMaxTimestep) mMaxTimestep = mpParam->getTimestep(); - - // this might be called during init, before we have any particles - if(mpParticles) { mpParticles->adaptPartTimestep(scaleFac); } -#if LBM_INCLUDE_TESTSOLVERS==1 - if((mUseTestdata)&&(mpTest)) { - mpTest->adaptTimestep(scaleFac, mLevel[mMaxRefine].omega, mLevel[mMaxRefine].timestep, vec2L( mpParam->calculateGravity(mSimulationTime)) ); - mpTest->mGrav3d = mLevel[mMaxRefine].gravity; - } -#endif // LBM_INCLUDE_TESTSOLVERS!=1 - - for(int lev=mMaxRefine; lev>=0 ; lev--) { - LbmFloat newSteptime = mLevel[lev].timestep; - LbmFloat dfScaleFac = (newSteptime/1.0)/(levOldStepsize[lev]/levOldOmega[lev]); - - if(!mSilent) { - debMsgStd("LbmFsgrSolver::TAdp",DM_NOTIFY,"Level: "<getCurrentGStar()<<", step:"<=0 ; lev--) { - int rescs=0; - int wss = 0, wse = 1; -#if COMPRESSGRIDS==1 - if(lev== mMaxRefine) wss = wse = mLevel[lev].setCurr; -#endif // COMPRESSGRIDS==1 - for(int workSet = wss; workSet<=wse; workSet++) { // COMPRT - //for(int workSet = 0; workSet<=1; workSet++) { - FSGR_FORIJK1(lev) { - - //if( (RFLAG(lev, i,j,k, workSet) & CFFluid) || (RFLAG(lev, i,j,k, workSet) & CFInter) ) { - if( - (RFLAG(lev,i,j,k, workSet) & CFFluid) || - (RFLAG(lev,i,j,k, workSet) & CFInter) || - (RFLAG(lev,i,j,k, workSet) & CFGrFromCoarse) || - (RFLAG(lev,i,j,k, workSet) & CFGrFromFine) || - (RFLAG(lev,i,j,k, workSet) & CFGrNorm) - ) { - // these cells have to be scaled... - } else { - continue; - } - - // collide on current set - LbmFloat rho, ux,uy,uz; - rho=0.0; ux = uy = uz = 0.0; - for(int l=0; l (allowMax*allowMax) ) { - LbmFloat cfac = allowMax/sqrt(ux*ux+uy*uy+uz*uz); - ux *= cfac; - uy *= cfac; - uz *= cfac; - for(int l=0; l0) { errMsg("adaptTimestep","!!!!! Brute force rescaling was necessary !!!!!!!"); } - debMsgStd("adaptTimestep",DM_MSG,"Brute force rescale done. level:"< - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -#if PARALLEL==1 -#include -#endif // PARALLEL=1 -#ifndef PARALLEL -#define PARALLEL 0 -#endif // PARALLEL - - -// general solver setting defines - -//! debug coordinate accesses and the like? (much slower) -// might be enabled by compilation -#ifndef FSGR_STRICT_DEBUG -#define FSGR_STRICT_DEBUG 0 -#endif // FSGR_STRICT_DEBUG - -//! debug coordinate accesses and the like? (much slower) -#define FSGR_OMEGA_DEBUG 0 - -//! OPT3D quick LES on/off, only debug/benchmarking -#define USE_LES 1 - -//! order of interpolation (0=always current/1=interpolate/2=always other) -//#define TIMEINTORDER 0 -// TODO remove interpol t param, also interTime - -// use optimized 3D code? -#if LBMDIM==2 -#define OPT3D 0 -#else -// determine with debugging... -# if FSGR_STRICT_DEBUG==1 -# define OPT3D 0 -# else // FSGR_STRICT_DEBUG==1 -// usually switch optimizations for 3d on, when not debugging -# define OPT3D 1 -// COMPRT -//# define OPT3D 0 -# endif // FSGR_STRICT_DEBUG==1 -#endif - -//! invalid mass value for unused mass data -#define MASS_INVALID -1000.0 - -// empty/fill cells without fluid/empty NB's by inserting them into the full/empty lists? -#define FSGR_LISTTRICK 1 -#define FSGR_LISTTTHRESHEMPTY 0.10 -#define FSGR_LISTTTHRESHFULL 0.90 -#define FSGR_MAGICNR 0.025 -//0.04 - -//! maxmimum no. of grid levels -#define FSGR_MAXNOOFLEVELS 5 - -// enable/disable fine grid compression for finest level -// make sure this is same as useGridComp in calculateMemreqEstimate -#if LBMDIM==3 -#define COMPRESSGRIDS 1 -#else -#define COMPRESSGRIDS 0 -#endif - -// helper for comparing floats with epsilon -#define GFX_FLOATNEQ(x,y) ( ABS((x)-(y)) > (VECTOR_EPSILON) ) -#define LBM_FLOATNEQ(x,y) ( ABS((x)-(y)) > (10.0*LBM_EPSILON) ) - - -// macros for loops over all DFs -#define FORDF0 for(int l= 0; l< LBM_DFNUM; ++l) -#define FORDF1 for(int l= 1; l< LBM_DFNUM; ++l) -// and with different loop var to prevent shadowing -#define FORDF0M for(int m= 0; m< LBM_DFNUM; ++m) -#define FORDF1M for(int m= 1; m< LBM_DFNUM; ++m) - -// iso value defines -// border for marching cubes -#define ISOCORR 3 - -#define LBM_INLINED inline - -// sirdude fix for solaris -#if !defined(linux) && defined(sun) -#include "ieeefp.h" -#ifndef expf -#define expf(x) exp((double)(x)) -#endif -#endif - -#include "solver_control.h" - -#if LBM_INCLUDE_TESTSOLVERS==1 -#include "solver_test.h" -#endif // LBM_INCLUDE_TESTSOLVERS==1 - -/*****************************************************************************/ -/*! cell access classes */ -class UniformFsgrCellIdentifier : - public CellIdentifierInterface , public LbmCellContents -{ - public: - //! which grid level? - int level; - //! location in grid - int x,y,z; - - //! reset constructor - UniformFsgrCellIdentifier() : - x(0), y(0), z(0) { }; - - // implement CellIdentifierInterface - virtual string getAsString() { - std::ostringstream ret; - ret <<"{ i"<2) ret<<",k"<x && y==cid->y && z==cid->z && level==cid->level ) return true; - return false; - } - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:UniformFsgrCellIdentifier") -#endif -}; - -//! information needed for each level in the simulation -class FsgrLevelData { -public: - int id; // level number - - //! node size on this level (geometric, in world coordinates, not simulation units!) - LbmFloat nodeSize; - //! node size on this level in simulation units - LbmFloat simCellSize; - //! quadtree node relaxation parameter - LbmFloat omega; - //! size this level was advanced to - LbmFloat time; - //! size of a single lbm step in time units on this level - LbmFloat timestep; - //! step count - int lsteps; - //! gravity force for this level - LbmVec gravity; - //! level array - LbmFloat *mprsCells[2]; - CellFlagType *mprsFlags[2]; - - //! smago params and precalculated values - LbmFloat lcsmago; - LbmFloat lcsmago_sqr; - LbmFloat lcnu; - - // LES statistics per level - double avgOmega; - double avgOmegaCnt; - - //! current set of dist funcs - int setCurr; - //! target/other set of dist funcs - int setOther; - - //! mass&volume for this level - LbmFloat lmass; - LbmFloat lvolume; - LbmFloat lcellfactor; - - //! local storage of mSizes - int lSizex, lSizey, lSizez; - int lOffsx, lOffsy, lOffsz; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:FsgrLevelData") -#endif -}; - - - -/*****************************************************************************/ -/*! class for solving a LBM problem */ -class LbmFsgrSolver : - public LbmSolverInterface // this means, the solver is a lbmData object and implements the lbmInterface -{ - - public: - //! Constructor - LbmFsgrSolver(); - //! Destructor - virtual ~LbmFsgrSolver(); - - //! initilize variables fom attribute list - virtual void parseAttrList(); - //! Initialize omegas and forces on all levels (for init/timestep change) - void initLevelOmegas(); - - // multi step solver init - /*! finish the init with config file values (allocate arrays...) */ - virtual bool initializeSolverMemory(); - /*! init solver arrays */ - virtual bool initializeSolverGrids(); - /*! prepare actual simulation start, setup viz etc */ - virtual bool initializeSolverPostinit(); - - //! notify object that dump is in progress (e.g. for field dump) - virtual void notifySolverOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename); - -# if LBM_USE_GUI==1 - //! show simulation info (implement LbmSolverInterface pure virtual func) - virtual void debugDisplay(int set); -# endif - - // implement CellIterator interface - typedef UniformFsgrCellIdentifier stdCellId; - virtual CellIdentifierInterface* getFirstCell( ); - virtual void advanceCell( CellIdentifierInterface* ); - virtual bool noEndCell( CellIdentifierInterface* ); - virtual void deleteCellIterator( CellIdentifierInterface** ); - virtual CellIdentifierInterface* getCellAt( ntlVec3Gfx pos ); - virtual int getCellSet ( CellIdentifierInterface* ); - virtual ntlVec3Gfx getCellOrigin ( CellIdentifierInterface* ); - virtual ntlVec3Gfx getCellSize ( CellIdentifierInterface* ); - virtual int getCellLevel ( CellIdentifierInterface* ); - virtual LbmFloat getCellDensity ( CellIdentifierInterface* ,int set); - virtual LbmVec getCellVelocity ( CellIdentifierInterface* ,int set); - virtual LbmFloat getCellDf ( CellIdentifierInterface* ,int set, int dir); - virtual LbmFloat getCellMass ( CellIdentifierInterface* ,int set); - virtual LbmFloat getCellFill ( CellIdentifierInterface* ,int set); - virtual CellFlagType getCellFlag ( CellIdentifierInterface* ,int set); - virtual LbmFloat getEquilDf ( int ); - virtual ntlVec3Gfx getVelocityAt (float x, float y, float z); - // convert pointers - stdCellId* convertBaseCidToStdCid( CellIdentifierInterface* basecid); - - //! perform geometry init (if switched on) - bool initGeometryFlags(); - //! init part for all freesurface testcases - void initFreeSurfaces(); - //! init density gradient if enabled - void initStandingFluidGradient(); - - /*! init a given cell with flag, density, mass and equilibrium dist. funcs */ - LBM_INLINED void initEmptyCell(int level, int i,int j,int k, CellFlagType flag, LbmFloat rho, LbmFloat mass); - LBM_INLINED void initVelocityCell(int level, int i,int j,int k, CellFlagType flag, LbmFloat rho, LbmFloat mass, LbmVec vel); - LBM_INLINED void changeFlag(int level, int xx,int yy,int zz,int set,CellFlagType newflag); - LBM_INLINED void forceChangeFlag(int level, int xx,int yy,int zz,int set,CellFlagType newflag); - LBM_INLINED void initInterfaceVars(int level, int i,int j,int k,int workSet, bool initMass); - //! interpolate velocity and density at a given position - void interpolateCellValues(int level,int ei,int ej,int ek,int workSet, LbmFloat &retrho, LbmFloat &retux, LbmFloat &retuy, LbmFloat &retuz); - - /*! perform a single LBM step */ - void stepMain(); - //! advance fine grid - void fineAdvance(); - //! advance coarse grid - void coarseAdvance(int lev); - //! update flux area values on coarse grids - void coarseCalculateFluxareas(int lev); - // adaptively coarsen grid - bool adaptGrid(int lev); - // restrict fine grid DFs to coarse grid - void coarseRestrictFromFine(int lev); - - /* simulation object interface, just calls stepMain */ - virtual void step(); - /*! init particle positions */ - virtual int initParticles(); - /*! move all particles */ - virtual void advanceParticles(); - /*! move a particle at a boundary */ - void handleObstacleParticle(ParticleObject *p); - /*! check whether to add particle - bool checkAddParticle(); - void performAddParticle();*/ - - - /*! debug object display (used e.g. for preview surface) */ - virtual vector getDebugObjects(); - - // gui/output debugging functions -# if LBM_USE_GUI==1 - virtual void debugDisplayNode(int dispset, CellIdentifierInterface* cell ); - virtual void lbmDebugDisplay(int dispset); - virtual void lbmMarkedCellDisplay(); -# endif // LBM_USE_GUI==1 - virtual void debugPrintNodeInfo(CellIdentifierInterface* cell, int forceSet=-1); - - //! for raytracing, preprocess - void prepareVisualization( void ); - - /* surface generation settings */ - virtual void setSurfGenSettings(short value); - - protected: - - //! internal quick print function (for debugging) - void printLbmCell(int level, int i, int j, int k,int set); - // debugging use CellIterator interface to mark cell - void debugMarkCellCall(int level, int vi,int vj,int vk); - - // loop over grid, stream&collide update - void mainLoop(const int lev); - // change time step size - void adaptTimestep(); - //! init mObjectSpeeds for current parametrization - void recalculateObjectSpeeds(); - //! init moving obstacles for next sim step sim - void initMovingObstacles(bool staticInit); - //! flag reinit step - always works on finest grid! - void reinitFlags( int workSet ); - //! mass dist weights - LbmFloat getMassdWeight(bool dirForw, int i,int j,int k,int workSet, int l); - //! compute surface normals: fluid, fluid more accurate, and for obstacles - void computeFluidSurfaceNormal(LbmFloat *cell, CellFlagType *cellflag, LbmFloat *snret); - void computeFluidSurfaceNormalAcc(LbmFloat *cell, CellFlagType *cellflag, LbmFloat *snret); - void computeObstacleSurfaceNormal(LbmFloat *cell, CellFlagType *cellflag, LbmFloat *snret); - void computeObstacleSurfaceNormalAcc(int i,int j,int k, LbmFloat *snret); - //! add point to mListNewInter list - LBM_INLINED void addToNewInterList( int ni, int nj, int nk ); - //! cell is interpolated from coarse level (inited into set, source sets are determined by t) - void interpolateCellFromCoarse(int lev, int i, int j,int k, int dstSet, LbmFloat t, CellFlagType flagSet,bool markNbs); - void coarseRestrictCell(int lev, int i,int j,int k, int srcSet, int dstSet); - - //! minimal and maximal z-coords (for 2D/3D loops) - LBM_INLINED int getForZMinBnd(); - LBM_INLINED int getForZMin1(); - LBM_INLINED int getForZMaxBnd(int lev); - LBM_INLINED int getForZMax1(int lev); - LBM_INLINED bool checkDomainBounds(int lev,int i,int j,int k); - LBM_INLINED bool checkDomainBoundsPos(int lev,LbmVec pos); - - // touch grid and flags once - void preinitGrids(); - // one relaxation step for standing fluid - void standingFluidPreinit(); - - - // member vars - - //! mass calculated during streaming step - LbmFloat mCurrentMass; - LbmFloat mCurrentVolume; - LbmFloat mInitialMass; - - //! count problematic cases, that occured so far... - int mNumProblems; - - // average mlsups, count how many so far... - double mAvgMLSUPS; - double mAvgMLSUPSCnt; - - //! Mcubes object for surface reconstruction - IsoSurface *mpPreviewSurface; - - //! use time adaptivity? - bool mTimeAdap; - //! force smaller timestep for next LBM step? (eg for mov obj) - bool mForceTimeStepReduce; - - //! fluid vol height - LbmFloat mFVHeight; - LbmFloat mFVArea; - bool mUpdateFVHeight; - - //! force quit for gfx - LbmFloat mGfxEndTime; - //! smoother surface initialization? - int mInitSurfaceSmoothing; - //! surface generation settings, default is all off (=0) - // each flag switches side on off, fssgNoObs is for obstacle sides - // -1 equals all on - typedef enum { - fssgNormal = 0, - fssgNoNorth = 1, - fssgNoSouth = 2, - fssgNoEast = 4, - fssgNoWest = 8, - fssgNoTop = 16, - fssgNoBottom = 32, - fssgNoObs = 64 - } fsSurfaceGen; - int mFsSurfGenSetting; - - //! lock time step down switching - int mTimestepReduceLock; - //! count no. of switches - int mTimeSwitchCounts; - // only switch of maxvel is higher for several steps... - int mTimeMaxvelStepCnt; - - //! total simulation time so far - LbmFloat mSimulationTime, mLastSimTime; - //! smallest and largest step size so far - LbmFloat mMinTimestep, mMaxTimestep; - //! track max. velocity - LbmFloat mMxvx, mMxvy, mMxvz, mMaxVlen; - - //! list of the cells to empty at the end of the step - vector mListEmpty; - //! list of the cells to make fluid at the end of the step - vector mListFull; - //! list of new interface cells to init - vector mListNewInter; - //! class for handling redist weights in reinit flag function - class lbmFloatSet { - public: - LbmFloat val[dTotalNum]; - LbmFloat numNbs; - }; - //! normalized vectors for all neighboring cell directions (for e.g. massdweight calc) - LbmVec mDvecNrm[27]; - - - //! debugging - bool checkSymmetry(string idstring); - //! kepp track of max/min no. of filled cells - int mMaxNoCells, mMinNoCells; - LONGINT mAvgNumUsedCells; - - //! precalculated objects speeds for current parametrization - vector mObjectSpeeds; - //! partslip bc. values for obstacle boundary conditions - vector mObjectPartslips; - //! moving object mass boundary condition values - vector mObjectMassMovnd; - - //! permanent movobj vert storage - vector mMOIVertices; - vector mMOIVerticesOld; - vector mMOINormals; - - //! get isofield weights - int mIsoWeightMethod; - float mIsoWeight[27]; - - // grid coarsening vars - - /*! vector for the data for each level */ - FsgrLevelData mLevel[FSGR_MAXNOOFLEVELS]; - - /*! minimal and maximal refinement levels */ - int mMaxRefine; - - /*! df scale factors for level up/down */ - LbmFloat mDfScaleUp, mDfScaleDown; - - /*! precomputed cell area values */ - LbmFloat mFsgrCellArea[27]; - /*! restriction interpolation weights */ - LbmFloat mGaussw[27]; - - /*! LES C_smago paramter for finest grid */ - float mInitialCsmago; - /*! LES stats for non OPT3D */ - LbmFloat mDebugOmegaRet; - /*! remember last init for animated params */ - LbmFloat mLastOmega; - LbmVec mLastGravity; - - //! fluid stats - int mNumInterdCells; - int mNumInvIfCells; - int mNumInvIfTotal; - int mNumFsgrChanges; - - //! debug function to disable standing f init - int mDisableStandingFluidInit; - //! init 2d with skipped Y/Z coords - bool mInit2dYZ; - //! debug function to force tadap syncing - int mForceTadapRefine; - //! border cutoff value - int mCutoff; - - // strict debug interface -# if FSGR_STRICT_DEBUG==1 - int debLBMGI(int level, int ii,int ij,int ik, int is); - CellFlagType& debRFLAG(int level, int xx,int yy,int zz,int set); - CellFlagType& debRFLAG_NB(int level, int xx,int yy,int zz,int set, int dir); - CellFlagType& debRFLAG_NBINV(int level, int xx,int yy,int zz,int set, int dir); - int debLBMQI(int level, int ii,int ij,int ik, int is, int l); - LbmFloat& debQCELL(int level, int xx,int yy,int zz,int set,int l); - LbmFloat& debQCELL_NB(int level, int xx,int yy,int zz,int set, int dir,int l); - LbmFloat& debQCELL_NBINV(int level, int xx,int yy,int zz,int set, int dir,int l); - LbmFloat* debRACPNT(int level, int ii,int ij,int ik, int is ); - LbmFloat& debRAC(LbmFloat* s,int l); -# endif // FSGR_STRICT_DEBUG==1 - - LbmControlData *mpControl; - - void initCpdata(); - void handleCpdata(); - void cpDebugDisplay(int dispset); - - bool mUseTestdata; -# if LBM_INCLUDE_TESTSOLVERS==1 - // test functions - LbmTestdata *mpTest; - void initTestdata(); - void destroyTestdata(); - void handleTestdata(); - void set3dHeight(int ,int ); - - int mMpNum,mMpIndex; - int mOrgSizeX; - LbmFloat mOrgStartX; - LbmFloat mOrgEndX; - void mrSetup(); - void mrExchange(); - void mrIsoExchange(); - LbmFloat mrInitTadap(LbmFloat max); - void gcFillBuffer( LbmGridConnector *gc, int *retSizeCnt, const int *bdfs); - void gcUnpackBuffer(LbmGridConnector *gc, int *retSizeCnt, const int *bdfs); - public: - // needed for testdata - void find3dHeight(int i,int j, LbmFloat prev, LbmFloat &ret, LbmFloat *retux, LbmFloat *retuy, LbmFloat *retuz); - // mptest - int getMpIndex() { return mMpIndex; }; -# endif // LBM_INCLUDE_TESTSOLVERS==1 - - // former LbmModelLBGK functions - // relaxation funtions - implemented together with relax macros - static inline LbmFloat getVelVecLen(int l, LbmFloat ux,LbmFloat uy,LbmFloat uz); - static inline LbmFloat getCollideEq(int l, LbmFloat rho, LbmFloat ux, LbmFloat uy, LbmFloat uz); - inline LbmFloat getLesNoneqTensorCoeff( LbmFloat df[], LbmFloat feq[] ); - inline LbmFloat getLesOmega(LbmFloat omega, LbmFloat csmago, LbmFloat Qo); - inline void collideArrays( int lev, int i, int j, int k, // position - more for debugging - LbmFloat df[], LbmFloat &outrho, // out only! - // velocity modifiers (returns actual velocity!) - LbmFloat &mux, LbmFloat &muy, LbmFloat &muz, - LbmFloat omega, LbmVec gravity, LbmFloat csmago, - LbmFloat *newOmegaRet, LbmFloat *newQoRet); - - - // former LBM models - //! shorten static const definitions -# define STCON static const - -# if LBMDIM==3 - - //! id string of solver - virtual string getIdString() { return string("FreeSurfaceFsgrSolver[BGK_D3Q19]"); } - - //! how many dimensions? UNUSED? replace by LBMDIM? - STCON int cDimension; - - // Wi factors for collide step - STCON LbmFloat cCollenZero; - STCON LbmFloat cCollenOne; - STCON LbmFloat cCollenSqrtTwo; - - //! threshold value for filled/emptied cells - STCON LbmFloat cMagicNr2; - STCON LbmFloat cMagicNr2Neg; - STCON LbmFloat cMagicNr; - STCON LbmFloat cMagicNrNeg; - - //! size of a single set of distribution functions - STCON int cDfNum; - //! direction vector contain vecs for all spatial dirs, even if not used for LBM model - STCON int cDirNum; - - //! distribution functions directions - typedef enum { - cDirInv= -1, - cDirC = 0, - cDirN = 1, - cDirS = 2, - cDirE = 3, - cDirW = 4, - cDirT = 5, - cDirB = 6, - cDirNE = 7, - cDirNW = 8, - cDirSE = 9, - cDirSW = 10, - cDirNT = 11, - cDirNB = 12, - cDirST = 13, - cDirSB = 14, - cDirET = 15, - cDirEB = 16, - cDirWT = 17, - cDirWB = 18 - } dfDir; - - /* Vector Order 3D: - * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 - * 0, 0, 0, 1,-1, 0, 0, 1,-1, 1,-1, 0, 0, 0, 0, 1, 1,-1,-1, 1,-1, 1,-1, 1,-1, 1,-1 - * 0, 1,-1, 0, 0, 0, 0, 1, 1,-1,-1, 1, 1,-1,-1, 0, 0, 0, 0, 1, 1,-1,-1, 1, 1,-1,-1 - * 0, 0, 0, 0, 0, 1,-1, 0, 0, 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1, 1, 1, 1, -1,-1,-1,-1 - */ - - /*! name of the dist. function - only for nicer output */ - STCON char* dfString[ 19 ]; - - /*! index of normal dist func, not used so far?... */ - STCON int dfNorm[ 19 ]; - - /*! index of inverse dist func, not fast, but useful... */ - STCON int dfInv[ 19 ]; - - /*! index of x reflected dist func for free slip, not valid for all DFs... */ - STCON int dfRefX[ 19 ]; - /*! index of x reflected dist func for free slip, not valid for all DFs... */ - STCON int dfRefY[ 19 ]; - /*! index of x reflected dist func for free slip, not valid for all DFs... */ - STCON int dfRefZ[ 19 ]; - - /*! dist func vectors */ - STCON int dfVecX[ 27 ]; - STCON int dfVecY[ 27 ]; - STCON int dfVecZ[ 27 ]; - - /*! arrays as before with doubles */ - STCON LbmFloat dfDvecX[ 27 ]; - STCON LbmFloat dfDvecY[ 27 ]; - STCON LbmFloat dfDvecZ[ 27 ]; - - /*! principal directions */ - STCON int princDirX[ 2*3 ]; - STCON int princDirY[ 2*3 ]; - STCON int princDirZ[ 2*3 ]; - - /*! vector lengths */ - STCON LbmFloat dfLength[ 19 ]; - - /*! equilibrium distribution functions, precalculated = getCollideEq(i, 0,0,0,0) */ - static LbmFloat dfEquil[ dTotalNum ]; - - /*! arrays for les model coefficients */ - static LbmFloat lesCoeffDiag[ (3-1)*(3-1) ][ 27 ]; - static LbmFloat lesCoeffOffdiag[ 3 ][ 27 ]; - -# else // end LBMDIM==3 , LBMDIM==2 - - //! id string of solver - virtual string getIdString() { return string("FreeSurfaceFsgrSolver[BGK_D2Q9]"); } - - //! how many dimensions? - STCON int cDimension; - - //! Wi factors for collide step - STCON LbmFloat cCollenZero; - STCON LbmFloat cCollenOne; - STCON LbmFloat cCollenSqrtTwo; - - //! threshold value for filled/emptied cells - STCON LbmFloat cMagicNr2; - STCON LbmFloat cMagicNr2Neg; - STCON LbmFloat cMagicNr; - STCON LbmFloat cMagicNrNeg; - - //! size of a single set of distribution functions - STCON int cDfNum; - STCON int cDirNum; - - //! distribution functions directions - typedef enum { - cDirInv= -1, - cDirC = 0, - cDirN = 1, - cDirS = 2, - cDirE = 3, - cDirW = 4, - cDirNE = 5, - cDirNW = 6, - cDirSE = 7, - cDirSW = 8 - } dfDir; - - /* Vector Order 2D: - * 0 1 2 3 4 5 6 7 8 - * 0, 0,0, 1,-1, 1,-1,1,-1 - * 0, 1,-1, 0,0, 1,1,-1,-1 */ - - /* name of the dist. function - only for nicer output */ - STCON char* dfString[ 9 ]; - - /* index of normal dist func, not used so far?... */ - STCON int dfNorm[ 9 ]; - - /* index of inverse dist func, not fast, but useful... */ - STCON int dfInv[ 9 ]; - - /* index of x reflected dist func for free slip, not valid for all DFs... */ - STCON int dfRefX[ 9 ]; - /* index of x reflected dist func for free slip, not valid for all DFs... */ - STCON int dfRefY[ 9 ]; - /* index of x reflected dist func for free slip, not valid for all DFs... */ - STCON int dfRefZ[ 9 ]; - - /* dist func vectors */ - STCON int dfVecX[ 9 ]; - STCON int dfVecY[ 9 ]; - /* Z, 2D values are all 0! */ - STCON int dfVecZ[ 9 ]; - - /* arrays as before with doubles */ - STCON LbmFloat dfDvecX[ 9 ]; - STCON LbmFloat dfDvecY[ 9 ]; - /* Z, 2D values are all 0! */ - STCON LbmFloat dfDvecZ[ 9 ]; - - /*! principal directions */ - STCON int princDirX[ 2*2 ]; - STCON int princDirY[ 2*2 ]; - STCON int princDirZ[ 2*2 ]; - - /* vector lengths */ - STCON LbmFloat dfLength[ 9 ]; - - /* equilibrium distribution functions, precalculated = getCollideEq(i, 0,0,0,0) */ - static LbmFloat dfEquil[ dTotalNum ]; - - /*! arrays for les model coefficients */ - static LbmFloat lesCoeffDiag[ (2-1)*(2-1) ][ 9 ]; - static LbmFloat lesCoeffOffdiag[ 2 ][ 9 ]; - -# endif // LBMDIM==2 - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:LbmFsgrSolver") -#endif -}; - -#undef STCON - - -/*****************************************************************************/ -// relaxation_macros - - - -// cell mark debugging -#if FSGR_STRICT_DEBUG==10 -#define debugMarkCell(lev,x,y,z) \ - errMsg("debugMarkCell",this->mName<<" step: "<mStepCnt<<" lev:"<<(lev)<<" marking "<dfVecX[dir],(yy)+this->dfVecY[dir],(zz)+this->dfVecZ[dir],set) ] -#define _RFLAG_NBINV(level,xx,yy,zz,set, dir) mLevel[level].mprsFlags[set][ (LONGINT)LBMGI((level),(xx)+this->dfVecX[this->dfInv[dir]],(yy)+this->dfVecY[this->dfInv[dir]],(zz)+this->dfVecZ[this->dfInv[dir]],set) ] - -// array handling ----------------------------------------------------------------------------------------------- - -#define _LBMQI(level, ii,ij,ik, is, lunused) ( (LONGINT)((LONGINT)mLevel[level].lOffsy*(LONGINT)(ik)) + (LONGINT)((LONGINT)mLevel[level].lOffsx*(LONGINT)(ij)) + (LONGINT)(ii) ) -#define _QCELL(level,xx,yy,zz,set,l) (mLevel[level].mprsCells[(set)][ (LONGINT)LBMQI((level),(xx),(yy),(zz),(set), l)*(LONGINT)dTotalNum +(LONGINT)(l)]) -#define _QCELL_NB(level,xx,yy,zz,set, dir,l) (mLevel[level].mprsCells[(set)][ (LONGINT)LBMQI((level),(xx)+this->dfVecX[dir],(yy)+this->dfVecY[dir],(zz)+this->dfVecZ[dir],set, l)*dTotalNum +(l)]) -#define _QCELL_NBINV(level,xx,yy,zz,set, dir,l) (mLevel[level].mprsCells[(set)][ (LONGINT)LBMQI((level),(xx)+this->dfVecX[this->dfInv[dir]],(yy)+this->dfVecY[this->dfInv[dir]],(zz)+this->dfVecZ[this->dfInv[dir]],set, l)*dTotalNum +(l)]) - -#define QCELLSTEP dTotalNum -#define _RACPNT(level, ii,ij,ik, is ) &QCELL(level,ii,ij,ik,is,0) -#define _RAC(s,l) (s)[(l)] - - -#if FSGR_STRICT_DEBUG==1 - -#define LBMGI(level,ii,ij,ik, is) debLBMGI(level,ii,ij,ik, is) -#define RFLAG(level,xx,yy,zz,set) debRFLAG(level,xx,yy,zz,set) -#define RFLAG_NB(level,xx,yy,zz,set, dir) debRFLAG_NB(level,xx,yy,zz,set, dir) -#define RFLAG_NBINV(level,xx,yy,zz,set, dir) debRFLAG_NBINV(level,xx,yy,zz,set, dir) - -#define LBMQI(level,ii,ij,ik, is, l) debLBMQI(level,ii,ij,ik, is, l) -#define QCELL(level,xx,yy,zz,set,l) debQCELL(level,xx,yy,zz,set,l) -#define QCELL_NB(level,xx,yy,zz,set, dir,l) debQCELL_NB(level,xx,yy,zz,set, dir,l) -#define QCELL_NBINV(level,xx,yy,zz,set, dir,l) debQCELL_NBINV(level,xx,yy,zz,set, dir,l) -#define RACPNT(level, ii,ij,ik, is ) debRACPNT(level, ii,ij,ik, is ) -#define RAC(s,l) debRAC(s,l) - -#else // FSGR_STRICT_DEBUG==1 - -#define LBMGI(level,ii,ij,ik, is) _LBMGI(level,ii,ij,ik, is) -#define RFLAG(level,xx,yy,zz,set) _RFLAG(level,xx,yy,zz,set) -#define RFLAG_NB(level,xx,yy,zz,set, dir) _RFLAG_NB(level,xx,yy,zz,set, dir) -#define RFLAG_NBINV(level,xx,yy,zz,set, dir) _RFLAG_NBINV(level,xx,yy,zz,set, dir) - -#define LBMQI(level,ii,ij,ik, is, l) _LBMQI(level,ii,ij,ik, is, l) -#define QCELL(level,xx,yy,zz,set,l) _QCELL(level,xx,yy,zz,set,l) -#define QCELL_NB(level,xx,yy,zz,set, dir,l) _QCELL_NB(level,xx,yy,zz,set, dir, l) -#define QCELL_NBINV(level,xx,yy,zz,set, dir,l) _QCELL_NBINV(level,xx,yy,zz,set, dir,l) -#define RACPNT(level, ii,ij,ik, is ) _RACPNT(level, ii,ij,ik, is ) -#define RAC(s,l) _RAC(s,l) - -#endif // FSGR_STRICT_DEBUG==1 - -// general defines ----------------------------------------------------------------------------------------------- - -// replace TESTFLAG -#define FLAGISEXACT(flag, compflag) ((flag & compflag)==compflag) - -#if LBMDIM==2 -#define dC 0 -#define dN 1 -#define dS 2 -#define dE 3 -#define dW 4 -#define dNE 5 -#define dNW 6 -#define dSE 7 -#define dSW 8 -#else -// direction indices -#define dC 0 -#define dN 1 -#define dS 2 -#define dE 3 -#define dW 4 -#define dT 5 -#define dB 6 -#define dNE 7 -#define dNW 8 -#define dSE 9 -#define dSW 10 -#define dNT 11 -#define dNB 12 -#define dST 13 -#define dSB 14 -#define dET 15 -#define dEB 16 -#define dWT 17 -#define dWB 18 -#endif -//? #define dWB 18 - -// default init for dFlux values -#define FLUX_INIT 0.5f * (float)(this->cDfNum) - -// only for non DF dir handling! -#define dNET 19 -#define dNWT 20 -#define dSET 21 -#define dSWT 22 -#define dNEB 23 -#define dNWB 24 -#define dSEB 25 -#define dSWB 26 - -//! fill value for boundary cells -#define BND_FILL 0.0 - -#define DFL1 (1.0/ 3.0) -#define DFL2 (1.0/18.0) -#define DFL3 (1.0/36.0) - -// loops over _all_ cells (including boundary layer) -#define FSGR_FORIJK_BOUNDS(leveli) \ - for(int k= getForZMinBnd(); k< getForZMaxBnd(leveli); ++k) \ - for(int j=0;jLBM_DFNUM)) { errFatal("LbmFsgrSolver::getCollideEq","Invalid DFEQ call "<dfEquil[l] * rho; } - RAC(ecel, dMass) = mass; - RAC(ecel, dFfrac) = mass/rho; - RAC(ecel, dFlux) = FLUX_INIT; - changeFlag(level, i,j,k, workSet, flag); - - workSet ^= 1; - changeFlag(level, i,j,k, workSet, flag); - return; -} - -void -LbmFsgrSolver::initVelocityCell(int level, int i,int j,int k, CellFlagType flag, LbmFloat rho, LbmFloat mass, LbmVec vel) { - LbmFloat *ecel; - int workSet = mLevel[level].setCurr; - - ecel = RACPNT(level, i,j,k, workSet); - FORDF0 { RAC(ecel, l) = getCollideEq(l, rho,vel[0],vel[1],vel[2]); } - RAC(ecel, dMass) = mass; - RAC(ecel, dFfrac) = mass/rho; - RAC(ecel, dFlux) = FLUX_INIT; - changeFlag(level, i,j,k, workSet, flag); - - workSet ^= 1; - changeFlag(level, i,j,k, workSet, flag); - return; -} - -int LbmFsgrSolver::getForZMinBnd() { - return 0; -} -int LbmFsgrSolver::getForZMin1() { - if(LBMDIM==2) return 0; - return 1; -} - -int LbmFsgrSolver::getForZMaxBnd(int lev) { - if(LBMDIM==2) return 1; - return mLevel[lev].lSizez -0; -} -int LbmFsgrSolver::getForZMax1(int lev) { - if(LBMDIM==2) return 1; - return mLevel[lev].lSizez -1; -} - -bool LbmFsgrSolver::checkDomainBounds(int lev,int i,int j,int k) { - if(i<0) return false; - if(j<0) return false; - if(k<0) return false; - if(i>mLevel[lev].lSizex-1) return false; - if(j>mLevel[lev].lSizey-1) return false; - if(k>mLevel[lev].lSizez-1) return false; - return true; -} -bool LbmFsgrSolver::checkDomainBoundsPos(int lev,LbmVec pos) { - const int i= (int)pos[0]; - if(i<0) return false; - if(i>mLevel[lev].lSizex-1) return false; - const int j= (int)pos[1]; - if(j<0) return false; - if(j>mLevel[lev].lSizey-1) return false; - const int k= (int)pos[2]; - if(k<0) return false; - if(k>mLevel[lev].lSizez-1) return false; - return true; -} - -void LbmFsgrSolver::initInterfaceVars(int level, int i,int j,int k,int workSet, bool initMass) { - LbmFloat *ccel = &QCELL(level ,i,j,k, workSet,0); - LbmFloat nrho = 0.0; - FORDF0 { nrho += RAC(ccel,l); } - if(initMass) { - RAC(ccel,dMass) = nrho; - RAC(ccel, dFfrac) = 1.; - } else { - // preinited, e.g. from reinitFlags - RAC(ccel, dFfrac) = RAC(ccel, dMass)/nrho; - RAC(ccel, dFlux) = FLUX_INIT; - } -} - - -#endif - - diff --git a/intern/elbeem/intern/solver_control.cpp b/intern/elbeem/intern/solver_control.cpp deleted file mode 100644 index 7064dba8e22..00000000000 --- a/intern/elbeem/intern/solver_control.cpp +++ /dev/null @@ -1,876 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - the visual lattice boltzmann freesurface simulator - * All code distributed as part of El'Beem is covered by the version 2 of the - * GNU General Public License. See the file COPYING for details. - * - * Copyright 2003-2008 Nils Thuerey - * - * control extensions - * - *****************************************************************************/ -#include "solver_class.h" -#include "solver_relax.h" -#include "particletracer.h" - -#include "solver_control.h" - -#include "controlparticles.h" - -#include "elbeem.h" - -#include "ntl_geometrymodel.h" - -/****************************************************************************** - * LbmControlData control set - *****************************************************************************/ - -LbmControlSet::LbmControlSet() : - mCparts(NULL), mCpmotion(NULL), mContrPartFile(""), mCpmotionFile(""), - mcForceAtt(0.), mcForceVel(0.), mcForceMaxd(0.), - mcRadiusAtt(0.), mcRadiusVel(0.), mcRadiusMind(0.), mcRadiusMaxd(0.), - mcCpScale(1.), mcCpOffset(0.) -{ -} -LbmControlSet::~LbmControlSet() { - if(mCparts) delete mCparts; - if(mCpmotion) delete mCpmotion; -} -void LbmControlSet::initCparts() { - mCparts = new ControlParticles(); - mCpmotion = new ControlParticles(); -} - - - -/****************************************************************************** - * LbmControlData control - *****************************************************************************/ - -LbmControlData::LbmControlData() : - mSetForceStrength(0.), - mCons(), - mCpUpdateInterval(8), // DG: was 16 --> causes problems (big sphere after some time), unstable - mCpOutfile(""), - mCpForces(), mCpKernel(), mMdKernel(), - mDiffVelCon(1.), - mDebugCpscale(0.), - mDebugVelScale(0.), - mDebugCompavScale(0.), - mDebugAttScale(0.), - mDebugMaxdScale(0.), - mDebugAvgVelScale(0.) -{ -} - -LbmControlData::~LbmControlData() -{ - while (!mCons.empty()) { - delete mCons.back(); mCons.pop_back(); - } -} - - -void LbmControlData::parseControldataAttrList(AttributeList *attr) { - // controlpart vars - mSetForceStrength = attr->readFloat("tforcestrength", mSetForceStrength,"LbmControlData", "mSetForceStrength", false); - //errMsg("tforcestrength set to "," "<readInt("controlparticle_updateinterval", mCpUpdateInterval,"LbmControlData","mCpUpdateInterval", false); - // tracer output file - mCpOutfile = attr->readString("controlparticle_outfile",mCpOutfile,"LbmControlData","mCpOutfile", false); - if(getenv("ELBEEM_CPOUTFILE")) { - string outfile(getenv("ELBEEM_CPOUTFILE")); - mCpOutfile = outfile; - debMsgStd("LbmControlData::parseAttrList",DM_NOTIFY,"Using envvar ELBEEM_CPOUTFILE to set mCpOutfile to "<0) - { suffix = string("0"); suffix[0]+=cpii; } - LbmControlSet *cset; - cset = new LbmControlSet(); - cset->initCparts(); - - cset->mContrPartFile = attr->readString("controlparticle"+suffix+"_file",cset->mContrPartFile,"LbmControlData","cset->mContrPartFile", false); - if((cpii==0) && (getenv("ELBEEM_CPINFILE")) ) { - string infile(getenv("ELBEEM_CPINFILE")); - cset->mContrPartFile = infile; - debMsgStd("LbmControlData::parseAttrList",DM_NOTIFY,"Using envvar ELBEEM_CPINFILE to set mContrPartFile to "<mContrPartFile,7); - } - - LbmFloat cpvort=0.; - cset->mcRadiusAtt = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_radiusatt", 0., "LbmControlData","mcRadiusAtt" ); - cset->mcRadiusVel = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_radiusvel", 0., "LbmControlData","mcRadiusVel" ); - cset->mcRadiusVel = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_radiusvel", 0., "LbmControlData","mcRadiusVel" ); - cset->mCparts->setRadiusAtt(cset->mcRadiusAtt.get(0.)); - cset->mCparts->setRadiusVel(cset->mcRadiusVel.get(0.)); - - // WARNING currently only for first set - //if(cpii==0) { - cset->mcForceAtt = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_attraction", 0. , "LbmControlData","cset->mcForceAtt", false); - cset->mcForceVel = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_velocity", 0. , "LbmControlData","mcForceVel", false); - cset->mcForceMaxd = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_maxdist", 0. , "LbmControlData","mcForceMaxd", false); - cset->mCparts->setInfluenceAttraction(cset->mcForceAtt.get(0.) ); - // warning - stores temprorarily, value converted to dt dep. factor - cset->mCparts->setInfluenceVelocity(cset->mcForceVel.get(0.) , 0.01 ); // dummy dt - cset->mCparts->setInfluenceMaxdist(cset->mcForceMaxd.get(0.) ); - cpvort = attr->readFloat("controlparticle"+suffix+"_vorticity", cpvort, "LbmControlData","cpvort", false); - cset->mCparts->setInfluenceTangential(cpvort); - - cset->mcRadiusMind = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_radiusmin", cset->mcRadiusMind.get(0.), "LbmControlData","mcRadiusMind", false); - cset->mcRadiusMaxd = attr->readChannelSinglePrecFloat("controlparticle"+suffix+"_radiusmax", cset->mcRadiusMind.get(0.), "LbmControlData","mcRadiusMaxd", false); - cset->mCparts->setRadiusMinMaxd(cset->mcRadiusMind.get(0.)); - cset->mCparts->setRadiusMaxd(cset->mcRadiusMaxd.get(0.)); - //} - - // now local... - //LbmVec cpOffset(0.), cpScale(1.); - LbmFloat cpTimescale = 1.; - string cpMirroring(""); - - //cset->mcCpOffset = attr->readChannelVec3f("controlparticle"+suffix+"_offset", ntlVec3f(0.),"LbmControlData","mcCpOffset", false); - //cset->mcCpScale = attr->readChannelVec3f("controlparticle"+suffix+"_scale", ntlVec3f(1.), "LbmControlData","mcCpScale", false); - cset->mcCpOffset = attr->readChannelVec3f("controlparticle"+suffix+"_offset", ntlVec3f(0.),"LbmControlData","mcCpOffset", false); - cset->mcCpScale = attr->readChannelVec3f("controlparticle"+suffix+"_scale", ntlVec3f(1.), "LbmControlData","mcCpScale", false); - cpTimescale = attr->readFloat("controlparticle"+suffix+"_timescale", cpTimescale, "LbmControlData","cpTimescale", false); - cpMirroring = attr->readString("controlparticle"+suffix+"_mirror", cpMirroring, "LbmControlData","cpMirroring", false); - - LbmFloat cpsWidth = cset->mCparts->getCPSWith(); - cpsWidth = attr->readFloat("controlparticle"+suffix+"_cpswidth", cpsWidth, "LbmControlData","cpsWidth", false); - LbmFloat cpsDt = cset->mCparts->getCPSTimestep(); - cpsDt = attr->readFloat("controlparticle"+suffix+"_cpstimestep", cpsDt, "LbmControlData","cpsDt", false); - LbmFloat cpsTstart = cset->mCparts->getCPSTimeStart(); - cpsTstart = attr->readFloat("controlparticle"+suffix+"_cpststart", cpsTstart, "LbmControlData","cpsTstart", false); - LbmFloat cpsTend = cset->mCparts->getCPSTimeEnd(); - cpsTend = attr->readFloat("controlparticle"+suffix+"_cpstend", cpsTend, "LbmControlData","cpsTend", false); - LbmFloat cpsMvmfac = cset->mCparts->getCPSMvmWeightFac(); - cpsMvmfac = attr->readFloat("controlparticle"+suffix+"_cpsmvmfac", cpsMvmfac, "LbmControlData","cpsMvmfac", false); - cset->mCparts->setCPSWith(cpsWidth); - cset->mCparts->setCPSTimestep(cpsDt); - cset->mCparts->setCPSTimeStart(cpsTstart); - cset->mCparts->setCPSTimeEnd(cpsTend); - cset->mCparts->setCPSMvmWeightFac(cpsMvmfac); - - cset->mCparts->setOffset( vec2L(cset->mcCpOffset.get(0.)) ); - cset->mCparts->setScale( vec2L(cset->mcCpScale.get(0.)) ); - cset->mCparts->setInitTimeScale( cpTimescale ); - cset->mCparts->setInitMirror( cpMirroring ); - - int mDebugInit = 0; - mDebugInit = attr->readInt("controlparticle"+suffix+"_debuginit", mDebugInit,"LbmControlData","mDebugInit", false); - cset->mCparts->setDebugInit(mDebugInit); - - // motion particle settings - LbmVec mcpOffset(0.), mcpScale(1.); - LbmFloat mcpTimescale = 1.; - string mcpMirroring(""); - - cset->mCpmotionFile = attr->readString("cpmotion"+suffix+"_file",cset->mCpmotionFile,"LbmControlData","mCpmotionFile", false); - mcpTimescale = attr->readFloat("cpmotion"+suffix+"_timescale", mcpTimescale, "LbmControlData","mcpTimescale", false); - mcpMirroring = attr->readString("cpmotion"+suffix+"_mirror", mcpMirroring, "LbmControlData","mcpMirroring", false); - mcpOffset = vec2L( attr->readVec3d("cpmotion"+suffix+"_offset", vec2P(mcpOffset),"LbmControlData","cpOffset", false) ); - mcpScale = vec2L( attr->readVec3d("cpmotion"+suffix+"_scale", vec2P(mcpScale), "LbmControlData","cpScale", false) ); - - cset->mCpmotion->setOffset( vec2L(mcpOffset) ); - cset->mCpmotion->setScale( vec2L(mcpScale) ); - cset->mCpmotion->setInitTimeScale( mcpTimescale ); - cset->mCpmotion->setInitMirror( mcpMirroring ); - - if(cset->mContrPartFile.length()>1) { - errMsg("LbmControlData","Using control particle set "<mContrPartFile<<" cpmfile:"<mCpmotionFile<<" mirr:'"<mCpmotion->getInitMirror()<<"' " ); - mCons.push_back( cset ); - } else { - delete cset; - } - } - - // debug, testing - make sure theres at least an empty set - if(mCons.size()<1) { - mCons.push_back( new LbmControlSet() ); - mCons[0]->initCparts(); - } - - // take from first set - for(int cpii=1; cpii<(int)mCons.size(); cpii++) { - mCons[cpii]->mCparts->setRadiusMinMaxd( mCons[0]->mCparts->getRadiusMinMaxd() ); - mCons[cpii]->mCparts->setRadiusMaxd( mCons[0]->mCparts->getRadiusMaxd() ); - mCons[cpii]->mCparts->setInfluenceAttraction( mCons[0]->mCparts->getInfluenceAttraction() ); - mCons[cpii]->mCparts->setInfluenceTangential( mCons[0]->mCparts->getInfluenceTangential() ); - mCons[cpii]->mCparts->setInfluenceVelocity( mCons[0]->mCparts->getInfluenceVelocity() , 0.01 ); // dummy dt - mCons[cpii]->mCparts->setInfluenceMaxdist( mCons[0]->mCparts->getInfluenceMaxdist() ); - } - - // invert for usage in relax macro - mDiffVelCon = 1.-attr->readFloat("cpdiffvelcon", mDiffVelCon, "LbmControlData","mDiffVelCon", false); - - mDebugCpscale = attr->readFloat("cpdebug_cpscale", mDebugCpscale, "LbmControlData","mDebugCpscale", false); - mDebugMaxdScale = attr->readFloat("cpdebug_maxdscale", mDebugMaxdScale, "LbmControlData","mDebugMaxdScale", false); - mDebugAttScale = attr->readFloat("cpdebug_attscale", mDebugAttScale, "LbmControlData","mDebugAttScale", false); - mDebugVelScale = attr->readFloat("cpdebug_velscale", mDebugVelScale, "LbmControlData","mDebugVelScale", false); - mDebugCompavScale = attr->readFloat("cpdebug_compavscale", mDebugCompavScale, "LbmControlData","mDebugCompavScale", false); - mDebugAvgVelScale = attr->readFloat("cpdebug_avgvelsc", mDebugAvgVelScale, "LbmControlData","mDebugAvgVelScale", false); -} - - -void -LbmFsgrSolver::initCpdata() -{ - // enable for cps via env. vars - //if( (getenv("ELBEEM_CPINFILE")) || (getenv("ELBEEM_CPOUTFILE")) ){ mUseTestdata=1; } - - - // manually switch on! if this is zero, nothing is done... - mpControl->mSetForceStrength = this->mTForceStrength = 1.; - while (!mpControl->mCons.empty()) { - delete mpControl->mCons.back(); mpControl->mCons.pop_back(); - } - - - // init all control fluid objects - int numobjs = (int)(mpGiObjects->size()); - for(int o=0; ogetGeoInitType() & FGI_CONTROL) { - // add new control set per object - LbmControlSet *cset; - - cset = new LbmControlSet(); - cset->initCparts(); - - // dont load any file - cset->mContrPartFile = string(""); - - cset->mcForceAtt = obj->getCpsAttrFStr(); - cset->mcRadiusAtt = obj->getCpsAttrFRad(); - cset->mcForceVel = obj->getCpsVelFStr(); - cset->mcRadiusVel = obj->getCpsVelFRad(); - - cset->mCparts->setCPSTimeStart(obj->getCpsTimeStart()); - cset->mCparts->setCPSTimeEnd(obj->getCpsTimeEnd()); - - if(obj->getCpsQuality() > LBM_EPSILON) - cset->mCparts->setCPSWith(1.0 / obj->getCpsQuality()); - - // this value can be left at 0.5: - cset->mCparts->setCPSMvmWeightFac(0.5); - - mpControl->mCons.push_back( cset ); - mpControl->mCons[mpControl->mCons.size()-1]->mCparts->initFromObject(obj); - } - } - - // NT blender integration manual test setup - if(0) { - // manually switch on! if this is zero, nothing is done... - mpControl->mSetForceStrength = this->mTForceStrength = 1.; - while (!mpControl->mCons.empty()) { - delete mpControl->mCons.back(); mpControl->mCons.pop_back(); - } - - // add new set - LbmControlSet *cset; - - cset = new LbmControlSet(); - cset->initCparts(); - // dont load any file - cset->mContrPartFile = string(""); - - // set radii for attraction & velocity forces - // set strength of the forces - // don't set directly! but use channels: - // mcForceAtt, mcForceVel, mcForceMaxd, mcRadiusAtt, mcRadiusVel, mcRadiusMind, mcRadiusMaxd etc. - - // wrong: cset->mCparts->setInfluenceAttraction(1.15); cset->mCparts->setRadiusAtt(1.5); - // right, e.g., to init some constant values: - cset->mcForceAtt = AnimChannel(0.2); - cset->mcRadiusAtt = AnimChannel(0.75); - cset->mcForceVel = AnimChannel(0.2); - cset->mcRadiusVel = AnimChannel(0.75); - - // this value can be left at 0.5: - cset->mCparts->setCPSMvmWeightFac(0.5); - - mpControl->mCons.push_back( cset ); - - // instead of reading from file (cset->mContrPartFile), manually init some particles - mpControl->mCons[0]->mCparts->initBlenderTest(); - - // other values that might be interesting to change: - //cset->mCparts->setCPSTimestep(0.02); - //cset->mCparts->setCPSTimeStart(0.); - //cset->mCparts->setCPSTimeEnd(1.); - - //mpControl->mDiffVelCon = 1.; // more rigid velocity control, 0 (default) allows more turbulence - } - - // control particle ------------------------------------------------------------------------------------- - - // init cppf stage, use set 0! - if(mCppfStage>0) { - if(mpControl->mCpOutfile.length()<1) mpControl->mCpOutfile = string("cpout"); // use getOutFilename !? - char strbuf[100]; - const char *cpFormat = "_d%dcppf%d"; - - // initial coarse stage, no input - if(mCppfStage==1) { - mpControl->mCons[0]->mContrPartFile = ""; - } else { - // read from prev stage - snprintf(strbuf,100, cpFormat ,LBMDIM,mCppfStage-1); - mpControl->mCons[0]->mContrPartFile = mpControl->mCpOutfile; - mpControl->mCons[0]->mContrPartFile += strbuf; - mpControl->mCons[0]->mContrPartFile += ".cpart2"; - } - - snprintf(strbuf,100, cpFormat ,LBMDIM,mCppfStage); - mpControl->mCpOutfile += strbuf; - } // */ - - for(int cpssi=0; cpssi<(int)mpControl->mCons.size(); cpssi++) { - ControlParticles *cparts = mpControl->mCons[cpssi]->mCparts; - ControlParticles *cpmotion = mpControl->mCons[cpssi]->mCpmotion; - - // now set with real dt - cparts->setInfluenceVelocity( mpControl->mCons[cpssi]->mcForceVel.get(0.), mLevel[mMaxRefine].timestep); - cparts->setCharLength( mLevel[mMaxRefine].nodeSize ); - cparts->setCharLength( mLevel[mMaxRefine].nodeSize ); - errMsg("LbmControlData","CppfStage "<mCons[cpssi]->mContrPartFile<< - " out:"<mCpOutfile<<" cl:"<< cparts->getCharLength() ); - - // control particle test init - if(mpControl->mCons[cpssi]->mCpmotionFile.length()>=1) cpmotion->initFromTextFile(mpControl->mCons[cpssi]->mCpmotionFile); - // not really necessary... - //? cparts->setFluidSpacing( mLevel[mMaxRefine].nodeSize ); // use grid coords!? - //? cparts->calculateKernelWeight(); - //? debMsgStd("LbmFsgrSolver::initCpdata",DM_MSG,"ControlParticles - motion inited: "<getSize() ,10); - - // ensure both are on for env. var settings - // when no particles, but outfile enabled, initialize - const int lev = mMaxRefine; - if((mpParticles) && (mpControl->mCpOutfile.length()>=1) && (cpssi==0)) { - // check if auto num - if( (mpParticles->getNumInitialParticles()<=1) && - (mpParticles->getNumParticles()<=1) ) { // initParticles done afterwards anyway - int tracers = 0; - const int workSet = mLevel[lev].setCurr; - FSGR_FORIJK_BOUNDS(lev) { - if(RFLAG(lev,i,j,k, workSet)&(CFFluid)) tracers++; - } - if(LBMDIM==3) tracers /= 8; - else tracers /= 4; - mpParticles->setNumInitialParticles(tracers); - mpParticles->setDumpTextFile(mpControl->mCpOutfile); - debMsgStd("LbmFsgrSolver::initCpdata",DM_MSG,"ControlParticles - set tracers #"<getNumParticles() ,10); - } - if(mpParticles->getDumpTextInterval()<=0.) { - mpParticles->setDumpTextInterval(mLevel[lev].timestep * mLevel[lev].lSizex); - debMsgStd("LbmFsgrSolver::initCpdata",DM_MSG,"ControlParticles - dump delta t not set, using dti="<< mpParticles->getDumpTextInterval()<<", sim dt="<setDumpParts(true); // DEBUG? also dump as particle system - } - - if(mpControl->mCons[cpssi]->mContrPartFile.length()>=1) cparts->initFromTextFile(mpControl->mCons[cpssi]->mContrPartFile); - cparts->setFluidSpacing( mLevel[lev].nodeSize ); // use grid coords!? - cparts->calculateKernelWeight(); - debMsgStd("LbmFsgrSolver::initCpdata",DM_MSG,"ControlParticles mCons"<getTotalSize()<<","<getSize()<<" dt:"<getTimestep()<<" control time:"<getControlTimStart()<<" to "<getControlTimEnd() ,10); - } // cpssi - - if(getenv("ELBEEM_CPINFILE")) { - this->mTForceStrength = 1.0; - } - this->mTForceStrength = mpControl->mSetForceStrength; - if(mpControl->mCpOutfile.length()>=1) mpParticles->setDumpTextFile(mpControl->mCpOutfile); - - // control particle init end ------------------------------------------------------------------------------------- - - // make sure equiv to solver init - if(this->mTForceStrength>0.) { \ - mpControl->mCpForces.resize( mMaxRefine+1 ); - for(int lev = 0; lev<=mMaxRefine; lev++) { - LONGINT rcellSize = (mLevel[lev].lSizex*mLevel[lev].lSizey*mLevel[lev].lSizez); - debMsgStd("LbmFsgrSolver::initControl",DM_MSG,"mCpForces init, lev="<mCpForces[lev].resize( (int)(rcellSize+4) ); - //for(int i=0 ;imCpForces.push_back( ControlForces() ); - for(int i=0 ;imCpForces[lev][i].resetForces(); - } - } // on? - - debMsgStd("LbmFsgrSolver::initCpdata",DM_MSG,"ControlParticles #mCons "<mCons.size()<<" done", 6); -} - - -#define CPODEBUG 0 -//define CPINTER ((int)(mpControl->mCpUpdateInterval)) - -#define KERN(x,y,z) mpControl->mCpKernel[ (((z)*cpkarWidth + (y))*cpkarWidth + (x)) ] -#define MDKERN(x,y,z) mpControl->mMdKernel[ (((z)*mdkarWidth + (y))*mdkarWidth + (x)) ] - -#define BOUNDCHECK(x,low,high) ( ((x)high) ? high : (x) ) ) -#define BOUNDSKIP(x,low,high) ( ((x)high) ) - -void -LbmFsgrSolver::handleCpdata() -{ - myTime_t cpstart = getTime(); - int cpChecks=0; - int cpInfs=0; - //debMsgStd("ControlData::handleCpdata",DM_MSG,"called... "<mTForceStrength,1); - - // add cp influence - if((true) && (this->mTForceStrength>0.)) { - // ok continue... - } // on off - else { - return; - } - - // check if we have control objects - if(mpControl->mCons.size()==0) - return; - - if((mpControl->mCpUpdateInterval<1) || (this->mStepCnt%mpControl->mCpUpdateInterval==0)) { - // do full reinit later on... - } - else if(this->mStepCnt>mpControl->mCpUpdateInterval) { - // only reinit new cells - // TODO !? remove loop dependance!? -#define NOFORCEENTRY(lev, i,j,k) (LBMGET_FORCE(lev, i,j,k).maxDistance==CPF_MAXDINIT) - // interpolate missing - for(int lev=0; lev<=mMaxRefine; lev++) { - FSGR_FORIJK_BOUNDS(lev) { - if( (RFLAG(lev,i,j,k, mLevel[lev].setCurr)) & (CFFluid|CFInter) ) - //if( (RFLAG(lev,i,j,k, mLevel[lev].setCurr)) & (CFInter) ) - //if(0) - { // only check new inter? RFLAG?check - if(NOFORCEENTRY(lev, i,j,k)) { - //errMsg("CP","FE_MISSING at "<cDirNum; l++) { - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - //errMsg("CP","FE_MISSING check "<0.) { - nbs = 1./nbs; - //? LBMGET_FORCE(lev, i,j,k).weightAtt = vals.weightAtt*nbs; - //? LBMGET_FORCE(lev, i,j,k).forceAtt = vals.forceAtt*nbs; - LBMGET_FORCE(lev, i,j,k).maxDistance = vals.maxDistance*nbs; - LBMGET_FORCE(lev, i,j,k).forceMaxd = vals.forceMaxd*nbs; - LBMGET_FORCE(lev, i,j,k).weightVel = vals.weightVel*nbs; - LBMGET_FORCE(lev, i,j,k).forceVel = vals.forceVel*nbs; - } - /*ControlForces *ff = &LBMGET_FORCE(lev, i,j,k); // DEBUG - errMsg("CP","FE_MISSING rec at "<weightAtt<<" wa:" <forceAtt[0],ff->forceAtt[1],ff->forceAtt[2] ) - <<" v:"<weightVel<<" wv:" <forceVel[0],ff->forceVel[1],ff->forceVel[2] ) - <<" v:"<maxDistance<<" wv:" <forceMaxd[0],ff->forceMaxd[1],ff->forceMaxd[2] ) ); // DEBUG */ - // else errMsg("CP","FE_MISSING rec at "< mpControl->mCpUpdateInterval - return; - } else { - // nothing to do ... - return; - } - - // reset - for(int lev=0; lev<=mMaxRefine; lev++) { - FSGR_FORIJK_BOUNDS(lev) { LBMGET_FORCE(lev,i,j,k).resetForces(); } - } - // do setup for coarsest level - const int coarseLev = 0; - const int fineLev = mMaxRefine; - - // init for current time - for(int cpssi=0; cpssi<(int)mpControl->mCons.size(); cpssi++) { - ControlParticles *cparts = mpControl->mCons[cpssi]->mCparts; - LbmControlSet *cset = mpControl->mCons[cpssi]; - - cparts->setRadiusAtt(cset->mcRadiusAtt.get(mSimulationTime)); - cparts->setRadiusVel(cset->mcRadiusVel.get(mSimulationTime)); - cparts->setInfluenceAttraction(cset->mcForceAtt.get(mSimulationTime) ); - cparts->setInfluenceMaxdist(cset->mcForceMaxd.get(mSimulationTime) ); - cparts->setRadiusMinMaxd(cset->mcRadiusMind.get(mSimulationTime)); - cparts->setRadiusMaxd(cset->mcRadiusMaxd.get(mSimulationTime)); - cparts->calculateKernelWeight(); // always necessary!? - cparts->setOffset( vec2L(cset->mcCpOffset.get(mSimulationTime)) ); - cparts->setScale( vec2L(cset->mcCpScale.get(mSimulationTime)) ); - - cparts->setInfluenceVelocity( cset->mcForceVel.get(mSimulationTime), mLevel[fineLev].timestep ); - cparts->setLastOffset( vec2L(cset->mcCpOffset.get(mSimulationTime-mLevel[fineLev].timestep)) ); - cparts->setLastScale( vec2L(cset->mcCpScale.get(mSimulationTime-mLevel[fineLev].timestep)) ); - - } - - // check actual values - LbmFloat iatt = ABS(mpControl->mCons[0]->mCparts->getInfluenceAttraction()); - LbmFloat ivel = mpControl->mCons[0]->mCparts->getInfluenceVelocity(); - LbmFloat imaxd = mpControl->mCons[0]->mCparts->getInfluenceMaxdist(); - //errMsg("FINCIT","iatt="<mCons[1]->mCparts->getInfluenceAttraction(); //ivel = mpControl->mCons[1]->mCparts->getInfluenceVelocity(); //imaxd = mpControl->mCons[1]->mCparts->getInfluenceMaxdist(); // TTTTTT - - // do control setup - for(int cpssi=0; cpssi<(int)mpControl->mCons.size(); cpssi++) { - ControlParticles *cparts = mpControl->mCons[cpssi]->mCparts; - ControlParticles *cpmotion = mpControl->mCons[cpssi]->mCpmotion; - - // TEST!? - bool radmod = false; - const LbmFloat minRadSize = mLevel[coarseLev].nodeSize * 1.5; - if((cparts->getRadiusAtt()>0.) && (cparts->getRadiusAtt()getRadiusAtt(); radmod=true; - debMsgStd("ControlData::initControl",DM_MSG,"Modified radii att, fac="<setRadiusAtt(cparts->getRadiusAtt()*radfac); - cparts->setRadiusVel(cparts->getRadiusVel()*radfac); - cparts->setRadiusMaxd(cparts->getRadiusMaxd()*radfac); - cparts->setRadiusMinMaxd(cparts->getRadiusMinMaxd()*radfac); - } else if((cparts->getRadiusVel()>0.) && (cparts->getRadiusVel()getRadiusVel(); - debMsgStd("ControlData::initControl",DM_MSG,"Modified radii vel, fac="<setRadiusVel(cparts->getRadiusVel()*radfac); - cparts->setRadiusMaxd(cparts->getRadiusMaxd()*radfac); - cparts->setRadiusMinMaxd(cparts->getRadiusMinMaxd()*radfac); - } else if((cparts->getRadiusMaxd()>0.) && (cparts->getRadiusMaxd()getRadiusMaxd(); - debMsgStd("ControlData::initControl",DM_MSG,"Modified radii maxd, fac="<setRadiusMaxd(cparts->getRadiusMaxd()*radfac); - cparts->setRadiusMinMaxd(cparts->getRadiusMinMaxd()*radfac); - } - if(radmod) { - debMsgStd("ControlData::initControl",DM_MSG,"Modified radii: att="<< - cparts->getRadiusAtt()<<", vel=" << cparts->getRadiusVel()<<", maxd=" << - cparts->getRadiusMaxd()<<", mind=" << cparts->getRadiusMinMaxd() ,5); - } - - cpmotion->prepareControl( mSimulationTime+((LbmFloat)mpControl->mCpUpdateInterval)*(mpParam->getTimestep()), mpParam->getTimestep(), NULL ); - cparts->prepareControl( mSimulationTime+((LbmFloat)mpControl->mCpUpdateInterval)*(mpParam->getTimestep()), mpParam->getTimestep(), cpmotion ); - } - - // do control... - for(int lev=0; lev<=mMaxRefine; lev++) { - LbmFloat levVolume = 1.; - LbmFloat levForceScale = 1.; - for(int ll=lev; llgetRadiusAtt()<<" gsx"<getSize(); cppi++) { - ControlParticle *cp = cparts->getParticle(cppi); - if(cp->influence<=0.) continue; - const int cpi = (int)( (cp->pos[0]-goffx)/gsx ); - const int cpj = (int)( (cp->pos[1]-goffy)/gsy ); - int cpk = (int)( (cp->pos[2]-goffz)/gsz ); - /*if( ((LBMDIM==3)&&(BOUNDSKIP(cpk - cpwsm, getForZMinBnd(), getForZMaxBnd(lev) ))) || - ((LBMDIM==3)&&(BOUNDSKIP(cpk + cpwsm, getForZMinBnd(), getForZMaxBnd(lev) ))) || - BOUNDSKIP(cpj - cpwsm, 0, mLevel[lev].lSizey ) || - BOUNDSKIP(cpj + cpwsm, 0, mLevel[lev].lSizey ) || - BOUNDSKIP(cpi - cpwsm, 0, mLevel[lev].lSizex ) || - BOUNDSKIP(cpi + cpwsm, 0, mLevel[lev].lSizex ) ) { - continue; - } // */ - int is,ie,js,je,ks,ke; - ks = BOUNDCHECK(cpk - cpw, getForZMinBnd(), getForZMaxBnd(lev) ); - ke = BOUNDCHECK(cpk + cpw, getForZMinBnd(), getForZMaxBnd(lev) ); - js = BOUNDCHECK(cpj - cpw, 0, mLevel[lev].lSizey ); - je = BOUNDCHECK(cpj + cpw, 0, mLevel[lev].lSizey ); - is = BOUNDCHECK(cpi - cpw, 0, mLevel[lev].lSizex ); - ie = BOUNDCHECK(cpi + cpw, 0, mLevel[lev].lSizex ); - if(LBMDIM==2) { cpk = 0; ks = 0; ke = 1; } - if(CPODEBUG) errMsg("cppft","i"<weightAtt; - // control particle mod, - // dont add multiple CFFluid fsgr boundaries - if(lev==mMaxRefine) { - //if( ( ((*pflag)&(CFFluid )) && (lev==mMaxRefine) ) || - //( ((*pflag)&(CFGrNorm)) && (lev density += levVolume* kk->weightAtt; // old CFFluid - } else if( (*pflag) & (CFEmpty) ) { - cp->density -= levVolume* 0.5; - } else { //if( ((*pflag) & (CFBnd)) ) { - cp->density -= levVolume* 0.2; // penalty - } - } else { - //if((*pflag)&(CFGrNorm)) { - //cp->density += levVolume* kk->weightAtt; // old CFFluid - //} - } - //else if(!((*pflag) & (CFUnused)) ) { cp->density -= levVolume* 0.2; } // penalty - - if( (*pflag) & (CFFluid|CFInter) ) // RFLAG_check - { - - cpChecks++; - //const LbmFloat pwforce = kk->weightAtt; - LbmFloat pwvel = kk->weightVel; - if((pwforce==0.)&&(pwvel==0.)) { continue; } - ff->weightAtt += 1e-6; // for distance - - if(pwforce>0.) { - ff->weightAtt += pwforce *cp->densityWeight *cp->influence; - ff->forceAtt += kk->forceAtt *levForceScale *cp->densityWeight *cp->influence; - - // old fill handling here - const int workSet =mLevel[lev].setCurr; - LbmFloat ux=0., uy=0., uz=0.; - FORDF1{ - const LbmFloat dfn = QCELL(lev, i,j,k, workSet, l); - ux += (this->dfDvecX[l]*dfn); - uy += (this->dfDvecY[l]*dfn); - uz += (this->dfDvecZ[l]*dfn); - } - // control particle mod - cp->avgVelWeight += levVolume*pwforce; - cp->avgVelAcc += LbmVec(ux,uy,uz) * levVolume*pwforce; - } - - if(pwvel>0.) { - // TODO make switch? vel.influence depends on density weight... - // (reduced lowering with 0.75 factor) - pwvel *= cp->influence *(1.-0.75*cp->densityWeight); - // control particle mod - // todo use Omega instead!? - ff->forceVel += cp->vel*levVolume*pwvel * velLatticeScale; // levVolume? - ff->weightVel += levVolume*pwvel; // levVolume? - ff->compAv += cp->avgVel*levVolume*pwvel; // levVolume? - ff->compAvWeight += levVolume*pwvel; // levVolume? - } - - if(CPODEBUG) errMsg("cppft","i"<weightAtt<<" wa:" - //<forceAtt[0],ff->forceAtt[1],ff->forceAtt[2] ) - //<<" v:"<weightVel<<" wv:" - //<forceVel[0],ff->forceVel[1],ff->forceVel[2] ) - //<<" v:"<maxDistance<<" wv:" - //<forceMaxd[0],ff->forceMaxd[1],ff->forceMaxd[2] ) - ); - } // celltype - - } // ijk - } // ijk - } // ijk - } // cpi, end first cp loop (att,vel) - debMsgStd("LbmFsgrSolver::handleCpdata",DM_MSG,"Force cpgrid "<mCons.size(); cpssi++) { - ControlParticles *cparts = mpControl->mCons[cpssi]->mCparts; - - // WARNING copied from above! - const LbmFloat velLatticeScale = mLevel[lev].timestep/mLevel[lev].nodeSize; - LbmFloat gsx = ((mvGeoEnd[0]-mvGeoStart[0])/(LbmFloat)mLevel[lev].lSizex); - LbmFloat gsy = ((mvGeoEnd[1]-mvGeoStart[1])/(LbmFloat)mLevel[lev].lSizey); - LbmFloat gsz = ((mvGeoEnd[2]-mvGeoStart[2])/(LbmFloat)mLevel[lev].lSizez); -#if LBMDIM==2 - gsz = gsx; -#endif - LbmFloat goffx = mvGeoStart[0]; - LbmFloat goffy = mvGeoStart[1]; - LbmFloat goffz = mvGeoStart[2]; - - //const LbmFloat cpwIncFac = 2.0; - const int mdw = MIN( mLevel[lev].lSizex/2, MAX( (int)( cparts->getRadiusMaxd() /gsx) +1 , 2) ); // wide kernel, md - const int mdkarWidth = 2*mdw+1; - mpControl->mMdKernel.resize(mdkarWidth* mdkarWidth* mdkarWidth); - ControlParticle cpt; cpt.reset(); - cpt.density = 0.5; cpt.densityWeight = 0.5; - cpt.pos = LbmVec( (gsx*(LbmFloat)mdw)+goffx, (gsy*(LbmFloat)mdw)+goffy, (gsz*(LbmFloat)mdw)+goffz ); // optimize? -#if LBMDIM==3 - for(int k= 0; kcalculateMaxdForce( &cpt, pos, &MDKERN(i,j,k) ); - } - } - - // second cpi loop, maxd forces - if(cparts->getInfluenceMaxdist()>0.) { - for(int cppi=0; cppigetSize(); cppi++) { - ControlParticle *cp = cparts->getParticle(cppi); - if(cp->influence<=0.) continue; - const int cpi = (int)( (cp->pos[0]-goffx)/gsx ); - const int cpj = (int)( (cp->pos[1]-goffy)/gsy ); - int cpk = (int)( (cp->pos[2]-goffz)/gsz ); - - int is,ie,js,je,ks,ke; - ks = BOUNDCHECK(cpk - mdw, getForZMinBnd(), getForZMaxBnd(lev) ); - ke = BOUNDCHECK(cpk + mdw, getForZMinBnd(), getForZMaxBnd(lev) ); - js = BOUNDCHECK(cpj - mdw, 0, mLevel[lev].lSizey ); - je = BOUNDCHECK(cpj + mdw, 0, mLevel[lev].lSizey ); - is = BOUNDCHECK(cpi - mdw, 0, mLevel[lev].lSizex ); - ie = BOUNDCHECK(cpi + mdw, 0, mLevel[lev].lSizex ); - if(LBMDIM==2) { cpk = 0; ks = 0; ke = 1; } - if(CPODEBUG) errMsg("cppft","i"<weightAtt == 0.) { - ControlForces *kk = &MDKERN( i-cpi+mdw, j-cpj+mdw, k-cpk+mdw); - const LbmFloat pmdf = kk->maxDistance; - if((ff->maxDistance > pmdf) || (ff->maxDistance<0.)) - ff->maxDistance = pmdf; - ff->forceMaxd = kk->forceMaxd; - // todo use Omega instead!? - ff->forceVel = cp->vel* velLatticeScale; - } - } // celltype - } } // ijk - } // cpi, md loop - } // maxd inf>0 */ - - - debMsgStd("ControlData::initControl",DM_MSG,"Maxd cpgrid "<mCons[0]->mCparts->finishControl( mpControl->mCpForces[lev], iatt,ivel,imaxd ); - - } // lev loop - - myTime_t cpend = getTime(); - debMsgStd("ControlData::handleCpdata",DM_MSG,"Time for cpgrid generation:"<< getTimeString(cpend-cpstart)<<", checks:"<mCpForces[lev][ (LBMGI(lev,i,j,k,0)) ] - -// debug mods off... -// same as in src/solver_relax.h! -#define __PRECOLLIDE_MODS(rho,ux,uy,uz, grav) \ - ux += (grav)[0]; \ - uy += (grav)[1]; \ - uz += (grav)[2]; - -//void testMaxdmod(int i, int j,int k, LbmFloat &ux,LbmFloat &uy,LbmFloat &uz,ControlForces &ff); -#if LBMDIM==3 -#define MAXDGRAV \ - if(myforce->forceMaxd[0]*ux+myforce->forceMaxd[1]*uyforceVel[0]+ v2wi*ux; \ - uy = v2w*myforce->forceVel[1]+ v2wi*uy; } \ - /* movement inverse to g? */ \ - if((uz>LBM_EPSILON)&&(uz>myforce->forceVel[2])) { \ - uz = v2w*myforce->forceVel[2]+ v2wi*uz; } -#else // LBMDIM==3 -#define MAXDGRAV \ - if(myforce->forceMaxd[0]*uxforceVel[0]+ v2wi*ux; } \ - /* movement inverse to g? */ \ - if((uy>LBM_EPSILON)&&(uy>myforce->forceVel[1])) { \ - uy = v2w*myforce->forceVel[1]+ v2wi*uy; } -#endif // LBMDIM==3 - -// debug modifications of collide vars (testing) -// requires: lev,i,j,k -#define PRECOLLIDE_MODS(rho,ux,uy,uz, grav) \ - LbmFloat attforce = 1.; \ - if(this->mTForceStrength>0.) { \ - ControlForces* myforce = &LBMGET_FORCE(lev,i,j,k); \ - const LbmFloat vf = myforce->weightAtt;\ - const LbmFloat vw = myforce->weightVel;\ - if(vf!=0.) { attforce = MAX(0., 1.-vf); /* TODO FIXME? use ABS(vf) for repulsion force? */ \ - ux += myforce->forceAtt[0]; \ - uy += myforce->forceAtt[1]; \ - uz += myforce->forceAtt[2]; \ - \ - } else if(( myforce->maxDistance>0.) && ( myforce->maxDistancemCons[0]->mCparts->getInfluenceMaxdist() * \ - (myforce->maxDistance-mpControl->mCons[0]->mCparts->getRadiusMinMaxd()) / (mpControl->mCons[0]->mCparts->getRadiusMaxd()-mpControl->mCons[0]->mCparts->getRadiusMinMaxd()); \ - const LbmFloat v2wi = 1.-v2w; \ - if(v2w>0.){ MAXDGRAV; \ - /* errMsg("ERRMDTT","at "<forceVel<<" " ); */ \ - }\ - } \ - if(vw>0.) { \ - const LbmFloat vwi = 1.-vw;\ - const LbmFloat vwd = mpControl->mDiffVelCon;\ - ux += vw*(myforce->forceVel[0]-myforce->compAv[0] + vwd*(myforce->compAv[0]-ux) ); \ - uy += vw*(myforce->forceVel[1]-myforce->compAv[1] + vwd*(myforce->compAv[1]-uy) ); \ - uz += vw*(myforce->forceVel[2]-myforce->compAv[2] + vwd*(myforce->compAv[2]-uz) ); \ - /* TODO test!? modify smooth vel by influence of force for each lbm step, to account for force update only each N steps */ \ - myforce->compAv = (myforce->forceVel*vw+ myforce->compAv*vwi); \ - } \ - } \ - ux += (grav)[0]*attforce; \ - uy += (grav)[1]*attforce; \ - uz += (grav)[2]*attforce; \ - /* end PRECOLLIDE_MODS */ - -#define TEST_IF_CHECK \ - if((!iffilled)&&(LBMGET_FORCE(lev,i,j,k).weightAtt!=0.)) { \ - errMsg("TESTIFFILL"," at "< mcForceAtt; - AnimChannel mcForceVel; - AnimChannel mcForceMaxd; - - AnimChannel mcRadiusAtt; - AnimChannel mcRadiusVel; - AnimChannel mcRadiusMind; - AnimChannel mcRadiusMaxd; - - AnimChannel mcCpScale; - AnimChannel mcCpOffset; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:LbmControlSet") -#endif -}; - - - -// main control data storage -class LbmControlData -{ - public: - LbmControlData(); - virtual ~LbmControlData(); - - // control data - - // contorl params - void parseControldataAttrList(AttributeList *attr); - - // control strength, set for solver interface - LbmFloat mSetForceStrength; - // cp vars - std::vector mCons; - // update interval - int mCpUpdateInterval; - // output - string mCpOutfile; - // control particle precomputed influence - std::vector< std::vector > mCpForces; - std::vector mCpKernel; - std::vector mMdKernel; - // activate differential velcon - LbmFloat mDiffVelCon; - - // cp debug displau - LbmFloat mDebugCpscale, mDebugVelScale, mDebugCompavScale, mDebugAttScale, mDebugMaxdScale, mDebugAvgVelScale; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:LbmControlData ") -#endif -}; - -#endif // LBM_TESTCLASS_H diff --git a/intern/elbeem/intern/solver_init.cpp b/intern/elbeem/intern/solver_init.cpp deleted file mode 100644 index 5f28b4da41a..00000000000 --- a/intern/elbeem/intern/solver_init.cpp +++ /dev/null @@ -1,2396 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Standard LBM Factory implementation - * - *****************************************************************************/ - - -#include "solver_class.h" -#include "solver_relax.h" -// for geo init FGI_ defines -#include "elbeem.h" -#include "globals.h" - - -// helper for 2d init -#define SWAPYZ(vec) { \ - const LbmFloat tmp = (vec)[2]; \ - (vec)[2] = (vec)[1]; (vec)[1] = tmp; } - - -/*****************************************************************************/ -//! common variables - -/*****************************************************************************/ -/*! 3D implementation D3Q19 */ -#if LBMDIM==3 - - //! how many dimensions? - const int LbmFsgrSolver::cDimension = 3; - - // Wi factors for collide step - const LbmFloat LbmFsgrSolver::cCollenZero = (1.0/3.0); - const LbmFloat LbmFsgrSolver::cCollenOne = (1.0/18.0); - const LbmFloat LbmFsgrSolver::cCollenSqrtTwo = (1.0/36.0); - - //! threshold value for filled/emptied cells - const LbmFloat LbmFsgrSolver::cMagicNr2 = 1.0005; - const LbmFloat LbmFsgrSolver::cMagicNr2Neg = -0.0005; - const LbmFloat LbmFsgrSolver::cMagicNr = 1.010001; - const LbmFloat LbmFsgrSolver::cMagicNrNeg = -0.010001; - - //! size of a single set of distribution functions - const int LbmFsgrSolver::cDfNum = 19; - //! direction vector contain vecs for all spatial dirs, even if not used for LBM model - const int LbmFsgrSolver::cDirNum = 27; - - //const string LbmFsgrSolver::dfString[ cDfNum ] = { - const char* LbmFsgrSolver::dfString[ cDfNum ] = { - " C", " N"," S"," E"," W"," T"," B", - "NE","NW","SE","SW", - "NT","NB","ST","SB", - "ET","EB","WT","WB" - }; - - const int LbmFsgrSolver::dfNorm[ cDfNum ] = { - cDirC, cDirN, cDirS, cDirE, cDirW, cDirT, cDirB, - cDirNE, cDirNW, cDirSE, cDirSW, - cDirNT, cDirNB, cDirST, cDirSB, - cDirET, cDirEB, cDirWT, cDirWB - }; - - const int LbmFsgrSolver::dfInv[ cDfNum ] = { - cDirC, cDirS, cDirN, cDirW, cDirE, cDirB, cDirT, - cDirSW, cDirSE, cDirNW, cDirNE, - cDirSB, cDirST, cDirNB, cDirNT, - cDirWB, cDirWT, cDirEB, cDirET - }; - - const int LbmFsgrSolver::dfRefX[ cDfNum ] = { - 0, 0, 0, 0, 0, 0, 0, - cDirSE, cDirSW, cDirNE, cDirNW, - 0, 0, 0, 0, - cDirEB, cDirET, cDirWB, cDirWT - }; - - const int LbmFsgrSolver::dfRefY[ cDfNum ] = { - 0, 0, 0, 0, 0, 0, 0, - cDirNW, cDirNE, cDirSW, cDirSE, - cDirNB, cDirNT, cDirSB, cDirST, - 0, 0, 0, 0 - }; - - const int LbmFsgrSolver::dfRefZ[ cDfNum ] = { - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, - cDirST, cDirSB, cDirNT, cDirNB, - cDirWT, cDirWB, cDirET, cDirEB - }; - - // Vector Order 3D: - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 - // 0, 0, 0, 1,-1, 0, 0, 1,-1, 1,-1, 0, 0, 0, 0, 1, 1,-1,-1, 1,-1, 1,-1, 1,-1, 1,-1 - // 0, 1,-1, 0, 0, 0, 0, 1, 1,-1,-1, 1, 1,-1,-1, 0, 0, 0, 0, 1, 1,-1,-1, 1, 1,-1,-1 - // 0, 0, 0, 0, 0, 1,-1, 0, 0, 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1, 1, 1, 1, -1,-1,-1,-1 - - const int LbmFsgrSolver::dfVecX[ cDirNum ] = { - 0, 0,0, 1,-1, 0,0, - 1,-1,1,-1, - 0,0,0,0, - 1,1,-1,-1, - 1,-1, 1,-1, - 1,-1, 1,-1, - }; - const int LbmFsgrSolver::dfVecY[ cDirNum ] = { - 0, 1,-1, 0,0,0,0, - 1,1,-1,-1, - 1,1,-1,-1, - 0,0,0,0, - 1, 1,-1,-1, - 1, 1,-1,-1 - }; - const int LbmFsgrSolver::dfVecZ[ cDirNum ] = { - 0, 0,0,0,0,1,-1, - 0,0,0,0, - 1,-1,1,-1, - 1,-1,1,-1, - 1, 1, 1, 1, - -1,-1,-1,-1 - }; - - const LbmFloat LbmFsgrSolver::dfDvecX[ cDirNum ] = { - 0, 0,0, 1,-1, 0,0, - 1,-1,1,-1, - 0,0,0,0, - 1,1,-1,-1, - 1,-1, 1,-1, - 1,-1, 1,-1 - }; - const LbmFloat LbmFsgrSolver::dfDvecY[ cDirNum ] = { - 0, 1,-1, 0,0,0,0, - 1,1,-1,-1, - 1,1,-1,-1, - 0,0,0,0, - 1, 1,-1,-1, - 1, 1,-1,-1 - }; - const LbmFloat LbmFsgrSolver::dfDvecZ[ cDirNum ] = { - 0, 0,0,0,0,1,-1, - 0,0,0,0, - 1,-1,1,-1, - 1,-1,1,-1, - 1, 1, 1, 1, - -1,-1,-1,-1 - }; - - /* principal directions */ - const int LbmFsgrSolver::princDirX[ 2*LbmFsgrSolver::cDimension ] = { - 1,-1, 0,0, 0,0 - }; - const int LbmFsgrSolver::princDirY[ 2*LbmFsgrSolver::cDimension ] = { - 0,0, 1,-1, 0,0 - }; - const int LbmFsgrSolver::princDirZ[ 2*LbmFsgrSolver::cDimension ] = { - 0,0, 0,0, 1,-1 - }; - - /*! arrays for les model coefficients, inited in lbmsolver constructor */ - LbmFloat LbmFsgrSolver::lesCoeffDiag[ (cDimension-1)*(cDimension-1) ][ cDirNum ]; - LbmFloat LbmFsgrSolver::lesCoeffOffdiag[ cDimension ][ cDirNum ]; - - - const LbmFloat LbmFsgrSolver::dfLength[ cDfNum ]= { - cCollenZero, - cCollenOne, cCollenOne, cCollenOne, - cCollenOne, cCollenOne, cCollenOne, - cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo, - cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo, - cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo - }; - - /* precalculated equilibrium dfs, inited in lbmsolver constructor */ - LbmFloat LbmFsgrSolver::dfEquil[ dTotalNum ]; - -#else // end LBMDIM==3 , LBMDIM==2 - -/*****************************************************************************/ -/*! 2D implementation D2Q9 */ - - //! how many dimensions? - const int LbmFsgrSolver::cDimension = 2; - - //! Wi factors for collide step - const LbmFloat LbmFsgrSolver::cCollenZero = (4.0/9.0); - const LbmFloat LbmFsgrSolver::cCollenOne = (1.0/9.0); - const LbmFloat LbmFsgrSolver::cCollenSqrtTwo = (1.0/36.0); - - //! threshold value for filled/emptied cells - const LbmFloat LbmFsgrSolver::cMagicNr2 = 1.0005; - const LbmFloat LbmFsgrSolver::cMagicNr2Neg = -0.0005; - const LbmFloat LbmFsgrSolver::cMagicNr = 1.010001; - const LbmFloat LbmFsgrSolver::cMagicNrNeg = -0.010001; - - //! size of a single set of distribution functions - const int LbmFsgrSolver::cDfNum = 9; - const int LbmFsgrSolver::cDirNum = 9; - - //const string LbmFsgrSolver::dfString[ cDfNum ] = { - const char* LbmFsgrSolver::dfString[ cDfNum ] = { - " C", - " N", " S", " E", " W", - "NE", "NW", "SE","SW" - }; - - const int LbmFsgrSolver::dfNorm[ cDfNum ] = { - cDirC, - cDirN, cDirS, cDirE, cDirW, - cDirNE, cDirNW, cDirSE, cDirSW - }; - - const int LbmFsgrSolver::dfInv[ cDfNum ] = { - cDirC, - cDirS, cDirN, cDirW, cDirE, - cDirSW, cDirSE, cDirNW, cDirNE - }; - - const int LbmFsgrSolver::dfRefX[ cDfNum ] = { - 0, - 0, 0, 0, 0, - cDirSE, cDirSW, cDirNE, cDirNW - }; - - const int LbmFsgrSolver::dfRefY[ cDfNum ] = { - 0, - 0, 0, 0, 0, - cDirNW, cDirNE, cDirSW, cDirSE - }; - - const int LbmFsgrSolver::dfRefZ[ cDfNum ] = { - 0, 0, 0, 0, 0, - 0, 0, 0, 0 - }; - - // Vector Order 2D: - // 0 1 2 3 4 5 6 7 8 - // 0, 0,0, 1,-1, 1,-1,1,-1 - // 0, 1,-1, 0,0, 1,1,-1,-1 - - const int LbmFsgrSolver::dfVecX[ cDirNum ] = { - 0, - 0,0, 1,-1, - 1,-1,1,-1 - }; - const int LbmFsgrSolver::dfVecY[ cDirNum ] = { - 0, - 1,-1, 0,0, - 1,1,-1,-1 - }; - const int LbmFsgrSolver::dfVecZ[ cDirNum ] = { - 0, 0,0,0,0, 0,0,0,0 - }; - - const LbmFloat LbmFsgrSolver::dfDvecX[ cDirNum ] = { - 0, - 0,0, 1,-1, - 1,-1,1,-1 - }; - const LbmFloat LbmFsgrSolver::dfDvecY[ cDirNum ] = { - 0, - 1,-1, 0,0, - 1,1,-1,-1 - }; - const LbmFloat LbmFsgrSolver::dfDvecZ[ cDirNum ] = { - 0, 0,0,0,0, 0,0,0,0 - }; - - const int LbmFsgrSolver::princDirX[ 2*LbmFsgrSolver::cDimension ] = { - 1,-1, 0,0 - }; - const int LbmFsgrSolver::princDirY[ 2*LbmFsgrSolver::cDimension ] = { - 0,0, 1,-1 - }; - const int LbmFsgrSolver::princDirZ[ 2*LbmFsgrSolver::cDimension ] = { - 0,0, 0,0 - }; - - - /*! arrays for les model coefficients, inited in lbmsolver constructor */ - LbmFloat LbmFsgrSolver::lesCoeffDiag[ (cDimension-1)*(cDimension-1) ][ cDirNum ]; - LbmFloat LbmFsgrSolver::lesCoeffOffdiag[ cDimension ][ cDirNum ]; - - - const LbmFloat LbmFsgrSolver::dfLength[ cDfNum ]= { - cCollenZero, - cCollenOne, cCollenOne, cCollenOne, cCollenOne, - cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo, cCollenSqrtTwo - }; - - /* precalculated equilibrium dfs, inited in lbmsolver constructor */ - LbmFloat LbmFsgrSolver::dfEquil[ dTotalNum ]; - -// D2Q9 end -#endif // LBMDIM==2 - - - - -/****************************************************************************** - * Lbm Constructor - *****************************************************************************/ -LbmFsgrSolver::LbmFsgrSolver() : - //D(), - mCurrentMass(0.0), mCurrentVolume(0.0), - mNumProblems(0), - mAvgMLSUPS(0.0), mAvgMLSUPSCnt(0.0), - mpPreviewSurface(NULL), - mTimeAdap(true), mForceTimeStepReduce(false), - mFVHeight(0.0), mFVArea(1.0), mUpdateFVHeight(false), - mInitSurfaceSmoothing(0), mFsSurfGenSetting(0), - mTimestepReduceLock(0), - mTimeSwitchCounts(0), mTimeMaxvelStepCnt(0), - mSimulationTime(0.0), mLastSimTime(0.0), - mMinTimestep(0.0), mMaxTimestep(0.0), - mMaxNoCells(0), mMinNoCells(0), mAvgNumUsedCells(0), - mObjectSpeeds(), mObjectPartslips(), mObjectMassMovnd(), - mMOIVertices(), mMOIVerticesOld(), mMOINormals(), - mIsoWeightMethod(1), - mMaxRefine(1), - mDfScaleUp(-1.0), mDfScaleDown(-1.0), - mInitialCsmago(0.02), // set to 0.02 for mMaxRefine==0 below and default for fine level, coarser ones are 0.03 - mDebugOmegaRet(0.0), - mLastOmega(1e10), mLastGravity(1e10), - mNumInvIfTotal(0), mNumFsgrChanges(0), - mDisableStandingFluidInit(0), - mInit2dYZ(false), - mForceTadapRefine(-1), mCutoff(-1) -{ - mpControl = new LbmControlData(); - -#if LBM_INCLUDE_TESTSOLVERS==1 - mpTest = new LbmTestdata(); - mMpNum = mMpIndex = 0; - mOrgSizeX = 0; - mOrgStartX = 0.; - mOrgEndX = 0.; -#endif // LBM_INCLUDE_TESTSOLVERS!=1 - mpIso = new IsoSurface( mIsoValue ); - - // init equilibrium dist. func - LbmFloat rho=1.0; - FORDF0 { - dfEquil[l] = this->getCollideEq( l,rho, 0.0, 0.0, 0.0); - } - dfEquil[dMass] = 1.; - dfEquil[dFfrac] = 1.; - dfEquil[dFlux] = FLUX_INIT; - - // init LES - int odm = 0; - for(int m=0; mlesCoeffDiag[m][l] = - this->lesCoeffOffdiag[m][l] = 0.0; - } - } - for(int m=0; mreadString("material_surf", matIso, "SimulationLbm","mpIso->material", false ); - mpIso->setMaterialName( matIso ); - mOutputSurfacePreview = mpSifAttrs->readInt("surfacepreview", mOutputSurfacePreview, "SimulationLbm","mOutputSurfacePreview", false ); - mTimeAdap = mpSifAttrs->readBool("timeadap", mTimeAdap, "SimulationLbm","mTimeAdap", false ); - mDomainBound = mpSifAttrs->readString("domainbound", mDomainBound, "SimulationLbm","mDomainBound", false ); - mDomainPartSlipValue = mpSifAttrs->readFloat("domainpartslip", mDomainPartSlipValue, "SimulationLbm","mDomainPartSlipValue", false ); - - mIsoWeightMethod= mpSifAttrs->readInt("isoweightmethod", mIsoWeightMethod, "SimulationLbm","mIsoWeightMethod", false ); - mInitSurfaceSmoothing = mpSifAttrs->readInt("initsurfsmooth", mInitSurfaceSmoothing, "SimulationLbm","mInitSurfaceSmoothing", false ); - mSmoothSurface = mpSifAttrs->readFloat("smoothsurface", mSmoothSurface, "SimulationLbm","mSmoothSurface", false ); - mSmoothNormals = mpSifAttrs->readFloat("smoothnormals", mSmoothNormals, "SimulationLbm","mSmoothNormals", false ); - mFsSurfGenSetting = mpSifAttrs->readInt("fssurfgen", mFsSurfGenSetting, "SimulationLbm","mFsSurfGenSetting", false ); - - // refinement - mMaxRefine = mRefinementDesired; - mMaxRefine = mpSifAttrs->readInt("maxrefine", mMaxRefine ,"LbmFsgrSolver", "mMaxRefine", false); - if(mMaxRefine<0) mMaxRefine=0; - if(mMaxRefine>FSGR_MAXNOOFLEVELS) mMaxRefine=FSGR_MAXNOOFLEVELS-1; - mDisableStandingFluidInit = mpSifAttrs->readInt("disable_stfluidinit", mDisableStandingFluidInit,"LbmFsgrSolver", "mDisableStandingFluidInit", false); - mInit2dYZ = mpSifAttrs->readBool("init2dyz", mInit2dYZ,"LbmFsgrSolver", "mInit2dYZ", false); - mForceTadapRefine = mpSifAttrs->readInt("forcetadaprefine", mForceTadapRefine,"LbmFsgrSolver", "mForceTadapRefine", false); - - // demo mode settings - mFVHeight = mpSifAttrs->readFloat("fvolheight", mFVHeight, "LbmFsgrSolver","mFVHeight", false ); - // FIXME check needed? - mFVArea = mpSifAttrs->readFloat("fvolarea", mFVArea, "LbmFsgrSolver","mFArea", false ); - - // debugging - skip some time... - double starttimeskip = 0.; - starttimeskip = mpSifAttrs->readFloat("forcestarttimeskip", starttimeskip, "LbmFsgrSolver","starttimeskip", false ); - mSimulationTime += starttimeskip; - if(starttimeskip>0.) debMsgStd("LbmFsgrSolver::parseStdAttrList",DM_NOTIFY,"Used starttimeskip="<parseTestdataAttrList(mpSifAttrs); -#ifdef ELBEEM_PLUGIN - mUseTestdata=1; // DEBUG -#endif // ELBEEM_PLUGIN - - mMpNum = mpSifAttrs->readInt("mpnum", mMpNum ,"LbmFsgrSolver", "mMpNum", false); - mMpIndex = mpSifAttrs->readInt("mpindex", mMpIndex ,"LbmFsgrSolver", "mMpIndex", false); - if(glob_mpactive) { - // used instead... - mMpNum = glob_mpnum; - mMpIndex = glob_mpindex; - } else { - glob_mpnum = mMpNum; - glob_mpindex = 0; - } - errMsg("LbmFsgrSolver::parseAttrList"," mpactive:"<0) { - mUseTestdata=1; // needed in this case... - } - - errMsg("LbmFsgrSolver::LBM_INCLUDE_TESTSOLVERS","Active, mUseTestdata:"<=2.) mUseTestdata=1; // equiv. to test solver check -#endif // LBM_INCLUDE_TESTSOLVERS!=1 - - mInitialCsmago = mpSifAttrs->readFloat("csmago", mInitialCsmago, "SimulationLbm","mInitialCsmago", false ); - // deprecated! - float mInitialCsmagoCoarse = 0.0; - mInitialCsmagoCoarse = mpSifAttrs->readFloat("csmago_coarse", mInitialCsmagoCoarse, "SimulationLbm","mInitialCsmagoCoarse", false ); -#if USE_LES==1 -#else // USE_LES==1 - debMsgStd("LbmFsgrSolver", DM_WARNING, "LES model switched off!",2); - mInitialCsmago = 0.0; -#endif // USE_LES==1 -} - - -/****************************************************************************** - * (part of enabling chapter 6 of "Free Surface Flows with Moving and Deforming Objects for LBM") - *****************************************************************************/ -void LbmFsgrSolver::setSurfGenSettings(short value) -{ - mFsSurfGenSetting = value; -} - - -/****************************************************************************** - * Initialize omegas and forces on all levels (for init/timestep change) - *****************************************************************************/ -void LbmFsgrSolver::initLevelOmegas() -{ - // no explicit settings - mOmega = mpParam->calculateOmega(mSimulationTime); - mGravity = vec2L( mpParam->calculateGravity(mSimulationTime) ); - mSurfaceTension = 0.; //mpParam->calculateSurfaceTension(); // unused - if(mInit2dYZ) { SWAPYZ(mGravity); } - - // check if last init was ok - LbmFloat gravDelta = norm(mGravity-mLastGravity); - //errMsg("ChannelAnimDebug","t:"<1)&&(mInitialCsmagogetTimestep(); - mLevel[i].lcsmago = fineCsmago; //CSMAGO_INITIAL; - mLevel[i].lcsmago_sqr = mLevel[i].lcsmago*mLevel[i].lcsmago; - mLevel[i].lcnu = (2.0* (1.0/mLevel[i].omega)-1.0) * (1.0/6.0); - } - - // init all sub levels - for(int i=mMaxRefine-1; i>=0; i--) { - //mLevel[i].omega = 2.0 * (mLevel[i+1].omega-0.5) + 0.5; - double nomega = 0.5 * ( (1.0/(double)mLevel[i+1].omega) -0.5) + 0.5; - nomega = 1.0/nomega; - mLevel[i].omega = (LbmFloat)nomega; - mLevel[i].timestep = 2.0 * mLevel[i+1].timestep; - mLevel[i].lcsmago = coarseCsmago; - mLevel[i].lcsmago_sqr = mLevel[i].lcsmago*mLevel[i].lcsmago; - mLevel[i].lcnu = (2.0* (1.0/mLevel[i].omega)-1.0) * (1.0/6.0); - } - - // for lbgk - mLevel[ mMaxRefine ].gravity = mGravity / mLevel[ mMaxRefine ].omega; - for(int i=mMaxRefine-1; i>=0; i--) { - // should be the same on all levels... - // for lbgk - mLevel[i].gravity = (mLevel[i+1].gravity * mLevel[i+1].omega) * 2.0 / mLevel[i].omega; - } - - mLastOmega = mOmega; - mLastGravity = mGravity; - // debug? invalidate old values... - mGravity = -100.0; - mOmega = -100.0; - - for(int i=0; i<=mMaxRefine; i++) { - if(!mSilent) { - errMsg("LbmFsgrSolver", "Level init "<0) { - mDfScaleUp = (mLevel[0 ].timestep/mLevel[0+1].timestep)* (1.0/mLevel[0 ].omega-1.0)/ (1.0/mLevel[0+1].omega-1.0); // yu - mDfScaleDown = (mLevel[0+1].timestep/mLevel[0 ].timestep)* (1.0/mLevel[0+1].omega-1.0)/ (1.0/mLevel[0 ].omega-1.0); // yu - } -} - - -/****************************************************************************** - * Init Solver (values should be read from config file) - *****************************************************************************/ - -/*! finish the init with config file values (allocate arrays...) */ -bool LbmFsgrSolver::initializeSolverMemory() -{ - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Init start... "<0) { - mSizex *= mCppfStage; - mSizey *= mCppfStage; - mSizez *= mCppfStage; - } - if(mFsSurfGenSetting==-1) { - // all on - mFsSurfGenSetting = - fssgNormal | fssgNoNorth | fssgNoSouth | fssgNoEast | - fssgNoWest | fssgNoTop | fssgNoBottom | fssgNoObs ; - } - - // size inits to force cubic cells and mult4 level dimensions - // and make sure we dont allocate too much... - bool memOk = false; - int orgSx = mSizex; - int orgSy = mSizey; - int orgSz = mSizez; - double sizeReduction = 1.0; - double memEstFromFunc = -1.0; - double memEstFine = -1.0; - string memreqStr(""); - bool firstMInit = true; - int minitTries=0; - while(!memOk) { - minitTries++; - initGridSizes( mSizex, mSizey, mSizez, - mvGeoStart, mvGeoEnd, mMaxRefine, PARALLEL); - - // MPT -#if LBM_INCLUDE_TESTSOLVERS==1 - if(firstMInit) { - mrSetup(); - } -#else - (void)firstMInit; -#endif // LBM_INCLUDE_TESTSOLVERS==1 - firstMInit=false; - - calculateMemreqEstimate( mSizex, mSizey, mSizez, - mMaxRefine, mFarFieldSize, &memEstFromFunc, &memEstFine, &memreqStr ); - - bool noLimit = false; - double memLimit = 0.; - string memLimStr("-"); - if(sizeof(void*)==4) { - // 32bit system, limit to 2GB - memLimit = 2.0* 1024.0*1024.0*1024.0; - memLimStr = string("2GB"); - } else { - // 64bit, just take 16GB as limit for now... - // memLimit = 16.0* 1024.0*1024.0*1024.0; - // memLimStr = string("16GB"); - noLimit = true; - } - - // restrict max. chunk of 1 mem block to 1GB for windows - bool memBlockAllocProblem = false; - double maxDefaultMemChunk = 2.*1024.*1024.*1024.; - //std::cerr<<" memEstFine "<< memEstFine <<" maxWin:" <maxWinMemChunk) { - memBlockAllocProblem = true; - } -#endif // WIN32 -#ifdef __APPLE__ - double maxMacMemChunk = 1200.*1024.*1024.; - if(memEstFine> maxMacMemChunk) { - memBlockAllocProblem = true; - } -#endif // Mac - if(sizeof(void*)==4 && memEstFine>maxDefaultMemChunk) { - // max memory chunk for 32bit systems 2gig - memBlockAllocProblem = true; - } - - if(!noLimit && (memEstFromFunc>memLimit || memBlockAllocProblem)) { - sizeReduction *= 0.9; - mSizex = (int)(orgSx * sizeReduction); - mSizey = (int)(orgSy * sizeReduction); - mSizez = (int)(orgSz * sizeReduction); - debMsgStd("LbmFsgrSolver::initialize",DM_WARNING,"initGridSizes: memory limit exceeded "<< - //memEstFromFunc<<"/"<setSize(mSizex, mSizey, mSizez); - if((minitTries>1)&&(glob_mpnum)) { errMsg("LbmFsgrSolver::initialize","Warning!!!!!!!!!!!!!!! Original gridsize changed........."); } - - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Definitions: " - <<"LBM_EPSILON="<setSimulationMaxSpeed(0.0); - if(mFVHeight>0.0) mpParam->setFluidVolumeHeight(mFVHeight); - mpParam->setTadapLevels( mMaxRefine+1 ); - - if(mForceTadapRefine>mMaxRefine) { - mpParam->setTadapLevels( mForceTadapRefine+1 ); - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Forcing a t-adap refine level of "<calculateAllMissingValues(mSimulationTime, false)) { - errFatal("LbmFsgrSolver::initialize","Fatal: failed to init parameters! Aborting...",SIMWORLD_INITERROR); - return false; - } - - - // init vectors - for(int i=0; i<=mMaxRefine; i++) { - mLevel[i].id = i; - mLevel[i].nodeSize = 0.0; - mLevel[i].simCellSize = 0.0; - mLevel[i].omega = 0.0; - mLevel[i].time = 0.0; - mLevel[i].timestep = 1.0; - mLevel[i].gravity = LbmVec(0.0); - mLevel[i].mprsCells[0] = NULL; - mLevel[i].mprsCells[1] = NULL; - mLevel[i].mprsFlags[0] = NULL; - mLevel[i].mprsFlags[1] = NULL; - - mLevel[i].avgOmega = 0.0; - mLevel[i].avgOmegaCnt = 0.0; - } - -#if PARALLEL == 1 - /* - // DG: this would be the correct sanity check, not the "hack below" */ - // if(( mSizey / mNumOMPThreads) * mNumOMPThreads != mSizey) { - // setNumOMPThreads(); - //} - if( mSizey < mNumOMPThreads ) { - setNumOMPThreads(mSizey); - } -#endif - - // init sizes - mLevel[mMaxRefine].lSizex = mSizex; - mLevel[mMaxRefine].lSizey = mSizey; - mLevel[mMaxRefine].lSizez = mSizez; - for(int i=mMaxRefine-1; i>=0; i--) { - mLevel[i].lSizex = mLevel[i+1].lSizex/2; - mLevel[i].lSizey = mLevel[i+1].lSizey/2; - mLevel[i].lSizez = mLevel[i+1].lSizez/2; - } - - // safety check - if(sizeof(CellFlagType) != CellFlagTypeSize) { - errFatal("LbmFsgrSolver::initialize","Fatal Error: CellFlagType has wrong size! Is:"<getCellSize(); - mLevel[ mMaxRefine ].lcellfactor = 1.0; - LONGINT rcellSize = (LONGINT)((LONGINT)((LONGINT)mLevel[mMaxRefine].lSizex*(LONGINT)mLevel[mMaxRefine].lSizey*(LONGINT)mLevel[mMaxRefine].lSizez) * (LONGINT)dTotalNum); - -#if COMPRESSGRIDS==0 - mLevel[ mMaxRefine ].mprsCells[0] = new LbmFloat[ rcellSize +4 ]; - mLevel[ mMaxRefine ].mprsCells[1] = new LbmFloat[ rcellSize +4 ]; - ownMemCheck += 2 * sizeof(LbmFloat) * (rcellSize+4); -#else // COMPRESSGRIDS==0 - LONGINT compressOffset = (LONGINT)((LONGINT)mLevel[mMaxRefine].lSizex * (LONGINT)mLevel[mMaxRefine].lSizey * (LONGINT)dTotalNum * 2); - // LONGINT tmp = ( (rcellSize +compressOffset +4)/(1024*1024) )*sizeof(LbmFloat); - // printf("Debug MEMMMM excee: %I64d, %I64d, %I64d, %d, %d\n", tmp, compressOffset, rcellSize, mLevel[mMaxRefine].lSizex, mLevel[mMaxRefine].lSizey ); - mLevel[ mMaxRefine ].mprsCells[1] = new LbmFloat[ rcellSize +compressOffset +4 ]; - mLevel[ mMaxRefine ].mprsCells[0] = mLevel[ mMaxRefine ].mprsCells[1]+compressOffset; - ownMemCheck += sizeof(LbmFloat) * (rcellSize +compressOffset +4); -#endif // COMPRESSGRIDS==0 - - if(!mLevel[ mMaxRefine ].mprsCells[1] || !mLevel[ mMaxRefine ].mprsCells[0]) { - errFatal("LbmFsgrSolver::initialize","Fatal: Couldnt allocate memory (1)! Aborting...",SIMWORLD_INITERROR); - return false; - } - - // +4 for safety ? - mLevel[ mMaxRefine ].mprsFlags[0] = new CellFlagType[ rcellSize/dTotalNum +4 ]; - mLevel[ mMaxRefine ].mprsFlags[1] = new CellFlagType[ rcellSize/dTotalNum +4 ]; - ownMemCheck += 2 * sizeof(CellFlagType) * (rcellSize/dTotalNum +4); - if(!mLevel[ mMaxRefine ].mprsFlags[1] || !mLevel[ mMaxRefine ].mprsFlags[0]) { - errFatal("LbmFsgrSolver::initialize","Fatal: Couldnt allocate memory (2)! Aborting...",SIMWORLD_INITERROR); - -#if COMPRESSGRIDS==0 - delete[] mLevel[ mMaxRefine ].mprsCells[0]; - delete[] mLevel[ mMaxRefine ].mprsCells[1]; -#else // COMPRESSGRIDS==0 - delete[] mLevel[ mMaxRefine ].mprsCells[1]; -#endif // COMPRESSGRIDS==0 - return false; - } - - LbmFloat lcfdimFac = 8.0; - if(LBMDIM==2) lcfdimFac = 4.0; - for(int i=mMaxRefine-1; i>=0; i--) { - mLevel[i].nodeSize = 2.0 * mLevel[i+1].nodeSize; - mLevel[i].simCellSize = 2.0 * mLevel[i+1].simCellSize; - mLevel[i].lcellfactor = mLevel[i+1].lcellfactor * lcfdimFac; - - if(LBMDIM==2){ mLevel[i].lSizez = 1; } // 2D - rcellSize = ((mLevel[i].lSizex*mLevel[i].lSizey*mLevel[i].lSizez) *dTotalNum); - mLevel[i].mprsFlags[0] = new CellFlagType[ rcellSize/dTotalNum +4 ]; - mLevel[i].mprsFlags[1] = new CellFlagType[ rcellSize/dTotalNum +4 ]; - ownMemCheck += 2 * sizeof(CellFlagType) * (rcellSize/dTotalNum +4); - mLevel[i].mprsCells[0] = new LbmFloat[ rcellSize +4 ]; - mLevel[i].mprsCells[1] = new LbmFloat[ rcellSize +4 ]; - ownMemCheck += 2 * sizeof(LbmFloat) * (rcellSize+4); - } - - // isosurface memory, use orig res values - if(mFarFieldSize>0.) { - ownMemCheck += (double)( (3*sizeof(int)+sizeof(float)) * ((mSizex+2)*(mSizey+2)*(mSizez+2)) ); - } else { - // ignore 3 int slices... - ownMemCheck += (double)( ( sizeof(float)) * ((mSizex+2)*(mSizey+2)*(mSizez+2)) ); - } - - // sanity check -#if ELBEEM_PLUGIN!=1 - if(ABS(1.0-ownMemCheck/memEstFromFunc)>0.01) { - errMsg("LbmFsgrSolver::initialize","Sanity Error - memory estimate is off! real:"<=0; i--) { - mLevel[i].lOffsx = mLevel[i].lSizex; - mLevel[i].lOffsy = mLevel[i].lOffsx*mLevel[i].lSizey; - mLevel[i].lOffsz = mLevel[i].lOffsy*mLevel[i].lSizez; - mLevel[i].setCurr = 0; - mLevel[i].setOther = 1; - mLevel[i].lsteps = 0; - mLevel[i].lmass = 0.0; - mLevel[i].lvolume = 0.0; - } - - // calc omega, force for all levels - initLevelOmegas(); - mMinTimestep = mpParam->getTimestep(); - mMaxTimestep = mpParam->getTimestep(); - - // init isosurf - mpIso->setIsolevel( mIsoValue ); -#if LBM_INCLUDE_TESTSOLVERS==1 - if(mUseTestdata) { - mpTest->setMaterialName( mpIso->getMaterialName() ); - delete mpIso; - mpIso = mpTest; - if(mpTest->mFarfMode>0) { // 3d off - mpTest->setIsolevel(-100.0); - } else { - mpTest->setIsolevel( mIsoValue ); - } - } -#endif // LBM_INCLUDE_TESTSOLVERS!=1 - // approximate feature size with mesh resolution - float featureSize = mLevel[ mMaxRefine ].nodeSize*0.5; - // smooth vars defined in solver_interface, set by simulation object - // reset for invalid values... - if((mSmoothSurface<0.)||(mSmoothSurface>50.)) mSmoothSurface = 1.; - if((mSmoothNormals<0.)||(mSmoothNormals>50.)) mSmoothNormals = 1.; - mpIso->setSmoothSurface( mSmoothSurface * featureSize ); - mpIso->setSmoothNormals( mSmoothNormals * featureSize ); - - // init iso weight values mIsoWeightMethod - int wcnt = 0; - float totw = 0.0; - for(int ak=-1;ak<=1;ak++) - for(int aj=-1;aj<=1;aj++) - for(int ai=-1;ai<=1;ai++) { - switch(mIsoWeightMethod) { - case 1: // light smoothing - mIsoWeight[wcnt] = sqrt(3.0) - sqrt( (LbmFloat)(ak*ak + aj*aj + ai*ai) ); - break; - case 2: // very light smoothing - mIsoWeight[wcnt] = sqrt(3.0) - sqrt( (LbmFloat)(ak*ak + aj*aj + ai*ai) ); - mIsoWeight[wcnt] *= mIsoWeight[wcnt]; - break; - case 3: // no smoothing - if(ai==0 && aj==0 && ak==0) mIsoWeight[wcnt] = 1.0; - else mIsoWeight[wcnt] = 0.0; - break; - default: // strong smoothing (=0) - mIsoWeight[wcnt] = 1.0; - break; - } - totw += mIsoWeight[wcnt]; - wcnt++; - } - for(int i=0; i<27; i++) mIsoWeight[i] /= totw; - - LbmVec isostart = vec2L(mvGeoStart); - LbmVec isoend = vec2L(mvGeoEnd); - int twodOff = 0; // 2d slices - if(LBMDIM==2) { - LbmFloat sn,se; - sn = isostart[2]+(isoend[2]-isostart[2])*0.5 - ((isoend[0]-isostart[0]) / (LbmFloat)(mSizex+1.0))*0.5; - se = isostart[2]+(isoend[2]-isostart[2])*0.5 + ((isoend[0]-isostart[0]) / (LbmFloat)(mSizex+1.0))*0.5; - isostart[2] = sn; - isoend[2] = se; - twodOff = 2; - } - int isosx = mSizex+2; - int isosy = mSizey+2; - int isosz = mSizez+2+twodOff; - - // MPT -#if LBM_INCLUDE_TESTSOLVERS==1 - //if( strstr( this->getName().c_str(), "mpfluid1" ) != NULL) { - if( (mMpNum>0) && (mMpIndex==0) ) { - //? mpindex==0 - // restore original value for node0 - isosx = mOrgSizeX + 2; - isostart[0] = mOrgStartX; - isoend[0] = mOrgEndX; - } - errMsg("LbmFsgrSolver::initialize", "MPT: gcon "<mGCMin.mSrcx,mpTest->mGCMin.mSrcy,mpTest->mGCMin.mSrcz)<<" dst" - << PRINT_VEC(mpTest->mGCMin.mDstx,mpTest->mGCMin.mDsty,mpTest->mGCMin.mDstz)<<" consize" - << PRINT_VEC(mpTest->mGCMin.mConSizex,mpTest->mGCMin.mConSizey,mpTest->mGCMin.mConSizez)<<" "); - errMsg("LbmFsgrSolver::initialize", "MPT: gcon "<mGCMax.mSrcx,mpTest->mGCMax.mSrcy,mpTest->mGCMax.mSrcz)<<" dst" - << PRINT_VEC(mpTest->mGCMax.mDstx,mpTest->mGCMax.mDsty,mpTest->mGCMax.mDstz)<<" consize" - << PRINT_VEC(mpTest->mGCMax.mConSizex,mpTest->mGCMax.mConSizey,mpTest->mGCMax.mConSizez)<<" "); -#endif // LBM_INCLUDE_TESTSOLVERS==1 - - errMsg(" SETISO ", "iso "<setStart( vec2G(isostart) ); - mpIso->setEnd( vec2G(isoend) ); - LbmVec isodist = isoend-isostart; - - int isosubs = mIsoSubdivs; - if(mFarFieldSize>1.) { - errMsg("LbmFsgrSolver::initialize","Warning - resetting isosubdivs, using fulledge!"); - isosubs = 1; - mpIso->setUseFulledgeArrays(true); - } - mpIso->setSubdivs(isosubs); - - mpIso->initializeIsosurface( isosx,isosy,isosz, vec2G(isodist) ); - - // reset iso field - for(int ak=0;akgetData(ai,aj,ak) = 0.0; } - - - /* init array (set all invalid first) */ - preinitGrids(); - for(int lev=0; lev<=mMaxRefine; lev++) { - FSGR_FORIJK_BOUNDS(lev) { - RFLAG(lev,i,j,k,0) = 0, RFLAG(lev,i,j,k,0) = 0; // reset for changeFlag usage - if(!mAllfluid) { - initEmptyCell(lev, i,j,k, CFEmpty, -1.0, -1.0); - } else { - initEmptyCell(lev, i,j,k, CFFluid, 1.0, 1.0); - } - } - } - - - if(LBMDIM==2) { - if(mOutputSurfacePreview) { - errMsg("LbmFsgrSolver::init","No preview in 2D allowed!"); - mOutputSurfacePreview = 0; } - } - if((glob_mpactive) && (glob_mpindex>0)) { - mOutputSurfacePreview = 0; - } - -#if LBM_USE_GUI==1 - if(mOutputSurfacePreview) { - errMsg("LbmFsgrSolver::init","No preview in GUI mode... mOutputSurfacePreview=0"); - mOutputSurfacePreview = 0; } -#endif // LBM_USE_GUI==1 - if(mOutputSurfacePreview) { - // same as normal one, but use reduced size - mpPreviewSurface = new IsoSurface( mIsoValue ); - mpPreviewSurface->setMaterialName( mpPreviewSurface->getMaterialName() ); - mpPreviewSurface->setIsolevel( mIsoValue ); - // usually dont display for rendering - mpPreviewSurface->setVisible( false ); - - mpPreviewSurface->setStart( vec2G(isostart) ); - mpPreviewSurface->setEnd( vec2G(isoend) ); - LbmVec pisodist = isoend-isostart; - LbmFloat pfac = mPreviewFactor; - mpPreviewSurface->initializeIsosurface( (int)(pfac*mSizex)+2, (int)(pfac*mSizey)+2, (int)(pfac*mSizez)+2, vec2G(pisodist) ); - //mpPreviewSurface->setName( getName() + "preview" ); - mpPreviewSurface->setName( "preview" ); - - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Preview with sizes "<<(pfac*mSizex)<<","<<(pfac*mSizey)<<","<<(pfac*mSizez)<<" enabled",10); - } - - // init defaults - mAvgNumUsedCells = 0; - mFixMass= 0.0; - return true; -} - -/*! init solver arrays */ -bool LbmFsgrSolver::initializeSolverGrids() { - /* init boundaries */ - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Boundary init...",10); - // init obstacles, and reinit time step size - initGeometryFlags(); - mLastSimTime = -1.0; - // TODO check for invalid cells? nitGenericTestCases(); - - // new - init noslip 1 everywhere... - // half fill boundary cells? - - CellFlagType domainBoundType = CFInvalid; - // TODO use normal object types instad... - if(mDomainBound.find(string("free")) != string::npos) { - domainBoundType = CFBnd | CFBndFreeslip; - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Domain Boundary Type: FreeSlip, value:"<size()); - domainBoundType |= (domainobj<<24); - //for(int i=0; i<(int)(domainobj+0); i++) { - //errMsg("GEOIN","i"<getName()); - //if((*mpGiObjects)[i] == mpIso) { //check... - //} - //} - //errMsg("GEOIN"," dm "<<(domainBoundType>>24)); - - for(int k=0;kgetName().c_str(), "vorttfluid" ) != NULL) && (LBMDIM==2)) { - errMsg("VORTT","init"); - int level=mMaxRefine; - int cx = mLevel[level].lSizex/2; - int cyo = mLevel[level].lSizey/2; - int sx = mLevel[level].lSizex/8; - int sy = mLevel[level].lSizey/8; - LbmFloat rho = 1.; - LbmFloat rhomass = 1.; - LbmFloat uFactor = 0.15; - LbmFloat vdist = 1.0; - - int cy1=cyo-(int)(vdist*sy); - int cy2=cyo+(int)(vdist*sy); - - //for(int j=cy-sy;jcalculateCellSize(); - if(LBMDIM==2) cspv[2] = 1.0; - inmCellCnt = 1; - double nrmMass = (double)mInitialMass / (double)(inmCellCnt) *cspv[0]*cspv[1]*cspv[2] * 1000.0; - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Initial Mass:"<=0; lev--) { - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Coarsening level "<setParticles(mpParticles, mPartDropMassSub); - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Iso Settings, subdivs="<getSubdivs()<<", partsize="<getSmoothSurface()<<","<getSmoothNormals()<<") ",10); - debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Init done ... ",10); - mInitDone = 1; - - // init fluid control - initCpdata(); - -#if LBM_INCLUDE_TESTSOLVERS==1 - initTestdata(); -#endif // ELBEEM_PLUGIN!=1 - // not inited? dont use... - if(mCutoff<0) mCutoff=0; - - initParticles(); - return true; -} - - - -// macros for mov obj init -#if LBMDIM==2 - -#define POS2GRID_CHECK(vec,n) \ - monTotal++;\ - int k=(int)( ((vec)[n][2]-iniPos[2])/dvec[2] +0.0); \ - if(k!=0) continue; \ - const int i=(int)( ((vec)[n][0]-iniPos[0])/dvec[0] +0.0); \ - if(i<=0) continue; \ - if(i>=mLevel[level].lSizex-1) continue; \ - const int j=(int)( ((vec)[n][1]-iniPos[1])/dvec[1] +0.0); \ - if(j<=0) continue; \ - if(j>=mLevel[level].lSizey-1) continue; \ - -#else // LBMDIM -> 3 -#define POS2GRID_CHECK(vec,n) \ - monTotal++;\ - const int i=(int)( ((vec)[n][0]-iniPos[0])/dvec[0] +0.0); \ - if(i<=0) continue; \ - if(i>=mLevel[level].lSizex-1) continue; \ - const int j=(int)( ((vec)[n][1]-iniPos[1])/dvec[1] +0.0); \ - if(j<=0) continue; \ - if(j>=mLevel[level].lSizey-1) continue; \ - const int k=(int)( ((vec)[n][2]-iniPos[2])/dvec[2] +0.0); \ - if(k<=0) continue; \ - if(k>=mLevel[level].lSizez-1) continue; \ - -#endif // LBMDIM - -// calculate object velocity from vert arrays in objvel vec -#define OBJVEL_CALC \ - LbmVec objvel = vec2L((mMOIVertices[n]-mMOIVerticesOld[n]) /dvec); { \ - const LbmFloat usqr = (objvel[0]*objvel[0]+objvel[1]*objvel[1]+objvel[2]*objvel[2])*1.5; \ - USQRMAXCHECK(usqr, objvel[0],objvel[1],objvel[2], mMaxVlen, mMxvx,mMxvy,mMxvz); \ - if(usqr>maxusqr) { \ - /* cutoff at maxVelVal */ \ - for(int jj=0; jj<3; jj++) { \ - if(objvel[jj]>0.) objvel[jj] = maxVelVal; \ - if(objvel[jj]<0.) objvel[jj] = -maxVelVal; \ - } \ - } } \ - if(ntype&(CFBndFreeslip)) { \ - const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); \ - /* const LbmVec oldov=objvel; */ /*DEBUG*/ \ - objvel = vec2L((*pNormals)[n]) *dp; \ - /* if((j==24)&&(n%5==2)) errMsg("FSBT","n"<size()); - ntlVec3Gfx dvec = ntlVec3Gfx(mLevel[level].nodeSize); //dvec*1.0; - // 2d display as rectangles - ntlVec3Gfx iniPos(0.0); - if(LBMDIM==2) { - dvec[2] = 1.0; - iniPos = (mvGeoStart + ntlVec3Gfx( 0.0, 0.0, (mvGeoEnd[2]-mvGeoStart[2])*0.5 ))-(dvec*0.0); - } else { - iniPos = (mvGeoStart + ntlVec3Gfx( 0.0 ))-(dvec*0.0); - } - - if( (int)mObjectMassMovnd.size() < numobjs) { - for(int i=mObjectMassMovnd.size(); igetGeoInitId() != mLbmInitId) skip=true; - if( (!staticInit) && (!obj->getIsAnimated()) ) skip=true; - if( ( staticInit) && ( obj->getIsAnimated()) ) skip=true; - if(skip) continue; - debMsgStd("LbmFsgrSolver::initMovingObstacles",DM_MSG," obj "<getName()<<" skip:"<getIsAnimated()<<" gid:"<getGeoInitId()<<" simgid:"<getGeoInitType()&FGI_ALLBOUNDS) || - ((obj->getGeoInitType()&FGI_FLUID) && staticInit) ) { - - otype = ntype = CFInvalid; - switch(obj->getGeoInitType()) { - /* case FGI_BNDPART: // old, use noslip for moving part/free objs - case FGI_BNDFREE: - if(!staticInit) { - errMsg("LbmFsgrSolver::initMovingObstacles","Warning - moving free/part slip objects NYI "<getName() ); - otype = ntype = CFBnd|CFBndNoslip; - } else { - if(obj->getGeoInitType()==FGI_BNDPART) otype = ntype = CFBnd|CFBndPartslip; - if(obj->getGeoInitType()==FGI_BNDFREE) otype = ntype = CFBnd|CFBndFreeslip; - } - break; - // off */ - case FGI_BNDPART: rhomass = BND_FILL; - otype = ntype = CFBnd|CFBndPartslip|(OId<<24); - break; - case FGI_BNDFREE: rhomass = BND_FILL; - otype = ntype = CFBnd|CFBndFreeslip|(OId<<24); - break; - // off */ - case FGI_BNDNO: rhomass = BND_FILL; - otype = ntype = CFBnd|CFBndNoslip|(OId<<24); - break; - case FGI_FLUID: - otype = ntype = CFFluid; - break; - case FGI_MBNDINFLOW: - otype = ntype = CFMbndInflow; - break; - case FGI_MBNDOUTFLOW: - otype = ntype = CFMbndOutflow; - break; - } - int wasActive = ((obj->getGeoActive(sourceTime)>0.)? 1:0); - int active = ((obj->getGeoActive(targetTime)>0.)? 1:0); - //errMsg("GEOACTT"," obj "<getName()<<" a:"<getGeoInitType()); continue; } - if((!active) && (otype&(CFMbndOutflow|CFMbndInflow)) ) continue; - - // copied from recalculateObjectSpeeds - mObjectSpeeds[OId] = vec2L(mpParam->calculateLattVelocityFromRw( vec2P( (*mpGiObjects)[OId]->getInitialVelocity(mSimulationTime) ))); - debMsgStd("LbmFsgrSolver::initMovingObstacles",DM_MSG,"id"<getName()<<" inivel set to "<< mObjectSpeeds[OId]<<", unscaled:"<< (*mpGiObjects)[OId]->getInitialVelocity(mSimulationTime) ,10 ); - - //vector tNormals; - vector *pNormals = NULL; - mMOINormals.clear(); - if(ntype&(CFBndFreeslip|CFBndPartslip)) { pNormals = &mMOINormals; } - - mMOIVertices.clear(); - if(obj->getMeshAnimated()) { - // do two full update - // TODO tNormals handling!? - mMOIVerticesOld.clear(); - obj->initMovingPointsAnim(sourceTime,mMOIVerticesOld, targetTime, mMOIVertices, pNormals, mLevel[mMaxRefine].nodeSize, mvGeoStart, mvGeoEnd); - monTrafo += mMOIVerticesOld.size(); - obj->applyTransformation(sourceTime, &mMOIVerticesOld,pNormals, 0, mMOIVerticesOld.size(), false ); - monTrafo += mMOIVertices.size(); - obj->applyTransformation(targetTime, &mMOIVertices,NULL /* no old normals needed */, 0, mMOIVertices.size(), false ); - } else { - // only do transform update - obj->getMovingPoints(mMOIVertices,pNormals); // mMOIVertices = mCachedMovPoints - mMOIVerticesOld = mMOIVertices; - // WARNING - assumes mSimulationTime is global!? - obj->applyTransformation(targetTime, &mMOIVertices,pNormals, 0, mMOIVertices.size(), false ); - monTrafo += mMOIVertices.size(); - - // correct flags from last position, but extrapolate - // velocity to next timestep - obj->applyTransformation(sourceTime, &mMOIVerticesOld, NULL /* no old normals needed */, 0, mMOIVerticesOld.size(), false ); - monTrafo += mMOIVerticesOld.size(); - } - - // object types - if(ntype&CFBnd){ - - // check if object is moving at all - if(obj->getIsAnimated()) { - ntlVec3Gfx objMaxVel = obj->calculateMaxVel(sourceTime,targetTime); - // FIXME? - if(normNoSqrt(objMaxVel)>0.0) { ntype |= CFBndMoving; } - // get old type - CHECK FIXME , timestep could have changed - cause trouble? - ntlVec3Gfx oldobjMaxVel = obj->calculateMaxVel(sourceTime - mpParam->getTimestep(),sourceTime); - if(normNoSqrt(oldobjMaxVel)>0.0) { otype |= CFBndMoving; } - } - if(obj->getMeshAnimated()) { ntype |= CFBndMoving; otype |= CFBndMoving; } - CellFlagType rflagnb[27]; - LbmFloat massCheck = 0.; - int massReinits=0; - bool fillCells = (mObjectMassMovnd[OId]<=-1.); - LbmFloat impactCorrFactor = obj->getGeoImpactFactor(targetTime); - - - // first pass - set new obs. cells - if(active) { - for(size_t n=0; n "< "< "<getName()<<" dccd massCheck="<getName()<<" verts"<getName()<<" inflow "<getCollideEq(l, iniRho,vel[0],vel[1],vel[2]); } - RAC(tcel, dMass) = RAC(tcel, dFfrac) = iniRho; - RAC(tcel, dFlux) = FLUX_INIT; - CellFlagType setFlag = CFInter; - changeFlag(level, i,j,k, workSet, setFlag); - mInitialMass += iniRho; - } - // second static init pass - if(staticInit) { - CellFlagType set2Flag = CFMbndInflow|(OId<<24); - for(size_t n=0; nsize()); - for(int o=0; ogetName()<<" type "<getGeoInitType()<<" anim"<getIsAnimated()<<" "<getVolumeInit() ,9); - if( - ((obj->getGeoInitType()&FGI_ALLBOUNDS) && (obj->getIsAnimated())) || - (obj->getVolumeInit()&VOLUMEINIT_SHELL) ) { - if(!obj->getMeshAnimated()) { - debMsgStd("LbmFsgrSolver::initMovingObstacles",DM_MSG," obj "<getName()<<" type "<getGeoInitType()<<" anim"<getIsAnimated()<<" "<getVolumeInit() ,9); - obj->initMovingPoints(mSimulationTime, mLevel[mMaxRefine].nodeSize); - } - } - } - - // max speed init - ntlVec3Gfx maxMovobjVelRw = getGeoMaxMovementVelocity( mSimulationTime, mpParam->getTimestep() ); - ntlVec3Gfx maxMovobjVel = vec2G( mpParam->calculateLattVelocityFromRw( vec2P( maxMovobjVelRw )) ); - mpParam->setSimulationMaxSpeed( norm(maxMovobjVel) + norm(mLevel[level].gravity) ); - LbmFloat allowMax = mpParam->getTadapMaxSpeed(); // maximum allowed velocity - debMsgStd("LbmFsgrSolver::initGeometryFlags",DM_MSG,"Maximum Velocity from geo init="<< maxMovobjVel <<" from mov. obj.="<setDesiredTimestep( newdt ); - mpParam->calculateAllMissingValues( mSimulationTime, mSilent ); - maxMovobjVel = vec2G( mpParam->calculateLattVelocityFromRw( vec2P(getGeoMaxMovementVelocity( - mSimulationTime, mpParam->getTimestep() )) )); - debMsgStd("LbmFsgrSolver::initGeometryFlags",DM_MSG,"New maximum Velocity from geo init="<< maxMovobjVel,5); - } - recalculateObjectSpeeds(); - // */ - - // init obstacles for first time step (requires obj speeds) - initMovingObstacles(true); - - /* set interface cells */ - ntlVec3Gfx pos,iniPos; // position of current cell - LbmFloat rhomass = 0.0; - CellFlagType ntype = CFInvalid; - int savedNodes = 0; - int OId = -1; - gfxReal distance; - - // 2d display as rectangles - if(LBMDIM==2) { - dvec[2] = 0.0; - iniPos =(mvGeoStart + ntlVec3Gfx( 0.0, 0.0, (mvGeoEnd[2]-mvGeoStart[2])*0.5 ))+(dvec*0.5); - //if(mInit2dYZ) { SWAPYZ(mGravity); for(int lev=0; lev<=mMaxRefine; lev++){ SWAPYZ( mLevel[lev].gravity ); } } - } else { - iniPos =(mvGeoStart + ntlVec3Gfx( 0.0 ))+(dvec*0.5); - } - - - // first init boundary conditions - // invalid cells are set to empty afterwards - // TODO use floop macros!? - for(int k= getForZMin1(); k< getForZMax1(level); ++k) { - for(int j=1;jgetGeoInitType() ){ - case FGI_MBNDINFLOW: - if(! pObj->getIsAnimated() ) { - rhomass = 1.0; - ntype = CFFluid | CFMbndInflow; - } else { - ntype = CFInvalid; - } - break; - case FGI_MBNDOUTFLOW: - if(! pObj->getIsAnimated() ) { - rhomass = 0.0; - ntype = CFEmpty|CFMbndOutflow; - } else { - ntype = CFInvalid; - } - break; - case FGI_BNDNO: - rhomass = BND_FILL; - ntype = CFBnd|CFBndNoslip; - break; - case FGI_BNDPART: - rhomass = BND_FILL; - ntype = CFBnd|CFBndPartslip; break; - case FGI_BNDFREE: - rhomass = BND_FILL; - ntype = CFBnd|CFBndFreeslip; break; - default: // warn here? - rhomass = BND_FILL; - ntype = CFBnd|CFBndNoslip; break; - } - } - if(ntype != CFInvalid) { - // initDefaultCell - if((ntype & CFMbndInflow) || (ntype & CFMbndOutflow) ) { } - ntype |= (OId<<24); // NEWTEST2 - initVelocityCell(level, i,j,k, ntype, rhomass, rhomass, mObjectSpeeds[OId] ); - } - - // walk along x until hit for following inits - if(distance<=-1.0) { distance = 100.0; } // FIXME dangerous - if(distance>=0.0) { - gfxReal dcnt=dvec[0]; - while(( dcnt< distance-dvec[0] )&&(i+1=0.0) { - gfxReal dcnt=dvec[0]; - while((dcnt< distance )&&(i+10 - - } - } - } // zmax - - // reset invalid to empty again - for(int k= getForZMin1(); k< getForZMax1(level); ++k) { - for(int j=1;j0) { - debMsgStd("Surface Smoothing init", DM_MSG, "Performing "<<(mInitSurfaceSmoothing)<<" smoothing timestep ",10); -#if COMPRESSGRIDS==1 - //errFatal("NYI","COMPRESSGRIDS mInitSurfaceSmoothing",SIMWORLD_INITERROR); return; -#endif // COMPRESSGRIDS==0 - } - for(int s=0; s1) { haveStandingFluid=(iindex); } \ - j = mLevel[mMaxRefine].lSizey; i=mLevel[mMaxRefine].lSizex; k=getForZMaxBnd(); \ - continue; \ - } - int gravIndex[3] = {0,0,0}; - int gravDir[3] = {1,1,1}; - int maxGravComp = 1; // by default y - int gravComp1 = 0; // by default y - int gravComp2 = 2; // by default y - if( ABS(mLevel[mMaxRefine].gravity[0]) > ABS(mLevel[mMaxRefine].gravity[1]) ){ maxGravComp = 0; gravComp1=1; gravComp2=2; } - if( ABS(mLevel[mMaxRefine].gravity[2]) > ABS(mLevel[mMaxRefine].gravity[0]) ){ maxGravComp = 2; gravComp1=0; gravComp2=1; } - - int gravIMin[3] = { 0 , 0 , 0 }; - int gravIMax[3] = { - mLevel[mMaxRefine].lSizex + 0, - mLevel[mMaxRefine].lSizey + 0, - mLevel[mMaxRefine].lSizez + 0 }; - if(LBMDIM==2) gravIMax[2] = 1; - - //int gravDir = 1; - if( mLevel[mMaxRefine].gravity[maxGravComp] > 0.0 ) { - // swap directions - int i=maxGravComp; - int tmp = gravIMin[i]; - gravIMin[i] = gravIMax[i] - 1; - gravIMax[i] = tmp - 1; - gravDir[i] = -1; - } -#define PRINTGDIRS \ - errMsg("Standing fp","X start="<>2); // not much use...? - //preinitSteps = 0; - debMsgStd("Standing fluid preinit", DM_MSG, "Performing "<initId(); - - if(getenv("ELBEEM_RAWDEBUGDUMP")) { - debMsgStd("LbmSolverInterface",DM_MSG,"Using env var ELBEEM_RAWDEBUGDUMP, mDumpRawText on",2); - mDumpRawText = true; - } - - if(getenv("ELBEEM_BINDEBUGDUMP")) { - debMsgStd("LbmSolverInterface",DM_MSG,"Using env var ELBEEM_RAWDEBUGDUMP, mDumpRawText on",2); - mDumpRawBinary = true; - } -} - -LbmSolverInterface::~LbmSolverInterface() -{ - if(mpSimTrafo) delete mpSimTrafo; -} - - -/****************************************************************************** - * initialize correct grid sizes given a geometric bounding box - * and desired grid resolutions, all params except maxrefine - * will be modified - *****************************************************************************/ -void initGridSizes(int &sizex, int &sizey, int &sizez, - ntlVec3Gfx &geoStart, ntlVec3Gfx &geoEnd, - int mMaxRefine, bool parallel) -{ - // fix size inits to force cubic cells and mult4 level dimensions - const int debugGridsizeInit = 1; - if(debugGridsizeInit) debMsgStd("initGridSizes",DM_MSG,"Called - size X:"<maxGridSize) maxGridSize = sizey; - if(sizez>maxGridSize) maxGridSize = sizez; - LbmFloat maxGeoSize = (geoEnd[0]-geoStart[0]); // get max size - if((geoEnd[1]-geoStart[1])>maxGeoSize) maxGeoSize = (geoEnd[1]-geoStart[1]); - if((geoEnd[2]-geoStart[2])>maxGeoSize) maxGeoSize = (geoEnd[2]-geoStart[2]); - // FIXME better divide max geo size by corresponding resolution rather than max? no prob for rx==ry==rz though - LbmFloat cellSize = (maxGeoSize / (LbmFloat)maxGridSize); - if(debugGridsizeInit) debMsgStd("initGridSizes",DM_MSG,"Start:"<=0; i--) { - currResx /= 2.0; - currResy /= 2.0; - currResz /= 2.0; - rcellSize = ((currResz*currResy*currResx) *ddTotalNum); - memCnt += (double)(sizeof(CellFlagType) * (rcellSize/ddTotalNum +4.0) *2.0); - memCnt += (double)(sizeof(LbmFloat) * (rcellSize +4.0) *2.0); - if(debugMemEst) debMsgStd("calculateMemreqEstimate",DM_MSG,"refine "<0.) { - memCnt += (double)( (3*sizeof(int)+sizeof(float)) * ((resx+2)*(resy+2)*(resz+2)) ); - } else { - // ignore 3 int slices... - memCnt += (double)( ( sizeof(float)) * ((resx+2)*(resy+2)*(resz+2)) ); - } - if(debugMemEst) debMsgStd("calculateMemreqEstimate",DM_MSG,"iso, mc:"<sfac){ memd /= sfac; sizeStr="KB"; } - if(memd>sfac){ memd /= sfac; sizeStr="MB"; } - if(memd>sfac){ memd /= sfac; sizeStr="GB"; } - if(memd>sfac){ memd /= sfac; sizeStr="TB"; } - - // return values - std::ostringstream ret; - if(memCnt< 1024.0*1024.0) { - // show full MBs - ret << (ceil(memd)); - } else { - // two digits for anything larger than MB - ret << (ceil(memd*100.0)/100.0); - } - ret << " "<< sizeStr; - *reqret = memCnt; - *reqstr = ret.str(); - //debMsgStd("LbmFsgrSolver::initialize",DM_MSG,"Required Grid memory: "<< memd <<" "<< sizeStr<<" ",4); -} - -void LbmSolverInterface::initDomainTrafo(float *mat) { - mpSimTrafo->initArrayCheck(mat); -} - -/*******************************************************************************/ -/*! parse a boundary flag string */ -CellFlagType LbmSolverInterface::readBoundaryFlagInt(string name, int defaultValue, string source,string target, bool needed) { - string val = mpSifAttrs->readString(name, "", source, target, needed); - if(!strcmp(val.c_str(),"")) { - // no value given... - return CFEmpty; - } - if(!strcmp(val.c_str(),"bnd_no")) { - return (CellFlagType)( CFBnd ); - } - if(!strcmp(val.c_str(),"bnd_free")) { - return (CellFlagType)( CFBnd ); - } - if(!strcmp(val.c_str(),"fluid")) { - /* might be used for some in/out flow cases */ - return (CellFlagType)( CFFluid ); - } - errMsg("LbmSolverInterface::readBoundaryFlagInt","Invalid value '"<readMat4Gfx("domain_trafo" , (*mpSimTrafo), "ntlBlenderDumper","mpSimTrafo", false, mpSimTrafo ); - - LbmVec sizeVec(mSizex,mSizey,mSizez); - sizeVec = vec2L( mpSifAttrs->readVec3d("size", vec2P(sizeVec), "LbmSolverInterface", "sizeVec", false) ); - mSizex = (int)sizeVec[0]; - mSizey = (int)sizeVec[1]; - mSizez = (int)sizeVec[2]; - // param needs size in any case - // test solvers might not have mpPara, though - if(mpParam) mpParam->setSize(mSizex, mSizey, mSizez ); - - mInitDensityGradient = mpSifAttrs->readBool("initdensitygradient", mInitDensityGradient,"LbmSolverInterface", "mInitDensityGradient", false); - mIsoValue = mpSifAttrs->readFloat("isovalue", mIsoValue, "LbmOptSolver","mIsoValue", false ); - - mDebugVelScale = mpSifAttrs->readFloat("debugvelscale", mDebugVelScale,"LbmSolverInterface", "mDebugVelScale", false); - mNodeInfoString = mpSifAttrs->readString("nodeinfo", mNodeInfoString, "SimulationLbm","mNodeInfoString", false ); - - mDumpVelocities = mpSifAttrs->readBool("dump_velocities", mDumpVelocities, "SimulationLbm","mDumpVelocities", false ); - if(getenv("ELBEEM_DUMPVELOCITIES")) { - int get = atoi(getenv("ELBEEM_DUMPVELOCITIES")); - if((get==0)||(get==1)) { - mDumpVelocities = get; - debMsgStd("LbmSolverInterface::parseAttrList",DM_NOTIFY,"Using envvar ELBEEM_DUMPVELOCITIES to set mDumpVelocities to "<readFloat("farfieldsize", mFarFieldSize,"LbmSolverInterface", "mFarFieldSize", false); - // old compat - float sizeScale = mpSifAttrs->readFloat("test_scale", 0.,"LbmTestdata", "mSizeScale", false); - if((mFarFieldSize<=0.)&&(sizeScale>0.)) { mFarFieldSize=sizeScale; errMsg("LbmTestdata","Warning - using mSizeScale..."); } - - mPartDropMassSub = mpSifAttrs->readFloat("part_dropmass", mPartDropMassSub,"LbmSolverInterface", "mPartDropMassSub", false); - - mCppfStage = mpSifAttrs->readInt("cppfstage", mCppfStage,"LbmSolverInterface", "mCppfStage", false); - mPartGenProb = mpSifAttrs->readFloat("partgenprob", mPartGenProb,"LbmFsgrSolver", "mPartGenProb", false); - mPartUsePhysModel = mpSifAttrs->readBool("partusephysmodel", mPartUsePhysModel,"LbmFsgrSolver", "mPartUsePhysModel", false); - mIsoSubdivs = mpSifAttrs->readInt("isosubdivs", mIsoSubdivs,"LbmFsgrSolver", "mIsoSubdivs", false); -} - - -/*******************************************************************************/ -/*! geometry initialization */ -/*******************************************************************************/ - -/*****************************************************************************/ -/*! init tree for certain geometry init */ -void LbmSolverInterface::initGeoTree() { - if(mpGlob == NULL) { errFatal("LbmSolverInterface::initGeoTree","Requires globals!",SIMWORLD_INITERROR); return; } - ntlScene *scene = mpGlob->getSimScene(); - mpGiObjects = scene->getObjects(); - mGiObjInside.resize( mpGiObjects->size() ); - mGiObjDistance.resize( mpGiObjects->size() ); - mGiObjSecondDist.resize( mpGiObjects->size() ); - for(size_t i=0; isize(); i++) { - if((*mpGiObjects)[i]->getGeoInitIntersect()) mAccurateGeoinit=true; - //debMsgStd("LbmSolverInterface::initGeoTree",DM_MSG,"id:"<getName() <<" gid:"<<(*mpGiObjects)[i]->getGeoInitId(), 9 ); - } - debMsgStd("LbmSolverInterface::initGeoTree",DM_MSG,"Accurate geo init: "<size() ,10); - - if(mpGiTree != NULL) delete mpGiTree; - char treeFlag = (1<<(this->mLbmInitId+4)); - mpGiTree = new ntlTree( -# if FSGR_STRICT_DEBUG!=1 - 15, 8, // TREEwarning - fixed values for depth & maxtriangles here... -# else // FSGR_STRICT_DEBUG==1 - 10, 20, // reduced/slower debugging values -# endif // FSGR_STRICT_DEBUG==1 - scene, treeFlag ); -} - -/*****************************************************************************/ -/*! destroy tree etc. when geometry init done */ -void LbmSolverInterface::freeGeoTree() { - if(mpGiTree != NULL) { - delete mpGiTree; - mpGiTree = NULL; - } -} - - -int globGeoInitDebug = 0; -int globGICPIProblems = 0; -/*****************************************************************************/ -/*! check for a certain flag type at position org */ -bool LbmSolverInterface::geoInitCheckPointInside(ntlVec3Gfx org, int flags, int &OId, gfxReal &distance, int shootDir) { - // shift ve ctors to avoid rounding errors - org += ntlVec3Gfx(0.0001); - OId = -1; - - // select shooting direction - ntlVec3Gfx dir = ntlVec3Gfx(1., 0., 0.); - if(shootDir==1) dir = ntlVec3Gfx(0., 1., 0.); - else if(shootDir==2) dir = ntlVec3Gfx(0., 0., 1.); - else if(shootDir==-2) dir = ntlVec3Gfx(0., 0., -1.); - else if(shootDir==-1) dir = ntlVec3Gfx(0., -1., 0.); - - ntlRay ray(org, dir, 0, 1.0, mpGlob); - bool done = false; - bool inside = false; - - vector giObjFirstHistSide; - giObjFirstHistSide.resize( mpGiObjects->size() ); - for(size_t i=0; iintersectX(ray,distance,normal, triIns, flags, true); - else mpGiTree->intersect(ray,distance,normal, triIns, flags, true); - if(triIns) { - ntlVec3Gfx norg = ray.getOrigin() + ray.getDirection()*distance; - LbmFloat orientation = dot(normal, dir); - OId = triIns->getObjectId(); - if(orientation<=0.0) { - // outside hit - normal *= -1.0; - mGiObjInside[OId]++; - if(giObjFirstHistSide[OId]==0) giObjFirstHistSide[OId] = 1; - if(globGeoInitDebug) errMsg("IIO"," oid:"<0) { - bool mess = false; - if((mGiObjInside[i]%2)==1) { - if(giObjFirstHistSide[i] != -1) mess=true; - } else { - if(giObjFirstHistSide[i] != 1) mess=true; - } - if(mess) { - //errMsg("IIIproblem","At "<0.0)) { - if( (distance<0.0) || // first intersection -> good - ((distance>0.0)&&(distance>mGiObjDistance[i])) // more than one intersection -> use closest one - ) { - distance = mGiObjDistance[i]; - OId = i; - inside = true; - } - } - } - if(!inside) { - distance = firstHit; - OId = firstOId; - } - if(globGeoInitDebug) errMsg("CHIII","i"<intersectX(ray,distance,normal, triIns, flags, true); - else mpGiTree->intersect(ray,distance,normal, triIns, flags, true); - if(triIns) { - // check outside intersect - LbmFloat orientation = dot(normal, dir); - if(orientation<=0.0) return false; - - OId = triIns->getObjectId(); - return true; - } - return false; - } -} -bool LbmSolverInterface::geoInitCheckPointInside(ntlVec3Gfx org, ntlVec3Gfx dir, int flags, int &OId, gfxReal &distance, const gfxReal halfCellsize, bool &thinHit, bool recurse) { - // shift ve ctors to avoid rounding errors - org += ntlVec3Gfx(0.0001); //? - OId = -1; - ntlRay ray(org, dir, 0, 1.0, mpGlob); - //int insCnt = 0; - bool done = false; - bool inside = false; - for(size_t i=0; iintersect(ray,distance,normal, triIns, flags, true); - if(triIns) { - ntlVec3Gfx norg = ray.getOrigin() + ray.getDirection()*distance; - LbmFloat orientation = dot(normal, dir); - OId = triIns->getObjectId(); - if(orientation<=0.0) { - // outside hit - normal *= -1.0; - //mGiObjDistance[OId] = -1.0; - //errMsg("IIO"," oid:"<0.0)) { - if( (distance<0.0) || // first intersection -> good - ((distance>0.0)&&(distance>mGiObjDistance[i])) // more than one intersection -> use closest one - ) { - distance = mGiObjDistance[i]; - OId = i; - inside = true; - } - } - } - // now check for thin hits - if(!inside) { - distance = -1.0; - for(size_t i=0; i=2)&&(mGiObjDistance[i]>0.0)&&(mGiObjSecondDist[i]>0.0)&& - (mGiObjDistance[i]<1.0*halfCellsize)&&(mGiObjSecondDist[i]<2.0*halfCellsize) ) { - if( (distance<0.0) || // first intersection -> good - ((distance>0.0)&&(distance>mGiObjDistance[i])) // more than one intersection -> use closest one - ) { - distance = mGiObjDistance[i]; - OId = i; - inside = true; - thinHit = true; - } - } - } - } - if(!inside) { - // check for hit in this cell, opposite to current dir (only recurse once) - if(recurse) { - gfxReal r_distance; - int r_OId; - bool ret = geoInitCheckPointInside(org, dir*-1.0, flags, r_OId, r_distance, halfCellsize, thinHit, false); - if((ret)&&(thinHit)) { - OId = r_OId; - distance = 0.0; - return true; - } - } - } - // really no hit... - if(!inside) { - distance = firstHit; - OId = firstOId; - /*if((mGiObjDistance[OId]>0.0)&&(mGiObjSecondDist[OId]>0.0)) { - const gfxReal thisdist = mGiObjSecondDist[OId]-mGiObjDistance[OId]; - // dont walk over this cell... - if(thisdistintersect(ray,distance,normal, triIns, flags, true); - if(triIns) { - // check outside intersect - LbmFloat orientation = dot(normal, dir); - if(orientation<=0.0) return false; - - OId = triIns->getObjectId(); - return true; - } - return false; - } -} - - -/*****************************************************************************/ -ntlVec3Gfx LbmSolverInterface::getGeoMaxMovementVelocity(LbmFloat simtime, LbmFloat stepsize) { - ntlVec3Gfx max(0.0); - if(mpGlob == NULL) return max; - // mpGiObjects has to be inited here... - - for(int i=0; i< (int)mpGiObjects->size(); i++) { - //errMsg("LbmSolverInterface::getGeoMaxMovementVelocity","i="<getName() ); // DEBUG - if( (*mpGiObjects)[i]->getGeoInitType() & (FGI_FLUID|FGI_MBNDINFLOW) ){ - //ntlVec3Gfx objMaxVel = obj->calculateMaxVel(sourceTime,targetTime); - ntlVec3Gfx orgvel = (*mpGiObjects)[i]->calculateMaxVel( simtime, simtime+stepsize ); - if( normNoSqrt(orgvel) > normNoSqrt(max) ) { max = orgvel; } - //errMsg("MVT","i"<getInitialVelocity(simtime)<<" o"<getInitialVelocity(simtime); - if( normNoSqrt(inivel) > normNoSqrt(max) ) { max = inivel; } - } - } - errMsg("LbmSolverInterface::getGeoMaxMovementVelocity", "max="<< max ); // DEBUG - return max; -} - - - - -/*******************************************************************************/ -/*! cell iteration functions */ -/*******************************************************************************/ - - - - -/*****************************************************************************/ -//! add cell to mMarkedCells list -void -LbmSolverInterface::addCellToMarkedList( CellIdentifierInterface *cid ) { - for(size_t i=0; iequal(cid) ) return; - //mMarkedCells[i]->setEnd(false); - } - mMarkedCells.push_back( cid ); - //cid->setEnd(true); -} - -/*****************************************************************************/ -//! marked cell iteration methods -CellIdentifierInterface* -LbmSolverInterface::markedGetFirstCell( ) { - if(mMarkedCells.size() > 0){ return mMarkedCells[0]; } - return NULL; -} - -CellIdentifierInterface* -LbmSolverInterface::markedAdvanceCell() { - mMarkedCellIndex++; - if(mMarkedCellIndex>=(int)mMarkedCells.size()) return NULL; - return mMarkedCells[mMarkedCellIndex]; -} - -void LbmSolverInterface::markedClearList() { - // FIXME free cids? - mMarkedCells.clear(); -} - -#if PARALLEL==1 -void LbmSolverInterface::setNumOMPThreads(int num_threads) { - mNumOMPThreads = num_threads; -} -#endif // PARALLEL==1 - -/*******************************************************************************/ -/*! string helper functions */ -/*******************************************************************************/ - - - -// 32k -string convertSingleFlag2String(CellFlagType cflag) { - CellFlagType flag = cflag; - if(flag == CFUnused ) return string("cCFUnused"); - if(flag == CFEmpty ) return string("cCFEmpty"); - if(flag == CFBnd ) return string("cCFBnd"); - if(flag == CFBndNoslip ) return string("cCFBndNoSlip"); - if(flag == CFBndFreeslip ) return string("cCFBndFreeSlip"); - if(flag == CFBndPartslip ) return string("cCFBndPartSlip"); - if(flag == CFNoInterpolSrc ) return string("cCFNoInterpolSrc"); - if(flag == CFFluid ) return string("cCFFluid"); - if(flag == CFInter ) return string("cCFInter"); - if(flag == CFNoNbFluid ) return string("cCFNoNbFluid"); - if(flag == CFNoNbEmpty ) return string("cCFNoNbEmpty"); - if(flag == CFNoDelete ) return string("cCFNoDelete"); - if(flag == CFNoBndFluid ) return string("cCFNoBndFluid"); - if(flag == CFGrNorm ) return string("cCFGrNorm"); - if(flag == CFGrFromFine ) return string("cCFGrFromFine"); - if(flag == CFGrFromCoarse ) return string("cCFGrFromCoarse"); - if(flag == CFGrCoarseInited ) return string("cCFGrCoarseInited"); - if(flag == CFMbndInflow ) return string("cCFMbndInflow"); - if(flag == CFMbndOutflow ) return string("cCFMbndOutflow"); - if(flag == CFInvalid ) return string("cfINVALID"); - - std::ostringstream mult; - int val = 0; - if(flag != 0) { - while(! (flag&1) ) { - flag = flag>>1; - val++; - } - } else { - val = -1; - } - if(val>=24) { - mult << "cfOID_" << (flag>>24) <<"_TYPE"; - } else { - mult << "cfUNKNOWN_" << val <<"_TYPE"; - } - return mult.str(); -} - -//! helper function to convert flag to string (for debuggin) -string convertCellFlagType2String( CellFlagType cflag ) { - int flag = cflag; - - const int jmax = sizeof(CellFlagType)*8; - bool somefound = false; - std::ostringstream mult; - mult << "["; - for(int j=0; j -#include "../gui/guifuncs.h" -#endif - -#include -#include "utilities.h" -#include "ntl_bsptree.h" -#include "ntl_geometryobject.h" -#include "parametrizer.h" -#include "attributes.h" -#include "isosurface.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -class ParticleTracer; -class ParticleObject; - -// use which fp-precision for LBM? 1=float, 2=double -#ifdef PRECISION_LBM_SINGLE -#define LBM_PRECISION 1 -#else -#ifdef PRECISION_LBM_DOUBLE -#define LBM_PRECISION 2 -#else -// default to floats -#define LBM_PRECISION 1 -#endif -#endif - -#if LBM_PRECISION==1 -/* low precision for LBM solver */ -typedef float LbmFloat; -typedef ntlVec3f LbmVec; -#define LBM_EPSILON (1e-5) -#else -/* standard precision for LBM solver */ -typedef double LbmFloat; -typedef ntlVec3d LbmVec; -#define LBM_EPSILON (1e-10) -#endif - -// long integer, needed e.g. for memory calculations -#ifndef USE_MSVC6FIXES -#define LONGINT long long int -#else -#define LONGINT _int64 -#endif - - -// default to 3dim -#ifndef LBMDIM -#define LBMDIM 3 -#endif // LBMDIM - -#if LBMDIM==2 -#define LBM_DFNUM 9 -#else -#define LBM_DFNUM 19 -#endif - -// conversions (lbm and parametrizer) -template inline LbmVec vec2L(T v) { return LbmVec(v[0],v[1],v[2]); } -template inline ParamVec vec2P(T v) { return ParamVec(v[0],v[1],v[2]); } - -template class ntlMatrix4x4; - - -// bubble id type -typedef int BubbleId; - -// basic cell type distinctions -#define CFUnused (1<< 0) -#define CFEmpty (1<< 1) -#define CFBnd (1<< 2) -#define CFMbndInflow (1<< 3) -#define CFMbndOutflow (1<< 4) -#define CFFluid (1<< 5) -#define CFInter (1<< 6) -// additional for fluid (needed separately for adaptive grids) -#define CFNoBndFluid (1<< 7) -#define CFNoDelete (1<< 8) - -// additional bnd add flags -#define CFBndNoslip (1<< 9) -#define CFBndFreeslip (1<<10) -#define CFBndPartslip (1<<11) -#define CFBndMoving (1<<12) - -// additional for fluid/interface -// force symmetry for flag reinit -#define CFNoInterpolSrc (1<<13) -#define CFNoNbFluid (1<<14) -#define CFNoNbEmpty (1<<15) - -// cell treated normally on coarser grids -#define CFGrNorm (1<<16) -#define CFGrCoarseInited (1<<17) - -// (the following values shouldnt overlap to ensure -// proper coarsening) -// border cells to be interpolated from finer grid -#define CFGrFromFine (1<<18) -// 32k aux border marker -#define CFGrToFine (1<<19) -// also needed on finest level -#define CFGrFromCoarse (1<<20) -// additional refinement tags (coarse grids only?) -// */ - -// above 24 is used to encode in/outflow object type -#define CFPersistMask (0xFF000000 | CFMbndInflow | CFMbndOutflow) -#define CFNoPersistMask (~CFPersistMask) - - -// nk -#define CFInvalid (CellFlagType)(1<<31) - -// use 32bit flag types -//#ifdef __x86_64__ - //typedef int cfINT32; -//#else - //typedef long cfINT32; -//#endif // defined (_IA64) -//#define CellFlagType cfINT32 -#define CellFlagType int -#define CellFlagTypeSize 4 - - -// aux. field indices (same for 2d) -#define dFfrac 19 -#define dMass 20 -#define dFlux 21 -// max. no. of cell values for 3d -#define dTotalNum 22 - - -/*****************************************************************************/ -/*! a single lbm cell */ -/* the template is only needed for - * dimension dependend constants e.g. - * number of df's in model */ -class LbmCellContents { - public: - LbmFloat df[ 27 ]; // be on the safe side here... - LbmFloat rho; - LbmVec vel; - LbmFloat mass; - CellFlagType flag; - BubbleId bubble; - LbmFloat ffrac; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:LbmCellContents") -#endif -}; - -/* struct for the coordinates of a cell in the grid */ -typedef struct { - int x,y,z; - int flag; // special handling? -} LbmPoint; - -/* struct for the coordinates of a cell in the grid */ -typedef struct { - char active; // bubble in use, oder may be overwritten? - LbmFloat volume; // volume of this bubble (0 vor atmosphere) - LbmFloat mass; // "mass" of bubble - int i,j,k; // index of a cell in the bubble -} LbmBubble; - - - - -//! choose which data to display -#define FLUIDDISPINVALID 0 -#define FLUIDDISPNothing 1 -#define FLUIDDISPCelltypes 2 -#define FLUIDDISPVelocities 3 -#define FLUIDDISPCellfills 4 -#define FLUIDDISPDensity 5 -#define FLUIDDISPGrid 6 -#define FLUIDDISPSurface 7 - - - -/*****************************************************************************/ -//! cell identifier interface -class CellIdentifierInterface { - public: - //! reset constructor - CellIdentifierInterface():mEnd(false) { }; - //! virtual destructor - virtual ~CellIdentifierInterface() {}; - - //! return node as string (with some basic info) - virtual string getAsString() = 0; - - //! compare cids - virtual bool equal(CellIdentifierInterface* other) = 0; - - //! set/get end flag for grid traversal (not needed for marked cells) - inline void setEnd(bool set){ mEnd = set; } - inline bool getEnd( ) { return mEnd; } - - //! has the grid been traversed? - bool mEnd; - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:CellIdentifierInterface") -#endif -}; - - - -/*****************************************************************************/ -/*! class defining abstract function interface */ -/* has to provide iterating functionality */ -class LbmSolverInterface -{ - public: - //! Constructor - LbmSolverInterface(); - //! Destructor - virtual ~LbmSolverInterface(); - //! id string of solver - virtual string getIdString() = 0; - - // multi step solver init - /*! finish the init with config file values (allocate arrays...) */ - virtual bool initializeSolverMemory() =0; - /*! init solver arrays */ - virtual bool initializeSolverGrids() =0; - /*! prepare actual simulation start, setup viz etc */ - virtual bool initializeSolverPostinit() =0; - - /*! notify object that dump is in progress (e.g. for field dump) */ - virtual void notifySolverOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename) = 0; - - /*! parse a boundary flag string */ - CellFlagType readBoundaryFlagInt(string name, int defaultValue, string source,string target, bool needed); - /*! parse standard attributes */ - void parseStdAttrList(); - /*! initilize variables fom attribute list (should at least call std parse) */ - virtual void parseAttrList() = 0; - - virtual void step() = 0; - virtual void prepareVisualization() { /* by default off */ }; - - /*! particle handling */ - virtual int initParticles() = 0; - virtual void advanceParticles() = 0; - /*! get surface object (NULL if no surface) */ - IsoSurface* getSurfaceGeoObj() { return mpIso; } - - /*! debug object display */ - virtual vector getDebugObjects() { vector empty(0); return empty; } - - /* surface generation settings */ - virtual void setSurfGenSettings(short value) = 0; - -#if LBM_USE_GUI==1 - /*! show simulation info */ - virtual void debugDisplay(int) = 0; -#endif - - /*! init tree for certain geometry init */ - void initGeoTree(); - /*! destroy tree etc. when geometry init done */ - void freeGeoTree(); - /*! check for a certain flag type at position org (needed for e.g. quadtree refinement) */ - bool geoInitCheckPointInside(ntlVec3Gfx org, int flags, int &OId, gfxReal &distance,int shootDir=0); - bool geoInitCheckPointInside(ntlVec3Gfx org, ntlVec3Gfx dir, int flags, int &OId, gfxReal &distance, - const gfxReal halfCellsize, bool &thinHit, bool recurse); - /*! set render globals, for scene/tree access */ - void setRenderGlobals(ntlRenderGlobals *glob) { mpGlob = glob; }; - /*! get max. velocity of all objects to initialize as fluid regions, and of all moving objects */ - ntlVec3Gfx getGeoMaxMovementVelocity(LbmFloat simtime, LbmFloat stepsize); - - /* rt interface functions */ - unsigned int getIsoVertexCount() { return mpIso->getIsoVertexCount(); } - unsigned int getIsoIndexCount() { return mpIso->getIsoIndexCount(); } - char* getIsoVertexArray() { return mpIso->getIsoVertexArray(); } - unsigned int *getIsoIndexArray() { return mpIso->getIsoIndexArray(); } - void triangulateSurface() { mpIso->triangulate(); } - - /* access functions */ - - /*! return grid sizes */ - int getSizeX( void ) { return mSizex; } - int getSizeY( void ) { return mSizey; } - int getSizeZ( void ) { return mSizez; } - /*! return grid sizes */ - void setSizeX( int ns ) { mSizex = ns; } - void setSizeY( int ns ) { mSizey = ns; } - void setSizeZ( int ns ) { mSizez = ns; } - /*! access fluid only simulation flag */ - void setAllfluid(bool set) { mAllfluid=set; } - bool getAllfluid() { return mAllfluid; } - - /*! set attr list pointer */ - void setAttrList(AttributeList *set) { mpSifAttrs = set; } - /*! Returns the attribute list pointer */ - inline AttributeList *getAttributeList() { return mpSifAttrs; } - /*! set sws attr list pointer */ - void setSwsAttrList(AttributeList *set) { mpSifSwsAttrs = set; } - inline AttributeList *getSwsAttributeList() { return mpSifSwsAttrs; } - - /*! set parametrizer pointer */ - inline void setParametrizer(Parametrizer *set) { mpParam = set; } - /*! get parametrizer pointer */ - inline Parametrizer *getParametrizer() { return mpParam; } - /*! get/set particle pointer */ - inline void setParticleTracer(ParticleTracer *set) { mpParticles = set; } - inline ParticleTracer *getParticleTracer() { return mpParticles; } - - /*! set density gradient init from e.g. init test cases */ - inline void setInitDensityGradient(bool set) { mInitDensityGradient = set; } - - /*! access geometry start vector */ - inline void setGeoStart(ntlVec3Gfx set) { mvGeoStart = set; } - inline ntlVec3Gfx getGeoStart() const { return mvGeoStart; } - - /*! access geometry end vector */ - inline void setGeoEnd(ntlVec3Gfx set) { mvGeoEnd = set; } - inline ntlVec3Gfx getGeoEnd() const { return mvGeoEnd; } - - /*! access geo init vars */ - inline void setLbmInitId(int set) { mLbmInitId = set; } - inline int getLbmInitId() const { return mLbmInitId; } - - /*! init domain transformation matrix from float array */ - void initDomainTrafo(float *mat); - /*! get domain transformation matrix to have object centered fluid vertices */ - inline ntlMatrix4x4 *getDomainTrafo() { return mpSimTrafo; } - - /*! access name string */ - inline void setName(string set) { mName = set; } - inline string getName() const { return mName; } - - /*! access string for node info debugging output */ - inline string getNodeInfoString() const { return mNodeInfoString; } - - /*! get panic flag */ - inline bool getPanic() { return mPanic; } - - //! set silent mode? - inline void setSilent(bool set){ mSilent = set; } - - //! set amount of surface/normal smoothing - inline void setSmoothing(float setss,float setns){ mSmoothSurface=setss; mSmoothNormals=setns; } - //! set amount of iso subdivisions - inline void setIsoSubdivs(int s){ mIsoSubdivs=s; } - //! set desired refinement - inline void setPreviewSize(int set){ mOutputSurfacePreview = set; } - //! set desired refinement - inline void setRefinementDesired(int set){ mRefinementDesired = set; } - - //! set/get dump velocities flag - inline void setDumpVelocities(bool set) { mDumpVelocities = set; } - inline bool getDumpVelocities() const { return mDumpVelocities; } - - //! set/get particle generation prob. - inline void setGenerateParticles(LbmFloat set) { mPartGenProb = set; } - inline LbmFloat getGenerateParticles() const { return mPartGenProb; } - - //! set/get dump velocities flag - inline void setDomainBound(string set) { mDomainBound = set; } - inline string getDomainBound() const { return mDomainBound; } - //! set/get dump velocities flag - inline void setDomainPartSlip(LbmFloat set) { mDomainPartSlipValue = set; } - inline LbmFloat getDomainPartSlip() const { return mDomainPartSlipValue; } - //! set/get far field size - inline void setFarFieldSize(LbmFloat set) { mFarFieldSize = set; } - inline LbmFloat getFarFieldSize() const { return mFarFieldSize; } - //! set/get cp stage - inline void setCpStage(int set) { mCppfStage = set; } - inline int getCpStage() const { return mCppfStage; } - //! set/get dump modes - inline void setDumpRawText(bool set) { mDumpRawText = set; } - inline bool getDumpRawText() const { return mDumpRawText; } - inline void setDumpRawBinary(bool set) { mDumpRawBinary = set; } - inline bool getDumpRawBinary() const { return mDumpRawBinary; } - inline void setDumpRawBinaryZip(bool set) { mDumpRawBinaryZip = set; } - inline bool getDumpRawBinaryZip() const { return mDumpRawBinaryZip; } - //! set/get debug vel scale - inline void setDebugVelScale(LbmFloat set) { mDebugVelScale = set; } - inline LbmFloat getDebugVelScale() const { return mDebugVelScale; } - - // cell iterator interface - - // cell id type - typedef CellIdentifierInterface* CellIdentifier; - - //! cell iteration methods - virtual CellIdentifierInterface* getFirstCell( ) = 0; - virtual void advanceCell( CellIdentifierInterface* ) = 0; - virtual bool noEndCell( CellIdentifierInterface* ) = 0; - //! clean up iteration, this should be called, when the iteration is not completely finished - virtual void deleteCellIterator( CellIdentifierInterface** ) = 0; - - //! find cell at a given position (returns NULL if not in domain) - virtual CellIdentifierInterface* getCellAt( ntlVec3Gfx pos ) = 0; - - //! return node information - virtual int getCellSet ( CellIdentifierInterface* ) = 0; - virtual ntlVec3Gfx getCellOrigin ( CellIdentifierInterface* ) = 0; - virtual ntlVec3Gfx getCellSize ( CellIdentifierInterface* ) = 0; - virtual int getCellLevel ( CellIdentifierInterface* ) = 0; - virtual LbmFloat getCellDensity ( CellIdentifierInterface*,int ) = 0; - virtual LbmVec getCellVelocity ( CellIdentifierInterface*,int ) = 0; - /*! get equilibrium distribution functions */ - virtual LbmFloat getEquilDf ( int ) = 0; - /*! redundant cell functions */ - virtual LbmFloat getCellDf ( CellIdentifierInterface* ,int set, int dir) = 0; - virtual LbmFloat getCellMass ( CellIdentifierInterface* ,int set) = 0; - virtual LbmFloat getCellFill ( CellIdentifierInterface* ,int set) = 0; - virtual CellFlagType getCellFlag ( CellIdentifierInterface* ,int set) = 0; - - /*! get velocity directly from position */ - virtual ntlVec3Gfx getVelocityAt(float x, float y, float z) = 0; - - // gui/output debugging functions -#if LBM_USE_GUI==1 - virtual void debugDisplayNode(int dispset, CellIdentifier cell ) = 0; - virtual void lbmDebugDisplay(int dispset) = 0; - virtual void lbmMarkedCellDisplay() = 0; -#endif // LBM_USE_GUI==1 - virtual void debugPrintNodeInfo(CellIdentifier cell, int forceSet=-1) = 0; - - // debugging cell marker functions - - //! add cell to mMarkedCells list - void addCellToMarkedList( CellIdentifierInterface *cid ); - //! marked cell iteration methods - CellIdentifierInterface* markedGetFirstCell( ); - CellIdentifierInterface* markedAdvanceCell(); - void markedClearList(); - -#if PARALLEL==1 - void setNumOMPThreads(int num_threads); -#endif // PARALLEL==1 - protected: - - /*! abort simulation on error... */ - bool mPanic; - - - /*! Size of the array in x,y,z direction */ - int mSizex, mSizey, mSizez; - /*! only fluid in sim? */ - bool mAllfluid; - - - /*! step counter */ - int mStepCnt; - - /*! mass change from one step to the next, for extreme cases fix globally */ - LbmFloat mFixMass; - - // deprecated param vars - /*! omega for lbm */ - LbmFloat mOmega; - /*! gravity strength in neg. z direction */ - LbmVec mGravity; - /*! Surface tension of the fluid */ - LbmFloat mSurfaceTension; - - - /* boundary inits */ - CellFlagType mBoundaryEast, mBoundaryWest, - mBoundaryNorth, mBoundarySouth, - mBoundaryTop, mBoundaryBottom; - - /*! initialization from config file done? */ - int mInitDone; - - /*! init density gradient? */ - bool mInitDensityGradient; - - /*! pointer to the attribute list, only pointer to obj attrs */ - AttributeList *mpSifAttrs; - AttributeList *mpSifSwsAttrs; - - /*! get parameters from this parametrize in finishInit */ - Parametrizer *mpParam; - //! store particle tracer - ParticleTracer *mpParticles; - - /*! number of particles lost so far */ - int mNumParticlesLost; - /*! number of particles lost so far */ - int mNumInvalidDfs; - /*! no of filled/emptied cells per time step */ - int mNumFilledCells, mNumEmptiedCells; - /*! counter number of used cells for performance */ - int mNumUsedCells; - /*! MLSUPS counter */ - LbmFloat mMLSUPS; - /*! debug - velocity output scaling factor */ - LbmFloat mDebugVelScale; - /*! string for node info debugging output */ - string mNodeInfoString; - - // geo init vars - // TODO deprecate SimulationObject vars - - /*! for display - start and end vectors for geometry */ - ntlVec3Gfx mvGeoStart, mvGeoEnd; - //! domain vertex trafos - ntlMatrix4x4 *mpSimTrafo; - - /*! perform accurate geometry init? */ - bool mAccurateGeoinit; - - /*! name of this lbm object (for debug output) */ - string mName; - - //! Mcubes object for surface reconstruction - IsoSurface *mpIso; - /*! isolevel value for marching cubes surface reconstruction */ - LbmFloat mIsoValue; - - //! debug output? - bool mSilent; - - /*! geometry init id, passed from ntl_geomclass */ - int mLbmInitId; - /*! tree object for geomerty initialization */ - ntlTree *mpGiTree; - /*! object vector for geo init */ - vector *mpGiObjects; - /*! inside which objects? */ - vector mGiObjInside; - /*! inside which objects? */ - vector mGiObjDistance; - vector mGiObjSecondDist; - /*! remember globals */ - ntlRenderGlobals *mpGlob; - - //! use refinement/coarsening? - int mRefinementDesired; - - //! output surface preview? if >0 yes, and use as reduzed size - int mOutputSurfacePreview; - LbmFloat mPreviewFactor; - - /*! enable surface and normals smoothing? */ - float mSmoothSurface; - float mSmoothNormals; - /*! isosurface subdivisions */ - int mIsoSubdivs; - - //! particle generation probability - LbmFloat mPartGenProb; - - //! dump velocities? - bool mDumpVelocities; - - // list for marked cells - vector mMarkedCells; - int mMarkedCellIndex; - - //! domain boundary free/no slip type - string mDomainBound; - //! part slip value for domain - LbmFloat mDomainPartSlipValue; - - // size of far field area - LbmFloat mFarFieldSize; - // amount of drop mass to subtract - LbmFloat mPartDropMassSub; - // use physical drop model for particles? - bool mPartUsePhysModel; - - //! test vars - // strength of applied force - LbmFloat mTForceStrength; - int mCppfStage; - - //! dumping modes - bool mDumpRawText; - bool mDumpRawBinary; - bool mDumpRawBinaryZip; - -#if PARALLEL==1 - int mNumOMPThreads; -#endif // PARALLEL==1 - -private: -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:LbmSolverInterface") -#endif -}; - - -// helper function to create consistent grid resolutions -void initGridSizes(int &mSizex, int &mSizey, int &mSizez, - ntlVec3Gfx &mvGeoStart, ntlVec3Gfx &mvGeoEnd, - int mMaxRefine, bool parallel); -// return the amount of memory required in total (reqret) -// and for the finest grid only (reqretFine, can be NULL) -void calculateMemreqEstimate(int resx,int resy,int resz, int refine, - float farfieldsize, double *reqret, double *reqretFine, string *reqstr); - -//! helper function to convert flag to string (for debuggin) -string convertCellFlagType2String( CellFlagType flag ); -string convertSingleFlag2String(CellFlagType cflag); - -#endif // LBMINTERFACE_H diff --git a/intern/elbeem/intern/solver_main.cpp b/intern/elbeem/intern/solver_main.cpp deleted file mode 100644 index 961bd44e08f..00000000000 --- a/intern/elbeem/intern/solver_main.cpp +++ /dev/null @@ -1,1723 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Standard LBM Factory implementation - * - *****************************************************************************/ - -#include "solver_class.h" -#include "solver_relax.h" -#include "particletracer.h" -#include "loop_tools.h" -#include "globals.h" - -#include -#include - -using std::isfinite; - -/*****************************************************************************/ -/*! perform a single LBM step */ -/*****************************************************************************/ - -double globdfcnt; -double globdfavg[19]; -double globdfmax[19]; -double globdfmin[19]; - -// simulation object interface -void LbmFsgrSolver::step() { - stepMain(); -} - -// lbm main step -void messageOutputForce(string from); -void LbmFsgrSolver::stepMain() { - myTime_t timestart = getTime(); - - initLevelOmegas(); - markedClearList(); // DMC clearMarkedCellsList - - // safety check, counter reset - mNumUsedCells = 0; - mNumInterdCells = 0; - mNumInvIfCells = 0; - - //debugOutNnl("LbmFsgrSolver::step : "<mMaxNoCells) mMaxNoCells = mNumUsedCells; - if(mNumUsedCells0)&&(mInitialMass>0.0)) { - LbmFloat mscale = mInitialMass/mCurrentMass; - - mscale = 1.0; - const LbmFloat dchh = 0.001; - if(mCurrentMassmInitialMass) mscale = 1.0-dchh; - - // use mass rescaling? - // with float precision this seems to be nonsense... - const bool MREnable = false; - - const int MSInter = 2; - static int mscount = 0; - if( (MREnable) && ((mLevel[0].lsteps%MSInter)== (MSInter-1)) && ( ABS( (mInitialMass/mCurrentMass)-1.0 ) > 0.01) && ( dsbits & (1<<(mMaxRefine-0)) ) ){ - // example: FORCE RESCALE MASS! ini:1843.5, cur:1817.6, f=1.01425 step:22153 levstep:5539 msc:37 - // mass rescale MASS RESCALE check - errMsg("MDTDD","\n\n"); - errMsg("MDTDD","FORCE RESCALE MASS! " - <<"ini:"<=0 ; lev--) { - //for(int workSet = 0; workSet<=1; workSet++) { - int wss = 0; - int wse = 1; -#if COMPRESSGRIDS==1 - if(lev== mMaxRefine) wss = wse = mLevel[lev].setCurr; -#endif // COMPRESSGRIDS==1 - for(int workSet = wss; workSet<=wse; workSet++) { // COMPRT - - FSGR_FORIJK1(lev) { - if( (RFLAG(lev,i,j,k, workSet) & (CFFluid| CFInter| CFGrFromCoarse| CFGrFromFine| CFGrNorm)) - ) { - - FORDF0 { QCELL(lev, i,j,k,workSet, l) *= mscale; } - QCELL(lev, i,j,k,workSet, dMass) *= mscale; - QCELL(lev, i,j,k,workSet, dFfrac) *= mscale; - - } else { - continue; - } - } - } - mLevel[lev].lmass *= mscale; - } - } - - mCurrentMass *= mscale; - }// if mass scale test */ - else { - // use current mass after full step for initial setting - if((mMaxRefine>0)&&(mInitialMass<=0.0) && (levsteps == (mMaxRefine+1))) { - mInitialMass = mCurrentMass; - debMsgStd("MDTDD",DM_NOTIFY,"Second Initial Mass Init: "<checkDumpTextPositions(mSimulationTime); - mpParticles->checkTrails(mSimulationTime); - } - - // one of the last things to do - adapt timestep - // was in fineAdvance before... - if(mTimeAdap) { - adaptTimestep(); - } // time adaptivity - - -#ifndef WIN32 - // good indicator for instabilities - if( (!isfinite(mMxvx)) || (!isfinite(mMxvy)) || (!isfinite(mMxvz)) ) { CAUSE_PANIC; } - if( (!isfinite(mCurrentMass)) || (!isfinite(mCurrentVolume)) ) { CAUSE_PANIC; } -#endif // WIN32 - - // output total step time - myTime_t timeend2 = getTime(); - double mdelta = (lastMass-mCurrentMass); - if(ABS(mdelta)<1e-12) mdelta=0.; - double effMLSUPS = ((double)mNumUsedCells / ((timeend2-timestart)/(double)1000.0) ) / (1000000.0); - if(mInitDone) { - if(effMLSUPS>10000){ effMLSUPS = -1; } - else { mAvgMLSUPS += effMLSUPS; mAvgMLSUPSCnt += 1.0; } // track average mlsups - } - - debMsgStd("LbmFsgrSolver::stepMain", DM_MSG, "mmpid:"<mPanic){ FSGR_FORIJK_BOUNDS(mMaxRefine) { \ - if(RFLAG(mMaxRefine,i,j,k,mLevel[mMaxRefine].setCurr)&(CFFluid|CFInter)) { \ - for(int l=0;lsetFluidVolumeHeight(mFVHeight); - } - - // advance time before timestep change - mSimulationTime += mpParam->getTimestep(); - // time adaptivity - mpParam->setSimulationMaxSpeed( sqrt(mMaxVlen / 1.5) ); - //if(mStartSymm) { checkSymmetry("step2"); } // DEBUG - if(!mSilent){ debMsgStd("fineAdvance",DM_NOTIFY," stepped from "<cDfNum; l++) { - LbmFloat df = QCELL(lev, i,j,k,workSet, l); - compRho += df; - compUx += (this->dfDvecX[l]*df); - compUy += (this->dfDvecY[l]*df); - compUz += (this->dfDvecZ[l]*df); - } - LbmVec u(compUx,compUy,compUz); - LbmFloat nu = norm(u); - if(nu>maxUlen) { - maxU = u; - maxUlen = nu; - mi=i; mj=j; mk=k; - } - if(compRho>maxRho) { - maxRho=compRho; - ri=i; rj=j; rk=k; - } - } else { - continue; - } - } - - errMsg("MAXVELCHECK"," at "<mFarfMode>0)) { return; } -# endif // ELBEEM_PLUGIN!=1 - - // main loop region - const bool doReduce = true; - const int gridLoopBound=1; - int calcNumInvIfCells = 0; - LbmFloat calcInitialMass = 0; - GRID_REGION_INIT(); -#if PARALLEL==1 - const int gDebugLevel = ::gDebugLevel; -#pragma omp parallel num_threads(mNumOMPThreads) \ - reduction(+: \ - calcCurrentMass,calcCurrentVolume, \ - calcCellsFilled,calcCellsEmptied, \ - calcNumUsedCells,calcNumInvIfCells,calcInitialMass) - GRID_REGION_START(); -#else // PARALLEL==1 - GRID_REGION_START(); -#endif // PARALLEL==1 - - // local to main - CellFlagType nbflag[LBM_DFNUM]; - int oldFlag, newFlag, nbored; - LbmFloat m[LBM_DFNUM]; - LbmFloat rho, ux, uy, uz, tmp, usqr; - - // smago vars - LbmFloat lcsmqadd, lcsmeq[LBM_DFNUM], lcsmomega; - - // ifempty cell conversion flags - bool iffilled, ifemptied; - LbmFloat nbfracs[LBM_DFNUM]; // ffracs of neighbors - int recons[LBM_DFNUM]; // reconstruct this DF? - int numRecons; // how many are reconstructed? - - LbmFloat mass=0., change=0., lcsmqo=0.; - rho= ux= uy= uz= usqr= tmp= 0.; - lcsmqadd = lcsmomega = 0.; - FORDF0{ lcsmeq[l] = 0.; } - - // --- - // now stream etc. - // use //template functions for 2D/3D - - GRID_LOOP_START(); - // loop start - // stream from current set to other, then collide and store - //errMsg("l2"," at "<>24; - if(!isValid) { - // make new if cell - const LbmVec vel(mObjectSpeeds[OId]); - // TODO add OPT3D treatment - FORDF0 { RAC(tcel, l) = this->getCollideEq(l, iniRho,vel[0],vel[1],vel[2]); } - RAC(tcel, dMass) = RAC(tcel, dFfrac) = iniRho; - RAC(tcel, dFlux) = FLUX_INIT; - changeFlag(lev, i,j,k, TSET(lev), CFInter); - calcCurrentMass += iniRho; - calcCurrentVolume += 1.0; - calcNumUsedCells++; - calcInitialMass += iniRho; - // dont treat cell until next step - continue; - } - } - else // these are exclusive - if(oldFlag & (CFMbndOutflow)) { - int isnotValid = oldFlag & (CFFluid); - if(isnotValid) { - // remove fluid cells, shouldnt be here anyway - LbmFloat fluidRho = m[0]; FORDF1 { fluidRho += m[l]; } - calcInitialMass -= fluidRho; - const LbmFloat iniRho = 0.0; - RAC(tcel, dMass) = RAC(tcel, dFfrac) = iniRho; - RAC(tcel, dFlux) = FLUX_INIT; - changeFlag(lev, i,j,k, TSET(lev), CFInter); - - // same as ifemptied for if below - LbmPoint oemptyp; oemptyp.flag = 0; - oemptyp.x = i; oemptyp.y = j; oemptyp.z = k; - LIST_EMPTY(oemptyp); - calcCellsEmptied++; - continue; - } - } - - if(oldFlag & (CFBnd|CFEmpty|CFGrFromCoarse|CFUnused)) { - *pFlagDst = oldFlag; - continue; - } - /*if( oldFlag & CFNoBndFluid ) { // TEST ME FASTER? - OPTIMIZED_STREAMCOLLIDE; PERFORM_USQRMAXCHECK; - RAC(tcel,dFfrac) = 1.0; - *pFlagDst = (CellFlagType)oldFlag; // newFlag; - calcCurrentMass += rho; calcCurrentVolume += 1.0; - calcNumUsedCells++; - continue; - }// TEST ME FASTER? */ - - // only neighbor flags! not own flag - nbored = 0; - -#if OPT3D==0 - FORDF1 { - nbflag[l] = RFLAG_NB(lev, i,j,k,SRCS(lev),l); - nbored |= nbflag[l]; - } -#else - nbflag[dSB] = *(pFlagSrc + (-mLevel[lev].lOffsy+-mLevel[lev].lOffsx)); nbored |= nbflag[dSB]; - nbflag[dWB] = *(pFlagSrc + (-mLevel[lev].lOffsy+-1)); nbored |= nbflag[dWB]; - nbflag[ dB] = *(pFlagSrc + (-mLevel[lev].lOffsy)); nbored |= nbflag[dB]; - nbflag[dEB] = *(pFlagSrc + (-mLevel[lev].lOffsy+ 1)); nbored |= nbflag[dEB]; - nbflag[dNB] = *(pFlagSrc + (-mLevel[lev].lOffsy+ mLevel[lev].lOffsx)); nbored |= nbflag[dNB]; - - nbflag[dSW] = *(pFlagSrc + (-mLevel[lev].lOffsx+-1)); nbored |= nbflag[dSW]; - nbflag[ dS] = *(pFlagSrc + (-mLevel[lev].lOffsx)); nbored |= nbflag[dS]; - nbflag[dSE] = *(pFlagSrc + (-mLevel[lev].lOffsx+ 1)); nbored |= nbflag[dSE]; - - nbflag[ dW] = *(pFlagSrc + (-1)); nbored |= nbflag[dW]; - nbflag[ dE] = *(pFlagSrc + ( 1)); nbored |= nbflag[dE]; - - nbflag[dNW] = *(pFlagSrc + ( mLevel[lev].lOffsx+-1)); nbored |= nbflag[dNW]; - nbflag[ dN] = *(pFlagSrc + ( mLevel[lev].lOffsx)); nbored |= nbflag[dN]; - nbflag[dNE] = *(pFlagSrc + ( mLevel[lev].lOffsx+ 1)); nbored |= nbflag[dNE]; - - nbflag[dST] = *(pFlagSrc + ( mLevel[lev].lOffsy+-mLevel[lev].lOffsx)); nbored |= nbflag[dST]; - nbflag[dWT] = *(pFlagSrc + ( mLevel[lev].lOffsy+-1)); nbored |= nbflag[dWT]; - nbflag[ dT] = *(pFlagSrc + ( mLevel[lev].lOffsy)); nbored |= nbflag[dT]; - nbflag[dET] = *(pFlagSrc + ( mLevel[lev].lOffsy+ 1)); nbored |= nbflag[dET]; - nbflag[dNT] = *(pFlagSrc + ( mLevel[lev].lOffsy+ mLevel[lev].lOffsx)); nbored |= nbflag[dNT]; - // */ -#endif - - // pointer to destination cell - calcNumUsedCells++; - - // FLUID cells - if( oldFlag & CFFluid ) { - // only standard fluid cells (with nothing except fluid as nbs - - if(oldFlag&CFMbndInflow) { - // force velocity for inflow, necessary to have constant direction of flow - // FIXME , test also set interface cells? - const int OId = oldFlag>>24; - //? DEFAULT_STREAM; - //const LbmFloat fluidRho = 1.0; - // for submerged inflows, streaming would have to be performed... - LbmFloat fluidRho = m[0]; FORDF1 { fluidRho += m[l]; } - const LbmVec vel(mObjectSpeeds[OId]); - ux=vel[0], uy=vel[1], uz=vel[2]; - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); - FORDF0 { RAC(tcel, l) = this->getCollideEq(l, fluidRho,ux,uy,uz); } - rho = fluidRho; - //errMsg("INFLOW_DEBUG","std at "<dfInv[(l)] ] - - // update mass - // only do boundaries for fluid cells, and interface cells without - // any fluid neighbors (assume that interface cells _with_ fluid - // neighbors are affected enough by these) - // which Df's have to be reconstructed? - // for fluid cells - just the f_i difference from streaming to empty cells ---- - numRecons = 0; - bool onlyBndnb = ((!(oldFlag&CFNoBndFluid))&&(oldFlag&CFNoNbFluid)&&(nbored&CFBndNoslip)); - //onlyBndnb = false; // DEBUG test off - - FORDF1 { // dfl loop - recons[l] = 0; - nbfracs[l] = 0.0; - // finally, "normal" interface cells ---- - if( nbflag[l]&(CFFluid|CFBnd) ) { // NEWTEST! FIXME check!!!!!!!!!!!!!!!!!! - change = nbdf(l) - MYDF(l); - } - // interface cells - distuingish cells that shouldn't fill/empty - else if( nbflag[l] & CFInter ) { - - LbmFloat mynbfac,nbnbfac; - // NEW TEST t1 - // t2 -> off - if((oldFlag&CFNoBndFluid)&&(nbflag[l]&CFNoBndFluid)) { - mynbfac = QCELL_NB(lev, i,j,k,SRCS(lev),l, dFlux) / QCELL(lev, i,j,k,SRCS(lev), dFlux); - nbnbfac = 1.0/mynbfac; - onlyBndnb = false; - } else { - mynbfac = nbnbfac = 1.0; // switch calc flux off - goto changeDefault; // NEWSURFT - //change = 0.; goto changeDone; // NEWSURFT - } - //mynbfac = nbnbfac = 1.0; // switch calc flux off t3 - - // perform interface case handling - if ((oldFlag|nbflag[l])&(CFNoNbFluid|CFNoNbEmpty)) { - switch (oldFlag&(CFNoNbFluid|CFNoNbEmpty)) { - case 0: - // we are a normal cell so... - switch (nbflag[l]&(CFNoNbFluid|CFNoNbEmpty)) { - case CFNoNbFluid: - // just fill current cell = empty neighbor - change = nbnbfac*nbdf(l) ; goto changeDone; - case CFNoNbEmpty: - // just empty current cell = fill neighbor - change = - mynbfac*MYDF(l) ; goto changeDone; - } - break; - - case CFNoNbFluid: - // we dont have fluid nb's so... - switch (nbflag[l]&(CFNoNbFluid|CFNoNbEmpty)) { - case 0: - case CFNoNbEmpty: - // we have no fluid nb's -> just empty - change = - mynbfac*MYDF(l) ; goto changeDone; - } - break; - - case CFNoNbEmpty: - // we dont have empty nb's so... - switch (nbflag[l]&(CFNoNbFluid|CFNoNbEmpty)) { - case 0: - case CFNoNbFluid: - // we have no empty nb's -> just fill - change = nbnbfac*nbdf(l); goto changeDone; - } - break; - }} // inter-inter exchange - - changeDefault: ; - // just do normal mass exchange... - change = ( nbnbfac*nbdf(l) - mynbfac*MYDF(l) ) ; - changeDone: ; - nbfracs[l] = QCELL_NB(lev, i,j,k, SRCS(lev),l, dFfrac); - if(nbfracs[l]<0.) nbfracs[l] = 0.; // NEWSURFT - change *= (myfrac + nbfracs[l]) * 0.5; - } // the other cell is interface - - // last alternative - reconstruction in this direction - else { - // empty + bnd case - recons[l] = 1; - numRecons++; - change = 0.0; - } - - // modify mass at SRCS - mass += change; - } // l - // normal interface, no if empty/fluid - - // computenormal - LbmFloat surfaceNormal[3]; - computeFluidSurfaceNormal(ccel,pFlagSrc, surfaceNormal); - - if( (ABS(surfaceNormal[0])+ABS(surfaceNormal[1])+ABS(surfaceNormal[2])) > LBM_EPSILON) { - // normal ok and usable... - FORDF1 { - if( (this->dfDvecX[l]*surfaceNormal[0] + this->dfDvecY[l]*surfaceNormal[1] + this->dfDvecZ[l]*surfaceNormal[2]) // dot Dvec,norml - > LBM_EPSILON) { - recons[l] = 2; - numRecons++; - } - } - } - - // calculate macroscopic cell values - LbmFloat oldUx, oldUy, oldUz; - LbmFloat oldRho; // OLD rho = ccel->rho; -# define REFERENCE_PRESSURE 1.0 // always atmosphere... -# if OPT3D==0 - oldRho=RAC(ccel,0); - oldUx = oldUy = oldUz = 0.0; - for(int l=1; lcDfNum; l++) { - oldRho += RAC(ccel,l); - oldUx += (this->dfDvecX[l]*RAC(ccel,l)); - oldUy += (this->dfDvecY[l]*RAC(ccel,l)); - oldUz += (this->dfDvecZ[l]*RAC(ccel,l)); - } - // reconstruct dist funcs from empty cells - FORDF1 { - if(recons[ l ]) { - m[ this->dfInv[l] ] = - this->getCollideEq(l, REFERENCE_PRESSURE, oldUx,oldUy,oldUz) + - this->getCollideEq(this->dfInv[l], REFERENCE_PRESSURE, oldUx,oldUy,oldUz) - - MYDF( l ); - } - } - ux=oldUx, uy=oldUy, uz=oldUz; // no local vars, only for usqr - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); // needed later on -# else // OPT3D==0 - oldRho = + RAC(ccel,dC) + RAC(ccel,dN ) - + RAC(ccel,dS ) + RAC(ccel,dE ) - + RAC(ccel,dW ) + RAC(ccel,dT ) - + RAC(ccel,dB ) + RAC(ccel,dNE) - + RAC(ccel,dNW) + RAC(ccel,dSE) - + RAC(ccel,dSW) + RAC(ccel,dNT) - + RAC(ccel,dNB) + RAC(ccel,dST) - + RAC(ccel,dSB) + RAC(ccel,dET) - + RAC(ccel,dEB) + RAC(ccel,dWT) - + RAC(ccel,dWB); - - oldUx = + RAC(ccel,dE) - RAC(ccel,dW) - + RAC(ccel,dNE) - RAC(ccel,dNW) - + RAC(ccel,dSE) - RAC(ccel,dSW) - + RAC(ccel,dET) + RAC(ccel,dEB) - - RAC(ccel,dWT) - RAC(ccel,dWB); - - oldUy = + RAC(ccel,dN) - RAC(ccel,dS) - + RAC(ccel,dNE) + RAC(ccel,dNW) - - RAC(ccel,dSE) - RAC(ccel,dSW) - + RAC(ccel,dNT) + RAC(ccel,dNB) - - RAC(ccel,dST) - RAC(ccel,dSB); - - oldUz = + RAC(ccel,dT) - RAC(ccel,dB) - + RAC(ccel,dNT) - RAC(ccel,dNB) - + RAC(ccel,dST) - RAC(ccel,dSB) - + RAC(ccel,dET) - RAC(ccel,dEB) - + RAC(ccel,dWT) - RAC(ccel,dWB); - - (void)oldRho; - - // now reconstruction - ux=oldUx, uy=oldUy, uz=oldUz; // no local vars, only for usqr - rho = REFERENCE_PRESSURE; - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); // needed later on - if(recons[dN ]) { m[dS ] = EQN + EQS - MYDF(dN ); } - if(recons[dS ]) { m[dN ] = EQS + EQN - MYDF(dS ); } - if(recons[dE ]) { m[dW ] = EQE + EQW - MYDF(dE ); } - if(recons[dW ]) { m[dE ] = EQW + EQE - MYDF(dW ); } - if(recons[dT ]) { m[dB ] = EQT + EQB - MYDF(dT ); } - if(recons[dB ]) { m[dT ] = EQB + EQT - MYDF(dB ); } - if(recons[dNE]) { m[dSW] = EQNE + EQSW - MYDF(dNE); } - if(recons[dNW]) { m[dSE] = EQNW + EQSE - MYDF(dNW); } - if(recons[dSE]) { m[dNW] = EQSE + EQNW - MYDF(dSE); } - if(recons[dSW]) { m[dNE] = EQSW + EQNE - MYDF(dSW); } - if(recons[dNT]) { m[dSB] = EQNT + EQSB - MYDF(dNT); } - if(recons[dNB]) { m[dST] = EQNB + EQST - MYDF(dNB); } - if(recons[dST]) { m[dNB] = EQST + EQNB - MYDF(dST); } - if(recons[dSB]) { m[dNT] = EQSB + EQNT - MYDF(dSB); } - if(recons[dET]) { m[dWB] = EQET + EQWB - MYDF(dET); } - if(recons[dEB]) { m[dWT] = EQEB + EQWT - MYDF(dEB); } - if(recons[dWT]) { m[dEB] = EQWT + EQEB - MYDF(dWT); } - if(recons[dWB]) { m[dET] = EQWB + EQET - MYDF(dWB); } -# endif - - - // inflow bc handling - if(oldFlag & (CFMbndInflow)) { - // fill if cells in inflow region - if(myfrac<0.5) { - mass += 0.25; - calcInitialMass += 0.25; - } - const int OId = oldFlag>>24; - const LbmVec vel(mObjectSpeeds[OId]); - ux=vel[0], uy=vel[1], uz=vel[2]; - //? usqr = 1.5 * (ux*ux + uy*uy + uz*uz); - //FORDF0 { RAC(tcel, l) = this->getCollideEq(l, fluidRho,ux,uy,uz); } rho = fluidRho; - rho = REFERENCE_PRESSURE; - FORDF0 { RAC(tcel, l) = this->getCollideEq(l, rho,ux,uy,uz); } - //errMsg("INFLOW_DEBUG","if at "<RWVEL_WINDTHRESH) && (lcsmqomSizez-SLOWDOWNREGION) ) { - LbmFloat nuz = uz; - if(k>mSizez-SLOWDOWNREGION) { - // special case - LbmFloat zfac = (LbmFloat)( k-(mSizez-SLOWDOWNREGION) ); - zfac /= (LbmFloat)(SLOWDOWNREGION); - nuz += (1.0) * zfac; // check max speed? OFF? - //errMsg("TOPT"," at "<0.025) { - const LbmFloat add = this->dfLength[l]*(-ux*this->dfDvecX[l]-uy*this->dfDvecY[l]-nuz*this->dfDvecZ[l])*jdf; - RAC(tcel,l) += add; } - } - //errMsg("TOPDOWNCORR"," jdf:"<0.0095)) { // add - if((prob0.012)) { // add - } else { doAdd = false; }// dont... - } - - - // remove noise - if(usqr<0.0001) doAdd=false; // TODO check!? - - // dont try to subtract from empty cells - // ensure cell has enough mass for new drop - LbmFloat newPartsize = 1.0; - if(mPartUsePhysModel) { - // 1-10 - newPartsize += 9.0* (rand()/(RAND_MAX+1.0)); - } else { - // 1-5, overall size has to be less than - // .62 (ca. 0.5) to make drops significantly smaller - // than a full cell! - newPartsize += 4.0* (rand()/(RAND_MAX+1.0)); - } - LbmFloat dropmass = ParticleObject::getMass(mPartDropMassSub*newPartsize); //PARTMASS(mPartDropMassSub*newPartsize); // mass: 4/3 pi r^3 rho - while(dropmass>mass) { - newPartsize -= 0.2; - dropmass = ParticleObject::getMass(mPartDropMassSub*newPartsize); - } - if(newPartsize<=1.) doAdd=false; - - if( (doAdd) ) { // init new particle - for(int s=0; s<1; s++) { // one part! - const LbmFloat posjitter = 0.05; - const LbmFloat posjitteroffs = posjitter*-0.5; - LbmFloat jpx = posjitteroffs+ posjitter* (rand()/(RAND_MAX+1.0)); - LbmFloat jpy = posjitteroffs+ posjitter* (rand()/(RAND_MAX+1.0)); - LbmFloat jpz = posjitteroffs+ posjitter* (rand()/(RAND_MAX+1.0)); - - const LbmFloat jitterstr = 1.0; - const LbmFloat jitteroffs = jitterstr*-0.5; - LbmFloat jx = jitteroffs+ jitterstr* (rand()/(RAND_MAX+1.0)); - LbmFloat jy = jitteroffs+ jitterstr* (rand()/(RAND_MAX+1.0)); - LbmFloat jz = jitteroffs+ jitterstr* (rand()/(RAND_MAX+1.0)); - - // average normal & velocity - // -> mostly along velocity dir, many into surface - // fluid velocity (not normalized!) - LbmVec flvelVel(ux,uy,uz); - LbmFloat flvelLen = norm(flvelVel); - // surface normal - LbmVec normVel(surfaceNormal[0],surfaceNormal[1],surfaceNormal[2]); - normalize(normVel); - LbmFloat normScale = (0.01+flvelLen); - // jitter vector, 0.2 * flvel - LbmVec jittVel(jx,jy,jz); - jittVel *= (0.05+flvelLen)*0.1; - // weighten velocities - const LbmFloat flvelWeight = 0.9; - LbmVec newpartVel = normVel*normScale*(1.-flvelWeight) + flvelVel*(flvelWeight) + jittVel; - - // offset towards surface (hide popping) - jpx += -normVel[0]*0.4; - jpy += -normVel[1]*0.4; - jpz += -normVel[2]*0.4; - - LbmFloat srci=i+0.5+jpx, srcj=j+0.5+jpy, srck=k+0.5+jpz; - int type=0; - type = PART_DROP; - -# if LBMDIM==2 - newpartVel[2]=0.; srck=0.5; -# endif // LBMDIM==2 - // subtract drop mass - mass -= dropmass; - // init new particle - { - ParticleObject np( ntlVec3Gfx(srci,srcj,srck) ); - np.setVel(newpartVel[0],newpartVel[1],newpartVel[2]); - np.setStatus(PART_IN); - np.setType(type); - //if((s%3)==2) np.setType(PART_FLOAT); - np.setSize(newPartsize); - //errMsg("NEWPART"," at "<= (rho * (1.0+FSGR_MAGICNR)) ) { iffilled = 1; } - // interface cell if empty? - if( (mass) <= (rho * ( -FSGR_MAGICNR)) ) { ifemptied = 1; } - - if(oldFlag & (CFMbndOutflow)) { - calcInitialMass -= mass; - mass = myfrac = 0.0; - iffilled = 0; ifemptied = 1; - } - - // looks much nicer... LISTTRICK -# if FSGR_LISTTRICK==1 - //if((oldFlag&CFNoNbEmpty)&&(newFlag&CFNoNbEmpty)) { TEST_IF_CHECK; } - if(newFlag&CFNoBndFluid) { // test NEW TEST - if(!iffilled) { - // remove cells independent from amount of change... - if( (oldFlag & CFNoNbEmpty)&&(newFlag & CFNoNbEmpty)&& - ( (mass>(rho*FSGR_LISTTTHRESHFULL)) || ((nbored&CFInter)==0) )) { - //if((nbored&CFInter)==0){ errMsg("NBORED!CFINTER","filled "< better cell conversions - RAC(tcel,dFfrac) = (mass/rho); - - // init new flux value - float flux = FLUX_INIT; // dxqn on - if(newFlag&CFNoBndFluid) { - //flux = 50.0; // extreme on - for(int nn=1; nncDfNum; nn++) { - if(nbflag[nn] & (CFFluid|CFInter|CFBnd)) { flux += this->dfLength[nn]; } - } - // optical hack - smooth slow moving - // surface regions - if(usqr< sssUsqrLimit) { - for(int nn=1; nncDfNum; nn++) { - if(nbfracs[nn]!=0.0) { - LbmFloat curSmooth = (sssUsqrLimit-usqr)*sssUsqrLimitInv; - if(curSmooth>1.0) curSmooth=1.0; - flux *= (1.0+ smoothStrength*curSmooth * (nbfracs[nn]-myfrac)) ; - } - } } - // NEW TEST */ - } - // flux = FLUX_INIT; // calc flux off - QCELL(lev, i,j,k,TSET(lev), dFlux) = flux; // */ - - // perform mass exchange with streamed values - QCELL(lev, i,j,k,TSET(lev), dMass) = mass; // MASST - // set new flag - *pFlagDst = (CellFlagType)newFlag; - calcCurrentMass += mass; - calcCurrentVolume += RAC(tcel,dFfrac); - - // interface cell handling done... - -#if PARALLEL!=1 - GRID_LOOPREG_END(); -#else // PARALLEL==1 -#include "paraloopend.h" // = GRID_LOOPREG_END(); -#endif // PARALLEL==1 - - // write vars from computations to class - mLevel[lev].lmass = calcCurrentMass; - mLevel[lev].lvolume = calcCurrentVolume; - mNumFilledCells = calcCellsFilled; - mNumEmptiedCells = calcCellsEmptied; - mNumUsedCells = calcNumUsedCells; - mNumInvIfCells += calcNumInvIfCells; - mInitialMass += calcInitialMass; -} - - - -void -LbmFsgrSolver::preinitGrids() -{ - const int lev = mMaxRefine; - const bool doReduce = false; - const int gridLoopBound=0; - - // preinit both grids - for(int s=0; s<2; s++) { - - GRID_REGION_INIT(); -#if PARALLEL==1 - const int gDebugLevel = ::gDebugLevel; -#pragma omp parallel num_threads(mNumOMPThreads) \ - reduction(+: \ - calcCurrentMass,calcCurrentVolume, \ - calcCellsFilled,calcCellsEmptied, \ - calcNumUsedCells ) -#endif // PARALLEL==1 - GRID_REGION_START(); - GRID_LOOP_START(); - for(int l=0; l-LBM_EPSILON) ret = 0.0; - else ret = scal * -1.0; - } - //errMsg("massd", PRINT_IJK<<" nv"<dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - //if((LBMDIM>2)&&( (ni<=0) || (nj<=0) || (nk<=0) || (ni>=mLevel[workLev].lSizex-1) || (nj>=mLevel[workLev].lSizey-1) || (nk>=mLevel[workLev].lSizez-1) )) { - if( (ni<=0) || (nj<=0) || - (ni>=mLevel[workLev].lSizex-1) || - (nj>=mLevel[workLev].lSizey-1) -# if LBMDIM==3 - || (nk<=0) || (nk>=mLevel[workLev].lSizez-1) -# endif // LBMDIM==1 - ) { - continue; } // new bc, dont treat cells on boundary NEWBC - if( RFLAG(workLev, ni,nj,nk, workSet) & CFEmpty ){ - - // preinit speed, get from average surrounding cells - // interpolate from non-workset to workset, sets are handled in function - - // new and empty interface cell, dont change old flag here! - addToNewInterList(ni,nj,nk); - - LbmFloat avgrho = 0.0; - LbmFloat avgux = 0.0, avguy = 0.0, avguz = 0.0; - interpolateCellValues(workLev,ni,nj,nk,workSet, avgrho,avgux,avguy,avguz); - - // careful with l's... - FORDF0M { - QCELL(workLev,ni,nj,nk, workSet, m) = this->getCollideEq( m,avgrho, avgux, avguy, avguz ); - //QCELL(workLev,ni,nj,nk, workSet, l) = avgnbdf[l]; // CHECK FIXME test? - } - //errMsg("FNEW", PRINT_VEC(ni,nj,nk)<<" mss"< - let fill cells+surrounding interface cells have the higher importance */ - for( vector::iterator iter=mListEmpty.begin(); - iter != mListEmpty.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - if((RFLAG(workLev,i,j,k, workSet)&(CFInter|CFNoDelete)) == (CFInter|CFNoDelete)){ errMsg("A"," ARGHARGRAG "); } // DEBUG - if(debugFlagreinit) errMsg("EMPT", PRINT_IJK<<" mss"<dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if( RFLAG(workLev,ni,nj,nk, workSet) & CFFluid){ - // init fluid->interface - //RFLAG(workLev,ni,nj,nk, workSet) = (CellFlagType)(CFInter); - changeFlag(workLev,ni,nj,nk, workSet, CFInter); - /* new mass = current density */ - LbmFloat nbrho = QCELL(workLev,ni,nj,nk, workSet, dC); - for(int rl=1; rl< this->cDfNum ; ++rl) { nbrho += QCELL(workLev,ni,nj,nk, workSet, rl); } - QCELL(workLev,ni,nj,nk, workSet, dMass) = nbrho; - QCELL(workLev,ni,nj,nk, workSet, dFfrac) = 1.0; - - // store point - addToNewInterList(ni,nj,nk); - } - if( RFLAG(workLev,ni,nj,nk, workSet) & CFInter){ - // test, also add to list... - addToNewInterList(ni,nj,nk); - } // NEW? - } - - /* for symmetry, set our flag right now */ - changeFlag(workLev,i,j,k, workSet, CFEmpty); - // mark cell not be changed mass... - not necessary, not in list anymore anyway! - } // emptylist - - - - // precompute weights to get rid of order dependancies - vector vWeights; - vWeights.resize( mListFull.size() + mListEmpty.size() ); - int weightIndex = 0; - int nbCount = 0; - LbmFloat nbWeights[LBM_DFNUM]; - LbmFloat nbTotWeights = 0.0; - for( vector::iterator iter=mListFull.begin(); - iter != mListFull.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - nbCount = 0; nbTotWeights = 0.0; - FORDF1 { - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if( RFLAG(workLev,ni,nj,nk, workSet) & CFInter) { - nbCount++; - if(iter->flag&1) nbWeights[l] = 1.; // NEWSURFT - else nbWeights[l] = getMassdWeight(1,i,j,k,workSet,l); // NEWSURFT - nbTotWeights += nbWeights[l]; - } else { - nbWeights[l] = -100.0; // DEBUG; - } - } - if(nbCount>0) { - //errMsg("FF I", PRINT_IJK<<" "<::iterator iter=mListEmpty.begin(); - iter != mListEmpty.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - nbCount = 0; nbTotWeights = 0.0; - FORDF1 { - int ni=i+this->dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if( RFLAG(workLev,ni,nj,nk, workSet) & CFInter) { - nbCount++; - if(iter->flag&1) nbWeights[l] = 1.; // NEWSURFT - else nbWeights[l] = getMassdWeight(0,i,j,k,workSet,l); // NEWSURFT - nbTotWeights += nbWeights[l]; - } else { - nbWeights[l] = -100.0; // DEBUG; - } - } - if(nbCount>0) { - //errMsg("EE I", PRINT_IJK<<" "<::iterator iter=mListFull.begin(); - iter != mListFull.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - - LbmFloat myrho = QCELL(workLev,i,j,k, workSet, dC); - FORDF1 { myrho += QCELL(workLev,i,j,k, workSet, l); } // QCELL.rho - - LbmFloat massChange = QCELL(workLev,i,j,k, workSet, dMass) - myrho; - if(vWeights[weightIndex].numNbs>0.0) { - const LbmFloat nbTotWeightsp = vWeights[weightIndex].val[0]; - //errMsg("FF I", PRINT_IJK<<" "<dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if( RFLAG(workLev,ni,nj,nk, workSet) & CFInter) { - LbmFloat change = -1.0; - if(nbTotWeightsp>0.0) { - //change = massChange * ( nbWeights[l]/nbTotWeightsp ); - change = massChange * ( vWeights[weightIndex].val[l]/nbTotWeightsp ); - } else { - change = (LbmFloat)(massChange/vWeights[weightIndex].numNbs); - } - QCELL(workLev,ni,nj,nk, workSet, dMass) += change; - } - } - massChange = 0.0; - } else { - // Problem! no interface neighbors - mFixMass += massChange; - //TTT mNumProblems++; - //errMsg(" FULL PROBLEM ", PRINT_IJK<<" "<::iterator iter=mListEmpty.begin(); - iter != mListEmpty.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - - LbmFloat massChange = QCELL(workLev, i,j,k, workSet, dMass); - if(vWeights[weightIndex].numNbs>0.0) { - const LbmFloat nbTotWeightsp = vWeights[weightIndex].val[0]; - //errMsg("EE I", PRINT_IJK<<" "<dfVecX[l], nj=j+this->dfVecY[l], nk=k+this->dfVecZ[l]; - if( RFLAG(workLev,ni,nj,nk, workSet) & CFInter) { - LbmFloat change = -1.0; - if(nbTotWeightsp>0.0) { - change = massChange * ( vWeights[weightIndex].val[l]/nbTotWeightsp ); - } else { - change = (LbmFloat)(massChange/vWeights[weightIndex].numNbs); - } - QCELL(workLev, ni,nj,nk, workSet, dMass) += change; - } - } - massChange = 0.0; - } else { - // Problem! no interface neighbors - mFixMass += massChange; - //TTT mNumProblems++; - //errMsg(" EMPT PROBLEM ", PRINT_IJK<<" "<::iterator iter=mListEmpty.begin(); - iter != mListEmpty.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - changeFlag(workLev,i,j,k, otherSet, CFEmpty); - } - - - // check if some of the new interface cells can be removed again - // never happens !!! not necessary - // calculate ffrac for new IF cells NEW - - // how many are really new interface cells? - int numNewIf = 0; - for( vector::iterator iter=mListNewInter.begin(); - iter != mListNewInter.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - if(!(RFLAG(workLev,i,j,k, workSet)&CFInter)) { - continue; - // FIXME remove from list? - } - numNewIf++; - } - - // redistribute mass, reinit flags - if(debugFlagreinit) errMsg("NEWIF", "total:"<::iterator iter=mListNewInter.begin(); - iter != mListNewInter.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - if((i<=0) || (j<=0) || - (i>=mLevel[workLev].lSizex-1) || - (j>=mLevel[workLev].lSizey-1) || - ((LBMDIM==3) && ((k<=0) || (k>=mLevel[workLev].lSizez-1) ) ) - ) { - continue; } // new bc, dont treat cells on boundary NEWBC - if(!(RFLAG(workLev,i,j,k, workSet)&CFInter)) { - //errMsg("???"," "<::iterator iter=mListNewInter.begin(); - iter != mListNewInter.end(); iter++ ) { - int i=iter->x, j=iter->y, k=iter->z; - if(!(RFLAG(workLev,i,j,k, workSet)&CFInter)) { continue; } - - initInterfaceVars(workLev, i,j,k, workSet, false); //int level, int i,int j,int k,int workSet, bool initMass) { - //LbmFloat nrho = 0.0; - //FORDF0 { nrho += QCELL(workLev, i,j,k, workSet, l); } - //QCELL(workLev,i,j,k, workSet, dFfrac) = QCELL(workLev,i,j,k, workSet, dMass)/nrho; - //QCELL(workLev,i,j,k, workSet, dFlux) = FLUX_INIT; - } - - if(mListNewInter.size()>0){ - //errMsg("FixMassDisted"," fm:"<mPanic=1; /* *((int*)(0x0)) = 1; crash*/ } -#else // FSGR_STRICT_DEBUG==1 -#define CAUSE_PANIC { this->mPanic=1; } /*set flag*/ -#endif // FSGR_STRICT_DEBUG==1 - -/****************************************************************************** - * normal relaxation - *****************************************************************************/ - -// standard arrays -#define CSRC_C RAC(ccel , dC ) -#define CSRC_E RAC(ccel + (-1) *(dTotalNum), dE ) -#define CSRC_W RAC(ccel + (+1) *(dTotalNum), dW ) -#define CSRC_N RAC(ccel + (-mLevel[lev].lOffsx) *(dTotalNum), dN ) -#define CSRC_S RAC(ccel + (+mLevel[lev].lOffsx) *(dTotalNum), dS ) -#define CSRC_NE RAC(ccel + (-mLevel[lev].lOffsx-1) *(dTotalNum), dNE) -#define CSRC_NW RAC(ccel + (-mLevel[lev].lOffsx+1) *(dTotalNum), dNW) -#define CSRC_SE RAC(ccel + (+mLevel[lev].lOffsx-1) *(dTotalNum), dSE) -#define CSRC_SW RAC(ccel + (+mLevel[lev].lOffsx+1) *(dTotalNum), dSW) -#define CSRC_T RAC(ccel + (-mLevel[lev].lOffsy) *(dTotalNum), dT ) -#define CSRC_B RAC(ccel + (+mLevel[lev].lOffsy) *(dTotalNum), dB ) -#define CSRC_ET RAC(ccel + (-mLevel[lev].lOffsy-1) *(dTotalNum), dET) -#define CSRC_EB RAC(ccel + (+mLevel[lev].lOffsy-1) *(dTotalNum), dEB) -#define CSRC_WT RAC(ccel + (-mLevel[lev].lOffsy+1) *(dTotalNum), dWT) -#define CSRC_WB RAC(ccel + (+mLevel[lev].lOffsy+1) *(dTotalNum), dWB) -#define CSRC_NT RAC(ccel + (-mLevel[lev].lOffsy-mLevel[lev].lOffsx) *(dTotalNum), dNT) -#define CSRC_NB RAC(ccel + (+mLevel[lev].lOffsy-mLevel[lev].lOffsx) *(dTotalNum), dNB) -#define CSRC_ST RAC(ccel + (-mLevel[lev].lOffsy+mLevel[lev].lOffsx) *(dTotalNum), dST) -#define CSRC_SB RAC(ccel + (+mLevel[lev].lOffsy+mLevel[lev].lOffsx) *(dTotalNum), dSB) - -#define XSRC_C(x) RAC(ccel + (x) *dTotalNum, dC ) -#define XSRC_E(x) RAC(ccel + ((x)-1) *dTotalNum, dE ) -#define XSRC_W(x) RAC(ccel + ((x)+1) *dTotalNum, dW ) -#define XSRC_N(x) RAC(ccel + ((x)-mLevel[lev].lOffsx) *dTotalNum, dN ) -#define XSRC_S(x) RAC(ccel + ((x)+mLevel[lev].lOffsx) *dTotalNum, dS ) -#define XSRC_NE(x) RAC(ccel + ((x)-mLevel[lev].lOffsx-1) *dTotalNum, dNE) -#define XSRC_NW(x) RAC(ccel + ((x)-mLevel[lev].lOffsx+1) *dTotalNum, dNW) -#define XSRC_SE(x) RAC(ccel + ((x)+mLevel[lev].lOffsx-1) *dTotalNum, dSE) -#define XSRC_SW(x) RAC(ccel + ((x)+mLevel[lev].lOffsx+1) *dTotalNum, dSW) -#define XSRC_T(x) RAC(ccel + ((x)-mLevel[lev].lOffsy) *dTotalNum, dT ) -#define XSRC_B(x) RAC(ccel + ((x)+mLevel[lev].lOffsy) *dTotalNum, dB ) -#define XSRC_ET(x) RAC(ccel + ((x)-mLevel[lev].lOffsy-1) *dTotalNum, dET) -#define XSRC_EB(x) RAC(ccel + ((x)+mLevel[lev].lOffsy-1) *dTotalNum, dEB) -#define XSRC_WT(x) RAC(ccel + ((x)-mLevel[lev].lOffsy+1) *dTotalNum, dWT) -#define XSRC_WB(x) RAC(ccel + ((x)+mLevel[lev].lOffsy+1) *dTotalNum, dWB) -#define XSRC_NT(x) RAC(ccel + ((x)-mLevel[lev].lOffsy-mLevel[lev].lOffsx) *dTotalNum, dNT) -#define XSRC_NB(x) RAC(ccel + ((x)+mLevel[lev].lOffsy-mLevel[lev].lOffsx) *dTotalNum, dNB) -#define XSRC_ST(x) RAC(ccel + ((x)-mLevel[lev].lOffsy+mLevel[lev].lOffsx) *dTotalNum, dST) -#define XSRC_SB(x) RAC(ccel + ((x)+mLevel[lev].lOffsy+mLevel[lev].lOffsx) *dTotalNum, dSB) - - - -#define OMEGA(l) mLevel[(l)].omega - -#define EQC ( DFL1*(rho - usqr)) -#define EQN ( DFL2*(rho + uy*(4.5*uy + 3.0) - usqr)) -#define EQS ( DFL2*(rho + uy*(4.5*uy - 3.0) - usqr)) -#define EQE ( DFL2*(rho + ux*(4.5*ux + 3.0) - usqr)) -#define EQW ( DFL2*(rho + ux*(4.5*ux - 3.0) - usqr)) -#define EQT ( DFL2*(rho + uz*(4.5*uz + 3.0) - usqr)) -#define EQB ( DFL2*(rho + uz*(4.5*uz - 3.0) - usqr)) - -#define EQNE ( DFL3*(rho + (+ux+uy)*(4.5*(+ux+uy) + 3.0) - usqr)) -#define EQNW ( DFL3*(rho + (-ux+uy)*(4.5*(-ux+uy) + 3.0) - usqr)) -#define EQSE ( DFL3*(rho + (+ux-uy)*(4.5*(+ux-uy) + 3.0) - usqr)) -#define EQSW ( DFL3*(rho + (-ux-uy)*(4.5*(-ux-uy) + 3.0) - usqr)) -#define EQNT ( DFL3*(rho + (+uy+uz)*(4.5*(+uy+uz) + 3.0) - usqr)) -#define EQNB ( DFL3*(rho + (+uy-uz)*(4.5*(+uy-uz) + 3.0) - usqr)) -#define EQST ( DFL3*(rho + (-uy+uz)*(4.5*(-uy+uz) + 3.0) - usqr)) -#define EQSB ( DFL3*(rho + (-uy-uz)*(4.5*(-uy-uz) + 3.0) - usqr)) -#define EQET ( DFL3*(rho + (+ux+uz)*(4.5*(+ux+uz) + 3.0) - usqr)) -#define EQEB ( DFL3*(rho + (+ux-uz)*(4.5*(+ux-uz) + 3.0) - usqr)) -#define EQWT ( DFL3*(rho + (-ux+uz)*(4.5*(-ux+uz) + 3.0) - usqr)) -#define EQWB ( DFL3*(rho + (-ux-uz)*(4.5*(-ux-uz) + 3.0) - usqr)) - - -// this is a bit ugly, but necessary for the CSRC_ access... -#define MSRC_C m[dC ] -#define MSRC_N m[dN ] -#define MSRC_S m[dS ] -#define MSRC_E m[dE ] -#define MSRC_W m[dW ] -#define MSRC_T m[dT ] -#define MSRC_B m[dB ] -#define MSRC_NE m[dNE] -#define MSRC_NW m[dNW] -#define MSRC_SE m[dSE] -#define MSRC_SW m[dSW] -#define MSRC_NT m[dNT] -#define MSRC_NB m[dNB] -#define MSRC_ST m[dST] -#define MSRC_SB m[dSB] -#define MSRC_ET m[dET] -#define MSRC_EB m[dEB] -#define MSRC_WT m[dWT] -#define MSRC_WB m[dWB] - -// this is a bit ugly, but necessary for the ccel local access... -#define CCEL_C RAC(ccel, dC ) -#define CCEL_N RAC(ccel, dN ) -#define CCEL_S RAC(ccel, dS ) -#define CCEL_E RAC(ccel, dE ) -#define CCEL_W RAC(ccel, dW ) -#define CCEL_T RAC(ccel, dT ) -#define CCEL_B RAC(ccel, dB ) -#define CCEL_NE RAC(ccel, dNE) -#define CCEL_NW RAC(ccel, dNW) -#define CCEL_SE RAC(ccel, dSE) -#define CCEL_SW RAC(ccel, dSW) -#define CCEL_NT RAC(ccel, dNT) -#define CCEL_NB RAC(ccel, dNB) -#define CCEL_ST RAC(ccel, dST) -#define CCEL_SB RAC(ccel, dSB) -#define CCEL_ET RAC(ccel, dET) -#define CCEL_EB RAC(ccel, dEB) -#define CCEL_WT RAC(ccel, dWT) -#define CCEL_WB RAC(ccel, dWB) -// for coarse to fine interpol access -#define CCELG_C(f) (RAC(ccel, dC )*mGaussw[(f)]) -#define CCELG_N(f) (RAC(ccel, dN )*mGaussw[(f)]) -#define CCELG_S(f) (RAC(ccel, dS )*mGaussw[(f)]) -#define CCELG_E(f) (RAC(ccel, dE )*mGaussw[(f)]) -#define CCELG_W(f) (RAC(ccel, dW )*mGaussw[(f)]) -#define CCELG_T(f) (RAC(ccel, dT )*mGaussw[(f)]) -#define CCELG_B(f) (RAC(ccel, dB )*mGaussw[(f)]) -#define CCELG_NE(f) (RAC(ccel, dNE)*mGaussw[(f)]) -#define CCELG_NW(f) (RAC(ccel, dNW)*mGaussw[(f)]) -#define CCELG_SE(f) (RAC(ccel, dSE)*mGaussw[(f)]) -#define CCELG_SW(f) (RAC(ccel, dSW)*mGaussw[(f)]) -#define CCELG_NT(f) (RAC(ccel, dNT)*mGaussw[(f)]) -#define CCELG_NB(f) (RAC(ccel, dNB)*mGaussw[(f)]) -#define CCELG_ST(f) (RAC(ccel, dST)*mGaussw[(f)]) -#define CCELG_SB(f) (RAC(ccel, dSB)*mGaussw[(f)]) -#define CCELG_ET(f) (RAC(ccel, dET)*mGaussw[(f)]) -#define CCELG_EB(f) (RAC(ccel, dEB)*mGaussw[(f)]) -#define CCELG_WT(f) (RAC(ccel, dWT)*mGaussw[(f)]) -#define CCELG_WB(f) (RAC(ccel, dWB)*mGaussw[(f)]) - - -#if PARALLEL==1 -#define CSMOMEGA_STATS(dlev, domega) -#else // PARALLEL==1 -#if FSGR_OMEGA_DEBUG==1 -#define CSMOMEGA_STATS(dlev, domega) \ - mLevel[dlev].avgOmega += domega; mLevel[dlev].avgOmegaCnt+=1.0; -#else // FSGR_OMEGA_DEBUG==1 -#define CSMOMEGA_STATS(dlev, domega) -#endif // FSGR_OMEGA_DEBUG==1 -#endif // PARALLEL==1 - - -// used for main loops and grav init -// source set -#define SRCS(l) mLevel[(l)].setCurr -// target set -#define TSET(l) mLevel[(l)].setOther - -// handle mov. obj -#if FSGR_STRICT_DEBUG==1 - -#define LBMDS_ADDMOV(linv,l) \ - \ - if((nbflag[linv]&CFBndMoving)&&(!(nbflag[l]&CFBnd))){ \ - \ - LbmFloat dte=QCELL_NBINV(lev, i, j, k, SRCS(lev), l,dFlux)-(mSimulationTime+this->mpParam->getTimestep()); \ - if( ABS(dte)< 1e-15 ) { \ - m[l]+=QCELL_NBINV(lev, i, j, k, SRCS(lev), l,l); \ - } else { \ - const int sdx = i+this->dfVecX[linv], sdy = j+this->dfVecY[linv], sdz = k+this->dfVecZ[linv]; \ - \ - errMsg("INVALID_MOV_OBJ_TIME"," at "<dfInv[l] ); \ - } \ - } else { \ - m[l] = QCELL_NBINV(lev, i, j, k, SRCS(lev), l,l); \ - if(RFLAG(lev, i,j,k, mLevel[lev].setCurr)&CFFluid) { \ - if(!(nbf&(CFFluid|CFInter)) ) { \ - int ni=i+this->dfVecX[this->dfInv[l]], nj=j+this->dfVecY[this->dfInv[l]], nk=k+this->dfVecZ[this->dfInv[l]]; \ - errMsg("STREAMCHECK"," Invalid nbflag, streamed DF l"<dfVecX[this->dfInv[l]], j+this->dfVecY[this->dfInv[l]],k+this->dfVecZ[this->dfInv[l]], l); \ - } \ - } \ - - - - -// careful ux,uy,uz need to be inited before! -#define DEFAULT_COLLIDEG(grav) \ - this->collideArrays(lev, i,j,k, m, rho,ux,uy,uz, OMEGA(lev), grav, mLevel[lev].lcsmago, &mDebugOmegaRet, &lcsmqo ); \ - CSMOMEGA_STATS(lev,mDebugOmegaRet); \ - FORDF0 { RAC(tcel,l) = m[l]; } \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - COLLCHECK; \ - - - -#define OPTIMIZED_STREAMCOLLIDE \ - m[0] = RAC(ccel,0); \ - FORDF1 { \ - \ - if(RFLAG_NBINV(lev, i,j,k,SRCS(lev),l)&CFBnd) { errMsg("???", "bnd-err-nobndfl"); CAUSE_PANIC; \ - } else { m[l] = QCELL_NBINV(lev, i, j, k, SRCS(lev), l, l); } \ - STREAMCHECK(8, i+this->dfVecX[this->dfInv[l]], j+this->dfVecY[this->dfInv[l]],k+this->dfVecZ[this->dfInv[l]], l); \ - } \ - rho=m[0]; \ - DEFAULT_COLLIDEG(mLevel[lev].gravity) \ - - - -#define OPTIMIZED_STREAMCOLLIDE___UNUSED \ - \ - this->collideArrays(lev, i,j,k, m, rho,ux,uy,uz, OMEGA(lev), mLevel[lev].gravity, mLevel[lev].lcsmago , &mDebugOmegaRet, &lcsmqo ); \ - CSMOMEGA_STATS(lev,mDebugOmegaRet); \ - FORDF0 { RAC(tcel,l) = m[l]; } \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - COLLCHECK; \ - - - -#else // 3D, opt OPT3D==true - - -// default stream opt3d add moving bc val -#define DEFAULT_STREAM \ - m[dC] = RAC(ccel,dC); \ - \ - if(0 /* ((!nbored) & CFBnd) */) { \ - \ - m[dN ] = CSRC_N ; m[dS ] = CSRC_S ; \ - m[dE ] = CSRC_E ; m[dW ] = CSRC_W ; \ - m[dT ] = CSRC_T ; m[dB ] = CSRC_B ; \ - m[dNE] = CSRC_NE; m[dNW] = CSRC_NW; m[dSE] = CSRC_SE; m[dSW] = CSRC_SW; \ - m[dNT] = CSRC_NT; m[dNB] = CSRC_NB; m[dST] = CSRC_ST; m[dSB] = CSRC_SB; \ - m[dET] = CSRC_ET; m[dEB] = CSRC_EB; m[dWT] = CSRC_WT; m[dWB] = CSRC_WB; \ - } else { \ - \ - if(nbflag[dS ]&CFBnd) { m[dN ] = RAC(ccel,dS ); LBMDS_ADDMOV(dS ,dN ); } else { m[dN ] = CSRC_N ; } \ - if(nbflag[dN ]&CFBnd) { m[dS ] = RAC(ccel,dN ); LBMDS_ADDMOV(dN ,dS ); } else { m[dS ] = CSRC_S ; } \ - if(nbflag[dW ]&CFBnd) { m[dE ] = RAC(ccel,dW ); LBMDS_ADDMOV(dW ,dE ); } else { m[dE ] = CSRC_E ; } \ - if(nbflag[dE ]&CFBnd) { m[dW ] = RAC(ccel,dE ); LBMDS_ADDMOV(dE ,dW ); } else { m[dW ] = CSRC_W ; } \ - if(nbflag[dB ]&CFBnd) { m[dT ] = RAC(ccel,dB ); LBMDS_ADDMOV(dB ,dT ); } else { m[dT ] = CSRC_T ; } \ - if(nbflag[dT ]&CFBnd) { m[dB ] = RAC(ccel,dT ); LBMDS_ADDMOV(dT ,dB ); } else { m[dB ] = CSRC_B ; } \ - \ - \ - if(nbflag[dSW]&CFBnd) { if(nbflag[dSW]&CFBndNoslip){ m[dNE] = RAC(ccel,dSW); LBMDS_ADDMOV(dSW,dNE); }else{ DEFAULT_STREAM_FREESLIP(dNE,dSW,nbflag[dSW]);} } else { m[dNE] = CSRC_NE; } \ - if(nbflag[dSE]&CFBnd) { if(nbflag[dSE]&CFBndNoslip){ m[dNW] = RAC(ccel,dSE); LBMDS_ADDMOV(dSE,dNW); }else{ DEFAULT_STREAM_FREESLIP(dNW,dSE,nbflag[dSE]);} } else { m[dNW] = CSRC_NW; } \ - if(nbflag[dNW]&CFBnd) { if(nbflag[dNW]&CFBndNoslip){ m[dSE] = RAC(ccel,dNW); LBMDS_ADDMOV(dNW,dSE); }else{ DEFAULT_STREAM_FREESLIP(dSE,dNW,nbflag[dNW]);} } else { m[dSE] = CSRC_SE; } \ - if(nbflag[dNE]&CFBnd) { if(nbflag[dNE]&CFBndNoslip){ m[dSW] = RAC(ccel,dNE); LBMDS_ADDMOV(dNE,dSW); }else{ DEFAULT_STREAM_FREESLIP(dSW,dNE,nbflag[dNE]);} } else { m[dSW] = CSRC_SW; } \ - if(nbflag[dSB]&CFBnd) { if(nbflag[dSB]&CFBndNoslip){ m[dNT] = RAC(ccel,dSB); LBMDS_ADDMOV(dSB,dNT); }else{ DEFAULT_STREAM_FREESLIP(dNT,dSB,nbflag[dSB]);} } else { m[dNT] = CSRC_NT; } \ - if(nbflag[dST]&CFBnd) { if(nbflag[dST]&CFBndNoslip){ m[dNB] = RAC(ccel,dST); LBMDS_ADDMOV(dST,dNB); }else{ DEFAULT_STREAM_FREESLIP(dNB,dST,nbflag[dST]);} } else { m[dNB] = CSRC_NB; } \ - if(nbflag[dNB]&CFBnd) { if(nbflag[dNB]&CFBndNoslip){ m[dST] = RAC(ccel,dNB); LBMDS_ADDMOV(dNB,dST); }else{ DEFAULT_STREAM_FREESLIP(dST,dNB,nbflag[dNB]);} } else { m[dST] = CSRC_ST; } \ - if(nbflag[dNT]&CFBnd) { if(nbflag[dNT]&CFBndNoslip){ m[dSB] = RAC(ccel,dNT); LBMDS_ADDMOV(dNT,dSB); }else{ DEFAULT_STREAM_FREESLIP(dSB,dNT,nbflag[dNT]);} } else { m[dSB] = CSRC_SB; } \ - if(nbflag[dWB]&CFBnd) { if(nbflag[dWB]&CFBndNoslip){ m[dET] = RAC(ccel,dWB); LBMDS_ADDMOV(dWB,dET); }else{ DEFAULT_STREAM_FREESLIP(dET,dWB,nbflag[dWB]);} } else { m[dET] = CSRC_ET; } \ - if(nbflag[dWT]&CFBnd) { if(nbflag[dWT]&CFBndNoslip){ m[dEB] = RAC(ccel,dWT); LBMDS_ADDMOV(dWT,dEB); }else{ DEFAULT_STREAM_FREESLIP(dEB,dWT,nbflag[dWT]);} } else { m[dEB] = CSRC_EB; } \ - if(nbflag[dEB]&CFBnd) { if(nbflag[dEB]&CFBndNoslip){ m[dWT] = RAC(ccel,dEB); LBMDS_ADDMOV(dEB,dWT); }else{ DEFAULT_STREAM_FREESLIP(dWT,dEB,nbflag[dEB]);} } else { m[dWT] = CSRC_WT; } \ - if(nbflag[dET]&CFBnd) { if(nbflag[dET]&CFBndNoslip){ m[dWB] = RAC(ccel,dET); LBMDS_ADDMOV(dET,dWB); }else{ DEFAULT_STREAM_FREESLIP(dWB,dET,nbflag[dET]);} } else { m[dWB] = CSRC_WB; } \ - } \ - - - - - -#define COLL_CALCULATE_DFEQ(dstarray) \ - dstarray[dN ] = EQN ; dstarray[dS ] = EQS ; \ - dstarray[dE ] = EQE ; dstarray[dW ] = EQW ; \ - dstarray[dT ] = EQT ; dstarray[dB ] = EQB ; \ - dstarray[dNE] = EQNE; dstarray[dNW] = EQNW; dstarray[dSE] = EQSE; dstarray[dSW] = EQSW; \ - dstarray[dNT] = EQNT; dstarray[dNB] = EQNB; dstarray[dST] = EQST; dstarray[dSB] = EQSB; \ - dstarray[dET] = EQET; dstarray[dEB] = EQEB; dstarray[dWT] = EQWT; dstarray[dWB] = EQWB; \ - - - -#define COLL_CALCULATE_NONEQTENSOR(csolev, srcArray ) \ - lcsmqadd = (srcArray##NE - lcsmeq[ dNE ]); \ - lcsmqadd -= (srcArray##NW - lcsmeq[ dNW ]); \ - lcsmqadd -= (srcArray##SE - lcsmeq[ dSE ]); \ - lcsmqadd += (srcArray##SW - lcsmeq[ dSW ]); \ - lcsmqo = (lcsmqadd* lcsmqadd); \ - lcsmqadd = (srcArray##ET - lcsmeq[ dET ]); \ - lcsmqadd -= (srcArray##EB - lcsmeq[ dEB ]); \ - lcsmqadd -= (srcArray##WT - lcsmeq[ dWT ]); \ - lcsmqadd += (srcArray##WB - lcsmeq[ dWB ]); \ - lcsmqo += (lcsmqadd* lcsmqadd); \ - lcsmqadd = (srcArray##NT - lcsmeq[ dNT ]); \ - lcsmqadd -= (srcArray##NB - lcsmeq[ dNB ]); \ - lcsmqadd -= (srcArray##ST - lcsmeq[ dST ]); \ - lcsmqadd += (srcArray##SB - lcsmeq[ dSB ]); \ - lcsmqo += (lcsmqadd* lcsmqadd); \ - lcsmqo *= 2.0; \ - lcsmqadd = (srcArray##E - lcsmeq[ dE ]); \ - lcsmqadd += (srcArray##W - lcsmeq[ dW ]); \ - lcsmqadd += (srcArray##NE - lcsmeq[ dNE ]); \ - lcsmqadd += (srcArray##NW - lcsmeq[ dNW ]); \ - lcsmqadd += (srcArray##SE - lcsmeq[ dSE ]); \ - lcsmqadd += (srcArray##SW - lcsmeq[ dSW ]); \ - lcsmqadd += (srcArray##ET - lcsmeq[ dET ]); \ - lcsmqadd += (srcArray##EB - lcsmeq[ dEB ]); \ - lcsmqadd += (srcArray##WT - lcsmeq[ dWT ]); \ - lcsmqadd += (srcArray##WB - lcsmeq[ dWB ]); \ - lcsmqo += (lcsmqadd* lcsmqadd); \ - lcsmqadd = (srcArray##N - lcsmeq[ dN ]); \ - lcsmqadd += (srcArray##S - lcsmeq[ dS ]); \ - lcsmqadd += (srcArray##NE - lcsmeq[ dNE ]); \ - lcsmqadd += (srcArray##NW - lcsmeq[ dNW ]); \ - lcsmqadd += (srcArray##SE - lcsmeq[ dSE ]); \ - lcsmqadd += (srcArray##SW - lcsmeq[ dSW ]); \ - lcsmqadd += (srcArray##NT - lcsmeq[ dNT ]); \ - lcsmqadd += (srcArray##NB - lcsmeq[ dNB ]); \ - lcsmqadd += (srcArray##ST - lcsmeq[ dST ]); \ - lcsmqadd += (srcArray##SB - lcsmeq[ dSB ]); \ - lcsmqo += (lcsmqadd* lcsmqadd); \ - lcsmqadd = (srcArray##T - lcsmeq[ dT ]); \ - lcsmqadd += (srcArray##B - lcsmeq[ dB ]); \ - lcsmqadd += (srcArray##NT - lcsmeq[ dNT ]); \ - lcsmqadd += (srcArray##NB - lcsmeq[ dNB ]); \ - lcsmqadd += (srcArray##ST - lcsmeq[ dST ]); \ - lcsmqadd += (srcArray##SB - lcsmeq[ dSB ]); \ - lcsmqadd += (srcArray##ET - lcsmeq[ dET ]); \ - lcsmqadd += (srcArray##EB - lcsmeq[ dEB ]); \ - lcsmqadd += (srcArray##WT - lcsmeq[ dWT ]); \ - lcsmqadd += (srcArray##WB - lcsmeq[ dWB ]); \ - lcsmqo += (lcsmqadd* lcsmqadd); \ - lcsmqo = sqrt(lcsmqo); \ - - - -// COLL_CALCULATE_CSMOMEGAVAL(csolev, lcsmomega); - -// careful - need lcsmqo -#define COLL_CALCULATE_CSMOMEGAVAL(csolev, dstomega ) \ - dstomega = 1.0/ \ - ( 3.0*( mLevel[(csolev)].lcnu+mLevel[(csolev)].lcsmago_sqr*( \ - -mLevel[(csolev)].lcnu + sqrt( mLevel[(csolev)].lcnu*mLevel[(csolev)].lcnu + 18.0*mLevel[(csolev)].lcsmago_sqr* lcsmqo ) \ - / (6.0*mLevel[(csolev)].lcsmago_sqr)) \ - ) +0.5 ); \ - - - -#define DEFAULT_COLLIDE_LES(grav) \ - rho = + MSRC_C + MSRC_N \ - + MSRC_S + MSRC_E \ - + MSRC_W + MSRC_T \ - + MSRC_B + MSRC_NE \ - + MSRC_NW + MSRC_SE \ - + MSRC_SW + MSRC_NT \ - + MSRC_NB + MSRC_ST \ - + MSRC_SB + MSRC_ET \ - + MSRC_EB + MSRC_WT \ - + MSRC_WB; \ - \ - ux = MSRC_E - MSRC_W \ - + MSRC_NE - MSRC_NW \ - + MSRC_SE - MSRC_SW \ - + MSRC_ET + MSRC_EB \ - - MSRC_WT - MSRC_WB ; \ - \ - uy = MSRC_N - MSRC_S \ - + MSRC_NE + MSRC_NW \ - - MSRC_SE - MSRC_SW \ - + MSRC_NT + MSRC_NB \ - - MSRC_ST - MSRC_SB ; \ - \ - uz = MSRC_T - MSRC_B \ - + MSRC_NT - MSRC_NB \ - + MSRC_ST - MSRC_SB \ - + MSRC_ET - MSRC_EB \ - + MSRC_WT - MSRC_WB ; \ - PRECOLLIDE_MODS(rho,ux,uy,uz, grav); \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - COLL_CALCULATE_DFEQ(lcsmeq); \ - COLL_CALCULATE_NONEQTENSOR(lev, MSRC_); \ - COLL_CALCULATE_CSMOMEGAVAL(lev, lcsmomega); \ - CSMOMEGA_STATS(lev,lcsmomega); \ - \ - RAC(tcel,dC ) = (1.0-lcsmomega)*MSRC_C + lcsmomega*EQC ; \ - \ - RAC(tcel,dN ) = (1.0-lcsmomega)*MSRC_N + lcsmomega*lcsmeq[ dN ]; \ - RAC(tcel,dS ) = (1.0-lcsmomega)*MSRC_S + lcsmomega*lcsmeq[ dS ]; \ - RAC(tcel,dE ) = (1.0-lcsmomega)*MSRC_E + lcsmomega*lcsmeq[ dE ]; \ - RAC(tcel,dW ) = (1.0-lcsmomega)*MSRC_W + lcsmomega*lcsmeq[ dW ]; \ - RAC(tcel,dT ) = (1.0-lcsmomega)*MSRC_T + lcsmomega*lcsmeq[ dT ]; \ - RAC(tcel,dB ) = (1.0-lcsmomega)*MSRC_B + lcsmomega*lcsmeq[ dB ]; \ - \ - RAC(tcel,dNE) = (1.0-lcsmomega)*MSRC_NE + lcsmomega*lcsmeq[ dNE]; \ - RAC(tcel,dNW) = (1.0-lcsmomega)*MSRC_NW + lcsmomega*lcsmeq[ dNW]; \ - RAC(tcel,dSE) = (1.0-lcsmomega)*MSRC_SE + lcsmomega*lcsmeq[ dSE]; \ - RAC(tcel,dSW) = (1.0-lcsmomega)*MSRC_SW + lcsmomega*lcsmeq[ dSW]; \ - RAC(tcel,dNT) = (1.0-lcsmomega)*MSRC_NT + lcsmomega*lcsmeq[ dNT]; \ - RAC(tcel,dNB) = (1.0-lcsmomega)*MSRC_NB + lcsmomega*lcsmeq[ dNB]; \ - RAC(tcel,dST) = (1.0-lcsmomega)*MSRC_ST + lcsmomega*lcsmeq[ dST]; \ - RAC(tcel,dSB) = (1.0-lcsmomega)*MSRC_SB + lcsmomega*lcsmeq[ dSB]; \ - RAC(tcel,dET) = (1.0-lcsmomega)*MSRC_ET + lcsmomega*lcsmeq[ dET]; \ - RAC(tcel,dEB) = (1.0-lcsmomega)*MSRC_EB + lcsmomega*lcsmeq[ dEB]; \ - RAC(tcel,dWT) = (1.0-lcsmomega)*MSRC_WT + lcsmomega*lcsmeq[ dWT]; \ - RAC(tcel,dWB) = (1.0-lcsmomega)*MSRC_WB + lcsmomega*lcsmeq[ dWB]; \ - - - -#define DEFAULT_COLLIDE_NOLES(grav) \ - rho = + MSRC_C + MSRC_N \ - + MSRC_S + MSRC_E \ - + MSRC_W + MSRC_T \ - + MSRC_B + MSRC_NE \ - + MSRC_NW + MSRC_SE \ - + MSRC_SW + MSRC_NT \ - + MSRC_NB + MSRC_ST \ - + MSRC_SB + MSRC_ET \ - + MSRC_EB + MSRC_WT \ - + MSRC_WB; \ - \ - ux = MSRC_E - MSRC_W \ - + MSRC_NE - MSRC_NW \ - + MSRC_SE - MSRC_SW \ - + MSRC_ET + MSRC_EB \ - - MSRC_WT - MSRC_WB ; \ - \ - uy = MSRC_N - MSRC_S \ - + MSRC_NE + MSRC_NW \ - - MSRC_SE - MSRC_SW \ - + MSRC_NT + MSRC_NB \ - - MSRC_ST - MSRC_SB ; \ - \ - uz = MSRC_T - MSRC_B \ - + MSRC_NT - MSRC_NB \ - + MSRC_ST - MSRC_SB \ - + MSRC_ET - MSRC_EB \ - + MSRC_WT - MSRC_WB ; \ - PRECOLLIDE_MODS(rho, ux,uy,uz, grav); \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - \ - RAC(tcel,dC ) = (1.0-OMEGA(lev))*MSRC_C + OMEGA(lev)*EQC ; \ - \ - RAC(tcel,dN ) = (1.0-OMEGA(lev))*MSRC_N + OMEGA(lev)*EQN ; \ - RAC(tcel,dS ) = (1.0-OMEGA(lev))*MSRC_S + OMEGA(lev)*EQS ; \ - RAC(tcel,dE ) = (1.0-OMEGA(lev))*MSRC_E + OMEGA(lev)*EQE ; \ - RAC(tcel,dW ) = (1.0-OMEGA(lev))*MSRC_W + OMEGA(lev)*EQW ; \ - RAC(tcel,dT ) = (1.0-OMEGA(lev))*MSRC_T + OMEGA(lev)*EQT ; \ - RAC(tcel,dB ) = (1.0-OMEGA(lev))*MSRC_B + OMEGA(lev)*EQB ; \ - \ - RAC(tcel,dNE) = (1.0-OMEGA(lev))*MSRC_NE + OMEGA(lev)*EQNE; \ - RAC(tcel,dNW) = (1.0-OMEGA(lev))*MSRC_NW + OMEGA(lev)*EQNW; \ - RAC(tcel,dSE) = (1.0-OMEGA(lev))*MSRC_SE + OMEGA(lev)*EQSE; \ - RAC(tcel,dSW) = (1.0-OMEGA(lev))*MSRC_SW + OMEGA(lev)*EQSW; \ - RAC(tcel,dNT) = (1.0-OMEGA(lev))*MSRC_NT + OMEGA(lev)*EQNT; \ - RAC(tcel,dNB) = (1.0-OMEGA(lev))*MSRC_NB + OMEGA(lev)*EQNB; \ - RAC(tcel,dST) = (1.0-OMEGA(lev))*MSRC_ST + OMEGA(lev)*EQST; \ - RAC(tcel,dSB) = (1.0-OMEGA(lev))*MSRC_SB + OMEGA(lev)*EQSB; \ - RAC(tcel,dET) = (1.0-OMEGA(lev))*MSRC_ET + OMEGA(lev)*EQET; \ - RAC(tcel,dEB) = (1.0-OMEGA(lev))*MSRC_EB + OMEGA(lev)*EQEB; \ - RAC(tcel,dWT) = (1.0-OMEGA(lev))*MSRC_WT + OMEGA(lev)*EQWT; \ - RAC(tcel,dWB) = (1.0-OMEGA(lev))*MSRC_WB + OMEGA(lev)*EQWB; \ - - - - - -#define OPTIMIZED_STREAMCOLLIDE_LES \ - \ - m[dC ] = CSRC_C ; \ - m[dN ] = CSRC_N ; m[dS ] = CSRC_S ; \ - m[dE ] = CSRC_E ; m[dW ] = CSRC_W ; \ - m[dT ] = CSRC_T ; m[dB ] = CSRC_B ; \ - m[dNE] = CSRC_NE; m[dNW] = CSRC_NW; m[dSE] = CSRC_SE; m[dSW] = CSRC_SW; \ - m[dNT] = CSRC_NT; m[dNB] = CSRC_NB; m[dST] = CSRC_ST; m[dSB] = CSRC_SB; \ - m[dET] = CSRC_ET; m[dEB] = CSRC_EB; m[dWT] = CSRC_WT; m[dWB] = CSRC_WB; \ - \ - rho = MSRC_C + MSRC_N + MSRC_S + MSRC_E + MSRC_W + MSRC_T \ - + MSRC_B + MSRC_NE + MSRC_NW + MSRC_SE + MSRC_SW + MSRC_NT \ - + MSRC_NB + MSRC_ST + MSRC_SB + MSRC_ET + MSRC_EB + MSRC_WT + MSRC_WB; \ - ux = MSRC_E - MSRC_W + MSRC_NE - MSRC_NW + MSRC_SE - MSRC_SW \ - + MSRC_ET + MSRC_EB - MSRC_WT - MSRC_WB; \ - uy = MSRC_N - MSRC_S + MSRC_NE + MSRC_NW - MSRC_SE - MSRC_SW \ - + MSRC_NT + MSRC_NB - MSRC_ST - MSRC_SB; \ - uz = MSRC_T - MSRC_B + MSRC_NT - MSRC_NB + MSRC_ST - MSRC_SB \ - + MSRC_ET - MSRC_EB + MSRC_WT - MSRC_WB; \ - PRECOLLIDE_MODS(rho, ux,uy,uz, mLevel[lev].gravity); \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - COLL_CALCULATE_DFEQ(lcsmeq); \ - COLL_CALCULATE_NONEQTENSOR(lev, MSRC_) \ - COLL_CALCULATE_CSMOMEGAVAL(lev, lcsmomega); \ - CSMOMEGA_STATS(lev,lcsmomega); \ - \ - RAC(tcel,dC ) = (1.0-lcsmomega)*MSRC_C + lcsmomega*EQC ; \ - RAC(tcel,dN ) = (1.0-lcsmomega)*MSRC_N + lcsmomega*lcsmeq[ dN ]; \ - RAC(tcel,dS ) = (1.0-lcsmomega)*MSRC_S + lcsmomega*lcsmeq[ dS ]; \ - RAC(tcel,dE ) = (1.0-lcsmomega)*MSRC_E + lcsmomega*lcsmeq[ dE ]; \ - RAC(tcel,dW ) = (1.0-lcsmomega)*MSRC_W + lcsmomega*lcsmeq[ dW ]; \ - RAC(tcel,dT ) = (1.0-lcsmomega)*MSRC_T + lcsmomega*lcsmeq[ dT ]; \ - RAC(tcel,dB ) = (1.0-lcsmomega)*MSRC_B + lcsmomega*lcsmeq[ dB ]; \ - \ - RAC(tcel,dNE) = (1.0-lcsmomega)*MSRC_NE + lcsmomega*lcsmeq[ dNE]; \ - RAC(tcel,dNW) = (1.0-lcsmomega)*MSRC_NW + lcsmomega*lcsmeq[ dNW]; \ - RAC(tcel,dSE) = (1.0-lcsmomega)*MSRC_SE + lcsmomega*lcsmeq[ dSE]; \ - RAC(tcel,dSW) = (1.0-lcsmomega)*MSRC_SW + lcsmomega*lcsmeq[ dSW]; \ - \ - RAC(tcel,dNT) = (1.0-lcsmomega)*MSRC_NT + lcsmomega*lcsmeq[ dNT]; \ - RAC(tcel,dNB) = (1.0-lcsmomega)*MSRC_NB + lcsmomega*lcsmeq[ dNB]; \ - RAC(tcel,dST) = (1.0-lcsmomega)*MSRC_ST + lcsmomega*lcsmeq[ dST]; \ - RAC(tcel,dSB) = (1.0-lcsmomega)*MSRC_SB + lcsmomega*lcsmeq[ dSB]; \ - \ - RAC(tcel,dET) = (1.0-lcsmomega)*MSRC_ET + lcsmomega*lcsmeq[ dET]; \ - RAC(tcel,dEB) = (1.0-lcsmomega)*MSRC_EB + lcsmomega*lcsmeq[ dEB]; \ - RAC(tcel,dWT) = (1.0-lcsmomega)*MSRC_WT + lcsmomega*lcsmeq[ dWT]; \ - RAC(tcel,dWB) = (1.0-lcsmomega)*MSRC_WB + lcsmomega*lcsmeq[ dWB]; \ - - - -#define OPTIMIZED_STREAMCOLLIDE_UNUSED \ - \ - rho = CSRC_C + CSRC_N + CSRC_S + CSRC_E + CSRC_W + CSRC_T \ - + CSRC_B + CSRC_NE + CSRC_NW + CSRC_SE + CSRC_SW + CSRC_NT \ - + CSRC_NB + CSRC_ST + CSRC_SB + CSRC_ET + CSRC_EB + CSRC_WT + CSRC_WB; \ - ux = CSRC_E - CSRC_W + CSRC_NE - CSRC_NW + CSRC_SE - CSRC_SW \ - + CSRC_ET + CSRC_EB - CSRC_WT - CSRC_WB; \ - uy = CSRC_N - CSRC_S + CSRC_NE + CSRC_NW - CSRC_SE - CSRC_SW \ - + CSRC_NT + CSRC_NB - CSRC_ST - CSRC_SB; \ - uz = CSRC_T - CSRC_B + CSRC_NT - CSRC_NB + CSRC_ST - CSRC_SB \ - + CSRC_ET - CSRC_EB + CSRC_WT - CSRC_WB; \ - PRECOLLIDE_MODS(rho, ux,uy,uz, mLevel[lev].gravity); \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - COLL_CALCULATE_DFEQ(lcsmeq); \ - COLL_CALCULATE_NONEQTENSOR(lev, CSRC_) \ - COLL_CALCULATE_CSMOMEGAVAL(lev, lcsmomega); \ - \ - RAC(tcel,dC ) = (1.0-lcsmomega)*CSRC_C + lcsmomega*EQC ; \ - RAC(tcel,dN ) = (1.0-lcsmomega)*CSRC_N + lcsmomega*lcsmeq[ dN ]; \ - RAC(tcel,dS ) = (1.0-lcsmomega)*CSRC_S + lcsmomega*lcsmeq[ dS ]; \ - RAC(tcel,dE ) = (1.0-lcsmomega)*CSRC_E + lcsmomega*lcsmeq[ dE ]; \ - RAC(tcel,dW ) = (1.0-lcsmomega)*CSRC_W + lcsmomega*lcsmeq[ dW ]; \ - RAC(tcel,dT ) = (1.0-lcsmomega)*CSRC_T + lcsmomega*lcsmeq[ dT ]; \ - RAC(tcel,dB ) = (1.0-lcsmomega)*CSRC_B + lcsmomega*lcsmeq[ dB ]; \ - \ - RAC(tcel,dNE) = (1.0-lcsmomega)*CSRC_NE + lcsmomega*lcsmeq[ dNE]; \ - RAC(tcel,dNW) = (1.0-lcsmomega)*CSRC_NW + lcsmomega*lcsmeq[ dNW]; \ - RAC(tcel,dSE) = (1.0-lcsmomega)*CSRC_SE + lcsmomega*lcsmeq[ dSE]; \ - RAC(tcel,dSW) = (1.0-lcsmomega)*CSRC_SW + lcsmomega*lcsmeq[ dSW]; \ - \ - RAC(tcel,dNT) = (1.0-lcsmomega)*CSRC_NT + lcsmomega*lcsmeq[ dNT]; \ - RAC(tcel,dNB) = (1.0-lcsmomega)*CSRC_NB + lcsmomega*lcsmeq[ dNB]; \ - RAC(tcel,dST) = (1.0-lcsmomega)*CSRC_ST + lcsmomega*lcsmeq[ dST]; \ - RAC(tcel,dSB) = (1.0-lcsmomega)*CSRC_SB + lcsmomega*lcsmeq[ dSB]; \ - \ - RAC(tcel,dET) = (1.0-lcsmomega)*CSRC_ET + lcsmomega*lcsmeq[ dET]; \ - RAC(tcel,dEB) = (1.0-lcsmomega)*CSRC_EB + lcsmomega*lcsmeq[ dEB]; \ - RAC(tcel,dWT) = (1.0-lcsmomega)*CSRC_WT + lcsmomega*lcsmeq[ dWT]; \ - RAC(tcel,dWB) = (1.0-lcsmomega)*CSRC_WB + lcsmomega*lcsmeq[ dWB]; \ - - - -#define OPTIMIZED_STREAMCOLLIDE_NOLES \ - \ - rho = CSRC_C + CSRC_N + CSRC_S + CSRC_E + CSRC_W + CSRC_T \ - + CSRC_B + CSRC_NE + CSRC_NW + CSRC_SE + CSRC_SW + CSRC_NT \ - + CSRC_NB + CSRC_ST + CSRC_SB + CSRC_ET + CSRC_EB + CSRC_WT + CSRC_WB; \ - ux = CSRC_E - CSRC_W + CSRC_NE - CSRC_NW + CSRC_SE - CSRC_SW \ - + CSRC_ET + CSRC_EB - CSRC_WT - CSRC_WB; \ - uy = CSRC_N - CSRC_S + CSRC_NE + CSRC_NW - CSRC_SE - CSRC_SW \ - + CSRC_NT + CSRC_NB - CSRC_ST - CSRC_SB; \ - uz = CSRC_T - CSRC_B + CSRC_NT - CSRC_NB + CSRC_ST - CSRC_SB \ - + CSRC_ET - CSRC_EB + CSRC_WT - CSRC_WB; \ - PRECOLLIDE_MODS(rho, ux,uy,uz, mLevel[lev].gravity); \ - usqr = 1.5 * (ux*ux + uy*uy + uz*uz); \ - RAC(tcel,dC ) = (1.0-OMEGA(lev))*CSRC_C + OMEGA(lev)*EQC ; \ - RAC(tcel,dN ) = (1.0-OMEGA(lev))*CSRC_N + OMEGA(lev)*EQN ; \ - RAC(tcel,dS ) = (1.0-OMEGA(lev))*CSRC_S + OMEGA(lev)*EQS ; \ - RAC(tcel,dE ) = (1.0-OMEGA(lev))*CSRC_E + OMEGA(lev)*EQE ; \ - RAC(tcel,dW ) = (1.0-OMEGA(lev))*CSRC_W + OMEGA(lev)*EQW ; \ - RAC(tcel,dT ) = (1.0-OMEGA(lev))*CSRC_T + OMEGA(lev)*EQT ; \ - RAC(tcel,dB ) = (1.0-OMEGA(lev))*CSRC_B + OMEGA(lev)*EQB ; \ - \ - RAC(tcel,dNE) = (1.0-OMEGA(lev))*CSRC_NE + OMEGA(lev)*EQNE; \ - RAC(tcel,dNW) = (1.0-OMEGA(lev))*CSRC_NW + OMEGA(lev)*EQNW; \ - RAC(tcel,dSE) = (1.0-OMEGA(lev))*CSRC_SE + OMEGA(lev)*EQSE; \ - RAC(tcel,dSW) = (1.0-OMEGA(lev))*CSRC_SW + OMEGA(lev)*EQSW; \ - \ - RAC(tcel,dNT) = (1.0-OMEGA(lev))*CSRC_NT + OMEGA(lev)*EQNT; \ - RAC(tcel,dNB) = (1.0-OMEGA(lev))*CSRC_NB + OMEGA(lev)*EQNB; \ - RAC(tcel,dST) = (1.0-OMEGA(lev))*CSRC_ST + OMEGA(lev)*EQST; \ - RAC(tcel,dSB) = (1.0-OMEGA(lev))*CSRC_SB + OMEGA(lev)*EQSB; \ - \ - RAC(tcel,dET) = (1.0-OMEGA(lev))*CSRC_ET + OMEGA(lev)*EQET; \ - RAC(tcel,dEB) = (1.0-OMEGA(lev))*CSRC_EB + OMEGA(lev)*EQEB; \ - RAC(tcel,dWT) = (1.0-OMEGA(lev))*CSRC_WT + OMEGA(lev)*EQWT; \ - RAC(tcel,dWB) = (1.0-OMEGA(lev))*CSRC_WB + OMEGA(lev)*EQWB; \ - - - - - -// LES switching for OPT3D -#if USE_LES==1 -#define DEFAULT_COLLIDEG(grav) DEFAULT_COLLIDE_LES(grav) -#define OPTIMIZED_STREAMCOLLIDE OPTIMIZED_STREAMCOLLIDE_LES -#else -#define DEFAULT_COLLIDEG(grav) DEFAULT_COLLIDE_NOLES(grav) -#define OPTIMIZED_STREAMCOLLIDE OPTIMIZED_STREAMCOLLIDE_NOLES -#endif - -#endif // 3D, opt OPT3D==true - -#define USQRMAXCHECK(Cusqr,Cux,Cuy,Cuz, CmMaxVlen,CmMxvx,CmMxvy,CmMxvz) \ - if(Cusqr>CmMaxVlen) { \ - CmMxvx = Cux; CmMxvy = Cuy; CmMxvz = Cuz; CmMaxVlen = Cusqr; \ - } /* stats */ - - - -/****************************************************************************** - * interpolateCellFromCoarse macros - *****************************************************************************/ - - -// WOXDY_N = Weight Order X Dimension Y _ number N -#define WO1D1 ( 1.0/ 2.0) -#define WO1D2 ( 1.0/ 4.0) -#define WO1D3 ( 1.0/ 8.0) - -#define WO2D1_1 (-1.0/16.0) -#define WO2D1_9 ( 9.0/16.0) - -#define WO2D2_11 (WO2D1_1 * WO2D1_1) -#define WO2D2_19 (WO2D1_9 * WO2D1_1) -#define WO2D2_91 (WO2D1_9 * WO2D1_1) -#define WO2D2_99 (WO2D1_9 * WO2D1_9) - -#define WO2D3_111 (WO2D1_1 * WO2D1_1 * WO2D1_1) -#define WO2D3_191 (WO2D1_9 * WO2D1_1 * WO2D1_1) -#define WO2D3_911 (WO2D1_9 * WO2D1_1 * WO2D1_1) -#define WO2D3_991 (WO2D1_9 * WO2D1_9 * WO2D1_1) -#define WO2D3_119 (WO2D1_1 * WO2D1_1 * WO2D1_9) -#define WO2D3_199 (WO2D1_9 * WO2D1_1 * WO2D1_9) -#define WO2D3_919 (WO2D1_9 * WO2D1_1 * WO2D1_9) -#define WO2D3_999 (WO2D1_9 * WO2D1_9 * WO2D1_9) - -#if FSGR_STRICT_DEBUG==1 -#define ADD_INT_DFSCHECK(alev, ai,aj,ak, at, afac, l) \ - if( (((1.0-(at))>0.0) && (!(QCELL((alev), (ai),(aj),(ak),mLevel[(alev)].setCurr , l) > -1.0 ))) || \ - ((( (at))>0.0) && (!(QCELL((alev), (ai),(aj),(ak),mLevel[(alev)].setOther, l) > -1.0 ))) ){ \ - errMsg("INVDFSCHECK", " l"<<(alev)<<" "<0.0) && (!(RFLAG((alev), (ai),(aj),(ak),mLevel[(alev)].setCurr )&(CFInter|CFFluid|CFGrCoarseInited) ))) || \ - ((( (at))>0.0) && (!(RFLAG((alev), (ai),(aj),(ak),mLevel[(alev)].setOther)&(CFInter|CFFluid|CFGrCoarseInited) ))) ){ \ - errMsg("INVFLAGCINTCHECK", " l"<<(alev)<<" at:"<<(at)<<" "<mPanic) { errMsg("interpolateCellFromCoarse", "ICFC_DFOUT cell "< only current -// t=0.5 -> mix -// t=1.0 -> only other -#if OPT3D==0 -#define ADD_INT_DFS(alev, ai,aj,ak, at, afac) \ - ADD_INT_FLAGCHECK(alev, ai,aj,ak, at, afac); \ - FORDF0{ \ - LbmFloat df = ( \ - QCELL((alev), (ai),(aj),(ak),mLevel[(alev)].setCurr , l)*(1.0-(at)) + \ - QCELL((alev), (ai),(aj),(ak),mLevel[(alev)].setOther, l)*( (at)) \ - ) ; \ - ADD_INT_DFSCHECK(alev, ai,aj,ak, at, afac, l); \ - df *= (afac); \ - rho += df; \ - ux += (this->dfDvecX[l]*df); \ - uy += (this->dfDvecY[l]*df); \ - uz += (this->dfDvecZ[l]*df); \ - intDf[l] += df; \ - } -// write interpolated dfs back to cell (correct non-eq. parts) -#define IDF_WRITEBACK_ \ - FORDF0{ \ - LbmFloat eq = getCollideEq(l, rho,ux,uy,uz);\ - QCELL(lev,i,j,k, dstSet, l) = (eq+ (intDf[l]-eq)*mDfScaleDown);\ - } \ - /* check that all values are ok */ \ - INTDEBOUT -#define IDF_WRITEBACK \ - LbmFloat omegaDst, omegaSrc;\ - /* smago new */ \ - LbmFloat feq[LBM_DFNUM]; \ - LbmFloat dfScale = mDfScaleDown; \ - FORDF0{ \ - feq[l] = getCollideEq(l, rho,ux,uy,uz); \ - } \ - if(mLevel[lev ].lcsmago>0.0) {\ - LbmFloat Qo = this->getLesNoneqTensorCoeff(intDf,feq); \ - omegaDst = this->getLesOmega(mLevel[lev+0].omega,mLevel[lev+0].lcsmago,Qo); \ - omegaSrc = this->getLesOmega(mLevel[lev-1].omega,mLevel[lev-1].lcsmago,Qo); \ - } else {\ - omegaDst = mLevel[lev+0].omega; \ - omegaSrc = mLevel[lev-1].omega;\ - } \ - \ - dfScale = (mLevel[lev+0].timestep/mLevel[lev-1].timestep)* (1.0/omegaDst-1.0)/ (1.0/omegaSrc-1.0); \ - FORDF0{ \ - /*errMsg("SMAGO"," org"<cDfNum; l++) { - if(this->lesCoeffOffdiag[m][l]==0.0) continue; - qadd += this->lesCoeffOffdiag[m][l]*(df[l]-feq[l]); - } - Qo += (qadd*qadd); - } - Qo *= 2.0; // off diag twice - for(int m=0; mcDfNum; l++) { - if(this->lesCoeffDiag[m][l]==0.0) continue; - qadd += this->lesCoeffDiag[m][l]*(df[l]-feq[l]); - } - Qo += (qadd*qadd); - } - Qo = sqrt(Qo); - return Qo; -}; - -inline LbmFloat LbmFsgrSolver::getLesOmega(LbmFloat omega, LbmFloat csmago, LbmFloat Qo) { - const LbmFloat tau = 1.0/omega; - const LbmFloat nu = (2.0*tau-1.0) * (1.0/6.0); - const LbmFloat C = csmago; - const LbmFloat Csqr = C*C; - LbmFloat S = -nu + sqrt( nu*nu + 18.0*Csqr*Qo ) / (6.0*Csqr); - return( 1.0/( 3.0*( nu+Csqr*S ) +0.5 ) ); -} - -#define DEBUG_CALCPRINTCELL(str,df) {\ - LbmFloat prho=df[0], pux=0., puy=0., puz=0.; \ - for(int dfl=1; dflcDfNum; dfl++) { \ - prho += df[dfl]; \ - pux += (this->dfDvecX[dfl]*df[dfl]); \ - puy += (this->dfDvecY[dfl]*df[dfl]); \ - puz += (this->dfDvecZ[dfl]*df[dfl]); \ - } \ - errMsg("DEBUG_CALCPRINTCELL",">"<cDfNum; l++) { - rho += df[l]; - ux += (this->dfDvecX[l]*df[l]); - uy += (this->dfDvecY[l]*df[l]); - uz += (this->dfDvecZ[l]*df[l]); - } - - - PRECOLLIDE_MODS(rho,ux,uy,uz, gravity); - for(l=0; lcDfNum; l++) { - feq[l] = getCollideEq(l,rho,ux,uy,uz); - } - - if(csmago>0.0) { - Qo = getLesNoneqTensorCoeff(df,feq); - omegaNew = getLesOmega(omega,csmago,Qo); - } else { - omegaNew = omega; // smago off... - } - if(newOmegaRet) *newOmegaRet = omegaNew; // return value for stats - if(newQoRet) *newQoRet = Qo; // return value of non-eq. stress tensor - - for(l=0; lcDfNum; l++) { - df[l] = (1.0-omegaNew ) * df[l] + omegaNew * feq[l]; - } - //if((i==16)&&(j==10)) DEBUG_CALCPRINTCELL( "2dcoll "< -#include -#ifndef sqrtf -#define sqrtf sqrt -#endif - -/****************************************************************************** - * helper functions - *****************************************************************************/ - -// try to enhance surface? -#define SURFACE_ENH 2 - -//! for raytracing -void LbmFsgrSolver::prepareVisualization( void ) { - int lev = mMaxRefine; - int workSet = mLevel[lev].setCurr; - - int mainGravDir=6; // if normalizing fails, we asume z-direction gravity - LbmFloat mainGravLen = 0.; - FORDF1{ - LbmFloat thisGravLen = dot(LbmVec(dfVecX[l],dfVecY[l],dfVecZ[l]), mLevel[mMaxRefine].gravity ); - if(thisGravLen>mainGravLen) { - mainGravLen = thisGravLen; - mainGravDir = l; - } - } - -#if LBMDIM==2 - // 2d, place in the middle of isofield slice (k=2) -# define ZKD1 0 - // 2d z offset = 2, lbmGetData adds 1, so use one here -# define ZKOFF 1 - // reset all values... - for(int k= 0; k< 5; ++k) - for(int j=0;jlbmGetData(i,j,ZKOFF)=0.0; - } -#else // LBMDIM==2 - // 3d, use normal bounds -# define ZKD1 1 -# define ZKOFF k - // reset all values... - for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) - for(int j=0;jlbmGetData(i,j,ZKOFF)=0.0; - } -#endif // LBMDIM==2 - - // MPT, ignore - if((glob_mpactive) && (glob_mpnum>1) && (glob_mpindex==0)) { - mpIso->resetAll(0.); - } - - - LbmFloat minval = mIsoValue*1.05; // / mIsoWeight[13]; - // add up... - float val = 0.0; - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) - for(int j=1;j6)) { - *mpIso->lbmGetData(i,j,ZKOFF) += minval; - } else if((noslipbnd)&&(intercnt>0)) { - // necessary? - *mpIso->lbmGetData(i,j,ZKOFF) += mIsoValue*0.9; - } else { - // nothing to do... - } - - continue; - } else if(cflag&(CFNoNbEmpty|CFFluid)) { - // no empty nb interface cells are treated as full - val=1.0; - } else { - val = (QCELL(lev, i,j,k,workSet, dFfrac)); - } - - if(noslipbnd) { - if(vallbmGetData(i,j,ZKOFF) += minval-( val * mIsoWeight[13] ); - } - } else { // all others, unused? - continue; - } -#endif // SURFACE_ENH>0 - - *mpIso->lbmGetData( i-1 , j-1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[0] ); - *mpIso->lbmGetData( i , j-1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[1] ); - *mpIso->lbmGetData( i+1 , j-1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[2] ); - - *mpIso->lbmGetData( i-1 , j ,ZKOFF-ZKD1) += ( val * mIsoWeight[3] ); - *mpIso->lbmGetData( i , j ,ZKOFF-ZKD1) += ( val * mIsoWeight[4] ); - *mpIso->lbmGetData( i+1 , j ,ZKOFF-ZKD1) += ( val * mIsoWeight[5] ); - - *mpIso->lbmGetData( i-1 , j+1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[6] ); - *mpIso->lbmGetData( i , j+1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[7] ); - *mpIso->lbmGetData( i+1 , j+1 ,ZKOFF-ZKD1) += ( val * mIsoWeight[8] ); - - - *mpIso->lbmGetData( i-1 , j-1 ,ZKOFF ) += ( val * mIsoWeight[9] ); - *mpIso->lbmGetData( i , j-1 ,ZKOFF ) += ( val * mIsoWeight[10] ); - *mpIso->lbmGetData( i+1 , j-1 ,ZKOFF ) += ( val * mIsoWeight[11] ); - - *mpIso->lbmGetData( i-1 , j ,ZKOFF ) += ( val * mIsoWeight[12] ); - *mpIso->lbmGetData( i , j ,ZKOFF ) += ( val * mIsoWeight[13] ); - *mpIso->lbmGetData( i+1 , j ,ZKOFF ) += ( val * mIsoWeight[14] ); - - *mpIso->lbmGetData( i-1 , j+1 ,ZKOFF ) += ( val * mIsoWeight[15] ); - *mpIso->lbmGetData( i , j+1 ,ZKOFF ) += ( val * mIsoWeight[16] ); - *mpIso->lbmGetData( i+1 , j+1 ,ZKOFF ) += ( val * mIsoWeight[17] ); - - - *mpIso->lbmGetData( i-1 , j-1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[18] ); - *mpIso->lbmGetData( i , j-1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[19] ); - *mpIso->lbmGetData( i+1 , j-1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[20] ); - - *mpIso->lbmGetData( i-1 , j ,ZKOFF+ZKD1) += ( val * mIsoWeight[21] ); - *mpIso->lbmGetData( i , j ,ZKOFF+ZKD1)+= ( val * mIsoWeight[22] ); - *mpIso->lbmGetData( i+1 , j ,ZKOFF+ZKD1) += ( val * mIsoWeight[23] ); - - *mpIso->lbmGetData( i-1 , j+1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[24] ); - *mpIso->lbmGetData( i , j+1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[25] ); - *mpIso->lbmGetData( i+1 , j+1 ,ZKOFF+ZKD1) += ( val * mIsoWeight[26] ); - } - - // TEST!? -#if SURFACE_ENH>=2 - - if(mFsSurfGenSetting&fssgNoObs) { - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) - for(int j=1;j=mLevel[mMaxRefine].lSizex) - //|| (nj>=mLevel[mMaxRefine].lSizey) - //|| (nk>=mLevel[mMaxRefine].lSizez) ) continue; - } - - if(nbored&CFInter) { - if(avgfcnt>0.) avgfill/=avgfcnt; - *mpIso->lbmGetData(i,j,ZKOFF) = avgfill; continue; - } - else if(nbored&CFFluid) { - *mpIso->lbmGetData(i,j,ZKOFF) = 1.; continue; - } - - } - } - - // move surface towards inner "row" of obstacle - // cells if necessary (all obs cells without fluid/inter - // nbs (=iso==0) next to obstacles...) - for(int k= getForZMin1(); k< getForZMax1(lev); ++k) - for(int j=1;jlbmGetData(i,j,ZKOFF)==0.)) { - int bndnbcnt=0; - FORDF1 { - const int ni = i+dfVecX[l]; - const int nj = j+dfVecY[l]; - const int nk = ZKOFF+dfVecZ[l]; - const CellFlagType nbflag = RFLAG(lev, ni,nj,nk, workSet); - if(nbflag&CFBnd) bndnbcnt++; - } - if(bndnbcnt>0) *mpIso->lbmGetData(i,j,ZKOFF)=mIsoValue*0.95; - } - } - } - // */ - - if(mFsSurfGenSetting&fssgNoNorth) - for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) - for(int j=0;jlbmGetData(0, j,ZKOFF) = *mpIso->lbmGetData(1, j,ZKOFF); - } - if(mFsSurfGenSetting&fssgNoEast) - for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) - for(int i=0;ilbmGetData(i,0, ZKOFF) = *mpIso->lbmGetData(i,1, ZKOFF); - } - if(mFsSurfGenSetting&fssgNoSouth) - for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) - for(int j=0;jlbmGetData(mLevel[lev].lSizex-1,j,ZKOFF) = *mpIso->lbmGetData(mLevel[lev].lSizex-2,j,ZKOFF); - } - if(mFsSurfGenSetting&fssgNoWest) - for(int k= getForZMinBnd(); k< getForZMaxBnd(lev); ++k) - for(int i=0;ilbmGetData(i,mLevel[lev].lSizey-1,ZKOFF) = *mpIso->lbmGetData(i,mLevel[lev].lSizey-2,ZKOFF); - } - if(LBMDIM>2) { - if(mFsSurfGenSetting&fssgNoBottom) - for(int j=0;jlbmGetData(i,j,0 ) = *mpIso->lbmGetData(i,j,1 ); - } - if(mFsSurfGenSetting&fssgNoTop) - for(int j=0;jlbmGetData(i,j,mLevel[lev].lSizez-1) = *mpIso->lbmGetData(i,j,mLevel[lev].lSizez-2); - } - } -#endif // SURFACE_ENH>=2 - - - // update preview, remove 2d? - if((mOutputSurfacePreview)&&(LBMDIM==3)) { - int pvsx = (int)(mPreviewFactor*mSizex); - int pvsy = (int)(mPreviewFactor*mSizey); - int pvsz = (int)(mPreviewFactor*mSizez); - //float scale = (float)mSizex / previewSize; - LbmFloat scalex = (LbmFloat)mSizex/(LbmFloat)pvsx; - LbmFloat scaley = (LbmFloat)mSizey/(LbmFloat)pvsy; - LbmFloat scalez = (LbmFloat)mSizez/(LbmFloat)pvsz; - for(int k= 0; k< (pvsz-1); ++k) - for(int j=0;j< pvsy;j++) - for(int i=0;i< pvsx;i++) { - *mpPreviewSurface->lbmGetData(i,j,k) = *mpIso->lbmGetData( (int)(i*scalex), (int)(j*scaley), (int)(k*scalez) ); - } - // set borders again... - for(int k= 0; k< (pvsz-1); ++k) { - for(int j=0;j< pvsy;j++) { - *mpPreviewSurface->lbmGetData(0,j,k) = *mpIso->lbmGetData( 0, (int)(j*scaley), (int)(k*scalez) ); - *mpPreviewSurface->lbmGetData(pvsx-1,j,k) = *mpIso->lbmGetData( mSizex-1, (int)(j*scaley), (int)(k*scalez) ); - } - for(int i=0;i< pvsx;i++) { - *mpPreviewSurface->lbmGetData(i,0,k) = *mpIso->lbmGetData( (int)(i*scalex), 0, (int)(k*scalez) ); - *mpPreviewSurface->lbmGetData(i,pvsy-1,k) = *mpIso->lbmGetData( (int)(i*scalex), mSizey-1, (int)(k*scalez) ); - } - } - for(int j=0;jlbmGetData(i,j,0) = *mpIso->lbmGetData( (int)(i*scalex), (int)(j*scaley) , 0); - *mpPreviewSurface->lbmGetData(i,j,pvsz-1) = *mpIso->lbmGetData( (int)(i*scalex), (int)(j*scaley) , mSizez-1); - } - - if(mFarFieldSize>=1.2) { - // also remove preview border - for(int k= 0; k< (pvsz-1); ++k) { - for(int j=0;j< pvsy;j++) { - *mpPreviewSurface->lbmGetData(0,j,k) = - *mpPreviewSurface->lbmGetData(1,j,k) = - *mpPreviewSurface->lbmGetData(2,j,k); - *mpPreviewSurface->lbmGetData(pvsx-1,j,k) = - *mpPreviewSurface->lbmGetData(pvsx-2,j,k) = - *mpPreviewSurface->lbmGetData(pvsx-3,j,k); - //0.0; - } - for(int i=0;i< pvsx;i++) { - *mpPreviewSurface->lbmGetData(i,0,k) = - *mpPreviewSurface->lbmGetData(i,1,k) = - *mpPreviewSurface->lbmGetData(i,2,k); - *mpPreviewSurface->lbmGetData(i,pvsy-1,k) = - *mpPreviewSurface->lbmGetData(i,pvsy-2,k) = - *mpPreviewSurface->lbmGetData(i,pvsy-3,k); - //0.0; - } - } - for(int j=0;jlbmGetData(i,j,0) = - *mpPreviewSurface->lbmGetData(i,j,1) = - *mpPreviewSurface->lbmGetData(i,j,2); - *mpPreviewSurface->lbmGetData(i,j,pvsz-1) = - *mpPreviewSurface->lbmGetData(i,j,pvsz-2) = - *mpPreviewSurface->lbmGetData(i,j,pvsz-3); - //0.0; - } - } - } - - // MPT - #if LBM_INCLUDE_TESTSOLVERS==1 - mrIsoExchange(); - #endif // LBM_INCLUDE_TESTSOLVERS==1 - - return; -} - -/*! calculate speeds of fluid objects (or inflow) */ -void LbmFsgrSolver::recalculateObjectSpeeds() { - const bool debugRecalc = false; - int numobjs = (int)(this->mpGiObjects->size()); - // note - (numobjs + 1) is entry for domain settings - - if(debugRecalc) errMsg("recalculateObjectSpeeds","start, #obj:"<255-1) { - errFatal("LbmFsgrSolver::recalculateObjectSpeeds","More than 256 objects currently not supported...",SIMWORLD_INITERROR); - return; - } - mObjectSpeeds.resize(numobjs+1); - for(int i=0; i<(int)(numobjs+0); i++) { - mObjectSpeeds[i] = vec2L(this->mpParam->calculateLattVelocityFromRw( vec2P( (*this->mpGiObjects)[i]->getInitialVelocity(mSimulationTime) ))); - if(debugRecalc) errMsg("recalculateObjectSpeeds","id"<mpGiObjects)[i]->getInitialVelocity(mSimulationTime) ); - } - - // also reinit part slip values here - mObjectPartslips.resize(numobjs+1); - for(int i=0; i<=(int)(numobjs+0); i++) { - if(impGiObjects)[i]->getGeoPartSlipValue(); - } else { - // domain setting - mObjectPartslips[i] = this->mDomainPartSlipValue; - } - LbmFloat set = mObjectPartslips[i]; - - // as in setInfluenceVelocity - const LbmFloat dt = mLevel[mMaxRefine].timestep; - const LbmFloat dtInter = 0.01; - //LbmFloat facFv = 1.-set; - // mLevel[mMaxRefine].timestep - LbmFloat facNv = (LbmFloat)( 1.-pow( (double)(set), (double)(dt/dtInter)) ); - errMsg("mObjectPartslips","id:"< LbmFsgrSolver::getDebugObjects() { - vector debo; - if(this->mOutputSurfacePreview) { - debo.push_back( mpPreviewSurface ); - } -#if LBM_INCLUDE_TESTSOLVERS==1 - if(mUseTestdata) { - vector tdebo; - tdebo = mpTest->getDebugObjects(); - for(size_t i=0; isetStart( this->mvGeoStart + ntlVec3Gfx(mLevel[mMaxRefine].nodeSize*0.5) ); - partt->setEnd ( this->mvGeoEnd + ntlVec3Gfx(mLevel[mMaxRefine].nodeSize*0.5) ); - - partt->setSimStart( ntlVec3Gfx(0.0) ); - partt->setSimEnd ( ntlVec3Gfx(mSizex, mSizey, getForZMaxBnd(mMaxRefine)) ); - - while( (numgetNumInitialParticles()) && (tries<100*partt->getNumInitialParticles()) ) { - LbmFloat x,y,z,t; - x = 1.0+(( (LbmFloat)(mSizex-3.) ) * (rand()/(RAND_MAX+1.0)) ); - y = 1.0+(( (LbmFloat)(mSizey-3.) ) * (rand()/(RAND_MAX+1.0)) ); - z = 1.0+(( (LbmFloat) getForZMax1(mMaxRefine)-2. )* (rand()/(RAND_MAX+1.0)) ); - int i = (int)(x+0.5); - int j = (int)(y+0.5); - int k = (int)(z+0.5); - if(LBMDIM==2) { - k = 0; z = 0.5; // place in the middle of domain - } - - //if( RFLAG(mMaxRefine, i,j,k, workSet)& (CFFluid) ) - //&& ( RFLAG(mMaxRefine, i,j,k, workSet)& CFNoNbFluid ) - //if( RFLAG(mMaxRefine, i,j,k, workSet) & (CFFluid|CFInter|CFMbndInflow) ) { - if( RFLAG(mMaxRefine, i,j,k, workSet) & (CFNoBndFluid|CFUnused) ) { - bool cellOk = true; - //? FORDF1 { if(!(RFLAG_NB(mMaxRefine,i,j,k,workSet, l) & CFFluid)) cellOk = false; } - if(!cellOk) continue; - // in fluid... - partt->addParticle(x,y,z); - partt->getLast()->setStatus(PART_IN); - partt->getLast()->setType(PART_TRACER); - - partt->getLast()->setSize(1.); - // randomize size - partt->getLast()->setSize(0.5 + (rand()/(RAND_MAX+1.0))); - - if( ( partt->getInitStart()>0.) - && ( partt->getInitEnd()>0.) - && ( partt->getInitEnd()>partt->getInitStart() )) { - t = partt->getInitStart()+ (partt->getInitEnd()-partt->getInitStart())*(rand()/(RAND_MAX+1.0)); - partt->getLast()->setLifeTime( -t ); - } - num++; - } - tries++; - } // */ - - /*FSGR_FORIJK1(mMaxRefine) { - if( (RFLAG(mMaxRefine,i,j,k, workSet) & (CFNoBndFluid)) ) { - LbmFloat rndn = (rand()/(RAND_MAX+1.0)); - if(rndn>0.0) { - ntlVec3Gfx pos( (LbmFloat)(i)-0.5, (LbmFloat)(j)-0.5, (LbmFloat)(k)-0.5 ); - if(LBMDIM==2) { pos[2]=0.5; } - partt->addParticle( pos[0],pos[1],pos[2] ); - partt->getLast()->setStatus(PART_IN); - partt->getLast()->setType(PART_TRACER); - partt->getLast()->setSize(1.0); - } - } - } // */ - - - // DEBUG TEST -#if LBM_INCLUDE_TESTSOLVERS==1 - if(mUseTestdata) { - const bool partDebug=false; - if(mpTest->mPartTestcase==0){ errMsg("LbmTestdata"," part init "<mPartTestcase); } - if(mpTest->mPartTestcase==-12){ - const int lev = mMaxRefine; - for(int i=5;i<15;i++) { - LbmFloat x,y,z; - y = 0.5+(LbmFloat)(i); - x = mLevel[lev].lSizex/20.0*10.0; - z = mLevel[lev].lSizez/20.0*2.0; - partt->addParticle(x,y,z); - partt->getLast()->setStatus(PART_IN); - partt->getLast()->setType(PART_BUBBLE); - partt->getLast()->setSize( (-4.0+(LbmFloat)i)/1.0 ); - if(partDebug) errMsg("PARTTT","SET "<getLast()->getPos() <<" s"<getLast()->getSize() ); - } - } - if(mpTest->mPartTestcase==-11){ - const int lev = mMaxRefine; - for(int i=5;i<15;i++) { - LbmFloat x,y,z; - y = 10.5+(LbmFloat)(i); - x = mLevel[lev].lSizex/20.0*10.0; - z = mLevel[lev].lSizez/20.0*40.0; - partt->addParticle(x,y,z); - partt->getLast()->setStatus(PART_IN); - partt->getLast()->setType(PART_DROP); - partt->getLast()->setSize( (-4.0+(LbmFloat)i)/1.0 ); - if(partDebug) errMsg("PARTTT","SET "<getLast()->getPos() <<" s"<getLast()->getSize() ); - } - } - // place floats on rectangular region FLOAT_JITTER_BND - if(mpTest->mPartTestcase==-10){ - const int lev = mMaxRefine; - const int sx = mLevel[lev].lSizex; - const int sy = mLevel[lev].lSizey; - //for(int j=-(int)(sy*0.25);j<-(int)(sy*0.25)+2;++j) { for(int i=-(int)(sx*0.25);i<-(int)(sy*0.25)+2;++i) { - //for(int j=-(int)(sy*1.25);j<(int)(2.25*sy);++j) { for(int i=-(int)(sx*1.25);i<(int)(2.25*sx);++i) { - for(int j=-(int)(sy*0.3);j<(int)(1.3*sy);++j) { for(int i=-(int)(sx*0.3);i<(int)(1.3*sx);++i) { - //for(int j=-(int)(sy*0.2);j<(int)(0.2*sy);++j) { for(int i= (int)(sx*0.5);i<= (int)(0.51*sx);++i) { - LbmFloat x,y,z; - x = 0.0+(LbmFloat)(i); - y = 0.0+(LbmFloat)(j); - //z = mLevel[lev].lSizez/10.0*2.5 - 1.0; - z = mLevel[lev].lSizez/20.0*9.5 - 1.0; - //z = mLevel[lev].lSizez/20.0*4.5 - 1.0; - partt->addParticle(x,y,z); - //if( (i>0)&&(i0)&&(jgetLast()->setStatus(PART_IN); } else { partt->getLast()->setStatus(PART_OUT); } - partt->getLast()->setStatus(PART_IN); - partt->getLast()->setType(PART_FLOAT); - partt->getLast()->setSize( 15.0 ); - if(partDebug) errMsg("PARTTT","SET "<getLast()->getPos() <<" s"<getLast()->getSize() ); - } - } } - } - // DEBUG TEST -#endif // LBM_INCLUDE_TESTSOLVERS - - - debMsgStd("LbmFsgrSolver::initParticles",DM_MSG,"Added "<mPartGenProb<<", tries:"<getNumParticles()) return 1; - - return 0; -} - -// helper function for particle debugging -/*static string getParticleStatusString(int state) { - std::ostringstream out; - if(state&PART_DROP) out << "dropp "; - if(state&PART_TRACER) out << "tracr "; - if(state&PART_BUBBLE) out << "bubbl "; - if(state&PART_FLOAT) out << "float "; - if(state&PART_INTER) out << "inter "; - - if(state&PART_IN) out << "inn "; - if(state&PART_OUT) out << "out "; - if(state&PART_INACTIVE) out << "INACT "; - if(state&PART_OUTFLUID) out << "outfluid "; - return out.str(); -} // */ - -#define P_CHANGETYPE(p, newtype) \ - p->setLifeTime(0.); \ - /* errMsg("PIT","U pit"<<(p)->getId()<<" pos:"<< (p)->getPos()<<" status:"<getFlags())<<" to "<< (newtype) ); */ \ - p->setType(newtype); - -// tracer defines -#define TRACE_JITTER 0.025 -#define TRACE_RAND (rand()/(RAND_MAX+1.0))*TRACE_JITTER-(TRACE_JITTER*0.5) -#define FFGET_NORM(var,dl) \ - if(RFLAG_NB(lev,i,j,k,workSet, dl) &(CFInter)){ (var) = QCELL_NB(lev,i,j,k,workSet,dl,dFfrac); } \ - else if(RFLAG_NB(lev,i,j,k,workSet, dl) &(CFFluid|CFUnused)){ (var) = 1.; } else (var) = 0.0; - -// float jitter -#define FLOAT_JITTER_BND (FLOAT_JITTER*2.0) -#define FLOAT_JITTBNDRAND(x) ((rand()/(RAND_MAX+1.0))*FLOAT_JITTER_BND*(1.-(x/(LbmFloat)maxdw))-(FLOAT_JITTER_BND*(1.-(x)/(LbmFloat)maxdw)*0.5)) - -#define DEL_PART { \ - /*errMsg("PIT","DEL AT "<< __LINE__<<" type:"<getType()<<" "); */ \ - p->setActive( false ); \ - continue; } - -void LbmFsgrSolver::advanceParticles() { - const int level = mMaxRefine; - const int workSet = mLevel[level].setCurr; - LbmFloat vx=0.0,vy=0.0,vz=0.0; - //int debugOutCounter=0; // debug output counter - - myTime_t parttstart = getTime(); - const LbmFloat cellsize = this->mpParam->getCellSize(); - const LbmFloat timestep = this->mpParam->getTimestep(); - //const LbmFloat viscAir = 1.79 * 1e-5; // RW2L kin. viscosity, mu - //const LbmFloat viscWater = 1.0 * 1e-6; // RW2L kin. viscosity, mu - const LbmFloat rhoAir = 1.2; // [kg m^-3] RW2L - const LbmFloat rhoWater = 1000.0; // RW2L - const LbmFloat minDropSize = 0.0005; // [m], = 2mm RW2L - const LbmVec velAir(0.); // [m / s] - - const LbmFloat r1 = 0.005; // r max - const LbmFloat r2 = 0.0005; // r min - const LbmFloat v1 = 9.0; // v max - const LbmFloat v2 = 2.0; // v min - const LbmVec rwgrav = vec2L( this->mpParam->getGravity(mSimulationTime) ); - const bool useff = (mFarFieldSize>1.2); // if(mpTest->mFarfMode>0){ - - // TODO scale bubble/part damping dep. on timestep, also drop bnd rev damping - const int cutval = mCutoff; // use full border!? - if(this->mStepCnt%50==49) { mpParticles->cleanup(); } - for(vector::iterator pit= mpParticles->getParticlesBegin(); - pit!= mpParticles->getParticlesEnd(); pit++) { - //if((*pit).getPos()[2]>10.) errMsg("PIT"," pit"<<(*pit).getId()<<" pos:"<< (*pit).getPos()<<" status:["<getLifeTime()<0.){ - if(p->getLifeTime() < -mSimulationTime) continue; - else p->setLifeTime(-mLevel[level].timestep); // zero for following update - } - int i,j,k; - p->setLifeTime(p->getLifeTime()+mLevel[level].timestep); - - // nearest neighbor, particle positions don't include empty bounds - ntlVec3Gfx pos = p->getPos(); - i= (int)pos[0]; j= (int)pos[1]; k= (int)pos[2];// no offset necessary - if(LBMDIM==2) { k = 0; } - - // only testdata handling, all for sws -#if LBM_INCLUDE_TESTSOLVERS==1 - if(useff && (mpTest->mFarfMode>0)) { - p->setStatus(PART_OUT); - mpTest->handleParticle(p, i,j,k); continue; - } -#endif // LBM_INCLUDE_TESTSOLVERS==1 - - // in out tests - if(p->getStatus()&PART_IN) { // IN - if( (imSizex-1-cutval)|| - (jmSizey-1-cutval) - //||(kmSizez-1-cutval) - ) { - if(!useff) { DEL_PART; - } else { - p->setStatus(PART_OUT); - } - } - } else { // OUT rough check - // check in again? - if( (i>=cutval)&&(i<=mSizex-1-cutval)&& - (j>=cutval)&&(j<=mSizey-1-cutval) - ) { - p->setStatus(PART_IN); - } - } - - if( (p->getType()==PART_BUBBLE) || - (p->getType()==PART_TRACER) ) { - - // no interpol - vx = vy = vz = 0.0; - if(p->getStatus()&PART_IN) { // IN - if(k>=cutval) { - if(k>mSizez-1-cutval) DEL_PART; - - if( RFLAG(level, i,j,k, workSet)&(CFFluid|CFUnused) ) { - // still ok - int partLev = level; - int si=i, sj=j, sk=k; - while(partLev>0 && RFLAG(partLev, si,sj,sk, workSet)&(CFUnused)) { - partLev--; - si/=2; - sj/=2; - sk/=2; - } - // get velocity from fluid cell - if( RFLAG(partLev, si,sj,sk, workSet)&(CFFluid) ) { - LbmFloat *ccel = RACPNT(partLev, si,sj,sk, workSet); - FORDF1{ - LbmFloat cdf = RAC(ccel, l); - // TODO update below - vx += (this->dfDvecX[l]*cdf); - vy += (this->dfDvecY[l]*cdf); - vz += (this->dfDvecZ[l]*cdf); - } - // remove gravity influence - const LbmFloat lesomega = mLevel[level].omega; // no les - vx -= mLevel[level].gravity[0] * lesomega*0.5; - vy -= mLevel[level].gravity[1] * lesomega*0.5; - vz -= mLevel[level].gravity[2] * lesomega*0.5; - } // fluid vel - - } else { // OUT - // out of bounds, deactivate... - // FIXME make fsgr treatment - if(p->getType()==PART_BUBBLE) { P_CHANGETYPE(p, PART_FLOAT ); continue; } - } - } else { - // below 3d region, just rise - } - } else { // OUT -# if LBM_INCLUDE_TESTSOLVERS==1 - if(useff) { mpTest->handleParticle(p, i,j,k); } - else DEL_PART; -# else // LBM_INCLUDE_TESTSOLVERS==1 - DEL_PART; -# endif // LBM_INCLUDE_TESTSOLVERS==1 - // TODO use x,y vel...? - } - - ntlVec3Gfx v = p->getVel(); // dampen... - if( (useff)&& (p->getType()==PART_BUBBLE) ) { - // test rise - - if(mPartUsePhysModel) { - LbmFloat radius = p->getSize() * minDropSize; - //LbmVec velPart = vec2L(p->getVel()) *cellsize/timestep; // L2RW, lattice velocity - //LbmVec velWater = LbmVec(vx,vy,vz) *cellsize/timestep;// L2RW, fluid velocity - //LbmVec velRel = velWater - velPart; - //LbmFloat velRelNorm = norm(velRel); - //LbmFloat pvolume = rhoAir * 4.0/3.0 * M_PI* radius*radius*radius; // volume: 4/3 pi r^3 - - //LbmVec fb = -rwgrav* pvolume *rhoWater; - //LbmVec fd = velRel*6.0*M_PI*radius* (1e-3); //viscWater; - //LbmVec change = (fb+fd) *10.0*timestep *(timestep/cellsize); - /*if(debugOutCounter<0) { - errMsg("PIT","BTEST1 vol="<getVel())) * 6.0*M_PI*radius* (1e-3); //viscWater; - LbmFloat w = 0.99; - vz = (1.0-w)*vz + w*(p->getVel()[2]-0.5*(p->getSize()/5.0)*mLevel[level].gravity[2]); - v = ntlVec3Gfx(vx,vy,vz)+vec2G(fd2); - p->setVel( v ); - } else { - // non phys, half old, half fluid, use slightly slower acc - v = v*0.5 + ntlVec3Gfx(vx,vy,vz)* 0.5-vec2G(mLevel[level].gravity)*0.5; - p->setVel( v * 0.99 ); - } - p->advanceVel(); - - } else if(p->getType()==PART_TRACER) { - v = ntlVec3Gfx(vx,vy,vz); - CellFlagType fflag = RFLAG(level, i,j,k, workSet); - - if(fflag&(CFFluid|CFInter) ) { p->setInFluid(true); - } else { p->setInFluid(false); } - - if( (( fflag&CFFluid ) && ( fflag&CFNoBndFluid )) || - (( fflag&CFInter ) && (!(fflag&CFNoNbFluid)) ) ) { - // only real fluid -# if LBMDIM==3 - p->advance( TRACE_RAND,TRACE_RAND,TRACE_RAND); -# else - p->advance( TRACE_RAND,TRACE_RAND, 0.); -# endif - - } else { - // move inwards along normal, make sure normal is valid first - // todo use class funcs! - const int lev = level; - LbmFloat nx=0.,ny=0.,nz=0., nv1,nv2; - bool nonorm = false; - if(i<=0) { nx = -1.; nonorm = true; } - if(i>=mSizex-1) { nx = 1.; nonorm = true; } - if(j<=0) { ny = -1.; nonorm = true; } - if(j>=mSizey-1) { ny = 1.; nonorm = true; } -# if LBMDIM==3 - if(k<=0) { nz = -1.; nonorm = true; } - if(k>=mSizez-1) { nz = 1.; nonorm = true; } -# endif // LBMDIM==3 - if(!nonorm) { - FFGET_NORM(nv1,dE); FFGET_NORM(nv2,dW); - nx = 0.5* (nv2-nv1); - FFGET_NORM(nv1,dN); FFGET_NORM(nv2,dS); - ny = 0.5* (nv2-nv1); -# if LBMDIM==3 - FFGET_NORM(nv1,dT); FFGET_NORM(nv2,dB); - nz = 0.5* (nv2-nv1); -# else // LBMDIM==3 - nz = 0.; -# endif // LBMDIM==3 - } else { - v = p->getVel() + vec2G(mLevel[level].gravity); - } - p->advanceVec( (ntlVec3Gfx(nx,ny,nz)) * -0.1 ); // + vec2G(mLevel[level].gravity); - } - } - - p->setVel( v ); - p->advanceVel(); - } - - // drop handling - else if(p->getType()==PART_DROP) { - ntlVec3Gfx v = p->getVel(); // dampen... - - if(mPartUsePhysModel) { - LbmFloat radius = p->getSize() * minDropSize; - LbmVec velPart = vec2L(p->getVel()) *cellsize /timestep; // * cellsize / timestep; // L2RW, lattice velocity - LbmVec velRel = velAir - velPart; - //LbmVec velRelLat = velRel /cellsize*timestep; // L2RW - LbmFloat velRelNorm = norm(velRel); - // TODO calculate values in lattice units, compute CD?!??! - LbmFloat mb = rhoWater * 4.0/3.0 * M_PI* radius*radius*radius; // mass: 4/3 pi r^3 rho - const LbmFloat rw = (r1-radius)/(r1-r2); - const LbmFloat rmax = (0.5 + 0.5*rw); - const LbmFloat vmax = (v2 + (v1-v2)* (1.0-rw) ); - const LbmFloat cd = (rmax) * (velRelNorm)/(vmax); - - LbmVec fg = rwgrav * mb;// * (1.0-rhoAir/rhoWater); - LbmVec fd = velRel* velRelNorm* cd*M_PI *rhoAir *0.5 *radius*radius; - LbmVec change = (fg+ fd ) *timestep / mb *(timestep/cellsize); - //if(k>0) { errMsg("\nPIT","NTEST1 mb="<setVel( v*0.9 ); // restdamping - } else { - p->addToVel( vec2G(mLevel[level].gravity) ); - } - } // OLD - p->advanceVel(); - - if(p->getStatus()&PART_IN) { // IN - if(kgetSize(); - const LbmFloat dropmass = ParticleObject::getMass(mPartDropMassSub*size); - bool orgcellok = false; - if( (oi<0)||(oi>mSizex-1)|| - (oj<0)||(oj>mSizey-1)|| - (ok<0)||(ok>mSizez-1) ) { - // org cell not ok! - } else if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){ - orgcellok = true; - } else { - // search upward for interface - oi=i; oj=j; ok=k; - for(int kk=0; kk<5 && ok<=mSizez-2; kk++) { - ok++; // check sizez-2 due to this increment! - if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){ - kk = 5; orgcellok = true; - } - } - } - - //errMsg("PTIMPULSE"," new v"< 0.166*0.166) { - v *= 1./sqrtf((float)vlensqr)*0.166; - } - // compute cell velocity - LbmFloat *tcel = RACPNT(level, oi,oj,ok, workSet); - LbmFloat velUx=0., velUy=0., velUz=0.; - FORDF0 { - velUx += (this->dfDvecX[l]*RAC(tcel,l)); - velUy += (this->dfDvecY[l]*RAC(tcel,l)); - velUz += (this->dfDvecZ[l]*RAC(tcel,l)); - } - // add impulse - /* - LbmFloat cellVelSqr = velUx*velUx+ velUy*velUy+ velUz*velUz; - //errMsg("PTIMPULSE"," new v"<getStatus() ); - } - } - myTime_t parttend = getTime(); - debMsgStd("LbmFsgrSolver::advanceParticles",DM_MSG,"Time for particle update:"<< getTimeString(parttend-parttstart)<<", #particles:"<getNumParticles() , 10 ); -} - -void LbmFsgrSolver::notifySolverOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename) { - int workSet = mLevel[mMaxRefine].setCurr; - std::ostringstream name; - - // debug - raw dump of ffrac values, as text! - if(mDumpRawText) { - name << outfilename<< frameNrStr <<".dump"; - FILE *file = fopen(name.str().c_str(),"w"); - if(file) { - - for(int k= getForZMinBnd(); k< getForZMaxBnd(mMaxRefine); ++k) { - for(int j=0;j1.) val=1.; - } - if(RFLAG(mMaxRefine, i,j,k, workSet) & CFFluid) val = 1.; - fprintf(file, "%f ",val); // text - //errMsg("W", PRINT_IJK<<" val:"<1.) val=1.; - } - if(RFLAG(mMaxRefine, i,j,k, workSet) & CFFluid) val = 1.; - fwrite( &val, sizeof(val), 1, file); // binary - } - } - } - fclose(file); - } // file - } // unzipped - else { - // zipped, use iso values - prepareVisualization(); - name << outfilename<< frameNrStr <<".bdump.gz"; - gzFile gzf = gzopen(name.str().c_str(),"wb9"); - if(gzf) { - // write size - int s; - s=mSizex; gzwrite(gzf, &s, sizeof(s)); - s=mSizey; gzwrite(gzf, &s, sizeof(s)); - s=mSizez; gzwrite(gzf, &s, sizeof(s)); - - // write isovalues - for(int k= getForZMinBnd(); k< getForZMaxBnd(mMaxRefine); ++k) { - for(int j=0;jlbmGetData( i,j,k ); - gzwrite(gzf, &val, sizeof(val)); - } - } - } - gzclose(gzf); - } // gzf - } // zip - } // bin dump - - dumptype = 0; frameNr = 0; // get rid of warning -} - -/*! move a particle at a boundary */ -void LbmFsgrSolver::handleObstacleParticle(ParticleObject *p) { - //if(normNoSqrt(v)<=0.) continue; // skip stuck - /* - p->setVel( v * -1. ); // revert - p->advanceVel(); // move back twice... - if( RFLAG(mMaxRefine, i,j,k, workSet)& (CFBndNoslip)) { - p->setVel( v * -0.5 ); // revert & dampen - } - p->advanceVel(); - // */ - // TODO mark/remove stuck parts!? - - const int level = mMaxRefine; - const int workSet = mLevel[level].setCurr; - LbmVec v = vec2L( p->getVel() ); - if(normNoSqrt(v)<=0.) { - p->setVel(vec2G(mLevel[level].gravity)); - } - - CellFlagType pflag = CFBnd; - ntlVec3Gfx posOrg(p->getPos()); - ntlVec3Gfx npos(0.); - int ni=1,nj=1,nk=1; - int tries = 0; - - // try to undo movement - p->advanceVec( (p->getVel()-vec2G(mLevel[level].gravity)) * -2.); - - npos = p->getPos(); ni= (int)npos[0]; - nj= (int)npos[1]; nk= (int)npos[2]; - if(LBMDIM==2) { nk = 0; } - //errMsg("BOUNDCPAR"," t"<setActive( false ); - return; - } - pflag = RFLAG(level, ni,nj,nk, workSet); - - // try to force particle out of boundary - bool haveNorm = false; - LbmVec bnormal; - if(pflag&CFBnd) { - npos = posOrg; ni= (int)npos[0]; - nj= (int)npos[1]; nk= (int)npos[2]; - if(LBMDIM==2) { nk = 0; } - - computeObstacleSurfaceNormalAcc(ni,nj,nk, &bnormal[0]); - haveNorm = true; - normalize(bnormal); - bnormal *= 0.25; - - tries = 1; - while(pflag&CFBnd && tries<=5) { - // use increasing step sizes - p->advanceVec( vec2G( bnormal *0.5 *(gfxReal)tries ) ); - npos = p->getPos(); - ni= (int)npos[0]; - nj= (int)npos[1]; - nk= (int)npos[2]; - - // delete out of domain - if(!checkDomainBounds(level,ni,nj,nk)) { - //errMsg("BOUNDCPAR"," DEL! "); - p->setActive( false ); - return; - } - pflag = RFLAG(level, ni,nj,nk, workSet); - tries++; - } - - // really stuck, delete... - if(pflag&CFBnd) { - p->setActive( false ); - return; - } - } - - // not in bound anymore! - if(!haveNorm) { - CellFlagType *bflag = &RFLAG(level, ni,nj,nk, workSet); - LbmFloat *bcell = RACPNT(level, ni,nj,nk, workSet); - computeObstacleSurfaceNormal(bcell,bflag, &bnormal[0]); - } - normalize(bnormal); - LbmVec normComp = bnormal * dot(vec2L(v),bnormal); - //errMsg("BOUNDCPAR","bnormal"<setVel(vec2G(v)); - p->advanceVel(); -} - -/*****************************************************************************/ -/*! internal quick print function (for debugging) */ -/*****************************************************************************/ -void -LbmFsgrSolver::printLbmCell(int level, int i, int j, int k, int set) { - stdCellId *newcid = new stdCellId; - newcid->level = level; - newcid->x = i; - newcid->y = j; - newcid->z = k; - - // this function is not called upon clicking, then its from setMouseClick - debugPrintNodeInfo( newcid, set ); - delete newcid; -} -void -LbmFsgrSolver::debugMarkCellCall(int level, int vi,int vj,int vk) { - stdCellId *newcid = new stdCellId; - newcid->level = level; - newcid->x = vi; - newcid->y = vj; - newcid->z = vk; - this->addCellToMarkedList( newcid ); -} - - -/*****************************************************************************/ -// implement CellIterator interface -/*****************************************************************************/ - - - -// values from guiflkt.cpp -extern double guiRoiSX, guiRoiSY, guiRoiSZ, guiRoiEX, guiRoiEY, guiRoiEZ; -extern int guiRoiMaxLev, guiRoiMinLev; -#define CID_SX (int)( (mLevel[cid->level].lSizex-1) * guiRoiSX ) -#define CID_SY (int)( (mLevel[cid->level].lSizey-1) * guiRoiSY ) -#define CID_SZ (int)( (mLevel[cid->level].lSizez-1) * guiRoiSZ ) - -#define CID_EX (int)( (mLevel[cid->level].lSizex-1) * guiRoiEX ) -#define CID_EY (int)( (mLevel[cid->level].lSizey-1) * guiRoiEY ) -#define CID_EZ (int)( (mLevel[cid->level].lSizez-1) * guiRoiEZ ) - -CellIdentifierInterface* -LbmFsgrSolver::getFirstCell( ) { - int level = mMaxRefine; - -#if LBMDIM==3 - if(mMaxRefine>0) { level = mMaxRefine-1; } // NO1HIGHESTLEV DEBUG -#endif - level = guiRoiMaxLev; - if(level>mMaxRefine) level = mMaxRefine; - - //errMsg("LbmFsgrSolver::getFirstCell","Celliteration started..."); - stdCellId *cid = new stdCellId; - cid->level = level; - cid->x = CID_SX; - cid->y = CID_SY; - cid->z = CID_SZ; - return cid; -} - -LbmFsgrSolver::stdCellId* -LbmFsgrSolver::convertBaseCidToStdCid( CellIdentifierInterface* basecid) { - //stdCellId *cid = dynamic_cast( basecid ); - stdCellId *cid = (stdCellId*)( basecid ); - return cid; -} - -void LbmFsgrSolver::advanceCell( CellIdentifierInterface* basecid) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - if(cid->getEnd()) return; - - //debugOut(" ADb "<x<<","<y<<","<z<<" e"<getEnd(), 10); - cid->x++; - if(cid->x > CID_EX){ cid->x = CID_SX; cid->y++; - if(cid->y > CID_EY){ cid->y = CID_SY; cid->z++; - if(cid->z > CID_EZ){ - cid->level--; - cid->x = CID_SX; - cid->y = CID_SY; - cid->z = CID_SZ; - if(cid->level < guiRoiMinLev) { - cid->level = guiRoiMaxLev; - cid->setEnd( true ); - } - } - } - } - //debugOut(" ADa "<x<<","<y<<","<z<<" e"<getEnd(), 10); -} - -bool LbmFsgrSolver::noEndCell( CellIdentifierInterface* basecid) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - return (!cid->getEnd()); -} - -void LbmFsgrSolver::deleteCellIterator( CellIdentifierInterface** cid ) { - delete *cid; - *cid = NULL; -} - -CellIdentifierInterface* LbmFsgrSolver::getCellAt( ntlVec3Gfx pos ) { - //int cellok = false; - pos -= (this->mvGeoStart); - - LbmFloat mmaxsize = mLevel[mMaxRefine].nodeSize; - for(int level=mMaxRefine; level>=0; level--) { // finest first - //for(int level=0; level<=mMaxRefine; level++) { // coarsest first - LbmFloat nsize = mLevel[level].nodeSize; - int x,y,z; - // CHECK +- maxsize? - x = (int)((pos[0]+0.5*mmaxsize) / nsize ); - y = (int)((pos[1]+0.5*mmaxsize) / nsize ); - z = (int)((pos[2]+0.5*mmaxsize) / nsize ); - if(LBMDIM==2) z = 0; - - // double check... - if(x<0) continue; - if(y<0) continue; - if(z<0) continue; - if(x>=mLevel[level].lSizex) continue; - if(y>=mLevel[level].lSizey) continue; - if(z>=mLevel[level].lSizez) continue; - - // return fluid/if/border cells - if( ( (RFLAG(level, x,y,z, mLevel[level].setCurr)&(CFUnused)) ) || - ( (levellevel = level; - newcid->x = x; - newcid->y = y; - newcid->z = z; - //errMsg("cellAt",this->mName<<" "<level].setCurr; - //return mLevel[cid->level].setOther; -} - -int LbmFsgrSolver::getCellLevel ( CellIdentifierInterface* basecid) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - return cid->level; -} - -ntlVec3Gfx LbmFsgrSolver::getCellOrigin ( CellIdentifierInterface* basecid) { - ntlVec3Gfx ret; - - stdCellId *cid = convertBaseCidToStdCid(basecid); - ntlVec3Gfx cs( mLevel[cid->level].nodeSize ); - if(LBMDIM==2) { cs[2] = 0.0; } - - if(LBMDIM==2) { - ret =(this->mvGeoStart + ntlVec3Gfx( cid->x *cs[0], cid->y *cs[1], (this->mvGeoEnd[2]-this->mvGeoStart[2])*0.5 ) - + ntlVec3Gfx(0.0,0.0,cs[1]*-0.25)*cid->level ) - +getCellSize(basecid); - } else { - ret =(this->mvGeoStart + ntlVec3Gfx( cid->x *cs[0], cid->y *cs[1], cid->z *cs[2] )) - +getCellSize(basecid); - } - return (ret); -} - -ntlVec3Gfx LbmFsgrSolver::getCellSize ( CellIdentifierInterface* basecid) { - // return half size - stdCellId *cid = convertBaseCidToStdCid(basecid); - ntlVec3Gfx retvec( mLevel[cid->level].nodeSize * 0.5 ); - // 2d display as rectangles - if(LBMDIM==2) { retvec[2] = 0.0; } - return (retvec); -} - -LbmFloat LbmFsgrSolver::getCellDensity ( CellIdentifierInterface* basecid,int set) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - - // skip non-fluid cells - if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&(CFFluid|CFInter)) { - // ok go on... - } else { - return 0.; - } - - LbmFloat rho = 0.0; - FORDF0 { rho += QCELL(cid->level, cid->x,cid->y,cid->z, set, l); } // ORG - return ((rho-1.0) * mLevel[cid->level].simCellSize / mLevel[cid->level].timestep) +1.0; // ORG - /*if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&CFInter) { // test - LbmFloat ux,uy,uz; - ux=uy=uz= 0.0; - int lev = cid->level; - LbmFloat df[27], feqOld[27]; - FORDF0 { - rho += QCELL(lev, cid->x,cid->y,cid->z, set, l); - ux += this->dfDvecX[l]* QCELL(lev, cid->x,cid->y,cid->z, set, l); - uy += this->dfDvecY[l]* QCELL(lev, cid->x,cid->y,cid->z, set, l); - uz += this->dfDvecZ[l]* QCELL(lev, cid->x,cid->y,cid->z, set, l); - df[l] = QCELL(lev, cid->x,cid->y,cid->z, set, l); - } - FORDF0 { - feqOld[l] = getCollideEq(l, rho,ux,uy,uz); - } - // debugging mods - //const LbmFloat Qo = this->getLesNoneqTensorCoeff(df,feqOld); - //const LbmFloat modOmega = this->getLesOmega(mLevel[lev].omega, mLevel[lev].lcsmago,Qo); - //rho = (2.0-modOmega) *25.0; - //rho = Qo*100.0; - //if(cid->x==24){ errMsg("MODOMT"," at "<x,cid->y,cid->z)<<" = "<level, cid->x,cid->y,cid->z, set)&(CFFluid|CFInter)) { - // ok go on... - } else { - return LbmVec(0.0); - } - - LbmFloat ux,uy,uz; - ux=uy=uz= 0.0; - FORDF0 { - ux += this->dfDvecX[l]* QCELL(cid->level, cid->x,cid->y,cid->z, set, l); - uy += this->dfDvecY[l]* QCELL(cid->level, cid->x,cid->y,cid->z, set, l); - uz += this->dfDvecZ[l]* QCELL(cid->level, cid->x,cid->y,cid->z, set, l); - } - LbmVec vel(ux,uy,uz); - // TODO fix... - return (vel * mLevel[cid->level].simCellSize / mLevel[cid->level].timestep * this->mDebugVelScale); // normal -} - -LbmFloat LbmFsgrSolver::getCellDf( CellIdentifierInterface* basecid,int set, int dir) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - return QCELL(cid->level, cid->x,cid->y,cid->z, set, dir); -} -LbmFloat LbmFsgrSolver::getCellMass( CellIdentifierInterface* basecid,int set) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - return QCELL(cid->level, cid->x,cid->y,cid->z, set, dMass); -} -LbmFloat LbmFsgrSolver::getCellFill( CellIdentifierInterface* basecid,int set) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&CFInter) return QCELL(cid->level, cid->x,cid->y,cid->z, set, dFfrac); - if(RFLAG(cid->level, cid->x,cid->y,cid->z, set)&CFFluid) return 1.0; - return 0.0; - //return QCELL(cid->level, cid->x,cid->y,cid->z, set, dFfrac); -} -CellFlagType LbmFsgrSolver::getCellFlag( CellIdentifierInterface* basecid,int set) { - stdCellId *cid = convertBaseCidToStdCid(basecid); - return RFLAG(cid->level, cid->x,cid->y,cid->z, set); -} - -LbmFloat LbmFsgrSolver::getEquilDf( int l ) { - return this->dfEquil[l]; -} - - -ntlVec3Gfx LbmFsgrSolver::getVelocityAt (float xp, float yp, float zp) { - ntlVec3Gfx avgvel(0.0); - LbmFloat avgnum = 0.; - - // taken from getCellAt! - const int level = mMaxRefine; - const int workSet = mLevel[level].setCurr; - const LbmFloat nsize = mLevel[level].nodeSize; - const int x = (int)((-this->mvGeoStart[0]+xp-0.5*nsize) / nsize ); - const int y = (int)((-this->mvGeoStart[1]+yp-0.5*nsize) / nsize ); - int z = (int)((-this->mvGeoStart[2]+zp-0.5*nsize) / nsize ); - if(LBMDIM==2) z=0; - //errMsg("DUMPVEL","p"<dfVecX[l]; - const int j = y+this->dfVecY[l]; - const int k = z+this->dfVecZ[l]; - - if( (i<0) || (j<0) || (k<0) - || (i>=mLevel[level].lSizex) - || (j>=mLevel[level].lSizey) - || (k>=mLevel[level].lSizez) ) continue; - - if( (RFLAG(level, i,j,k, mLevel[level].setCurr)&(CFFluid|CFInter)) ) { - ntlVec3Gfx vel(0.0); - LbmFloat *ccel = RACPNT(level, i,j,k ,workSet); // omp - for(int n=1; ncDfNum; n++) { - vel[0] += (this->dfDvecX[n]*RAC(ccel,n)); - vel[1] += (this->dfDvecY[n]*RAC(ccel,n)); - vel[2] += (this->dfDvecZ[n]*RAC(ccel,n)); - } - - avgvel += vel; - avgnum += 1.0; - if(l==0) { // center slightly more weight - avgvel += vel; avgnum += 1.0; - } - } // */ - } - - if(avgnum>0.) { - ntlVec3Gfx retv = avgvel / avgnum; - retv *= nsize/mLevel[level].timestep; - // scale for current animation settings (frame time) - retv *= mpParam->getCurrentAniFrameTime(); - //errMsg("DUMPVEL","t"<getCurrentAniFrameTime() ); - return retv; - } - // no cells here...? - //errMsg("DUMPVEL"," at "<( set, this ); - lbmDebugDisplay( set ); -} -#endif - -/*****************************************************************************/ -// strict debugging functions -/*****************************************************************************/ -#if FSGR_STRICT_DEBUG==1 -#define STRICT_EXIT *((int *)0)=0; - -int LbmFsgrSolver::debLBMGI(int level, int ii,int ij,int ik, int is) { - if(level < 0){ errMsg("LbmStrict::debLBMGI"," invLev- l"< mMaxRefine){ errMsg("LbmStrict::debLBMGI"," invLev+ l"<mLevel[level].lSizex-1){ errMsg("LbmStrict"," invX+ l"<mLevel[level].lSizey-1){ errMsg("LbmStrict"," invY+ l"<mLevel[level].lSizez-1){ errMsg("LbmStrict"," invZ+ l"<1){ errMsg("LbmStrict"," invS+ l"<this->cDirNum){ errMsg("LbmStrict"," invD+ l"<this->cDirNum){ errMsg("LbmStrict"," invD+ l"< mMaxRefine){ errMsg("LbmStrict::debLBMQI"," invLev+ l"<mLevel[level].lSizex-1){ errMsg("LbmStrict"," invX+ l"<mLevel[level].lSizey-1){ errMsg("LbmStrict"," invY+ l"<mLevel[level].lSizez-1){ errMsg("LbmStrict"," invZ+ l"<1){ errMsg("LbmStrict"," invS+ l"<this->cDfNum){ // dFfrac is an exception - if((l != dMass) && (l != dFfrac) && (l != dFlux)){ errMsg("LbmStrict"," invD+ "<<" l"<mInitDone) && (is!=mLevel[level].setCurr)){ STRICT_EXIT; } // COMPRT debug -#endif // COMPRESSGRIDS==1 - return _LBMQI(level, ii,ij,ik, is, l); -}; - -LbmFloat& LbmFsgrSolver::debQCELL(int level, int xx,int yy,int zz,int set,int l) { - //errMsg("LbmStrict","debQCELL debug: l"<this->cDfNum){ errMsg("LbmStrict"," invD+ l"<this->cDfNum){ errMsg("LbmStrict"," invD+ l"<dTotalNum){ errMsg("LbmStrict"," invD+ "<<" l"<this->cDfNum){ // dFfrac is an exception - //if((l != dMass) && (l != dFfrac) && (l != dFlux)){ errMsg("LbmStrict"," invD+ "<<" l"<getNodeInfoString(); - - for(size_t i=0; igetCellOrigin( cell ); - ntlVec3Gfx halfsize = this->getCellSize( cell ); - int set = this->getCellSet( cell ); - debMsgStd("debugPrintNodeInfo",DM_NOTIFY, "Printing cell info '"<getAsString()<<" from "<getName()<<" currSet:"<=0) setmax = 1; - - for(int s=0; s=0) workset = forceSet; - debMsgStd(" ",DM_MSG, "Printing set:"<getCellDf(cell,workset,l), 1); - } - } - if(printRho) { - debMsgStd(" ",DM_MSG, " Rho: "<getCellDensity(cell,workset), 1); - } - if(printVel) { - debMsgStd(" ",DM_MSG, " Vel: "<getCellVelocity(cell,workset), 1); - } - if(printFlag) { - CellFlagType flag = this->getCellFlag(cell,workset); - debMsgStd(" ",DM_MSG, " Flg: "<< flag<<" "<getCellMass(cell,workset), 1); - } - // dirty... TODO fixme - debMsgStd(" ",DM_MSG, " Flx: "<getCellDf(cell,workset,dFlux), 1); - } -} - - diff --git a/intern/elbeem/intern/utilities.cpp b/intern/elbeem/intern/utilities.cpp deleted file mode 100644 index 40596681b90..00000000000 --- a/intern/elbeem/intern/utilities.cpp +++ /dev/null @@ -1,498 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Global C style utility funcions - * - *****************************************************************************/ - - -#include -#include -#ifdef WIN32 -// for timing -#include -#else -#include -#include -#include -#endif - -#include "utilities.h" - -#ifndef NOPNG -#ifdef WIN32 -#include "png.h" -#else -#include -#endif -#endif // NOPNG -#include - -// global debug level -#ifdef DEBUG -int gDebugLevel = DEBUG; -#else // DEBUG -int gDebugLevel = 0; -#endif // DEBUG - -// global world state, acces with get/setElbeemState -int gElbeemState = SIMWORLD_INVALID; - -// access global state of elbeem simulator -void setElbeemState(int set) { - gElbeemState = set; -} -int getElbeemState(void) { - return gElbeemState; -} -int isSimworldOk(void) { - return (getElbeemState() >=0); -} - -// last error as string, acces with get/setElbeemErrorString -char gElbeemErrorString[256] = {'-','\0' }; - -// access elbeem simulator error string -void setElbeemErrorString(const char* set) { - strncpy(gElbeemErrorString, set, 256); -} -char* getElbeemErrorString(void) { return gElbeemErrorString; } - - -//! for interval debugging output -myTime_t globalIntervalTime = 0; -//! color output setting for messages (0==off, else on) -#ifdef WIN32 -// switch off first call -#define DEF_globalColorSetting -1 -#else // WIN32 -// linux etc., on by default -#define DEF_globalColorSetting 1 -#endif // WIN32 -int globalColorSetting = DEF_globalColorSetting; // linux etc., on by default -int globalFirstEnvCheck = 0; -void resetGlobalColorSetting() { globalColorSetting = DEF_globalColorSetting; } - -// global string for formatting vector output, TODO test!? -const char *globVecFormatStr = "V[%f,%f,%f]"; - - -// global mp on/off switch -bool glob_mpactive = false; -// global access to mpi index, for debugging (e.g. in utilities.cpp) -int glob_mpnum = -1; -int glob_mpindex = -1; -int glob_mppn = -1; - - -//----------------------------------------------------------------------------- -// helper function that converts a string to integer, -// and returns an alternative value if the conversion fails -int convertString2Int(const char *str, int alt) -{ - int val; - char *endptr; - bool success=true; - - val = strtol(str, &endptr, 10); - if( (str==endptr) || - ((str!=endptr) && (*endptr != '\0')) ) success = false; - - if(!success) { - return alt; - } - return val; -} - -//----------------------------------------------------------------------------- -//! helper function that converts a flag field to a readable integer -string convertFlags2String(int flags) { - std::ostringstream ret; - ret <<"("; - int max = sizeof(int)*8; - for(int i=0; i4) && (filentemp[filentemp.length()-4]=='.')) { - filentemp[filentemp.length()-4] = '\0'; - } - std::ostringstream filennew; - filennew << filentemp.c_str(); - filennew << ".ppm.gz"; - - gzf = gzopen(filennew.str().c_str(), "wb9"); - if(!gzf) goto fail; - - gzprintf(gzf,"P6\n%d %d\n255\n",w,h); - // output binary pixels - for(int j=0;j0) { - ret << ms<<"m"<< ss<<"s" ; - } else { - if(ps>0) { - ret << ss<<"."; - if(ps<10) { ret <<"0"; } - ret <e[0]) || - (s[1]>e[1]) || - (s[2]>e[2]) ) { - errFatal("checkBoundingBox","Check by '"<0) { - myTime_t currTime = getTime(); - if((currTime - globalIntervalTime)>interval) { - globalIntervalTime = getTime(); - } else { - return; - } - } - - // colors off? - if( (globalColorSetting == -1) || // off for e.g. win32 - ((globalColorSetting==1) && ((id==DM_FATAL)||( getenv("ELBEEM_NOCOLOROUT") )) ) - ) { - // only reset once - col_std = col_black = col_dark_gray = col_bright_gray = - col_red = col_bright_red = col_green = - col_bright_green = col_bright_yellow = - col_yellow = col_cyan = col_bright_cyan = - col_purple = col_bright_purple = col_neutral = ""; - globalColorSetting = 0; - } - - std::ostringstream sout; - if(id==DM_DIRECT) { - sout << msg; - } else { - sout << col_cyan<< from; - switch(id) { - case DM_MSG: - sout << col_std << " message:"; - break; - case DM_NOTIFY: - sout << col_bright_cyan << " note:" << col_std; - break; - case DM_IMPORTANT: - sout << col_yellow << " important:" << col_std; - break; - case DM_WARNING: - sout << col_bright_red << " warning:" << col_std; - break; - case DM_ERROR: - sout << col_red << " error:" << col_red; - break; - case DM_FATAL: - sout << col_red << " fatal("<=0) { - mpin << "elbeem_log_"<< glob_mpindex <<".txt"; - } else { - mpin << "elbeem_log_ini.txt"; - } - fileout = 1; - strncpy(filen, mpin.str().c_str(),255); filen[255]='\0'; -#else - strncpy(filen, "elbeem_debug_log.txt",255); -#endif - -#ifdef WIN32 - // windows causes trouble with direct output - fileout = 1; -#endif // WIN32 - -#if PARALLEL==1 - fileout = 2;// buffer out, switch off again... - if(globOutstrForce) fileout=1; -#endif - if(getenv("ELBEEM_FORCESTDOUT")) { - fileout = 0;// always direct out - } - //fprintf(stdout,"out deb %d, %d, '%s',l%d \n",globOutstrForce,fileout, filen, globOutstr.str().size() ); - -#if PARALLEL==1 -#pragma omp critical -#endif // PARALLEL==1 - { - if(fileout==1) { - // debug level is >0 anyway, so write to file... - FILE *logf = fopen(filen,"a+"); - // dont complain anymore here... - if(logf) { - if(globOutstrForce) { - fprintf(logf, "%s",globOutstr.str().c_str() ); - globOutstr.str(""); // reset - } - fprintf(logf, "%s",sout.str().c_str() ); - fclose(logf); - } - } else if(fileout==2) { - globOutstr << sout.str(); - } else { - // normal stdout output - fprintf(stdout, "%s",sout.str().c_str() ); - if(id!=DM_DIRECT) fflush(stdout); - } - } // omp crit -} - -// helper functions from external program using elbeem lib (e.g. Blender) -/* set gDebugLevel according to env. var */ -extern "C" -void elbeemCheckDebugEnv(void) { - const char *strEnvName = "BLENDER_ELBEEMDEBUG"; - const char *strEnvName2 = "ELBEEM_DEBUGLEVEL"; - if(globalFirstEnvCheck) return; - - if(getenv(strEnvName)) { - gDebugLevel = atoi(getenv(strEnvName)); - if(gDebugLevel>0) debMsgStd("performElbeemSimulation",DM_NOTIFY,"Using envvar '"<0) debMsgStd("performElbeemSimulation",DM_NOTIFY,"Using envvar '"<10) gDebugLevel = 0; // only use valid values - globalFirstEnvCheck = 1; -} - -/* elbeem debug output function */ -extern "C" -void elbeemDebugOut(char *msg) { - elbeemCheckDebugEnv(); - // external messages default to debug level 5... - if(gDebugLevel<5) return; - // delegate to messageOutputFunc - messageOutputFunc("[External]",DM_MSG,msg,0); -} - -/* set elbeem debug output level (0=off to 10=full on) */ -extern "C" -void elbeemSetDebugLevel(int level) { - if(level<0) level=0; - if(level>10) level=10; - gDebugLevel=level; -} - - -/* estimate how much memory a given setup will require */ -#include "solver_interface.h" - -extern "C" -double elbeemEstimateMemreq(int res, - float sx, float sy, float sz, - int refine, char *retstr) { - int resx = res, resy = res, resz = res; - // dont use real coords, just place from 0.0 to sizeXYZ - ntlVec3Gfx vgs(0.0), vge(sx,sy,sz); - initGridSizes( resx,resy,resz, vgs,vge, refine, 0); - - double memreq = -1.0; - string memreqStr(""); - // ignore farfield for now... - calculateMemreqEstimate(resx,resy,resz, refine, 0., &memreq, NULL, &memreqStr ); - - if(retstr) { - // copy at max. 32 characters - strncpy(retstr, memreqStr.c_str(), 32 ); - retstr[31] = '\0'; - } - return memreq; -} - - - diff --git a/intern/elbeem/intern/utilities.h b/intern/elbeem/intern/utilities.h deleted file mode 100644 index 274862b93b4..00000000000 --- a/intern/elbeem/intern/utilities.h +++ /dev/null @@ -1,205 +0,0 @@ -/** \file - * \ingroup elbeem - */ -/****************************************************************************** - * - * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method - * Copyright 2003-2006 Nils Thuerey - * - * Global C style utility funcions - * - *****************************************************************************/ -#ifndef UTILITIES_H -#include "ntl_vector3dim.h" - - -/* debugging outputs , debug level 0 (off) to 10 (max) */ -#ifdef ELBEEM_PLUGIN -#ifdef DEBUG -#undef DEBUG -#endif -#define DEBUG 0 -#else // ELBEEM_PLUGIN -#define DEBUG 10 -#endif // ELBEEM_PLUGIN -extern "C" int gDebugLevel; - - -// time measurements -typedef unsigned long myTime_t; - - -// state of the simulation world -// default -#define SIMWORLD_INVALID 0 -// performing init -#define SIMWORLD_INITIALIZING 1 -// after init, before starting simulation -#define SIMWORLD_INITED 2 -// stop of the simulation run, can be continued later -#define SIMWORLD_STOP 3 -// error during init -#define SIMWORLD_INITERROR -1 -// error during simulation -#define SIMWORLD_PANIC -2 -// general error -#define SIMWORLD_GENERICERROR -3 - -// access global state of elbeem simulator -void setElbeemState(int set); -int getElbeemState(void); -int isSimworldOk(void); - -// access elbeem simulator error string -void setElbeemErrorString(const char* set); -char* getElbeemErrorString(void); - - -/* debug output function */ -#define DM_MSG 1 -#define DM_NOTIFY 2 -#define DM_IMPORTANT 3 -#define DM_WARNING 4 -#define DM_ERROR 5 -#define DM_DIRECT 6 -#define DM_FATAL 7 -void messageOutputFunc(string from, int id, string msg, myTime_t interval); - -/* debugging messages defines */ -#ifdef DEBUG -#if LBM_PRECISION==2 -#define MSGSTREAM std::ostringstream msg; msg.precision(15); msg.width(17); -#else -#define MSGSTREAM std::ostringstream msg; msg.precision(7); msg.width(9); -#endif - -# define debMsgDirect(mStr) if(gDebugLevel>0) { std::ostringstream msg; msg << mStr; messageOutputFunc(string(""), DM_DIRECT, msg.str(), 0); } -# define debMsgStd(from,id,mStr,level) if(gDebugLevel>=level) { MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, id, msg.str(), 0); } -# define debMsgNnl(from,id,mStr,level) if(gDebugLevel>=level) { MSGSTREAM; msg << mStr ; messageOutputFunc(from, id, msg.str(), 0); } -# define debMsgInter(from,id,mStr,level, interval) if(gDebugLevel>=level) { MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, id, msg.str(), interval); } -# define debugOut(mStr,level) if(gDebugLevel>=level) { debMsgStd("D",DM_MSG,mStr,level); } -# define debugOutNnl(mStr,level) if(gDebugLevel>=level) { debMsgNnl("D",DM_MSG,mStr,level); } -# define debugOutInter(mStr,level, interval) debMsgInter("D",DM_MSG ,mStr,level, interval); -/* Error output function */ -#define errMsg(from,mStr) if(gDebugLevel>0){ MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, DM_ERROR, msg.str(), 0); } -#define warnMsg(from,mStr) if(gDebugLevel>0){ MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, DM_WARNING, msg.str(), 0); } - -#else -// no messages at all... -# define debMsgDirect(mStr) -# define debMsgStd(from,id,mStr,level) -# define debMsgNnl(from,id,mStr,level) -# define debMsgInter(from,id,mStr,level, interval) -# define debugOut(mStr,level) -# define debugOutNnl(mStr,level) -# define debugOutInter(mStr,level, interval) -# define errMsg(from,mStr) -# define warnMsg(from,mStr) -#endif - -#define errorOut(mStr) { errMsg("D",mStr); } - -// fatal errors - have to be handled -#define errFatal(from,mStr,errCode) { \ - setElbeemState(errCode); \ - MSGSTREAM; msg << mStr; \ - messageOutputFunc(from, DM_FATAL, msg.str(), 0); \ -} - - -//! helper function that converts a string to integer -int convertString2Int(const char *str, int alt); - -//! helper function that converts a flag field to a readable integer -string convertFlags2String(int flags); - -//! get the current system time -myTime_t getTime(); -//! convert time to readable string -string getTimeString(myTime_t usecs); - -//! helper to check if a bounding box was specified in the right way -bool checkBoundingBox(ntlVec3Gfx s, ntlVec3Gfx e, string checker); - -//! reset color output for elbeem init -void resetGlobalColorSetting(); - - -/*! print some vector from 3 values e.g. for ux,uy,uz */ -#define PRINT_VEC(x,y,z) " ["<<(x)<<","<<(y)<<","<<(z)<<"] " - -/*! print some vector from 3 values e.g. for ux,uy,uz */ -#define PRINT_VEC2D(x,y) " ["<<(x)<<","<<(y)<<"] " - -/*! print l'th neighbor of i,j,k as a vector, as we need ijk all the time */ -#define PRINT_IJK_NBL PRINT_VEC(i+D::dfVecX[l],j+D::dfVecY[l],k+D::dfVecZ[l]) - -/*! print i,j,k as a vector, as we need ijk all the time */ -#define PRINT_IJK PRINT_VEC(i,j,k) - -/*! print i,j,k as a vector, as we need ijk all the time */ -#define PRINT_IJ PRINT_VEC2D(i,j) - -/*! print some vector from 3 values e.g. for ux,uy,uz */ -#define PRINT_NTLVEC(v) " ["<<(v)[0]<<","<<(v)[1]<<","<<(v)[2]<<"] " - -/*! print some vector from 3 values e.g. for ux,uy,uz */ -#define PRINT_NTLVEC2D(v) " ["<<(v)[0]<<","<<(v)[1]<<"] " - -/*! print a triangle */ -#define PRINT_TRIANGLE(t,mpV) " { "< -inline T -MIN( T a, T b ) -{ return (a < b) ? a : b ; } - -/* maximum */ -#ifdef MAX -#undef MAX -#endif -template < class T > -inline T -MAX( T a, T b ) -{ return (a < b) ? b : a ; } - -/* sign of the value */ -template < class T > -inline T -SIGNUM( T a ) -{ return (0 < a) ? 1 : -1 ; } - -/* sign, returns -1,0,1 depending on sign/value=0 */ -template < class T > -inline T -SIGNUM0( T a ) -{ return (0 < a) ? 1 : ( a < 0 ? -1 : 0 ) ; } - -/* round to nearest integer */ -inline int -ROUND(double d) -{ return int(d + 0.5); } - -/* square function */ -template < class T > -inline T -SQUARE( T a ) -{ return a*a; } - - -#define UTILITIES_H -#endif diff --git a/intern/smoke/CMakeLists.txt b/intern/smoke/CMakeLists.txt deleted file mode 100644 index 5c8e495fa93..00000000000 --- a/intern/smoke/CMakeLists.txt +++ /dev/null @@ -1,99 +0,0 @@ -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# 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. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2006, Blender Foundation -# All rights reserved. -# ***** END GPL LICENSE BLOCK ***** - -set(INC - intern - ../memutil -) - -set(INC_SYS - ${BULLET_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${ZLIB_INCLUDE_DIRS} -) - -set(SRC - intern/EIGENVALUE_HELPER.cpp - intern/FLUID_3D.cpp - intern/FLUID_3D_SOLVERS.cpp - intern/FLUID_3D_STATIC.cpp - intern/LU_HELPER.cpp - intern/SPHERE.cpp - intern/WTURBULENCE.cpp - intern/smoke_API.cpp - - extern/smoke_API.h - intern/EIGENVALUE_HELPER.h - intern/FFT_NOISE.h - intern/FLUID_3D.h - intern/IMAGE.h - intern/INTERPOLATE.h - intern/LU_HELPER.h - intern/MERSENNETWISTER.h - intern/OBSTACLE.h - intern/SPHERE.h - intern/VEC3.h - intern/WAVELET_NOISE.h - intern/WTURBULENCE.h - intern/tnt/jama_eig.h - intern/tnt/jama_lu.h - intern/tnt/tnt.h - intern/tnt/tnt_array1d.h - intern/tnt/tnt_array1d_utils.h - intern/tnt/tnt_array2d.h - intern/tnt/tnt_array2d_utils.h - intern/tnt/tnt_array3d.h - intern/tnt/tnt_array3d_utils.h - intern/tnt/tnt_cmat.h - intern/tnt/tnt_fortran_array1d.h - intern/tnt/tnt_fortran_array1d_utils.h - intern/tnt/tnt_fortran_array2d.h - intern/tnt/tnt_fortran_array2d_utils.h - intern/tnt/tnt_fortran_array3d.h - intern/tnt/tnt_fortran_array3d_utils.h - intern/tnt/tnt_i_refvec.h - intern/tnt/tnt_math_utils.h - intern/tnt/tnt_sparse_matrix_csr.h - intern/tnt/tnt_stopwatch.h - intern/tnt/tnt_subscript.h - intern/tnt/tnt_vec.h - intern/tnt/tnt_version.h -) - -set(LIB -) - -# quiet -Wundef -add_definitions(-DDDF_DEBUG=0) - -if(WITH_OPENMP) - add_definitions(-DPARALLEL=1) -else() - add_definitions(-DPARALLEL=0) -endif() - -if(WITH_FFTW3) - add_definitions(-DWITH_FFTW3) - list(APPEND INC_SYS - ${FFTW3_INCLUDE_DIRS} - ) -endif() - -blender_add_lib(bf_intern_smoke "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/intern/smoke/extern/smoke_API.h b/intern/smoke/extern/smoke_API.h deleted file mode 100644 index 169f679526c..00000000000 --- a/intern/smoke/extern/smoke_API.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2009 by Daniel Genrich - * All rights reserved. - */ - -/** \file - * \ingroup smoke - */ - - -#ifndef SMOKE_API_H_ -#define SMOKE_API_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct FLUID_3D; - -// low res -struct FLUID_3D *smoke_init(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors); -void smoke_free(struct FLUID_3D *fluid); - -void smoke_initBlenderRNA(struct FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate, - float *flame_smoke, float *flame_smoke_color, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp); -void smoke_step(struct FLUID_3D *fluid, float gravity[3], float dtSubdiv); - -float *smoke_get_density(struct FLUID_3D *fluid); -float *smoke_get_flame(struct FLUID_3D *fluid); -float *smoke_get_fuel(struct FLUID_3D *fluid); -float *smoke_get_react(struct FLUID_3D *fluid); -float *smoke_get_color_r(struct FLUID_3D *fluid); -float *smoke_get_color_g(struct FLUID_3D *fluid); -float *smoke_get_color_b(struct FLUID_3D *fluid); -void smoke_get_rgba(struct FLUID_3D *fluid, float *data, int sequential); -void smoke_get_rgba_from_density(struct FLUID_3D *fluid, float color[3], float *data, int sequential); -float *smoke_get_heat(struct FLUID_3D *fluid); -float *smoke_get_velocity_x(struct FLUID_3D *fluid); -float *smoke_get_velocity_y(struct FLUID_3D *fluid); -float *smoke_get_velocity_z(struct FLUID_3D *fluid); - -/* Moving obstacle velocity provided by blender */ -void smoke_get_ob_velocity(struct FLUID_3D *fluid, float **x, float **y, float **z); - -float *smoke_get_force_x(struct FLUID_3D *fluid); -float *smoke_get_force_y(struct FLUID_3D *fluid); -float *smoke_get_force_z(struct FLUID_3D *fluid); - -unsigned char *smoke_get_obstacle(struct FLUID_3D *fluid); - -size_t smoke_get_index(int x, int max_x, int y, int max_y, int z); -size_t smoke_get_index2d(int x, int max_x, int y); - -void smoke_dissolve(struct FLUID_3D *fluid, int speed, int log); - -// wavelet turbulence functions -struct WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype, const char *noisefile_path, int use_fire, int use_colors); -void smoke_turbulence_free(struct WTURBULENCE *wt); -void smoke_turbulence_step(struct WTURBULENCE *wt, struct FLUID_3D *fluid); - -float *smoke_turbulence_get_density(struct WTURBULENCE *wt); -float *smoke_turbulence_get_color_r(struct WTURBULENCE *wt); -float *smoke_turbulence_get_color_g(struct WTURBULENCE *wt); -float *smoke_turbulence_get_color_b(struct WTURBULENCE *wt); -void smoke_turbulence_get_rgba(struct WTURBULENCE *wt, float *data, int sequential); -void smoke_turbulence_get_rgba_from_density(struct WTURBULENCE *wt, float color[3], float *data, int sequential); -float *smoke_turbulence_get_flame(struct WTURBULENCE *wt); -float *smoke_turbulence_get_fuel(struct WTURBULENCE *wt); -float *smoke_turbulence_get_react(struct WTURBULENCE *wt); -void smoke_turbulence_get_res(struct WTURBULENCE *wt, int *res); -int smoke_turbulence_get_cells(struct WTURBULENCE *wt); -void smoke_turbulence_set_noise(struct WTURBULENCE *wt, int type, const char *noisefile_path); -void smoke_initWaveletBlenderRNA(struct WTURBULENCE *wt, float *strength); -void smoke_dissolve_wavelet(struct WTURBULENCE *wt, int speed, int log); - -/* export */ -void smoke_export(struct FLUID_3D *fluid, float *dt, float *dx, float **dens, float **react, float **flame, float **fuel, float **heat, float **heatold, - float **vx, float **vy, float **vz, float **r, float **g, float **b, unsigned char **obstacles); -void smoke_turbulence_export(struct WTURBULENCE *wt, float **dens, float **react, float **flame, float **fuel, - float **r, float **g, float **b, float **tcu, float **tcv, float **tcw); - -/* data fields */ -int smoke_has_heat(struct FLUID_3D *fluid); -int smoke_has_fuel(struct FLUID_3D *fluid); -int smoke_has_colors(struct FLUID_3D *fluid); -int smoke_turbulence_has_fuel(struct WTURBULENCE *wt); -int smoke_turbulence_has_colors(struct WTURBULENCE *wt); - -void smoke_ensure_heat(struct FLUID_3D *fluid); -void smoke_ensure_fire(struct FLUID_3D *fluid, struct WTURBULENCE *wt); -void smoke_ensure_colors(struct FLUID_3D *fluid, struct WTURBULENCE *wt, float init_r, float init_g, float init_b); - -#ifdef __cplusplus -} -#endif - -#endif /* SMOKE_API_H_ */ diff --git a/intern/smoke/intern/EIGENVALUE_HELPER.cpp b/intern/smoke/intern/EIGENVALUE_HELPER.cpp deleted file mode 100644 index fbfd6d3bd22..00000000000 --- a/intern/smoke/intern/EIGENVALUE_HELPER.cpp +++ /dev/null @@ -1,888 +0,0 @@ -/** \file - * \ingroup smoke - */ - -#include "EIGENVALUE_HELPER.h" - - -void Eigentred2(sEigenvalue& eval) { - - // This is derived from the Algol procedures tred2 by - // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for - // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutine in EISPACK. - - int n=eval.n; - - for (int j = 0; j < n; j++) { - eval.d[j] = eval.V[n-1][j]; - } - - // Householder reduction to tridiagonal form. - - for (int i = n-1; i > 0; i--) { - - // Scale to avoid under/overflow. - - float scale = 0.0; - float h = 0.0; - for (int k = 0; k < i; k++) { - scale = scale + fabs(eval.d[k]); - } - if (scale == 0.0f) { - eval.e[i] = eval.d[i-1]; - for (int j = 0; j < i; j++) { - eval.d[j] = eval.V[i-1][j]; - eval.V[i][j] = 0.0; - eval.V[j][i] = 0.0; - } - } else { - - // Generate Householder vector. - - for (int k = 0; k < i; k++) { - eval.d[k] /= scale; - h += eval.d[k] * eval.d[k]; - } - float f = eval.d[i-1]; - float g = sqrt(h); - if (f > 0) { - g = -g; - } - eval.e[i] = scale * g; - h = h - f * g; - eval.d[i-1] = f - g; - for (int j = 0; j < i; j++) { - eval.e[j] = 0.0; - } - - // Apply similarity transformation to remaining columns. - - for (int j = 0; j < i; j++) { - f = eval.d[j]; - eval.V[j][i] = f; - g = eval.e[j] + eval.V[j][j] * f; - for (int k = j+1; k <= i-1; k++) { - g += eval.V[k][j] * eval.d[k]; - eval.e[k] += eval.V[k][j] * f; - } - eval.e[j] = g; - } - f = 0.0; - for (int j = 0; j < i; j++) { - eval.e[j] /= h; - f += eval.e[j] * eval.d[j]; - } - float hh = f / (h + h); - for (int j = 0; j < i; j++) { - eval.e[j] -= hh * eval.d[j]; - } - for (int j = 0; j < i; j++) { - f = eval.d[j]; - g = eval.e[j]; - for (int k = j; k <= i-1; k++) { - eval.V[k][j] -= (f * eval.e[k] + g * eval.d[k]); - } - eval.d[j] = eval.V[i-1][j]; - eval.V[i][j] = 0.0; - } - } - eval.d[i] = h; - } - - // Accumulate transformations. - - for (int i = 0; i < n-1; i++) { - eval.V[n-1][i] = eval.V[i][i]; - eval.V[i][i] = 1.0; - float h = eval.d[i+1]; - if (h != 0.0f) { - for (int k = 0; k <= i; k++) { - eval.d[k] = eval.V[k][i+1] / h; - } - for (int j = 0; j <= i; j++) { - float g = 0.0; - for (int k = 0; k <= i; k++) { - g += eval.V[k][i+1] * eval.V[k][j]; - } - for (int k = 0; k <= i; k++) { - eval.V[k][j] -= g * eval.d[k]; - } - } - } - for (int k = 0; k <= i; k++) { - eval.V[k][i+1] = 0.0; - } - } - for (int j = 0; j < n; j++) { - eval.d[j] = eval.V[n-1][j]; - eval.V[n-1][j] = 0.0; - } - eval.V[n-1][n-1] = 1.0; - eval.e[0] = 0.0; -} - -void Eigencdiv(sEigenvalue& eval, float xr, float xi, float yr, float yi) { - float r,d; - if (fabs(yr) > fabs(yi)) { - r = yi/yr; - d = yr + r*yi; - eval.cdivr = (xr + r*xi)/d; - eval.cdivi = (xi - r*xr)/d; - } else { - r = yr/yi; - d = yi + r*yr; - eval.cdivr = (r*xr + xi)/d; - eval.cdivi = (r*xi - xr)/d; - } - } - -void Eigentql2 (sEigenvalue& eval) { - - // This is derived from the Algol procedures tql2, by - // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for - // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutine in EISPACK. - - int n=eval.n; - - for (int i = 1; i < n; i++) { - eval.e[i-1] = eval.e[i]; - } - eval.e[n-1] = 0.0; - - float f = 0.0; - float tst1 = 0.0; - float eps = pow(2.0,-52.0); - for (int l = 0; l < n; l++) { - - // Find small subdiagonal element - - tst1 = max(tst1,fabs(eval.d[l]) + fabs(eval.e[l])); - int m = l; - - // Original while-loop from Java code - while (m < n) { - if (fabs(eval.e[m]) <= eps*tst1) { - break; - } - m++; - } - - - // If m == l, d[l] is an eigenvalue, - // otherwise, iterate. - - if (m > l) { - int iter = 0; - do { - iter = iter + 1; // (Could check iteration count here.) - - // Compute implicit shift - - float g = eval.d[l]; - float p = (eval.d[l+1] - g) / (2.0f * eval.e[l]); - float r = hypot(p,1.0); - if (p < 0) { - r = -r; - } - eval.d[l] = eval.e[l] / (p + r); - eval.d[l+1] = eval.e[l] * (p + r); - float dl1 = eval.d[l+1]; - float h = g - eval.d[l]; - for (int i = l+2; i < n; i++) { - eval.d[i] -= h; - } - f = f + h; - - // Implicit QL transformation. - - p = eval.d[m]; - float c = 1.0; - float c2 = c; - float c3 = c; - float el1 = eval.e[l+1]; - float s = 0.0; - float s2 = 0.0; - for (int i = m-1; i >= l; i--) { - c3 = c2; - c2 = c; - s2 = s; - g = c * eval.e[i]; - h = c * p; - r = hypot(p,eval.e[i]); - eval.e[i+1] = s * r; - s = eval.e[i] / r; - c = p / r; - p = c * eval.d[i] - s * g; - eval.d[i+1] = h + s * (c * g + s * eval.d[i]); - - // Accumulate transformation. - - for (int k = 0; k < n; k++) { - h = eval.V[k][i+1]; - eval.V[k][i+1] = s * eval.V[k][i] + c * h; - eval.V[k][i] = c * eval.V[k][i] - s * h; - } - } - p = -s * s2 * c3 * el1 * eval.e[l] / dl1; - eval.e[l] = s * p; - eval.d[l] = c * p; - - // Check for convergence. - - } while (fabs(eval.e[l]) > eps*tst1); - } - eval.d[l] = eval.d[l] + f; - eval.e[l] = 0.0; - } - - // Sort eigenvalues and corresponding vectors. - - for (int i = 0; i < n-1; i++) { - int k = i; - float p = eval.d[i]; - for (int j = i+1; j < n; j++) { - if (eval.d[j] < p) { - k = j; - p = eval.d[j]; - } - } - if (k != i) { - eval.d[k] = eval.d[i]; - eval.d[i] = p; - for (int j = 0; j < n; j++) { - p = eval.V[j][i]; - eval.V[j][i] = eval.V[j][k]; - eval.V[j][k] = p; - } - } - } -} - -void Eigenorthes (sEigenvalue& eval) { - - // This is derived from the Algol procedures orthes and ortran, - // by Martin and Wilkinson, Handbook for Auto. Comp., - // Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutines in EISPACK. - - int n=eval.n; - - int low = 0; - int high = n-1; - - for (int m = low+1; m <= high-1; m++) { - - // Scale column. - - float scale = 0.0; - for (int i = m; i <= high; i++) { - scale = scale + fabs(eval.H[i][m-1]); - } - if (scale != 0.0f) { - - // Compute Householder transformation. - - float h = 0.0; - for (int i = high; i >= m; i--) { - eval.ort[i] = eval.H[i][m-1]/scale; - h += eval.ort[i] * eval.ort[i]; - } - float g = sqrt(h); - if (eval.ort[m] > 0) { - g = -g; - } - h = h - eval.ort[m] * g; - eval.ort[m] = eval.ort[m] - g; - - // Apply Householder similarity transformation - // H = (I-u*u'/h)*H*(I-u*u')/h) - - for (int j = m; j < n; j++) { - float f = 0.0; - for (int i = high; i >= m; i--) { - f += eval.ort[i]*eval.H[i][j]; - } - f = f/h; - for (int i = m; i <= high; i++) { - eval.H[i][j] -= f*eval.ort[i]; - } - } - - for (int i = 0; i <= high; i++) { - float f = 0.0; - for (int j = high; j >= m; j--) { - f += eval.ort[j]*eval.H[i][j]; - } - f = f/h; - for (int j = m; j <= high; j++) { - eval.H[i][j] -= f*eval.ort[j]; - } - } - eval.ort[m] = scale*eval.ort[m]; - eval.H[m][m-1] = scale*g; - } - } - - // Accumulate transformations (Algol's ortran). - - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - eval.V[i][j] = (i == j ? 1.0 : 0.0); - } - } - - for (int m = high-1; m >= low+1; m--) { - if (eval.H[m][m-1] != 0.0f) { - for (int i = m+1; i <= high; i++) { - eval.ort[i] = eval.H[i][m-1]; - } - for (int j = m; j <= high; j++) { - float g = 0.0; - for (int i = m; i <= high; i++) { - g += eval.ort[i] * eval.V[i][j]; - } - // Double division avoids possible underflow - g = (g / eval.ort[m]) / eval.H[m][m-1]; - for (int i = m; i <= high; i++) { - eval.V[i][j] += g * eval.ort[i]; - } - } - } - } - } - -void Eigenhqr2 (sEigenvalue& eval) { - - // This is derived from the Algol procedure hqr2, - // by Martin and Wilkinson, Handbook for Auto. Comp., - // Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutine in EISPACK. - - // Initialize - - int nn = eval.n; - int n = nn-1; - int low = 0; - int high = nn-1; - float eps = pow(2.0,-52.0); - float exshift = 0.0; - float p=0,q=0,r=0,s=0,z=0,t,w,x,y; - - // Store roots isolated by balanc and compute matrix norm - - float norm = 0.0; - for (int i = 0; i < nn; i++) { - if ((i < low) || (i > high)) { - eval.d[i] = eval.H[i][i]; - eval.e[i] = 0.0; - } - for (int j = max(i-1,0); j < nn; j++) { - norm = norm + fabs(eval.H[i][j]); - } - } - - // Outer loop over eigenvalue index - - int iter = 0; - int totIter = 0; - while (n >= low) { - - // NT limit no. of iterations - totIter++; - if(totIter>100) { - //if(totIter>15) std::cout<<"!!!!iter ABORT !!!!!!! "< low) { - s = fabs(eval.H[l-1][l-1]) + fabs(eval.H[l][l]); - if (s == 0.0f) { - s = norm; - } - if (fabs(eval.H[l][l-1]) < eps * s) { - break; - } - l--; - } - - // Check for convergence - // One root found - - if (l == n) { - eval.H[n][n] = eval.H[n][n] + exshift; - eval.d[n] = eval.H[n][n]; - eval.e[n] = 0.0; - n--; - iter = 0; - - // Two roots found - - } else if (l == n-1) { - w = eval.H[n][n-1] * eval.H[n-1][n]; - p = (eval.H[n-1][n-1] - eval.H[n][n]) / 2.0f; - q = p * p + w; - z = sqrt(fabs(q)); - eval.H[n][n] = eval.H[n][n] + exshift; - eval.H[n-1][n-1] = eval.H[n-1][n-1] + exshift; - x = eval.H[n][n]; - - // float pair - - if (q >= 0) { - if (p >= 0) { - z = p + z; - } else { - z = p - z; - } - eval.d[n-1] = x + z; - eval.d[n] = eval.d[n-1]; - if (z != 0.0f) { - eval.d[n] = x - w / z; - } - eval.e[n-1] = 0.0; - eval.e[n] = 0.0; - x = eval.H[n][n-1]; - s = fabs(x) + fabs(z); - p = x / s; - q = z / s; - r = sqrt(p * p+q * q); - p = p / r; - q = q / r; - - // Row modification - - for (int j = n-1; j < nn; j++) { - z = eval.H[n-1][j]; - eval.H[n-1][j] = q * z + p * eval.H[n][j]; - eval.H[n][j] = q * eval.H[n][j] - p * z; - } - - // Column modification - - for (int i = 0; i <= n; i++) { - z = eval.H[i][n-1]; - eval.H[i][n-1] = q * z + p * eval.H[i][n]; - eval.H[i][n] = q * eval.H[i][n] - p * z; - } - - // Accumulate transformations - - for (int i = low; i <= high; i++) { - z = eval.V[i][n-1]; - eval.V[i][n-1] = q * z + p * eval.V[i][n]; - eval.V[i][n] = q * eval.V[i][n] - p * z; - } - - // Complex pair - - } else { - eval.d[n-1] = x + p; - eval.d[n] = x + p; - eval.e[n-1] = z; - eval.e[n] = -z; - } - n = n - 2; - iter = 0; - - // No convergence yet - - } else { - - // Form shift - - x = eval.H[n][n]; - y = 0.0; - w = 0.0; - if (l < n) { - y = eval.H[n-1][n-1]; - w = eval.H[n][n-1] * eval.H[n-1][n]; - } - - // Wilkinson's original ad hoc shift - - if (iter == 10) { - exshift += x; - for (int i = low; i <= n; i++) { - eval.H[i][i] -= x; - } - s = fabs(eval.H[n][n-1]) + fabs(eval.H[n-1][n-2]); - x = y = 0.75f * s; - w = -0.4375f * s * s; - } - - // MATLAB's new ad hoc shift - - if (iter == 30) { - s = (y - x) / 2.0f; - s = s * s + w; - if (s > 0) { - s = sqrt(s); - if (y < x) { - s = -s; - } - s = x - w / ((y - x) / 2.0f + s); - for (int i = low; i <= n; i++) { - eval.H[i][i] -= s; - } - exshift += s; - x = y = w = 0.964; - } - } - - iter = iter + 1; // (Could check iteration count here.) - - // Look for two consecutive small sub-diagonal elements - - int m = n-2; - while (m >= l) { - z = eval.H[m][m]; - r = x - z; - s = y - z; - p = (r * s - w) / eval.H[m+1][m] + eval.H[m][m+1]; - q = eval.H[m+1][m+1] - z - r - s; - r = eval.H[m+2][m+1]; - s = fabs(p) + fabs(q) + fabs(r); - p = p / s; - q = q / s; - r = r / s; - if (m == l) { - break; - } - if (fabs(eval.H[m][m-1]) * (fabs(q) + fabs(r)) < - eps * (fabs(p) * (fabs(eval.H[m-1][m-1]) + fabs(z) + - fabs(eval.H[m+1][m+1])))) { - break; - } - m--; - } - - for (int i = m+2; i <= n; i++) { - eval.H[i][i-2] = 0.0; - if (i > m+2) { - eval.H[i][i-3] = 0.0; - } - } - - // Double QR step involving rows l:n and columns m:n - - for (int k = m; k <= n-1; k++) { - int notlast = (k != n-1); - if (k != m) { - p = eval.H[k][k-1]; - q = eval.H[k+1][k-1]; - r = (notlast ? eval.H[k+2][k-1] : 0.0f); - x = fabs(p) + fabs(q) + fabs(r); - if (x != 0.0f) { - p = p / x; - q = q / x; - r = r / x; - } - } - if (x == 0.0f) { - break; - } - s = sqrt(p * p + q * q + r * r); - if (p < 0) { - s = -s; - } - if (s != 0) { - if (k != m) { - eval.H[k][k-1] = -s * x; - } else if (l != m) { - eval.H[k][k-1] = -eval.H[k][k-1]; - } - p = p + s; - x = p / s; - y = q / s; - z = r / s; - q = q / p; - r = r / p; - - // Row modification - - for (int j = k; j < nn; j++) { - p = eval.H[k][j] + q * eval.H[k+1][j]; - if (notlast) { - p = p + r * eval.H[k+2][j]; - eval.H[k+2][j] = eval.H[k+2][j] - p * z; - } - eval.H[k][j] = eval.H[k][j] - p * x; - eval.H[k+1][j] = eval.H[k+1][j] - p * y; - } - - // Column modification - - for (int i = 0; i <= min(n,k+3); i++) { - p = x * eval.H[i][k] + y * eval.H[i][k+1]; - if (notlast) { - p = p + z * eval.H[i][k+2]; - eval.H[i][k+2] = eval.H[i][k+2] - p * r; - } - eval.H[i][k] = eval.H[i][k] - p; - eval.H[i][k+1] = eval.H[i][k+1] - p * q; - } - - // Accumulate transformations - - for (int i = low; i <= high; i++) { - p = x * eval.V[i][k] + y * eval.V[i][k+1]; - if (notlast) { - p = p + z * eval.V[i][k+2]; - eval.V[i][k+2] = eval.V[i][k+2] - p * r; - } - eval.V[i][k] = eval.V[i][k] - p; - eval.V[i][k+1] = eval.V[i][k+1] - p * q; - } - } // (s != 0) - } // k loop - } // check convergence - } // while (n >= low) - //if(totIter>15) std::cout<<"!!!!iter "<= 0; n--) { - p = eval.d[n]; - q = eval.e[n]; - - // float vector - - if (q == 0) { - int l = n; - eval.H[n][n] = 1.0; - for (int i = n-1; i >= 0; i--) { - w = eval.H[i][i] - p; - r = 0.0; - for (int j = l; j <= n; j++) { - r = r + eval.H[i][j] * eval.H[j][n]; - } - if (eval.e[i] < 0.0f) { - z = w; - s = r; - } else { - l = i; - if (eval.e[i] == 0.0f) { - if (w != 0.0f) { - eval.H[i][n] = -r / w; - } else { - eval.H[i][n] = -r / (eps * norm); - } - - // Solve real equations - - } else { - x = eval.H[i][i+1]; - y = eval.H[i+1][i]; - q = (eval.d[i] - p) * (eval.d[i] - p) + eval.e[i] * eval.e[i]; - t = (x * s - z * r) / q; - eval.H[i][n] = t; - if (fabs(x) > fabs(z)) { - eval.H[i+1][n] = (-r - w * t) / x; - } else { - eval.H[i+1][n] = (-s - y * t) / z; - } - } - - // Overflow control - - t = fabs(eval.H[i][n]); - if ((eps * t) * t > 1) { - for (int j = i; j <= n; j++) { - eval.H[j][n] = eval.H[j][n] / t; - } - } - } - } - - // Complex vector - - } else if (q < 0) { - int l = n-1; - - // Last vector component imaginary so matrix is triangular - - if (fabs(eval.H[n][n-1]) > fabs(eval.H[n-1][n])) { - eval.H[n-1][n-1] = q / eval.H[n][n-1]; - eval.H[n-1][n] = -(eval.H[n][n] - p) / eval.H[n][n-1]; - } else { - Eigencdiv(eval, 0.0,-eval.H[n-1][n],eval.H[n-1][n-1]-p,q); - eval.H[n-1][n-1] = eval.cdivr; - eval.H[n-1][n] = eval.cdivi; - } - eval.H[n][n-1] = 0.0; - eval.H[n][n] = 1.0; - for (int i = n-2; i >= 0; i--) { - float ra,sa,vr,vi; - ra = 0.0; - sa = 0.0; - for (int j = l; j <= n; j++) { - ra = ra + eval.H[i][j] * eval.H[j][n-1]; - sa = sa + eval.H[i][j] * eval.H[j][n]; - } - w = eval.H[i][i] - p; - - if (eval.e[i] < 0.0f) { - z = w; - r = ra; - s = sa; - } else { - l = i; - if (eval.e[i] == 0) { - Eigencdiv(eval,-ra,-sa,w,q); - eval.H[i][n-1] = eval.cdivr; - eval.H[i][n] = eval.cdivi; - } else { - - // Solve complex equations - - x = eval.H[i][i+1]; - y = eval.H[i+1][i]; - vr = (eval.d[i] - p) * (eval.d[i] - p) + eval.e[i] * eval.e[i] - q * q; - vi = (eval.d[i] - p) * 2.0f * q; - if ((vr == 0.0f) && (vi == 0.0f)) { - vr = eps * norm * (fabs(w) + fabs(q) + - fabs(x) + fabs(y) + fabs(z)); - } - Eigencdiv(eval, x*r-z*ra+q*sa,x*s-z*sa-q*ra,vr,vi); - eval.H[i][n-1] = eval.cdivr; - eval.H[i][n] = eval.cdivi; - if (fabs(x) > (fabs(z) + fabs(q))) { - eval.H[i+1][n-1] = (-ra - w * eval.H[i][n-1] + q * eval.H[i][n]) / x; - eval.H[i+1][n] = (-sa - w * eval.H[i][n] - q * eval.H[i][n-1]) / x; - } else { - Eigencdiv(eval, -r-y*eval.H[i][n-1],-s-y*eval.H[i][n],z,q); - eval.H[i+1][n-1] = eval.cdivr; - eval.H[i+1][n] = eval.cdivi; - } - } - - // Overflow control - - t = max(fabs(eval.H[i][n-1]),fabs(eval.H[i][n])); - if ((eps * t) * t > 1) { - for (int j = i; j <= n; j++) { - eval.H[j][n-1] = eval.H[j][n-1] / t; - eval.H[j][n] = eval.H[j][n] / t; - } - } - } - } - } - } - - // Vectors of isolated roots - - for (int i = 0; i < nn; i++) { - if (i < low || i > high) { - for (int j = i; j < nn; j++) { - eval.V[i][j] = eval.H[i][j]; - } - } - } - - // Back transformation to get eigenvectors of original matrix - - for (int j = nn-1; j >= low; j--) { - for (int i = low; i <= high; i++) { - z = 0.0; - for (int k = low; k <= min(j,high); k++) { - z = z + eval.V[i][k] * eval.H[k][j]; - } - eval.V[i][j] = z; - } - } -} - - - -int computeEigenvalues3x3( - float dout[3], - float a[3][3]) -{ - /*TNT::Array2D A = TNT::Array2D(3,3, &a[0][0]); - TNT::Array1D eig = TNT::Array1D(3); - TNT::Array1D eigImag = TNT::Array1D(3); - JAMA::Eigenvalue jeig = JAMA::Eigenvalue(A);*/ - - sEigenvalue jeig; - - // Compute the values - { - jeig.n = 3; - int n=3; - //V = Array2D(n,n); - //d = Array1D(n); - //e = Array1D(n); - for (int y=0; y<3; y++) - { - jeig.d[y]=0.0f; - jeig.e[y]=0.0f; - for (int t=0; t<3; t++) jeig.V[y][t]=0.0f; - } - - jeig.issymmetric = 1; - for (int j = 0; (j < 3) && jeig.issymmetric; j++) { - for (int i = 0; (i < 3) && jeig.issymmetric; i++) { - jeig.issymmetric = (a[i][j] == a[j][i]); - } - } - - if (jeig.issymmetric) { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - jeig.V[i][j] = a[i][j]; - } - } - - // Tridiagonalize. - Eigentred2(jeig); - - // Diagonalize. - Eigentql2(jeig); - - } else { - //H = TNT::Array2D(n,n); - for (int y=0; y<3; y++) - { - jeig.ort[y]=0.0f; - for (int t=0; t<3; t++) jeig.H[y][t]=0.0f; - } - //ort = TNT::Array1D(n); - - for (int j = 0; j < n; j++) { - for (int i = 0; i < n; i++) { - jeig.H[i][j] = a[i][j]; - } - } - - // Reduce to Hessenberg form. - Eigenorthes(jeig); - - // Reduce Hessenberg to real Schur form. - Eigenhqr2(jeig); - } - } - - //jeig.getfloatEigenvalues(eig); - - // complex ones - //jeig.getImagEigenvalues(eigImag); - dout[0] = sqrt(jeig.d[0]*jeig.d[0] + jeig.e[0]*jeig.e[0]); - dout[1] = sqrt(jeig.d[1]*jeig.d[1] + jeig.e[1]*jeig.e[1]); - dout[2] = sqrt(jeig.d[2]*jeig.d[2] + jeig.e[2]*jeig.e[2]); - return 0; -} diff --git a/intern/smoke/intern/EIGENVALUE_HELPER.h b/intern/smoke/intern/EIGENVALUE_HELPER.h deleted file mode 100644 index ef204b442d9..00000000000 --- a/intern/smoke/intern/EIGENVALUE_HELPER.h +++ /dev/null @@ -1,77 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -////////////////////////////////////////////////////////////////////// -// Modified to not require TNT matrix library anymore. It was very slow -// when being run in parallel. Required TNT JAMA::Eigenvalue libraries were -// converted into independent functions. -// - MiikaH -// -////////////////////////////////////////////////////////////////////// -// Helper function, compute eigenvalues of 3x3 matrix -////////////////////////////////////////////////////////////////////// - -#ifndef EIGENVAL_HELPER_H -#define EIGENVAL_HELPER_H - -//#include "tnt/jama_eig.h" - -#include -#include - -using namespace std; - -////////////////////////////////////////////////////////////////////// -// eigenvalues of 3x3 non-symmetric matrix -////////////////////////////////////////////////////////////////////// - - -struct sEigenvalue -{ - int n; - int issymmetric; - float d[3]; /* real part */ - float e[3]; /* img part */ - float V[3][3]; /* Eigenvectors */ - - float H[3][3]; - - - float ort[3]; - - float cdivr; - float cdivi; -}; - -void Eigentred2(sEigenvalue& eval); - -void Eigencdiv(sEigenvalue& eval, float xr, float xi, float yr, float yi); - -void Eigentql2 (sEigenvalue& eval); - -void Eigenorthes (sEigenvalue& eval); - -void Eigenhqr2 (sEigenvalue& eval); - -int computeEigenvalues3x3(float dout[3], float a[3][3]); - - -#endif diff --git a/intern/smoke/intern/FFT_NOISE.h b/intern/smoke/intern/FFT_NOISE.h deleted file mode 100644 index d44cbabd64e..00000000000 --- a/intern/smoke/intern/FFT_NOISE.h +++ /dev/null @@ -1,183 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -///////////////////////////////////////////////////////////////////////// -// - -#ifndef FFT_NOISE_H_ -#define FFT_NOISE_H_ - -#ifdef WITH_FFTW3 -#include -#include -#include - -#include "WAVELET_NOISE.h" - -#ifndef M_PI -#define M_PI 3.14159265 -#endif - -///////////////////////////////////////////////////////////////////////// -// shift spectrum to the format that FFTW expects -///////////////////////////////////////////////////////////////////////// -static void shift3D(float*& field, int xRes, int yRes, int zRes) -{ - int xHalf = xRes / 2; - int yHalf = yRes / 2; - int zHalf = zRes / 2; - // int slabSize = xRes * yRes; - for (int z = 0; z < zHalf; z++) - for (int y = 0; y < yHalf; y++) - for (int x = 0; x < xHalf; x++) - { - int index = x + y * xRes + z * xRes * yRes; - float temp; - int xSwap = xHalf; - int ySwap = yHalf * xRes; - int zSwap = zHalf * xRes * yRes; - - // [0,0,0] to [1,1,1] - temp = field[index]; - field[index] = field[index + xSwap + ySwap + zSwap]; - field[index + xSwap + ySwap + zSwap] = temp; - - // [1,0,0] to [0,1,1] - temp = field[index + xSwap]; - field[index + xSwap] = field[index + ySwap + zSwap]; - field[index + ySwap + zSwap] = temp; - - // [0,1,0] to [1,0,1] - temp = field[index + ySwap]; - field[index + ySwap] = field[index + xSwap + zSwap]; - field[index + xSwap + zSwap] = temp; - - // [0,0,1] to [1,1,0] - temp = field[index + zSwap]; - field[index + zSwap] = field[index + xSwap + ySwap]; - field[index + xSwap + ySwap] = temp; - } -} - -static void generatTile_FFT(float* const noiseTileData, std::string filename) -{ - if (loadTile(noiseTileData, filename)) return; - - int res = NOISE_TILE_SIZE; - int xRes = res; - int yRes = res; - int zRes = res; - int totalCells = xRes * yRes * zRes; - - // create and shift the filter - float* filter = new float[totalCells]; - for (int z = 0; z < zRes; z++) - for (int y = 0; y < yRes; y++) - for (int x = 0; x < xRes; x++) - { - int index = x + y * xRes + z * xRes * yRes; - float diff[] = {(float)abs(x - xRes / 2), - (float)abs(y - yRes / 2), - (float)abs(z - zRes / 2)}; - float radius = sqrtf(diff[0] * diff[0] + - diff[1] * diff[1] + - diff[2] * diff[2]) / (xRes / 2); - radius *= M_PI; - float H = cos((M_PI / 2.0f) * log(4.0f * radius / M_PI) / log(2.0f)); - H = H * H; - float filtered = H; - - // clamp everything outside the wanted band - if (radius >= M_PI / 2.0f) - filtered = 0.0f; - - // make sure to capture all low frequencies - if (radius <= M_PI / 4.0f) - filtered = 1.0f; - - filter[index] = filtered; - } - shift3D(filter, xRes, yRes, zRes); - - // create the noise - float* noise = new float[totalCells]; - int index = 0; - MTRand twister; - for (int z = 0; z < zRes; z++) - for (int y = 0; y < yRes; y++) - for (int x = 0; x < xRes; x++, index++) - noise[index] = twister.randNorm(); - - // create padded field - fftw_complex* forward = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * totalCells); - - // init padded field - index = 0; - for (int z = 0; z < zRes; z++) - for (int y = 0; y < yRes; y++) - for (int x = 0; x < xRes; x++, index++) - { - forward[index][0] = noise[index]; - forward[index][1] = 0.0f; - } - - // forward FFT - fftw_complex* backward = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * totalCells); - fftw_plan forwardPlan = fftw_plan_dft_3d(xRes, yRes, zRes, forward, backward, FFTW_FORWARD, FFTW_ESTIMATE); - fftw_execute(forwardPlan); - fftw_destroy_plan(forwardPlan); - - // apply filter - index = 0; - for (int z = 0; z < zRes; z++) - for (int y = 0; y < yRes; y++) - for (int x = 0; x < xRes; x++, index++) - { - backward[index][0] *= filter[index]; - backward[index][1] *= filter[index]; - } - - // backward FFT - fftw_plan backwardPlan = fftw_plan_dft_3d(xRes, yRes, zRes, backward, forward, FFTW_BACKWARD, FFTW_ESTIMATE); - fftw_execute(backwardPlan); - fftw_destroy_plan(backwardPlan); - - // subtract out the low frequency components - index = 0; - for (int z = 0; z < zRes; z++) - for (int y = 0; y < yRes; y++) - for (int x = 0; x < xRes; x++, index++) - noise[index] -= forward[index][0] / totalCells; - - // fill noiseTileData - memcpy(noiseTileData, noise, sizeof(float) * totalCells); - // save out the noise tile - saveTile(noise, filename); - - fftw_free(forward); - fftw_free(backward); - delete[] filter; - delete[] noise; -} - -#endif - -#endif /* FFT_NOISE_H_ */ diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp deleted file mode 100644 index e76abea35d8..00000000000 --- a/intern/smoke/intern/FLUID_3D.cpp +++ /dev/null @@ -1,1792 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// FLUID_3D.cpp: implementation of the FLUID_3D class. -// -////////////////////////////////////////////////////////////////////// -// Heavy parallel optimization done. Many of the old functions now -// take begin and end parameters and process only specified part of the data. -// Some functions were divided into multiple ones. -// - MiikaH -////////////////////////////////////////////////////////////////////// - -#include "FLUID_3D.h" -#include "IMAGE.h" -#include -#include "SPHERE.h" -#include - -#include "float.h" - -#if PARALLEL==1 -#include -#endif // PARALLEL - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -FLUID_3D::FLUID_3D(int *res, float dx, float dtdef, int init_heat, int init_fire, int init_colors) : - _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f) -{ - // set simulation consts - _dt = dtdef; // just in case. set in step from a RNA factor - - _iterations = 100; - _tempAmb = 0; - _heatDiffusion = 1e-3; - _totalTime = 0.0f; - _totalSteps = 0; - _res = Vec3Int(_xRes,_yRes,_zRes); - _maxRes = MAX3(_xRes, _yRes, _zRes); - - // initialize wavelet turbulence - /* - if(amplify) - _wTurbulence = new WTURBULENCE(_res[0],_res[1],_res[2], amplify, noisetype); - else - _wTurbulence = NULL; - */ - - // scale the constants according to the refinement of the grid - if (!dx) - _dx = 1.0f / (float)_maxRes; - else - _dx = dx; - _constantScaling = 64.0f / _maxRes; - _constantScaling = (_constantScaling < 1.0f) ? 1.0f : _constantScaling; - _vorticityEps = 2.0f / _constantScaling; // Just in case set a default value - - // allocate arrays - _totalCells = _xRes * _yRes * _zRes; - _slabSize = _xRes * _yRes; - _xVelocity = new float[_totalCells]; - _yVelocity = new float[_totalCells]; - _zVelocity = new float[_totalCells]; - _xVelocityOb = new float[_totalCells]; - _yVelocityOb = new float[_totalCells]; - _zVelocityOb = new float[_totalCells]; - _xVelocityOld = new float[_totalCells]; - _yVelocityOld = new float[_totalCells]; - _zVelocityOld = new float[_totalCells]; - _xForce = new float[_totalCells]; - _yForce = new float[_totalCells]; - _zForce = new float[_totalCells]; - _density = new float[_totalCells]; - _densityOld = new float[_totalCells]; - _obstacles = new unsigned char[_totalCells]; // set 0 at end of step - - // For threaded version: - _xVelocityTemp = new float[_totalCells]; - _yVelocityTemp = new float[_totalCells]; - _zVelocityTemp = new float[_totalCells]; - _densityTemp = new float[_totalCells]; - - // DG TODO: check if alloc went fine - - for (int x = 0; x < _totalCells; x++) - { - _density[x] = 0.0f; - _densityOld[x] = 0.0f; - _xVelocity[x] = 0.0f; - _yVelocity[x] = 0.0f; - _zVelocity[x] = 0.0f; - _xVelocityOb[x] = 0.0f; - _yVelocityOb[x] = 0.0f; - _zVelocityOb[x] = 0.0f; - _xVelocityOld[x] = 0.0f; - _yVelocityOld[x] = 0.0f; - _zVelocityOld[x] = 0.0f; - _xForce[x] = 0.0f; - _yForce[x] = 0.0f; - _zForce[x] = 0.0f; - _obstacles[x] = false; - } - - /* heat */ - _heat = _heatOld = _heatTemp = NULL; - if (init_heat) { - initHeat(); - } - // Fire simulation - _flame = _fuel = _fuelTemp = _fuelOld = NULL; - _react = _reactTemp = _reactOld = NULL; - if (init_fire) { - initFire(); - } - // Smoke color - _color_r = _color_rOld = _color_rTemp = NULL; - _color_g = _color_gOld = _color_gTemp = NULL; - _color_b = _color_bOld = _color_bTemp = NULL; - if (init_colors) { - initColors(0.0f, 0.0f, 0.0f); - } - - // boundary conditions of the fluid domain - // set default values -> vertically non-colliding - _domainBcFront = true; - _domainBcTop = false; - _domainBcLeft = true; - _domainBcBack = _domainBcFront; - _domainBcBottom = _domainBcTop; - _domainBcRight = _domainBcLeft; - - _colloPrev = 1; // default value -} - -void FLUID_3D::initHeat() -{ - if (!_heat) { - _heat = new float[_totalCells]; - _heatOld = new float[_totalCells]; - _heatTemp = new float[_totalCells]; - - for (int x = 0; x < _totalCells; x++) - { - _heat[x] = 0.0f; - _heatOld[x] = 0.0f; - } - } -} - -void FLUID_3D::initFire() -{ - if (!_flame) { - _flame = new float[_totalCells]; - _fuel = new float[_totalCells]; - _fuelTemp = new float[_totalCells]; - _fuelOld = new float[_totalCells]; - _react = new float[_totalCells]; - _reactTemp = new float[_totalCells]; - _reactOld = new float[_totalCells]; - - for (int x = 0; x < _totalCells; x++) - { - _flame[x] = 0.0f; - _fuel[x] = 0.0f; - _fuelTemp[x] = 0.0f; - _fuelOld[x] = 0.0f; - _react[x] = 0.0f; - _reactTemp[x] = 0.0f; - _reactOld[x] = 0.0f; - } - } -} - -void FLUID_3D::initColors(float init_r, float init_g, float init_b) -{ - if (!_color_r) { - _color_r = new float[_totalCells]; - _color_rOld = new float[_totalCells]; - _color_rTemp = new float[_totalCells]; - _color_g = new float[_totalCells]; - _color_gOld = new float[_totalCells]; - _color_gTemp = new float[_totalCells]; - _color_b = new float[_totalCells]; - _color_bOld = new float[_totalCells]; - _color_bTemp = new float[_totalCells]; - - for (int x = 0; x < _totalCells; x++) - { - _color_r[x] = _density[x] * init_r; - _color_rOld[x] = 0.0f; - _color_g[x] = _density[x] * init_g; - _color_gOld[x] = 0.0f; - _color_b[x] = _density[x] * init_b; - _color_bOld[x] = 0.0f; - } - } -} - -void FLUID_3D::setBorderObstacles() -{ - - // set side obstacles - unsigned int index; - for (int y = 0; y < _yRes; y++) - for (int x = 0; x < _xRes; x++) - { - // bottom slab - index = x + y * _xRes; - if(_domainBcBottom) _obstacles[index] = 1; - - // top slab - index += _totalCells - _slabSize; - if(_domainBcTop) _obstacles[index] = 1; - } - - for (int z = 0; z < _zRes; z++) - for (int x = 0; x < _xRes; x++) - { - // front slab - index = x + z * _slabSize; - if(_domainBcFront) _obstacles[index] = 1; - - // back slab - index += _slabSize - _xRes; - if(_domainBcBack) _obstacles[index] = 1; - } - - for (int z = 0; z < _zRes; z++) - for (int y = 0; y < _yRes; y++) - { - // left slab - index = y * _xRes + z * _slabSize; - if(_domainBcLeft) _obstacles[index] = 1; - - // right slab - index += _xRes - 1; - if(_domainBcRight) _obstacles[index] = 1; - } -} - -FLUID_3D::~FLUID_3D() -{ - if (_xVelocity) delete[] _xVelocity; - if (_yVelocity) delete[] _yVelocity; - if (_zVelocity) delete[] _zVelocity; - if (_xVelocityOb) delete[] _xVelocityOb; - if (_yVelocityOb) delete[] _yVelocityOb; - if (_zVelocityOb) delete[] _zVelocityOb; - if (_xVelocityOld) delete[] _xVelocityOld; - if (_yVelocityOld) delete[] _yVelocityOld; - if (_zVelocityOld) delete[] _zVelocityOld; - if (_xForce) delete[] _xForce; - if (_yForce) delete[] _yForce; - if (_zForce) delete[] _zForce; - if (_density) delete[] _density; - if (_densityOld) delete[] _densityOld; - if (_heat) delete[] _heat; - if (_heatOld) delete[] _heatOld; - if (_obstacles) delete[] _obstacles; - - if (_xVelocityTemp) delete[] _xVelocityTemp; - if (_yVelocityTemp) delete[] _yVelocityTemp; - if (_zVelocityTemp) delete[] _zVelocityTemp; - if (_densityTemp) delete[] _densityTemp; - if (_heatTemp) delete[] _heatTemp; - - if (_flame) delete[] _flame; - if (_fuel) delete[] _fuel; - if (_fuelTemp) delete[] _fuelTemp; - if (_fuelOld) delete[] _fuelOld; - if (_react) delete[] _react; - if (_reactTemp) delete[] _reactTemp; - if (_reactOld) delete[] _reactOld; - - if (_color_r) delete[] _color_r; - if (_color_rOld) delete[] _color_rOld; - if (_color_rTemp) delete[] _color_rTemp; - if (_color_g) delete[] _color_g; - if (_color_gOld) delete[] _color_gOld; - if (_color_gTemp) delete[] _color_gTemp; - if (_color_b) delete[] _color_b; - if (_color_bOld) delete[] _color_bOld; - if (_color_bTemp) delete[] _color_bTemp; - - // printf("deleted fluid\n"); -} - -// init direct access functions from blender -void FLUID_3D::initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *borderCollision, float *burning_rate, - float *flame_smoke, float *flame_smoke_color, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp) -{ - _alpha = alpha; - _beta = beta; - _dtFactor = dt_factor; - _vorticityRNA = vorticity; - _borderColli = borderCollision; - _burning_rate = burning_rate; - _flame_smoke = flame_smoke; - _flame_smoke_color = flame_smoke_color; - _flame_vorticity = flame_vorticity; - _ignition_temp = flame_ignition_temp; - _max_temp = flame_max_temp; -} - -////////////////////////////////////////////////////////////////////// -// step simulation once -////////////////////////////////////////////////////////////////////// -void FLUID_3D::step(float dt, float gravity[3]) -{ -#if 0 - // If border rules have been changed - if (_colloPrev != *_borderColli) { - printf("Border collisions changed\n"); - - // DG TODO: Need to check that no animated obstacle flags are overwritten - setBorderCollisions(); - } -#endif - - // DG: TODO for the moment redo border for every timestep since it's been deleted every time by moving obstacles - setBorderCollisions(); - - - // set delta time by dt_factor - _dt = (*_dtFactor) * dt; - // set vorticity from RNA value - _vorticityEps = (*_vorticityRNA)/_constantScaling; - -#if PARALLEL==1 - int threadval = 1; - threadval = omp_get_max_threads(); - - int stepParts = 1; - float partSize = _zRes; - - stepParts = threadval*2; // Dividing parallelized sections into numOfThreads * 2 sections - partSize = (float)_zRes/stepParts; // Size of one part; - - if (partSize < 4) {stepParts = threadval; // If the slice gets too low (might actually slow things down, change it to larger - partSize = (float)_zRes/stepParts;} - if (partSize < 4) {stepParts = (int)(ceil((float)_zRes/4.0f)); // If it's still too low (only possible on future systems with +24 cores), change it to 4 - partSize = (float)_zRes/stepParts;} -#else - int zBegin=0; - int zEnd=_zRes; -#endif - - wipeBoundariesSL(0, _zRes); - -#if PARALLEL==1 - #pragma omp parallel - { - #pragma omp for schedule(static,1) - for (int i=0; i FLT_EPSILON ) - { - // printf("velocity x!\n"); - _xVelocity[index] = _xVelocityOb[index - 1]; - _xVelocity[index - 1] = _xVelocityOb[index - 1]; - } - // if(_obstacles[index+_xRes]) yup = - _yVelocityOb[index]; - if((_obstacles[index - _xRes] & 8) && abs(_yVelocityOb[index - _xRes]) > FLT_EPSILON) - { - // printf("velocity y!\n"); - _yVelocity[index] = _yVelocityOb[index - _xRes]; - _yVelocity[index - _xRes] = _yVelocityOb[index - _xRes]; - } - // if(_obstacles[index+_slabSize]) ztop = - _zVelocityOb[index]; - if((_obstacles[index - _slabSize] & 8) && abs(_zVelocityOb[index - _slabSize]) > FLT_EPSILON) - { - // printf("velocity z!\n"); - _zVelocity[index] = _zVelocityOb[index - _slabSize]; - _zVelocity[index - _slabSize] = _zVelocityOb[index - _slabSize]; - } - } - else - { - _density[index] = 0; - } - //vIndex++; - } // x loop - //vIndex += 2; - } // y loop - //vIndex += 2 * _xRes; - } // z loop -} - -////////////////////////////////////////////////////////////////////// -// diffuse heat -////////////////////////////////////////////////////////////////////// -void FLUID_3D::diffuseHeat() -{ - SWAP_POINTERS(_heat, _heatOld); - - copyBorderAll(_heatOld, 0, _zRes); - solveHeat(_heat, _heatOld, _obstacles); - - // zero out inside obstacles - for (int x = 0; x < _totalCells; x++) - if (_obstacles[x]) - _heat[x] = 0.0f; -} - -////////////////////////////////////////////////////////////////////// -// stamp an obstacle in the _obstacles field -////////////////////////////////////////////////////////////////////// -void FLUID_3D::addObstacle(OBSTACLE* obstacle) -{ - int index = 0; - for (int z = 0; z < _zRes; z++) - for (int y = 0; y < _yRes; y++) - for (int x = 0; x < _xRes; x++, index++) - if (obstacle->inside(x * _dx, y * _dx, z * _dx)) { - _obstacles[index] = true; - } -} - -////////////////////////////////////////////////////////////////////// -// calculate the obstacle directional types -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setObstaclePressure(float *_pressure, int zBegin, int zEnd) -{ - - // completely TODO <-- who wrote this and what is here TODO? DG - - const size_t index_ = _slabSize + _xRes + 1; - - //int vIndex=_slabSize + _xRes + 1; - - int bb=0; - int bt=0; - - if (zBegin == 0) {bb = 1;} - if (zEnd == _zRes) {bt = 1;} - - // tag remaining obstacle blocks - for (int z = zBegin + bb; z < zEnd - bt; z++) - { - size_t index = index_ +(z-1)*_slabSize; - - for (int y = 1; y < _yRes - 1; y++, index += 2) - { - for (int x = 1; x < _xRes - 1; x++, index++) - { - // could do cascade of ifs, but they are a pain - if (_obstacles[index] /* && !(_obstacles[index] & 8) DG TODO TEST THIS CONDITION */) - { - const int top = _obstacles[index + _slabSize]; - const int bottom= _obstacles[index - _slabSize]; - const int up = _obstacles[index + _xRes]; - const int down = _obstacles[index - _xRes]; - const int left = _obstacles[index - 1]; - const int right = _obstacles[index + 1]; - - // unused - // const bool fullz = (top && bottom); - // const bool fully = (up && down); - //const bool fullx = (left && right); - - /* - _xVelocity[index] = - _yVelocity[index] = - _zVelocity[index] = 0.0f; - */ - _pressure[index] = 0.0f; - - // average pressure neighbors - float pcnt = 0.; - if (left && !right) { - _pressure[index] += _pressure[index + 1]; - pcnt += 1.0f; - } - if (!left && right) { - _pressure[index] += _pressure[index - 1]; - pcnt += 1.0f; - } - if (up && !down) { - _pressure[index] += _pressure[index - _xRes]; - pcnt += 1.0f; - } - if (!up && down) { - _pressure[index] += _pressure[index + _xRes]; - pcnt += 1.0f; - } - if (top && !bottom) { - _pressure[index] += _pressure[index - _slabSize]; - pcnt += 1.0f; - } - if (!top && bottom) { - _pressure[index] += _pressure[index + _slabSize]; - pcnt += 1.0f; - } - - if(pcnt > 0.000001f) - _pressure[index] /= pcnt; - - // TODO? set correct velocity bc's - // velocities are only set to zero right now - // this means it's not a full no-slip boundary condition - // but a "half-slip" - still looks ok right now - } - //vIndex++; - } // x loop - //vIndex += 2; - } // y loop - //vIndex += 2 * _xRes; - } // z loop -} - -void FLUID_3D::setObstacleBoundaries(float *_pressure, int zBegin, int zEnd) -{ - // cull degenerate obstacles , move to addObstacle? - - // r = b - Ax - const size_t index_ = _slabSize + _xRes + 1; - - int bb=0; - int bt=0; - - if (zBegin == 0) {bb = 1;} - if (zEnd == _zRes) {bt = 1;} - - for (int z = zBegin + bb; z < zEnd - bt; z++) - { - size_t index = index_ +(z-1)*_slabSize; - - for (int y = 1; y < _yRes - 1; y++, index += 2) - { - for (int x = 1; x < _xRes - 1; x++, index++) - { - if (_obstacles[index] != EMPTY) - { - const int top = _obstacles[index + _slabSize]; - const int bottom= _obstacles[index - _slabSize]; - const int up = _obstacles[index + _xRes]; - const int down = _obstacles[index - _xRes]; - const int left = _obstacles[index - 1]; - const int right = _obstacles[index + 1]; - - int counter = 0; - if (up) counter++; - if (down) counter++; - if (left) counter++; - if (right) counter++; - if (top) counter++; - if (bottom) counter++; - - if (counter < 3) - _obstacles[index] = EMPTY; - } - if (_obstacles[index]) - { - _xVelocity[index] = - _yVelocity[index] = - _zVelocity[index] = 0.0f; - _pressure[index] = 0.0f; - } - //vIndex++; - } // x-loop - //vIndex += 2; - } // y-loop - //vIndex += 2* _xRes; - } // z-loop -} - -void FLUID_3D::floodFillComponent(int *buffer, size_t *queue, size_t limit, size_t pos, int from, int to) -{ - /* Flood 'from' cells with 'to' in the grid. Rely on (from != 0 && from != to && edges == 0) to stop. */ - int offsets[] = { -1, +1, -_xRes, +_xRes, -_slabSize, +_slabSize }; - size_t qend = 0; - - buffer[pos] = to; - queue[qend++] = pos; - - for (size_t qidx = 0; qidx < qend; qidx++) - { - pos = queue[qidx]; - - for (int i = 0; i < 6; i++) - { - size_t next = pos + offsets[i]; - - if (next < limit && buffer[next] == from) - { - buffer[next] = to; - queue[qend++] = next; - } - } - } -} - -void FLUID_3D::mergeComponents(int *buffer, size_t *queue, size_t cur, size_t other) -{ - /* Replace higher value with lower. */ - if (buffer[other] < buffer[cur]) - { - floodFillComponent(buffer, queue, cur, cur, buffer[cur], buffer[other]); - } - else if (buffer[cur] < buffer[other]) - { - floodFillComponent(buffer, queue, cur, other, buffer[other], buffer[cur]); - } -} - -void FLUID_3D::fixObstacleCompression(float *divergence) -{ - int x, y, z; - size_t index; - - /* Find compartments completely separated by obstacles. - * Edge of the domain is automatically component 0. */ - int *component = new int[_totalCells]; - size_t *queue = new size_t[_totalCells]; - - memset(component, 0, sizeof(int) * _totalCells); - - int next_id = 1; - - for (z = 1, index = _slabSize + _xRes + 1; z < _zRes - 1; z++, index += 2 * _xRes) - { - for (y = 1; y < _yRes - 1; y++, index += 2) - { - for (x = 1; x < _xRes - 1; x++, index++) - { - if(!_obstacles[index]) - { - /* Check for connection to the domain edge at iteration end. */ - if ((x == _xRes-2 && !_obstacles[index + 1]) || - (y == _yRes-2 && !_obstacles[index + _xRes]) || - (z == _zRes-2 && !_obstacles[index + _slabSize])) - { - component[index] = 0; - } - else { - component[index] = next_id; - } - - if (!_obstacles[index - 1]) - mergeComponents(component, queue, index, index - 1); - if (!_obstacles[index - _xRes]) - mergeComponents(component, queue, index, index - _xRes); - if (!_obstacles[index - _slabSize]) - mergeComponents(component, queue, index, index - _slabSize); - - if (component[index] == next_id) - next_id++; - } - } - } - } - - delete[] queue; - - /* Compute average divergence within each component. */ - float *total_divergence = new float[next_id]; - int *component_size = new int[next_id]; - - memset(total_divergence, 0, sizeof(float) * next_id); - memset(component_size, 0, sizeof(int) * next_id); - - for (z = 1, index = _slabSize + _xRes + 1; z < _zRes - 1; z++, index += 2 * _xRes) - { - for (y = 1; y < _yRes - 1; y++, index += 2) - { - for (x = 1; x < _xRes - 1; x++, index++) - { - if(!_obstacles[index]) - { - int ci = component[index]; - - component_size[ci]++; - total_divergence[ci] += divergence[index]; - } - } - } - } - - /* Adjust divergence to make the average zero in each component except the edge. */ - total_divergence[0] = 0.0f; - - for (z = 1, index = _slabSize + _xRes + 1; z < _zRes - 1; z++, index += 2 * _xRes) - { - for (y = 1; y < _yRes - 1; y++, index += 2) - { - for (x = 1; x < _xRes - 1; x++, index++) - { - if(!_obstacles[index]) - { - int ci = component[index]; - - divergence[index] -= total_divergence[ci] / component_size[ci]; - } - } - } - } - - delete[] component; - delete[] component_size; - delete[] total_divergence; -} - -////////////////////////////////////////////////////////////////////// -// add buoyancy forces -////////////////////////////////////////////////////////////////////// -void FLUID_3D::addBuoyancy(float *heat, float *density, float gravity[3], int zBegin, int zEnd) -{ - int index = zBegin*_slabSize; - - for (int z = zBegin; z < zEnd; z++) - for (int y = 0; y < _yRes; y++) - for (int x = 0; x < _xRes; x++, index++) - { - float buoyancy = *_alpha * density[index] + (*_beta * (((heat) ? heat[index] : 0.0f) - _tempAmb)); - _xForce[index] -= gravity[0] * buoyancy; - _yForce[index] -= gravity[1] * buoyancy; - _zForce[index] -= gravity[2] * buoyancy; - } -} - - -////////////////////////////////////////////////////////////////////// -// add vorticity to the force field -////////////////////////////////////////////////////////////////////// -#define VORT_VEL(i, j) \ - ((_obstacles[obpos[(i)]] & 8) ? ((abs(objvelocity[(j)][obpos[(i)]]) > FLT_EPSILON) ? objvelocity[(j)][obpos[(i)]] : velocity[(j)][index]) : velocity[(j)][obpos[(i)]]) - -void FLUID_3D::addVorticity(int zBegin, int zEnd) -{ - // set flame vorticity from RNA value - float flame_vorticity = (*_flame_vorticity)/_constantScaling; - //int x,y,z,index; - if(_vorticityEps+flame_vorticity<=0.0f) return; - - int _blockSize=zEnd-zBegin; - int _blockTotalCells = _slabSize * (_blockSize+2); - - float *_xVorticity, *_yVorticity, *_zVorticity, *_vorticity; - - int bb=0; - int bt=0; - int bb1=-1; - int bt1=-1; - - if (zBegin == 0) {bb1 = 1; bb = 1; _blockTotalCells-=_blockSize;} - if (zEnd == _zRes) {bt1 = 1;bt = 1; _blockTotalCells-=_blockSize;} - - _xVorticity = new float[_blockTotalCells]; - _yVorticity = new float[_blockTotalCells]; - _zVorticity = new float[_blockTotalCells]; - _vorticity = new float[_blockTotalCells]; - - memset(_xVorticity, 0, sizeof(float)*_blockTotalCells); - memset(_yVorticity, 0, sizeof(float)*_blockTotalCells); - memset(_zVorticity, 0, sizeof(float)*_blockTotalCells); - memset(_vorticity, 0, sizeof(float)*_blockTotalCells); - - //const size_t indexsetupV=_slabSize; - const size_t index_ = _slabSize + _xRes + 1; - - // calculate vorticity - float gridSize = 0.5f / _dx; - //index = _slabSize + _xRes + 1; - - float *velocity[3]; - float *objvelocity[3]; - - velocity[0] = _xVelocity; - velocity[1] = _yVelocity; - velocity[2] = _zVelocity; - - objvelocity[0] = _xVelocityOb; - objvelocity[1] = _yVelocityOb; - objvelocity[2] = _zVelocityOb; - - size_t vIndex=_xRes + 1; - for (int z = zBegin + bb1; z < (zEnd - bt1); z++) - { - size_t index = index_ +(z-1)*_slabSize; - vIndex = index-(zBegin-1+bb)*_slabSize; - - for (int y = 1; y < _yRes - 1; y++, index += 2) - { - for (int x = 1; x < _xRes - 1; x++, index++) - { - if (!_obstacles[index]) - { - int obpos[6]; - - obpos[0] = (_obstacles[index + _xRes] == 1) ? index : index + _xRes; // up - obpos[1] = (_obstacles[index - _xRes] == 1) ? index : index - _xRes; // down - float dy = (obpos[0] == index || obpos[1] == index) ? 1.0f / _dx : gridSize; - - obpos[2] = (_obstacles[index + _slabSize] == 1) ? index : index + _slabSize; // out - obpos[3] = (_obstacles[index - _slabSize] == 1) ? index : index - _slabSize; // in - float dz = (obpos[2] == index || obpos[3] == index) ? 1.0f / _dx : gridSize; - - obpos[4] = (_obstacles[index + 1] == 1) ? index : index + 1; // right - obpos[5] = (_obstacles[index - 1] == 1) ? index : index - 1; // left - float dx = (obpos[4] == index || obpos[5] == index) ? 1.0f / _dx : gridSize; - - float xV[2], yV[2], zV[2]; - - zV[1] = VORT_VEL(0, 2); - zV[0] = VORT_VEL(1, 2); - yV[1] = VORT_VEL(2, 1); - yV[0] = VORT_VEL(3, 1); - _xVorticity[vIndex] = (zV[1] - zV[0]) * dy + (-yV[1] + yV[0]) * dz; - - xV[1] = VORT_VEL(2, 0); - xV[0] = VORT_VEL(3, 0); - zV[1] = VORT_VEL(4, 2); - zV[0] = VORT_VEL(5, 2); - _yVorticity[vIndex] = (xV[1] - xV[0]) * dz + (-zV[1] + zV[0]) * dx; - - yV[1] = VORT_VEL(4, 1); - yV[0] = VORT_VEL(5, 1); - xV[1] = VORT_VEL(0, 0); - xV[0] = VORT_VEL(1, 0); - _zVorticity[vIndex] = (yV[1] - yV[0]) * dx + (-xV[1] + xV[0])* dy; - - _vorticity[vIndex] = sqrtf(_xVorticity[vIndex] * _xVorticity[vIndex] + - _yVorticity[vIndex] * _yVorticity[vIndex] + - _zVorticity[vIndex] * _zVorticity[vIndex]); - - } - vIndex++; - } - vIndex+=2; - } - //vIndex+=2*_xRes; - } - - // calculate normalized vorticity vectors - float eps = _vorticityEps; - - //index = _slabSize + _xRes + 1; - vIndex=_slabSize + _xRes + 1; - - for (int z = zBegin + bb; z < (zEnd - bt); z++) - { - size_t index = index_ +(z-1)*_slabSize; - vIndex = index-(zBegin-1+bb)*_slabSize; - - for (int y = 1; y < _yRes - 1; y++, index += 2) - { - for (int x = 1; x < _xRes - 1; x++, index++) - { - // - - if (!_obstacles[index]) - { - float N[3]; - - int up = (_obstacles[index + _xRes] == 1) ? vIndex : vIndex + _xRes; - int down = (_obstacles[index - _xRes] == 1) ? vIndex : vIndex - _xRes; - float dy = (up == vIndex || down == vIndex) ? 1.0f / _dx : gridSize; - - int out = (_obstacles[index + _slabSize] == 1) ? vIndex : vIndex + _slabSize; - int in = (_obstacles[index - _slabSize] == 1) ? vIndex : vIndex - _slabSize; - float dz = (out == vIndex || in == vIndex) ? 1.0f / _dx : gridSize; - - int right = (_obstacles[index + 1] == 1) ? vIndex : vIndex + 1; - int left = (_obstacles[index - 1] == 1) ? vIndex : vIndex - 1; - float dx = (right == vIndex || left == vIndex) ? 1.0f / _dx : gridSize; - - N[0] = (_vorticity[right] - _vorticity[left]) * dx; - N[1] = (_vorticity[up] - _vorticity[down]) * dy; - N[2] = (_vorticity[out] - _vorticity[in]) * dz; - - float magnitude = sqrtf(N[0] * N[0] + N[1] * N[1] + N[2] * N[2]); - if (magnitude > FLT_EPSILON) - { - float flame_vort = (_fuel) ? _fuel[index]*flame_vorticity : 0.0f; - magnitude = 1.0f / magnitude; - N[0] *= magnitude; - N[1] *= magnitude; - N[2] *= magnitude; - - _xForce[index] += (N[1] * _zVorticity[vIndex] - N[2] * _yVorticity[vIndex]) * _dx * (eps + flame_vort); - _yForce[index] += (N[2] * _xVorticity[vIndex] - N[0] * _zVorticity[vIndex]) * _dx * (eps + flame_vort); - _zForce[index] += (N[0] * _yVorticity[vIndex] - N[1] * _xVorticity[vIndex]) * _dx * (eps + flame_vort); - } - } // if - vIndex++; - } // x loop - vIndex+=2; - } // y loop - //vIndex+=2*_xRes; - } // z loop - - if (_xVorticity) delete[] _xVorticity; - if (_yVorticity) delete[] _yVorticity; - if (_zVorticity) delete[] _zVorticity; - if (_vorticity) delete[] _vorticity; -} - - -void FLUID_3D::advectMacCormackBegin(int zBegin, int zEnd) -{ - Vec3Int res = Vec3Int(_xRes,_yRes,_zRes); - - setZeroX(_xVelocityOld, res, zBegin, zEnd); - setZeroY(_yVelocityOld, res, zBegin, zEnd); - setZeroZ(_zVelocityOld, res, zBegin, zEnd); -} - -////////////////////////////////////////////////////////////////////// -// Advect using the MacCormack method from the Selle paper -////////////////////////////////////////////////////////////////////// -void FLUID_3D::advectMacCormackEnd1(int zBegin, int zEnd) -{ - Vec3Int res = Vec3Int(_xRes,_yRes,_zRes); - - const float dt0 = _dt / _dx; - - int begin=zBegin * _slabSize; - int end=begin + (zEnd - zBegin) * _slabSize; - for (int x = begin; x < end; x++) - _xForce[x] = 0.0; - - // advectFieldMacCormack1(dt, xVelocity, yVelocity, zVelocity, oldField, newField, res) - - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _densityOld, _densityTemp, res, zBegin, zEnd); - if (_heat) { - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _heatOld, _heatTemp, res, zBegin, zEnd); - } - if (_fuel) { - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _fuelOld, _fuelTemp, res, zBegin, zEnd); - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _reactOld, _reactTemp, res, zBegin, zEnd); - } - if (_color_r) { - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _color_rOld, _color_rTemp, res, zBegin, zEnd); - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _color_gOld, _color_gTemp, res, zBegin, zEnd); - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _color_bOld, _color_bTemp, res, zBegin, zEnd); - } - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _xVelocityOld, _xVelocity, res, zBegin, zEnd); - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _yVelocityOld, _yVelocity, res, zBegin, zEnd); - advectFieldMacCormack1(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _zVelocityOld, _zVelocity, res, zBegin, zEnd); - - // Have to wait untill all the threads are done -> so continuing in step 3 -} - -////////////////////////////////////////////////////////////////////// -// Advect using the MacCormack method from the Selle paper -////////////////////////////////////////////////////////////////////// -void FLUID_3D::advectMacCormackEnd2(int zBegin, int zEnd) -{ - const float dt0 = _dt / _dx; - Vec3Int res = Vec3Int(_xRes,_yRes,_zRes); - - // use force array as temp array - float* t1 = _xForce; - - // advectFieldMacCormack2(dt, xVelocity, yVelocity, zVelocity, oldField, newField, tempfield, temp, res, obstacles) - - /* finish advection */ - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _densityOld, _density, _densityTemp, t1, res, _obstacles, zBegin, zEnd); - if (_heat) { - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _heatOld, _heat, _heatTemp, t1, res, _obstacles, zBegin, zEnd); - } - if (_fuel) { - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _fuelOld, _fuel, _fuelTemp, t1, res, _obstacles, zBegin, zEnd); - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _reactOld, _react, _reactTemp, t1, res, _obstacles, zBegin, zEnd); - } - if (_color_r) { - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _color_rOld, _color_r, _color_rTemp, t1, res, _obstacles, zBegin, zEnd); - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _color_gOld, _color_g, _color_gTemp, t1, res, _obstacles, zBegin, zEnd); - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _color_bOld, _color_b, _color_bTemp, t1, res, _obstacles, zBegin, zEnd); - } - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _xVelocityOld, _xVelocityTemp, _xVelocity, t1, res, _obstacles, zBegin, zEnd); - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _yVelocityOld, _yVelocityTemp, _yVelocity, t1, res, _obstacles, zBegin, zEnd); - advectFieldMacCormack2(dt0, _xVelocityOld, _yVelocityOld, _zVelocityOld, _zVelocityOld, _zVelocityTemp, _zVelocity, t1, res, _obstacles, zBegin, zEnd); - - /* set boundary conditions for velocity */ - if(!_domainBcLeft) copyBorderX(_xVelocityTemp, res, zBegin, zEnd); - else setZeroX(_xVelocityTemp, res, zBegin, zEnd); - - if(!_domainBcFront) copyBorderY(_yVelocityTemp, res, zBegin, zEnd); - else setZeroY(_yVelocityTemp, res, zBegin, zEnd); - - if(!_domainBcTop) copyBorderZ(_zVelocityTemp, res, zBegin, zEnd); - else setZeroZ(_zVelocityTemp, res, zBegin, zEnd); - - /* clear data boundaries */ - setZeroBorder(_density, res, zBegin, zEnd); - if (_fuel) { - setZeroBorder(_fuel, res, zBegin, zEnd); - setZeroBorder(_react, res, zBegin, zEnd); - } - if (_color_r) { - setZeroBorder(_color_r, res, zBegin, zEnd); - setZeroBorder(_color_g, res, zBegin, zEnd); - setZeroBorder(_color_b, res, zBegin, zEnd); - } -} - - -void FLUID_3D::processBurn(float *fuel, float *smoke, float *react, float *heat, - float *r, float *g, float *b, int total_cells, float dt) -{ - float burning_rate = *_burning_rate; - float flame_smoke = *_flame_smoke; - float ignition_point = *_ignition_temp; - float temp_max = *_max_temp; - - for (int index = 0; index < total_cells; index++) - { - float orig_fuel = fuel[index]; - float orig_smoke = smoke[index]; - float smoke_emit = 0.0f; - float flame = 0.0f; - - /* process fuel */ - fuel[index] -= burning_rate * dt; - if (fuel[index] < 0.0f) fuel[index] = 0.0f; - /* process reaction coordinate */ - if (orig_fuel > FLT_EPSILON) { - react[index] *= fuel[index]/orig_fuel; - flame = pow(react[index], 0.5f); - } - else { - react[index] = 0.0f; - } - - /* emit smoke based on fuel burn rate and "flame_smoke" factor */ - smoke_emit = (orig_fuel < 1.0f) ? (1.0f - orig_fuel)*0.5f : 0.0f; - smoke_emit = (smoke_emit + 0.5f) * (orig_fuel-fuel[index]) * 0.1f * flame_smoke; - smoke[index] += smoke_emit; - CLAMP(smoke[index], 0.0f, 1.0f); - - /* set fluid temperature from the flame temperature profile */ - if (heat && flame) - heat[index] = (1.0f - flame)*ignition_point + flame*temp_max; - - /* mix new color */ - if (r && smoke_emit > FLT_EPSILON) { - float smoke_factor = smoke[index]/(orig_smoke+smoke_emit); - r[index] = (r[index] + _flame_smoke_color[0] * smoke_emit) * smoke_factor; - g[index] = (g[index] + _flame_smoke_color[1] * smoke_emit) * smoke_factor; - b[index] = (b[index] + _flame_smoke_color[2] * smoke_emit) * smoke_factor; - } - } -} - -void FLUID_3D::updateFlame(float *react, float *flame, int total_cells) -{ - for (int index = 0; index < total_cells; index++) - { - /* model flame temperature curve from the reaction coordinate (fuel) - * TODO: Would probably be best to get rid of whole "flame" data field. - * Currently it's just sqrt mirror of reaction coordinate, and therefore - * basically just waste of memory and disk space... - */ - if (react[index]>0.0f) { - /* do a smooth falloff for rest of the values */ - flame[index] = pow(react[index], 0.5f); - } - else - flame[index] = 0.0f; - } -} diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h deleted file mode 100644 index 097451836f2..00000000000 --- a/intern/smoke/intern/FLUID_3D.h +++ /dev/null @@ -1,269 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// FLUID_3D.h: interface for the FLUID_3D class. -// -////////////////////////////////////////////////////////////////////// -// Heavy parallel optimization done. Many of the old functions now -// take begin and end parameters and process only specified part of the data. -// Some functions were divided into multiple ones. -// - MiikaH -////////////////////////////////////////////////////////////////////// - -#ifndef FLUID_3D_H -#define FLUID_3D_H - -#include -#include -#include -#include -#include "OBSTACLE.h" -// #include "WTURBULENCE.h" -#include "VEC3.h" - -using namespace std; -using namespace BasicVector; -struct WTURBULENCE; - -struct FLUID_3D -{ - public: - FLUID_3D(int *res, float dx, float dtdef, int init_heat, int init_fire, int init_colors); - FLUID_3D() {}; - virtual ~FLUID_3D(); - - void initHeat(); - void initFire(); - void initColors(float init_r, float init_g, float init_b); - - void initBlenderRNA(float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate, - float *flame_smoke, float *flame_smoke_color, float *flame_vorticity, float *ignition_temp, float *max_temp); - - // create & allocate vector noise advection - void initVectorNoise(int amplify); - - void addSmokeColumn(); - static void addSmokeTestCase(float* field, Vec3Int res); - - void step(float dt, float gravity[3]); - void addObstacle(OBSTACLE* obstacle); - - const float* xVelocity() { return _xVelocity; }; - const float* yVelocity() { return _yVelocity; }; - const float* zVelocity() { return _zVelocity; }; - - int xRes() const { return _xRes; }; - int yRes() const { return _yRes; }; - int zRes() const { return _zRes; }; - - public: - // dimensions - int _xRes, _yRes, _zRes, _maxRes; - Vec3Int _res; - size_t _totalCells; - int _slabSize; - float _dx; - float _p0[3]; - float _p1[3]; - float _totalTime; - int _totalSteps; - int _totalImgDumps; - int _totalVelDumps; - - void artificialDampingSL(int zBegin, int zEnd); - void artificialDampingExactSL(int pos); - - void setBorderObstacles(); - - // fields - float* _density; - float* _densityOld; - float* _heat; - float* _heatOld; - float* _xVelocity; - float* _yVelocity; - float* _zVelocity; - float* _xVelocityOb; - float* _yVelocityOb; - float* _zVelocityOb; - float* _xVelocityOld; - float* _yVelocityOld; - float* _zVelocityOld; - float* _xForce; - float* _yForce; - float* _zForce; - unsigned char* _obstacles; /* only used (useful) for static obstacles like domain boundaries */ - unsigned char* _obstaclesAnim; - - // Required for proper threading: - float* _xVelocityTemp; - float* _yVelocityTemp; - float* _zVelocityTemp; - float* _heatTemp; - float* _densityTemp; - - // fire simulation - float *_flame; - float *_fuel; - float *_fuelTemp; - float *_fuelOld; - float *_react; - float *_reactTemp; - float *_reactOld; - - // smoke color - float *_color_r; - float *_color_rOld; - float *_color_rTemp; - float *_color_g; - float *_color_gOld; - float *_color_gTemp; - float *_color_b; - float *_color_bOld; - float *_color_bTemp; - - - // CG fields - int _iterations; - - // simulation constants - float _dt; - float *_dtFactor; - float _vorticityEps; - float _heatDiffusion; - float *_vorticityRNA; // RNA-pointer. - float *_alpha; // for the buoyancy density term <-- as pointer to get blender RNA in here - float *_beta; // was _buoyancy <-- as pointer to get blender RNA in here - float _tempAmb; /* ambient temperature */ - float _constantScaling; - - bool _domainBcFront; // z - bool _domainBcTop; // y - bool _domainBcLeft; // x - bool _domainBcBack; // DOMAIN_BC_FRONT - bool _domainBcBottom; // DOMAIN_BC_TOP - bool _domainBcRight; // DOMAIN_BC_LEFT - int *_borderColli; // border collision rules <-- as pointer to get blender RNA in here - int _colloPrev; // To track whether value has been changed (to not - // have to recalibrate borders if nothing has changed - void setBorderCollisions(); - - void setObstacleVelocity(int zBegin, int zEnd); - - // WTURBULENCE object, if active - // WTURBULENCE* _wTurbulence; - - // boundary setting functions - void copyBorderAll(float* field, int zBegin, int zEnd); - - // timestepping functions - void wipeBoundaries(int zBegin, int zEnd); - void wipeBoundariesSL(int zBegin, int zEnd); - void addForce(int zBegin, int zEnd); - void addVorticity(int zBegin, int zEnd); - void addBuoyancy(float *heat, float *density, float gravity[3], int zBegin, int zEnd); - - // solver stuff - void project(); - void diffuseHeat(); - void diffuseColor(); - void solvePressure(float* field, float* b, unsigned char* skip); - void solvePressurePre(float* field, float* b, unsigned char* skip); - void solveHeat(float* field, float* b, unsigned char* skip); - void solveDiffusion(float* field, float* b, float* factor); - - - // handle obstacle boundaries - void setObstacleBoundaries(float *_pressure, int zBegin, int zEnd); - void setObstaclePressure(float *_pressure, int zBegin, int zEnd); - - void fixObstacleCompression(float *divergence); - - public: - // advection, accessed e.g. by WTURBULENCE class - //void advectMacCormack(); - void advectMacCormackBegin(int zBegin, int zEnd); - void advectMacCormackEnd1(int zBegin, int zEnd); - void advectMacCormackEnd2(int zBegin, int zEnd); - - void floodFillComponent(int *components, size_t *queue, size_t limit, size_t start, int from, int to); - void mergeComponents(int *components, size_t *queue, size_t cur, size_t other); - - /* burning */ - float *_burning_rate; // RNA pointer - float *_flame_smoke; // RNA pointer - float *_flame_smoke_color; // RNA pointer - float *_flame_vorticity; // RNA pointer - float *_ignition_temp; // RNA pointer - float *_max_temp; // RNA pointer - void processBurn(float *fuel, float *smoke, float *react, float *heat, - float *r, float *g, float *b, int total_cells, float dt); - void updateFlame(float *react, float *flame, int total_cells); - - // boundary setting functions - static void copyBorderX(float* field, Vec3Int res, int zBegin, int zEnd); - static void copyBorderY(float* field, Vec3Int res, int zBegin, int zEnd); - static void copyBorderZ(float* field, Vec3Int res, int zBegin, int zEnd); - static void setNeumannX(float* field, Vec3Int res, int zBegin, int zEnd); - static void setNeumannY(float* field, Vec3Int res, int zBegin, int zEnd); - static void setNeumannZ(float* field, Vec3Int res, int zBegin, int zEnd); - static void setZeroX(float* field, Vec3Int res, int zBegin, int zEnd); - static void setZeroY(float* field, Vec3Int res, int zBegin, int zEnd); - static void setZeroZ(float* field, Vec3Int res, int zBegin, int zEnd); - static void setZeroBorder(float* field, Vec3Int res, int zBegin, int zEnd) { - setZeroX(field, res, zBegin, zEnd); - setZeroY(field, res, zBegin, zEnd); - setZeroZ(field, res, zBegin, zEnd); - }; - - - - // static advection functions, also used by WTURBULENCE - static void advectFieldSemiLagrange(const float dt, const float* velx, const float* vely, const float* velz, - float* oldField, float* newField, Vec3Int res, int zBegin, int zEnd); - static void advectFieldMacCormack1(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* tempResult, Vec3Int res, int zBegin, int zEnd); - static void advectFieldMacCormack2(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* newField, float* tempResult, float* temp1,Vec3Int res, const unsigned char* obstacles, int zBegin, int zEnd); - - - // temp ones for testing - /*static void advectFieldMacCormack(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const unsigned char* obstacles);*/ - /*static void advectFieldSemiLagrange2(const float dt, const float* velx, const float* vely, const float* velz, - float* oldField, float* newField, Vec3Int res);*/ - - // maccormack helper functions - static void clampExtrema(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* newField, Vec3Int res, int zBegin, int zEnd); - static void clampOutsideRays(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection, int zBegin, int zEnd); - - - - // output helper functions - // static void writeImageSliceXY(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.); - // static void writeImageSliceYZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.); - // static void writeImageSliceXZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.); - // static void writeProjectedIntern(const float *field, Vec3Int res, int dir1, int dir2, string prefix, int picCnt, float scale=1.); -}; - -#endif diff --git a/intern/smoke/intern/FLUID_3D_SOLVERS.cpp b/intern/smoke/intern/FLUID_3D_SOLVERS.cpp deleted file mode 100644 index b05c45e1a02..00000000000 --- a/intern/smoke/intern/FLUID_3D_SOLVERS.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// FLUID_3D.cpp: implementation of the FLUID_3D class. -// -////////////////////////////////////////////////////////////////////// -// Both solvers optimized by merging loops and precalculating -// stuff used in iteration loop. -// - MiikaH -////////////////////////////////////////////////////////////////////// - -#include "FLUID_3D.h" -#include -#define SOLVER_ACCURACY 1e-06 - -////////////////////////////////////////////////////////////////////// -// solve the heat equation with CG -////////////////////////////////////////////////////////////////////// -void FLUID_3D::solveHeat(float* field, float* b, unsigned char* skip) -{ - int x, y, z; - const int twoxr = 2 * _xRes; - size_t index; - const float heatConst = _dt * _heatDiffusion / (_dx * _dx); - float *_q, *_residual, *_direction, *_Acenter; - - // i = 0 - int i = 0; - - _residual = new float[_totalCells]; // set 0 - _direction = new float[_totalCells]; // set 0 - _q = new float[_totalCells]; // set 0 - _Acenter = new float[_totalCells]; // set 0 - - memset(_residual, 0, sizeof(float)*_totalCells); - memset(_q, 0, sizeof(float)*_totalCells); - memset(_direction, 0, sizeof(float)*_totalCells); - memset(_Acenter, 0, sizeof(float)*_totalCells); - - float deltaNew = 0.0f; - - // r = b - Ax - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += twoxr) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - { - // if the cell is a variable - _Acenter[index] = 1.0f; - if (!skip[index]) - { - // set the matrix to the Poisson stencil in order - if (!skip[index + 1]) _Acenter[index] += heatConst; - if (!skip[index - 1]) _Acenter[index] += heatConst; - if (!skip[index + _xRes]) _Acenter[index] += heatConst; - if (!skip[index - _xRes]) _Acenter[index] += heatConst; - if (!skip[index + _slabSize]) _Acenter[index] += heatConst; - if (!skip[index - _slabSize]) _Acenter[index] += heatConst; - - _residual[index] = b[index] - (_Acenter[index] * field[index] + - field[index - 1] * (skip[index - 1] ? 0.0f : -heatConst) + - field[index + 1] * (skip[index + 1] ? 0.0f : -heatConst) + - field[index - _xRes] * (skip[index - _xRes] ? 0.0f : -heatConst) + - field[index + _xRes] * (skip[index + _xRes] ? 0.0f : -heatConst) + - field[index - _slabSize] * (skip[index - _slabSize] ? 0.0f : -heatConst) + - field[index + _slabSize] * (skip[index + _slabSize] ? 0.0f : -heatConst)); - } - else - { - _residual[index] = 0.0f; - } - - _direction[index] = _residual[index]; - deltaNew += _residual[index] * _residual[index]; - } - - - // While deltaNew > (eps^2) * delta0 - const float eps = SOLVER_ACCURACY; - float maxR = 2.0f * eps; - while ((i < _iterations) && (maxR > eps)) - { - // q = Ad - float alpha = 0.0f; - - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += twoxr) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - { - // if the cell is a variable - if (!skip[index]) - { - - _q[index] = (_Acenter[index] * _direction[index] + - _direction[index - 1] * (skip[index - 1] ? 0.0f : -heatConst) + - _direction[index + 1] * (skip[index + 1] ? 0.0f : -heatConst) + - _direction[index - _xRes] * (skip[index - _xRes] ? 0.0f : -heatConst) + - _direction[index + _xRes] * (skip[index + _xRes] ? 0.0f : -heatConst) + - _direction[index - _slabSize] * (skip[index - _slabSize] ? 0.0f : -heatConst) + - _direction[index + _slabSize] * (skip[index + _slabSize] ? 0.0f : -heatConst)); - } - else - { - _q[index] = 0.0f; - } - alpha += _direction[index] * _q[index]; - } - - if (fabs(alpha) > 0.0f) - alpha = deltaNew / alpha; - - float deltaOld = deltaNew; - deltaNew = 0.0f; - - maxR = 0.0f; - - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += twoxr) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - { - field[index] += alpha * _direction[index]; - - _residual[index] -= alpha * _q[index]; - maxR = (_residual[index] > maxR) ? _residual[index] : maxR; - - deltaNew += _residual[index] * _residual[index]; - } - - float beta = deltaNew / deltaOld; - - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += twoxr) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - _direction[index] = _residual[index] + beta * _direction[index]; - - - i++; - } - // cout << i << " iterations converged to " << maxR << endl; - - if (_residual) delete[] _residual; - if (_direction) delete[] _direction; - if (_q) delete[] _q; - if (_Acenter) delete[] _Acenter; -} - -void FLUID_3D::solvePressurePre(float* field, float* b, unsigned char* skip) -{ - int x, y, z; - size_t index; - float *_q, *_Precond, *_h, *_residual, *_direction; - - // i = 0 - int i = 0; - - _residual = new float[_totalCells]; // set 0 - _direction = new float[_totalCells]; // set 0 - _q = new float[_totalCells]; // set 0 - _h = new float[_totalCells]; // set 0 - _Precond = new float[_totalCells]; // set 0 - - memset(_residual, 0, sizeof(float)*_xRes*_yRes*_zRes); - memset(_q, 0, sizeof(float)*_xRes*_yRes*_zRes); - memset(_direction, 0, sizeof(float)*_xRes*_yRes*_zRes); - memset(_h, 0, sizeof(float)*_xRes*_yRes*_zRes); - memset(_Precond, 0, sizeof(float)*_xRes*_yRes*_zRes); - - float deltaNew = 0.0f; - - // r = b - Ax - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - { - // if the cell is a variable - float Acenter = 0.0f; - if (!skip[index]) - { - // set the matrix to the Poisson stencil in order - if (!skip[index + 1]) Acenter += 1.0f; - if (!skip[index - 1]) Acenter += 1.0f; - if (!skip[index + _xRes]) Acenter += 1.0f; - if (!skip[index - _xRes]) Acenter += 1.0f; - if (!skip[index + _slabSize]) Acenter += 1.0f; - if (!skip[index - _slabSize]) Acenter += 1.0f; - - _residual[index] = b[index] - (Acenter * field[index] + - field[index - 1] * (skip[index - 1] ? 0.0f : -1.0f) + - field[index + 1] * (skip[index + 1] ? 0.0f : -1.0f) + - field[index - _xRes] * (skip[index - _xRes] ? 0.0f : -1.0f)+ - field[index + _xRes] * (skip[index + _xRes] ? 0.0f : -1.0f)+ - field[index - _slabSize] * (skip[index - _slabSize] ? 0.0f : -1.0f)+ - field[index + _slabSize] * (skip[index + _slabSize] ? 0.0f : -1.0f) ); - } - else - { - _residual[index] = 0.0f; - } - - // P^-1 - if(Acenter < 1.0f) - _Precond[index] = 0.0; - else - _Precond[index] = 1.0f / Acenter; - - // p = P^-1 * r - _direction[index] = _residual[index] * _Precond[index]; - - deltaNew += _residual[index] * _direction[index]; - } - - - // While deltaNew > (eps^2) * delta0 - const float eps = SOLVER_ACCURACY; - //while ((i < _iterations) && (deltaNew > eps*delta0)) - float maxR = 2.0f * eps; - // while (i < _iterations) - while ((i < _iterations) && (maxR > 0.001f * eps)) - { - - float alpha = 0.0f; - - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - { - // if the cell is a variable - float Acenter = 0.0f; - if (!skip[index]) - { - // set the matrix to the Poisson stencil in order - if (!skip[index + 1]) Acenter += 1.0f; - if (!skip[index - 1]) Acenter += 1.0f; - if (!skip[index + _xRes]) Acenter += 1.0f; - if (!skip[index - _xRes]) Acenter += 1.0f; - if (!skip[index + _slabSize]) Acenter += 1.0f; - if (!skip[index - _slabSize]) Acenter += 1.0f; - - _q[index] = Acenter * _direction[index] + - _direction[index - 1] * (skip[index - 1] ? 0.0f : -1.0f) + - _direction[index + 1] * (skip[index + 1] ? 0.0f : -1.0f) + - _direction[index - _xRes] * (skip[index - _xRes] ? 0.0f : -1.0f) + - _direction[index + _xRes] * (skip[index + _xRes] ? 0.0f : -1.0f)+ - _direction[index - _slabSize] * (skip[index - _slabSize] ? 0.0f : -1.0f) + - _direction[index + _slabSize] * (skip[index + _slabSize] ? 0.0f : -1.0f); - } - else - { - _q[index] = 0.0f; - } - - alpha += _direction[index] * _q[index]; - } - - - if (fabs(alpha) > 0.0f) - alpha = deltaNew / alpha; - - float deltaOld = deltaNew; - deltaNew = 0.0f; - - maxR = 0.0; - - float tmp; - - // x = x + alpha * d - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - { - field[index] += alpha * _direction[index]; - - _residual[index] -= alpha * _q[index]; - - _h[index] = _Precond[index] * _residual[index]; - - tmp = _residual[index] * _h[index]; - deltaNew += tmp; - maxR = (tmp > maxR) ? tmp : maxR; - - } - - - // beta = deltaNew / deltaOld - float beta = deltaNew / deltaOld; - - // d = h + beta * d - index = _slabSize + _xRes + 1; - for (z = 1; z < _zRes - 1; z++, index += 2 * _xRes) - for (y = 1; y < _yRes - 1; y++, index += 2) - for (x = 1; x < _xRes - 1; x++, index++) - _direction[index] = _h[index] + beta * _direction[index]; - - // i = i + 1 - i++; - } - // cout << i << " iterations converged to " << sqrt(maxR) << endl; - - if (_h) delete[] _h; - if (_Precond) delete[] _Precond; - if (_residual) delete[] _residual; - if (_direction) delete[] _direction; - if (_q) delete[] _q; -} diff --git a/intern/smoke/intern/FLUID_3D_STATIC.cpp b/intern/smoke/intern/FLUID_3D_STATIC.cpp deleted file mode 100644 index 60c13ae9e60..00000000000 --- a/intern/smoke/intern/FLUID_3D_STATIC.cpp +++ /dev/null @@ -1,646 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// FLUID_3D.cpp: implementation of the static functions of the FLUID_3D class. -// -////////////////////////////////////////////////////////////////////// -// Heavy parallel optimization done. Many of the old functions now -// take begin and end parameters and process only specified part of the data. -// Some functions were divided into multiple ones. -// - MiikaH -////////////////////////////////////////////////////////////////////// - -#include -#include "FLUID_3D.h" -#include "IMAGE.h" -#include "WTURBULENCE.h" -#include "INTERPOLATE.h" - -////////////////////////////////////////////////////////////////////// -// add a test cube of density to the center -////////////////////////////////////////////////////////////////////// -/* -void FLUID_3D::addSmokeColumn() { - addSmokeTestCase(_density, _res, 1.0); - // addSmokeTestCase(_zVelocity, _res, 1.0); - addSmokeTestCase(_heat, _res, 1.0); - if (_wTurbulence) { - addSmokeTestCase(_wTurbulence->getDensityBig(), _wTurbulence->getResBig(), 1.0); - } -} -*/ - -////////////////////////////////////////////////////////////////////// -// generic static version, so that it can be applied to the -// WTURBULENCE grid as well -////////////////////////////////////////////////////////////////////// - -void FLUID_3D::addSmokeTestCase(float* field, Vec3Int res) -{ - const int slabSize = res[0]*res[1]; int maxRes = (int)MAX3V(res); - float dx = 1.0f / (float)maxRes; - - float xTotal = dx * res[0]; - float yTotal = dx * res[1]; - - float heighMin = 0.05; - float heighMax = 0.10; - - for (int y = 0; y < res[2]; y++) - for (int z = (int)(heighMin*res[2]); z <= (int)(heighMax * res[2]); z++) - for (int x = 0; x < res[0]; x++) { - float xLength = x * dx - xTotal * 0.4f; - float yLength = y * dx - yTotal * 0.5f; - float radius = sqrtf(xLength * xLength + yLength * yLength); - - if (radius < 0.075f * xTotal) { - int index = x + y * res[0] + z * slabSize; - field[index] = 1.0f; - } - } -} - - -////////////////////////////////////////////////////////////////////// -// set x direction to Neumann boundary conditions -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setNeumannX(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - int index; - for (int z = zBegin; z < zEnd; z++) - for (int y = 0; y < res[1]; y++) - { - // left slab - index = y * res[0] + z * slabSize; - field[index] = field[index + 2]; - - // right slab - index = y * res[0] + z * slabSize + res[0] - 1; - field[index] = field[index - 2]; - } - } - -////////////////////////////////////////////////////////////////////// -// set y direction to Neumann boundary conditions -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setNeumannY(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - int index; - for (int z = zBegin; z < zEnd; z++) - for (int x = 0; x < res[0]; x++) - { - // front slab - index = x + z * slabSize; - field[index] = field[index + 2 * res[0]]; - - // back slab - index = x + z * slabSize + slabSize - res[0]; - field[index] = field[index - 2 * res[0]]; - } -} - -////////////////////////////////////////////////////////////////////// -// set z direction to Neumann boundary conditions -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setNeumannZ(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - const int totalCells = res[0] * res[1] * res[2]; - const int cellsslab = totalCells - slabSize; - int index; - - if (zBegin == 0) { - for (int y = 0; y < res[1]; y++) - for (int x = 0; x < res[0]; x++) - { - // front slab - index = x + y * res[0]; - field[index] = field[index + 2 * slabSize]; - } - } - - if (zEnd == res[2]) { - for (int y = 0; y < res[1]; y++) - for (int x = 0; x < res[0]; x++) - { - // back slab - index = x + y * res[0] + cellsslab; - field[index] = field[index - 2 * slabSize]; - } - } - -} - -////////////////////////////////////////////////////////////////////// -// set x direction to zero -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setZeroX(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - int index; - for (int z = zBegin; z < zEnd; z++) - for (int y = 0; y < res[1]; y++) - { - // left slab - index = y * res[0] + z * slabSize; - field[index] = 0.0f; - - // right slab - index += res[0] - 1; - field[index] = 0.0f; - } -} - -////////////////////////////////////////////////////////////////////// -// set y direction to zero -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setZeroY(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - int index; - for (int z = zBegin; z < zEnd; z++) - for (int x = 0; x < res[0]; x++) - { - // bottom slab - index = x + z * slabSize; - field[index] = 0.0f; - - // top slab - index += slabSize - res[0]; - field[index] = 0.0f; - } -} - -////////////////////////////////////////////////////////////////////// -// set z direction to zero -////////////////////////////////////////////////////////////////////// -void FLUID_3D::setZeroZ(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - const int totalCells = res[0] * res[1] * res[2]; - - int index = 0; - if (zBegin == 0) - { - for (int y = 0; y < res[1]; y++) - for (int x = 0; x < res[0]; x++, index++) - { - // front slab - field[index] = 0.0f; - } - } - - if (zEnd == res[2]) - { - index=0; - int indexx=0; - const int cellsslab = totalCells - slabSize; - - for (int y = 0; y < res[1]; y++) - for (int x = 0; x < res[0]; x++, index++) - { - - // back slab - indexx = index + cellsslab; - field[indexx] = 0.0f; - } - } - } -////////////////////////////////////////////////////////////////////// -// copy grid boundary -////////////////////////////////////////////////////////////////////// -void FLUID_3D::copyBorderX(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - int index; - for (int z = zBegin; z < zEnd; z++) - for (int y = 0; y < res[1]; y++) - { - // left slab - index = y * res[0] + z * slabSize; - field[index] = field[index + 1]; - - // right slab - index += res[0] - 1; - field[index] = field[index - 1]; - } -} -void FLUID_3D::copyBorderY(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - //const int totalCells = res[0] * res[1] * res[2]; - int index; - for (int z = zBegin; z < zEnd; z++) - for (int x = 0; x < res[0]; x++) - { - // bottom slab - index = x + z * slabSize; - field[index] = field[index + res[0]]; - // top slab - index += slabSize - res[0]; - field[index] = field[index - res[0]]; - } -} -void FLUID_3D::copyBorderZ(float* field, Vec3Int res, int zBegin, int zEnd) -{ - const int slabSize = res[0] * res[1]; - const int totalCells = res[0] * res[1] * res[2]; - int index=0; - - if (zBegin == 0) - { - for (int y = 0; y < res[1]; y++) - for (int x = 0; x < res[0]; x++, index++) - { - field[index] = field[index + slabSize]; - } - } - - if (zEnd == res[2]) - { - - index=0; - int indexx=0; - const int cellsslab = totalCells - slabSize; - - for (int y = 0; y < res[1]; y++) - for (int x = 0; x < res[0]; x++, index++) - { - // back slab - indexx = index + cellsslab; - field[indexx] = field[indexx - slabSize]; - } - } -} - -///////////////////////////////////////////////////////////////////// -// advect field with the semi lagrangian method -////////////////////////////////////////////////////////////////////// -void FLUID_3D::advectFieldSemiLagrange(const float dt, const float* velx, const float* vely, const float* velz, - float* oldField, float* newField, Vec3Int res, int zBegin, int zEnd) -{ - const int xres = res[0]; - const int yres = res[1]; - const int zres = res[2]; - const int slabSize = res[0] * res[1]; - - - for (int z = zBegin; z < zEnd; z++) - for (int y = 0; y < yres; y++) - for (int x = 0; x < xres; x++) - { - const int index = x + y * xres + z * xres*yres; - - // backtrace - float xTrace = x - dt * velx[index]; - float yTrace = y - dt * vely[index]; - float zTrace = z - dt * velz[index]; - - // clamp backtrace to grid boundaries - if (xTrace < 0.5f) xTrace = 0.5f; - if (xTrace > xres - 1.5f) xTrace = xres - 1.5f; - if (yTrace < 0.5f) yTrace = 0.5f; - if (yTrace > yres - 1.5f) yTrace = yres - 1.5f; - if (zTrace < 0.5f) zTrace = 0.5f; - if (zTrace > zres - 1.5f) zTrace = zres - 1.5f; - - // locate neighbors to interpolate - const int x0 = (int)xTrace; - const int x1 = x0 + 1; - const int y0 = (int)yTrace; - const int y1 = y0 + 1; - const int z0 = (int)zTrace; - const int z1 = z0 + 1; - - // get interpolation weights - const float s1 = xTrace - x0; - const float s0 = 1.0f - s1; - const float t1 = yTrace - y0; - const float t0 = 1.0f - t1; - const float u1 = zTrace - z0; - const float u0 = 1.0f - u1; - - const int i000 = x0 + y0 * xres + z0 * slabSize; - const int i010 = x0 + y1 * xres + z0 * slabSize; - const int i100 = x1 + y0 * xres + z0 * slabSize; - const int i110 = x1 + y1 * xres + z0 * slabSize; - const int i001 = x0 + y0 * xres + z1 * slabSize; - const int i011 = x0 + y1 * xres + z1 * slabSize; - const int i101 = x1 + y0 * xres + z1 * slabSize; - const int i111 = x1 + y1 * xres + z1 * slabSize; - - // interpolate - // (indices could be computed once) - newField[index] = u0 * (s0 * (t0 * oldField[i000] + - t1 * oldField[i010]) + - s1 * (t0 * oldField[i100] + - t1 * oldField[i110])) + - u1 * (s0 * (t0 * oldField[i001] + - t1 * oldField[i011]) + - s1 * (t0 * oldField[i101] + - t1 * oldField[i111])); - } -} - - -///////////////////////////////////////////////////////////////////// -// advect field with the maccormack method -// -// comments are the pseudocode from selle's paper -////////////////////////////////////////////////////////////////////// -void FLUID_3D::advectFieldMacCormack1(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* tempResult, Vec3Int res, int zBegin, int zEnd) -{ - /*const int sx= res[0]; - const int sy= res[1]; - const int sz= res[2]; - - for (int x = 0; x < sx * sy * sz; x++) - phiHatN[x] = phiHatN1[x] = oldField[x];*/ // not needed as all the values are written first - - float*& phiN = oldField; - float*& phiN1 = tempResult; - - - - // phiHatN1 = A(phiN) - advectFieldSemiLagrange( dt, xVelocity, yVelocity, zVelocity, phiN, phiN1, res, zBegin, zEnd); // uses wide data from old field and velocities (both are whole) -} - - - -void FLUID_3D::advectFieldMacCormack2(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, - float* oldField, float* newField, float* tempResult, float* temp1, Vec3Int res, const unsigned char* obstacles, int zBegin, int zEnd) -{ - float* phiHatN = tempResult; - float* t1 = temp1; - const int sx= res[0]; - const int sy= res[1]; - - float*& phiN = oldField; - float*& phiN1 = newField; - - - - // phiHatN = A^R(phiHatN1) - advectFieldSemiLagrange( -1.0f*dt, xVelocity, yVelocity, zVelocity, phiHatN, t1, res, zBegin, zEnd); // uses wide data from old field and velocities (both are whole) - - // phiN1 = phiHatN1 + (phiN - phiHatN) / 2 - const int border = 0; - for (int z = zBegin+border; z < zEnd-border; z++) - for (int y = border; y < sy-border; y++) - for (int x = border; x < sx-border; x++) { - int index = x + y * sx + z * sx*sy; - phiN1[index] = phiHatN[index] + (phiN[index] - t1[index]) * 0.50f; - //phiN1[index] = phiHatN1[index]; // debug, correction off - } - copyBorderX(phiN1, res, zBegin, zEnd); - copyBorderY(phiN1, res, zBegin, zEnd); - copyBorderZ(phiN1, res, zBegin, zEnd); - - // clamp any newly created extrema - clampExtrema(dt, xVelocity, yVelocity, zVelocity, oldField, newField, res, zBegin, zEnd); // uses wide data from old field and velocities (both are whole) - - // if the error estimate was bad, revert to first order - clampOutsideRays(dt, xVelocity, yVelocity, zVelocity, oldField, newField, res, obstacles, phiHatN, zBegin, zEnd); // phiHatN is only used at cells within thread range, so its ok - -} - - -////////////////////////////////////////////////////////////////////// -// Clamp the extrema generated by the BFECC error correction -////////////////////////////////////////////////////////////////////// -void FLUID_3D::clampExtrema(const float dt, const float* velx, const float* vely, const float* velz, - float* oldField, float* newField, Vec3Int res, int zBegin, int zEnd) -{ - const int xres= res[0]; - const int yres= res[1]; - const int zres= res[2]; - const int slabSize = res[0] * res[1]; - - int bb=0; - int bt=0; - - if (zBegin == 0) {bb = 1;} - if (zEnd == res[2]) {bt = 1;} - - - for (int z = zBegin+bb; z < zEnd-bt; z++) - for (int y = 1; y < yres-1; y++) - for (int x = 1; x < xres-1; x++) - { - const int index = x + y * xres+ z * xres*yres; - // backtrace - float xTrace = x - dt * velx[index]; - float yTrace = y - dt * vely[index]; - float zTrace = z - dt * velz[index]; - - // clamp backtrace to grid boundaries - if (xTrace < 0.5f) xTrace = 0.5f; - if (xTrace > xres - 1.5f) xTrace = xres - 1.5f; - if (yTrace < 0.5f) yTrace = 0.5f; - if (yTrace > yres - 1.5f) yTrace = yres - 1.5f; - if (zTrace < 0.5f) zTrace = 0.5f; - if (zTrace > zres - 1.5f) zTrace = zres - 1.5f; - - // locate neighbors to interpolate - const int x0 = (int)xTrace; - const int x1 = x0 + 1; - const int y0 = (int)yTrace; - const int y1 = y0 + 1; - const int z0 = (int)zTrace; - const int z1 = z0 + 1; - - const int i000 = x0 + y0 * xres + z0 * slabSize; - const int i010 = x0 + y1 * xres + z0 * slabSize; - const int i100 = x1 + y0 * xres + z0 * slabSize; - const int i110 = x1 + y1 * xres + z0 * slabSize; - const int i001 = x0 + y0 * xres + z1 * slabSize; - const int i011 = x0 + y1 * xres + z1 * slabSize; - const int i101 = x1 + y0 * xres + z1 * slabSize; - const int i111 = x1 + y1 * xres + z1 * slabSize; - - float minField = oldField[i000]; - float maxField = oldField[i000]; - - minField = (oldField[i010] < minField) ? oldField[i010] : minField; - maxField = (oldField[i010] > maxField) ? oldField[i010] : maxField; - - minField = (oldField[i100] < minField) ? oldField[i100] : minField; - maxField = (oldField[i100] > maxField) ? oldField[i100] : maxField; - - minField = (oldField[i110] < minField) ? oldField[i110] : minField; - maxField = (oldField[i110] > maxField) ? oldField[i110] : maxField; - - minField = (oldField[i001] < minField) ? oldField[i001] : minField; - maxField = (oldField[i001] > maxField) ? oldField[i001] : maxField; - - minField = (oldField[i011] < minField) ? oldField[i011] : minField; - maxField = (oldField[i011] > maxField) ? oldField[i011] : maxField; - - minField = (oldField[i101] < minField) ? oldField[i101] : minField; - maxField = (oldField[i101] > maxField) ? oldField[i101] : maxField; - - minField = (oldField[i111] < minField) ? oldField[i111] : minField; - maxField = (oldField[i111] > maxField) ? oldField[i111] : maxField; - - newField[index] = (newField[index] > maxField) ? maxField : newField[index]; - newField[index] = (newField[index] < minField) ? minField : newField[index]; - } -} - -////////////////////////////////////////////////////////////////////// -// Reverts any backtraces that go into boundaries back to first -// order -- in this case the error correction term was totally -// incorrect -////////////////////////////////////////////////////////////////////// -void FLUID_3D::clampOutsideRays(const float dt, const float* velx, const float* vely, const float* velz, - float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection, int zBegin, int zEnd) -{ - const int sx= res[0]; - const int sy= res[1]; - const int sz= res[2]; - const int slabSize = res[0] * res[1]; - - int bb=0; - int bt=0; - - if (zBegin == 0) {bb = 1;} - if (zEnd == res[2]) {bt = 1;} - - for (int z = zBegin+bb; z < zEnd-bt; z++) - for (int y = 1; y < sy-1; y++) - for (int x = 1; x < sx-1; x++) - { - const int index = x + y * sx+ z * slabSize; - // backtrace - float xBackward = x + dt * velx[index]; - float yBackward = y + dt * vely[index]; - float zBackward = z + dt * velz[index]; - float xTrace = x - dt * velx[index]; - float yTrace = y - dt * vely[index]; - float zTrace = z - dt * velz[index]; - - // see if it goes outside the boundaries - bool hasObstacle = - (zTrace < 1.0f) || (zTrace > sz - 2.0f) || - (yTrace < 1.0f) || (yTrace > sy - 2.0f) || - (xTrace < 1.0f) || (xTrace > sx - 2.0f) || - (zBackward < 1.0f) || (zBackward > sz - 2.0f) || - (yBackward < 1.0f) || (yBackward > sy - 2.0f) || - (xBackward < 1.0f) || (xBackward > sx - 2.0f); - // reuse old advection instead of doing another one... - if(hasObstacle) { newField[index] = oldAdvection[index]; continue; } - - // clamp to prevent an out of bounds access when looking into - // the _obstacles array - zTrace = (zTrace < 0.5f) ? 0.5f : zTrace; - zTrace = (zTrace > sz - 1.5f) ? sz - 1.5f : zTrace; - yTrace = (yTrace < 0.5f) ? 0.5f : yTrace; - yTrace = (yTrace > sy - 1.5f) ? sy - 1.5f : yTrace; - xTrace = (xTrace < 0.5f) ? 0.5f : xTrace; - xTrace = (xTrace > sx - 1.5f) ? sx - 1.5f : xTrace; - - // locate neighbors to interpolate, - // do backward first since we will use the forward indices if a - // reversion is actually necessary - zBackward = (zBackward < 0.5f) ? 0.5f : zBackward; - zBackward = (zBackward > sz - 1.5f) ? sz - 1.5f : zBackward; - yBackward = (yBackward < 0.5f) ? 0.5f : yBackward; - yBackward = (yBackward > sy - 1.5f) ? sy - 1.5f : yBackward; - xBackward = (xBackward < 0.5f) ? 0.5f : xBackward; - xBackward = (xBackward > sx - 1.5f) ? sx - 1.5f : xBackward; - - int x0 = (int)xBackward; - int x1 = x0 + 1; - int y0 = (int)yBackward; - int y1 = y0 + 1; - int z0 = (int)zBackward; - int z1 = z0 + 1; - if(obstacles && !hasObstacle) { - hasObstacle = hasObstacle || - obstacles[x0 + y0 * sx + z0*slabSize] || - obstacles[x0 + y1 * sx + z0*slabSize] || - obstacles[x1 + y0 * sx + z0*slabSize] || - obstacles[x1 + y1 * sx + z0*slabSize] || - obstacles[x0 + y0 * sx + z1*slabSize] || - obstacles[x0 + y1 * sx + z1*slabSize] || - obstacles[x1 + y0 * sx + z1*slabSize] || - obstacles[x1 + y1 * sx + z1*slabSize] ; - } - // reuse old advection instead of doing another one... - if(hasObstacle) { newField[index] = oldAdvection[index]; continue; } - - x0 = (int)xTrace; - x1 = x0 + 1; - y0 = (int)yTrace; - y1 = y0 + 1; - z0 = (int)zTrace; - z1 = z0 + 1; - if(obstacles && !hasObstacle) { - hasObstacle = hasObstacle || - obstacles[x0 + y0 * sx + z0*slabSize] || - obstacles[x0 + y1 * sx + z0*slabSize] || - obstacles[x1 + y0 * sx + z0*slabSize] || - obstacles[x1 + y1 * sx + z0*slabSize] || - obstacles[x0 + y0 * sx + z1*slabSize] || - obstacles[x0 + y1 * sx + z1*slabSize] || - obstacles[x1 + y0 * sx + z1*slabSize] || - obstacles[x1 + y1 * sx + z1*slabSize] ; - } // obstacle array - // reuse old advection instead of doing another one... - if(hasObstacle) { newField[index] = oldAdvection[index]; continue; } - - // see if either the forward or backward ray went into - // a boundary - if (hasObstacle) { - // get interpolation weights - float s1 = xTrace - x0; - float s0 = 1.0f - s1; - float t1 = yTrace - y0; - float t0 = 1.0f - t1; - float u1 = zTrace - z0; - float u0 = 1.0f - u1; - - const int i000 = x0 + y0 * sx + z0 * slabSize; - const int i010 = x0 + y1 * sx + z0 * slabSize; - const int i100 = x1 + y0 * sx + z0 * slabSize; - const int i110 = x1 + y1 * sx + z0 * slabSize; - const int i001 = x0 + y0 * sx + z1 * slabSize; - const int i011 = x0 + y1 * sx + z1 * slabSize; - const int i101 = x1 + y0 * sx + z1 * slabSize; - const int i111 = x1 + y1 * sx + z1 * slabSize; - - // interpolate, (indices could be computed once) - newField[index] = u0 * (s0 * ( - t0 * oldField[i000] + - t1 * oldField[i010]) + - s1 * (t0 * oldField[i100] + - t1 * oldField[i110])) + - u1 * (s0 * (t0 * oldField[i001] + - t1 * oldField[i011]) + - s1 * (t0 * oldField[i101] + - t1 * oldField[i111])); - } - } // xyz -} diff --git a/intern/smoke/intern/IMAGE.h b/intern/smoke/intern/IMAGE.h deleted file mode 100644 index 4680e4eace2..00000000000 --- a/intern/smoke/intern/IMAGE.h +++ /dev/null @@ -1,289 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -////////////////////////////////////////////////////////////////////// -// -#ifndef IMAGE_H -#define IMAGE_H - -#include -#include -#include -#include -#include - -////////////////////////////////////////////////////////////////////// -// NT helper functions -////////////////////////////////////////////////////////////////////// -template < class T > inline T ABS( T a ) { - return (0 < a) ? a : -a ; -} - -template < class T > inline void SWAP_POINTERS( T &a, T &b ) { - T temp = a; - a = b; - b = temp; -} - -template < class T > inline void CLAMP( T &a, T b=0., T c=1.) { - if(ac) { a=c; return; } -} - -template < class T > inline T MIN( const T& a, const T& b) { - return (a < b) ? a : b; -} - -template < class T > inline T MAX( const T& a, const T& b) { - return (a > b) ? a : b; -} - -template < class T > inline T MAX3( const T& a, const T& b, const T& c) { - T max = (a > b) ? a : b; - max = (max > c) ? max : c; - return max; -} - -template < class T > inline float MAX3V( const T& vec) { - float max = (vec[0] > vec[1]) ? vec[0] : vec[1]; - max = (max > vec[2]) ? max : vec[2]; - return max; -} - -template < class T > inline float MIN3V( const T& vec) { - float min = (vec[0] < vec[1]) ? vec[0] : vec[1]; - min = (min < vec[2]) ? min : vec[2]; - return min; -} - -////////////////////////////////////////////////////////////////////// -// PNG, POV-Ray, and PBRT output functions -////////////////////////////////////////////////////////////////////// -#ifndef NOPNG -#ifdef WIN32 -#include "png.h" -#else -#include -#endif -#endif // NOPNG - -/* - NOTE when someone decided to uncomment the following code, please remember to put it between #ifndef NOPNG #endif -*/ -namespace IMAGE { - /* - static int writePng(const char *fileName, unsigned char **rowsp, int w, int h) - { - // defaults - const int colortype = PNG_COLOR_TYPE_RGBA; - const int bitdepth = 8; - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; - png_bytep *rows = rowsp; - - FILE *fp = NULL; - std::string doing = "open for writing"; - if (!(fp = fopen(fileName, "wb"))) goto fail; - - if(!png_ptr) { - doing = "create png write struct"; - if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) goto fail; - } - if(!info_ptr) { - doing = "create png info struct"; - if (!(info_ptr = png_create_info_struct(png_ptr))) goto fail; - } - - if (setjmp(png_jmpbuf(png_ptr))) goto fail; - doing = "init IO"; - png_init_io(png_ptr, fp); - doing = "write header"; - png_set_IHDR(png_ptr, info_ptr, w, h, bitdepth, colortype, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - doing = "write info"; - png_write_info(png_ptr, info_ptr); - doing = "write image"; - png_write_image(png_ptr, rows); - doing = "write end"; - png_write_end(png_ptr, NULL); - doing = "write destroy structs"; - png_destroy_write_struct(&png_ptr, &info_ptr); - - fclose( fp ); - return 0; - - fail: - std::cerr << "writePng: could not "<1.) val=1.; - if(val<0.) val=0.; - pngbuf[(j*xRes+i)*4+0] = (unsigned char)(val*255.); - pngbuf[(j*xRes+i)*4+1] = (unsigned char)(val*255.); - pngbuf[(j*xRes+i)*4+2] = (unsigned char)(val*255.); - pfield++; - pngbuf[(j*xRes+i)*4+3] = 255; - } - rows[j] = &pngbuf[(yRes-j-1)*xRes*4]; - } - std::string filenamePNG = prefix + number + std::string(".png"); - writePng(filenamePNG.c_str(), rows, xRes, yRes, false); - printf("Writing %s\n", filenamePNG.c_str()); - - } -*/ - ///////////////////////////////////////////////////////////////////////////////// - // export pbrt volumegrid geometry object - ///////////////////////////////////////////////////////////////////////////////// - /* - static void dumpPBRT(int counter, std::string prefix, float* fieldOrg, int xRes, int yRes, int zRes) - { - char buffer[256]; - sprintf(buffer,"%04i", counter); - std::string number = std::string(buffer); - - std::string filenamePbrt = prefix + number + std::string(".pbrt.gz"); - printf("Writing PBRT %s\n", filenamePbrt.c_str()); - - float *field = new float[xRes*yRes*zRes]; - // normalize values - float maxDensVal = ABS(fieldOrg[0]); - float targetNorm = 0.5; - for (int i = 0; i < xRes * yRes * zRes; i++) { - if(ABS(fieldOrg[i])>maxDensVal) maxDensVal = ABS(fieldOrg[i]); - field[i] = 0.; - } - if(maxDensVal>0.) { - for (int i = 0; i < xRes * yRes * zRes; i++) { - field[i] = ABS(fieldOrg[i]) / maxDensVal * targetNorm; - } - } - - std::fstream fout; - fout.open(filenamePbrt.c_str(), std::ios::out); - - int maxRes = (xRes > yRes) ? xRes : yRes; - maxRes = (maxRes > zRes) ? maxRes : zRes; - - const float xSize = 1.0 / (float)maxRes * (float)xRes; - const float ySize = 1.0 / (float)maxRes * (float)yRes; - const float zSize = 1.0 / (float)maxRes * (float)zRes; - - gzFile file; - file = gzopen(filenamePbrt.c_str(), "wb1"); - if (file == NULL) { - std::cerr << " Couldn't write file " << filenamePbrt << "!!!" << std::endl; - return; - } - - // dimensions - gzprintf(file, "Volume \"volumegrid\" \n"); - gzprintf(file, " \"integer nx\" %i\n", xRes); - gzprintf(file, " \"integer ny\" %i\n", yRes); - gzprintf(file, " \"integer nz\" %i\n", zRes); - gzprintf(file, " \"point p0\" [ 0.0 0.0 0.0 ] \"point p1\" [%f %f %f ] \n", xSize, ySize, zSize); - gzprintf(file, " \"float density\" [ \n"); - for (int i = 0; i < xRes * yRes * zRes; i++) - gzprintf(file, "%f ", field[i]); - gzprintf(file, "] \n \n"); - - gzclose(file); - delete[] field; - } - */ - - ///////////////////////////////////////////////////////////////////////////////// - // 3D df3 export - ///////////////////////////////////////////////////////////////////////////////// -/* - static void dumpDF3(int counter, std::string prefix, float* fieldOrg, int xRes, int yRes, int zRes) - { - char buffer[256]; - - // do deferred copying to final directory, better for network directories - sprintf(buffer,"%04i", counter); - std::string number = std::string(buffer); - std::string filenameDf3 = prefix + number + std::string(".df3.gz"); - printf("Writing DF3 %s\n", filenameDf3.c_str()); - - gzFile file; - file = gzopen(filenameDf3.c_str(), "wb1"); - if (file == NULL) { - std::cerr << " Couldn't write file " << filenameDf3 << "!!!" << std::endl; - return; - } - - // dimensions - const int byteSize = 2; - const unsigned short int onx=xRes,ony=yRes,onz=zRes; - unsigned short int nx,ny,nz; - nx = onx >> 8; - ny = ony >> 8; - nz = onz >> 8; - nx += (onx << 8); - ny += (ony << 8); - nz += (onz << 8); - gzwrite(file, (void*)&nx, sizeof(short)); - gzwrite(file, (void*)&ny, sizeof(short)); - gzwrite(file, (void*)&nz, sizeof(short)); - const int nitems = onx*ony*onz; - const float mul = (float)( (1<<(8*byteSize))-1); - - unsigned short int *buf = new unsigned short int[nitems]; - for (int k = 0; k < onz; k++) - for (int j = 0; j < ony; j++) - for (int i = 0; i < onx; i++) { - float val = fieldOrg[k*(onx*ony)+j*onx+i] ; - CLAMP(val); - buf[k*(onx*ony)+j*onx+i] = (short int)(val*mul); - } - gzwrite(file, (void*)buf, sizeof(unsigned short int)* nitems); - - gzclose(file); - delete[] buf; - } - */ - -}; - - -#endif - diff --git a/intern/smoke/intern/INTERPOLATE.h b/intern/smoke/intern/INTERPOLATE.h deleted file mode 100644 index e9821e4f93e..00000000000 --- a/intern/smoke/intern/INTERPOLATE.h +++ /dev/null @@ -1,230 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -////////////////////////////////////////////////////////////////////// -#ifndef INTERPOLATE_H -#define INTERPOLATE_H - -#include -#include - -namespace INTERPOLATE { - -////////////////////////////////////////////////////////////////////// -// linear interpolators -////////////////////////////////////////////////////////////////////// -static inline float lerp(float t, float a, float b) { - return ( a + t * (b - a) ); -} - -static inline float lerp(float* field, float x, float y, int res) { - // clamp backtrace to grid boundaries - if (x < 0.5f) x = 0.5f; - if (x > res - 1.5f) x = res - 1.5f; - if (y < 0.5f) y = 0.5f; - if (y > res - 1.5f) y = res - 1.5f; - - const int x0 = (int)x; - const int y0 = (int)y; - x -= x0; - y -= y0; - float d00, d10, d01, d11; - - // lerp the velocities - d00 = field[x0 + y0 * res]; - d10 = field[(x0 + 1) + y0 * res]; - d01 = field[x0 + (y0 + 1) * res]; - d11 = field[(x0 + 1) + (y0 + 1) * res]; - return lerp(y, lerp(x, d00, d10), - lerp(x, d01, d11)); -} - -////////////////////////////////////////////////////////////////////////////////////////// -// 3d linear interpolation -////////////////////////////////////////////////////////////////////////////////////////// -static inline float lerp3d(float* field, float x, float y, float z, int xres, int yres, int zres) { - // clamp pos to grid boundaries - if (x < 0.5f) x = 0.5f; - if (x > xres - 1.5f) x = xres - 1.5f; - if (y < 0.5f) y = 0.5f; - if (y > yres - 1.5f) y = yres - 1.5f; - if (z < 0.5f) z = 0.5f; - if (z > zres - 1.5f) z = zres - 1.5f; - - // locate neighbors to interpolate - const int x0 = (int)x; - const int x1 = x0 + 1; - const int y0 = (int)y; - const int y1 = y0 + 1; - const int z0 = (int)z; - const int z1 = z0 + 1; - - // get interpolation weights - const float s1 = x - (float)x0; - const float s0 = 1.0f - s1; - const float t1 = y - (float)y0; - const float t0 = 1.0f - t1; - const float u1 = z - (float)z0; - const float u0 = 1.0f - u1; - - const int slabSize = xres*yres; - const int i000 = x0 + y0 * xres + z0 * slabSize; - const int i010 = x0 + y1 * xres + z0 * slabSize; - const int i100 = x1 + y0 * xres + z0 * slabSize; - const int i110 = x1 + y1 * xres + z0 * slabSize; - const int i001 = x0 + y0 * xres + z1 * slabSize; - const int i011 = x0 + y1 * xres + z1 * slabSize; - const int i101 = x1 + y0 * xres + z1 * slabSize; - const int i111 = x1 + y1 * xres + z1 * slabSize; - - // interpolate (indices could be computed once) - return ( u0 * (s0 * (t0 * field[i000] + - t1 * field[i010]) + - s1 * (t0 * field[i100] + - t1 * field[i110])) + - u1 * (s0 * (t0 * field[i001] + - t1 * field[i011]) + - s1 * (t0 * field[i101] + - t1 * field[i111])) ); -} - -////////////////////////////////////////////////////////////////////////////////////////// -// convert field entries of type T to floats, then interpolate -////////////////////////////////////////////////////////////////////////////////////////// -template -static inline float lerp3dToFloat(T* field1, - float x, float y, float z, int xres, int yres, int zres) { - // clamp pos to grid boundaries - if (x < 0.5f) x = 0.5f; - if (x > xres - 1.5f) x = xres - 1.5f; - if (y < 0.5f) y = 0.5f; - if (y > yres - 1.5f) y = yres - 1.5f; - if (z < 0.5f) z = 0.5f; - if (z > zres - 1.5f) z = zres - 1.5f; - - // locate neighbors to interpolate - const int x0 = (int)x; - const int x1 = x0 + 1; - const int y0 = (int)y; - const int y1 = y0 + 1; - const int z0 = (int)z; - const int z1 = z0 + 1; - - // get interpolation weights - const float s1 = x - (float)x0; - const float s0 = 1.0f - s1; - const float t1 = y - (float)y0; - const float t0 = 1.0f - t1; - const float u1 = z - (float)z0; - const float u0 = 1.0f - u1; - - const int slabSize = xres*yres; - const int i000 = x0 + y0 * xres + z0 * slabSize; - const int i010 = x0 + y1 * xres + z0 * slabSize; - const int i100 = x1 + y0 * xres + z0 * slabSize; - const int i110 = x1 + y1 * xres + z0 * slabSize; - const int i001 = x0 + y0 * xres + z1 * slabSize; - const int i011 = x0 + y1 * xres + z1 * slabSize; - const int i101 = x1 + y0 * xres + z1 * slabSize; - const int i111 = x1 + y1 * xres + z1 * slabSize; - - // interpolate (indices could be computed once) - return (float)( - ( u0 * (s0 * (t0 * (float)field1[i000] + - t1 * (float)field1[i010]) + - s1 * (t0 * (float)field1[i100] + - t1 * (float)field1[i110])) + - u1 * (s0 * (t0 * (float)field1[i001] + - t1 * (float)field1[i011]) + - s1 * (t0 * (float)field1[i101] + - t1 * (float)field1[i111])) ) ); -} - -////////////////////////////////////////////////////////////////////////////////////////// -// interpolate a vector from 3 fields -////////////////////////////////////////////////////////////////////////////////////////// -static inline Vec3 lerp3dVec(float* field1, float* field2, float* field3, - float x, float y, float z, int xres, int yres, int zres) { - // clamp pos to grid boundaries - if (x < 0.5f) x = 0.5f; - if (x > xres - 1.5f) x = xres - 1.5f; - if (y < 0.5f) y = 0.5f; - if (y > yres - 1.5f) y = yres - 1.5f; - if (z < 0.5f) z = 0.5f; - if (z > zres - 1.5f) z = zres - 1.5f; - - // locate neighbors to interpolate - const int x0 = (int)x; - const int x1 = x0 + 1; - const int y0 = (int)y; - const int y1 = y0 + 1; - const int z0 = (int)z; - const int z1 = z0 + 1; - - // get interpolation weights - const float s1 = x - (float)x0; - const float s0 = 1.0f - s1; - const float t1 = y - (float)y0; - const float t0 = 1.0f - t1; - const float u1 = z - (float)z0; - const float u0 = 1.0f - u1; - - const int slabSize = xres*yres; - const int i000 = x0 + y0 * xres + z0 * slabSize; - const int i010 = x0 + y1 * xres + z0 * slabSize; - const int i100 = x1 + y0 * xres + z0 * slabSize; - const int i110 = x1 + y1 * xres + z0 * slabSize; - const int i001 = x0 + y0 * xres + z1 * slabSize; - const int i011 = x0 + y1 * xres + z1 * slabSize; - const int i101 = x1 + y0 * xres + z1 * slabSize; - const int i111 = x1 + y1 * xres + z1 * slabSize; - - // interpolate (indices could be computed once) - return Vec3( - ( u0 * (s0 * (t0 * field1[i000] + - t1 * field1[i010]) + - s1 * (t0 * field1[i100] + - t1 * field1[i110])) + - u1 * (s0 * (t0 * field1[i001] + - t1 * field1[i011]) + - s1 * (t0 * field1[i101] + - t1 * field1[i111])) ) , - ( u0 * (s0 * (t0 * field2[i000] + - t1 * field2[i010]) + - s1 * (t0 * field2[i100] + - t1 * field2[i110])) + - u1 * (s0 * (t0 * field2[i001] + - t1 * field2[i011]) + - s1 * (t0 * field2[i101] + - t1 * field2[i111])) ) , - ( u0 * (s0 * (t0 * field3[i000] + - t1 * field3[i010]) + - s1 * (t0 * field3[i100] + - t1 * field3[i110])) + - u1 * (s0 * (t0 * field3[i001] + - t1 * field3[i011]) + - s1 * (t0 * field3[i101] + - t1 * field3[i111])) ) - ); -} - -}; -#endif diff --git a/intern/smoke/intern/LICENSE.txt b/intern/smoke/intern/LICENSE.txt deleted file mode 100644 index 94a9ed024d3..00000000000 --- a/intern/smoke/intern/LICENSE.txt +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/intern/smoke/intern/LU_HELPER.cpp b/intern/smoke/intern/LU_HELPER.cpp deleted file mode 100644 index 0a4260c2e64..00000000000 --- a/intern/smoke/intern/LU_HELPER.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/** \file - * \ingroup smoke - */ - -#include "LU_HELPER.h" - -int isNonsingular (sLU LU_) { - for (int j = 0; j < 3; j++) { - if (LU_.values[j][j] == 0) - return 0; - } - return 1; -} - -sLU computeLU( float a[3][3]) -{ - sLU result; - int m=3; - int n=3; - - //float LU_[3][3]; - for (int i = 0; i < m; i++) { - result.piv[i] = i; - for (int j = 0; j < n; j++) result.values[i][j]=a[i][j]; - } - - result.pivsign = 1; - //Real *LUrowi = 0;; - //Array1D LUcolj(m); - //float *LUrowi = 0; - float LUcolj[3]; - - // Outer loop. - - for (int j = 0; j < n; j++) { - - // Make a copy of the j-th column to localize references. - - for (int i = 0; i < m; i++) { - LUcolj[i] = result.values[i][j]; - } - - // Apply previous transformations. - - for (int i = 0; i < m; i++) { - //float LUrowi[3]; - //LUrowi = result.values[i]; - - // Most of the time is spent in the following dot product. - - int kmax = min(i,j); - double s = 0.0; - for (int k = 0; k < kmax; k++) { - s += (double)(result.values[i][k]*LUcolj[k]); - } - - result.values[i][j] = LUcolj[i] -= (float)s; - } - - // Find pivot and exchange if necessary. - - int p = j; - for (int i = j+1; i < m; i++) { - if (abs(LUcolj[i]) > abs(LUcolj[p])) { - p = i; - } - } - if (p != j) { - int k=0; - for (k = 0; k < n; k++) { - double t = result.values[p][k]; - result.values[p][k] = result.values[j][k]; - result.values[j][k] = t; - } - k = result.piv[p]; - result.piv[p] = result.piv[j]; - result.piv[j] = k; - result.pivsign = -result.pivsign; - } - - // Compute multipliers. - - if ((j < m) && (result.values[j][j] != 0.0f)) { - for (int i = j+1; i < m; i++) { - result.values[i][j] /= result.values[j][j]; - } - } - } - - return result; -} - -void solveLU3x3(sLU& A, float x[3], float b[3]) -{ - //TNT::Array1D jamaB = TNT::Array1D(3, &b[0]); - //TNT::Array1D jamaX = A.solve(jamaB); - - - // Solve A, B - - { - if (!isNonsingular(A)) { - x[0]=0.0f; - x[1]=0.0f; - x[2]=0.0f; - return; - } - - - //Array1D Ax = permute_copy(b, piv); - float Ax[3]; - - // permute copy: b , A.piv - { - for (int i = 0; i < 3; i++) - Ax[i] = b[A.piv[i]]; - } - - // Solve L*Y = B(piv) - for (int k = 0; k < 3; k++) { - for (int i = k+1; i < 3; i++) { - Ax[i] -= Ax[k]*A.values[i][k]; - } - } - - // Solve U*X = Y; - for (int k = 2; k >= 0; k--) { - Ax[k] /= A.values[k][k]; - for (int i = 0; i < k; i++) - Ax[i] -= Ax[k]*A.values[i][k]; - } - - - x[0] = Ax[0]; - x[1] = Ax[1]; - x[2] = Ax[2]; - return; - } -} diff --git a/intern/smoke/intern/LU_HELPER.h b/intern/smoke/intern/LU_HELPER.h deleted file mode 100644 index 3cc8e9e3ced..00000000000 --- a/intern/smoke/intern/LU_HELPER.h +++ /dev/null @@ -1,54 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -////////////////////////////////////////////////////////////////////// -// Modified to not require TNT matrix library anymore. It was very slow -// when being run in parallel. Required TNT JAMA:LU libraries were -// converted into independent functions. -// - MiikaH -////////////////////////////////////////////////////////////////////// - -#ifndef LU_HELPER_H -#define LU_HELPER_H - -#include -#include - -using namespace std; - -////////////////////////////////////////////////////////////////////// -// Helper function, compute eigenvalues of 3x3 matrix -////////////////////////////////////////////////////////////////////// - -struct sLU -{ - float values[3][3]; - int pivsign; - int piv[3]; -}; - - -int isNonsingular (sLU LU_); -sLU computeLU( float a[3][3]); -void solveLU3x3(sLU& A, float x[3], float b[3]); - - -#endif diff --git a/intern/smoke/intern/MERSENNETWISTER.h b/intern/smoke/intern/MERSENNETWISTER.h deleted file mode 100644 index b142ca4072b..00000000000 --- a/intern/smoke/intern/MERSENNETWISTER.h +++ /dev/null @@ -1,432 +0,0 @@ -/** \file - * \ingroup smoke - */ -// MersenneTwister.h -// Mersenne Twister random number generator -- a C++ class MTRand -// Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus -// Richard J. Wagner v1.0 15 May 2003 rjwagner@writeme.com - -// The Mersenne Twister is an algorithm for generating random numbers. It -// was designed with consideration of the flaws in various other generators. -// The period, 2^19937-1, and the order of equidistribution, 623 dimensions, -// are far greater. The generator is also fast; it avoids multiplication and -// division, and it benefits from caches and pipelines. For more information -// see the inventors' web page at http://www.math.keio.ac.jp/~matumoto/emt.html - -// Reference -// M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally -// Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on -// Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. - -// Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, -// Copyright (C) 2000 - 2003, Richard J. Wagner -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The names of its contributors may not be used to endorse or promote -// products derived from this software without specific prior written -// permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// The original code included the following notice: -// -// When you use this, send an email to: matumoto@math.keio.ac.jp -// with an appropriate reference to your work. -// -// It would be nice to CC: rjwagner@writeme.com and Cokus@math.washington.edu -// when you write. - -#ifndef MERSENNETWISTER_H -#define MERSENNETWISTER_H - -// Not thread safe (unless auto-initialization is avoided and each thread has -// its own MTRand object) - -#include -#include -#include -#include -#include - -class MTRand { -// Data -public: - typedef unsigned long uint32; // unsigned integer type, at least 32 bits - - enum { N = 624 }; // length of state vector - enum { SAVE = N + 1 }; // length of array for save() - -protected: - enum { M = 397 }; // period parameter - - uint32 state[N]; // internal state - uint32 *pNext; // next value to get from state - int left; // number of values left before reload needed - - -//Methods -public: - MTRand( const uint32& oneSeed ); // initialize with a simple uint32 - MTRand( uint32 *const bigSeed, uint32 const seedLength = N ); // or an array - MTRand(); // auto-initialize with /dev/urandom or time() and clock() - - // Do NOT use for CRYPTOGRAPHY without securely hashing several returned - // values together, otherwise the generator state can be learned after - // reading 624 consecutive values. - - // Access to 32-bit random numbers - double rand(); // real number in [0,1] - double rand( const double& n ); // real number in [0,n] - double randExc(); // real number in [0,1) - double randExc( const double& n ); // real number in [0,n) - double randDblExc(); // real number in (0,1) - double randDblExc( const double& n ); // real number in (0,n) - uint32 randInt(); // integer in [0,2^32-1] - uint32 randInt( const uint32& n ); // integer in [0,n] for n < 2^32 - double operator()() { return rand(); } // same as rand() - - // Access to 53-bit random numbers (capacity of IEEE double precision) - double rand53(); // real number in [0,1) - - // Access to nonuniform random number distributions - double randNorm( const double& mean = 0.0, const double& variance = 1.0 ); - - // Re-seeding functions with same behavior as initializers - void seed( const uint32 oneSeed ); - void seed( uint32 *const bigSeed, const uint32 seedLength = N ); - void seed(); - - // Saving and loading generator state - void save( uint32* saveArray ) const; // to array of size SAVE - void load( uint32 *const loadArray ); // from such array - friend std::ostream& operator<<( std::ostream& os, const MTRand& mtrand ); - friend std::istream& operator>>( std::istream& is, MTRand& mtrand ); - -protected: - void initialize( const uint32 oneSeed ); - void reload(); - uint32 hiBit( const uint32& u ) const { return u & 0x80000000UL; } - uint32 loBit( const uint32& u ) const { return u & 0x00000001UL; } - uint32 loBits( const uint32& u ) const { return u & 0x7fffffffUL; } - uint32 mixBits( const uint32& u, const uint32& v ) const - { return hiBit(u) | loBits(v); } - uint32 twist( const uint32& m, const uint32& s0, const uint32& s1 ) const - { return m ^ (mixBits(s0,s1)>>1) ^ ((~loBit(s1) + 1) & 0x9908b0dfUL); } - static uint32 hash( time_t t, clock_t c ); -}; - - -inline MTRand::MTRand( const uint32& oneSeed ) - { seed(oneSeed); } - -inline MTRand::MTRand( uint32 *const bigSeed, const uint32 seedLength ) - { seed(bigSeed,seedLength); } - -inline MTRand::MTRand() - { seed(); } - -inline double MTRand::rand() - { return double(randInt()) * (1.0/4294967295.0); } - -inline double MTRand::rand( const double& n ) - { return rand() * n; } - -inline double MTRand::randExc() - { return double(randInt()) * (1.0/4294967296.0); } - -inline double MTRand::randExc( const double& n ) - { return randExc() * n; } - -inline double MTRand::randDblExc() - { return ( double(randInt()) + 0.5 ) * (1.0/4294967296.0); } - -inline double MTRand::randDblExc( const double& n ) - { return randDblExc() * n; } - -inline double MTRand::rand53() -{ - uint32 a = randInt() >> 5, b = randInt() >> 6; - return ( a * 67108864.0 + b ) * (1.0/9007199254740992.0); // by Isaku Wada -} - -inline double MTRand::randNorm( const double& mean, const double& variance ) -{ - // Return a real number from a normal (Gaussian) distribution with given - // mean and variance by Box-Muller method - double r = sqrt( -2.0 * log( 1.0-randDblExc()) ) * variance; - double phi = 2.0 * 3.14159265358979323846264338328 * randExc(); - return mean + r * cos(phi); -} - -inline MTRand::uint32 MTRand::randInt() -{ - // Pull a 32-bit integer from the generator state - // Every other access function simply transforms the numbers extracted here - - if( left == 0 ) reload(); - --left; - - uint32 s1; - s1 = *pNext++; - s1 ^= (s1 >> 11); - s1 ^= (s1 << 7) & 0x9d2c5680UL; - s1 ^= (s1 << 15) & 0xefc60000UL; - return ( s1 ^ (s1 >> 18) ); -} - -inline MTRand::uint32 MTRand::randInt( const uint32& n ) -{ - // Find which bits are used in n - // Optimized by Magnus Jonsson (magnus@smartelectronix.com) - uint32 used = n; - used |= used >> 1; - used |= used >> 2; - used |= used >> 4; - used |= used >> 8; - used |= used >> 16; - - // Draw numbers until one is found in [0,n] - uint32 i; - do - i = randInt() & used; // toss unused bits to shorten search - while( i > n ); - return i; -} - - -inline void MTRand::seed( const uint32 oneSeed ) -{ - // Seed the generator with a simple uint32 - initialize(oneSeed); - reload(); -} - - -inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength ) -{ - // Seed the generator with an array of uint32's - // There are 2^19937-1 possible initial states. This function allows - // all of those to be accessed by providing at least 19937 bits (with a - // default seed length of N = 624 uint32's). Any bits above the lower 32 - // in each element are discarded. - // Just call seed() if you want to get array from /dev/urandom - initialize(19650218UL); - int i = 1; - uint32 j = 0; - int k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); - for( ; k; --k ) - { - state[i] = - state[i] ^ ( (state[i-1] ^ (state[i-1] >> 30)) * 1664525UL ); - state[i] += ( bigSeed[j] & 0xffffffffUL ) + j; - state[i] &= 0xffffffffUL; - ++i; ++j; - if( i >= N ) { state[0] = state[N-1]; i = 1; } - if( j >= seedLength ) j = 0; - } - for( k = N - 1; k; --k ) - { - state[i] = - state[i] ^ ( (state[i-1] ^ (state[i-1] >> 30)) * 1566083941UL ); - state[i] -= i; - state[i] &= 0xffffffffUL; - ++i; - if( i >= N ) { state[0] = state[N-1]; i = 1; } - } - state[0] = 0x80000000UL; // MSB is 1, assuring non-zero initial array - reload(); -} - - -inline void MTRand::seed() -{ - // seed deterministically to produce reproducible runs - seed(123456); - - /* - // Seed the generator with an array from /dev/urandom if available - // Otherwise use a hash of time() and clock() values - - // First try getting an array from /dev/urandom - FILE* urandom = fopen( "/dev/urandom", "rb" ); - if( urandom ) - { - uint32 bigSeed[N]; - uint32 *s = bigSeed; - int i = N; - bool success = true; - while( success && i-- ) - success = fread( s++, sizeof(uint32), 1, urandom ); - fclose(urandom); - if( success ) { seed( bigSeed, N ); return; } - } - - // Was not successful, so use time() and clock() instead - seed( hash( time(NULL), clock() ) ); - */ -} - - -inline void MTRand::initialize( const uint32 seed ) -{ - // Initialize generator state with seed - // See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier. - // In previous versions, most significant bits (MSBs) of the seed affect - // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. - uint32 *s = state; - uint32 *r = state; - int i = 1; - *s++ = seed & 0xffffffffUL; - for( ; i < N; ++i ) - { - *s++ = ( 1812433253UL * ( *r ^ (*r >> 30) ) + i ) & 0xffffffffUL; - r++; - } -} - - -inline void MTRand::reload() -{ - // Generate N new values in state - // Made clearer and faster by Matthew Bellew (matthew.bellew@home.com) - uint32 *p = state; - int i; - for( i = N - M; i--; ++p ) - *p = twist( p[M], p[0], p[1] ); - for( i = M; --i; ++p ) - *p = twist( p[M-N], p[0], p[1] ); - *p = twist( p[M-N], p[0], state[0] ); - - left = N, pNext = state; -} - - -inline MTRand::uint32 MTRand::hash( time_t t, clock_t c ) -{ - // Get a uint32 from t and c - // Better than uint32(x) in case x is floating point in [0,1] - // Based on code by Lawrence Kirby (fred@genesis.demon.co.uk) - - static uint32 differ = 0; // guarantee time-based seeds will change - - uint32 h1 = 0; - unsigned char *p = (unsigned char *) &t; - for( size_t i = 0; i < sizeof(t); ++i ) - { - h1 *= UCHAR_MAX + 2U; - h1 += p[i]; - } - uint32 h2 = 0; - p = (unsigned char *) &c; - for( size_t j = 0; j < sizeof(c); ++j ) - { - h2 *= UCHAR_MAX + 2U; - h2 += p[j]; - } - return ( h1 + differ++ ) ^ h2; -} - - -inline void MTRand::save( uint32* saveArray ) const -{ - uint32 *sa = saveArray; - const uint32 *s = state; - int i = N; - for( ; i--; *sa++ = *s++ ) {} - *sa = left; -} - - -inline void MTRand::load( uint32 *const loadArray ) -{ - uint32 *s = state; - uint32 *la = loadArray; - int i = N; - for( ; i--; *s++ = *la++ ) {} - left = *la; - pNext = &state[N-left]; -} - - -inline std::ostream& operator<<( std::ostream& os, const MTRand& mtrand ) -{ - const MTRand::uint32 *s = mtrand.state; - int i = mtrand.N; - for( ; i--; os << *s++ << "\t" ) {} - return os << mtrand.left; -} - - -inline std::istream& operator>>( std::istream& is, MTRand& mtrand ) -{ - MTRand::uint32 *s = mtrand.state; - int i = mtrand.N; - for( ; i--; is >> *s++ ) {} - is >> mtrand.left; - mtrand.pNext = &mtrand.state[mtrand.N-mtrand.left]; - return is; -} - -#endif // MERSENNETWISTER_H - -// Change log: -// -// v0.1 - First release on 15 May 2000 -// - Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus -// - Translated from C to C++ -// - Made completely ANSI compliant -// - Designed convenient interface for initialization, seeding, and -// obtaining numbers in default or user-defined ranges -// - Added automatic seeding from /dev/urandom or time() and clock() -// - Provided functions for saving and loading generator state -// -// v0.2 - Fixed bug which reloaded generator one step too late -// -// v0.3 - Switched to clearer, faster reload() code from Matthew Bellew -// -// v0.4 - Removed trailing newline in saved generator format to be consistent -// with output format of built-in types -// -// v0.5 - Improved portability by replacing static const int's with enum's and -// clarifying return values in seed(); suggested by Eric Heimburg -// - Removed MAXINT constant; use 0xffffffffUL instead -// -// v0.6 - Eliminated seed overflow when uint32 is larger than 32 bits -// - Changed integer [0,n] generator to give better uniformity -// -// v0.7 - Fixed operator precedence ambiguity in reload() -// - Added access for real numbers in (0,1) and (0,n) -// -// v0.8 - Included time.h header to properly support time_t and clock_t -// -// v1.0 - Revised seeding to match 26 Jan 2002 update of Nishimura and Matsumoto -// - Allowed for seeding with arrays of any length -// - Added access for real numbers in [0,1) with 53-bit resolution -// - Added access for real numbers from normal (Gaussian) distributions -// - Increased overall speed by optimizing twist() -// - Doubled speed of integer [0,n] generation -// - Fixed out-of-range number generation on 64-bit machines -// - Improved portability by substituting literal constants for long enum's -// - Changed license from GNU LGPL to BSD - diff --git a/intern/smoke/intern/Makefile.FFT b/intern/smoke/intern/Makefile.FFT deleted file mode 100644 index 7e9d089cec2..00000000000 --- a/intern/smoke/intern/Makefile.FFT +++ /dev/null @@ -1,22 +0,0 @@ -# common stuff -LDFLAGS_COMMON = -lfftw3 #-lglut -lglu32 -lopengl32 -lz -lpng -CFLAGS_COMMON = -c -Wall -I./ #-I/cygdrive/c/lib/glvu/include -D_WIN32 - -CC = g++ -CFLAGS = ${CFLAGS_COMMON} -O3 -Wno-unused -LDFLAGS = ${LDFLAGS_COMMON} -EXECUTABLE = noiseFFT - -SOURCES = noiseFFT.cpp -OBJECTS = $(SOURCES:.cpp=.o) - -all: $(SOURCES) $(EXECUTABLE) - -$(EXECUTABLE): $(OBJECTS) - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - -.cpp.o: - $(CC) $(CFLAGS) $< -o $@ - -clean: - rm -f *.o $(EXECUTABLE_LOADER) $(EXECUTABLE) diff --git a/intern/smoke/intern/Makefile.cygwin b/intern/smoke/intern/Makefile.cygwin deleted file mode 100644 index 2a747219554..00000000000 --- a/intern/smoke/intern/Makefile.cygwin +++ /dev/null @@ -1,23 +0,0 @@ -CC = g++ -LDFLAGS = -lz -lpng -CFLAGS = -O3 -Wno-unused -c -Wall -I./ -D_WIN32 -EXECUTABLE = FLUID_3D - -SOURCES = main.cpp FLUID_3D.cpp FLUID_3D_SOLVERS.cpp FLUID_3D_STATIC.cpp SPHERE.cpp WTURBULENCE.cpp -OBJECTS = $(SOURCES:.cpp=.o) - -all: $(SOURCES) $(EXECUTABLE) - -$(EXECUTABLE): $(OBJECTS) - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - -.cpp.o: - $(CC) $(CFLAGS) $< -o $@ - -SPHERE.o: SPHERE.h -FLUID_3D.o: FLUID_3D.h FLUID_3D.cpp -FLUID_3D_SOLVERS.o: FLUID_3D.h FLUID_3D_SOLVERS.cpp -main.o: FLUID_3D.h FLUID_3D.cpp FLUID_3D_SOLVERS.cpp - -clean: - rm -f *.o $(EXECUTABLE_LOADER) $(EXECUTABLE) diff --git a/intern/smoke/intern/Makefile.linux b/intern/smoke/intern/Makefile.linux deleted file mode 100644 index 5fbb6e6c3e3..00000000000 --- a/intern/smoke/intern/Makefile.linux +++ /dev/null @@ -1,23 +0,0 @@ -CC = g++ -LDFLAGS = -lz -lpng -fopenmp -lgomp -CFLAGS = -c -Wall -I./ -fopenmp -DPARALLEL=1 -O3 -Wno-unused -EXECUTABLE = FLUID_3D - -SOURCES = main.cpp FLUID_3D.cpp FLUID_3D_SOLVERS.cpp FLUID_3D_STATIC.cpp SPHERE.cpp WTURBULENCE.cpp -OBJECTS = $(SOURCES:.cpp=.o) - -all: $(SOURCES) $(EXECUTABLE) - -$(EXECUTABLE): $(OBJECTS) - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - -.cpp.o: - $(CC) $(CFLAGS) $< -o $@ - -SPHERE.o: SPHERE.h -FLUID_3D.o: FLUID_3D.h FLUID_3D.cpp -FLUID_3D_SOLVERS.o: FLUID_3D.h FLUID_3D_SOLVERS.cpp -main.o: FLUID_3D.h FLUID_3D.cpp FLUID_3D_SOLVERS.cpp - -clean: - rm -f *.o $(EXECUTABLE_LOADER) $(EXECUTABLE) diff --git a/intern/smoke/intern/Makefile.mac b/intern/smoke/intern/Makefile.mac deleted file mode 100644 index d0b7bd38c85..00000000000 --- a/intern/smoke/intern/Makefile.mac +++ /dev/null @@ -1,35 +0,0 @@ -CC = g++ - -# uncomment the other two OPENMP_... lines, if your gcc supports OpenMP -#OPENMP_FLAGS = -fopenmp -DPARALLEL=1 -I/opt/gcc-4.3/usr/local/include -#OPENMPLD_FLAGS = -fopenmp -lgomp -I/opt/gcc-4.3/usr/local/lib -OPENMP_FLAGS = -OPENMPLD_FLAGS = - -# assumes MacPorts libpng installation -PNG_INCLUDE = -I/opt/local/include -PNG_LIBS = -I/opt/local/lib - -LDFLAGS = $(PNG_LIBS)-lz -lpng $(OPENMPLD_FLAGS) -CFLAGS = -c -Wall -I./ $(PNG_INCLUDE) $(OPENMP_FLAGS) -O3 -Wno-unused -EXECUTABLE = FLUID_3D - -SOURCES = main.cpp FLUID_3D.cpp FLUID_3D_SOLVERS.cpp FLUID_3D_STATIC.cpp SPHERE.cpp WTURBULENCE.cpp -OBJECTS = $(SOURCES:.cpp=.o) - -all: $(SOURCES) $(EXECUTABLE) - -$(EXECUTABLE): $(OBJECTS) - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - -.cpp.o: - $(CC) $(CFLAGS) $< -o $@ - -SPHERE.o: SPHERE.h -FLUID_3D.o: FLUID_3D.h FLUID_3D.cpp -FLUID_3D_SOLVERS.o: FLUID_3D.h FLUID_3D_SOLVERS.cpp -main.o: FLUID_3D.h FLUID_3D.cpp FLUID_3D_SOLVERS.cpp - -clean: - rm -f *.o $(EXECUTABLE_LOADER) $(EXECUTABLE) - diff --git a/intern/smoke/intern/OBSTACLE.h b/intern/smoke/intern/OBSTACLE.h deleted file mode 100644 index a23b484e7c1..00000000000 --- a/intern/smoke/intern/OBSTACLE.h +++ /dev/null @@ -1,46 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// OBSTACLE.h: interface for the OBSTACLE class. -// -////////////////////////////////////////////////////////////////////// - -#ifndef OBSTACLE_H -#define OBSTACLE_H - -enum OBSTACLE_FLAGS { - EMPTY = 0, - /* 1 is used to flag an object cell */ - MARCHED = 2, - RETIRED = 4, - ANIMATED = 8, -}; - -class OBSTACLE -{ -public: - OBSTACLE() {}; - virtual ~OBSTACLE() {}; - - virtual bool inside(float x, float y, float z) = 0; -}; - -#endif diff --git a/intern/smoke/intern/SPHERE.cpp b/intern/smoke/intern/SPHERE.cpp deleted file mode 100644 index 914ed5666c3..00000000000 --- a/intern/smoke/intern/SPHERE.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// SPHERE.cpp: implementation of the SPHERE class. -// -////////////////////////////////////////////////////////////////////// - -#include "SPHERE.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -SPHERE::SPHERE(float x, float y, float z, float radius) : - _radius(radius) -{ - _center[0] = x; - _center[1] = y; - _center[2] = z; -} - -SPHERE::~SPHERE() -{ - -} - -bool SPHERE::inside(float x, float y, float z) -{ - float translate[] = {x - _center[0], y - _center[1], z - _center[2]}; - float magnitude = translate[0] * translate[0] + - translate[1] * translate[1] + - translate[2] * translate[2]; - - return (magnitude < _radius * _radius) ? true : false; -} diff --git a/intern/smoke/intern/SPHERE.h b/intern/smoke/intern/SPHERE.h deleted file mode 100644 index 6fdc93a5ee9..00000000000 --- a/intern/smoke/intern/SPHERE.h +++ /dev/null @@ -1,44 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// SPHERE.h: interface for the SPHERE class. -// -////////////////////////////////////////////////////////////////////// - -#ifndef SPHERE_H -#define SPHERE_H - -#include "OBSTACLE.h" - -class SPHERE : public OBSTACLE -{ -public: - SPHERE(float x, float y, float z, float radius); - virtual ~SPHERE(); - - bool inside(float x, float y, float z); - -private: - float _center[3]; - float _radius; -}; - -#endif diff --git a/intern/smoke/intern/VEC3.h b/intern/smoke/intern/VEC3.h deleted file mode 100644 index 3672da74196..00000000000 --- a/intern/smoke/intern/VEC3.h +++ /dev/null @@ -1,991 +0,0 @@ -/** \file - * \ingroup smoke - */ -/****************************************************************************** - * Copyright 2007 Nils Thuerey - * Basic vector class - *****************************************************************************/ -#ifndef BASICVECTOR_H -#define BASICVECTOR_H - -#include -#include -#include -#include -#include - -// use which fp-precision? 1=float, 2=double -#ifndef FLOATINGPOINT_PRECISION -#if DDF_DEBUG==1 -#define FLOATINGPOINT_PRECISION 2 -#else // DDF_DEBUG==1 -#define FLOATINGPOINT_PRECISION 1 -#endif // DDF_DEBUG==1 -#endif - -// VECTOR_EPSILON is the minimal vector length -// In order to be able to discriminate floating point values near zero, and -// to be sure not to fail a comparison because of roundoff errors, use this -// value as a threshold. - -#if FLOATINGPOINT_PRECISION==1 -typedef float Real; -#define FP_REAL_MAX __FLT_MAX__ -#define VECTOR_EPSILON (1e-5f) -#else -typedef double Real; -#define FP_REAL_MAX __DBL_MAX__ -#define VECTOR_EPSILON (1e-10) -#endif - - -// hardcoded limits for now... -// for e.g. MSVC compiler... -// some of these defines can be needed -// for linux systems as well (e.g. FLT_MAX) -#ifndef __FLT_MAX__ -# ifdef FLT_MAX // try to use it instead -# define __FLT_MAX__ FLT_MAX -# else // FLT_MAX -# define __FLT_MAX__ 3.402823466e+38f -# endif // FLT_MAX -#endif // __FLT_MAX__ -#ifndef __DBL_MAX__ -# ifdef DBL_MAX // try to use it instead -# define __DBL_MAX__ DBL_MAX -# else // DBL_MAX -# define __DBL_MAX__ 1.7976931348623158e+308 -# endif // DBL_MAX -#endif // __DBL_MAX__ - -#ifndef FLT_MAX -#define FLT_MAX __FLT_MAX__ -#endif - -#ifndef DBL_MAX -#define DBL_MAX __DBL_MAX__ -#endif - -#ifndef M_PI -# define M_PI 3.1415926536 -# define M_E 2.7182818284 -#endif - - - -namespace BasicVector { - - -// basic inlined vector class -template -class Vector3Dim -{ -public: - // Constructor - inline Vector3Dim(); - // Copy-Constructor - inline Vector3Dim(const Vector3Dim &v ); - inline Vector3Dim(const float *); - inline Vector3Dim(const double *); - // construct a vector from one Scalar - inline Vector3Dim(Scalar); - // construct a vector from three Scalars - inline Vector3Dim(Scalar, Scalar, Scalar); - - // get address of array for OpenGL - Scalar *getAddress() { return value; } - - // Assignment operator - inline const Vector3Dim& operator= (const Vector3Dim& v); - // Assignment operator - inline const Vector3Dim& operator= (Scalar s); - // Assign and add operator - inline const Vector3Dim& operator+= (const Vector3Dim& v); - // Assign and add operator - inline const Vector3Dim& operator+= (Scalar s); - // Assign and sub operator - inline const Vector3Dim& operator-= (const Vector3Dim& v); - // Assign and sub operator - inline const Vector3Dim& operator-= (Scalar s); - // Assign and mult operator - inline const Vector3Dim& operator*= (const Vector3Dim& v); - // Assign and mult operator - inline const Vector3Dim& operator*= (Scalar s); - // Assign and div operator - inline const Vector3Dim& operator/= (const Vector3Dim& v); - // Assign and div operator - inline const Vector3Dim& operator/= (Scalar s); - - - // unary operator - inline Vector3Dim operator- () const; - - // binary operator add - inline Vector3Dim operator+ (const Vector3Dim&) const; - // binary operator add - inline Vector3Dim operator+ (Scalar) const; - // binary operator sub - inline Vector3Dim operator- (const Vector3Dim&) const; - // binary operator sub - inline Vector3Dim operator- (Scalar) const; - // binary operator mult - inline Vector3Dim operator* (const Vector3Dim&) const; - // binary operator mult - inline Vector3Dim operator* (Scalar) const; - // binary operator div - inline Vector3Dim operator/ (const Vector3Dim&) const; - // binary operator div - inline Vector3Dim operator/ (Scalar) const; - - // Projection normal to a vector - inline Vector3Dim getOrthogonalntlVector3Dim() const; - // Project into a plane - inline const Vector3Dim& projectNormalTo(const Vector3Dim &v); - - // minimize - inline const Vector3Dim &minimize(const Vector3Dim &); - // maximize - inline const Vector3Dim &maximize(const Vector3Dim &); - - // access operator - inline Scalar& operator[](unsigned int i); - // access operator - inline const Scalar& operator[](unsigned int i) const; - - //! actual values - union { - struct { - Scalar value[3]; - }; - struct { - Scalar x; - Scalar y; - Scalar z; - }; - struct { - Scalar X; - Scalar Y; - Scalar Z; - }; - }; -protected: - -}; - - - - - -//------------------------------------------------------------------------------ -// VECTOR inline FUNCTIONS -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Constructor. - */ -template -inline Vector3Dim::Vector3Dim( void ) -{ - value[0] = value[1] = value[2] = 0; -} - - - -/************************************************************************* - Copy-Constructor. - */ -template -inline Vector3Dim::Vector3Dim( const Vector3Dim &v ) -{ - value[0] = v.value[0]; - value[1] = v.value[1]; - value[2] = v.value[2]; -} -template -inline Vector3Dim::Vector3Dim( const float *fvalue) -{ - value[0] = (Scalar)fvalue[0]; - value[1] = (Scalar)fvalue[1]; - value[2] = (Scalar)fvalue[2]; -} -template -inline Vector3Dim::Vector3Dim( const double *fvalue) -{ - value[0] = (Scalar)fvalue[0]; - value[1] = (Scalar)fvalue[1]; - value[2] = (Scalar)fvalue[2]; -} - - - -/************************************************************************* - Constructor for a vector from a single Scalar. All components of - the vector get the same value. - \param s The value to set - \return The new vector - */ -template -inline Vector3Dim::Vector3Dim(Scalar s ) -{ - value[0]= s; - value[1]= s; - value[2]= s; -} - - -/************************************************************************* - Constructor for a vector from three Scalars. - \param s1 The value for the first vector component - \param s2 The value for the second vector component - \param s3 The value for the third vector component - \return The new vector - */ -template -inline Vector3Dim::Vector3Dim(Scalar s1, Scalar s2, Scalar s3) -{ - value[0]= s1; - value[1]= s2; - value[2]= s3; -} - - - -/************************************************************************* - Copy a Vector3Dim componentwise. - \param v vector with values to be copied - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator=( const Vector3Dim &v ) -{ - value[0] = v.value[0]; - value[1] = v.value[1]; - value[2] = v.value[2]; - return *this; -} - - -/************************************************************************* - Copy a Scalar to each component. - \param s The value to copy - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator=(Scalar s) -{ - value[0] = s; - value[1] = s; - value[2] = s; - return *this; -} - - -/************************************************************************* - Add another Vector3Dim componentwise. - \param v vector with values to be added - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator+=( const Vector3Dim &v ) -{ - value[0] += v.value[0]; - value[1] += v.value[1]; - value[2] += v.value[2]; - return *this; -} - - -/************************************************************************* - Add a Scalar value to each component. - \param s Value to add - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator+=(Scalar s) -{ - value[0] += s; - value[1] += s; - value[2] += s; - return *this; -} - - -/************************************************************************* - Subtract another vector componentwise. - \param v vector of values to subtract - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator-=( const Vector3Dim &v ) -{ - value[0] -= v.value[0]; - value[1] -= v.value[1]; - value[2] -= v.value[2]; - return *this; -} - - -/************************************************************************* - Subtract a Scalar value from each component. - \param s Value to subtract - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator-=(Scalar s) -{ - value[0]-= s; - value[1]-= s; - value[2]-= s; - return *this; -} - - -/************************************************************************* - Multiply with another vector componentwise. - \param v vector of values to multiply with - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator*=( const Vector3Dim &v ) -{ - value[0] *= v.value[0]; - value[1] *= v.value[1]; - value[2] *= v.value[2]; - return *this; -} - - -/************************************************************************* - Multiply each component with a Scalar value. - \param s Value to multiply with - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator*=(Scalar s) -{ - value[0] *= s; - value[1] *= s; - value[2] *= s; - return *this; -} - - -/************************************************************************* - Divide by another Vector3Dim componentwise. - \param v vector of values to divide by - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator/=( const Vector3Dim &v ) -{ - value[0] /= v.value[0]; - value[1] /= v.value[1]; - value[2] /= v.value[2]; - return *this; -} - - -/************************************************************************* - Divide each component by a Scalar value. - \param s Value to divide by - \return Reference to self - */ -template -inline const Vector3Dim& -Vector3Dim::operator/=(Scalar s) -{ - value[0] /= s; - value[1] /= s; - value[2] /= s; - return *this; -} - - -//------------------------------------------------------------------------------ -// unary operators -//------------------------------------------------------------------------------ - - -/************************************************************************* - Build componentwise the negative this vector. - \return The new (negative) vector - */ -template -inline Vector3Dim -Vector3Dim::operator-() const -{ - return Vector3Dim(-value[0], -value[1], -value[2]); -} - - - -//------------------------------------------------------------------------------ -// binary operators -//------------------------------------------------------------------------------ - - -/************************************************************************* - Build a vector with another vector added componentwise. - \param v The second vector to add - \return The sum vector - */ -template -inline Vector3Dim -Vector3Dim::operator+( const Vector3Dim &v ) const -{ - return Vector3Dim(value[0]+v.value[0], - value[1]+v.value[1], - value[2]+v.value[2]); -} - - -/************************************************************************* - Build a vector with a Scalar value added to each component. - \param s The Scalar value to add - \return The sum vector - */ -template -inline Vector3Dim -Vector3Dim::operator+(Scalar s) const -{ - return Vector3Dim(value[0]+s, - value[1]+s, - value[2]+s); -} - - -/************************************************************************* - Build a vector with another vector subtracted componentwise. - \param v The second vector to subtract - \return The difference vector - */ -template -inline Vector3Dim -Vector3Dim::operator-( const Vector3Dim &v ) const -{ - return Vector3Dim(value[0]-v.value[0], - value[1]-v.value[1], - value[2]-v.value[2]); -} - - -/************************************************************************* - Build a vector with a Scalar value subtracted componentwise. - \param s The Scalar value to subtract - \return The difference vector - */ -template -inline Vector3Dim -Vector3Dim::operator-(Scalar s ) const -{ - return Vector3Dim(value[0]-s, - value[1]-s, - value[2]-s); -} - - - -/************************************************************************* - Build a vector with another vector multiplied by componentwise. - \param v The second vector to muliply with - \return The product vector - */ -template -inline Vector3Dim -Vector3Dim::operator*( const Vector3Dim& v) const -{ - return Vector3Dim(value[0]*v.value[0], - value[1]*v.value[1], - value[2]*v.value[2]); -} - - -/************************************************************************* - Build a Vector3Dim with a Scalar value multiplied to each component. - \param s The Scalar value to multiply with - \return The product vector - */ -template -inline Vector3Dim -Vector3Dim::operator*(Scalar s) const -{ - return Vector3Dim(value[0]*s, value[1]*s, value[2]*s); -} - - -/************************************************************************* - Build a vector divided componentwise by another vector. - \param v The second vector to divide by - \return The ratio vector - */ -template -inline Vector3Dim -Vector3Dim::operator/(const Vector3Dim& v) const -{ - return Vector3Dim(value[0]/v.value[0], - value[1]/v.value[1], - value[2]/v.value[2]); -} - - - -/************************************************************************* - Build a vector divided componentwise by a Scalar value. - \param s The Scalar value to divide by - \return The ratio vector - */ -template -inline Vector3Dim -Vector3Dim::operator/(Scalar s) const -{ - return Vector3Dim(value[0]/s, - value[1]/s, - value[2]/s); -} - - - - - -/************************************************************************* - Get a particular component of the vector. - \param i Number of Scalar to get - \return Reference to the component - */ -template -inline Scalar& -Vector3Dim::operator[]( unsigned int i ) -{ - return value[i]; -} - - -/************************************************************************* - Get a particular component of a constant vector. - \param i Number of Scalar to get - \return Reference to the component - */ -template -inline const Scalar& -Vector3Dim::operator[]( unsigned int i ) const -{ - return value[i]; -} - - - -//------------------------------------------------------------------------------ -// BLITZ compatibility functions -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Compute the scalar product with another vector. - \param v The second vector to work with - \return The value of the scalar product - */ -template -inline Scalar dot(const Vector3Dim &t, const Vector3Dim &v ) -{ - //return t.value[0]*v.value[0] + t.value[1]*v.value[1] + t.value[2]*v.value[2]; - return ((t[0]*v[0]) + (t[1]*v[1]) + (t[2]*v[2])); -} - - -/************************************************************************* - Calculate the cross product of this and another vector - */ -template -inline Vector3Dim cross(const Vector3Dim &t, const Vector3Dim &v) -{ - Vector3Dim cp( - ((t[1]*v[2]) - (t[2]*v[1])), - ((t[2]*v[0]) - (t[0]*v[2])), - ((t[0]*v[1]) - (t[1]*v[0])) ); - return cp; -} - - - - -/************************************************************************* - Compute a vector that is orthonormal to self. Nothing else can be assumed - for the direction of the new vector. - \return The orthonormal vector - */ -template -Vector3Dim -Vector3Dim::getOrthogonalntlVector3Dim() const -{ - // Determine the component with max. absolute value - int max= (fabs(value[0]) > fabs(value[1])) ? 0 : 1; - max= (fabs(value[max]) > fabs(value[2])) ? max : 2; - - /************************************************************************* - Choose another axis than the one with max. component and project - orthogonal to self - */ - Vector3Dim vec(0.0); - vec[(max+1)%3]= 1; - vec.normalize(); - vec.projectNormalTo(this->getNormalized()); - return vec; -} - - -/************************************************************************* - Projects the vector into a plane normal to the given vector, which must - have unit length. Self is modified. - \param v The plane normal - \return The projected vector - */ -template -inline const Vector3Dim& -Vector3Dim::projectNormalTo(const Vector3Dim &v) -{ - Scalar sprod = dot(*this,v); - value[0]= value[0] - v.value[0] * sprod; - value[1]= value[1] - v.value[1] * sprod; - value[2]= value[2] - v.value[2] * sprod; - return *this; -} - - - -//------------------------------------------------------------------------------ -// Other helper functions -//------------------------------------------------------------------------------ - - - -/************************************************************************* - Minimize the vector, i.e. set each entry of the vector to the minimum - of both values. - \param pnt The second vector to compare with - \return Reference to the modified self - */ -template -inline const Vector3Dim & -Vector3Dim::minimize(const Vector3Dim &pnt) -{ - for (unsigned int i = 0; i < 3; i++) - value[i] = MIN(value[i],pnt[i]); - return *this; -} - - - -/************************************************************************* - Maximize the vector, i.e. set each entry of the vector to the maximum - of both values. - \param pnt The second vector to compare with - \return Reference to the modified self - */ -template -inline const Vector3Dim & -Vector3Dim::maximize(const Vector3Dim &pnt) -{ - for (unsigned int i = 0; i < 3; i++) - value[i] = MAX(value[i],pnt[i]); - return *this; -} - - - - - - -/************************************************************************/ -// HELPER FUNCTIONS, independent of implementation -/************************************************************************/ - -#define VECTOR_TYPE Vector3Dim - - -/************************************************************************* - Compute the length (norm) of the vector. - \return The value of the norm - */ -template -inline Scalar norm( const VECTOR_TYPE &v) -{ - Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - return (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) ? 1. : sqrt(l); -} - -// for e.g. min max operator -inline Real normHelper(const Vector3Dim &v) { - return norm(v); -} -inline Real normHelper(const Real &v) { - return (0.0f < v) ? v : -v ; -} -inline Real normHelper(const int &v) { - return (0 < v) ? (Real)(v) : (Real)(-v) ; -} - - -/************************************************************************* - Same as getNorm but doesnt sqrt - */ -template -inline Scalar normNoSqrt( const VECTOR_TYPE &v) -{ - return v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; -} - - -/************************************************************************* - Compute a normalized vector based on this vector. - \return The new normalized vector - */ -template -inline VECTOR_TYPE getNormalized( const VECTOR_TYPE &v) -{ - Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - if (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) - return v; /* normalized "enough"... */ - else if (l > VECTOR_EPSILON*VECTOR_EPSILON) - { - Scalar fac = 1./sqrt(l); - return VECTOR_TYPE(v[0]*fac, v[1]*fac, v[2]*fac); - } - else - return VECTOR_TYPE((Scalar)0); -} - - -/************************************************************************* - Compute the norm of the vector and normalize it. - \return The value of the norm - */ -template -inline Scalar normalize( VECTOR_TYPE &v) -{ - Scalar norm; - Scalar l = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - if (fabs(l-1.) < VECTOR_EPSILON*VECTOR_EPSILON) { - norm = 1.; - } else if (l > VECTOR_EPSILON*VECTOR_EPSILON) { - norm = sqrt(l); - Scalar fac = 1./norm; - v[0] *= fac; - v[1] *= fac; - v[2] *= fac; - } else { - v[0]= v[1]= v[2]= 0; - norm = 0.; - } - return (Scalar)norm; -} - - -/************************************************************************* - Compute a vector, that is self (as an incoming - vector) reflected at a surface with a distinct normal vector. Note - that the normal is reversed, if the scalar product with it is positive. - \param n The surface normal - \return The new reflected vector - */ -template -inline VECTOR_TYPE reflectVector(const VECTOR_TYPE &t, const VECTOR_TYPE &n) -{ - VECTOR_TYPE nn= (dot(t, n) > 0.0) ? (n*-1.0) : n; - return ( t - nn * (2.0 * dot(nn, t)) ); -} - - - -/************************************************************************* - * My own refraction calculation - * Taken from Glassner's book, section 5.2 (Heckberts method) - */ -template -inline VECTOR_TYPE refractVector(const VECTOR_TYPE &t, const VECTOR_TYPE &normal, Scalar nt, Scalar nair, int &refRefl) -{ - Scalar eta = nair / nt; - Scalar n = -dot(t, normal); - Scalar tt = 1.0 + eta*eta* (n*n-1.0); - if(tt<0.0) { - // we have total reflection! - refRefl = 1; - } else { - // normal reflection - tt = eta*n - sqrt(tt); - return( t*eta + normal*tt ); - } - return t; -} - - -/************************************************************************* - Test two ntlVector3Dims for equality based on the equality of their - values within a small threshold. - \param c The second vector to compare - \return TRUE if both are equal - \sa getEpsilon() - */ -template -inline bool equal(const VECTOR_TYPE &v, const VECTOR_TYPE &c) -{ - return (ABS(v[0]-c[0]) + - ABS(v[1]-c[1]) + - ABS(v[2]-c[2]) < VECTOR_EPSILON); -} - - -/************************************************************************* - * Assume this vector is an RGB color, and convert it to HSV - */ -template -inline void rgbToHsv( VECTOR_TYPE &V ) -{ - Scalar h=0,s=0,v=0; - Scalar maxrgb, minrgb, delta; - // convert to hsv... - maxrgb = V[0]; - int maxindex = 1; - if(V[2] > maxrgb){ maxrgb = V[2]; maxindex = 2; } - if(V[1] > maxrgb){ maxrgb = V[1]; maxindex = 3; } - minrgb = V[0]; - if(V[2] < minrgb) minrgb = V[2]; - if(V[1] < minrgb) minrgb = V[1]; - - v = maxrgb; - delta = maxrgb-minrgb; - - if(maxrgb > 0) s = delta/maxrgb; - else s = 0; - - h = 0; - if(s > 0) { - if(maxindex == 1) { - h = ((V[1]-V[2])/delta) + 0.0; } - if(maxindex == 2) { - h = ((V[2]-V[0])/delta) + 2.0; } - if(maxindex == 3) { - h = ((V[0]-V[1])/delta) + 4.0; } - h *= 60.0; - if(h < 0.0) h += 360.0; - } - - V[0] = h; - V[1] = s; - V[2] = v; -} - -/************************************************************************* - * Assume this vector is HSV and convert to RGB - */ -template -inline void hsvToRgb( VECTOR_TYPE &V ) -{ - Scalar h = V[0], s = V[1], v = V[2]; - Scalar r=0,g=0,b=0; - Scalar p,q,t, fracth; - int floorh; - // ...and back to rgb - if(s == 0) { - r = g = b = v; } - else { - h /= 60.0; - floorh = (int)h; - fracth = h - floorh; - p = v * (1.0 - s); - q = v * (1.0 - (s * fracth)); - t = v * (1.0 - (s * (1.0 - fracth))); - switch (floorh) { - case 0: r = v; g = t; b = p; break; - case 1: r = q; g = v; b = p; break; - case 2: r = p; g = v; b = t; break; - case 3: r = p; g = q; b = v; break; - case 4: r = t; g = p; b = v; break; - case 5: r = v; g = p; b = q; break; - } - } - - V[0] = r; - V[1] = g; - V[2] = b; -} - -//------------------------------------------------------------------------------ -// STREAM FUNCTIONS -//------------------------------------------------------------------------------ - - - -//! global string for formatting vector output in utilities.cpp -//extern const char *globVecFormatStr; -#if 0 -static const char *globVecFormatStr = "[%6.4f,%6.4f,%6.4f]"; -#endif - -/************************************************************************* - Outputs the object in human readable form using the format - [x,y,z] - */ -template -std::ostream& -operator<<( std::ostream& os, const BasicVector::Vector3Dim& i ) -{ -#if 0 - char buf[256]; -# if _WIN32 - sprintf(buf,globVecFormatStr, (double)i[0],(double)i[1],(double)i[2]); -# else - snprintf(buf,256,globVecFormatStr, (double)i[0],(double)i[1],(double)i[2]); -# endif - os << std::string(buf); -#else - (void)i; /* Ignored. */ -#endif - return os; -} - - -/************************************************************************* - Reads the contents of the object from a stream using the same format - as the output operator. - */ -template -std::istream& -operator>>( std::istream& is, BasicVector::Vector3Dim& i ) -{ - char c; - char dummy[3]; - is >> c >> i[0] >> dummy >> i[1] >> dummy >> i[2] >> c; - return is; -} - - -/**************************************************************************/ -// typedefs! -/**************************************************************************/ - -/* get minimal vector length value that can be discriminated. */ -inline Real getVecEpsilon() { return (Real)VECTOR_EPSILON; } - -// a 3D integer vector -typedef Vector3Dim Vec3Int; - -// a 3D vector -typedef Vector3Dim Vec3; - - -}; // namespace - - -#endif /* BASICVECTOR_H */ diff --git a/intern/smoke/intern/WAVELET_NOISE.h b/intern/smoke/intern/WAVELET_NOISE.h deleted file mode 100644 index 13ffe1e9697..00000000000 --- a/intern/smoke/intern/WAVELET_NOISE.h +++ /dev/null @@ -1,519 +0,0 @@ -/** \file - * \ingroup smoke - */ -////////////////////////////////////////////////////////////////////// -// This file is part of Wavelet Turbulence. -// -// Wavelet Turbulence 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 3 of the License, or -// (at your option) any later version. -// -// Wavelet Turbulence is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Wavelet Turbulence. If not, see . -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -////////////////////////////////////////////////////////////////////////////////////////// -// Wavelet noise functions -// -// This code is based on the C code provided in the appendices of: -// -// @article{1073264, -// author = {Robert L. Cook and Tony DeRose}, -// title = {Wavelet noise}, -// journal = {ACM Trans. Graph.}, -// volume = {24}, -// number = {3}, -// year = {2005}, -// issn = {0730-0301}, -// pages = {803--811}, -// doi = {http://doi.acm.org/10.1145/1073204.1073264}, -// publisher = {ACM}, -// address = {New York, NY, USA}, -// } -// -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef WAVELET_NOISE_H -#define WAVELET_NOISE_H - -#include - -#include - -#ifdef WIN32 -#include -#define isnan _isnan -#endif - -// Tile file header, update revision upon any change done to the noise generator -static const char tilefile_headerstring[] = "Noise Tile File rev. "; -static const char tilefile_revision[] = "001"; - -#define NOISE_TILE_SIZE 128 -static const int noiseTileSize = NOISE_TILE_SIZE; - -// warning - noiseTileSize has to be 128^3! -#define modFast128(x) ((x) & 127) -#define modFast64(x) ((x) & 63) -#define DOWNCOEFFS 0.000334f,-0.001528f, 0.000410f, 0.003545f,-0.000938f,-0.008233f, 0.002172f, 0.019120f, \ - -0.005040f,-0.044412f, 0.011655f, 0.103311f,-0.025936f,-0.243780f, 0.033979f, 0.655340f, \ - 0.655340f, 0.033979f,-0.243780f,-0.025936f, 0.103311f, 0.011655f,-0.044412f,-0.005040f, \ - 0.019120f, 0.002172f,-0.008233f,-0.000938f, 0.003546f, 0.000410f,-0.001528f, 0.000334f - -////////////////////////////////////////////////////////////////////////////////////////// -// Wavelet downsampling -- periodic boundary conditions -////////////////////////////////////////////////////////////////////////////////////////// -static void downsampleX(float *from, float *to, int n){ - // if these values are not local incorrect results are generated - float downCoeffs[32] = { DOWNCOEFFS }; - const float *a = &downCoeffs[16]; - for (int i = 0; i < n / 2; i++) { - to[i] = 0; - for (int k = 2 * i - 16; k < 2 * i + 16; k++) - to[i] += a[k - 2 * i] * from[modFast128(k)]; - } -} -static void downsampleY(float *from, float *to, int n){ - // if these values are not local incorrect results are generated - float downCoeffs[32] = { DOWNCOEFFS }; - const float *a = &downCoeffs[16]; - for (int i = 0; i < n / 2; i++) { - to[i * n] = 0; - for (int k = 2 * i - 16; k < 2 * i + 16; k++) - to[i * n] += a[k - 2 * i] * from[modFast128(k) * n]; - } -} -static void downsampleZ(float *from, float *to, int n){ - // if these values are not local incorrect results are generated - float downCoeffs[32] = { DOWNCOEFFS }; - const float *a = &downCoeffs[16]; - for (int i = 0; i < n / 2; i++) { - to[i * n * n] = 0; - for (int k = 2 * i - 16; k < 2 * i + 16; k++) - to[i * n * n] += a[k - 2 * i] * from[modFast128(k) * n * n]; - } -} - -////////////////////////////////////////////////////////////////////////////////////////// -// Wavelet downsampling -- Neumann boundary conditions -////////////////////////////////////////////////////////////////////////////////////////// -static void downsampleNeumann(const float *from, float *to, int n, int stride) -{ - // if these values are not local incorrect results are generated - float downCoeffs[32] = { DOWNCOEFFS }; - const float *const aCoCenter= &downCoeffs[16]; - for (int i = 0; i <= n / 2; i++) { - to[i * stride] = 0; - for (int k = 2 * i - 16; k < 2 * i + 16; k++) { - // handle boundary - float fromval; - if (k < 0) { - fromval = from[0]; - } else if(k > n - 1) { - fromval = from[(n - 1) * stride]; - } else { - fromval = from[k * stride]; - } - to[i * stride] += aCoCenter[k - 2 * i] * fromval; - } - } -} -static void downsampleXNeumann(float* to, const float* from, int sx,int sy, int sz) { - for (int iy = 0; iy < sy; iy++) - for (int iz = 0; iz < sz; iz++) { - const int i = iy * sx + iz*sx*sy; - downsampleNeumann(&from[i], &to[i], sx, 1); - } -} -static void downsampleYNeumann(float* to, const float* from, int sx,int sy, int sz) { - for (int ix = 0; ix < sx; ix++) - for (int iz = 0; iz < sz; iz++) { - const int i = ix + iz*sx*sy; - downsampleNeumann(&from[i], &to[i], sy, sx); - } -} -static void downsampleZNeumann(float* to, const float* from, int sx,int sy, int sz) { - for (int ix = 0; ix < sx; ix++) - for (int iy = 0; iy < sy; iy++) { - const int i = ix + iy*sx; - downsampleNeumann(&from[i], &to[i], sz, sx*sy); - } -} - -////////////////////////////////////////////////////////////////////////////////////////// -// Wavelet upsampling - periodic boundary conditions -////////////////////////////////////////////////////////////////////////////////////////// -static float _upCoeffs[4] = {0.25f, 0.75f, 0.75f, 0.25f}; -static void upsampleX(float *from, float *to, int n) { - const float *p = &_upCoeffs[2]; - - for (int i = 0; i < n; i++) { - to[i] = 0; - for (int k = i / 2; k <= i / 2 + 1; k++) - to[i] += p[i - 2 * k] * from[modFast64(k)]; - } -} -static void upsampleY(float *from, float *to, int n) { - const float *p = &_upCoeffs[2]; - - for (int i = 0; i < n; i++) { - to[i * n] = 0; - for (int k = i / 2; k <= i / 2 + 1; k++) - to[i * n] += p[i - 2 * k] * from[modFast64(k) * n]; - } -} -static void upsampleZ(float *from, float *to, int n) { - const float *p = &_upCoeffs[2]; - - for (int i = 0; i < n; i++) { - to[i * n * n] = 0; - for (int k = i / 2; k <= i / 2 + 1; k++) - to[i * n * n] += p[i - 2 * k] * from[modFast64(k) * n * n]; - } -} - -////////////////////////////////////////////////////////////////////////////////////////// -// Wavelet upsampling - Neumann boundary conditions -////////////////////////////////////////////////////////////////////////////////////////// -static void upsampleNeumann(const float *from, float *to, int n, int stride) { - static const float *const pCoCenter = &_upCoeffs[2]; - for (int i = 0; i < n; i++) { - to[i * stride] = 0; - for (int k = i / 2; k <= i / 2 + 1; k++) { - float fromval; - if(k>n/2) { - fromval = from[(n/2) * stride]; - } else { - fromval = from[k * stride]; - } - to[i * stride] += pCoCenter[i - 2 * k] * fromval; - } - } -} -static void upsampleXNeumann(float* to, const float* from, int sx, int sy, int sz) { - for (int iy = 0; iy < sy; iy++) - for (int iz = 0; iz < sz; iz++) { - const int i = iy * sx + iz*sx*sy; - upsampleNeumann(&from[i], &to[i], sx, 1); - } -} -static void upsampleYNeumann(float* to, const float* from, int sx, int sy, int sz) { - for (int ix = 0; ix < sx; ix++) - for (int iz = 0; iz < sz; iz++) { - const int i = ix + iz*sx*sy; - upsampleNeumann(&from[i], &to[i], sy, sx); - } -} -static void upsampleZNeumann(float* to, const float* from, int sx, int sy, int sz) { - for (int ix = 0; ix < sx; ix++) - for (int iy = 0; iy < sy; iy++) { - const int i = ix + iy*sx; - upsampleNeumann(&from[i], &to[i], sz, sx*sy); - } -} - - -////////////////////////////////////////////////////////////////////////////////////////// -// load in an existing noise tile -////////////////////////////////////////////////////////////////////////////////////////// -static bool loadTile(float* const noiseTileData, std::string filename) -{ - FILE* file; - char headerbuffer[64]; - size_t headerlen; - size_t bread; - int endiantest = 1; - char endianness; - - file = fopen(filename.c_str(), "rb"); - - if (file == NULL) { - printf("loadTile: No noise tile '%s' found.\n", filename.c_str()); - return false; - } - - //Check header - headerlen = strlen(tilefile_headerstring) + strlen(tilefile_revision) + 2; - bread = fread((void*)headerbuffer, 1, headerlen, file); - if (*((unsigned char*)&endiantest) == 1) - endianness = 'L'; - else - endianness = 'B'; - if ((bread != headerlen) - || (strncmp(headerbuffer, tilefile_headerstring, strlen(tilefile_headerstring))) - || (strncmp(headerbuffer+ strlen(tilefile_headerstring), tilefile_revision, strlen(tilefile_revision))) - || (headerbuffer[headerlen-2] != endianness) - || (headerbuffer[headerlen-1] != (char)((char)sizeof(long)+'0'))) - { - printf("loadTile : Noise tile '%s' was generated on an incompatible platform.\n",filename.c_str()); - fclose(file); - return false; - } - - // dimensions - size_t gridSize = noiseTileSize * noiseTileSize * noiseTileSize; - - // noiseTileData memory is managed by caller - bread = fread((void*)noiseTileData, sizeof(float), gridSize, file); - fclose(file); - printf("Noise tile file '%s' loaded.\n", filename.c_str()); - - if (bread != gridSize) { - printf("loadTile: Noise tile '%s' is wrong size %d.\n", filename.c_str(), (int)bread); - return false; - } - - // check for invalid nan tile data that could be generated. bug is now - // fixed, but invalid files may still hang around - if (isnan(noiseTileData[0])) { - printf("loadTile: Noise tile '%s' contains nan values.\n", filename.c_str()); - return false; - } - - return true; -} - -////////////////////////////////////////////////////////////////////////////////////////// -// write out an existing noise tile -////////////////////////////////////////////////////////////////////////////////////////// -static void saveTile(float* const noiseTileData, std::string filename) -{ - FILE* file; - file = fopen(filename.c_str(), "wb"); - int endiantest=1; - char longsize; - - if (file == NULL) { - printf("saveTile: Noise tile '%s' could not be saved.\n", filename.c_str()); - return; - } - - //Write file header - fwrite(tilefile_headerstring, strlen(tilefile_headerstring), 1, file); - fwrite(tilefile_revision, strlen(tilefile_revision), 1, file); - //Endianness - if (*((unsigned char*)&endiantest) == 1) - fwrite("L", 1, 1, file); //Little endian - else - fwrite("B",1,1,file); //Big endian - //32/64bit - longsize = (char)sizeof(long)+'0'; - fwrite(&longsize, 1, 1, file); - - - fwrite((void*)noiseTileData, sizeof(float), noiseTileSize * noiseTileSize * noiseTileSize, file); - fclose(file); - - printf("saveTile: Noise tile file '%s' saved.\n", filename.c_str()); -} - -////////////////////////////////////////////////////////////////////////////////////////// -// create a new noise tile if necessary -////////////////////////////////////////////////////////////////////////////////////////// -static void generateTile_WAVELET(float* const noiseTileData, std::string filename) { - // if a tile already exists, just use that - if (loadTile(noiseTileData, filename)) return; - - const int n = noiseTileSize; - const int n3 = n*n*n; - std::cout <<"Generating new 3d noise tile size="<. -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// WTURBULENCE handling -/////////////////////////////////////////////////////////////////////////////////// -// Parallelized turbulence even further. TNT matrix library functions -// rewritten to improve performance. -// - MiikaH -////////////////////////////////////////////////////////////////////// - -#include "WTURBULENCE.h" -#include "INTERPOLATE.h" -#include "IMAGE.h" -#include -#include "WAVELET_NOISE.h" -#include "FFT_NOISE.h" -#include "EIGENVALUE_HELPER.h" -#include "LU_HELPER.h" -#include "SPHERE.h" -#include -#include - -// needed to access static advection functions -#include "FLUID_3D.h" - -#if PARALLEL==1 -#include -#endif // PARALLEL - -// 2^ {-5/6} -static const float persistence = 0.56123f; - -////////////////////////////////////////////////////////////////////// -// constructor -////////////////////////////////////////////////////////////////////// -WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype, const char *noisefile_path, int init_fire, int init_colors) -{ - // if noise magnitude is below this threshold, its contribution - // is negilgible, so stop evaluating new octaves - _cullingThreshold = 1e-3; - - // factor by which to increase the simulation resolution - _amplify = amplify; - - // manually adjust the overall amount of turbulence - // DG - RNA-fied _strength = 2.; - - // add the corresponding octaves of noise - _octaves = (int)(log((float)_amplify) / log(2.0f) + 0.5f); // XXX DEBUG/ TODO: int casting correct? - dg - - // noise resolution - _xResBig = _amplify * xResSm; - _yResBig = _amplify * yResSm; - _zResBig = _amplify * zResSm; - _resBig = Vec3Int(_xResBig, _yResBig, _zResBig); - _invResBig = Vec3(1.0f/(float)_resBig[0], 1.0f/(float)_resBig[1], 1.0f/(float)_resBig[2]); - _slabSizeBig = _xResBig*_yResBig; - _totalCellsBig = _slabSizeBig * _zResBig; - - // original / small resolution - _xResSm = xResSm; - _yResSm = yResSm; - _zResSm = zResSm; - _resSm = Vec3Int(xResSm, yResSm, zResSm); - _invResSm = Vec3(1.0f/(float)_resSm[0], 1.0f/(float)_resSm[1], 1.0f/(float)_resSm[2] ); - _slabSizeSm = _xResSm*_yResSm; - _totalCellsSm = _slabSizeSm * _zResSm; - - // allocate high resolution density field - _totalStepsBig = 0; - _densityBig = new float[_totalCellsBig]; - _densityBigOld = new float[_totalCellsBig]; - - for(int i = 0; i < _totalCellsBig; i++) { - _densityBig[i] = - _densityBigOld[i] = 0.; - } - - /* fire */ - _flameBig = _fuelBig = _fuelBigOld = NULL; - _reactBig = _reactBigOld = NULL; - if (init_fire) { - initFire(); - } - /* colors */ - _color_rBig = _color_rBigOld = NULL; - _color_gBig = _color_gBigOld = NULL; - _color_bBig = _color_bBigOld = NULL; - if (init_colors) { - initColors(0.0f, 0.0f, 0.0f); - } - - // allocate & init texture coordinates - _tcU = new float[_totalCellsSm]; - _tcV = new float[_totalCellsSm]; - _tcW = new float[_totalCellsSm]; - _tcTemp = new float[_totalCellsSm]; - - // map all - const float dx = 1.0f/(float)(_resSm[0]); - const float dy = 1.0f/(float)(_resSm[1]); - const float dz = 1.0f/(float)(_resSm[2]); - int index = 0; - for (int z = 0; z < _zResSm; z++) - for (int y = 0; y < _yResSm; y++) - for (int x = 0; x < _xResSm; x++, index++) - { - _tcU[index] = x*dx; - _tcV[index] = y*dy; - _tcW[index] = z*dz; - _tcTemp[index] = 0.; - } - - // noise tiles - _noiseTile = new float[noiseTileSize * noiseTileSize * noiseTileSize]; - setNoise(noisetype, noisefile_path); -} - -void WTURBULENCE::initFire() -{ - if (!_fuelBig) { - _flameBig = new float[_totalCellsBig]; - _fuelBig = new float[_totalCellsBig]; - _fuelBigOld = new float[_totalCellsBig]; - _reactBig = new float[_totalCellsBig]; - _reactBigOld = new float[_totalCellsBig]; - - for(int i = 0; i < _totalCellsBig; i++) { - _flameBig[i] = - _fuelBig[i] = - _fuelBigOld[i] = 0.; - _reactBig[i] = - _reactBigOld[i] = 0.; - } - } -} - -void WTURBULENCE::initColors(float init_r, float init_g, float init_b) -{ - if (!_color_rBig) { - _color_rBig = new float[_totalCellsBig]; - _color_rBigOld = new float[_totalCellsBig]; - _color_gBig = new float[_totalCellsBig]; - _color_gBigOld = new float[_totalCellsBig]; - _color_bBig = new float[_totalCellsBig]; - _color_bBigOld = new float[_totalCellsBig]; - - for(int i = 0; i < _totalCellsBig; i++) { - _color_rBig[i] = _densityBig[i] * init_r; - _color_rBigOld[i] = 0.0f; - _color_gBig[i] = _densityBig[i] * init_g; - _color_gBigOld[i] = 0.0f; - _color_bBig[i] = _densityBig[i] * init_b; - _color_bBigOld[i] = 0.0f; - } - } -} - -////////////////////////////////////////////////////////////////////// -// destructor -////////////////////////////////////////////////////////////////////// -WTURBULENCE::~WTURBULENCE() { - delete[] _densityBig; - delete[] _densityBigOld; - if (_flameBig) delete[] _flameBig; - if (_fuelBig) delete[] _fuelBig; - if (_fuelBigOld) delete[] _fuelBigOld; - if (_reactBig) delete[] _reactBig; - if (_reactBigOld) delete[] _reactBigOld; - - if (_color_rBig) delete[] _color_rBig; - if (_color_rBigOld) delete[] _color_rBigOld; - if (_color_gBig) delete[] _color_gBig; - if (_color_gBigOld) delete[] _color_gBigOld; - if (_color_bBig) delete[] _color_bBig; - if (_color_bBigOld) delete[] _color_bBigOld; - - delete[] _tcU; - delete[] _tcV; - delete[] _tcW; - delete[] _tcTemp; - - delete[] _noiseTile; -} - -////////////////////////////////////////////////////////////////////// -// Change noise type -// -// type (1<<0) = wavelet / 2 -// type (1<<1) = FFT / 4 -// type (1<<2) = curl / 8 -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::setNoise(int type, const char *noisefile_path) -{ - if(type == (1<<1)) // FFT - { -#ifdef WITH_FFTW3 - // needs fft - std::string noiseTileFilename = std::string(noisefile_path) + std::string("noise.fft"); - generatTile_FFT(_noiseTile, noiseTileFilename); - return; -#else - fprintf(stderr, "FFTW not enabled, falling back to wavelet noise.\n"); -#endif - } -#if 0 - if(type == (1<<2)) // curl - { - // TODO: not supported yet - return; - } -#endif - - std::string noiseTileFilename = std::string(noisefile_path) + std::string("noise.wavelets"); - generateTile_WAVELET(_noiseTile, noiseTileFilename); -} - -// init direct access functions from blender -void WTURBULENCE::initBlenderRNA(float *strength) -{ - _strength = strength; -} - -////////////////////////////////////////////////////////////////////// -// Get the smallest valid x derivative -// -// Takes the one-sided finite difference in both directions and -// selects the smaller of the two -////////////////////////////////////////////////////////////////////// -static float minDx(int x, int y, int z, float* input, const Vec3Int& res) -{ - const int index = x + y * res[0] + z * res[0] * res[1]; - const int maxx = res[0]-2; - - // get grid values - float center = input[index]; - float left = (x <= 1) ? FLT_MAX : input[index - 1]; - float right = (x >= maxx) ? FLT_MAX : input[index + 1]; - - const float dx = res[0]; - - // get all the derivative estimates - float dLeft = (x <= 1) ? FLT_MAX : (center - left) * dx; - float dRight = (x >= maxx) ? FLT_MAX : (right - center) * dx; - float dCenter = (x <= 1 || x >= maxx) ? FLT_MAX : (right - left) * dx * 0.5f; - - // if it's on a boundary, only one estimate is valid - if (x <= 1) return dRight; - if (x >= maxx) return dLeft; - - // if it's not on a boundary, get the smallest one - float finalD; - finalD = (fabs(dCenter) < fabs(dRight)) ? dCenter : dRight; - finalD = (fabs(finalD) < fabs(dLeft)) ? finalD : dLeft; - - return finalD; -} - -////////////////////////////////////////////////////////////////////// -// get the smallest valid y derivative -// -// Takes the one-sided finite difference in both directions and -// selects the smaller of the two -////////////////////////////////////////////////////////////////////// -static float minDy(int x, int y, int z, float* input, const Vec3Int& res) -{ - const int index = x + y * res[0] + z * res[0] * res[1]; - const int maxy = res[1]-2; - - // get grid values - float center = input[index]; - float down = (y <= 1) ? FLT_MAX : input[index - res[0]]; - float up = (y >= maxy) ? FLT_MAX : input[index + res[0]]; - - const float dx = res[1]; // only for square domains - - // get all the derivative estimates - float dDown = (y <= 1) ? FLT_MAX : (center - down) * dx; - float dUp = (y >= maxy) ? FLT_MAX : (up - center) * dx; - float dCenter = (y <= 1 || y >= maxy) ? FLT_MAX : (up - down) * dx * 0.5f; - - // if it's on a boundary, only one estimate is valid - if (y <= 1) return dUp; - if (y >= maxy) return dDown; - - // if it's not on a boundary, get the smallest one - float finalD = (fabs(dCenter) < fabs(dUp)) ? dCenter : dUp; - finalD = (fabs(finalD) < fabs(dDown)) ? finalD : dDown; - - return finalD; -} - -////////////////////////////////////////////////////////////////////// -// get the smallest valid z derivative -// -// Takes the one-sided finite difference in both directions and -// selects the smaller of the two -////////////////////////////////////////////////////////////////////// -static float minDz(int x, int y, int z, float* input, const Vec3Int& res) -{ - const int slab = res[0]*res[1]; - const int index = x + y * res[0] + z * slab; - const int maxz = res[2]-2; - - // get grid values - float center = input[index]; - float front = (z <= 1) ? FLT_MAX : input[index - slab]; - float back = (z >= maxz) ? FLT_MAX : input[index + slab]; - - const float dx = res[2]; // only for square domains - - // get all the derivative estimates - float dfront = (z <= 1) ? FLT_MAX : (center - front) * dx; - float dback = (z >= maxz) ? FLT_MAX : (back - center) * dx; - float dCenter = (z <= 1 || z >= maxz) ? FLT_MAX : (back - front) * dx * 0.5f; - - // if it's on a boundary, only one estimate is valid - if (z <= 1) return dback; - if (z >= maxz) return dfront; - - // if it's not on a boundary, get the smallest one - float finalD = (fabs(dCenter) < fabs(dback)) ? dCenter : dback; - finalD = (fabs(finalD) < fabs(dfront)) ? finalD : dfront; - - return finalD; -} - -////////////////////////////////////////////////////////////////////// -// handle texture coordinates (advection, reset, eigenvalues), -// Beware -- uses big density maccormack as temporary arrays -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::advectTextureCoordinates (float dtOrg, float* xvel, float* yvel, float* zvel, float *tempBig1, float *tempBig2) { - - // advection - SWAP_POINTERS(_tcTemp, _tcU); - FLUID_3D::copyBorderX(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderY(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderZ(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::advectFieldMacCormack1(dtOrg, xvel, yvel, zvel, - _tcTemp, tempBig1, _resSm, 0 , _resSm[2]); - FLUID_3D::advectFieldMacCormack2(dtOrg, xvel, yvel, zvel, - _tcTemp, _tcU, tempBig1, tempBig2, _resSm, NULL, 0 , _resSm[2]); - - SWAP_POINTERS(_tcTemp, _tcV); - FLUID_3D::copyBorderX(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderY(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderZ(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::advectFieldMacCormack1(dtOrg, xvel, yvel, zvel, - _tcTemp, tempBig1, _resSm, 0 , _resSm[2]); - FLUID_3D::advectFieldMacCormack2(dtOrg, xvel, yvel, zvel, - _tcTemp, _tcV, tempBig1, tempBig2, _resSm, NULL, 0 , _resSm[2]); - - SWAP_POINTERS(_tcTemp, _tcW); - FLUID_3D::copyBorderX(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderY(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderZ(_tcTemp, _resSm, 0 , _resSm[2]); - FLUID_3D::advectFieldMacCormack1(dtOrg, xvel, yvel, zvel, - _tcTemp, tempBig1, _resSm, 0 , _resSm[2]); - FLUID_3D::advectFieldMacCormack2(dtOrg, xvel, yvel, zvel, - _tcTemp, _tcW, tempBig1, tempBig2, _resSm, NULL, 0 , _resSm[2]); -} - -////////////////////////////////////////////////////////////////////// -// Compute the eigenvalues of the advected texture -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::computeEigenvalues(float *_eigMin, float *_eigMax) { - // stats - float maxeig = -1.; - float mineig = 10.; - - // texture coordinate eigenvalues - for (int z = 1; z < _zResSm-1; z++) { - for (int y = 1; y < _yResSm-1; y++) - for (int x = 1; x < _xResSm-1; x++) - { - const int index = x+ y *_resSm[0] + z*_slabSizeSm; - - // compute jacobian - float jacobian[3][3] = { - { minDx(x, y, z, _tcU, _resSm), minDx(x, y, z, _tcV, _resSm), minDx(x, y, z, _tcW, _resSm) } , - { minDy(x, y, z, _tcU, _resSm), minDy(x, y, z, _tcV, _resSm), minDy(x, y, z, _tcW, _resSm) } , - { minDz(x, y, z, _tcU, _resSm), minDz(x, y, z, _tcV, _resSm), minDz(x, y, z, _tcW, _resSm) } - }; - - // ONLY compute the eigenvalues after checking that the matrix - // is nonsingular - sLU LU = computeLU(jacobian); - - if (isNonsingular(LU)) - { - // get the analytic eigenvalues, quite slow right now... - Vec3 eigenvalues = Vec3(1.); - computeEigenvalues3x3( &eigenvalues[0], jacobian); - _eigMax[index] = MAX3V(eigenvalues); - _eigMin[index] = MIN3V(eigenvalues); - maxeig = MAX(_eigMax[index],maxeig); - mineig = MIN(_eigMin[index],mineig); - } - else - { - _eigMax[index] = 10.0f; - _eigMin[index] = 0.1; - } - } - } -} - -////////////////////////////////////////////////////////////////////// -// advect & reset texture coordinates based on eigenvalues -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::resetTextureCoordinates(float *_eigMin, float *_eigMax) -{ - // allowed deformation of the textures - const float limit = 2.f; - const float limitInv = 1.0f/limit; - - // standard reset - int resets = 0; - const float dx = 1.0f/(float)(_resSm[0]); - const float dy = 1.0f/(float)(_resSm[1]); - const float dz = 1.0f/(float)(_resSm[2]); - - for (int z = 1; z < _zResSm-1; z++) - for (int y = 1; y < _yResSm-1; y++) - for (int x = 1; x < _xResSm-1; x++) - { - const int index = x+ y *_resSm[0] + z*_slabSizeSm; - if (_eigMax[index] > limit || _eigMin[index] < limitInv) - { - _tcU[index] = (float)x * dx; - _tcV[index] = (float)y * dy; - _tcW[index] = (float)z * dz; - resets++; - } - } -} - -////////////////////////////////////////////////////////////////////// -// Compute the highest frequency component of the wavelet -// decomposition -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::decomposeEnergy(float *_energy, float *_highFreqEnergy) -{ - // do the decomposition -- the goal here is to have - // the energy with the high frequency component stomped out - // stored in _tcTemp when it is done. _highFreqEnergy is only used - // as an additional temp array - - // downsample input - downsampleXNeumann(_highFreqEnergy, _energy, _xResSm, _yResSm, _zResSm); - downsampleYNeumann(_tcTemp, _highFreqEnergy, _xResSm, _yResSm, _zResSm); - downsampleZNeumann(_highFreqEnergy, _tcTemp, _xResSm, _yResSm, _zResSm); - - // upsample input - upsampleZNeumann(_tcTemp, _highFreqEnergy, _xResSm, _yResSm, _zResSm); - upsampleYNeumann(_highFreqEnergy, _tcTemp, _xResSm, _yResSm, _zResSm); - upsampleXNeumann(_tcTemp, _highFreqEnergy, _xResSm, _yResSm, _zResSm); - - // subtract the down and upsampled field from the original field -- - // what should be left over is solely the high frequency component - int index = 0; - for (int z = 0; z < _zResSm; z++) - for (int y = 0; y < _yResSm; y++) { - for (int x = 0; x < _xResSm; x++, index++) { - // brute force reset of boundaries - if(z >= _zResSm - 1 || x >= _xResSm - 1 || y >= _yResSm - 1 || z <= 0 || y <= 0 || x <= 0) - _highFreqEnergy[index] = 0.; - else - _highFreqEnergy[index] = _energy[index] - _tcTemp[index]; - } - } -} - -////////////////////////////////////////////////////////////////////// -// compute velocity from energies and march into obstacles -// for wavelet decomposition -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::computeEnergy(float *_energy, float* xvel, float* yvel, float* zvel, unsigned char *origObstacles) -{ - unsigned char *obstacles = new unsigned char[_totalCellsSm]; - memcpy(obstacles, origObstacles, sizeof(unsigned char) * _totalCellsSm); - - // compute everywhere - for (int x = 0; x < _totalCellsSm; x++) - _energy[x] = 0.5f * (xvel[x] * xvel[x] + yvel[x] * yvel[x] + zvel[x] * zvel[x]); - - FLUID_3D::copyBorderX(_energy, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderY(_energy, _resSm, 0 , _resSm[2]); - FLUID_3D::copyBorderZ(_energy, _resSm, 0 , _resSm[2]); - - // pseudo-march the values into the obstacles - // the wavelet upsampler only uses a 3x3 support neighborhood, so - // propagating the values in by 4 should be sufficient - int index; - - // iterate - for (int iter = 0; iter < 4; iter++) - { - index = _slabSizeSm + _xResSm + 1; - for (int z = 1; z < _zResSm - 1; z++, index += 2 * _xResSm) - for (int y = 1; y < _yResSm - 1; y++, index += 2) - for (int x = 1; x < _xResSm - 1; x++, index++) - if (obstacles[index] && obstacles[index] != RETIRED) - { - float sum = 0.0f; - int valid = 0; - - if (!obstacles[index + 1] || obstacles[index + 1] == RETIRED) - { - sum += _energy[index + 1]; - valid++; - } - if (!obstacles[index - 1] || obstacles[index - 1] == RETIRED) - { - sum += _energy[index - 1]; - valid++; - } - if (!obstacles[index + _xResSm] || obstacles[index + _xResSm] == RETIRED) - { - sum += _energy[index + _xResSm]; - valid++; - } - if (!obstacles[index - _xResSm] || obstacles[index - _xResSm] == RETIRED) - { - sum += _energy[index - _xResSm]; - valid++; - } - if (!obstacles[index + _slabSizeSm] || obstacles[index + _slabSizeSm] == RETIRED) - { - sum += _energy[index + _slabSizeSm]; - valid++; - } - if (!obstacles[index - _slabSizeSm] || obstacles[index - _slabSizeSm] == RETIRED) - { - sum += _energy[index - _slabSizeSm]; - valid++; - } - if (valid > 0) - { - _energy[index] = sum / (float)valid; - obstacles[index] = MARCHED; - } - } - index = _slabSizeSm + _xResSm + 1; - for (int z = 1; z < _zResSm - 1; z++, index += 2 * _xResSm) - for (int y = 1; y < _yResSm - 1; y++, index += 2) - for (int x = 1; x < _xResSm - 1; x++, index++) - if (obstacles[index] == MARCHED) - obstacles[index] = RETIRED; - } - index = _slabSizeSm + _xResSm + 1; - for (int z = 1; z < _zResSm - 1; z++, index += 2 * _xResSm) - for (int y = 1; y < _yResSm - 1; y++, index += 2) - for (int x = 1; x < _xResSm - 1; x++, index++) - if (obstacles[index]) - obstacles[index] = 1; // DG TODO ? animated obstacle flag? - - delete [] obstacles; -} - -////////////////////////////////////////////////////////////////////////////////////////// -// Evaluate derivatives -////////////////////////////////////////////////////////////////////////////////////////// -Vec3 WTURBULENCE::WVelocity(Vec3 orgPos) -{ - // arbitrarily offset evaluation points - const Vec3 p1 = orgPos + Vec3(NOISE_TILE_SIZE/2.0,0,0); - const Vec3 p2 = orgPos + Vec3(0,NOISE_TILE_SIZE/2.0,0); - const Vec3 p3 = orgPos + Vec3(0,0,NOISE_TILE_SIZE/2.0); - - const float f1y = WNoiseDy(p1, _noiseTile); - const float f1z = WNoiseDz(p1, _noiseTile); - - const float f2x = WNoiseDx(p2, _noiseTile); - const float f2z = WNoiseDz(p2, _noiseTile); - - const float f3x = WNoiseDx(p3, _noiseTile); - const float f3y = WNoiseDy(p3, _noiseTile); - - Vec3 ret = Vec3( - f3y - f2z, - f1z - f3x, - f2x - f1y ); - return ret; -} - -////////////////////////////////////////////////////////////////////////////////////////// -// Evaluate derivatives with Jacobian -////////////////////////////////////////////////////////////////////////////////////////// -Vec3 WTURBULENCE::WVelocityWithJacobian(const Vec3& orgPos, float* xUnwarped, float* yUnwarped, float* zUnwarped) -{ - // arbitrarily offset evaluation points - const Vec3 p1 = orgPos + Vec3(NOISE_TILE_SIZE/2.0,0,0); - const Vec3 p2 = orgPos + Vec3(0,NOISE_TILE_SIZE/2.0,0); - const Vec3 p3 = orgPos + Vec3(0,0,NOISE_TILE_SIZE/2.0); - - Vec3 final; - final[0] = WNoiseDx(p1, _noiseTile); - final[1] = WNoiseDy(p1, _noiseTile); - final[2] = WNoiseDz(p1, _noiseTile); - // UNUSED const float f1x = xUnwarped[0] * final[0] + xUnwarped[1] * final[1] + xUnwarped[2] * final[2]; - const float f1y = yUnwarped[0] * final[0] + yUnwarped[1] * final[1] + yUnwarped[2] * final[2]; - const float f1z = zUnwarped[0] * final[0] + zUnwarped[1] * final[1] + zUnwarped[2] * final[2]; - - final[0] = WNoiseDx(p2, _noiseTile); - final[1] = WNoiseDy(p2, _noiseTile); - final[2] = WNoiseDz(p2, _noiseTile); - const float f2x = xUnwarped[0] * final[0] + xUnwarped[1] * final[1] + xUnwarped[2] * final[2]; - // UNUSED const float f2y = yUnwarped[0] * final[0] + yUnwarped[1] * final[1] + yUnwarped[2] * final[2]; - const float f2z = zUnwarped[0] * final[0] + zUnwarped[1] * final[1] + zUnwarped[2] * final[2]; - - final[0] = WNoiseDx(p3, _noiseTile); - final[1] = WNoiseDy(p3, _noiseTile); - final[2] = WNoiseDz(p3, _noiseTile); - const float f3x = xUnwarped[0] * final[0] + xUnwarped[1] * final[1] + xUnwarped[2] * final[2]; - const float f3y = yUnwarped[0] * final[0] + yUnwarped[1] * final[1] + yUnwarped[2] * final[2]; - // UNUSED const float f3z = zUnwarped[0] * final[0] + zUnwarped[1] * final[1] + zUnwarped[2] * final[2]; - - Vec3 ret = Vec3( - f3y - f2z, - f1z - f3x, - f2x - f1y ); - return ret; -} - - -////////////////////////////////////////////////////////////////////// -// perform an actual noise advection step -////////////////////////////////////////////////////////////////////// -/*void WTURBULENCE::stepTurbulenceReadable(float dtOrg, float* xvel, float* yvel, float* zvel, unsigned char *obstacles) -{ - // enlarge timestep to match grid - const float dt = dtOrg * _amplify; - const float invAmp = 1.0f / _amplify; - float *tempBig1 = new float[_totalCellsBig]; - float *tempBig2 = new float[_totalCellsBig]; - float *bigUx = new float[_totalCellsBig]; - float *bigUy = new float[_totalCellsBig]; - float *bigUz = new float[_totalCellsBig]; - float *_energy = new float[_totalCellsSm]; - float *highFreqEnergy = new float[_totalCellsSm]; - float *eigMin = new float[_totalCellsSm]; - float *eigMax = new float[_totalCellsSm]; - - memset(tempBig1, 0, sizeof(float)*_totalCellsBig); - memset(tempBig2, 0, sizeof(float)*_totalCellsBig); - memset(highFreqEnergy, 0, sizeof(float)*_totalCellsSm); - memset(eigMin, 0, sizeof(float)*_totalCellsSm); - memset(eigMax, 0, sizeof(float)*_totalCellsSm); - - // prepare textures - advectTextureCoordinates(dtOrg, xvel,yvel,zvel, tempBig1, tempBig2); - - // compute eigenvalues of the texture coordinates - computeEigenvalues(eigMin, eigMax); - - // do wavelet decomposition of energy - computeEnergy(_energy, xvel, yvel, zvel, obstacles); - decomposeEnergy(_energy, highFreqEnergy); - - // zero out coefficients inside of the obstacle - for (int x = 0; x < _totalCellsSm; x++) - if (obstacles[x]) _energy[x] = 0.f; - - float maxVelocity = 0.; - for (int z = 1; z < _zResBig - 1; z++) - for (int y = 1; y < _yResBig - 1; y++) - for (int x = 1; x < _xResBig - 1; x++) - { - // get unit position for both fine and coarse grid - const Vec3 pos = Vec3(x,y,z); - const Vec3 posSm = pos * invAmp; - - // get grid index for both fine and coarse grid - const int index = x + y *_xResBig + z *_slabSizeBig; - const int indexSmall = (int)posSm[0] + (int)posSm[1] * _xResSm + (int)posSm[2] * _slabSizeSm; - - // get a linearly interpolated velocity and texcoords - // from the coarse grid - Vec3 vel = INTERPOLATE::lerp3dVec( xvel,yvel,zvel, - posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm); - Vec3 uvw = INTERPOLATE::lerp3dVec( _tcU,_tcV,_tcW, - posSm[0], posSm[1], posSm[2], _xResSm,_yResSm,_zResSm); - - // multiply the texture coordinate by _resSm so that turbulence - // synthesis begins at the first octave that the coarse grid - // cannot capture - Vec3 texCoord = Vec3(uvw[0] * _resSm[0], - uvw[1] * _resSm[1], - uvw[2] * _resSm[2]); - - // retrieve wavelet energy at highest frequency - float energy = INTERPOLATE::lerp3d( - highFreqEnergy, posSm[0],posSm[1],posSm[2], _xResSm, _yResSm, _zResSm); - - // base amplitude for octave 0 - float coefficient = sqrtf(2.0f * fabs(energy)); - const float amplitude = *_strength * fabs(0.5 * coefficient) * persistence; - - // add noise to velocity, but only if the turbulence is - // sufficiently undeformed, and the energy is large enough - // to make a difference - const bool addNoise = eigMax[indexSmall] < 2. && - eigMin[indexSmall] > 0.5; - if (addNoise && amplitude > _cullingThreshold) { - // base amplitude for octave 0 - float amplitudeScaled = amplitude; - - for (int octave = 0; octave < _octaves; octave++) - { - // multiply the vector noise times the maximum allowed - // noise amplitude at this octave, and add it to the total - vel += WVelocity(texCoord) * amplitudeScaled; - - // scale coefficient for next octave - amplitudeScaled *= persistence; - texCoord *= 2.0f; - } - } - - // Store velocity + turbulence in big grid for maccormack step - // - // If you wanted to save memory, you would instead perform a - // semi-Lagrangian backtrace for the current grid cell here. Then - // you could just throw the velocity away. - bigUx[index] = vel[0]; - bigUy[index] = vel[1]; - bigUz[index] = vel[2]; - - // compute the velocity magnitude for substepping later - const float velMag = bigUx[index] * bigUx[index] + - bigUy[index] * bigUy[index] + - bigUz[index] * bigUz[index]; - if (velMag > maxVelocity) maxVelocity = velMag; - - // zero out velocity inside obstacles - float obsCheck = INTERPOLATE::lerp3dToFloat( - obstacles, posSm[0], posSm[1], posSm[2], _xResSm, _yResSm, _zResSm); - if (obsCheck > 0.95) - bigUx[index] = bigUy[index] = bigUz[index] = 0.; - } - - // prepare density for an advection - SWAP_POINTERS(_densityBig, _densityBigOld); - - // based on the maximum velocity present, see if we need to substep, - // but cap the maximum number of substeps to 5 - const int maxSubSteps = 5; - maxVelocity = sqrt(maxVelocity) * dt; - int totalSubsteps = (int)(maxVelocity / (float)maxSubSteps); - totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; - totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; - const float dtSubdiv = dt / (float)totalSubsteps; - - // set boundaries of big velocity grid - FLUID_3D::setZeroX(bigUx, _resBig, 0, _resBig[2]); - FLUID_3D::setZeroY(bigUy, _resBig, 0, _resBig[2]); - FLUID_3D::setZeroZ(bigUz, _resBig, 0, _resBig[2]); - - // do the MacCormack advection, with substepping if necessary - for(int substep = 0; substep < totalSubsteps; substep++) - { - FLUID_3D::advectFieldMacCormack(dtSubdiv, bigUx, bigUy, bigUz, - _densityBigOld, _densityBig, tempBig1, tempBig2, _resBig, NULL); - - if (substep < totalSubsteps - 1) - SWAP_POINTERS(_densityBig, _densityBigOld); - } // substep - - // wipe the density borders - FLUID_3D::setZeroBorder(_densityBig, _resBig, 0, _resBig[2]); - - // reset texture coordinates now in preparation for next timestep - // Shouldn't do this before generating the noise because then the - // eigenvalues stored do not reflect the underlying texture coordinates - resetTextureCoordinates(eigMin, eigMax); - - delete[] tempBig1; - delete[] tempBig2; - delete[] bigUx; - delete[] bigUy; - delete[] bigUz; - delete[] _energy; - delete[] highFreqEnergy; - - delete[] eigMin; - delete[] eigMax; - - - _totalStepsBig++; -}*/ - -//struct - -////////////////////////////////////////////////////////////////////// -// perform the full turbulence algorithm, including OpenMP -// if available -////////////////////////////////////////////////////////////////////// -void WTURBULENCE::stepTurbulenceFull(float dtOrg, float* xvel, float* yvel, float* zvel, unsigned char *obstacles) -{ - // enlarge timestep to match grid - const float dt = dtOrg * _amplify; - const float invAmp = 1.0f / _amplify; - float *tempFuelBig = NULL, *tempReactBig = NULL; - float *tempColor_rBig = NULL, *tempColor_gBig = NULL, *tempColor_bBig = NULL; - float *tempDensityBig = (float *)calloc(_totalCellsBig, sizeof(float)); - float *tempBig = (float *)calloc(_totalCellsBig, sizeof(float)); - float *bigUx = (float *)calloc(_totalCellsBig, sizeof(float)); - float *bigUy = (float *)calloc(_totalCellsBig, sizeof(float)); - float *bigUz = (float *)calloc(_totalCellsBig, sizeof(float)); - float *_energy = (float *)calloc(_totalCellsSm, sizeof(float)); - float *highFreqEnergy = (float *)calloc(_totalCellsSm, sizeof(float)); - float *eigMin = (float *)calloc(_totalCellsSm, sizeof(float)); - float *eigMax = (float *)calloc(_totalCellsSm, sizeof(float)); - - if (_fuelBig) { - tempFuelBig = (float *)calloc(_totalCellsBig, sizeof(float)); - tempReactBig = (float *)calloc(_totalCellsBig, sizeof(float)); - } - if (_color_rBig) { - tempColor_rBig = (float *)calloc(_totalCellsBig, sizeof(float)); - tempColor_gBig = (float *)calloc(_totalCellsBig, sizeof(float)); - tempColor_bBig = (float *)calloc(_totalCellsBig, sizeof(float)); - } - - memset(_tcTemp, 0, sizeof(float)*_totalCellsSm); - - - // prepare textures - advectTextureCoordinates(dtOrg, xvel,yvel,zvel, tempDensityBig, tempBig); - - // do wavelet decomposition of energy - computeEnergy(_energy, xvel, yvel, zvel, obstacles); - - for (int x = 0; x < _totalCellsSm; x++) - if (obstacles[x]) _energy[x] = 0.f; - - decomposeEnergy(_energy, highFreqEnergy); - - // zero out coefficients inside of the obstacle - for (int x = 0; x < _totalCellsSm; x++) - if (obstacles[x]) highFreqEnergy[x] = 0.f; - - Vec3Int ressm(_xResSm, _yResSm, _zResSm); - FLUID_3D::setNeumannX(highFreqEnergy, ressm, 0 , ressm[2]); - FLUID_3D::setNeumannY(highFreqEnergy, ressm, 0 , ressm[2]); - FLUID_3D::setNeumannZ(highFreqEnergy, ressm, 0 , ressm[2]); - - - int threadval = 1; -#if PARALLEL==1 - threadval = omp_get_max_threads(); -#endif - - - // parallel region setup - // Uses omp_get_max_trheads to get number of required cells. - float* maxVelMagThreads = new float[threadval]; - - for (int i=0; i 0.5f; - if (addNoise && amplitude > _cullingThreshold) { - // base amplitude for octave 0 - float amplitudeScaled = amplitude; - - for (int octave = 0; octave < _octaves; octave++) - { - // multiply the vector noise times the maximum allowed - // noise amplitude at this octave, and add it to the total - vel += WVelocityWithJacobian(texCoord, &xUnwarped[0], &yUnwarped[0], &zUnwarped[0]) * amplitudeScaled; - - // scale coefficient for next octave - amplitudeScaled *= persistence; - texCoord *= 2.0f; - } - } - - // Store velocity + turbulence in big grid for maccormack step - // - // If you wanted to save memory, you would instead perform a - // semi-Lagrangian backtrace for the current grid cell here. Then - // you could just throw the velocity away. - bigUx[index] = vel[0]; - bigUy[index] = vel[1]; - bigUz[index] = vel[2]; - - // compute the velocity magnitude for substepping later - const float velMag = bigUx[index] * bigUx[index] + - bigUy[index] * bigUy[index] + - bigUz[index] * bigUz[index]; - if (velMag > maxVelMag1) maxVelMag1 = velMag; - - // zero out velocity inside obstacles - float obsCheck = INTERPOLATE::lerp3dToFloat( - obstacles, posSm[0], posSm[1], posSm[2], _xResSm, _yResSm, _zResSm); - if (obsCheck > 0.95f) - bigUx[index] = bigUy[index] = bigUz[index] = 0.; - } // xyz*/ - -#if PARALLEL==1 - maxVelMagThreads[id] = maxVelMag1; -#else - maxVelMagThreads[0] = maxVelMag1; -#endif - } - } - } // omp - - // compute maximum over threads - float maxVelMag = maxVelMagThreads[0]; -#if PARALLEL==1 - for (int i = 1; i < threadval; i++) - if (maxVelMag < maxVelMagThreads[i]) - maxVelMag = maxVelMagThreads[i]; -#endif - delete [] maxVelMagThreads; - - - // prepare density for an advection - SWAP_POINTERS(_densityBig, _densityBigOld); - SWAP_POINTERS(_fuelBig, _fuelBigOld); - SWAP_POINTERS(_reactBig, _reactBigOld); - SWAP_POINTERS(_color_rBig, _color_rBigOld); - SWAP_POINTERS(_color_gBig, _color_gBigOld); - SWAP_POINTERS(_color_bBig, _color_bBigOld); - - // based on the maximum velocity present, see if we need to substep, - // but cap the maximum number of substeps to 5 - const int maxSubSteps = 25; - const int maxVel = 5; - maxVelMag = sqrt(maxVelMag) * dt; - int totalSubsteps = (int)(maxVelMag / (float)maxVel); - totalSubsteps = (totalSubsteps < 1) ? 1 : totalSubsteps; - // printf("totalSubsteps: %d\n", totalSubsteps); - totalSubsteps = (totalSubsteps > maxSubSteps) ? maxSubSteps : totalSubsteps; - const float dtSubdiv = dt / (float)totalSubsteps; - - // set boundaries of big velocity grid - FLUID_3D::setZeroX(bigUx, _resBig, 0 , _resBig[2]); - FLUID_3D::setZeroY(bigUy, _resBig, 0 , _resBig[2]); - FLUID_3D::setZeroZ(bigUz, _resBig, 0 , _resBig[2]); - -#if PARALLEL==1 - int stepParts = threadval*2; // Dividing parallelized sections into numOfThreads * 2 sections - float partSize = (float)_zResBig/stepParts; // Size of one part; - - if (partSize < 4) {stepParts = threadval; // If the slice gets too low (might actually slow things down, change it to larger - partSize = (float)_zResBig/stepParts;} - if (partSize < 4) {stepParts = (int)(ceil((float)_zResBig/4.0f)); // If it's still too low (only possible on future systems with +24 cores), change it to 4 - partSize = (float)_zResBig/stepParts;} -#else - int zBegin=0; - int zEnd=_resBig[2]; -#endif - - // do the MacCormack advection, with substepping if necessary - for(int substep = 0; substep < totalSubsteps; substep++) - { - -#if PARALLEL==1 - #pragma omp parallel - { - - #pragma omp for schedule(static,1) - for (int i=0; i. -// -// Copyright 2008 Theodore Kim and Nils Thuerey -// -// WTURBULENCE handling -/////////////////////////////////////////////////////////////////////////////////// - -#ifndef WTURBULENCE_H -#define WTURBULENCE_H - -#include "VEC3.h" -using namespace BasicVector; -class SIMPLE_PARSER; - -/////////////////////////////////////////////////////////////////////////////// -/// Main WTURBULENCE class, stores large density array etc. -/////////////////////////////////////////////////////////////////////////////// -struct WTURBULENCE -{ - public: - // both config files can be NULL, altCfg might override values from noiseCfg - WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int noisetype, const char *noisefile_path, int init_fire, int init_colors); - - /// destructor - virtual ~WTURBULENCE(); - - void initFire(); - void initColors(float init_r, float init_g, float init_b); - - void setNoise(int type, const char *noisefile_path); - void initBlenderRNA(float *strength); - - // step more readable version -- no rotation correction - void stepTurbulenceReadable(float dt, float* xvel, float* yvel, float* zvel, unsigned char *obstacles); - - // step more complete version -- include rotation correction - // and use OpenMP if available - void stepTurbulenceFull(float dt, float* xvel, float* yvel, float* zvel, unsigned char *obstacles); - - // texcoord functions - void advectTextureCoordinates(float dtOrg, float* xvel, float* yvel, float* zvel, float *tempBig1, float *tempBig2); - void resetTextureCoordinates(float *_eigMin, float *_eigMax); - - void computeEnergy(float *energy, float* xvel, float* yvel, float* zvel, unsigned char *obstacles); - - // evaluate wavelet noise function - Vec3 WVelocity(Vec3 p); - Vec3 WVelocityWithJacobian(const Vec3& p, float* xUnwarped, float* yUnwarped, float* zUnwarped); - - // access functions - inline float* getDensityBig() { return _densityBig; } - inline float* getFlameBig() { return _flameBig; } - inline float* getFuelBig() { return _fuelBig; } - inline float* getArrayTcU() { return _tcU; } - inline float* getArrayTcV() { return _tcV; } - inline float* getArrayTcW() { return _tcW; } - - inline Vec3Int getResSm() { return _resSm; } // small resolution - inline Vec3Int getResBig() { return _resBig; } - inline int getOctaves() { return _octaves; } - - // is accessed on through rna gui - float *_strength; - - // protected: - // enlargement factor from original velocity field / simulation - // _Big = _amplify * _Sm - int _amplify; - int _octaves; - - // noise settings - float _cullingThreshold; - // float _noiseStrength; - // float _noiseSizeScale; - // bool _uvwAdvection; - // bool _uvwReset; - // float _noiseTimeanimSpeed; - // int _dumpInterval; - // nt _noiseControlType; - // debug, scale density for projections output images - // float _outputScale; - - // noise resolution - int _xResBig; - int _yResBig; - int _zResBig; - Vec3Int _resBig; - Vec3 _invResBig; - int _totalCellsBig; - int _slabSizeBig; - // original / small resolution - int _xResSm; - int _yResSm; - int _zResSm; - Vec3Int _resSm; - Vec3 _invResSm; - int _totalCellsSm; - int _slabSizeSm; - - float* _densityBig; - float* _densityBigOld; - float* _flameBig; - float* _fuelBig; - float* _fuelBigOld; - float* _reactBig; - float* _reactBigOld; - - float* _color_rBig; - float* _color_rBigOld; - float* _color_gBig; - float* _color_gBigOld; - float* _color_bBig; - float* _color_bBigOld; - - // texture coordinates for noise - float* _tcU; - float* _tcV; - float* _tcW; - float* _tcTemp; - - // noise data - float* _noiseTile; - //float* _noiseTileExt; - - // step counter - int _totalStepsBig; - - void computeEigenvalues(float *_eigMin, float *_eigMax); - void decomposeEnergy(float *energy, float *_highFreqEnergy); -}; - -#endif // WTURBULENCE_H - diff --git a/intern/smoke/intern/smoke_API.cpp b/intern/smoke/intern/smoke_API.cpp deleted file mode 100644 index a02fa3bd684..00000000000 --- a/intern/smoke/intern/smoke_API.cpp +++ /dev/null @@ -1,495 +0,0 @@ -/* - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2009 by Daniel Genrich - * All rights reserved. - */ - -/** \file - * \ingroup smoke - */ - -#include "FLUID_3D.h" -#include "WTURBULENCE.h" - -#include -#include -#include - -#include "../extern/smoke_API.h" /* to ensure valid prototypes */ - -extern "C" FLUID_3D *smoke_init(int *res, float dx, float dtdef, int use_heat, int use_fire, int use_colors) -{ - FLUID_3D *fluid = new FLUID_3D(res, dx, dtdef, use_heat, use_fire, use_colors); - return fluid; -} - -extern "C" WTURBULENCE *smoke_turbulence_init(int *res, int amplify, int noisetype, const char *noisefile_path, int use_fire, int use_colors) -{ - if (amplify) - return new WTURBULENCE(res[0],res[1],res[2], amplify, noisetype, noisefile_path, use_fire, use_colors); - else - return NULL; -} - -extern "C" void smoke_free(FLUID_3D *fluid) -{ - delete fluid; - fluid = NULL; -} - -extern "C" void smoke_turbulence_free(WTURBULENCE *wt) -{ - delete wt; - wt = NULL; -} - -extern "C" size_t smoke_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */) -{ - return x + y * max_x + z * max_x*max_y; -} - -extern "C" size_t smoke_get_index2d(int x, int max_x, int y /*, int max_y, int z, int max_z */) -{ - return x + y * max_x; -} - -extern "C" void smoke_step(FLUID_3D *fluid, float gravity[3], float dtSubdiv) -{ - if (fluid->_fuel) { - fluid->processBurn(fluid->_fuel, fluid->_density, fluid->_react, fluid->_heat, - fluid->_color_r, fluid->_color_g, fluid->_color_b, fluid->_totalCells, (*fluid->_dtFactor)*dtSubdiv); - } - fluid->step(dtSubdiv, gravity); - - if (fluid->_fuel) { - fluid->updateFlame(fluid->_react, fluid->_flame, fluid->_totalCells); - } -} - -extern "C" void smoke_turbulence_step(WTURBULENCE *wt, FLUID_3D *fluid) -{ - if (wt->_fuelBig) { - fluid->processBurn(wt->_fuelBig, wt->_densityBig, wt->_reactBig, 0, - wt->_color_rBig, wt->_color_gBig, wt->_color_bBig, wt->_totalCellsBig, fluid->_dt); - } - wt->stepTurbulenceFull(fluid->_dt/fluid->_dx, fluid->_xVelocity, fluid->_yVelocity, fluid->_zVelocity, fluid->_obstacles); - - if (wt->_fuelBig) { - fluid->updateFlame(wt->_reactBig, wt->_flameBig, wt->_totalCellsBig); - } -} - -extern "C" void smoke_initBlenderRNA(FLUID_3D *fluid, float *alpha, float *beta, float *dt_factor, float *vorticity, int *border_colli, float *burning_rate, - float *flame_smoke, float *flame_smoke_color, float *flame_vorticity, float *flame_ignition_temp, float *flame_max_temp) -{ - fluid->initBlenderRNA(alpha, beta, dt_factor, vorticity, border_colli, burning_rate, flame_smoke, flame_smoke_color, flame_vorticity, flame_ignition_temp, flame_max_temp); -} - -extern "C" void smoke_initWaveletBlenderRNA(WTURBULENCE *wt, float *strength) -{ - wt->initBlenderRNA(strength); -} - -static void data_dissolve(float *density, float *heat, float *r, float *g, float *b, int total_cells, int speed, int log) -{ - if (log) { - /* max density/speed = dydx */ - float fac = 1.0f - (1.0f / (float)speed); - - for(size_t i = 0; i < total_cells; i++) - { - /* density */ - density[i] *= fac; - - /* heat */ - if (heat) { - heat[i] *= fac; - } - - /* color */ - if (r) { - r[i] *= fac; - g[i] *= fac; - b[i] *= fac; - } - } - } - else // linear falloff - { - /* max density/speed = dydx */ - float dydx = 1.0f / (float)speed; - - for(size_t i = 0; i < total_cells; i++) - { - float d = density[i]; - /* density */ - density[i] -= dydx; - if (density[i] < 0.0f) - density[i] = 0.0f; - - /* heat */ - if (heat) { - if (abs(heat[i]) < dydx) heat[i] = 0.0f; - else if (heat[i] > 0.0f) heat[i] -= dydx; - else if (heat[i] < 0.0f) heat[i] += dydx; - } - - /* color */ - if (r && d) { - r[i] *= (density[i]/d); - g[i] *= (density[i]/d); - b[i] *= (density[i]/d); - } - - } - } -} - -extern "C" void smoke_dissolve(FLUID_3D *fluid, int speed, int log) -{ - data_dissolve(fluid->_density, fluid->_heat, fluid->_color_r, fluid->_color_g, fluid->_color_b, fluid->_totalCells, speed, log); -} - -extern "C" void smoke_dissolve_wavelet(WTURBULENCE *wt, int speed, int log) -{ - data_dissolve(wt->_densityBig, 0, wt->_color_rBig, wt->_color_gBig, wt->_color_bBig, wt->_totalCellsBig, speed, log); -} - -extern "C" void smoke_export(FLUID_3D *fluid, float *dt, float *dx, float **dens, float **react, float **flame, float **fuel, float **heat, - float **heatold, float **vx, float **vy, float **vz, float **r, float **g, float **b, unsigned char **obstacles) -{ - *dens = fluid->_density; - if(fuel) - *fuel = fluid->_fuel; - if(react) - *react = fluid->_react; - if(flame) - *flame = fluid->_flame; - if(heat) - *heat = fluid->_heat; - if(heatold) - *heatold = fluid->_heatOld; - *vx = fluid->_xVelocity; - *vy = fluid->_yVelocity; - *vz = fluid->_zVelocity; - if(r) - *r = fluid->_color_r; - if(g) - *g = fluid->_color_g; - if(b) - *b = fluid->_color_b; - *obstacles = fluid->_obstacles; - *dt = fluid->_dt; - *dx = fluid->_dx; -} - -extern "C" void smoke_turbulence_export(WTURBULENCE *wt, float **dens, float **react, float **flame, float **fuel, - float **r, float **g, float **b , float **tcu, float **tcv, float **tcw) -{ - if (!wt) - return; - - *dens = wt->_densityBig; - if(fuel) - *fuel = wt->_fuelBig; - if(react) - *react = wt->_reactBig; - if(flame) - *flame = wt->_flameBig; - if(r) - *r = wt->_color_rBig; - if(g) - *g = wt->_color_gBig; - if(b) - *b = wt->_color_bBig; - *tcu = wt->_tcU; - *tcv = wt->_tcV; - *tcw = wt->_tcW; -} - -extern "C" float *smoke_get_density(FLUID_3D *fluid) -{ - return fluid->_density; -} - -extern "C" float *smoke_get_fuel(FLUID_3D *fluid) -{ - return fluid->_fuel; -} - -extern "C" float *smoke_get_react(FLUID_3D *fluid) -{ - return fluid->_react; -} - -extern "C" float *smoke_get_heat(FLUID_3D *fluid) -{ - return fluid->_heat; -} - -extern "C" float *smoke_get_velocity_x(FLUID_3D *fluid) -{ - return fluid->_xVelocity; -} - -extern "C" float *smoke_get_velocity_y(FLUID_3D *fluid) -{ - return fluid->_yVelocity; -} - -extern "C" float *smoke_get_velocity_z(FLUID_3D *fluid) -{ - return fluid->_zVelocity; -} - -extern "C" float *smoke_get_force_x(FLUID_3D *fluid) -{ - return fluid->_xForce; -} - -extern "C" float *smoke_get_force_y(FLUID_3D *fluid) -{ - return fluid->_yForce; -} - -extern "C" float *smoke_get_force_z(FLUID_3D *fluid) -{ - return fluid->_zForce; -} - -extern "C" float *smoke_get_flame(FLUID_3D *fluid) -{ - return fluid->_flame; -} - -extern "C" float *smoke_get_color_r(FLUID_3D *fluid) -{ - return fluid->_color_r; -} - -extern "C" float *smoke_get_color_g(FLUID_3D *fluid) -{ - return fluid->_color_g; -} - -extern "C" float *smoke_get_color_b(FLUID_3D *fluid) -{ - return fluid->_color_b; -} - -static void get_rgba(float *r, float *g, float *b, float *a, int total_cells, float *data, int sequential) -{ - int i; - int m = 4, i_g = 1, i_b = 2, i_a = 3; - /* sequential data */ - if (sequential) { - m = 1; - i_g *= total_cells; - i_b *= total_cells; - i_a *= total_cells; - } - - for (i=0; i_color_r, fluid->_color_g, fluid->_color_b, fluid->_density, fluid->_totalCells, data, sequential); -} - -extern "C" void smoke_turbulence_get_rgba(WTURBULENCE *wt, float *data, int sequential) -{ - get_rgba(wt->_color_rBig, wt->_color_gBig, wt->_color_bBig, wt->_densityBig, wt->_totalCellsBig, data, sequential); -} - -/* get a single color premultiplied voxel grid */ -static void get_rgba_from_density(float color[3], float *a, int total_cells, float *data, int sequential) -{ - int i; - int m = 4, i_g = 1, i_b = 2, i_a = 3; - /* sequential data */ - if (sequential) { - m = 1; - i_g *= total_cells; - i_b *= total_cells; - i_a *= total_cells; - } - - for (i=0; i_density, fluid->_totalCells, data, sequential); -} - -extern "C" void smoke_turbulence_get_rgba_from_density(WTURBULENCE *wt, float color[3], float *data, int sequential) -{ - get_rgba_from_density(color, wt->_densityBig, wt->_totalCellsBig, data, sequential); -} - -extern "C" float *smoke_turbulence_get_density(WTURBULENCE *wt) -{ - return wt ? wt->getDensityBig() : NULL; -} - -extern "C" float *smoke_turbulence_get_fuel(WTURBULENCE *wt) -{ - return wt ? wt->getFuelBig() : NULL; -} - -extern "C" float *smoke_turbulence_get_react(WTURBULENCE *wt) -{ - return wt ? wt->_reactBig : NULL; -} - -extern "C" float *smoke_turbulence_get_color_r(WTURBULENCE *wt) -{ - return wt ? wt->_color_rBig : NULL; -} - -extern "C" float *smoke_turbulence_get_color_g(WTURBULENCE *wt) -{ - return wt ? wt->_color_gBig : NULL; -} - -extern "C" float *smoke_turbulence_get_color_b(WTURBULENCE *wt) -{ - return wt ? wt->_color_bBig : NULL; -} - -extern "C" float *smoke_turbulence_get_flame(WTURBULENCE *wt) -{ - return wt ? wt->getFlameBig() : NULL; -} - -extern "C" void smoke_turbulence_get_res(WTURBULENCE *wt, int *res) -{ - if (wt) { - Vec3Int r = wt->getResBig(); - res[0] = r[0]; - res[1] = r[1]; - res[2] = r[2]; - } -} - -extern "C" int smoke_turbulence_get_cells(WTURBULENCE *wt) -{ - if (wt) { - Vec3Int r = wt->getResBig(); - return r[0] * r[1] * r[2]; - } - return 0; -} - -extern "C" unsigned char *smoke_get_obstacle(FLUID_3D *fluid) -{ - return fluid->_obstacles; -} - -extern "C" void smoke_get_ob_velocity(FLUID_3D *fluid, float **x, float **y, float **z) -{ - *x = fluid->_xVelocityOb; - *y = fluid->_yVelocityOb; - *z = fluid->_zVelocityOb; -} - -#if 0 -extern "C" unsigned char *smoke_get_obstacle_anim(FLUID_3D *fluid) -{ - return fluid->_obstaclesAnim; -} -#endif - -extern "C" void smoke_turbulence_set_noise(WTURBULENCE *wt, int type, const char *noisefile_path) -{ - wt->setNoise(type, noisefile_path); -} - -extern "C" int smoke_has_heat(FLUID_3D *fluid) -{ - return (fluid->_heat) ? 1 : 0; -} - -extern "C" int smoke_has_fuel(FLUID_3D *fluid) -{ - return (fluid->_fuel) ? 1 : 0; -} - -extern "C" int smoke_has_colors(FLUID_3D *fluid) -{ - return (fluid->_color_r && fluid->_color_g && fluid->_color_b) ? 1 : 0; -} - -extern "C" int smoke_turbulence_has_fuel(WTURBULENCE *wt) -{ - return (wt->_fuelBig) ? 1 : 0; -} - -extern "C" int smoke_turbulence_has_colors(WTURBULENCE *wt) -{ - return (wt->_color_rBig && wt->_color_gBig && wt->_color_bBig) ? 1 : 0; -} - -/* additional field initialization */ -extern "C" void smoke_ensure_heat(FLUID_3D *fluid) -{ - if (fluid) { - fluid->initHeat(); - } -} - -extern "C" void smoke_ensure_fire(FLUID_3D *fluid, WTURBULENCE *wt) -{ - if (fluid) { - fluid->initFire(); - } - if (wt) { - wt->initFire(); - } -} - -extern "C" void smoke_ensure_colors(FLUID_3D *fluid, WTURBULENCE *wt, float init_r, float init_g, float init_b) -{ - if (fluid) { - fluid->initColors(init_r, init_g, init_b); - } - if (wt) { - wt->initColors(init_r, init_g, init_b); - } -} diff --git a/intern/smoke/intern/tnt/jama_eig.h b/intern/smoke/intern/tnt/jama_eig.h deleted file mode 100644 index 8b1ac999798..00000000000 --- a/intern/smoke/intern/tnt/jama_eig.h +++ /dev/null @@ -1,1053 +0,0 @@ -/** \file - * \ingroup smoke - */ -#ifndef JAMA_EIG_H -#define JAMA_EIG_H - - -#include "tnt_array1d.h" -#include "tnt_array2d.h" -#include "tnt_math_utils.h" - -#include -// for min(), max() below - -#include -// for fabs() below - -using namespace TNT; -using namespace std; - -// NT debugging -//static int gEigenDebug=0; -//if(gEigenDebug) std::cerr<<"n="< - If A is symmetric, then A = V*D*V' where the eigenvalue matrix D is - diagonal and the eigenvector matrix V is orthogonal. That is, - the diagonal values of D are the eigenvalues, and - V*V' = I, where I is the identity matrix. The columns of V - represent the eigenvectors in the sense that A*V = V*D. - -

- If A is not symmetric, then the eigenvalue matrix D is block diagonal - with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, - a + i*b, in 2-by-2 blocks, [a, b; -b, a]. That is, if the complex - eigenvalues look like -

-
-          u + iv     .        .          .      .    .
-            .      u - iv     .          .      .    .
-            .        .      a + ib       .      .    .
-            .        .        .        a - ib   .    .
-            .        .        .          .      x    .
-            .        .        .          .      .    y
-
- then D looks like -
-
-            u        v        .          .      .    .
-           -v        u        .          .      .    . 
-            .        .        a          b      .    .
-            .        .       -b          a      .    .
-            .        .        .          .      x    .
-            .        .        .          .      .    y
-
- This keeps V a real matrix in both symmetric and non-symmetric - cases, and A*V = V*D. - - - -

- The matrix V may be badly - conditioned, or even singular, so the validity of the equation - A = V*D*inverse(V) depends upon the condition number of V. - -

- (Adapted from JAMA, a Java Matrix Library, developed by jointly - by the Mathworks and NIST; see http://math.nist.gov/javanumerics/jama). -**/ - -template -class Eigenvalue -{ - - - /** Row and column dimension (square matrix). */ - int n; - - int issymmetric; /* boolean*/ - - /** Arrays for internal storage of eigenvalues. */ - - TNT::Array1D d; /* real part */ - TNT::Array1D e; /* img part */ - - /** Array for internal storage of eigenvectors. */ - TNT::Array2D V; - - /** Array for internal storage of nonsymmetric Hessenberg form. - @serial internal storage of nonsymmetric Hessenberg form. - */ - TNT::Array2D H; - - - /** Working storage for nonsymmetric algorithm. - @serial working storage for nonsymmetric algorithm. - */ - TNT::Array1D ort; - - - // Symmetric Householder reduction to tridiagonal form. - - void tred2() { - - // This is derived from the Algol procedures tred2 by - // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for - // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutine in EISPACK. - - for (int j = 0; j < n; j++) { - d[j] = V[n-1][j]; - } - - // Householder reduction to tridiagonal form. - - for (int i = n-1; i > 0; i--) { - - // Scale to avoid under/overflow. - - Real scale = 0.0; - Real h = 0.0; - for (int k = 0; k < i; k++) { - scale = scale + fabs(d[k]); - } - if (scale == 0.0) { - e[i] = d[i-1]; - for (int j = 0; j < i; j++) { - d[j] = V[i-1][j]; - V[i][j] = 0.0; - V[j][i] = 0.0; - } - } else { - - // Generate Householder vector. - - for (int k = 0; k < i; k++) { - d[k] /= scale; - h += d[k] * d[k]; - } - Real f = d[i-1]; - Real g = sqrt(h); - if (f > 0) { - g = -g; - } - e[i] = scale * g; - h = h - f * g; - d[i-1] = f - g; - for (int j = 0; j < i; j++) { - e[j] = 0.0; - } - - // Apply similarity transformation to remaining columns. - - for (int j = 0; j < i; j++) { - f = d[j]; - V[j][i] = f; - g = e[j] + V[j][j] * f; - for (int k = j+1; k <= i-1; k++) { - g += V[k][j] * d[k]; - e[k] += V[k][j] * f; - } - e[j] = g; - } - f = 0.0; - for (int j = 0; j < i; j++) { - e[j] /= h; - f += e[j] * d[j]; - } - Real hh = f / (h + h); - for (int j = 0; j < i; j++) { - e[j] -= hh * d[j]; - } - for (int j = 0; j < i; j++) { - f = d[j]; - g = e[j]; - for (int k = j; k <= i-1; k++) { - V[k][j] -= (f * e[k] + g * d[k]); - } - d[j] = V[i-1][j]; - V[i][j] = 0.0; - } - } - d[i] = h; - } - - // Accumulate transformations. - - for (int i = 0; i < n-1; i++) { - V[n-1][i] = V[i][i]; - V[i][i] = 1.0; - Real h = d[i+1]; - if (h != 0.0) { - for (int k = 0; k <= i; k++) { - d[k] = V[k][i+1] / h; - } - for (int j = 0; j <= i; j++) { - Real g = 0.0; - for (int k = 0; k <= i; k++) { - g += V[k][i+1] * V[k][j]; - } - for (int k = 0; k <= i; k++) { - V[k][j] -= g * d[k]; - } - } - } - for (int k = 0; k <= i; k++) { - V[k][i+1] = 0.0; - } - } - for (int j = 0; j < n; j++) { - d[j] = V[n-1][j]; - V[n-1][j] = 0.0; - } - V[n-1][n-1] = 1.0; - e[0] = 0.0; - } - - // Symmetric tridiagonal QL algorithm. - - void tql2 () { - - // This is derived from the Algol procedures tql2, by - // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for - // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutine in EISPACK. - - for (int i = 1; i < n; i++) { - e[i-1] = e[i]; - } - e[n-1] = 0.0; - - Real f = 0.0; - Real tst1 = 0.0; - Real eps = pow(2.0,-52.0); - for (int l = 0; l < n; l++) { - - // Find small subdiagonal element - - tst1 = max(tst1,fabs(d[l]) + fabs(e[l])); - int m = l; - - // Original while-loop from Java code - while (m < n) { - if (fabs(e[m]) <= eps*tst1) { - break; - } - m++; - } - - - // If m == l, d[l] is an eigenvalue, - // otherwise, iterate. - - if (m > l) { - int iter = 0; - do { - iter = iter + 1; // (Could check iteration count here.) - - // Compute implicit shift - - Real g = d[l]; - Real p = (d[l+1] - g) / (2.0 * e[l]); - Real r = hypot(p,1.0); - if (p < 0) { - r = -r; - } - d[l] = e[l] / (p + r); - d[l+1] = e[l] * (p + r); - Real dl1 = d[l+1]; - Real h = g - d[l]; - for (int i = l+2; i < n; i++) { - d[i] -= h; - } - f = f + h; - - // Implicit QL transformation. - - p = d[m]; - Real c = 1.0; - Real c2 = c; - Real c3 = c; - Real el1 = e[l+1]; - Real s = 0.0; - Real s2 = 0.0; - for (int i = m-1; i >= l; i--) { - c3 = c2; - c2 = c; - s2 = s; - g = c * e[i]; - h = c * p; - r = hypot(p,e[i]); - e[i+1] = s * r; - s = e[i] / r; - c = p / r; - p = c * d[i] - s * g; - d[i+1] = h + s * (c * g + s * d[i]); - - // Accumulate transformation. - - for (int k = 0; k < n; k++) { - h = V[k][i+1]; - V[k][i+1] = s * V[k][i] + c * h; - V[k][i] = c * V[k][i] - s * h; - } - } - p = -s * s2 * c3 * el1 * e[l] / dl1; - e[l] = s * p; - d[l] = c * p; - - // Check for convergence. - - } while (fabs(e[l]) > eps*tst1); - } - d[l] = d[l] + f; - e[l] = 0.0; - } - - // Sort eigenvalues and corresponding vectors. - - for (int i = 0; i < n-1; i++) { - int k = i; - Real p = d[i]; - for (int j = i+1; j < n; j++) { - if (d[j] < p) { - k = j; - p = d[j]; - } - } - if (k != i) { - d[k] = d[i]; - d[i] = p; - for (int j = 0; j < n; j++) { - p = V[j][i]; - V[j][i] = V[j][k]; - V[j][k] = p; - } - } - } - } - - // Nonsymmetric reduction to Hessenberg form. - - void orthes () { - - // This is derived from the Algol procedures orthes and ortran, - // by Martin and Wilkinson, Handbook for Auto. Comp., - // Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutines in EISPACK. - - int low = 0; - int high = n-1; - - for (int m = low+1; m <= high-1; m++) { - - // Scale column. - - Real scale = 0.0; - for (int i = m; i <= high; i++) { - scale = scale + fabs(H[i][m-1]); - } - if (scale != 0.0) { - - // Compute Householder transformation. - - Real h = 0.0; - for (int i = high; i >= m; i--) { - ort[i] = H[i][m-1]/scale; - h += ort[i] * ort[i]; - } - Real g = sqrt(h); - if (ort[m] > 0) { - g = -g; - } - h = h - ort[m] * g; - ort[m] = ort[m] - g; - - // Apply Householder similarity transformation - // H = (I-u*u'/h)*H*(I-u*u')/h) - - for (int j = m; j < n; j++) { - Real f = 0.0; - for (int i = high; i >= m; i--) { - f += ort[i]*H[i][j]; - } - f = f/h; - for (int i = m; i <= high; i++) { - H[i][j] -= f*ort[i]; - } - } - - for (int i = 0; i <= high; i++) { - Real f = 0.0; - for (int j = high; j >= m; j--) { - f += ort[j]*H[i][j]; - } - f = f/h; - for (int j = m; j <= high; j++) { - H[i][j] -= f*ort[j]; - } - } - ort[m] = scale*ort[m]; - H[m][m-1] = scale*g; - } - } - - // Accumulate transformations (Algol's ortran). - - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - V[i][j] = (i == j ? 1.0 : 0.0); - } - } - - for (int m = high-1; m >= low+1; m--) { - if (H[m][m-1] != 0.0) { - for (int i = m+1; i <= high; i++) { - ort[i] = H[i][m-1]; - } - for (int j = m; j <= high; j++) { - Real g = 0.0; - for (int i = m; i <= high; i++) { - g += ort[i] * V[i][j]; - } - // Double division avoids possible underflow - g = (g / ort[m]) / H[m][m-1]; - for (int i = m; i <= high; i++) { - V[i][j] += g * ort[i]; - } - } - } - } - } - - - // Complex scalar division. - - Real cdivr, cdivi; - void cdiv(Real xr, Real xi, Real yr, Real yi) { - Real r,d; - if (fabs(yr) > fabs(yi)) { - r = yi/yr; - d = yr + r*yi; - cdivr = (xr + r*xi)/d; - cdivi = (xi - r*xr)/d; - } else { - r = yr/yi; - d = yi + r*yr; - cdivr = (r*xr + xi)/d; - cdivi = (r*xi - xr)/d; - } - } - - - // Nonsymmetric reduction from Hessenberg to real Schur form. - - void hqr2 () { - - // This is derived from the Algol procedure hqr2, - // by Martin and Wilkinson, Handbook for Auto. Comp., - // Vol.ii-Linear Algebra, and the corresponding - // Fortran subroutine in EISPACK. - - // Initialize - - int nn = this->n; - int n = nn-1; - int low = 0; - int high = nn-1; - Real eps = pow(2.0,-52.0); - Real exshift = 0.0; - Real p=0,q=0,r=0,s=0,z=0,t,w,x,y; - - // Store roots isolated by balanc and compute matrix norm - - Real norm = 0.0; - for (int i = 0; i < nn; i++) { - if ((i < low) || (i > high)) { - d[i] = H[i][i]; - e[i] = 0.0; - } - for (int j = max(i-1,0); j < nn; j++) { - norm = norm + fabs(H[i][j]); - } - } - - // Outer loop over eigenvalue index - - int iter = 0; - int totIter = 0; - while (n >= low) { - - // NT limit no. of iterations - totIter++; - if(totIter>100) { - //if(totIter>15) std::cout<<"!!!!iter ABORT !!!!!!! "< low) { - s = fabs(H[l-1][l-1]) + fabs(H[l][l]); - if (s == 0.0) { - s = norm; - } - if (fabs(H[l][l-1]) < eps * s) { - break; - } - l--; - } - - // Check for convergence - // One root found - - if (l == n) { - H[n][n] = H[n][n] + exshift; - d[n] = H[n][n]; - e[n] = 0.0; - n--; - iter = 0; - - // Two roots found - - } else if (l == n-1) { - w = H[n][n-1] * H[n-1][n]; - p = (H[n-1][n-1] - H[n][n]) / 2.0; - q = p * p + w; - z = sqrt(fabs(q)); - H[n][n] = H[n][n] + exshift; - H[n-1][n-1] = H[n-1][n-1] + exshift; - x = H[n][n]; - - // Real pair - - if (q >= 0) { - if (p >= 0) { - z = p + z; - } else { - z = p - z; - } - d[n-1] = x + z; - d[n] = d[n-1]; - if (z != 0.0) { - d[n] = x - w / z; - } - e[n-1] = 0.0; - e[n] = 0.0; - x = H[n][n-1]; - s = fabs(x) + fabs(z); - p = x / s; - q = z / s; - r = sqrt(p * p+q * q); - p = p / r; - q = q / r; - - // Row modification - - for (int j = n-1; j < nn; j++) { - z = H[n-1][j]; - H[n-1][j] = q * z + p * H[n][j]; - H[n][j] = q * H[n][j] - p * z; - } - - // Column modification - - for (int i = 0; i <= n; i++) { - z = H[i][n-1]; - H[i][n-1] = q * z + p * H[i][n]; - H[i][n] = q * H[i][n] - p * z; - } - - // Accumulate transformations - - for (int i = low; i <= high; i++) { - z = V[i][n-1]; - V[i][n-1] = q * z + p * V[i][n]; - V[i][n] = q * V[i][n] - p * z; - } - - // Complex pair - - } else { - d[n-1] = x + p; - d[n] = x + p; - e[n-1] = z; - e[n] = -z; - } - n = n - 2; - iter = 0; - - // No convergence yet - - } else { - - // Form shift - - x = H[n][n]; - y = 0.0; - w = 0.0; - if (l < n) { - y = H[n-1][n-1]; - w = H[n][n-1] * H[n-1][n]; - } - - // Wilkinson's original ad hoc shift - - if (iter == 10) { - exshift += x; - for (int i = low; i <= n; i++) { - H[i][i] -= x; - } - s = fabs(H[n][n-1]) + fabs(H[n-1][n-2]); - x = y = 0.75 * s; - w = -0.4375 * s * s; - } - - // MATLAB's new ad hoc shift - - if (iter == 30) { - s = (y - x) / 2.0; - s = s * s + w; - if (s > 0) { - s = sqrt(s); - if (y < x) { - s = -s; - } - s = x - w / ((y - x) / 2.0 + s); - for (int i = low; i <= n; i++) { - H[i][i] -= s; - } - exshift += s; - x = y = w = 0.964; - } - } - - iter = iter + 1; // (Could check iteration count here.) - - // Look for two consecutive small sub-diagonal elements - - int m = n-2; - while (m >= l) { - z = H[m][m]; - r = x - z; - s = y - z; - p = (r * s - w) / H[m+1][m] + H[m][m+1]; - q = H[m+1][m+1] - z - r - s; - r = H[m+2][m+1]; - s = fabs(p) + fabs(q) + fabs(r); - p = p / s; - q = q / s; - r = r / s; - if (m == l) { - break; - } - if (fabs(H[m][m-1]) * (fabs(q) + fabs(r)) < - eps * (fabs(p) * (fabs(H[m-1][m-1]) + fabs(z) + - fabs(H[m+1][m+1])))) { - break; - } - m--; - } - - for (int i = m+2; i <= n; i++) { - H[i][i-2] = 0.0; - if (i > m+2) { - H[i][i-3] = 0.0; - } - } - - // Double QR step involving rows l:n and columns m:n - - for (int k = m; k <= n-1; k++) { - int notlast = (k != n-1); - if (k != m) { - p = H[k][k-1]; - q = H[k+1][k-1]; - r = (notlast ? H[k+2][k-1] : 0.0); - x = fabs(p) + fabs(q) + fabs(r); - if (x != 0.0) { - p = p / x; - q = q / x; - r = r / x; - } - } - if (x == 0.0) { - break; - } - s = sqrt(p * p + q * q + r * r); - if (p < 0) { - s = -s; - } - if (s != 0) { - if (k != m) { - H[k][k-1] = -s * x; - } else if (l != m) { - H[k][k-1] = -H[k][k-1]; - } - p = p + s; - x = p / s; - y = q / s; - z = r / s; - q = q / p; - r = r / p; - - // Row modification - - for (int j = k; j < nn; j++) { - p = H[k][j] + q * H[k+1][j]; - if (notlast) { - p = p + r * H[k+2][j]; - H[k+2][j] = H[k+2][j] - p * z; - } - H[k][j] = H[k][j] - p * x; - H[k+1][j] = H[k+1][j] - p * y; - } - - // Column modification - - for (int i = 0; i <= min(n,k+3); i++) { - p = x * H[i][k] + y * H[i][k+1]; - if (notlast) { - p = p + z * H[i][k+2]; - H[i][k+2] = H[i][k+2] - p * r; - } - H[i][k] = H[i][k] - p; - H[i][k+1] = H[i][k+1] - p * q; - } - - // Accumulate transformations - - for (int i = low; i <= high; i++) { - p = x * V[i][k] + y * V[i][k+1]; - if (notlast) { - p = p + z * V[i][k+2]; - V[i][k+2] = V[i][k+2] - p * r; - } - V[i][k] = V[i][k] - p; - V[i][k+1] = V[i][k+1] - p * q; - } - } // (s != 0) - } // k loop - } // check convergence - } // while (n >= low) - //if(totIter>15) std::cout<<"!!!!iter "<= 0; n--) { - p = d[n]; - q = e[n]; - - // Real vector - - if (q == 0) { - int l = n; - H[n][n] = 1.0; - for (int i = n-1; i >= 0; i--) { - w = H[i][i] - p; - r = 0.0; - for (int j = l; j <= n; j++) { - r = r + H[i][j] * H[j][n]; - } - if (e[i] < 0.0) { - z = w; - s = r; - } else { - l = i; - if (e[i] == 0.0) { - if (w != 0.0) { - H[i][n] = -r / w; - } else { - H[i][n] = -r / (eps * norm); - } - - // Solve real equations - - } else { - x = H[i][i+1]; - y = H[i+1][i]; - q = (d[i] - p) * (d[i] - p) + e[i] * e[i]; - t = (x * s - z * r) / q; - H[i][n] = t; - if (fabs(x) > fabs(z)) { - H[i+1][n] = (-r - w * t) / x; - } else { - H[i+1][n] = (-s - y * t) / z; - } - } - - // Overflow control - - t = fabs(H[i][n]); - if ((eps * t) * t > 1) { - for (int j = i; j <= n; j++) { - H[j][n] = H[j][n] / t; - } - } - } - } - - // Complex vector - - } else if (q < 0) { - int l = n-1; - - // Last vector component imaginary so matrix is triangular - - if (fabs(H[n][n-1]) > fabs(H[n-1][n])) { - H[n-1][n-1] = q / H[n][n-1]; - H[n-1][n] = -(H[n][n] - p) / H[n][n-1]; - } else { - cdiv(0.0,-H[n-1][n],H[n-1][n-1]-p,q); - H[n-1][n-1] = cdivr; - H[n-1][n] = cdivi; - } - H[n][n-1] = 0.0; - H[n][n] = 1.0; - for (int i = n-2; i >= 0; i--) { - Real ra,sa,vr,vi; - ra = 0.0; - sa = 0.0; - for (int j = l; j <= n; j++) { - ra = ra + H[i][j] * H[j][n-1]; - sa = sa + H[i][j] * H[j][n]; - } - w = H[i][i] - p; - - if (e[i] < 0.0) { - z = w; - r = ra; - s = sa; - } else { - l = i; - if (e[i] == 0) { - cdiv(-ra,-sa,w,q); - H[i][n-1] = cdivr; - H[i][n] = cdivi; - } else { - - // Solve complex equations - - x = H[i][i+1]; - y = H[i+1][i]; - vr = (d[i] - p) * (d[i] - p) + e[i] * e[i] - q * q; - vi = (d[i] - p) * 2.0 * q; - if ((vr == 0.0) && (vi == 0.0)) { - vr = eps * norm * (fabs(w) + fabs(q) + - fabs(x) + fabs(y) + fabs(z)); - } - cdiv(x*r-z*ra+q*sa,x*s-z*sa-q*ra,vr,vi); - H[i][n-1] = cdivr; - H[i][n] = cdivi; - if (fabs(x) > (fabs(z) + fabs(q))) { - H[i+1][n-1] = (-ra - w * H[i][n-1] + q * H[i][n]) / x; - H[i+1][n] = (-sa - w * H[i][n] - q * H[i][n-1]) / x; - } else { - cdiv(-r-y*H[i][n-1],-s-y*H[i][n],z,q); - H[i+1][n-1] = cdivr; - H[i+1][n] = cdivi; - } - } - - // Overflow control - - t = max(fabs(H[i][n-1]),fabs(H[i][n])); - if ((eps * t) * t > 1) { - for (int j = i; j <= n; j++) { - H[j][n-1] = H[j][n-1] / t; - H[j][n] = H[j][n] / t; - } - } - } - } - } - } - - // Vectors of isolated roots - - for (int i = 0; i < nn; i++) { - if (i < low || i > high) { - for (int j = i; j < nn; j++) { - V[i][j] = H[i][j]; - } - } - } - - // Back transformation to get eigenvectors of original matrix - - for (int j = nn-1; j >= low; j--) { - for (int i = low; i <= high; i++) { - z = 0.0; - for (int k = low; k <= min(j,high); k++) { - z = z + V[i][k] * H[k][j]; - } - V[i][j] = z; - } - } - } - -public: - - - /** Check for symmetry, then construct the eigenvalue decomposition - @param A Square real (non-complex) matrix - */ - - Eigenvalue(const TNT::Array2D &A) { - n = A.dim2(); - V = Array2D(n,n); - d = Array1D(n); - e = Array1D(n); - - issymmetric = 1; - for (int j = 0; (j < n) && issymmetric; j++) { - for (int i = 0; (i < n) && issymmetric; i++) { - issymmetric = (A[i][j] == A[j][i]); - } - } - - if (issymmetric) { - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - V[i][j] = A[i][j]; - } - } - - // Tridiagonalize. - tred2(); - - // Diagonalize. - tql2(); - - } else { - H = TNT::Array2D(n,n); - ort = TNT::Array1D(n); - - for (int j = 0; j < n; j++) { - for (int i = 0; i < n; i++) { - H[i][j] = A[i][j]; - } - } - - // Reduce to Hessenberg form. - orthes(); - - // Reduce Hessenberg to real Schur form. - hqr2(); - } - } - - - /** Return the eigenvector matrix - @return V - */ - - void getV (TNT::Array2D &V_) { - V_ = V; - return; - } - - /** Return the real parts of the eigenvalues - @return real(diag(D)) - */ - - void getRealEigenvalues (TNT::Array1D &d_) { - d_ = d; - return ; - } - - /** Return the imaginary parts of the eigenvalues - in parameter e_. - - @pararm e_: new matrix with imaginary parts of the eigenvalues. - */ - void getImagEigenvalues (TNT::Array1D &e_) { - e_ = e; - return; - } - - -/** - Computes the block diagonal eigenvalue matrix. - If the original matrix A is not symmetric, then the eigenvalue - matrix D is block diagonal with the real eigenvalues in 1-by-1 - blocks and any complex eigenvalues, - a + i*b, in 2-by-2 blocks, [a, b; -b, a]. That is, if the complex - eigenvalues look like -

-
-          u + iv     .        .          .      .    .
-            .      u - iv     .          .      .    .
-            .        .      a + ib       .      .    .
-            .        .        .        a - ib   .    .
-            .        .        .          .      x    .
-            .        .        .          .      .    y
-
- then D looks like -
-
-            u        v        .          .      .    .
-           -v        u        .          .      .    . 
-            .        .        a          b      .    .
-            .        .       -b          a      .    .
-            .        .        .          .      x    .
-            .        .        .          .      .    y
-
- This keeps V a real matrix in both symmetric and non-symmetric - cases, and A*V = V*D. - - @param D: upon return, the matrix is filled with the block diagonal - eigenvalue matrix. - -*/ - void getD (TNT::Array2D &D) { - D = Array2D(n,n); - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - D[i][j] = 0.0; - } - D[i][i] = d[i]; - if (e[i] > 0) { - D[i][i+1] = e[i]; - } else if (e[i] < 0) { - D[i][i-1] = e[i]; - } - } - } -}; - -} //namespace JAMA - - -#endif -// JAMA_EIG_H diff --git a/intern/smoke/intern/tnt/jama_lu.h b/intern/smoke/intern/tnt/jama_lu.h deleted file mode 100644 index 7855c060eca..00000000000 --- a/intern/smoke/intern/tnt/jama_lu.h +++ /dev/null @@ -1,322 +0,0 @@ -/** \file - * \ingroup smoke - */ -#ifndef JAMA_LU_H -#define JAMA_LU_H - -#include "tnt.h" -#include -//for min(), max() below - -using namespace TNT; -using namespace std; - -namespace JAMA -{ - - /** LU Decomposition. -

- For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n - unit lower triangular matrix L, an n-by-n upper triangular matrix U, - and a permutation vector piv of length m so that A(piv,:) = L*U. - If m < n, then L is m-by-m and U is m-by-n. -

- The LU decompostion with pivoting always exists, even if the matrix is - singular, so the constructor will never fail. The primary use of the - LU decomposition is in the solution of square systems of simultaneous - linear equations. This will fail if isNonsingular() returns false. - */ -template -class LU -{ - - - - /* Array for internal storage of decomposition. */ - Array2D LU_; - int m, n, pivsign; - Array1D piv; - - - Array2D permute_copy(const Array2D &A, - const Array1D &piv, int j0, int j1) - { - int piv_length = piv.dim(); - - Array2D X(piv_length, j1-j0+1); - - - for (int i = 0; i < piv_length; i++) - for (int j = j0; j <= j1; j++) - X[i][j-j0] = A[piv[i]][j]; - - return X; - } - - Array1D permute_copy(const Array1D &A, - const Array1D &piv) - { - int piv_length = piv.dim(); - if (piv_length != A.dim()) - return Array1D(); - - Array1D x(piv_length); - - - for (int i = 0; i < piv_length; i++) - x[i] = A[piv[i]]; - - return x; - } - - - public : - - /** LU Decomposition - @param A Rectangular matrix - @return LU Decomposition object to access L, U and piv. - */ - - LU (const Array2D &A) : LU_(A.copy()), m(A.dim1()), n(A.dim2()), - piv(A.dim1()) - - { - - // Use a "left-looking", dot-product, Crout/Doolittle algorithm. - - - for (int i = 0; i < m; i++) { - piv[i] = i; - } - pivsign = 1; - Real *LUrowi = 0;; - Array1D LUcolj(m); - - // Outer loop. - - for (int j = 0; j < n; j++) { - - // Make a copy of the j-th column to localize references. - - for (int i = 0; i < m; i++) { - LUcolj[i] = LU_[i][j]; - } - - // Apply previous transformations. - - for (int i = 0; i < m; i++) { - LUrowi = LU_[i]; - - // Most of the time is spent in the following dot product. - - int kmax = min(i,j); - double s = 0.0; - for (int k = 0; k < kmax; k++) { - s += LUrowi[k]*LUcolj[k]; - } - - LUrowi[j] = LUcolj[i] -= s; - } - - // Find pivot and exchange if necessary. - - int p = j; - for (int i = j+1; i < m; i++) { - if (abs(LUcolj[i]) > abs(LUcolj[p])) { - p = i; - } - } - if (p != j) { - int k=0; - for (k = 0; k < n; k++) { - double t = LU_[p][k]; - LU_[p][k] = LU_[j][k]; - LU_[j][k] = t; - } - k = piv[p]; - piv[p] = piv[j]; - piv[j] = k; - pivsign = -pivsign; - } - - // Compute multipliers. - - if ((j < m) && (LU_[j][j] != 0.0)) { - for (int i = j+1; i < m; i++) { - LU_[i][j] /= LU_[j][j]; - } - } - } - } - - - /** Is the matrix nonsingular? - @return 1 (true) if upper triangular factor U (and hence A) - is nonsingular, 0 otherwise. - */ - - int isNonsingular () { - for (int j = 0; j < n; j++) { - if (LU_[j][j] == 0) - return 0; - } - return 1; - } - - /** Return lower triangular factor - @return L - */ - - Array2D getL () { - Array2D L_(m,n); - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - if (i > j) { - L_[i][j] = LU_[i][j]; - } else if (i == j) { - L_[i][j] = 1.0; - } else { - L_[i][j] = 0.0; - } - } - } - return L_; - } - - /** Return upper triangular factor - @return U portion of LU factorization. - */ - - Array2D getU () { - Array2D U_(n,n); - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - if (i <= j) { - U_[i][j] = LU_[i][j]; - } else { - U_[i][j] = 0.0; - } - } - } - return U_; - } - - /** Return pivot permutation vector - @return piv - */ - - Array1D getPivot () { - return piv; - } - - - /** Compute determinant using LU factors. - @return determinant of A, or 0 if A is not square. - */ - - Real det () { - if (m != n) { - return Real(0); - } - Real d = Real(pivsign); - for (int j = 0; j < n; j++) { - d *= LU_[j][j]; - } - return d; - } - - /** Solve A*X = B - @param B A Matrix with as many rows as A and any number of columns. - @return X so that L*U*X = B(piv,:), if B is nonconformant, returns - 0x0 (null) array. - */ - - Array2D solve (const Array2D &B) - { - - /* Dimensions: A is mxn, X is nxk, B is mxk */ - - if (B.dim1() != m) { - return Array2D(0,0); - } - if (!isNonsingular()) { - return Array2D(0,0); - } - - // Copy right hand side with pivoting - int nx = B.dim2(); - - - Array2D X = permute_copy(B, piv, 0, nx-1); - - // Solve L*Y = B(piv,:) - for (int k = 0; k < n; k++) { - for (int i = k+1; i < n; i++) { - for (int j = 0; j < nx; j++) { - X[i][j] -= X[k][j]*LU_[i][k]; - } - } - } - // Solve U*X = Y; - for (int k = n-1; k >= 0; k--) { - for (int j = 0; j < nx; j++) { - X[k][j] /= LU_[k][k]; - } - for (int i = 0; i < k; i++) { - for (int j = 0; j < nx; j++) { - X[i][j] -= X[k][j]*LU_[i][k]; - } - } - } - return X; - } - - - /** Solve A*x = b, where x and b are vectors of length equal - to the number of rows in A. - - @param b a vector (Array1D> of length equal to the first dimension - of A. - @return x a vector (Array1D> so that L*U*x = b(piv), if B is nonconformant, - returns 0x0 (null) array. - */ - - Array1D solve (const Array1D &b) - { - - /* Dimensions: A is mxn, X is nxk, B is mxk */ - - if (b.dim1() != m) { - return Array1D(); - } - if (!isNonsingular()) { - return Array1D(); - } - - - Array1D x = permute_copy(b, piv); - - // Solve L*Y = B(piv) - for (int k = 0; k < n; k++) { - for (int i = k+1; i < n; i++) { - x[i] -= x[k]*LU_[i][k]; - } - } - - // Solve U*X = Y; - for (int k = n-1; k >= 0; k--) { - x[k] /= LU_[k][k]; - for (int i = 0; i < k; i++) - x[i] -= x[k]*LU_[i][k]; - } - - - return x; - } - -}; /* class LU */ - -} /* namespace JAMA */ - -#endif -/* JAMA_LU_H */ diff --git a/intern/smoke/intern/tnt/tnt.h b/intern/smoke/intern/tnt/tnt.h deleted file mode 100644 index ef9de784bb3..00000000000 --- a/intern/smoke/intern/tnt/tnt.h +++ /dev/null @@ -1,67 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT): Linear Algebra Module -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - -#ifndef TNT_H -#define TNT_H - - - -//--------------------------------------------------------------------- -// Define this macro if you want TNT to track some of the out-of-bounds -// indexing. This can encur a small run-time overhead, but is recommended -// while developing code. It can be turned off for production runs. -// -// #define TNT_BOUNDS_CHECK -//--------------------------------------------------------------------- -// - -//#define TNT_BOUNDS_CHECK - - - -#include "tnt_version.h" -#include "tnt_math_utils.h" -#include "tnt_array1d.h" -#include "tnt_array2d.h" -#include "tnt_array3d.h" -#include "tnt_array1d_utils.h" -#include "tnt_array2d_utils.h" -#include "tnt_array3d_utils.h" - -#include "tnt_fortran_array1d.h" -#include "tnt_fortran_array2d.h" -#include "tnt_fortran_array3d.h" -#include "tnt_fortran_array1d_utils.h" -#include "tnt_fortran_array2d_utils.h" -#include "tnt_fortran_array3d_utils.h" - -#include "tnt_sparse_matrix_csr.h" - -#include "tnt_stopwatch.h" -#include "tnt_subscript.h" -#include "tnt_vec.h" -#include "tnt_cmat.h" - - -#endif -// TNT_H diff --git a/intern/smoke/intern/tnt/tnt_array1d.h b/intern/smoke/intern/tnt/tnt_array1d.h deleted file mode 100644 index 999cbd08d24..00000000000 --- a/intern/smoke/intern/tnt/tnt_array1d.h +++ /dev/null @@ -1,281 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef TNT_ARRAY1D_H -#define TNT_ARRAY1D_H - -//#include -#include - -#ifdef TNT_BOUNDS_CHECK -#include -#endif - - -#include "tnt_i_refvec.h" - -namespace TNT -{ - -template -class Array1D -{ - - private: - - /* ... */ - i_refvec v_; - int n_; - T* data_; /* this normally points to v_.begin(), but - * could also point to a portion (subvector) - * of v_. - */ - - void copy_(T* p, const T* q, int len) const; - void set_(T* begin, T* end, const T& val); - - - public: - - typedef T value_type; - - - Array1D(); - explicit Array1D(int n); - Array1D(int n, const T &a); - Array1D(int n, T *a); - inline Array1D(const Array1D &A); - inline operator T*(); - inline operator const T*(); - inline Array1D & operator=(const T &a); - inline Array1D & operator=(const Array1D &A); - inline Array1D & ref(const Array1D &A); - Array1D copy() const; - Array1D & inject(const Array1D & A); - inline T& operator[](int i); - inline const T& operator[](int i) const; - inline int dim1() const; - inline int dim() const; - ~Array1D(); - - - /* ... extended interface ... */ - - inline int ref_count() const; - inline Array1D subarray(int i0, int i1); - -}; - - - - -template -Array1D::Array1D() : v_(), n_(0), data_(0) {} - -template -Array1D::Array1D(const Array1D &A) : v_(A.v_), n_(A.n_), - data_(A.data_) -{ -#ifdef TNT_DEBUG - std::cout << "Created Array1D(const Array1D &A) \n"; -#endif - -} - - -template -Array1D::Array1D(int n) : v_(n), n_(n), data_(v_.begin()) -{ -#ifdef TNT_DEBUG - std::cout << "Created Array1D(int n) \n"; -#endif -} - -template -Array1D::Array1D(int n, const T &val) : v_(n), n_(n), data_(v_.begin()) -{ -#ifdef TNT_DEBUG - std::cout << "Created Array1D(int n, const T& val) \n"; -#endif - set_(data_, data_+ n, val); - -} - -template -Array1D::Array1D(int n, T *a) : v_(a), n_(n) , data_(v_.begin()) -{ -#ifdef TNT_DEBUG - std::cout << "Created Array1D(int n, T* a) \n"; -#endif -} - -template -inline Array1D::operator T*() -{ - return &(v_[0]); -} - - -template -inline Array1D::operator const T*() -{ - return &(v_[0]); -} - - - -template -inline T& Array1D::operator[](int i) -{ -#ifdef TNT_BOUNDS_CHECK - assert(i>= 0); - assert(i < n_); -#endif - return data_[i]; -} - -template -inline const T& Array1D::operator[](int i) const -{ -#ifdef TNT_BOUNDS_CHECK - assert(i>= 0); - assert(i < n_); -#endif - return data_[i]; -} - - - - -template -Array1D & Array1D::operator=(const T &a) -{ - set_(data_, data_+n_, a); - return *this; -} - -template -Array1D Array1D::copy() const -{ - Array1D A( n_); - copy_(A.data_, data_, n_); - - return A; -} - - -template -Array1D & Array1D::inject(const Array1D &A) -{ - if (A.n_ == n_) - copy_(data_, A.data_, n_); - - return *this; -} - - - - - -template -Array1D & Array1D::ref(const Array1D &A) -{ - if (this != &A) - { - v_ = A.v_; /* operator= handles the reference counting. */ - n_ = A.n_; - data_ = A.data_; - - } - return *this; -} - -template -Array1D & Array1D::operator=(const Array1D &A) -{ - return ref(A); -} - -template -inline int Array1D::dim1() const { return n_; } - -template -inline int Array1D::dim() const { return n_; } - -template -Array1D::~Array1D() {} - - -/* ............................ exented interface ......................*/ - -template -inline int Array1D::ref_count() const -{ - return v_.ref_count(); -} - -template -inline Array1D Array1D::subarray(int i0, int i1) -{ - if ((i0 > 0) && (i1 < n_) || (i0 <= i1)) - { - Array1D X(*this); /* create a new instance of this array. */ - X.n_ = i1-i0+1; - X.data_ += i0; - - return X; - } - else - { - return Array1D(); - } -} - - -/* private internal functions */ - - -template -void Array1D::set_(T* begin, T* end, const T& a) -{ - for (T* p=begin; p -void Array1D::copy_(T* p, const T* q, int len) const -{ - T *end = p + len; - while (p -#include - -namespace TNT -{ - - -template -std::ostream& operator<<(std::ostream &s, const Array1D &A) -{ - int N=A.dim1(); - -#ifdef TNT_DEBUG - s << "addr: " << (void *) &A[0] << "\n"; -#endif - s << N << "\n"; - for (int j=0; j -std::istream& operator>>(std::istream &s, Array1D &A) -{ - int N; - s >> N; - - Array1D B(N); - for (int i=0; i> B[i]; - A = B; - return s; -} - - - -template -Array1D operator+(const Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Array1D(); - - else - { - Array1D C(n); - - for (int i=0; i -Array1D operator-(const Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Array1D(); - - else - { - Array1D C(n); - - for (int i=0; i -Array1D operator*(const Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Array1D(); - - else - { - Array1D C(n); - - for (int i=0; i -Array1D operator/(const Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Array1D(); - - else - { - Array1D C(n); - - for (int i=0; i -Array1D& operator+=(Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=0; i -Array1D& operator-=(Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=0; i -Array1D& operator*=(Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=0; i -Array1D& operator/=(Array1D &A, const Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=0; i -#include -#ifdef TNT_BOUNDS_CHECK -#include -#endif - -#include "tnt_array1d.h" - -namespace TNT -{ - -template -class Array2D -{ - - - private: - - - - Array1D data_; - Array1D v_; - int m_; - int n_; - - public: - - typedef T value_type; - Array2D(); - Array2D(int m, int n); - Array2D(int m, int n, T *a); - Array2D(int m, int n, const T &a); - inline Array2D(const Array2D &A); - inline operator T**(); - inline operator const T**(); - inline Array2D & operator=(const T &a); - inline Array2D & operator=(const Array2D &A); - inline Array2D & ref(const Array2D &A); - Array2D copy() const; - Array2D & inject(const Array2D & A); - inline T* operator[](int i); - inline const T* operator[](int i) const; - inline int dim1() const; - inline int dim2() const; - ~Array2D(); - - /* extended interface (not part of the standard) */ - - - inline int ref_count(); - inline int ref_count_data(); - inline int ref_count_dim1(); - Array2D subarray(int i0, int i1, int j0, int j1); - -}; - - -template -Array2D::Array2D() : data_(), v_(), m_(0), n_(0) {} - -template -Array2D::Array2D(const Array2D &A) : data_(A.data_), v_(A.v_), - m_(A.m_), n_(A.n_) {} - - - - -template -Array2D::Array2D(int m, int n) : data_(m*n), v_(m), m_(m), n_(n) -{ - if (m>0 && n>0) - { - T* p = &(data_[0]); - for (int i=0; i -Array2D::Array2D(int m, int n, const T &val) : data_(m*n), v_(m), - m_(m), n_(n) -{ - if (m>0 && n>0) - { - data_ = val; - T* p = &(data_[0]); - for (int i=0; i -Array2D::Array2D(int m, int n, T *a) : data_(m*n, a), v_(m), m_(m), n_(n) -{ - if (m>0 && n>0) - { - T* p = &(data_[0]); - - for (int i=0; i -inline T* Array2D::operator[](int i) -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 0); - assert(i < m_); -#endif - -return v_[i]; - -} - - -template -inline const T* Array2D::operator[](int i) const -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 0); - assert(i < m_); -#endif - -return v_[i]; - -} - -template -Array2D & Array2D::operator=(const T &a) -{ - /* non-optimzied, but will work with subarrays in future verions */ - - for (int i=0; i -Array2D Array2D::copy() const -{ - Array2D A(m_, n_); - - for (int i=0; i -Array2D & Array2D::inject(const Array2D &A) -{ - if (A.m_ == m_ && A.n_ == n_) - { - for (int i=0; i -Array2D & Array2D::ref(const Array2D &A) -{ - if (this != &A) - { - v_ = A.v_; - data_ = A.data_; - m_ = A.m_; - n_ = A.n_; - - } - return *this; -} - - - -template -Array2D & Array2D::operator=(const Array2D &A) -{ - return ref(A); -} - -template -inline int Array2D::dim1() const { return m_; } - -template -inline int Array2D::dim2() const { return n_; } - - -template -Array2D::~Array2D() {} - - - - -template -inline Array2D::operator T**() -{ - return &(v_[0]); -} -template -inline Array2D::operator const T**() -{ - return &(v_[0]); -} - -/* ............... extended interface ............... */ -/** - Create a new view to a subarray defined by the boundaries - [i0][i0] and [i1][j1]. The size of the subarray is - (i1-i0) by (j1-j0). If either of these lengths are zero - or negative, the subarray view is null. - -*/ -template -Array2D Array2D::subarray(int i0, int i1, int j0, int j1) -{ - Array2D A; - int m = i1-i0+1; - int n = j1-j0+1; - - /* if either length is zero or negative, this is an invalide - subarray. return a null view. - */ - if (m<1 || n<1) - return A; - - A.data_ = data_; - A.m_ = m; - A.n_ = n; - A.v_ = Array1D(m); - T* p = &(data_[0]) + i0 * n_ + j0; - for (int i=0; i -inline int Array2D::ref_count() -{ - return ref_count_data(); -} - - - -template -inline int Array2D::ref_count_data() -{ - return data_.ref_count(); -} - -template -inline int Array2D::ref_count_dim1() -{ - return v_.ref_count(); -} - - - - -} /* namespace TNT */ - -#endif -/* TNT_ARRAY2D_H */ - diff --git a/intern/smoke/intern/tnt/tnt_array2d_utils.h b/intern/smoke/intern/tnt/tnt_array2d_utils.h deleted file mode 100644 index 63f98073506..00000000000 --- a/intern/smoke/intern/tnt/tnt_array2d_utils.h +++ /dev/null @@ -1,290 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - -#ifndef TNT_ARRAY2D_UTILS_H -#define TNT_ARRAY2D_UTILS_H - -#include -#include - -namespace TNT -{ - - -template -std::ostream& operator<<(std::ostream &s, const Array2D &A) -{ - int M=A.dim1(); - int N=A.dim2(); - - s << M << " " << N << "\n"; - - for (int i=0; i -std::istream& operator>>(std::istream &s, Array2D &A) -{ - - int M, N; - - s >> M >> N; - - Array2D B(M,N); - - for (int i=0; i> B[i][j]; - } - - A = B; - return s; -} - - -template -Array2D operator+(const Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Array2D(); - - else - { - Array2D C(m,n); - - for (int i=0; i -Array2D operator-(const Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Array2D(); - - else - { - Array2D C(m,n); - - for (int i=0; i -Array2D operator*(const Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Array2D(); - - else - { - Array2D C(m,n); - - for (int i=0; i -Array2D operator/(const Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Array2D(); - - else - { - Array2D C(m,n); - - for (int i=0; i -Array2D& operator+=(Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=0; i -Array2D& operator-=(Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=0; i -Array2D& operator*=(Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=0; i -Array2D& operator/=(Array2D &A, const Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=0; i -Array2D matmult(const Array2D &A, const Array2D &B) -{ - if (A.dim2() != B.dim1()) - return Array2D(); - - int M = A.dim1(); - int N = A.dim2(); - int K = B.dim2(); - - Array2D C(M,K); - - for (int i=0; i -#include -#ifdef TNT_BOUNDS_CHECK -#include -#endif - -#include "tnt_array1d.h" -#include "tnt_array2d.h" - -namespace TNT -{ - -template -class Array3D -{ - - - private: - Array1D data_; - Array2D v_; - int m_; - int n_; - int g_; - - - public: - - typedef T value_type; - - Array3D(); - Array3D(int m, int n, int g); - Array3D(int m, int n, int g, T val); - Array3D(int m, int n, int g, T *a); - - inline operator T***(); - inline operator const T***(); - inline Array3D(const Array3D &A); - inline Array3D & operator=(const T &a); - inline Array3D & operator=(const Array3D &A); - inline Array3D & ref(const Array3D &A); - Array3D copy() const; - Array3D & inject(const Array3D & A); - - inline T** operator[](int i); - inline const T* const * operator[](int i) const; - inline int dim1() const; - inline int dim2() const; - inline int dim3() const; - ~Array3D(); - - /* extended interface */ - - inline int ref_count(){ return data_.ref_count(); } - Array3D subarray(int i0, int i1, int j0, int j1, - int k0, int k1); -}; - -template -Array3D::Array3D() : data_(), v_(), m_(0), n_(0) {} - -template -Array3D::Array3D(const Array3D &A) : data_(A.data_), - v_(A.v_), m_(A.m_), n_(A.n_), g_(A.g_) -{ -} - - - -template -Array3D::Array3D(int m, int n, int g) : data_(m*n*g), v_(m,n), - m_(m), n_(n), g_(g) -{ - - if (m>0 && n>0 && g>0) - { - T* p = & (data_[0]); - int ng = n_*g_; - - for (int i=0; i -Array3D::Array3D(int m, int n, int g, T val) : data_(m*n*g, val), - v_(m,n), m_(m), n_(n), g_(g) -{ - if (m>0 && n>0 && g>0) - { - - T* p = & (data_[0]); - int ng = n_*g_; - - for (int i=0; i -Array3D::Array3D(int m, int n, int g, T* a) : - data_(m*n*g, a), v_(m,n), m_(m), n_(n), g_(g) -{ - - if (m>0 && n>0 && g>0) - { - T* p = & (data_[0]); - int ng = n_*g_; - - for (int i=0; i -inline T** Array3D::operator[](int i) -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 0); - assert(i < m_); -#endif - -return v_[i]; - -} - -template -inline const T* const * Array3D::operator[](int i) const -{ return v_[i]; } - -template -Array3D & Array3D::operator=(const T &a) -{ - for (int i=0; i -Array3D Array3D::copy() const -{ - Array3D A(m_, n_, g_); - for (int i=0; i -Array3D & Array3D::inject(const Array3D &A) -{ - if (A.m_ == m_ && A.n_ == n_ && A.g_ == g_) - - for (int i=0; i -Array3D & Array3D::ref(const Array3D &A) -{ - if (this != &A) - { - m_ = A.m_; - n_ = A.n_; - g_ = A.g_; - v_ = A.v_; - data_ = A.data_; - } - return *this; -} - -template -Array3D & Array3D::operator=(const Array3D &A) -{ - return ref(A); -} - - -template -inline int Array3D::dim1() const { return m_; } - -template -inline int Array3D::dim2() const { return n_; } - -template -inline int Array3D::dim3() const { return g_; } - - - -template -Array3D::~Array3D() {} - -template -inline Array3D::operator T***() -{ - return v_; -} - - -template -inline Array3D::operator const T***() -{ - return v_; -} - -/* extended interface */ -template -Array3D Array3D::subarray(int i0, int i1, int j0, - int j1, int k0, int k1) -{ - - /* check that ranges are valid. */ - if (!( 0 <= i0 && i0 <= i1 && i1 < m_ && - 0 <= j0 && j0 <= j1 && j1 < n_ && - 0 <= k0 && k0 <= k1 && k1 < g_)) - return Array3D(); /* null array */ - - - Array3D A; - A.data_ = data_; - A.m_ = i1-i0+1; - A.n_ = j1-j0+1; - A.g_ = k1-k0+1; - A.v_ = Array2D(A.m_,A.n_); - T* p = &(data_[0]) + i0*n_*g_ + j0*g_ + k0; - - for (int i=0; i -#include - -namespace TNT -{ - - -template -std::ostream& operator<<(std::ostream &s, const Array3D &A) -{ - int M=A.dim1(); - int N=A.dim2(); - int K=A.dim3(); - - s << M << " " << N << " " << K << "\n"; - - for (int i=0; i -std::istream& operator>>(std::istream &s, Array3D &A) -{ - - int M, N, K; - - s >> M >> N >> K; - - Array3D B(M,N,K); - - for (int i=0; i> B[i][j][k]; - - A = B; - return s; -} - - - -template -Array3D operator+(const Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Array3D(); - - else - { - Array3D C(m,n,p); - - for (int i=0; i -Array3D operator-(const Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Array3D(); - - else - { - Array3D C(m,n,p); - - for (int i=0; i -Array3D operator*(const Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Array3D(); - - else - { - Array3D C(m,n,p); - - for (int i=0; i -Array3D operator/(const Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Array3D(); - - else - { - Array3D C(m,n,p); - - for (int i=0; i -Array3D& operator+=(Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=0; i -Array3D& operator-=(Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=0; i -Array3D& operator*=(Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=0; i -Array3D& operator/=(Array3D &A, const Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=0; i -#include -#include -#include - -namespace TNT -{ - - -template -class Matrix -{ - - - public: - - typedef Subscript size_type; - typedef T value_type; - typedef T element_type; - typedef T* pointer; - typedef T* iterator; - typedef T& reference; - typedef const T* const_iterator; - typedef const T& const_reference; - - Subscript lbound() const { return 1;} - - protected: - Subscript m_; - Subscript n_; - Subscript mn_; // total size - T* v_; - T** row_; - T* vm1_ ; // these point to the same data, but are 1-based - T** rowm1_; - - // internal helper function to create the array - // of row pointers - - void initialize(Subscript M, Subscript N) - { - mn_ = M*N; - m_ = M; - n_ = N; - - v_ = new T[mn_]; - row_ = new T*[M]; - rowm1_ = new T*[M]; - - assert(v_ != NULL); - assert(row_ != NULL); - assert(rowm1_ != NULL); - - T* p = v_; - vm1_ = v_ - 1; - for (Subscript i=0; i &A) - { - initialize(A.m_, A.n_); - copy(A.v_); - } - - Matrix(Subscript M, Subscript N, const T& value = T()) - { - initialize(M,N); - set(value); - } - - Matrix(Subscript M, Subscript N, const T* v) - { - initialize(M,N); - copy(v); - } - - Matrix(Subscript M, Subscript N, const char *s) - { - initialize(M,N); - //std::istrstream ins(s); - std::istringstream ins(s); - - Subscript i, j; - - for (i=0; i> row_[i][j]; - } - - // destructor - // - ~Matrix() - { - destroy(); - } - - - // reallocating - // - Matrix& newsize(Subscript M, Subscript N) - { - if (num_rows() == M && num_cols() == N) - return *this; - - destroy(); - initialize(M,N); - - return *this; - } - - - - - // assignments - // - Matrix& operator=(const Matrix &A) - { - if (v_ == A.v_) - return *this; - - if (m_ == A.m_ && n_ == A.n_) // no need to re-alloc - copy(A.v_); - - else - { - destroy(); - initialize(A.m_, A.n_); - copy(A.v_); - } - - return *this; - } - - Matrix& operator=(const T& scalar) - { - set(scalar); - return *this; - } - - - Subscript dim(Subscript d) const - { -#ifdef TNT_BOUNDS_CHECK - assert( d >= 1); - assert( d <= 2); -#endif - return (d==1) ? m_ : ((d==2) ? n_ : 0); - } - - Subscript num_rows() const { return m_; } - Subscript num_cols() const { return n_; } - - - - - inline T* operator[](Subscript i) - { -#ifdef TNT_BOUNDS_CHECK - assert(0<=i); - assert(i < m_) ; -#endif - return row_[i]; - } - - inline const T* operator[](Subscript i) const - { -#ifdef TNT_BOUNDS_CHECK - assert(0<=i); - assert(i < m_) ; -#endif - return row_[i]; - } - - inline reference operator()(Subscript i) - { -#ifdef TNT_BOUNDS_CHECK - assert(1<=i); - assert(i <= mn_) ; -#endif - return vm1_[i]; - } - - inline const_reference operator()(Subscript i) const - { -#ifdef TNT_BOUNDS_CHECK - assert(1<=i); - assert(i <= mn_) ; -#endif - return vm1_[i]; - } - - - - inline reference operator()(Subscript i, Subscript j) - { -#ifdef TNT_BOUNDS_CHECK - assert(1<=i); - assert(i <= m_) ; - assert(1<=j); - assert(j <= n_); -#endif - return rowm1_[i][j]; - } - - - - inline const_reference operator() (Subscript i, Subscript j) const - { -#ifdef TNT_BOUNDS_CHECK - assert(1<=i); - assert(i <= m_) ; - assert(1<=j); - assert(j <= n_); -#endif - return rowm1_[i][j]; - } - - - - -}; - - -/* *************************** I/O ********************************/ - -template -std::ostream& operator<<(std::ostream &s, const Matrix &A) -{ - Subscript M=A.num_rows(); - Subscript N=A.num_cols(); - - s << M << " " << N << "\n"; - - for (Subscript i=0; i -std::istream& operator>>(std::istream &s, Matrix &A) -{ - - Subscript M, N; - - s >> M >> N; - - if ( !(M == A.num_rows() && N == A.num_cols() )) - { - A.newsize(M,N); - } - - - for (Subscript i=0; i> A[i][j]; - } - - - return s; -} - -// *******************[ basic matrix algorithms ]*************************** - - -template -Matrix operator+(const Matrix &A, - const Matrix &B) -{ - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - - assert(M==B.num_rows()); - assert(N==B.num_cols()); - - Matrix tmp(M,N); - Subscript i,j; - - for (i=0; i -Matrix operator-(const Matrix &A, - const Matrix &B) -{ - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - - assert(M==B.num_rows()); - assert(N==B.num_cols()); - - Matrix tmp(M,N); - Subscript i,j; - - for (i=0; i -Matrix mult_element(const Matrix &A, - const Matrix &B) -{ - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - - assert(M==B.num_rows()); - assert(N==B.num_cols()); - - Matrix tmp(M,N); - Subscript i,j; - - for (i=0; i -Matrix transpose(const Matrix &A) -{ - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - - Matrix S(N,M); - Subscript i, j; - - for (i=0; i -inline Matrix matmult(const Matrix &A, - const Matrix &B) -{ - -#ifdef TNT_BOUNDS_CHECK - assert(A.num_cols() == B.num_rows()); -#endif - - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - Subscript K = B.num_cols(); - - Matrix tmp(M,K); - T sum; - - for (Subscript i=0; i -inline Matrix operator*(const Matrix &A, - const Matrix &B) -{ - return matmult(A,B); -} - -template -inline int matmult(Matrix& C, const Matrix &A, - const Matrix &B) -{ - - assert(A.num_cols() == B.num_rows()); - - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - Subscript K = B.num_cols(); - - C.newsize(M,K); - - T sum; - - const T* row_i; - const T* col_k; - - for (Subscript i=0; i -Vector matmult(const Matrix &A, const Vector &x) -{ - -#ifdef TNT_BOUNDS_CHECK - assert(A.num_cols() == x.dim()); -#endif - - Subscript M = A.num_rows(); - Subscript N = A.num_cols(); - - Vector tmp(M); - T sum; - - for (Subscript i=0; i -inline Vector operator*(const Matrix &A, const Vector &x) -{ - return matmult(A,x); -} - -} // namespace TNT - -#endif -// CMAT_H diff --git a/intern/smoke/intern/tnt/tnt_fortran_array1d.h b/intern/smoke/intern/tnt/tnt_fortran_array1d.h deleted file mode 100644 index 45a764cf3e0..00000000000 --- a/intern/smoke/intern/tnt/tnt_fortran_array1d.h +++ /dev/null @@ -1,270 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef TNT_FORTRAN_ARRAY1D_H -#define TNT_FORTRAN_ARRAY1D_H - -#include -#include - -#ifdef TNT_BOUNDS_CHECK -#include -#endif - - -#include "tnt_i_refvec.h" - -namespace TNT -{ - -template -class Fortran_Array1D -{ - - private: - - i_refvec v_; - int n_; - T* data_; /* this normally points to v_.begin(), but - * could also point to a portion (subvector) - * of v_. - */ - - void initialize_(int n); - void copy_(T* p, const T* q, int len) const; - void set_(T* begin, T* end, const T& val); - - - public: - - typedef T value_type; - - - Fortran_Array1D(); - explicit Fortran_Array1D(int n); - Fortran_Array1D(int n, const T &a); - Fortran_Array1D(int n, T *a); - inline Fortran_Array1D(const Fortran_Array1D &A); - inline Fortran_Array1D & operator=(const T &a); - inline Fortran_Array1D & operator=(const Fortran_Array1D &A); - inline Fortran_Array1D & ref(const Fortran_Array1D &A); - Fortran_Array1D copy() const; - Fortran_Array1D & inject(const Fortran_Array1D & A); - inline T& operator()(int i); - inline const T& operator()(int i) const; - inline int dim1() const; - inline int dim() const; - ~Fortran_Array1D(); - - - /* ... extended interface ... */ - - inline int ref_count() const; - inline Fortran_Array1D subarray(int i0, int i1); - -}; - - - - -template -Fortran_Array1D::Fortran_Array1D() : v_(), n_(0), data_(0) {} - -template -Fortran_Array1D::Fortran_Array1D(const Fortran_Array1D &A) : v_(A.v_), n_(A.n_), - data_(A.data_) -{ -#ifdef TNT_DEBUG - std::cout << "Created Fortran_Array1D(const Fortran_Array1D &A) \n"; -#endif - -} - - -template -Fortran_Array1D::Fortran_Array1D(int n) : v_(n), n_(n), data_(v_.begin()) -{ -#ifdef TNT_DEBUG - std::cout << "Created Fortran_Array1D(int n) \n"; -#endif -} - -template -Fortran_Array1D::Fortran_Array1D(int n, const T &val) : v_(n), n_(n), data_(v_.begin()) -{ -#ifdef TNT_DEBUG - std::cout << "Created Fortran_Array1D(int n, const T& val) \n"; -#endif - set_(data_, data_+ n, val); - -} - -template -Fortran_Array1D::Fortran_Array1D(int n, T *a) : v_(a), n_(n) , data_(v_.begin()) -{ -#ifdef TNT_DEBUG - std::cout << "Created Fortran_Array1D(int n, T* a) \n"; -#endif -} - -template -inline T& Fortran_Array1D::operator()(int i) -{ -#ifdef TNT_BOUNDS_CHECK - assert(i>= 1); - assert(i <= n_); -#endif - return data_[i-1]; -} - -template -inline const T& Fortran_Array1D::operator()(int i) const -{ -#ifdef TNT_BOUNDS_CHECK - assert(i>= 1); - assert(i <= n_); -#endif - return data_[i-1]; -} - - - - -template -Fortran_Array1D & Fortran_Array1D::operator=(const T &a) -{ - set_(data_, data_+n_, a); - return *this; -} - -template -Fortran_Array1D Fortran_Array1D::copy() const -{ - Fortran_Array1D A( n_); - copy_(A.data_, data_, n_); - - return A; -} - - -template -Fortran_Array1D & Fortran_Array1D::inject(const Fortran_Array1D &A) -{ - if (A.n_ == n_) - copy_(data_, A.data_, n_); - - return *this; -} - - - - - -template -Fortran_Array1D & Fortran_Array1D::ref(const Fortran_Array1D &A) -{ - if (this != &A) - { - v_ = A.v_; /* operator= handles the reference counting. */ - n_ = A.n_; - data_ = A.data_; - - } - return *this; -} - -template -Fortran_Array1D & Fortran_Array1D::operator=(const Fortran_Array1D &A) -{ - return ref(A); -} - -template -inline int Fortran_Array1D::dim1() const { return n_; } - -template -inline int Fortran_Array1D::dim() const { return n_; } - -template -Fortran_Array1D::~Fortran_Array1D() {} - - -/* ............................ exented interface ......................*/ - -template -inline int Fortran_Array1D::ref_count() const -{ - return v_.ref_count(); -} - -template -inline Fortran_Array1D Fortran_Array1D::subarray(int i0, int i1) -{ -#ifdef TNT_DEBUG - std::cout << "entered subarray. \n"; -#endif - if ((i0 > 0) && (i1 < n_) || (i0 <= i1)) - { - Fortran_Array1D X(*this); /* create a new instance of this array. */ - X.n_ = i1-i0+1; - X.data_ += i0; - - return X; - } - else - { -#ifdef TNT_DEBUG - std::cout << "subarray: null return.\n"; -#endif - return Fortran_Array1D(); - } -} - - -/* private internal functions */ - - -template -void Fortran_Array1D::set_(T* begin, T* end, const T& a) -{ - for (T* p=begin; p -void Fortran_Array1D::copy_(T* p, const T* q, int len) const -{ - T *end = p + len; - while (p - -namespace TNT -{ - - -/** - Write an array to a character outstream. Output format is one that can - be read back in via the in-stream operator: one integer - denoting the array dimension (n), followed by n elements, - one per line. - -*/ -template -std::ostream& operator<<(std::ostream &s, const Fortran_Array1D &A) -{ - int N=A.dim1(); - - s << N << "\n"; - for (int j=1; j<=N; j++) - { - s << A(j) << "\n"; - } - s << "\n"; - - return s; -} - -/** - Read an array from a character stream. Input format - is one integer, denoting the dimension (n), followed - by n whitespace-separated elments. Newlines are ignored - -

- Note: the array being read into references new memory - storage. If the intent is to fill an existing conformant - array, use cin >> B; A.inject(B) ); - instead or read the elements in one-a-time by hand. - - @param s the charater to read from (typically std::in) - @param A the array to read into. -*/ -template -std::istream& operator>>(std::istream &s, Fortran_Array1D &A) -{ - int N; - s >> N; - - Fortran_Array1D B(N); - for (int i=1; i<=N; i++) - s >> B(i); - A = B; - return s; -} - - -template -Fortran_Array1D operator+(const Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Fortran_Array1D(); - - else - { - Fortran_Array1D C(n); - - for (int i=1; i<=n; i++) - { - C(i) = A(i) + B(i); - } - return C; - } -} - - - -template -Fortran_Array1D operator-(const Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Fortran_Array1D(); - - else - { - Fortran_Array1D C(n); - - for (int i=1; i<=n; i++) - { - C(i) = A(i) - B(i); - } - return C; - } -} - - -template -Fortran_Array1D operator*(const Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Fortran_Array1D(); - - else - { - Fortran_Array1D C(n); - - for (int i=1; i<=n; i++) - { - C(i) = A(i) * B(i); - } - return C; - } -} - - -template -Fortran_Array1D operator/(const Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() != n ) - return Fortran_Array1D(); - - else - { - Fortran_Array1D C(n); - - for (int i=1; i<=n; i++) - { - C(i) = A(i) / B(i); - } - return C; - } -} - - - - - - - - - -template -Fortran_Array1D& operator+=(Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=1; i<=n; i++) - { - A(i) += B(i); - } - } - return A; -} - - - - -template -Fortran_Array1D& operator-=(Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=1; i<=n; i++) - { - A(i) -= B(i); - } - } - return A; -} - - - -template -Fortran_Array1D& operator*=(Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=1; i<=n; i++) - { - A(i) *= B(i); - } - } - return A; -} - - - - -template -Fortran_Array1D& operator/=(Fortran_Array1D &A, const Fortran_Array1D &B) -{ - int n = A.dim1(); - - if (B.dim1() == n) - { - for (int i=1; i<=n; i++) - { - A(i) /= B(i); - } - } - return A; -} - - -} // namespace TNT - -#endif diff --git a/intern/smoke/intern/tnt/tnt_fortran_array2d.h b/intern/smoke/intern/tnt/tnt_fortran_array2d.h deleted file mode 100644 index 7f14d5436e9..00000000000 --- a/intern/smoke/intern/tnt/tnt_fortran_array2d.h +++ /dev/null @@ -1,228 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT): Two-dimensional Fortran numerical array -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef TNT_FORTRAN_ARRAY2D_H -#define TNT_FORTRAN_ARRAY2D_H - -#include -#include - -#ifdef TNT_BOUNDS_CHECK -#include -#endif - -#include "tnt_i_refvec.h" - -namespace TNT -{ - -template -class Fortran_Array2D -{ - - - private: - i_refvec v_; - int m_; - int n_; - T* data_; - - - void initialize_(int n); - void copy_(T* p, const T* q, int len); - void set_(T* begin, T* end, const T& val); - - public: - - typedef T value_type; - - Fortran_Array2D(); - Fortran_Array2D(int m, int n); - Fortran_Array2D(int m, int n, T *a); - Fortran_Array2D(int m, int n, const T &a); - inline Fortran_Array2D(const Fortran_Array2D &A); - inline Fortran_Array2D & operator=(const T &a); - inline Fortran_Array2D & operator=(const Fortran_Array2D &A); - inline Fortran_Array2D & ref(const Fortran_Array2D &A); - Fortran_Array2D copy() const; - Fortran_Array2D & inject(const Fortran_Array2D & A); - inline T& operator()(int i, int j); - inline const T& operator()(int i, int j) const ; - inline int dim1() const; - inline int dim2() const; - ~Fortran_Array2D(); - - /* extended interface */ - - inline int ref_count() const; - -}; - -template -Fortran_Array2D::Fortran_Array2D() : v_(), m_(0), n_(0), data_(0) {} - - -template -Fortran_Array2D::Fortran_Array2D(const Fortran_Array2D &A) : v_(A.v_), - m_(A.m_), n_(A.n_), data_(A.data_) {} - - - -template -Fortran_Array2D::Fortran_Array2D(int m, int n) : v_(m*n), m_(m), n_(n), - data_(v_.begin()) {} - -template -Fortran_Array2D::Fortran_Array2D(int m, int n, const T &val) : - v_(m*n), m_(m), n_(n), data_(v_.begin()) -{ - set_(data_, data_+m*n, val); -} - - -template -Fortran_Array2D::Fortran_Array2D(int m, int n, T *a) : v_(a), - m_(m), n_(n), data_(v_.begin()) {} - - - - -template -inline T& Fortran_Array2D::operator()(int i, int j) -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 1); - assert(i <= m_); - assert(j >= 1); - assert(j <= n_); -#endif - - return v_[ (j-1)*m_ + (i-1) ]; - -} - -template -inline const T& Fortran_Array2D::operator()(int i, int j) const -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 1); - assert(i <= m_); - assert(j >= 1); - assert(j <= n_); -#endif - - return v_[ (j-1)*m_ + (i-1) ]; - -} - - -template -Fortran_Array2D & Fortran_Array2D::operator=(const T &a) -{ - set_(data_, data_+m_*n_, a); - return *this; -} - -template -Fortran_Array2D Fortran_Array2D::copy() const -{ - - Fortran_Array2D B(m_,n_); - - B.inject(*this); - return B; -} - - -template -Fortran_Array2D & Fortran_Array2D::inject(const Fortran_Array2D &A) -{ - if (m_ == A.m_ && n_ == A.n_) - copy_(data_, A.data_, m_*n_); - - return *this; -} - - - -template -Fortran_Array2D & Fortran_Array2D::ref(const Fortran_Array2D &A) -{ - if (this != &A) - { - v_ = A.v_; - m_ = A.m_; - n_ = A.n_; - data_ = A.data_; - } - return *this; -} - -template -Fortran_Array2D & Fortran_Array2D::operator=(const Fortran_Array2D &A) -{ - return ref(A); -} - -template -inline int Fortran_Array2D::dim1() const { return m_; } - -template -inline int Fortran_Array2D::dim2() const { return n_; } - - -template -Fortran_Array2D::~Fortran_Array2D() -{ -} - -template -inline int Fortran_Array2D::ref_count() const { return v_.ref_count(); } - - - - -template -void Fortran_Array2D::set_(T* begin, T* end, const T& a) -{ - for (T* p=begin; p -void Fortran_Array2D::copy_(T* p, const T* q, int len) -{ - T *end = p + len; - while (p - -namespace TNT -{ - - -template -std::ostream& operator<<(std::ostream &s, const Fortran_Array2D &A) -{ - int M=A.dim1(); - int N=A.dim2(); - - s << M << " " << N << "\n"; - - for (int i=1; i<=M; i++) - { - for (int j=1; j<=N; j++) - { - s << A(i,j) << " "; - } - s << "\n"; - } - - - return s; -} - -template -std::istream& operator>>(std::istream &s, Fortran_Array2D &A) -{ - - int M, N; - - s >> M >> N; - - Fortran_Array2D B(M,N); - - for (int i=1; i<=M; i++) - for (int j=1; j<=N; j++) - { - s >> B(i,j); - } - - A = B; - return s; -} - - - - -template -Fortran_Array2D operator+(const Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Fortran_Array2D(); - - else - { - Fortran_Array2D C(m,n); - - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - C(i,j) = A(i,j) + B(i,j); - } - return C; - } -} - -template -Fortran_Array2D operator-(const Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Fortran_Array2D(); - - else - { - Fortran_Array2D C(m,n); - - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - C(i,j) = A(i,j) - B(i,j); - } - return C; - } -} - - -template -Fortran_Array2D operator*(const Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Fortran_Array2D(); - - else - { - Fortran_Array2D C(m,n); - - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - C(i,j) = A(i,j) * B(i,j); - } - return C; - } -} - - -template -Fortran_Array2D operator/(const Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() != m || B.dim2() != n ) - return Fortran_Array2D(); - - else - { - Fortran_Array2D C(m,n); - - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - C(i,j) = A(i,j) / B(i,j); - } - return C; - } -} - - - -template -Fortran_Array2D& operator+=(Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - A(i,j) += B(i,j); - } - } - return A; -} - -template -Fortran_Array2D& operator-=(Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - A(i,j) -= B(i,j); - } - } - return A; -} - -template -Fortran_Array2D& operator*=(Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - A(i,j) *= B(i,j); - } - } - return A; -} - -template -Fortran_Array2D& operator/=(Fortran_Array2D &A, const Fortran_Array2D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - - if (B.dim1() == m || B.dim2() == n ) - { - for (int i=1; i<=m; i++) - { - for (int j=1; j<=n; j++) - A(i,j) /= B(i,j); - } - } - return A; -} - -} // namespace TNT - -#endif diff --git a/intern/smoke/intern/tnt/tnt_fortran_array3d.h b/intern/smoke/intern/tnt/tnt_fortran_array3d.h deleted file mode 100644 index ee3de255a15..00000000000 --- a/intern/smoke/intern/tnt/tnt_fortran_array3d.h +++ /dev/null @@ -1,226 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT): Three-dimensional Fortran numerical array -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef TNT_FORTRAN_ARRAY3D_H -#define TNT_FORTRAN_ARRAY3D_H - -#include -#include -#ifdef TNT_BOUNDS_CHECK -#include -#endif -#include "tnt_i_refvec.h" - -namespace TNT -{ - -template -class Fortran_Array3D -{ - - - private: - - - i_refvec v_; - int m_; - int n_; - int k_; - T* data_; - - public: - - typedef T value_type; - - Fortran_Array3D(); - Fortran_Array3D(int m, int n, int k); - Fortran_Array3D(int m, int n, int k, T *a); - Fortran_Array3D(int m, int n, int k, const T &a); - inline Fortran_Array3D(const Fortran_Array3D &A); - inline Fortran_Array3D & operator=(const T &a); - inline Fortran_Array3D & operator=(const Fortran_Array3D &A); - inline Fortran_Array3D & ref(const Fortran_Array3D &A); - Fortran_Array3D copy() const; - Fortran_Array3D & inject(const Fortran_Array3D & A); - inline T& operator()(int i, int j, int k); - inline const T& operator()(int i, int j, int k) const ; - inline int dim1() const; - inline int dim2() const; - inline int dim3() const; - inline int ref_count() const; - ~Fortran_Array3D(); - - -}; - -template -Fortran_Array3D::Fortran_Array3D() : v_(), m_(0), n_(0), k_(0), data_(0) {} - - -template -Fortran_Array3D::Fortran_Array3D(const Fortran_Array3D &A) : - v_(A.v_), m_(A.m_), n_(A.n_), k_(A.k_), data_(A.data_) {} - - - -template -Fortran_Array3D::Fortran_Array3D(int m, int n, int k) : - v_(m*n*k), m_(m), n_(n), k_(k), data_(v_.begin()) {} - - - -template -Fortran_Array3D::Fortran_Array3D(int m, int n, int k, const T &val) : - v_(m*n*k), m_(m), n_(n), k_(k), data_(v_.begin()) -{ - for (T* p = data_; p < data_ + m*n*k; p++) - *p = val; -} - -template -Fortran_Array3D::Fortran_Array3D(int m, int n, int k, T *a) : - v_(a), m_(m), n_(n), k_(k), data_(v_.begin()) {} - - - - -template -inline T& Fortran_Array3D::operator()(int i, int j, int k) -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 1); - assert(i <= m_); - assert(j >= 1); - assert(j <= n_); - assert(k >= 1); - assert(k <= k_); -#endif - - return data_[(k-1)*m_*n_ + (j-1) * m_ + i-1]; - -} - -template -inline const T& Fortran_Array3D::operator()(int i, int j, int k) const -{ -#ifdef TNT_BOUNDS_CHECK - assert(i >= 1); - assert(i <= m_); - assert(j >= 1); - assert(j <= n_); - assert(k >= 1); - assert(k <= k_); -#endif - - return data_[(k-1)*m_*n_ + (j-1) * m_ + i-1]; -} - - -template -Fortran_Array3D & Fortran_Array3D::operator=(const T &a) -{ - - T *end = data_ + m_*n_*k_; - - for (T *p=data_; p != end; *p++ = a); - - return *this; -} - -template -Fortran_Array3D Fortran_Array3D::copy() const -{ - - Fortran_Array3D B(m_, n_, k_); - B.inject(*this); - return B; - -} - - -template -Fortran_Array3D & Fortran_Array3D::inject(const Fortran_Array3D &A) -{ - - if (m_ == A.m_ && n_ == A.n_ && k_ == A.k_) - { - T *p = data_; - T *end = data_ + m_*n_*k_; - const T* q = A.data_; - for (; p < end; *p++ = *q++); - } - return *this; -} - - - - -template -Fortran_Array3D & Fortran_Array3D::ref(const Fortran_Array3D &A) -{ - - if (this != &A) - { - v_ = A.v_; - m_ = A.m_; - n_ = A.n_; - k_ = A.k_; - data_ = A.data_; - } - return *this; -} - -template -Fortran_Array3D & Fortran_Array3D::operator=(const Fortran_Array3D &A) -{ - return ref(A); -} - -template -inline int Fortran_Array3D::dim1() const { return m_; } - -template -inline int Fortran_Array3D::dim2() const { return n_; } - -template -inline int Fortran_Array3D::dim3() const { return k_; } - - -template -inline int Fortran_Array3D::ref_count() const -{ - return v_.ref_count(); -} - -template -Fortran_Array3D::~Fortran_Array3D() -{ -} - - -} /* namespace TNT */ - -#endif -/* TNT_FORTRAN_ARRAY3D_H */ - diff --git a/intern/smoke/intern/tnt/tnt_fortran_array3d_utils.h b/intern/smoke/intern/tnt/tnt_fortran_array3d_utils.h deleted file mode 100644 index d337932380b..00000000000 --- a/intern/smoke/intern/tnt/tnt_fortran_array3d_utils.h +++ /dev/null @@ -1,252 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - -#ifndef TNT_FORTRAN_ARRAY3D_UTILS_H -#define TNT_FORTRAN_ARRAY3D_UTILS_H - -#include -#include - -namespace TNT -{ - - -template -std::ostream& operator<<(std::ostream &s, const Fortran_Array3D &A) -{ - int M=A.dim1(); - int N=A.dim2(); - int K=A.dim3(); - - s << M << " " << N << " " << K << "\n"; - - for (int i=1; i<=M; i++) - { - for (int j=1; j<=N; j++) - { - for (int k=1; k<=K; k++) - s << A(i,j,k) << " "; - s << "\n"; - } - s << "\n"; - } - - - return s; -} - -template -std::istream& operator>>(std::istream &s, Fortran_Array3D &A) -{ - - int M, N, K; - - s >> M >> N >> K; - - Fortran_Array3D B(M,N,K); - - for (int i=1; i<=M; i++) - for (int j=1; j<=N; j++) - for (int k=1; k<=K; k++) - s >> B(i,j,k); - - A = B; - return s; -} - - -template -Fortran_Array3D operator+(const Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Fortran_Array3D(); - - else - { - Fortran_Array3D C(m,n,p); - - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - C(i,j,k) = A(i,j,k)+ B(i,j,k); - - return C; - } -} - - -template -Fortran_Array3D operator-(const Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Fortran_Array3D(); - - else - { - Fortran_Array3D C(m,n,p); - - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - C(i,j,k) = A(i,j,k)- B(i,j,k); - - return C; - } -} - - -template -Fortran_Array3D operator*(const Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Fortran_Array3D(); - - else - { - Fortran_Array3D C(m,n,p); - - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - C(i,j,k) = A(i,j,k)* B(i,j,k); - - return C; - } -} - - -template -Fortran_Array3D operator/(const Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() != m || B.dim2() != n || B.dim3() != p ) - return Fortran_Array3D(); - - else - { - Fortran_Array3D C(m,n,p); - - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - C(i,j,k) = A(i,j,k)/ B(i,j,k); - - return C; - } -} - - -template -Fortran_Array3D& operator+=(Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - A(i,j,k) += B(i,j,k); - } - - return A; -} - - -template -Fortran_Array3D& operator-=(Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - A(i,j,k) -= B(i,j,k); - } - - return A; -} - - -template -Fortran_Array3D& operator*=(Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - A(i,j,k) *= B(i,j,k); - } - - return A; -} - - -template -Fortran_Array3D& operator/=(Fortran_Array3D &A, const Fortran_Array3D &B) -{ - int m = A.dim1(); - int n = A.dim2(); - int p = A.dim3(); - - if (B.dim1() == m && B.dim2() == n && B.dim3() == p ) - { - for (int i=1; i<=m; i++) - for (int j=1; j<=n; j++) - for (int k=1; k<=p; k++) - A(i,j,k) /= B(i,j,k); - } - - return A; -} - - -} // namespace TNT - -#endif diff --git a/intern/smoke/intern/tnt/tnt_i_refvec.h b/intern/smoke/intern/tnt/tnt_i_refvec.h deleted file mode 100644 index eaf8a4d0e68..00000000000 --- a/intern/smoke/intern/tnt/tnt_i_refvec.h +++ /dev/null @@ -1,246 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef TNT_I_REFVEC_H -#define TNT_I_REFVEC_H - -#include -#include - -#ifdef TNT_BOUNDS_CHECK -#include -#endif - -#ifndef NULL -#define NULL 0 -#endif - -namespace TNT -{ -/* - Internal representation of ref-counted array. The TNT - arrays all use this building block. - -

- If an array block is created by TNT, then every time - an assignment is made, the left-hand-side reference - is decreased by one, and the right-hand-side refernce - count is increased by one. If the array block was - external to TNT, the refernce count is a NULL pointer - regardless of how many references are made, since the - memory is not freed by TNT. - - - -*/ -template -class i_refvec -{ - - - private: - T* data_; - int *ref_count_; - - - public: - - i_refvec(); - explicit i_refvec(int n); - inline i_refvec(T* data); - inline i_refvec(const i_refvec &v); - inline T* begin(); - inline const T* begin() const; - inline T& operator[](int i); - inline const T& operator[](int i) const; - inline i_refvec & operator=(const i_refvec &V); - void copy_(T* p, const T* q, const T* e); - void set_(T* p, const T* b, const T* e); - inline int ref_count() const; - inline int is_null() const; - inline void destroy(); - ~i_refvec(); - -}; - -template -void i_refvec::copy_(T* p, const T* q, const T* e) -{ - for (T* t=p; q -i_refvec::i_refvec() : data_(NULL), ref_count_(NULL) {} - -/** - In case n is 0 or negative, it does NOT call new. -*/ -template -i_refvec::i_refvec(int n) : data_(NULL), ref_count_(NULL) -{ - if (n >= 1) - { -#ifdef TNT_DEBUG - std::cout << "new data storage.\n"; -#endif - data_ = new T[n]; - ref_count_ = new int; - *ref_count_ = 1; - } -} - -template -inline i_refvec::i_refvec(const i_refvec &V): data_(V.data_), - ref_count_(V.ref_count_) -{ - if (V.ref_count_ != NULL) - (*(V.ref_count_))++; -} - - -template -i_refvec::i_refvec(T* data) : data_(data), ref_count_(NULL) {} - -template -inline T* i_refvec::begin() -{ - return data_; -} - -template -inline const T& i_refvec::operator[](int i) const -{ - return data_[i]; -} - -template -inline T& i_refvec::operator[](int i) -{ - return data_[i]; -} - - -template -inline const T* i_refvec::begin() const -{ - return data_; -} - - - -template -i_refvec & i_refvec::operator=(const i_refvec &V) -{ - if (this == &V) - return *this; - - - if (ref_count_ != NULL) - { - (*ref_count_) --; - if ((*ref_count_) == 0) - destroy(); - } - - data_ = V.data_; - ref_count_ = V.ref_count_; - - if (V.ref_count_ != NULL) - (*(V.ref_count_))++; - - return *this; -} - -template -void i_refvec::destroy() -{ - if (ref_count_ != NULL) - { -#ifdef TNT_DEBUG - std::cout << "destorying data... \n"; -#endif - delete ref_count_; - -#ifdef TNT_DEBUG - std::cout << "deleted ref_count_ ...\n"; -#endif - if (data_ != NULL) - delete []data_; -#ifdef TNT_DEBUG - std::cout << "deleted data_[] ...\n"; -#endif - data_ = NULL; - } -} - -/* -* return 1 is vector is empty, 0 otherwise -* -* if is_null() is false and ref_count() is 0, then -* -*/ -template -int i_refvec::is_null() const -{ - return (data_ == NULL ? 1 : 0); -} - -/* -* returns -1 if data is external, -* returns 0 if a is NULL array, -* otherwise returns the positive number of vectors sharing -* this data space. -*/ -template -int i_refvec::ref_count() const -{ - if (data_ == NULL) - return 0; - else - return (ref_count_ != NULL ? *ref_count_ : -1) ; -} - -template -i_refvec::~i_refvec() -{ - if (ref_count_ != NULL) - { - (*ref_count_)--; - - if (*ref_count_ == 0) - destroy(); - } -} - - -} /* namespace TNT */ - - - - - -#endif -/* TNT_I_REFVEC_H */ - diff --git a/intern/smoke/intern/tnt/tnt_math_utils.h b/intern/smoke/intern/tnt/tnt_math_utils.h deleted file mode 100644 index ed4a3b7f78f..00000000000 --- a/intern/smoke/intern/tnt/tnt_math_utils.h +++ /dev/null @@ -1,35 +0,0 @@ -/** \file - * \ingroup smoke - */ -#ifndef MATH_UTILS_H -#define MATH_UTILS_H - -/* needed for fabs, sqrt() below */ -#include - -namespace TNT -{ -/** - @returns hypotenuse of real (non-complex) scalars a and b by - avoiding underflow/overflow - using (a * sqrt( 1 + (b/a) * (b/a))), rather than - sqrt(a*a + b*b). -*/ -template -Real hypot(const Real &a, const Real &b) -{ - - if (a== 0) - return fabs(b); - else - { - Real c = b/a; - return fabs(a) * sqrt(1 + c*c); - } -} -} /* TNT namespace */ - - - -#endif -/* MATH_UTILS_H */ diff --git a/intern/smoke/intern/tnt/tnt_sparse_matrix_csr.h b/intern/smoke/intern/tnt/tnt_sparse_matrix_csr.h deleted file mode 100644 index 61d52542641..00000000000 --- a/intern/smoke/intern/tnt/tnt_sparse_matrix_csr.h +++ /dev/null @@ -1,106 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - -#ifndef TNT_SPARSE_MATRIX_CSR_H -#define TNT_SPARSE_MATRIX_CSR_H - -#include "tnt_array1d.h" - -namespace TNT -{ - - -/** - Read-only view of a sparse matrix in compressed-row storage - format. Neither array elements (nonzeros) nor sparsity - structure can be modified. If modifications are required, - create a new view. - -

- Index values begin at 0. - -

- Storage requirements: An (m x n) matrix with - nz nonzeros requires no more than ((T+I)*nz + M*I) - bytes, where T is the size of data elements and - I is the size of integers. - - -*/ -template -class Sparse_Matrix_CompRow { - -private: - Array1D val_; // data values (nz_ elements) - Array1D rowptr_; // row_ptr (dim_[0]+1 elements) - Array1D colind_; // col_ind (nz_ elements) - - int dim1_; // number of rows - int dim2_; // number of cols - -public: - - Sparse_Matrix_CompRow(const Sparse_Matrix_CompRow &S); - Sparse_Matrix_CompRow(int M, int N, int nz, const T *val, - const int *r, const int *c); - - - - inline const T& val(int i) const { return val_[i]; } - inline const int& row_ptr(int i) const { return rowptr_[i]; } - inline const int& col_ind(int i) const { return colind_[i];} - - inline int dim1() const {return dim1_;} - inline int dim2() const {return dim2_;} - int NumNonzeros() const {return val_.dim1();} - - - Sparse_Matrix_CompRow& operator=( - const Sparse_Matrix_CompRow &R); - - - -}; - -/** - Construct a read-only view of existing sparse matrix in - compressed-row storage format. - - @param M the number of rows of sparse matrix - @param N the number of columns of sparse matrix - @param nz the number of nonzeros - @param val a contiguous list of nonzero values - @param r row-pointers: r[i] denotes the begining position of row i - (i.e. the ith row begins at val[row[i]]). - @param c column-indices: c[i] denotes the column location of val[i] -*/ -template -Sparse_Matrix_CompRow::Sparse_Matrix_CompRow(int M, int N, int nz, - const T *val, const int *r, const int *c) : val_(nz,val), - rowptr_(M, r), colind_(nz, c), dim1_(M), dim2_(N) {} - - -} -// namespace TNT - -#endif diff --git a/intern/smoke/intern/tnt/tnt_stopwatch.h b/intern/smoke/intern/tnt/tnt_stopwatch.h deleted file mode 100644 index a4eb09acbc4..00000000000 --- a/intern/smoke/intern/tnt/tnt_stopwatch.h +++ /dev/null @@ -1,98 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef STOPWATCH_H -#define STOPWATCH_H - -// for clock() and CLOCKS_PER_SEC -#include - - -namespace TNT -{ - -inline static double seconds(void) -{ - const double secs_per_tick = 1.0 / CLOCKS_PER_SEC; - return ( (double) clock() ) * secs_per_tick; -} - -class Stopwatch { - private: - int running_; - double start_time_; - double total_; - - public: - inline Stopwatch(); - inline void start(); - inline double stop(); - inline double read(); - inline void resume(); - inline int running(); -}; - -inline Stopwatch::Stopwatch() : running_(0), start_time_(0.0), total_(0.0) {} - -void Stopwatch::start() -{ - running_ = 1; - total_ = 0.0; - start_time_ = seconds(); -} - -double Stopwatch::stop() -{ - if (running_) - { - total_ += (seconds() - start_time_); - running_ = 0; - } - return total_; -} - -inline void Stopwatch::resume() -{ - if (!running_) - { - start_time_ = seconds(); - running_ = 1; - } -} - - -inline double Stopwatch::read() -{ - if (running_) - { - stop(); - resume(); - } - return total_; -} - - -} /* TNT namespace */ -#endif - - - diff --git a/intern/smoke/intern/tnt/tnt_subscript.h b/intern/smoke/intern/tnt/tnt_subscript.h deleted file mode 100644 index 00cc0220bd1..00000000000 --- a/intern/smoke/intern/tnt/tnt_subscript.h +++ /dev/null @@ -1,57 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - -#ifndef TNT_SUBSCRPT_H -#define TNT_SUBSCRPT_H - - -//--------------------------------------------------------------------- -// This definition describes the default TNT data type used for -// indexing into TNT matrices and vectors. The data type should -// be wide enough to index into large arrays. It defaults to an -// "int", but can be overriden at compile time redefining TNT_SUBSCRIPT_TYPE, -// e.g. -// -// c++ -DTNT_SUBSCRIPT_TYPE='unsigned int' ... -// -//--------------------------------------------------------------------- -// - -#ifndef TNT_SUBSCRIPT_TYPE -#define TNT_SUBSCRIPT_TYPE int -#endif - -namespace TNT -{ - typedef TNT_SUBSCRIPT_TYPE Subscript; -} /* namespace TNT */ - - -// () indexing in TNT means 1-offset, i.e. x(1) and A(1,1) are the -// first elements. This offset is left as a macro for future -// purposes, but should not be changed in the current release. -// -// -#define TNT_BASE_OFFSET (1) - -#endif diff --git a/intern/smoke/intern/tnt/tnt_vec.h b/intern/smoke/intern/tnt/tnt_vec.h deleted file mode 100644 index 77458c6b8c1..00000000000 --- a/intern/smoke/intern/tnt/tnt_vec.h +++ /dev/null @@ -1,407 +0,0 @@ -/** \file - * \ingroup smoke - */ -/* -* -* Template Numerical Toolkit (TNT) -* -* Mathematical and Computational Sciences Division -* National Institute of Technology, -* Gaithersburg, MD USA -* -* -* This software was developed at the National Institute of Standards and -* Technology (NIST) by employees of the Federal Government in the course -* of their official duties. Pursuant to title 17 Section 105 of the -* United States Code, this software is not subject to copyright protection -* and is in the public domain. NIST assumes no responsibility whatsoever for -* its use by other parties, and makes no guarantees, expressed or implied, -* about its quality, reliability, or any other characteristic. -* -*/ - - - -#ifndef TNT_VEC_H -#define TNT_VEC_H - -#include "tnt_subscript.h" -#include -#include -#include -#include - -namespace TNT -{ - -/** - [Deprecatred] Value-based vector class from pre-1.0 - TNT version. Kept here for backward compatiblity, but should - use the newer TNT::Array1D classes instead. - -*/ - -template -class Vector -{ - - - public: - - typedef Subscript size_type; - typedef T value_type; - typedef T element_type; - typedef T* pointer; - typedef T* iterator; - typedef T& reference; - typedef const T* const_iterator; - typedef const T& const_reference; - - Subscript lbound() const { return 1;} - - protected: - T* v_; - T* vm1_; // pointer adjustment for optimzied 1-offset indexing - Subscript n_; - - // internal helper function to create the array - // of row pointers - - void initialize(Subscript N) - { - // adjust pointers so that they are 1-offset: - // v_[] is the internal contiguous array, it is still 0-offset - // - assert(v_ == NULL); - v_ = new T[N]; - assert(v_ != NULL); - vm1_ = v_-1; - n_ = N; - } - - void copy(const T* v) - { - Subscript N = n_; - Subscript i; - -#ifdef TNT_UNROLL_LOOPS - Subscript Nmod4 = N & 3; - Subscript N4 = N - Nmod4; - - for (i=0; i &A) : v_(0), vm1_(0), n_(0) - { - initialize(A.n_); - copy(A.v_); - } - - Vector(Subscript N, const T& value = T()) : v_(0), vm1_(0), n_(0) - { - initialize(N); - set(value); - } - - Vector(Subscript N, const T* v) : v_(0), vm1_(0), n_(0) - { - initialize(N); - copy(v); - } - - Vector(Subscript N, char *s) : v_(0), vm1_(0), n_(0) - { - initialize(N); - std::istringstream ins(s); - - Subscript i; - - for (i=0; i> v_[i]; - } - - - // methods - // - Vector& newsize(Subscript N) - { - if (n_ == N) return *this; - - destroy(); - initialize(N); - - return *this; - } - - - // assignments - // - Vector& operator=(const Vector &A) - { - if (v_ == A.v_) - return *this; - - if (n_ == A.n_) // no need to re-alloc - copy(A.v_); - - else - { - destroy(); - initialize(A.n_); - copy(A.v_); - } - - return *this; - } - - Vector& operator=(const T& scalar) - { - set(scalar); - return *this; - } - - inline Subscript dim() const - { - return n_; - } - - inline Subscript size() const - { - return n_; - } - - - inline reference operator()(Subscript i) - { -#ifdef TNT_BOUNDS_CHECK - assert(1<=i); - assert(i <= n_) ; -#endif - return vm1_[i]; - } - - inline const_reference operator() (Subscript i) const - { -#ifdef TNT_BOUNDS_CHECK - assert(1<=i); - assert(i <= n_) ; -#endif - return vm1_[i]; - } - - inline reference operator[](Subscript i) - { -#ifdef TNT_BOUNDS_CHECK - assert(0<=i); - assert(i < n_) ; -#endif - return v_[i]; - } - - inline const_reference operator[](Subscript i) const - { -#ifdef TNT_BOUNDS_CHECK - assert(0<=i); - - - - - - - assert(i < n_) ; -#endif - return v_[i]; - } - - - -}; - - -/* *************************** I/O ********************************/ - -template -std::ostream& operator<<(std::ostream &s, const Vector &A) -{ - Subscript N=A.dim(); - - s << N << "\n"; - - for (Subscript i=0; i -std::istream & operator>>(std::istream &s, Vector &A) -{ - - Subscript N; - - s >> N; - - if ( !(N == A.size() )) - { - A.newsize(N); - } - - - for (Subscript i=0; i> A[i]; - - - return s; -} - -// *******************[ basic matrix algorithms ]*************************** - - -template -Vector operator+(const Vector &A, - const Vector &B) -{ - Subscript N = A.dim(); - - assert(N==B.dim()); - - Vector tmp(N); - Subscript i; - - for (i=0; i -Vector operator-(const Vector &A, - const Vector &B) -{ - Subscript N = A.dim(); - - assert(N==B.dim()); - - Vector tmp(N); - Subscript i; - - for (i=0; i -Vector operator*(const Vector &A, - const Vector &B) -{ - Subscript N = A.dim(); - - assert(N==B.dim()); - - Vector tmp(N); - Subscript i; - - for (i=0; i -T dot_prod(const Vector &A, const Vector &B) -{ - Subscript N = A.dim(); - assert(N == B.dim()); - - Subscript i; - T sum = 0; - - for (i=0; i