├── .gitignore ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── cmake.modules ├── FindAMD.cmake ├── FindBLAS.cmake ├── FindCAMD.cmake ├── FindCCOLAMD.cmake ├── FindCHOLMOD.cmake ├── FindCOLAMD.cmake ├── FindFFTW3.cmake ├── FindHDF5.cmake ├── FindLAPACK.cmake ├── FindMETIS.cmake ├── FindMKL.cmake ├── FindMUMPS.cmake ├── FindMatlab.cmake ├── FindRT.cmake ├── FindSUITESPARSE.cmake ├── FindSUITESPARSE_CONFIG.cmake ├── FindSUPERLU.cmake └── FindUMFPACK.cmake ├── docs ├── _config.yml └── index.md ├── examples ├── README ├── amr_grids │ ├── README.md │ ├── amr_grids.c │ ├── input │ │ ├── 2d_2L.input │ │ ├── 2d_L.input │ │ ├── 2d_SQ+L.input │ │ ├── 2d_ann.input │ │ ├── 2d_circle.input │ │ ├── 2d_grid.input │ │ ├── 2d_square.input │ │ ├── 3d_2cubes_edge.input │ │ ├── 3d_2cubes_vertex.input │ │ ├── 3d_cube.input │ │ ├── 3d_fichera.input │ │ ├── 4d_cube.input │ │ └── 5d_cube.input │ ├── makefile │ ├── output │ │ └── .gitignore │ └── supporting_amr_grids.h ├── approximation │ ├── README.md │ ├── makefile │ ├── output │ │ └── .gitignore │ ├── ra_examples.h │ ├── test_aaa.c │ └── test_brasil.c ├── basic_elliptic │ ├── basic_elliptic.c │ ├── basic_elliptic_data.h │ ├── input.dat │ ├── makefile │ ├── output │ │ └── .gitignore │ └── unitSQ_n9.haz ├── elliptic_p1 │ ├── elliptic_p1.c │ ├── functions_elliptic_p1.h │ ├── makefile │ ├── output │ │ └── .gitignore │ └── supporting_elliptic_p1.h ├── examples.mk ├── grids │ ├── 1D │ │ ├── unitLINE_n17.haz │ │ ├── unitLINE_n3.haz │ │ ├── unitLINE_n33.haz │ │ ├── unitLINE_n5.haz │ │ ├── unitLINE_n65.haz │ │ └── unitLINE_n9.haz │ ├── 2D │ │ ├── L05.haz │ │ ├── circle_level0.haz │ │ ├── circle_level1.haz │ │ ├── circle_level2.haz │ │ ├── circle_level3.haz │ │ ├── unitCIRC_hole_n17.haz │ │ ├── unitSQ_hole_n17.haz │ │ ├── unitSQ_n129.haz │ │ ├── unitSQ_n17.haz │ │ ├── unitSQ_n257.haz │ │ ├── unitSQ_n3.haz │ │ ├── unitSQ_n33.haz │ │ ├── unitSQ_n5.haz │ │ ├── unitSQ_n513.haz │ │ ├── unitSQ_n65.haz │ │ └── unitSQ_n9.haz │ └── 3D │ │ ├── unitCUBE_hole_v4886.haz │ │ ├── unitCUBE_n17.haz │ │ ├── unitCUBE_n3.haz │ │ ├── unitCUBE_n33.haz │ │ ├── unitCUBE_n5.haz │ │ ├── unitCUBE_n9.haz │ │ ├── unitSPH_hole_v4886.haz │ │ └── unitSPH_n17.haz ├── haznics │ ├── README.md │ ├── hodge_Hcurl_3d.py │ ├── install_haznics.sh │ ├── mixedpoisson.py │ ├── mixedpoisson_Hdiv_3d.py │ ├── poisson.py │ ├── setup.rc │ ├── stokes_flat.py │ ├── stokes_mixed.py │ ├── test_poisson.py │ └── tests │ │ ├── input.dat │ │ ├── test_blockmat.py │ │ ├── test_haznics.py │ │ ├── test_hxcurl.py │ │ ├── test_params.py │ │ └── test_rational_approx.py ├── heat_equation │ ├── heat_equation.c │ ├── heat_equation_data.h │ ├── input.dat │ ├── makefile │ └── output │ │ └── .gitignore ├── make_all_examples.sh ├── mg_geometric │ ├── README │ ├── gmg.c │ ├── gmg_routines.h │ ├── makefile │ ├── out_level_11.txt │ ├── output │ │ └── .gitignore │ ├── rhs_bc.h │ └── sample.input ├── solvers │ ├── A.dat │ ├── A11.dat │ ├── A12.dat │ ├── A21.dat │ ├── A22.dat │ ├── Arhs.dat │ ├── As.dat │ ├── b.dat │ ├── bsrmat_SPE01.dat │ ├── input.dat │ ├── input_Schwarz.dat │ ├── makefile │ ├── rhs_SPE01.dat │ ├── solvers.c │ ├── solvers_bdcsr.c │ ├── solvers_bsr.c │ └── test_Schwarz.c ├── stokes │ ├── input.dat │ ├── makefile │ ├── output │ │ └── .gitignore │ ├── stokes.c │ ├── stokes_data.h │ ├── stokes_precond.h │ └── stokes_system.h └── xd_1d_models │ ├── README.md │ ├── definitions_xd_1d.h │ ├── input │ ├── 1d_matrices_2d │ │ ├── A.npy │ │ ├── B.npy │ │ ├── Bt.npy │ │ ├── C.npy │ │ ├── b0.npy │ │ └── b1.npy │ ├── 1d_matrices_3d │ │ └── .gitignore │ ├── 1d_nets_2d │ │ ├── 001_coordinates_of_vertices │ │ ├── 002_segments_definition │ │ ├── 003_number_of_points_by_segment │ │ ├── 004_coordinates_of_all_inner_points_:including_vertices: │ │ ├── 005_point_thickness │ │ └── 009_thickness │ ├── 1d_nets_3d │ │ ├── 001_coordinates_of_vertices │ │ ├── 002_segments_definition │ │ ├── 003_number_of_points_by_segment │ │ ├── 004_coordinates_of_all_inner_points_:including_vertices: │ │ ├── 005_point_thickness │ │ └── 009_thickness │ └── solver.input │ ├── main_meshing_xd_1d.c │ ├── main_solver_xd_1d.c │ ├── makefile │ ├── output │ └── .gitignore │ ├── run_meshing.py │ ├── run_solver.py │ ├── solver_xd_1d.h │ └── supporting_xd_1d.h ├── haz_config ├── hazmath.mk └── hazmath.mk.example ├── haz_docs ├── HELP.txt └── hazmath.Doxygen.cnf.in ├── haz_shutils ├── get_dup_hashes.sh ├── haznics_swig.sh ├── headmk.sh ├── headmk_haznics.sh ├── mkheaders.awk └── mkheaders_simple.awk ├── include ├── .gitignore ├── amr.h ├── dense.h ├── doxygen.h ├── eigen.h ├── fem.h ├── graphs.h ├── macro.h ├── mesh.h ├── nonlinear.h ├── param.h ├── solver.h ├── sparse.h ├── timestep.h └── vec.h ├── makefile └── src ├── amr ├── amr_coords.c ├── amr_utils.c ├── input_grid.c ├── interpolate.c ├── macroelements.c ├── marking.c ├── mesh_cube_anydim.c ├── nested_iteration.c ├── scomplex.c ├── uniform_refinement.c └── unigrid.c ├── approximation ├── haz_aaa.c └── haz_brasil.c ├── assemble ├── .gitignore ├── any_dimension_p1.c ├── assemble_global.c ├── assemble_local.c └── assemble_utils.c ├── eigen ├── eigen_drivers.c └── qz.c ├── fem ├── .gitignore ├── basis.c ├── error.c ├── fespace.c ├── interp.c └── quadrature.c ├── graphs ├── basic.c └── bfs_dfs.c ├── haznics ├── haznics.i ├── helper.c └── numpy.ii ├── interfaces └── i_multigraph.c ├── mesh ├── .gitignore ├── mesh_create.c ├── mesh_io.c ├── mesh_stats.c └── voronoi.c ├── nonlinear └── newton.c ├── solver ├── .gitignore ├── amg_setup_ua.c ├── amg_solve.c ├── direct.c ├── famg_solve.c ├── fmgcycle.c ├── fsmoother.c ├── hazmath_direct.c ├── itsolver.c ├── krylov.c ├── mgcycle.c ├── precond.c ├── schwarz_setup.c ├── smoother.c └── yschwarz_setup.c ├── timestepping └── timestep.c └── utilities ├── .gitignore ├── array.c ├── coefficient.c ├── data.c ├── dense.c ├── format.c ├── graph_utils.c ├── input.c ├── io.c ├── message.c ├── parameters.c ├── sorting.c ├── sparse.c ├── string_utils.c ├── timing.c ├── vec.c └── wrapper.c /.gitignore: -------------------------------------------------------------------------------- 1 | BUILD_HAZ/ 2 | lib/ 3 | include/hazmath.h 4 | include/haznics_add.h 5 | haz_docs/html_docs 6 | haz_docs/tex_docs 7 | haz_docs/html_docs/*.* 8 | haz_docs/tex_docs/*.* 9 | *.dSYM/ 10 | *.ex 11 | */*.ex 12 | *.o 13 | *.a 14 | *~ 15 | *.mod 16 | \#* 17 | .\#* 18 | *.bak 19 | .DS_Store 20 | swig_files/ 21 | cbc.block/ 22 | fenics_ii/ 23 | quadpy/ 24 | ulfy/ 25 | octave-workspace 26 | 27 | HAZMATH.config 28 | HAZMATH.creator 29 | HAZMATH.creator.user 30 | HAZMATH.files 31 | HAZMATH.includes 32 | HAZMATH.pro 33 | junk.* 34 | *.bak 35 | hazmath-*.tar.gz 36 | trabajo/ 37 | trabajo/* 38 | examples/fractures/LS/matrix_structure3.dat 39 | examples/fractures/LS/matrix_structure2.dat 40 | examples/fractures/LS/matrix_structure1.dat 41 | 42 | examples/haznics/*.pvd 43 | examples/haznics/*.vtu 44 | examples/haznics/results/ 45 | examples/xd_1d_models/input/solver.input 46 | .vscode/ 47 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2009- Xiaozhe Hu, James H. Adler, Ludmil T. Zikatanov 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | ****************************************************************************** 24 | -------------------------------------------------------------------------------- /cmake.modules/FindAMD.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find AMD 2 | # 3 | # OUTPUT: 4 | # AMD_FOUND - system has AMD 5 | # AMD_INCLUDE_DIRS - include directories for AMD 6 | # AMD_LIBRARIES - libraries for AMD 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | # 12 | message(STATUS "Checking for package 'AMD'") 13 | 14 | # Check for header file 15 | find_path(AMD_INCLUDE_DIRS amd.h 16 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/include ${SUITESPARSE_DIR}/AMD/include $ENV{SUITESPARSE_DIR}/include $ENV{SUITESPARSE_DIR}/AMD/include 17 | PATH_SUFFIXES suitesparse ufsparse 18 | DOC "Directory where the AMD header is located" 19 | ) 20 | mark_as_advanced(AMD_INCLUDE_DIRS) 21 | 22 | # Check for AMD library 23 | find_library(AMD_LIBRARIES amd 24 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/lib ${SUITESPARSE_DIR}/AMD/lib $ENV{SUITESPARSE_DIR}/lib $ENV{SUITESPARSE_DIR}/AMD/lib 25 | DOC "The AMD library" 26 | ) 27 | mark_as_advanced(AMD_LIBRARIES) 28 | 29 | # Standard package handling 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(AMD 32 | "AMD could not be found. Be sure to set SUITESPARSE_DIR correctly." 33 | AMD_LIBRARIES AMD_INCLUDE_DIRS) 34 | -------------------------------------------------------------------------------- /cmake.modules/FindBLAS.cmake: -------------------------------------------------------------------------------- 1 | 2 | # - Try to find BLAS 3 | # 4 | # OUTPUT: 5 | # BLAS_FOUND - system has BLAS 6 | # BLAS_LIBRARIES - libraries for BLAS 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | # Modified 2020-05-29 --ltz 12 | 13 | #message(STATUS "Checking for 'BLAS' library") 14 | # Check for BLAS library 15 | find_library(BLAS_LIBRARY blas 16 | HINTS ${BLAS_DIR} ${BLAS_DIR}/lib ${BLAS_DIR}/blas/lib $ENV{BLAS_DIR}/lib $ENV{BLAS_DIR}/BLAS/lib 17 | DOC "The BLAS library" 18 | ) 19 | mark_as_advanced(BLAS_LIBRARY) 20 | 21 | # Collect libraries 22 | if (BLAS_FOUND) 23 | set(BLAS_LIBRARIES ${BLAS_LIBRARIES}) 24 | endif() 25 | 26 | # Try compiling and running test program 27 | if (BLAS_LIBRARIES) 28 | # Set flags for building test program 29 | set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 30 | endif(BLAS_LIBRARIES) 31 | 32 | 33 | # Standard package handling 34 | include(FindPackageHandleStandardArgs) 35 | find_package_handle_standard_args(BLAS 36 | "BLAS could not be found. Be sure to set BLAS_DIR correctly." 37 | BLAS_LIBRARY) 38 | -------------------------------------------------------------------------------- /cmake.modules/FindCAMD.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find CAMD 2 | # 3 | # OUTPUT: 4 | # CAMD_FOUND - system has CAMD 5 | # CAMD_INCLUDE_DIRS - include directories for CAMD 6 | # CAMD_LIBRARIES - libraries for CAMD 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | 12 | message(STATUS "Checking for package 'CAMD'") 13 | 14 | # Check for header file 15 | find_path(CAMD_INCLUDE_DIRS camd.h 16 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/include ${SUITESPARSE_DIR}/CAMD/include $ENV{SUITESPARSE_DIR}/include $ENV{SUITESPARSE_DIR}/CAMD/include 17 | PATH_SUFFIXES suitesparse ufsparse 18 | DOC "Directory where the CAMD header is located" 19 | ) 20 | mark_as_advanced(CAMD_INCLUDE_DIRS) 21 | 22 | # Check for CAMD library 23 | find_library(CAMD_LIBRARIES camd 24 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/lib ${SUITESPARSE_DIR}/CAMD/lib $ENV{SUITESPARSE_DIR}/lib $ENV{SUITESPARSE_DIR}/CAMD/lib 25 | DOC "The CAMD library" 26 | ) 27 | mark_as_advanced(CAMD_LIBRARIES) 28 | 29 | # Standard package handling 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(CAMD 32 | "CAMD could not be found. Be sure to set SUITESPARSE_DIR correctly." 33 | CAMD_LIBRARIES CAMD_INCLUDE_DIRS) 34 | -------------------------------------------------------------------------------- /cmake.modules/FindCCOLAMD.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find CCOLAMD 2 | # 3 | # OUTPUT: 4 | # CCOLAMD_FOUND - system has CCOLAMD 5 | # CCOLAMD_INCLUDE_DIRS - include directories for CCOLAMD 6 | # CCOLAMD_LIBRARIES - libraries for CCOLAMD 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | 12 | message(STATUS "Checking for package 'CCOLAMD'") 13 | 14 | # Check for header file 15 | find_path(CCOLAMD_INCLUDE_DIRS ccolamd.h 16 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/include ${SUITESPARSE_DIR}/CCOLAMD/include $ENV{SUITESPARSE_DIR}/include $ENV{SUITESPARSE_DIR}/CCOLAMD/include 17 | PATH_SUFFIXES suitesparse ufsparse 18 | DOC "Directory where the CCOLAMD header is located" 19 | ) 20 | mark_as_advanced(CCOLAMD_INCLUDE_DIRS) 21 | 22 | # Check for CCOLAMD library 23 | find_library(CCOLAMD_LIBRARIES ccolamd 24 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/lib ${SUITESPARSE_DIR}/CCOLAMD/lib $ENV{SUITESPARSE_DIR}/lib $ENV{SUITESPARSE_DIR}/CCOLAMD/lib 25 | DOC "The CCOLAMD library" 26 | ) 27 | mark_as_advanced(CCOLAMD_LIBRARIES) 28 | 29 | # Standard package handling 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(CCOLAMD 32 | "CCOLAMD could not be found. Be sure to set SUITESPARSE_DIR correctly." 33 | CCOLAMD_LIBRARIES CCOLAMD_INCLUDE_DIRS) 34 | -------------------------------------------------------------------------------- /cmake.modules/FindCOLAMD.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find COLAMD 2 | # 3 | # OUTPUT: 4 | # COLAMD_FOUND - system has COLAMD 5 | # COLAMD_INCLUDE_DIRS - include directories for COLAMD 6 | # COLAMD_LIBRARIES - libraries for COLAMD 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | 12 | message(STATUS "Checking for package 'COLAMD'") 13 | 14 | # Check for header file 15 | find_path(COLAMD_INCLUDE_DIRS colamd.h 16 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/include ${SUITESPARSE_DIR}/COLAMD/include $ENV{SUITESPARSE_DIR}/include $ENV{SUITESPARSE_DIR}/COLAMD/include 17 | PATH_SUFFIXES suitesparse ufsparse 18 | DOC "Directory where the COLAMD header is located" 19 | ) 20 | mark_as_advanced(COLAMD_INCLUDE_DIRS) 21 | 22 | # Check for COLAMD library 23 | find_library(COLAMD_LIBRARIES colamd 24 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/lib ${SUITESPARSE_DIR}/COLAMD/lib $ENV{SUITESPARSE_DIR}/lib $ENV{SUITESPARSE_DIR}/COLAMD/lib 25 | DOC "The COLAMD library" 26 | ) 27 | mark_as_advanced(COLAMD_LIBRARIES) 28 | 29 | # Standard package handling 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(COLAMD 32 | "COLAMD could not be found. Be sure to set SUITESPARSE_DIR correctly." 33 | COLAMD_LIBRARIES COLAMD_INCLUDE_DIRS) 34 | -------------------------------------------------------------------------------- /cmake.modules/FindFFTW3.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find FFTW3 2 | # 3 | # OUTPUT: 4 | # FFTW3_FOUND - system has FFTW3 5 | # FFTW3_LIBRARIES - libraries for FFTW3 6 | # 7 | # Ludmil 8 | # 20230201 9 | 10 | # Check for FFTW3 library 11 | message(STATUS "Checking for 'FFTW3' library") 12 | find_library(FFTW3_LIBRARY ${FFTW3_LIBRARY_NAME} 13 | ) 14 | mark_as_advanced(FFTW3_LIBRARY) 15 | 16 | # Collect libraries 17 | if (FFTW3_FOUND) 18 | set(FFTW3_LIBRARIES ${FFTW3_LIBRARIES}) 19 | endif() 20 | 21 | # Try compiling and running test program 22 | if (FFTW3_LIBRARIES) 23 | # Set flags for building test program 24 | set(CMAKE_REQUIRED_LIBRARIES ${FFTW3_LIBRARIES}) 25 | endif(FFTW3_LIBRARIES) 26 | 27 | 28 | # Standard package handling 29 | include(FindPackageHandleStandardArgs) 30 | find_package_handle_standard_args(FFTW3 31 | "FFTW3 could not be found. Be sure to set FFTW3_DIR correctly." 32 | FFTW3_LIBRARY) 33 | -------------------------------------------------------------------------------- /cmake.modules/FindHDF5.cmake: -------------------------------------------------------------------------------- 1 | 2 | # - Try to find HDF5 3 | # 4 | # OUTPUT: 5 | # HDF5_FOUND - system has HDF5 6 | # HDF5_LIBRARIES - libraries for HDF5 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | # Modified 2020-05-29 --ltz 12 | 13 | # Check for HDF5 library 14 | message(STATUS "Checking for 'HDF5' library") 15 | find_library(HDF5_LIBRARY ${HDF5_LIBRARY_NAME} 16 | ) 17 | #HINTS ${HDF5_DIR} ${HDF5_DIR}/lib ${HDF5_DIR}/hdf5/serial ${HDF5_DIR}/hdf5/openmpi DOC "The HDF5 library" 18 | mark_as_advanced(HDF5_LIBRARY) 19 | 20 | # Collect libraries 21 | if (HDF5_FOUND) 22 | set(HDF5_LIBRARIES ${HDF5_LIBRARIES}) 23 | endif() 24 | 25 | # Try compiling and running test program 26 | if (HDF5_LIBRARIES) 27 | # Set flags for building test program 28 | set(CMAKE_REQUIRED_LIBRARIES ${HDF5_LIBRARIES}) 29 | endif(HDF5_LIBRARIES) 30 | 31 | 32 | # Standard package handling 33 | include(FindPackageHandleStandardArgs) 34 | find_package_handle_standard_args(HDF5 35 | "HDF5 could not be found. Be sure to set HDF5_DIR correctly." 36 | HDF5_LIBRARY) 37 | -------------------------------------------------------------------------------- /cmake.modules/FindLAPACK.cmake: -------------------------------------------------------------------------------- 1 | 2 | # - Try to find LAPACK 3 | # 4 | # OUTPUT: 5 | # LAPACK_FOUND - system has LAPACK 6 | # LAPACK_LIBRARIES - libraries for LAPACK 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | # Modified 2020-05-29 --ltz 12 | 13 | # Check for LAPACK library 14 | #message(STATUS "Checking for 'BLAS' library") 15 | find_library(LAPACK_LIBRARY lapack 16 | HINTS ${LAPACK_DIR} ${LAPACK_DIR}/lib ${LAPACK_DIR}/lapack/lib $ENV{LAPACK_DIR}/lib $ENV{LAPACK_DIR}/LAPACK/lib 17 | DOC "The LAPACK library" 18 | ) 19 | mark_as_advanced(LAPACK_LIBRARY) 20 | 21 | # Collect libraries 22 | if (LAPACK_FOUND) 23 | set(LAPACK_LIBRARIES ${LAPACK_LIBRARIES}) 24 | endif() 25 | 26 | # Try compiling and running test program 27 | if (LAPACK_LIBRARIES) 28 | # Set flags for building test program 29 | set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES}) 30 | endif(LAPACK_LIBRARIES) 31 | 32 | 33 | # Standard package handling 34 | include(FindPackageHandleStandardArgs) 35 | find_package_handle_standard_args(LAPACK 36 | "LAPACK could not be found. Be sure to set LAPACK_DIR correctly." 37 | LAPACK_LIBRARY) 38 | -------------------------------------------------------------------------------- /cmake.modules/FindMETIS.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find METIS 2 | # 3 | # OUTPUT: 4 | # METIS_FOUND - system has METIS 5 | # METIS_INCLUDE_DIRS - include directories for METIS 6 | # METIS_LIBRARIES - libraries for METIS 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | 11 | message(STATUS "Checking for package 'METIS'") 12 | 13 | # Check for header file 14 | find_path(METIS_INCLUDE_DIRS metis.h 15 | HINTS ${METIS_DIR}/include ${METIS_DIR}/lib ${METIS_DIR}/METIS/include ${METIS_DIR}/METIS/lib $ENV{METIS_DIR}/include $ENV{METIS_DIR}/lib $ENV{METIS_DIR}/METIS/include $ENV{METIS_DIR}/METIS/lib 16 | PATH_SUFFIXES suitesparse ufsparse 17 | DOC "Directory where the METIS header is located" 18 | ) 19 | mark_as_advanced(METIS_INCLUDE_DIRS) 20 | 21 | # Check for METIS library 22 | find_library(METIS_LIBRARIES metis 23 | HINTS ${METIS_DIR}/include ${METIS_DIR}/lib ${METIS_DIR}/METIS/include ${METIS_DIR}/METIS/lib $ENV{METIS_DIR}/include $ENV{METIS_DIR}/lib $ENV{METIS_DIR}/METIS/include $ENV{METIS_DIR}/METIS/lib 24 | DOC "The METIS library" 25 | ) 26 | mark_as_advanced(METIS_LIBRARIES) 27 | 28 | # Standard package handling 29 | include(FindPackageHandleStandardArgs) 30 | find_package_handle_standard_args(METIS 31 | "METIS could not be found. Be sure to set METIS_DIR." 32 | METIS_LIBRARIES METIS_INCLUDE_DIRS) 33 | -------------------------------------------------------------------------------- /cmake.modules/FindMUMPS.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find MUMPS 2 | # 3 | # Once done this will define 4 | # MUMPS_FOUND - System has Mumps 5 | # MUMPS_INCLUDE_DIRS - The Mumps include directories 6 | # MUMPS_LIBRARY_DIRS - The library directories needed to use Mumps 7 | # MUMPS_LIBRARIES - The libraries needed to use Mumps 8 | # 9 | # Chensong Zhang 10 | # 10/06/2014 11 | 12 | message(STATUS "Checking for dependent packages of 'MUMPS'") 13 | 14 | find_package(BLAS) 15 | find_package(Threads REQUIRED) 16 | 17 | if (MUMPS_INCLUDE_DIR) 18 | # in cache already 19 | SET(MUMPS_FIND_QUIETLY TRUE) 20 | endif (MUMPS_INCLUDE_DIR) 21 | 22 | # Check for header file 23 | # find_path(MUMPS_INCLUDE_DIR dmumps_c.h mpi.h 24 | # HINTS ${MUMPS_DIR}/include ${MUMPS_DIR}/libseq $ENV{MUMPS_DIR}/include $ENV{IPOPT_HOME}/MUMPS/include/ 25 | find_path(MUMPS_INCLUDE_DIR dmumps_c.h 26 | HINTS ${MUMPS_DIR}/include $ENV{MUMPS_DIR}/include $ENV{IPOPT_HOME}/MUMPS/include/ 27 | DOC "Directory where the MUMPS header is located" 28 | ) 29 | mark_as_advanced(MUMPS_INCLUDE_DIR) 30 | 31 | # Check for MUMPS libraries: dmumps, mumps_common pord mpiseq 32 | find_library(MUMPS_LIB dmumps 33 | HINTS ${MUMPS_DIR}/lib $ENV{MUMPS_DIR}/lib $ENV{IPOPT_HOME}/MUMPS/lib/ 34 | DOC "The MUMPS library" 35 | ) 36 | 37 | find_library(MUMPS_LIBC mumps_common 38 | HINTS ${MUMPS_DIR}/lib $ENV{MUMPS_DIR}/lib $ENV{IPOPT_HOME}/MUMPS/lib/ 39 | DOC "The MUMPS Common library" 40 | ) 41 | 42 | find_library(MUMPS_LIB_PORD pord 43 | HINTS ${MUMPS_DIR}/lib $ENV{MUMPS_DIR}/lib ${MUMPS_DIR}/PORD/lib $ENV{MUMPS_DIR}/PORD/lib 44 | DOC "The MUMPS PORD library" 45 | ) 46 | 47 | find_library(MUMPS_LIB_MPISEQ mpiseq 48 | HINTS ${MUMPS_DIR}/lib $ENV{MUMPS_DIR}/lib ${MUMPS_DIR}/libseq $ENV{MUMPS_DIR}/libseq 49 | DOC "The MUMPS MPISEQ library" 50 | ) 51 | 52 | set(MUMPS_INCLUDE_DIRS "${MUMPS_INCLUDE_DIR}" ) 53 | set(MUMPS_LIBRARIES "${MUMPS_LIB}" "${MUMPS_LIBC}" "${MUMPS_LIB_PORD}" "${MUMPS_LIB_MPISEQ}") 54 | 55 | if (Threads_FOUND) 56 | set(MUMPS_LIBRARIES ${MUMPS_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 57 | endif() 58 | 59 | if (BLAS_FOUND) 60 | set(MUMPS_LIBRARIES ${MUMPS_LIBRARIES} ${BLAS_LIBRARIES}) 61 | endif() 62 | 63 | include(FindPackageHandleStandardArgs) 64 | # handle the QUIETLY and REQUIRED arguments and set LIBCPLEX_FOUND to TRUE 65 | # if all listed variables are TRUE 66 | find_package_handle_standard_args(MUMPS DEFAULT_MSG 67 | MUMPS_LIB MUMPS_INCLUDE_DIR) 68 | 69 | mark_as_advanced(MUMPS_INCLUDE_DIR MUMPS_LIB MUMPS_LIBC MUMPS_LIB_PORD MUMPS_LIB_MPISEQ) 70 | -------------------------------------------------------------------------------- /cmake.modules/FindRT.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find RT 2 | # 3 | # OUTPUT: 4 | # RT_FOUND - system has RT 5 | # RT_INCLUDE_DIRS - include directories for RT 6 | # RT_LIBRARIES - libraries for RT 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | 11 | message(STATUS "Checking for package 'RT'") 12 | 13 | # Check for header file 14 | find_path(RT_INCLUDE_DIRS time.h 15 | HINTS /usr/include /usr/local/include /opt/local/include 16 | DOC "Directory where the RT header is located" 17 | ) 18 | mark_as_advanced(RT_INCLUDE_DIRS) 19 | 20 | # Check for RT library 21 | find_library(RT_LIBRARIES rt 22 | HINTS /usr/lib /usr/local/lib /opt/local/lib 23 | DOC "The RT library" 24 | ) 25 | mark_as_advanced(RT_LIBRARIES) 26 | 27 | # Standard package handling 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(RT 30 | "RT could not be found. Be sure to set RT_DIR." 31 | RT_LIBRARIES RT_INCLUDE_DIRS) 32 | -------------------------------------------------------------------------------- /cmake.modules/FindSUITESPARSE.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find SUITESPARSE: ALL LIBRARIES. 2 | # 3 | # OUTPUT: 4 | # SUITESPARSE_FOUND - system has SUITESPARSE 5 | # SUITESPARSE_INCLUDE_DIRS - include directories for SUITESPARSE 6 | # SUITESPARSE_LIBRARIES - libraries for SUITESPARSE 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 ludmil 11 | # Modified 2021-07-20 ludmil 12 | 13 | # Find packages that SUITESPARSE depends on 14 | find_package(BLAS) 15 | find_package(LAPACK) 16 | find_package(SUITESPARSE_CONFIG) 17 | find_package(AMD) 18 | find_package(UMFPACK) 19 | find_package(COLAMD) 20 | find_package(CAMD) 21 | find_package(CCOLAMD) 22 | #find_package(METIS) 23 | if(NOT APPLE) 24 | find_package(RT) 25 | endif(NOT APPLE) 26 | #find_package(BLAS) 27 | #find_package(LAPACK) 28 | #find_package(UMFPACK) 29 | 30 | message(STATUS "Checking for packages in 'SUITESPARSE'") 31 | 32 | # Set initial values 33 | set(SUITESPARSE_INCLUDE_DIRS "") 34 | set(SUITESPARSE_LIBRARIES "") 35 | mark_as_advanced(SUITESPARSE_INCLUDE_DIRS) 36 | 37 | # Collect paths 38 | if (AMD_FOUND) 39 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${AMD_INCLUDE_DIRS}) 40 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARY} ${AMD_LIBRARIES}) 41 | endif() 42 | if (SUITESPARSE_CONFIG_FOUND) 43 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${SUITESPARSE_CONFIG_INCLUDE_DIRS}) 44 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${SUITESPARSE_CONFIG_LIBRARIES}) 45 | endif() 46 | if (UMFPACK_FOUND) 47 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${UMFPACK_INCLUDE_DIRS}) 48 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARY} ${UMFPACK_LIBRARIES}) 49 | endif() 50 | if (COLAMD_FOUND) 51 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${COLAMD_INCLUDE_DIRS}) 52 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${COLAMD_LIBRARIES}) 53 | endif() 54 | if (CAMD_FOUND) 55 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${CAMD_INCLUDE_DIRS}) 56 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${CAMD_LIBRARIES}) 57 | endif() 58 | if (CCOLAMD_FOUND) 59 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${CCOLAMD_INCLUDE_DIRS}) 60 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${CCOLAMD_LIBRARIES}) 61 | endif() 62 | if (RT_FOUND AND (NOT APPLE)) 63 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${RT_INCLUDE_DIRS}) 64 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${RT_LIBRARIES}) 65 | endif() 66 | if (METIS_FOUND) 67 | set(SUITESPARSE_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIRS} ${METIS_INCLUDE_DIRS}) 68 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${METIS_LIBRARIES}) 69 | endif() 70 | 71 | if (BLAS_FOUND) 72 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${BLAS_LIBRARIES}) 73 | endif() 74 | if (LAPACK_FOUND) 75 | set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} ${LAPACK_LIBRARIES}) 76 | endif() 77 | 78 | #set(SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARIES} "-lgfortran") 79 | 80 | mark_as_advanced(SUITESPARSE_INCLUDE_DIRS) 81 | mark_as_advanced(SUITESPARSE_LIBRARIES) 82 | 83 | # Try to run a test program that uses SUITESPARSE 84 | # Standard package handling 85 | include(FindPackageHandleStandardArgs) 86 | find_package_handle_standard_args(SUITESPARSE 87 | "SUITESPARSE could not be found. Be sure to set SUITESPARSE_DIR correctly." 88 | SUITESPARSE_LIBRARIES SUITESPARSE_INCLUDE_DIRS) 89 | -------------------------------------------------------------------------------- /cmake.modules/FindSUITESPARSE_CONFIG.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find SUITEPARSE_CONFIG 2 | # 3 | # OUTPUT: 4 | # SUITESPARSE_CONFIG_FOUND - system has SUITEPARSE_CONFIG 5 | # SUITESPARSE_CONFIG_INCLUDE_DIRS - include directories for SUITEPARSE_CONFIG 6 | # SUITESPARSE_CONFIG_LIBRARIES - libraries for SUITEPARSE_CONFIG 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | 12 | message(STATUS "Checking for package 'SUITESPARSE_CONFIG'") 13 | 14 | # Check for header file 15 | find_path(SUITESPARSE_CONFIG_INCLUDE_DIRS SuiteSparse_config.h UFconfig.h 16 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/include ${SUITESPARSE_DIR}/SuiteSparse_config ${SUITESPARSE_DIR}/SuiteSparse_config/include ${SUITESPARSE_DIR}/SuiteSparse_config ${SUITESPARSE_DIR}/SuiteSparse_config/include $ENV{SUITESPARSE_DIR} $ENV{SUITESPARSE_DIR}/include 17 | PATH_SUFFIXES suitesparse SuiteSparse ufsparse 18 | DOC "Directory where the SUITESPARSE_CONFIG header is located" 19 | ) 20 | mark_as_advanced(SUITESPARSE_CONFIG_INCLUDE_DIRS) 21 | 22 | # Check for SUITESPARSE_CONFIG library 23 | find_library(SUITESPARSE_CONFIG_LIBRARIES suitesparseconfig ufconfig 24 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/lib ${SUITESPARSE_DIR}/SuiteSparse_config ${SUITESPARSE_DIR}/SuiteSparse_config/lib $ENV{SUITESPARSE_DIR} $ENV{SUITESPARSE_DIR}/lib $ENV{SUITESPARSE_DIR}/SuiteSparse_config $ENV{SUITESPARSE_DIR}/SuiteSparse_config/lib 25 | DOC "The SUITESPARSE_CONFIG library" 26 | ) 27 | mark_as_advanced(SUITESPARSE_CONFIG_LIBRARIES) 28 | 29 | # Standard package handling 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(SUITESPARSE_CONFIG 32 | "SUITESPARSE_CONFIG could not be found. Be sure to set SUITESPARSE_DIR correctly." 33 | SUITESPARSE_CONFIG_LIBRARIES SUITESPARSE_CONFIG_INCLUDE_DIRS) 34 | -------------------------------------------------------------------------------- /cmake.modules/FindSUPERLU.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find SuperLU 2 | # 3 | # OUTPUT: 4 | # SUPERLU_FOUND - system has SuperLU 5 | # SUPERLU_INCLUDE_DIRS - include directories for SuperLU 6 | # SUPERLU_LIBRARIES - libraries for SuperLU 7 | # 8 | # Xiaozhe Hu 9 | # 02/24/2014 10 | 11 | message(STATUS "Checking for dependent packages of 'SuperLU'") 12 | 13 | # Find packages that SuperLU depends on 14 | find_package(BLAS) 15 | 16 | message(STATUS "Checking for package 'SuperLU'") 17 | 18 | # Check for header file 19 | find_path(SUPERLU_INCLUDE_DIRS slu_ddefs.h 20 | HINTS ${SUPERLU_DIR}/SRC ${SUPERLU_DIR}/SuperLU/SRC $ENV{SUPERLU_DIR}/SRC $ENV{SUPERLU_DIR}/SuperLU/SRC 21 | PATH_SUFFIXES SuperLU 22 | DOC "Directory where the SuperLU header is located" 23 | ) 24 | mark_as_advanced(SUPERLU_INCLUDE_DIRS) 25 | 26 | # Check for SuperLU library 27 | find_library(SUPERLU_LIBRARIES superlu superlu_4.3 superlu_4.2 superlu_4.1 superlu_4.0 28 | HINTS ${SUPERLU_DIR}/lib ${SUPERLU_DIR}/SuperLU/lib $ENV{SUPERLU_DIR}/lib $ENV{SUPERLU_DIR}/SuperLU/lib 29 | DOC "The SuperLU library" 30 | ) 31 | mark_as_advanced(SUPERLU_LIBRARIES) 32 | 33 | # Collect libraries 34 | if (BLAS_FOUND) 35 | set(SUPERLU_LIBRARIES ${SUPERLU_LIBRARIES} ${BLAS_LIBRARIES}) 36 | endif() 37 | 38 | # Standard package handling 39 | include(FindPackageHandleStandardArgs) 40 | find_package_handle_standard_args(SUPERLU 41 | "SuperLU could not be found. Be sure to set SUPERLU_DIR." 42 | SUPERLU_LIBRARIES SUPERLU_INCLUDE_DIRS) 43 | -------------------------------------------------------------------------------- /cmake.modules/FindUMFPACK.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find UMFPACK 2 | # 3 | # OUTPUT: 4 | # UMFPACK_FOUND - system has UMFPACK 5 | # UMFPACK_INCLUDE_DIRS - include directories for UMFPACK 6 | # UMFPACK_LIBRARIES - libraries for UMFPACK 7 | # 8 | # Xiaozhe Hu 9 | # 02/27/2013 10 | # Modified 2015-08-08 --ltz 11 | 12 | message(STATUS "Checking for dependent packages of 'UMFPACK'") 13 | 14 | # Find packages that UMFPACK depends on 15 | find_package(BLAS) 16 | find_package(SUITESPARSE_CONFIG) 17 | find_package(AMD) 18 | ### next one not needed if we only want UMFPACK. 19 | find_package(CHOLMOD) 20 | 21 | message(STATUS "Checking for package 'UMFPACK'") 22 | 23 | # Check for header file 24 | find_path(UMFPACK_INCLUDE_DIRS umfpack.h 25 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/include ${SUITESPARSE_DIR}/UMFPACK/include $ENV{SUITESPARSE_DIR}/include $ENV{SUITESPARSE_DIR}/UMFPACK/include 26 | PATH_SUFFIXES suitesparse ufsparse 27 | DOC "Directory where the UMFPACK header is located" 28 | ) 29 | mark_as_advanced(UMFPACK_INCLUDE_DIRS) 30 | 31 | # Check for UMFPACK library 32 | find_library(UMFPACK_LIBRARY umfpack 33 | HINTS ${SUITESPARSE_DIR} ${SUITESPARSE_DIR}/lib ${SUITESPARSE_DIR}/UMFPACK/lib $ENV{SUITESPARSE_DIR}/lib $ENV{SUITESPARSE_DIR}/UMFPACK/lib 34 | DOC "The UMFPACK library" 35 | ) 36 | mark_as_advanced(UMFPACK_LIBRARY) 37 | 38 | # Collect libraries 39 | if (AMD_FOUND) 40 | set(UMFPACK_INCLUDE_DIRS ${UMFPACK_INCLUDE_DIRS} ${AMD_INCLUDE_DIRS}) 41 | set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARY} ${AMD_LIBRARIES}) 42 | endif() 43 | if (BLAS_FOUND) 44 | set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${BLAS_LIBRARIES}) 45 | endif() 46 | if (SUITESPARSE_CONFIG_FOUND) 47 | set(UMFPACK_INCLUDE_DIRS ${UMFPACK_INCLUDE_DIRS} ${SUITESPARSE_CONFIG_INCLUDE_DIRS}) 48 | set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${SUITESPARSE_CONFIG_LIBRARIES}) 49 | endif() 50 | if (CHOLMOD_FOUND) 51 | set(UMFPACK_INCLUDE_DIRS ${UMFPACK_INCLUDE_DIRS} ${CHOLMOD_INCLUDE_DIRS}) 52 | set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${CHOLMOD_LIBRARIES}) 53 | endif() 54 | 55 | 56 | # Try compiling and running test program 57 | if (UMFPACK_INCLUDE_DIRS AND UMFPACK_LIBRARIES) 58 | 59 | # Set flags for building test program 60 | set(CMAKE_REQUIRED_INCLUDES ${UMFPACK_INCLUDE_DIRS}) 61 | set(CMAKE_REQUIRED_LIBRARIES ${UMFPACK_LIBRARIES}) 62 | 63 | # Build and run test program 64 | include(CheckCXXSourceRuns) 65 | check_cxx_source_runs(" 66 | /* Test program umfpack-ex1.c */ 67 | 68 | #include 69 | 70 | int main() 71 | { 72 | int n = 5; 73 | double x[5]; 74 | void *Symbolic, *Numeric; 75 | int i; 76 | 77 | int Ap[] = { 0, 2, 5, 9, 10, 12 }; 78 | int Ai[] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4 }; 79 | double Ax[] = { 2, 3, 3, -1, 4, 4, -3, 1, 2, 2, 6, 1 }; 80 | double b[] = { 8, 45, -3, 3, 19 }; 81 | 82 | umfpack_di_symbolic(n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL); 83 | umfpack_di_numeric(Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL); 84 | umfpack_di_free_symbolic(&Symbolic); 85 | 86 | umfpack_di_solve(UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, NULL, NULL); 87 | umfpack_di_free_numeric(&Numeric); 88 | 89 | return 0; 90 | } 91 | " UMFPACK_TEST_RUNS) 92 | 93 | endif() 94 | 95 | 96 | # Standard package handling 97 | include(FindPackageHandleStandardArgs) 98 | find_package_handle_standard_args(UMFPACK 99 | "UMFPACK could not be found. Be sure to set SUITESPARSE_DIR correctly." 100 | UMFPACK_LIBRARY UMFPACK_INCLUDE_DIRS UMFPACK_TEST_RUNS) 101 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | show_downloads: true 3 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: HAZmath 3 | --- 4 | 5 | ## HAZmath: A Simple Finite Element, Graph, and Solver Library 6 | --- 7 | 8 | **Authors:** [Xiaozhe \***H**\*u (Tufts)](https://xiaozhehu.math.tufts.edu/), [James \***A**\*dler (Tufts)](https://jadler.math.tufts.edu/), [Ludmil \***Z**\*ikatanov (Penn State)](https://ludmil02.github.io/) 9 | 10 | **Contributors:** 11 | 12 | - ***HAZNICS (HAZMATH+FEniCS) and Python interface:*** Ana Budisa (Simula, Norway), Miroslav Kuchta (Simula, Norway), Kent-Andre Mardal (Simula, Univ Oslo, Norway). 13 | - ***Rational Approximation of Functions***: Clemens Hofreither (RICAM, Austrian Academy of Sciences) 14 | - ***Grid refinement and adaptive FE***: Yuwen Li (Penn State) 15 | - ***Geometric MultiGrid:*** Johannes Kraus (Universitat Duisburg-Essen, Germany), Peter Ohm (Sandia), Yunrong Zhu (Idaho State). 16 | 17 | --- 18 | 19 | **Overview:** The HAZMATH Finite Element (FE) and Solver library is built from C (C99 compatible) source files and provides software components that can be used to simulate physical/social phenomena described by Partial Differential Equations (PDEs), systems of PDEs, or graphs. We have included several standard discretizations for PDEs, often used in various applications. Our examples range from simple scalar elliptic PDEs to systems of PDEs, include time-dependent and nonlinear problems, and contain methods for the solution of linear systems. 20 | 21 | Our aim is to provide a basic tool, which can be used to tackle specific problems on demand. We do not intend to create a universal package that contains all discretizations available. HAZMATH contains the software to solve numerical models based on finite-element/volume/difference discretizations, and our team can assist in tweaking and adjusting these basic tools to meet the demands of the specific application. Thus, we aim to complement the user's expertise and help build application-specific packages. 22 | 23 | --- 24 | 25 | **Components:** As of early 2017, the main components of the HAZMATH FE/Graph library are: 26 | 27 | 1. **Basic FE:** Low order (up to order 2) continuous FE and mixed FE discretizations for Darcy's flow and scalar elliptic equations; Stable discretizations for Stokes and linear elasticity; Discretization for full Maxwell's equations using Nedelec and Raviart-Thomas elements. 28 | 29 | 2. **Solvers:** Unsmoothed Aggregation Algebraic Multigrid Methods (UA-AMG); Preconditioned Krylov subspace methods. 30 | 31 | 3. **HAZNICS:** Collaboration with Simula; Interface with Python and use of HAZMATH solvers in applications modeled by [FEniCS](https://fenicsproject.org/) finite element libraries. 32 | 33 | 4. **Interfaces with External Libraries:** Some routines require a direct linear solver and these depend on the [SuiteSparse](http://faculty.cse.tamu.edu/davis/suitesparse.html) library (by Tim Davis, Texas A & M), which the user needs to install. We also provide an interface for using [Multigraph 2.1](http://ccom.ucsd.edu/~reb/software.html) (by Randolph E Bank, UCSD) as a solver. 34 | 35 | --- 36 | 37 | **System Requirements:** The library should build on any standard Linux OS or MAC OS X, using cmake (>=3.12). 38 | 39 | --- 40 | 41 | **Licensing:** This software is a free software distributed under the MIT License. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. See further details about the [MIT License](https://opensource.org/licenses/MIT) at the [Open Source Initiative Licenses](https://opensource.org/licenses/) page. 42 | 43 | 44 | (c) 2009- by X. Hu, J. Adler, L. Zikatanov 45 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | ##################################################### 2 | # Last Modified 2017-09-29 --jha 3 | #################################################### 4 | 5 | 6 | To make the executables for the examples: 7 | 1. edit the variables in examples.mk to match your system. 8 | 2. change to the directory with an example and type "make", e.g.: 9 | cd basic_elliptic ; make 10 | 3. Note that if you want to link to an external package, such as SuiteSparse 11 | make sure that HAZMATH was compiled appropriately and modify the makefile in 12 | specific examples directory as needed. 13 | -------------------------------------------------------------------------------- /examples/amr_grids/input/2d_2L.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | title{2 Lshaped domains with connected boundaries} 5 | % 6 | dimension{2} % spatial dimension in which the grid has to be generated 7 | % 8 | print_level{0} % how much information to print out: 0 less | >0 Something 9 | 10 | %---------------% 11 | % files: writeable by the user 12 | % vtu files for plotting follow the same convention. 13 | %---------------% 14 | file_grid{output/2d_2L.haz} 15 | file_vtu{output/2d_2L.vtu} 16 | 17 | %---------------% 18 | % coordinate systems: Each has coordinates of the origin o[0:dim-1] 19 | % type (0=cartesian, 1=polar) 20 | % 21 | %---------------% 22 | 23 | num_coordsystems{3} % number of coordinate systems 24 | 25 | %% data for the coord systems: coord-system label, coords of the 26 | %% origin, type. the labels should be integers, consequtive and start 27 | %% from 0 the values of the above quantities are given as space tab 28 | %% separated values 29 | 30 | data_coordsystems{0 0. 0. 0 31 | 1 0. 0. 1 32 | 2 -1. -1. 1} 33 | %---------------% 34 | % graph which describes the domain. The input are 35 | % vertices and edges. The graph has to be a union of polygons, 36 | % of polyhedrons that are isomorphic to an n-dimensional cube. 37 | %---------------% 38 | 39 | num_vertices{15} %number of vertices 40 | 41 | %---------------% 42 | %coords (see way below): for every node 1:numvertices give coords (dim 43 | % coords per node) 44 | 45 | % If two points on an edge are in the same coordinate system, 46 | % then all points on this edge are in polar coordinate system. 47 | % if two points on an edge are in in different coordinate systems, 48 | % then the points on the edge are on a straight 49 | %% line connecting the two vertices. 50 | %---------------% 51 | 52 | %%% vertex number (consequtive), coord system, vertex coords. Polar coords are in 53 | %%% degrees. 54 | data_vertices{0 0 -1. -1. %% vertex number, coord system, coords 55 | 1 0 -1. 0. 56 | 2 0 1.5 1.5 57 | 3 0 0. 0. 58 | 4 0 1. -1. 59 | 5 0 1. 0. 60 | 6 0 -1. 1. 61 | 7 0 0. 1. 62 | 63 | 8 0 2. 2. 64 | 9 0 1.5 2. 65 | 10 0 0. -1. 66 | 11 0 2. 1.5 67 | 12 0 1.5 1. 68 | 13 0 2. 1. 69 | 14 0 1. 1.5 70 | } 71 | 72 | %---------------% 73 | % edges and number of divisions for every edge. 74 | % opposite edges have the same number of divisions. if they do not, 75 | % then the max number of divisions is taken. 76 | %---------------% 77 | 78 | num_edges{7} % 79 | 80 | %% edge: 1st vertex, 2nd vertex, number of divisions. Does not have to contain all edges. Edges that are not listed here and are not parallel to any of the edges listed here are not divided. 81 | 82 | data_edges{0 1 1 83 | 1 3 1 84 | 0 10 1 85 | 10 3 1 86 | 3 7 1 87 | 4 5 1 88 | 6 7 1 89 | } 90 | 91 | num_macroelements{6} 92 | 93 | %%% vertices forming the macroelement ordered as explained in the 94 | %%% README. vertex numbers (v[0]...v[2^{d}-1]) and the material for 95 | %%% the macroelement. 96 | 97 | data_macroelements{ 98 | 10 4 3 5 1 99 | 0 1 10 3 2 100 | 6 7 1 3 -8 101 | 102 | 7 12 14 2 1 103 | 11 8 2 9 -8 104 | 12 13 2 11 2 105 | } 106 | 107 | num_macrofaces{10} 108 | 109 | % any face which needs a code (for example boundary faces: face 110 | % number. If a face is not included here and is a boundary face then 111 | % its code is set to Dirichlet (i.e. 1...16). Internal faces not found 112 | % here have a code 0. Faces given here and not found in the 113 | % macroelement list are ignored. 114 | 115 | data_macrofaces{0 10 1 %boundary face with code 1 116 | 1 4 0 % iterior face 117 | 3 10 4 118 | 10 3 0 119 | 0 1 32 120 | 1 4 24 121 | 4 5 17 122 | 3 5 1 123 | 6 7 2 124 | 7 3 3 125 | } 126 | 127 | %%%%%%%%%%%%%%AMR %%%%%%%%%%%%%%%%%%%%%%%%%%%% 128 | num_refinements{10} 129 | 130 | refinement_type{0} 131 | 132 | err_stop_refinement{ -1.e-10 } 133 | %%% marking type: 0 everything is marked; not zero can be user defined 134 | %%% marking strategy as in the examples given in the file 135 | %%% solve_estimate_mark.h 136 | 137 | amr_marking_type{1} 138 | 139 | -------------------------------------------------------------------------------- /examples/amr_grids/input/2d_L.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | title{L-shaped domain} 5 | dimension{2} % spatial dimension in which the grid has to be generated 6 | print_level{1} % how much information to print out: 0 less | >0 more 7 | refinement_type{1} %% -1 (edges going left to right in the unit cube; 1 (criss-cross). 8 | file_grid{output/2d_L.haz} 9 | file_vtu{output/2d_L.vtu} 10 | 11 | %%%%%%%%%%%%%%AMR %%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | %%% marking type: 0 everything is marked; not zero can be user defined 13 | %%% marking strategy as in the examples given in the file 14 | %%% solve_estimate_mark.h 15 | 16 | amr_marking_type{1} 17 | 18 | num_refinements{0} 19 | 20 | err_stop_refinement{ -1.e-10 } 21 | 22 | 23 | %%% coordinate systems: 24 | num_coordsystems{3} % number of coordinate systems 25 | data_coordsystems{0 0. 0. 0 26 | 1 0. 0. 1 27 | 2 -1. -1. 1} 28 | 29 | num_vertices{8} %number of vertices 30 | data_vertices{0 0 -1. -1. %% vertex number, coord system, coords 31 | 1 0 -1. 0. 32 | 2 0 0. -1. 33 | 3 0 0. 0. 34 | 4 0 1. -1. 35 | 5 0 1. 0. 36 | 6 0 -1. 1. 37 | 7 0 0. 1. 38 | } 39 | num_edges{6} % 40 | data_edges{0 1 2 %(v1 v2 num_divisions) 41 | 1 3 2 42 | 0 2 2 43 | 2 3 2 44 | 3 7 2 45 | 4 5 2 46 | 6 7 2 47 | } 48 | num_macroelements{3} 49 | data_macroelements{2 4 3 5 1 50 | 0 1 2 3 2 51 | 6 7 1 3 -8 52 | } 53 | num_macrofaces{10} 54 | data_macrofaces{0 2 1 %boundary face with code 1 55 | 1 4 -1 % iterior face 56 | 3 2 4 57 | 2 3 -2 58 | 0 1 32 59 | 1 4 24 60 | 4 5 17 61 | 3 5 1 62 | 6 7 2 63 | 7 3 3 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /examples/amr_grids/input/2d_ann.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | title{Annulus in 2D} 5 | % 6 | dimension{2} % spatial dimension in which the grid has to be generated 7 | % 8 | print_level{0} % how much information to print out: 0 less | >0 more 9 | 10 | refinement_type{0} % -1 is usual 11 | 12 | %---------------% 13 | % files: writeable by the user 14 | %% vtu files for plotting follow the same convention. 15 | %---------------% 16 | file_grid{output/2d_ann.haz} 17 | file_vtu{output/2d_ann.vtu} 18 | 19 | %---------------% 20 | % coordinate systems: Each has coordinates of the origin o[0:dim-1] 21 | % type (0=cartesian, 1=polar) 22 | % 23 | %---------------% 24 | 25 | num_coordsystems{3} % number of coordinate systems 26 | 27 | %% data for the coord systems: coord-system label, coords of the 28 | %% origin, type. the labels should be integers, consequtive and start 29 | %% from 0 the values of the above quantities are given as space tab 30 | %% separated values 31 | 32 | data_coordsystems{0 0 0. 0. 33 | 1 1 0. 0. 34 | 2 1 -1. -1.} 35 | %---------------% 36 | % graph which describes the domain. The input are 37 | % vertices and edges. The graph has to be a union of polygons, 38 | % of polyhedrons that are isomorphic to an n-dimensional cube. 39 | %---------------% 40 | 41 | num_vertices{8} %number of vertices 42 | %%% coords, type, origin for polar system: angles are in degrees 43 | %%% data_vertices{ 44 | %%% 0 0 -1. -1. 45 | %%% 1 0 -1. 1. 46 | %%% 2 0 1. -1. 47 | %%% 3 0 1. 1. 48 | %%% 4 0 -0.25 -0.25 49 | %%% 5 0 -0.25 0.25 50 | %%% 6 0 0.25 -0.25 51 | %%% 7 0 0.25 0.25 52 | %%% } 53 | 54 | data_vertices{ 55 | 0 1 2. -135. 56 | 1 1 2. 135. 57 | 2 1 2. 45. 58 | 3 1 2. -45. 59 | 4 1 1. -135. 60 | 5 1 1. 135. 61 | 6 1 1. 45. 62 | 7 1 1. -45. 63 | } 64 | 65 | num_edges{8} % 66 | 67 | %% edge: 1st vertex, 2nd vertex, number of divisions. 68 | data_edges{4 0 6 69 | 5 1 6 70 | 6 2 6 71 | 3 7 6 72 | 0 1 12 73 | 2 3 12 74 | 1 2 12 75 | 0 3 12 76 | } 77 | %%% ====================MACROELEMENTS========================= 78 | num_macroelements{4} 79 | %%% NUMBERING OF VERTICES DESCRIBING A MACROELEMENT: Check the README. 80 | 81 | %%% macroelement number, vertices forming the macroelement, macroelement code. 82 | 83 | data_macroelements{ 84 | 0 1 4 5 1 85 | 0 3 4 7 2 86 | 2 3 6 7 4 87 | 1 2 5 6 5 88 | } 89 | 90 | num_macrofaces{1} 91 | 92 | % any face which needs a code (for example boundary faces: face 93 | % number. If a face is not included here and is a boundary face then 94 | % its code is set to Dirichlet (i.e. 1...16). Internal faces not found 95 | % here have a code 0. Faces given here and not found in the 96 | % macroelement list are ignored. 97 | 98 | data_macrofaces{0 1 1 99 | } 100 | 101 | %%%%%%%%%%%%%%AMR %%%%%%%%%%%%%%%%%%%%%%%%%%%% 102 | num_refinements{5} 103 | 104 | err_stop_refinement{ -1.e-10 } 105 | %%% marking type: 0 everything is marked; not zero can be user defined 106 | %%% marking strategy as in the examples given in the file 107 | %%% solve_estimate_mark.h 108 | 109 | amr_marking_type{1} 110 | 111 | -------------------------------------------------------------------------------- /examples/amr_grids/input/2d_circle.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | %%%%%%%%%%%%%% AMR %%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | %%% marking type: 0 everything is marked; not zero can be user defined 6 | %%% marking strategy as in the examples given in the file 7 | %%% solve_estimate_mark.h 8 | 9 | title{Unit square in 2D} 10 | 11 | amr_marking_type{0} %% 0 means uniform refinement everywhere. 12 | 13 | num_refinements{5} 14 | 15 | err_stop_refinement{ -1.e-10 } %% for the user to define and use 16 | 17 | dimension{2} % spatial dimension in which the grid has to be generated 18 | 19 | print_level{1} % how much information to print out: 0 Nothing | >0 Something 20 | 21 | refinement_type{0} 22 | 23 | file_grid{output/2d_circle.haz} 24 | file_vtu{output/2d_circle.vtu} 25 | 26 | %---------------% 27 | % coordinate systems: Each has coordinates of the origin o[0:dim-1] 28 | % type (0=cartesian, 1=polar)% 29 | %---------------% 30 | num_coordsystems{2} % number of coordinate systems 31 | data_coordsystems{0 0 0. 0. 32 | 1 1 0. 0.} 33 | 34 | %---------------% 35 | % graph which describes the domain. The input are 36 | % vertices and edges. 37 | %---------------% 38 | 39 | num_vertices{4} %number of vertices 40 | %%% coords, type, origin for polar system: angles are in degrees 41 | data_vertices{0 1 1. -135. 42 | 1 1 1. -45. 43 | 2 1 1. 135. 44 | 3 1 1. 45. } 45 | % 46 | %---------------% 47 | % edges and number of divisions for every edge. 48 | % opposite edges have the same number of divisions. if they do not, 49 | % then the max number of divisions is taken. 50 | %---------------% 51 | 52 | num_edges{4} % 53 | 54 | %% edge: 1st vertex, 2nd vertex, number of divisions. 55 | data_edges{0 1 6 56 | 1 3 6 57 | 0 2 6 58 | 2 3 6 } 59 | 60 | 61 | %%% ====================MACROELEMENTS========================= 62 | num_macroelements{1} 63 | data_macroelements{0 1 2 3 2} %% v1...v4 and material. 64 | %%% ====================MACROFACES========================= 65 | num_macrofaces{4} 66 | data_macrofaces{0 1 1 67 | 1 3 1 68 | 0 2 1 69 | 3 2 1 70 | } %% codes on boundary faces (v1,v2,code). 71 | -------------------------------------------------------------------------------- /examples/amr_grids/input/2d_grid.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | title{2D Sector (polar coords)} 5 | % 6 | dimension{2} % spatial dimension in which the grid has to be generated 7 | % 8 | print_level{0} % how much information to print out: 0 Nothing | >0 Something 9 | 10 | refinement_type{0} 11 | 12 | 13 | %---------------% 14 | % files: writeable by the user 15 | % vtu files for plotting follow the same convention. 16 | %---------------% 17 | file_grid{output/2d_sector.haz} 18 | file_vtu{output/2d_sector.vtu} 19 | 20 | %---------------% 21 | % coordinate systems: Each has coordinates of the origin o[0:dim-1] 22 | % type (0=cartesian, 1=polar) 23 | % 24 | %---------------% 25 | 26 | num_coordsystems{3} % number of coordinate systems 27 | 28 | %% data for the coord systems: coord-system label, coords of the 29 | %% origin, type. the labels should be integers, consequtive and start 30 | %% from 0 the values of the above quantities are given as space tab 31 | %% separated values 32 | 33 | data_coordsystems{0 0 0. 0. 34 | 1 1 0. 0. 35 | 2 1 -1. -1.} 36 | %---------------% 37 | % graph which describes the domain. The input are 38 | % vertices and edges. The graph has to be a union of polygons, 39 | % of polyhedrons that are isomorphic to an n-dimensional cube. 40 | %---------------% 41 | 42 | num_vertices{4} %number of vertices 43 | 44 | %---------------% 45 | %---------------% 46 | 47 | %%% coords, type, origin for polar system: angles are in degrees 48 | data_vertices{0 0 -1. -1. 49 | 1 1 2. 0. 50 | 2 1 2. 90. 51 | 3 1 2. 45.} 52 | 53 | 54 | %data_vertices{0 0 -1. -1. 55 | % 1 0 1. -1. 56 | % 2 0 -1. 1. 57 | % 3 0 1. 1. } 58 | % 59 | %---------------% 60 | % edges and number of divisions for every edge. 61 | % opposite edges have the same number of divisions. if they do not, 62 | % then the max number of divisions is taken. 63 | %---------------% 64 | 65 | num_edges{4} % 66 | 67 | %% edge: 1st vertex, 2nd vertex, number of divisions. 68 | data_edges{0 1 1 69 | 1 3 2 70 | 0 2 4 71 | 2 3 3 } 72 | 73 | 74 | %%% ====================MACROELEMENTS========================= 75 | num_macroelements{1} 76 | %%% NUMBERING OF VERTICES DESCRIBING A MACROELEMENT: Check the README. 77 | 78 | %%% macroelement number, vertices forming the macroelement, macroelement code. 79 | 80 | data_macroelements{0 1 2 3 -11 81 | } 82 | 83 | num_macrofaces{4} 84 | 85 | % any face which needs a code (for example boundary faces: face 86 | % number. If a face is not included here and is a boundary face then 87 | % its code is set to Dirichlet (i.e. 1...16). Internal faces not found 88 | % here have a code 0. Faces given here and not found in the 89 | % macroelement list are ignored. 90 | 91 | data_macrofaces{0 1 1 92 | 1 3 31 93 | 0 2 2 94 | 3 2 14 95 | } 96 | 97 | %%%%%%%%%%%%%%AMR %%%%%%%%%%%%%%%%%%%%%%%%%%%% 98 | num_refinements{1} 99 | 100 | err_stop_refinement{ -1.e-10 } 101 | 102 | %%% marking type: 0 everything is marked; not zero can be user defined 103 | %%% marking strategy as in the examples given in the file 104 | %%% solve_estimate_mark.h 105 | 106 | amr_marking_type{0} 107 | 108 | -------------------------------------------------------------------------------- /examples/amr_grids/input/2d_square.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | %%%%%%%%%%%%%% AMR %%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | %%% marking type: 0 everything is marked; not zero can be user defined 6 | %% marking strategy as in the examples given in the file 7 | %%% solve_estimate_mark.h 8 | %%% 9 | title{Unit square in 2D} 10 | 11 | %% 0 means uniform refinement everywhere. 33 means refining near specific points. 12 | %% 1 means something different like Doerfler marking 13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14 | amr_marking_type{0} 15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | 17 | num_refinements{0} 18 | 19 | err_stop_refinement{ -1.e-10 } %% for the user to define and use 20 | 21 | dimension{2} % spatial dimension in which the grid has to be generated 22 | 23 | print_level{0} % how much information to print out: 0 Nothing | >0 Something 24 | 25 | refinement_type{-2} %0 is criss-cross; -2=edges are pointing towards one side 26 | 27 | file_grid{output/2d_square.haz} 28 | file_vtu{output/2d_square.vtu} 29 | 30 | %---------------% 31 | % coordinate systems: Each has coordinates of the origin o[0:dim-1] 32 | % type (0=cartesian, 1=polar)% 33 | %---------------% 34 | num_coordsystems{1} % number of coordinate systems 35 | data_coordsystems{0 0 0. 0.} 36 | 37 | %---------------% 38 | % graph which describes the domain. The input are 39 | % vertices and edges. 40 | %---------------% 41 | 42 | num_vertices{4} %number of vertices 43 | %%% coords, type, origin for polar system: angles are in degrees 44 | data_vertices{0 0 -1. -1. 45 | 1 0 1. -1. 46 | 2 0 -1. 1. 47 | 3 0 1. 1. } 48 | % 49 | %---------------% 50 | % edges and number of divisions for every edge. 51 | % opposite edges have the same number of divisions. if they do not, 52 | % then the max number of divisions is taken. 53 | %---------------% 54 | 55 | 56 | num_edges{2} % 57 | 58 | %% edge: 1st vertex, 2nd vertex, number of divisions. 59 | data_edges{0 1 5 60 | 0 2 5} 61 | 62 | 63 | %%% num_edges{4} % 64 | %%% data_edges{0 1 1 65 | %%% 1 3 1 66 | %%% 0 2 1 67 | %%% 2 3 1 } 68 | 69 | 70 | %%% ====================MACROELEMENTS========================= 71 | num_macroelements{1} 72 | data_macroelements{0 1 2 3 2} %% v1...v4 and material. 73 | %%% ====================MACROFACES========================= 74 | num_macrofaces{4} 75 | data_macrofaces{0 1 1 76 | 1 3 1 77 | 0 2 1 78 | 3 2 1 79 | } %% codes on boundary faces (v1,v2,code). 80 | 81 | 82 | -------------------------------------------------------------------------------- /examples/amr_grids/input/3d_cube.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | % 5 | title{Grid on the cube (0,1)x(0,1)x(0,1)} 6 | % 7 | dimension{3} % spatial dimension in which the grid has to be generated 8 | print_level{0} % how much information to print out: 0 little | >0 more 9 | %---------------% 10 | 11 | num_refinements{1} 12 | 13 | refinement_type{11} 14 | 15 | amr_marking_type{0} 16 | 17 | err_stop_refinement{ -1.e-10 } 18 | %%% files: should be writeable by the user 19 | %%% vtu files for plotting follow the same convention. 20 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 21 | file_grid{output/3d_c.msh} 22 | file_vtu{output/3d_c.vtu} 23 | 24 | %%%num_edges{12} 25 | %%% it is enough to specify 3 divisions only for the 3 26 | %%% edges of the cube which span 3D. 27 | 28 | num_edges{3} 29 | 30 | data_edges{0 1 1 %% edge: 1st vertex, 2nd vertex, number of divisions. 31 | 0 2 1 32 | 0 4 1 33 | } 34 | %%% ====================VERTICES========================= 35 | num_vertices{8} %number of vertices 36 | 37 | %---------------% 38 | %%% coords: for every node 1:numvertices give coords (dim 39 | %%% coords per node) 40 | %%% 41 | %%% If two points on an edge are in the same coordinate system, 42 | %%% then all points on this edge are in polar coordinate system. 43 | %%% if two points on an edge are in in different coordinate systems, 44 | %%% then the points on the edge are on a straight 45 | %%% line connecting the two vertices. 46 | %---------------% 47 | %%% vertex number (label) coord_system, coords 48 | data_vertices{0 0 0. 0. 0. 49 | 1 0 0. 0 1. 50 | 2 0 0. 1. 0. 51 | 3 0 0. 1. 1. 52 | 4 0 1. 0. 0. 53 | 5 0 1. 0. 1. 54 | 6 0 1. 1. 0. 55 | 7 0 1. 1. 1. } 56 | %%%%% 57 | 58 | %%% ====================MACROELEMENTS========================= 59 | 60 | num_macroelements{1} 61 | 62 | %%% Numbering (ordering) of the vertices describing a macroelement: 63 | %%% CHECK the README. 64 | 65 | %%% MACROELEMENT: its 2^d vertices and a macroelement code. 66 | 67 | data_macroelements{0 1 2 3 4 5 6 7 10 } 68 | 69 | num_macrofaces{6} 70 | % any face which needs a code (for example boundary faces: face 71 | % number. If a face is not included here and is a boundary face then 72 | % its code is set to Dirichlet (i.e. 1...16). Internal faces not found 73 | % here have a code 0. Faces given here and not found in the 74 | % macroelement list are ignored. 75 | % If no faces are given then every boundary point gets a code of 1 (Dirichlet); 76 | data_macrofaces{0 1 2 3 17 77 | 0 4 1 5 1 78 | 4 7 5 6 19 79 | 2 6 3 7 2 80 | 0 4 2 6 20 81 | 1 5 7 3 3 82 | } 83 | 84 | num_coordsystems{1} 85 | 86 | data_coordsystems{0 0. 0. 0. 0} 87 | 88 | 89 | %%% marking type: 0 everything is marked; not zero can be user defined 90 | %%% marking strategy as in the examples given in the file 91 | %%% solve_estimate_mark.h 92 | 93 | num_refine_points{1} %number of points near which the mesh will be refined 94 | %%% coords, type, origin for polar system: angles are in degrees 95 | data_refine_points{0 0 0.5 0.125 0.375 96 | } 97 | -------------------------------------------------------------------------------- /examples/amr_grids/input/4d_cube.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | % 5 | title{Grid on the 4d cube (-1,1)x(-1,1)x(-1,1)x(-1,-1)} 6 | % 7 | dimension{4} % spatial dimension in which the grid has to be generated 8 | print_level{10} % how much information to print out: 0 little | >0 more 9 | %---------------% 10 | 11 | num_refinements{0} 12 | 13 | %%%%% SHOULD NOT BE USED HERE: refinement_type{-1} 14 | 15 | err_stop_refinement{ -1.e-10 } 16 | %%% files: should be writeable by the user 17 | %%% vtu files for plotting follow the same convention. 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | file_grid{output/4dcube.haz} 20 | file_vtu{output/4dcube.vtu} 21 | 22 | %%%num_edges{12} 23 | %%% it is enough to specify 4 divisions only for the 4 24 | %%% edges of the cube which span 4D. 25 | 26 | num_edges{4} 27 | 28 | data_edges{0 1 1 %% edge: 1st vertex, 2nd vertex, number of divisions. 29 | 0 2 1 30 | 0 4 1 31 | 0 8 1 32 | } 33 | %%% ====================VERTICES========================= 34 | num_vertices{16} %number of vertices 35 | 36 | %---------------% 37 | %%% coords: for every node 1:numvertices give coords (dim 38 | %%% coords per node) 39 | %%% 40 | %%% If two points on an edge are in the same coordinate system, 41 | %%% then all points on this edge are in polar coordinate system. 42 | %%% if two points on an edge are in in different coordinate systems, 43 | %%% then the points on the edge are on a straight 44 | %%% line connecting the two vertices. 45 | %---------------% 46 | %%% vertex number (label) coord_system, coords 47 | data_vertices{0 0 -1. -1. -1. -1. 48 | 1 0 -1. -1. -1 1. 49 | 2 0 -1. -1. 1. -1. 50 | 3 0 -1. -1. 1. 1. 51 | 4 0 -1. 1. -1. -1. 52 | 5 0 -1. 1. -1. 1. 53 | 6 0 -1. 1. 1. -1. 54 | 7 0 -1. 1. 1. 1. 55 | 8 0 1. -1. -1. -1. 56 | 9 0 1. -1. -1 1. 57 | 10 0 1. -1. 1. -1. 58 | 11 0 1. -1. 1. 1. 59 | 12 0 1. 1. -1. -1. 60 | 13 0 1. 1. -1. 1. 61 | 14 0 1. 1. 1. -1. 62 | 15 0 1. 1. 1. 1.} 63 | %%%%% 64 | %%% ====================MACROELEMENTS========================= 65 | 66 | num_macroelements{1} 67 | 68 | %%% Numbering (ordering) of the vertices describing a macroelement: 69 | %%% CHECK the README. 70 | 71 | %%% MACROELEMENT: its 2^d vertices and a macroelement code. 72 | 73 | data_macroelements{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 } 74 | 75 | % any face which needs a code (for example boundary faces: face 76 | % number. If a face is not included here and is a boundary face then 77 | % its code is set to Dirichlet (i.e. 1...16). Internal faces not found 78 | % here have a code 0. Faces given here and not found in the 79 | % macroelement list are ignored. 80 | % If no faces are given then every boundary point gets a code of 1 (Dirichlet); 81 | num_macrofaces{1} 82 | data_macrofaces{0 1 2 3 4 5 6 7 1} 83 | %%% or a complete list of the 4d cube faces below:) 84 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 85 | %%% num_macrofaces{8} 86 | %%% data_macrofaces{ 0 1 2 3 4 5 6 7 1 87 | %%% 0 1 2 3 8 9 10 11 2 88 | %%% 0 1 4 5 8 9 12 13 3 89 | %%% 0 2 4 6 8 10 12 14 4 90 | %%% 8 9 10 11 12 13 14 15 5 91 | %%% 4 5 6 7 12 13 14 15 6 92 | %%% 2 3 6 7 10 11 14 15 7 93 | %%% 1 3 5 7 9 11 13 15 8} 94 | % 95 | num_coordsystems{1} 96 | 97 | data_coordsystems{0 0. 0. 0. 0. 0} 98 | 99 | 100 | %%% marking type: 0 everything is marked; not zero can be user defined 101 | %%% marking strategy as in the examples given in the file 102 | %%% solve_estimate_mark.h 103 | 104 | amr_marking_type{0} 105 | 106 | -------------------------------------------------------------------------------- /examples/amr_grids/input/5d_cube.input: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: for grid generation % 3 | %----------------------------------------------% 4 | % 5 | title{Grid on the 5d cube (-1,1)x(-1,1)x(-1,1)x(-1,-1)} 6 | % 7 | dimension{5} % spatial dimension in which the grid has to be generated 8 | print_level{1} % how much information to print out: 0 little | >0 more 9 | %---------------% 10 | 11 | num_refinements{0} 12 | 13 | %%%%% SHOULD NOT BE USED HERE: refinement_type{-1} 14 | 15 | err_stop_refinement{ -1.e-10 } 16 | %%% files: should be writeable by the user 17 | %%% vtu files for plotting follow the same convention. 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | file_grid{output/5d_cube.haz} 20 | file_vtu{output/5d_cube.vtu} 21 | 22 | %%%num_edges{12} 23 | %%% it is enough to specify 5 divisions only for the 5 24 | %%% edges of the cube which span 5D. 25 | 26 | num_edges{5} 27 | 28 | data_edges{0 1 1 %% edge: 1st vertex, 2nd vertex, number of divisions. 29 | 0 2 1 30 | 0 4 1 31 | 0 8 1 32 | 0 16 1 33 | } 34 | %%% ====================VERTICES========================= 35 | num_vertices{32} %number of vertices 36 | 37 | %---------------% 38 | %%% coords: for every node 1:numvertices give coords (dim 39 | %%% coords per node) 40 | %%% 41 | %%% If two points on an edge are in the same coordinate system, 42 | %%% then all points on this edge are in polar coordinate system. 43 | %%% if two points on an edge are in in different coordinate systems, 44 | %%% then the points on the edge are on a straight 45 | %%% line connecting the two vertices. 46 | %---------------% 47 | %%% vertex number (label) coord_system, coords 48 | data_vertices{ 49 | 0 0 -1 -1. -1. -1. -1. 50 | 1 0 -1 -1. -1. -1 1. 51 | 2 0 -1 -1. -1. 1. -1. 52 | 3 0 -1 -1. -1. 1. 1. 53 | 4 0 -1 -1. 1. -1. -1. 54 | 5 0 -1 -1. 1. -1. 1. 55 | 6 0 -1 -1. 1. 1. -1. 56 | 7 0 -1 -1. 1. 1. 1. 57 | 8 0 -1 1. -1. -1. -1. 58 | 9 0 -1 1. -1. -1 1. 59 | 10 0 -1 1. -1. 1. -1. 60 | 11 0 -1 1. -1. 1. 1. 61 | 12 0 -1 1. 1. -1. -1. 62 | 13 0 -1 1. 1. -1. 1. 63 | 14 0 -1 1. 1. 1. -1. 64 | 15 0 -1 1. 1. 1. 1. 65 | 16 0 1. -1. -1. -1. -1. 66 | 17 0 1. -1. -1. -1 1. 67 | 18 0 1. -1. -1. 1. -1. 68 | 19 0 1. -1. -1. 1. 1. 69 | 20 0 1. -1. 1. -1. -1. 70 | 21 0 1. -1. 1. -1. 1. 71 | 22 0 1. -1. 1. 1. -1. 72 | 23 0 1. -1. 1. 1. 1. 73 | 24 0 1. 1. -1. -1. -1. 74 | 25 0 1. 1. -1. -1 1. 75 | 26 0 1. 1. -1. 1. -1. 76 | 27 0 1. 1. -1. 1. 1. 77 | 28 0 1. 1. 1. -1. -1. 78 | 29 0 1. 1. 1. -1. 1. 79 | 30 0 1. 1. 1. 1. -1. 80 | 31 0 1. 1. 1. 1. 1. 81 | } 82 | %%%%% 83 | %%% ====================MACROELEMENTS========================= 84 | 85 | num_macroelements{1} 86 | 87 | %%% Numbering (ordering) of the vertices describing a macroelement: 88 | %%% CHECK the README. 89 | 90 | %%% MACROELEMENT: its 2^d vertices and a macroelement code. 91 | 92 | data_macroelements{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 27 28 29 30 31 1 } 93 | 94 | % any face which needs a code (for example boundary faces: face 95 | % number. If a face is not included here and is a boundary face then 96 | % its code is set to Dirichlet (i.e. 1...16). Internal faces not found 97 | % here have a code 0. Faces given here and not found in the 98 | % macroelement list are ignored. 99 | % If no faces are given then every boundary point gets a code of 1 (Dirichlet); 100 | num_macrofaces{1} 101 | data_macrofaces{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1} 102 | num_coordsystems{1} 103 | 104 | data_coordsystems{0 0. 0. 0. 0. 0. 0} 105 | 106 | 107 | %%% marking type: 0 everything is marked; not zero can be user defined 108 | %%% marking strategy as in the examples given in the file 109 | %%% solve_estimate_mark.h 110 | 111 | amr_marking_type{0} 112 | 113 | -------------------------------------------------------------------------------- /examples/amr_grids/makefile: -------------------------------------------------------------------------------- 1 | ##################################################### 2 | # Last Modified 2019-06-10 --jha 3 | #################################################### 4 | 5 | # SRC File name 6 | SRCFILE = amr_grids 7 | HEADERS = supporting_$(SRCFILE).h 8 | 9 | INCLUDE = 10 | 11 | LIBS = 12 | 13 | # Switch between debug or optimized 14 | CFLAGS = -g 15 | 16 | 17 | ## If an external libraries support is compiled in the hazmath library, 18 | ## uncomment the corresponding lines below: 19 | WITH_SUITESPARSE=1 20 | WITH_LAPACK=1 21 | 22 | sinclude ../examples.mk 23 | -------------------------------------------------------------------------------- /examples/amr_grids/output/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | */ -------------------------------------------------------------------------------- /examples/approximation/README.md: -------------------------------------------------------------------------------- 1 | # Testing the rational approximation of functions in HAZMATH and HAZNICS 2 | 3 | --- 4 | 5 | The examples below are for approximating the function: f(x) = x^{-0.5} + 0.25*x^{0.5} on the interval [a,1], a<<1. 6 | 7 | - to make the hazmath library from this directory: 8 | 9 | --- 10 | 11 | make -C ../.. distclean ; make -C ../.. config haznics=yes suitesparse=yes lapack=yes shared=yes ; make -C ../.. install 12 | 13 | --- 14 | 15 | - to test AAA algorithm: 16 | - in the makefile in this directory ("examples/approximation") set SRCFILE = test_aaa 17 | - type "make clean ; make" 18 | - to test the AAA algorithm run "./test_aaa" as follows: 19 | 20 | --- 21 | 22 | ./test_aaa.ex <<EOF_FRAC >frac_aaa.m 23 | -0.50 0.50 1.00 0.25 0.00001 1.00 24 | EOF_FRAC 25 | 26 | --- 27 | 28 | - to test the BRASIL algorithm: 29 | - in the makefile in this directory ("examples/approximation") set SRC_SRCFILE = test_brasil 30 | - type "make clean ; make" 31 | - to test the BRASIL algorithm run "./test_aaa" as follows: 32 | 33 | --- 34 | 35 | ./test_brasil.ex <<EOF_FRAC >frac_brasil.m 36 | -0.50 0.50 1.00 0.25 0.00001 1.00 37 | EOF_FRAC 38 | 39 | --- 40 | 41 | - In both cases use octave or matlab to check the approximation. 42 | 43 | # References 44 | 45 | 1. AAA algorithm: See: Yuji Nakatsukasa, Olivier Sete, and Lloyd N. Trefethen. The AAA 46 | algorithm for rational approximation. SIAM J. Sci.Comput., 40(3):A1494–A1522, 2018. 47 | [https://doi.org/10.1137/16M1106122](https://doi.org/10.1137/16M1106122) 48 | 49 | 2. BRASIL algorithm: C. Hofreither, "An algorithm for best rational approximation based on 50 | barycentric rational interpolation." Numerical Algorithms, 2021 51 | [https://doi.org/10.1007/s11075-020-01042-0](https://doi.org/10.1007/s11075-020-01042-0) 52 | 53 | --- 54 | 55 | END of README for Rational Approximation 56 | 57 | (c) HAZMATH 2009- 58 | -------------------------------------------------------------------------------- /examples/approximation/makefile: -------------------------------------------------------------------------------- 1 | ##################################################### 2 | # Last Modified 2021-07-21 --ltz 3 | #################################################### 4 | 5 | testing = aaa 6 | 7 | ### SRC File name 8 | SRCFILE = test_$(testing) 9 | 10 | HEADERS = ra_examples.h 11 | 12 | INCLUDE = 13 | 14 | LIBS = 15 | 16 | # Switch between debug or optimized 17 | CFLAGS = -O 18 | 19 | ## If external libraries support is compiled in the hazmath library, 20 | ## comment/uncomment what is necessary below. 21 | WITH_LAPACK=1 22 | WITH_SUITESPARSE=0 23 | 24 | sinclude ../examples.mk 25 | -------------------------------------------------------------------------------- /examples/approximation/output/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | */ -------------------------------------------------------------------------------- /examples/approximation/ra_examples.h: -------------------------------------------------------------------------------- 1 | /************************************************************************/ 2 | /************************************************************************/ 3 | /*function to be approximated*/ 4 | REAL16 f_to_approx_l(REAL16 x,REAL16 s, REAL16 t, REAL16 alpha, REAL16 beta) 5 | { 6 | // fprintf(stdout,"\ns1=%Lf; s2=%Lf; alpha=%Lf; beta=%Lf;",s,t,alpha,beta); 7 | return 1./(alpha*powl(x,s)+beta*powl(x,t)); 8 | } 9 | /**/ 10 | /*OLD:function to be approximated*/ 11 | REAL16 old_f_to_approx_l(REAL16 x,void *param) 12 | { 13 | REAL16 *s,s1,s2,alpha,beta; 14 | if(param!=NULL){ 15 | s=(REAL16 *)param; 16 | s1=s[0]; 17 | s2=s[1]; 18 | alpha=s[2]; 19 | beta=s[3]; 20 | } else { 21 | s1=0.5e0; 22 | s2=-0.5e0; 23 | alpha=1e0; 24 | beta=2e0; 25 | } 26 | // fprintf(stdout,"\ns1=%Lf; s2=%Lf; alpha=%Lf; beta=%Lf;",s1,s2,alpha,beta); 27 | return f_to_approx_l(x,s1,s2,alpha,beta); 28 | } 29 | /**/ 30 | -------------------------------------------------------------------------------- /examples/basic_elliptic/input.dat: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters for basic_elliptic example % 3 | % This can simulate the grad grad, curl curl, % 4 | % or div div operator as a test problem. % 5 | % lines starting with % are comments % 6 | % must have spaces around the equal sign "=" % 7 | %----------------------------------------------% 8 | 9 | %---------------% 10 | % output 11 | %---------------% 12 | 13 | print_level = 2; % how much information to print out: 0 Nothing | >0 Something 14 | output_dir = ./output/ % directory for all output (must be created) 15 | 16 | 17 | %---------------% 18 | % mesh 19 | %---------------% 20 | 21 | read_mesh_from_file = 0 % [0/1]; 1=Either read from file in .haz format or 0=build uniform mesh directly 22 | 23 | % For reading in a pre-made mesh file (any dimension works) 24 | gridfile = unitSQ_n9.haz 25 | 26 | % For using HAZmath's built-in uniform mesh functions 27 | spatial_dim = 2 % For now only 2D or 3D 28 | refinement_type = 11 % Refinement type (>10 uniform or <10 other) 29 | refinement_levels = 5 % Number of levels of refinement (2^(l)+1 vertices in each direction) 30 | boundary_codes = 1 % Will set the boundary codes 31 | 32 | %---------------% 33 | % finite element 34 | %---------------% 35 | 36 | nquad = 3 % Quadrature nodes each direction 37 | FE_type = 1 % 1-9 PX | 10-19 QX (not yet) | 20 Ned | 30 RT | -9--1 DGX (not yet) 38 | 39 | %---------------% 40 | % time stepping 41 | %---------------% 42 | 43 | % Not needed here 44 | time_step_type = 1 % 0 CN | 1 BDF1 | 2 BDF2 | 45 | time_steps = 0 % number of time steps 46 | time_step_size = 0.01 % time step size 47 | 48 | %---------------% 49 | % nonlinear solver 50 | %---------------% 51 | 52 | % Not needed here 53 | nonlinear_itsolver_type = 0 % 0 Linear Problem | 1 Newton | 2 Picard (not yet) 54 | nonlinear_itsolver_maxit = 0 % maximal iterations of nonlinear solver 55 | nonlinear_itsolver_tol = 1e-8 % tolerance for nonlinear solver 56 | nonlinear_itsolver_toltype = 0 % type of tolerance for nonlinear solver 1 - ||nonlinear residual||10 uniform refinement; 40 | // 41 | INT jlevel,k; 42 | scomplex **sc_all=NULL,*sc=NULL,*sctop=NULL; 43 | /**/ 44 | INT ndiv=(1<ns,(long long )sc_all[0]->nv); fflush(stdout); 51 | /**/ 52 | sc=sc_all[0]; 53 | scfinalize(sc,(INT )1); 54 | sc_vols(sc); 55 | clock_t clk_mesh_end = clock(); 56 | /* Assemble */ 57 | clock_t clk_assembly_start = clock(); // begin assembly timing; 58 | dCSRmat A=dcsr_create(0,0,0); 59 | dvector rhs, sol; 60 | rhs.row=0; rhs.val=NULL; 61 | sol.row=0; sol.val=NULL; 62 | // Time the mesh generation and FE setup 63 | REAL alpha=1e0,gamma=0e0; 64 | /* call_assembly_w_dg(sc, \ */ 65 | /* &A, \ */ 66 | /* &rhs, \ */ 67 | /* alpha,gamma); */ 68 | /* dcsr_write_dcoo("Adg.dat",&A); */ 69 | /********************************************************/ 70 | call_assembly(sc, \ 71 | &A, \ 72 | &rhs, \ 73 | alpha,gamma); 74 | //dcsr_write_dcoo("A.dat",&A); 75 | short todraw=1; 76 | draw_grids(todraw, sc,&sol); 77 | /* write the output mesh file: */ 78 | /* hazw("output/mesh.haz",sc,0); */ 79 | clock_t clk_assembly_end = clock(); // End of timing for mesh and FE setup 80 | /*Solve*/ 81 | clock_t clk_solver_start = clock(); // End of timing for mesh and FE setup 82 | solveit(&A,&rhs,&sol); 83 | clock_t clk_solver_end = clock(); // End of timing for mesh and FE setup 84 | // err computation |u_I-u_h|_{1} and use rhs as a working space 85 | REAL err1,err0,uinterp; 86 | INT i,ij,j; 87 | // rhs= A*(err) 88 | for(i=0;inv;++i){ 89 | err0=0e0; 90 | for(ij=A.IA[i];ijx[j*dim],0e0,dim,NULL); 93 | err0+=A.val[ij]*(sol.val[j]-uinterp); 94 | } 95 | rhs.val[i]=err0; 96 | } 97 | // err0=err'*A*err. 98 | err0=0e0; 99 | for(i=0;inv;++i){ 100 | exactsol(&uinterp,&sc->x[i*dim],0e0,dim,NULL); 101 | err0+=rhs.val[i]*(sol.val[i]-uinterp); 102 | } 103 | fprintf(stdout,"\n|u_I-u_h|_1=%.6e\n",sqrt(err0)); 104 | haz_scomplex_free(sc_all[0]); 105 | free(sc_all); 106 | dvec_free(&sol); 107 | dvec_free(&rhs); 108 | dcsr_free(&A); 109 | clock_t clk_all_end = clock(); // End of timing for mesh and FE setup 110 | fprintf(stdout,"\n%%%%%%CPUtime(mesh) = %10.3f sec\n%%%%%%CPUtime(assembly) = %10.3f sec\n%%%%%%CPUtime(solver) = %10.3f sec\n%%%%%%CPUtime(all) = %10.3f sec\n", \ 111 | (REAL ) (clk_mesh_end - clk_mesh_start)/CLOCKS_PER_SEC, \ 112 | (REAL ) (clk_assembly_end - clk_assembly_start)/CLOCKS_PER_SEC, \ 113 | (REAL ) (clk_solver_end - clk_solver_start)/CLOCKS_PER_SEC, \ 114 | (REAL ) (clk_all_end - clk_all_start)/CLOCKS_PER_SEC); 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /examples/elliptic_p1/functions_elliptic_p1.h: -------------------------------------------------------------------------------- 1 | /*! \file examples/basic_elliptic/eafe_data.h 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov 2019/01/09. 4 | * Copyright 2015_HAZMATH__. All rights reserved. 5 | * 6 | * \brief This contains all the Data parameters and coefficients 7 | * for the basic_elliptic examples. This includes exact solutions, 8 | * RHS functions, and boundary conditions. 9 | * 10 | * \note We include different examples for 2D and 3D problems, and for FE types 11 | * P1, P2, RT0, Nedelec0 12 | */ 13 | 14 | // Exact Solution (if we have one) 15 | void exactsol(REAL *val,REAL* x,REAL time, \ 16 | const INT dim,void *param) 17 | { 18 | switch(dim){ 19 | case 1: 20 | *val = -x[0]*x[0]; 21 | break; 22 | case 2: 23 | *val = 4*x[0]*x[0]-5e0*x[1]*x[1]; 24 | break; 25 | case 3: 26 | *val = 3*x[0]*x[0]+x[1]*x[1]-5e0*x[2]*x[2]; 27 | break; 28 | default: 29 | *val = 0e0; 30 | break; 31 | } 32 | } 33 | // PDE Coefficients 34 | /*====================================================================*/ 35 | void diffusion(REAL *val,REAL *x, const REAL time, \ 36 | const INT dim, void *params) 37 | { 38 | // diffusion coefficient. 39 | val[0]=1e0; 40 | return; 41 | } 42 | /*====================================================================*/ 43 | void advection(REAL *val,REAL *x, const REAL time, \ 44 | const INT dim, void *param) 45 | { 46 | // advection coefficient (vector valued); 47 | memset(val,0,dim*sizeof(REAL)); 48 | // val[0]=1e0; 49 | return; 50 | } 51 | /*EOF*/ 52 | void reaction(REAL *val,REAL* x,REAL time, \ 53 | const INT dim, void *param) 54 | { 55 | // reaction coefficieent 56 | val[0] = 0e0; 57 | } 58 | // 59 | void rhs_pde(REAL *val,REAL* x,REAL time, \ 60 | const INT dim, void *param) 61 | { 62 | REAL u; 63 | // right hand side for the PDE 64 | exactsol(val,x,time,dim,param); 65 | val[0]=2e0; // + 2e0*val[0]; 66 | } 67 | void rhs_natural_bc(REAL *val,REAL* x,REAL time, \ 68 | const INT dim, void *param) 69 | { 70 | // right hand side for the natural boundary condition 71 | // (flux.n=rhs_natural_bc) 72 | val[0] = 0e0; 73 | } 74 | 75 | void rhs_essential_bc(REAL *val,REAL* x,REAL time, \ 76 | const INT dim,void *param) 77 | { 78 | // dirichlet boundary conditions: set up through exactsol(). 79 | exactsol(val,x,time,dim,param); 80 | } 81 | -------------------------------------------------------------------------------- /examples/elliptic_p1/makefile: -------------------------------------------------------------------------------- 1 | ##################################################### 2 | # Last Modified 2017-03-06 --ltz 3 | #################################################### 4 | # SRC File name 5 | SRCFILE = elliptic_p1 6 | 7 | HEADERS = supporting_$(SRCFILE).h 8 | 9 | INCLUDE = 10 | 11 | LIBS = 12 | 13 | # Switch between debug or optimized 14 | CFLAGS = -g 15 | 16 | ## If external libraries support is compiled in the hazmath library, 17 | ## comment/uncomment what is necessary below. If libhazmath was 18 | ## configured with "lapack=yes" for example then we need "WITH_LAPACK=1" below. 19 | WITH_LAPACK=1 20 | WITH_SUITESPARSE=0 21 | 22 | sinclude ../examples.mk 23 | 24 | -------------------------------------------------------------------------------- /examples/elliptic_p1/output/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | */ -------------------------------------------------------------------------------- /examples/grids/1D/unitLINE_n17.haz: -------------------------------------------------------------------------------- 1 | 16 17 1 0 2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 3 | 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 4 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 | 0.0000000000000000e+00 6.2500000000000000e-02 1.2500000000000000e-01 1.8750000000000000e-01 2.5000000000000000e-01 3.1250000000000000e-01 3.7500000000000000e-01 4.3750000000000000e-01 5.0000000000000000e-01 5.6250000000000000e-01 6.2500000000000000e-01 6.8750000000000000e-01 7.5000000000000000e-01 8.1250000000000000e-01 8.7500000000000000e-01 9.3750000000000000e-01 1.0000000000000000e+00 6 | 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 7 | -------------------------------------------------------------------------------- /examples/grids/1D/unitLINE_n3.haz: -------------------------------------------------------------------------------- 1 | 2 3 1 0 2 | 1 2 3 | 2 3 4 | 1 1 5 | 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 6 | 1 0 1 7 | -------------------------------------------------------------------------------- /examples/grids/1D/unitLINE_n33.haz: -------------------------------------------------------------------------------- 1 | 32 33 1 0 2 | 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 27 28 29 30 31 32 3 | 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 27 28 29 30 31 32 33 4 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 | 0.0000000000000000e+00 3.1250000000000000e-02 6.2500000000000000e-02 9.3750000000000000e-02 1.2500000000000000e-01 1.5625000000000000e-01 1.8750000000000000e-01 2.1875000000000000e-01 2.5000000000000000e-01 2.8125000000000000e-01 3.1250000000000000e-01 3.4375000000000000e-01 3.7500000000000000e-01 4.0625000000000000e-01 4.3750000000000000e-01 4.6875000000000000e-01 5.0000000000000000e-01 5.3125000000000000e-01 5.6250000000000000e-01 5.9375000000000000e-01 6.2500000000000000e-01 6.5625000000000000e-01 6.8750000000000000e-01 7.1875000000000000e-01 7.5000000000000000e-01 7.8125000000000000e-01 8.1250000000000000e-01 8.4375000000000000e-01 8.7500000000000000e-01 9.0625000000000000e-01 9.3750000000000000e-01 9.6875000000000000e-01 1.0000000000000000e+00 6 | 1 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 1 7 | -------------------------------------------------------------------------------- /examples/grids/1D/unitLINE_n5.haz: -------------------------------------------------------------------------------- 1 | 4 5 1 0 2 | 1 2 3 4 3 | 2 3 4 5 4 | 1 1 1 1 5 | 0.0000000000000000e+00 2.5000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 6 | 1 0 0 0 1 7 | -------------------------------------------------------------------------------- /examples/grids/1D/unitLINE_n65.haz: -------------------------------------------------------------------------------- 1 | 64 65 1 0 2 | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 3 | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 4 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 | 0.0000000000000000e+00 1.5625000000000000e-02 3.1250000000000000e-02 4.6875000000000000e-02 6.2500000000000000e-02 7.8125000000000000e-02 9.3750000000000000e-02 1.0937500000000000e-01 1.2500000000000000e-01 1.4062500000000000e-01 1.5625000000000000e-01 1.7187500000000000e-01 1.8750000000000000e-01 2.0312500000000000e-01 2.1875000000000000e-01 2.3437500000000000e-01 2.5000000000000000e-01 2.6562500000000000e-01 2.8125000000000000e-01 2.9687500000000000e-01 3.1250000000000000e-01 3.2812500000000000e-01 3.4375000000000000e-01 3.5937500000000000e-01 3.7500000000000000e-01 3.9062500000000000e-01 4.0625000000000000e-01 4.2187500000000000e-01 4.3750000000000000e-01 4.5312500000000000e-01 4.6875000000000000e-01 4.8437500000000000e-01 5.0000000000000000e-01 5.1562500000000000e-01 5.3125000000000000e-01 5.4687500000000000e-01 5.6250000000000000e-01 5.7812500000000000e-01 5.9375000000000000e-01 6.0937500000000000e-01 6.2500000000000000e-01 6.4062500000000000e-01 6.5625000000000000e-01 6.7187500000000000e-01 6.8750000000000000e-01 7.0312500000000000e-01 7.1875000000000000e-01 7.3437500000000000e-01 7.5000000000000000e-01 7.6562500000000000e-01 7.8125000000000000e-01 7.9687500000000000e-01 8.1250000000000000e-01 8.2812500000000000e-01 8.4375000000000000e-01 8.5937500000000000e-01 8.7500000000000000e-01 8.9062500000000000e-01 9.0625000000000000e-01 9.2187500000000000e-01 9.3750000000000000e-01 9.5312500000000000e-01 9.6875000000000000e-01 9.8437500000000000e-01 1.0000000000000000e+00 6 | 1 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 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 1 7 | -------------------------------------------------------------------------------- /examples/grids/1D/unitLINE_n9.haz: -------------------------------------------------------------------------------- 1 | 8 9 1 0 2 | 1 2 3 4 5 6 7 8 3 | 2 3 4 5 6 7 8 9 4 | 1 1 1 1 1 1 1 1 5 | 0.0000000000000000e+00 1.2500000000000000e-01 2.5000000000000000e-01 3.7500000000000000e-01 5.0000000000000000e-01 6.2500000000000000e-01 7.5000000000000000e-01 8.7500000000000000e-01 1.0000000000000000e+00 6 | 1 0 0 0 0 0 0 0 1 7 | -------------------------------------------------------------------------------- /examples/grids/2D/circle_level0.haz: -------------------------------------------------------------------------------- 1 | 18 15 2 0 2 | 10 6 10 11 11 8 9 6 6 5 4 2 5 12 12 12 13 13 3 | 6 3 11 10 14 4 6 9 5 4 5 5 6 14 8 11 10 9 4 | 8 1 15 8 15 7 10 3 8 8 2 1 1 11 7 8 15 10 5 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 | -0.95128652011707515 -0.95040649142967082 -0.58816100613240418 -0.58602384012113984 -0.42588508508807771 -0.26104919487016609 -1.4862034380946915e-09 -3.6039937353904179e-11 1.2416843719886833e-09 0.26104919487194367 0.42588508476476439 0.5860238398267309 0.58816100775554592 0.95040649107536535 0.95128652070822617 7 | 0.308308217429206 -0.31101045163780994 0.80874385950308303 -0.81029380935969297 -0.13802812423796007 0.3587738126600139 -1 -0.44029443278287383 1 0.35877381231384642 -0.13802812454722299 -0.81029381088649666 0.8087438596032207 -0.31101045272052025 0.30830821560520655 8 | 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 9 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 | -------------------------------------------------------------------------------- /examples/grids/2D/circle_level1.haz: -------------------------------------------------------------------------------- 1 | 85 55 2 0 2 | 20 49 43 12 20 19 19 29 24 32 42 34 4 7 13 21 50 53 10 5 33 23 18 17 8 17 8 8 31 34 32 39 38 39 38 38 52 48 39 54 42 48 27 27 35 38 18 27 27 47 50 53 36 31 5 19 23 17 14 22 22 6 2 8 6 3 6 9 25 25 25 22 31 25 37 37 29 36 40 37 44 46 44 47 44 3 | 12 52 49 9 19 10 29 19 32 34 50 42 7 13 18 18 54 50 5 9 23 19 17 18 4 8 17 2 34 31 39 42 43 38 39 35 48 39 48 48 48 54 21 18 27 27 27 32 38 53 47 47 31 36 3 16 16 22 22 24 17 8 6 6 3 6 14 6 29 31 20 25 25 22 33 40 37 37 37 44 37 44 47 44 36 4 | 15 45 45 15 12 12 30 20 28 28 41 41 11 11 11 13 55 55 12 12 30 30 11 24 11 11 14 4 41 28 34 34 45 45 32 43 45 45 42 52 50 50 26 21 26 35 24 24 32 51 41 50 41 29 9 10 19 14 15 28 24 14 1 2 1 9 15 15 20 29 15 15 28 28 30 33 30 29 46 46 36 51 51 41 41 5 | 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 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 0 0 0 0 0 0 0 0 0 6 | -0.99793823364571832 -0.9786413916953397 -0.9461550707742874 -0.88098448344391556 -0.81760683638594722 -0.74674622898837406 -0.72409312951865468 -0.69168412781404154 -0.67607008857135975 -0.62522381309158492 -0.54377247886791691 -0.51413740186045942 -0.51045072144113957 -0.50835940993496265 -0.43237037815296925 -0.40128475673260566 -0.38108000556893151 -0.28400243745017029 -0.26820816650035845 -0.26350746231134392 -0.25599669036173522 -0.24641446330694852 -0.14082304025894832 -0.13034378661972815 -0.12923797377187227 -6.260811913350036e-09 -6.8361335021015879e-10 1.8074558794101125e-10 1.0999399807642975e-09 4.0530934289351178e-09 0.12923797510508234 0.13034378623529627 0.14082304042872362 0.2464144637265302 0.25599667968344009 0.26350746316938506 0.26820817373228678 0.28400243495492988 0.3810800051799213 0.40128475395737601 0.43237037914242243 0.508359410105098 0.51045071189019509 0.51413740604299951 0.54377247617603164 0.62522381345396461 0.67607009185317724 0.69168412631797949 0.72409312398072156 0.74674623014014629 0.81760683737557627 0.88098447870220098 0.94615507101946539 0.97864139046660836 0.99793823541736915 7 | 0.064181624502485504 -0.20557486821736828 0.32371373568519995 -0.47314515805183655 0.57577692072231734 0.034461832609545787 -0.68970221127665277 -0.2747330016485286 0.30084518304860253 0.78044550351610076 -0.53339503885641748 0.51970824852414665 -0.85990700761748162 -0.075401448900608112 0.18282964775291558 0.91595335292223568 -0.343689587225608 -0.66580702392878777 0.68285185808748561 0.40335099255671775 -0.96667765818697737 -0.095981952435887932 0.99003478233298692 -0.4208166413136652 0.15630183298978639 -1 -0.72045733388536337 -0.14497222700046267 0.45737594996993997 0.73368608761711229 0.15630183265220063 -0.42081664163586385 0.99003478230883801 -0.095981953153171068 -0.96667766101481578 0.40335099272583425 0.68285185685988503 -0.66580702512558676 -0.34368958829888285 0.91595335341263184 0.18282964668880342 -0.075401449619479449 -0.85990701215232446 0.51970824403674376 -0.53339504259641801 0.78044550322579398 0.3008451777340807 -0.27473300555320751 -0.6897022170088376 0.034461828261401185 0.57577691931703812 -0.47314516561629777 0.32371373372524048 -0.20557487406675709 0.064181619926098374 8 | 1 1 1 1 1 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 1 1 1 1 1 9 | 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 | -------------------------------------------------------------------------------- /examples/grids/2D/unitSQ_n3.haz: -------------------------------------------------------------------------------- 1 | 8 9 2 0 2 | 1 4 2 5 4 7 5 8 3 | 2 2 3 3 5 5 6 6 4 | 4 5 5 6 7 8 8 9 5 | 1 1 1 1 1 1 1 1 6 | 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 7 | 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 8 | 1 1 1 1 0 1 1 1 1 9 | -------------------------------------------------------------------------------- /examples/grids/2D/unitSQ_n5.haz: -------------------------------------------------------------------------------- 1 | 32 25 2 0 2 | 1 6 2 7 3 8 4 9 6 11 7 12 8 13 9 14 11 16 12 17 13 18 14 19 16 21 17 22 18 23 19 24 3 | 2 2 3 3 4 4 5 5 7 7 8 8 9 9 10 10 12 12 13 13 14 14 15 15 17 17 18 18 19 19 20 20 4 | 6 7 7 8 8 9 9 10 11 12 12 13 13 14 14 15 16 17 17 18 18 19 19 20 21 22 22 23 23 24 24 25 5 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 | 0.0000000000000000e+00 2.5000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 2.5000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 2.5000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 2.5000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 2.5000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 7 | 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 2.5000000000000000e-01 2.5000000000000000e-01 2.5000000000000000e-01 2.5000000000000000e-01 2.5000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 7.5000000000000000e-01 7.5000000000000000e-01 7.5000000000000000e-01 7.5000000000000000e-01 7.5000000000000000e-01 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 8 | 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 1 1 1 1 9 | -------------------------------------------------------------------------------- /examples/grids/3D/unitCUBE_n3.haz: -------------------------------------------------------------------------------- 1 | 48 27 3 0 2 | 1 1 1 1 1 1 2 2 2 2 2 2 4 4 4 4 4 4 5 5 5 5 5 5 10 10 10 10 10 10 11 11 11 11 11 11 13 13 13 13 13 13 14 14 14 14 14 14 3 | 11 2 5 10 13 4 12 3 6 11 14 5 14 5 8 13 16 7 15 6 9 14 17 8 20 11 14 19 22 13 21 12 15 20 23 14 23 14 17 22 25 16 24 15 18 23 26 17 4 | 10 11 2 13 4 5 11 12 3 14 5 6 13 14 5 16 7 8 14 15 6 17 8 9 19 20 11 22 13 14 20 21 12 23 14 15 22 23 14 25 16 17 23 24 15 26 17 18 5 | 14 14 14 14 14 14 15 15 15 15 15 15 17 17 17 17 17 17 18 18 18 18 18 18 23 23 23 23 23 23 24 24 24 24 24 24 26 26 26 26 26 26 27 27 27 27 27 27 6 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 7 | 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 1.0000000000000000e+00 8 | 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 9 | 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 5.0000000000000000e-01 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 10 | 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 11 | -------------------------------------------------------------------------------- /examples/haznics/README.md: -------------------------------------------------------------------------------- 1 | ### Requirements 2 | - swig >= 4.0.0 (check [this](http://www.swig.org/download.html) for software download and [this](https://github.com/swig/swig/wiki/Getting-Started) for installing) 3 | - python >= 3.5 (with numpy >= 1.13.3) 4 | - cmake >= 3.12 5 | 6 | ### Install additional packages (required by HAZniCS demos): 7 | - Edit, if needed, `install_haznics.sh` to match your system and execute with 8 | ``` 9 | /bin/sh ./install_haznics.sh 10 | ``` 11 | (this installs all package dependencies: [FEniCS v2019.1.0](https://fenicsproject.org/download/archive/), [FEniCS_ii](https://github.com/MiroK/fenics_ii), [cbc.block](https://bitbucket.org/fenics-apps/cbc.block/) ) 12 | - add HAZniCS library to PYTHONPATH with 13 | ``` 14 | source setup.rc 15 | ``` 16 | 17 | ### Running tests 18 | ``` 19 | cd tests/ 20 | python3 test_haznics.py 21 | ``` 22 | 23 | ### Running demos, e.g. Poisson equation 24 | ``` 25 | python3 poisson.py 26 | ``` 27 | -------------------------------------------------------------------------------- /examples/haznics/hodge_Hcurl_3d.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file examples/haznics/hodge_Hcurl_3d.py 3 | Created by Ana Budisa on 2021-09-03. 4 | Example copyright by bitbucket.org/fenics-apps/cbc.block. 5 | 6 | This demo shows the use of a non-trivial block preconditioner for the Hodge 7 | equations namely the curl-curl auxiliary space preconditioner is employed 8 | for the Schur complement . It is adapted from the code described in the block 9 | preconditioning chapter of the FENiCS book, by Kent-Andre Mardal . 10 | 11 | The block structure is as follows, 12 | 13 | | A B | 14 | AA = | |, 15 | | C -D | 16 | 17 | where C=B' and D is positive definite; hence, the system as a whole is 18 | symmetric indefinite. 19 | 20 | The block preconditioner is based on an approximation of the Riesz mapping 21 | with respect to H(curl) inner product (L) and L2 inner product (S): 22 | 23 | | L 0 | 24 | BB^ = | |, 25 | | 0 S | 26 | 27 | For L we use HXCurl auxiliary space preconditioner, i.e. 28 | 29 | L^ = HXCurl(L), 30 | 31 | and for S we use AMG, i.e. 32 | 33 | S^ = AMG(S). 34 | """ 35 | 36 | from __future__ import division 37 | from __future__ import print_function 38 | 39 | from dolfin import * 40 | from block import * 41 | from block.iterative import MinRes 42 | from block.algebraic.hazmath import AMG, HXCurl, Pcurl 43 | import sys 44 | import haznics 45 | 46 | set_log_level(30) 47 | 48 | N = 8 # problem size ( n x n x n mesh of a cube) 49 | 50 | # Parse command-line arguments like "N=6" 51 | for s in sys.argv[1:]: 52 | exec(s) 53 | 54 | mesh = UnitCubeMesh(N, N, N) 55 | 56 | V = FunctionSpace(mesh, "N1curl", 1) 57 | Q = FunctionSpace(mesh, "CG", 1) 58 | 59 | v, u = TestFunction(V), TrialFunction(V) 60 | q, p = TestFunction(Q), TrialFunction(Q) 61 | 62 | # Variational form 63 | a = inner(curl(v), curl(u)) * dx 64 | m = inner(u, v) * dx 65 | A = assemble(a) 66 | B = assemble(inner(grad(p), v) * dx) 67 | C = assemble(inner(grad(q), u) * dx) 68 | D = assemble(inner(p, q) * dx) 69 | 70 | # For the preconditioner 71 | E = assemble(inner(p, q) * dx + inner(grad(p), grad(q)) * dx) 72 | F = assemble(a + m) 73 | 74 | # system matrix 75 | AA = block_mat([[A, B], 76 | [C, -D]]) 77 | 78 | # right hand side 79 | gdim = mesh.geometry().dim() 80 | b0 = assemble(inner(v, Constant((1,) * gdim)) * dx) 81 | b1 = assemble(inner(q, Constant(2)) * dx) 82 | 83 | bb = block_vec([b0, b1]) 84 | 85 | if True: 86 | from scipy.sparse import csr_matrix 87 | 88 | Pc = Pcurl(mesh) 89 | Pc = Pc.down_cast().mat() 90 | pi, pj, pv = Pc.getValuesCSR() 91 | Pc = csr_matrix((pv, pj, pi)) 92 | 93 | F = F.down_cast().mat() 94 | fi, fj, fv = F.getValuesCSR() 95 | F = csr_matrix((fv, fj, fi)) 96 | 97 | Agrad = Pc.transpose(copy=True) * F * Pc 98 | from scipy.sparse.linalg import norm as sp_norm 99 | 100 | assert sp_norm(Agrad - Agrad.transpose(copy=True)) < 1e-14 101 | from numpy.linalg import eigh 102 | 103 | ew, ev = eigh(Agrad.todense()) # ascending - first k vectors are kernel, if k is multiplicity of eigenvalue zero 104 | zero_ew = sum(ew < 1e-14) 105 | print("number of zero eigvals: ", zero_ew) 106 | 107 | X = VectorFunctionSpace(mesh, "CG", 1) 108 | for i in range(zero_ew): 109 | uu = Function(X) 110 | # import pdb; pdb.set_trace() 111 | # print(ev[:, i]) 112 | uu.vector().set_local(ev[:, i]) 113 | File("kernel_vector_%s.pvd" % str(i)) << uu 114 | exit(0) 115 | 116 | # parameters for the AMG in the preconditioner 117 | params = {"maxit": 1, 118 | 'cycle_type': haznics.W_CYCLE, 119 | "smoother": haznics.SMOOTHER_GS, 120 | "coarse_dof": 50, 121 | "aggregation_type": haznics.HEC, # (VMB, MIS, MWM, HEC) 122 | "strong_coupled": 0.05, 123 | # "max_levels": 10, 124 | # "print_level": 10, 125 | } 126 | 127 | prec = block_mat([[HXCurl(F, V, params), 0], 128 | [0, AMG(E, params)]]) 129 | 130 | # solver 131 | AAinv = MinRes(AA, precond=prec, tolerance=1e-9, maxiter=200, show=2) 132 | 133 | # solve 134 | [Uh, Ph] = AAinv * bb 135 | 136 | """ 137 | # plot 138 | if MPI.size(mesh.mpi_comm()) == 1 and gdim == 2: 139 | import matplotlib.pyplot as plt 140 | 141 | plt.subplot(121) 142 | plot(Function(V, Uh)) 143 | 144 | plt.subplot(122) 145 | plot(Function(Q, Ph)) 146 | 147 | plt.show() 148 | """ 149 | -------------------------------------------------------------------------------- /examples/haznics/install_haznics.sh: -------------------------------------------------------------------------------- 1 | # A simple shell script to get haznics python dependencies 2 | # Setup by Ana Budisa - 2021-07-15 (what a date this is!) 3 | 4 | # Install fenics 5 | echo "Installing fenics..." 6 | sudo apt-get install software-properties-common 7 | sudo add-apt-repository ppa:fenics-packages/fenics 8 | sudo apt-get update 9 | sudo apt-get install fenics 10 | echo "... Done." 11 | 12 | # Install quadpy (xii dependency which avoids eigh_tridiagonal) 13 | echo "Installing quadpy..." 14 | git clone https://github.com/nschloe/quadpy.git 15 | cd quadpy 16 | git checkout v0.12.10 17 | python3 setup.py install --user 18 | cd .. 19 | echo "... Done." 20 | 21 | # Install fenics_ii (xii) 22 | echo "Installing fenics_ii..." 23 | git clone https://github.com/MiroK/fenics_ii.git 24 | cd fenics_ii 25 | python3 setup.py install --user 26 | cd .. 27 | echo "... Done." 28 | 29 | # Install hsmg 30 | # echo "Installing hsmg..." 31 | # git clone https://github.com/MiroK/hsmg.git 32 | # cd hsmg 33 | # git fetch --all 34 | # source setup.rc 35 | # cd .. 36 | # echo "... Done." 37 | ## export PYTHONPATH="./hsmg/":"$PYTHONPATH" 38 | 39 | # Install cbc.block 40 | echo "Installing cbc.block..." 41 | git clone https://bitbucket.org/fenics-apps/cbc.block.git 42 | cd cbc.block 43 | python3 setup.py install --user 44 | cd .. 45 | echo "... Done." 46 | 47 | # Install ulfy 48 | echo "Installing ulfy..." 49 | git clone https://github.com/MiroK/ulfy.git 50 | cd ulfy 51 | python3 setup.py install --user 52 | cd .. 53 | echo "... Done." 54 | 55 | # Install hazmath (with the python interface haznics=yes) 56 | echo "Installing hazmath (with haznics)..." 57 | make -C ../.. config shared=yes suitesparse=yes lapack=yes haznics=yes swig=yes 58 | #make -C ../.. config shared=yes lapack=yes haznics=yes swig=yes 59 | make -C ../.. install 60 | 61 | echo "... Done." 62 | 63 | -------------------------------------------------------------------------------- /examples/haznics/mixedpoisson.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file examples/haznics/mixedpoisson.py 3 | Created by Ana Budisa on 2021-08-30. 4 | Example copyright by bitbucket.org/fenics-apps/cbc.block. 5 | 6 | We solve 7 | 8 | div(sigma) = f 9 | sigma = - K*grad(u) 10 | 11 | on a unit square domain. The algebraic system to be solved can be written as 12 | 13 | BB^ AA [sigma u]^T = BB^ [0 b]^T, 14 | 15 | where AA is a 2x2 block system with zero in the (2,2) block 16 | 17 | | A B | 18 | AA = | |, 19 | | C 0 | 20 | 21 | and BB^ approximates the inverse of the block operator 22 | 23 | | A 0 | 24 | BB = | |, 25 | | 0 L | 26 | 27 | where L is the Laplace operator. Since the DG(0) approximation of L is zero, we 28 | calculate it instead as L = C*B. For A, an ML multilevel preconditioner is used: 29 | 30 | A^ = ML(A) 31 | 32 | For L, we create a composite operator so that 33 | 34 | x = L*v ==> w = B*v; x = C*w, 35 | 36 | so we use an inner iterative solver: 37 | 38 | L^ = Richardson(L, precond=0.5, iter=40). 39 | """ 40 | from __future__ import division 41 | from __future__ import print_function 42 | 43 | from block import * 44 | from block.iterative import MinRes, Richardson 45 | from block.algebraic.hazmath import AMG 46 | from dolfin import * 47 | 48 | # Create mesh 49 | mesh = UnitSquareMesh(32, 32) 50 | 51 | # Define function spaces 52 | BDM = FunctionSpace(mesh, "BDM", 1) 53 | DG = FunctionSpace(mesh, "DG", 0) 54 | 55 | # Define trial and test functions 56 | tau, sigma = TestFunction(BDM), TrialFunction(BDM) 57 | v, u = TestFunction(DG), TrialFunction(DG) 58 | 59 | 60 | # Define essential boundary 61 | def boundary(x): 62 | return near(x[1], 0.0) or near(x[1], 1.0) 63 | 64 | 65 | # Define function G such that G \cdot n = g 66 | class BoundarySource(UserExpression): 67 | def __init__(self, mesh): 68 | super().__init__(self) 69 | self.mesh = mesh 70 | 71 | def eval_cell(self, values, x, ufc_cell): 72 | cell = Cell(self.mesh, ufc_cell.index) 73 | n = cell.normal(ufc_cell.local_facet) 74 | g = sin(5*x[0]) 75 | values[0] = g*n[0] 76 | values[1] = g*n[1] 77 | 78 | def value_shape(self): 79 | return (2,) 80 | 81 | 82 | G = BoundarySource(mesh) 83 | 84 | # Define the blockwise boundary conditions -- a Dirichlet condition on the 85 | # first block, and no conditions on the second block. 86 | bcs_BDM = [DirichletBC(BDM, G, boundary)] 87 | bcs = block_bc([bcs_BDM, None], True) 88 | 89 | # Define source function 90 | f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=4) 91 | 92 | # Define variational forms 93 | a11 = dot(sigma, tau) * dx 94 | a12 = div(tau) * u * dx 95 | a21 = div(sigma) * v *dx 96 | L2 = - f * v * dx 97 | 98 | AA = block_assemble([[a11, a12], 99 | [a21, 0 ]]) 100 | 101 | bb = block_assemble([0, L2]) 102 | 103 | bcs.apply(AA).apply(bb) 104 | 105 | # Extract the individual submatrices 106 | [[A, B], 107 | [C, _]] = AA 108 | 109 | # Use multilevel preconditioner from hazmath (UA-AMG) for A 110 | Ap = AMG(A,parameters={"max_levels":10,"print_level":0,"coarse_solver":32}) 111 | 112 | # Create an approximate inverse of L=C*B using inner Richardson iterations 113 | L = C*B 114 | Lp = Richardson(L, precond=0.5, iter=40, name='L^') 115 | 116 | # Define the block preconditioner 117 | AAp = block_mat([[Ap, 0], 118 | [0, Lp]]) 119 | 120 | # Use MinRes as outer solver 121 | AAinv = MinRes(AA, precond=AAp, show=2, name='AA^') 122 | 123 | # ===================== 124 | # Solve the system 125 | Sigma, U = AAinv * bb 126 | # ===================== 127 | 128 | # Check that the norms of solutions are as expected 129 | print(('norm Sigma:', Sigma.norm('l2'))) 130 | print(('norm U :', U.norm('l2'))) 131 | 132 | if abs(1.213-Sigma.norm('l2')) > 1e-3 or abs(6.716-U.norm('l2')) > 1e-3: 133 | raise RuntimeError("Wrong value in norms -- please check!") 134 | 135 | -------------------------------------------------------------------------------- /examples/haznics/mixedpoisson_Hdiv_3d.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file examples/haznics/mixedpoisson_Hdiv_3d.py 3 | Created by Ana Budisa on 2021-09-03. 4 | Example copyright by bitbucket.org/fenics-apps/cbc.block. 5 | 6 | We solve 7 | 8 | div(sigma) = f 9 | sigma = - K*grad(u) 10 | 11 | on a unit cube domain. The algebraic system to be solved can be written as 12 | 13 | BB^ AA [sigma u]^T = BB^ [0 b]^T, 14 | 15 | where AA is a 2x2 block system with zero in the (2,2) block 16 | 17 | | A B | 18 | AA = | |, 19 | | C 0 | 20 | 21 | and BB^ approximates the inverse of the block operator 22 | 23 | | M 0 | 24 | BB = | |, 25 | | 0 N | 26 | 27 | M is the Riesz map with respect to H(div) inner product and N is the 28 | Riesz map with respect to the L^2 inner product. For M, HX div auxiliary space 29 | preconditioner is used: 30 | 31 | M^ = HXDiv(M), 32 | 33 | and for N we use AMG, i.e. 34 | 35 | N^ = AMG(N). 36 | """ 37 | from __future__ import division 38 | from __future__ import print_function 39 | 40 | from block import * 41 | from block.iterative import MinRes 42 | from block.algebraic.hazmath import AMG, HXDiv 43 | from dolfin import * 44 | 45 | n = 8 46 | # Create mesh 47 | mesh = UnitCubeMesh(n, n, n) 48 | 49 | # Define function spaces 50 | RT = FunctionSpace(mesh, "RT", 1) 51 | DG = FunctionSpace(mesh, "DG", 0) 52 | 53 | # Define trial and test functions 54 | tau, sigma = TestFunction(RT), TrialFunction(RT) 55 | v, u = TestFunction(DG), TrialFunction(DG) 56 | 57 | 58 | # Define function G such that G \cdot n = g 59 | class BoundarySource(UserExpression): 60 | def __init__(self, mesh, **kwargs): 61 | super().__init__(self) 62 | self.mesh = mesh 63 | def eval_cell(self, values, x, ufc_cell): 64 | cell = Cell(self.mesh, ufc_cell.index) 65 | n = cell.normal(ufc_cell.local_facet) 66 | g = sin(5*x[0]) 67 | values[0] = g*n[0] 68 | values[1] = g*n[1] 69 | values[2] = g*n[2] 70 | def value_shape(self): 71 | return (3,) 72 | 73 | 74 | G = BoundarySource(mesh, degree=1) 75 | 76 | 77 | # Define essential boundary 78 | def boundary(x): 79 | return near(x[1], 0.0) 80 | 81 | 82 | # Define the blockwise boundary conditions -- a Dirichlet condition on the 83 | # first block, and no conditions on the second block. 84 | bcs_RT = [DirichletBC(RT, G, boundary)] 85 | bcs = block_bc([bcs_RT, None], True) 86 | 87 | # Define source function 88 | f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=4) 89 | 90 | # Define variational forms (one per block) 91 | a11 = inner(sigma, tau) * dx 92 | a12 = inner(div(tau), u) * dx 93 | a21 = inner(div(sigma), v) * dx 94 | # Add sources 95 | L2 = -inner(f, v) * dx 96 | 97 | # system matrix 98 | AA = block_assemble([[a11, a12], 99 | [a21, 0 ]]) 100 | # right hand side 101 | bb = block_assemble([0, L2]) 102 | 103 | # apply boundary conditions 104 | bcs.apply(AA).apply(bb) 105 | 106 | # Unlike in mixedpoisson.py the blocks of the preconditioner are constructed 107 | # rather than extracted from the system 108 | prec11 = inner(sigma, tau) * dx + inner(div(sigma), div(tau)) * dx 109 | prec22 = inner(u, v) * dx 110 | 111 | BB = block_assemble([[prec11, 0], 112 | [0, prec22]]) 113 | bcs.apply(BB) 114 | 115 | # We invert the blocks by tailored multigrid method 116 | params = {"max_levels": 10, 117 | # "print_level": 10, 118 | } 119 | M = HXDiv(BB[0][0], V=RT, parameters=params) 120 | N = AMG(BB[1][1], parameters=params) 121 | 122 | # Define the block preconditioner 123 | AAp = block_mat([[M, 0], 124 | [0, N]]) 125 | 126 | # Solver 127 | AAinv = MinRes(AA, precond=AAp, show=2, name='AA^', tolerance=1E-10) 128 | 129 | # ===================== 130 | # Solve the system 131 | Sigma, U = AAinv * bb 132 | # ===================== 133 | 134 | # Print norms that can be compared with those reported by demo-parallelmixedpoisson 135 | print(('norm Sigma:', Sigma.norm('l2'))) 136 | print(('norm U :', U.norm('l2'))) 137 | 138 | # Plot sigma and u 139 | # if MPI.size(mesh.mpi_comm()) == 1: 140 | # File('sigma_h.pvd') << Function(RT, Sigma) 141 | # File('u_h.pvd') << Function(DG, U) 142 | -------------------------------------------------------------------------------- /examples/haznics/poisson.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file examples/haznics/poisson.py 3 | Created by Ana Budisa on 2021-08-30. 4 | Example copyright by bitbucket.org/fenics-apps/cbc.block. 5 | 6 | We solve 7 | 8 | u + div(grad(u)) = f 9 | 10 | on a unit square domain. The preconditioner for this system is AMG. 11 | Outer solver is Conjugate Gradients. 12 | """ 13 | from block.iterative import ConjGrad 14 | from block.algebraic.hazmath import AMG 15 | from dolfin import * 16 | 17 | # Function spaces, elements 18 | mesh = UnitCubeMesh(16, 16, 16) 19 | 20 | V = FunctionSpace(mesh, "CG", 1) 21 | 22 | f = Expression("sin(pi*x[0])", degree=2) 23 | u, v = TrialFunction(V), TestFunction(V) 24 | 25 | a = u*v*dx + dot(grad(u), grad(v))*dx 26 | L = f*v*dx 27 | 28 | A = assemble(a) 29 | b = assemble(L) 30 | 31 | # here we use hazmath AMG: 32 | B = AMG(A,parameters={"max_levels":10,"print_level":10,"coarse_solver":32}) 33 | 34 | Ainv = ConjGrad(A, precond=B, tolerance=1e-10, show=2) 35 | 36 | # solve 37 | x = Ainv*b 38 | 39 | u = Function(V) 40 | u.vector()[:] = x[:] 41 | 42 | # default solver in Dolfin 43 | u2 = Function(V) 44 | solve(A, u2.vector(), b) 45 | 46 | print("Max differences between the two solutions: ", (u.vector()-u2.vector()).max()) 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/haznics/setup.rc: -------------------------------------------------------------------------------- 1 | # /bin/sh ./install_haznics.sh 2 | export PYTHONPATH=$(pwd)/../../swig_files:$PYTHONPATH 3 | dijitso clean 4 | -------------------------------------------------------------------------------- /examples/haznics/stokes_flat.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file examples/haznics/stokes_mixed.py 3 | Created by Ana Budisa on 2021-08-30. 4 | Example copyright by bitbucket.org/fenics-apps/cbc.block. 5 | 6 | This demo solves the steady Stokes equations for a lid driven 7 | cavity. We solve 8 | 9 | - div(symmgrad(u) - pI) = f 10 | - div(u) = 0 11 | 12 | with Taylor-Hood elements on a unit square domain. 13 | The algebraic system can be written as 14 | 15 | BB^ AA [u p]^T = BB^ [0 b]^T, 16 | 17 | where AA is a 2x2 block system with zero in the (2,2) block 18 | 19 | | A B | 20 | AA = | |, 21 | | C 0 | 22 | 23 | and BB^ approximates the inverse of the block operator 24 | 25 | | A 0 | 26 | BB = | |, 27 | | 0 M | 28 | 29 | where A is the Laplace operator and M the inner product in L2. 30 | For A, an AMG preconditioner is used, i.e. A^ = AMG(A). 31 | For M, we use Jacobi. 32 | """ 33 | from dolfin import * 34 | from block import * 35 | from block.algebraic.petsc import Jacobi 36 | from block.algebraic.hazmath import AMG 37 | from block.iterative import MinRes 38 | import haznics 39 | 40 | mesh = UnitSquareMesh(32, 32) 41 | 42 | V = VectorFunctionSpace(mesh, 'CG', 2) 43 | Q = FunctionSpace(mesh, 'CG', 1) 44 | W = (V, Q) 45 | 46 | f = Constant((0., 0.)) 47 | 48 | u, p = map(TrialFunction, W) 49 | v, q = map(TestFunction, W) 50 | 51 | a = [[inner(grad(u), grad(v)) * dx, -p * div(v) * dx], 52 | [-q * div(u) * dx, 0]] 53 | 54 | b = [[inner(grad(u), grad(v)) * dx + inner(u, v) * dx, 0], 55 | [0 , p * q * dx]] 56 | 57 | L = [inner(f, v) * dx, 0] 58 | 59 | Vbcs = [DirichletBC(V, (0., 0.), "on_boundary&&(x[1]<1-DOLFIN_EPS)"), 60 | DirichletBC(V, (1., 0.), "on_boundary&&(x[1]>1-DOLFIN_EPS)")] 61 | bcs = block_bc([Vbcs, []], symmetric=True) 62 | 63 | # assemble as block matrices 64 | A, B, rhs = map(block_assemble, (a, b, L)) 65 | bcs.apply(A).apply(rhs) 66 | bcs.apply(B) 67 | 68 | # build the preconditioner 69 | params = { 70 | 'AMG_type': haznics.SA_AMG, 71 | "aggregation_type": haznics.VMB, 72 | "max_levels":10,"print_level":10,"coarse_solver":32 73 | } 74 | P = block_mat([[AMG(B[0, 0], parameters=params), 0], 75 | [ 0, Jacobi(B[1, 1])]]) 76 | 77 | Ainv = MinRes(A, precond=P, relativeconv=True, tolerance=1e-5, show=3) 78 | x = Ainv * rhs 79 | 80 | from block.algebraic.hazmath import PETSc_to_dCSRmat 81 | XXX = B[0,0].array() 82 | import numpy as np 83 | xnorm0=np.linalg.norm(XXX - XXX.T) 84 | print("\nxnorm0=",xnorm0) 85 | Ahaz=PETSc_to_dCSRmat(B[0,0]) 86 | 87 | print('Haz B[0, 0] symmetry', haznics.chk_symmetry(Ahaz)) 88 | 89 | # plotting 90 | u, p = map(Function, W, x) 91 | 92 | print('|u|_0', sqrt(abs(assemble(inner(u, u)*dx)))) 93 | print('|p|_0', sqrt(abs(assemble(inner(p, p)*dx)))) 94 | 95 | File('./results/stokes_flat_u.pvd') << u 96 | File('./results/stokes_flat_p.pvd') << p 97 | -------------------------------------------------------------------------------- /examples/haznics/stokes_mixed.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file examples/haznics/stokes_mixed.py 3 | Created by Ana Budisa on 2021-08-30. 4 | Example copyright by bitbucket.org/fenics-apps/cbc.block. 5 | 6 | This demo solves the steady Stokes equations for a lid driven 7 | cavity. We solve 8 | 9 | - div(symmgrad(u) - pI) = f 10 | - div(u) = 0 11 | 12 | with Taylor-Hood elements on a unit square domain. 13 | The algebraic system can be written as 14 | 15 | BB^ AA [u p]^T = BB^ [0 b]^T, 16 | 17 | where AA is a 2x2 block system with zero in the (2,2) block 18 | 19 | | A B | 20 | AA = | |, 21 | | C 0 | 22 | 23 | and BB^ approximates the inverse of the block operator 24 | 25 | | A 0 | 26 | BB = | |, 27 | | 0 M | 28 | 29 | where A is the Laplace operator and M the inner product in L2. 30 | For A, an AMG preconditioner is used, i.e. A^ = AMG(A). 31 | For M, we use Jacobi preconditioner. 32 | """ 33 | from dolfin import * 34 | from block import * 35 | from block.algebraic.petsc import Jacobi 36 | from block.algebraic.hazmath import AMG 37 | from block.iterative import MinRes 38 | import haznics 39 | 40 | mesh = UnitSquareMesh(32, 32) 41 | 42 | P2 = VectorElement("Lagrange", triangle, 2) 43 | P1 = FiniteElement("Lagrange", triangle, 1) 44 | TH = MixedElement([P2, P1]) 45 | 46 | W = FunctionSpace(mesh, TH) 47 | 48 | f = Constant((0., 0.)) 49 | 50 | u, p = TrialFunctions(W) 51 | v, q = TestFunctions(W) 52 | 53 | a = inner(grad(u), grad(v)) * dx \ 54 | - p * div(v) * dx \ 55 | - q * div(u) * dx 56 | 57 | b = inner(grad(u), grad(v)) * dx + inner(u, v) * dx \ 58 | + p * q * dx 59 | 60 | L = inner(f, v) * dx 61 | 62 | bcs = [DirichletBC(W.sub(0), (0., 0.), "on_boundary&&(x[1]<1-DOLFIN_EPS)"), 63 | DirichletBC(W.sub(0), (1., 0.), "on_boundary&&(x[1]>1-DOLFIN_EPS)")] 64 | 65 | # assemble as block matrices 66 | A, _, rhs = block_assemble(a, L, bcs, symmetric=True) 67 | B, _, _ = block_assemble(b, L, bcs, symmetric=True) 68 | 69 | # build the preconditioner 70 | params = { 71 | 'AMG_type': haznics.SA_AMG, 72 | "aggregation_type": haznics.VMB, 73 | "max_levels":10,"print_level":10,"coarse_solver":32 74 | } 75 | 76 | from block.algebraic.hazmath import PETSc_to_dCSRmat 77 | XXX = B[0,0].array() 78 | import numpy as np 79 | xnorm0=np.linalg.norm(XXX - XXX.T) 80 | print("\nxnorm0=",xnorm0) 81 | Ahaz=PETSc_to_dCSRmat(B[0,0]) 82 | 83 | print('Haz B[0, 0] symmetry', haznics.chk_symmetry(Ahaz)) 84 | 85 | P = block_mat([[AMG(B[0, 0], parameters=params), 0], 86 | [ 0, Jacobi(B[1, 1])]]) 87 | 88 | Ainv = MinRes(A, precond=P, relativeconv=True, tolerance=1e-5, show=3) 89 | x = Ainv * rhs 90 | 91 | # plotting 92 | V, Q = [sub_space.collapse() for sub_space in W.split()] 93 | u, p = map(Function, [V, Q], x) 94 | 95 | print('|u|_0', sqrt(abs(assemble(inner(u, u)*dx)))) 96 | print('|p|_0', sqrt(abs(assemble(inner(p, p)*dx)))) 97 | 98 | File('./results/stokes_mixed_u.pvd') << u 99 | File('./results/stokes_mixed_p.pvd') << p 100 | -------------------------------------------------------------------------------- /examples/haznics/tests/input.dat: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: Laplacian_Simple_Test % 3 | % lines starting with % are comments % 4 | % must have spaces around the equal sign "=" % 5 | %----------------------------------------------% 6 | 7 | %---------------% 8 | % output flags 9 | %---------------% 10 | 11 | print_level = 2; % how much information to print out: 0 Nothing | >0 Something 12 | 13 | %---------------% 14 | % files 15 | %---------------% 16 | 17 | %gridfile = ../grids/1D/unitLINE_n17.haz 18 | %gridfile = ../grids/2D/unitSQ_n17.haz 19 | %gridfile = ../grids/3D/unitCUBE_n17.haz 20 | gridfile = /Users/xhu03/Work/Projects/HAZMAT/hydrolena/data/grids/255_5layers.grd 21 | output_dir = ./output/ 22 | 23 | %---------------% 24 | % finite element 25 | %---------------% 26 | 27 | nquad = 2 % Quadrature nodes each direction 28 | 29 | FE_type = 1 % 0-9 PX | 10-19 QX (not yet) | 20 Ned | 30 RT | -9--1 DGX (not yet) 30 | 31 | %---------------% 32 | % time stepping 33 | %---------------% 34 | 35 | time_step_type = 1 % 0 CN | 1 BDF1 | 2 BDF2 | 36 | time_steps = 0 % number of time steps 37 | time_step_size = 0.001 % time step size 38 | 39 | %---------------% 40 | % nonlinear solver 41 | %---------------% 42 | 43 | nonlinear_itsolver_type = 0 % 0 Linear Problem | 1 Newton | 2 Picard (not yet) 44 | nonlinear_itsolver_maxit = 0 % maximal iterations of nonlinear solver 45 | nonlinear_itsolver_tol = 1e-8 % tolerance for nonlinear solver 46 | nonlinear_itsolver_toltype = 0 % type of tolerance for nonlinear solver 1 - ||nonlinear residual|| 1E-12) or np.any(residues_i > 1E-12): 25 | poles = poles_r + 1j * poles_i 26 | residues = residues_r + 1j * residues_i 27 | else: 28 | poles = poles_r 29 | residues = residues_r 30 | 31 | return poles, residues 32 | 33 | 34 | if __name__ == "__main__": 35 | # params 36 | s = -0.2 37 | t = 0.6 38 | alpha = 1.0 39 | beta = 1.0 40 | coeff = 1./alpha if alpha > beta else 1/beta 41 | 42 | bound = 1.0 43 | tol = 1E-12 44 | npoints = (8*1024)+1 45 | 46 | # interpolation points 47 | x = np.linspace(0.0001, bound, npoints) 48 | 49 | # interpolation values at the points 50 | F = np.power((alpha * np.power(x, s) + beta * np.power(x, t)), -1) 51 | 52 | print("\nRational approx of a function f(x) = (a * x^s + b * x^t)^-1 on [0, 1]") 53 | print("s = %.1f, t = %.1f, alpha = %.1f, beta = %.1f\n" % (s, t, alpha, beta)) 54 | 55 | # compute poles, res with haznics 56 | pol_haz, res_haz = rational_approx_haznics(x, F, tol) 57 | 58 | # compute poles, res with baryrat 59 | r = aaa(x, F, tol=tol) 60 | pol_br, res_br = r.polres() 61 | 62 | # compute the constant term c0 63 | c0 = np.power((alpha * np.power(1.0, s) + beta * np.power(1.0, t)), -1) - np.sum(res_br / (1.0 - pol_br)) 64 | res_br = np.append(c0, res_br) 65 | 66 | # different points 67 | y = np.linspace(0.0001, bound, 6001) 68 | FF = np.power((alpha * np.power(y, s) + beta * np.power(y, t)), -1) 69 | 70 | rff = coeff * res_haz[0] * np.ones_like(FF) 71 | for pk, rk in zip(pol_haz, res_haz[1:]): 72 | rff[:] += coeff * rk / (y - pk) 73 | 74 | # error in interpolation points 75 | er = F - r(x) 76 | print(" BR ---- Rational approx error in interp points: ", np.linalg.norm(er, np.inf) / np.linalg.norm(F, np.inf)) 77 | 78 | # er_haz = F - rf 79 | 80 | # error in different points 81 | err = FF - r(y) 82 | err_haz = FF - rff 83 | 84 | print("\n HAZ ---- Number of poles: ", pol_haz.size) 85 | print(" HAZ ---- Poles: \n", pol_haz) 86 | print(" HAZ ---- Residues: \n", res_haz) 87 | 88 | print() 89 | print(" BR ---- Number of poles: ", pol_br.size) 90 | print(" BR ---- Poles: \n", pol_br) 91 | print(" BR ---- Residues: \n", res_br) 92 | 93 | # print(" HAZ ---- Rational approx error in interp points: ", np.linalg.norm(er_haz, np.inf) / np.linalg.norm(F, np.inf)) 94 | print(" HAZ ---- Rational approx error in different points: ", np.linalg.norm(err_haz, np.inf) / np.linalg.norm(FF, np.inf)) 95 | print(" BR ---- Rational approx error in different points: ", np.linalg.norm(err, np.inf) / np.linalg.norm(FF, np.inf)) 96 | 97 | 98 | -------------------------------------------------------------------------------- /examples/heat_equation/heat_equation_data.h: -------------------------------------------------------------------------------- 1 | /*! \file examples/heat_equation/heat_equation_data.h 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov 2019/01/09. 4 | * Copyright 2015_HAZMATH__. All rights reserved. 5 | * 6 | * \brief This contains all the Data parameters and coefficients 7 | * for the heat_equation example. This includes exact solutions, 8 | * RHS functions, initial conditions, and boundary conditions. 9 | * 10 | */ 11 | 12 | // PDE Coefficients 13 | void diffusion_coeff(REAL *val,REAL* x,REAL time,void *param) { 14 | // a(x) 15 | *val = 1.0; 16 | } 17 | 18 | // Exact Solution (if you have one) 19 | // Change as needed for different dimensions 20 | void exactsol2D(REAL *val,REAL* x,REAL time,void *param) { 21 | *val = sin(M_PI*x[0])*sin(M_PI*x[1])*exp(-2.0*M_PI*M_PI*time); 22 | } 23 | void exactsol3D(REAL *val,REAL* x,REAL time,void *param) { 24 | *val = sin(M_PI*x[0])*sin(M_PI*x[1])*sin(M_PI*x[2])*exp(-3*M_PI*M_PI*time); 25 | } 26 | 27 | // Right-hand Side 28 | void myrhs(REAL *val,REAL* x,REAL time,void *param) { 29 | *val = 0.0; 30 | } 31 | 32 | // Boundary Conditions 33 | void bc(REAL *val,REAL* x,REAL time,void *param) { 34 | *val= 0.0; 35 | } 36 | 37 | // Initial Conditions 38 | // Change as needed for different dimensions 39 | void initial_conditions2D(REAL *val,REAL* x,REAL time,void *param) { 40 | *val = sin(M_PI*x[0])*sin(M_PI*x[1]); 41 | } 42 | void initial_conditions3D(REAL *val,REAL* x,REAL time,void *param) { 43 | *val = sin(M_PI*x[0])*sin(M_PI*x[1])*sin(M_PI*x[2]); 44 | } 45 | -------------------------------------------------------------------------------- /examples/heat_equation/input.dat: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters: Heat Equation Simple Test % 3 | % lines starting with % are comments % 4 | % must have spaces around the equal sign "=" % 5 | %----------------------------------------------% 6 | 7 | %---------------% 8 | % output 9 | %---------------% 10 | 11 | print_level = 2; % how much information to print out: 0 Nothing | >0 Something 12 | output_dir = ./output/ % directory for all output (must be created) 13 | 14 | %---------------% 15 | % mesh 16 | %---------------% 17 | 18 | % We will build from HAZmath functions. See basic_elliptic for how to input gridfile 19 | read_mesh_from_file = 0 % Either read from file in .haz format (1) or build uniform mesh directly (0) 20 | 21 | % For using HAZmath's built-in uniform mesh functions 22 | spatial_dim = 2 % For now only 2D or 3D 23 | refinement_type = 11 % Refinement type (>10 uniform or <10 other) 24 | refinement_levels = 4 % Number of levels of refinement (2^(l+1) vertices in each direction) 25 | boundary_codes = 1 % Will set flags for DoF on boundary to be this value: 1-16 Dirichlet | 17-32 Neumann | 26 | 27 | %---------------% 28 | % finite element 29 | %---------------% 30 | 31 | nquad = 2 % Quadrature nodes each direction 32 | FE_type = 2 % 1-9 PX | 10-19 QX (not yet) | 20 Ned | 30 RT | -9--1 DGX (not yet) 33 | 34 | %---------------% 35 | % time stepping 36 | %---------------% 37 | 38 | time_step_type = 0 % 0 CN | 1 BDF1 | 2 BDF2 | 39 | time_steps = 10 % number of time steps 40 | time_step_size = 0.1 % time step size 41 | 42 | %---------------% 43 | % nonlinear solver 44 | %---------------% 45 | 46 | % Not needed here 47 | nonlinear_itsolver_type = 0 % 0 Linear Problem | 1 Newton | 2 Picard (not yet) 48 | nonlinear_itsolver_maxit = 0 % maximal iterations of nonlinear solver 49 | nonlinear_itsolver_tol = 1e-8 % tolerance for nonlinear solver 50 | nonlinear_itsolver_toltype = 0 % type of tolerance for nonlinear solver 1 - ||nonlinear residual|| Bytes/dof 26.29 22 | 23 | 8 V-cycles; rel.residual= 4.803e-07 ; damp.factor= 1.602e-01 24 | 25 | ***CPU (calculated by clock())= 4971.07 seconds 26 | 27 | -------------------------------------------------------------------------------- /examples/mg_geometric/output/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | */ -------------------------------------------------------------------------------- /examples/mg_geometric/sample.input: -------------------------------------------------------------------------------- 1 | 8 2 | 3 3 | 2 4 | 0 5 | 6 | First is number of levels (7 in this example) 7 | 8 | Second is the spatial dimension (2 in this example) 9 | 10 | Third is the number of smoothing steps (2 in this example) 11 | 12 | Forth is indicator whether FMG cycle is used or no. 1 is FMG 0 is V-cycle 13 | 14 | -------------------------------------------------------------------------------- /examples/solvers/A22.dat: -------------------------------------------------------------------------------- 1 | 128 128 128 2 | 0 0 1.000000000000000e+00 3 | 1 1 0.000000000000000e+00 4 | 2 2 0.000000000000000e+00 5 | 3 3 0.000000000000000e+00 6 | 4 4 0.000000000000000e+00 7 | 5 5 0.000000000000000e+00 8 | 6 6 0.000000000000000e+00 9 | 7 7 0.000000000000000e+00 10 | 8 8 0.000000000000000e+00 11 | 9 9 0.000000000000000e+00 12 | 10 10 0.000000000000000e+00 13 | 11 11 0.000000000000000e+00 14 | 12 12 0.000000000000000e+00 15 | 13 13 0.000000000000000e+00 16 | 14 14 0.000000000000000e+00 17 | 15 15 0.000000000000000e+00 18 | 16 16 0.000000000000000e+00 19 | 17 17 0.000000000000000e+00 20 | 18 18 0.000000000000000e+00 21 | 19 19 0.000000000000000e+00 22 | 20 20 0.000000000000000e+00 23 | 21 21 0.000000000000000e+00 24 | 22 22 0.000000000000000e+00 25 | 23 23 0.000000000000000e+00 26 | 24 24 0.000000000000000e+00 27 | 25 25 0.000000000000000e+00 28 | 26 26 0.000000000000000e+00 29 | 27 27 0.000000000000000e+00 30 | 28 28 0.000000000000000e+00 31 | 29 29 0.000000000000000e+00 32 | 30 30 0.000000000000000e+00 33 | 31 31 0.000000000000000e+00 34 | 32 32 0.000000000000000e+00 35 | 33 33 0.000000000000000e+00 36 | 34 34 0.000000000000000e+00 37 | 35 35 0.000000000000000e+00 38 | 36 36 0.000000000000000e+00 39 | 37 37 0.000000000000000e+00 40 | 38 38 0.000000000000000e+00 41 | 39 39 0.000000000000000e+00 42 | 40 40 0.000000000000000e+00 43 | 41 41 0.000000000000000e+00 44 | 42 42 0.000000000000000e+00 45 | 43 43 0.000000000000000e+00 46 | 44 44 0.000000000000000e+00 47 | 45 45 0.000000000000000e+00 48 | 46 46 0.000000000000000e+00 49 | 47 47 0.000000000000000e+00 50 | 48 48 0.000000000000000e+00 51 | 49 49 0.000000000000000e+00 52 | 50 50 0.000000000000000e+00 53 | 51 51 0.000000000000000e+00 54 | 52 52 0.000000000000000e+00 55 | 53 53 0.000000000000000e+00 56 | 54 54 0.000000000000000e+00 57 | 55 55 0.000000000000000e+00 58 | 56 56 0.000000000000000e+00 59 | 57 57 0.000000000000000e+00 60 | 58 58 0.000000000000000e+00 61 | 59 59 0.000000000000000e+00 62 | 60 60 0.000000000000000e+00 63 | 61 61 0.000000000000000e+00 64 | 62 62 0.000000000000000e+00 65 | 63 63 0.000000000000000e+00 66 | 64 64 0.000000000000000e+00 67 | 65 65 0.000000000000000e+00 68 | 66 66 0.000000000000000e+00 69 | 67 67 0.000000000000000e+00 70 | 68 68 0.000000000000000e+00 71 | 69 69 0.000000000000000e+00 72 | 70 70 0.000000000000000e+00 73 | 71 71 0.000000000000000e+00 74 | 72 72 0.000000000000000e+00 75 | 73 73 0.000000000000000e+00 76 | 74 74 0.000000000000000e+00 77 | 75 75 0.000000000000000e+00 78 | 76 76 0.000000000000000e+00 79 | 77 77 0.000000000000000e+00 80 | 78 78 0.000000000000000e+00 81 | 79 79 0.000000000000000e+00 82 | 80 80 0.000000000000000e+00 83 | 81 81 0.000000000000000e+00 84 | 82 82 0.000000000000000e+00 85 | 83 83 0.000000000000000e+00 86 | 84 84 0.000000000000000e+00 87 | 85 85 0.000000000000000e+00 88 | 86 86 0.000000000000000e+00 89 | 87 87 0.000000000000000e+00 90 | 88 88 0.000000000000000e+00 91 | 89 89 0.000000000000000e+00 92 | 90 90 0.000000000000000e+00 93 | 91 91 0.000000000000000e+00 94 | 92 92 0.000000000000000e+00 95 | 93 93 0.000000000000000e+00 96 | 94 94 0.000000000000000e+00 97 | 95 95 0.000000000000000e+00 98 | 96 96 0.000000000000000e+00 99 | 97 97 0.000000000000000e+00 100 | 98 98 0.000000000000000e+00 101 | 99 99 0.000000000000000e+00 102 | 100 100 0.000000000000000e+00 103 | 101 101 0.000000000000000e+00 104 | 102 102 0.000000000000000e+00 105 | 103 103 0.000000000000000e+00 106 | 104 104 0.000000000000000e+00 107 | 105 105 0.000000000000000e+00 108 | 106 106 0.000000000000000e+00 109 | 107 107 0.000000000000000e+00 110 | 108 108 0.000000000000000e+00 111 | 109 109 0.000000000000000e+00 112 | 110 110 0.000000000000000e+00 113 | 111 111 0.000000000000000e+00 114 | 112 112 0.000000000000000e+00 115 | 113 113 0.000000000000000e+00 116 | 114 114 0.000000000000000e+00 117 | 115 115 0.000000000000000e+00 118 | 116 116 0.000000000000000e+00 119 | 117 117 0.000000000000000e+00 120 | 118 118 0.000000000000000e+00 121 | 119 119 0.000000000000000e+00 122 | 120 120 0.000000000000000e+00 123 | 121 121 0.000000000000000e+00 124 | 122 122 0.000000000000000e+00 125 | 123 123 0.000000000000000e+00 126 | 124 124 0.000000000000000e+00 127 | 125 125 0.000000000000000e+00 128 | 126 126 0.000000000000000e+00 129 | 127 127 0.000000000000000e+00 130 | -------------------------------------------------------------------------------- /examples/solvers/input_Schwarz.dat: -------------------------------------------------------------------------------- 1 | %----------------------------------------------% 2 | % input parameters for basic_elliptic example % 3 | % This can simulate the grad grad, curl curl, % 4 | % or div div operator as a test problem. % 5 | % lines starting with % are comments % 6 | % must have spaces around the equal sign "=" % 7 | %----------------------------------------------% 8 | 9 | %---------------% 10 | % output 11 | %---------------% 12 | 13 | print_level = 2; % how much information to print out: 0 Nothing | >0 Something 14 | output_dir = ./output/ % directory for all output (must be created) 15 | 16 | 17 | %---------------% 18 | % mesh 19 | %---------------% 20 | 21 | read_mesh_from_file = 0 % [0/1]; 1=Either read from file in .haz format or 0=build uniform mesh directly 22 | 23 | % For reading in a pre-made mesh file (any dimension works) 24 | gridfile = unitSQ_n9.haz 25 | 26 | % For using HAZmath's built-in uniform mesh functions 27 | spatial_dim = 3 % For now only 2D or 3D 28 | refinement_type = 11 % Refinement type (>10 uniform or <10 other) 29 | refinement_levels = 6 % Number of levels of refinement (2^(l+1) vertices in each direction) 30 | boundary_codes = 1 % Will set the boundary codes 31 | 32 | %---------------% 33 | % finite element 34 | %---------------% 35 | 36 | nquad = 2 % Quadrature nodes each direction 37 | FE_type = 1 % 1-9 PX | 10-19 QX (not yet) | 20 Ned | 30 RT | -9--1 DGX (not yet) 38 | 39 | %---------------% 40 | % time stepping 41 | %---------------% 42 | 43 | % Not needed here 44 | time_step_type = 1 % 0 CN | 1 BDF1 | 2 BDF2 | 45 | time_steps = 0 % number of time steps 46 | time_step_size = 0.01 % time step size 47 | 48 | %---------------% 49 | % nonlinear solver 50 | %---------------% 51 | 52 | % Not needed here 53 | nonlinear_itsolver_type = 0 % 0 Linear Problem | 1 Newton | 2 Picard (not yet) 54 | nonlinear_itsolver_maxit = 0 % maximal iterations of nonlinear solver 55 | nonlinear_itsolver_tol = 1e-8 % tolerance for nonlinear solver 56 | nonlinear_itsolver_toltype = 0 % type of tolerance for nonlinear solver 1 - ||nonlinear residual||3): 43 | op.dim=3 44 | 45 | if(op.idir==''): 46 | op.idir="./input/1d_nets_"+str(op.dim)+"d/" 47 | 48 | import ctypes 49 | import os 50 | op.idir=os.path.abspath(op.idir)+'/' 51 | op.odir=os.path.abspath(op.odir)+'/' 52 | 53 | sdim=str(op.dim) 54 | libxd_1d_=ctypes.CDLL(os.path.abspath('./libxd_1d_.so')) 55 | 56 | dim=ctypes.c_int(op.dim); 57 | max_nodes=ctypes.c_int(op.max_nodes); 58 | ref_levels=ctypes.c_int(op.ref_levels); 59 | 60 | idir=bytes(op.idir,'utf-8') 61 | odir=bytes(op.odir,'utf-8') 62 | 63 | 64 | #libxd_1d_.xd_1d_lib(const INT dimbig, const INT max_nodes_in, const INT ref_levels_in, const char *idir, const char *odir) 65 | 66 | libxd_1d_.xd_1d_lib(dim,max_nodes,ref_levels,idir,odir) 67 | 68 | mesh=meshio.read(op.odir+'1d_grid'+str(op.max_nodes)+'.vtu') 69 | mesh.write(op.odir+'1d_grid'+str(op.max_nodes)+'.xdmf') 70 | # '+str(op.max_nodes)+' 71 | 72 | mesh=meshio.read(op.odir+sdim+'d_grid'+str(op.max_nodes)+'.vtu') 73 | mesh.write(op.odir+sdim+'d_grid'+str(op.max_nodes)+'.xdmf') 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /examples/xd_1d_models/run_solver.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created at 16:25:34 on Sun 20230404 4 | 5 | @author: ltz1 6 | """ 7 | 8 | # 9 | from optparse import OptionParser 10 | import time 11 | import re 12 | import pathlib 13 | import meshio 14 | 15 | #ztime=str(time.strftime("%H:%M:%S")) 16 | #zdate=str(time.strftime("%Y%m%d")) 17 | 18 | ############################################################## 19 | 20 | usage = "usage: python3 %prog [-h] -d dimension -i input_dir -o output_dir" 21 | 22 | default_dim=2; 23 | 24 | getopt = OptionParser(usage=usage) 25 | 26 | getopt.add_option("-f", "--solver_input", action="store", type="string", dest="solver_input_file", help="solver input", metavar="SOLVER_INPUT",default="./input/solver.input") 27 | 28 | getopt.add_option("-i", "--input_matrices_dir", action="store", type="string", dest="matrices_dir", help="Directory with matrices(npy)", metavar="MATRICES_DIR",default="./input/1d_matrices_"+str(default_dim)+"d/") 29 | 30 | (op, args) = getopt.parse_args() 31 | 32 | import ctypes 33 | import os 34 | op.solver_input_file=os.path.abspath(op.solver_input_file) 35 | op.matrices_dir=os.path.abspath(op.matrices_dir)+'/' 36 | 37 | libxd_1d_=ctypes.CDLL(os.path.abspath('./libxd_1d_.so')) 38 | 39 | sfile=bytes(op.solver_input_file,'utf-8') 40 | mdir=bytes(op.matrices_dir,'utf-8') 41 | print("\nsolver input file: ",op.solver_input_file,"\nmatrices_dir=",op.matrices_dir,"\n") 42 | libxd_1d_.solver_xd_1d(sfile,mdir) 43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/xd_1d_models/solver_xd_1d.h: -------------------------------------------------------------------------------- 1 | /*! \file examples/solver/solver_bdcsr.c 2 | * 3 | * Created by Xiaozhe Hu on 04/16/22. 4 | * Copyright 2022_HAZMATH__. All rights reserved. 5 | * 6 | * \brief This program read in a matrix (in block_dCSRmat format) and a right hand side and solve it by certain linear solvers 7 | * 8 | * \note 9 | * 10 | */ 11 | 12 | /************* HAZMATH FUNCTIONS and INCLUDES ***************************/ 13 | INT solver_xd_1d(const char *finput_solver,const char *dir_matrices) 14 | { 15 | /*************** ACTION *************************************/ 16 | // char *dir_matrices=strdup("./input/1d_matrices_2d/"); 17 | // char *finput_solver=strdup("./input/solver.input"); 18 | /* Set Solver Parameters */ 19 | input_param inparam; 20 | dCSRmat A; // 21 | dvector b,x; 22 | ivector *idofs=malloc(1*sizeof(ivector)); 23 | idofs->row=0; 24 | idofs->val=NULL; 25 | // 26 | read_and_setup_blk(finput_solver,dir_matrices,&inparam,&A,&b,&x,&idofs); 27 | // 28 | // INT num_iters=-20; 29 | /* Set parameters for linear iterative methods */ 30 | linear_itsolver_param linear_itparam; 31 | param_linear_solver_set(&linear_itparam, &inparam); 32 | /* Set parameters for algebriac multigrid methods */ 33 | AMG_param amgparam; 34 | param_amg_init(&amgparam); 35 | param_amg_set(&amgparam, &inparam); 36 | param_amg_print(&amgparam); 37 | 38 | fprintf(stdout,"\n===========================================================================\n"); 39 | fprintf(stdout,"Solving the linear system \n"); 40 | fprintf(stdout,"===========================================================================\n"); 41 | // -------------------------------------------------------------------------------------------- 42 | // Set diagonal blocks for AMG solver. Coarsening is based on the blocks in AD. 43 | // They can be diagonal blocks of the block matrix A or approximations to the Schur complements 44 | // -------------------------------------------------------------------------------------------- 45 | if (linear_itparam.linear_precond_type == 16 ){ 46 | linear_solver_dcsr_krylov_metric_amg(&A, &b, &x, idofs, &linear_itparam, &amgparam); 47 | } 48 | else if (linear_itparam.linear_precond_type == PREC_AMG){ 49 | linear_solver_dcsr_krylov_amg(&A, &b, &x, &linear_itparam, &amgparam); 50 | } 51 | // No preconditoner 52 | else{ 53 | linear_itparam.linear_precond_type=0; 54 | linear_solver_dcsr_krylov(&A, &b, &x, &linear_itparam); 55 | } 56 | dvec_free(&b); 57 | dvec_free(&x); 58 | dcsr_free(&A); 59 | return 0; 60 | } 61 | /*******************************************************************/ 62 | -------------------------------------------------------------------------------- /haz_config/hazmath.mk.example: -------------------------------------------------------------------------------- 1 | ####################################################################### 2 | # Simple Finite Element Package (HAZMAT) 3 | # 4 | ################# User Defined Configuration Options ################# 5 | # 6 | # 1. Copy this file to a file named "hazmat.mk". 7 | # 2. Edit "hazmat.mk" to adjust options/settings for your system 8 | # following the directions below. 9 | # 3. Type "make help" to see all build and configuration options. 10 | ######################################################################## 11 | # 12 | # The default setting for build type for HAZMAT is RELEASE. The RELEASE 13 | # build type by default has the "-O3". You may adjust the optimization 14 | # compilation options according to your hardware and software setting. 15 | # For example, on a macbook pro with Intel i7, best options could be 16 | # "-Ofast -march=corei7 -mtune=corei7". 17 | # 18 | # If you want to work with build type DEBUG, then uncomment the next 19 | # line (to include "-Wall -g") 20 | # 21 | debug=yes 22 | # 23 | # In order to get debug output during run-time, you can uncomment the 24 | # following line (to include "-Wall -g -DDEBUG_MODE=3"): 25 | # 26 | debug=all 27 | # 28 | # The default setting for vebosity level for HAZMAT is verbose=no. If you 29 | # want to increase verbosity level, uncomment the next line: 30 | # 31 | # verbose=yes 32 | # 33 | # By default, HAZMAT generates static libraries. If you need to generate 34 | # shared libs instead of static libs, uncomment the next line: 35 | # 36 | # shared=yes 37 | # 38 | # You may use multithread version after you enable OpenMP support. To 39 | # setup the environment, you need 40 | # >> export OMP_NUM_THREADS=4 (for bash) 41 | # >> setenv OMP_NUM_THREADS 4 (for tcsh) 42 | # If you want to compile with OpenMP support, uncomment the next line: 43 | # 44 | # openmp=yes 45 | # 46 | # These user options can also be applied as make command line options. 47 | # For example, to enforce the debug compiling options: 48 | # 49 | # make config debug=yes 50 | # 51 | #------------------------------------------------------------------------- 52 | # If you want to use the SuiteSparse package, uncomment the next 53 | # line (and read carefully the instructons below it): 54 | # 55 | # suitesparse=yes 56 | # 57 | # If you have installed SuiteSparse from source or for some other 58 | # reason you want to specify the path to SuiteSparse libraries and 59 | # header files, uncomment and edit the definition of "suitesparse_dir" 60 | # below (and continue reading...) 61 | # 62 | suitesparse_dir=/opt/local/lib 63 | # 64 | # IMPORTANT: 65 | # This defines the path to the SuiteSparse library and include files. 66 | # These are expected to be found in $(suitesparse_dir)/lib and 67 | # $(suitesparse_dir)/include or in the system standard paths for libraries 68 | # and header files. 69 | # ------------------------------------------------------------------------- 70 | # If you want to use the interface with MATLAB, uncomment the next line: 71 | # 72 | # matlab=yes 73 | # 74 | # ------------------------------------------------------------------------ 75 | #################### User Defined Compiler Flags ##################### 76 | #cflags="-funroll-loops -funswitch-loops" 77 | #cxxflags="-funroll-loops -funswitch-loops" 78 | #fflags="-funroll-loops -funswitch-loops" 79 | -------------------------------------------------------------------------------- /haz_docs/HELP.txt: -------------------------------------------------------------------------------- 1 | ============================================================= 2 | HAZMATH 3 | ------------------------------------------------------------- 4 | Quick start: 1. Edit "haz_config/hazmath.mk" as needed. 5 | 2. Type "make config" ; 6 | and then "make install" 7 | ============================================================= 8 | make config # set environment to build 9 | make config CC=gcc # set a specific C compiler 10 | make config debug=yes # compiler's debug options ON 11 | make headers # function defs in include/hazmath.h 12 | make docs # install documentations for HAZMATH 13 | # (!need to set doxygen=yes!) 14 | make # compile/link libhazmath 15 | make install # install libhazmath and examples 16 | make clean # remove *.o and *~ files 17 | make distclean # delete the build directory 18 | ============================================================= 19 | *More user defined options can go in "haz_config/hazmath.mk"* 20 | 21 | -------------------------------------------------------------------------------- /haz_shutils/get_dup_hashes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## prints all sha of commits that are seen twice or more in the log 3 | ## with the same author and the same time stamp. 4 | 5 | usage() { 6 | echo "" 7 | echo "===========================================================" 8 | echo "Usage:" 9 | echo " $1 existing_local_git_repository" 10 | echo "===========================================================" 11 | echo "*** OR if you are already in a git repo tree *** " 12 | echo "-----------------------------------------------------------" 13 | echo " $1 ." 14 | echo "-----------------------------------------------------------" 15 | echo "" 16 | } 17 | 18 | if [ $# -ne 1 ] 19 | then 20 | echo "Wrong number of arguments (num_args=$#)" 21 | usage $0 22 | exit 1 23 | else 24 | if [ -d $1 ] 25 | then 26 | cd $1 27 | chk=`git rev-parse --is-inside-work-tree 2>&1|cut -d: -f1` 28 | if [ $chk = "true" ] 29 | then 30 | git log --date=format:'%s' --pretty=format:'%H:%ad%al' | awk -F: 'a[$2]++{print $0}' | cut -d: -f1 31 | exit 0 32 | else 33 | echo "ERR: $1 is not a git repository" 34 | usage $0 35 | exit 3 36 | fi 37 | else 38 | usage $0 39 | exit 2 40 | fi 41 | fi 42 | -------------------------------------------------------------------------------- /haz_shutils/haznics_swig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # A simple shell script to get haznics dependencies 3 | # Ana Budisa - 2021-07-15 4 | 5 | # Update cmake if needed 6 | echo "Installing cmake v >= 3.16..." 7 | sudo apt-get update 8 | sudo apt-get install cmake 9 | echo "... Done." 10 | 11 | # Install swig4.0 12 | echo "Installing swig v >= 4.0..." 13 | sudo apt-get install swig 14 | echo "... Done." 15 | 16 | # Install suitesparse if needed 17 | echo "Installing suitesparse..." 18 | sudo apt install -y libsuitesparse-dev 19 | echo "... Done." 20 | 21 | # Install python-dev 22 | echo "Installing python3-dev..." 23 | sudo apt-get install -y python3-dev 24 | echo "... Done." 25 | 26 | # Install numpy 27 | echo "Installing numpy on python3..." 28 | sudo python3 -m pip install --upgrade pip 29 | sudo pip install numpy 30 | echo "... Done." -------------------------------------------------------------------------------- /haz_shutils/headmk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # usage is headmk.sh ${CMAKE_CURRENT_SOURCE_DIR} where we assume that 4 | # ${CMAKE_CURRENT_SOURCE_DIR} has subdirectories src and include and 5 | # the function names from src/*/*.c are put into the include/hazmath.h 6 | # commented as is not needed for now (ltz, 20190730) 7 | #set +x 8 | 9 | cat $1/src/assemble/*.c $1/src/fem/*.c \ 10 | $1/src/mesh/*.c $1/src/nonlinear/*.c \ 11 | $1/src/solver/*.c $1/src/utilities/*.c \ 12 | $1/src/timestepping/*.c $1/src/interfaces/*.c \ 13 | $1/src/amr/*.c $1/src/graphs/*.c \ 14 | $1/src/eigen/*.c \ 15 | $1/src/approximation/*.c \ 16 | | awk -v name="hazmath.h" -f mkheaders.awk > $1/include/hazmath.h 17 | 18 | #cat $1/src/haznics/*.CC \ 19 | # | awk -v name="helpder.hidden" -f mkheaders.awk >> $1/include/hazmath.h 20 | 21 | #set -x 22 | -------------------------------------------------------------------------------- /haz_shutils/headmk_haznics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # usage is headmk_swig.sh ${CMAKE_CURRENT_SOURCE_DIR} where we assume that 4 | # ${CMAKE_CURRENT_SOURCE_DIR} has subdirectories src and include and 5 | # the function names from src/haznics/*.c are put into the include/hazmath_swig.h 6 | # commented as is not needed for now (ltz, 20190730) FORTRAN: the 7 | #set +x 8 | 9 | cat $1/src/haznics/*.c \ 10 | | awk -v name="haznics_add.h" -f mkheaders_simple.awk > $1/include/haznics_add.h 11 | 12 | #set -x 13 | -------------------------------------------------------------------------------- /haz_shutils/mkheaders.awk: -------------------------------------------------------------------------------- 1 | # generate prototypes for Samba C code 2 | # originally writen by A. Tridge, June 1996 3 | # this modified version was taken from rsync 2.4.6 4 | 5 | # removed some things that I do not need in SiPSMG (ltz, 2009) 6 | # modified by JAdler for FEM_MHD (2010-May-07) 7 | 8 | BEGIN { 9 | inheader=0; 10 | print "/*******************************************************************/ " 11 | print "/* This header file was automatically generated with \"make headers\". */" 12 | print "/* WARNING: DO NOT EDIT!!! */ " 13 | print "/*******************************************************************/ " 14 | print "" 15 | print "// Standard Includes" 16 | print "#include " 17 | print "#include " 18 | print "#include " 19 | print "#include " 20 | print "#include " 21 | print "#include " 22 | print "#include " 23 | print "#include " 24 | print "#include " 25 | print "#include " 26 | print "#include " 27 | print "#include " 28 | print "#include " 29 | print "#if WITH_HAZNICS" 30 | print "#include " 31 | print "#endif" 32 | print "// Internal Includes" 33 | print "#include \"macro.h\"" 34 | print "#include \"mesh.h\"" 35 | print "#include \"amr.h\"" 36 | print "#include \"sparse.h\"" 37 | print "#include \"dense.h\"" 38 | print "#include \"vec.h\"" 39 | print "#include \"fem.h\"" 40 | print "#include \"solver.h\"" 41 | print "#include \"nonlinear.h\"" 42 | print "#include \"timestep.h\"" 43 | print "#include \"param.h\"" 44 | print "#include \"eigen.h\"" 45 | print "#include \"graphs.h\"" 46 | print "// Special Includes" 47 | print "#if WITH_MATLAB" 48 | print "#include \"mex.h\"" 49 | print "#endif" 50 | print "#if WITH_HAZNICS" 51 | print "#include \"haznics_add.h\"" 52 | print "#endif" 53 | } 54 | 55 | { 56 | if (inheader) { 57 | if (match($0,"[)][ \t]*$") || match($0,"[)][ \t][{][ \t]*$")) { 58 | inheader = 0; 59 | printf "%s;\n",$0; 60 | } else { 61 | printf "%s\n",$0; 62 | } 63 | next; 64 | } 65 | } 66 | 67 | /\/*! \\file/ { 68 | printf "\n/* In file: %s */\n",$3; 69 | } 70 | 71 | /^static|^extern/ || !/^[a-zA-Z]/ || /[;]/ { 72 | next; 73 | } 74 | 75 | !/^INT|^REAL|^coordinates|^mesh_struct|^qcoordinates|^FILE|^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^SHORT|^BOOL|^void|^double|^time|^dCSRmat|^dvector|^iCSRmat|^ivector|^dCOOmat|^dDENSEmat|^iDENSEmat|^dBSRmat|^block_dCSRmat|^AMG_data|^AMG_param|^scomplex|^MG_blk_data|^HX_curl_data|^HX_div_data|^precond_block_data|^precond_data|^precond_ra_data|^smoother_data|^smoother_matvec|^PyObject|^subscomplex|^macrocomplex|^unigrid|^cube2simp|^input_grid|^coordsystem|^features|^locdetails/ { 76 | 77 | next; 78 | } 79 | 80 | /[(].*[)][ \t]*$/ { 81 | printf "%s;\n",$0; 82 | next; 83 | } 84 | 85 | /[(]/ { 86 | inheader=1; 87 | printf "%s\n",$0; 88 | next; 89 | } 90 | 91 | END { 92 | print "\n/* End of header file */" 93 | } 94 | -------------------------------------------------------------------------------- /haz_shutils/mkheaders_simple.awk: -------------------------------------------------------------------------------- 1 | # generate prototypes for Samba C code 2 | # originally writen by A. Tridge, June 1996 3 | # this modified version was taken from rsync 2.4.6 4 | 5 | # removed some things that I do not need in SiPSMG (ltz, 2009) 6 | # modified by JAdler for FEM_MHD (2010-May-07) 7 | 8 | BEGIN { 9 | inheader=0; 10 | print "/*******************************************************************/ " 11 | print "/* This header file was automatically generated with \"make headers\". */" 12 | print "/* WARNING: DO NOT EDIT!!! */ " 13 | print "/*******************************************************************/ " 14 | print "" 15 | } 16 | 17 | { 18 | if (inheader) { 19 | if (match($0,"[)][ \t]*$") || match($0,"[)][ \t][{][ \t]*$")) { 20 | inheader = 0; 21 | printf "%s;\n",$0; 22 | } else { 23 | printf "%s\n",$0; 24 | } 25 | next; 26 | } 27 | } 28 | 29 | /\/*! \\file/ { 30 | printf "\n/* In file: %s */\n",$3; 31 | } 32 | 33 | /^static|^extern/ || !/^[a-zA-Z]/ || /[;]/ { 34 | next; 35 | } 36 | 37 | !/^INT|^REAL|^coordinates|^mesh_struct|^qcoordinates|^FILE|^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^struct|^SHORT|^BOOL|^void|^double|^time|^dCSRmat|^dvector|^iCSRmat|^ivector|^dCOOmat|^dDENSEmat|^iDENSEmat|^block_dCSRmat|^AMG_data|^AMG_param|^scomplex|^MG_blk_data|^HX_curl_data|^HX_div_data|^precond_block_data|^precond_data|^precond_ra_data|^precond|^smoother_data|^smoother_matvec|^PyObject|^subscomplex|^macrocomplex|^unigrid|^cube2simp|^input_grid|^coordsystem|^features|^locdetails/ { 38 | 39 | next; 40 | } 41 | 42 | /[(].*[)][ \t]*$/ { 43 | printf "%s;\n",$0; 44 | next; 45 | } 46 | 47 | /[(]/ { 48 | inheader=1; 49 | printf "%s\n",$0; 50 | next; 51 | } 52 | 53 | END { 54 | print "\n/* End of header file */" 55 | } 56 | 57 | -------------------------------------------------------------------------------- /include/.gitignore: -------------------------------------------------------------------------------- 1 | ignore -------------------------------------------------------------------------------- /include/dense.h: -------------------------------------------------------------------------------- 1 | // 2 | // dense.h 3 | // 4 | // 5 | // Created by Hu, Xiaozhe on 01/04/20. 6 | // 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef _dense_h 14 | #define _dense_h 15 | 16 | /** 17 | * \struct dDENSEmat 18 | * \brief Dense matrix of REAL type in DENSE format 19 | * 20 | * DENSE Format in REAL 21 | * 22 | */ 23 | typedef struct dDENSEmat{ 24 | 25 | //! number of rows 26 | INT row; 27 | 28 | //! number of columns 29 | INT col; 30 | 31 | //! array of values 32 | REAL *val; 33 | 34 | } dDENSEmat; 35 | 36 | /** 37 | * \struct iDENSEmat 38 | * \brief Dense matrix of INT type in DENSE format 39 | * 40 | * DENSE Format in INT 41 | * 42 | */ 43 | typedef struct iDENSEmat{ 44 | 45 | //! number of rows 46 | INT row; 47 | 48 | //! number of columns 49 | INT col; 50 | 51 | //! array of values 52 | INT *val; 53 | 54 | } iDENSEmat; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/doxygen.h: -------------------------------------------------------------------------------- 1 | /*! \file doxygen.h 2 | * \brief Main page for Doygen documentation 3 | */ 4 | 5 | /** \mainpage Introduction 6 | * 7 | * The HAZMATH Finite Element (FE) and Solver library is built from C (C99 compatible) source files and 8 | * provides software components that can be used to simulate physical/social phenomena described by Partial 9 | * Differential Equations (PDEs), systems of PDEs, or graphs. We have included several standard discretizations 10 | * for PDEs, often used in various applications. Our examples range from simple scalar elliptic PDEs to systems 11 | * of PDEs, include time-dependent and nonlinear problems, and contain methods for the solution of linear 12 | * systems. 13 | * 14 | * Our aim is to provide a basic tool, which can be used to tackle specific problems on demand. We do not intend 15 | * to create a universal package that contains all discretizations available. HAZMATH contains the software to 16 | * solve numerical models based on finite-element/volume/difference discretizations, and our team can assist in 17 | * tweaking and adjusting these basic tools to meet the demands of the specific application. Thus, we aim to 18 | * complement the user's expertise and help build application-specific packages. 19 | * 20 | */ 21 | 22 | /** 23 | * \page download How to obtain HAZMATH 24 | * 25 | * A tarball with installation instructions and the source files needed to build the HAZmath library 26 | * and the examples can be requested by emailing the developers at hazmath [at] googlegroups [dot] com. 27 | * 28 | */ 29 | 30 | 31 | /** 32 | * \page developers Developers 33 | * 34 | * Authors: 35 | * 36 | * - Xiaozhe Hu (Tufts University) 37 | * 38 | * - James Adler (Tufts University) 39 | * 40 | * - Ludmil Zikatanov (Penn State University) 41 | * 42 | * Contributors: 43 | * 44 | * - Peter Ohm (Tufts University) 45 | * 46 | */ 47 | 48 | /** 49 | * \page doxygen_comment Doxygen 50 | * 51 | * We use Doxygen as our automatic documentation generator, which will 52 | * minimize future maintenence. You can obtain this software (Windows, Linux and 53 | * OS X) as well as its manual on the official website: 54 | * 55 | * http://www.doxygen.org 56 | * 57 | * 58 | */ 59 | 60 | /*---------------------------------*/ 61 | /*-- End of File --*/ 62 | /*---------------------------------*/ 63 | 64 | -------------------------------------------------------------------------------- /include/eigen.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // eigen.h 4 | // 5 | // 6 | // Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov on 20200529 7 | // 8 | // 9 | #ifndef _eigen_h 10 | #define _eigen_h 11 | #endif 12 | 13 | // LAPACK Routines 14 | 15 | // Symmetric eigenvalue computation 16 | void dsygv_( INT *itype, char *jobz, char *uplo, INT *n, \ 17 | REAL *a, INT *lda, REAL *b, INT *ldb, REAL *w, \ 18 | REAL *work, INT *lwork, INT *info ); 19 | 20 | // Symmetric tridiagonal eigenvalur computation 21 | void dsterf_(INT *N, REAL *D, REAL *E, INT *INFO); 22 | 23 | // svd 24 | void dgesvd_( char *joba, char *jobu, INT *m, INT *n, \ 25 | REAL *a, INT *lda, REAL *s, REAL *u, INT *ldu, REAL *vt, \ 26 | INT *ldvt, REAL *work, INT *lwork, INT *info ); 27 | 28 | // qr factorization 29 | void dgeqrf_(INT *m, INT *n, REAL *a, INT *lda, REAL *tau, REAL* work, \ 30 | INT* lwork, INT* info); 31 | 32 | // extract Q from QR factorization 33 | void dorgqr_(INT *m, INT *n1, INT *n2, REAL *a, INT *lda, REAL *tau, REAL* work, \ 34 | INT* lwork, INT* info); 35 | // 36 | // nonsymmetric eigenvalue computations and SVD 37 | // 38 | void dgeevx_( char *balanc, char *jobvl, char *jobvr, char *sense, \ 39 | INT *n, REAL *a, INT *lda, REAL *wr, REAL *wi, \ 40 | REAL *vl, INT *ldvl, REAL *vr, INT *ldvr, \ 41 | INT *ilo, INT *ihi, REAL *scale, REAL *abnrm, \ 42 | REAL *rconde, REAL *rcondv, REAL *work, INT *lwork, \ 43 | INT *iwork, INT *info ); 44 | 45 | void dgesvd_(char *jobu, char *jobvt, INT *m, INT *n, \ 46 | REAL *a, INT *lda, REAL *s, \ 47 | REAL *u,INT *ldu, REAL *vt, INT *ldvt, \ 48 | REAL *work,INT *lwork, INT *info); 49 | // this should be replaced by lapack.h if any exists in a standard install of lapack. 50 | -------------------------------------------------------------------------------- /include/graphs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \struct stack 3 | * \brief to be added -- Ludmil 4 | */ 5 | typedef struct stack { 6 | INT top; 7 | INT num_items; 8 | INT null_item; 9 | INT *items; 10 | } stack; 11 | ////////////////////////////////////////////////////////////// 12 | /** 13 | * \struct weights 14 | * \brief to be added -- Xiaozhe 15 | */ 16 | typedef struct 17 | { 18 | REAL val; 19 | INT id; //for the permutation 20 | } weights; 21 | 22 | /** 23 | * \struct iweights 24 | * \brief to be added -- Xiaozhe 25 | */ 26 | typedef struct 27 | { 28 | INT mask; 29 | INT val; 30 | INT id; //for the permutation 31 | } iweights; 32 | 33 | typedef int (*testit)(const void*, const void*); 34 | 35 | -------------------------------------------------------------------------------- /include/mesh.h: -------------------------------------------------------------------------------- 1 | // 2 | // mesh.h 3 | // 4 | // 5 | // Created by James Adler, Xiaozhe Hi, and Ludmil Zikatanov 2015-01-09. 6 | // 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef _mesh_h 14 | #define _mesh_h 15 | 16 | #include "sparse.h" 17 | #include "vec.h" 18 | 19 | /** 20 | * \struct coords 21 | * \brief Returns coordinates of nodes 22 | */ 23 | typedef struct coords{ 24 | 25 | //! coordinate values (ordered x(0) y(0) z(0) x(1) y(1) z(1) etc...)) 26 | REAL* x; 27 | 28 | //! Size of arrays (number of nodes) 29 | INT n; 30 | 31 | //! dimension 32 | INT dim; 33 | 34 | } coords; 35 | 36 | /** 37 | * \struct coordinates 38 | * \brief Returns coordinates of nodes 39 | */ 40 | typedef struct coordinates{ 41 | 42 | //! x values 43 | REAL* x; 44 | 45 | //! y values 46 | REAL* y; 47 | 48 | //! z values (if in 3D) 49 | REAL* z; 50 | 51 | //! Size of arrays (number of nodes) 52 | INT n; 53 | 54 | } coordinates; 55 | 56 | 57 | /** 58 | * \struct mesh_struct 59 | * \brief Builds a triangular/tetrahedral mesh, including all its 60 | * properties and mappings between vertices, edges, and faces 61 | */ 62 | typedef struct mesh_struct{ 63 | 64 | //! dimension 65 | INT dim; 66 | 67 | //! Number of elements 68 | INT nelm; 69 | 70 | //! number of vertices 71 | INT nv; 72 | 73 | //! number of vertices per element 74 | INT v_per_elm; 75 | 76 | //! number of edges 77 | INT nedge; 78 | 79 | //! number of edges per element 80 | INT ed_per_elm; 81 | 82 | //! number of faces (in 2D faces=edges) 83 | INT nface; 84 | 85 | //! number of faces per element 86 | INT f_per_elm; 87 | 88 | //! Number of connected regions in domain - usually 1 89 | INT nconn_reg; 90 | 91 | //! Number of connected boundaries - usually 1 92 | INT nconn_bdry; 93 | 94 | //! Array indicating which vertices are on which component 95 | INT* v_component; 96 | 97 | //! coordinates of vertices 98 | coordinates* cv; 99 | 100 | //! number of vertices on boundary 101 | INT nbv; 102 | 103 | //! number of edges on boundary 104 | INT nbedge; 105 | 106 | //! number of faces on boundary 107 | INT nbface; 108 | 109 | //! element to vertex map (CSR Format) 110 | iCSRmat* el_v; 111 | 112 | //! element to edge map (CSR Format) 113 | iCSRmat* el_ed; 114 | 115 | //! element to face map (CSR Format) 116 | iCSRmat* el_f; 117 | 118 | //! edge to vertex map (CSR Format) 119 | iCSRmat* ed_v; 120 | 121 | //! face to vertex map (CSR Format) 122 | iCSRmat* f_v; 123 | 124 | //! face to edge map (CSR Format) 125 | iCSRmat* f_ed; 126 | 127 | //! element volumes (areas in 2D) 128 | REAL* el_vol; 129 | 130 | //! barycenter of element 131 | REAL* el_mid; 132 | 133 | //! edge lengths 134 | REAL* ed_len; 135 | 136 | //! tangent vectors on edges 137 | REAL* ed_tau; 138 | 139 | //! midpoint of edges 140 | REAL* ed_mid; 141 | 142 | //! area of faces 143 | REAL* f_area; 144 | 145 | //! normal vector on face 146 | REAL* f_norm; 147 | 148 | //! midpoint of face 149 | REAL* f_mid; 150 | 151 | //! indicates a flag for vertex such as whether a vertex is on boundary 152 | INT* v_flag; 153 | 154 | //! indicates a flag for edge such as whether an edge is on boundary 155 | INT* ed_flag; 156 | 157 | //! indicates a flag for face such as whether a face is on boundary 158 | INT* f_flag; 159 | 160 | //! indicates a flag for element such as in what domain the element is. 161 | INT* el_flag; 162 | 163 | //! extra double working array for random things 164 | REAL* dwork; 165 | 166 | //! extra int working array for random things 167 | INT* iwork; 168 | 169 | } mesh_struct; 170 | 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /include/nonlinear.h: -------------------------------------------------------------------------------- 1 | // 2 | // nonlinear.h 3 | // 4 | // 5 | // Created by Adler, James on 10/18/16. 6 | // 7 | // Contains Structs for nonlinear iterations 8 | // For now just assumes Newton, and FAS in the works 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #ifndef _nonlinear_h 16 | #define _nonlinear_h 17 | 18 | /** 19 | * \struct newton 20 | * \brief Returns data for Newton Stepping 21 | */ 22 | typedef struct newton{ 23 | 24 | //! Indicate if matrices are in block form 1=yes 0=no 25 | INT isblock; 26 | 27 | //! Max number of Newton Steps 28 | INT max_steps; 29 | 30 | //! Current Newton step 31 | INT current_step; 32 | 33 | //! Tolerance Type: 0 - ||nonlinear residual|| 10 | #include 11 | #include 12 | 13 | #ifndef _vec_h 14 | #define _vec_h 15 | 16 | /** 17 | * \struct dvector 18 | * \brief Vector with n entries of REAL type 19 | */ 20 | typedef struct dvector{ 21 | 22 | //! number of rows 23 | INT row; 24 | 25 | //! actual vector entries 26 | REAL *val; 27 | 28 | } dvector; /**< Vector of REAL type */ 29 | 30 | /** 31 | * \struct ivector 32 | * \brief Vector with n entries of INT type 33 | */ 34 | typedef struct ivector{ 35 | 36 | //! number of rows 37 | INT row; 38 | 39 | //! actual vector entries 40 | INT *val; 41 | 42 | } ivector; /**< Vector of INT type */ 43 | 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/amr/marking.c: -------------------------------------------------------------------------------- 1 | /*! \file src/amr/marking.c 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov on 20240430. 4 | * Copyright 2017__HAZMATH__. All rights reserved. 5 | * 6 | * \note contains functions for marking strategies used in AMR. 7 | * 8 | */ 9 | #include "hazmath.h" 10 | 11 | /*! 12 | * \fn ivector amar_maximal_mark(scomplex *sc,dvector *estimator, REAL gamma) 13 | * 14 | * \brief mark elements for adaptive refinement using maximal marking strategy 15 | * mark all elements with error estimator greater than gamma*max(estimator) 16 | * 17 | * \param sc Pointer to the simplicial complex 18 | * \param estimator Pointer to error estimator 19 | * \param gamma Fraction of max error estimator to mark (eg. 0 -> mark all, 1 -> mark none) 20 | * 21 | * \return marked ivector of elements to be marked, TRUE for marked 22 | * 23 | */ 24 | ivector amr_maximal_mark(scomplex *sc, REAL *estimator, REAL gamma) 25 | { 26 | 27 | INT i,k=0; 28 | INT ns = sc->ns; 29 | REAL errmax; 30 | ivector marked=ivec_create(sc->ns); 31 | errmax=estimator[0]; 32 | for(i=1;ierrmax) { 34 | errmax=estimator[i]; 35 | } 36 | } 37 | for(i=0;igamma*errmax){ 39 | marked.val[i]=TRUE; 40 | k++; 41 | } else { 42 | marked.val[i]=FALSE; 43 | } 44 | } 45 | 46 | printf("\nMarking elements for AMR using Maximal Mark strategy.\n\tMarking elements with %3.2f%% of the max error: --> %d of %d elements were marked to be refined.\n",gamma*100,k,ns); 47 | return marked; 48 | } 49 | -------------------------------------------------------------------------------- /src/amr/mesh_cube_anydim.c: -------------------------------------------------------------------------------- 1 | /*! \file examples/elliptic_p1/mesh_cube_init.c 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov on 20190420. 4 | * Copyright 2019__HAZMATH__. All rights reserved. 5 | * 6 | * \note meshes the unit cube in R(d), d=2,3,4,5,.... 7 | * 8 | * \note: modified by ltz on 20210601 9 | * 10 | */ 11 | /**********************************************************************/ 12 | #include "hazmath.h" 13 | /**********************************************************************/ 14 | /*! 15 | * \fn scomplex **mesh_cube_init(const INT dim, const INT ref_type) 16 | * 17 | * \brief creates initial meshes for the cube in 2,3,4,5 dimensions. 18 | * 19 | * \param dim: the spatial dimension \param ref_type: the refinement 20 | * type: if >10, then uniform refinement; if <10, then 21 | * newest vertex bisection. Check include/amr.h scomplex 22 | * structure for more info. 23 | * 24 | * \return the simplicial complex with the initial mesh. 25 | * 26 | * \note 27 | * 28 | */ 29 | /****************************************************************/ 30 | scomplex **mesh_cube_init(const INT dim, const INT ndiv, const INT ref_type) 31 | { 32 | INT i,j,in; 33 | scomplex **sc_all=NULL; 34 | cube2simp *c2s=cube2simplex(dim); 35 | input_grid *g=malloc(sizeof(input_grid)); 36 | // set up initial grid; 37 | g->title=strdup("Cube in n-d"); 38 | g->fgrid=strdup("mesh.haz"); 39 | g->fvtu=strdup("mesh.vtu"); 40 | // 41 | g->ncsys=1; 42 | g->dim=c2s->n; 43 | INT nvface=c2s->nvface,nvcube=c2s->nvcube; 44 | g->nf=c2s->nf; 45 | g->nv=c2s->nvcube; 46 | g->ne=c2s->ne; 47 | g->nel=1; 48 | // 49 | g->ox=(REAL *)calloc(g->dim*abs(g->ncsys),sizeof(REAL)); 50 | g->systypes=(INT *)calloc(g->ncsys,sizeof(INT)); 51 | g->syslabels=(INT *)calloc(g->ncsys,sizeof(INT)); 52 | g->csysv=(INT *)calloc(g->nv,sizeof(INT)); 53 | g->labelsv=(INT *)calloc(g->nv,sizeof(INT)); 54 | g->bcodesv=(INT *)calloc(g->nv,sizeof(INT)); 55 | // init these as 0 (they are not needed in this example). 56 | memset(g->systypes,0,g->ncsys*sizeof(INT)); 57 | memset(g->syslabels,0,g->ncsys*sizeof(INT)); 58 | memset(g->csysv,0,g->nv*sizeof(INT)); 59 | memset(g->labelsv,0,g->nv*sizeof(INT)); 60 | memset(g->bcodesv,0,g->nv*sizeof(INT)); 61 | //nodes 62 | g->mnodes=(INT *)calloc(g->nel*(nvcube+1),sizeof(INT)); 63 | for(i=0;imnodes[i]=i; 65 | } 66 | g->mnodes[nvcube]=1; 67 | // faces 68 | g->mfaces=(INT *)calloc(abs(g->nf)*(nvface+1),sizeof(INT)); 69 | for(i=0;inf;++i){ 70 | memcpy((g->mfaces+i*(nvface+1)),(c2s->faces+i*nvface),c2s->nvface*sizeof(INT)); 71 | g->mfaces[nvface+i*(nvface+1)]=1; 72 | } 73 | // vertex coords: 74 | g->xv=(REAL *)calloc(g->dim*g->nv,sizeof(REAL)); 75 | for(i=0;inv;++i){ 76 | in=i*g->dim; 77 | for(j=0;jdim;j++){ 78 | g->xv[in+j]=(REAL )c2s->bits[in+j]; 79 | } 80 | } 81 | // edges 82 | g->seg=(INT *)calloc(3*g->ne,sizeof(INT)); 83 | g->xe=(REAL *)calloc(g->dim*g->ne,sizeof(REAL)); 84 | INT j1,j2; 85 | for(i=0;ine;++i){ 86 | j1=c2s->edges[2*i]; 87 | j2=c2s->edges[2*i+1]; 88 | g->seg[3*i] = j1; 89 | g->seg[3*i+1] = j2; 90 | g->seg[3*i+2] = ndiv; 91 | for(j=0;jxe[j+i*dim]=0.5*(g->xv[j+j1*dim]+g->xv[j+j2*dim]); 93 | } 94 | cube2simp_free(c2s); 95 | if(g->dim > 3) 96 | g->ref_type=0; 97 | else 98 | g->ref_type=-2; 99 | g->nref=0; /* number of refinements (AMR)*/ 100 | g->mark_type=0; /* AMR marking type (0)uniform; nonzero: user defined.. */ 101 | g->err_stop=1e-20; /* stop tolerance for AMR */ 102 | g->num_refine_points=0; 103 | g->print_level=0; 104 | g->data_refine_points=NULL; 105 | if(g->print_level>15) input_grid_print(g); 106 | sc_all=generate_initial_grid(g); 107 | input_grid_free(g); 108 | ////////////////////////////////////////////////////// 109 | if(sc_all[0]->n > 3) 110 | sc_all[0]->ref_type=0; 111 | else 112 | sc_all[0]->ref_type=ref_type; 113 | ////////////////////////////////////////////////////// 114 | // if(dim <4) vtkw(g->fvtu,sc,0,1.); 115 | // haz_scomplex_print(sc_all[0],0,"XXX"); fflush(stdout); 116 | return sc_all; 117 | } 118 | -------------------------------------------------------------------------------- /src/assemble/.gitignore: -------------------------------------------------------------------------------- 1 | ignore -------------------------------------------------------------------------------- /src/fem/.gitignore: -------------------------------------------------------------------------------- 1 | ignore -------------------------------------------------------------------------------- /src/mesh/.gitignore: -------------------------------------------------------------------------------- 1 | ignore -------------------------------------------------------------------------------- /src/solver/.gitignore: -------------------------------------------------------------------------------- 1 | ignore -------------------------------------------------------------------------------- /src/utilities/.gitignore: -------------------------------------------------------------------------------- 1 | ignore -------------------------------------------------------------------------------- /src/utilities/graph_utils.c: -------------------------------------------------------------------------------- 1 | /*! \file src/utilities/graph_utils.c 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov on 5/13/17. 4 | * Copyright 2017__HAZMATH__. All rights reserved. 5 | * 6 | * \note: done cleanup for releasing -- Xiaozhe Hu 08/28/2021 7 | */ 8 | /********************************************************************/ 9 | #include "hazmath.h" 10 | 11 | /*****************************************************************************************/ 12 | /*! 13 | * \fn stack* stack_init(INT num_items) 14 | * 15 | * \brief function to create a stack of given num_items. It initializes size of stack as 0 16 | * 17 | * \param num_items Number of items 18 | * 19 | * \return s Pointer to the stack 20 | * 21 | */ 22 | stack* stack_init(INT num_items) 23 | { 24 | stack *s = (stack *)malloc(sizeof(stack)); 25 | s->num_items = num_items; 26 | s->top = -1; 27 | s->null_item=INT_MIN; 28 | s->items = (INT*)malloc(s->num_items * sizeof(INT)); 29 | return s; 30 | } 31 | 32 | /*****************************************************************************************/ 33 | /*! 34 | * \fn void push_in(stack* s, INT item) 35 | * 36 | * \brief Function to push an item to stack. It increases top by 1 37 | * 38 | * \param s Pointer to the stack (OUTPUT) 39 | * \param item Item 40 | * 41 | */ 42 | void push_in(stack* s, INT item) 43 | { 44 | // push ellement in the stack 45 | if (s->top >= (s->num_items - 1)) { 46 | fprintf(stderr,"cannot push furter item in stack: max items reached"); 47 | exit(5); 48 | } 49 | s->top++; 50 | s->items[s->top] = item; 51 | // printf("%d pushed to stack\n", item); 52 | return; 53 | } 54 | 55 | /*****************************************************************************************/ 56 | /*! 57 | * \fn void push_in(stack* s) 58 | * 59 | * \brief Function to remove an item from stack. It decreases top by 1 60 | * 61 | * \param s Pointer to the stack (OUTPUT) 62 | * 63 | */ 64 | INT pop_out(stack* s) 65 | { 66 | if (s->top==-1) 67 | return s->null_item; 68 | INT top_el=s->items[s->top]; 69 | s->top--; 70 | return top_el; 71 | } 72 | 73 | /*****************************************************************************************/ 74 | /*! 75 | * \fn void push_in(stack* s) 76 | * 77 | * \brief Function to return the top from stack without removing it 78 | * 79 | * \param s Pointer to the stack (OUTPUT) 80 | * 81 | */ 82 | INT get_top(stack *s) 83 | { 84 | if (s->top==-1) return s->null_item; 85 | return s->items[s->top]; 86 | } 87 | 88 | /*****************************************************************************************/ 89 | /*! 90 | * \fn static void topo_recurrsive(INT v, INT *ia, INT *ja, SHORT *mask,stack *s) 91 | * 92 | * \brief A recursive function used by topo_sort 93 | * 94 | * \param v 95 | * \param ia Pointer to the integer array 96 | * \param ja Pointer to the integer array 97 | * \param mask 98 | * \param s Pointer to the stack 99 | * 100 | */ 101 | static void topo_recurrsive(INT v, INT *ia, INT *ja, SHORT *mask,stack *s) 102 | { 103 | INT i,vrow; 104 | // Mark the current node as visited. 105 | mask[v] = (SHORT )1; 106 | for (vrow=ia[v];vrowrow); 127 | // Mark all the vertices as not visited 128 | SHORT *mask = (SHORT *)calloc(a->row,sizeof(SHORT)); 129 | for (i=0;irow;++i) mask[i]=(SHORT )0; 130 | for (i=0;irow;++i) 131 | if (!mask[i]) 132 | topo_recurrsive(i, a->IA,a->JA,mask, s); 133 | // trace the contents of stack 134 | /* while (s->top != -1) { */ 135 | /* item=pop_out(s); */ 136 | /* //we can print it if we want fprintf(stdout,"%d ",item); */ 137 | /* } */ 138 | return; 139 | } 140 | -------------------------------------------------------------------------------- /src/utilities/string_utils.c: -------------------------------------------------------------------------------- 1 | /*! \file src/utilities/string_utils.c 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov on 5/13/17. 4 | * Copyright 2017__HAZMATH__. All rights reserved. 5 | * 6 | * \note: 20230321 7 | */ 8 | /********************************************************************/ 9 | #include "hazmath.h" 10 | 11 | /*****************************************************************************************/ 12 | /*! 13 | * \fn void print_ascii(const char *s) 14 | * 15 | * \brief function to print the ascii codes separated by | of the chars in a string s. 16 | * 17 | * \param *s the string; 18 | */ 19 | void print_ascii(const char *s) 20 | { 21 | size_t l=strlen(s)+1; 22 | const char *s_end=s+l; 23 | fprintf(stdout,"\nl=%ld\n|",l); 24 | for(; s < s_end ;++s) 25 | fprintf(stdout,"%03d|",*s); 26 | fprintf(stdout,"\n"); 27 | return; 28 | } 29 | /*****************************************************************************************/ 30 | /*! 31 | * \fn void trim_str(char **str, INT nstrings) 32 | * 33 | * \brief function to trim all space-like chars from the beginning and the end of a strings. Input is an array of strings and the number of strings. 34 | * The new string is realloc-ed and stored at str[k], k=0:nstrings-1 35 | * 36 | * \param **str pointer to the input/output array of strings. 37 | */ 38 | void trim_str(char **str, INT nstrings) 39 | { 40 | const char *back,*front; 41 | size_t size_s,l0; 42 | INT k; 43 | for(k=0;k front) && isspace((unsigned char)*back)) { 58 | back--; 59 | } 60 | back++; // ad one more at the end 61 | // Set size of the trimmed string: 62 | size_t j,l1=l0-1,n_s=(size_t )(back-front); 63 | if(n_s < l1){ 64 | size_s = n_s; 65 | // Copy the string at the beginning, realloc and add '\0'. 66 | for(j=0;j0){ 98 | j=0; 99 | while(j<(l0-1)){ 100 | if(*(s0+j)=='\r' && *(s0+j+1)=='\n'){ 101 | j+=2; 102 | *s='\n'; 103 | s++; 104 | } else { 105 | *s=*(s0+j); 106 | j++; 107 | s++; 108 | } 109 | } 110 | size_s=s-str[k]; 111 | str[k]=realloc(str[k],(size_s+1)*sizeof(char)); 112 | *(str[k]+size_s)='\0'; 113 | s=str[k]; 114 | while(*s!='\0'){ 115 | if(*s=='\r') *s='\n'; 116 | s++; 117 | } 118 | } 119 | } 120 | return; 121 | } 122 | -------------------------------------------------------------------------------- /src/utilities/timing.c: -------------------------------------------------------------------------------- 1 | /*! \file src/utilities/timing.c 2 | * 3 | * Created by James Adler, Xiaozhe Hu, and Ludmil Zikatanov on 10/06/15. 4 | * Copyright 2015__HAZMATH__. All rights reserved. 5 | * 6 | * \note: modified by Xiaozhe Hu on 10/27/2016 7 | * \note: done cleanup for releasing -- Xiaozhe Hu 10/27/2016 & 08/28/2021 8 | */ 9 | 10 | #include "hazmath.h" 11 | 12 | /*************************************************************************************/ 13 | /*! 14 | * \fn get_time (REAL *time) 15 | * 16 | * \brief Get system time 17 | * 18 | * \author Xiaozhe Hu 19 | * \date 10/06/2015 20 | * 21 | */ 22 | void get_time (REAL *time) 23 | { 24 | if ( time != NULL ) { 25 | *time = (REAL) clock() / CLOCKS_PER_SEC; 26 | } 27 | } 28 | 29 | /******************************* END **************************************************/ 30 | --------------------------------------------------------------------------------