From d1c8c32d5f7ed10a08c54e75a232687b0d3cc32f Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Sat, 28 Oct 2017 18:22:38 +0200 Subject: [PATCH] Port to jbuilder --- .gitignore | 32 +- INSTALL.txt | 62 -- Makefile | 58 +- _oasis | 140 ---- _tags | 5 - config/discover.ml | 26 + config/jbuild | 11 + {src => config}/make_FC_code.ml | 20 +- display/jbuild | 26 + {src => display}/mesh_display.ml | 0 {src => display}/mesh_display.mli | 0 {src => display}/mesh_displayFC.ml | 2 +- {src => easymesh}/easymesh.ml | 0 {src => easymesh}/easymesh.mli | 0 {src => easymesh}/easymeshFC.ml | 0 easymesh/jbuild | 25 + mesh-display.descr | 1 + mesh-display.opam | 20 + mesh-easymesh.descr | 7 + mesh-easymesh.opam | 22 + mesh-triangle.descr | 8 + mesh-triangle.opam | 24 + opam/descr => mesh.descr | 2 +- mesh.opam | 21 + myocamlbuild.ml | 938 ++++++++++++++++++++++ opam/findlib | 1 - opam/opam | 38 - setup.ml | 60 -- src/jbuild | 15 + tests/jbuild | 19 + triangle/jbuild | 45 ++ {src => triangle}/mesh_triangle.ml | 0 {src => triangle}/mesh_triangle.mli | 0 {src => triangle}/mesh_triangleFC.ml | 27 +- {src => triangle}/mesh_triangle_common.ml | 0 {src => triangle}/triangle_stubs.c | 4 +- {src => triangle}/triangulate_stub.c | 0 37 files changed, 1248 insertions(+), 411 deletions(-) delete mode 100644 INSTALL.txt delete mode 100644 _oasis delete mode 100644 _tags create mode 100644 config/discover.ml create mode 100644 config/jbuild rename {src => config}/make_FC_code.ml (91%) create mode 100644 display/jbuild rename {src => display}/mesh_display.ml (100%) rename {src => display}/mesh_display.mli (100%) rename {src => display}/mesh_displayFC.ml (99%) rename {src => easymesh}/easymesh.ml (100%) rename {src => easymesh}/easymesh.mli (100%) rename {src => easymesh}/easymeshFC.ml (100%) create mode 100644 easymesh/jbuild create mode 100644 mesh-display.descr create mode 100644 mesh-display.opam create mode 100644 mesh-easymesh.descr create mode 100644 mesh-easymesh.opam create mode 100644 mesh-triangle.descr create mode 100644 mesh-triangle.opam rename opam/descr => mesh.descr (85%) create mode 100644 mesh.opam delete mode 100644 opam/findlib delete mode 100644 opam/opam delete mode 100644 setup.ml create mode 100644 src/jbuild create mode 100644 tests/jbuild create mode 100644 triangle/jbuild rename {src => triangle}/mesh_triangle.ml (100%) rename {src => triangle}/mesh_triangle.mli (100%) rename {src => triangle}/mesh_triangleFC.ml (93%) rename {src => triangle}/mesh_triangle_common.ml (100%) rename {src => triangle}/triangle_stubs.c (99%) rename {src => triangle}/triangulate_stub.c (100%) diff --git a/.gitignore b/.gitignore index e64378b..bce73fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,7 @@ # OCaml -*-conf-unix-*- -*.annot -*.cm[ioax] -*.cmxa -*.exe -*.com -*.byte -*.native -doc -.depend.ocaml -._d/ -src/triangle -src/triangle.zip +.merlin +*.install +triangle/triangle src/levels.tex src/testmesh*.tex _build @@ -21,26 +12,9 @@ RE:.*\.ba[0-9] *.log *.pdf auto/ -# Test executables -tests/square # Generated files (unmodified) AUTHORS.txt INSTALL.txt README.txt -setup.data -*.clib -*.mllib -src/META -configure -API.docdir -API.odocl -src/easymeshC.ml -src/easymeshF.ml -src/mesh_displayC.ml -src/mesh_displayF.ml -src/mesh_triangleC.ml -src/mesh_triangleF.ml -src/meshC.ml -src/meshF.ml # Tarball *.tar.gz \ No newline at end of file diff --git a/INSTALL.txt b/INSTALL.txt deleted file mode 100644 index 3828f42..0000000 --- a/INSTALL.txt +++ /dev/null @@ -1,62 +0,0 @@ -(* OASIS_START *) -(* DO NOT EDIT (digest: dbe611742ab8a145fa4ab325b3d4b806) *) -This is the INSTALL file for the mesh distribution. - -This package uses OASIS to generate its build system. See section OASIS for -full information. - -Dependencies -============ - -In order to compile this package, you will need: -* ocaml for all, doc API -* findlib -* lacaml for executable square_easymesh, executable square_triangle - -Installing -========== - -1. Uncompress the source archive and go to the root of the package -2. Run 'ocaml setup.ml -configure' -3. Run 'ocaml setup.ml -build' -4. Run 'ocaml setup.ml -install' - -Uninstalling -============ - -1. Go to the root of the package -2. Run 'ocaml setup.ml -uninstall' - -OASIS -===== - -OASIS is a program that generates a setup.ml file using a simple '_oasis' -configuration file. The generated setup only depends on the standard OCaml -installation: no additional library is required. - -(* OASIS_STOP *) - -Triangle (dependency) -===================== - -The module Mesh_triangle uses the -[Triangle](http://www.cs.cmu.edu/~quake/triangle.html) library which -was awarded the James Hardy Wilkinson Prize in Numerical Software in -2003. The command - - make configure - -will attempt to detect whether the library is installed, either -globally on the system (this is the case if "libtriangle-dev" is -installed on Debian) or in src/triangle. It it is not and you have -"wget" and "unzip", it will download Triangle and unpack it in -src/triangle. Otherwise, you will have to download Triangle from the -above web site and unzip it in src/triangle. - -Development Version -=================== - -If you downloaded the sources from the development repository, you -need to have [oasis](http://oasis.forge.ocamlcore.org/index.php) -to create 'setup.ml' using 'oasis setup'. Then follow the -instructions of the "Triangle" and "Installing" sections. diff --git a/Makefile b/Makefile index f0d26e0..2bfdef0 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,16 @@ -WEB = mesh.forge.ocamlcore.org:/home/groups/mesh/htdocs/ TRIANGLE_URL = http://www.netlib.org/voronoi/triangle.zip -PKG_VERSION = $(shell oasis query version) -DIR = $(shell oasis query name)-$(PKG_VERSION) -TARBALL = $(DIR).tar.gz +all byte native: + jbuilder build @install #--dev + +clean: + jbuilder clean + +doc: + jbuilder build --dev @doc -DISTFILES = AUTHORS.txt INSTALL.txt README.txt \ - Makefile myocamlbuild.ml _oasis _tags \ - $(wildcard $(addprefix src/, *.ml *.mli *.clib *.mllib *.c triangle/)) \ - $(wildcard tests/*.ml) -.PHONY: configure all byte native doc upload-doc install uninstall reinstall -all byte native: setup.data - ocaml setup.ml -build -BYTES_DIR = $(shell ocamlfind query bytes) -BYTES_CMA = $(wildcard $(BYTES_DIR)/bytes.cma) -BYTES_INC = $(if $(BYTES_CMA), -I $(BYTES_DIR) $(BYTES_CMA)) GENERATE_ML_FILES = ocaml $(BYTES_INC) src/make_FC_code.ml \ --pkg-version $(PKG_VERSION) @@ -47,41 +41,7 @@ configure: setup.ml opam/opam exit 2; \ fi -setup.ml: _oasis - $(GENERATE_ML_FILES) - oasis setup -setup-update dynamic - -doc install uninstall reinstall: all - ocaml setup.ml -$@ - -opam/opam: _oasis - oasis2opam --local -y - upload-doc: doc scp -C -p -r _build/API.docdir $(WEB) -.PHONY: dist tar -dist tar: setup.ml - mkdir -p $(DIR) - for f in $(DISTFILES); do \ - cp --parents $$f $(DIR); \ - done -# Generate a setup.ml independent of oasis: - cd $(DIR); $(GENERATE_ML_FILES) && oasis setup -# Download the C lib triangle, so OPAM complilation is smooth: - mkdir -p $(DIR)/src/triangle; - cd $(DIR)/src/triangle && wget $(TRIANGLE_URL) \ - && unzip triangle.zip && rm triangle.zip - tar -zcvf $(TARBALL) $(DIR) - $(RM) -r $(DIR) - -.PHONY: clean distclean -clean: - ocaml setup.ml -clean - $(GENERATE_ML_FILES) --clean - $(RM) $(TARBALL) - -distclean: - ocaml setup.ml -distclean - $(RM) $(wildcard src/*.clib src/*.mllib) - $(RM) $(wildcard *.ba[0-9] *.bak *~ *.odocl) +.PHONY: all byte native doc clean distclean diff --git a/_oasis b/_oasis deleted file mode 100644 index fa2cf40..0000000 --- a/_oasis +++ /dev/null @@ -1,140 +0,0 @@ -# -*-conf-*- -OASISFormat: 0.4 -Name: mesh -Version: 0.8.8 -Synopsis: Triangular mesh generation and manipulation. -Description: This is an interface to various mesh generators, - in particular triangle. It also provides functions to optimize the - numbering of mesh points and to export meshes and piecewise linear - functions defined on them to TikZ, Scilab, Matlab, and Mathematica - formats. -Authors: Christophe Troestler -Maintainers: Christophe Troestler -License: LGPL-2.0 with OCaml linking exception -Plugins: StdFiles (0.4), META (0.4) -Homepage: https://github.com/Chris00/mesh -#BugReports: https://github.com/Chris00/mesh/issues - -Flag libtriangle - Description: Enable if you build on a system with libtriangle - Default: false - -Flag has_graphics - Description: Enable if the module Graphics is present - Default: false - -Flag lacaml - Description: Enable if the package lacaml is installed. - Default: false - -Library mesh - Path: src/ - BuildTools: ocamlbuild - Modules: Mesh, Easymesh - InternalModules: Mesh_utils, Mesh_common, MeshF, MeshC, EasymeshF, EasymeshC - BuildDepends: bigarray, bytes - -Library mesh_display - Build$: flag(has_graphics) - Path: src/ - BuildTools: ocamlbuild - Modules: Mesh_display - InternalModules: Mesh_displayF, Mesh_displayC - BuildDepends: mesh,graphics - FindlibName: display - FindlibParent: mesh - XMETADescription: Display of meshes using OCaml Graphics module. - -Library mesh_triangle - Path: src/ - BuildTools: ocamlbuild - Modules: Mesh_triangle - InternalModules: Mesh_triangle_common, Mesh_triangleF, Mesh_triangleC - CSources: triangle_stubs.c - if flag(libtriangle) - CCOpt: -DTRILIBRARY -DEXTERNAL_TEST -DLIBTRIANGLE - CCLib: -ltriangle - else - CCOpt: -DTRILIBRARY -DEXTERNAL_TEST - BuildDepends: mesh - FindlibName: triangle - FindlibParent: mesh - XMETADescription: Binding to the triangle mesh generator. - -Document API - Title: API reference for Mesh - Type: OCamlbuild (0.4) - InstallDir: $docdir/api - BuildTools: ocamldoc, ocamlbuild - XOCamlbuildPath: . - XOCamlbuildLibraries: mesh, mesh.triangle, mesh.display - -# Tests: -Executable square_easymesh - Build$: flag(tests) && flag(lacaml) && flag(has_graphics) - Path: tests/ - MainIs: square_easymesh.ml - BuildTools: ocamlbuild - BuildDepends: mesh.display,lacaml,graphics - CompiledObject: best - Install: false - -Executable square_triangle - Build$: flag(tests) && flag(lacaml) - Path: tests/ - MainIs: square_triangle.ml - BuildTools: ocamlbuild - BuildDepends: mesh.triangle,lacaml,graphics - CompiledObject: best - Install: false - -Executable level_display - Build$: flag(tests) - Path: tests/ - MainIs: level_display.ml - BuildTools: ocamlbuild - BuildDepends: mesh.triangle,graphics - CompiledObject: best - Install: false - -Executable refine - Build$: flag(tests) - Path: tests - MainIs: refine.ml - BuildTools: ocamlbuild - BuildDepends: mesh.triangle,graphics - CompiledObject: best - Install: false - -Executable attributes - Build$: flag(tests) - Path: tests - MainIs: attributes.ml - BuildTools: ocamlbuild - BuildDepends: mesh.triangle,graphics - CompiledObject: best - Install: false - -Executable export - Build$: flag(tests) - Path: tests - MainIs: export.ml - BuildTools: ocamlbuild - BuildDepends: mesh,mesh.triangle - CompiledObject: best - Install: false - -Executable degenerate_pslg - Build$: flag(tests) - Path: tests - MainIs: degenerate_pslg.ml - BuildTools: ocamlbuild - BuildDepends: mesh, mesh.triangle - CompiledObject: best - Install: false - - -SourceRepository trunk - Type: git - Location: https://github.com/Chris00/mesh.git - Browser: https://github.com/Chris00/mesh diff --git a/_tags b/_tags deleted file mode 100644 index 639bbe3..0000000 --- a/_tags +++ /dev/null @@ -1,5 +0,0 @@ -# OASIS_START -# OASIS_STOP - -<**/*.ml>: annot, safe_string - diff --git a/config/discover.ml b/config/discover.ml new file mode 100644 index 0000000..538adb4 --- /dev/null +++ b/config/discover.ml @@ -0,0 +1,26 @@ +open Base +open Stdio + +let configure t = + let module C = Configurator in + let system_libtriangle = + (* Test the presence of the header file. *) + C.c_test t ~link_flags:["-ltriangle"] + "#include + int main() { + return 0; + }" in + let ccopt, cclib = + if system_libtriangle then + (* System with libtriangle *) + ["-DTRILIBRARY"; "-DEXTERNAL_TEST"; "-DLIBTRIANGLE"], + ["-ltriangle"] + else + ["-DTRILIBRARY"; "-DEXTERNAL_TEST"], [] in + let write_sexp file sexp = + Out_channel.write_all file ~data:(Sexp.to_string sexp) in + write_sexp "c_flags.sexp" (sexp_of_list sexp_of_string ccopt); + write_sexp "c_library_flags.sexp" (sexp_of_list sexp_of_string cclib) + +let () = + Configurator.main "discover" configure diff --git a/config/jbuild b/config/jbuild new file mode 100644 index 0000000..407facf --- /dev/null +++ b/config/jbuild @@ -0,0 +1,11 @@ +(jbuild_version 1) + +(executable + ((name make_FC_code) + (modules (make_FC_code)) + (libraries (str)))) + +(executable + ((name discover) + (modules (Discover)) + (libraries (base stdio configurator)))) diff --git a/src/make_FC_code.ml b/config/make_FC_code.ml similarity index 91% rename from src/make_FC_code.ml rename to config/make_FC_code.ml index 1b5a0ec..04d84db 100644 --- a/src/make_FC_code.ml +++ b/config/make_FC_code.ml @@ -3,8 +3,6 @@ This script is supposed to be run before oasis. The tarballs must contain the already generated files. *) -#load "str.cma";; - let string_of_file fn = let buf = Buffer.create 4096 in let fh = open_in fn in @@ -26,9 +24,7 @@ let write_ro fn s = let include_re = Str.regexp "INCLUDE(\\([^()]+\\))" let rec tr_include s = - let inc s = - let fn = Filename.concat "src" (Str.matched_group 1 s) in - tr_include (string_of_file fn) in + let inc s = tr_include (string_of_file (Str.matched_group 1 s)) in Str.global_substitute include_re inc s let arg = @@ -110,10 +106,10 @@ let rm_gen fn_base = let filenames = (* Filename, module name *) - [ "src/mesh_triangle", "Mesh"; - "src/mesh", "Mesh"; - "src/mesh_display", "Mesh_display"; - "src/easymesh", "Easymesh"; + [ "mesh_triangle", "Mesh"; + "mesh", "Mesh"; + "mesh_display", "Mesh_display"; + "easymesh", "Easymesh"; ] let () = @@ -129,5 +125,7 @@ let () = if !clean then List.iter (fun (fn, _) -> rm_gen fn) filenames else - List.iter (fun (fn, mod_name) -> - gen_FC fn ~mod_name ~pkg_version:!pkg_version) filenames + List.iter (fun (fn_base, mod_name) -> + if Sys.file_exists (fn_base ^ "FC.ml") then + gen_FC fn_base ~mod_name ~pkg_version:!pkg_version + ) filenames diff --git a/display/jbuild b/display/jbuild new file mode 100644 index 0000000..eea311f --- /dev/null +++ b/display/jbuild @@ -0,0 +1,26 @@ +(jbuild_version 1) + +(library + ((name mesh_display) + (public_name mesh-display) + (synopsis "Triangular mesh representation using the graphics module") + (modules (Mesh_display + Mesh_displayF Mesh_displayC Mesh_common Mesh_utils)) + (flags (:standard -safe-string)) + (libraries (mesh graphics)))) + +(rule + ((targets (mesh_displayF.ml mesh_displayC.ml)) + (deps (../config/make_FC_code.exe + mesh_displayFC.ml ../src/mesh_level_curvesFC.ml)) + (action (run ../config/make_FC_code.exe)))) + +(rule + ((targets (mesh_common.ml)) + (deps (../src/mesh_common.ml)) + (action (copy# ${^} mesh_common.ml)))) + +(rule + ((targets (mesh_utils.ml)) + (deps (../src/mesh_utils.ml)) + (action (copy# ${^} mesh_utils.ml)))) diff --git a/src/mesh_display.ml b/display/mesh_display.ml similarity index 100% rename from src/mesh_display.ml rename to display/mesh_display.ml diff --git a/src/mesh_display.mli b/display/mesh_display.mli similarity index 100% rename from src/mesh_display.mli rename to display/mesh_display.mli diff --git a/src/mesh_displayFC.ml b/display/mesh_displayFC.ml similarity index 99% rename from src/mesh_displayFC.ml rename to display/mesh_displayFC.ml index 17fc0b5..7c64518 100644 --- a/src/mesh_displayFC.ml +++ b/display/mesh_displayFC.ml @@ -156,7 +156,7 @@ let fill_quadrilateral s color {x=x0; y=y0} {x=x1; y=y1} {x=x2; y=y2} (************************************************************************) (* Include peformed by make_FC_code.ml *) -INCLUDE(mesh_level_curvesFC.ml);; +INCLUDE(../src/mesh_level_curvesFC.ml);; (************************************************************************) let level_curves ~width ~height ?(boundary=(fun _ -> Some 0)) diff --git a/src/easymesh.ml b/easymesh/easymesh.ml similarity index 100% rename from src/easymesh.ml rename to easymesh/easymesh.ml diff --git a/src/easymesh.mli b/easymesh/easymesh.mli similarity index 100% rename from src/easymesh.mli rename to easymesh/easymesh.mli diff --git a/src/easymeshFC.ml b/easymesh/easymeshFC.ml similarity index 100% rename from src/easymeshFC.ml rename to easymesh/easymeshFC.ml diff --git a/easymesh/jbuild b/easymesh/jbuild new file mode 100644 index 0000000..371188c --- /dev/null +++ b/easymesh/jbuild @@ -0,0 +1,25 @@ +(jbuild_version 1) + +(library + ((name mesh_easymesh) + (public_name mesh-easymesh) + (synopsis "Triangular mesh generation with Easymesh") + (modules (Easymesh EasymeshF EasymeshC Mesh_common Mesh_utils)) + (flags (:standard -safe-string)) + (libraries (mesh bigarray bytes)))) + +(rule + ((targets (easymeshF.ml easymeshC.ml)) + (deps (../config/make_FC_code.exe + easymeshFC.ml)) + (action (run ../config/make_FC_code.exe)))) + +(rule + ((targets (mesh_common.ml)) + (deps (../src/mesh_common.ml)) + (action (copy# ${^} mesh_common.ml)))) + +(rule + ((targets (mesh_utils.ml)) + (deps (../src/mesh_utils.ml)) + (action (copy# ${^} mesh_utils.ml)))) diff --git a/mesh-display.descr b/mesh-display.descr new file mode 100644 index 0000000..fa5f0d4 --- /dev/null +++ b/mesh-display.descr @@ -0,0 +1 @@ +Triangular mesh representation using the graphics module diff --git a/mesh-display.opam b/mesh-display.opam new file mode 100644 index 0000000..7ec5e90 --- /dev/null +++ b/mesh-display.opam @@ -0,0 +1,20 @@ +opam-version: "1.2" +maintainer: "Christophe Troestler " +authors: [ "Christophe Troestler" ] +tags: [] +license: "LGPL-2.0 with OCaml linking exception" +homepage: "https://github.com/Chris00/mesh" +dev-repo: "https://github.com/Chris00/mesh.git" +bug-reports: "https://github.com/Chris00/mesh/issues" +#doc: "" +build: [ + [ "jbuilder" "subst" ] {pinned} + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [["jbuilder" "runtest" "-p" name "-j" jobs]] +depends: [ + "ocamlfind" {build & >= "1.5"} + "jbuilder" {build} + "mesh" {>= "0.9"} + "graphics" +] diff --git a/mesh-easymesh.descr b/mesh-easymesh.descr new file mode 100644 index 0000000..041bd49 --- /dev/null +++ b/mesh-easymesh.descr @@ -0,0 +1,7 @@ +Triangular mesh generation with EasyMesh + +[EasyMesh][] is a two-dimensional quality mesh generator developed by +Bojan Niceno and available from MIT. This module provides an +interface calling the program EasyMesh to perform the mesh generation. + +[EasyMesh]: http://web.mit.edu/easymesh_v1.4/www/easymesh.html diff --git a/mesh-easymesh.opam b/mesh-easymesh.opam new file mode 100644 index 0000000..2deeb2a --- /dev/null +++ b/mesh-easymesh.opam @@ -0,0 +1,22 @@ +opam-version: "1.2" +maintainer: "Christophe Troestler " +authors: [ "Christophe Troestler" ] +license: "LGPL-2.0 with OCaml linking exception" +homepage: "https://github.com/Chris00/mesh" +dev-repo: "https://github.com/Chris00/mesh.git" +bug-reports: "https://github.com/Chris00/mesh/issues" +#doc: "" +tags: [ "Mesh" "Triangulation" "PDE" ] +build: [ + [ "jbuilder" "subst" ] {pinned} + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [[ "jbuilder" "runtest" "-p" name "-j" jobs ]] +depends: [ + "ocamlfind" {build & >= "1.5"} + "jbuilder" {build & >="1.0+beta9"} + "base-bigarray" + "base-bytes" + "mesh" + "lacaml" {test} +] diff --git a/mesh-triangle.descr b/mesh-triangle.descr new file mode 100644 index 0000000..e1f6961 --- /dev/null +++ b/mesh-triangle.descr @@ -0,0 +1,8 @@ +Binding to the triangle mesh generator + +This module is a binding to the [Triangle][] library which was awarded +the James Hardy Wilkinson Prize in Numerical Software in 2003. If +libtriangle-dev is not installed on your system, it will install a +local copy for this library. + +[Triangle]: http://www.cs.cmu.edu/~quake/triangle.html diff --git a/mesh-triangle.opam b/mesh-triangle.opam new file mode 100644 index 0000000..ce3e42c --- /dev/null +++ b/mesh-triangle.opam @@ -0,0 +1,24 @@ +opam-version: "1.2" +maintainer: "Christophe Troestler " +authors: [ "Christophe Troestler" ] +license: "LGPL-2.0 with OCaml linking exception" +homepage: "https://github.com/Chris00/mesh" +dev-repo: "https://github.com/Chris00/mesh.git" +bug-reports: "https://github.com/Chris00/mesh/issues" +#doc: "" +tags: [ "clib:triangle" ] +build: [ + [ "jbuilder" "subst" ] {pinned} + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [[ "jbuilder" "runtest" "-p" name "-j" jobs ]] +depends: [ + "ocamlfind" {build & >= "1.5"} + "jbuilder" {build & >="1.0+beta9"} + "configurator" {build} + "base-bigarray" + "base-bytes" + "mesh" + "lacaml" {test} +] + diff --git a/opam/descr b/mesh.descr similarity index 85% rename from opam/descr rename to mesh.descr index dd1be15..7fb99a4 100644 --- a/opam/descr +++ b/mesh.descr @@ -1,4 +1,4 @@ -Triangular mesh generation and manipulation. +Triangular mesh generation and manipulation This is an interface to various mesh generators, in particular triangle. It also provides functions to optimize the numbering of mesh diff --git a/mesh.opam b/mesh.opam new file mode 100644 index 0000000..3b04188 --- /dev/null +++ b/mesh.opam @@ -0,0 +1,21 @@ +opam-version: "1.2" +maintainer: "Christophe Troestler " +authors: [ "Christophe Troestler" ] +license: "LGPL-2.0 with OCaml linking exception" +homepage: "https://github.com/Chris00/mesh" +dev-repo: "https://github.com/Chris00/mesh.git" +bug-reports: "https://github.com/Chris00/mesh/issues" +#doc: "" +tags: [ "Mesh" "Triangulation" "PDE" ] +build: [ + [ "jbuilder" "subst" ] {pinned} + [ "jbuilder" "build" "-p" name "-j" jobs ] +] +build-test: [[ "jbuilder" "runtest" "-p" name "-j" jobs ]] +depends: [ + "ocamlfind" {build & >= "1.5"} + "jbuilder" {build & >="1.0+beta9"} + "base-bigarray" + "base-bytes" + "lacaml" {test} +] diff --git a/myocamlbuild.ml b/myocamlbuild.ml index b410e3f..c86436e 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -1,4 +1,942 @@ (* OASIS_START *) +(* DO NOT EDIT (digest: 8f11ac339898fa84868c36ff217cfc88) *) +module OASISGettext = struct +(* # 22 "src/oasis/OASISGettext.ml" *) + + + let ns_ str = str + let s_ str = str + let f_ (str: ('a, 'b, 'c, 'd) format4) = str + + + let fn_ fmt1 fmt2 n = + if n = 1 then + fmt1^^"" + else + fmt2^^"" + + + let init = [] +end + +module OASISString = struct +(* # 22 "src/oasis/OASISString.ml" *) + + + (** Various string utilities. + + Mostly inspired by extlib and batteries ExtString and BatString libraries. + + @author Sylvain Le Gall + *) + + + let nsplitf str f = + if str = "" then + [] + else + let buf = Buffer.create 13 in + let lst = ref [] in + let push () = + lst := Buffer.contents buf :: !lst; + Buffer.clear buf + in + let str_len = String.length str in + for i = 0 to str_len - 1 do + if f str.[i] then + push () + else + Buffer.add_char buf str.[i] + done; + push (); + List.rev !lst + + + (** [nsplit c s] Split the string [s] at char [c]. It doesn't include the + separator. + *) + let nsplit str c = + nsplitf str ((=) c) + + + let find ~what ?(offset=0) str = + let what_idx = ref 0 in + let str_idx = ref offset in + while !str_idx < String.length str && + !what_idx < String.length what do + if str.[!str_idx] = what.[!what_idx] then + incr what_idx + else + what_idx := 0; + incr str_idx + done; + if !what_idx <> String.length what then + raise Not_found + else + !str_idx - !what_idx + + + let sub_start str len = + let str_len = String.length str in + if len >= str_len then + "" + else + String.sub str len (str_len - len) + + + let sub_end ?(offset=0) str len = + let str_len = String.length str in + if len >= str_len then + "" + else + String.sub str 0 (str_len - len) + + + let starts_with ~what ?(offset=0) str = + let what_idx = ref 0 in + let str_idx = ref offset in + let ok = ref true in + while !ok && + !str_idx < String.length str && + !what_idx < String.length what do + if str.[!str_idx] = what.[!what_idx] then + incr what_idx + else + ok := false; + incr str_idx + done; + if !what_idx = String.length what then + true + else + false + + + let strip_starts_with ~what str = + if starts_with ~what str then + sub_start str (String.length what) + else + raise Not_found + + + let ends_with ~what ?(offset=0) str = + let what_idx = ref ((String.length what) - 1) in + let str_idx = ref ((String.length str) - 1) in + let ok = ref true in + while !ok && + offset <= !str_idx && + 0 <= !what_idx do + if str.[!str_idx] = what.[!what_idx] then + decr what_idx + else + ok := false; + decr str_idx + done; + if !what_idx = -1 then + true + else + false + + + let strip_ends_with ~what str = + if ends_with ~what str then + sub_end str (String.length what) + else + raise Not_found + + + let replace_chars f s = + let buf = Buffer.create (String.length s) in + String.iter (fun c -> Buffer.add_char buf (f c)) s; + Buffer.contents buf + + let lowercase_ascii = + replace_chars + (fun c -> + if (c >= 'A' && c <= 'Z') then + Char.chr (Char.code c + 32) + else + c) + + let uncapitalize_ascii s = + if s <> "" then + (lowercase_ascii (String.sub s 0 1)) ^ (String.sub s 1 ((String.length s) - 1)) + else + s + + let uppercase_ascii = + replace_chars + (fun c -> + if (c >= 'a' && c <= 'z') then + Char.chr (Char.code c - 32) + else + c) + + let capitalize_ascii s = + if s <> "" then + (uppercase_ascii (String.sub s 0 1)) ^ (String.sub s 1 ((String.length s) - 1)) + else + s + +end + +module OASISUtils = struct +(* # 22 "src/oasis/OASISUtils.ml" *) + + + open OASISGettext + + + module MapExt = + struct + module type S = + sig + include Map.S + val add_list: 'a t -> (key * 'a) list -> 'a t + val of_list: (key * 'a) list -> 'a t + val to_list: 'a t -> (key * 'a) list + end + + module Make (Ord: Map.OrderedType) = + struct + include Map.Make(Ord) + + let rec add_list t = + function + | (k, v) :: tl -> add_list (add k v t) tl + | [] -> t + + let of_list lst = add_list empty lst + + let to_list t = fold (fun k v acc -> (k, v) :: acc) t [] + end + end + + + module MapString = MapExt.Make(String) + + + module SetExt = + struct + module type S = + sig + include Set.S + val add_list: t -> elt list -> t + val of_list: elt list -> t + val to_list: t -> elt list + end + + module Make (Ord: Set.OrderedType) = + struct + include Set.Make(Ord) + + let rec add_list t = + function + | e :: tl -> add_list (add e t) tl + | [] -> t + + let of_list lst = add_list empty lst + + let to_list = elements + end + end + + + module SetString = SetExt.Make(String) + + + let compare_csl s1 s2 = + String.compare (OASISString.lowercase_ascii s1) (OASISString.lowercase_ascii s2) + + + module HashStringCsl = + Hashtbl.Make + (struct + type t = string + let equal s1 s2 = (compare_csl s1 s2) = 0 + let hash s = Hashtbl.hash (OASISString.lowercase_ascii s) + end) + + module SetStringCsl = + SetExt.Make + (struct + type t = string + let compare = compare_csl + end) + + + let varname_of_string ?(hyphen='_') s = + if String.length s = 0 then + begin + invalid_arg "varname_of_string" + end + else + begin + let buf = + OASISString.replace_chars + (fun c -> + if ('a' <= c && c <= 'z') + || + ('A' <= c && c <= 'Z') + || + ('0' <= c && c <= '9') then + c + else + hyphen) + s; + in + let buf = + (* Start with a _ if digit *) + if '0' <= s.[0] && s.[0] <= '9' then + "_"^buf + else + buf + in + OASISString.lowercase_ascii buf + end + + + let varname_concat ?(hyphen='_') p s = + let what = String.make 1 hyphen in + let p = + try + OASISString.strip_ends_with ~what p + with Not_found -> + p + in + let s = + try + OASISString.strip_starts_with ~what s + with Not_found -> + s + in + p^what^s + + + let is_varname str = + str = varname_of_string str + + + let failwithf fmt = Printf.ksprintf failwith fmt + + + let rec file_location ?pos1 ?pos2 ?lexbuf () = + match pos1, pos2, lexbuf with + | Some p, None, _ | None, Some p, _ -> + file_location ~pos1:p ~pos2:p ?lexbuf () + | Some p1, Some p2, _ -> + let open Lexing in + let fn, lineno = p1.pos_fname, p1.pos_lnum in + let c1 = p1.pos_cnum - p1.pos_bol in + let c2 = c1 + (p2.pos_cnum - p1.pos_cnum) in + Printf.sprintf (f_ "file %S, line %d, characters %d-%d") fn lineno c1 c2 + | _, _, Some lexbuf -> + file_location + ~pos1:(Lexing.lexeme_start_p lexbuf) + ~pos2:(Lexing.lexeme_end_p lexbuf) + () + | None, None, None -> + s_ "" + + + let failwithpf ?pos1 ?pos2 ?lexbuf fmt = + let loc = file_location ?pos1 ?pos2 ?lexbuf () in + Printf.ksprintf (fun s -> failwith (Printf.sprintf "%s: %s" loc s)) fmt + + +end + +module OASISExpr = struct +(* # 22 "src/oasis/OASISExpr.ml" *) + + + open OASISGettext + open OASISUtils + + + type test = string + type flag = string + + + type t = + | EBool of bool + | ENot of t + | EAnd of t * t + | EOr of t * t + | EFlag of flag + | ETest of test * string + + + type 'a choices = (t * 'a) list + + + let eval var_get t = + let rec eval' = + function + | EBool b -> + b + + | ENot e -> + not (eval' e) + + | EAnd (e1, e2) -> + (eval' e1) && (eval' e2) + + | EOr (e1, e2) -> + (eval' e1) || (eval' e2) + + | EFlag nm -> + let v = + var_get nm + in + assert(v = "true" || v = "false"); + (v = "true") + + | ETest (nm, vl) -> + let v = + var_get nm + in + (v = vl) + in + eval' t + + + let choose ?printer ?name var_get lst = + let rec choose_aux = + function + | (cond, vl) :: tl -> + if eval var_get cond then + vl + else + choose_aux tl + | [] -> + let str_lst = + if lst = [] then + s_ "" + else + String.concat + (s_ ", ") + (List.map + (fun (cond, vl) -> + match printer with + | Some p -> p vl + | None -> s_ "") + lst) + in + match name with + | Some nm -> + failwith + (Printf.sprintf + (f_ "No result for the choice list '%s': %s") + nm str_lst) + | None -> + failwith + (Printf.sprintf + (f_ "No result for a choice list: %s") + str_lst) + in + choose_aux (List.rev lst) + + +end + + +# 443 "myocamlbuild.ml" +module BaseEnvLight = struct +(* # 22 "src/base/BaseEnvLight.ml" *) + + + module MapString = Map.Make(String) + + + type t = string MapString.t + + + let default_filename = Filename.concat (Sys.getcwd ()) "setup.data" + + + let load ?(allow_empty=false) ?(filename=default_filename) ?stream () = + let line = ref 1 in + let lexer st = + let st_line = + Stream.from + (fun _ -> + try + match Stream.next st with + | '\n' -> incr line; Some '\n' + | c -> Some c + with Stream.Failure -> None) + in + Genlex.make_lexer ["="] st_line + in + let rec read_file lxr mp = + match Stream.npeek 3 lxr with + | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] -> + Stream.junk lxr; Stream.junk lxr; Stream.junk lxr; + read_file lxr (MapString.add nm value mp) + | [] -> mp + | _ -> + failwith + (Printf.sprintf "Malformed data file '%s' line %d" filename !line) + in + match stream with + | Some st -> read_file (lexer st) MapString.empty + | None -> + if Sys.file_exists filename then begin + let chn = open_in_bin filename in + let st = Stream.of_channel chn in + try + let mp = read_file (lexer st) MapString.empty in + close_in chn; mp + with e -> + close_in chn; raise e + end else if allow_empty then begin + MapString.empty + end else begin + failwith + (Printf.sprintf + "Unable to load environment, the file '%s' doesn't exist." + filename) + end + + let rec var_expand str env = + let buff = Buffer.create ((String.length str) * 2) in + Buffer.add_substitute + buff + (fun var -> + try + var_expand (MapString.find var env) env + with Not_found -> + failwith + (Printf.sprintf + "No variable %s defined when trying to expand %S." + var + str)) + str; + Buffer.contents buff + + + let var_get name env = var_expand (MapString.find name env) env + let var_choose lst env = OASISExpr.choose (fun nm -> var_get nm env) lst +end + + +# 523 "myocamlbuild.ml" +module MyOCamlbuildFindlib = struct +(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *) + + + (** OCamlbuild extension, copied from + * https://ocaml.org/learn/tutorials/ocamlbuild/Using_ocamlfind_with_ocamlbuild.html + * by N. Pouillard and others + * + * Updated on 2016-06-02 + * + * Modified by Sylvain Le Gall + *) + open Ocamlbuild_plugin + + + type conf = {no_automatic_syntax: bool} + + + let run_and_read = Ocamlbuild_pack.My_unix.run_and_read + + + let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings + + + let exec_from_conf exec = + let exec = + let env = BaseEnvLight.load ~allow_empty:true () in + try + BaseEnvLight.var_get exec env + with Not_found -> + Printf.eprintf "W: Cannot get variable %s\n" exec; + exec + in + let fix_win32 str = + if Sys.os_type = "Win32" then begin + let buff = Buffer.create (String.length str) in + (* Adapt for windowsi, ocamlbuild + win32 has a hard time to handle '\\'. + *) + String.iter + (fun c -> Buffer.add_char buff (if c = '\\' then '/' else c)) + str; + Buffer.contents buff + end else begin + str + end + in + fix_win32 exec + + + let split s ch = + let buf = Buffer.create 13 in + let x = ref [] in + let flush () = + x := (Buffer.contents buf) :: !x; + Buffer.clear buf + in + String.iter + (fun c -> + if c = ch then + flush () + else + Buffer.add_char buf c) + s; + flush (); + List.rev !x + + + let split_nl s = split s '\n' + + + let before_space s = + try + String.before s (String.index s ' ') + with Not_found -> s + + (* ocamlfind command *) + let ocamlfind x = S[Sh (exec_from_conf "ocamlfind"); x] + + (* This lists all supported packages. *) + let find_packages () = + List.map before_space (split_nl & run_and_read (exec_from_conf "ocamlfind" ^ " list")) + + + (* Mock to list available syntaxes. *) + let find_syntaxes () = ["camlp4o"; "camlp4r"] + + + let well_known_syntax = [ + "camlp4.quotations.o"; + "camlp4.quotations.r"; + "camlp4.exceptiontracer"; + "camlp4.extend"; + "camlp4.foldgenerator"; + "camlp4.listcomprehension"; + "camlp4.locationstripper"; + "camlp4.macro"; + "camlp4.mapgenerator"; + "camlp4.metagenerator"; + "camlp4.profiler"; + "camlp4.tracer" + ] + + + let dispatch conf = + function + | After_options -> + (* By using Before_options one let command line options have an higher + * priority on the contrary using After_options will guarantee to have + * the higher priority override default commands by ocamlfind ones *) + Options.ocamlc := ocamlfind & A"ocamlc"; + Options.ocamlopt := ocamlfind & A"ocamlopt"; + Options.ocamldep := ocamlfind & A"ocamldep"; + Options.ocamldoc := ocamlfind & A"ocamldoc"; + Options.ocamlmktop := ocamlfind & A"ocamlmktop"; + Options.ocamlmklib := ocamlfind & A"ocamlmklib" + + | After_rules -> + + (* Avoid warnings for unused tag *) + flag ["tests"] N; + + (* When one link an OCaml library/binary/package, one should use + * -linkpkg *) + flag ["ocaml"; "link"; "program"] & A"-linkpkg"; + + (* For each ocamlfind package one inject the -package option when + * compiling, computing dependencies, generating documentation and + * linking. *) + List.iter + begin fun pkg -> + let base_args = [A"-package"; A pkg] in + (* TODO: consider how to really choose camlp4o or camlp4r. *) + let syn_args = [A"-syntax"; A "camlp4o"] in + let (args, pargs) = + (* Heuristic to identify syntax extensions: whether they end in + ".syntax"; some might not. + *) + if not (conf.no_automatic_syntax) && + (Filename.check_suffix pkg "syntax" || + List.mem pkg well_known_syntax) then + (syn_args @ base_args, syn_args) + else + (base_args, []) + in + flag ["ocaml"; "compile"; "pkg_"^pkg] & S args; + flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args; + flag ["ocaml"; "doc"; "pkg_"^pkg] & S args; + flag ["ocaml"; "link"; "pkg_"^pkg] & S base_args; + flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args; + + (* TODO: Check if this is allowed for OCaml < 3.12.1 *) + flag ["ocaml"; "compile"; "package("^pkg^")"] & S pargs; + flag ["ocaml"; "ocamldep"; "package("^pkg^")"] & S pargs; + flag ["ocaml"; "doc"; "package("^pkg^")"] & S pargs; + flag ["ocaml"; "infer_interface"; "package("^pkg^")"] & S pargs; + end + (find_packages ()); + + (* Like -package but for extensions syntax. Morover -syntax is useless + * when linking. *) + List.iter begin fun syntax -> + flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax]; + flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & + S[A"-syntax"; A syntax]; + end (find_syntaxes ()); + + (* The default "thread" tag is not compatible with ocamlfind. + * Indeed, the default rules add the "threads.cma" or "threads.cmxa" + * options when using this tag. When using the "-linkpkg" option with + * ocamlfind, this module will then be added twice on the command line. + * + * To solve this, one approach is to add the "-thread" option when using + * the "threads" package using the previous plugin. + *) + flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]); + flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]); + flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]); + flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]); + flag ["c"; "pkg_threads"; "compile"] (S[A "-thread"]); + flag ["ocaml"; "package(threads)"; "compile"] (S[A "-thread"]); + flag ["ocaml"; "package(threads)"; "doc"] (S[A "-I"; A "+threads"]); + flag ["ocaml"; "package(threads)"; "link"] (S[A "-thread"]); + flag ["ocaml"; "package(threads)"; "infer_interface"] (S[A "-thread"]); + flag ["c"; "package(threads)"; "compile"] (S[A "-thread"]); + + | _ -> + () +end + +module MyOCamlbuildBase = struct +(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *) + + + (** Base functions for writing myocamlbuild.ml + @author Sylvain Le Gall + *) + + + open Ocamlbuild_plugin + module OC = Ocamlbuild_pack.Ocaml_compiler + + + type dir = string + type file = string + type name = string + type tag = string + + + type t = + { + lib_ocaml: (name * dir list * string list) list; + lib_c: (name * dir * file list) list; + flags: (tag list * (spec OASISExpr.choices)) list; + (* Replace the 'dir: include' from _tags by a precise interdepends in + * directory. + *) + includes: (dir * dir list) list; + } + + +(* # 110 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *) + + + let env_filename = Pathname.basename BaseEnvLight.default_filename + + + let dispatch_combine lst = + fun e -> + List.iter + (fun dispatch -> dispatch e) + lst + + + let tag_libstubs nm = + "use_lib"^nm^"_stubs" + + + let nm_libstubs nm = + nm^"_stubs" + + + let dispatch t e = + let env = BaseEnvLight.load ~allow_empty:true () in + match e with + | Before_options -> + let no_trailing_dot s = + if String.length s >= 1 && s.[0] = '.' then + String.sub s 1 ((String.length s) - 1) + else + s + in + List.iter + (fun (opt, var) -> + try + opt := no_trailing_dot (BaseEnvLight.var_get var env) + with Not_found -> + Printf.eprintf "W: Cannot get variable %s\n" var) + [ + Options.ext_obj, "ext_obj"; + Options.ext_lib, "ext_lib"; + Options.ext_dll, "ext_dll"; + ] + + | After_rules -> + (* Declare OCaml libraries *) + List.iter + (function + | nm, [], intf_modules -> + ocaml_lib nm; + let cmis = + List.map (fun m -> (OASISString.uncapitalize_ascii m) ^ ".cmi") + intf_modules in + dep ["ocaml"; "link"; "library"; "file:"^nm^".cma"] cmis + | nm, dir :: tl, intf_modules -> + ocaml_lib ~dir:dir (dir^"/"^nm); + List.iter + (fun dir -> + List.iter + (fun str -> + flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir])) + ["compile"; "infer_interface"; "doc"]) + tl; + let cmis = + List.map (fun m -> dir^"/"^(OASISString.uncapitalize_ascii m)^".cmi") + intf_modules in + dep ["ocaml"; "link"; "library"; "file:"^dir^"/"^nm^".cma"] + cmis) + t.lib_ocaml; + + (* Declare directories dependencies, replace "include" in _tags. *) + List.iter + (fun (dir, include_dirs) -> + Pathname.define_context dir include_dirs) + t.includes; + + (* Declare C libraries *) + List.iter + (fun (lib, dir, headers) -> + (* Handle C part of library *) + flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib] + (S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib"; + A("-l"^(nm_libstubs lib))]); + + flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib] + (S[A"-cclib"; A("-l"^(nm_libstubs lib))]); + + if bool_of_string (BaseEnvLight.var_get "native_dynlink" env) then + flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib] + (S[A"-dllib"; A("dll"^(nm_libstubs lib))]); + + (* When ocaml link something that use the C library, then one + need that file to be up to date. + This holds both for programs and for libraries. + *) + dep ["link"; "ocaml"; tag_libstubs lib] + [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; + + dep ["compile"; "ocaml"; tag_libstubs lib] + [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; + + (* TODO: be more specific about what depends on headers *) + (* Depends on .h files *) + dep ["compile"; "c"] + headers; + + (* Setup search path for lib *) + flag ["link"; "ocaml"; "use_"^lib] + (S[A"-I"; P(dir)]); + ) + t.lib_c; + + (* Add flags *) + List.iter + (fun (tags, cond_specs) -> + let spec = BaseEnvLight.var_choose cond_specs env in + let rec eval_specs = + function + | S lst -> S (List.map eval_specs lst) + | A str -> A (BaseEnvLight.var_expand str env) + | spec -> spec + in + flag tags & (eval_specs spec)) + t.flags + | _ -> + () + + + let dispatch_default conf t = + dispatch_combine + [ + dispatch t; + MyOCamlbuildFindlib.dispatch conf; + ] + + +end + + +# 884 "myocamlbuild.ml" +open Ocamlbuild_plugin;; +let package_default = + { + MyOCamlbuildBase.lib_ocaml = + [ + ("mesh", ["src"], []); + ("mesh_display", ["src"], []); + ("mesh_triangle", ["src"], []) + ]; + lib_c = [("mesh_triangle", "src/", [])]; + flags = + [ + (["oasis_library_mesh_triangle_ccopt"; "compile"], + [ + (OASISExpr.EBool true, S []); + (OASISExpr.EFlag "libtriangle", + S + [ + A "-ccopt"; + A "-DTRILIBRARY"; + A "-ccopt"; + A "-DEXTERNAL_TEST"; + A "-ccopt"; + A "-DLIBTRIANGLE" + ]); + (OASISExpr.ENot (OASISExpr.EFlag "libtriangle"), + S + [ + A "-ccopt"; + A "-DTRILIBRARY"; + A "-ccopt"; + A "-DEXTERNAL_TEST" + ]) + ]); + (["oasis_library_mesh_triangle_cclib"; "link"], + [ + (OASISExpr.EBool true, S []); + (OASISExpr.EFlag "libtriangle", + S [A "-cclib"; A "-ltriangle"]) + ]); + (["oasis_library_mesh_triangle_cclib"; "ocamlmklib"; "c"], + [ + (OASISExpr.EBool true, S []); + (OASISExpr.EFlag "libtriangle", S [A "-ltriangle"]) + ]) + ]; + includes = [("tests", ["src"])] + } + ;; + +let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false} + +let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;; + +# 940 "myocamlbuild.ml" (* OASIS_STOP *) (* Ocamlbuild_plugin.dispatch dispatch_default;; *) diff --git a/opam/findlib b/opam/findlib deleted file mode 100644 index bf1f8ef..0000000 --- a/opam/findlib +++ /dev/null @@ -1 +0,0 @@ -mesh diff --git a/opam/opam b/opam/opam deleted file mode 100644 index 377bcab..0000000 --- a/opam/opam +++ /dev/null @@ -1,38 +0,0 @@ -opam-version: "1.2" -name: "mesh" -version: "0.8.8" -maintainer: "Christophe Troestler " -authors: [ "Christophe Troestler" ] -license: "LGPL-2.0 with OCaml linking exception" -homepage: "https://github.com/Chris00/mesh" -dev-repo: "https://github.com/Chris00/mesh.git" -bug-reports: "https://github.com/Chris00/mesh/issues" -tags: [ "clib:triangle" ] -build: [ - ["oasis" "setup"] - ["ocaml" "setup.ml" "-configure" "--prefix" prefix - "--%{lacaml:enable}%-lacaml"] - ["ocaml" "setup.ml" "-build"] -] -install: ["ocaml" "setup.ml" "-install"] -remove: [ - ["ocamlfind" "remove" "mesh"] -] -build-test: [ - ["oasis" "setup"] - ["ocaml" "setup.ml" "-configure" "--enable-tests" - "--%{lacaml:enable}%-lacaml"] - ["ocaml" "setup.ml" "-build"] - ["ocaml" "setup.ml" "-test"] -] -build-doc: [ "ocaml" "setup.ml" "-doc" ] -depends: [ - "base-bigarray" - "base-bytes" - "oasis" {build & >= "0.4"} - "ocamlbuild" {build} - "ocamlfind" {build & >= "1.5"} -] -depopts: [ - "lacaml" -] diff --git a/setup.ml b/setup.ml deleted file mode 100644 index 8676c93..0000000 --- a/setup.ml +++ /dev/null @@ -1,60 +0,0 @@ -(* OASIS_START *) -(* DO NOT EDIT (digest: 9852805d5c19ca1cb6abefde2dcea323) *) -(******************************************************************************) -(* OASIS: architecture for building OCaml libraries and applications *) -(* *) -(* Copyright (C) 2011-2013, Sylvain Le Gall *) -(* Copyright (C) 2008-2011, OCamlCore SARL *) -(* *) -(* This library is free software; you can redistribute it and/or modify it *) -(* under the terms of the GNU Lesser General Public License as published by *) -(* the Free Software Foundation; either version 2.1 of the License, or (at *) -(* your option) any later version, with the OCaml static compilation *) -(* exception. *) -(* *) -(* This library is distributed in the hope that it will be useful, but *) -(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *) -(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more *) -(* details. *) -(* *) -(* You should have received a copy of the GNU Lesser General Public License *) -(* along with this library; if not, write to the Free Software Foundation, *) -(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *) -(******************************************************************************) - -let () = - try - Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") - with Not_found -> () -;; -#use "topfind";; -#require "oasis.dynrun";; -open OASISDynRun;; - -(* OASIS_STOP *) - -open OASISTypes - -let setup_t = - (* Unless one installs on OSX with "brew install ocaml --with-x11", - the [Graphics] module will not be present. *) - let has_graphics = try ignore(BaseCheck.package_version "graphics"); true - with Failure _ -> false in - (* Change [setup_t] to set the default value of the flag "graphics" - to [true]. *) - if has_graphics then - let change_flag = function - | Flag(cs, flag) when cs.cs_name = "has_graphics" -> - let flag = { flag with - flag_default = [(OASISExpr.EBool true, true)] } in - Flag(cs, flag) - | section -> section in - let package = - { setup_t.BaseSetup.package with - sections = List.map change_flag setup_t.BaseSetup.package.sections } in - { setup_t with BaseSetup.package = package } - else - setup_t - -let () = - BaseSetup.setup setup_t diff --git a/src/jbuild b/src/jbuild new file mode 100644 index 0000000..3b47027 --- /dev/null +++ b/src/jbuild @@ -0,0 +1,15 @@ +(jbuild_version 1) + +(library + ((name mesh) + (public_name mesh) + (synopsis "Triangular mesh generation and manipulation") + (modules (Mesh Mesh_utils Mesh_common MeshF MeshC)) + (flags (:standard -safe-string)) + (libraries (bigarray bytes)))) + +(rule + ((targets (meshF.ml meshC.ml)) + (deps (../config/make_FC_code.exe + meshFC.ml mesh_level_curvesFC.ml)) + (action (run ../config/make_FC_code.exe)))) diff --git a/tests/jbuild b/tests/jbuild new file mode 100644 index 0000000..ffc08bb --- /dev/null +++ b/tests/jbuild @@ -0,0 +1,19 @@ +(jbuild_version 1) + +(executables + ((names (square_easymesh )) + (modules (square_easymesh )) + (libraries (mesh_display lacaml)))) + +(executables + ((names (square_triangle level_display refine attributes export + degenerate_pslg)) + (modules (square_triangle level_display refine attributes export + degenerate_pslg)) + (libraries (mesh_triangle mesh_display lacaml)))) + +(alias + ((name runtest) + (package mesh-display) + (deps (square_easymesh.exe)) + (action (run ${exe:square_easymesh.exe})))) diff --git a/triangle/jbuild b/triangle/jbuild new file mode 100644 index 0000000..37cb9cb --- /dev/null +++ b/triangle/jbuild @@ -0,0 +1,45 @@ +(jbuild_version 1) + +(library + ((name mesh_triangle) + (public_name mesh-triangle) + (synopsis "Binding to the triangle mesh generator") + (modules (Mesh_triangle + Mesh_triangle_common Mesh_triangleF Mesh_triangleC + Mesh_common Mesh_utils)) + (c_names (libtriangle_stubs)) + (c_flags ((:include c_flags.sexp) + -O3 -march=native -fPIC -DPIC)) + (c_library_flags (:include c_library_flags.sexp)) + (libraries (mesh)))) + +(rule + ((targets (mesh_triangleF.ml mesh_triangleC.ml)) + (deps (../config/make_FC_code.exe + mesh_triangleFC.ml)) + (action (run ../config/make_FC_code.exe)))) + +(rule + ((targets (c_flags.sexp c_library_flags.sexp)) + (deps (../config/discover.exe)) + (action (run ${<} -ocamlc ${OCAMLC})))) + +(rule + ((targets (mesh_common.ml)) + (deps (../src/mesh_common.ml)) + (action (copy# ${^} mesh_common.ml)))) + +(rule + ((targets (mesh_utils.ml)) + (deps (../src/mesh_utils.ml)) + (action (copy# ${^} mesh_utils.ml)))) + +(rule + ((targets (libtriangle_stubs.c)) + (deps (triangle_stubs.c triangulate_stub.c + triangle/triangle.c triangle/triangle.h)) + (action (progn + (copy triangle_stubs.c libtriangle_stubs.c) + ;(copy triangulate_stub.c triangulate_stub.c) + (copy triangle/triangle.c triangle.c) + (copy triangle/triangle.h triangle.h))))) diff --git a/src/mesh_triangle.ml b/triangle/mesh_triangle.ml similarity index 100% rename from src/mesh_triangle.ml rename to triangle/mesh_triangle.ml diff --git a/src/mesh_triangle.mli b/triangle/mesh_triangle.mli similarity index 100% rename from src/mesh_triangle.mli rename to triangle/mesh_triangle.mli diff --git a/src/mesh_triangleFC.ml b/triangle/mesh_triangleFC.ml similarity index 93% rename from src/mesh_triangleFC.ml rename to triangle/mesh_triangleFC.ml index 2337d84..4fd8e8b 100644 --- a/src/mesh_triangleFC.ml +++ b/triangle/mesh_triangleFC.ml @@ -14,12 +14,15 @@ type int_vec = layout Mesh.int_vec let layout = Bigarray.LAYOUT let default_switches = "DEFAULT_SWITCHES" +let empty_vec = Array1.create int layout 0 let empty_mat0 = CREATE_MAT(float64, 0, 0) +let empty_mat2 = CREATE_MAT(float64, 2, 0) +let empty_mat4 = CREATE_MAT(float64, 4, 0) let pslg ~hole ~region ~point_attribute ~point_marker ~point ~segment_marker ~segment = let point_marker = match point_marker with - | None -> MeshFC.empty_vec + | None -> empty_vec | Some m -> let n = Array1.dim m in if 0 < n && n < NCOLS(point) then @@ -32,20 +35,20 @@ let pslg ~hole ~region ~point_attribute ~point_marker ~point invalid_arg "Mesh_triangle.pslg: COLS point_attribute <> COLS point"; a in let segment_marker = match segment_marker with - | None -> MeshFC.empty_vec + | None -> empty_vec | Some m -> let n = Array1.dim m in if 0 < n && n < NCOLS(segment) then invalid_arg "Mesh_triangle.pslg: segment_marker too small"; m in let hole = match hole with - | None -> MeshFC.empty_mat2 + | None -> empty_mat2 | Some h -> if NCOLS(h) > 0 && NROWS(h) <> 2 then invalid_arg "Mesh_triangle.pslg: ROWS hole must be 2"; h in let region = match region with - | None -> MeshFC.empty_mat4 + | None -> empty_mat4 | Some r -> if NCOLS(r) > 0 && NROWS(r) <> 4 then invalid_arg "Mesh_triangle.pslg: ROWS region must be 4"; @@ -229,7 +232,7 @@ let triangulate ?(delaunay=true) ?min_angle ?max_area ?(region_area=false) ***********************************************************************) let sub (mesh: mesh) ?(pos=FST) len = - let m, n_tr, cols_tr = MeshFC.internal_sub (mesh :> MeshFC.mesh) + let m, n_tr, cols_tr = Mesh__MeshFC.internal_sub (mesh :> Mesh__MeshFC.mesh) ~pos len in let point_attribute = if NROWS(mesh#point_attribute) = 0 || NCOLS(mesh#point_attribute) = 0 then @@ -241,7 +244,7 @@ let sub (mesh: mesh) ?(pos=FST) len = if NROWS(old_att) = 0 || NCOLS(old_att) = 0 then old_att else ( let att = CREATE_MAT(float64, NROWS(old_att), n_tr) in - MeshFC.iteri (fun i pi -> + Mesh__MeshFC.iteri (fun i pi -> for j = FST to LASTROW(att) do GET(att, j, i) <- GET(old_att, j, pi); done @@ -259,8 +262,8 @@ let sub (mesh: mesh) ?(pos=FST) len = let permute_points_name = "Mesh_triangle.permute_points" let do_permute_points (old_mesh: mesh) (perm: int_vec) inv_perm : mesh = - let mesh = MeshFC.do_permute_points permute_points_name - (old_mesh :> MeshFC.mesh) + let mesh = Mesh__MeshFC.do_permute_points permute_points_name + (old_mesh :> Mesh__MeshFC.mesh) perm inv_perm in (* Permute the attributes *) let old_attr : mat = old_mesh#point_attribute in @@ -277,7 +280,7 @@ let do_permute_points (old_mesh: mesh) (perm: int_vec) inv_perm : mesh = let permute_points (mesh: mesh) ~inv (perm: int_vec) = - let inv_perm = MeshFC.inverse_perm permute_points_name perm in + let inv_perm = Mesh__MeshFC.inverse_perm permute_points_name perm in if inv then do_permute_points mesh inv_perm perm else do_permute_points mesh perm inv_perm @@ -285,8 +288,8 @@ let permute_points (mesh: mesh) ~inv (perm: int_vec) = let permute_triangles_name = "Mesh_triangle.permute_triangles" let do_permute_triangles (old_mesh: mesh) (perm: int_vec) : mesh = - let mesh = MeshFC.do_permute_triangles permute_triangles_name - (old_mesh :> MeshFC.mesh) perm in + let mesh = Mesh__MeshFC.do_permute_triangles permute_triangles_name + (old_mesh :> Mesh__MeshFC.mesh) perm in (* Permute attributes *) let old_attr : mat = old_mesh#triangle_attribute in let attr = CREATE_MAT(float64, NROWS(old_attr), NCOLS(old_attr)) in @@ -301,6 +304,6 @@ let do_permute_triangles (old_mesh: mesh) (perm: int_vec) : mesh = ~triangle_attribute: attr let permute_triangles (mesh: mesh) ~inv (perm: int_vec) = - let inv_perm = MeshFC.inverse_perm permute_triangles_name perm in + let inv_perm = Mesh__MeshFC.inverse_perm permute_triangles_name perm in if inv then do_permute_triangles mesh inv_perm else do_permute_triangles mesh perm diff --git a/src/mesh_triangle_common.ml b/triangle/mesh_triangle_common.ml similarity index 100% rename from src/mesh_triangle_common.ml rename to triangle/mesh_triangle_common.ml diff --git a/src/triangle_stubs.c b/triangle/triangle_stubs.c similarity index 99% rename from src/triangle_stubs.c rename to triangle/triangle_stubs.c index 3002e0e..7c289c3 100644 --- a/src/triangle_stubs.c +++ b/triangle/triangle_stubs.c @@ -21,11 +21,11 @@ #ifdef LIBTRIANGLE /* Use the external library if it exists. */ -#include "triangle.h" +#include typedef REAL *vertex; /* taken from triangle.c */ #else /* Include triangle code. */ -#include "triangle/triangle.c" +#include "triangle.c" #endif #define REAL_BIGARRAY_VAL(v) ((REAL *) Data_bigarray_val(v)) diff --git a/src/triangulate_stub.c b/triangle/triangulate_stub.c similarity index 100% rename from src/triangulate_stub.c rename to triangle/triangulate_stub.c