From bbdd4bb024228a71c35f7b74e42fc18f02dc4f72 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 7 Feb 2012 10:13:02 +0000 Subject: [PATCH] move wrapper code into wrappers/ directory. Python wrappers will follow. --- CMakeLists.txt | 78 +- wrappers/java/CMakeLists.txt | 74 + wrappers/java/WrapGmsh.i | 117 ++ wrappers/java/WrappingJava/build.xml | 156 ++ .../WrappingJava/src/main/java/.classpath | 7 + .../java/WrappingJava/src/main/java/.project | 17 + .../java/com/artenum/sample/EssaiGmsh_v1.java | 1401 +++++++++++++++++ .../java/com/artenum/sample/EssaiGmsh_v2.java | 59 + .../java/org/geuz/gmsh/utils/NativeList.java | 113 ++ .../java/org/geuz/gmsh/utils/NativeSet.java | 176 +++ .../org/geuz/gmsh/utils/listWrapperGmsh.h | 78 + .../java/org/geuz/gmsh/utils/setWrapperGmsh.h | 77 + .../java/WrappingJava/src/main/java/t5.geo | 166 ++ 13 files changed, 2446 insertions(+), 73 deletions(-) create mode 100644 wrappers/java/CMakeLists.txt create mode 100644 wrappers/java/WrapGmsh.i create mode 100644 wrappers/java/WrappingJava/build.xml create mode 100644 wrappers/java/WrappingJava/src/main/java/.classpath create mode 100644 wrappers/java/WrappingJava/src/main/java/.project create mode 100755 wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java create mode 100755 wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v2.java create mode 100644 wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeList.java create mode 100644 wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeSet.java create mode 100644 wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/listWrapperGmsh.h create mode 100644 wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/setWrapperGmsh.h create mode 100644 wrappers/java/WrappingJava/src/main/java/t5.geo diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b9979245e..d18cc668e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1209,79 +1209,11 @@ if(ENABLE_WRAP_PYTHON) endif(SWIG_FOUND AND PYTHONLIBS_FOUND) endif(ENABLE_WRAP_PYTHON) -if(ENABLE_WRAP_JAVA) - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/org/geuz/gmsh/utils) - # flag used to compilation during Java wrapping - set(CMAKE_CXX_FLAGS "-fno-strict-aliasing") - # find SWIG and include the swig file - find_package(SWIG REQUIRED) - include(${SWIG_USE_FILE}) - # find Java and JNI and include files required - find_package(Java REQUIRED) - find_package(JNI REQUIRED) - include_directories(${JNI_INCLUDE_DIRS}) - include_directories(${JAVA_INCLUDE_PATH}) - include_directories(${JAVA_INCLUDE_PATH2}) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - # define where the interface file (used by SWIG) are - set(SWIG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WrapGmsh.i) - # let swig know that example.i is c++ - set_source_files_properties(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) - # define where the Java files generated by SWIG will be stored - set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/org/geuz/gmsh/generated/) - # defines the packaging of Java files generated by SWIG - set(JAVAPACKAGENAME "org.geuz.gmsh.generated") - set(CMAKE_SWIG_FLAGS -package ${JAVAPACKAGENAME}) - # create the swig module called WrapGmsh - # using the SWIG_SOURCE flag defined previously - # swig will be used to create WrapGmshJAVA_wrap.cxx from SWIG_SOURCE - swig_add_module(WrapGmsh java ${SWIG_SOURCES}) - # link dynamic library called libWrapGmsh with the help of "shared" library - swig_link_libraries(WrapGmsh shared) - # define a good name for the dynamic libraty which depends on the OS - if(WIN32) - set_target_properties(WrapGmsh PROPERTIES PREFIX "") - endif(WIN32) - if(UNIX) - set_target_properties(WrapGmsh PROPERTIES PREFIX "lib") - endif(UNIX) - add_custom_command(TARGET gmsh - POST_BUILD # do the rest of the command after the build period - # write on the output consol - COMMAND cmake -E echo "Compiling Java files..." - #compilation of Java files generated by SWIG - COMMAND ${JAVA_COMPILE} - ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/org/geuz/gmsh/generated/*.java - -classpath ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - -d ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - # compilation of Java files used by wrapping - COMMAND ${JAVA_COMPILE} - ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/org/geuz/gmsh/utils/*.java - -classpath ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - -d ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - # compilation of Java files used as demonstration - COMMAND ${JAVA_COMPILE} - ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/com/artenum/sample/*.java - -classpath ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - -d ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - # create a jar file which contains the files with a .class extension - COMMAND cmake -E echo "Creating jar file..." - COMMAND ${JAVA_ARCHIVE} cvf ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/WrapGmsh.jar - -C ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ org - COMMAND ${JAVA_ARCHIVE} cvf ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/Sample.jar - -C ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ com - # create a jar from Sample - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/t5.geo - ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ - # copy the build.xml file to run the ant script - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/build.xml - ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/) - install(TARGETS WrapGmsh shared DESTINATION lib OPTIONAL) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/WrapGmsh.jar - DESTINATION lib) +if(ENABLE_WRAP_JAVA) + if(NOT HAVE_BLAS OR NOT HAVE_LAPACK) + message("WARNING: Java wrapping samples will not work without BLAS and LAPACK") + endif(NOT HAVE_BLAS OR NOT HAVE_LAPACK) + add_subdirectory(wrappers/java) endif(ENABLE_WRAP_JAVA) include(CPack) diff --git a/wrappers/java/CMakeLists.txt b/wrappers/java/CMakeLists.txt new file mode 100644 index 0000000000..4c8fbc6380 --- /dev/null +++ b/wrappers/java/CMakeLists.txt @@ -0,0 +1,74 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/org/geuz/gmsh/utils) +# flag used to compilation during Java wrapping +set(CMAKE_CXX_FLAGS "-fno-strict-aliasing") +# find SWIG and include the swig file +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) +# find Java and JNI and include files required +find_package(Java REQUIRED) +find_package(JNI REQUIRED) +include_directories(${JNI_INCLUDE_DIRS}) +include_directories(${JAVA_INCLUDE_PATH}) +include_directories(${JAVA_INCLUDE_PATH2}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +# define where the interface file (used by SWIG) are +set(SWIG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WrapGmsh.i) +# let swig know that example.i is c++ +set_source_files_properties(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) +# define where the Java files generated by SWIG will be stored +set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/org/geuz/gmsh/generated/) +# defines the packaging of Java files generated by SWIG +set(JAVAPACKAGENAME "org.geuz.gmsh.generated") +set(CMAKE_SWIG_FLAGS -package ${JAVAPACKAGENAME}) +# create the swig module called WrapGmsh +# using the SWIG_SOURCE flag defined previously +# swig will be used to create WrapGmshJAVA_wrap.cxx from SWIG_SOURCE +swig_add_module(WrapGmsh java ${SWIG_SOURCES}) +swig_link_libraries(WrapGmsh shared) + +# link dynamic library called libWrapGmsh with the help of "sharedSrc" library + +# define a good name for the dynamic libraty which depends on the OS +if(WIN32) + set_target_properties(WrapGmsh PROPERTIES PREFIX "") +endif(WIN32) +if(UNIX) + set_target_properties(WrapGmsh PROPERTIES PREFIX "lib") +endif(UNIX) +add_custom_command(TARGET WrapGmsh +POST_BUILD # do the rest of the command after the build period +# write on the output consol + COMMAND cmake -E echo "Compiling Java files..." + #compilation of Java files generated by SWIG + COMMAND ${JAVA_COMPILE} + ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/org/geuz/gmsh/generated/*.java + -classpath ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + -d ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + # compilation of Java files used by wrapping + COMMAND ${JAVA_COMPILE} + ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/org/geuz/gmsh/utils/*.java + -classpath ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + -d ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + # compilation of Java files used as demonstration + COMMAND ${JAVA_COMPILE} + ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/com/artenum/sample/*.java + -classpath ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + -d ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + # create a jar file which contains the files with a .class extension + COMMAND cmake -E echo "Creating jar file..." + COMMAND ${JAVA_ARCHIVE} cvf ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/WrapGmsh.jar + -C ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ org + COMMAND ${JAVA_ARCHIVE} cvf ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/Sample.jar + -C ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ com + # create a jar from Sample + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/src/main/java/t5.geo + ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/ + # copy the build.xml file to run the ant script + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/WrappingJava/build.xml + ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/) +install(TARGETS WrapGmsh DESTINATION lib OPTIONAL) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/WrappingJava/WrapGmsh.jar + DESTINATION lib) diff --git a/wrappers/java/WrapGmsh.i b/wrappers/java/WrapGmsh.i new file mode 100644 index 0000000000..f8563031cf --- /dev/null +++ b/wrappers/java/WrapGmsh.i @@ -0,0 +1,117 @@ +/*wrapGmsh.i*/ + %module WrapGmsh + %{ + /* Put header files here or function declarations like below */ +#include "Gmsh.h" +#include "GModel.h" +#include "Geo.h" +#include "GVertex.h" +#include "gmshVertex.h" +#include "GEntity.h" +#include "GModelFactory.h" +#include "GEdge.h" +#include "GFace.h" +#include "GRegion.h" +#include "GeoStringInterface.h" +#include "GEntity.h" +#include "setWrapperGmsh.h" +#include "listWrapperGmsh.h" +#include "MPoint.h" +#include "MLine.h" +#include "MTriangle.h" +#include "MFace.h" +#include "MTetrahedron.h" +#include "GModelIO_Mesh.cpp" + + %} + +//declares meshGenerationStatus enumeration +%include "enums.swg" +%javaconst(1); +enum meshGenerationStatus {PENDING, DONE, FAILED}; + +//these fonctions/classes must be wrapped +%include "std_string.i" +%include "MElement.h" +%include "MPoint.h" +%include "MLine.h" +%include "MFace.h" +%include "MTriangle.h" +%include "MTetrahedron.h" +%include "GEntity.h" +%include "GModel.h" +%include "Geo.h" +%include "GVertex.h" +%include "gmshVertex.h" +%include "GModelFactory.h" +%include "GEdge.h" +%include "GFace.h" +%include "GRegion.h" +%include "MVertex.h" +%include "GEntity.h" +%include "ListUtils.h" +extern int GModel::getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition); +extern int GModel::indexMeshVertices(bool all, int singlePartition); +extern int GmshInitialize(int argc, char **argv); +extern int GmshFinalize(); +extern Vertex *Create_Vertex(int Num, double X, double Y, double Z, double lc, double u); +extern void add_physical(std::string type, List_T *list, std::string fileName); + +//use the Vector object defined in Java language to wrap the std vector. +%include "std_vector.i" +namespace std { + %template(EdgeVector) std::vector<GEdge *>; + %template(EdgeVectorOfVector) std::vector<std::vector<GEdge *> >; + %template(FaceVector) std::vector<GFace *>; + %template(FaceVectorOfVector) std::vector<std::vector<GFace *> >; + %template(GVertexVector) std::vector<GVertex *>; + %template(RegionVector) std::vector<GRegion *>; + %template(GEntityVector) std::vector<GEntity*>; + %template(MVertexVector) std::vector<MVertex*>; + %template(MPointVector) std::vector<MPoint*>; + %template(MLineVector) std::vector<MLine*>; + %template(MTriangleVector) std::vector<MTriangle*>; + %template(MTetrahedrVector) std::vector<MTetrahedron*>; + %template(IntVector) std::vector<int>; +}; + + +//wrap Set from std +%include "setWrapperGmsh.h" + +%template (GVertexSetWrapper) SetWrapperGmsh<GVertex*, GEntityLessThan>; +%template (GVertexSetIterator) SetIteratorGmsh<GVertex*, GEntityLessThan>; + +%template (GEdgeSetWrapper) SetWrapperGmsh<GEdge*, GEntityLessThan>; +%template (GEdgeSetIterator) SetIteratorGmsh<GEdge*, GEntityLessThan>; + +%template (GFaceSetWrapper) SetWrapperGmsh<GFace*, GEntityLessThan>; +%template (GFaceSetIterator) SetIteratorGmsh<GFace*, GEntityLessThan>; + +%template (GRegionSetWrapper) SetWrapperGmsh<GRegion*, GEntityLessThan>; +%template (GRegionSetIterator) SetIteratorGmsh<GRegion*, GEntityLessThan>; + + +//wrap List from std +%include "listWrapperGmsh.h" + +%template (GVertexListWrapper) ListWrapperGmsh<GVertex*>; +%template (GVertexListIterator) ListIteratorGmsh<GVertex*>; + +%template (GEdgeListWrapper) ListWrapperGmsh<GEdge*>; +%template (GEdgeListIterator) ListIteratorGmsh<GEdge*>; + +%template (GFaceListWrapper) ListWrapperGmsh<GFace*>; +%template (GFaceListIterator) ListIteratorGmsh<GFace*>; + +%template (GRegionListWrapper) ListWrapperGmsh<GRegion*>; +%template (GRegionListIterator) ListIteratorGmsh<GRegion*>; + + + + + + + + + diff --git a/wrappers/java/WrappingJava/build.xml b/wrappers/java/WrappingJava/build.xml new file mode 100644 index 0000000000..b02b8d61b5 --- /dev/null +++ b/wrappers/java/WrappingJava/build.xml @@ -0,0 +1,156 @@ +<project name="GMSH wrapping sample" default="help" basedir="."> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- Global properties --> + <!-- ////////////////////////////////////////////////////////////// --> + + <!-- Build year --> + <tstamp> + <format property="year" pattern="yyyy" /> + </tstamp> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- System-specific properties --> + <!-- ////////////////////////////////////////////////////////////// --> + + <!-- System architecture --> + <condition property="arch" value="32b"> + <or> + <os arch="x86" /> + <os arch="i386" /> + <os arch="i486" /> + <os arch="i586" /> + </or> + </condition> + <condition property="arch" value="64b"> + <or> + <os arch="x86_64" /> + <os arch="i686" /> + <os arch="amd64" /> + </or> + </condition> + + <!-- Operating system --> + <condition property="platform" value="linux${arch}"> + <os name="Linux" /> + </condition> + <condition property="platform" value="win32b"> + <os family="Windows" /> + </condition> + <condition property="platform" value="osx64b"> + <os name="Mac OS X" /> + </condition> + + <!-- Native environment variable name --> + <condition property="jni.system.var" value="LD_LIBRARY_PATH"> + <os name="Linux" /> + </condition> + <condition property="jni.system.var" value="PATH"> + <os family="Windows" /> + </condition> + <condition property="jni.system.var" value="DYLD_LIBRARY_PATH"> + <os name="Mac OS X" /> + </condition> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- Classpath --> + <!-- ////////////////////////////////////////////////////////////// --> + + + <!-- Run classpath --> + <path id="run.class.path"> + + <!-- Generated JAR files --> + <fileset dir="${basedir}"> + <include name="Sample.jar" /> + <include name="WrapGmsh.jar" /> + </fileset> + + </path> + + <!-- Main classes --> + <property name="sample1.main" value="com.artenum.sample.EssaiGmsh_v1" /> + <property name="sample2.main" value="com.artenum.sample.EssaiGmsh_v2" /> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- Ant build message --> + <!-- ////////////////////////////////////////////////////////////// --> + + <echo message="//////////////////////////////////////////////////////////////" /> + <echo message=" GMSH wrapping sample " /> + <echo message=" Version 0.0.1 " /> + <echo message=" " /> + <echo message="//////////////////////////////////////////////////////////////" /> + <echo message=" Developed by Artenum SARL 2011-${year} " /> + <echo message=" http://www.artenum.com " /> + <echo message="//////////////////////////////////////////////////////////////" /> + <echo message="" /> + <echo message="System information:" /> + <echo message="" /> + <echo message="Architecture: ${os.arch}" /> + <echo message="Operating system: ${os.name}" /> + <echo message="Java version: ${java.version}" /> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- Ant help message --> + <!-- ////////////////////////////////////////////////////////////// --> + + <target name="help" description="Display the main targets available"> + <echo message="//////////////////////////////////////////////////////////////" /> + <echo message="Ant tasks available:" /> + <echo message=" " /> + <echo message=" - clean : remove all Ant-generated files" /> + <echo message=" " /> + <echo message=" - sample1 : executes the GMSH wrapping sample code nr 1" /> + <echo message=" - sample2 : executes the GMSH wrapping sample code nr 2" /> + </target> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- Cleaning Ant files --> + <!-- ////////////////////////////////////////////////////////////// --> + + <target name="clean" description="Clean Ant-generated files"> + <echo message="//////////////////////////////////////////////////////////////" /> + <echo message=" Cleaning Ant-generated files" /> + <echo message="//////////////////////////////////////////////////////////////" /> + <echo message="" /> + <delete file="device_with_booms.msh" /> + <delete file="meshtest.msh" /> + <delete file="test.geo" /> + + + </target> + + <!-- ////////////////////////////////////////////////////////////// --> + <!-- Sample codes execution --> + <!-- ////////////////////////////////////////////////////////////// --> + + <!-- Execute the application --> + <target name="sample1" description="Execute the sample 1"> + <echo message="##############################################################" /> + <echo message=" Executing sample1" /> + <echo message="##############################################################" /> + <echo message="" /> + <java classname="${sample1.main}" fork="true"> + <env key="${jni.system.var}" value=".." /> + <classpath refid="run.class.path" /> + <jvmarg value="-Xmx512M" /> + <jvmarg value="-Xms100M" /> + </java> + </target> + + <!-- Execute the application --> + <target name="sample2" description="Execute the sample 2"> + <echo message="##############################################################" /> + <echo message=" Executing sample2" /> + <echo message="##############################################################" /> + <echo message="" /> + <java classname="${sample2.main}" fork="true"> + <env key="${jni.system.var}" value=".." /> + <classpath refid="run.class.path" /> + <jvmarg value="-Xmx512M" /> + <jvmarg value="-Xms100M" /> + </java> + </target> + +</project> diff --git a/wrappers/java/WrappingJava/src/main/java/.classpath b/wrappers/java/WrappingJava/src/main/java/.classpath new file mode 100644 index 0000000000..ea49a96860 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path=""/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="/home/benj/Bureau/gmshWrap_v1.6/build/WrappingJava/WrapGmsh.jar"/> + <classpathentry kind="output" path=""/> +</classpath> diff --git a/wrappers/java/WrappingJava/src/main/java/.project b/wrappers/java/WrappingJava/src/main/java/.project new file mode 100644 index 0000000000..f9a9e1e636 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>java</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java b/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java new file mode 100755 index 0000000000..fa4c26e5d7 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v1.java @@ -0,0 +1,1401 @@ +package com.artenum.sample; + +import org.geuz.gmsh.generated.EdgeVector; +import org.geuz.gmsh.generated.EdgeVectorOfVector; +import org.geuz.gmsh.generated.FaceVector; +import org.geuz.gmsh.generated.FaceVectorOfVector; +import org.geuz.gmsh.generated.GEdge; +import org.geuz.gmsh.generated.GEntityVector; +import org.geuz.gmsh.generated.GFace; +import org.geuz.gmsh.generated.GModel; +import org.geuz.gmsh.generated.GRegion; +import org.geuz.gmsh.generated.GVertex; +import org.geuz.gmsh.generated.GVertexVector; +import org.geuz.gmsh.generated.GeoFactory; +import org.geuz.gmsh.generated.IntVector; +import org.geuz.gmsh.generated.List_T; +import org.geuz.gmsh.generated.MLine; +import org.geuz.gmsh.generated.MPoint; +import org.geuz.gmsh.generated.MTetrahedron; +import org.geuz.gmsh.generated.MTriangle; +import org.geuz.gmsh.generated.RegionVector; +import org.geuz.gmsh.generated.WrapGmsh; + +/** + * This class is an example of use of Gmsh wrapping in Java. + * + * @author benjamin jeanty-ruard + * + */ +public class EssaiGmsh_v1 { + + static { + try { + System.loadLibrary("WrapGmsh"); + } catch (final UnsatisfiedLinkError e) { + System.err + .println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + + } + + public static void main(final String[] args) { + + // initialization of gmsh + WrapGmsh.GmshInitialize(0, null); + + // creation of GModel which stores all geometric elements and all mesh + // elements + final GModel m = new GModel(); + + // creation of List which are used to define "physical property" for + // some elements + final List_T lst1 = WrapGmsh.List_Create(5, 5, 4); + final List_T lst2 = WrapGmsh.List_Create(5, 5, 4); + final List_T lst3 = WrapGmsh.List_Create(5, 5, 4); + final List_T lst4 = WrapGmsh.List_Create(5, 5, 4); + + // outside tetrahedron + + final double x1 = 1.0;// x coordinate of first point + final double y1 = 0.0;// y coordinate of first point + final double z1 = 0.0;// z coordinate of first point + + final double lc1 = 0.05;// define mesh precision + + final double x2 = 0.0; + final double y2 = 1.0; + final double z2 = 0.0; + + final double lc2 = 0.05; + + final double x3 = 0.0; + final double y3 = 0.0; + final double z3 = 0.0; + + final double lc3 = 0.05; + + final double x4 = 0.0; + final double y4 = 0.0; + final double z4 = 1.0; + + final double lc4 = 0.05; + + // inside tetrahedron + + final double x5 = 0.9; + final double y5 = 0.025; + final double z5 = 0.025; + + final double lc5 = 0.05; + + final double x6 = 0.025; + final double y6 = 0.9; + final double z6 = 0.025; + + final double lc6 = 0.05; + + final double x7 = 0.025; + final double y7 = 0.025; + final double z7 = 0.025; + + final double lc7 = 0.05; + + final double x8 = 0.025; + final double y8 = 0.025; + final double z8 = 0.9; + + final double lc8 = 0.05; + + // hole between outside tetrahedron and inside tetrahedron + + final double x9 = 0.1; + final double y9 = 0.0; + final double z9 = 0.1; + + final double lc9 = 0.05; + + final double x10 = 0.4; + final double y10 = 0.0; + final double z10 = 0.1; + + final double lc10 = 0.01; + + final double x11 = 0.4; + final double y11 = 0.0; + final double z11 = 0.4; + + final double lc11 = 0.01; + + final double x12 = 0.1; + final double y12 = 0.0; + final double z12 = 0.4; + + final double lc12 = 0.01; + + final double x13 = 0.1; + final double y13 = 0.025; + final double z13 = 0.1; + + final double lc13 = 0.01; + + final double x14 = 0.4; + final double y14 = 0.025; + final double z14 = 0.1; + + final double lc14 = 0.01; + + final double x15 = 0.4; + final double y15 = 0.025; + final double z15 = 0.4; + + final double lc15 = 0.01; + + final double x16 = 0.1; + final double y16 = 0.025; + final double z16 = 0.4; + + final double lc16 = 0.01; + + // curved tetrahedron + + final double x17 = 0.0; + final double y17 = 0.0; + final double z17 = -2.0; + + final double lc17 = 0.1; + + final double x18 = 1.0; + final double y18 = 0.0; + final double z18 = -1.0; + + final double lc18 = 0.1; + + final double x19 = 0.0; + final double y19 = 1.0; + final double z19 = -1.0; + + final double lc19 = 0.1; + + final double x20 = 0.0; + final double y20 = 0.0; + final double z20 = -1.0; + + final double lc20 = 0.1; + + // inside sphere + + final double x21 = 0.7; + final double y21 = 0.354; + final double z21 = -1.354; + + final double lc21 = 0.1; + + final double x22 = 0.354; + final double y22 = 0.008; + final double z22 = -1.354; + + final double lc22 = 0.1; + + final double x23 = 0.008; + final double y23 = 0.354; + final double z23 = -1.354; + + final double lc23 = 0.1; + + final double x24 = 0.354; + final double y24 = 0.7; + final double z24 = -1.354; + + final double lc24 = 0.1; + + final double x25 = 0.354; + final double y25 = 0.354; + final double z25 = -1.008; + + final double lc25 = 0.1; + + final double x26 = 0.354; + final double y26 = 0.354; + final double z26 = -1.7; + + final double lc26 = 0.1; + + final double x27 = 0.354; + final double y27 = 0.354; + final double z27 = -1.354; + + final double lc27 = 0.1; + + // -----------------------------------------------------------------------// + // declaration of variables + // -----------------------------------------------------------------------// + // variable used to define physical property of some elements (vertex, + // edge, ...) + int tag; + + // string used to define physical of some elements. It can be equal to + // "Point", "Line", "Surface" or "Volume" + final String str = "Point"; + final String str1 = "Line"; + final String str2 = "Surface"; + final String str3 = "Volume"; + + // creation of GeoFactory used to create vertices, edges, faces, ... + final GeoFactory gFact = new GeoFactory(); + + // GVertex of outside tetrahedron + GVertex v1; + GVertex v2; + GVertex v3; + GVertex v4; + + // GVertex of inside tetrahedron + GVertex v5; + GVertex v6; + GVertex v7; + GVertex v8; + + // GVertex of hole between inside tetrahedron and outside tetrahedron + GVertex v9; + GVertex v10; + GVertex v11; + GVertex v12; + GVertex v13; + GVertex v14; + GVertex v15; + GVertex v16; + + // GVertex of curved tetrahedron + final GVertex v17; + final GVertex v18; + final GVertex v19; + final GVertex v20; + + // GVertex of inside sphere + final GVertex v21; + final GVertex v22; + final GVertex v23; + final GVertex v24; + final GVertex v25; + final GVertex v26; + final GVertex v27; + + // GEdge of outside tetrahedorn + GEdge e1; + GEdge e2; + GEdge e3; + GEdge e4; + GEdge e5; + GEdge e6; + + // GEdge of inside tetrahedron + GEdge e7; + GEdge e8; + GEdge e9; + GEdge e10; + GEdge e11; + GEdge e12; + + // GEdge of hole between inside tetrahedron and outside tetrahedron + GEdge e13; + GEdge e14; + GEdge e15; + GEdge e16; + GEdge e17; + GEdge e18; + GEdge e19; + GEdge e20; + GEdge e21; + GEdge e22; + GEdge e23; + GEdge e24; + + // GEdge of curved tetrahedron + final GEdge e25; + final GEdge e26; + final GEdge e27; + final GEdge e28; + final GEdge e29; + final GEdge e30; + + // GEdge of inside sphere + final GEdge e31; + final GEdge e32; + final GEdge e33; + final GEdge e34; + final GEdge e35; + final GEdge e36; + final GEdge e37; + final GEdge e38; + final GEdge e39; + final GEdge e40; + final GEdge e41; + final GEdge e42; + + // GFace of outside tetrahdron + GFace f1; + GFace f2; + GFace f3; + GFace f4; + + // GFace of inside tetrahedron + GFace f5; + GFace f6; + GFace f7; + GFace f8; + + // GFace of hole between inside tetrahderon and outside tetrahedron + GFace f9; + GFace f10; + GFace f11; + GFace f12; + + // GFace of curved tetrahedron + final GFace f15; + final GFace f16; + final GFace f17; + final GFace f18; + + // GFace of inside sphere + final GFace f19; + final GFace f20; + final GFace f21; + final GFace f22; + final GFace f23; + final GFace f24; + final GFace f25; + final GFace f26; + + // vector of Gedge used by definition of faces of outside teterahedon + final EdgeVector edg1 = new EdgeVector(); + final EdgeVector edg2 = new EdgeVector(); + final EdgeVector edg3 = new EdgeVector(); + final EdgeVector edg4 = new EdgeVector(); + + // vector of Gedge used by definition of faces of inside teterahedon + final EdgeVector edg5 = new EdgeVector(); + final EdgeVector edg6 = new EdgeVector(); + final EdgeVector edg7 = new EdgeVector(); + final EdgeVector edg8 = new EdgeVector(); + + // vector of Gedge used by definition of faces of hole between inside + // tetrahedron and outside teterahedon + final EdgeVector edg9 = new EdgeVector(); + final EdgeVector edg10 = new EdgeVector(); + final EdgeVector edg11 = new EdgeVector(); + final EdgeVector edg12 = new EdgeVector(); + final EdgeVector edg13 = new EdgeVector(); + final EdgeVector edg14 = new EdgeVector(); + + // vector of Gedge used by definition of faces of curved teterahedon + final EdgeVector edg15 = new EdgeVector(); + final EdgeVector edg16 = new EdgeVector(); + final EdgeVector edg17 = new EdgeVector(); + final EdgeVector edg18 = new EdgeVector(); + + // vector of Gedge used by definition of faces of inside sphere + final EdgeVector edg19 = new EdgeVector(); + final EdgeVector edg20 = new EdgeVector(); + final EdgeVector edg21 = new EdgeVector(); + final EdgeVector edg22 = new EdgeVector(); + final EdgeVector edg23 = new EdgeVector(); + final EdgeVector edg24 = new EdgeVector(); + final EdgeVector edg25 = new EdgeVector(); + final EdgeVector edg26 = new EdgeVector(); + + // vector of vector of Gedge used by definition of faces of outside + // teterahedon + final EdgeVectorOfVector edges1 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges2 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges3 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges4 = new EdgeVectorOfVector(); + + // vector of vector of Gedge used by definition of faces of inside + // teterahedon + final EdgeVectorOfVector edges5 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges6 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges7 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges8 = new EdgeVectorOfVector(); + + // vector of vector of Gedge used by definition of faces of hole between + // inside tetrahedron and outside + // teterahedon + final EdgeVectorOfVector edges9 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges10 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges11 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges12 = new EdgeVectorOfVector(); + + // vector of vector of Gedge used by definition of faces of curved + // teterahedon + final EdgeVectorOfVector edges15 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges16 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges17 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges18 = new EdgeVectorOfVector(); + + // vector of vector of Gedge used by definition of faces of inside + // sphere + final EdgeVectorOfVector edges19 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges20 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges21 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges22 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges23 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges24 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges25 = new EdgeVectorOfVector(); + final EdgeVectorOfVector edges26 = new EdgeVectorOfVector(); + + // outside tetrahedron minus inside tetrahedron + GRegion r1; + // GRegion of curved tetrahedre minus inside sphere + final GRegion r2; + + // vector of GFace used to define the volume outside tetrahedron minus + // inside tetrahedron minus hole between them + final FaceVector fce1 = new FaceVector(); + // vector of GFace used to define the volume curved tetrahedron + final FaceVector fce2 = new FaceVector(); + // vector of GFace used to define the volume inside sphere + final FaceVector fce3 = new FaceVector(); + + // vector of vector of GFace used to define the volume defined by the + // outside tetrahedron minus the inside tetrahedron minus the hole + // between them + final FaceVectorOfVector faces1 = new FaceVectorOfVector(); + + // vector of vector of GFace used to define the volume defined by the + // curved tetrahedron minus the inside sphere + final FaceVectorOfVector faces2 = new FaceVectorOfVector(); + + // -----------------------------------------------------------------------// + // creation of geometric elements + // -----------------------------------------------------------------------// + + // // VERTEX + + // creation of vertices of outside tetrahedron + v1 = gFact.addVertex(m, x1, y1, z1, lc1); + v2 = gFact.addVertex(m, x2, y2, z2, lc2); + v3 = gFact.addVertex(m, x3, y3, z3, lc3); + v4 = gFact.addVertex(m, x4, y4, z4, lc4); + + // creation of vertices of inside tetrahedron + v5 = gFact.addVertex(m, x5, y5, z5, lc5); + v6 = gFact.addVertex(m, x6, y6, z6, lc6); + v7 = gFact.addVertex(m, x7, y7, z7, lc7); + v8 = gFact.addVertex(m, x8, y8, z8, lc8); + + // creation of vertices of hole between inside tetrahedron and inside + // tetrahedron + v9 = gFact.addVertex(m, x9, y9, z9, lc9); + v10 = gFact.addVertex(m, x10, y10, z10, lc10); + v11 = gFact.addVertex(m, x11, y11, z11, lc11); + v12 = gFact.addVertex(m, x12, y12, z12, lc12); + v13 = gFact.addVertex(m, x13, y13, z13, lc13); + v14 = gFact.addVertex(m, x14, y14, z14, lc14); + v15 = gFact.addVertex(m, x15, y15, z15, lc15); + v16 = gFact.addVertex(m, x16, y16, z16, lc16); + + // creation of vertices of curved tetrahedron + v17 = gFact.addVertex(m, x17, y17, z17, lc17); + v18 = gFact.addVertex(m, x18, y18, z18, lc18); + v19 = gFact.addVertex(m, x19, y19, z19, lc19); + v20 = gFact.addVertex(m, x20, y20, z20, lc20); + + // creation of vertices of inside sphere + v21 = gFact.addVertex(m, x21, y21, z21, lc21); + v22 = gFact.addVertex(m, x22, y22, z22, lc22); + v23 = gFact.addVertex(m, x23, y23, z23, lc23); + v24 = gFact.addVertex(m, x24, y24, z24, lc24); + v25 = gFact.addVertex(m, x25, y25, z25, lc25); + v26 = gFact.addVertex(m, x26, y26, z26, lc26); + v27 = gFact.addVertex(m, x27, y27, z27, lc27); + + // // definition of "physical property" for all points + + // 3 "physicals" for outside tetrahedron minus inside tetrahdron minus + // hole between them + + // compute the first vertex tag + tag = v1.tag(); + + // add tag computed to first physical + WrapGmsh.List_Add(lst1, tag); + + // add tag computed to second physical, so the first vertex own 2 + // physicals + WrapGmsh.List_Add(lst2, tag); + + // add tag computed to second physical, so the first vertex own 3 + // physicals + WrapGmsh.List_Add(lst3, tag); + tag = v2.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v3.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v4.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v5.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v6.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v7.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v8.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v9.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v10.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v11.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v12.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v13.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v14.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v15.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = v16.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + + // add all tags defines in the first physical in the GModel + WrapGmsh.add_physical(str, lst1, m.getFileName()); + + WrapGmsh.add_physical(str, lst2, m.getFileName()); + WrapGmsh.add_physical(str, lst3, m.getFileName()); + + // delete what is in the List + WrapGmsh.List_Reset(lst1); + WrapGmsh.List_Reset(lst2); + WrapGmsh.List_Reset(lst3); + + // same action about curved tetrahedron minus inside sphere + tag = v17.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v18.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v19.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v20.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v21.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v22.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v23.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v24.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v25.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = v26.tag(); + WrapGmsh.List_Add(lst4, tag); + + WrapGmsh.add_physical(str, lst4, m.getFileName()); + WrapGmsh.List_Reset(lst4); + + // //LINE + + // creation of edges of outside tetrahedron + e1 = gFact.addLine(m, v2, v1); + e2 = gFact.addLine(m, v3, v1); + e3 = gFact.addLine(m, v1, v4); + e4 = gFact.addLine(m, v3, v2); + e5 = gFact.addLine(m, v2, v4); + e6 = gFact.addLine(m, v4, v3); + + // creation of edges of inside tetrahedron + e7 = gFact.addLine(m, v5, v6); + e8 = gFact.addLine(m, v5, v8); + e9 = gFact.addLine(m, v5, v7); + e10 = gFact.addLine(m, v6, v7); + e11 = gFact.addLine(m, v7, v8); + e12 = gFact.addLine(m, v6, v8); + + // creation of edges of hole between outside tetrahedron and insde + // tetrahedron + e13 = gFact.addLine(m, v9, v10); + e14 = gFact.addLine(m, v10, v11); + e15 = gFact.addLine(m, v11, v12); + e16 = gFact.addLine(m, v9, v12); + e17 = gFact.addLine(m, v12, v16); + e18 = gFact.addLine(m, v11, v15); + e19 = gFact.addLine(m, v10, v14); + e20 = gFact.addLine(m, v9, v13); + e21 = gFact.addLine(m, v13, v16); + e22 = gFact.addLine(m, v13, v14); + e23 = gFact.addLine(m, v14, v15); + e24 = gFact.addLine(m, v15, v16); + + // creation of edges of curved tetrahedron + e25 = gFact.addLine(m, v18, v20); + e26 = gFact.addLine(m, v19, v20); + + // define a curved between v18 and v19, and v20 is the center + e27 = gFact.addCircleArc(m, v18, v20, v19); + e28 = gFact.addLine(m, v17, v20); + e29 = gFact.addCircleArc(m, v17, v20, v19); + e30 = gFact.addCircleArc(m, v17, v20, v18); + + // creation of edges of inside tetrahedron + e31 = gFact.addCircleArc(m, v21, v27, v25); + e32 = gFact.addCircleArc(m, v22, v27, v25); + e33 = gFact.addCircleArc(m, v23, v27, v25); + e34 = gFact.addCircleArc(m, v24, v27, v25); + e35 = gFact.addCircleArc(m, v21, v27, v26); + e36 = gFact.addCircleArc(m, v22, v27, v26); + e37 = gFact.addCircleArc(m, v23, v27, v26); + e38 = gFact.addCircleArc(m, v24, v27, v26); + e39 = gFact.addCircleArc(m, v21, v27, v22); + e40 = gFact.addCircleArc(m, v21, v27, v24); + e41 = gFact.addCircleArc(m, v23, v27, v24); + e42 = gFact.addCircleArc(m, v23, v27, v22); + + // // definition of physical for edges + + // definition of 3 physicals for outside tetrahedron minus inside + // tetrahedron minus hole between them + + tag = e1.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e2.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e3.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e4.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e5.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e6.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e7.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e8.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e9.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e10.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e11.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e12.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e13.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e14.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e15.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e16.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e17.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e18.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e19.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e20.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e21.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e22.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e23.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = e24.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + + WrapGmsh.add_physical(str1, lst1, m.getFileName()); + WrapGmsh.add_physical(str1, lst2, m.getFileName()); + WrapGmsh.add_physical(str1, lst3, m.getFileName()); + WrapGmsh.List_Reset(lst1); + WrapGmsh.List_Reset(lst2); + WrapGmsh.List_Reset(lst3); + + // same actions about curved tetrahedron minus inside sphere + + tag = e25.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e26.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e27.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e28.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e29.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e30.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e31.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e32.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e33.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e34.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e35.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e36.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e37.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e38.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e39.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e40.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e41.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = e42.tag(); + WrapGmsh.List_Add(lst4, tag); + + WrapGmsh.add_physical(str1, lst4, m.getFileName()); + WrapGmsh.List_Reset(lst4); + + // //FACE + // // A face is defined by a vector of vector of edges because it is + // possible to define faces with holes. + + // -------------------- + // definition of first face of outside tetrahedron + edg1.add(e2); + edg1.add(e3); + edg1.add(e6); + + // definition of second face of outside tetrahedron + edg2.add(e2); + edg2.add(e4); + edg2.add(e1); + + // definition of third face of outside tetrahedron + edg3.add(e4); + edg3.add(e5); + edg3.add(e6); + + // definition of fourth face of outside tetrahedron + edg4.add(e1); + edg4.add(e5); + edg4.add(e3); + + // -------------------- + // definition of first face of inside tetrahedron + edg5.add(e8); + edg5.add(e9); + edg5.add(e11); + + // definition of second face of inside tetrahedron + edg6.add(e10); + edg6.add(e11); + edg6.add(e12); + + // definition of third face of inside tetrahedron + edg7.add(e7); + edg7.add(e9); + edg7.add(e10); + + // definition of fourth face of inside tetrahedron + edg8.add(e7); + edg8.add(e8); + edg8.add(e12); + + // -------------------- + // definition of first face of hole between inside tetrahdron and + // outside tetrahedron (it is a cube) + edg9.add(e16); + edg9.add(e13); + edg9.add(e14); + edg9.add(e15); + + // definition of second face of hole between inside tetrahdron and + // outside tetrahedron (it is a cube) + edg10.add(e16); + edg10.add(e17); + edg10.add(e20); + edg10.add(e21); + + // definition of third face of hole between inside tetrahdron and + // outside tetrahedron (it is a cube) + edg11.add(e15); + edg11.add(e17); + edg11.add(e18); + edg11.add(e24); + + // definition of fourth face of hole between inside tetrahdron and + // outside tetrahedron (it is a cube) + edg12.add(e14); + edg12.add(e18); + edg12.add(e19); + edg12.add(e23); + + // definition of fifth face of hole between inside tetrahdron and + // outside tetrahedron (it is a cube) + edg13.add(e13); + edg13.add(e19); + edg13.add(e20); + edg13.add(e22); + + // definition of sixth face of hole between inside tetrahdron and + // outside tetrahedron (it is a cube) + edg14.add(e21); + edg14.add(e22); + edg14.add(e23); + edg14.add(e24); + + // -------------------- + // definition of first face of curved tetrahdron + edg15.add(e25); + edg15.add(e28); + edg15.add(e30); + + // definition of second face of curved tetrahdron + edg16.add(e26); + edg16.add(e28); + edg16.add(e29); + + // definition of third face of curved tetrahdron + edg17.add(e25); + edg17.add(e26); + edg17.add(e27); + + // definition of fourth face of curved tetrahdron + edg18.add(e27); + edg18.add(e29); + edg18.add(e30); + + // -------------------- + // definition of first face of inside tetrahdron + edg19.add(e31); + edg19.add(e32); + edg19.add(e39); + + // definition of second face of inside tetrahdron + edg20.add(e32); + edg20.add(e33); + edg20.add(e42); + + // definition of third face of inside tetrahdron + edg21.add(e33); + edg21.add(e34); + edg21.add(e41); + + // definition of fourth face of inside tetrahdron + edg22.add(e34); + edg22.add(e31); + edg22.add(e40); + + // -------------------------- + // definition of first face of inside sphere + edg23.add(e39); + edg23.add(e35); + edg23.add(e36); + + // definition of second face of inside sphere + edg24.add(e35); + edg24.add(e38); + edg24.add(e40); + + // definition of third face of inside sphere + edg25.add(e37); + edg25.add(e38); + edg25.add(e41); + + // definition of fourth face of inside sphere + edg26.add(e36); + edg26.add(e37); + edg26.add(e42); + + // -------------------- + // definition of first face with hole of outside tetrahedron + edges1.add(edg1); + edges1.add(edg9); + // definition of second face of outside tetrahedron + edges2.add(edg2); + // definition of third face of outside tetrahedron + edges3.add(edg3); + // definition of fourth face of outside tetrahedron + edges4.add(edg4); + + // -------------------- + // definition of first face with hole of inside tetrahedron + edges5.add(edg5); + edges5.add(edg14); + // definition of second face of inside tetrahedron + edges6.add(edg6); + // definition of third face of inside tetrahedron + edges7.add(edg7); + // definition of fourth face of inside tetrahedron + edges8.add(edg8); + + // -------------------- + // definition of first face of hole between outside tetrahdron and + // inside tetrahdron + edges9.add(edg10); + // definition of second face of hole between outside tetrahdron and + // inside tetrahdron + edges10.add(edg11); + // definition of third face of hole between outside tetrahdron and + // inside tetrahdron + edges11.add(edg12); + // definition of fourth face of hole between outside tetrahdron and + // inside tetrahdron + edges12.add(edg13); + + // -------------------- + // definition of first face of curved tetrahedron + edges15.add(edg15); + // definition of second face of curved tetrahedron + edges16.add(edg16); + // definition of third face of curved tetrahedron + edges17.add(edg17); + // definition of fourth face of curved tetrahedron + edges18.add(edg18); + + // -------------------- + // definition of the first face of inside sphere + edges19.add(edg19); + // definition of the second face of inside sphere + edges20.add(edg20); + // definition of the third face of inside sphere + edges21.add(edg21); + // definition of the fourth face of inside sphere + edges22.add(edg22); + // definition of the fifith face of inside sphere + edges23.add(edg23); + // definition of the sixth face of inside sphere + edges24.add(edg24); + // definition of the seventh face of inside sphere + edges25.add(edg25); + // definition of the eighth face of inside sphere + edges26.add(edg26); + + // creation of faces of outside tetrahedron + f1 = gFact.addPlanarFace(m, edges1); + f2 = gFact.addPlanarFace(m, edges2); + f3 = gFact.addPlanarFace(m, edges3); + f4 = gFact.addPlanarFace(m, edges4); + + // creation of faces of inside tetrahedron + f5 = gFact.addPlanarFace(m, edges5); + f6 = gFact.addPlanarFace(m, edges6); + f7 = gFact.addPlanarFace(m, edges7); + f8 = gFact.addPlanarFace(m, edges8); + + // creation of faces of hole betwxeen inside and outside tetrahdron + f9 = gFact.addPlanarFace(m, edges9); + f10 = gFact.addPlanarFace(m, edges10); + f11 = gFact.addPlanarFace(m, edges11); + f12 = gFact.addPlanarFace(m, edges12); + + // creation of faces of curved tetrahedron + f15 = gFact.addPlanarFace(m, edges15); + f16 = gFact.addPlanarFace(m, edges16); + f17 = gFact.addPlanarFace(m, edges17); + f18 = gFact.addIncurvedFace(m, edges18); + + // creation of faces of curved tetrahedron + f19 = gFact.addIncurvedFace(m, edges19); + f20 = gFact.addIncurvedFace(m, edges20); + f21 = gFact.addIncurvedFace(m, edges21); + f22 = gFact.addIncurvedFace(m, edges22); + f23 = gFact.addIncurvedFace(m, edges23); + f24 = gFact.addIncurvedFace(m, edges24); + f25 = gFact.addIncurvedFace(m, edges25); + f26 = gFact.addIncurvedFace(m, edges26); + + // //definition of physical for faces + + // 3 physicals for the outside tetraherdon minus inside tetrahdron minus + // hole between them + + tag = f1.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f2.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f3.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f4.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f5.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f6.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f7.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f8.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f9.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f10.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f11.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + tag = f12.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + + WrapGmsh.add_physical(str2, lst1, m.getFileName()); + WrapGmsh.add_physical(str2, lst2, m.getFileName()); + WrapGmsh.add_physical(str2, lst3, m.getFileName()); + WrapGmsh.List_Reset(lst1); + WrapGmsh.List_Reset(lst2); + WrapGmsh.List_Reset(lst3); + + // same actions about curved tetrahedron minus inside sphere + + tag = f15.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f16.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f17.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f18.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f19.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f20.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f21.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f22.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f23.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f24.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f25.tag(); + WrapGmsh.List_Add(lst4, tag); + tag = f26.tag(); + WrapGmsh.List_Add(lst4, tag); + + WrapGmsh.add_physical(str2, lst4, m.getFileName()); + WrapGmsh.List_Reset(lst4); + + // //VOLUME + // //same approach as creation of faces but in a superior dimension + + // outside tetraheron + fce1.add(f1); + fce1.add(f2); + fce1.add(f3); + fce1.add(f4); + + // inside tetrahedron + fce1.add(f5); + fce1.add(f6); + fce1.add(f7); + fce1.add(f8); + + // hole between outside tetrahedron and inside tetrahdron + fce1.add(f9); + fce1.add(f10); + fce1.add(f11); + fce1.add(f12); + + // curved tetrahdron + fce2.add(f15); + fce2.add(f16); + fce2.add(f17); + fce2.add(f18); + + // inside sphere + fce3.add(f19); + fce3.add(f20); + fce3.add(f21); + fce3.add(f22); + fce3.add(f23); + fce3.add(f24); + fce3.add(f25); + fce3.add(f26); + + // outside tetrahedron minus inside tetrahedron minus hole between them + faces1.add(fce1); + + // // curved tetrahedron minus inside sphere + faces2.add(fce2); + faces2.add(fce3); + + // outside tetrahedron minus inside tetrahedron minus hole between them + r1 = gFact.addVolume(m, faces1); + // // curved tetrahedron minus inside sphere + r2 = gFact.addVolume(m, faces2); + + // //definition of physical for volumes + + // 3 "physicals" for the outside tetrhedron minus the inside tetrahdron + // minus the hole between them. + tag = r1.tag(); + WrapGmsh.List_Add(lst1, tag); + WrapGmsh.List_Add(lst2, tag); + WrapGmsh.List_Add(lst3, tag); + + WrapGmsh.add_physical(str3, lst1, m.getFileName()); + WrapGmsh.add_physical(str3, lst2, m.getFileName()); + WrapGmsh.add_physical(str3, lst3, m.getFileName()); + WrapGmsh.List_Reset(lst1); + WrapGmsh.List_Reset(lst2); + WrapGmsh.List_Reset(lst3); + + // // 1 "physical" for curved tetrahedron minus the inside sphere + // + tag = r2.tag(); + WrapGmsh.List_Add(lst4, tag); + + WrapGmsh.add_physical(str3, lst4, m.getFileName()); + WrapGmsh.List_Reset(lst4); + + // write .geo file which contains the geomtry defined before + m.writeGEO("test.geo"); + + // mesh the geometry defined in the GModel m + m.mesh(3); + + // write .msh file which contains informations about mesh in GModel m. + m.writeMSH("meshtest.msh"); + + // read mesh elements produced by m.mesh(3) + System.out.println("$MeshFormat"); + System.out.println("2.2 0 8"); + System.out.println("$EndMeshFormat"); + System.out.println("$Nodes"); + // boolean which indicates if all elements are meshed + final boolean all = m.noPhysicalGroups(); + // number of nodes which is defined in mesh + System.out.println(m.indexMeshVertices(all, 0)); + + final GEntityVector entities = new GEntityVector(); + m.getEntities(entities); + for (int i = 0; i < entities.size(); i++) { + for (int j = 0; j < entities.get(i).getMesh_vertices().size(); j++) { + final int index = entities.get(i).getMesh_vertices().get(j).getIndex(); + + // if index <0 then there is not physical + if (index >= 0) { + final double x = entities.get(i).getMesh_vertices().get(j).x(); + final double y = entities.get(i).getMesh_vertices().get(j).y(); + final double z = entities.get(i).getMesh_vertices().get(j).z(); + + System.out.println(index + " " + x + " " + y + " " + z); + + } + + } + } + + System.out.println("$EndNodes"); + System.out.println("$Elements"); + // number of elements which is defined in mesh + //System.out.println(WrapGmsh.getNumElementsMSH(m, all, 0)); + + int iter = 1; + + // point + final GVertexVector bindingsGetVertices = m.bindingsGetVertices(); + for (int indexVertex = 0; indexVertex < bindingsGetVertices.size(); indexVertex++) { + final GVertex it = bindingsGetVertices.get(indexVertex); + for (int k = 0; k < it.getPoints().size(); k++) { + for (int j = 0; j < it.getPhysicals().size(); j++) { + final int physical = it.getPhysicals().get(j); + + final MPoint mPt = it.getPoints().get(k); + + final int type = mPt.getTypeForMSH(); + + final IntVector verts = new IntVector(); + + mPt.getVerticesIdForMSH(verts); + + // 1 is the number of physical which is associated with the + // element. + // there is always 1 but it is possible to write several + // times the same line but with a different physical. This + // is the logical used by gmsh but in reality it is 2 + // because there is the physical AND the elemnentary. For + // more information see the gmsh documentation + System.out.println(iter + " " + type + " 1 " + physical + " " + verts.get(0)); + + iter++; + } + } + } + + // edges + + final EdgeVector bindingsGetEdges = m.bindingsGetEdges(); + for (int indexEdges = 0; indexEdges < bindingsGetEdges.size(); indexEdges++) { + final GEdge it = bindingsGetEdges.get(indexEdges); + for (int j = 0; j < it.getLines().size(); j++) { + for (int k = 0; k < it.getPhysicals().size(); k++) { + final int physical = it.getPhysicals().get(k); + + final MLine mLine = it.getLines().get(j); + + final int type = mLine.getTypeForMSH(); + + final IntVector verts = new IntVector(); + + mLine.getVerticesIdForMSH(verts); + System.out.println(iter + " " + type + " 1 " + physical + " " + verts.get(0) + " " + verts.get(1)); + + iter++; + } + } + } + + // triangles + + final FaceVector bindingsGetFaces = m.bindingsGetFaces(); + for (int indexFace = 0; indexFace < bindingsGetFaces.size(); indexFace++) { + final GFace it = bindingsGetFaces.get(indexFace); + for (int j = 0; j < it.getTriangles().size(); j++) { + for (int k = 0; k < it.getPhysicals().size(); k++) { + final int physical = it.getPhysicals().get(k); + + final MTriangle mTriangle = it.getTriangles().get(j); + + final int type = mTriangle.getTypeForMSH(); + final IntVector verts = new IntVector(); + mTriangle.getVerticesIdForMSH(verts); + System.out.println(iter + " " + type + " 1 " + physical + " " + verts.get(0) + " " + verts.get(1) + " " + verts.get(2)); + + iter++; + + } + } + } + + // tetrahedron + + final RegionVector bindingsGetRegions = m.bindingsGetRegions(); + + for (int indexRegion = 0; indexRegion < bindingsGetRegions.size(); indexRegion++) { + final GRegion it = bindingsGetRegions.get(indexRegion); + for (int j = 0; j < it.getTetrahedra().size(); j++) { + for (int k = 0; k < it.getPhysicals().size(); k++) { + final int physical = it.getPhysicals().get(k); + + final MTetrahedron mTetrahedron = it.getTetrahedra().get(j); + + final int type = mTetrahedron.getTypeForMSH(); + + final IntVector verts = new IntVector(); + mTetrahedron.getVerticesIdForMSH(verts); + System.out + .println(iter + " " + type + " 1 " + physical + " " + verts.get(0) + " " + verts.get(1) + " " + verts.get(2) + " " + verts.get(3)); + + iter++; + } + } + } + System.out.println("$EndElements"); + + WrapGmsh.GmshFinalize(); + + } + +} + diff --git a/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v2.java b/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v2.java new file mode 100755 index 0000000000..190f63f4f2 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/com/artenum/sample/EssaiGmsh_v2.java @@ -0,0 +1,59 @@ + /** + * Project : Java Wrapping of Gmsh + * Copyright : see Gmsh Copyright + * License : see Gmsh License + * Contrat number : internal Artenum development + * Developed by: Artenum SARL + * Creation : august 2011 + * authors : Benjamin JEANTY-RUARD - Artenum + * Status : final + */ + + + + +package com.artenum.sample; + +import org.geuz.gmsh.generated.GModel; +import org.geuz.gmsh.generated.WrapGmsh; + +/** + * This class is an example of use of Gmsh wrapping in Java. + * + * @author benjamin jeanty-ruard + * + */ +public class EssaiGmsh_v2 { + + static { + try { + System.loadLibrary("WrapGmsh"); + } catch (final UnsatisfiedLinkError e) { + System.err + .println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + + } + + public static void main(final String[] args) { + + // initialization of gmsh + WrapGmsh.GmshInitialize(0, null); + + final GModel m1 = new GModel(); + + // import information contained in .geo file inside GModel m1 + GModel.readGEO("t5.geo"); + + // mesh the geometry defined in the GModel m + m1.mesh(3); + + // write .msh file which contains informations about mesh in GModel m. + m1.writeMSH("t5.msh"); + + WrapGmsh.GmshFinalize(); + + } + +} diff --git a/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeList.java b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeList.java new file mode 100644 index 0000000000..921ff17ca3 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeList.java @@ -0,0 +1,113 @@ +package org.geuz.gmsh.utils; + +import java.lang.reflect.Method; +import java.util.AbstractList; +import java.util.List; + +/** + * Wrapper for std::vector from SWIG + * + * @author Chad Retz + * + * @param <T> + */ +public class NativeList<T> extends AbstractList<T> implements List<T> { + + private final Object listWrapper; + private final Method sizeMethod; + private final Method addMethod; + private final Method clearMethod; + private final Method setMethod; + private final Method removeMethod; + private final Method getMethod; + + /** + * Construct native list from std::vector wrappers + * + * @param nativeClass The native class + * @param nativeList The SWIG vector + * @param listWrapperClass The SWIG vector class wrapper + */ + public NativeList(Class<T> nativeClass, Object nativeList, Class<?> listWrapperClass) { + try { + listWrapper = listWrapperClass.getConstructor(nativeList.getClass()). + newInstance(nativeList); + sizeMethod = listWrapperClass.getDeclaredMethod("size"); + addMethod = listWrapperClass.getDeclaredMethod("add", + Integer.TYPE, nativeClass); + clearMethod = listWrapperClass.getDeclaredMethod("clear"); + setMethod = listWrapperClass.getDeclaredMethod("set", + Integer.TYPE, nativeClass); + removeMethod = listWrapperClass.getDeclaredMethod("remove", Integer.TYPE); + getMethod = listWrapperClass.getDeclaredMethod("get", Integer.TYPE); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void add(int index, T item) { + try { + addMethod.invoke(listWrapper, index, item); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void clear() { + try { + clearMethod.invoke(listWrapper); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + @SuppressWarnings("unchecked") + public T set(int index, T item) { + try { + return (T) setMethod.invoke(listWrapper, index, item); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + @SuppressWarnings("unchecked") + public T remove(int index) { + try { + return (T) removeMethod.invoke(listWrapper, index); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean remove(Object item) { + try { + return (Boolean) removeMethod.invoke(listWrapper, item); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + @SuppressWarnings("unchecked") + public T get(int index) { + try { + return (T) getMethod.invoke(listWrapper, index); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public int size() { + try { + return (Integer) sizeMethod.invoke(listWrapper); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeSet.java b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeSet.java new file mode 100644 index 0000000000..5a978a8acc --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/NativeSet.java @@ -0,0 +1,176 @@ +package org.geuz.gmsh.utils; + +import java.lang.reflect.Method; +import java.util.AbstractSet; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * Wrapper for std::set and std::list from SWIG. This does not support removal + * during iteration. + * + * @author Chad Retz + * + * @param <T> + */ +public class NativeSet<T> extends AbstractSet<T> implements Set<T> { + + private final Class<T> nativeClass; + private final Class<?> setIteratorClass; + private final Object nativeSet; + private final Object setWrapper; + private final Method sizeMethod; + private final Method containsMethod; + private final Method addMethod; + private final Method clearMethod; + private final Method removeMethod; + private final Method hasNextMethod; + private final Method nextMethod; + + /** + * Instantiate the native set + * + * @param nativeClass + * The native class + * @param setIteratorClass + * The class for the SetIterator + * @param nativeSet + * The native set object + * @param setWrapperClass + * The class for the Set + */ + public NativeSet(final Class<T> nativeClass, final Class<?> setIteratorClass, final Object nativeSet, final Class<?> setWrapperClass) { + this.nativeClass = nativeClass; + this.setIteratorClass = setIteratorClass; + this.nativeSet = nativeSet; + try { + this.setWrapper = setWrapperClass.getConstructor(nativeSet.getClass()).newInstance(nativeSet); + this.sizeMethod = setWrapperClass.getDeclaredMethod("size"); + this.containsMethod = setWrapperClass.getDeclaredMethod("contains", nativeClass); + this.addMethod = setWrapperClass.getDeclaredMethod("add", nativeClass); + this.clearMethod = setWrapperClass.getDeclaredMethod("clear"); + this.removeMethod = setWrapperClass.getDeclaredMethod("remove", nativeClass); + this.hasNextMethod = setIteratorClass.getDeclaredMethod("hasNext"); + this.nextMethod = setIteratorClass.getDeclaredMethod("next"); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean add(final T item) { + try { + return (Boolean) this.addMethod.invoke(this.setWrapper, item); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void clear() { + try { + this.clearMethod.invoke(this.setWrapper); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean contains(final Object item) { + try { + return this.nativeClass.isAssignableFrom(item.getClass()) && (Boolean) this.containsMethod.invoke(this.setWrapper, item); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public Iterator<T> iterator() { + return new NativeSetIterator(); + } + + @Override + public boolean remove(final Object item) { + try { + return (Boolean) this.removeMethod.invoke(this.setWrapper, item); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean removeAll(final Collection<?> collection) { + boolean modified = false; + for (final Object item : collection) { + modified |= this.remove(item); + } + return modified; + } + + @Override + public boolean retainAll(final Collection<?> collection) { + // best way? + final List<T> toRemove = new ArrayList<T>(this.size()); + for (final T item : this) { + if (!collection.contains(item)) { + toRemove.add(item); + } + } + return this.removeAll(toRemove); + } + + @Override + public int size() { + try { + return (Integer) this.sizeMethod.invoke(this.setWrapper); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + protected class NativeSetIterator implements Iterator<T> { + + private final Object setIterator; + + private NativeSetIterator() { + try { + this.setIterator = NativeSet.this.setIteratorClass.getConstructor(NativeSet.this.nativeSet.getClass()).newInstance(NativeSet.this.nativeSet); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean hasNext() { + try { + return (Boolean) NativeSet.this.hasNextMethod.invoke(this.setIterator); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + @Override + @SuppressWarnings("unchecked") + public T next() { + try { + return (T) NativeSet.this.nextMethod.invoke(this.setIterator); + } catch (final Exception e) { + throw new RuntimeException(e); + } + } + + /** + * {@inheritDoc} + * <p> + * Unsupported + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + } +} diff --git a/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/listWrapperGmsh.h b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/listWrapperGmsh.h new file mode 100644 index 0000000000..2e02e57b3c --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/listWrapperGmsh.h @@ -0,0 +1,78 @@ +#pragma once +#include <list> + +template<class T> +class ListWrapperGmsh +{ +public: + std::list<T>* _list; + ListWrapperGmsh(std::list<T>* original) + { + this->_list = original; + } + + ~ListWrapperGmsh() + { + } + + int size() + { + return this->_list->size(); + } + + bool contains(T item) + { + typename std::list<T>::iterator iter; + for(iter = this->_list->begin(); + iter != this->_list->end(); iter++) { + if (*iter == item) { + return true; + } + } + return false; + } + + bool add(T item) + { + this->_list->push_back(item); + return true; + } + + void clear() + { + this->_list->clear(); + } + + bool remove(T item) + { + int size = this->_list->size(); + this->_list->remove(item); + return size != this->_list->size(); + } +}; + +template<class T> +class ListIteratorGmsh +{ +private: + std::list<T>* _list; + typename std::list<T>::const_iterator _iter; +public: + ListIteratorGmsh(std::list<T>* original) + { + this->_list = original; + this->_iter = this->_list->begin(); + } + + bool hasNext() + { + return this->_iter != this->_list->end(); + } + + T next() + { + T ret = (T) *this->_iter; + this->_iter++; + return ret; + } +}; diff --git a/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/setWrapperGmsh.h b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/setWrapperGmsh.h new file mode 100644 index 0000000000..5c37aa8449 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/org/geuz/gmsh/utils/setWrapperGmsh.h @@ -0,0 +1,77 @@ +#pragma once +#include <set> + +template<class T, class U> +class SetWrapperGmsh +{ +private: + std::set<T, U>* _set; +public: + +// std::set<T>::iterator iterType; + SetWrapperGmsh(std::set<T, U>* original) + { + this->_set = original; + } + + ~SetWrapperGmsh() + { + } + + int size() + { + return this->_set->size(); + } + + bool contains(T item) + { +// std::set<T>::iterator iter= this->_set->find(item); + return this->_set->find(item) != this->_set->end(); + } + + bool add(T item) + { + return this->_set->insert(item).second; + } + + void clear() + { + this->_set->clear(); + } + + bool remove(T item) + { + if (this->_set->find(item) != this->_set->end()) { + this->_set->erase(this->_set->find(item)); + return true; + } else { + return false; + } + } +}; + +template<class T, class U> +class SetIteratorGmsh +{ +private: + std::set<T, U>* _set; + typename std::set<T, U>::iterator _iter; +public: + SetIteratorGmsh(std::set<T, U>* original) + { + this->_set = original; + this->_iter = this->_set->begin(); + } + + bool hasNext() + { + return this->_iter != this->_set->end(); + } + + T next() + { + T ret = (T) *this->_iter; + this->_iter++; + return ret; + } +}; diff --git a/wrappers/java/WrappingJava/src/main/java/t5.geo b/wrappers/java/WrappingJava/src/main/java/t5.geo new file mode 100644 index 0000000000..4f924457c6 --- /dev/null +++ b/wrappers/java/WrappingJava/src/main/java/t5.geo @@ -0,0 +1,166 @@ +/********************************************************************* + * + * Gmsh tutorial 5 + * + * Characteristic lengths, arrays of variables, functions, loops + * + *********************************************************************/ + +// We start by defining some target mesh sizes: + +lcar1 = .1; +lcar2 = .0005; +lcar3 = .055; + +// If we wanted to change these mesh sizes globally (without changing +// the above definitions), we could give a global scaling factor for +// all characteristic lengths on the command line with the `-clscale' +// option (or with `Mesh.CharacteristicLengthFactor' in an option +// file). For example, with: +// +// > gmsh t5.geo -clscale 1 +// +// this input file produces a mesh of approximately 1,300 nodes and +// 11,000 tetrahedra. With +// +// > gmsh t5.geo -clscale 0.2 +// +// the mesh counts approximately 350,000 nodes and 2.1 million +// tetrahedra. You can check mesh statistics in the graphical user +// interface with the `Tools->Statistics' menu. + +// We proceed by defining some elementary entities describing a +// truncated cube: + +Point(1) = {0.5,0.5,0.5,lcar2}; Point(2) = {0.5,0.5,0,lcar1}; +Point(3) = {0,0.5,0.5,lcar1}; Point(4) = {0,0,0.5,lcar1}; +Point(5) = {0.5,0,0.5,lcar1}; Point(6) = {0.5,0,0,lcar1}; +Point(7) = {0,0.5,0,lcar1}; Point(8) = {0,1,0,lcar1}; +Point(9) = {1,1,0,lcar1}; Point(10) = {0,0,1,lcar1}; +Point(11) = {0,1,1,lcar1}; Point(12) = {1,1,1,lcar1}; +Point(13) = {1,0,1,lcar1}; Point(14) = {1,0,0,lcar1}; + +Line(1) = {8,9}; Line(2) = {9,12}; Line(3) = {12,11}; +Line(4) = {11,8}; Line(5) = {9,14}; Line(6) = {14,13}; +Line(7) = {13,12}; Line(8) = {11,10}; Line(9) = {10,13}; +Line(10) = {10,4}; Line(11) = {4,5}; Line(12) = {5,6}; +Line(13) = {6,2}; Line(14) = {2,1}; Line(15) = {1,3}; +Line(16) = {3,7}; Line(17) = {7,2}; Line(18) = {3,4}; +Line(19) = {5,1}; Line(20) = {7,8}; Line(21) = {6,14}; + +Line Loop(22) = {-11,-19,-15,-18}; Plane Surface(23) = {22}; +Line Loop(24) = {16,17,14,15}; Plane Surface(25) = {24}; +Line Loop(26) = {-17,20,1,5,-21,13}; Plane Surface(27) = {26}; +Line Loop(28) = {-4,-1,-2,-3}; Plane Surface(29) = {28}; +Line Loop(30) = {-7,2,-5,-6}; Plane Surface(31) = {30}; +Line Loop(32) = {6,-9,10,11,12,21}; Plane Surface(33) = {32}; +Line Loop(34) = {7,3,8,9}; Plane Surface(35) = {34}; +Line Loop(36) = {-10,18,-16,-20,4,-8}; Plane Surface(37) = {36}; +Line Loop(38) = {-14,-13,-12,19}; Plane Surface(39) = {38}; + +// Instead of using included files, we now use a user-defined function +// in order to carve some holes in the cube: + +Function CheeseHole + + // In the following commands we use the reserved variable name + // `newp', which automatically selects a new point number. This + // number is chosen as the highest current point number, plus + // one. (Note that, analogously to `newp', the variables `newc', + // `news', `newv' and `newreg' select the highest number amongst + // currently defined curves, surfaces, volumes and `any entities + // other than points', respectively.) + + p1 = newp; Point(p1) = {x, y, z, lcar3} ; + p2 = newp; Point(p2) = {x+r,y, z, lcar3} ; + p3 = newp; Point(p3) = {x, y+r,z, lcar3} ; + p4 = newp; Point(p4) = {x, y, z+r,lcar3} ; + p5 = newp; Point(p5) = {x-r,y, z, lcar3} ; + p6 = newp; Point(p6) = {x, y-r,z, lcar3} ; + p7 = newp; Point(p7) = {x, y, z-r,lcar3} ; + + c1 = newreg; Circle(c1) = {p2,p1,p7}; + c2 = newreg; Circle(c2) = {p7,p1,p5}; + c3 = newreg; Circle(c3) = {p5,p1,p4}; + c4 = newreg; Circle(c4) = {p4,p1,p2}; + c5 = newreg; Circle(c5) = {p2,p1,p3}; + c6 = newreg; Circle(c6) = {p3,p1,p5}; + c7 = newreg; Circle(c7) = {p5,p1,p6}; + c8 = newreg; Circle(c8) = {p6,p1,p2}; + c9 = newreg; Circle(c9) = {p7,p1,p3}; + c10 = newreg; Circle(c10) = {p3,p1,p4}; + c11 = newreg; Circle(c11) = {p4,p1,p6}; + c12 = newreg; Circle(c12) = {p6,p1,p7}; + + // We need non-plane surfaces to define the spherical holes. Here we + // use ruled surfaces, which can have 3 or 4 sides: + + l1 = newreg; Line Loop(l1) = {c5,c10,c4}; Ruled Surface(newreg) = {l1}; + l2 = newreg; Line Loop(l2) = {c9,-c5,c1}; Ruled Surface(newreg) = {l2}; + l3 = newreg; Line Loop(l3) = {c12,-c8,-c1}; Ruled Surface(newreg) = {l3}; + l4 = newreg; Line Loop(l4) = {c8,-c4,c11}; Ruled Surface(newreg) = {l4}; + l5 = newreg; Line Loop(l5) = {-c10,c6,c3}; Ruled Surface(newreg) = {l5}; + l6 = newreg; Line Loop(l6) = {-c11,-c3,c7}; Ruled Surface(newreg) = {l6}; + l7 = newreg; Line Loop(l7) = {-c2,-c7,-c12};Ruled Surface(newreg) = {l7}; + l8 = newreg; Line Loop(l8) = {-c6,-c9,c2}; Ruled Surface(newreg) = {l8}; + + // We then store the surface loops identification numbers in a list + // for later reference (we will need these to define the final + // volume): + + theloops[t] = newreg ; + + Surface Loop(theloops[t]) = {l8+1,l5+1,l1+1,l2+1,l3+1,l7+1,l6+1,l4+1}; + + thehole = newreg ; + Volume(thehole) = theloops[t] ; + +Return + +// We can use a `For' loop to generate five holes in the cube: + +x = 0 ; y = 0.75 ; z = 0 ; r = 0.09 ; + +For t In {1:5} + + x += 0.166 ; + z += 0.166 ; + + // We call the `CheeseHole' function: + + Call CheeseHole ; + + // We define a physical volume for each hole: + + Physical Volume (t) = thehole ; + + // We also print some variables on the terminal (note that, since + // all variables are treated internally as floating point numbers, + // the format string should only contain valid floating point format + // specifiers like `%g', `%f', '%e', etc.): + + Printf("Hole %g (center = {%g,%g,%g}, radius = %g) has number %g!", + t, x, y, z, r, thehole) ; + +EndFor + +// We can then define the surface loop for the exterior surface of the +// cube: + +theloops[0] = newreg ; + +Surface Loop(theloops[0]) = {35,31,29,37,33,23,39,25,27} ; + +// The volume of the cube, without the 5 holes, is now defined by 6 +// surface loops: the first surface loop defines the exterior surface; +// the surface loops other than the first one define holes. (Again, +// to reference an array of variables, its identifier is followed by +// square brackets): + +Volume(186) = {theloops[]} ; + +// We finally define a physical volume for the elements discretizing +// the cube, without the holes (whose elements were already tagged +// with numbers 1 to 5 in the `For' loop): + +Physical Volume (10) = 186 ; -- GitLab