Index: issm/trunk/src/c/Makefile.am
===================================================================
--- issm/trunk/src/c/Makefile.am	(revision 3912)
+++ issm/trunk/src/c/Makefile.am	(revision 3913)
@@ -34,4 +34,47 @@
 					./objects/Bamg/BamgOpts.h\
 					./objects/Bamg/BamgOpts.cpp\
+					./objects/Bamg/CrackedEdge.h\
+					./objects/Bamg/CrackedEdge.cpp\
+					./objects/Bamg/Curve.h\
+					./objects/Bamg/Curve.cpp\
+					./objects/Bamg/Direction.h\
+					./objects/Bamg/Direction.cpp\
+					./objects/Bamg/DoubleAndInt.h\
+					./objects/Bamg/Edge.h\
+					./objects/Bamg/Edge.cpp\
+					./objects/Bamg/GeometricalEdge.h\
+					./objects/Bamg/GeometricalEdge.cpp\
+					./objects/Bamg/GeometricalSubDomain.h\
+					./objects/Bamg/GeometricalSubDomain.cpp\
+					./objects/Bamg/GeometricalVertex.h\
+					./objects/Bamg/GeometricalVertex.cpp\
+					./objects/Bamg/Geometry.cpp\
+					./objects/Bamg/Geometry.h\
+					./objects/Bamg/ListofIntersectionTriangles.cpp\
+					./objects/Bamg/ListofIntersectionTriangles.h\
+					./objects/Bamg/MatVVP2x2.cpp\
+					./objects/Bamg/Metric.cpp\
+					./objects/Bamg/Metric.h\
+					./objects/Bamg/QuadTree.cpp\
+					./objects/Bamg/QuadTree.h\
+					./objects/Bamg/R2.h\
+					./objects/Bamg/SetOfE4.cpp\
+					./objects/Bamg/SetOfE4.h\
+					./objects/Bamg/SubDomain.h\
+					./objects/Bamg/SubDomain.cpp\
+					./objects/Bamg/TriangleAdjacent.h\
+					./objects/Bamg/TriangleAdjacent.cpp\
+					./objects/Bamg/Triangle.cpp\
+					./objects/Bamg/Triangle.h\
+					./objects/Bamg/Triangles.cpp\
+					./objects/Bamg/Triangles.h\
+					./objects/Bamg/MeshVertex.cpp\
+					./objects/Bamg/MeshVertex.h\
+					./objects/Bamg/VertexOnEdge.h\
+					./objects/Bamg/VertexOnEdge.cpp\
+					./objects/Bamg/VertexOnGeom.h\
+					./objects/Bamg/VertexOnGeom.cpp\
+					./objects/Bamg/VertexOnVertex.h\
+					./objects/Bamg/VertexOnVertex.cpp\
 					./objects/Element.h\
 					./objects/Model.h\
@@ -184,4 +227,14 @@
 					./shared/String/isdistributed.cpp\
 					./shared/String/sharedstring.h\
+					./shared/Bamg/Abs.h \
+					./shared/Bamg/BigPrimeNumber.h\
+					./shared/Bamg/BigPrimeNumber.cpp\
+					./shared/Bamg/BinaryRand.h \
+					./shared/Bamg/det.h \
+					./shared/Bamg/Exchange.h \
+					./shared/Bamg/extrema.h \
+					./shared/Bamg/HeapSort.h \
+					./shared/Bamg/Norm.h \
+					./shared/Bamg/OppositeAngle.h \
 					./toolkits/petsc\
 					./toolkits/petsc/patches\
@@ -238,225 +291,167 @@
 					./EnumDefinitions/EnumAsString.cpp\
 					./EnumDefinitions/StringAsEnum.cpp\
-					./ModelProcessorx/ModelProcessorx.h\
-					./ModelProcessorx/Partitioning.cpp\
-					./ModelProcessorx/CreateDataSets.cpp\
-					./ModelProcessorx/CreateParameters.cpp\
-					./ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp\
-					./ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp\
-					./ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp \
-					./ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp\
-					./ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp\
-					./ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp \
-					./ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp\
-					./ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp\
-					./ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
-					./ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp\
-					./ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp\
-					./ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp \
-					./ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp\
-					./ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp\
-					./ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp \
-					./ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp\
-					./ModelProcessorx/Control/CreateParametersControl.cpp\
-					./ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp\
-					./ModelProcessorx/Thermal/CreateConstraintsThermal.cpp\
-					./ModelProcessorx/Thermal/CreateLoadsThermal.cpp\
-					./ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp\
-					./ModelProcessorx/Melting/CreateConstraintsMelting.cpp\
-					./ModelProcessorx/Melting/CreateLoadsMelting.cpp\
-					./ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp\
-					./ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp\
-					./ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp\
-					./ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp\
-					./ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp\
-					./ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp\
-					./ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp\
-					./ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp\
-					./ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp\
-					./ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp\
-					./ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp\
-					./ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp\
-					./ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp\
-					./ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp\
-					./ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
-					./ModelProcessorx/Qmu/CreateParametersQmu.cpp\
-					./Dofx/Dofx.h\
-					./Dofx/Dofx.cpp\
-					./Dux/Dux.h\
-					./Dux/Dux.cpp\
-					./ControlConstrainx/ControlConstrainx.h\
-					./ControlConstrainx/ControlConstrainx.cpp\
-					./SurfaceAreax/SurfaceAreax.h\
-					./SurfaceAreax/SurfaceAreax.cpp\
-					./Misfitx/Misfitx.h\
-					./Misfitx/Misfitx.cpp\
-					./CostFunctionx/CostFunctionx.h\
-					./CostFunctionx/CostFunctionx.cpp\
-					./Orthx/Orthx.h\
-					./Orthx/Orthx.cpp\
-					./Gradjx/Gradjx.h\
-					./Gradjx/Gradjx.cpp\
-					./SplitSolutionVectorx/SplitSolutionVectorx.h\
-					./SplitSolutionVectorx/SplitSolutionVectorx.cpp\
-					./UpdateInputsFromConstantx/UpdateInputsFromConstantx.h\
-					./UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp\
-					./UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h\
-					./UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp\
-					./GetSolutionFromInputsx/GetSolutionFromInputsx.h\
-					./GetSolutionFromInputsx/GetSolutionFromInputsx.cpp\
-					./UpdateInputsFromVectorx/UpdateInputsFromVectorx.h\
-					./UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp\
-					./UpdateGeometryx/UpdateGeometryx.h\
-					./UpdateGeometryx/UpdateGeometryx.cpp\
-					./UpdateVertexPositionsx/UpdateVertexPositionsx.h\
-					./UpdateVertexPositionsx/UpdateVertexPositionsx.cpp\
-					./ConfigureObjectsx/ConfigureObjectsx.h\
-					./ConfigureObjectsx/ConfigureObjectsx.cpp\
-					./ComputeBasalStressx/ComputeBasalStressx.h\
-					./ComputeBasalStressx/ComputeBasalStressx.cpp\
-					./ComputePressurex/ComputePressurex.h\
-					./ComputePressurex/ComputePressurex.cpp\
-					./ComputeStrainRatex/ComputeStrainRatex.h\
-					./ComputeStrainRatex/ComputeStrainRatex.cpp\
-					./BuildNodeSetsx/BuildNodeSetsx.h\
-					./BuildNodeSetsx/BuildNodeSetsx.cpp\
-					./BuildNodeSetsx/PartitionSets.cpp\
-					./SpcNodesx/SpcNodesx.h\
-					./SpcNodesx/SpcNodesx.cpp\
-					./MpcNodesx/MpcNodesx.h\
-					./MpcNodesx/MpcNodesx.cpp\
-					./InterpFromGridToMeshx/InterpFromGridToMeshx.cpp\
-					./InterpFromGridToMeshx/InterpFromGridToMeshx.h\
-					./InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp\
-					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\
-					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h\
-					./InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\
-					./InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h\
-					./InterpFromMeshToGridx/InterpFromMeshToGridx.cpp\
-					./InterpFromMeshToGridx/InterpFromMeshToGridx.h\
-					./HoleFillerx/HoleFillerx.cpp\
-					./HoleFillerx/HoleFillerx.h\
-					./AverageFilterx/AverageFilterx.cpp\
-					./AverageFilterx/AverageFilterx.h\
-					./MeshPartitionx/MeshPartitionx.cpp\
-					./MeshPartitionx/MeshPartitionx.h\
-					./ContourToMeshx/ContourToMeshx.cpp\
-					./ContourToMeshx/ContourToMeshxt.cpp\
-					./ContourToMeshx/ContourToMeshx.h\
-					./ContourToNodesx/ContourToNodesx.cpp\
-					./ContourToNodesx/ContourToNodesx.h\
-					./Reducevectorgtosx/Reducevectorgtosx.cpp\
-					./Reducevectorgtosx/Reducevectorgtosx.h\
-					./Reducevectorgtofx/Reducevectorgtofx.cpp\
-					./Reducevectorgtofx/Reducevectorgtofx.h\
-					./Reducematrixfromgtofx/Reducematrixfromgtofx.cpp\
-					./Reducematrixfromgtofx/Reducematrixfromgton.cpp\
-					./Reducematrixfromgtofx/Reducematrixfromgtofx.h\
-					./Reduceloadfromgtofx/Reduceloadfromgtofx.h\
-					./Reduceloadfromgtofx/Reduceloadfromgtofx.cpp\
-					./NormalizeConstraintsx/NormalizeConstraintsx.cpp\
-					./NormalizeConstraintsx/NormalizeConstraintsx.h\
-					./NodeConnectivityx/NodeConnectivityx.cpp\
-					./NodeConnectivityx/NodeConnectivityx.h\
-					./ElementConnectivityx/ElementConnectivityx.cpp\
-					./ElementConnectivityx/ElementConnectivityx.h\
-					./MassFluxx/MassFluxx.cpp\
-					./MassFluxx/MassFluxx.h\
-					./SystemMatricesx/SystemMatricesx.cpp\
-					./SystemMatricesx/SystemMatricesx.h\
-					./PenaltyConstraintsx/PenaltyConstraintsx.cpp\
-					./PenaltyConstraintsx/PenaltyConstraintsx.h\
-					./PenaltyConstraintsx/RiftConstraints.cpp\
-					./PenaltyConstraintsx/RiftConstraints.h\
-					./PenaltySystemMatricesx/PenaltySystemMatricesx.cpp\
-					./PenaltySystemMatricesx/PenaltySystemMatricesx.h\
-					./Solverx/Solverx.cpp\
-					./Solverx/Solverx.h\
-					./Mergesolutionfromftogx/Mergesolutionfromftogx.cpp\
-					./Mergesolutionfromftogx/Mergesolutionfromftogx.h\
-					./ProcessParamsx/ProcessParamsx.cpp\
-					./ProcessParamsx/ProcessParamsx.h\
-					./PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.cpp\
-					./PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.h\
-					./Qmux/Qmux.h\
-					./Qmux/Qmux.cpp\
-					./Qmux/SpawnCore.cpp\
-					./Qmux/SpawnCoreSerial.cpp\
-					./FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp\
-					./FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h\
-					./FieldDepthAveragex/FieldDepthAveragex.cpp\
-					./FieldDepthAveragex/FieldDepthAveragex.h\
-					./DepthAverageInputx/DepthAverageInputx.cpp\
-					./DepthAverageInputx/DepthAverageInputx.h\
-					./FieldExtrudex/FieldExtrudex.cpp\
-					./FieldExtrudex/FieldExtrudex.h\
-					./InputToResultx/InputToResultx.cpp\
-					./InputToResultx/InputToResultx.h\
-					./ExtrudeInputx/ExtrudeInputx.cpp\
-					./ExtrudeInputx/ExtrudeInputx.h\
-					./OutputRiftsx/OutputRiftsx.h\
-					./OutputRiftsx/OutputRiftsx.cpp\
-					./Bamgx/Bamgx.cpp\
-					./Bamgx/Bamgx.h\
-					./Bamgx/include/include.h \
-					./Bamgx/include/macros.h \
-					./Bamgx/include/typedefs.h \
-					./Bamgx/objects/BamgObjects.h \
-					./Bamgx/objects/CrackedEdge.h\
-					./Bamgx/objects/CrackedEdge.cpp\
-					./Bamgx/objects/Curve.h\
-					./Bamgx/objects/Curve.cpp\
-					./Bamgx/objects/Direction.h\
-					./Bamgx/objects/Direction.cpp\
-					./Bamgx/objects/DoubleAndInt.h\
-					./Bamgx/objects/Edge.h\
-					./Bamgx/objects/Edge.cpp\
-					./Bamgx/objects/GeometricalEdge.h\
-					./Bamgx/objects/GeometricalEdge.cpp\
-					./Bamgx/objects/GeometricalSubDomain.h\
-					./Bamgx/objects/GeometricalSubDomain.cpp\
-					./Bamgx/objects/GeometricalVertex.h\
-					./Bamgx/objects/GeometricalVertex.cpp\
-					./Bamgx/objects/Geometry.cpp\
-					./Bamgx/objects/Geometry.h\
-					./Bamgx/objects/ListofIntersectionTriangles.cpp\
-					./Bamgx/objects/ListofIntersectionTriangles.h\
-					./Bamgx/objects/MatVVP2x2.cpp\
-					./Bamgx/objects/Metric.cpp\
-					./Bamgx/objects/Metric.h\
-					./Bamgx/objects/QuadTree.cpp\
-					./Bamgx/objects/QuadTree.h\
-					./Bamgx/objects/R2.h\
-					./Bamgx/objects/SetOfE4.cpp\
-					./Bamgx/objects/SetOfE4.h\
-					./Bamgx/objects/SubDomain.h\
-					./Bamgx/objects/SubDomain.cpp\
-					./Bamgx/objects/TriangleAdjacent.h\
-					./Bamgx/objects/TriangleAdjacent.cpp\
-					./Bamgx/objects/Triangle.cpp\
-					./Bamgx/objects/Triangle.h\
-					./Bamgx/objects/Triangles.cpp\
-					./Bamgx/objects/Triangles.h\
-					./Bamgx/objects/MeshVertex.cpp\
-					./Bamgx/objects/MeshVertex.h\
-					./Bamgx/objects/VertexOnEdge.h\
-					./Bamgx/objects/VertexOnEdge.cpp\
-					./Bamgx/objects/VertexOnGeom.h\
-					./Bamgx/objects/VertexOnGeom.cpp\
-					./Bamgx/objects/VertexOnVertex.h\
-					./Bamgx/objects/VertexOnVertex.cpp\
-					./Bamgx/shared/Abs.h \
-					./Bamgx/shared/BigPrimeNumber.h\
-					./Bamgx/shared/BigPrimeNumber.cpp\
-					./Bamgx/shared/BinaryRand.h \
-					./Bamgx/shared/det.h \
-					./Bamgx/shared/Exchange.h \
-					./Bamgx/shared/extrema.h \
-					./Bamgx/shared/HeapSort.h \
-					./Bamgx/shared/Norm.h \
-					./Bamgx/shared/OppositeAngle.h \
-					./Bamgx/shared/shared.h\
-					./BamgConvertMeshx/BamgConvertMeshx.cpp\
-					./BamgConvertMeshx/BamgConvertMeshx.h
+					./modules/ModelProcessorx/ModelProcessorx.h\
+					./modules/ModelProcessorx/Partitioning.cpp\
+					./modules/ModelProcessorx/CreateDataSets.cpp\
+					./modules/ModelProcessorx/CreateParameters.cpp\
+					./modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp\
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp\
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp \
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp\
+					./modules/ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp\
+					./modules/ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp \
+					./modules/ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp\
+					./modules/ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp\
+					./modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
+					./modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp\
+					./modules/ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp\
+					./modules/ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp \
+					./modules/ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp\
+					./modules/ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp\
+					./modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp \
+					./modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp\
+					./modules/ModelProcessorx/Control/CreateParametersControl.cpp\
+					./modules/ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp\
+					./modules/ModelProcessorx/Thermal/CreateConstraintsThermal.cpp\
+					./modules/ModelProcessorx/Thermal/CreateLoadsThermal.cpp\
+					./modules/ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp\
+					./modules/ModelProcessorx/Melting/CreateConstraintsMelting.cpp\
+					./modules/ModelProcessorx/Melting/CreateLoadsMelting.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp\
+					./modules/Dofx/Dofx.h\
+					./modules/Dofx/Dofx.cpp\
+					./modules/Dux/Dux.h\
+					./modules/Dux/Dux.cpp\
+					./modules/ControlConstrainx/ControlConstrainx.h\
+					./modules/ControlConstrainx/ControlConstrainx.cpp\
+					./modules/SurfaceAreax/SurfaceAreax.h\
+					./modules/SurfaceAreax/SurfaceAreax.cpp\
+					./modules/Misfitx/Misfitx.h\
+					./modules/Misfitx/Misfitx.cpp\
+					./modules/CostFunctionx/CostFunctionx.h\
+					./modules/CostFunctionx/CostFunctionx.cpp\
+					./modules/Orthx/Orthx.h\
+					./modules/Orthx/Orthx.cpp\
+					./modules/Gradjx/Gradjx.h\
+					./modules/Gradjx/Gradjx.cpp\
+					./modules/SplitSolutionVectorx/SplitSolutionVectorx.h\
+					./modules/SplitSolutionVectorx/SplitSolutionVectorx.cpp\
+					./modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.h\
+					./modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp\
+					./modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h\
+					./modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp\
+					./modules/GetSolutionFromInputsx/GetSolutionFromInputsx.h\
+					./modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp\
+					./modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.h\
+					./modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp\
+					./modules/UpdateGeometryx/UpdateGeometryx.h\
+					./modules/UpdateGeometryx/UpdateGeometryx.cpp\
+					./modules/UpdateVertexPositionsx/UpdateVertexPositionsx.h\
+					./modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp\
+					./modules/ConfigureObjectsx/ConfigureObjectsx.h\
+					./modules/ConfigureObjectsx/ConfigureObjectsx.cpp\
+					./modules/ComputeBasalStressx/ComputeBasalStressx.h\
+					./modules/ComputeBasalStressx/ComputeBasalStressx.cpp\
+					./modules/ComputePressurex/ComputePressurex.h\
+					./modules/ComputePressurex/ComputePressurex.cpp\
+					./modules/ComputeStrainRatex/ComputeStrainRatex.h\
+					./modules/ComputeStrainRatex/ComputeStrainRatex.cpp\
+					./modules/BuildNodeSetsx/BuildNodeSetsx.h\
+					./modules/BuildNodeSetsx/BuildNodeSetsx.cpp\
+					./modules/BuildNodeSetsx/PartitionSets.cpp\
+					./modules/SpcNodesx/SpcNodesx.h\
+					./modules/SpcNodesx/SpcNodesx.cpp\
+					./modules/MpcNodesx/MpcNodesx.h\
+					./modules/MpcNodesx/MpcNodesx.cpp\
+					./modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp\
+					./modules/InterpFromGridToMeshx/InterpFromGridToMeshx.h\
+					./modules/InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp\
+					./modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\
+					./modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h\
+					./modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\
+					./modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h\
+					./modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp\
+					./modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h\
+					./modules/HoleFillerx/HoleFillerx.cpp\
+					./modules/HoleFillerx/HoleFillerx.h\
+					./modules/AverageFilterx/AverageFilterx.cpp\
+					./modules/AverageFilterx/AverageFilterx.h\
+					./modules/MeshPartitionx/MeshPartitionx.cpp\
+					./modules/MeshPartitionx/MeshPartitionx.h\
+					./modules/ContourToMeshx/ContourToMeshx.cpp\
+					./modules/ContourToMeshx/ContourToMeshxt.cpp\
+					./modules/ContourToMeshx/ContourToMeshx.h\
+					./modules/ContourToNodesx/ContourToNodesx.cpp\
+					./modules/ContourToNodesx/ContourToNodesx.h\
+					./modules/Reducevectorgtosx/Reducevectorgtosx.cpp\
+					./modules/Reducevectorgtosx/Reducevectorgtosx.h\
+					./modules/Reducevectorgtofx/Reducevectorgtofx.cpp\
+					./modules/Reducevectorgtofx/Reducevectorgtofx.h\
+					./modules/Reducematrixfromgtofx/Reducematrixfromgtofx.cpp\
+					./modules/Reducematrixfromgtofx/Reducematrixfromgton.cpp\
+					./modules/Reducematrixfromgtofx/Reducematrixfromgtofx.h\
+					./modules/Reduceloadfromgtofx/Reduceloadfromgtofx.h\
+					./modules/Reduceloadfromgtofx/Reduceloadfromgtofx.cpp\
+					./modules/NormalizeConstraintsx/NormalizeConstraintsx.cpp\
+					./modules/NormalizeConstraintsx/NormalizeConstraintsx.h\
+					./modules/NodeConnectivityx/NodeConnectivityx.cpp\
+					./modules/NodeConnectivityx/NodeConnectivityx.h\
+					./modules/ElementConnectivityx/ElementConnectivityx.cpp\
+					./modules/ElementConnectivityx/ElementConnectivityx.h\
+					./modules/MassFluxx/MassFluxx.cpp\
+					./modules/MassFluxx/MassFluxx.h\
+					./modules/SystemMatricesx/SystemMatricesx.cpp\
+					./modules/SystemMatricesx/SystemMatricesx.h\
+					./modules/PenaltyConstraintsx/PenaltyConstraintsx.cpp\
+					./modules/PenaltyConstraintsx/PenaltyConstraintsx.h\
+					./modules/PenaltyConstraintsx/RiftConstraints.cpp\
+					./modules/PenaltyConstraintsx/RiftConstraints.h\
+					./modules/PenaltySystemMatricesx/PenaltySystemMatricesx.cpp\
+					./modules/PenaltySystemMatricesx/PenaltySystemMatricesx.h\
+					./modules/Solverx/Solverx.cpp\
+					./modules/Solverx/Solverx.h\
+					./modules/Mergesolutionfromftogx/Mergesolutionfromftogx.cpp\
+					./modules/Mergesolutionfromftogx/Mergesolutionfromftogx.h\
+					./modules/ProcessParamsx/ProcessParamsx.cpp\
+					./modules/ProcessParamsx/ProcessParamsx.h\
+					./modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.cpp\
+					./modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.h\
+					./modules/Qmux/Qmux.h\
+					./modules/Qmux/Qmux.cpp\
+					./modules/Qmux/SpawnCore.cpp\
+					./modules/Qmux/SpawnCoreSerial.cpp\
+					./modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp\
+					./modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h\
+					./modules/FieldDepthAveragex/FieldDepthAveragex.cpp\
+					./modules/FieldDepthAveragex/FieldDepthAveragex.h\
+					./modules/DepthAverageInputx/DepthAverageInputx.cpp\
+					./modules/DepthAverageInputx/DepthAverageInputx.h\
+					./modules/FieldExtrudex/FieldExtrudex.cpp\
+					./modules/FieldExtrudex/FieldExtrudex.h\
+					./modules/InputToResultx/InputToResultx.cpp\
+					./modules/InputToResultx/InputToResultx.h\
+					./modules/ExtrudeInputx/ExtrudeInputx.cpp\
+					./modules/ExtrudeInputx/ExtrudeInputx.h\
+					./modules/OutputRiftsx/OutputRiftsx.h\
+					./modules/OutputRiftsx/OutputRiftsx.cpp\
+					./modules/Bamgx/Bamgx.cpp\
+					./modules/Bamgx/Bamgx.h\
+					./modules/BamgConvertMeshx/BamgConvertMeshx.cpp\
+					./modules/BamgConvertMeshx/BamgConvertMeshx.h
 
 libISSM_a_CXXFLAGS = -fPIC -DMATLAB -D_SERIAL_ -ansi -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXOPTFLAGS)
@@ -483,4 +478,47 @@
 					./objects/Bamg/BamgOpts.h\
 					./objects/Bamg/BamgOpts.cpp\
+					./objects/Bamg/BamgObjects.h \
+					./objects/Bamg/CrackedEdge.h\
+					./objects/Bamg/CrackedEdge.cpp\
+					./objects/Bamg/Curve.h\
+					./objects/Bamg/Curve.cpp\
+					./objects/Bamg/Direction.h\
+					./objects/Bamg/Direction.cpp\
+					./objects/Bamg/DoubleAndInt.h\
+					./objects/Bamg/Edge.h\
+					./objects/Bamg/Edge.cpp\
+					./objects/Bamg/GeometricalEdge.h\
+					./objects/Bamg/GeometricalEdge.cpp\
+					./objects/Bamg/GeometricalSubDomain.h\
+					./objects/Bamg/GeometricalSubDomain.cpp\
+					./objects/Bamg/GeometricalVertex.h\
+					./objects/Bamg/GeometricalVertex.cpp\
+					./objects/Bamg/Geometry.cpp\
+					./objects/Bamg/Geometry.h\
+					./objects/Bamg/ListofIntersectionTriangles.cpp\
+					./objects/Bamg/ListofIntersectionTriangles.h\
+					./objects/Bamg/MatVVP2x2.cpp\
+					./objects/Bamg/Metric.cpp\
+					./objects/Bamg/Metric.h\
+					./objects/Bamg/QuadTree.cpp\
+					./objects/Bamg/QuadTree.h\
+					./objects/Bamg/R2.h\
+					./objects/Bamg/SetOfE4.cpp\
+					./objects/Bamg/SetOfE4.h\
+					./objects/Bamg/SubDomain.h\
+					./objects/Bamg/SubDomain.cpp\
+					./objects/Bamg/TriangleAdjacent.h\
+					./objects/Bamg/TriangleAdjacent.cpp\
+					./objects/Bamg/Triangle.cpp\
+					./objects/Bamg/Triangle.h\
+					./objects/Bamg/Triangles.cpp\
+					./objects/Bamg/Triangles.h\
+					./objects/Bamg/MeshVertex.cpp\
+					./objects/Bamg/MeshVertex.h\
+					./objects/Bamg/VertexOnEdge.h\
+					./objects/Bamg/VertexOnEdge.cpp\
+					./objects/Bamg/VertexOnGeom.h\
+					./objects/Bamg/VertexOnGeom.cpp\
+					./objects/Bamg/VertexOnVertex.h\
 					./objects/Element.h\
 					./objects/Model.h\
@@ -631,4 +669,14 @@
 					./shared/String/isdistributed.cpp\
 					./shared/String/sharedstring.h\
+					./shared/Bamg/Abs.h \
+					./shared/Bamg/BigPrimeNumber.h\
+					./shared/Bamg/BigPrimeNumber.cpp\
+					./shared/Bamg/BinaryRand.h \
+					./shared/Bamg/det.h \
+					./shared/Bamg/Exchange.h \
+					./shared/Bamg/extrema.h \
+					./shared/Bamg/HeapSort.h \
+					./shared/Bamg/Norm.h \
+					./shared/Bamg/OppositeAngle.h \
 					./toolkits/petsc\
 					./toolkits/petsc/patches\
@@ -684,156 +732,156 @@
 					./EnumDefinitions/EnumAsString.cpp\
 					./EnumDefinitions/StringAsEnum.cpp\
-					./ModelProcessorx/ModelProcessorx.h\
-					./ModelProcessorx/Partitioning.cpp\
-					./ModelProcessorx/CreateDataSets.cpp\
-					./ModelProcessorx/CreateParameters.cpp\
-					./ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp\
-					./ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp\
-					./ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp \
-					./ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp\
-					./ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp\
-					./ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp \
-					./ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp\
-					./ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp\
-					./ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
-					./ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp\
-					./ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp\
-					./ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp \
-					./ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp\
-					./ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp\
-					./ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp \
-					./ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp\
-					./ModelProcessorx/Control/CreateParametersControl.cpp\
-					./ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp\
-					./ModelProcessorx/Thermal/CreateConstraintsThermal.cpp\
-					./ModelProcessorx/Thermal/CreateLoadsThermal.cpp\
-					./ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp\
-					./ModelProcessorx/Melting/CreateConstraintsMelting.cpp\
-					./ModelProcessorx/Melting/CreateLoadsMelting.cpp\
-					./ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp\
-					./ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp\
-					./ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp\
-					./ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp\
-					./ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp\
-					./ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp\
-					./ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp\
-					./ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp\
-					./ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp\
-					./ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp\
-					./ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp\
-					./ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp\
-					./ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp\
-					./ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp\
-					./ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
-					./ModelProcessorx/Qmu/CreateParametersQmu.cpp\
-					./Dofx/Dofx.h\
-					./Dofx/Dofx.cpp\
-					./Dux/Dux.h\
-					./Dux/Dux.cpp\
-					./ControlConstrainx/ControlConstrainx.h\
-					./ControlConstrainx/ControlConstrainx.cpp\
-					./SurfaceAreax/SurfaceAreax.h\
-					./SurfaceAreax/SurfaceAreax.cpp\
-					./Misfitx/Misfitx.h\
-					./Misfitx/Misfitx.cpp\
-					./CostFunctionx/CostFunctionx.h\
-					./CostFunctionx/CostFunctionx.cpp\
-					./Orthx/Orthx.h\
-					./Orthx/Orthx.cpp\
-					./Gradjx/Gradjx.h\
-					./Gradjx/Gradjx.cpp\
-					./SplitSolutionVectorx/SplitSolutionVectorx.h\
-					./SplitSolutionVectorx/SplitSolutionVectorx.cpp\
-					./UpdateInputsFromConstantx/UpdateInputsFromConstantx.h\
-					./UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp\
-					./UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h\
-					./UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp\
-					./GetSolutionFromInputsx/GetSolutionFromInputsx.h\
-					./GetSolutionFromInputsx/GetSolutionFromInputsx.cpp\
-					./UpdateInputsFromVectorx/UpdateInputsFromVectorx.h\
-					./UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp\
-					./UpdateGeometryx/UpdateGeometryx.h\
-					./UpdateGeometryx/UpdateGeometryx.cpp\
-					./UpdateVertexPositionsx/UpdateVertexPositionsx.h\
-					./UpdateVertexPositionsx/UpdateVertexPositionsx.cpp\
-					./ConfigureObjectsx/ConfigureObjectsx.h\
-					./ConfigureObjectsx/ConfigureObjectsx.cpp\
-					./ComputeBasalStressx/ComputeBasalStressx.h\
-					./ComputeBasalStressx/ComputeBasalStressx.cpp\
-					./ComputePressurex/ComputePressurex.h\
-					./ComputePressurex/ComputePressurex.cpp\
-					./ComputeStrainRatex/ComputeStrainRatex.h\
-					./ComputeStrainRatex/ComputeStrainRatex.cpp\
-					./BuildNodeSetsx/BuildNodeSetsx.h\
-					./BuildNodeSetsx/BuildNodeSetsx.cpp\
-					./BuildNodeSetsx/PartitionSets.cpp\
-					./SpcNodesx/SpcNodesx.h\
-					./SpcNodesx/SpcNodesx.cpp\
-					./MpcNodesx/MpcNodesx.h\
-					./MpcNodesx/MpcNodesx.cpp\
-					./InterpFromGridToMeshx/InterpFromGridToMeshx.cpp\
-					./InterpFromGridToMeshx/InterpFromGridToMeshx.h\
-					./InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp\
-					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\
-					./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h\
-					./InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\
-					./InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h\
-					./InterpFromMeshToGridx/InterpFromMeshToGridx.cpp\
-					./InterpFromMeshToGridx/InterpFromMeshToGridx.h\
-					./HoleFillerx/HoleFillerx.cpp\
-					./HoleFillerx/HoleFillerx.h\
-					./AverageFilterx/AverageFilterx.cpp\
-					./AverageFilterx/AverageFilterx.h\
-					./MeshPartitionx/MeshPartitionx.cpp\
-					./MeshPartitionx/MeshPartitionx.h\
-					./ContourToMeshx/ContourToMeshx.cpp\
-					./ContourToMeshx/ContourToMeshxt.cpp\
-					./ContourToMeshx/ContourToMeshx.h\
-					./Reducevectorgtosx/Reducevectorgtosx.cpp\
-					./Reducevectorgtosx/Reducevectorgtosx.h\
-					./Reducevectorgtofx/Reducevectorgtofx.cpp\
-					./Reducevectorgtofx/Reducevectorgtofx.h\
-					./Reducematrixfromgtofx/Reducematrixfromgtofx.cpp\
-					./Reducematrixfromgtofx/Reducematrixfromgton.cpp\
-					./Reducematrixfromgtofx/Reducematrixfromgtofx.h\
-					./Reduceloadfromgtofx/Reduceloadfromgtofx.h\
-					./Reduceloadfromgtofx/Reduceloadfromgtofx.cpp\
-					./NormalizeConstraintsx/NormalizeConstraintsx.cpp\
-					./NormalizeConstraintsx/NormalizeConstraintsx.h\
-					./MassFluxx/MassFluxx.cpp\
-					./MassFluxx/MassFluxx.h\
-					./SystemMatricesx/SystemMatricesx.cpp\
-					./SystemMatricesx/SystemMatricesx.h\
-					./PenaltyConstraintsx/PenaltyConstraintsx.cpp\
-					./PenaltyConstraintsx/PenaltyConstraintsx.h\
-					./PenaltyConstraintsx/RiftConstraints.cpp\
-					./PenaltyConstraintsx/RiftConstraints.h\
-					./PenaltySystemMatricesx/PenaltySystemMatricesx.cpp\
-					./PenaltySystemMatricesx/PenaltySystemMatricesx.h\
-					./Solverx/Solverx.cpp\
-					./Solverx/Solverx.h\
-					./Mergesolutionfromftogx/Mergesolutionfromftogx.cpp\
-					./Mergesolutionfromftogx/Mergesolutionfromftogx.h\
-					./ProcessParamsx/ProcessParamsx.cpp\
-					./ProcessParamsx/ProcessParamsx.h\
-					./Qmux/Qmux.h\
-					./Qmux/Qmux.cpp\
-					./Qmux/DakotaResponses.cpp\
-					./Qmux/SpawnCore.cpp\
-					./Qmux/SpawnCoreParallel.cpp\
-					./FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp\
-					./FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h\
-					./FieldDepthAveragex/FieldDepthAveragex.cpp\
-					./FieldDepthAveragex/FieldDepthAveragex.h\
-					./DepthAverageInputx/DepthAverageInputx.cpp\
-					./DepthAverageInputx/DepthAverageInputx.h\
-					./FieldExtrudex/FieldExtrudex.cpp\
-					./FieldExtrudex/FieldExtrudex.h\
-					./InputToResultx/InputToResultx.cpp\
-					./InputToResultx/InputToResultx.h\
-					./ExtrudeInputx/ExtrudeInputx.cpp\
-					./ExtrudeInputx/ExtrudeInputx.h\
-					./OutputRiftsx/OutputRiftsx.h\
-					./OutputRiftsx/OutputRiftsx.cpp\
+					./modules/ModelProcessorx/ModelProcessorx.h\
+					./modules/ModelProcessorx/Partitioning.cpp\
+					./modules/ModelProcessorx/CreateDataSets.cpp\
+					./modules/ModelProcessorx/CreateParameters.cpp\
+					./modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp\
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp\
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp \
+					./modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp\
+					./modules/ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp\
+					./modules/ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp \
+					./modules/ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp\
+					./modules/ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp\
+					./modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
+					./modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp\
+					./modules/ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp\
+					./modules/ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp \
+					./modules/ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp\
+					./modules/ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp\
+					./modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp \
+					./modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp\
+					./modules/ModelProcessorx/Control/CreateParametersControl.cpp\
+					./modules/ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp\
+					./modules/ModelProcessorx/Thermal/CreateConstraintsThermal.cpp\
+					./modules/ModelProcessorx/Thermal/CreateLoadsThermal.cpp\
+					./modules/ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp\
+					./modules/ModelProcessorx/Melting/CreateConstraintsMelting.cpp\
+					./modules/ModelProcessorx/Melting/CreateLoadsMelting.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp\
+					./modules/ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp\
+					./modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp\
+					./modules/Dofx/Dofx.h\
+					./modules/Dofx/Dofx.cpp\
+					./modules/Dux/Dux.h\
+					./modules/Dux/Dux.cpp\
+					./modules/ControlConstrainx/ControlConstrainx.h\
+					./modules/ControlConstrainx/ControlConstrainx.cpp\
+					./modules/SurfaceAreax/SurfaceAreax.h\
+					./modules/SurfaceAreax/SurfaceAreax.cpp\
+					./modules/Misfitx/Misfitx.h\
+					./modules/Misfitx/Misfitx.cpp\
+					./modules/CostFunctionx/CostFunctionx.h\
+					./modules/CostFunctionx/CostFunctionx.cpp\
+					./modules/Orthx/Orthx.h\
+					./modules/Orthx/Orthx.cpp\
+					./modules/Gradjx/Gradjx.h\
+					./modules/Gradjx/Gradjx.cpp\
+					./modules/SplitSolutionVectorx/SplitSolutionVectorx.h\
+					./modules/SplitSolutionVectorx/SplitSolutionVectorx.cpp\
+					./modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.h\
+					./modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp\
+					./modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h\
+					./modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp\
+					./modules/GetSolutionFromInputsx/GetSolutionFromInputsx.h\
+					./modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp\
+					./modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.h\
+					./modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp\
+					./modules/UpdateGeometryx/UpdateGeometryx.h\
+					./modules/UpdateGeometryx/UpdateGeometryx.cpp\
+					./modules/UpdateVertexPositionsx/UpdateVertexPositionsx.h\
+					./modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp\
+					./modules/ConfigureObjectsx/ConfigureObjectsx.h\
+					./modules/ConfigureObjectsx/ConfigureObjectsx.cpp\
+					./modules/ComputeBasalStressx/ComputeBasalStressx.h\
+					./modules/ComputeBasalStressx/ComputeBasalStressx.cpp\
+					./modules/ComputePressurex/ComputePressurex.h\
+					./modules/ComputePressurex/ComputePressurex.cpp\
+					./modules/ComputeStrainRatex/ComputeStrainRatex.h\
+					./modules/ComputeStrainRatex/ComputeStrainRatex.cpp\
+					./modules/BuildNodeSetsx/BuildNodeSetsx.h\
+					./modules/BuildNodeSetsx/BuildNodeSetsx.cpp\
+					./modules/BuildNodeSetsx/PartitionSets.cpp\
+					./modules/SpcNodesx/SpcNodesx.h\
+					./modules/SpcNodesx/SpcNodesx.cpp\
+					./modules/MpcNodesx/MpcNodesx.h\
+					./modules/MpcNodesx/MpcNodesx.cpp\
+					./modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp\
+					./modules/InterpFromGridToMeshx/InterpFromGridToMeshx.h\
+					./modules/InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp\
+					./modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\
+					./modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h\
+					./modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp\
+					./modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h\
+					./modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp\
+					./modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h\
+					./modules/HoleFillerx/HoleFillerx.cpp\
+					./modules/HoleFillerx/HoleFillerx.h\
+					./modules/AverageFilterx/AverageFilterx.cpp\
+					./modules/AverageFilterx/AverageFilterx.h\
+					./modules/MeshPartitionx/MeshPartitionx.cpp\
+					./modules/MeshPartitionx/MeshPartitionx.h\
+					./modules/ContourToMeshx/ContourToMeshx.cpp\
+					./modules/ContourToMeshx/ContourToMeshxt.cpp\
+					./modules/ContourToMeshx/ContourToMeshx.h\
+					./modules/Reducevectorgtosx/Reducevectorgtosx.cpp\
+					./modules/Reducevectorgtosx/Reducevectorgtosx.h\
+					./modules/Reducevectorgtofx/Reducevectorgtofx.cpp\
+					./modules/Reducevectorgtofx/Reducevectorgtofx.h\
+					./modules/Reducematrixfromgtofx/Reducematrixfromgtofx.cpp\
+					./modules/Reducematrixfromgtofx/Reducematrixfromgton.cpp\
+					./modules/Reducematrixfromgtofx/Reducematrixfromgtofx.h\
+					./modules/Reduceloadfromgtofx/Reduceloadfromgtofx.h\
+					./modules/Reduceloadfromgtofx/Reduceloadfromgtofx.cpp\
+					./modules/NormalizeConstraintsx/NormalizeConstraintsx.cpp\
+					./modules/NormalizeConstraintsx/NormalizeConstraintsx.h\
+					./modules/MassFluxx/MassFluxx.cpp\
+					./modules/MassFluxx/MassFluxx.h\
+					./modules/SystemMatricesx/SystemMatricesx.cpp\
+					./modules/SystemMatricesx/SystemMatricesx.h\
+					./modules/PenaltyConstraintsx/PenaltyConstraintsx.cpp\
+					./modules/PenaltyConstraintsx/PenaltyConstraintsx.h\
+					./modules/PenaltyConstraintsx/RiftConstraints.cpp\
+					./modules/PenaltyConstraintsx/RiftConstraints.h\
+					./modules/PenaltySystemMatricesx/PenaltySystemMatricesx.cpp\
+					./modules/PenaltySystemMatricesx/PenaltySystemMatricesx.h\
+					./modules/Solverx/Solverx.cpp\
+					./modules/Solverx/Solverx.h\
+					./modules/Mergesolutionfromftogx/Mergesolutionfromftogx.cpp\
+					./modules/Mergesolutionfromftogx/Mergesolutionfromftogx.h\
+					./modules/ProcessParamsx/ProcessParamsx.cpp\
+					./modules/ProcessParamsx/ProcessParamsx.h\
+					./modules/Qmux/Qmux.h\
+					./modules/Qmux/Qmux.cpp\
+					./modules/Qmux/DakotaResponses.cpp\
+					./modules/Qmux/SpawnCore.cpp\
+					./modules/Qmux/SpawnCoreParallel.cpp\
+					./modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp\
+					./modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h\
+					./modules/FieldDepthAveragex/FieldDepthAveragex.cpp\
+					./modules/FieldDepthAveragex/FieldDepthAveragex.h\
+					./modules/DepthAverageInputx/DepthAverageInputx.cpp\
+					./modules/DepthAverageInputx/DepthAverageInputx.h\
+					./modules/FieldExtrudex/FieldExtrudex.cpp\
+					./modules/FieldExtrudex/FieldExtrudex.h\
+					./modules/InputToResultx/InputToResultx.cpp\
+					./modules/InputToResultx/InputToResultx.h\
+					./modules/ExtrudeInputx/ExtrudeInputx.cpp\
+					./modules/ExtrudeInputx/ExtrudeInputx.h\
+					./modules/OutputRiftsx/OutputRiftsx.h\
+					./modules/OutputRiftsx/OutputRiftsx.cpp\
 					./solutions/diagnostic_core.cpp\
 					./solutions/diagnostic_core_linear.cpp\
@@ -861,66 +909,8 @@
 					./solutions/steadystate_core.cpp\
 					./solutions/OutputResults.cpp\
-					./Bamgx/Bamgx.cpp\
-					./Bamgx/Bamgx.h\
-					./Bamgx/include/include.h \
-					./Bamgx/include/macros.h \
-					./Bamgx/include/typedefs.h \
-					./Bamgx/objects/BamgObjects.h \
-					./Bamgx/objects/CrackedEdge.h\
-					./Bamgx/objects/CrackedEdge.cpp\
-					./Bamgx/objects/Curve.h\
-					./Bamgx/objects/Curve.cpp\
-					./Bamgx/objects/Direction.h\
-					./Bamgx/objects/Direction.cpp\
-					./Bamgx/objects/DoubleAndInt.h\
-					./Bamgx/objects/Edge.h\
-					./Bamgx/objects/Edge.cpp\
-					./Bamgx/objects/GeometricalEdge.h\
-					./Bamgx/objects/GeometricalEdge.cpp\
-					./Bamgx/objects/GeometricalSubDomain.h\
-					./Bamgx/objects/GeometricalSubDomain.cpp\
-					./Bamgx/objects/GeometricalVertex.h\
-					./Bamgx/objects/GeometricalVertex.cpp\
-					./Bamgx/objects/Geometry.cpp\
-					./Bamgx/objects/Geometry.h\
-					./Bamgx/objects/ListofIntersectionTriangles.cpp\
-					./Bamgx/objects/ListofIntersectionTriangles.h\
-					./Bamgx/objects/MatVVP2x2.cpp\
-					./Bamgx/objects/Metric.cpp\
-					./Bamgx/objects/Metric.h\
-					./Bamgx/objects/QuadTree.cpp\
-					./Bamgx/objects/QuadTree.h\
-					./Bamgx/objects/R2.h\
-					./Bamgx/objects/SetOfE4.cpp\
-					./Bamgx/objects/SetOfE4.h\
-					./Bamgx/objects/SubDomain.h\
-					./Bamgx/objects/SubDomain.cpp\
-					./Bamgx/objects/TriangleAdjacent.h\
-					./Bamgx/objects/TriangleAdjacent.cpp\
-					./Bamgx/objects/Triangle.cpp\
-					./Bamgx/objects/Triangle.h\
-					./Bamgx/objects/Triangles.cpp\
-					./Bamgx/objects/Triangles.h\
-					./Bamgx/objects/MeshVertex.cpp\
-					./Bamgx/objects/MeshVertex.h\
-					./Bamgx/objects/VertexOnEdge.h\
-					./Bamgx/objects/VertexOnEdge.cpp\
-					./Bamgx/objects/VertexOnGeom.h\
-					./Bamgx/objects/VertexOnGeom.cpp\
-					./Bamgx/objects/VertexOnVertex.h\
-					./Bamgx/objects/VertexOnVertex.cpp\
-					./Bamgx/shared/Abs.h \
-					./Bamgx/shared/BigPrimeNumber.h\
-					./Bamgx/shared/BigPrimeNumber.cpp\
-					./Bamgx/shared/BinaryRand.h \
-					./Bamgx/shared/det.h \
-					./Bamgx/shared/Exchange.h \
-					./Bamgx/shared/extrema.h \
-					./Bamgx/shared/HeapSort.h \
-					./Bamgx/shared/Norm.h \
-					./Bamgx/shared/OppositeAngle.h \
-					./Bamgx/shared/shared.h\
-					./BamgConvertMeshx/BamgConvertMeshx.cpp\
-					./BamgConvertMeshx/BamgConvertMeshx.h
+					./modules/Bamgx/Bamgx.cpp\
+					./modules/Bamgx/Bamgx.h\
+					./modules/BamgConvertMeshx/BamgConvertMeshx.cpp\
+					./modules/BamgConvertMeshx/BamgConvertMeshx.h
 
 libpISSM_a_CXXFLAGS = -fPIC -D_PARALLEL_   -D_C_ $(CXXOPTFLAGS)
Index: issm/trunk/src/c/include/macros.h
===================================================================
--- issm/trunk/src/c/include/macros.h	(revision 3912)
+++ issm/trunk/src/c/include/macros.h	(revision 3913)
@@ -5,4 +5,6 @@
 #ifndef _MACROS_H_
 #define _MACROS_H_
+
+#include "./typedefs.h"
 
 #ifdef HAVE_CONFIG_H
@@ -67,3 +69,4 @@
 #endif
 
+
 #endif
Index: issm/trunk/src/c/modules/AverageFilterx/AverageFilterx.cpp
===================================================================
--- issm/trunk/src/c/modules/AverageFilterx/AverageFilterx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/AverageFilterx/AverageFilterx.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include <time.h>
 #include "./AverageFilterx.h"
-#include "../shared/shared.h"
+#include "../../shared/shared.h"
 
 int AverageFilterx(double** pimageout,double* image, int lines,int samps,int smooth){
Index: issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp
===================================================================
--- issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.cpp	(revision 3913)
@@ -4,9 +4,8 @@
 #include "./BamgConvertMeshx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-
-#include "../Bamgx/objects/BamgObjects.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../objects/objects.h"
 
 using namespace bamg;
Index: issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.h
===================================================================
--- issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.h	(revision 3912)
+++ issm/trunk/src/c/modules/BamgConvertMeshx/BamgConvertMeshx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _BAMGCONVERTMESHX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/BuildNodeSetsx/BuildNodeSetsx.cpp
===================================================================
--- issm/trunk/src/c/modules/BuildNodeSetsx/BuildNodeSetsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/BuildNodeSetsx/BuildNodeSetsx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./BuildNodeSetsx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 int BuildNodeSetsx( NodeSets** pnodesets, DataSet* nodes){
Index: issm/trunk/src/c/modules/BuildNodeSetsx/BuildNodeSetsx.h
===================================================================
--- issm/trunk/src/c/modules/BuildNodeSetsx/BuildNodeSetsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/BuildNodeSetsx/BuildNodeSetsx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _BUILDNODESETSX_H
 
-#include "../DataSet/DataSet.h" 
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h" 
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/BuildNodeSetsx/PartitionSets.cpp
===================================================================
--- issm/trunk/src/c/modules/BuildNodeSetsx/PartitionSets.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/BuildNodeSetsx/PartitionSets.cpp	(revision 3913)
@@ -4,6 +4,6 @@
 	
 #include "stdio.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
 
 void PartitionSets(Vec* ppartitionb, Vec* ppartitionc,Vec flags_a,Vec flags_b,Vec flags_c,int gsize){
Index: issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.cpp
===================================================================
--- issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./ComputeBasalStressx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void	ComputeBasalStressx( Vec* psigma,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads, DataSet* materials,Parameters* parameters,
Index: issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.h
===================================================================
--- issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _COMPUTEBASALSTRESSX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.cpp
===================================================================
--- issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./ComputePressurex.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void	ComputePressurex( Vec* pp_g,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads, DataSet* materials,Parameters* parameters,
Index: issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.h
===================================================================
--- issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.h	(revision 3912)
+++ issm/trunk/src/c/modules/ComputePressurex/ComputePressurex.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _COMPUTEPRESSUREX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ComputeStrainRatex/ComputeStrainRatex.cpp
===================================================================
--- issm/trunk/src/c/modules/ComputeStrainRatex/ComputeStrainRatex.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ComputeStrainRatex/ComputeStrainRatex.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./ComputeStrainRatex.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void	ComputeStrainRatex( Vec* peps,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads, DataSet* materials,Parameters* parameters,
Index: issm/trunk/src/c/modules/ComputeStrainRatex/ComputeStrainRatex.h
===================================================================
--- issm/trunk/src/c/modules/ComputeStrainRatex/ComputeStrainRatex.h	(revision 3912)
+++ issm/trunk/src/c/modules/ComputeStrainRatex/ComputeStrainRatex.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _COMPUTESTRAINRATEX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp
===================================================================
--- issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./ConfigureObjectsx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 int	ConfigureObjectsx( DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials,Parameters* parameters){
Index: issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.h
===================================================================
--- issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ConfigureObjectsx/ConfigureObjectsx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _CONFIGUREOBJECTSX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h
===================================================================
--- issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ContourToMeshx/ContourToMeshx.h	(revision 3913)
@@ -7,6 +7,6 @@
 #define _CONTOURTOMESHX_H
 
-#include "../shared/shared.h"
-#include "../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../objects/objects.h"
 
 /*threading: */
Index: issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.h
===================================================================
--- issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ContourToNodesx/ContourToNodesx.h	(revision 3913)
@@ -7,6 +7,6 @@
 #define _CONTOURTONODESX_H
 
-#include "../shared/shared.h"
-#include "../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.cpp
===================================================================
--- issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./ControlConstrainx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void ControlConstrainx( double* p_g, int numdofnodes, double cm_min, double cm_max,int control_type){
Index: issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.h
===================================================================
--- issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ControlConstrainx/ControlConstrainx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _CONTROLCONSTRAINX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp
===================================================================
--- issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./CostFunctionx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 #include "../SurfaceAreax/SurfaceAreax.h"
 
Index: issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.h
===================================================================
--- issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.h	(revision 3912)
+++ issm/trunk/src/c/modules/CostFunctionx/CostFunctionx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _COSTFUNCTIONX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.cpp
===================================================================
--- issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./DepthAverageInputx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void DepthAverageInputx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,int enum_type){
Index: issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.h
===================================================================
--- issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.h	(revision 3912)
+++ issm/trunk/src/c/modules/DepthAverageInputx/DepthAverageInputx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _DEPTHAVERAGEINPUTX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Dofx/Dofx.cpp
===================================================================
--- issm/trunk/src/c/modules/Dofx/Dofx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Dofx/Dofx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./Dofx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 int Dofx( DofVec** ppartition, DofVec** ptpartition, DataSet* elements,DataSet* nodes, DataSet* vertices, Parameters* parameters) {
Index: issm/trunk/src/c/modules/Dofx/Dofx.h
===================================================================
--- issm/trunk/src/c/modules/Dofx/Dofx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Dofx/Dofx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _DOFX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Dux/Dux.cpp
===================================================================
--- issm/trunk/src/c/modules/Dux/Dux.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Dux/Dux.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./Dux.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 #include "../SurfaceAreax/SurfaceAreax.h"
 
Index: issm/trunk/src/c/modules/Dux/Dux.h
===================================================================
--- issm/trunk/src/c/modules/Dux/Dux.h	(revision 3912)
+++ issm/trunk/src/c/modules/Dux/Dux.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _DUX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp
===================================================================
--- issm/trunk/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp	(revision 3913)
@@ -10,8 +10,8 @@
 #include "./ElementConnectivityx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 int hascommondedge(double* element1,double* element2);
Index: issm/trunk/src/c/modules/ExtrudeInputx/ExtrudeInputx.cpp
===================================================================
--- issm/trunk/src/c/modules/ExtrudeInputx/ExtrudeInputx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ExtrudeInputx/ExtrudeInputx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./ExtrudeInputx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void ExtrudeInputx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,int enum_type){
Index: issm/trunk/src/c/modules/ExtrudeInputx/ExtrudeInputx.h
===================================================================
--- issm/trunk/src/c/modules/ExtrudeInputx/ExtrudeInputx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ExtrudeInputx/ExtrudeInputx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _EXTRUDEINPUTX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp
===================================================================
--- issm/trunk/src/c/modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./FieldAverageOntoVerticesx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void FieldAverageOntoVerticesx(Vec* pfield, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters){
Index: issm/trunk/src/c/modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h
===================================================================
--- issm/trunk/src/c/modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h	(revision 3912)
+++ issm/trunk/src/c/modules/FieldAverageOntoVerticesx/FieldAverageOntoVerticesx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _FIELDAVERAGEVERTICESX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/FieldDepthAveragex/FieldDepthAveragex.cpp
===================================================================
--- issm/trunk/src/c/modules/FieldDepthAveragex/FieldDepthAveragex.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/FieldDepthAveragex/FieldDepthAveragex.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./FieldDepthAveragex.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void FieldDepthAveragex( Vec field, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,char* fieldname){
Index: issm/trunk/src/c/modules/FieldDepthAveragex/FieldDepthAveragex.h
===================================================================
--- issm/trunk/src/c/modules/FieldDepthAveragex/FieldDepthAveragex.h	(revision 3912)
+++ issm/trunk/src/c/modules/FieldDepthAveragex/FieldDepthAveragex.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _FIELDDEPTHAVERAGEX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/FieldExtrudex/FieldExtrudex.cpp
===================================================================
--- issm/trunk/src/c/modules/FieldExtrudex/FieldExtrudex.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/FieldExtrudex/FieldExtrudex.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./FieldExtrudex.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void FieldExtrudex( Vec field, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,char* field_name,int collapse){
Index: issm/trunk/src/c/modules/FieldExtrudex/FieldExtrudex.h
===================================================================
--- issm/trunk/src/c/modules/FieldExtrudex/FieldExtrudex.h	(revision 3912)
+++ issm/trunk/src/c/modules/FieldExtrudex/FieldExtrudex.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _FIELDEXTRUDEX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp
===================================================================
--- issm/trunk/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.cpp	(revision 3913)
@@ -4,8 +4,8 @@
 
 #include "./GetSolutionFromInputsx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void	GetSolutionFromInputsx( Vec* psolution, DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads, DataSet* materials,  Parameters* parameters, int analysis_type, int sub_analysis_type){
Index: issm/trunk/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.h
===================================================================
--- issm/trunk/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/GetSolutionFromInputsx/GetSolutionFromInputsx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _GETSOLUTIONFROMINPUTSXX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Gradjx/Gradjx.cpp
===================================================================
--- issm/trunk/src/c/modules/Gradjx/Gradjx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Gradjx/Gradjx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./Gradjx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void Gradjx( Vec* pgrad_g, int numberofnodes, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,
Index: issm/trunk/src/c/modules/Gradjx/Gradjx.h
===================================================================
--- issm/trunk/src/c/modules/Gradjx/Gradjx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Gradjx/Gradjx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _GRADJX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/HoleFillerx/HoleFillerx.cpp
===================================================================
--- issm/trunk/src/c/modules/HoleFillerx/HoleFillerx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/HoleFillerx/HoleFillerx.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include <time.h>
 #include "./HoleFillerx.h"
-#include "../shared/shared.h"
+#include "../../shared/shared.h"
 
 int HoleFillerx(double** pimageout,double* image, int lines,int samps,int smooth){
Index: issm/trunk/src/c/modules/InputToResultx/InputToResultx.cpp
===================================================================
--- issm/trunk/src/c/modules/InputToResultx/InputToResultx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/InputToResultx/InputToResultx.cpp	(revision 3913)
@@ -5,9 +5,9 @@
 #include "./InputToResultx.h"
 
-#include "../shared/shared.h"
-#include "../objects/objects.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../objects/objects.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void InputToResultx(Result** presult,DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials,Parameters* parameters,int enum_type,int id, double time, int step){
Index: issm/trunk/src/c/modules/InputToResultx/InputToResultx.h
===================================================================
--- issm/trunk/src/c/modules/InputToResultx/InputToResultx.h	(revision 3912)
+++ issm/trunk/src/c/modules/InputToResultx/InputToResultx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _INPUTTORESULTX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp
===================================================================
--- issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp	(revision 3913)
@@ -10,6 +10,6 @@
 
 #include "./InterpFromGridToMeshx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
 
 int InterpFromGridToMeshx( Vec* pdata_mesh,double* x_in, int x_rows, double* y_in, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods,double default_value) {
Index: issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.h
===================================================================
--- issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.h	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _INTERPFROMGRIDTOMESHX_H
 
-#include "../toolkits/toolkits.h"
+#include "../../toolkits/toolkits.h"
 
 
Index: issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp
===================================================================
--- issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp	(revision 3913)
@@ -4,5 +4,5 @@
 
 #include "./InterpFromGridToMeshx.h"
-#include "../shared/shared.h"
+#include "../../shared/shared.h"
 
 void* InterpFromGridToMeshxt(void* vpthread_handle){
Index: issm/trunk/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp
===================================================================
--- issm/trunk/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp	(revision 3913)
@@ -4,6 +4,6 @@
 
 #include "./InterpFromMeshToGridx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
 
 void InterpFromMeshToGridx(double** px_m,double** py_m,double** pgriddata,double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh, int data_length, double cornereast,double cornernorth,double xposting,double yposting,int nlines,int ncols,double default_value) {
Index: issm/trunk/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h
===================================================================
--- issm/trunk/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _INTERPFROMMESHTOGRIDX_H
 
-#include "../toolkits/toolkits.h"
+#include "../../toolkits/toolkits.h"
 
 void InterpFromMeshToGridx(double** px_m,double** py_m,double** pgriddata,double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh, int data_length, double cornereast,double cornernorth,double xposting,double yposting,int nlines,int ncols,double default_value);
Index: issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp
===================================================================
--- issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 3913)
@@ -4,9 +4,8 @@
 #include "./InterpFromMeshToMesh2dx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-
-#include "../Bamgx/objects/BamgObjects.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../objects/objects.h"
 
 using namespace bamg;
Index: issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h
===================================================================
--- issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _INTERPFROMMESHTOMESH2DX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp
===================================================================
--- issm/trunk/src/c/modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.cpp	(revision 3913)
@@ -4,6 +4,6 @@
 
 #include "./InterpFromMeshToMesh3dx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
 
 int InterpFromMeshToMesh3dx( Vec* pdata_prime,double* index_data, double* x_data, double* y_data, double* z_data, int nods_data,int nels_data, double* data, int data_length, double* x_prime, double* y_prime, double* z_prime, int nods_prime,double default_value) {
Index: issm/trunk/src/c/modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h
===================================================================
--- issm/trunk/src/c/modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h	(revision 3912)
+++ issm/trunk/src/c/modules/InterpFromMeshToMesh3dx/InterpFromMeshToMesh3dx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _INTERPFROMMESHTOMESH3DX_H
 
-#include "../toolkits/toolkits.h"
+#include "../../toolkits/toolkits.h"
 
 int InterpFromMeshToMesh3dx( Vec* pdata_prime,double* index_data, double* x_data, double* y_data, double* z_data, int nods_data,int nels_data, double* data, int data_length, double* x_prime, double* y_prime, double* z_prime, int nods_prime,double default_value);
Index: issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp
===================================================================
--- issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./MassFluxx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void MassFluxx(double* pmass_flux, DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads,DataSet* materials,Parameters* parameters,  double* segments,int num_segments,double* ug){
Index: issm/trunk/src/c/modules/MassFluxx/MassFluxx.h
===================================================================
--- issm/trunk/src/c/modules/MassFluxx/MassFluxx.h	(revision 3912)
+++ issm/trunk/src/c/modules/MassFluxx/MassFluxx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _MASSFLUXX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Mergesolutionfromftogx/Mergesolutionfromftogx.h
===================================================================
--- issm/trunk/src/c/modules/Mergesolutionfromftogx/Mergesolutionfromftogx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Mergesolutionfromftogx/Mergesolutionfromftogx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _MERGESOLUTIONFROMFTOGX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/MeshPartitionx/MeshPartitionx.cpp
===================================================================
--- issm/trunk/src/c/modules/MeshPartitionx/MeshPartitionx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/MeshPartitionx/MeshPartitionx.cpp	(revision 3913)
@@ -4,8 +4,8 @@
 
 #include "./MeshPartitionx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 int MeshPartitionx(int** pepart, int** pnpart, int numberofelements,int numberofgrids,double* elements,
Index: issm/trunk/src/c/modules/Misfitx/Misfitx.cpp
===================================================================
--- issm/trunk/src/c/modules/Misfitx/Misfitx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Misfitx/Misfitx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./Misfitx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 #include "../SurfaceAreax/SurfaceAreax.h"
 
Index: issm/trunk/src/c/modules/Misfitx/Misfitx.h
===================================================================
--- issm/trunk/src/c/modules/Misfitx/Misfitx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Misfitx/Misfitx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _MISFITX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateConstraintsBalancedthickness.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateElementsNodesAndMaterialsBalancedthickness.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness/CreateLoadsBalancedthickness.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateConstraintsBalancedthickness2.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../io/io.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../io/io.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateElementsNodesAndMaterialsBalancedthickness2.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedthickness2/CreateLoadsBalancedthickness2.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateConstraintsBalancedvelocities.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateElementsNodesAndMaterialsBalancedvelocities.cpp	(revision 3913)
@@ -3,12 +3,12 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
-#include "../../include/include.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Balancedvelocities/CreateLoadsBalancedvelocities.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */ 
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/CreateDataSets.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/CreateDataSets.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/CreateDataSets.cpp	(revision 3913)
@@ -9,9 +9,9 @@
 #endif
 
-#include "../objects/objects.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "./ModelProcessorx/ModelProcessorx.h"
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "./ModelProcessorx.h"
 
 
Index: issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */ 
 
-#include "../DataSet/DataSet.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../objects/objects.h"
-#include "../shared/shared.h"
+#include "../../DataSet/DataSet.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
 #include "../MeshPartitionx/MeshPartitionx.h"
-#include "../io/io.h"
+#include "../../io/io.h"
 
 void CreateParameters(Parameters** pparameters,IoModel* iomodel,ConstDataHandle iomodel_handle){
Index: issm/trunk/src/c/modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp	(revision 3913)
@@ -9,7 +9,7 @@
 #endif
 
-#include "../shared/shared.h"
-#include "../io/io.h"
-#include "../include/include.h"
+#include "../../shared/shared.h"
+#include "../../io/io.h"
+#include "../../include/include.h"
 #include "./ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateElementsNodesAndMaterialsDiagnosticHoriz.cpp	(revision 3913)
@@ -3,12 +3,12 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
-#include "../../include/include.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateElementsNodesAndMaterialsDiagnosticHutter.cpp	(revision 3913)
@@ -3,12 +3,12 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
-#include "../../include/include.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateConstraintsDiagnosticStokes.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateElementsNodesAndMaterialsDiagnosticStokes.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticStokes/CreateLoadsDiagnosticStokes.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateConstraintsDiagnosticVert.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateElementsNodesAndMaterialsDiagnosticVert.cpp	(revision 3913)
@@ -3,12 +3,12 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
-#include "../../include/include.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/DiagnosticVert/CreateLoadsDiagnosticVert.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateConstraintsMelting.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateConstraintsMelting.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateConstraintsMelting.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateElementsNodesAndMaterialsMelting.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../include/include.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../include/include.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateLoadsMelting.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateLoadsMelting.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Melting/CreateLoadsMelting.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/ModelProcessorx.h
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/ModelProcessorx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/ModelProcessorx.h	(revision 3913)
@@ -11,5 +11,5 @@
 class IoModel;
 class Parameters;
-#include "../io/io.h"
+#include "../../io/io.h"
 
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Partitioning.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Partitioning.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Partitioning.cpp	(revision 3913)
@@ -10,9 +10,9 @@
 
 #include <string.h>
-#include "../objects/objects.h"
-#include "../shared/shared.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../io/io.h"
-#include "../include/include.h"
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../io/io.h"
+#include "../../include/include.h"
 #include "../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx/ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateConstraintsPrognostic.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../io/io.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../io/io.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateElementsNodesAndMaterialsPrognostic.cpp	(revision 3913)
@@ -3,12 +3,12 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../io/io.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../io/io.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
-#include "../../include/include.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateConstraintsPrognostic2.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateElementsNodesAndMaterialsPrognostic2.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../io/io.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../io/io.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateLoadsPrognostic2.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../io/io.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../io/io.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateParametersPrognostic2.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateParametersPrognostic2.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Prognostic2/CreateParametersPrognostic2.cpp	(revision 3913)
@@ -4,10 +4,10 @@
 
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Qmu/CreateParametersQmu.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */ 
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../io/io.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../io/io.h"
+#include "../../../include/include.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateConstraintsSlopeCompute.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateElementsNodesAndMaterialsSlopeCompute.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/SlopeCompute/CreateLoadsSlopeCompute.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateConstraintsThermal.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateConstraintsThermal.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateConstraintsThermal.cpp	(revision 3913)
@@ -3,10 +3,10 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../io/io.h"
-#include "../../toolkits/toolkits.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../io/io.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateElementsNodesAndMaterialsThermal.cpp	(revision 3913)
@@ -3,11 +3,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../include/include.h"
-#include "../../shared/shared.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../include/include.h"
+#include "../../../shared/shared.h"
 #include "../../MeshPartitionx/MeshPartitionx.h"
 #include "../ModelProcessorx.h"
Index: issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateLoadsThermal.cpp
===================================================================
--- issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateLoadsThermal.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ModelProcessorx/Thermal/CreateLoadsThermal.cpp	(revision 3913)
@@ -2,11 +2,11 @@
  */
 
-#include "../../DataSet/DataSet.h"
-#include "../../toolkits/toolkits.h"
-#include "../../io/io.h"
-#include "../../EnumDefinitions/EnumDefinitions.h"
-#include "../../objects/objects.h"
-#include "../../shared/shared.h"
-#include "../../include/include.h"
+#include "../../../DataSet/DataSet.h"
+#include "../../../toolkits/toolkits.h"
+#include "../../../io/io.h"
+#include "../../../EnumDefinitions/EnumDefinitions.h"
+#include "../../../objects/objects.h"
+#include "../../../shared/shared.h"
+#include "../../../include/include.h"
 #include "../ModelProcessorx.h"
 
Index: issm/trunk/src/c/modules/MpcNodesx/MpcNodesx.cpp
===================================================================
--- issm/trunk/src/c/modules/MpcNodesx/MpcNodesx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/MpcNodesx/MpcNodesx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./MpcNodesx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 int MpcNodesx( Mat* pRmg, DataSet* nodes,DataSet* constraints){
Index: issm/trunk/src/c/modules/MpcNodesx/MpcNodesx.h
===================================================================
--- issm/trunk/src/c/modules/MpcNodesx/MpcNodesx.h	(revision 3912)
+++ issm/trunk/src/c/modules/MpcNodesx/MpcNodesx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _MPCNODESX_H
 
-#include "../DataSet/DataSet.h"
-#include "../toolkits/toolkits.h"
+#include "../../DataSet/DataSet.h"
+#include "../../toolkits/toolkits.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp
===================================================================
--- issm/trunk/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp	(revision 3913)
@@ -13,8 +13,8 @@
 #include "./NodeConnectivityx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void	NodeConnectivityx( double** pconnectivity, int* pwidth, double* elements, int nel, int nods){
Index: issm/trunk/src/c/modules/NormalizeConstraintsx/NormalizeConstraintsx.cpp
===================================================================
--- issm/trunk/src/c/modules/NormalizeConstraintsx/NormalizeConstraintsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/NormalizeConstraintsx/NormalizeConstraintsx.cpp	(revision 3913)
@@ -5,5 +5,5 @@
 #include "./NormalizeConstraintsx.h"
 
-#include "../shared/shared.h"
+#include "../../shared/shared.h"
 
 void NormalizeConstraintsx( Mat* pGmn, Mat Rmg, NodeSets* nodesets){
Index: issm/trunk/src/c/modules/NormalizeConstraintsx/NormalizeConstraintsx.h
===================================================================
--- issm/trunk/src/c/modules/NormalizeConstraintsx/NormalizeConstraintsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/NormalizeConstraintsx/NormalizeConstraintsx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _NORMALIZECONSTRAINTSX_H_
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Orthx/Orthx.h
===================================================================
--- issm/trunk/src/c/modules/Orthx/Orthx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Orthx/Orthx.h	(revision 3913)
@@ -6,7 +6,7 @@
 #define _ORTHX_H
 
-#include "../objects/objects.h"
-#include "../include/include.h"
-#include "../shared/shared.h"
+#include "../../objects/objects.h"
+#include "../../include/include.h"
+#include "../../shared/shared.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/OutputRiftsx/OutputRiftsx.cpp
===================================================================
--- issm/trunk/src/c/modules/OutputRiftsx/OutputRiftsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/OutputRiftsx/OutputRiftsx.cpp	(revision 3913)
@@ -6,8 +6,8 @@
 #include "./OutputRiftsx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void OutputRiftsx( Vec* priftproperties, DataSet* loads, int numrifts){
Index: issm/trunk/src/c/modules/OutputRiftsx/OutputRiftsx.h
===================================================================
--- issm/trunk/src/c/modules/OutputRiftsx/OutputRiftsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/OutputRiftsx/OutputRiftsx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _OUTPUTRIFTSX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/PenaltyConstraintsx/PenaltyConstraintsx.cpp
===================================================================
--- issm/trunk/src/c/modules/PenaltyConstraintsx/PenaltyConstraintsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/PenaltyConstraintsx/PenaltyConstraintsx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./PenaltyConstraintsx.h"
 #include "./RiftConstraints.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void PenaltyConstraintsx(int* pconverged, int* pnum_unstable_constraints, DataSet* elements,DataSet* nodes, DataSet* vertices,
Index: issm/trunk/src/c/modules/PenaltyConstraintsx/PenaltyConstraintsx.h
===================================================================
--- issm/trunk/src/c/modules/PenaltyConstraintsx/PenaltyConstraintsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/PenaltyConstraintsx/PenaltyConstraintsx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _PENALTYCONSTRAINTSX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/PenaltyConstraintsx/RiftConstraints.cpp
===================================================================
--- issm/trunk/src/c/modules/PenaltyConstraintsx/RiftConstraints.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/PenaltyConstraintsx/RiftConstraints.cpp	(revision 3913)
@@ -4,7 +4,7 @@
 
 #include "./RiftConstraints.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../include/include.h"
-#include "../shared/shared.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../include/include.h"
+#include "../../shared/shared.h"
 
 #define _ZIGZAGCOUNTER_
Index: issm/trunk/src/c/modules/PenaltyConstraintsx/RiftConstraints.h
===================================================================
--- issm/trunk/src/c/modules/PenaltyConstraintsx/RiftConstraints.h	(revision 3912)
+++ issm/trunk/src/c/modules/PenaltyConstraintsx/RiftConstraints.h	(revision 3913)
@@ -7,6 +7,6 @@
 #define _RIFTCONSTRAINTS_H_
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 int RiftConstraints(int* pconverged, int* pnum_unstable_constraints,DataSet* loads,int min_mechanical_constraints,int analysis_type,int sub_analysis_type);
Index: issm/trunk/src/c/modules/PenaltySystemMatricesx/PenaltySystemMatricesx.cpp
===================================================================
--- issm/trunk/src/c/modules/PenaltySystemMatricesx/PenaltySystemMatricesx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/PenaltySystemMatricesx/PenaltySystemMatricesx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./PenaltySystemMatricesx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void PenaltySystemMatricesx(Mat Kgg, Vec pg,double* pkmax,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads,DataSet* materials, Parameters* parameters,
Index: issm/trunk/src/c/modules/PenaltySystemMatricesx/PenaltySystemMatricesx.h
===================================================================
--- issm/trunk/src/c/modules/PenaltySystemMatricesx/PenaltySystemMatricesx.h	(revision 3912)
+++ issm/trunk/src/c/modules/PenaltySystemMatricesx/PenaltySystemMatricesx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _PENALTYSYSTEMMATRICESX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/ProcessParamsx/ProcessParamsx.cpp
===================================================================
--- issm/trunk/src/c/modules/ProcessParamsx/ProcessParamsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/ProcessParamsx/ProcessParamsx.cpp	(revision 3913)
@@ -9,9 +9,9 @@
 #include "./ProcessParamsx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../DataSet/DataSet.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../DataSet/DataSet.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void ProcessParamsx( Parameters* parameters, Vec  part){
Index: issm/trunk/src/c/modules/ProcessParamsx/ProcessParamsx.h
===================================================================
--- issm/trunk/src/c/modules/ProcessParamsx/ProcessParamsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/ProcessParamsx/ProcessParamsx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _PROCESSPARAMSX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.cpp
===================================================================
--- issm/trunk/src/c/modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.cpp	(revision 3913)
@@ -4,7 +4,7 @@
 #include "./PropagateFlagsFromConnectivityx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
 
 void RecursivePropagation(double* pool, double* connectivity,int index, double* flags);
Index: issm/trunk/src/c/modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.h
===================================================================
--- issm/trunk/src/c/modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.h	(revision 3912)
+++ issm/trunk/src/c/modules/PropagateFlagsFromConnectivityx/PropagateFlagsFromConnectivityx.h	(revision 3913)
@@ -5,5 +5,5 @@
 #define _PROPAGATEFLAGSFROMCONNECTIVITYX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Qmux/DakotaResponses.cpp
===================================================================
--- issm/trunk/src/c/modules/Qmux/DakotaResponses.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Qmux/DakotaResponses.cpp	(revision 3913)
@@ -9,8 +9,8 @@
 #endif
 
-#include "../DataSet/DataSet.h"    
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../DataSet/DataSet.h"    
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 #include "../MassFluxx/MassFluxx.h"
 #include "../Misfitx/Misfitx.h"
Index: issm/trunk/src/c/modules/Qmux/Qmux.cpp
===================================================================
--- issm/trunk/src/c/modules/Qmux/Qmux.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Qmux/Qmux.cpp	(revision 3913)
@@ -35,9 +35,9 @@
 #include "./Qmux.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../objects/DakotaPlugin.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../objects/DakotaPlugin.h"
 
 #ifdef _HAVE_DAKOTA_ //only works if dakota library has been compiled in.
Index: issm/trunk/src/c/modules/Qmux/Qmux.h
===================================================================
--- issm/trunk/src/c/modules/Qmux/Qmux.h	(revision 3912)
+++ issm/trunk/src/c/modules/Qmux/Qmux.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _QMUX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Qmux/SpawnCore.cpp
===================================================================
--- issm/trunk/src/c/modules/Qmux/SpawnCore.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Qmux/SpawnCore.cpp	(revision 3913)
@@ -10,10 +10,10 @@
 
 
-#include "../objects/objects.h"
-#include "../io/io.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../shared/shared.h"
+#include "../../objects/objects.h"
+#include "../../io/io.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
 #include "./Qmux.h"
-#include "../include/include.h"
+#include "../../include/include.h"
 
 int SpawnCore(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, void* model,int analysis_type,int sub_analysis_type,int counter){
Index: issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp
===================================================================
--- issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Qmux/SpawnCoreParallel.cpp	(revision 3913)
@@ -26,11 +26,11 @@
 
 
-#include "../objects/objects.h"
-#include "../io/io.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../shared/shared.h"
+#include "../../objects/objects.h"
+#include "../../io/io.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
 #include "./Qmux.h"
-#include "../include/include.h"
-#include "../solutions/solutions.h"
+#include "../../include/include.h"
+#include "../../solutions/solutions.h"
 
 void SpawnCoreParallel(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, Model* model,int analysis_type,int sub_analysis_type,int counter){
Index: issm/trunk/src/c/modules/Qmux/SpawnCoreSerial.cpp
===================================================================
--- issm/trunk/src/c/modules/Qmux/SpawnCoreSerial.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Qmux/SpawnCoreSerial.cpp	(revision 3913)
@@ -12,10 +12,10 @@
 
 
-#include "../objects/objects.h"
-#include "../io/io.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../shared/shared.h"
+#include "../../objects/objects.h"
+#include "../../io/io.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
 #include "./Qmux.h"
-#include "../include/include.h"
+#include "../../include/include.h"
 
 void SpawnCoreSerial(double* responses, int numresponses, double* variables, char** variables_descriptors,int numvariables, mxArray* model,int analysis_type,int sub_analysis_type,int counter){
Index: issm/trunk/src/c/modules/Reduceloadfromgtofx/Reduceloadfromgtofx.h
===================================================================
--- issm/trunk/src/c/modules/Reduceloadfromgtofx/Reduceloadfromgtofx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Reduceloadfromgtofx/Reduceloadfromgtofx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _REDUCELOADFROMGTOFX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Reducematrixfromgtofx/Reducematrixfromgtofx.h
===================================================================
--- issm/trunk/src/c/modules/Reducematrixfromgtofx/Reducematrixfromgtofx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Reducematrixfromgtofx/Reducematrixfromgtofx.h	(revision 3913)
@@ -7,5 +7,5 @@
 #define _REDUCEMATRIXFROMGTOFX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Reducematrixfromgtofx/Reducematrixfromgton.cpp
===================================================================
--- issm/trunk/src/c/modules/Reducematrixfromgtofx/Reducematrixfromgton.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Reducematrixfromgtofx/Reducematrixfromgton.cpp	(revision 3913)
@@ -9,5 +9,5 @@
 #endif
 
-#include "../toolkits/toolkits.h"
+#include "../../toolkits/toolkits.h"
 
 void  Reducematrixfromgton(Mat* pKnn,Mat Kgg,Mat Gmn,double* pv_m,int msize, double* pv_n,int nsize,int flag){
Index: issm/trunk/src/c/modules/Reducevectorgtofx/Reducevectorgtofx.h
===================================================================
--- issm/trunk/src/c/modules/Reducevectorgtofx/Reducevectorgtofx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Reducevectorgtofx/Reducevectorgtofx.h	(revision 3913)
@@ -7,5 +7,5 @@
 #define _REDUCEVECTORGTOFX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Reducevectorgtosx/Reducevectorgtosx.h
===================================================================
--- issm/trunk/src/c/modules/Reducevectorgtosx/Reducevectorgtosx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Reducevectorgtosx/Reducevectorgtosx.h	(revision 3913)
@@ -7,5 +7,5 @@
 #define _REDUCEVECTORGTOSX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/Solverx/Solverx.cpp
===================================================================
--- issm/trunk/src/c/modules/Solverx/Solverx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/Solverx/Solverx.cpp	(revision 3913)
@@ -5,6 +5,6 @@
 #include "./Solverx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
 
 #ifdef HAVE_CONFIG_H
Index: issm/trunk/src/c/modules/Solverx/Solverx.h
===================================================================
--- issm/trunk/src/c/modules/Solverx/Solverx.h	(revision 3912)
+++ issm/trunk/src/c/modules/Solverx/Solverx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _SOLVERX_H
 
-#include "../objects/objects.h"
+#include "../../objects/objects.h"
 
 
Index: issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp
===================================================================
--- issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./SpcNodesx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void SpcNodesx( DofVec** pyg, DataSet* nodes,DataSet* constraints){
Index: issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.h
===================================================================
--- issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.h	(revision 3912)
+++ issm/trunk/src/c/modules/SpcNodesx/SpcNodesx.h	(revision 3913)
@@ -6,7 +6,7 @@
 #define _SPCNODESX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
-#include "../toolkits/toolkits.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../toolkits/toolkits.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/SplitSolutionVectorx/SplitSolutionVectorx.cpp
===================================================================
--- issm/trunk/src/c/modules/SplitSolutionVectorx/SplitSolutionVectorx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/SplitSolutionVectorx/SplitSolutionVectorx.cpp	(revision 3913)
@@ -3,5 +3,5 @@
 
 #include "./SplitSolutionVectorx.h"
-#include "../shared/shared.h"
+#include "../../shared/shared.h"
 
 void SplitSolutionVectorx(Vec u_g,int numberofnodes,int numberofdofs, ...){
Index: issm/trunk/src/c/modules/SplitSolutionVectorx/SplitSolutionVectorx.h
===================================================================
--- issm/trunk/src/c/modules/SplitSolutionVectorx/SplitSolutionVectorx.h	(revision 3912)
+++ issm/trunk/src/c/modules/SplitSolutionVectorx/SplitSolutionVectorx.h	(revision 3913)
@@ -12,5 +12,5 @@
 
 #include <stdarg.h>
-#include "../toolkits/toolkits.h"
+#include "../../toolkits/toolkits.h"
 
 void SplitSolutionVectorx(Vec u_g,int numberofnodes,int numberofdofs, ...);
Index: issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.cpp
===================================================================
--- issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./SurfaceAreax.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void SurfaceAreax( double* pS, DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials,Parameters* parameters,
Index: issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.h
===================================================================
--- issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.h	(revision 3912)
+++ issm/trunk/src/c/modules/SurfaceAreax/SurfaceAreax.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _SURFACEAREAX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/SystemMatricesx/SystemMatricesx.cpp
===================================================================
--- issm/trunk/src/c/modules/SystemMatricesx/SystemMatricesx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/SystemMatricesx/SystemMatricesx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./SystemMatricesx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void SystemMatricesx(Mat* pKgg, Vec* ppg,DataSet* elements,DataSet* nodes, DataSet* vertices,DataSet* loads,DataSet* materials, Parameters* parameters,
Index: issm/trunk/src/c/modules/SystemMatricesx/SystemMatricesx.h
===================================================================
--- issm/trunk/src/c/modules/SystemMatricesx/SystemMatricesx.h	(revision 3912)
+++ issm/trunk/src/c/modules/SystemMatricesx/SystemMatricesx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _SYSTEMMATRICESX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/UpdateGeometryx/UpdateGeometryx.cpp
===================================================================
--- issm/trunk/src/c/modules/UpdateGeometryx/UpdateGeometryx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateGeometryx/UpdateGeometryx.cpp	(revision 3913)
@@ -5,9 +5,9 @@
 #include "./UpdateGeometryx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
-#include "../DataSet/DataSet.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../DataSet/DataSet.h"
 
 void UpdateGeometryx(Vec* poutthickness,Vec* poutbed,Vec* poutsurface, 
Index: issm/trunk/src/c/modules/UpdateGeometryx/UpdateGeometryx.h
===================================================================
--- issm/trunk/src/c/modules/UpdateGeometryx/UpdateGeometryx.h	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateGeometryx/UpdateGeometryx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _UPDATEGEOMETRYX_H
 
-#include "../DataSet/DataSet.h"
-#include "../objects/objects.h"
+#include "../../DataSet/DataSet.h"
+#include "../../objects/objects.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp
===================================================================
--- issm/trunk/src/c/modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.cpp	(revision 3913)
@@ -4,8 +4,8 @@
 
 #include "./UpdateInputsFromConstantx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void UpdateInputsFromConstantx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,double constant, int name){
Index: issm/trunk/src/c/modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.h
===================================================================
--- issm/trunk/src/c/modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.h	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateInputsFromConstantx/UpdateInputsFromConstantx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _UPDATEINPUTSFROMCONSTANTXX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp
===================================================================
--- issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.cpp	(revision 3913)
@@ -4,8 +4,8 @@
 
 #include "./UpdateInputsFromSolutionx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void UpdateInputsFromSolutionx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,Vec solution, int analysis_type, int sub_analysis_type){
Index: issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h
===================================================================
--- issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateInputsFromSolutionx/UpdateInputsFromSolutionx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _UPDATEINPUTSFROMSOLUTIONXX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp
===================================================================
--- issm/trunk/src/c/modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.cpp	(revision 3913)
@@ -4,8 +4,8 @@
 
 #include "./UpdateInputsFromVectorx.h"
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void UpdateInputsFromVectorx( DataSet* elements,DataSet* nodes, DataSet* vertices, DataSet* loads, DataSet* materials, Parameters* parameters,Vec vector, int NameEnum, int TypeEnum){
Index: issm/trunk/src/c/modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.h
===================================================================
--- issm/trunk/src/c/modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.h	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateInputsFromVectorx/UpdateInputsFromVectorx.h	(revision 3913)
@@ -6,6 +6,6 @@
 #define _UPDATEINPUTSFROMVECTORXX_H
 
-#include "../objects/objects.h"
-#include "../DataSet/DataSet.h"
+#include "../../objects/objects.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp
===================================================================
--- issm/trunk/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp	(revision 3913)
@@ -5,8 +5,8 @@
 #include "./UpdateVertexPositionsx.h"
 
-#include "../shared/shared.h"
-#include "../include/include.h"
-#include "../toolkits/toolkits.h"
-#include "../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
 
 void UpdateVertexPositionsx( DataSet* vertices, Vec thickness,Vec bed){
Index: issm/trunk/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.h
===================================================================
--- issm/trunk/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.h	(revision 3912)
+++ issm/trunk/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.h	(revision 3913)
@@ -6,5 +6,5 @@
 #define _UPDATEVERTEXPOSITIONSXX_H
 
-#include "../DataSet/DataSet.h"
+#include "../../DataSet/DataSet.h"
 
 /* local prototypes: */
Index: issm/trunk/src/c/objects/Bamg/CrackedEdge.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/CrackedEdge.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/CrackedEdge.cpp	(revision 3913)
@@ -0,0 +1,33 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "CrackedEdge.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+	/*FUNCTION CrackedEdge() {{{1*/
+	CrackedEdge::CrackedEdge() {
+		a=NULL;
+		b=NULL;
+		E=NULL;
+		e1=NULL;
+		e2=NULL;
+		indexa[0]=-1;
+		indexa[1]=-1;
+		indexa[2]=-1;
+		indexb[0]=-1;
+		indexb[1]=-1;
+		indexb[2]=-1;
+		length=0;
+		normal.x=0;
+		normal.y=0;
+
+	}
+	/*}}}*/
+
+	/*Methods*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/CrackedEdge.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/CrackedEdge.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/CrackedEdge.h	(revision 3913)
@@ -0,0 +1,31 @@
+#ifndef _CRACKEDEDGE_H_
+#define _CRACKEDEDGE_H_
+
+#include "./typedefs.h"
+
+namespace bamg {
+
+	//classes
+	class Triangle;
+	class GeometricalEdge;
+	class Edge;
+
+	class CrackedEdge {
+
+		public:
+			Triangle* a;
+			Triangle* b; 
+			GeometricalEdge* E;
+			Edge* e1;
+			Edge* e2;
+			double length;
+			R2     normal;
+			long   indexa[3];
+			long   indexb[3];
+
+			//Constructors
+			CrackedEdge();
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/Curve.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Curve.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Curve.cpp	(revision 3913)
@@ -0,0 +1,23 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "Curve.h"
+#include "Geometry.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION Curve::Set {{{1*/
+	void Curve::Set(const Curve & rec,const Geometry & Gh ,Geometry & GhNew){
+		*this = rec;
+		be = GhNew.edges + Gh.Number(be);    
+		ee = GhNew.edges + Gh.Number(ee); 
+		if(next) next= GhNew.curves + Gh.Number(next); 
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/Curve.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Curve.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Curve.h	(revision 3913)
@@ -0,0 +1,27 @@
+#ifndef _CURVE_H_
+#define _CURVE_H_
+
+#include "../../shared/Bamg/shared.h"
+
+namespace bamg {
+
+	//classes
+	class GeometricalEdge;
+	class Curve;
+	class Geometry;
+
+	class Curve {
+		public:
+			GeometricalEdge * be,*ee; // begin et end edge
+			int kb,ke;  //  begin vetex and end vertex
+			Curve* next; // next curve equi to this
+			bool master; // true => of equi curve point on this curve  
+
+			//Methods
+			Curve() : be(0),ee(0),kb(0),ke(0),next(0),master(true) {} 
+			void Reverse() { Exchange(be,ee); Exchange(kb,ke);} //  revese the sens of the curse 
+			void Set(const Curve & rec,const Geometry & Th ,Geometry & ThNew);
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/Direction.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Direction.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Direction.cpp	(revision 3913)
@@ -0,0 +1,31 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "Direction.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+	/*FUNCTION Direction(Icoor1 i,Icoor1 j) {{{1*/
+	Direction::Direction(Icoor1 i,Icoor1 j) {
+		Icoor2 n2 = 2*(Abs(i)+Abs(j));  
+		Icoor2 r  = MaxICoor* (Icoor2) i;
+		Icoor1 r1 = (Icoor1) (2*(r/ n2)); // odd number 
+		dir = (j>0) ? r1 : r1+1;          // odd-> j>0 even-> j<0
+	}/*}}}*/
+
+	/*Methods*/
+	/*FUNCTION Direction::sens{{{1*/
+	int Direction::sens(Icoor1 i,Icoor1 j) {
+		int r =1; 
+		if (dir!= MaxICoor) {
+			Icoor2 x(dir/2),y1(MaxICoor/2-Abs(x)),y(dir%2?-y1:y1);
+			r = (x*i + y*j) >=0;
+		}
+		return r;
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/Direction.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Direction.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Direction.h	(revision 3913)
@@ -0,0 +1,21 @@
+#ifndef _DIRECTION_H_
+#define _DIRECTION_H_
+
+#include "./include.h"
+#include "../../shared/Bamg/shared.h"
+
+namespace bamg {
+
+	class Direction {
+		private:
+			Icoor1 dir;
+
+		public:
+			//Methods
+			Direction(): dir(MaxICoor){}; //  no direction set
+			Direction(Icoor1 i,Icoor1 j);
+			int sens(Icoor1 i,Icoor1 j);
+	};
+}
+#endif
+
Index: issm/trunk/src/c/objects/Bamg/DoubleAndInt.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/DoubleAndInt.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/DoubleAndInt.h	(revision 3913)
@@ -0,0 +1,19 @@
+#ifndef _DOUBLEANDINT_H_
+#define _DOUBLEANDINT_H_
+
+#include "./include.h"
+
+namespace bamg {
+
+	class DoubleAndInt {
+		//class used by Triangles::MakeQuadrangles
+
+		public:
+			double q;
+			long i3j;
+
+			//Operators
+			int operator<(DoubleAndInt a){return q > a.q;}
+	};
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/Edge.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Edge.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Edge.cpp	(revision 3913)
@@ -0,0 +1,36 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "Edge.h"
+#include "Triangles.h"
+#include "Geometry.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION Edge::Set {{{1*/
+	void Edge::Set(const Triangles & Th ,long i,Triangles & ThNew){ 
+		*this = Th.edges[i];
+		v[0] = ThNew.vertices + Th.Number(v[0]);    
+		v[1] = ThNew.vertices + Th.Number(v[1]);
+		if (onGeometry) 
+		 onGeometry =  ThNew.Gh.edges+Th.Gh.Number(onGeometry);
+		if (adj[0]) adj[0] =   ThNew.edges +   Th.Number(adj[0]);
+		if (adj[1]) adj[1] =   ThNew.edges +   Th.Number(adj[1]);
+	}
+	/*}}}*/
+	/*FUNCTION Edge::Echo {{{1*/
+	void Edge::Echo(void){ 
+		printf("Edge:\n");
+		printf("   pointers towards two vertices: %p %p\n",v[0],v[1]);
+		printf("   ref = %i\n",ref);
+		printf("   onGeometry = %p\n",onGeometry);
+		printf("   two adjacent edges on the same curve: %p %p\n",adj[0],adj[1]);
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/Edge.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Edge.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Edge.h	(revision 3913)
@@ -0,0 +1,49 @@
+#ifndef _EDGE_H_
+#define _EDGE_H_
+
+#include "./include.h"
+#include "./MeshVertex.h"
+#include "../../include/include.h"
+#include "../../shared/Exceptions/exceptions.h"
+#include "./GeometricalEdge.h"
+
+namespace bamg {
+
+	//classes
+	class Triangles;
+	
+	class Edge {
+
+		public:
+			MeshVertex* v[2];
+			long ref;
+			GeometricalEdge* onGeometry;
+			Edge* adj[2]; // the 2 adj edges if on the same curve 
+
+			//Operators
+			MeshVertex & operator[](int i){return *v[i];};
+			MeshVertex * operator()(int i){return v[i];};
+			R2       operator()(double t) const; // return the point 
+			const MeshVertex & operator[](int i) const { return *v[i];};
+
+			//Methods
+			void ReNumbering(MeshVertex *vb,MeshVertex *ve, long *renu){
+				if (v[0] >=vb && v[0] <ve) v[0] = vb + renu[v[0]-vb];
+				if (v[1] >=vb && v[1] <ve) v[1] = vb + renu[v[1]-vb];
+			}
+			int Intersection(const  Edge & e) const { 
+				if (!(adj[0]==&e || adj[1]==&e)){
+					ISSMERROR("Intersection bug");
+				}
+				if (adj[0]!=&e && adj[1]!=&e){
+					ISSMERROR("adj[0]!=&e && adj[1]!=&e");
+				}
+				return adj[0]==&e ? 0 : 1;
+			}
+			void Set(const Triangles &,long,Triangles &);
+			void Echo(void);
+
+	};
+}
+#endif
+
Index: issm/trunk/src/c/objects/Bamg/GeometricalEdge.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/GeometricalEdge.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/GeometricalEdge.cpp	(revision 3913)
@@ -0,0 +1,141 @@
+#include <cstdio>
+#include <string.h>
+#include <cmath>
+
+#include "../../include/include.h"
+#include "../../shared/Exceptions/exceptions.h"
+
+#include "GeometricalEdge.h"
+#include "Geometry.h"
+
+using namespace std;
+
+namespace bamg {
+
+	/*Constructor/Destructor*/
+
+	/*Methods*/
+	/*FUNCTION GeometricalEdge::R1tg{{{1*/
+	double GeometricalEdge::R1tg(double theta,R2 & t) const{
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/R1tg)*/
+		// 1/R of radius of cuvature
+
+		R2 A=v[0]->r,B=v[1]->r;
+		double dca,dcb,dcta,dctb;
+		double ddca,ddcb,ddcta,ddctb;
+		double tt = theta*theta;
+
+		//check theta
+		ISSMASSERT(theta>=0 && theta<=1);
+
+		if (TgA()){ 
+			if (TgB()){
+				// Tangent A and B provided:
+				// interpolation d'hermite
+				dcb = 6*theta*(1-theta);
+				ddcb = 6*(1-2*theta);
+				dca = -dcb;
+				ddca = -ddcb;
+				dcta =  (3*theta - 4)*theta + 1;
+				ddcta=6*theta-4;
+				dctb = 3*tt - 2*theta;
+				ddctb = 6*theta-2;
+			}
+			else {
+				//Tangent A provided but tangent B not provided
+				// 1-t*t, t-t*t, t*t
+				double t = theta;
+				dcb = 2*t;
+				ddcb = 2;
+				dca = -dcb;
+				ddca = -2;
+				dcta = 1-dcb;
+				ddcta = -ddcb;
+				dctb=0;    
+				ddctb=0;    
+			}
+		}
+		else{
+			if (TgB()){
+				//Tangent B provided but tangent A not provided
+				double t = 1-theta;
+				dca = -2*t;
+				ddca = 2;
+				dcb = -dca;
+				ddcb = -2;
+				dctb = 1+dca;
+				ddctb= ddca;
+				dcta =0;
+				ddcta =0;
+			}
+			else {
+				//Neither thangent A nor tangent B provided
+				// lagrange P1
+				t=B-A;
+				return 0;
+			} 
+		}
+		R2 d  =  A*dca  + B*dcb  + tg[0]* dcta  + tg[1] * dctb;
+		R2 dd =  A*ddca + B*ddcb + tg[0]* ddcta + tg[1] * ddctb;
+		double d2=(d,d);
+		double sd2 = sqrt(d2);
+		t=d;
+		if(d2>1.0e-20){
+			t/=sd2;
+			return Abs(Det(d,dd))/(d2*sd2);
+		}
+		else return 0;
+	}
+	/*}}}1*/
+	/*FUNCTION GeometricalEdge::F{{{1*/
+	R2 GeometricalEdge::F(double theta) const{
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/F)*/
+		// parametrization of the curve edge
+
+	   R2 A=v[0]->r,B=v[1]->r;
+		double ca,cb,cta,ctb;
+		if ( theta<-1e-12){
+			ISSMERROR("theta<-1e-12");
+		}
+		if ( theta>1+1e-12){
+			ISSMERROR("theta>1+1e-12");
+		}
+		if (TgA()) 
+		 if (TgB()) // interpolation d'hermite
+			{ cb =  theta*theta*(3-2*theta);
+			 ca =  1-cb;     
+			 cta = (1-theta)*(1-theta)*theta;
+			 ctb = (theta-1)*theta*theta ;
+			}
+		 else { // 1-t*t, t-t*t, t*t
+			 double t = theta;
+			 cb = t*t;
+			 ca = 1-cb;
+			 cta= t-cb;
+			 ctb=0;    
+		 }    
+		else
+		 if (TgB()){
+			 double t = 1-theta;
+			 ca = t*t;
+			 cb = 1-ca;
+			 ctb= -t+ca;
+			 cta=0;    
+		 }
+		 else {
+			 ca =(1-theta),cb = theta,cta=ctb=0; // lagrange P1
+		 }
+		return A*ca + B*cb + tg[0]* cta + tg[1] * ctb;
+	  }
+	/*}}}1*/
+	/*FUNCTION GeometricalEdge::Set {{{1*/
+	void GeometricalEdge::Set(const GeometricalEdge & rec,const Geometry & Gh ,Geometry & GhNew){ 
+		*this = rec;
+		v[0] = GhNew.vertices + Gh.Number(v[0]);    
+		v[1] = GhNew.vertices + Gh.Number(v[1]); 
+		if (Adj[0]) Adj[0] =  GhNew.edges + Gh.Number(Adj[0]);     
+		if (Adj[1]) Adj[1] =  GhNew.edges + Gh.Number(Adj[1]);     
+	}
+	/*}}}*/
+
+}
Index: issm/trunk/src/c/objects/Bamg/GeometricalEdge.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/GeometricalEdge.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/GeometricalEdge.h	(revision 3913)
@@ -0,0 +1,47 @@
+#ifndef _GEOMETRICALEDGE_H_
+#define _GEOMETRICALEDGE_H_
+
+#include "./include.h"
+
+namespace bamg {
+
+	//classes
+	class GeometricalVertex;
+	class Geometry;
+
+	class GeometricalEdge {
+
+		public:
+			GeometricalVertex* v[2];
+			long ref;
+			long CurveNumber;
+			R2   tg[2]; // the 2 tangentes (tg[0] =0 => no continuity)
+			GeometricalEdge* Adj[2]; 
+			int DirAdj[2];
+			int flag ;
+
+			//Operators
+			GeometricalVertex       & operator[](int i){return *v[i];};
+			const GeometricalVertex & operator[](int i) const { return *v[i];};
+			GeometricalVertex       * operator()(int i){return v[i];};  
+
+			//Methods
+			R2     F(double theta) const ; // parametrization of the curve edge
+			double R1tg(double theta,R2 &t) const ; // 1/radius of curvature + tangente
+			int    Tg(int i) const{return i==0 ? TgA() : TgB();}
+			int    Cracked() const    {return flag & 1;  }
+			int    TgA()const         {return flag & 4;  }
+			int    TgB()const         {return flag & 8;  }
+			int    Mark()const        {return flag & 16; }
+			int    Required()         {return flag & 64; }
+			void   SetCracked()     { flag |= 1;  }
+			void   SetTgA()         { flag |=4;   }
+			void   SetTgB()         { flag |=8;   }
+			void   SetMark()        { flag |=16;  }
+			void   SetUnMark()      { flag &= 1007 /* 1023-16*/;}
+			void   SetRequired()    { flag |= 64; }
+			void   Set(const GeometricalEdge & rec,const Geometry & Th ,Geometry & ThNew);
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/GeometricalSubDomain.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/GeometricalSubDomain.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/GeometricalSubDomain.cpp	(revision 3913)
@@ -0,0 +1,20 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "GeometricalSubDomain.h"
+#include "Geometry.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION GeometricalSubDomain::Set {{{1*/
+	void GeometricalSubDomain::Set(const GeometricalSubDomain & rec,const Geometry & Gh ,const Geometry & GhNew){
+		*this = rec;
+		edge = Gh.Number(edge) + GhNew.edges;
+	}/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/GeometricalSubDomain.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/GeometricalSubDomain.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/GeometricalSubDomain.h	(revision 3913)
@@ -0,0 +1,23 @@
+#ifndef _GEOMETRICALSUBDOMAIN_H_
+#define _GEOMETRICALSUBDOMAIN_H_
+
+#include "./include.h"
+
+namespace bamg {
+
+	//classes
+	class GeometricalEdge;
+	class Geometry;
+
+	class GeometricalSubDomain {
+		public:
+			GeometricalEdge *edge;
+			int sens; // -1 or 1
+			long ref;
+
+			//Methods
+			void Set(const GeometricalSubDomain &,const Geometry & ,const Geometry &);
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/GeometricalVertex.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/GeometricalVertex.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/GeometricalVertex.cpp	(revision 3913)
@@ -0,0 +1,54 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "GeometricalVertex.h"
+#include "../../include/include.h"
+#include "../../shared/Exceptions/exceptions.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+	//See header file
+
+	/*Methods*/
+	/*FUNCTION GeometricalVertex::Corner {{{1*/
+	int  GeometricalVertex::Corner() const {
+		return cas & 4;
+	}
+	/*}}}*/
+	/*FUNCTION GeometricalVertex::Required {{{1*/
+	int  GeometricalVertex::Required()const {
+		// a corner is required
+		return cas & 6;
+	}
+	/*}}}*/
+	/*FUNCTION GeometricalVertex::IsThe {{{1*/
+	int  GeometricalVertex::IsThe() const {
+		return link == this;
+	}  
+	/*}}}*/
+	/*FUNCTION GeometricalVertex::SetCorner {{{1*/
+	void GeometricalVertex::SetCorner(){
+		cas |= 4;
+	}
+	/*}}}*/
+	/*FUNCTION GeometricalVertex::SetRequired {{{1*/
+	void GeometricalVertex::SetRequired(){
+		cas |= 2;
+	}
+	/*}}}*/
+	/*FUNCTION GeometricalVertex::Set {{{1*/
+	void GeometricalVertex::Set(){
+		cas=0;
+	}
+	/*}}}*/
+	/*FUNCTION GeometricalVertex::The {{{1*/
+	GeometricalVertex* GeometricalVertex::The(){
+		// return a unique vertex
+		ISSMASSERT(link);
+		return link;
+	}/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/GeometricalVertex.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/GeometricalVertex.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/GeometricalVertex.h	(revision 3913)
@@ -0,0 +1,38 @@
+#ifndef _GEOMETRICALVERTEX_H_
+#define _GEOMETRICALVERTEX_H_
+
+#include "./include.h"
+#include "MeshVertex.h"
+
+namespace bamg {
+
+	class Geometry;
+
+	class GeometricalVertex : public MeshVertex { 
+
+		public:
+			friend class Geometry;
+
+			int cas;
+			GeometricalVertex* link; //  link all the same GeometricalVertex circular (Crack) 
+
+			//Constructors
+			GeometricalVertex() :cas(0), link(this) {};
+
+			//Methods
+			int  Corner() const;
+			int  Required()const;
+			int  IsThe() const;
+			void SetCorner();
+			void SetRequired();
+			void Set();
+			GeometricalVertex* The();
+
+			//Inline methods
+			inline void Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & ){
+				*this=rec;
+			}
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/Geometry.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Geometry.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Geometry.cpp	(revision 3913)
@@ -0,0 +1,972 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "../objects.h"
+#include "../../include/include.h"
+#include "../../shared/Exceptions/exceptions.h"
+
+namespace bamg {
+
+	static const  Direction NoDirOfSearch=Direction();
+
+	/*Constructors/Destructors*/
+	/*FUNCTION  Geometry::Geometry(const Geometry & Gh){{{1*/
+	Geometry::Geometry(const Geometry & Gh) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/Geometry)*/
+
+		long i;
+		*this = Gh;
+		NbRef =0;
+		quadtree=0;
+		vertices = nbv ? new GeometricalVertex[nbv] : NULL;
+		triangles = nbt ? new  Triangle[nbt]:NULL;
+		edges = nbe ? new GeometricalEdge[nbe]:NULL;
+		curves= NbOfCurves ? new Curve[NbOfCurves]:NULL;
+		subdomains = NbSubDomains ? new GeometricalSubDomain[NbSubDomains]:NULL;
+		for (i=0;i<nbv;i++)
+		 vertices[i].Set(Gh.vertices[i],Gh,*this);
+		for (i=0;i<nbe;i++)
+		 edges[i].Set(Gh.edges[i],Gh,*this);
+		for (i=0;i<NbOfCurves;i++)
+		 curves[i].Set(Gh.curves[i],Gh,*this);
+		for (i=0;i<NbSubDomains;i++)
+		 subdomains[i].Set(Gh.subdomains[i],Gh,*this);
+		if (nbt);  {
+			ISSMERROR("nbt");
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Geometry::~Geometry(){{{1*/
+	Geometry::~Geometry() {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/~Geometry)*/
+
+		long int verbosity=0;
+
+		if (NbRef>0){
+			ISSMERROR("NbRef>0");
+		}
+		if(vertices)  delete [] vertices;vertices=0;
+		if(edges)     delete [] edges;edges=0;
+		// if(edgescomponante) delete [] edgescomponante; edgescomponante=0;
+		if(triangles) delete [] triangles;triangles=0;
+		if(quadtree)  delete  quadtree;quadtree=0;
+		if(curves)  delete  []curves;curves=0;NbOfCurves=0;
+		if(subdomains) delete [] subdomains;subdomains=0;
+		//  if(ordre)     delete [] ordre;
+		EmptyGeometry();
+	}
+	/*}}}1*/
+
+	/*IO*/
+	/*FUNCTION Geometry::ReadGeometry{{{1*/
+	void Geometry::ReadGeometry(BamgGeom* bamggeom,BamgOpts* bamgopts){
+
+		int verbose;
+		nbiv=nbv=nbvx=0;
+		nbe=nbt=nbtx=0;
+		NbOfCurves=0;
+
+		double Hmin = HUGE_VAL;// the infinie value 
+		int i,j,k,n,i1,i2;
+
+		//initialize some variables
+		int Version=1,dim=2;
+		nbv=bamggeom->VerticesSize[0];
+		nbe=bamggeom->EdgesSize[0];
+		nbvx = nbv;
+		nbiv = nbv;
+		verbose=bamgopts->verbose;
+
+		//some checks
+		if (bamggeom->Vertices==NULL){
+			ISSMERROR("the domain provided does not contain any vertex");
+		}
+		if (bamggeom->Edges==NULL){
+			ISSMERROR("the domain provided does not contain any edge");
+		}
+
+		//Vertices
+		if (bamggeom->Vertices){
+			if(verbose>5) printf("      processing Vertices\n");
+			if (bamggeom->VerticesSize[1]!=3) ISSMERROR("Vertices should have 3 columns");
+			vertices = new GeometricalVertex[nbvx];
+			for (i=0;i<nbv;i++) {
+				vertices[i].r.x=(double)bamggeom->Vertices[i*3+0];
+				vertices[i].r.y=(double)bamggeom->Vertices[i*3+1];
+				vertices[i].ReferenceNumber=(long)bamggeom->Vertices[i*3+2];
+				vertices[i].DirOfSearch=NoDirOfSearch;
+				vertices[i].color =0;
+				vertices[i].Set();
+			}
+			//find domain extrema for pmin,pmax that will define the square box
+			//used for by the quadtree
+			pmin =  vertices[0].r;
+			pmax =  vertices[0].r;
+			for (i=0;i<nbv;i++) {
+				pmin.x = Min(pmin.x,vertices[i].r.x);
+				pmin.y = Min(pmin.y,vertices[i].r.y);
+				pmax.x = Max(pmax.x,vertices[i].r.x);
+				pmax.y = Max(pmax.y,vertices[i].r.y);
+			}
+			R2 DD05 = (pmax-pmin)*0.05;
+			pmin -=  DD05;
+			pmax +=  DD05;
+			//coefIcoor is the coefficient used to have coordinates
+			//in ]0 1[^2:  x'=coefIcoor*(x-pmin.x)
+			coefIcoor= (MaxICoor)/(Max(pmax.x-pmin.x,pmax.y-pmin.y));
+			if(coefIcoor <=0){
+				ISSMERROR("coefIcoor should be positive");
+			}
+		}
+		else{
+			ISSMERROR("No MeshVertex provided");
+		}
+
+		//Edges
+		if (bamggeom->Edges){
+			R2     zero2(0,0);
+			double* len=NULL;
+
+			if(verbose>5) printf("      processing Edges\n");
+			if (bamggeom->EdgesSize[1]!=3) ISSMERROR("Edges should have 3 columns");
+			edges = new GeometricalEdge[nbe];
+
+			//initialize len (length of each edge)
+			len = new double[nbv];
+			for(i=0;i<nbv;i++) len[i]=0;
+
+			for (i=0;i<nbe;i++){
+
+				//printf("%i th edge of geometry: [%i %i]\n",i+1,(int)bamggeom->Edges[i*3+0],(int)bamggeom->Edges[i*3+1]);
+				i1=(int)bamggeom->Edges[i*3+0]-1; //-1 for C indexing
+				i2=(int)bamggeom->Edges[i*3+1]-1; //-1 for C indexing
+				edges[i].ref=(long)bamggeom->Edges[i*3+2];
+
+				edges[i].v[0]= vertices + i1;
+				edges[i].v[1]= vertices + i2;
+
+				//get length of edge
+				R2    x12=vertices[i2].r-vertices[i1].r;
+				double l12=sqrt((x12,x12));
+				Hmin=Min(Hmin,l12);
+
+				//initialize other fields
+				edges[i].tg[0]=zero2;
+				edges[i].tg[1]=zero2;
+				edges[i].DirAdj[0] = edges[i].DirAdj[1] = -1;
+				edges[i].Adj[0] = edges[i].Adj[1] = 0;
+				edges[i].flag = 0;
+
+				//Cracked?
+				if (edges[i].ref!=1){
+					edges[i].SetCracked();
+				}
+
+				//prepare metric
+				vertices[i1].color++;
+				vertices[i2].color++;
+				len[i1] += l12;
+				len[i2] += l12;
+			}
+
+			// definition  the default of the given mesh size 
+			for (i=0;i<nbv;i++) 
+			 if (vertices[i].color > 0) 
+			  vertices[i].m=Metric(len[i] /(double) vertices[i].color);
+			 else 
+			  vertices[i].m=Metric(Hmin);
+			delete [] len;
+			
+		}
+		else{
+			ISSMERROR("No edges provided");
+		}
+
+		//hVertices
+		if(bamggeom->hVertices){
+			if(verbose>5) printf("      processing hVertices\n");
+			for (i=0;i< nbv;i++){
+				if (!isnan(bamggeom->hVertices[i])){
+					vertices[i].m=Metric((double)bamggeom->hVertices[i]);
+				}
+			}
+		}
+
+		//MetricVertices
+		if(bamggeom->MetricVertices){
+			if(verbose>5) printf("      processing MetricVertices\n");
+			for (i=0;i< nbv;i++) {
+				vertices[i].m = Metric((double)bamggeom->MetricVertices[i*3+0],(double)bamggeom->MetricVertices[i*3+1],(double)bamggeom->MetricVertices[i*3+2]);
+			}
+		}
+
+		//h1h2VpVertices
+		if(bamggeom->h1h2VpVertices){
+			if(verbose>5) printf("      processing h1h2VpVertices\n");
+			double h1,h2,v1,v2;
+			for (i=0;i< nbv;i++) {
+				h1=(double)bamggeom->MetricVertices[i*4+0];
+				h2=(double)bamggeom->MetricVertices[i*4+1];
+				v1=(double)bamggeom->MetricVertices[i*4+2];
+				v2=(double)bamggeom->MetricVertices[i*4+3];
+				vertices[i].m = Metric(MatVVP2x2(1/(h1*h1),1/(h2*h2),D2(v1,v2)));
+			}
+		}
+
+		//MaximalAngleOfCorner
+		if (bamgopts->MaximalAngleOfCorner){
+			if(verbose>5) printf("      processing MaximalAngleOfCorner\n");
+			MaximalAngleOfCorner=bamgopts->MaximalAngleOfCorner*Pi/180;
+		}
+
+		//TangentAtEdges
+		if (bamggeom->TangentAtEdges){
+			if(verbose>5) printf("      processing TangentAtEdges");
+			if (bamggeom->TangentAtEdgesSize[1]!=4) ISSMERROR("TangentAtEdges should have 4 columns");
+			int n,i,j,k;
+			R2 tg;
+
+			n=bamggeom->TangentAtEdgesSize[0];
+			for (k=0;k<n;k++) {
+				i=(int)bamggeom->TangentAtEdges[k*4+0]-1; //for C indexing
+				j=(int)bamggeom->TangentAtEdges[k*4+1]-1; //for C indexing
+				tg.x=bamggeom->TangentAtEdges[k*4+2];
+				tg.y=bamggeom->TangentAtEdges[k*4+3];
+				if (j!=0 && j!=1){
+					ISSMERROR("TangentAtEdges second index should be 1 or 2 only");
+				}
+				edges[i].tg[j] = tg;
+			}
+		}
+
+		//Corners
+		if(bamggeom->Corners){
+			if(verbose>5) printf("      processing Corners");
+			if (bamggeom->CornersSize[1]!=1) ISSMERROR("Corners should have 1 column");
+			n=bamggeom->CornersSize[0];
+			for (i=0;i<n;i++) {     
+				j=(int)bamggeom->Corners[i]-1; //for C indexing
+				if (j>nbv-1 || j<0){
+					ISSMERROR("Bad corner definition: should in [0 %i]",nbv);
+				}
+				vertices[j].SetCorner();
+				vertices[j].SetRequired();  }
+		}
+
+		//RequiredVertices
+		if(bamggeom->RequiredVertices){
+			if(verbose>5) printf("      processing RequiredVertices\n");
+			if (bamggeom->RequiredVerticesSize[1]!=1) ISSMERROR("RequiredVertices should have 1 column");
+			n=bamggeom->RequiredVerticesSize[0];
+			for (i=0;i<n;i++) {     
+				j=(int)bamggeom->RequiredVertices[i]-1; //for C indexing
+				if (j>nbv-1 || j<0){
+					ISSMERROR("Bad RequiredVerticess  definition: should in [0 %i]",nbv);
+				}
+				vertices[j].SetRequired();  }
+		}
+
+		//RequiredEdges
+		if(bamggeom->RequiredEdges){
+			if(verbose>5) printf("      processing RequiredEdges\n");
+			if (bamggeom->RequiredEdgesSize[1]!=1) ISSMERROR("RequiredEdges should have 1 column");
+			n=bamggeom->RequiredEdgesSize[0];
+			for (i=0;i<n;i++) {     
+				j=(int)bamggeom->RequiredEdges[i]-1; //for C indexing
+				if (j>nbe-1 || j<0){
+					ISSMERROR("Bad RequiredEdges definition: should in [0 %i]",nbe);
+				}
+				edges[j].SetRequired();  
+			}
+		}
+
+		//SubDomain
+		if(bamggeom->SubDomains){
+			long i0,i1,i2,i3;
+			if(verbose>5) printf("      processing SubDomains\n");
+			if (bamggeom->SubDomainsSize[1]!=4) ISSMERROR("SubDomains should have 4 columns");
+			NbSubDomains=bamggeom->SubDomainsSize[0];
+			subdomains = new GeometricalSubDomain[NbSubDomains];
+			for (i=0;i<NbSubDomains;i++) {
+				i0=(int)bamggeom->SubDomains[i*4+0];
+				i1=(int)bamggeom->SubDomains[i*4+1];
+				i2=(int)bamggeom->SubDomains[i*4+2];
+				i3=(int)bamggeom->SubDomains[i*4+3];
+				if (i0!=2) ISSMERROR("Bad Subdomain definition: first number should be 2 (for Edges)");
+				if (i1>nbe || i1<=0) ISSMERROR("Bad Subdomain definition: second number should in [1 %i] (edge number)",nbe);
+				subdomains[i].edge=edges + (i1-1);
+				subdomains[i].sens = (int) i2;
+				subdomains[i].ref = i3;
+			}
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Geometry::WriteGeometry{{{1*/
+	void Geometry::WriteGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts){
+
+		int verbose;
+		int nbreq=0;
+		int nbreqv=0;
+		int nbtan=0;
+		int nbcracked=0;
+		int i,count;
+
+		/*Get options*/
+		verbose=bamgopts->verbose;
+
+		/*Initialize output*/
+		BamgGeomInit(bamggeom);
+
+		/*Vertices*/
+		if(verbose>5) printf("      writing Vertices\n");
+		bamggeom->VerticesSize[0]=nbv;
+		bamggeom->VerticesSize[1]=3;
+		if (nbv){
+			bamggeom->Vertices=(double*)xmalloc(3*nbv*sizeof(double));
+			for (i=0;i<nbv;i++){
+				bamggeom->Vertices[i*3+0]=vertices[i].r.x;
+				bamggeom->Vertices[i*3+1]=vertices[i].r.y;
+				bamggeom->Vertices[i*3+2]=vertices[i].ref();
+
+				//update counters
+				if (vertices[i].Required()) nbreqv++;
+			}
+		}
+
+		/*Edges*/
+		if(verbose>5) printf("      writing Edges\n");
+		bamggeom->EdgesSize[0]=nbe;
+		bamggeom->EdgesSize[1]=3;
+		if (nbe){
+			bamggeom->Edges=(double*)xmalloc(3*nbe*sizeof(double));
+			for (i=0;i<nbe;i++){
+				bamggeom->Edges[i*3+0]=Number(edges[i][0])+1; //back to Matlab indexing
+				bamggeom->Edges[i*3+1]=Number(edges[i][1])+1; //back to Matlab indexing
+				bamggeom->Edges[i*3+2]=(double)edges[i].ref;
+
+				//update counters
+				if (edges[i].Required()) nbreq++;
+				if (edges[i].TgA() && edges[i][0].Corner()) nbtan++;
+				if (edges[i].TgB() && edges[i][1].Corner()) nbtan++;
+			}
+		}
+
+		/*RequiredEdges*/
+		if(verbose>5) printf("      writing %i RequiredEdges\n",nbreq);
+		bamggeom->RequiredEdgesSize[0]=nbreq;
+		bamggeom->RequiredEdgesSize[1]=1;
+		if (nbreq){
+			bamggeom->RequiredEdges=(double*)xmalloc(1*nbreq*sizeof(double));
+			count=0;
+			for (i=0;i<nbe;i++){
+				if (edges[i].Required()){
+					bamggeom->RequiredEdges[count]=i+1; //back to Matlab indexing
+					count=count+1;
+				}
+			}
+		}
+
+		//No corners
+
+		/*RequiredVertices*/
+		if(verbose>5) printf("      writing %i RequiredVertices\n",nbreqv);
+		bamggeom->RequiredVerticesSize[0]=nbreqv;
+		bamggeom->RequiredVerticesSize[1]=1;
+		if (nbreqv){
+			bamggeom->RequiredVertices=(double*)xmalloc(1*nbreqv*sizeof(double));
+			count=0;
+			for (i=0;i<nbv;i++){
+				if (vertices[i].Required()){
+					bamggeom->RequiredVertices[count]=i+1; //back to Matlab indexing
+					count=count+1;
+				}
+			}
+		}
+
+		/*SubDomains*/
+		if(verbose>5) printf("      writing SubDomains\n");
+		bamggeom->SubDomainsSize[0]=NbSubDomains;
+		bamggeom->SubDomainsSize[1]=4;
+		if (NbSubDomains){
+			bamggeom->SubDomains=(double*)xmalloc(4*NbSubDomains*sizeof(double));
+			for (i=0;i<NbSubDomains;i++){
+				bamggeom->SubDomains[4*i+0]=2;
+				bamggeom->SubDomains[4*i+1]=Number(subdomains[i].edge)+1; //back to Matlab indexing
+				bamggeom->SubDomains[4*i+2]=subdomains[i].sens;
+				bamggeom->SubDomains[4*i+3]=subdomains[i].ref;
+			}
+		}
+
+		/*TangentAtEdges*/
+		if(verbose>5) printf("      writing TangentAtEdges\n");
+		bamggeom->TangentAtEdgesSize[0]=nbtan;
+		bamggeom->TangentAtEdgesSize[1]=4;
+		if (nbtan){
+			bamggeom->TangentAtEdges=(double*)xmalloc(4*nbtan*sizeof(double));
+			count=0;
+			for (i=0;i<nbe;i++){
+				if (edges[i].TgA() && edges[i][0].Corner()){
+					bamggeom->TangentAtEdges[4*i+0]=i+1; //back to Matlab indexing
+					bamggeom->TangentAtEdges[4*i+1]=1;
+					bamggeom->TangentAtEdges[4*i+2]=edges[i].tg[0].x;
+					bamggeom->TangentAtEdges[4*i+3]=edges[i].tg[0].y;
+				}
+				if (edges[i].TgB() && edges[i][1].Corner()){
+					bamggeom->TangentAtEdges[4*i+0]=i+1; //back to Matlab indexing
+					bamggeom->TangentAtEdges[4*i+1]=2;
+					bamggeom->TangentAtEdges[4*i+2]=edges[i].tg[1].x;
+					bamggeom->TangentAtEdges[4*i+3]=edges[i].tg[2].y;
+				}
+				count=count+1;
+			}
+		}
+	}
+	/*}}}1*/
+
+	/*Methods*/
+	/*FUNCTION  Geometry::AfterRead(){{{1*/
+	void Geometry::AfterRead(){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/AfterRead)*/
+
+		long int verbosity=0;
+
+		long i,j,k;
+		int jj;
+		long* head_v=new long[nbv];
+		long* next_p=new long[2*nbe];
+		float* eangle=new float[nbe];
+		double eps=1e-20;
+		QuadTree quadtree; // build quadtree to find duplicates
+		MeshVertex* v0=vertices; 
+		GeometricalVertex* v0g=(GeometricalVertex*) (void*)v0;   
+
+		k=0;
+		//link all vertices to themselves by default
+		for (i=0;i<nbv;i++) vertices[i].link = vertices+i;
+
+		//build quadtree for this geometry
+		for (i=0;i<nbv;i++){
+
+			/*build integer coordinates (non unique)
+			these coordinates are used by the quadtree to group
+			the vertices by groups of 5:
+			All the coordinates are transformed to ]0,1[^2
+			then, the integer coordinates are computed using 
+			the transformation ]0,1[^2 -> [0 2^(30-1)[^2 for a quadtree of depth 30*/
+			vertices[i].i=toI2(vertices[i].r); 
+
+			//find nearest vertex already present in the quadtree (NULL if empty)
+			MeshVertex* v=quadtree.NearestVertex(vertices[i].i.x,vertices[i].i.y); 
+
+			//if there is a vertex found that is to close to vertices[i] -> error
+			if( v && Norme1(v->r - vertices[i]) < eps ){
+				// mama's old trick to get j 
+				GeometricalVertex* vg=(GeometricalVertex*) (void*)v;
+				j=vg-v0g;
+				//check that the clostest vertex is not itself...
+				if ( v !=  &(MeshVertex &) vertices[j]){
+					ISSMERROR(" v !=  &(MeshVertex &) vertices[j]");
+				}
+				vertices[i].link = vertices + j;
+				k++;	      
+			}
+
+			//The nearest vertex was non existent or far enough from vertices[i]
+			//Add vertices[i] to the quadtree
+			else  quadtree.Add(vertices[i]);
+		}
+
+		//if k>0, there are some duplicate vertices -> error
+		if (k) {
+			printf("number of distinct vertices= %i, over %i\n",nbv - k,nbv);
+			printf("List of duplicate vertices:\n");
+			for (i=0;i<nbv;i++){
+				if (!vertices[i].IsThe()) printf("  %i and %i\n",i,Number(vertices[i].The()));
+			}
+			ISSMERROR("See above");
+		}
+
+		/* Here we use a powerful chaining algorithm
+		 *
+		 * 1. What is a chaining algorithm?
+		 *
+		 * If F is a function that goes from i in [0 n] to j in [0 m]
+		 * and we want to compute the reciprocal function F-1 of F
+		 * (what are the antecedents of a given j in Im(F) )
+		 * We use 2 lists:
+		 *    head_F[j] that holds the head of lists
+		 *    next_F[i] that holds the list of elements that have the same image
+		 *
+		 * Example:
+		 *    i1, i2, ..., ip in [0,n] are all antecedents of a given j in [0 m]
+		 *    head_F[j] = ip
+		 *    next_F[ip]= ip-1
+		 *    ....
+		 *    next_F[i2]= i1
+		 *    next_F[i1]= -1  //end of the list
+		 *
+		 * Algorithm:
+		 *    for(j=0;j<m;j++)  head_F[j] = -1 //initialization
+		 *    for(i=0;i<n;i++){
+		 *       j=F[i];
+		 *       next_F[i]= head_F[j];
+		 *       head_F[j]=i;
+		 *    }
+		 * 
+		 *    Then, we can go through all the elements that have for image j:
+		 *    for(i=head_F[j]; i!=-1; i=next_F[i])
+		 *    initialization of i by i=head_F[j]
+		 *    stop the loop when i=-1 (end of the chain)
+		 *    iterate using i=next_F[i] (next element that have for image j)
+		 * 
+		 * 2. How to use this algorithm here?
+		 * 
+		 * Here F is a function that associates two vertices v0 and v1 for a given edge E
+		 * We want to build the reciprocal function: what are the edges that contains
+		 * a vertex v?
+		 * To do so, we use the same chaining algorithm but there is a difficulty
+		 * coming from the fact that F we have a couple of vertices and not one 
+		 * vertices.
+		 * To overcome this difficulty, we use a global indices exactly like in 
+		 * C/C++ so that
+		 * a member of a 2-column-table can be described by one index p=i*2+j
+		 * i=(int)p/2 line number of p
+		 * j=p%2       column number of p
+		 *
+		 * Algorithm:
+		 *    for(i=0;i<nbv;i++)  head_v[i] = -1 //initialization
+		 *    for(i=0;i<nbe;i++){
+		 *       for(j=0;j<2;j++){
+		 *          p=2*i+j;
+		 *          v=edges(i,j);
+		 *          next_p[p]= head_v[v];
+		 *          head_v[v]=p;
+		 *       }
+		 *    }
+		 */
+
+		//initialize head_v as -1
+		for (i=0;i<nbv;i++) head_v[i]=-1;
+		k=0;
+		for (i=0;i<nbe;i++) {
+			//compute vector of edge i that goes from vertex 0 to vertex 1
+			R2 v10=edges[i].v[1]->r - edges[i].v[0]->r;
+			double lv10=Norme2(v10);
+			//check that its length is not 0
+			if(lv10==0) {
+				ISSMERROR("Length of edge %i is 0",i);
+			}
+			//compute angle in [-Pi Pi]
+			eangle[i] = atan2(v10.y,v10.x);
+			//build chains head_v and next_p
+			for (j=0;j<2;j++){
+				long v=Number(edges[i].v[j]);
+				next_p[k]=head_v[v];
+				head_v[v]=k++; //post increment: head_v[v]=k; and then k=k+1;
+			}
+		}
+
+		//sort head_v by order of increasing edges angle
+		for (i=0;i<nbv;i++) {
+			int exch=1, ord=0;      
+
+			//exchange vertices position in head_v and next_p till tey are sorted
+			while (exch){
+				long *p=head_v+i;               // pointer toward head_v[vertex i]
+				long *po=p;                     // copy of pointer p
+				long  n=*p;                     // next value of edge holding i
+				register float angleold=-1000 ; // angle = - infinity
+				ord=0; exch=0;
+
+				// loop over the edges that contain the vertex i
+				while (n >=0){
+					ord++;
+					register long  i1=n/2;       // i1 = floor (n/2)
+					register long  j1=n%2;       // j1 = 1 if n is odd
+					register long* pn=next_p+n;  // pointer to next_p[n]
+
+					//  n = next_p[n] = position in edge of next vertex i
+					n=*pn;                       
+
+					//compute angle between horizontal axis and v0->v1
+					float angle = j1 ? OppositeAngle(eangle[i1]):  eangle[i1]; 
+
+					//exchange if the current edge angle is smaller than the previous one
+					if (angleold > angle){
+						exch=1;
+						*pn=*po;  // next_p[n] = n + 1
+						*po=*p;   // 
+						*p=n;     // next_p[n+1] = n
+						po=pn;    // po now point toward pn (invert next and current)
+					}
+
+					//else, continue going to the next edge position
+					else{                        //  to have : po -> p -> pn
+						angleold=angle; // update maximum angle
+						po=p;           // po now point toward p  (current position)
+						p=pn;           // p  now point toward pn (next position)
+					}
+				}
+			}
+
+			// angular test on current vertex to guess whether it is a corner (ord = number of edges horlding i)
+			if(ord == 2) { 
+				long  n1 = head_v[i];
+				long  n2 = next_p[n1];
+				long  i1 = n1/2, i2 = n2/2; // edge number
+				long  j1 = n1%2, j2 = n2%2; // vertex in the edge 
+				float angle1=  j1 ? OppositeAngle(eangle[i1]) : eangle[i1];
+				float angle2= !j2 ? OppositeAngle(eangle[i2]) : eangle[i2];
+				float da12 = Abs(angle2-angle1);
+				if (( da12 >= MaximalAngleOfCorner ) && (da12 <= 2*Pi -MaximalAngleOfCorner)) {
+					vertices[i].SetCorner() ; 
+				}
+				// if the ref a changing then is     SetRequired();
+				if (edges[i1].flag != edges[i2].flag || edges[i1].Required()){
+					vertices[i].SetRequired();
+				}
+				if (edges[i1].ref != edges[i2].ref) {
+					vertices[i].SetRequired();
+				}
+			}
+			if(ord != 2) {
+				vertices[i].SetCorner();
+			}
+
+			// close the list around the vertex 
+			long no=-1, ne = head_v[i];
+			while (ne >=0) ne = next_p[no=ne];        
+			if(no>=0) next_p[no] = head_v[i];
+			// now the list around the vertex is circular
+		}
+
+		k =0;
+		for (i=0;i<nbe;i++){
+			for (j=0;j<2;j++){
+				long n1 = next_p[k++]; 
+				long i1 = n1/2 ,j1=n1%2;
+				if( edges[i1].v[j1] != edges[i].v[j]) {
+					ISSMERROR("Bug Adj edge");
+				}
+				edges[i1].Adj[j1] = edges + i;
+				edges[i1].DirAdj[j1] = j;
+			}
+		}
+
+		// generation of  all the tangents
+		for (i=0;i<nbe;i++) {
+			//Get AB = vertex1->vertex2
+			R2    AB =edges[i].v[1]->r -edges[i].v[0]->r;        
+			//Get length of AB
+			double lAB=Norme2(AB);
+			//initialize tangent
+			double ltg2[2]={0.0};
+
+			//loop over the 2 vertices of the edge
+			for (jj=0;jj<2;jj++) {
+				R2     tg =edges[i].tg[jj];
+				double ltg=Norme2(tg);
+
+				//by default, tangent=[0 0]
+				if(ltg == 0) {
+					//if the current vertex of the edge is not a corner
+					if(!edges[i].v[jj]->Corner()){
+						tg = edges[i].v[1-jj]->r - edges[i].Adj[jj]->v[1-edges[i].DirAdj[jj]]->r; //previous point and next point on curve
+						ltg= Norme2(tg);
+						tg = tg *(lAB/ltg);
+						ltg= lAB;
+					}
+					//else:  a Corner with no tangent => nothing to do    
+				}
+				else{
+					//tangent has already been computed
+					tg = tg*(lAB/ltg),ltg=lAB;
+				}
+
+				ltg2[jj] = ltg;
+
+				if ((tg,AB)<0){
+					tg = -tg;
+				}
+
+				edges[i].tg[jj] = tg;
+			}
+			if (ltg2[0]!=0) edges[i].SetTgA();
+			if (ltg2[1]!=0) edges[i].SetTgB();
+		} 
+
+		for (int step=0;step<2;step++){
+			for (i=0;i<nbe;i++) edges[i].SetUnMark();
+			NbOfCurves = 0;
+			long  nbgem=0;
+			for (int level=0;level < 2 && nbgem != nbe;level++)
+			 for (i=0;i<nbe;i++) {
+				 GeometricalEdge & ei = edges[i];   
+				 for(jj=0;jj<2;jj++){
+					 if (!ei.Mark() && (level || ei[jj].Required())) { 
+						 // warning ei.Mark() can be change in loop for(jj=0;jj<2;jj++) 
+						 int k0=jj,k1;
+						 GeometricalEdge *e = & ei;
+						 GeometricalVertex *a=(*e)(k0); // begin 
+						 if(curves){
+							 curves[NbOfCurves].be=e;
+							 curves[NbOfCurves].kb=k0;
+						 }
+						 int nee=0;
+						 for(;;) { 
+							 nee++;
+							 k1 = 1-k0; // next vertex of the edge 
+							 e->SetMark();
+							 nbgem++;
+							 e->CurveNumber=NbOfCurves;
+							 if(curves) {
+								 curves[NbOfCurves].ee=e;
+								 curves[NbOfCurves].ke=k1;
+							 }
+							 GeometricalVertex *b=(*e)(k1);
+							 if (a == b ||  b->Required() ) break;
+							 k0 = e->DirAdj[k1];//  vertex in next edge
+							 e = e->Adj[k1]; // next edge
+						 }
+						 NbOfCurves++;
+						 if(level) a->SetRequired();
+					 }
+				 }
+			 } 
+			ISSMASSERT(nbgem && nbe);
+			if(step==0){
+				curves = new Curve[NbOfCurves];
+			}
+		} 
+		for(int i=0;i<NbOfCurves ;i++){
+			GeometricalEdge * be=curves[i].be, *eqbe=be;
+			//GeometricalEdge * ee=curves[i].ee, *eqee=be;
+			curves[i].master=true;
+		}
+
+		/*clean up*/
+		delete []next_p;
+		delete []head_v;
+		delete []eangle;
+
+	}
+	/*}}}1*/
+	/*FUNCTION  Geometry::Containing{{{1*/
+	GeometricalEdge* Geometry::Containing(const R2 P,  GeometricalEdge * start) const {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/Contening)*/
+
+		GeometricalEdge* on =start,* pon=0;
+		// walk with the cos on geometry
+		int k=0;
+		while(pon != on){  
+			k++;
+			pon = on;
+			if (k>=100){
+				ISSMERROR("k>=100");
+			}
+			R2 A= (*on)[0];
+			R2 B= (*on)[1];
+			R2 AB = B-A;
+			R2 AP = P-A;
+			R2 BP = P-B;
+			if ( (AB,AP) < 0) 
+			 on = on->Adj[0];
+			else if ( (AB,BP)  > 0) 
+			 on = on->Adj[1];
+			else
+			 return on;
+		}
+		return on;
+	}
+	/*}}}1*/
+	/*FUNCTION  Geometry::Echo {{{1*/
+
+	void Geometry::Echo(void){
+
+		printf("Geometry:\n");
+		printf("   nbvx (maximum number of vertices) : %i\n",nbvx);
+		printf("   nbtx (maximum number of triangles): %i\n",nbtx);
+		printf("   nbv  (number of vertices) : %i\n",nbv);
+		printf("   nbt  (number of triangles): %i\n",nbt);
+		printf("   nbe  (number of edges)    : %i\n",nbe);
+		printf("   nbv  (number of initial vertices) : %i\n",nbiv);
+		printf("   NbSubDomains: %i\n",NbSubDomains);
+		printf("   NbOfCurves: %i\n",NbOfCurves);
+		printf("   vertices: %p\n",vertices);
+		printf("   triangles: %p\n",triangles);
+		printf("   edges: %p\n",edges);
+		printf("   quadtree: %p\n",quadtree);
+		printf("   subdomains: %p\n",subdomains);
+		printf("   curves: %p\n",curves);
+		printf("   pmin (x,y): (%g %g)\n",pmin.x,pmin.y);
+		printf("   pmax (x,y): (%g %g)\n",pmax.x,pmax.y);
+		printf("   coefIcoor: %g\n",coefIcoor);
+		printf("   MaximalAngleOfCorner: %g\n",MaximalAngleOfCorner);
+
+		return;
+	}
+	/*}}}*/
+	/*FUNCTION  Geometry::EmptyGeometry(){{{1*/
+	void Geometry::EmptyGeometry() {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/EmptyGeometry)*/
+
+		NbRef=0;
+		quadtree=0;
+		curves=0;
+		// edgescomponante=0;
+		triangles=0;
+		edges=0;
+		vertices=0;
+		NbSubDomains=0;
+		//  nbtf=0;
+		//  BeginOfCurve=0;  
+		nbiv=nbv=nbvx=0;
+		nbe=nbt=nbtx=0;
+		NbOfCurves=0;
+		//  BeginOfCurve=0;
+		subdomains=0;
+		MaximalAngleOfCorner = 10*Pi/180;
+	}
+	/*}}}1*/
+	/*FUNCTION  Geometry::ProjectOnCurve {{{1*/
+	GeometricalEdge* Geometry::ProjectOnCurve(const Edge &e,double s,MeshVertex &V,VertexOnGeom &GV) const {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/ProjectOnCurve)*/
+		/*Add a vertex on an existing geometrical edge according to the metrics of the two vertices constituting the edge*/
+
+		double save_s=s;
+		int NbTry=0;
+
+retry:
+
+		s=save_s;
+		GeometricalEdge* on=e.onGeometry;
+		if (!on){
+			ISSMERROR("ProjectOnCurve error message: edge provided should be on geometry");
+		}
+		if (!e[0].onGeometry ||  !e[1].onGeometry){
+			ISSMERROR("ProjectOnCurve error message: at least one of the vertex of the edge provided is not on geometry");
+		}
+
+		//Get the two vertices of the edge
+		const MeshVertex &v0=e[0];
+		const MeshVertex &v1=e[1];
+
+		//Get position of V0, V1 and vector v0->v1
+		R2 V0=v0,V1=v1,V01=V1-V0;
+
+		//Get geometrical vertices corresponding to v0 and v1
+		VertexOnGeom  vg0=*v0.onGeometry,  vg1=*v1.onGeometry;
+
+		//build two pointers towrad current geometrical edge
+		GeometricalEdge *eg0=on, *eg1=on;
+
+		//Get edge direction and swap v0 and v1 if necessary
+		R2 Ag=(R2)(*on)[0],Bg=(R2)(*on)[1],AB=Bg-Ag; 
+		int OppositeSens = (V01,AB)<0;
+		int sens0=0,sens1=1;
+		if (OppositeSens) s=1-s,Exchange(vg0,vg1),Exchange(V0,V1);
+
+		//Compute metric of new vertex as a linear interpolation of the two others
+		V.m=Metric(1.0-s,v0,s,v1);
+
+		const int mxe=100;
+		GeometricalEdge* ge[mxe+1];
+		int     sensge[mxe+1];
+		double  lge[mxe+1];
+		int bge=mxe/2,tge=bge;
+		ge[bge] = e.onGeometry;
+		sensge[bge]=1;
+
+		while (eg0!=(GeometricalEdge*)vg0 && (*eg0)(sens0)!=(GeometricalVertex*)vg0){ 
+			if (bge<=0) {
+				if(NbTry) {
+					printf("Fatal Error: on the class triangles before call Geometry::ProjectOnCurve\n");
+					printf("That bug might come from:\n");
+					printf(" 1)  a mesh edge  containing more than %i geometrical edges\n",mxe/2);
+					printf(" 2)  code bug : be sure that we call   Triangles::SetVertexFieldOn() before\n");
+					printf("To solve the problem do a coarsening of the geometrical mesh or change the constant value of mxe (dangerous)\n");
+					ISSMERROR("see above");
+				  }
+				NbTry++;
+				goto retry;
+			}
+			GeometricalEdge* tmpge = eg0;
+			ge[--bge] =eg0 = eg0->Adj[sens0];
+			ISSMASSERT(bge>=0 && bge<=mxe);
+			sens0 = 1-( sensge[bge] = tmpge->DirAdj[sens0]);
+		}
+		while (eg1 != (GeometricalEdge*) vg1  &&  (*eg1)(sens1) != (GeometricalVertex*) vg1) { 
+			if(tge>=mxe ) { 
+				printf("WARNING: on the class triangles before call Geometry::ProjectOnCurve is having issues (isn't it Eric?)\n");
+				NbTry++;
+				if (NbTry<2) goto retry;
+				printf("Fatal Error: on the class triangles before call Geometry::ProjectOnCurve\n");
+				printf("That bug might come from:\n");
+				printf(" 1)  a mesh edge  contening more than %i geometrical edges\n",mxe/2);
+				printf(" 2)  code bug : be sure that we call   Triangles::SetVertexFieldOn() before\n");
+				printf("To solve the problem do a coarsening of the geometrical mesh or change the constant value of mxe (dangerous)\n");
+				ISSMERROR("see above");
+			}
+			GeometricalEdge* tmpge = eg1;
+			ge[++tge] =eg1 = eg1->Adj[sens1];
+			sensge[tge]= sens1 = 1-tmpge->DirAdj[sens1];
+			ISSMASSERT(tge>=0 && tge<=mxe);
+		}
+
+
+		if ((*eg0)(sens0)==(GeometricalVertex*)vg0)
+		 vg0=VertexOnGeom(*(MeshVertex*) vg0,*eg0,sens0); //vg0 = absisce
+
+		if ((*eg1)(sens1)==(GeometricalVertex*)vg1)
+		 vg1=VertexOnGeom(*(MeshVertex*) vg1,*eg1,sens1);
+
+		double sg;
+		if (eg0 == eg1) { 
+			register double s0=vg0,s1=vg1;
+			sg =  s0*(1.0-s) +  s*s1;
+			on=eg0;
+		}
+		else {
+			R2 AA=V0,BB;
+			double s0,s1;
+			int i=bge;
+			double ll=0;
+			for(i=bge;i<tge;i++){
+				ISSMASSERT(i>=0 && i<=mxe);
+				BB =  (*ge[i])[sensge[i]];
+				lge[i]=ll += Norme2(AA-BB);
+				AA=BB ;}
+				lge[tge]=ll+=Norme2(AA-V1); 
+				// search the geometrical edge
+				if (s>1.0){
+					ISSMERROR("s>1.0");
+				}
+				double ls= s*ll;
+				on =0;
+				s0 = vg0;
+				s1= sensge[bge];
+				double l0=0,l1;
+				i=bge;
+				while (  (l1=lge[i]) < ls ) {
+					if (i<0 || i>mxe){
+						ISSMERROR("i<0 || i>mxe");
+					}
+					i++,s0=1-(s1=sensge[i]),l0=l1;
+				}
+				on=ge[i];
+				if (i==tge) 
+				 s1=vg1;
+
+				s  =(ls-l0)/(l1-l0);
+				sg =s0*(1.0-s)+s*s1;    
+		} 
+		ISSMASSERT(on);
+		V.r= on->F(sg);
+		GV=VertexOnGeom(V,*on,sg);
+		return on;
+	}
+	/*}}}1*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/Geometry.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Geometry.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Geometry.h	(revision 3913)
@@ -0,0 +1,72 @@
+#ifndef _GEOMETRY_H_
+#define _GEOMETRY_H_
+
+#include "./include.h"
+#include "./BamgGeom.h"
+#include "./BamgOpts.h"
+#include "./GeometricalVertex.h"
+#include "./GeometricalEdge.h"
+#include "./Curve.h"
+
+namespace bamg {
+
+	class Triangle;
+	class QuadTree;
+	class GeometricalSubDomain;
+	class Edge;
+
+	class Geometry { 
+
+		public:
+			long NbRef;     // counter of ref on the this class if 0 we can delete
+			long nbvx,nbtx; // maximum number of vertices
+			long nbv,nbt,nbiv,nbe; // number of vertices
+			long NbSubDomains; // 
+			long NbOfCurves;
+			GeometricalVertex* vertices;
+			Triangle* triangles; 
+			GeometricalEdge* edges;
+			QuadTree* quadtree;
+			GeometricalSubDomain* subdomains;
+			Curve* curves;
+			R2 pmin,pmax; // extrema
+			double coefIcoor;  // coef to integer Icoor1;
+			double MaximalAngleOfCorner;
+
+			//Constructor/Destructors
+			~Geometry(); 
+			Geometry(const Geometry & Gh); //Copy  Operator 
+			Geometry(int nbg,const Geometry** ag); // intersection operator 
+
+			//Operators
+			const GeometricalVertex & operator[]  (long i) const { return vertices[i];};
+			GeometricalVertex & operator[](long i) { return vertices[i];};
+			const  GeometricalEdge & operator()  (long i) const { return edges[i];};
+			GeometricalEdge & operator()(long i) { return edges[i];}; 
+
+			//Methods
+			int empty(){return (nbv ==0) && (nbt==0) && (nbe==0) && (NbSubDomains==0); }
+			void Echo();
+			I2 toI2(const R2 & P) const {
+				return  I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
+							,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
+			double MinimalHmin() {return 2.0/coefIcoor;}
+			double MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
+			void ReadGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
+			void EmptyGeometry();
+			Geometry() {EmptyGeometry();}// empty Geometry
+			void AfterRead();
+			Geometry(BamgGeom* bamggeom, BamgOpts* bamgopts) {EmptyGeometry();ReadGeometry(bamggeom,bamgopts);AfterRead();}
+			long Number(const GeometricalVertex & t) const  { return &t - vertices;}
+			long Number(const GeometricalVertex * t) const  { return t - vertices;}
+			long Number(const GeometricalEdge & t) const  { return &t - edges;}
+			long Number(const GeometricalEdge * t) const  { return t - edges;}
+			long Number(const Curve * c) const  { return c - curves;}
+			void UnMarkEdges() {for (int i=0;i<nbe;i++) edges[i].SetUnMark();}
+			GeometricalEdge *  ProjectOnCurve(const Edge & ,double,MeshVertex &,VertexOnGeom &) const ;
+			GeometricalEdge *  Containing(const R2 P,  GeometricalEdge * start) const;
+			void WriteGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
+	};
+	
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/ListofIntersectionTriangles.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/ListofIntersectionTriangles.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/ListofIntersectionTriangles.cpp	(revision 3913)
@@ -0,0 +1,366 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "../objects.h"
+
+namespace bamg {
+
+	/*Methods*/
+	/*FUNCTION ListofIntersectionTriangles::SplitEdge{{{1*/
+	void ListofIntersectionTriangles::SplitEdge(const Triangles & Bh, const R2 &A,const R2  &B,int nbegin) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ListofIntersectionTriangles)*/
+
+		Triangle *tbegin, *t;
+
+		long int verbosity=2;
+		Icoor2 deta[3], deti,detj;
+		double ba[3];
+		int nbt =0,ifirst=-1,ilast;
+		int i0,i1,i2;
+		int ocut,i,j,k=-1;
+		//  int OnAVertices =0;
+		Icoor2 dt[3];
+		I2 a = Bh.toI2(A) ,b= Bh.toI2(B);// compute  the Icoor a,b
+		I2 vi,vj;  
+		int iedge =-1;// not a edge
+
+		if(nbegin)  {// optimisation 
+			// we suppose  knowing the starting  triangle
+			t=tbegin=lIntTria[ilast=(Size-1)].t;
+			if (tbegin->det>=0) 
+			 ifirst = ilast;}  
+		else {// not optimisation 
+			init();
+			t=tbegin = Bh.FindTriangleContaining(a,deta);
+			if( t->det>=0)
+			 ilast=NewItem(t,double(deta[0])/t->det,double(deta[1])/t->det,double(deta[2])/t->det);
+			else 
+			  {// find the nearest boundary edge  of the vertex A
+				// find a edge or such normal projection a the edge IJ is on the edge
+				//   <=> IJ.IA >=0 && IJ.AJ >=0
+				ilast=ifirst;
+				double ba,bb;
+				TriangleAdjacent edge=CloseBoundaryEdge(a,t,ba,bb);
+				MeshVertex & v0 = *edge.EdgeVertex(0), & v1 = *edge.EdgeVertex(1);
+				NewItem(A,Metric(ba,v0,bb,v1));
+				t=edge;
+				// test if the point b is in the same side
+				if (det(v0.i,v1.i,b)>=0) {
+					TriangleAdjacent edge=CloseBoundaryEdge(a,t,ba,bb);
+					MeshVertex & v0 = *edge.EdgeVertex(0), & v1 = *edge.EdgeVertex(1);
+					NewItem(A,Metric(ba,v0,bb,v1));
+					return;
+				}
+			  } // find the nearest boundary edge  of the vertex A
+		} // end not optimisation 
+		if (t->det<0) {  // outside departure
+			while (t->det <0) { // intersection boundary edge and a,b,
+				k=(*t)(0) ?  ((  (*t)(1) ? ( (*t)(2) ? -1 : 2) : 1  )) : 0;
+				if (k<0){
+					ISSMERROR("k<0");
+				}
+				ocut = OppositeEdge[k];
+				i=VerticesOfTriangularEdge[ocut][0];
+				j=VerticesOfTriangularEdge[ocut][1];
+				vi=(*t)[i];
+				vj=(*t)[j];
+				deti = bamg::det(a,b,vi);
+				detj = bamg::det(a,b,vj);
+				if (deti>0) // go to  i direction on gamma
+				 ocut = PreviousEdge[ocut];      
+				else if (detj<=0) // go to j direction on gamma
+				 ocut = NextEdge[ocut];         
+				TriangleAdjacent tadj =t->Adj(ocut);
+				t = tadj;
+				iedge= tadj; 
+				if (t == tbegin) { // 
+					double ba,bb;
+					long int verbosity=2;
+					TriangleAdjacent edge=CloseBoundaryEdge(a,t,ba,bb);
+					MeshVertex & v0 = *edge.EdgeVertex(0), & v1 = *edge.EdgeVertex(1);
+					NewItem(A,Metric(ba,v0,bb,v1));
+					return;
+				}
+			} //  end while (t->det <0)
+			// theoriticaly we have: deti =<0 and detj>0
+
+			// computation of barycentric coor
+			// test if the point b is on size on t
+			// we revert vi,vj because vi,vj is def in Adj triangle
+			if ( det(vi,vj,b)>=0) {
+				t=tbegin;
+				double ba,bb;
+				TriangleAdjacent edge=CloseBoundaryEdge(b,t,ba,bb);
+				NewItem(B,Metric(ba,*edge.EdgeVertex(0),bb,*edge.EdgeVertex(1)));
+				return;
+			}
+			else
+			  {
+				k = OppositeVertex[iedge];
+				i=VerticesOfTriangularEdge[iedge][0];
+				j=VerticesOfTriangularEdge[iedge][1];
+				double dij = detj-deti;
+				if (i+j+k != 0 + 1 +2){
+					ISSMERROR("i+j+k != 0 + 1 +2");
+				}
+				ba[j] =  detj/dij;
+				ba[i] = -deti/dij;
+				ba[k] = 0;
+				ilast=NewItem(t,ba[0],ba[1],ba[2]); }
+		}  //  outside departure
+
+
+
+		// recherche the intersection of [a,b] with Bh Mesh.
+		// we know  a triangle ta contening the vertex a
+		// we have 2 case for intersection [a,b] with a edge [A,B] of Bh
+		// 1) the intersection point is in ]A,B[
+		// 2)                        is A or B
+		// first version --- 
+		for (;;) {
+			//    t->Draw();
+			if (iedge < 0) {
+				i0 =0;i1=1;i2=2;
+				dt[0] =bamg::det(a,b,(*t)[0]);
+				dt[1] =bamg::det(a,b,(*t)[1]);
+				dt[2] =bamg::det(a,b,(*t)[2]);}
+			else {
+				i2 = iedge;
+				i0 = NextEdge[i2];
+				i1 = NextEdge[i0]; 
+				dt[VerticesOfTriangularEdge[iedge][0]] = detj;// we revert i,j because
+				dt[VerticesOfTriangularEdge[iedge][1]] = deti;// we take the Triangle by the other side
+				dt[iedge] = det(a,b,(*t)[OppositeVertex[iedge]]);}
+
+				// so we have just to see the transition from - to + of the det0..2 on edge of t
+				// because we are going from a to b
+				if       ((dt[i=VerticesOfTriangularEdge[i0][0]] <  0) &&
+							( dt[j=VerticesOfTriangularEdge[i0][1]] > 0))
+				 ocut =i0;
+				else  if ((dt[i=VerticesOfTriangularEdge[i1][0]] <  0) &&
+							(dt[j=VerticesOfTriangularEdge[i1][1]] >  0))
+				 ocut =i1;
+				else  if ((dt[i=VerticesOfTriangularEdge[i2][0]] <  0) && 
+							(dt[j=VerticesOfTriangularEdge[i2][1]] >  0))
+				 ocut =i2;
+				else if   ((dt[i=VerticesOfTriangularEdge[i0][0]] == 0) &&
+							( dt[j=VerticesOfTriangularEdge[i0][1]] >  0))
+				 ocut =i0;
+				else  if ((dt[i=VerticesOfTriangularEdge[i1][0]] == 0) &&
+							(dt[j=VerticesOfTriangularEdge[i1][1]] >  0))
+				 ocut =i1;
+				else  if ((dt[i=VerticesOfTriangularEdge[i2][0]] == 0) && 
+							(dt[j=VerticesOfTriangularEdge[i2][1]] >  0))
+				 ocut =i2;
+				else if   ((dt[i=VerticesOfTriangularEdge[i0][0]] <  0) &&
+							( dt[j=VerticesOfTriangularEdge[i0][1]] == 0))
+				 ocut =i0;
+				else  if ((dt[i=VerticesOfTriangularEdge[i1][0]] <  0) &&
+							(dt[j=VerticesOfTriangularEdge[i1][1]] == 0))
+				 ocut =i1;
+				else  if ((dt[i=VerticesOfTriangularEdge[i2][0]] <  0) && 
+							(dt[j=VerticesOfTriangularEdge[i2][1]] == 0))
+				 ocut =i2;
+				else { //  On a edge (2 zero)
+					k =0;
+					if (dt[0]) ocut=0,k++; 
+					if (dt[1]) ocut=1,k++; 
+					if (dt[2]) ocut=2,k++;
+					if(k == 1) {
+						if (dt[ocut] >0) // triangle upper AB
+						 ocut = NextEdge[ocut];
+						i= VerticesOfTriangularEdge[ocut][0];
+						j= VerticesOfTriangularEdge[ocut][1];
+					}
+					else {
+						ISSMERROR("Bug Split Edge");
+					}
+				}
+
+						k = OppositeVertex[ocut];
+
+						Icoor2 detbij = bamg::det((*t)[i],(*t)[j],b);
+
+
+						if (detbij >= 0) { //we find the triangle contening b
+							dt[0]=bamg::det((*t)[1],(*t)[2],b);
+							dt[1]=bamg::det((*t)[2],(*t)[0],b);
+							dt[2]=bamg::det((*t)[0],(*t)[1],b);
+							double dd = t->det;
+							NewItem(t,dt[0]/dd,dt[1]/dd,dt[2]/dd);      
+							return ;}
+						else { // next triangle by  adjacent by edge ocut 
+							deti = dt[i];
+							detj = dt[j];
+							double dij = detj-deti;
+							ba[i] =  detj/dij;
+							ba[j] = -deti/dij;
+							ba[3-i-j ] = 0;
+							ilast=NewItem(t, ba[0],ba[1],ba[2]);      
+
+							TriangleAdjacent ta =t->Adj(ocut);
+							t = ta;
+							iedge= ta; 
+							if (t->det <= 0)  {
+								double ba,bb;
+								TriangleAdjacent edge=CloseBoundaryEdge(b,t,ba,bb);
+								NewItem(B,Metric(ba,*edge.EdgeVertex(0),bb,*edge.EdgeVertex(1)));
+								return;
+							}
+						}// we  go outside of omega 
+		} // for(;;)
+	}
+	/*}}}1*/
+	/*FUNCTION ListofIntersectionTriangles::NewItem(Triangle * tt,double d0,double d1,double d2) {{{1*/
+	int  ListofIntersectionTriangles::NewItem(Triangle * tt,double d0,double d1,double d2) { 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/NewItem)*/
+
+		register int n;
+		R2 x(0,0);
+		if ( d0) x =      (*tt)[0].r * d0;
+		if ( d1) x = x +  (*tt)[1].r * d1;
+		if ( d2) x = x +  (*tt)[2].r * d2;
+		// newer add same point 
+		if(!Size ||  Norme2_2(lIntTria[Size-1].x-x)) {
+			if (Size==MaxSize) ReShape();
+			lIntTria[Size].t=tt;
+			lIntTria[Size].bary[0]=d0;
+			lIntTria[Size].bary[1]=d1;
+			lIntTria[Size].bary[2]=d2;
+			lIntTria[Size].x = x;
+			Metric m0,m1,m2;
+			register MeshVertex * v;
+			if ((v=(*tt)(0))) m0    = v->m;
+			if ((v=(*tt)(1))) m1    = v->m;
+			if ((v=(*tt)(2))) m2    = v->m;
+			lIntTria[Size].m =  Metric(lIntTria[Size].bary,m0,m1,m2);
+			n=Size++;}
+		else n=Size-1;
+		return n;
+	}
+	/*}}}1*/
+	/*FUNCTION ListofIntersectionTriangles::NewItem(R2 A,const Metric & mm){{{1*/
+	int ListofIntersectionTriangles::NewItem(R2 A,const Metric & mm) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/NewItem)*/
+
+		register int n;
+		if(!Size ||  Norme2_2(lIntTria[Size-1].x-A)) {
+			if (Size==MaxSize) ReShape();
+			lIntTria[Size].t=0;
+			lIntTria[Size].x=A;
+			lIntTria[Size].m=mm;
+			n=Size++;
+		}
+		else  n=Size-1;
+		return  n; 
+	}
+	/*}}}1*/
+	/*FUNCTION ListofIntersectionTriangles::Length{{{1*/
+	double  ListofIntersectionTriangles::Length(){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Length)*/
+
+		// computation of the length
+
+		// check Size
+		if (Size<=0){
+			ISSMERROR("Size<=0");
+		}
+
+		Metric Mx,My;
+		int ii,jj;
+		R2 x,y,xy;
+
+		SegInterpolation* SegI=lSegsI;
+		SegI=lSegsI;
+		lSegsI[NbSeg].last=Size;
+		int EndSeg=Size;
+
+		y = lIntTria[0].x;
+		double sxy, s = 0;
+		lIntTria[0].s =0;
+		SegI->lBegin=s;
+
+		for (jj=0,ii=1;ii<Size;jj=ii++) {  
+			// seg jj,ii
+			x  = y;
+			y  = lIntTria[ii].x;
+			xy = y-x;
+			Mx = lIntTria[ii].m;
+			My = lIntTria[jj].m;
+			sxy= LengthInterpole(Mx,My,xy);
+			s += sxy;
+			lIntTria[ii].s = s;
+			if (ii == EndSeg){
+				SegI->lEnd=s;
+				SegI++;
+				EndSeg=SegI->last;
+				SegI->lBegin=s;
+			}
+		}
+		len = s;
+		SegI->lEnd=s;
+
+		return s;
+	}
+	/*}}}1*/
+	/*FUNCTION ListofIntersectionTriangles::NewPoints{{{1*/
+	long ListofIntersectionTriangles::NewPoints(MeshVertex* vertices,long &nbv,long nbvx){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/NewPoints)*/
+
+		//If length<1.5, do nothing
+		double s=Length();
+		if (s<1.5) return 0;
+
+		const long nbvold=nbv;
+		int ii = 1 ;
+		R2 y,x;
+		Metric My,Mx ;
+		double sx =0,sy;
+		int nbi=Max(2,(int) (s+0.5));
+		double sint=s/nbi;
+		double si  =sint;
+
+		int EndSeg=Size;
+		SegInterpolation* SegI=NULL;
+		if (NbSeg) SegI=lSegsI,EndSeg=SegI->last;
+
+		for (int k=1;k<nbi;k++){
+			while ((ii < Size) && ( lIntTria[ii].s <= si )){
+				if (ii++ == EndSeg){
+					SegI++;
+					EndSeg=SegI->last;
+				}
+			}
+
+			int ii1=ii-1;
+			x  =lIntTria[ii1].x;
+			sx =lIntTria[ii1].s;
+			Metric Mx=lIntTria[ii1].m;
+			y  =lIntTria[ii].x;
+			sy =lIntTria[ii].s;
+			Metric My=lIntTria[ii].m;
+			double lxy = sy-sx;
+			double cy = abscisseInterpole(Mx,My,y-x,(si-sx)/lxy);
+
+			R2 C;
+			double cx = 1-cy;
+			C = SegI ? SegI->F(si): x * cx + y *cy;
+			//C.Echo();
+			//x.Echo();
+			//y.Echo();
+			//printf("cx = %g, cy=%g\n",cx,cy);
+
+			si += sint;
+			if ( nbv<nbvx) {
+				vertices[nbv].r = C;
+				vertices[nbv++].m = Metric(cx,lIntTria[ii-1].m,cy,lIntTria[ii].m);
+			}
+			else return nbv-nbvold;
+		  }
+		return nbv-nbvold;
+	}
+	/*}}}1*/
+
+}
Index: issm/trunk/src/c/objects/Bamg/ListofIntersectionTriangles.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/ListofIntersectionTriangles.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/ListofIntersectionTriangles.h	(revision 3913)
@@ -0,0 +1,112 @@
+#ifndef _LISTOFINTERSECTIONTRIANGLES_H_
+#define _LISTOFINTERSECTIONTRIANGLES_H_
+
+#include "./include.h"
+
+namespace bamg {
+
+	class Triangle;
+
+	class ListofIntersectionTriangles {
+
+		class IntersectionTriangles {
+			public: 
+				Triangle* t;
+				double  bary[3];  // use if t != 0
+				R2 x;
+				Metric m;
+				double s; // curvilinear coordinate 
+				double sp;// length of the previous segment in m
+				double sn;// length of the next segment in m
+		};
+
+		class SegInterpolation {
+			public:
+				GeometricalEdge * e;
+				double sBegin,sEnd; // abscisse of the seg on edge parameter
+				double lBegin,lEnd; // length abscisse set in ListofIntersectionTriangles::Length
+				int last;// last index  in ListofIntersectionTriangles for this Sub seg of edge
+
+				//Methods
+				R2 F(double s){ 
+					double c01=lEnd-lBegin, c0=(lEnd-s)/c01, c1=(s-lBegin)/c01;
+					if (lBegin>s || s>lEnd){
+						ISSMERROR("lBegin>s || s>lEnd");
+					}
+					return e->F(sBegin*c0+sEnd*c1);
+				}
+		};
+
+		public:
+
+			int MaxSize;
+			int Size;
+			double len;
+			int state;
+			IntersectionTriangles * lIntTria;
+			int NbSeg;
+			int MaxNbSeg;
+			SegInterpolation * lSegsI;
+
+			//Constructors/Destructors
+			ListofIntersectionTriangles(int n=256,int m=16)
+			  : MaxSize(n), Size(0), len(-1),state(-1),lIntTria(new IntersectionTriangles[n]) ,
+			  NbSeg(0), MaxNbSeg(m), lSegsI(new SegInterpolation[m]){
+				  long int verbosity=0;
+				  if (verbosity>9) printf("   construct ListofIntersectionTriangles %i %i\n",MaxSize,MaxNbSeg);
+			}
+			~ListofIntersectionTriangles(){
+				if (lIntTria) delete [] lIntTria,lIntTria=0;
+				if (lSegsI) delete [] lSegsI,lSegsI=0;
+			} 
+
+			//Operators
+			IntersectionTriangles & operator[](int i) {return lIntTria[i];}
+			operator int&() {return Size;}
+
+			//Methods
+			void  init(){state=0;len=0;Size=0;}
+			int   NewItem(Triangle * tt,double d0,double d1,double d2);
+			int   NewItem(R2,const Metric & );
+			void  SplitEdge(const Triangles & ,const R2 &,const R2  &,int nbegin=0); 
+			double Length(); 
+			long  NewPoints(MeshVertex *,long & nbv,long nbvx);
+			void  NewSubSeg(GeometricalEdge *e,double s0,double s1){ 
+				long int verbosity=0;
+				if (NbSeg>=MaxNbSeg) {
+					int mneo= MaxNbSeg;
+					MaxNbSeg *= 2;
+					if (verbosity>3){
+						printf("   reshape lSegsI from %i to %i\n",mneo,MaxNbSeg);
+					}
+					SegInterpolation * lEn =  new SegInterpolation[MaxNbSeg];
+					if (!lSegsI || NbSeg>=MaxNbSeg){
+						ISSMERROR("!lSegsI || NbSeg>=MaxNbSeg");
+					}
+					for (int i=0;i< NbSeg;i++) 
+					 lEn[i] = lSegsI[MaxNbSeg]; // copy old to new            
+					delete []  lSegsI; // remove old
+					lSegsI = lEn;        
+				}
+				if (NbSeg) lSegsI[NbSeg-1].last=Size;
+				lSegsI[NbSeg].e=e;
+				lSegsI[NbSeg].sBegin=s0;
+				lSegsI[NbSeg].sEnd=s1;     
+				NbSeg++;           
+			}
+			void ReShape(){ 
+				register int newsize = MaxSize*2;
+				IntersectionTriangles* nw = new IntersectionTriangles[newsize];
+				if (!nw) ISSMERROR("!nw");
+				// recopy
+				for (int i=0;i<MaxSize;i++) nw[i] = lIntTria[i];       
+				long int verbosity=0;
+				if(verbosity>3) printf("   ListofIntersectionTriangles  ReShape Maxsize %i -> %i\n",MaxSize,MaxNbSeg);
+				MaxSize = newsize; 
+				delete [] lIntTria;// remove old
+				lIntTria = nw; // copy pointer
+			}
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/MatVVP2x2.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/MatVVP2x2.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/MatVVP2x2.cpp	(revision 3913)
@@ -0,0 +1,58 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "Metric.h"
+
+namespace bamg {
+
+	/*Constructor*/
+	/*FUNCTION MatVVP2x2::MatVVP2x2(const Metric M){{{1*/
+	MatVVP2x2::MatVVP2x2(const Metric M){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/MatVVP2x2)*/
+
+		double a11=M.a11,a21=M.a21,a22=M.a22;
+		const double eps = 1.e-5;
+		double c11 = a11*a11, c22 = a22*a22, c21= a21*a21;
+		double b=-a11-a22,c=-c21+a11*a22;
+		double delta = b*b - 4 * c ;
+		double n2=(c11+c22+c21);
+
+		//if norm(M)<10^30 -> M=zeros(2,2)
+		if ( n2 < 1e-30) lambda1=lambda2=0,v.x=1,v.y=0;
+
+		//if matrix is already diagonal and has a 0 eigen value
+		else if (delta < eps*n2){ 
+			lambda1=lambda2=-b/2, v.x=1,v.y=0;
+		}
+
+		//general case: construction of 2 eigen vectors
+		else {
+			delta     = sqrt(delta);
+			lambda1   = (-b-delta)/2.0,lambda2 = (-b+delta)/2.0;
+			double v0 = a11-lambda1, v1 = a21,v2 = a22 - lambda1;
+			double s0 = v0*v0 + v1*v1, s1 = v1*v1 +v2*v2;
+			if(s1 < s0)
+			 s0=sqrt(s0),v.x=v1/s0,v.y=-v0/s0;
+			else
+			 s1=sqrt(s1),v.x=v2/s1,v.y=-v1/s1;
+		};
+	}
+	/*}}}1*/
+
+	/*Methods*/
+	/*FUNCTION MatVVP2x2::Echo {{{1*/
+	void MatVVP2x2::Echo(void){
+
+		printf("MatVVP2x2:\n");
+		printf("   lambda1: %g\n",lambda1);
+		printf("   lambda2: %g\n",lambda2);
+		printf("   v.x: %g\n",v.x);
+		printf("   v.y: %g\n",v.y);
+
+		return;
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/MeshVertex.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/MeshVertex.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/MeshVertex.cpp	(revision 3913)
@@ -0,0 +1,251 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "../objects.h"
+
+namespace bamg {
+
+	/*Methods*/
+	/*FUNCTION MeshVertex::Smoothing{{{1*/
+	double  MeshVertex::Smoothing(Triangles &Th,const Triangles &BTh,Triangle* &tstart ,double omega){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Smoothing)*/
+
+		register MeshVertex* s=this;
+		MeshVertex &vP = *s,vPsave=vP;
+
+		register Triangle* tbegin= t , *tria = t , *ttc;
+
+		register int k=0,kk=0,j = EdgesVertexTriangle[vint][0],jc;
+		R2 P(s->r),PNew(0,0);
+		do {
+			k++; 
+
+			if (!tria->Hidden(j)){
+				MeshVertex &vQ = (*tria)[VerticesOfTriangularEdge[j][0]]; 
+
+				R2 Q = vQ,QP(P-Q);
+				double lQP = LengthInterpole(vP,vQ,QP);
+				PNew += Q+QP/Max(lQP,1e-20);
+				kk ++;
+			}
+			ttc =  tria->TriangleAdj(j);
+			jc = NextEdge[tria->NuEdgeTriangleAdj(j)];
+			tria = ttc;
+			j = NextEdge[jc];
+			if (k>=2000){
+				ISSMERROR("k>=2000 (Maximum number of iterations reached)");
+			}
+		} while ( tbegin != tria); 
+		if (kk<4) return 0;
+		PNew = PNew/(double)kk;
+		R2 Xmove((PNew-P)*omega);
+		PNew = P+Xmove;
+		double delta=Norme2_2(Xmove); 
+
+		Icoor2 deta[3];
+		I2 IBTh  = BTh.toI2(PNew);
+
+		tstart=BTh.FindTriangleContaining(IBTh,deta,tstart);  
+
+		if (tstart->det <0){ // outside
+			double ba,bb;
+			TriangleAdjacent edge= CloseBoundaryEdge(IBTh,tstart,ba,bb) ;
+			tstart = edge;
+			vP.m= Metric(ba,*edge.EdgeVertex(0),bb,*edge.EdgeVertex(1));
+		}
+		else { // inside
+			double   aa[3];
+			double s = deta[0]+deta[1]+deta[2];
+			aa[0]=deta[0]/s;
+			aa[1]=deta[1]/s;
+			aa[2]=deta[2]/s;
+			vP.m = Metric(aa,(*tstart)[0],(*tstart)[1],(*tstart)[2]);
+		}
+
+		// recompute the det of the triangle
+		vP.r = PNew;
+
+		vP.i = Th.toI2(PNew);
+
+		MeshVertex vPnew = vP;
+
+		int ok=1;
+		int loop=1;
+		k=0;
+		while (ok){
+			ok =0;
+			do {
+				k++; 
+				double detold = tria->det;
+				tria->det =  bamg::det( (*tria)[0],(*tria)[1]  ,(*tria)[2]);
+				if (loop) {
+					MeshVertex *v0,*v1,*v2,*v3;
+					if (tria->det<0) ok =1;			       
+					else if (tria->Quadrangle(v0,v1,v2,v3))
+					  {
+						vP = vPsave;
+						double qold =QuadQuality(*v0,*v1,*v2,*v3);
+						vP = vPnew;
+						double qnew =QuadQuality(*v0,*v1,*v2,*v3);
+						if (qnew<qold) ok = 1;
+					  }
+					else if ( (double)tria->det < detold/2 ) ok=1;
+
+				}
+				tria->SetUnMarkUnSwap(0);
+				tria->SetUnMarkUnSwap(1);
+				tria->SetUnMarkUnSwap(2);
+				ttc =  tria->TriangleAdj(j);
+				jc = NextEdge[tria->NuEdgeTriangleAdj(j)];
+				tria = ttc;
+				j = NextEdge[jc];
+				if (k>=2000){
+					ISSMERROR("k>=2000");
+				}
+			}while ( tbegin != tria); 
+
+			if (ok && loop) vP=vPsave; // no move 
+			loop=0;
+		}
+		return delta;
+	}
+	/*}}}1*/
+	/*FUNCTION MeshVertex::MetricFromHessian{{{1*/
+	void MeshVertex::MetricFromHessian(const double Hxx,const double Hyx, const double Hyy,const double smin,const double smax,const double s,double err,BamgOpts* bamgopts){
+		/*Compute Metric from Hessian*/
+
+		/*get options*/
+		double power=(bamgopts->power);
+		double anisomax=(bamgopts->anisomax);
+		double CutOff=bamgopts->cutoff;
+		double hmin=(bamgopts->hmin);
+		double hmax=(bamgopts->hmax);
+		double coef=bamgopts->coef;
+		int    Metrictype=(bamgopts->Metrictype);
+
+		/*Intermediary*/
+		double ci;
+
+		/*compute multiplicative coefficient depending on Metric Type (2/9 because it is 2d)*/
+
+		//Absolute Error
+		/*
+		 *            2         1       
+		 *Metric M = ---  ------------   Abs(Hessian)
+		 *            9   err * coeff^2  
+		 */
+		if (Metrictype==0){
+			ci= 2.0/9.0 * 1/(err*coef*coef);
+		}
+
+		//Relative Error
+		/*
+		 *            2         1            Abs(Hessian)
+		 *Metric M = ---  ------------  ----------------------
+		 *            9   err * coeff^2  max( |s| , cutoff*max(|s|) )
+		 *
+		 */
+		else if (Metrictype==1){
+			ci= 2.0/9.0 * 1/(err*coef*coef) * 1/Max( Abs(s), CutOff*(Max(Abs(smin),Abs(smax))));
+		}
+
+		//Rescaled absolute error
+		/*
+		 *            2         1            Abs(Hessian)
+		 *Metric M = ---  ------------  ---------------------- 
+		 *            9   err * coeff^2       (smax-smin)
+		 */
+		else if (Metrictype==2){
+			ci= 2.0/9.0 * 1/(err*coef*coef) * 1/(smax-smin);
+		}
+		else{
+			ISSMERROR("Metrictype %i not supported yet (use 0,1 or 2(default))",Metrictype);
+		}
+
+		//initialize metric Miv with ci*H
+		Metric Miv(Hxx*ci,Hyx*ci,Hyy*ci);
+
+		//Get eigen values and vectors of Miv
+		MatVVP2x2 Vp(Miv);
+
+		//move eigen valuse to their absolute values
+		Vp.Abs();
+
+		//Apply a power if requested by user
+		if(power!=1.0) Vp.pow(power);
+
+		//modify eigen values according to hmin and hmax
+		Vp.Maxh(hmax);
+		Vp.Minh(hmin);
+
+		//Bound anisotropy by 1/(anisomax)^2
+		Vp.BoundAniso2(1/(anisomax*anisomax));
+
+		//rebuild Metric from Vp
+		Metric MVp(Vp);
+
+		//Apply Metric to vertex
+		m.IntersectWith(MVp);
+
+	}
+	/*}}}1*/
+	/*FUNCTION MeshVertex::Echo {{{1*/
+
+	void MeshVertex::Echo(void){
+
+		printf("Vertex:\n");
+		printf("  integer   coordinates i.x: %i, i.y: %i\n",i.x,i.y);
+		printf("  Euclidean coordinates r.x: %g, r.y: %g\n",r.x,r.y);
+		printf("  ReferenceNumber = %i\n",ReferenceNumber);
+		m.Echo();
+
+		return;
+	}
+	/*}}}*/
+	/*FUNCTION MeshVertex::Optim {{{1*/
+	long MeshVertex::Optim(int i,int koption){ 
+		long ret=0;
+		if ( t && (vint >= 0 ) && (vint <3) ){
+			ret = t->Optim(vint,koption);
+			if(!i){
+				t =0; // for no future optime 
+				vint= 0;
+			}
+		}
+		return ret;
+	}
+	/*}}}*/
+
+	/*Intermediary*/
+	/*FUNCTION QuadQuality{{{1*/
+	double QuadQuality(const MeshVertex & a,const MeshVertex &b,const MeshVertex &c,const MeshVertex &d) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshQuad.cpp/QuadQuality)*/
+
+		// calcul de 4 angles --
+		R2 A((R2)a),B((R2)b),C((R2)c),D((R2)d);
+		R2 AB(B-A),BC(C-B),CD(D-C),DA(A-D);
+		//  Move(A),Line(B),Line(C),Line(D),Line(A);
+		const Metric & Ma  = a;
+		const Metric & Mb  = b;
+		const Metric & Mc  = c;
+		const Metric & Md  = d;
+
+		double lAB=Norme2(AB);
+		double lBC=Norme2(BC);
+		double lCD=Norme2(CD);
+		double lDA=Norme2(DA);
+		AB /= lAB;  BC /= lBC;  CD /= lCD;  DA /= lDA;
+		// version aniso 
+		double cosDAB= Ma(DA,AB)/(Ma(DA)*Ma(AB)),sinDAB= Det(DA,AB);
+		double cosABC= Mb(AB,BC)/(Mb(AB)*Mb(BC)),sinABC= Det(AB,BC);
+		double cosBCD= Mc(BC,CD)/(Mc(BC)*Mc(CD)),sinBCD= Det(BC,CD);
+		double cosCDA= Md(CD,DA)/(Md(CD)*Md(DA)),sinCDA= Det(CD,DA);
+		double sinmin=Min(Min(sinDAB,sinABC),Min(sinBCD,sinCDA));
+		if (sinmin<=0) return sinmin;
+		return 1.0-Max(Max(Abs(cosDAB),Abs(cosABC)),Max(Abs(cosBCD),Abs(cosCDA)));
+	}
+	/*}}}1*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/MeshVertex.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/MeshVertex.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/MeshVertex.h	(revision 3913)
@@ -0,0 +1,55 @@
+#ifndef _MESHVERTEX_H_
+#define _MESHVERTEX_H_
+
+#include "./include.h"
+#include "./Metric.h"
+#include "./Direction.h"
+#include "./BamgOpts.h"
+
+namespace bamg {
+
+	//classes
+	class Triangle;
+	class Triangles;
+	class VertexOnGeom;
+	class VertexOnEdge;
+
+	class MeshVertex {
+
+		public:
+			I2 i;  // integer coordinates
+			R2 r;  // real coordinates
+			Metric m;
+			long ReferenceNumber;
+			Direction DirOfSearch;
+			short vint;  // the vertex number in triangle; varies between 0 and 2 in t
+			union {
+				Triangle* t;   // one triangle which is containing the vertex
+				long      color;
+				MeshVertex*   to;  // used in geometry MeshVertex to know the Mesh MeshVertex associated 
+				VertexOnGeom* onGeometry;        // if vint == 8; // set with Triangles::SetVertexFieldOn()
+				MeshVertex*       onBackgroundVertex;// if vint == 16 on Background vertex Triangles::SetVertexFieldOnBTh()
+				VertexOnEdge* onBackgroundEdge;  // if vint == 32 on Background edge
+			};
+
+			//Operators
+			operator I2() const {return i;}             // Cast operator
+			operator const R2 & () const {return r;}    // Cast operator
+			operator Metric () const {return m;}        // Cast operator
+			double operator()(R2 x) const { return m(x);} // Get x in the metric m
+
+			//methods (No constructor and no destructors...)
+			double Smoothing(Triangles & ,const Triangles & ,Triangle  * & ,double =1);
+			void   MetricFromHessian(const double Hxx,const double Hyx, const double Hyy, const double smin,const double smax,const double s,const double err,BamgOpts* bamgopts);
+			void   Echo();
+			int    ref() const { return ReferenceNumber;}
+			long   Optim(int =1,int =0); 
+
+			//inline functions
+			inline void Set(const MeshVertex &rec,const Triangles & ,Triangles & ){*this=rec;}
+	};
+
+	//Intermediary
+	double QuadQuality(const MeshVertex &,const MeshVertex &,const MeshVertex &,const MeshVertex &);
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/Metric.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Metric.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Metric.cpp	(revision 3913)
@@ -0,0 +1,331 @@
+#include <cstdio>
+#include <string.h>
+#include <cmath>
+
+#include "Metric.h"
+#include "../../include/include.h"
+#include "../../shared/Exceptions/exceptions.h"
+
+using namespace std;
+
+namespace bamg {
+
+	SaveMetricInterpole  LastMetricInterpole;
+
+	/*Constructor/Destructor*/
+	/*FUNCTION Metric::Metric(const double  a[3],const  Metric m0, const  Metric m1,const  Metric  m2 ){{{1*/ 
+	Metric::Metric(const double  a[3],const  Metric m0, const  Metric m1,const  Metric m2 ){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/Metric)*/
+
+		Metric mab(a[0]*m0.a11 + a[1]*m1.a11 + a[2]*m2.a11,
+					a[0]*m0.a21 + a[1]*m1.a21 + a[2]*m2.a21,
+					a[0]*m0.a22 + a[1]*m1.a22 + a[2]*m2.a22);
+
+		MatVVP2x2 vab(mab);
+
+		R2 v1(vab.v.x,vab.v.y);
+		R2 v2(-v1.y,v1.x);
+
+		double h1 = a[0] / m0(v1) + a[1] / m1(v1) + a[2] / m2(v1);
+		double h2 = a[0] / m0(v2) + a[1] / m1(v2) + a[2] / m2(v2);
+
+		vab.lambda1 =  1 / (h1*h1);
+		vab.lambda2 =  1 / (h2*h2);
+		*this = vab;
+	}
+	/*}}}1*/
+	/*FUNCTION Metric::Metric( double  a,const  Metric ma, double  b,const  Metric mb){{{1*/
+	Metric::Metric( double  a,const  Metric ma, double  b,const  Metric mb) { 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/MatVVP2x2)*/
+
+		Metric mab(a*ma.a11+b*mb.a11,a*ma.a21+b*mb.a21,a*ma.a22+b*mb.a22);
+		MatVVP2x2 vab(mab);
+
+		R2 v1(vab.v.x,vab.v.y);
+		R2 v2(-v1.y,v1.x);
+
+
+		double h1 = a / ma(v1) + b / mb(v1);
+		double h2 = a / ma(v2) + b / mb(v2);
+		vab.lambda1 =  1 / (h1*h1);
+		vab.lambda2 =  1 / (h2*h2);
+		*this = vab;
+	}
+	/*}}}1*/
+
+	/*Methods*/
+	/*FUNCTION Metric::Echo {{{1*/
+	void Metric::Echo(void){
+
+		printf("Metric:\n");
+		printf("   [a11 a21 a22]: [%g %g %g]\n",a11,a21,a22);
+
+		return;
+	}
+	/*}}}*/
+	/*FUNCTION Metric::IntersectWith{{{1*/
+	int Metric::IntersectWith(const Metric M2) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/IntersectWith)*/
+
+		/*Get a new metric from an existing metric (M1=this)
+		 * and a new metric given in input M2 using a 
+		 * Simultaneous Matrix Reduction:
+		 * If M1 and M2 are 2 metrics, we must build N=M1^-1 M2 (Alauzet2003 p16) 
+		 * the eigen vectors of N form a matrix P
+		 * The new metric M = M1 inter M2 is then given by:
+		 *
+		 *      -T [ max(lambda1, mu1)          0         ]  -1				 
+		 * M = P   [                                      ] P		 
+		 *         [        0            max(lambda2, mu2)] 
+		 *
+		 * where lambdai and mui can be computed using Rayleigh formula: 
+		 *    lambdai = vi' M1 vi
+		 * with vi eigen vectors of N (columns of P)
+		 */
+
+		int         change=0;
+		Metric &M1=*this;
+		D2xD2       P;
+
+		//Get P, eigen vectors of N=inv(M1) M2
+		SimultaneousMatrixReduction(*this,M2,P);
+
+		//extract the eigen vectors of P (columns)
+		R2 v1(P.x.x,P.y.x);
+		R2 v2(P.x.y,P.y.y);
+
+		//compute lambdai mui
+		double lambda1=M1(v1,v1);
+		double lambda2=M1(v2,v2);
+		double mu1=M2(v1,v1);
+		double mu2=M2(v2,v2);
+
+		//check where any change needs to be done on M1
+		if ( lambda1 < mu1 )  change=1,lambda1=mu1;
+		if ( lambda2 < mu2 )  change=1,lambda2=mu2; 
+
+		//update M1 if necessary
+		if (change) {
+			D2xD2 invP(P.inv());
+			D2xD2 D(lambda1,0,0,lambda2); 
+			D2xD2 M(invP.t()*D*invP);
+			a11=M.x.x;
+			a21=0.5*(M.x.y+M.y.x);
+			a22=M.y.y;
+		}
+		return change;
+	}
+	/*}}}1*/
+
+	/*Intermediary*/
+	/*FUNCTION LengthInterpole{{{1*/
+	double LengthInterpole(const Metric Ma,const  Metric Mb, R2 AB) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/LengthInterpole)*/
+
+		double k=1./2.;
+		int level=0;
+		static int kkk=0;
+		static  Metric Ms1[32],Ms2[32];
+		static double lMs1[32],lMs2[32];
+		static double K[32];
+		double l=0,sss=0;
+		Ms1[level]=Ma;
+		Ms2[level]=Mb;
+		double sa =  Ma(AB);
+		double sb =  Mb(AB);
+		lMs1[level]=sa;
+		lMs2[level]=sb;
+		K[level]=k;
+		level++;
+		int i=0;
+		double * L= LastMetricInterpole.L, *S = LastMetricInterpole.S;
+		double  sstop = 0.1; // Max(0.6,(sa+sb)/5000);
+		while (level) {
+			level--;
+			Metric M1=Ms1[level];
+			Metric M2=Ms2[level];
+			k=K[level];
+			double s1=  lMs1[level];
+			double s2=  lMs2[level];
+
+			double s= (s1+s2)*k;
+			if( s > sstop   && level < 30 && i < 500-level ) {
+				Metric Mi(0.5,M1,0.5,M2);
+				double si = Mi(AB);
+				if( Abs((s1+s2)-(si+si)) > s1*0.001) 
+				  {
+					k=k/2;
+					// we begin by the end to walk in the correct sens from a to b
+					// due to the stack 
+					Ms1[level]=Mi;
+					Ms2[level]=M2;
+					lMs1[level]=si;
+					lMs2[level]=s2;
+					K[level]=k;
+					level++;
+					Ms1[level]=M1;
+					Ms2[level]=Mi;
+					lMs1[level]=s1;
+					lMs2[level]=si;
+					K[level]=k;
+					level++;
+				  }
+				else
+				 L[i]= l += s,S[i]=sss+=k,i++;
+			}
+			else 
+			 L[i]= l += s,S[i]=sss+=k,i++;
+		}
+		// warning for optimisation S is in [0:0.5] not in [0:1]
+		if (i>=512){
+			ISSMERROR("i>=512");
+		}
+		LastMetricInterpole.lab=l;
+		LastMetricInterpole.opt=i;
+		if (i>200 && kkk++<10) printf("WARNING: LengthInterpole: ( i=%i l=%i sss=%i ) %g\n",i,l,sss,sstop); 
+		return l;
+	}
+	/*}}}1*/
+	/*FUNCTION SimultaneousMatrixReduction{{{1*/
+	void SimultaneousMatrixReduction( Metric M1,  Metric M2, D2xD2 &V) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/ReductionSimultanee)*/
+
+		/*In this routine we must return a matrix V that is composed of the 
+		 * eigen vectors of N=inv(M1) M2.
+		 * Instead of looking at N directly, we are going to use the fact that
+		 * M1 and M2 are symmetrical, positive definite. 
+		 * The eigen values of N are given by solving
+		 *    inv(M1) M2 V = lambda V
+		 * which is equivalent to
+		 *    M2 V = lambda M1 V
+		 * and we will hence solve
+		 *    (M2 - lambda M1) V = 0
+		 */
+
+		int i;
+
+		//M1 and M2 components
+		double a11=M1.a11,a21=M1.a21,a22=M1.a22;
+		double b11=M2.a11,b21=M2.a21,b22=M2.a22;
+
+		/*To get the eigen values, we solve the following problem:
+		 *    det(M2-lambda M1) = 0
+		 *    (b11 - lambda a11)(b22-lambda a22) - (b21-lambda a21)^2
+		 * and we have the following trinome:
+		 *    a lambda^2 + b lambda + c =0
+		 * with:
+		 *    a = a11 a22 - a21 a21 (=det(M1))
+		 *    b = -a11 b22 -b11 a22 + 2 b21 a21
+		 *    c = b11 b22 - b21 b21 (=det(M2))
+		 *    */
+		const double a= a11*a22  - a21*a21;
+		const double b=-a11*b22 - b11*a22+2*b21*a21;
+		const double c=-b21*b21 + b11*b22;
+		const double bb=b*b,ac=a*c;
+		const double delta= bb-4*ac;
+
+		// first, case of a double root if:
+		//  - all the terms are very small (a??)
+		//  - or : delta is very small
+		if ( (bb + Abs(ac) < 1.0e-34 ) ||  (delta < 1.0e-6*bb) ){
+			//all vectors are eigen vectors -> choose 1,0 and 0,1
+			V= D2xD2(1,0,0,1);
+		}
+
+		//general case: two distinct roots: lambda1 and lambda2
+		else {
+
+			/*Compute eigen values*/
+			const double delta2 = sqrt(delta);
+			double lambda[2];
+			lambda[0]= (-b - delta2)/(2*a);
+			lambda[1]= (-b + delta2)/(2*a);
+
+			/*compute eigen vectors*/
+			double vp[2][2];
+			double v0,v1,v2;
+			double s0,s1;
+
+			for(i=0;i<2;i++){
+				/*Now, one must find the eigen vectors. For that we use the 
+				 * following property of the scalare product
+				 *    (Ax,b) = transp(b) Ax = transp(x) transp(A) b
+				 *           = (transp(A) b ,x)
+				 * Here we are dealing with A= M2 - lambda M1 which is symmetrical:
+				 *    for all (x,y) in R2 
+				 *       ((M2 - lambda M1)x,y)=((M2 - lambda M1)y,x)
+				 * If y is in Ker(M2 - lambda M1):
+				 *    for all x in R2
+				 *       ((M2 - lambda M1)y,x)=0
+				 * This shows that:
+				 *    Ker(M2 - lambda M1) is orthogonal to Im(M2 - lambda M1)
+				 * To find the eigen vectors, we only have to find two vectors
+				 * of the image and take their perpendicular as long as they are
+				 * not 0.
+				 * To do that, we take (1,0) and (0,1) and take the larger norm*/
+
+				//compute V = M2 - lambdai M1
+				v0 = b11 - lambda[i]*a11;
+				v1 = b21 - lambda[i]*a21;
+				v2 = b22 - lambda[i]*a22;
+
+				// compute s1=norm(V(1,0)) and s0=norm(V(0,1))
+				s0 = v0*v0 + v1*v1;
+				s1 = v1*v1 + v2*v2;
+
+				//compute vp1 = (vp1x,vp1y)
+				if(s1 < s0){
+					s0=sqrt(s0);
+					vp[0][i]=   v1/s0;
+					vp[1][i]= - v0/s0;
+				}
+				else{
+					s1=sqrt(s1);
+					vp[0][i]=   v2/s1;
+					vp[1][i]= - v1/s1;
+				}
+			}
+
+			//compute V from vp
+			V=D2xD2(vp[0][0],vp[0][1],vp[1][0],vp[1][1]);
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION abscisseInterpole{{{1*/
+	double abscisseInterpole(const Metric Ma,const  Metric Mb, R2 AB,double s,int optim) { 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/abscisseInterpole)*/
+
+		if(!optim)  LengthInterpole(Ma,Mb,AB);
+		double l  = s* LastMetricInterpole.lab,r;
+		int j=LastMetricInterpole.opt-1,i=0,k;
+
+		double * L= LastMetricInterpole.L, *S = LastMetricInterpole.S;
+		// warning for optimisation S is the abcisse in [0:0.5]
+		// and L is le lenght 
+		if(l<=L[0])
+		 r=2*S[0]*l/L[0];
+		else if (l>=L[j])
+		 r=1;
+		else 
+		  {
+			while (j-i>1)
+			  {
+				k= (i+j)/2;
+				if(l<=L[k])
+				 j=k;// l<=L[j] 
+				else
+				 i=k; //  L[i]<l
+			  };
+			if (i==j)
+			 r = 2*S[i];
+			else
+			 r =  2*(S[i]*(L[j]-l)+ S[j]*(l-L[i]))/(L[j]-L[i]);
+		  }
+		if (r>1 || r<0){
+			ISSMERROR("r>1 || r<0");
+		}
+		return r ;
+	}
+	/*}}}1*/
+
+}
Index: issm/trunk/src/c/objects/Bamg/Metric.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Metric.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Metric.h	(revision 3913)
@@ -0,0 +1,126 @@
+#ifndef _METRIC_H
+#define _METRIC_H
+
+#include "./include.h"
+#include "../../shared/Bamg/shared.h"
+#include "R2.h"
+
+namespace bamg {
+
+	typedef P2<double,double>    D2;
+	typedef P2xP2<double,double> D2xD2;
+
+	class Metric;
+	class MatVVP2x2;
+
+
+	class Metric{
+
+		public:
+			//fields
+			double a11,a21,a22;
+			//friends
+			friend class MatVVP2x2;
+			//functions
+			Metric(){};
+			Metric(const MatVVP2x2);
+			Metric(double a): a11(1/(a*a)),a21(0),a22(1/(a*a)){}
+			Metric(double a,double b,double c) :a11(a),a21(b),a22(c){}
+			Metric( double  a,const  Metric ma, double  b,const  Metric mb);
+			Metric(const double  a[3],const  Metric m0,const  Metric m1,const  Metric m2 );
+			void  Echo();
+			R2    mul(const R2 x)const {return R2(a11*x.x+a21*x.y,a21*x.x+a22*x.y);}
+			double det() const {return a11*a22-a21*a21;}  
+			R2    Orthogonal(const R2 x){return R2(-(a21*x.x+a22*x.y),a11*x.x+a21*x.y);}
+			R2    Orthogonal(const I2 x){return R2(-(a21*x.x+a22*x.y),a11*x.x+a21*x.y);}
+			int   IntersectWith(const Metric M2);
+			inline void Box(double &hx,double &hy) const ;  
+			//operators
+			Metric operator*(double c) const {double c2=c*c;return  Metric(a11*c2,a21*c2,a22*c2);} 
+			Metric operator/(double c) const {double c2=1/(c*c);return  Metric(a11*c2,a21*c2,a22*c2);} 
+			operator D2xD2(){ return D2xD2(a11,a21,a21,a22);}
+			double  operator()(R2 x) const { return sqrt(x.x*x.x*a11+2*x.x*x.y*a21+x.y*x.y*a22);};
+			double  operator()(R2 x,R2 y) const { return x.x*y.x*a11+(x.x*x.y+x.y*y.x)*a21+x.y*y.y*a22;};
+
+	};
+
+	class MatVVP2x2{
+		public:
+			//fields
+			double lambda1,lambda2;
+			D2     v;
+			//friends
+			friend  class Metric;
+			//functions
+			MatVVP2x2(const Metric );
+			MatVVP2x2(double r1,double r2,const D2 vp1): lambda1(r1),lambda2(r2),v(vp1){}
+			void  Echo();
+			void  Abs(){lambda1=bamg::Abs(lambda1),lambda2=bamg::Abs(lambda2);}
+			void  pow(double p){lambda1=::pow(lambda1,p);lambda2=::pow(lambda2,p);}
+			void  Min(double a) { lambda1=bamg::Min(a,lambda1); lambda2=bamg::Min(a,lambda2) ;}
+			void  Max(double a) { lambda1=bamg::Max(a,lambda1); lambda2=bamg::Max(a,lambda2) ;}
+			void Minh(double h) {Min(1.0/(h*h));}
+			void Maxh(double h) {Max(1.0/(h*h));}
+			void Isotrope() {lambda1=lambda2=bamg::Max(lambda1,lambda2);}
+			double hmin() const {return sqrt(1/bamg::Max3(lambda1,lambda2,1e-30));}
+			double hmax() const {return sqrt(1/bamg::Max(bamg::Min(lambda1,lambda2),1e-30));}
+			double lmax() const {return bamg::Max3(lambda1,lambda2,1e-30);}
+			double lmin() const {return bamg::Max(bamg::Min(lambda1,lambda2),1e-30);}
+			double Aniso2() const  { return lmax()/lmin();}
+			double Aniso() const  { return sqrt( Aniso2());}
+			void BoundAniso(const double c){ BoundAniso2(1/(c*c));}
+			inline void BoundAniso2(const double coef);
+			//operators
+			void operator *=(double coef){ lambda1*=coef;lambda2*=coef;}
+	};
+
+	class SaveMetricInterpole {
+		friend double LengthInterpole(const Metric ,const  Metric , R2 );
+		friend double abscisseInterpole(const Metric ,const  Metric , R2 ,double ,int );
+		int opt;
+		double lab;
+		double L[1024],S[1024];
+	};
+
+	extern SaveMetricInterpole  LastMetricInterpole; // for optimization 
+	//Functions
+	void  SimultaneousMatrixReduction( Metric M1,  Metric M2,D2xD2 &V);
+	double LengthInterpole(const Metric Ma,const  Metric Mb, R2 AB);
+	double abscisseInterpole(const Metric Ma,const  Metric Mb, R2 AB,double s,int optim=0);
+
+	//inlines
+	inline void  MatVVP2x2::BoundAniso2(const double coef){
+		if (coef<=1.00000000001){
+			if (lambda1 < lambda2)
+			 lambda1 = bamg::Max(lambda1,lambda2*coef);
+			else
+			 lambda2 = bamg::Max(lambda2,lambda1*coef);
+		}
+		else{  //TO BE CHECKED
+			if (lambda1 > lambda2)
+			 lambda1 = bamg::Min(lambda1,lambda2*coef);
+			else
+			 lambda2 = bamg::Min(lambda2,lambda1*coef);
+		}
+	}
+	inline Metric::Metric(const MatVVP2x2 M) {
+		double v00=M.v.x*M.v.x;
+		double v11=M.v.y*M.v.y;
+		double v01=M.v.x*M.v.y;
+		a11=v00*M.lambda1+v11*M.lambda2;
+		a21=v01*(M.lambda1-M.lambda2);
+		a22=v00*M.lambda2+v11*M.lambda1;
+	}
+	inline   void  Metric::Box(double &hx,double &hy) const {
+		double d=  a11*a22-a21*a21;
+		hx = sqrt(a22/d);
+		hy = sqrt(a11/d);
+	}
+	inline double LengthInterpole(double la,double lb) {
+		return ( Abs(la - lb) < 1.0e-6*Max3(la,lb,1.0e-20) ) ?  (la+lb)/2  : la*lb*log(la/lb)/(la-lb);
+	}
+	inline double abscisseInterpole(double la,double lb,double lab,double s){
+		return ( Abs(la - lb) <1.0e-6*Max3(la,lb,1.0e-20))  ? s : (exp(s*lab*(la-lb)/(la*lb))-1)*lb/(la-lb);
+	}
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/QuadTree.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/QuadTree.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/QuadTree.cpp	(revision 3913)
@@ -0,0 +1,553 @@
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "../objects.h"
+
+namespace bamg {
+
+	/*MACROS {{{1*/
+#define INTER_SEG(a,b,x,y) (((y) > (a)) && ((x) <(b)))
+#define ABS(i) ((i)<0 ?-(i) :(i))
+#define MAX1(i,j) ((i)>(j) ?(i) :(j))
+#define NORM(i1,j1,i2,j2) MAX1(ABS((i1)-(j1)),ABS((i2)-(j2)))
+	//IJ(i,j,l) returns the box number of i and j with respect to l
+	//if !j&l and !i$l -> 0 (box zero: lower left )
+	//if !j&l and  i$l -> 1 (box one:  lower right)
+	//if  j&l and !i$l -> 2 (box two:  upper left )
+	//if  j&l and  i$l -> 3 (box three:upper right)
+#define IJ(i,j,l)  ((j&l) ? ((i&l) ? 3:2 ) :((i&l) ? 1:0 ))
+	//I_IJ(k,l) returns l if first  bit of k is 1, else 0
+#define I_IJ(k,l)  ((k&1) ? l:0)
+	//J_IJ(k,l) returns l if second bit of k is 1, else 0
+#define J_IJ(k,l)  ((k&2) ? l:0)
+	/*}}}*/
+	/*DOCUMENTATION What is a QuadTree? {{{1
+	 * A Quadtree is a very simple way to group the vertices according
+	 * to their location. A square that holds all the points of the mesh
+	 * (or the geometry) is divided into 4 boxes. As soom as one box
+	 * hold more than 4 vertices, it is divided into 4 new boxes, etc...
+	 * There cannot be more than MAXDEEP (=30) subdivision.
+	 * This process is like a Dichotomy in dimension 2
+	 *
+	 *  + - -  -    - -    -    - - + -   - + - + - + - -     - - +
+	 *  |                           |       |   | X |             |
+	 *                                      + - + - +
+	 *  |                           |       |   |   |             |
+	 *                              + -   - + - + - +             +
+	 *  |                           |       |       |             |
+	 *                         
+	 *  |                           |       |       |             |
+	 *  + - -  -    - -    -    - - + -   - + -   - + - -     - - +
+	 *  |                           |               |             |
+	 *                         
+	 *  |                           |               |             |
+	 *                         
+	 *  |                           |               |             |
+	 *  |                           |               |             |
+	 *  + - -  -    - -    -    - - + -   -   -   - + - -     - - +
+	 *  |                           |                             |
+	 *                         
+	 *  |                           |                             |
+	 *                         
+	 *  |                           |                             |
+	 *                         
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  |                           |                             |
+	 *  + - -  -    - -    -    - - + -   -   -   -   - -     - - +
+	 *
+	 * The coordinate system used in a quadtree are integers to avoid
+	 * round-off errors. The vertex in the lower left box has the coordinates
+	 * (0 0) 
+	 * The upper right vertex has the follwing coordinates:
+	 * 2^30 -1           2^30 -1        in decimal
+	 * 0 1 1 1 .... 1    0 1 1 1 .... 1 in binary
+	 *  \--   29  --/     \--   29  --/
+	 * Using the binaries is therefor very easy to locate a vertex in a box:
+	 * we just need to look at the bits from the left to the right (See ::Add)
+	 }}}1*/
+
+	/*Constructors/Destructors*/
+	/*FUNCTION QuadTree::QuadTree(Triangles * t,long nbv){{{1*/
+	QuadTree::QuadTree(Triangles * t,long nbv) : 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/QuadTree)*/
+
+		lenStorageQuadTreeBox(t->nbvx/8+10),
+		th(t),
+		NbQuadTreeBox(0),
+		NbVertices(0),
+		NbQuadTreeBoxSearch(0),
+		NbVerticesSearch(0)
+	{ 
+	 if (nbv == -1) nbv = t->nbv;
+	 sb =new StorageQuadTreeBox(lenStorageQuadTreeBox);
+	 root=NewQuadTreeBox();
+	 if ( MaxISize <= MaxICoor){
+		 ISSMERROR("MaxISize <= MaxICoor");
+	 }
+	 for (int i=0;i<nbv;i++) 
+	  Add(t->vertices[i]);
+	}
+	/*}}}1*/
+	/*FUNCTION QuadTree::QuadTree(){{{1*/
+	QuadTree::QuadTree() : 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/QuadTree)*/
+
+		lenStorageQuadTreeBox(100), // by default 100 vertices by box
+		th(0),                      // initial mesh = NULL
+		NbQuadTreeBox(0),           // initial number of quadtree boxes = 0
+		NbVertices(0),              // initial number of vertices = 0
+		NbQuadTreeBoxSearch(0),     // initial ?? = 0
+		NbVerticesSearch(0){        // initial ?? = 0
+			//create lenStorageQuadTreeBox (100) StorageQuadTreeBox elements
+			sb  =new StorageQuadTreeBox(lenStorageQuadTreeBox); 
+			//root=QuadTreeBox* pointer roward ??
+			root=NewQuadTreeBox();
+		}
+	/*}}}1*/
+	/*FUNCTION QuadTree::~QuadTree(){{{1*/
+	QuadTree::~QuadTree() {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/~QuadTree)*/
+
+		delete sb; 
+		root=0;
+	}
+	/*}}}1*/
+
+	/*Methods*/
+	/*FUNCTION QuadTree::Add{{{1*/
+	void  QuadTree::Add(MeshVertex &w){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/Add)*/
+
+		QuadTreeBox** pb;
+		QuadTreeBox*  b;
+		register long i=w.i.x, j=w.i.y;
+		register long level=MaxISize;
+
+		//Get inital box (the largest)
+		pb = &root;
+
+		//Find the smallest box where w is located
+		while((b=*pb) && (b->n<0)){ 
+
+			//shift b->n by -1
+			b->n--;
+
+			//shifted righ by one bit: level=00000010 -> 00000001
+			level >>= 1;
+
+			//Get next subbox according to the bit value (level)
+			pb = &b->b[IJ(i,j,level)];
+		}
+
+		//OK, we have found b, a Subbox holding vertices (might be full)
+		//check that the vertex is not already in the box
+		if  (b) {      
+			if (b->n > 3 &&  b->v[3] == &w) return;
+			if (b->n > 2 &&  b->v[2] == &w) return;
+			if (b->n > 1 &&  b->v[1] == &w) return;
+			if (b->n > 0 &&  b->v[0] == &w) return;
+		}
+
+		//check that l is not 0 (this should not happen as MaxDeep = 30)
+		if (level==0){
+			ISSMERROR("level==0 cannot be true as it has been initialized as MaxISize = %i",MaxISize);
+		}
+
+		//Now, try to add the vertex, if the subbox is full (n=4), we have to divide it
+		//in 4 new subboxes
+		while ((b= *pb) && (b->n == 4)){ // the QuadTreeBox is full
+
+			//Copy the 4 vertices in the current QuadTreebox
+			MeshVertex* v4[4];
+			v4[0]= b->v[0];
+			v4[1]= b->v[1];
+			v4[2]= b->v[2];
+			v4[3]= b->v[3];
+
+			//set n as negative (box full -> holds 4 pointers toward subboxes and not 4 vertices)
+			b->n = -b->n;
+
+			//Initialize the 4 pointers toward the 4 subboxes
+			b->b[0]=b->b[1]=b->b[2]=b->b[3]=NULL;
+
+			// div the size by 2
+			level >>= 1;
+
+			//Put the four vertices in the new boxes
+			for (register int k=0;k<4;k++){
+				register int ij;
+				register QuadTreeBox* bb =  b->b[ij=IJ(v4[k]->i.x,v4[k]->i.y,level)];
+
+				// alloc the QuadTreeBox 
+				if (!bb) bb=b->b[ij]=NewQuadTreeBox(); 
+
+				//Copy the 4 vertices
+				bb->v[bb->n++] = v4[k];
+			}
+
+			//Get the subbox where w (i,j) is located
+			pb = &b->b[IJ(i,j,level)];
+		}
+
+		//  alloc the QuadTreeBox 
+		if (!(b = *pb)) b=*pb= NewQuadTreeBox();
+
+		//Add w
+		b->v[b->n++]=&w;
+
+		//Increase NbVertices by one (we have one new vertex)
+		NbVertices++;    
+	}
+	/*}}}1*/
+	/*FUNCTION QuadTree::NearestVertex{{{1*/
+	MeshVertex*  QuadTree::NearestVertex(Icoor1 i,Icoor1 j) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/NearestVertex)*/
+
+		/*Build QuadTree*/
+		QuadTreeBox* pb[MaxDeep];
+		int      pi[MaxDeep];
+		Icoor1   ii[MaxDeep];
+		Icoor1   jj[MaxDeep];
+		register int level=0; // levelevelevel
+		register long n0;
+		register QuadTreeBox* b;
+		long     h=MaxISize,h0;
+		long     hb=MaxISize;
+		Icoor1   i0=0,j0=0;
+		//iplus= i projected in [0,MaxISize-1] (example: if i<0, i=0)
+		Icoor1   iplus( i<MaxISize?(i<0?0:i):MaxISize-1);
+		//jplus= j projected in [0,MaxISize-1] (example: if j>=MaxISize, j=MaxISize-1)
+		Icoor1   jplus( j<MaxISize?(j<0?0:j):MaxISize-1);
+		//initial nearest vertex pointer
+		MeshVertex*  vn=NULL;
+
+		//Get initial Quadtree box (largest)
+		b = root;
+
+		//if the tree is empty, return NULL pointer
+		if (!root->n) return vn; 
+
+		//else, find the non empty QuadTreeBox containing  the point (i,j)
+		while((n0=b->n)<0){
+
+			//shifted righ by one bit: hb2=01000000 -> 00100000
+			register Icoor1 hb2 = hb >> 1;
+			//Get QuadTreeBox number of size hb2 containing i;j (Macro)
+			register int      k = IJ(iplus,jplus,hb2);
+			//Get the corresponding box b0
+			register QuadTreeBox* b0=b->b[k];
+
+			// break if NULL box or empty
+			if (( b0 == NULL) || (b0->n == 0)) break;
+
+			//Get next Qudtree box
+			NbQuadTreeBoxSearch++;
+			b=b0;	
+			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox (macro)
+			j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 
+			hb = hb2; 
+		}
+
+		// if the current subbox is holding vertices, we are almost done
+		if ( n0>0 ){  
+			//loop over the vertices of the box and find the closest vertex
+			for(register int k=0;k<n0;k++){
+				I2 i2=b->v[k]->i;
+				h0=NORM(iplus,i2.x,jplus,i2.y);
+				if (h0<h){
+					h = h0;
+					vn = b->v[k];
+				}
+				NbVerticesSearch++;
+			}
+			return vn;
+		}
+
+		/* general case: the current box is empty, we have to get backwards
+			and find the closest not-empty box and find the closest vertex*/
+
+		//initialize pb pi ii and jj
+		pb[0]=b;                  //pointer toward the box b
+		pi[0]=b->n>0? (int)b->n:4;//number of vertices in the box
+		ii[0]=i0;                 // i coordinate of the box
+		jj[0]=j0;                 // j coordinate of the box
+
+		//initialize h as hb
+		h=hb;
+
+		//loop, until level=0
+		do {
+			//get current box
+			b= pb[level];
+
+			//Loop over the vertices in current box (if not empty!)
+			while (pi[level]--){
+
+				//k = number of vertices in the box if there are vertices
+				//k = 4 if the current box is pointing toward 4 other boxes
+				register int k=pi[level];
+
+				//if the current subbox is holding vertices,
+				if (b->n>0){ // MeshVertex QuadTreeBox not empty
+					NbVerticesSearch++;
+					I2 i2 =  b->v[k]->i;
+					h0 = NORM(iplus,i2.x,jplus,i2.y);
+					if (h0 <h){
+						h = h0;
+						vn = b->v[k];
+					}
+				}
+
+				else{
+					register QuadTreeBox* b0=b;
+					NbQuadTreeBoxSearch++;
+
+					//if the next box exists:
+					if ((b=b->b[k])){
+						//shifted righ by one bit: hb2=01000000 -> 00100000
+						hb>>=1;
+						register Icoor1 iii = ii[level]+I_IJ(k,hb);
+						register Icoor1 jjj = jj[level]+J_IJ(k,hb);
+
+						//if the current point is in b,go to next box
+						if (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)){
+							pb[++level]=  b;
+							pi[level]= b->n>0 ?(int)  b->n : 4  ;
+							ii[level]= iii;
+							jj[level]= jjj;
+						}
+
+						//else go backwards
+						else{
+							//shifted righ by one bit: hb=001000000 -> 01000000
+							b=b0;
+							hb<<=1;
+						}
+					}
+					//Go backwards
+					else b=b0;
+				}
+			}
+
+			//else go backwards
+			//shifted righ by one bit: hb=001000000 -> 01000000
+			hb <<= 1;
+		} while (level--);
+
+		//return vn, nearest vertex
+		return vn;
+	}
+	/*}}}1*/
+	/*FUNCTION QuadTree::NearestVertexWithNormal{{{1*/
+	MeshVertex*  QuadTree::NearestVertexWithNormal(Icoor1 i,Icoor1 j) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/NearestVertexWithNormal)*/
+
+		QuadTreeBox * pb[ MaxDeep ];
+		int  pi[ MaxDeep  ];
+		Icoor1 ii[  MaxDeep ], jj [ MaxDeep];
+		int l; // level
+		QuadTreeBox * b;
+		long     h =MaxISize,h0;
+		long     hb=MaxISize;
+		Icoor1  i0=0,j0=0;
+		Icoor1  iplus( i<MaxISize?(i<0?0:i):MaxISize-1);
+		Icoor1  jplus( j<MaxISize?(j<0?0:j):MaxISize-1);
+
+		MeshVertex *vn=0;
+
+		// init for optimisation ---
+		b = root;
+		register long  n0;
+		if (!root->n)
+		 return vn; // empty tree 
+
+		while( (n0 = b->n) < 0) 
+		  {
+			// search the non empty 
+			// QuadTreeBox containing  the point (i,j)
+			register Icoor1 hb2 = hb >> 1 ;
+			register  int k = IJ(iplus,jplus,hb2);// QuadTreeBox number of size hb2 contening i;j
+			register QuadTreeBox * b0= b->b[k];
+			if ( ( b0 == 0) || (b0->n == 0) ) 
+			 break; // null box or empty   => break 	    
+			NbQuadTreeBoxSearch++;
+			b=b0;	
+			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox
+			j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 
+			hb = hb2; 
+		  }
+
+
+		if ( n0 > 0) 
+		  {  
+			for(register int k=0;k<n0;k++)
+			  {
+				I2 i2 =  b->v[k]->i;
+				//   try if is in the right sens -- 
+				h0 = NORM(iplus,i2.x,jplus,i2.y);
+				if (h0 <h) {
+					h = h0;
+					vn = b->v[k];}
+					NbVerticesSearch++;
+			  }
+			if (vn) return vn; 
+		  }
+		// general case -----
+		// INITIALISATION OF THE HEAP 
+		l =0; // level 
+		pb[0]= b;
+		pi[0]=b->n>0 ?(int)  b->n : 4  ;
+		ii[0]=i0;
+		jj[0]=j0;
+		h=hb;
+		do {   // walk on the tree  
+			b= pb[l];
+			while (pi[l]--) // loop on 4 element of the box
+			  { 	      
+				int k = pi[l];
+
+				if (b->n>0) // MeshVertex QuadTreeBox none empty
+				  { 
+					NbVerticesSearch++;
+					I2 i2 =  b->v[k]->i;
+					// if good sens when try -- 
+
+					h0 = NORM(iplus,i2.x,jplus,i2.y);
+					if (h0 <h) 
+					  {
+						h = h0;
+						vn = b->v[k];
+					  }
+				  }
+				else // Pointer QuadTreeBox 
+				  { 
+					register QuadTreeBox *b0=b;
+					NbQuadTreeBoxSearch++;
+					if ((b=b->b[k])) 
+					  {
+						hb >>=1 ; // div by 2
+						register Icoor1 iii = ii[l]+I_IJ(k,hb);
+						register Icoor1 jjj = jj[l]+J_IJ(k,hb);
+
+						if  (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)) 
+						  {
+							pb[++l]=  b;
+							pi[l]= b->n>0 ?(int)  b->n : 4  ;
+							ii[l]= iii;
+							jj[l]= jjj;
+
+						  }
+						else
+						 b=b0, hb <<=1 ;
+					  }
+					else
+					 b=b0;
+				  }
+			  }
+			hb <<= 1; // mul by 2 
+		} while (l--);
+
+		return vn;
+	}
+	/*}}}1*/
+	/*FUNCTION QuadTree::StorageQuadTreeBox::StorageQuadTreeBox{{{1*/
+	QuadTree::StorageQuadTreeBox::StorageQuadTreeBox(long ll,StorageQuadTreeBox *nn) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/StorageQuadTreeBox)*/
+
+		len = ll;
+		n = nn;
+		b = new QuadTreeBox[ll];
+		for (int i = 0; i <ll;i++)
+		 b[i].n =0,b[i].b[0]=b[i].b[1]=b[i].b[2]=b[i].b[3]=0;
+		bc =b;
+		be = b +ll;
+		if (!b){
+			ISSMERROR("!b");
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION QuadTree::ToClose {{{1*/
+	MeshVertex *   QuadTree::ToClose(MeshVertex & v,double seuil,Icoor1 hx,Icoor1 hy){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.cpp/ToClose)*/
+
+		const Icoor1 i=v.i.x;
+		const Icoor1 j=v.i.y;
+		const R2 X(v.r);
+		const Metric  Mx(v.m);
+
+		QuadTreeBox * pb[ MaxDeep ];
+		int  pi[ MaxDeep  ];
+		Icoor1 ii[  MaxDeep ], jj [ MaxDeep];
+		register int l=0; // level
+		register QuadTreeBox * b;
+		Icoor1 h=MaxISize;
+		Icoor1 hb =  MaxISize;
+		Icoor1 i0=0,j0=0;
+
+		//  MeshVertex *vn=0;
+
+		if (!root->n)
+		 return 0; // empty tree 
+
+		// general case -----
+		pb[0]=root;
+		pi[0]=root->n>0 ?(int)  root->n : 4  ;
+		ii[0]=i0;
+		jj[0]=j0;
+		h=hb;
+		do {    
+			b= pb[l];
+			while (pi[l]--)
+			  { 	      
+				register int k = pi[l];
+
+				if (b->n>0) // MeshVertex QuadTreeBox none empty
+				  { 
+					NbVerticesSearch++;
+					I2 i2 =  b->v[k]->i;
+					if ( ABS(i-i2.x) <hx && ABS(j-i2.y) <hy )
+					  {
+						R2 XY(X,b->v[k]->r);
+						double dd;
+						if( (dd= LengthInterpole(Mx(XY), b->v[k]->m(XY)))  < seuil ){
+							return b->v[k]; 
+						  }
+					  }
+				  }
+				else // Pointer QuadTreeBox 
+				  { 
+					register QuadTreeBox *b0=b;
+					NbQuadTreeBoxSearch++;
+					if ((b=b->b[k]))
+					  {
+						hb >>=1 ; // div by 2
+						register long iii = ii[l]+I_IJ(k,hb);
+						register long jjj = jj[l]+J_IJ(k,hb);
+
+						if  (INTER_SEG(iii,iii+hb,i-hx,i+hx) && INTER_SEG(jjj,jjj+hb,j-hy,j+hy)) 
+						  {
+							pb[++l]=  b;
+							pi[l]= b->n>0 ?(int)  b->n : 4  ;
+							ii[l]= iii;
+							jj[l]= jjj;
+
+						  }
+						else
+						 b=b0, hb <<=1 ;
+					  }
+					else
+					 b=b0;
+				  }
+			  }
+			hb <<= 1; // mul by 2 
+		} while (l--);
+
+		return 0;
+	}
+	/*}}}1*/
+
+}
Index: issm/trunk/src/c/objects/Bamg/QuadTree.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/QuadTree.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/QuadTree.h	(revision 3913)
@@ -0,0 +1,65 @@
+/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, QuadTree.h)*/
+#ifndef _QUADTREE_H
+#define _QUADTREE_H
+
+#include "./include.h"
+
+namespace bamg {
+
+	const int  MaxDeep = 30;
+	const long MaxISize = ( 1L << MaxDeep); 
+
+	class Triangles;
+	class MeshVertex;
+
+	class QuadTree{
+		private:
+			class QuadTreeBox { 
+				public:
+					long n; 
+					//contains only one object form the list (either MeshVertex or QuadTreeBox)
+					// if n < 4 => MeshVertex else =>  QuadTreeBox;
+					union{
+						QuadTreeBox* b[4];
+						MeshVertex* v[4];
+					};
+			};
+			class StorageQuadTreeBox {
+				public:
+					QuadTreeBox *b,*bc,*be;
+					long len;
+					StorageQuadTreeBox* n; // next StorageQuadTreeBox
+					StorageQuadTreeBox(long ,StorageQuadTreeBox* =NULL);
+					~StorageQuadTreeBox() {
+						if(n) delete n;
+						delete [] b;
+					}
+					long  SizeOf() const {return len*sizeof(QuadTreeBox)+sizeof(StorageQuadTreeBox)+ (n?n->SizeOf():0);}
+			};
+			StorageQuadTreeBox* sb;
+			long                lenStorageQuadTreeBox;
+
+		public:
+			//fields
+			QuadTreeBox* root;
+			Triangles*   th;
+			//functions
+			~QuadTree();
+			QuadTree(Triangles * t,long nbv=-1);
+			QuadTree();
+			long    NbQuadTreeBox,NbVertices;
+			long    NbQuadTreeBoxSearch,NbVerticesSearch;
+			MeshVertex* NearestVertex(Icoor1 i,Icoor1 j);
+			MeshVertex* NearestVertexWithNormal(Icoor1 i,Icoor1 j);
+			MeshVertex* ToClose(MeshVertex & ,double ,Icoor1,Icoor1);
+			long    SizeOf() const {return sizeof(QuadTree)+sb->SizeOf();}
+			void    Add( MeshVertex & w);
+			QuadTreeBox* NewQuadTreeBox(){
+				if(! (sb->bc<sb->be)) sb=new StorageQuadTreeBox(lenStorageQuadTreeBox,sb);
+				if (!sb || (sb->bc->n != 0)){ISSMERROR("!sb || (sb->bc->n != 0)");}
+				NbQuadTreeBox++;
+				return sb->bc++;
+			}
+	};
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/R2.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/R2.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/R2.h	(revision 3913)
@@ -0,0 +1,104 @@
+/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, R2.h)*/
+#ifndef _R2_H
+#define _R2_H
+
+#include <cstdio>
+
+namespace bamg {
+
+	template <class R,class RR> class P2xP2;
+	template <class R,class RR>
+	  class P2 {
+		  public:  
+			  //fields
+			  R x,y;
+			  //functions
+			  P2 () :x(0),y(0) {};
+			  P2 (R a,R b)  :x(a),y(b)  {}
+			  P2 (P2 A,P2 B) : x(B.x-A.x),y(B.y-A.y) {}
+			  void Echo(){
+				  printf("Member of P2:\n");
+				  printf("   x: %g\n",x);
+				  printf("   y: %g\n",y);
+			  }
+			  //operators
+			  RR       operator,(const P2<R,RR> & cc) const {return  (RR) x* (RR) cc.x+(RR) y* (RR) cc.y;} //scalar product
+			  P2<R,RR> operator+(const P2<R,RR> & cc) const {return P2<R,RR>(x+cc.x,y+cc.y);}
+			  P2<R,RR> operator-(const P2<R,RR> & cc) const {return P2<R,RR>(x-cc.x,y-cc.y);}
+			  P2<R,RR> operator-()  const{return P2<R,RR>(-x,-y);}
+			  P2<R,RR> operator*(R  cc) const {return P2<R,RR>(x*cc,y*cc);}
+			  P2<R,RR> operator/(R  cc) const {return P2<R,RR>(x/cc,y/cc);}
+			  P2<R,RR> operator+=(const  P2<R,RR> & cc) {x += cc.x;y += cc.y;return *this;}
+			  P2<R,RR> operator/=(const  R r) {x /= r;y /= r;return *this;}
+			  P2<R,RR> operator*=(const  R r) {x *= r;y *= r;return *this;}
+			  P2<R,RR> operator-=(const  P2<R,RR> & cc) {x -= cc.x;y -= cc.y;return *this;}
+	  };
+
+	template <class R,class RR>
+	  class P2xP2 {
+		  private:
+			  friend P2<R,RR> operator*(P2<R,RR> c,P2xP2<R,RR> cc){
+				  return P2<R,RR>(c.x*cc.x.x + c.y*cc.y.x, c.x*cc.x.y + c.y*cc.y.y);
+			  } 
+		  public:
+			  //fields
+			  P2<R,RR> x,y; 
+			  //functions
+			  P2xP2 (): x(),y()  {}
+			  P2xP2 (P2<R,RR> a,P2<R,RR> b): x(a),y(b) {}
+			  P2xP2 (P2<R,RR> a,P2<R,RR> b,P2<R,RR> c ): x(b-a),y(c-a) {}
+			  P2xP2 (R xx,R xy,R yx,R yy) :x(xx,xy),y(yx,yy) {}
+			  void Echo(){
+				  printf("Member of P2xP2:\n");
+				  printf("   x.x: %g   x.y: %g\n",x.x,x.y);
+				  printf("   y.x: %g   y.x: %g\n",y.x,y.y);
+			  }
+			  RR          det() const {return (RR) x.x* (RR) y.y - (RR) x.y * (RR) y.x;}
+			  P2xP2<R,RR> inv()  const{
+				  RR d = (*this).det(); 
+				  return P2xP2<R,RR>((R)( y.y /d) ,(R)(-x.y/d),(R)( -y.x/d) ,(R)( x.x/d) );
+			  };
+			  P2xP2<R,RR> t()  {return P2xP2<R,RR>(x.x,y.x,x.y,y.y);} //transposer 
+			  P2<R,RR>    tx() {return P2<R,RR>(x.x,y.x);} 
+			  P2<R,RR>    ty() {return P2<R,RR>(x.y,y.y);} 
+			  //Operators
+			  P2<R,RR>     operator*(const P2<R,RR> c) const {return P2<R,RR>(x.x*c.x + x.y*c.y, y.x*c.x + y.y*c.y);}
+			  P2xP2<R,RR>  operator*(P2xP2<R,RR> c) const{
+				  return  P2xP2<R,RR>(x.x*c.x.x + x.y*c.y.x,
+							  x.x*c.x.y + x.y*c.y.y,
+							  y.x*c.x.x + y.y*c.y.x,
+							  y.x*c.x.y + y.y*c.y.y);
+			  }
+	  };  
+
+	//inline functions
+	template  <class R,class RR>  
+	  inline RR Det(const P2<R,RR> x,const P2<R,RR> y) {
+		  return (RR) x.x * (RR) y.y - (RR) x.y * (RR) y.x ;
+	  } 
+	template  <class R,class RR>  
+	  inline RR Area2 (const P2<R,RR> a,const P2<R,RR> b,const P2<R,RR> c) {
+		  return Det(b-a,c-a) ;
+	  }
+	template  <class R,class RR>  
+	  inline R Norme1 (const P2<R,RR> x) {
+		  return (Abs(x.x)+Abs(x.y)) ;
+	  } 
+	template  <class R,class RR>  
+	  inline R NormeInfini (const P2<R,RR> x) {
+		  return Max(Abs(x.x),Abs(x.y)) ;
+	  }
+	template  <class R,class RR>  
+	  inline RR Norme2_2 (const P2<R,RR> x) {
+		  return (RR)x.x*(RR)x.x + (RR)x.y*(RR)x.y ;
+	  } 
+	template  <class R,class RR>  
+	  inline RR Norme2 (const P2<R,RR> x) {
+		  return sqrt((RR)x.x*(RR)x.x + (RR)x.y*(RR)x.y) ;
+	  } 
+	template  <class R,class RR>  
+	  inline P2<R,RR> Orthogonal (const P2<R,RR> x) {
+		  return  P2<R,RR>(-x.y,x.x);
+	  } 
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/SetOfE4.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/SetOfE4.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/SetOfE4.cpp	(revision 3913)
@@ -0,0 +1,90 @@
+#include "../objects.h"
+
+using namespace std;
+namespace bamg {
+
+	/*Constructor*/
+	/*FUNCTION  SetOfEdges4::SetOfEdges4(long mmx,long nnx){{{1*/
+	SetOfEdges4::SetOfEdges4(long mmx,long nnx){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/SetOfEdges4)*/
+
+		/*Intermediary*/
+		int i;
+
+		//initialize fields
+		nx   =nnx;   //number of vertices
+		nbax =mmx;   // 3 * number of triangles
+		NbOfEdges=0;
+		head = new long [nx];
+		Edges= new IntEdge[nbax];
+
+		//initialize head (-1 everywhere)
+		i=nx;
+		while(i--) head[i]=-1;
+	}
+	/*}}}1*/
+
+	/*Methods*/ 
+	/*FUNCTION  SetOfEdges4::find {{{1*/
+	long SetOfEdges4::find(long ii,long jj) { 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/find)*/
+
+		/*Intermediary*/
+		int n;
+
+		//check that head is not empty
+		ISSMASSERT(head);
+
+		//get n from h (usually h=ii)
+		n=head[Abs(ii)%nx];
+
+		//go through the existing edges that holds h (=ii) and return position in Edge
+		while (n >= 0){
+
+			//if the edge ii jj is already in Edges, return n
+			if (ii == Edges[n].i && jj == Edges[n].j) return n;
+
+			//else go to next edge that holds ii
+			else n = Edges[n].next;
+		}
+
+		//if we reach this point, the edge does not exist return -1
+		return -1;
+	}
+	/*}}}1*/
+	/*FUNCTION  SetOfEdges4::add{{{1*/
+	long SetOfEdges4::add(long ii,long jj) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/add)*/
+
+		/*Intermediary*/
+		int h,n;
+
+		//get n from h (usually h=ii)
+		ISSMASSERT(head);
+		n=head[h=Abs(ii)%nx];
+
+		//go through the existing edges that holds h (=ii) and check that 
+		//the edge ii jj is not already in Edge
+		while (n >= 0){
+
+			//if the edge ii jj is already in Edges, return n
+			if (ii == Edges[n].i && jj == Edges[n].j) return n;
+
+			//else go to next edge that holds ii
+			else n = Edges[n].next;
+		}
+
+		//check that nbax <=NbOfEdges
+		if (nbax <=NbOfEdges ) {
+			ISSMERROR("SetOfEdges4::add overflow: NbOfEdges=%i > nbax=%i",NbOfEdges,nbax);
+		}
+
+		//update chain
+		Edges[NbOfEdges].i=ii;
+		Edges[NbOfEdges].j=jj;
+		Edges[NbOfEdges].next= head[h];
+		head[h] = NbOfEdges;
+		return NbOfEdges ++;
+	}
+	/*}}}1*/
+}
Index: issm/trunk/src/c/objects/Bamg/SetOfE4.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/SetOfE4.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/SetOfE4.h	(revision 3913)
@@ -0,0 +1,42 @@
+#ifndef _SetOfEdge4_h
+#define _SetOfEdge4_h
+
+namespace bamg {
+
+	class SetOfEdges4;
+
+	class IntEdge{
+		friend class SetOfEdges4;
+		public:
+		long i,j;
+		long next; 
+	};
+
+	class SetOfEdges4 {
+
+		private:
+			long nx,nbax,NbOfEdges;
+			long* head; 
+			IntEdge* Edges;
+
+		public:
+
+			// Constructors
+			SetOfEdges4(long ,long);// nb Edges mx , nb de sommet 
+			~SetOfEdges4() {delete [] head; delete [] Edges;}
+
+			//operators
+			IntEdge & operator[](long k){return  Edges[k];}
+
+			//Methods
+			long add (long ii,long jj);
+			long SortAndAdd (long ii,long jj) {return ii <=jj ? add (ii,jj)  : add (jj,ii) ;}
+			long nb(){return NbOfEdges;}
+			long find (long ii,long jj);
+			long SortAndFind (long ii,long jj) {return ii <=jj ? find (ii,jj)  : find (jj,ii) ;}
+			long i(long k){return Edges[k].i;}
+			long j(long k){return Edges[k].j;}
+			long newarete(long k){return NbOfEdges == k+1;}
+	};
+}
+#endif 
Index: issm/trunk/src/c/objects/Bamg/SubDomain.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/SubDomain.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/SubDomain.cpp	(revision 3913)
@@ -0,0 +1,28 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "SubDomain.h"
+#include "Triangles.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION SubDomain::Set {{{1*/
+	void SubDomain::Set(const Triangles & Th ,long i,Triangles & ThNew){
+		*this = Th.subdomains[i];
+		if ( head-Th.triangles<0 || head-Th.triangles>=Th.nbt){
+			ISSMERROR("head-Th.triangles<0 || head-Th.triangles>=Th.nbt");
+		}
+		head = ThNew.triangles + Th.Number(head) ; 
+		if (edge-Th.edges<0 || edge-Th.edges>=Th.nbe);{
+			ISSMERROR("edge-Th.edges<0 || edge-Th.edges>=Th.nbe");
+		}
+		edge = ThNew.edges+ Th.Number(edge);
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/SubDomain.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/SubDomain.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/SubDomain.h	(revision 3913)
@@ -0,0 +1,25 @@
+#ifndef _SUBDOMAIN_H_
+#define _SUBDOMAIN_H_
+
+#include "./include.h"
+#include "./Edge.h"
+
+namespace bamg {
+
+	//classes
+	class Triangle;
+	class Triangles;
+
+	class SubDomain {
+		public:
+			Triangle * head;
+			long  ref;  
+			int sens; // -1 or 1
+			Edge* edge; // to  geometrical 	
+
+			//Methods
+			void Set(const Triangles &,long,Triangles &);
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/Triangle.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Triangle.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Triangle.cpp	(revision 3913)
@@ -0,0 +1,328 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "../objects.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+	/*FUNCTION Triangle(Triangles *Th,long i,long j,long k) {{{1*/
+	Triangle::Triangle(Triangles *Th,long i,long j,long k) {
+		MeshVertex *v=Th->vertices;
+		long nbv = Th->nbv;
+		if (i<0 || j<0 || k<0){
+			ISSMERROR("i<0 || j<0 || k<0");
+		}
+		if (i>=nbv || j>=nbv || k>=nbv){
+			ISSMERROR("i>=nbv || j>=nbv || k>=nbv");
+		}
+		TriaVertices[0]=v+i;
+		TriaVertices[1]=v+j;
+		TriaVertices[2]=v+k;
+		TriaAdjTriangles[0]=TriaAdjTriangles[1]=TriaAdjTriangles[2]=0;
+		TriaAdjSharedEdge[0]=TriaAdjSharedEdge[1]=TriaAdjSharedEdge[2]=0;
+		det=0;
+	}
+	/*}}}*/
+	/*FUNCTION Triangle(MeshVertex *v0,MeshVertex *v1,MeshVertex *v2) {{{1*/
+	Triangle::Triangle(MeshVertex *v0,MeshVertex *v1,MeshVertex *v2){
+		TriaVertices[0]=v0;
+		TriaVertices[1]=v1;
+		TriaVertices[2]=v2;
+		TriaAdjTriangles[0]=TriaAdjTriangles[1]=TriaAdjTriangles[2]=0;
+		TriaAdjSharedEdge[0]=TriaAdjSharedEdge[1]=TriaAdjSharedEdge[2]=0;
+		if (v0) det=0;
+		else {
+			det=-1;
+			link=NULL;};  
+	}
+	/*}}}*/
+
+	/*Methods*/
+	/*FUNCTION Triangle::Echo {{{1*/
+	void Triangle::Echo(void){
+
+		int i;
+
+		printf("Triangle:\n");
+		printf("   TriaVertices pointer towards three vertices\n");
+		printf("      TriaVertices[0] TriaVertices[1] TriaVertices[2] = %p %p %p\n",TriaVertices[0],TriaVertices[1],TriaVertices[2]);
+		printf("   TriaAdjTriangles pointer towards three adjacent triangles\n");
+		printf("      TriaAdjTriangles[0] TriaAdjTriangles[1] TriaAdjTriangles[2] = %p %p %p\n",TriaAdjTriangles[0],TriaAdjTriangles[1],TriaAdjTriangles[2]);
+		printf("   det (integer triangle determinant) = %i\n",det);
+		if (link){
+			printf("   link (pointer toward duplicate triangle)= %p\n",link);
+		}
+		else{
+			printf("   color = %i\n",color);
+		}
+
+		printf("\nThree vertices:\n");
+		for(i=0;i<3;i++){
+			if (TriaVertices[i]){
+				TriaVertices[i]->Echo();
+			}
+			else{
+				printf("   vertex %i does not exist\n",i+1);
+			}
+		}
+
+		return;
+	}
+	/*}}}*/
+	/*FUNCTION Triangle::FindBoundaryEdge{{{1*/
+	TriangleAdjacent Triangle::FindBoundaryEdge(int i) const{
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/FindBoundaryEdge)*/
+
+		/*Intermediary*/
+		Triangle* ttc=NULL;
+		int k,j,jc;
+
+		// call current triangle t
+		Triangle* t = (Triangle*)this;
+
+		//is the current triangle inside or outside?
+		int outside=!link  ;
+
+		// EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
+		// initialize j as the first vertex of the ith edge
+		j=EdgesVertexTriangle[i][0];
+
+		//Loop over the adjacent triangle of t
+		k=0;
+		do{
+			//keep track of outside
+			int outsidep = outside;
+			//increment k
+			k++;
+			//Get ttc, adjacent triangle of t with respect to vertex j
+			ttc =  t->TriaAdjTriangles[j];
+			//is the current triangle inside or outside?
+			outside = !ttc->link;
+			//if both previous triangle are outside, return
+			if (outside+outsidep == 1) return TriangleAdjacent(t,j);
+
+			//update t and j
+			t = ttc;
+			//NextEdge[3] = {1,2,0};
+			jc = NextEdge[t->TriaAdjSharedEdge[j]&3];
+			j = NextEdge[jc];
+
+			//check number of iterations
+			if (k>=2000){
+				ISSMERROR("too many iteration in Triangle::FindBoundaryEdge (k>=2000)");
+			}
+		} while (this!= t);
+		//not found, return empty triangle
+		return TriangleAdjacent(NULL,0);
+	}
+	/*}}}1*/
+	/*FUNCTION Triangle::Optim{{{1*/
+	long  Triangle::Optim(short i,int koption) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Optim)*/
+
+		// turn around (positive direction)
+		Triangle *t=this;
+		long NbSwap =0;
+		int  k = 0;
+		int  j = OppositeEdge[i];
+		int  jp= PreviousEdge[j];
+
+		// initialize tp, jp the previous triangle & edge
+		Triangle *tp=TriaAdjTriangles[jp];
+		jp = TriaAdjSharedEdge[jp]&3;
+		do {
+			while (t->swap(j,koption)){
+				if (k>=20000) ISSMERROR("k>=20000");
+				NbSwap++;
+				k++;
+				t=  tp->TriaAdjTriangles[jp];      // set unchange t qnd j for previous triangles
+				j=  NextEdge[tp->TriaAdjSharedEdge[jp]&3];
+			}
+			// end on this  Triangle 
+			tp = t;
+			jp = NextEdge[j];
+
+			t=  tp->TriaAdjTriangles[jp];      // set unchange t qnd j for previous triangles
+			j=  NextEdge[tp->TriaAdjSharedEdge[jp]&3];
+
+		} while( t != this);
+		return NbSwap;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangle::Quadrangle {{{1*/
+	Triangle* Triangle::Quadrangle(MeshVertex * & v0,MeshVertex * & v1,MeshVertex * & v2,MeshVertex * & v3) const{
+		// return the other triangle of the quad if a quad or 0 if not a quat
+		Triangle * t =0;
+		if (link) {
+			int a=-1;
+			if (TriaAdjSharedEdge[0] & 16 ) a=0;
+			if (TriaAdjSharedEdge[1] & 16 ) a=1;
+			if (TriaAdjSharedEdge[2] & 16 ) a=2;
+			if (a>=0) {
+				t = TriaAdjTriangles[a];
+				//  if (t-this<0) return 0;
+				v2 = TriaVertices[VerticesOfTriangularEdge[a][0]];
+				v0 = TriaVertices[VerticesOfTriangularEdge[a][1]];
+				v1 = TriaVertices[OppositeEdge[a]];
+				v3 = t->TriaVertices[OppositeEdge[TriaAdjSharedEdge[a]&3]];
+			}
+		}
+		return t;
+	}
+	/*}}}*/
+	/*FUNCTION Triangle::QualityQuad {{{1*/
+	double   Triangle::QualityQuad(int a,int option) const{
+		double q;
+		if (!link || TriaAdjSharedEdge[a] &4)
+		 q=  -1;
+		else {
+			Triangle * t = TriaAdjTriangles[a];
+			if (t-this<0) q=  -1;// because we do 2 times 
+			else if (!t->link ) q=  -1;
+			else if (TriaAdjSharedEdge[0] & 16 || TriaAdjSharedEdge[1] & 16  || TriaAdjSharedEdge[2] & 16 || t->TriaAdjSharedEdge[0] & 16 || t->TriaAdjSharedEdge[1] & 16 || t->TriaAdjSharedEdge[2] & 16 )
+			 q= -1;
+			else if(option){ 
+				const MeshVertex & v2 = *TriaVertices[VerticesOfTriangularEdge[a][0]];
+				const MeshVertex & v0 = *TriaVertices[VerticesOfTriangularEdge[a][1]];
+				const MeshVertex & v1 = *TriaVertices[OppositeEdge[a]];
+				const MeshVertex & v3 = * t->TriaVertices[OppositeEdge[TriaAdjSharedEdge[a]&3]];
+				q =  QuadQuality(v0,v1,v2,v3); // do the float part
+			}
+			else q= 1;
+		}
+		return  q;
+	}
+	/*}}}*/
+	/*FUNCTION Triangle::Set {{{1*/
+	void Triangle::Set(const Triangle & rec,const Triangles & Th ,Triangles & ThNew){ 
+		*this = rec;
+		if ( TriaVertices[0] ) TriaVertices[0] = ThNew.vertices +  Th.Number(TriaVertices[0]);
+		if ( TriaVertices[1] ) TriaVertices[1] = ThNew.vertices +  Th.Number(TriaVertices[1]);
+		if ( TriaVertices[2] ) TriaVertices[2] = ThNew.vertices +  Th.Number(TriaVertices[2]);
+		if(TriaAdjTriangles[0]) TriaAdjTriangles[0] =  ThNew.triangles + Th.Number(TriaAdjTriangles[0]);
+		if(TriaAdjTriangles[1]) TriaAdjTriangles[1] =  ThNew.triangles + Th.Number(TriaAdjTriangles[1]);
+		if(TriaAdjTriangles[2]) TriaAdjTriangles[2] =  ThNew.triangles + Th.Number(TriaAdjTriangles[2]);
+		if (link  >= Th.triangles && link  < Th.triangles + Th.nbt)
+		 link = ThNew.triangles + Th.Number(link);
+	}
+	/*}}}*/
+	/*FUNCTION Triangle::swap{{{1*/
+	int Triangle::swap(short a,int koption){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/swap)*/
+
+		if(a/4 !=0) return 0;// arete lock or MarkUnSwap
+
+		register Triangle *t1=this,*t2=TriaAdjTriangles[a];// les 2 triangles adjacent
+		register short a1=a,a2=TriaAdjSharedEdge[a];// les 2 numero de l arete dans les 2 triangles
+		if(a2/4 !=0) return 0; // arete lock or MarkUnSwap
+
+		register MeshVertex  *sa=t1->TriaVertices[VerticesOfTriangularEdge[a1][0]];
+		register MeshVertex  *sb=t1->TriaVertices[VerticesOfTriangularEdge[a1][1]];
+		register MeshVertex  *s1=t1->TriaVertices[OppositeVertex[a1]];
+		register MeshVertex  *s2=t2->TriaVertices[OppositeVertex[a2]];
+
+		Icoor2 det1=t1->det , det2=t2->det ;
+		Icoor2 detT = det1+det2;
+		Icoor2 detA = Abs(det1) + Abs(det2);
+		Icoor2 detMin = Min(det1,det2);
+
+		int OnSwap = 0;       
+		// si 2 triangle infini (bord) => detT = -2;
+		if (sa == 0) {// les deux triangles sont frontieres
+			det2=bamg::det(s2->i,sb->i,s1->i);
+			OnSwap = det2 >0;}
+		else if (sb == 0) { // les deux triangles sont frontieres
+			det1=bamg::det(s1->i,sa->i,s2->i);
+			OnSwap = det1 >0;}
+		else if(( s1 != 0) && (s2 != 0) ) {
+			det1 = bamg::det(s1->i,sa->i,s2->i);
+			det2 = detT - det1;
+			OnSwap = (Abs(det1) + Abs(det2)) < detA;
+
+			Icoor2 detMinNew=Min(det1,det2);
+			//     if (detMin<0 && (Abs(det1) + Abs(det2) == detA)) OnSwap=BinaryRand();// just for test   
+			if (! OnSwap &&(detMinNew>0)) {
+				OnSwap = detMin ==0;
+				if (! OnSwap) {
+					int  kopt = koption;
+					while (1)
+					 if(kopt) {
+						 // critere de Delaunay pure isotrope
+						 register Icoor2 xb1 = sb->i.x - s1->i.x,
+									 x21 = s2->i.x - s1->i.x,
+									 yb1 = sb->i.y - s1->i.y,
+									 y21 = s2->i.y - s1->i.y,
+									 xba = sb->i.x - sa->i.x, 
+									 x2a = s2->i.x - sa->i.x,
+									 yba = sb->i.y - sa->i.y,
+									 y2a = s2->i.y - sa->i.y;
+						 register double
+							cosb12 =  double(xb1*x21 + yb1*y21),
+									 cosba2 =  double(xba*x2a + yba*y2a) ,
+									 sinb12 = double(det2),
+									 sinba2 = double(t2->det);
+
+
+						 // angle b12 > angle ba2 => cotg(angle b12) < cotg(angle ba2)
+						 OnSwap =  ((double) cosb12 * (double)  sinba2) <  ((double) cosba2 * (double) sinb12);
+						 break;
+					 }
+					 else {	
+						 // critere de Delaunay anisotrope 
+						 double som;
+						 I2 AB=(I2) *sb - (I2) *sa;
+						 I2 MAB2=((I2) *sb + (I2) *sa);
+						 R2 MAB(MAB2.x*0.5,MAB2.y*0.5);
+						 I2 A1=(I2) *s1 - (I2) *sa;
+						 I2 D = (I2) * s1 - (I2) * sb ;
+						 R2 S2(s2->i.x,s2->i.y);
+						 R2 S1(s1->i.x,s1->i.y);
+							{
+							 Metric M=s1->m;
+							 R2 ABo = M.Orthogonal(AB);
+							 R2 A1o = M.Orthogonal(A1);
+							 // (A+B)+ x ABo = (S1+B)/2+ y A1 
+							 // ABo x - A1o y =  (S1+B)/2-(A+B)/2 = (S1-B)/2 = D/2
+							 double dd = Abs(ABo.x*A1o.y)+Abs(ABo.y*A1o.x);
+							 double d = (ABo.x*A1o.y - ABo.y*A1o.x)*2; // because D/2
+							 if (Abs(d) > dd*1.e-3) {
+								 R2 C(MAB+ABo*((D.x*A1o.y - D.y*A1o.x)/d));
+								 som  = M(C - S2)/M(C - S1);
+							 } else 
+								{kopt=1;continue;}
+
+							}
+							{
+							 Metric M=s2->m;
+							 R2 ABo = M.Orthogonal(AB);
+							 R2 A1o = M.Orthogonal(A1);
+							 // (A+B)+ x ABo = (S1+B)/2+ y A1 
+							 // ABo x - A1o y =  (S1+B)/2-(A+B)/2 = (S1-B)/2 = D/2 
+							 double dd = Abs(ABo.x*A1o.y)+Abs(ABo.y*A1o.x);
+							 double d = (ABo.x*A1o.y - ABo.y*A1o.x)*2; // because D/2
+							 if(Abs(d) > dd*1.e-3) {
+								 R2 C(MAB+ABo*((D.x*A1o.y - D.y*A1o.x)/d));
+								 som  += M(C - S2)/M(C -  S1);
+							 } else 
+								{kopt=1;continue;}
+							}
+						 OnSwap = som < 2;
+						 break;
+					 }
+
+				} // OnSwap 
+			} // (! OnSwap &&(det1 > 0) && (det2 > 0) )
+		}
+		if( OnSwap ) 
+		 bamg::swap(t1,a1,t2,a2,s1,s2,det1,det2);
+		else {
+			t1->SetMarkUnSwap(a1);     
+		}
+		return OnSwap;
+	}
+	/*}}}1*/
+
+}
Index: issm/trunk/src/c/objects/Bamg/Triangle.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Triangle.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Triangle.h	(revision 3913)
@@ -0,0 +1,125 @@
+#ifndef _TRIANGLE_H_
+#define _TRIANGLE_H_
+
+#include "./include.h"
+#include "TriangleAdjacent.h"
+
+namespace bamg {
+
+	//classes
+	class Triangles;
+	class MeshVertex;
+	class Triangle;
+
+	class Triangle {
+
+		friend class TriangleAdjacent;
+
+		private:
+			MeshVertex*   TriaVertices[3];      // 3 vertices if t is triangle, t[i] allowed by access function, (*t)[i] if pointer
+			Triangle* TriaAdjTriangles[3];  // 3 pointers toward the adjacent triangles
+			short     TriaAdjSharedEdge[3]; // number of the edges in the adjacent triangles the edge number 1 is the edge number TriaAdjSharedEdge[1] in the Adjacent triangle 1
+
+		public: 
+			Icoor2 det; // determinant du triangle (2 fois l aire des vertices entieres)
+			union { 
+				Triangle * link ;
+				long color;
+			};
+
+			//Constructors/Destructors
+			Triangle() {}
+			Triangle(Triangles *Th,long i,long j,long k);
+			Triangle(MeshVertex *v0,MeshVertex *v1,MeshVertex *v2);
+
+			//Operators
+			const MeshVertex & operator[](int i) const {return *TriaVertices[i];};
+			MeshVertex & operator[](int i)  {return *TriaVertices[i];};
+			const MeshVertex * operator()(int i) const {return TriaVertices[i];};
+			MeshVertex * & operator()(int i)  {return TriaVertices[i];};
+
+			//Methods
+			void   Echo();
+			int    swap(short a1,int=0);
+			long   Optim(short a,int =0);
+			int    Locked(int a)const { return TriaAdjSharedEdge[a]&4;} 
+			int    Hidden(int a)const { return TriaAdjSharedEdge[a]&16;} 
+			int    GetAllflag(int a){return TriaAdjSharedEdge[a] & 1020;}
+			void   SetAllFlag(int a,int f){TriaAdjSharedEdge[a] = (TriaAdjSharedEdge[a] &3) + (1020 & f);}
+			double QualityQuad(int a,int option=1) const;
+			short  NuEdgeTriangleAdj(int i) const {return TriaAdjSharedEdge[i&3]&3;} // Number of the  adjacent edge in adj tria  
+			TriangleAdjacent FindBoundaryEdge(int i) const;
+			TriangleAdjacent Adj(int i)  const {return TriangleAdjacent(TriaAdjTriangles[i],TriaAdjSharedEdge[i]&3);};
+			Triangle* TriangleAdj(int i) const {return TriaAdjTriangles[i&3];}
+			Triangle* Quadrangle(MeshVertex * & v0,MeshVertex * & v1,MeshVertex * & v2,MeshVertex * & v3) const ;
+			void  ReNumbering(Triangle *tb,Triangle *te, long *renu){
+				if (link  >=tb && link  <te) link  = tb + renu[link -tb];
+				if (TriaAdjTriangles[0] >=tb && TriaAdjTriangles[0] <te) TriaAdjTriangles[0] = tb + renu[TriaAdjTriangles[0]-tb];
+				if (TriaAdjTriangles[1] >=tb && TriaAdjTriangles[1] <te) TriaAdjTriangles[1] = tb + renu[TriaAdjTriangles[1]-tb];
+				if (TriaAdjTriangles[2] >=tb && TriaAdjTriangles[2] <te) TriaAdjTriangles[2] = tb + renu[TriaAdjTriangles[2]-tb];    
+			}
+			void ReNumbering(MeshVertex *vb,MeshVertex *ve, long *renu){
+				if (TriaVertices[0] >=vb && TriaVertices[0] <ve) TriaVertices[0] = vb + renu[TriaVertices[0]-vb];
+				if (TriaVertices[1] >=vb && TriaVertices[1] <ve) TriaVertices[1] = vb + renu[TriaVertices[1]-vb];
+				if (TriaVertices[2] >=vb && TriaVertices[2] <ve) TriaVertices[2] = vb + renu[TriaVertices[2]-vb];    
+			}
+			void SetAdjAdj(short a){
+				a &= 3;
+				register Triangle *tt=TriaAdjTriangles[a];
+				TriaAdjSharedEdge [a] &= 55; // remove MarkUnSwap
+				register short aatt = TriaAdjSharedEdge[a] & 3;
+				if(tt){ 
+					tt->TriaAdjTriangles[aatt]=this;
+					tt->TriaAdjSharedEdge[aatt]=a + (TriaAdjSharedEdge[a] & 60 ) ;}// Copy all the mark 
+			  }
+			void SetAdj2(short a,Triangle *t,short aat){
+				TriaAdjTriangles[a]=t;    //the adjacent triangle to the edge a is t
+				TriaAdjSharedEdge[a]=aat; //position of the edge in the adjacent triangle
+				if(t) { //if t!=NULL add adjacent triangle to t (this)
+					t->TriaAdjTriangles[aat]=this;
+					t->TriaAdjSharedEdge[aat]=a;
+				}
+			}
+			void SetTriangleContainingTheVertex() { 
+				if (TriaVertices[0]) (TriaVertices[0]->t=this,TriaVertices[0]->vint=0);
+				if (TriaVertices[1]) (TriaVertices[1]->t=this,TriaVertices[1]->vint=1);
+				if (TriaVertices[2]) (TriaVertices[2]->t=this,TriaVertices[2]->vint=2);
+			}
+			void SetHidden(int a){
+				//Get Adjacent Triangle number a
+				register Triangle* t = TriaAdjTriangles[a];
+				//if it exist
+				//C|=D -> C=(C|D) bitwise inclusive OR
+				if(t) t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=16;
+				TriaAdjSharedEdge[a] |= 16;
+			}
+
+			void SetLocked(int a){
+				//mark the edge as on Boundary
+				register Triangle * t = TriaAdjTriangles[a];
+				t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=4;
+				TriaAdjSharedEdge[a] |= 4;
+			}
+			void SetMarkUnSwap(int a){
+				register Triangle * t = TriaAdjTriangles[a];
+				t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=8;
+				TriaAdjSharedEdge[a] |=8 ;
+			}
+			void SetUnMarkUnSwap(int a){ 
+				register Triangle * t = TriaAdjTriangles[a];
+				t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] &=55; // 23 + 32 
+				TriaAdjSharedEdge[a] &=55 ;
+			}
+			void SetDet() {
+				if(TriaVertices[0] && TriaVertices[1] && TriaVertices[2])    det = bamg::det(*TriaVertices[0],*TriaVertices[1],*TriaVertices[2]);
+				else det = -1; }
+
+			//Inline methods
+			double qualite() ;
+			void  Set(const Triangle &,const Triangles &,Triangles &);
+			int   In(MeshVertex *v) const { return TriaVertices[0]==v || TriaVertices[1]==v || TriaVertices[2]==v ;}
+
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/TriangleAdjacent.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/TriangleAdjacent.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/TriangleAdjacent.cpp	(revision 3913)
@@ -0,0 +1,76 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "TriangleAdjacent.h"
+#include "Triangles.h"
+
+namespace bamg {
+
+
+	/*Constructors/Destructors*/
+	//See header file
+
+	/*Methods*/
+	/*FUNCTION TriangleAdjacent::Locked {{{1*/
+	int  TriangleAdjacent::Locked() const {
+		return t->TriaAdjSharedEdge[a] & 4;
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::MarkUnSwap {{{1*/
+	int  TriangleAdjacent::MarkUnSwap() const {
+		return t->TriaAdjSharedEdge[a] & 8;
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::GetAllFlag_UnSwap {{{1*/
+	int  TriangleAdjacent::GetAllFlag_UnSwap() const {
+		// take all flag except MarkUnSwap
+		return t->TriaAdjSharedEdge[a] & 1012;
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::SetLock {{{1*/
+	void TriangleAdjacent::SetLock(){
+		t->SetLocked(a);
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::Adj {{{1*/
+	TriangleAdjacent TriangleAdjacent::Adj() const {
+		return  t->Adj(a);
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::EdgeVertex {{{1*/
+	MeshVertex* TriangleAdjacent::EdgeVertex(const int & i) const {
+		return t->TriaVertices[VerticesOfTriangularEdge[a][i]];
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::OppositeVertex {{{1*/
+	MeshVertex* TriangleAdjacent::OppositeVertex() const {
+		return t->TriaVertices[bamg::OppositeVertex[a]]; 
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::det {{{1*/
+	Icoor2 & TriangleAdjacent::det() const {
+		return t->det;
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::swap {{{1*/
+	int TriangleAdjacent::swap(){
+		return  t->swap(a);
+	}
+	/*}}}*/
+	/*FUNCTION TriangleAdjacent::SetAdj2 {{{1*/
+	void TriangleAdjacent::SetAdj2(const TriangleAdjacent & ta, int l  ){
+		//set Adjacent Triangle of a triangle
+		if(t) {
+			t->TriaAdjTriangles[a]=ta.t;
+			t->TriaAdjSharedEdge[a]=ta.a|l;
+		}
+		if(ta.t) {
+			ta.t->TriaAdjTriangles[ta.a] = t ;
+			ta.t->TriaAdjSharedEdge[ta.a] = a| l ;
+		}
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/TriangleAdjacent.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/TriangleAdjacent.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/TriangleAdjacent.h	(revision 3913)
@@ -0,0 +1,46 @@
+#ifndef _TRIANGLEADJACENT_H_
+#define _TRIANGLEADJACENT_H_
+
+#include "./include.h"
+#include "./MeshVertex.h"
+
+namespace bamg {
+
+	//classes
+	class Triangle;
+	class Triangle;
+
+	class TriangleAdjacent {
+
+		public:
+			Triangle* t; //pointer toward the triangle
+			int  a;      //Edge number
+
+			//Constructors
+			TriangleAdjacent() {};
+			TriangleAdjacent(Triangle* tt,int  aa): t(tt),a(aa &3) {};
+
+			//Operators
+			operator Triangle * () const {return t;}
+			operator Triangle & () const {return *t;}
+			operator int() const {return a;}
+			TriangleAdjacent & operator++(){ a= NextEdge[a]; return *this; }
+			TriangleAdjacent operator--(){ a= PreviousEdge[a]; return *this; }
+
+			//Methods
+
+			//Methods
+			int  Locked() const;
+			int  MarkUnSwap() const;
+			int  GetAllFlag_UnSwap() const;
+			void SetLock();
+			void SetAdj2(const TriangleAdjacent &ta, int l=0);
+			int  swap();
+			TriangleAdjacent Adj() const;
+			MeshVertex* EdgeVertex(const int & i) const;
+			MeshVertex* OppositeVertex() const;
+			Icoor2& det() const;
+	};
+}
+#endif
+
Index: issm/trunk/src/c/objects/Bamg/Triangles.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/Triangles.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Triangles.cpp	(revision 3913)
@@ -0,0 +1,5851 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "../objects.h"
+
+namespace bamg {
+
+	static const  Direction NoDirOfSearch=Direction();
+	long NbUnSwap =0;
+
+	/*Constructors/Destructors*/
+	/*FUNCTION Triangles::Triangles(BamgGeom* bamggeom,BamgMesh* bamgmesh, BamgOpts* bamgopts){{{1*/
+	Triangles::Triangles(BamgGeom* bamggeom,BamgMesh* bamgmesh, BamgOpts* bamgopts):Gh(*(new Geometry())),BTh(*this){ 
+
+		/*Initialize fields*/
+		PreInit(0);
+
+		/*Read Geometry if provided*/
+		if(bamggeom->Edges) {
+			Gh.ReadGeometry(bamggeom,bamgopts);
+			Gh.AfterRead();
+		}
+
+		/*Read background mesh*/
+		ReadMesh(bamgmesh,bamgopts);
+
+		/*Build Geometry if not provided*/
+		if(bamggeom->Edges==NULL) {
+			/*Recreate geometry if needed*/
+			printf("WARNING: mesh present but no geometry found. Reconstructing...\n");
+			BuildGeometryFromMesh(bamgopts);
+			Gh.AfterRead();
+		}
+
+		/*Set integer coordinates*/
+		SetIntCoor();
+
+		/*Fill holes and generate mesh properties*/
+		ReconstructExistingMesh();
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::Triangles(double* index,double* x,double* y,int nods,int nels){{{1*/
+	Triangles::Triangles(double* index,double* x,double* y,int nods,int nels):Gh(*(new Geometry())),BTh(*this){
+
+		PreInit(0);
+		ReadMesh(index,x,y,nods,nels);
+		SetIntCoor();
+		ReconstructExistingMesh();
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::Triangles(const Triangles & Tho,const int *flag ,const int *bb){{{1*/
+	Triangles::Triangles(const Triangles & Tho,const int *flag ,const int *bb,BamgOpts* bamgopts) : Gh(*(new Geometry())), BTh(*this) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Triangles)*/
+
+		  int i,k,itadj;
+		  int kt=0;
+		  int * kk    = new int [Tho.nbv];
+		  long * reft = new long[Tho.nbt];
+		  long nbInT =    Tho.TriangleReferenceList(reft);
+		  long * refv = new long[Tho.nbv];
+
+		  for (i=0;i<Tho.nbv;i++)
+			kk[i]=-1;
+		  for (i=0;i<Tho.nbv;i++)
+			refv[i]=0;
+		  int nbNewBedge =0;
+		  //  int nbOldBedge =0;  
+		  for (i=0;i<Tho.nbt;i++)
+			if(  reft[i] >=0 && flag[i]) 
+			  {
+				const Triangle & t = Tho.triangles[i];
+				kt++;
+				kk[Tho.Number(t[0])]=1;
+				kk[Tho.Number(t[1])]=1;
+				kk[Tho.Number(t[2])]=1;
+				itadj=Tho.Number(t.TriangleAdj(0));
+				if (  reft[itadj] >=0 && !flag[itadj])
+				  { nbNewBedge++;
+					refv[Tho.Number(t[VerticesOfTriangularEdge[0][0]])]=bb[i];
+					refv[Tho.Number(t[VerticesOfTriangularEdge[0][1]])]=bb[i];
+				  }
+				itadj=Tho.Number(t.TriangleAdj(1));
+				if (  reft[itadj] >=0 && !flag[itadj])
+				  { nbNewBedge++;
+					refv[Tho.Number(t[VerticesOfTriangularEdge[1][0]])]=bb[i];
+					refv[Tho.Number(t[VerticesOfTriangularEdge[1][1]])]=bb[i];}
+					itadj=Tho.Number(t.TriangleAdj(2));
+					if (  reft[itadj] >=0 && !flag[itadj])
+					  { nbNewBedge++;
+						refv[Tho.Number(t[VerticesOfTriangularEdge[2][0]])]=bb[i];
+						refv[Tho.Number(t[VerticesOfTriangularEdge[2][1]])]=bb[i];}
+			  }
+		  k=0;
+		  for (i=0;i<Tho.nbv;i++){
+			  if (kk[i]>=0) kk[i]=k++;
+			}
+		  printf("   number of vertices %i, remove = %i\n",k,Tho.nbv - k);
+		  printf("   number of triangles %i, remove = \n",kt,nbInT-kt);
+		  printf("   number of New boundary edge %i\n",nbNewBedge);
+		  long inbvx =k;
+		  PreInit(inbvx);
+		  for (i=0;i<Tho.nbv;i++)
+			if (kk[i]>=0) 
+			  {
+				vertices[nbv] = Tho.vertices[i];
+				if (!vertices[nbv].ref())
+				 vertices[nbv].ReferenceNumber = refv[i];
+				nbv++;
+			  }
+		  if (inbvx != nbv){
+			  ISSMERROR("inbvx != nbv");
+		  }
+		  for (i=0;i<Tho.nbt;i++)
+			if(  reft[i] >=0 && flag[i]) 
+			  {
+				const Triangle & t = Tho.triangles[i];
+				int i0 = Tho.Number(t[0]);
+				int i1 = Tho.Number(t[1]);
+				int i2 = Tho.Number(t[2]);
+				if (i0<0 || i1<0 || i2<0){
+					ISSMERROR("i0<0 || i1<0 || i2< 0");
+				}
+				if (i0>=Tho.nbv || i1>=Tho.nbv || i2>=Tho.nbv){
+					ISSMERROR("i0>=Tho.nbv || i1>=Tho.nbv || i2>=Tho.nbv");
+				}
+				triangles[nbt] = Triangle(this,kk[i0],kk[i1],kk[i2]);
+				triangles[nbt].color = Tho.subdomains[reft[i]].ref; 
+				nbt++;           
+			  }
+		  if (kt!=nbt){
+			  ISSMERROR("kt!=nbt");
+		  }
+		  if (nbt==0 && nbv==0) {
+			  ISSMERROR("All triangles have been removed");
+		  }
+		  delete [] kk;
+		  delete [] reft;
+		  delete [] refv;
+		  //double cutoffradian = 10.0/180.0*Pi;
+		  BuildGeometryFromMesh(bamgopts);
+		  Gh.AfterRead(); 
+		  SetIntCoor();
+		  ReconstructExistingMesh();
+
+		  if (!NbSubDomains){
+			  ISSMERROR("NbSubDomains==0");
+		  }
+		  if (!subdomains[0].head || !subdomains[0].head->link){
+			  ISSMERROR("!subdomains[0].head || !subdomains[0].head->link");
+		  }
+
+	  }
+	/*}}}1*/
+	/*FUNCTION Triangles::Triangles(Triangles & Th,Geometry * pGh,Triangles * pBth,long nbvxx) COPY{{{1*/
+	Triangles::Triangles(Triangles & Th,Geometry * pGh,Triangles * pBth,long nbvxx)
+	  : Gh(*(pGh?pGh:&Th.Gh)), BTh(*(pBth?pBth:this)) {
+		  /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Triangles)*/
+		  Gh.NbRef++;
+		  nbvxx = Max(nbvxx,Th.nbv); 
+		  long i;
+		  // do all the allocation to be sure all the pointer existe
+
+		  PreInit(nbvxx);// to make the allocation 
+		  // copy of triangles
+		  nt=Th.nt;
+		  nbv = Th.nbv;
+		  nbt = Th.nbt;
+		  nbiv = Th.nbiv;
+		  nbe = Th.nbe;
+		  NbSubDomains = Th.NbSubDomains;
+		  NbOutT = Th.NbOutT;
+		  NbOfQuad =  Th.NbOfQuad ;
+		  NbOfSwapTriangle =0;
+		  NbVerticesOnGeomVertex = Th.NbVerticesOnGeomVertex;
+		  if(NbVerticesOnGeomVertex)
+			VerticesOnGeomVertex = new VertexOnGeom[NbVerticesOnGeomVertex];
+		  NbVerticesOnGeomEdge = Th.NbVerticesOnGeomEdge;
+		  if (NbVerticesOnGeomEdge)
+			VerticesOnGeomEdge = new VertexOnGeom[NbVerticesOnGeomEdge] ;
+		  if (& BTh == & Th.BTh){ // same background 
+			  BTh.NbRef++;
+			  NbVertexOnBThVertex = Th.NbVertexOnBThVertex;
+			  if(NbVertexOnBThVertex)
+				VertexOnBThVertex = new VertexOnVertex[NbVertexOnBThVertex];
+			  NbVertexOnBThEdge = Th.NbVertexOnBThEdge;
+			  if(NbVertexOnBThEdge)
+				VertexOnBThEdge = new VertexOnEdge[NbVertexOnBThEdge];
+			 }
+		  else { // no add on background mesh 
+			  BTh.NbRef++;
+			  NbVertexOnBThVertex=0;
+			  VertexOnBThVertex=0;
+			  NbVertexOnBThEdge=0;
+			  VertexOnBThEdge=0;
+			 }
+
+
+		  if(nbe)
+			edges = new Edge[nbe];
+		  if(NbSubDomains)
+			subdomains = new SubDomain[NbSubDomains];
+		  pmin = Th.pmin;
+		  pmax = Th.pmax;
+		  coefIcoor = Th.coefIcoor;
+		  for(i=0;i<nbt;i++)
+			triangles[i].Set(Th.triangles[i],Th,*this);
+		  for(i=0;i<nbe;i++)
+			edges[i].Set(Th,i,*this);
+		  for(i=0;i<nbv;i++)
+			vertices[i].Set(Th.vertices[i],Th,*this);
+		  for(i=0;i<NbSubDomains;i++)  
+			subdomains[i].Set(Th,i,*this);
+		  for (i=0;i<NbVerticesOnGeomVertex;i++)
+			VerticesOnGeomVertex[i].Set(Th.VerticesOnGeomVertex[i],Th,*this);
+		  for (i=0;i<NbVerticesOnGeomEdge;i++)
+			VerticesOnGeomEdge[i].Set(Th.VerticesOnGeomEdge[i],Th,*this);
+		  quadtree=0;
+
+	  }
+	/*}}}1*/
+	/*FUNCTION Triangles::~Triangles(){{{1*/
+	Triangles::~Triangles() {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Triangles)*/
+
+		long int verbosity=2;
+		//if(vertices)  delete [] vertices; //TEST  crash if not commented
+		if(edges)     delete [] edges;
+		if(triangles) delete [] triangles;
+		if(quadtree)  delete quadtree;
+		//if(ordre)     delete [] ordre; //TEST  crash if not commented
+		if( subdomains) delete []  subdomains;
+		if (VerticesOnGeomEdge) delete [] VerticesOnGeomEdge;
+		if (VerticesOnGeomVertex) delete [] VerticesOnGeomVertex;
+		if (VertexOnBThVertex) delete [] VertexOnBThVertex;
+		if (VertexOnBThEdge) delete [] VertexOnBThEdge;
+
+		if (&Gh) {
+			if (Gh.NbRef>0) Gh.NbRef--;
+			else if (Gh.NbRef==0) delete &Gh;
+		}
+		if (&BTh && (&BTh != this)) {
+			if (BTh.NbRef>0) BTh.NbRef--;
+			else if (BTh.NbRef==0) delete &BTh;
+		}
+		PreInit(0); // set all to zero 
+	}
+	/*}}}1*/
+
+	/*IO*/
+	/*FUNCTION Triangles::ReadMesh(double* index,double* x,double* y,int nods,int nels){{{1*/
+	void Triangles::ReadMesh(double* index,double* x,double* y,int nods,int nels){
+
+		double Hmin = HUGE_VAL;// the infinie value 
+		long i1,i2,i3,iref;
+		long i,j;
+		Metric M1(1);
+		int verbose=0;
+
+		nbv=nods;
+		nbvx=nbv;
+		nbt=nels;
+		nbiv=nbvx;
+
+		//Vertices
+		if (verbose) printf("Reading vertices (%i)\n",nbv);
+		vertices=(MeshVertex*)xmalloc(nbv*sizeof(MeshVertex));
+		ordre=(MeshVertex**)xmalloc(nbv*sizeof(MeshVertex*));
+		for (i=0;i<nbv;i++){
+			vertices[i].r.x=x[i];
+			vertices[i].r.y=y[i];
+			vertices[i].ReferenceNumber=1;
+			vertices[i].DirOfSearch =NoDirOfSearch;
+			vertices[i].m=M1;
+			vertices[i].color=0;
+		}
+		nbtx=2*nbvx-2; // for filling The Holes and quadrilaterals 
+
+		//Triangles
+		if (verbose) printf("Reading triangles (%i)\n",nbt);
+		triangles =new Triangle[nbtx]; //we cannot allocate only nbt triangles since 
+		//other triangles will be added for each edge
+		for (i=0;i<nbt;i++){
+			Triangle & t = triangles[i];
+			i1=(long)index[i*3+0]-1; //for C indexing
+			i2=(long)index[i*3+1]-1; //for C indexing
+			i3=(long)index[i*3+2]-1; //for C indexing
+			t=Triangle(this,i1,i2,i3);
+			t.color=1;
+		}
+
+		/*Recreate geometry: */
+		if (verbose) printf("Building Geometry\n");
+		BuildGeometryFromMesh();
+		if (verbose) printf("Completing geometry\n");
+		Gh.AfterRead();
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts){{{1*/
+	void Triangles::ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts){
+
+		int verbose;
+		double Hmin = HUGE_VAL;// the infinie value 
+		long i1,i2,i3,iref;
+		long i,j;
+		long ifgeom=0;
+		Metric M1(1);
+
+		verbose=bamgopts->verbose;
+
+		nbv=bamgmesh->VerticesSize[0];
+		nbvx=nbv;
+		nbt=bamgmesh->TrianglesSize[0];
+		nbiv=nbvx;
+
+		//Vertices
+		if(bamgmesh->Vertices){
+			if(verbose>5) printf("      processing Vertices\n");
+
+			vertices=(MeshVertex*)xmalloc(nbv*sizeof(MeshVertex));
+			ordre=(MeshVertex**)xmalloc(nbv*sizeof(MeshVertex*));
+
+			for (i=0;i<nbv;i++){
+				vertices[i].r.x=bamgmesh->Vertices[i*3+0];
+				vertices[i].r.y=bamgmesh->Vertices[i*3+1];
+				vertices[i].ReferenceNumber=(long)bamgmesh->Vertices[i*3+2];
+				vertices[i].DirOfSearch =NoDirOfSearch;
+				vertices[i].m=M1;
+				vertices[i].color=0;
+			}
+			nbtx=2*nbvx-2; // for filling The Holes and quadrilaterals 
+		}
+		else{
+			if(verbose>5) ISSMERROR("no Vertices found in the initial mesh");
+		}
+
+		//Triangles
+		if(bamgmesh->Triangles){
+			if(verbose>5) printf("      processing Triangles\n");
+			triangles =new Triangle[nbtx]; //we cannot allocate only nbt triangles since 
+			//other triangles will be added for each edge
+			for (i=0;i<nbt;i++){
+				Triangle & t = triangles[i];
+				i1=(long)bamgmesh->Triangles[i*4+0]-1; //for C indexing
+				i2=(long)bamgmesh->Triangles[i*4+1]-1; //for C indexing
+				i3=(long)bamgmesh->Triangles[i*4+2]-1; //for C indexing
+				t=Triangle(this,i1,i2,i3);
+				t.color=(long)bamgmesh->Triangles[i*4+3];
+			}
+		}
+		else{
+			if(verbose>5) ISSMERROR("no Triangles found in the initial mesh");
+		}
+
+		//Quadrilaterals
+		if(bamgmesh->Quadrilaterals){
+			if(verbose>5) printf("      processing Quadrilaterals\n");
+			long i1,i2,i3,i4,iref;
+			triangles =new Triangle[nbt];
+			for (i=0;i<bamgmesh->QuadrilateralsSize[0];i++){
+				//divide the quad into two triangles
+				Triangle & t1 = triangles[2*i];
+				Triangle & t2 = triangles[2*i+1];
+				i1=(long)bamgmesh->Quadrilaterals[i*5+0]-1; //for C indexing
+				i2=(long)bamgmesh->Quadrilaterals[i*5+1]-1; //for C indexing
+				i3=(long)bamgmesh->Quadrilaterals[i*5+2]-1; //for C indexing
+				i4=(long)bamgmesh->Quadrilaterals[i*5+3]-1; //for C indexing
+				t1=Triangle(this,i1,i2,i3);
+				t2=Triangle(this,i3,i4,i1);
+				t1.color=(long)bamgmesh->Quadrilaterals[i*5+4];
+				t2.color=(long)bamgmesh->Quadrilaterals[i*5+4];
+				t1.SetHidden(OppositeEdge[1]); // two times  because the adj was not created 
+				t2.SetHidden(OppositeEdge[1]); 
+			}
+		}
+
+		//VerticesOnGeometricEdge
+		if(bamgmesh->VerticesOnGeometricEdge){
+			if(verbose>5) printf("      processing VerticesOnGeometricEdge\n");
+			NbVerticesOnGeomEdge=bamgmesh->VerticesOnGeometricEdgeSize[0];
+			VerticesOnGeomEdge= new  VertexOnGeom[NbVerticesOnGeomEdge] ;
+			for (i=0;i<NbVerticesOnGeomEdge;i++){
+				long  i1,i2;
+				double s;
+				i1=(long)  bamgmesh->VerticesOnGeometricEdge[i*3+0]-1; //for C indexing
+				i2=(long)  bamgmesh->VerticesOnGeometricEdge[i*3+1]-1; //for C indexing
+				s =(double)bamgmesh->VerticesOnGeometricEdge[i*3+2];
+				VerticesOnGeomEdge[i]=VertexOnGeom(vertices[i1],Gh.edges[i2],s);
+			}
+		}
+
+		//VerticesOnGeometricVertex
+		if(bamgmesh->VerticesOnGeometricVertexSize[0]){
+			if(verbose>5) printf("      processing VerticesOnGeometricVertex\n");
+			NbVerticesOnGeomVertex=bamgmesh->VerticesOnGeometricVertexSize[0];
+			VerticesOnGeomVertex  = new  VertexOnGeom[NbVerticesOnGeomVertex] ;
+			for (i=0;i<NbVerticesOnGeomVertex;i++){
+				long  i1,i2;
+				i1=(long)bamgmesh->VerticesOnGeometricVertex[i*2+0]-1; //for C indexing
+				i2=(long)bamgmesh->VerticesOnGeometricVertex[i*2+1]-1; //for C indexing
+				VerticesOnGeomVertex[i]=VertexOnGeom(vertices[i1],Gh.vertices[i2]);
+			}
+		}
+
+		//Edges
+		if (bamgmesh->Edges){
+			int i1,i2;
+			double* len=NULL;
+
+			if(verbose>5) printf("      processing Edges\n");
+			nbe=bamgmesh->EdgesSize[0];
+			edges= new Edge[nbe];
+			//initialize length of each edge (used to provided metric)
+			len= new double[nbv];
+			for(i=0;i<nbv;i++) len[i]=0;
+
+			for (i=0;i<nbe;i++){
+				i1=(int)bamgmesh->Edges[i*3+0]-1; //-1 for C indexing
+				i2=(int)bamgmesh->Edges[i*3+1]-1; //-1 for C indexing
+				edges[i].ref=(long)bamgmesh->Edges[i*3+2];
+				edges[i].v[0]= vertices +i1;
+				edges[i].v[1]= vertices +i2;
+				edges[i].adj[0]=NULL;
+				edges[i].adj[1]=NULL;
+				R2 x12=vertices[i2].r-vertices[i1].r;
+				double l12=sqrt((x12,x12));
+
+				//prepare metric
+				vertices[i1].color++;
+				vertices[i2].color++;
+				len[i1]+=l12;
+				len[i2]+=l12;
+				Hmin = Min(Hmin,l12);
+			}
+
+			// definition  the default of the given mesh size 
+			for (i=0;i<nbv;i++){
+				if (vertices[i].color>0) 
+				 vertices[i].m=Metric(len[i]/(double)vertices[i].color);
+				else 
+				 vertices[i].m=Metric(Hmin);
+			}
+			delete [] len;
+
+			// construction of edges[].adj 
+			for (i=0;i<nbv;i++){ 
+				vertices[i].color=(vertices[i].color ==2) ?-1:-2;
+			}
+			for (i=0;i<nbe;i++){
+				for (j=0;j<2;j++) { 
+					MeshVertex *v=edges[i].v[j];
+					long i0=v->color,j0;
+					if(i0==-1){
+						v->color=i*2+j;
+					}
+					else if (i0>=0) {// i and i0 edge are adjacent by the vertex v
+						j0 = i0%2;
+						i0 = i0/2;
+						ISSMASSERT(v==edges[i0 ].v[j0]);
+						edges[i ].adj[j ] =edges +i0;
+						edges[i0].adj[j0] =edges +i ;
+						v->color = -3;
+					}
+				}
+			}
+		}
+
+		//EdgeOnGeometricEdge
+		if(bamgmesh->EdgesOnGeometricEdge){
+			if(verbose>5) printf("      processing EdgesOnGeometricEdge\n");
+			int i1,i2,i,j;
+			i2=bamgmesh->EdgesOnGeometricEdgeSize[0];
+			for (i1=0;i1<i2;i1++) {
+				i=(int)bamgmesh->EdgesOnGeometricEdge[i1*2+0]-1; //C indexing
+				j=(int)bamgmesh->EdgesOnGeometricEdge[i1*2+1]-1; //C indexing
+				//Check value
+				if(!(i>=0 && j>=0 && i<nbe && j<Gh.nbe)) {
+					ISSMERROR("ReadMesh error: EdgesOnGeometricEdge edge provided (line %i: [%i %i]) is incorrect (must be positive, [0<i<nbe=%i 0<j<Gh.nbe=%i]",i1+1,i+1,j+1,nbe,Gh.nbe);
+				}
+				edges[i].onGeometry=Gh.edges+j;
+			}
+		}
+
+		//hVertices
+		if(bamgmesh->hVertices){
+			if(verbose>5) printf("      processing hVertices\n");
+			for (i=0;i< nbv;i++){
+				if (!isnan(bamgmesh->hVertices[i])){
+					vertices[i].m=Metric((double)bamgmesh->hVertices[i]);
+				}
+			}
+		}
+
+		//SubDomain
+		if(bamgmesh->SubDomains){
+			long i3,head,sens;
+			if(verbose>5) printf("      processing SubDomains\n");
+			NbSubDomains=bamgmesh->SubDomainsSize[0];
+			subdomains = new SubDomain [ NbSubDomains ];
+			for (i=0;i<NbSubDomains;i++) {
+				i3  =(int)bamgmesh->SubDomains[i*3+0];
+				head=(int)bamgmesh->SubDomains[i*3+1]-1;//C indexing
+				sens=(int)bamgmesh->SubDomains[i*3+2];
+				if (i3!=23) ISSMERROR("Bad Subdomain definition: first number should be 3");
+				if (head<0 || head>=nbt) ISSMERROR("Bad Subdomain definition: head should in [1 %i] (triangle number)",nbt);
+				subdomains[i].head = triangles+head;
+			}
+		}
+
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::WriteMesh {{{1*/
+	void Triangles::WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts){
+
+		/*Intermediary*/
+		int i,j,k,num,i1,i2;
+		long n;
+		int* head_1=NULL;
+		int* next_1=NULL;
+		int* connectivitysize_1=NULL;
+		int  connectivitymax_1=0;
+
+		/*Get options*/
+		int verbose=bamgopts->verbose;
+
+		/*Initialize output*/
+		BamgMeshInit(bamgmesh);
+
+		/*Build reft that holds the number the subdomain number of each triangle, and the real numbering of the elements*/
+		long* reft = new long[nbt];
+		long* numt = new long[nbt];
+		long nbInT = TriangleReferenceList(reft);
+		TriangleIntNumbering(numt);
+
+		/*Chaining algorithm used to generate connectivity tables and other outputs*/
+
+		//Memory Allocation
+		head_1=(int*)xmalloc(nbv*sizeof(int));
+		next_1=(int*)xmalloc(3*nbt*sizeof(int));
+		connectivitysize_1=(int*)xmalloc(nbv*sizeof(int));
+
+		//Initialization
+		for (i=0;i<nbv;i++) head_1[i]=-1;
+		for (i=0;i<nbv;i++) connectivitysize_1[i]=0;
+		k=0;
+		//Chains generation
+		for (i=0;i<nbt;i++) {
+			//Do not take into account outside triangles (reft<0)
+			if (reft[i]>=0){
+				for (j=0;j<3;j++){
+					int v=Number(triangles[i][j]); //jth vertex of the ith triangle
+					if (k>3*nbt-1 || k<0) ISSMERROR("k = %i, nbt = %i",k,nbt);
+					next_1[k]=head_1[v];
+					if (v>nbv-1 || v<0)   ISSMERROR("v = %i, nbv = %i",v,nbv);
+					head_1[v]=k++;
+					connectivitysize_1[v]+=1;
+				}
+			}
+		}
+		//Get maximum connectivity
+		connectivitymax_1=0;
+		for (i=0;i<nbv;i++){
+			if (connectivitysize_1[i]>connectivitymax_1) connectivitymax_1=connectivitysize_1[i];
+		}
+
+		/*OK, now build outputs*/
+
+		/*Vertices*/
+		if(verbose>5) printf("      writing Vertices\n");
+		bamgmesh->VerticesSize[0]=nbv;
+		bamgmesh->VerticesSize[1]=3;
+		if (nbv){
+			bamgmesh->Vertices=(double*)xmalloc(3*nbv*sizeof(double));
+			for (i=0;i<nbv;i++){
+				bamgmesh->Vertices[i*3+0]=vertices[i].r.x;
+				bamgmesh->Vertices[i*3+1]=vertices[i].r.y;
+				bamgmesh->Vertices[i*3+2]=vertices[i].ref();
+			}
+		}
+
+		/*Edges*/
+		if(verbose>5) printf("      writing Edges\n");
+		bamgmesh->EdgesSize[0]=nbe;
+		bamgmesh->EdgesSize[1]=3;
+		int NumSegments=0;
+		if (nbe){
+			bamgmesh->Edges=(double*)xmalloc(3*nbe*sizeof(double));
+			for (i=0;i<nbe;i++){
+				bamgmesh->Edges[i*3+0]=Number(edges[i][0])+1; //back to M indexing
+				bamgmesh->Edges[i*3+1]=Number(edges[i][1])+1; //back to M indexing
+				bamgmesh->Edges[i*3+2]=edges[i].ref;
+				if(edges[i].onGeometry){
+					NumSegments++;
+				}
+			}
+		}
+
+		/*Element edges*/
+		if(verbose>5) printf("      writing element edges\n");
+		SetOfEdges4* edge4=new SetOfEdges4(nbt*3,nbv);
+		double* elemedge=NULL;
+		elemedge=(double*)xmalloc(3*nbt*sizeof(double));
+		for (i=0;i<3*nbt;i++) elemedge[i]=NAN;
+		k=0;
+		for (i=0;i<nbt;i++){
+			//Do not take into account outside triangles (reft<0)
+			if (reft[i]>=0){
+				for  (j=0;j<3;j++) {
+					i1=Number(triangles[i][VerticesOfTriangularEdge[j][0]]);
+					i2=Number(triangles[i][VerticesOfTriangularEdge[j][1]]);
+					n =edge4->SortAndFind(i1,i2);
+					if (n==-1){
+						//first time
+						n=edge4->SortAndAdd(i1,i2);
+						elemedge[n*2+0]=double(k);
+					}
+					else{
+						//second time
+						elemedge[n*2+1]=double(k);
+					}
+				}
+				k++;
+			}
+		}
+		bamgmesh->ElementEdgesSize[0]=edge4->nb();
+		bamgmesh->ElementEdgesSize[1]=4;
+		bamgmesh->ElementEdges=(double*)xmalloc(4*edge4->nb()*sizeof(double));
+		for (i=0;i<edge4->nb();i++){
+			/*Invert first two vertices if necessary*/
+			bool found=false;
+			for (j=0;j<3;j++){
+				if (triangles[(int)elemedge[2*i+0]](j)==vertices+edge4->i(i)){
+					if (triangles[(int)elemedge[2*i+0]]((j+1)%3)==vertices+edge4->j(i)){
+						//trigonometric direction
+						bamgmesh->ElementEdges[i*4+0]=edge4->i(i)+1;// back to M indexing
+						bamgmesh->ElementEdges[i*4+1]=edge4->j(i)+1;// back to M indexing
+					}
+					else{
+						bamgmesh->ElementEdges[i*4+0]=edge4->j(i)+1;// back to M indexing
+						bamgmesh->ElementEdges[i*4+1]=edge4->i(i)+1;// back to M indexing
+					}
+					found=true;
+					break;
+				}
+			}
+			ISSMASSERT(found);
+			bamgmesh->ElementEdges[i*4+2]=elemedge[2*i+0]+1; // back to M indexing
+			bamgmesh->ElementEdges[i*4+3]=elemedge[2*i+1]+1; // back to M indexing
+		}
+		//clean up
+		delete edge4;
+		xfree((void**)&elemedge);
+
+		/*Segments*/
+		if(verbose>5) printf("      writing Segments\n");
+		bamgmesh->SegmentsSize[0]=NumSegments;
+		bamgmesh->SegmentsSize[1]=4;
+		bamgmesh->Segments=(double*)xmalloc(4*NumSegments*sizeof(double));
+		num=0;
+		for (i=0;i<nbe;i++){
+			if(edges[i].onGeometry){
+				//build segment
+				int i1=Number(edges[i][0]);
+				int i2=Number(edges[i][1]);
+				bool stop=false;
+				for(j=head_1[i1];j!=-1;j=next_1[j]){
+					for(k=0;k<3;k++){
+						if (Number(triangles[(int)j/3][k])==i1){
+							if (Number(triangles[(int)j/3][(int)((k+1)%3)])==i2){
+								bamgmesh->Segments[num*4+0]=Number(edges[i][0])+1; //back to M indexing
+								bamgmesh->Segments[num*4+1]=Number(edges[i][1])+1; //back to M indexing
+								bamgmesh->Segments[num*4+2]=(int)j/3+1;            //back to M indexing
+								bamgmesh->Segments[num*4+3]=edges[i].ref;
+								num+=1;
+								stop=true;
+								break;
+							}
+							if (Number(triangles[(int)j/3][(int)((k+2)%3)])==i2){
+								bamgmesh->Segments[num*4+0]=Number(edges[i][1])+1; //back to M indexing
+								bamgmesh->Segments[num*4+1]=Number(edges[i][0])+1; //back to M indexing
+								bamgmesh->Segments[num*4+2]=(int)j/3+1;            //back to M indexing
+								bamgmesh->Segments[num*4+3]=edges[i].ref;
+								num+=1;
+								stop=true;
+								break;
+							}
+						}
+					}
+					if(stop) break;
+				}
+				if (!stop){
+					ISSMERROR("Element holding segment [%i %i] not found...",i1+1,i2+1);
+				}
+			}
+		}
+
+		/*Triangles*/
+		if(verbose>5) printf("      writing Triangles\n");
+		k=nbInT-NbOfQuad*2;
+		num=0;
+		bamgmesh->TrianglesSize[0]=k;
+		bamgmesh->TrianglesSize[1]=4;
+		if (k){
+			bamgmesh->Triangles=(double*)xmalloc(4*k*sizeof(double));
+			for (i=0;i<nbt;i++){
+				Triangle &t=triangles[i];
+				//reft[i]=-1 for outside triangle
+				if (reft[i]>=0 && !( t.Hidden(0) || t.Hidden(1) || t.Hidden(2) )){
+					bamgmesh->Triangles[num*4+0]=Number(t[0])+1; //back to M indexing
+					bamgmesh->Triangles[num*4+1]=Number(t[1])+1; //back to M indexing
+					bamgmesh->Triangles[num*4+2]=Number(t[2])+1; //back to M indexing
+					bamgmesh->Triangles[num*4+3]=subdomains[reft[i]].ref;
+					num=num+1;
+				}
+			}
+		}
+
+		/*Quadrilaterals*/
+		if(verbose>5) printf("      writing Quadrilaterals\n");
+		bamgmesh->QuadrilateralsSize[0]=NbOfQuad;
+		bamgmesh->QuadrilateralsSize[1]=5;
+		if (NbOfQuad){
+			bamgmesh->Quadrilaterals=(double*)xmalloc(5*NbOfQuad*sizeof(double));
+			for (i=0;i<nbt;i++){
+				Triangle &t =triangles[i];
+				Triangle* ta;
+				MeshVertex *v0,*v1,*v2,*v3;
+				if (reft[i]<0) continue;
+				if ((ta=t.Quadrangle(v0,v1,v2,v3)) !=0 && &t<ta) { 
+					bamgmesh->Quadrilaterals[i*5+0]=Number(v0)+1; //back to M indexing
+					bamgmesh->Quadrilaterals[i*5+1]=Number(v1)+1; //back to M indexing
+					bamgmesh->Quadrilaterals[i*5+2]=Number(v2)+1; //back to M indexing
+					bamgmesh->Quadrilaterals[i*5+3]=Number(v3)+1; //back to M indexing
+					bamgmesh->Quadrilaterals[i*5+4]=subdomains[reft[i]].ref;
+				}
+			}
+		}
+
+		/*SubDomains*/
+		if(verbose>5) printf("      writing SubDomains\n");
+		bamgmesh->SubDomainsSize[0]=NbSubDomains;
+		bamgmesh->SubDomainsSize[1]=4;
+		if (NbSubDomains){
+			bamgmesh->SubDomains=(double*)xmalloc(4*NbSubDomains*sizeof(double));
+			for (i=0;i<NbSubDomains;i++){
+				bamgmesh->SubDomains[i*4+0]=3;
+				bamgmesh->SubDomains[i*4+1]=reft[Number(subdomains[i].head)];
+				bamgmesh->SubDomains[i*4+2]=1;
+				bamgmesh->SubDomains[i*4+3]=subdomains[i].ref;
+			}
+		}
+
+		/*SubDomainsFromGeom*/
+		if(verbose>5) printf("      writing SubDomainsFromGeom\n");
+		bamgmesh->SubDomainsFromGeomSize[0]=Gh.NbSubDomains;
+		bamgmesh->SubDomainsFromGeomSize[1]=4;
+		if (Gh.NbSubDomains){
+			bamgmesh->SubDomainsFromGeom=(double*)xmalloc(4*Gh.NbSubDomains*sizeof(double));
+			for (i=0;i<Gh.NbSubDomains;i++){
+				bamgmesh->SubDomainsFromGeom[i*4+0]=2;
+				bamgmesh->SubDomainsFromGeom[i*4+1]=Number(subdomains[i].edge)+1; //back to Matlab indexing
+				bamgmesh->SubDomainsFromGeom[i*4+2]=subdomains[i].sens;
+				bamgmesh->SubDomainsFromGeom[i*4+3]=Gh.subdomains[i].ref;
+			}
+		}
+
+		/*VerticesOnGeomVertex*/
+		if(verbose>5) printf("      writing VerticesOnGeometricVertex\n");
+		bamgmesh->VerticesOnGeometricVertexSize[0]=NbVerticesOnGeomVertex;
+		bamgmesh->VerticesOnGeometricVertexSize[1]=2;
+		if (NbVerticesOnGeomVertex){
+			bamgmesh->VerticesOnGeometricVertex=(double*)xmalloc(2*NbVerticesOnGeomVertex*sizeof(double));
+			for (i=0;i<NbVerticesOnGeomVertex;i++){
+				VertexOnGeom &v=VerticesOnGeomVertex[i];
+				ISSMASSERT(v.OnGeomVertex());
+				bamgmesh->VerticesOnGeometricVertex[i*2+0]=Number((MeshVertex*)v)+1; //back to Matlab indexing
+				bamgmesh->VerticesOnGeometricVertex[i*2+1]=Gh.Number((GeometricalVertex*)v)+1; //back to Matlab indexing
+			}
+		}
+
+		/*VertexOnGeometricEdge*/
+		if(verbose>5) printf("      writing VerticesOnGeometricEdge\n");
+		bamgmesh->VerticesOnGeometricEdgeSize[0]=NbVerticesOnGeomEdge;
+		bamgmesh->VerticesOnGeometricEdgeSize[1]=3;
+		if (NbVerticesOnGeomEdge){
+			bamgmesh->VerticesOnGeometricEdge=(double*)xmalloc(3*NbVerticesOnGeomEdge*sizeof(double));
+			for (i=0;i<NbVerticesOnGeomEdge;i++){
+				const VertexOnGeom &v=VerticesOnGeomEdge[i];
+				if (!v.OnGeomEdge()){
+					ISSMERROR("A vertices supposed to be OnGeometricEdge is actually not");
+				}
+				bamgmesh->VerticesOnGeometricEdge[i*3+0]=Number((MeshVertex*)v)+1; //back to Matlab indexing
+				bamgmesh->VerticesOnGeometricEdge[i*3+1]=Gh.Number((const GeometricalEdge*)v)+1; //back to Matlab indexing
+				bamgmesh->VerticesOnGeometricEdge[i*3+2]=(double)v; //absisce
+			}
+		}
+
+		/*EdgesOnGeometricEdge*/
+		if(verbose>5) printf("      writing EdgesOnGeometricEdge\n");
+		k=0;
+		for (i=0;i<nbe;i++){
+			if (edges[i].onGeometry) k=k+1;
+		}
+		bamgmesh->EdgesOnGeometricEdgeSize[0]=k;
+		bamgmesh->EdgesOnGeometricEdgeSize[1]=2;
+		if (k){
+			bamgmesh->EdgesOnGeometricEdge=(double*)xmalloc(2*(int)k*sizeof(double));
+			int count=0;
+			for (i=0;i<nbe;i++){
+				if (edges[i].onGeometry){
+					bamgmesh->EdgesOnGeometricEdge[count*2+0]=(double)i+1; //back to Matlab indexing
+					bamgmesh->EdgesOnGeometricEdge[count*2+1]=(double)Gh.Number(edges[i].onGeometry)+1; //back to Matlab indexing
+					count=count+1;
+				}
+			}
+		}
+
+		/*Element Connectivity*/
+		if(verbose>5) printf("      writing Element connectivity\n");
+		bamgmesh->ElementConnectivitySize[0]=nbt-NbOutT;
+		bamgmesh->ElementConnectivitySize[1]=3;
+		bamgmesh->ElementConnectivity=(double*)xmalloc(3*(nbt-NbOutT)*sizeof(double));
+		for (i=0;i<3*(nbt-NbOutT);i++) bamgmesh->ElementConnectivity[i]=NAN;
+		num=0;
+		for (i=0;i<nbt;i++){
+			if (reft[i]>=0){
+				for (j=0;j<3;j++){
+					k=Number(triangles[i].TriangleAdj(j));
+					if (reft[k]>=0){
+						ISSMASSERT(3*num+j<3*(nbt-NbOutT));
+						bamgmesh->ElementConnectivity[3*num+j]=k+1; // back to Matlab indexing
+					}
+				}
+				num+=1;
+			}
+		}
+
+		/*ElementNodal Connectivity*/
+		if(verbose>5) printf("      writing Nodal element connectivity\n");
+		bamgmesh->NodalElementConnectivitySize[0]=nbv;
+		bamgmesh->NodalElementConnectivitySize[1]=connectivitymax_1;
+		bamgmesh->NodalElementConnectivity=(double*)xmalloc(connectivitymax_1*nbv*sizeof(double));
+		for (i=0;i<connectivitymax_1*nbv;i++) bamgmesh->NodalElementConnectivity[i]=NAN;
+		for (i=0;i<nbv;i++){
+			k=0;
+			for(j=head_1[i];j!=-1;j=next_1[j]){
+				ISSMASSERT(connectivitymax_1*i+k < connectivitymax_1*nbv);
+				bamgmesh->NodalElementConnectivity[connectivitymax_1*i+k]=floor(j/3)+1;
+				k++;
+			}
+		}
+
+		/*Nodal Connectivity*/
+		if(verbose>5) printf("      writing Nodal connectivity\n");
+		//chaining algorithm (again...)
+		int* head_2=NULL;
+		int* next_2=NULL;
+		int* connectivitysize_2=NULL;
+		int  connectivitymax_2=0;
+		i1=bamgmesh->ElementEdgesSize[0];
+		i2=bamgmesh->ElementEdgesSize[1];
+		head_2=(int*)xmalloc(nbv*sizeof(int));
+		next_2=(int*)xmalloc(2*i1*sizeof(int));
+		connectivitysize_2=(int*)xmalloc(nbv*sizeof(int));
+		//Initialization
+		for (i=0;i<nbv;i++) head_2[i]=-1;
+		for (i=0;i<nbv;i++) connectivitysize_2[i]=0;
+		k=0;
+		//Chains generation
+		for (i=0;i<i1;i++) {
+			for (j=0;j<2;j++){
+				int v=(int)bamgmesh->ElementEdges[i*i2+j]-1; //back to C indexing
+				if (k>2*i1-1 || k<0) ISSMERROR("Index exceed matrix dimensions (k=%i not in [0 %i]",k,2*i1-1);
+				next_2[k]=head_2[v];
+				if (v>nbv-1 || v<0)   ISSMERROR("Index exceed matrix dimensions (v=%i not in [0 %i])",v,nbv-1);
+				head_2[v]=k++;
+				connectivitysize_2[v]+=1;
+			}
+		}
+		//Get maximum connectivity
+		for (i=0;i<nbv;i++){
+			if (connectivitysize_2[i]>connectivitymax_2) connectivitymax_2=connectivitysize_2[i];
+		}
+		//Build output
+		bamgmesh->NodalConnectivitySize[0]=nbv;
+		bamgmesh->NodalConnectivitySize[1]=connectivitymax_2;
+		bamgmesh->NodalConnectivity=(double*)xmalloc(connectivitymax_2*nbv*sizeof(double));
+		for (i=0;i<connectivitymax_2*nbv;i++) bamgmesh->NodalConnectivity[i]=NAN;
+		for (i=0;i<nbv;i++){
+			k=0;
+			for(j=head_2[i];j!=-1;j=next_2[j]){
+				ISSMASSERT(connectivitymax_2*i+k < connectivitymax_2*nbv);
+				num=(int)bamgmesh->ElementEdges[int(j/2)*i2+0];
+				if (i+1==num){ //carefull, ElementEdge is in M indexing
+					//i is the first vertex of the edge, it is therefore connected to the second vertex
+					bamgmesh->NodalConnectivity[connectivitymax_2*i+k]=bamgmesh->ElementEdges[int(j/2)*i2+1];
+				}
+				else{
+					bamgmesh->NodalConnectivity[connectivitymax_2*i+k]=num;
+				}
+				k++;
+			}
+		}
+
+		/*Cracked vertices*/
+		if(verbose>5) printf("      writing Cracked vertices\n");
+		bamgmesh->CrackedVerticesSize[0]=NbCrackedVertices;
+		bamgmesh->CrackedVerticesSize[1]=2;
+		if (NbCrackedVertices){
+			bamgmesh->CrackedVertices=(double*)xmalloc(2*NbCrackedVertices*sizeof(double));
+			for (i=0;i<NbCrackedVertices;i++){
+				bamgmesh->CrackedVertices[i*2+0]=CrackedVertices[i*2+0]+1; //M indexing
+				bamgmesh->CrackedVertices[i*2+1]=CrackedVertices[i*2+1]+1; //M indexing
+			}
+		}
+
+		/*Cracked vertices*/
+		if(verbose>5) printf("      writing Cracked vertices\n");
+		bamgmesh->CrackedEdgesSize[0]=NbCrackedEdges;
+		bamgmesh->CrackedEdgesSize[1]=4;
+		if (NbCrackedEdges){
+			bamgmesh->CrackedEdges=(double*)xmalloc(2*NbCrackedEdges*sizeof(double));
+			for (i=0;i<NbCrackedEdges;i++){
+				bamgmesh->CrackedEdges[i*2+0]=0;//CrackedEdges[i]->+1; //M indexing
+				bamgmesh->CrackedEdges[i*2+1]=0;//CrackedEdges[i]-]->+1; //M indexing
+			}
+		}
+
+		//clean up
+		xfree((void**)&connectivitysize_1);
+		xfree((void**)&head_1);
+		xfree((void**)&next_1);
+		xfree((void**)&connectivitysize_2);
+		xfree((void**)&head_2);
+		xfree((void**)&next_2);
+		delete [] reft;
+		delete [] numt;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::ReadMetric{{{1*/
+	void Triangles::ReadMetric(const BamgOpts* bamgopts) {
+
+		/*Intermediary*/
+		int  i,j;
+
+		if(bamgopts->verbose>3) printf("      processing metric\n");
+		double hmin = Max(bamgopts->hmin,MinimalHmin());
+		double hmax = Min(bamgopts->hmax,MaximalHmax());
+		double coef = bamgopts->coef;
+
+		//for now we only use j==3
+		j=3;
+
+		for (i=0;i<nbv;i++){
+			double h;
+			if (j == 1){
+				h=bamgopts->metric[i];
+				vertices[i].m=Metric(Max(hmin,Min(hmax, h*coef)));
+			}
+			else if (j==3){
+				//do not erase metric computed by hVertices
+				if (vertices[i].m.a11==1 && vertices[i].m.a21==0 && vertices[i].m.a22==1){
+					double a,b,c;	     
+					a=bamgopts->metric[i*3+0];
+					b=bamgopts->metric[i*3+1];
+					c=bamgopts->metric[i*3+2];
+					Metric M(a,b,c);
+					MatVVP2x2 Vp(M/coef);
+
+					Vp.Maxh(hmax);
+					Vp.Minh(hmin);
+					vertices[i].m = Vp;
+				}
+			}
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::WriteMetric{{{1*/
+	void Triangles::WriteMetric(BamgOpts* bamgopts) {
+		int i;
+		xfree((void**)&bamgopts->metric);
+		bamgopts->metric=(double*)xmalloc(3*nbv*sizeof(double));
+		for (i=0;i<nbv;i++){
+			bamgopts->metric[i*3+0]=vertices[i].m.a11;
+			bamgopts->metric[i*3+1]=vertices[i].m.a21;
+			bamgopts->metric[i*3+2]=vertices[i].m.a22;
+		}
+	}
+	/*}}}1*/
+
+	/*Methods*/
+	/*FUNCTION Triangles::AddGeometryMetric{{{1*/
+	void Triangles::AddGeometryMetric(BamgOpts* bamgopts){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/IntersectGeomMetric)*/
+
+		/*Get options*/
+		int    verbosity=bamgopts->verbose;
+		double anisomax =bamgopts->anisomax;
+		double errg     =bamgopts->errg;
+
+		double ss[2]={0.00001,0.99999};
+		double errC = 2*sqrt(2*errg);
+		double hmax = Gh.MaximalHmax();
+		double hmin = Gh.MinimalHmin();
+
+		//check that hmax is positive
+		if (hmax<=0){
+			ISSMERROR("hmax<=0");
+		}
+
+		//errC cannot be higher than 1
+		if (errC>1) errC=1;
+
+		//Set all vertices to "on"
+		SetVertexFieldOn();
+
+		//loop over all the vertices on edges
+		for (int  i=0;i<nbe;i++){
+			for (int j=0;j<2;j++){
+
+				MeshVertex V;
+				VertexOnGeom GV;
+				Gh.ProjectOnCurve(edges[i],ss[j],V,GV);
+
+				GeometricalEdge* eg = GV;
+				double s = GV;
+				R2 tg;
+				double  R1= eg->R1tg(s,tg);
+				double  ht=hmax;
+				// err relative to the length of the edge
+				if (R1>1.0e-20) {  
+					ht = Min(Max(errC/R1,hmin),hmax);
+				}
+				double hn=Min(hmax,ht*anisomax);
+
+				if (ht<=0 || hn<=0){
+					ISSMERROR("ht<=0 || hn<=0");
+				}
+				MatVVP2x2 Vp(1/(ht*ht),1/(hn*hn),tg);
+				Metric MVp(Vp);
+				edges[i][j].m.IntersectWith(MVp);
+			}
+		}
+		// the problem is for the vertex on vertex 
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::AddMetric{{{1*/
+	void Triangles::AddMetric(BamgOpts* bamgopts){
+		//  Hessiantype = 0 =>  H is computed using double P2 projection
+		//  Hessiantype = 1 =>  H is computed with green formula
+
+		/*Options*/
+		int Hessiantype=bamgopts->Hessiantype;
+
+		if (Hessiantype==0){
+			BuildMetric0(bamgopts);
+		}
+		else if (Hessiantype==1){
+			BuildMetric1(bamgopts);
+		}
+		else{
+			ISSMERROR("Hessiantype %i not supported yet (1->use Green formula, 0-> double P2 projection)",Hessiantype);
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::AddVertex{{{1*/
+	void Triangles::AddVertex( MeshVertex &s,Triangle* t, Icoor2* det3) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Add)*/
+		// -------------------------------------------
+		//             s2
+		//                                            !
+		//             /|\                            !
+		//            / | \                           !
+		//           /  |  \                          !
+		//    tt1   /   |   \ tt0                     !
+		//         /    |s   \                        !
+		//        /     .     \                       !
+		//       /  .      `   \                      !
+		//      / .           ` \                     !
+		//      ----------------                      !
+		//   s0       tt2       s1
+		//-------------------------------------------- 
+
+		//the three triangles tt
+		Triangle* tt[3];
+		//three vertices of t
+		MeshVertex &s0 = (*t)[0], &s1=(*t)[1], &s2=(*t)[2];
+		//three determinants
+		Icoor2 det3local[3];
+		// number of zero det3
+		register int nbzerodet =0; 
+		// izerodet = egde contening the vertex s
+		register int izerodet=-1,iedge; 
+		//determinant of t
+		Icoor2 detOld = t->det;
+
+		// infinitevertexpos = order of the infinite vertex (NULL)
+		// if no infinite vertex (NULL) infinitevertexpos=-1
+		// else if v_i is infinite, infinitevertexpos=i
+		int infinitevertexpos = &s0 ?  ((  &s1 ? ( &s2  ? -1 : 2) : 1  )) : 0;
+
+		//some checks
+		if (( infinitevertexpos <0 ) && (detOld <0) ||  ( infinitevertexpos >=0  ) && (detOld >0) ){
+			ISSMERROR("bug in Triangles::Add, bad configuration");
+		}
+
+		// if det3 does not exist, build it 
+		if (!det3) { 
+			//allocate
+			det3 = det3local;
+			//if no infinite vertex
+			if (infinitevertexpos<0 ) {
+				det3[0]=bamg::det(s ,s1,s2);
+				det3[1]=bamg::det(s0,s ,s2);
+				det3[2]=bamg::det(s0,s1,s );}
+			else { 
+				// one of &s1  &s2  &s0 is NULL so (&si || &sj) <=> !&sk
+				det3[0]= &s0 ? -1 : bamg::det(s ,s1,s2) ;
+				det3[1]= &s1 ? -1 : bamg::det(s0,s ,s2) ;
+				det3[2]= &s2 ? -1 : bamg::det(s0,s1,s ) ;
+			}
+		}
+
+		if (!det3[0]) izerodet=0,nbzerodet++;
+		if (!det3[1]) izerodet=1,nbzerodet++;
+		if (!det3[2]) izerodet=2,nbzerodet++;
+
+		//if nbzerodet>0, point s is on an egde or on a vertex 
+		if  (nbzerodet >0 ){ 
+			if (nbzerodet == 1) {
+				iedge = OppositeEdge[izerodet];
+				TriangleAdjacent ta = t->Adj(iedge);
+
+				// the point is on the edge 
+				// if the point is one the boundary 
+				// add the point in outside part 
+				if ( t->det >=0) { // inside triangle
+					if ((( Triangle *) ta)->det < 0 ) {
+						// add in outside triangle 
+						AddVertex(s,( Triangle *) ta);
+						return;
+					}
+				}
+			}
+			else {
+				//t->Echo();
+				printf("\nproblem while trying to add:\n");
+				s.Echo();
+				ISSMERROR("Bug in Triangles::Add points duplicated %i times",nbzerodet);
+			}
+		}
+
+		// remove de MarkUnSwap edge
+		t->SetUnMarkUnSwap(0);     
+		t->SetUnMarkUnSwap(1);     
+		t->SetUnMarkUnSwap(2);
+
+		tt[0]= t;
+		tt[1]= &triangles[nbt++];
+		tt[2]= &triangles[nbt++];
+
+		if (nbt>nbtx) {
+			ISSMERROR("Not ebough triangles");
+		}
+
+		*tt[1]=   *tt[2]= *t;
+		// gestion of the link
+		tt[0]->link=tt[1];
+		tt[1]->link=tt[2]; 
+
+		(* tt[0])(OppositeVertex[0])=&s;
+		(* tt[1])(OppositeVertex[1])=&s;
+		(* tt[2])(OppositeVertex[2])=&s;
+
+		tt[0]->det=det3[0];
+		tt[1]->det=det3[1];
+		tt[2]->det=det3[2];         
+
+		//  update adj des triangles externe 
+		tt[0]->SetAdjAdj(0);
+		tt[1]->SetAdjAdj(1);
+		tt[2]->SetAdjAdj(2);
+		//  update des adj des 3 triangle interne
+		const int i0 = 0;
+		const int i1= NextEdge[i0];
+		const int i2 = PreviousEdge[i0];
+
+		tt[i0]->SetAdj2(i2,tt[i2],i0);
+		tt[i1]->SetAdj2(i0,tt[i0],i1);
+		tt[i2]->SetAdj2(i1,tt[i1],i2);
+
+		tt[0]->SetTriangleContainingTheVertex();
+		tt[1]->SetTriangleContainingTheVertex();
+		tt[2]->SetTriangleContainingTheVertex();
+
+
+		// swap if the point s is on a edge
+		if(izerodet>=0) {
+			int rswap =tt[izerodet]->swap(iedge);
+
+			if (!rswap) {
+				ISSMERROR("swap the point s is on a edge");
+			}
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::BoundAnisotropy{{{1*/
+	void  Triangles::BoundAnisotropy(double anisomax,double hminaniso) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/BoundAnisotropy)*/
+
+		long int verbosity=0;
+		double lminaniso = 1/ (Max(hminaniso*hminaniso,1e-100));
+
+		//display info
+		if (verbosity > 1)  printf("   BoundAnisotropy by %g\n",anisomax);
+
+		double h1=1.e30,h2=1e-30;
+		double coef = 1./(anisomax*anisomax);
+		double hn1=1.e30,hn2=1e-30,rnx =1.e-30,rx=0;  
+
+		//loop over all vertices
+		for (int i=0;i<nbv;i++){
+			MatVVP2x2 Vp(vertices[i]);
+			double lmax=Vp.lmax();
+			Vp*=Min(lminaniso,lmax)/lmax;
+			Vp.BoundAniso2(coef);
+			vertices[i].m = Vp;
+
+			//info to be displayed
+			if (verbosity>2){
+				h1 =Min(h1,Vp.lmin());
+				h2 =Max(h2,Vp.lmax());
+				hn1=Min(hn1,Vp.lmin());
+				hn2=Max(hn2,Vp.lmax());
+				rx =Max(rx,Vp.Aniso2());
+				rnx= Max(rnx,Vp.Aniso2());
+			}
+		}
+
+		//display info
+		if (verbosity>2){
+			printf("      input:  Hmin = %g, Hmax = %g, factor of anisotropy max  = %g\n",pow(h2,-0.5),pow(h1,-0.5),pow(rx,0.5));
+			printf("      output: Hmin = %g, Hmax = %g, factor of anisotropy max  = %g\n",pow(hn2,-0.5),pow(hn1,-0.5),pow(rnx,0.5));
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::BuildGeometryFromMesh{{{1*/
+	void Triangles::BuildGeometryFromMesh(BamgOpts* bamgopts){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/ConsGeometry)*/
+
+		/*Reconstruct Geometry from Mesh*/
+
+		/*Intermediary*/
+		int i,j,k,kk,it,jt;
+		int    verbosity=0;
+		double cutoffradian=10*Pi/180;
+
+		/*Recover options*/
+		if (bamgopts){
+			verbosity=bamgopts->verbose;
+			cutoffradian=bamgopts->MaximalAngleOfCorner*Pi/180;
+		}
+
+		//display info
+		if (verbosity>1) printf("   construction of the geometry from the 2d mesh\n");
+
+		//check that the mesh is not empty
+		if (nbt<=0 || nbv <=0 ) {
+			ISSMERROR("nbt or nbv is negative (Mesh empty?)");
+		}
+
+		//Gh is the geometry of the mesh (this), initialize MaximalAngleOfCorner
+		if (cutoffradian>=0) Gh.MaximalAngleOfCorner = cutoffradian;
+
+		/*Construction of the edges*/
+
+		//initialize st and edge4
+		SetOfEdges4* edge4= new SetOfEdges4(nbt*3,nbv);
+		long*        st   = new long[nbt*3];
+
+		//initialize st as -1 (chaining algorithm)
+		for (i=0;i<nbt*3;i++) st[i]=-1;
+
+		//build edge4 (chain)
+		for (i=0;i<nbe;i++){
+			edge4->SortAndAdd(Number(edges[i][0]),Number(edges[i][1]));
+		}
+		//check that there is no double edge
+		if (nbe !=  edge4->nb()){ 
+			ISSMERROR("Some Double edge in the mesh, the number is %i, nbe4=%i",nbe,edge4->nb()); 
+		}
+		//keep nbe in nbeold
+		long nbeold = nbe;
+
+		//Go through the triangles and ass the edges in edge4 if they are not there yet
+		for (i=0;i<nbt;i++){
+			//3 edges per triangle
+			for  (j=0;j<3;j++) {
+				//Add Edge to edge4 (k=numberofedges in edge4)
+				long k =edge4->SortAndAdd(Number(triangles[i][VerticesOfTriangularEdge[j][0]]), Number(triangles[i][VerticesOfTriangularEdge[j][1]]));
+				long invisible = triangles[i].Hidden(j);
+
+				//if st[k] has not been changed yet, add 3*i+j (= vertex position in the index)
+				if(st[k]==-1) st[k]=3*i+j;
+
+				//else st[k]>=0 -> the edge already exist, check
+				else if(st[k]>=0) {
+					//check that it is not an edge on boundary (should not already exist)
+					if (triangles[i].TriangleAdj(j) || triangles[st[k]/3].TriangleAdj((int) (st[k]%3))){
+						ISSMERROR("problem in Geometry reconstruction: an edge on boundary is duplicated (double element?)");
+					}
+					//OK, the element is not on boundary, is belongs to 2 triangles -> build Adjacent triangles list
+					triangles[i].SetAdj2(j,triangles + st[k] / 3,(int) (st[k]%3));
+					if (invisible)  triangles[i].SetHidden(j);
+					// if k < nbe mark the edge as on Boundary (Locked)
+					if (k<nbe) {
+						triangles[i].SetLocked(j);
+					}
+					//set st[k] as negative so that the edge should not be called again
+					st[k]=-2-st[k]; 
+				}
+				//else (see 3 lines above), the edge has been called more than twice: return error
+				else {
+					printf("The edge (%i,%i) belongs to more than 2 triangles (%i)\n",Number(triangles[i][VerticesOfTriangularEdge[j][0]]),Number(triangles[i][VerticesOfTriangularEdge[j][1]]),k);
+					printf("Edge %i of triangle %i\n",j,i);
+					printf("Edge %i of triangle %i\n",(-st[k]+2)%3,(-st[k]+2)/3);
+					printf("Edge %i of triangle %i\n",triangles[(-st[k]+2)/3].NuEdgeTriangleAdj((int)((-st[k]+2)%3)),Number(triangles[(-st[k]+2)/3].TriangleAdj((int)((-st[k]+2)%3))));
+					ISSMERROR("An edge belongs to more than 2 triangles");
+				}	
+			}
+		}
+
+		//delete edge4
+		long nbedges = edge4->nb(); // the total number of edges 
+		delete edge4; edge4=NULL;
+
+		//display info
+		if(verbosity>5) {
+			printf("         info on Mesh:\n");
+			printf("            - number of vertices    = %i \n",nbv); 
+			printf("            - number of triangles   = %i \n",nbt); 
+			printf("            - number of given edges = %i \n",nbe); 
+			printf("            - number of all edges   = %i \n",nbedges); 
+			printf("            - Euler number 1 - nb of holes = %i \n"  ,nbt-nbedges+nbv); 
+		}
+
+		// check consistency of edge[].adj and geometrical required  vertices
+		k=0; kk=0;
+		for (i=0;i<nbedges;i++){
+			//internal edge
+			if (st[i] <-1) {
+				//get triangle number back
+				it =  (-2-st[i])/3;
+				//get edge position back
+				j  =  (int) ((-2-st[i])%3);
+				Triangle &tt=*triangles[it].TriangleAdj(j);
+				if (triangles[it].color != tt.color|| i < nbeold) k++;
+			}
+			//boundary edge (alone)
+			else if (st[i] >=0) 
+			 kk++;
+		}
+
+		/*Constructions of edges*/
+
+		k += kk;
+		kk=0;
+		if (k) {
+			nbe = k;
+			Edge* edgessave=edges;
+			edges = new Edge[nbe];
+			k =0;
+
+			//display info
+			if(verbosity>4) printf("   Construction of the edges %i\n",nbe);
+
+			for (i=0;i<nbedges;i++){ 
+				long  add= -1;
+
+				//internal edge (belongs to two triangles)
+				if (st[i] <-1){ 
+					it =  (-2-st[i])/3;
+					j  =  (int) ((-2-st[i])%3);
+					Triangle & tt = * triangles[it].TriangleAdj(j);
+					if (triangles[it].color !=  tt.color || i < nbeold) add=k++;
+				}
+				//boundary edge
+				else if (st[i] >=0){
+					it = st[i]/3;
+					j  = (int) (st[i]%3);
+					add=k++;
+				}
+				if (add>=0 && add < nbe){
+					edges[add].v[0] = &triangles[it][VerticesOfTriangularEdge[j][0]];
+					edges[add].v[1] = &triangles[it][VerticesOfTriangularEdge[j][1]];
+					edges[add].onGeometry=NULL; 
+					//if already existed
+					if (i<nbeold){
+						edges[add].ref=edgessave[i].ref; 		      
+						edges[add].onGeometry=edgessave[i].onGeometry; //  HACK to get required edges
+						printf("oh no...\n");
+					}
+					else
+					 edges[add].ref=Min(edges[add].v[0]->ref(),edges[add].v[1]->ref());
+				  }
+			}
+
+			//check that we have been through all edges
+			if (k!=nbe){
+				ISSMERROR("problem in edge construction process: k!=nbe (should not happen)");
+			}
+			//delete edgessave
+			if (edgessave) delete [] edgessave;
+		}
+
+		/*Color the vertices*/
+
+		//initialize color of all vertices as 0
+		for (i=0;i<nbv;i++) vertices[i].color =0;
+
+		//go through the edges and add a color to corresponding vertices
+		//(A vertex in 4 edges will have a color 4)
+		for (i=0;i<nbe;i++){
+		 for (j=0;j<2;j++) edges[i].v[j]->color++;
+		}
+
+		//change the color: if a vertex belongs to 2 edges -1, else -2
+		for (i=0;i<nbv;i++) {
+			vertices[i].color=(vertices[i].color ==2)? -1 : -2;
+		}
+
+		/*Build edges[i].adj: adjacency of each edge (if on the same curve)*/
+		for (i=0;i<nbe;i++){
+			for (j=0;j<2;j++){ 
+				//get current vertex
+				MeshVertex* v=edges[i].v[j];
+				//get vertex color (i0)
+				long i0=v->color;
+				long j0;
+
+				//if color<0 (first time), no adjacent edge
+				if(i0<0) edges[i].adj[j]=NULL;
+
+				//if color=-1 (corner),change the vertex color as 2*i+j (position of the vertex in edges)
+				if(i0==-1) v->color=i*2+j;
+
+				//if color>=0 (i and i0 edge are adjacent by the vertex v)
+				else if (i0>=0) {
+					//get position of v in edges back
+					j0 =  i0%2; //column in edges
+					i0 =  i0/2; //line in edges
+
+					//check that we have the correct vertex
+					if (v!=edges[i0 ].v[j0]){
+						ISSMERROR("v!=edges[i0 ].v[j0]: this should not happen as the vertex belongs to this edge");
+					}
+
+					//Add adjacence
+					edges[i ].adj[j ]=edges +i0;
+					edges[i0].adj[j0]=edges +i ;
+
+					//change color to -3
+					v->color = -3;
+				}
+			}
+		}
+
+		/*Reconstruct subdomains info*/
+
+		//check that NbSubDomains is empty
+		if (NbSubDomains){
+			ISSMERROR("NbSubDomains should be 0");
+		}
+		NbSubDomains=0;
+
+		//color the subdomains
+		long* colorT= new long[nbt];
+		Triangle *tt,*t;
+
+		//initialize the color of each triangle as -1
+		for (it=0;it<nbt;it++) colorT[it]=-1;
+
+		//loop over the triangles
+		for (it=0;it<nbt;it++){
+
+			//if the triangle has not been colored yet:
+			if (colorT[it]<0){
+
+				//color = number of subdomains
+				colorT[it]=NbSubDomains;
+
+				//color all the adjacent triangles of T that share a non marked edge
+				int level =1;
+				int kolor=triangles[it].color;
+				st[0]=it; // stack 
+				st[1]=0;
+				k=1;
+				while (level>0){
+					if( (j=st[level]++)<3 ){ 
+						t = &triangles[st[level-1]];
+						tt=t->TriangleAdj((int)j);
+
+						//color the adjacent triangle
+						if ( ! t->Locked(j) && tt && (colorT[jt = Number(tt)] == -1) && ( tt->color==kolor)) {
+							colorT[jt]=NbSubDomains;
+							st[++level]=jt;
+							st[++level]=0;
+							k++;
+						}
+					}
+					else level-=2;
+				}
+				NbSubDomains++;
+			}
+		}
+		if (verbosity> 3) printf("      The Number of sub domain = %i\n",NbSubDomains); 
+
+		//build subdomains
+		long isd;
+		subdomains = new SubDomain[NbSubDomains];
+
+		//initialize subdomains[isd].head as 0
+		for (isd=0;isd<NbSubDomains;isd++) subdomains[isd].head =0;
+		  
+		k=0;
+		for (it=0;it<nbt;it++){
+			for (int j=0;j<3;j++){
+				tt=triangles[it].TriangleAdj(j);
+				if ((!tt || tt->color != triangles[it].color) && !subdomains[isd=colorT[it]].head){
+					subdomains[isd].head = triangles+it;
+					subdomains[isd].ref =  triangles[it].color;
+					subdomains[isd].sens = j; // hack
+					subdomains[isd].edge = 0;
+					k++;
+				}
+			}
+		}
+		//check that we have been through all subdomains
+		if (k!= NbSubDomains){
+			ISSMERROR("k!= NbSubDomains");
+		}
+		//delete colorT and st
+		delete [] colorT;
+		delete [] st;
+
+		/*Reconstruct Geometry Gh*/
+
+		//build colorV -1 for all vertex and 0 for the vertices belonging to edges
+		long* colorV = new long[nbv];
+		for (i=0;i<nbv;i++) colorV[i]=-1;
+		for (i=0;i<nbe;i++){
+		 for ( j=0;j<2;j++) colorV[Number(edges[i][j])]=0;
+		}
+		//number the vertices belonging to edges
+		k=0;
+		for (i=0;i<nbv;i++){
+		 if(!colorV[i]) colorV[i]=k++;
+		}
+
+		//Build Gh
+		Gh.nbv=k;
+		Gh.nbe = nbe;
+		Gh.vertices = new GeometricalVertex[k];
+		Gh.edges = new GeometricalEdge[nbe];
+		Gh.NbSubDomains = NbSubDomains;
+		Gh.subdomains = new GeometricalSubDomain[NbSubDomains];
+		if (verbosity>3) printf("   number of vertices = %i\n   number of edges = %i\n",Gh.nbv,Gh.nbe);
+		NbVerticesOnGeomVertex = Gh.nbv;
+		VerticesOnGeomVertex = new VertexOnGeom[NbVerticesOnGeomVertex];
+		NbVerticesOnGeomEdge =0;
+		VerticesOnGeomEdge =0;
+
+		//Build VertexOnGeom
+		for (i=0;i<nbv;i++){
+			if((j=colorV[i])>=0){
+				MeshVertex & v = Gh.vertices[j];
+				v = vertices[i];
+				v.color =0;
+				VerticesOnGeomVertex[j] = VertexOnGeom(vertices[i], Gh.vertices[j]);
+			}
+		}
+
+		//Buid pmin and pmax of Gh (extrema coordinates)
+		Gh.pmin =  Gh.vertices[0].r;
+		Gh.pmax =  Gh.vertices[0].r;
+		// recherche des extrema des vertices pmin,pmax
+		for (i=0;i<Gh.nbv;i++) {
+			Gh.pmin.x = Min(Gh.pmin.x,Gh.vertices[i].r.x);
+			Gh.pmin.y = Min(Gh.pmin.y,Gh.vertices[i].r.y);
+			Gh.pmax.x = Max(Gh.pmax.x,Gh.vertices[i].r.x);
+			Gh.pmax.y = Max(Gh.pmax.y,Gh.vertices[i].r.y);
+		}
+		R2 DD05 = (Gh.pmax-Gh.pmin)*0.05;
+		Gh.pmin -=  DD05;
+		Gh.pmax +=  DD05;
+
+		//Build Gh.coefIcoor
+		Gh.coefIcoor= (MaxICoor)/(Max(Gh.pmax.x-Gh.pmin.x,Gh.pmax.y-Gh.pmin.y));
+		if (Gh.coefIcoor<=0){
+			ISSMERROR("Gh.coefIcoor<=0 in infered Geometry (this should not happen)");
+		}
+
+		/*Build Gh.edges*/
+
+		//initialize len as 0
+		double * len = new double[Gh.nbv];
+		for(i=0;i<Gh.nbv;i++) len[i]=0;
+
+		//initialize edge4 again
+		edge4= new SetOfEdges4(nbe,nbv);  
+		double hmin = HUGE_VAL;
+		int kreq=0;
+		for (i=0;i<nbe;i++){
+
+			long i0 = Number(edges[i][0]);
+			long i1 = Number(edges[i][1]);
+			long j0 = colorV[i0];
+			long j1 = colorV[i1];
+
+			Gh.edges[i].v[0] = Gh.vertices +  j0;
+			Gh.edges[i].v[1] = Gh.vertices +  j1;
+
+			Gh.edges[i].flag = 0;
+
+			Gh.edges[i].tg[0]=R2();
+			Gh.edges[i].tg[1]=R2();
+
+			bool required= edges[i].onGeometry; 
+			if(required) kreq++;
+			edges[i].onGeometry =  Gh.edges + i;
+			if(required){
+				Gh.edges[i].v[0]->SetRequired();
+				Gh.edges[i].v[1]->SetRequired();
+				Gh.edges[i].SetRequired();
+			}
+
+			R2 x12 = Gh.vertices[j0].r-Gh.vertices[j1].r;
+			double l12=Norme2(x12);        
+			hmin = Min(hmin,l12);
+
+			Gh.vertices[j1].color++;
+			Gh.vertices[j0].color++;
+
+			len[j0]+= l12;
+			len[j1] += l12;
+			hmin = Min(hmin,l12);
+			Gh.edges[i].ref  = edges[i].ref;
+
+			k = edge4->SortAndAdd(i0,i1);
+			if (k != i){
+				ISSMERROR("problem in Edge4 construction: k != i");
+			}
+		}
+
+		//Build metric for all vertices of Gh
+		for (i=0;i<Gh.nbv;i++){
+		 if (Gh.vertices[i].color > 0) 
+		  Gh.vertices[i].m=  Metric(len[i] /(double) Gh.vertices[i].color);
+		 else 
+		  Gh.vertices[i].m=  Metric(hmin);
+		}
+		//delete len
+		delete [] len;
+
+		//Build Gh.subdomains
+		for (i=0;i<NbSubDomains;i++){
+			it = Number(subdomains[i].head);
+			j = subdomains[i].sens;
+			long i0 = Number(triangles[it][VerticesOfTriangularEdge[j][0]]);
+			long i1 = Number(triangles[it][VerticesOfTriangularEdge[j][1]]);
+			k = edge4->SortAndFind(i0,i1);
+			if(k>=0){
+				subdomains[i].sens = (vertices + i0 == edges[k].v[0]) ? 1 : -1;
+				subdomains[i].edge = edges+k;
+				Gh.subdomains[i].edge = Gh.edges + k;
+				Gh.subdomains[i].sens  =  subdomains[i].sens;
+				Gh.subdomains[i].ref =  subdomains[i].ref;
+			}
+			else
+			 ISSMERROR("%i should be >=0");
+		  }
+
+		delete edge4;
+		delete [] colorV;
+
+		//unset adj
+		for (i=0;i<nbt;i++){
+			for ( j=0;j<3;j++){
+				triangles[i].SetAdj2(j,0,triangles[i].GetAllflag(j));
+			}
+		}
+
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::BuildMetric0 (double P2 projection){{{1*/
+	void Triangles::BuildMetric0(BamgOpts* bamgopts){
+
+		/*Options*/
+		double* s=NULL;
+		long    nbsol;
+		int     verbosity;
+
+		int   i,j,k,iA,iB,iC;
+		int   iv;
+
+		/*Recover options*/
+		verbosity=bamgopts->verbose;
+
+		/*Get and process fields*/
+		s=bamgopts->field;
+		nbsol=bamgopts->numfields;
+
+		//initialization of some variables
+		double* ss=(double*)s;
+		double  sA,sB,sC;
+		double*  detT = new double[nbt];
+		double*  sumareas = new double[nbv];
+		double*  alpha= new double[nbt*3];
+		double*  beta = new double[nbt*3];
+		double*  dx_elem    = new double[nbt];
+		double*  dy_elem    = new double[nbt];
+		double*  dx_vertex  = new double[nbv];
+		double*  dy_vertex  = new double[nbv];
+		double*  dxdx_elem  = new double[nbt];
+		double*  dxdy_elem  = new double[nbt];
+		double*  dydy_elem  = new double[nbt];
+		double*  dxdx_vertex= new double[nbv];
+		double*  dxdy_vertex= new double[nbv];
+		double*  dydy_vertex= new double[nbv];
+
+		//display infos
+		if(verbosity>1) {
+			printf("   Construction of Metric: number of field: %i (nbt=%i, nbv=%i)\n",nbsol,nbt,nbv);
+		}
+
+		//first, build the chains that will be used for the Hessian computation, as weel as the area of each element
+		int* head_s=NULL;
+		head_s=(int*)xmalloc(nbv*sizeof(int));
+		int* next_p=NULL;
+		next_p=(int*)xmalloc(3*nbt*sizeof(int));
+		int  p=0;
+		//initialization
+		for(i=0;i<nbv;i++){
+			sumareas[i]=0;
+			head_s[i]=-1;
+		}
+		for(i=0;i<nbt;i++){
+
+			//lopp over the real triangles (no boundary elements)
+			if(triangles[i].link){ 
+
+				//get current triangle t
+				const Triangle &t=triangles[i];
+
+				// coor of 3 vertices 
+				R2 A=t[0];
+				R2 B=t[1];
+				R2 C=t[2];
+
+				//compute triangle determinant (2*Area)
+				double dett = bamg::Area2(A,B,C);
+				detT[i]=dett;
+
+				/*The nodal functions are such that for a vertex A:
+				 *    N_A(x,y)=alphaA x + beta_A y +gamma_A
+				 *    N_A(A) = 1,   N_A(B) = 0,   N_A(C) = 0
+				 * solving this system of equation (determinant = 2Area(T) != 0 if A,B and C are not inlined)
+				 * leads to:
+				 *    N_A = (xB yC - xC yB + x(yB-yC) +y(xC-xB))/(2*Area(T))
+				 * and this gives:
+				 *    alpha_A = (yB-yC)/(2*Area(T))*/
+				alpha[i*3+0]=(B.y-C.y)/dett;
+				alpha[i*3+1]=(C.y-A.y)/dett;
+				alpha[i*3+2]=(A.y-B.y)/dett;
+				beta[ i*3+0]=(C.x-B.x)/dett;
+				beta[ i*3+1]=(A.x-C.x)/dett;
+				beta[ i*3+2]=(B.x-A.x)/dett;
+
+				//compute chains
+				for(j=0;j<3;j++){
+					k=Number(triangles[i][j]);
+					next_p[p]=head_s[k];
+					head_s[k]=p++;
+
+					//add area to sumareas
+					sumareas[k]+=dett;
+				}
+
+			}
+		}
+
+		//for all Solutions
+		for (int nusol=0;nusol<nbsol;nusol++) {
+			double smin=ss[nusol],smax=ss[nusol];
+
+			//get min(s), max(s) and initialize Hessian (dxdx,dxdy,dydy)
+			for ( iv=0,k=0; iv<nbv; iv++){
+				smin=Min(smin,ss[iv*nbsol+nusol]);
+				smax=Max(smax,ss[iv*nbsol+nusol]);
+			}
+			double sdelta=smax-smin;
+			double absmax=Max(Abs(smin),Abs(smax));
+
+			//display info
+			if(verbosity>2) printf("      Solution %i, Min = %g, Max = %g, Delta = %g\n",nusol,smin,smax,sdelta);
+
+			//skip constant field
+			if (sdelta < 1.0e-10*Max(absmax,1e-20)){
+				printf("      Solution %i is constant, skipping...\n",nusol);
+				continue;
+			}
+
+			//initialize the hessian and gradient matrices
+			for ( iv=0,k=0; iv<nbv; iv++) dxdx_vertex[iv]=dxdy_vertex[iv]=dydy_vertex[iv]=dx_vertex[iv]=dy_vertex[iv]=0;
+
+			//1: Compute gradient for each element (exact)
+			for (i=0;i<nbt;i++){
+				if(triangles[i].link){
+					// number of the 3 vertices
+					iA = Number(triangles[i][0]);
+					iB = Number(triangles[i][1]);
+					iC = Number(triangles[i][2]);
+
+					// value of the P1 fonction on 3 vertices 
+					sA = ss[iA*nbsol+nusol];
+					sB = ss[iB*nbsol+nusol];
+					sC = ss[iC*nbsol+nusol];
+
+					//gradient = (sum alpha_i s_i, sum_i beta_i s_i)
+					dx_elem[i]=sA*alpha[3*i+0]+sB*alpha[3*i+1]+sC*alpha[3*i+2];
+					dy_elem[i]=sA*beta[ 3*i+0]+sB*beta[ 3*i+1]+sC*beta[ 3*i+2];
+				}
+			}
+
+			//2: then compute a gradient for each vertex using a P2 projection
+			for(i=0;i<nbv;i++){
+				for(p=head_s[i];p!=-1;p=next_p[p]){
+					//Get triangle number
+					k=(long)(p/3);
+					dx_vertex[i]+=dx_elem[k]*detT[k]/sumareas[i];
+					dy_vertex[i]+=dy_elem[k]*detT[k]/sumareas[i];
+				}
+			}
+
+			//3: compute Hessian matrix on each element
+			for (i=0;i<nbt;i++){
+				if(triangles[i].link){
+					// number of the 3 vertices
+					iA = Number(triangles[i][0]);
+					iB = Number(triangles[i][1]);
+					iC = Number(triangles[i][2]);
+
+					//Hessian
+					dxdx_elem[i]=dx_vertex[iA]*alpha[3*i+0]+dx_vertex[iB]*alpha[3*i+1]+dx_vertex[iC]*alpha[3*i+2];
+					dxdy_elem[i]=dy_vertex[iA]*alpha[3*i+0]+dy_vertex[iB]*alpha[3*i+1]+dy_vertex[iC]*alpha[3*i+2];
+					dydy_elem[i]=dy_vertex[iA]*beta[3*i+0]+dy_vertex[iB]*beta[3*i+1]+dy_vertex[iC]*beta[3*i+2];
+				}
+			}
+
+			//4: finaly compute Hessian on each vertex using the second P2 projection
+			for(i=0;i<nbv;i++){
+				for(p=head_s[i];p!=-1;p=next_p[p]){
+					//Get triangle number
+					k=(long)(p/3);
+					dxdx_vertex[i]+=dxdx_elem[k]*detT[k]/sumareas[i];
+					dxdy_vertex[i]+=dxdy_elem[k]*detT[k]/sumareas[i];
+					dydy_vertex[i]+=dydy_elem[k]*detT[k]/sumareas[i];
+				}
+			}
+
+			/*Compute Metric from Hessian*/
+			for ( iv=0;iv<nbv;iv++){
+				vertices[iv].MetricFromHessian(dxdx_vertex[iv],dxdy_vertex[iv],dydy_vertex[iv],smin,smax,ss[iv*nbsol+nusol],bamgopts->err[nusol],bamgopts);
+			}
+
+		}//for all solutions
+
+		//clean up
+		xfree((void**)&head_s);
+		xfree((void**)&next_p);
+		delete [] detT;
+		delete [] alpha;
+		delete [] beta;
+		delete [] sumareas;
+		delete [] dx_elem;
+		delete [] dy_elem;
+		delete [] dx_vertex;
+		delete [] dy_vertex;
+		delete [] dxdx_elem;
+		delete [] dxdy_elem;
+		delete [] dydy_elem;
+		delete [] dxdx_vertex;
+		delete [] dxdy_vertex;
+		delete [] dydy_vertex;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::BuildMetric1 (Green formula){{{1*/
+	void Triangles::BuildMetric1(BamgOpts* bamgopts){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/IntersectConsMetric)*/
+
+		/*Options*/
+		double* s=NULL;
+		long nbsol;
+		int NbJacobi;
+		int verbosity;
+
+		/*Recover options*/
+		verbosity=bamgopts->verbose;
+		NbJacobi=bamgopts->nbjacobi;
+
+		/*Get and process fields*/
+		s=bamgopts->field;
+		nbsol=bamgopts->numfields;
+
+		//initialization of some variables
+		long    i,k,iA,iB,iC,iv;
+		R2      O(0,0);
+		double* ss=(double*)s;
+		double  sA,sB,sC;
+		double*  detT = new double[nbt];
+		double*  Mmass= new double[nbv];
+		double*  Mmassxx= new double[nbv];
+		double*  dxdx= new double[nbv];
+		double*  dxdy= new double[nbv];
+		double*  dydy= new double[nbv];
+		double*  workT= new double[nbt];
+		double*  workV= new double[nbv];
+		int*    OnBoundary = new int[nbv];
+
+		//display infos
+		if(verbosity>1) {
+			printf("   Construction of Metric: number of field: %i (nbt=%i, nbv=%i)\n",nbsol,nbt,nbv);
+		}
+
+		//initialize Mmass, OnBoundary and Massxx by zero
+		for (iv=0;iv<nbv;iv++){
+			Mmass[iv]=0;
+			OnBoundary[iv]=0;
+			Mmassxx[iv]=0;
+		}
+
+		//Build detT Mmas Mmassxx workT and OnBoundary
+		for (i=0;i<nbt;i++){ 
+
+			//lopp over the real triangles (no boundary elements)
+			if(triangles[i].link){ 
+
+				//get current triangle t
+				const Triangle &t=triangles[i];
+
+				// coor of 3 vertices 
+				R2 A=t[0];
+				R2 B=t[1];
+				R2 C=t[2];
+
+				// number of the 3 vertices
+				iA = Number(t[0]);
+				iB = Number(t[1]);
+				iC = Number(t[2]);
+
+				//compute triangle determinant (2*Area)
+				double dett = bamg::Area2(A,B,C);
+				detT[i]=dett;
+				dett /= 6;
+
+				// construction of OnBoundary (flag=1 if on boundary, else 0)
+				int nbb=0;
+				for(int j=0;j<3;j++){
+					//get adjacent triangle
+					Triangle *ta=t.Adj(j);
+					//if there is no adjacent triangle, the edge of the triangle t is on boundary
+					if ( !ta || !ta->link){
+						//mark the two vertices of the edge as OnBoundary
+						OnBoundary[Number(t[VerticesOfTriangularEdge[j][0]])]=1;
+						OnBoundary[Number(t[VerticesOfTriangularEdge[j][1]])]=1;
+						nbb++;
+					}
+				}
+
+				//number of vertices on boundary for current triangle t
+				workT[i] = nbb;
+
+				//Build Mmass Mmass[i] = Mmass[i] + Area/3
+				Mmass[iA] += dett;
+				Mmass[iB] += dett;
+				Mmass[iC] += dett;
+
+				//Build Massxx = Mmass
+				Mmassxx[iA] += dett;
+				Mmassxx[iB] += dett;
+				Mmassxx[iC] += dett;
+			}
+
+			//else: the triangle is a boundary triangle -> workT=-1
+			else workT[i]=-1;
+		}
+
+		//for all Solution  
+		for (int nusol=0;nusol<nbsol;nusol++) {
+
+			double smin=ss[nusol],smax=ss[nusol];
+			double h1=1.e30,h2=1e-30,rx=0;
+			double hn1=1.e30,hn2=1e-30,rnx =1.e-30;  
+
+			//get min(s), max(s) and initialize Hessian (dxdx,dxdy,dydy)
+			for ( iv=0,k=0; iv<nbv; iv++ ){
+				dxdx[iv]=dxdy[iv]=dydy[iv]=0;
+				smin=Min(smin,ss[iv*nbsol+nusol]);
+				smax=Max(smax,ss[iv*nbsol+nusol]);
+			}
+			double sdelta=smax-smin;
+			double absmax=Max(Abs(smin),Abs(smax));
+
+			//display info
+			if(verbosity>2) printf("      Solution %i, Min = %g, Max = %g, Delta = %g, number of fields = %i\n",nusol,smin,smax,sdelta,nbsol);
+
+			//skip constant field
+			if (sdelta < 1.0e-10*Max(absmax,1e-20) ){
+				if (verbosity>2) printf("      Solution %i is constant, skipping...\n");
+				continue;
+			}
+
+			//pointer toward ss that is also a pointer toward s (solutions)
+			double* sf=ss; 
+
+				//initialize the hessian matrix
+				for ( iv=0,k=0; iv<nbv; iv++) dxdx[iv]=dxdy[iv]=dydy[iv]=0;
+
+				//loop over the triangles
+				for (i=0;i<nbt;i++){
+
+					//for real all triangles 
+					if(triangles[i].link){
+
+						// coor of 3 vertices 
+						R2 A=triangles[i][0];
+						R2 B=triangles[i][1];
+						R2 C=triangles[i][2];
+
+						//warning: the normal is internal and the size is the length of the edge
+						R2 nAB = Orthogonal(B-A);
+						R2 nBC = Orthogonal(C-B);
+						R2 nCA = Orthogonal(A-C);
+						//note that :  nAB + nBC + nCA == 0 
+
+						// number of the 3 vertices
+						iA = Number(triangles[i][0]);
+						iB = Number(triangles[i][1]);
+						iC = Number(triangles[i][2]);
+
+						// for the test of  boundary edge
+						// the 3 adj triangles 
+						Triangle *tBC = triangles[i].TriangleAdj(OppositeEdge[0]);
+						Triangle *tCA = triangles[i].TriangleAdj(OppositeEdge[1]);
+						Triangle *tAB = triangles[i].TriangleAdj(OppositeEdge[2]);
+
+						// value of the P1 fonction on 3 vertices 
+						sA = ss[iA*nbsol+nusol];
+						sB = ss[iB*nbsol+nusol];
+						sC = ss[iC*nbsol+nusol];
+
+						/*The nodal functions are such that for a vertex A:
+						  N_A(x,y)=alphaA x + beta_A y +gamma_A
+						  N_A(A) = 1,   N_A(B) = 0,   N_A(C) = 0
+						  solving this system of equation (determinant = 2Area(T) != 0 if A,B and C are not inlined)
+						  leads to:
+						  N_A = (xB yC - xC yB + x(yB-yC) +y(xC-xB))/(2*Area(T))
+						  and this gives:
+						  alpha_A = (yB-yC)/(2*Area(T))
+						  beta_A = (xC-xB)/(2*Area(T))
+						  and therefore:
+						  grad N_A = nA / detT
+						  for an interpolation of a solution s:
+						  grad(s) = s * sum_{i=A,B,C} grad(N_i) */
+
+						R2 Grads=(nAB*sC+nBC*sA+nCA*sB)/detT[i];
+
+						//Use Green to compute Hessian Matrix
+
+						// if edge on boundary no contribution  => normal = 0
+						if ( !tBC || !tBC->link ) nBC=O;
+						if ( !tCA || !tCA->link ) nCA=O;
+						if ( !tAB || !tAB->link ) nAB=O;
+
+						// remark we forgot a 1/2 because
+						//       int_{edge} w_i = 1/2 if i is in edge 
+						//                         0  if not
+						// if we don't take the  boundary 
+						dxdx[iA] += ( nCA.x + nAB.x ) *Grads.x;
+						dxdx[iB] += ( nAB.x + nBC.x ) *Grads.x;
+						dxdx[iC] += ( nBC.x + nCA.x ) *Grads.x;
+
+						//warning optimization (1) the division by 2 is done on the metric construction
+						dxdy[iA] += (( nCA.y + nAB.y ) *Grads.x + ( nCA.x + nAB.x ) *Grads.y) ;
+						dxdy[iB] += (( nAB.y + nBC.y ) *Grads.x + ( nAB.x + nBC.x ) *Grads.y) ;
+						dxdy[iC] += (( nBC.y + nCA.y ) *Grads.x + ( nBC.x + nCA.x ) *Grads.y) ; 
+
+						dydy[iA] += ( nCA.y + nAB.y ) *Grads.y;
+						dydy[iB] += ( nAB.y + nBC.y ) *Grads.y;
+						dydy[iC] += ( nBC.y + nCA.y ) *Grads.y;
+
+					} // for real all triangles 
+				}
+
+				long kk=0;
+				for ( iv=0,k=0 ; iv<nbv; iv++){
+					if(Mmassxx[iv]>0){
+						dxdx[iv] /= 2*Mmassxx[iv];
+						// warning optimization (1) on term dxdy[iv]*ci/2 
+						dxdy[iv] /= 4*Mmassxx[iv];
+						dydy[iv] /= 2*Mmassxx[iv];
+						// Compute the matrix with abs(eigen value)
+						Metric M(dxdx[iv], dxdy[iv], dydy[iv]);
+						MatVVP2x2 Vp(M);
+						Vp.Abs();
+						M = Vp;
+						dxdx[iv] = M.a11;
+						dxdy[iv] = M.a21;
+						dydy[iv] = M.a22;
+					}
+					else kk++;
+				}
+
+				// correction of second derivative
+				// by a laplacien
+				double* d2[3] = {dxdx, dxdy, dydy};
+				double* dd;
+				for (int xy = 0;xy<3;xy++) {
+					dd = d2[xy];
+					// do leat 2 iteration for boundary problem
+					for (int ijacobi=0;ijacobi<Max(NbJacobi,2);ijacobi++){
+						for (i=0;i<nbt;i++) 
+						 if(triangles[i].link){// the real triangles 
+							 // number of the 3 vertices
+							 iA = Number(triangles[i][0]);
+							 iB = Number(triangles[i][1]);
+							 iC = Number(triangles[i][2]);
+							 double cc=3;
+							 if(ijacobi==0)
+							  cc = Max((double) ((Mmassxx[iA]>0)+(Mmassxx[iB]>0)+(Mmassxx[iC]>0)),1.);
+							 workT[i] = (dd[iA]+dd[iB]+dd[iC])/cc;
+						 }
+						for (iv=0;iv<nbv;iv++) workV[iv]=0;
+
+						for (i=0;i<nbt;i++){ 
+							if(triangles[i].link){ // the real triangles 
+								// number of the 3 vertices
+								iA = Number(triangles[i][0]);
+								iB = Number(triangles[i][1]);
+								iC = Number(triangles[i][2]);
+								double cc =  workT[i]*detT[i];
+								workV[iA] += cc;
+								workV[iB] += cc;
+								workV[iC] += cc;
+							}
+						}
+
+						for (iv=0;iv<nbv;iv++){
+							if( ijacobi<NbJacobi || OnBoundary[iv]){
+								dd[iv] = workV[iv]/(Mmass[iv]*6);
+							}
+						}
+					}
+				}
+
+				/*Compute Metric from Hessian*/
+				for ( iv=0;iv<nbv;iv++){
+					vertices[iv].MetricFromHessian(dxdx[iv],dxdy[iv],dydy[iv],smin,smax,ss[iv*nbsol+nusol],bamgopts->err[nusol],bamgopts);
+				}
+
+		}// end for all solution 
+
+		delete [] detT;
+		delete [] Mmass;
+		delete [] dxdx;
+		delete [] dxdy;
+		delete [] dydy;
+		delete []  workT;
+		delete [] workV;
+		delete [] Mmassxx;
+		delete []  OnBoundary;
+
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::CrackMesh{{{1*/
+	void Triangles::CrackMesh(BamgOpts* bamgopts) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/CrackMesh)*/
+
+		/*Intermediary*/
+		int i,j,k,num,count;
+		int i1,i2;
+		int j1,j2;
+
+		/*Options*/
+		int verbose=bamgopts->verbose;
+
+		//  computed the number of cracked edge
+		for (k=i=0;i<nbe;i++){
+			if(edges[i].onGeometry->Cracked()) k++;
+		}
+
+		//Return if no edge is cracked
+		if(k==0) return;
+		if (verbose>4) printf("      number of Cracked Edges = %i\n",k);
+
+		//Initialize Cracked edge
+		NbCrackedEdges=k;
+		CrackedEdges=new CrackedEdge[k];
+
+		//Compute number of Cracked Vertices
+		k=0;
+		NbCrackedVertices=0;
+
+		int* splitvertex=new int[nbv];
+		for (i=0;i<nbv;i++) splitvertex[i]=0;
+
+		for (i=0;i<nbe;i++){
+			if(edges[i].onGeometry->Cracked()){
+
+				//Fill edges fields of CrackedEdges
+				CrackedEdges[k  ].E =edges[i].onGeometry;
+				CrackedEdges[k++].e1=&edges[i];
+
+				//Get number of the two vertices on the edge
+				i1=Number(edges[i][0]);
+				i2=Number(edges[i][1]);
+				ISSMASSERT(i1>=0 && i1<nbv && i2>=0 && i2<nbv);
+				splitvertex[i1]++;
+				splitvertex[i2]++;
+
+				//If the vertex has already been flagged once, it is a cracked vertex (tip otherwise)
+				if (splitvertex[i1]==2) NbCrackedVertices++;
+				if (splitvertex[i2]==2) NbCrackedVertices++;
+
+				//The vertex cannot be marked more than twice
+				if (splitvertex[i1]==3 || splitvertex[i2]==3){
+					ISSMERROR("Crossing rifts not supported yet");
+				}
+			}
+		}
+		ISSMASSERT(k==NbCrackedEdges);
+
+		//Add new vertices
+		if (verbose>4) printf("      number of Cracked Vertices = %i\n",NbCrackedVertices);
+		if (NbCrackedVertices){
+			CrackedVertices=(long*)xmalloc(2*NbCrackedVertices*sizeof(double));
+			num=0;
+			for (i=0;i<nbv;i++){
+				if (splitvertex[i]==2){
+					CrackedVertices[num*2+0]=i;      //index of first vertex
+					CrackedVertices[num*2+1]=nbv+num;//index of new vertex
+					num++;
+				}
+			}
+			ISSMASSERT(num==NbCrackedVertices);
+		}
+		delete [] splitvertex;
+
+		//Now, find the triangles that hold a cracked edge
+		ReMakeTriangleContainingTheVertex();
+
+		long* Edgeflags=new long[NbCrackedEdges];
+		for(i=0;i<NbCrackedEdges;i++) Edgeflags[i]=0;
+
+		for(i=0;i<NbCrackedEdges;i++){
+			//Get the numbers of the 2 vertices of the crren cracked edge
+			i1=Number((*CrackedEdges[i].e1)[0]);
+			i2=Number((*CrackedEdges[i].e1)[1]);
+
+			//find a triangle holding the vertex i1 (first vertex of the ith cracked edge)
+			Triangle* tbegin=vertices[i1].t;
+			k=vertices[i1].vint;//local number of i in triangle tbegin
+			ISSMASSERT(Number((*tbegin)[k])==Number(vertices[i1]));
+
+			//Now, we are going to go through the adjacent triangle that hold i1 till
+			//we find one that has the cracked edge
+			TriangleAdjacent ta(tbegin,EdgesVertexTriangle[k][0]);
+			count=0;
+			do {
+				for(j=0;j<3;j++){
+					//Find the position of i1 in the triangle index
+					if (Number((*ta.t)[j])==i1){
+						j1=j;
+						break;
+					}
+				}
+				for(j=0;j<3;j++){
+					//Check wether i2 is also in the triangle index
+					if (Number((*ta.t)[j])==i2){
+						j2=j;
+						//Invert j1 and j2 if necessary
+						if ((j1+1)%3==j2){
+							int j3=j1;
+							j1=j2;
+							j2=j3;
+						}
+						if (Edgeflags[i]==0){
+							//first element
+							CrackedEdges[i].a=ta.t;
+							CrackedEdges[i].length=Norme2((*ta.t)[j1].r-(*ta.t)[j2].r);
+							CrackedEdges[i].normal=Orthogonal((*ta.t)[j1].r-(*ta.t)[j2].r);
+						}
+						else{
+							//Second element -> to renumber
+							CrackedEdges[i].b=ta.t;
+							CrackedEdges[i].length=Norme2((*ta.t)[j1].r-(*ta.t)[j2].r);
+							CrackedEdges[i].normal=Orthogonal((*ta.t)[j1].r-(*ta.t)[j2].r);
+						}
+						Edgeflags[i]++;
+						break;
+					}
+				}
+				//printf("%i -> %i %i %i, edge [%i->%i %i->%i]\n",element_renu[Number(ta.t)],Number((*ta.t)[0])+1,Number((*ta.t)[1])+1,Number((*ta.t)[2])+1,i1,j1,i2,j2);
+				ta = Next(ta).Adj(); 
+				if (count++>50) ISSMERROR("Maximum number of iteration exceeded");
+			}while ((tbegin != ta)); 
+		}
+
+		//Check EdgeFlag
+		for(i=0;i<NbCrackedEdges;i++){
+			if (Edgeflags[i]!=2){
+				ISSMERROR("A problem occured: at least one crack edge (number %i) does not belong to 2 elements",i+1);
+			}
+		}
+		delete [] Edgeflags;
+
+		//Reset MeshVertex to On
+		SetVertexFieldOn();
+
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::ForceBoundary{{{1*/
+		void Triangles::ForceBoundary() {
+			/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ForceBoundary)*/
+
+			long int verbosity=2;
+			int k=0;
+			int nbfe=0,nbswp=0,Nbswap=0;
+
+			//display
+			if (verbosity > 2) printf("   ForceBoundary  nb of edge: %i\n",nbe);
+
+			//check that there is no triangle with 0 determinant
+			for (int t = 0; t < nbt; t++){
+				if (!triangles[t].det) k++;
+			}
+			if (k!=0) {
+				ISSMERROR("there is %i triangles of mes = 0",k);
+			}
+
+			//Force Edges
+			TriangleAdjacent ta(0,0);
+			for (int i = 0; i < nbe; i++){
+
+				//Force edge i
+				nbswp =  ForceEdge(edges[i][0],edges[i][1],ta);
+				if (nbswp<0) k++;
+				else Nbswap += nbswp;
+
+				if (nbswp) nbfe++;
+				if ( nbswp < 0 && k < 5){
+					ISSMERROR("Missing Edge %i, v0=%i,v1=%i",i,Number(edges[i][0]),Number(edges[i][1]));
+				}
+			}
+
+			if (k!=0) {
+				ISSMERROR("There are %i lost edges, the boundary might be crossing",k);
+			}
+			for (int j=0;j<nbv;j++){
+				Nbswap +=  vertices[j].Optim(1,0);
+			}
+			if (verbosity > 3) printf("      number of inforced edge = %i, number of swap= %i\n",nbfe,Nbswap); 
+		}
+	/*}}}1*/
+	/*FUNCTION Triangles::FindSubDomain{{{1*/
+	void Triangles::FindSubDomain(int OutSide) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/FindSubDomain)*/
+
+		long int verbosity=0;
+
+		if (verbosity >2){
+			if (OutSide) printf("   Find all external sub-domain\n"); 
+			else printf("   Find all internal sub-domain\n");
+		  }
+		short * HeapArete = new short[nbt];
+		Triangle  **  HeapTriangle = new Triangle*  [nbt];
+		Triangle *t,*t1;
+		long k,it;
+
+		for (int itt=0;itt<nbt;itt++) 
+		 triangles[itt].link=0; // par defaut pas de couleur
+
+		long  NbSubDomTot =0;
+		for ( it=0;it<nbt;it++)  { 
+			if ( ! triangles[it].link  ) {
+				t = triangles + it;
+				NbSubDomTot++;; // new composante connexe
+				long i = 0; // niveau de la pile 
+				t->link = t ; // sd forme d'un triangle cicular link
+
+				HeapTriangle[i] =t ; 
+				HeapArete[i] = 3;
+
+				while (i >= 0) // boucle sur la pile
+				  { while ( HeapArete[i]--) // boucle sur les 3 aretes 
+					  { 
+						int na =  HeapArete[i];
+						Triangle * tc =  HeapTriangle[i]; // triangle courant
+						if( ! tc->Locked(na)) // arete non frontiere
+						  {
+							Triangle * ta = tc->TriangleAdj(na) ; // næ triangle adjacent
+							if (ta->link == 0 ) // non deja chainer => on enpile
+							  { 
+								i++;
+								ta->link = t->link ;  // on chaine les triangles
+								t->link = ta ;  // d'un meme sous domaine          
+								HeapArete[i] = 3; // pour les 3 triangles adjacents
+								HeapTriangle[i] = ta;
+							  }}
+					  } // deplie fin de boucle sur les 3 adjacences
+					i--;
+				  }          
+			}      
+		}
+
+		// supression de tous les sous domaine infini <=>  contient le sommet NULL
+		it =0;
+		NbOutT = 0;
+		while (it<nbt) {
+			if (triangles[it].link) 
+			  { 
+				if (!( triangles[it](0) &&  triangles[it](1) &&  triangles[it](2) )) 
+				  {
+					// infini triangle 
+					NbSubDomTot --;
+					t=&triangles[it];
+					NbOutT--;  // on fait un coup de trop. 
+					while  (t){
+						NbOutT++;
+						t1=t;
+						t=t->link;
+						t1->link=0;
+					}
+				  }
+			  }   
+			it++;} // end while (it<nbt)
+			if (nbt == NbOutT ||  !NbSubDomTot) {
+				ISSMERROR("The boundary is not close: all triangles are outside");
+			}
+
+			delete [] HeapArete;
+			delete [] HeapTriangle;
+
+
+			if (OutSide|| !Gh.subdomains || !Gh.NbSubDomains ) 
+			  { // No geom sub domain
+				long i;
+				if (subdomains) delete [] subdomains;
+				subdomains = new SubDomain[ NbSubDomTot];
+				NbSubDomains=  NbSubDomTot;
+				for ( i=0;i<NbSubDomains;i++) {
+					subdomains[i].head=NULL;
+					subdomains[i].ref=i+1;
+				}
+				long * mark = new long[nbt];
+				for (it=0;it<nbt;it++)
+				 mark[it]=triangles[it].link ? -1 : -2;
+
+				it =0;
+				k = 0;
+				while (it<nbt) {
+					if (mark[it] == -1) {
+						t1 = & triangles[it];
+						t = t1->link;
+						mark[it]=k;
+						subdomains[k].head = t1;
+						do {
+							mark[Number(t)]=k;
+							t=t->link;
+						} while (t!=t1);
+						mark[it]=k++;}
+						//    else if(mark[it] == -2 ) triangles[it].Draw(999);
+						it++;} // end white (it<nbt)
+						if (k!=NbSubDomains){
+							ISSMERROR("k!=NbSubDomains");
+						}
+						if(OutSide) 
+						  {
+							//  to remove all the sub domain by parity adjacents
+							//  because in this case we have only the true boundary edge
+							// so teh boundary is manifold
+							long nbk = NbSubDomains;
+							while (nbk)
+							 for (it=0;it<nbt && nbk ;it++)
+							  for (int na=0;na<3 && nbk ;na++)
+								 {
+								  Triangle *ta = triangles[it].TriangleAdj(na);
+								  long kl = ta ? mark[Number(ta)] : -2;
+								  long kr = mark[it];
+								  if(kr !=kl) {
+									  if (kl >=0 && subdomains[kl].ref <0 && kr >=0 && subdomains[kr].ref>=0)
+										nbk--,subdomains[kr].ref=subdomains[kl].ref-1;
+									  if (kr >=0 && subdomains[kr].ref <0 && kl >=0 && subdomains[kl].ref>=0)
+										nbk--,subdomains[kl].ref=subdomains[kr].ref-1;
+									  if(kr<0 && kl >=0 && subdomains[kl].ref>=0)
+										nbk--,subdomains[kl].ref=-1;
+									  if(kl<0 && kr >=0 && subdomains[kr].ref>=0)
+										nbk--,subdomains[kr].ref=-1;
+								  }
+								 }
+							long  j=0;
+							for ( i=0;i<NbSubDomains;i++)
+							 if((-subdomains[i].ref) %2) { // good 
+								 if(i != j) 
+								  Exchange(subdomains[i],subdomains[j]);
+								 j++;}
+							 else{ 
+								 t= subdomains[i].head;
+								 while (t){
+									 NbOutT++;
+									 t1=t;
+									 t=t->link;
+									 t1->link=0;
+								 }//while (t)
+								}
+							if(verbosity>4) printf("      Number of removes subdomains (OutSideMesh) = %i\n",NbSubDomains-j);
+							NbSubDomains=j;
+						  }
+
+						delete []  mark; 
+
+			  }
+			else
+			  { // find the head for all sub domaine
+				if (Gh.NbSubDomains != NbSubDomains && subdomains)
+				 delete [] subdomains, subdomains=0;
+				if (! subdomains  ) 
+				 subdomains = new SubDomain[ Gh.NbSubDomains];
+				NbSubDomains =Gh.NbSubDomains;
+				long err=0;
+				ReMakeTriangleContainingTheVertex();
+				long * mark = new long[nbt];
+				Edge **GeometricalEdgetoEdge = MakeGeometricalEdgeToEdge();
+
+				for (it=0;it<nbt;it++)
+				 mark[it]=triangles[it].link ? -1 : -2;
+				long inew =0;
+				for (int i=0;i<NbSubDomains;i++) {
+					GeometricalEdge &eg = *Gh.subdomains[i].edge;
+					subdomains[i].ref = Gh.subdomains[i].ref;
+					int ssdlab = subdomains[i].ref;
+					// by carefull is not easy to find a edge create from a GeometricalEdge 
+					// see routine MakeGeometricalEdgeToEdge
+					Edge &e = *GeometricalEdgetoEdge[Gh.Number(eg)];
+					if (&e==NULL){
+						ISSMERROR("&e==NULL");
+					}
+					MeshVertex * v0 =  e(0),*v1 = e(1);
+					Triangle *t  = v0->t;
+					int sens = Gh.subdomains[i].sens;
+					// test if ge and e is in the same sens 
+					if (((eg[0].r-eg[1].r),(e[0].r-e[1].r))<0) sens = -sens ;
+					subdomains[i].sens = sens;
+					subdomains[i].edge = &e;
+					if (!t || !sens){
+						ISSMERROR("!t || !sens");
+					}
+
+					TriangleAdjacent  ta(t,EdgesVertexTriangle[v0->vint][0]);// previous edges
+
+					while (1) {
+						if ( v0 != ta.EdgeVertex(1) ){
+							ISSMERROR("v0 != ta.EdgeVertex(1)");
+						}
+						if (ta.EdgeVertex(0) == v1) { // ok we find the edge
+							if (sens>0)  
+							 subdomains[i].head=t=Adj(ta);
+							else 
+							 subdomains[i].head=t=ta;
+							if(t<triangles || t >= triangles+nbt || t->det < 0 || t->link == 0) {
+								ISSMERROR("bad definition of SubSomain %i",i);
+							}
+							long it = Number(t);
+							if (mark[it] >=0) {
+								break;
+							}
+							if(i != inew) 
+							 Exchange(subdomains[i],subdomains[inew]);
+							inew++;
+							Triangle *tt=t;
+							long kkk=0;
+							do 
+							  {
+								kkk++;
+								if (mark[Number(tt)]>=0){
+									ISSMERROR("mark[Number(tt)]>=0");
+								}
+								mark[Number(tt)]=i;
+								tt=tt->link;
+							  } while (tt!=t);
+							break;
+						}
+						ta = Previous(Adj(ta));         
+						if(t == (Triangle *) ta) {
+							ISSMERROR("bad definition of SubSomain %i",i);
+						}
+					}
+				}
+
+				if (inew < NbSubDomains) {
+					if (verbosity>5) printf("WARNING: %i SubDomains are being removed\n",NbSubDomains-inew);
+					NbSubDomains=inew;}
+
+
+					for (it=0;it<nbt;it++)
+					 if ( mark[it] ==-1 ) 
+					  NbOutT++,triangles[it].link =0;
+					delete [] GeometricalEdgetoEdge;
+					delete [] mark;
+
+			  }
+			NbOutT=0;
+			for (it=0;it<nbt;it++) 
+			 if(!triangles[it].link)  NbOutT++;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::FindTriangleContaining{{{1*/
+	Triangle * Triangles::FindTriangleContaining(const I2 & B,Icoor2 dete[3], Triangle *tstart) const {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/FindTriangleContening)*/
+
+		Triangle * t=0;	
+		int j,jp,jn,jj;
+		if (tstart) t=tstart;
+		else {
+			if (!quadtree){
+				ISSMERROR("no starting triangle provided and no quadtree available");
+			}
+			MeshVertex *a = quadtree->NearestVertex(B.x,B.y) ;
+
+			if (!a || !a->t ) {
+				if (a) {
+					printf("TriangleContaining vertex number %i, another call to ReMakeTriangleContainingTheVertex was required\n", Number(a));
+				}
+				ISSMERROR("problem in Triangles::FindTriangleContaining");
+			}
+			if (a<vertices || a>=vertices+nbv){
+				ISSMERROR("a<vertices || a>=vertices+nbv");
+			}
+			t = a->t;
+			if (t<triangles || t>=triangles+nbt){
+				a->Echo();
+				ISSMERROR("t<triangles || t>=triangles+nbt");
+			}
+		}
+		Icoor2  detop ;
+
+		// number of test triangle 
+		int kkkk =0; 
+
+		// if the initial triangles is outside  
+		while ( t->det < 0){ 
+			int k0=(*t)(0) ?  ((  (*t)(1) ? ( (*t)(2) ? -1 : 2) : 1  )) : 0;
+			if (k0<0){ // k0 the NULL vertex
+				ISSMERROR("k0<0");
+			}
+			int k1=NextVertex[k0],k2=PreviousVertex[k0];
+			dete[k0]=det(B,(*t)[k1],(*t)[k2]);
+			dete[k1]=dete[k2]=-1;     
+			if (dete[k0] > 0) // outside B 
+			 return t; 
+			t = t->TriangleAdj(OppositeEdge[k0]);
+			kkkk++;
+			if (kkkk>=2){
+				ISSMERROR("kkkk>=2");
+			}
+		}
+
+		jj=0;
+		detop = det(*(*t)(VerticesOfTriangularEdge[jj][0]),*(*t)(VerticesOfTriangularEdge[jj][1]),B);
+
+		while(t->det  > 0 ) { 
+			kkkk++;
+			if (kkkk>=2000){
+				ISSMERROR("kkkk>=2000");
+			}
+			j= OppositeVertex[jj];
+			dete[j] = detop;  //det(*b,*s1,*s2);
+			jn = NextVertex[j];
+			jp = PreviousVertex[j];
+			dete[jp]= det(*(*t)(j),*(*t)(jn),B);
+			dete[jn] = t->det-dete[j] -dete[jp];
+
+			// count the number k of  dete <0
+			int k=0,ii[3];
+			if (dete[0] < 0 ) ii[k++]=0; 
+			if (dete[1] < 0 ) ii[k++]=1;
+			if (dete[2] < 0 ) ii[k++]=2;
+			// 0 => ok
+			// 1 => go in way 1
+			// 2 => two way go in way 1 or 2 randomly
+
+			if (k==0) break;
+			if (k == 2 && BinaryRand()) Exchange(ii[0],ii[1]);
+			if ( k>=3){
+				ISSMERROR("k>=3");
+			}
+			TriangleAdjacent t1 = t->Adj(jj=ii[0]);
+			if ((t1.det() < 0 ) && (k == 2))
+			 t1 = t->Adj(jj=ii[1]);
+			t=t1;
+			j=t1;// for optimisation we now the -det[OppositeVertex[j]];
+			detop = -dete[OppositeVertex[jj]];
+			jj = j;
+		}
+
+		if (t->det<0) // outside triangle 
+		 dete[0]=dete[1]=dete[2]=-1,dete[OppositeVertex[jj]]=detop;
+		//  NbOfTriangleSearchFind += kkkk;  
+		return t;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::GeomToTriangles0{{{1*/
+	void Triangles::GeomToTriangles0(long inbvx,BamgOpts* bamgopts){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/GeomToTriangles0)*/
+
+		/*Generate mesh from geometry*/
+
+		Gh.NbRef++;// add a ref to GH
+
+		int i,j,k;
+		int NbOfCurves=0,NbNewPoints,NbEdgeCurve;
+		double lcurve,lstep,s;
+		const int MaxSubEdge = 10;
+
+		R2 AB;
+		GeometricalVertex *a,*b;
+		MeshVertex *va,*vb;
+		GeometricalEdge * e;
+
+		/*Get options*/
+		int verbose=bamgopts->verbose;
+
+		//initialize this
+		if (verbose>3) printf("      Generating Boundary vertices\n");
+		PreInit(inbvx);
+		nbv=0;
+		NbVerticesOnGeomVertex=0;
+		NbVerticesOnGeomEdge=0;
+
+		//build background mesh flag (1 if background, else 0)
+		int  background=(&BTh != this);
+
+		//Compute number of vertices on geometrical vertex
+		for (i=0;i<Gh.nbv;i++){
+			if (Gh[i].Required() && Gh[i].IsThe()) NbVerticesOnGeomVertex++;
+		}
+
+		//initialize VerticesOnGeomVertex
+		VerticesOnGeomVertex = new VertexOnGeom[NbVerticesOnGeomVertex];  
+		if( NbVerticesOnGeomVertex >= nbvx) {
+			ISSMERROR("too many vertices on geometry: %i >= %i",NbVerticesOnGeomVertex,nbvx);
+		}
+
+		//Add all the geometrical vertices to the mesh
+		nbv=0;
+		for (i=0;i<Gh.nbv;i++){
+			/* Add vertex only if required and not duplicate 
+			 * (IsThe is a method of GeometricalVertex that checks
+			 * that we are taking into acount only one vertex is
+			 * 2 vertices are superimposed) */
+			if (Gh[i].Required() && Gh[i].IsThe()) {//Gh  vertices Required
+
+				//Add the vertex (provided that nbv<nbvx)
+				if (nbv<nbvx){
+					vertices[nbv]=Gh[i];
+				}
+				else{
+					ISSMERROR("Maximum number of vertices (nbvx = %i) too small",nbvx);
+				}
+				
+				//Add pointer from geometry (Gh) to vertex from mesh (Th)
+				Gh[i].to=vertices+nbv;
+
+				//Build VerticesOnGeomVertex for current point
+				VerticesOnGeomVertex[nbv]= VertexOnGeom(*Gh[i].to,Gh[i]);
+
+				//nbv increment
+				nbv++;
+			}
+		}
+
+		//check that edges has been allocated
+		if (edges){
+			ISSMERROR("edges is empty");
+		}
+
+		/* Now we are going to create the first edges corresponding
+		 * to the one present in the geometry provided.
+		 * We proceed in 2 steps
+		 *  -step 1: we count all the edges
+		 *           we allocate the number of edges at the end of step 1
+		 *  -step 2: the edges are created */
+		for (int step=0;step<2;step++){
+
+			//initialize number of edges and number of edges max
+			long nbex=0;
+			nbe=0;
+			long NbVerticesOnGeomEdge0=NbVerticesOnGeomEdge;
+			Gh.UnMarkEdges();	
+			NbOfCurves=0;
+
+			//go through the edges of the geometry
+			for (i=0;i<Gh.nbe;i++) {
+
+				//ei = current Geometrical edge
+				GeometricalEdge &ei=Gh.edges[i];   
+
+				for(int j=0;j<2;j++) {
+
+					/*The first time, no edge is marked but this might change during the loop*/
+					if (!ei.Mark() && ei[j].Required()){ 
+
+						long  nbvend=0;
+						Edge* PreviousNewEdge=NULL;
+
+						lstep = -1;
+
+						/*If Edge is required*/
+						if(ei.Required()){
+							//do not create internal points if required (take it as is)
+							if (j==0){
+								if(step==0) nbe++;
+								else{ 
+									e=&ei;
+									a=ei(0)->The();
+									b=ei(1)->The();
+
+									//check that edges has been allocated
+									if (!edges){
+										ISSMERROR("edges has not been allocated...");
+									}
+									edges[nbe].v[0]=a->to;
+									edges[nbe].v[1]=b->to;;
+									edges[nbe].ref = e->ref;
+									edges[nbe].onGeometry = e;
+									edges[nbe].adj[0] = 0;
+									edges[nbe].adj[1] = 0;
+									nbe++;
+								}
+							}
+						}
+
+						/*If Edge is not required: on a curve*/
+						else {
+							for ( int kstep=0;kstep<=step;kstep++){
+								//step=0, do nothing
+								//step=1, compute the length of the curve
+								//step=2  create the points and edge
+								PreviousNewEdge=0;
+								NbNewPoints=0;
+								NbEdgeCurve=0;
+								if (nbvend>=nbvx) ISSMERROR("maximum number of vertices too low! Check the domain outline or increase nbvx");
+								lcurve =0;
+								s = lstep;
+
+								// i = edge number, j=[0;1] vertex number in edge
+
+								k=j;            // k = vertex number in edge (0 or 1)
+								e=&ei;          // e = reference of current edge
+								a=ei(k)->The(); // a = pointer toward the kth vertex of the current edge
+								va = a->to;     // va = pointer toward vertex associated
+								e->SetMark();   // Mark edge
+
+								//if SameGeo We have go to the background geometry 
+								//to find the discretisation of the curve
+								for(;;){ 
+									k = 1-k;
+									b = (*e)(k)->The();// b = pointer toward the other vertex of the current edge
+									AB= b->r - a->r;   // AB = vector of the current edge
+									Metric MA = background ? BTh.MetricAt(a->r) :a->m ;  //Get metric associated to A
+									Metric MB =  background ? BTh.MetricAt(b->r) :b->m ; //Get metric associated to B
+									double ledge = (MA(AB) + MB(AB))/2;                   //Get edge length in metric
+
+									/* We are now creating the edges of the mesh from the
+									 * geometrical edge selected above.
+									 * The edge will be divided according to the metric
+									 * previously computed and cannot be divided more
+									 * than 10 times (MaxSubEdge). */
+
+									//By default, there is only one subedge that is the geometrical edge itself
+									int NbSubEdge = 1;
+
+									//initialize lSubEdge, holding the length of each subedge (cannot be higher than 10)
+									double lSubEdge[MaxSubEdge];
+
+									//Build Subedges according to the edge length
+									//if ledge < 1.5 (between one and 2), take the edge as is
+									if (ledge < 1.5) lSubEdge[0] = ledge;
+									//else, divide the edge
+									else {
+										//compute number of subedges (division of the edge)
+										NbSubEdge = Min( MaxSubEdge, (int) (ledge +0.5));
+										//A and B are the position of points on the edge
+										R2 A,B;
+										A=a->r;
+										Metric MAs=MA,MBs;
+										ledge=0; 
+										double x =0, xstep= 1./NbSubEdge;
+										for (int kk=0; kk < NbSubEdge; kk++,A=B,MAs=MBs ) {
+											x += xstep;
+											B =  e->F(k ? x : 1-x);
+											MBs= background ? BTh.MetricAt(B) :Metric(1-x, MA, x ,MB);
+											AB = A-B;
+											lSubEdge[kk]= (ledge += (MAs(AB)+MBs(AB))/2);
+										}
+									}
+
+									double lcurveb = lcurve+ ledge ;
+
+									//Now, create corresponding points
+									while (lcurve<=s && s <= lcurveb && nbv < nbvend){
+
+										double ss = s-lcurve;
+
+										/*Find the SubEdge containing ss using Dichotomy*/
+
+										int kk0=-1,kk1=NbSubEdge-1,kkk;
+										double ll0=0,ll1=ledge,llk;
+										while (kk1-kk0>1){
+											if (ss < (llk=lSubEdge[kkk=(kk0+kk1)/2]))
+											 kk1=kkk,ll1=llk;
+											else
+											 kk0=kkk,ll0=llk;
+										}
+										ISSMASSERT(kk1!=kk0);
+
+										double sbb = (ss-ll0  )/(ll1-ll0);
+										double bb = (kk1+sbb)/NbSubEdge, aa=1-bb;
+
+										// new vertex on edge
+										vb = &vertices[nbv++];
+										vb->m = Metric(aa,a->m,bb,b->m);
+										vb->ReferenceNumber = e->ref;
+										vb->DirOfSearch =NoDirOfSearch;
+										double abcisse = k ? bb : aa;
+										vb->r =  e->F( abcisse );
+										VerticesOnGeomEdge[NbVerticesOnGeomEdge++]= VertexOnGeom(*vb,*e,abcisse);        
+
+										// to take into account the direction of the edge
+										s += lstep;
+										edges[nbe].v[0]=va;
+										edges[nbe].v[1]=vb;
+										edges[nbe].ref =e->ref;
+										edges[nbe].onGeometry = e;
+										edges[nbe].adj[0] = PreviousNewEdge;
+										if(PreviousNewEdge) PreviousNewEdge->adj[1]=&edges[nbe];
+										PreviousNewEdge=edges+nbe;
+										nbe++;
+										va = vb;
+									}
+									lcurve = lcurveb;
+									e->SetMark();
+									a=b;
+									if (b->Required() ) break;
+									int kprev=k;
+									k = e->DirAdj[kprev];// next vertices
+									e = e->Adj[kprev];
+									ISSMASSERT(e);
+								}// for(;;)
+								vb = b->to;
+								NbEdgeCurve = Max((long) (lcurve +0.5), (long) 1);
+								NbNewPoints = NbEdgeCurve-1;
+								if(!kstep){
+									NbVerticesOnGeomEdge0 += NbNewPoints;
+									NbOfCurves++;
+								}
+								nbvend=nbv+NbNewPoints; 
+								lstep = lcurve / NbEdgeCurve;
+							}// end of curve --
+							if (edges) { // last edges of the curves 
+								edges[nbe].v[0]=va;
+								edges[nbe].v[1]=vb;
+								edges[nbe].ref = e->ref;
+								edges[nbe].onGeometry = e;
+								edges[nbe].adj[0] = PreviousNewEdge;
+								edges[nbe].adj[1] = 0;
+								if(PreviousNewEdge) PreviousNewEdge->adj[1] = & edges[nbe];
+								nbe++;
+							}
+							else nbe += NbEdgeCurve;
+						} // end on  curve ---
+					}
+				}
+			} // for (i=0;i<nbe;i++)
+			if(!step) {
+				if (edges){
+					ISSMERROR("edges");
+				}
+				if (VerticesOnGeomEdge){
+					ISSMERROR("VerticesOnGeomEdge");
+				}
+				edges = new Edge[nbex=nbe];
+				if(NbVerticesOnGeomEdge0)
+				 VerticesOnGeomEdge = new VertexOnGeom[NbVerticesOnGeomEdge0];
+				if (!VerticesOnGeomEdge && NbVerticesOnGeomEdge0!=0){
+					ISSMERROR("!VerticesOnGeomEdge && NbVerticesOnGeomEdge0!=0");
+				}
+				// do the vertex on a geometrical vertex
+				NbVerticesOnGeomEdge0 = NbVerticesOnGeomEdge;       
+			}
+			else if (NbVerticesOnGeomEdge != NbVerticesOnGeomEdge0){
+				ISSMERROR("NbVerticesOnGeomEdge != NbVerticesOnGeomEdge0");
+			}
+		}
+
+		//Insert points inside existing triangles
+		if (verbose>4) printf("      -- current number of vertices = %i\n",nbv);
+		if (verbose>3) printf("      Creating initial Constrained Delaunay Triangulation...\n");
+		if (verbose>3) printf("         Inserting boundary points\n");
+		Insert();
+
+		//Force the boundary
+		if (verbose>3) printf("         Forcing boundaries\n");
+		ForceBoundary();
+
+		//Extract SubDomains
+		if (verbose>3) printf("         Extracting subdomains\n");
+		FindSubDomain();
+
+		if (verbose>3) printf("      Inserting internal points\n");
+		NewPoints(*this,bamgopts,0) ;
+		if (verbose>4) printf("      -- current number of vertices = %i\n",nbv);
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::GeomToTriangles1{{{1*/
+	void Triangles::GeomToTriangles1(long inbvx,BamgOpts* bamgopts,int KeepVertices){ 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/GeomToTriangles1)*/
+
+		/*Get options*/
+		int verbose=bamgopts->verbose;
+
+		Gh.NbRef++;// add a ref to Gh
+
+		/************************************************************************* 
+		// methode in 2 step
+		// 1 - compute the number of new edge to allocate
+		// 2 - construct the edge
+remark: 
+in this part we suppose to have a background mesh with the same
+geometry 
+
+To construct the discretisation of the new mesh we have to 
+rediscretize the boundary of background Mesh 
+because we have only the pointeur from the background mesh to the geometry.
+We need the abcisse of the background mesh vertices on geometry
+so a vertex is 
+0 on GeometricalVertex ;
+1 on GeometricalEdge + abcisse
+2 internal 
+		 *************************************************************************/
+
+		//Check that background mesh and current mesh do have the same geometry
+		ISSMASSERT(&BTh.Gh==&Gh);
+		BTh.NbRef++; // add a ref to BackGround Mesh
+
+		//Initialize new mesh
+		PreInit(inbvx);
+		BTh.SetVertexFieldOn();
+		int* bcurve = new int[Gh.NbOfCurves]; // 
+
+		// we have 2 ways to make the loop 
+		// 1) on the geometry 
+		// 2) on the background mesh
+		//  if you do the loop on geometry, we don't have the pointeur on background,
+		//  and if you do the loop in background we have the pointeur on geometry
+		// so do the walk on  background
+		//  long NbVerticesOnGeomVertex;
+		//  VertexOnGeom * VerticesOnGeomVertex;  
+		//  long NbVerticesOnGeomEdge;
+		//  VertexOnGeom * VerticesOnGeomEdge;
+
+		NbVerticesOnGeomVertex=0;
+		NbVerticesOnGeomEdge=0;
+
+		/*STEP 1 copy of Required vertices*/
+
+		int i; 
+		for (i=0;i<Gh.nbv;i++) if (Gh[i].Required()) NbVerticesOnGeomVertex++;
+		if( NbVerticesOnGeomVertex >= nbvx) { ISSMERROR("too many vertices on geometry: %i >= %i",NbVerticesOnGeomVertex,nbvx);}
+
+		VerticesOnGeomVertex = new VertexOnGeom[  NbVerticesOnGeomVertex];
+		VertexOnBThVertex    = new VertexOnVertex[NbVerticesOnGeomVertex];
+
+		//At this point there is NO vertex but vertices should be have been allocated by PreInit
+		ISSMASSERT(vertices);
+		for (i=0;i<Gh.nbv;i++){
+			if (Gh[i].Required()) {//Gh vertices Required
+				vertices[nbv]  =Gh[i];
+				vertices[nbv].i=I2(0,0);
+				Gh[i].to = vertices + nbv;// save Geom -> Th
+				VerticesOnGeomVertex[nbv]= VertexOnGeom(vertices[nbv],Gh[i]);
+				nbv++;
+			}
+			else Gh[i].to=0;
+		} 
+		for (i=0;i<BTh.NbVerticesOnGeomVertex;i++){ 
+			VertexOnGeom &vog=BTh.VerticesOnGeomVertex[i];
+			if (vog.IsRequiredVertex()){
+				GeometricalVertex* gv=vog;
+				MeshVertex *bv = vog;
+				ISSMASSERT(gv->to); // use of Geom -> Th
+				VertexOnBThVertex[NbVertexOnBThVertex++]=VertexOnVertex(gv->to,bv);
+				gv->to->m = bv->m; // for taking the metrix of the background mesh
+			}
+		}
+		ISSMASSERT(NbVertexOnBThVertex==NbVerticesOnGeomVertex);
+
+		/*STEP 2: reseed bounday edges*/
+
+		//  find the begining of the curve in BTh
+		Gh.UnMarkEdges();	
+		int bfind=0;
+		for (int i=0;i<Gh.NbOfCurves;i++) bcurve[i]=-1; 
+		for (int iedge=0;iedge<BTh.nbe;iedge++){      
+			Edge &ei = BTh.edges[iedge];
+			for(int je=0;je<2;je++){ // for the 2 extremities
+
+				// If one of the vertex is required we are in a new curve
+				if (ei[je].onGeometry->IsRequiredVertex()){ 
+
+					//Get curve number
+					int nc=ei.onGeometry->CurveNumber;
+					
+					//BUG FIX from original bamg
+					//Check that we are on the same edge and right extrimity
+					if(ei.onGeometry==Gh.curves[nc].be  && (GeometricalVertex *)*ei[je].onGeometry==&(*Gh.curves[nc].be)[Gh.curves[nc].kb]){
+						bcurve[nc]=iedge*2+je;
+						bfind++;	
+					}
+					else if ((ei.onGeometry==Gh.curves[nc].ee  && (GeometricalVertex *)*ei[je].onGeometry==&(*Gh.curves[nc].ee)[Gh.curves[nc].ke]) && bcurve[nc]==-1){
+						bcurve[nc]=iedge*2+je;
+						bfind++;	
+					}
+				}
+			}
+		} 
+		if (bfind!=Gh.NbOfCurves){
+			ISSMERROR("problem generating number of curves (Gh.NbOfCurves=%i bfind=%i)",Gh.NbOfCurves,bfind);
+		}
+
+		// method in 2 + 1 step 
+		//  0.0) compute the length and the number of vertex to do allocation
+		//  1.0) recompute the length
+		//  1.1) compute the  vertex 
+		long nbex=0,NbVerticesOnGeomEdgex=0;
+		for (int step=0; step <2;step++){
+
+			long NbOfNewPoints=0;
+			long NbOfNewEdge=0;
+			long iedge;
+			Gh.UnMarkEdges();	
+			double L=0;
+
+			for (int icurve=0;icurve<Gh.NbOfCurves;icurve++){ 
+
+				iedge=bcurve[icurve]/2;
+				int jedge=bcurve[icurve]%2;
+				if(!Gh.curves[icurve].master) continue; // we skip all equi curve
+				Edge &ei = BTh.edges[iedge];
+				// warning: ei.on->Mark() can be change in
+				// loop for(jedge=0;jedge<2;jedge++) 
+			
+				double Lstep=0,Lcurve=0;    // step between two points   (phase==1) 
+				long NbCreatePointOnCurve=0;// Nb of new points on curve (phase==1) 
+
+				for(int phase=0;phase<=step;phase++){
+
+					for(Curve * curve= Gh.curves+icurve;curve;curve= curve->next){
+
+						int icurveequi= Gh.Number(curve);
+
+						if( phase==0 &&  icurveequi!=icurve)  continue;
+
+						int   k0=jedge,k1;
+						Edge* pe=  BTh.edges+iedge;
+						int   iedgeequi=bcurve[icurveequi]/2;
+						int   jedgeequi=bcurve[icurveequi]%2;
+
+						int k0equi=jedgeequi,k1equi;		  
+						Edge * peequi= BTh.edges+iedgeequi;
+						GeometricalEdge *ongequi = peequi->onGeometry;
+
+						double sNew=Lstep;// abscisse of the new points (phase==1) 
+						L=0;// length of the curve
+						long i=0;// index of new points on the curve
+						register GeometricalVertex * GA0 = *(*peequi)[k0equi].onGeometry;
+						MeshVertex *A0;
+						A0 = GA0->to;  // the vertex in new mesh
+						MeshVertex *A1;
+						VertexOnGeom *GA1;
+						Edge* PreviousNewEdge = 0;
+
+						// New Curve phase 
+						ISSMASSERT(A0-vertices>=0 && A0-vertices<nbv);
+						if(ongequi->Required()){
+							GeometricalVertex *GA1 = *(*peequi)[1-k0equi].onGeometry;
+							A1 = GA1->to;  //
+						}       
+						else {
+							for(;;){
+								Edge &ee=*pe; 
+								Edge &eeequi=*peequi; 
+								k1 = 1-k0; // next vertex of the edge 
+								k1equi= 1 - k0equi;
+								ISSMASSERT(pe && ee.onGeometry);
+								ee.onGeometry->SetMark();
+								MeshVertex & v0=ee[0], & v1=ee[1];
+								R2 AB=(R2)v1-(R2)v0;
+								double L0=L,LAB;
+								LAB=LengthInterpole(v0.m,v1.m,AB);
+								L+= LAB;
+
+								if (phase){
+									// computation of the new points for the given curve
+									while ((i!=NbCreatePointOnCurve) && sNew<=L) { 
+
+										//some checks
+										ISSMASSERT(sNew>=L0);
+										ISSMASSERT(LAB);
+										ISSMASSERT(vertices && nbv<nbvx);
+										ISSMASSERT(edges && nbe<nbex);
+										ISSMASSERT(VerticesOnGeomEdge && NbVerticesOnGeomEdge<NbVerticesOnGeomEdgex);
+
+										// new vertex on edge
+										A1=vertices+nbv++;
+										GA1=VerticesOnGeomEdge+NbVerticesOnGeomEdge;
+										Edge* e = edges + nbe++;
+										double se= (sNew-L0)/LAB;
+										if (se<0 || se>=1.000000001){
+											ISSMERROR("Problem creating point on a boundary: se=%g should be in [0 1]",se);
+										}
+										se = abscisseInterpole(v0.m,v1.m,AB,se,1);
+										if (se<0 || se>1){
+											ISSMERROR("Problem creating point on a boundary: se=%g should be in [0 1]",se);
+										}
+										se = k1         ? se : 1. - se;
+										se = k1==k1equi ? se : 1. - se;
+										VertexOnBThEdge[NbVerticesOnGeomEdge++] = VertexOnEdge(A1,&eeequi,se); // save 
+										ongequi=Gh.ProjectOnCurve(eeequi,se,*A1,*GA1); 
+										A1->ReferenceNumber = eeequi.ref;
+										A1->DirOfSearch =NoDirOfSearch;
+										e->onGeometry = ongequi;
+										e->v[0]=A0;
+										e->v[1]=A1;
+										e->ref = eeequi.ref;
+										e->adj[0]=PreviousNewEdge;
+
+										if (PreviousNewEdge) PreviousNewEdge->adj[1]=e;
+										PreviousNewEdge=e;
+										A0=A1;
+										sNew += Lstep;
+										if (++i== NbCreatePointOnCurve) break;
+									}
+								}
+
+								//some checks
+								ISSMASSERT(ee.onGeometry->CurveNumber==ei.onGeometry->CurveNumber);
+								if (ee[k1].onGeometry->IsRequiredVertex()) {
+									ISSMASSERT(eeequi[k1equi].onGeometry->IsRequiredVertex());
+									register GeometricalVertex * GA1 = *eeequi[k1equi].onGeometry;
+									A1=GA1->to;// the vertex in new mesh
+									ISSMASSERT(A1-vertices>=0 && A1-vertices<nbv);
+									break;
+								}
+								if (!ee.adj[k1]) {
+									ISSMERROR(" adj edge %i, nbe=%i, Gh.vertices=%i",BTh.Number(ee),nbe,Gh.vertices);
+								}
+								pe = ee.adj[k1]; // next edge
+								k0 = pe->Intersection(ee); 
+								peequi= eeequi.adj[k1equi];  // next edge
+								k0equi=peequi->Intersection(eeequi);            
+							}// for(;;) end of the curve
+						}
+
+
+						if (phase){ // construction of the last edge
+							Edge* e=edges + nbe++;
+							e->onGeometry  = ongequi;
+							e->v[0]=A0;
+							e->v[1]=A1;
+							e->ref = peequi->ref;
+							e->adj[0]=PreviousNewEdge;
+							e->adj[1]=0;
+							if (PreviousNewEdge) PreviousNewEdge->adj[1]=e;
+							PreviousNewEdge = e;
+
+							ISSMASSERT(i==NbCreatePointOnCurve);
+						}
+					} //  end loop on equi curve 
+
+					if (!phase)  { // 
+						long NbSegOnCurve = Max((long)(L+0.5),(long) 1);// nb of seg
+						Lstep = L/NbSegOnCurve; 
+						Lcurve = L;
+						NbCreatePointOnCurve = NbSegOnCurve-1;
+
+						for(Curve * curve= Gh.curves+icurve;curve;curve= curve->next){
+							NbOfNewEdge += NbSegOnCurve;
+							NbOfNewPoints += NbCreatePointOnCurve;
+						}
+					}
+				}
+			}//  end of curve loop 
+
+			//Allocate memory
+			if(step==0){
+				if(nbv+NbOfNewPoints > nbvx) {
+					ISSMERROR("too many vertices on geometry: %i >= %i",nbv+NbOfNewPoints,nbvx);
+				}
+				edges = new Edge[NbOfNewEdge];
+				nbex = NbOfNewEdge;
+				if(NbOfNewPoints) {
+					VerticesOnGeomEdge    = new VertexOnGeom[NbOfNewPoints];
+					NbVertexOnBThEdge     = NbOfNewPoints;
+					VertexOnBThEdge       = new  VertexOnEdge[NbOfNewPoints];
+					NbVerticesOnGeomEdgex = NbOfNewPoints;
+				}
+				NbOfNewPoints =0;
+				NbOfNewEdge = 0;
+			}
+		}
+		ISSMASSERT(nbe!=0);
+		delete [] bcurve;
+
+		//Insert points inside existing triangles
+		if (verbose>4) printf("      -- current number of vertices = %i\n",nbv);
+		if (verbose>3) printf("      Creating initial Constrained Delaunay Triangulation...\n");
+		if (verbose>3) printf("         Inserting boundary points\n");
+		Insert();
+
+		//Force the boundary
+		if (verbose>3) printf("         Forcing boundaries\n");
+		ForceBoundary();
+
+		//Extract SubDomains
+		if (verbose>3) printf("         Extracting subdomains\n");
+		FindSubDomain();
+
+		if (verbose>3) printf("      Inserting internal points\n");
+		NewPoints(BTh,bamgopts,KeepVertices) ;
+		if (verbose>4) printf("      -- current number of vertices = %i\n",nbv);
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::Insert{{{1*/
+	void Triangles::Insert() {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Insert)*/
+
+		/*Insert points in the existing Geometry*/
+
+		//Intermediary
+		int i;
+
+		/*Get options*/
+		long int verbosity=2;
+
+		//Display info
+		if (verbosity>2) printf("   Insert initial %i vertices\n",nbv);
+
+		//Compute integer coordinates and determinants for the existing vertices (from Geometry)
+		SetIntCoor();
+
+		/*Now we want to build a list (ordre) of the vertices in a random
+		 * order. To do so, we use the following method:
+		 *
+		 * From an initial k0 in [0 nbv[ random (vertex number)
+		 * the next k (vertex number) is computed using a big
+		 * prime number (PN>>nbv) following:
+		 *
+		 * k_{i+1} = k_i + PN  [nbv]
+		 *
+		 * let's show that:
+		 *
+		 *   for all j in [0 nbv[, ∃! i in [0 nbv[ such that k_i=j
+		 *
+		 * Let's assume that there are 2 distinct j1 and j2 such that
+		 * k_j1 = k_j2
+		 *
+		 * This means that
+		 *  
+		 *  k0+j1*PN = k0+j2*PN [nbv]
+		 *  (j1-j2)*PN =0       [nbv]
+		 * since PN is a prime number larger than nbv, and nbv!=1
+		 *  j1-j2=0             [nbv]
+		 * BUT
+		 *  j1 and j2 are in [0 nbv[ which is impossible.
+		 *
+		 *  We hence have built a random list of nbv elements of
+		 *  [0 nbv[ all distincts*/
+		for (i=0;i<nbv;i++) ordre[i]= &vertices[i] ;
+		const long PrimeNumber= BigPrimeNumber(nbv) ;
+		int   k0=rand()%nbv; 
+		for (int is3=0; is3<nbv; is3++){
+			ordre[is3]= &vertices[k0=(k0+PrimeNumber)%nbv];
+		}
+
+		/*Modify ordre such that the first 3 vertices form a triangle*/
+
+		//get first vertex i such that [0,1,i] are not aligned
+		for (i=2 ; det( ordre[0]->i, ordre[1]->i, ordre[i]->i ) == 0;){
+			//if i is higher than nbv, it means that all the determinants are 0,
+			//all vertices are aligned!
+			if  ( ++i >= nbv) {
+				ISSMERROR("all the vertices are aligned");
+			}
+		}
+		// exchange i et 2 in "ordre" so that
+		// the first 3 vertices are not aligned (real triangle)
+		Exchange(ordre[2], ordre[i]);
+
+		/*Take the first edge formed by the first two vertices and build
+		 * the initial simple mesh from this edge and 2 boundary triangles*/
+
+		MeshVertex *  v0=ordre[0], *v1=ordre[1];
+
+		nbt = 2;
+		triangles[0](0) = NULL; //infinite vertex
+		triangles[0](1) = v0;
+		triangles[0](2) = v1;
+		triangles[1](0) = NULL;//infinite vertex
+		triangles[1](2) = v0;
+		triangles[1](1) = v1;
+
+		//Build adjacence
+		const int e0 = OppositeEdge[0];
+		const int e1 = NextEdge[e0];
+		const int e2 = PreviousEdge[e0];
+		triangles[0].SetAdj2(e0, &triangles[1] ,e0);
+		triangles[0].SetAdj2(e1, &triangles[1] ,e2);
+		triangles[0].SetAdj2(e2, &triangles[1] ,e1);
+
+		triangles[0].det = -1;  //boundary triangle: det = -1
+		triangles[1].det = -1;  //boundary triangle: det = -1
+
+		triangles[0].SetTriangleContainingTheVertex();
+		triangles[1].SetTriangleContainingTheVertex();
+
+		triangles[0].link=&triangles[1];
+		triangles[1].link=&triangles[0];
+
+		//build quadtree
+		if (!quadtree)  quadtree = new QuadTree(this,0);
+		quadtree->Add(*v0);
+		quadtree->Add(*v1);
+
+		/*Now, add the vertices One by One*/
+
+		long NbSwap=0;
+		if (verbosity>3) printf("   Begining of insertion process...\n");
+
+		for (int icount=2; icount<nbv; icount++) {
+
+			//Get new vertex
+			MeshVertex *newvertex=ordre[icount];
+
+			//Find the triangle in which newvertex is located
+			Icoor2 dete[3];
+			Triangle* tcvi = FindTriangleContaining(newvertex->i,dete); //(newvertex->i = integer coordinates)
+
+			//Add newvertex to the quadtree
+			quadtree->Add(*newvertex); 
+
+			//Add newvertex to the existing mesh
+			AddVertex(*newvertex,tcvi,dete);
+
+			//Make the mesh Delaunay around newvertex by swaping the edges
+			NbSwap += newvertex->Optim(1,0);
+		}
+
+		//Display info
+		if (verbosity>3) {
+			printf("      NbSwap of insertion: %i\n",NbSwap);
+			printf("      NbSwap/nbv:          %i\n",NbSwap/nbv);
+		}
+
+#ifdef NBLOOPOPTIM
+
+		k0 = rand()%nbv ; 
+		for (int is4=0; is4<nbv; is4++) 
+		 ordre[is4]= &vertices[k0 = (k0 + PrimeNumber)% nbv];
+
+		for(int Nbloop=0;Nbloop<NBLOOPOPTIM;Nbloop++){
+			long  NbSwap = 0;
+			for (int is1=0; is1<nbv; is1++) 
+			 NbSwap += ordre[is1]->Optim(0,0);
+			if (verbosity>3) {
+				printf("      Optim Loop: %i\n",Nbloop);
+				printf("      NbSwap/nbv:          %i\n",NbSwap/nbv);
+			}
+			if(!NbSwap) break;
+		}
+		ReMakeTriangleContainingTheVertex(); 
+		// because we break the TriangleContainingTheVertex
+#endif
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::InsertNewPoints{{{1*/
+	long Triangles::InsertNewPoints(long nbvold,long & NbTSwap) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/InsertNewPoints)*/
+
+		long int verbosity=0;
+		double seuil= 1.414/2 ;// for two close point 
+		long i;
+		long NbSwap=0;
+		Icoor2 dete[3];
+
+		//number of new points
+		const long nbvnew=nbv-nbvold;
+
+		//display info if required
+		if (verbosity>5) printf("      Try to Insert %i new points\n",nbvnew);
+
+		//return if no new points
+		if (!nbvnew) return 0; 
+
+		/*construction of a random order*/
+		const long PrimeNumber= BigPrimeNumber(nbv)  ;
+		//remainder of the division of rand() by nbvnew
+		long k3 = rand()%nbvnew;
+		//loop over the new points
+		for (int is3=0; is3<nbvnew; is3++){
+			register long j=nbvold +(k3 = (k3+PrimeNumber)%nbvnew);
+			register long i=nbvold+is3; 
+			ordre[i]= vertices + j;
+			ordre[i]->ReferenceNumber=i;
+		}
+
+		// for all the new point
+		long iv=nbvold;
+		for (i=nbvold;i<nbv;i++){
+			MeshVertex &vi=*ordre[i];
+			vi.i=toI2(vi.r);
+			vi.r=toR2(vi.i);
+			double hx,hy;
+			vi.m.Box(hx,hy);
+			Icoor1 hi=(Icoor1) (hx*coefIcoor),hj=(Icoor1) (hy*coefIcoor);
+			if (!quadtree->ToClose(vi,seuil,hi,hj)){
+				// a good new point 
+				MeshVertex &vj = vertices[iv];
+				long  j=vj.ReferenceNumber; 
+				if (&vj!=ordre[j]){
+					ISSMERROR("&vj!= ordre[j]");
+				}
+				if(i!=j){ 
+					Exchange(vi,vj);
+					Exchange(ordre[j],ordre[i]);
+				}
+				vj.ReferenceNumber=0; 
+				Triangle *tcvj=FindTriangleContaining(vj.i,dete);
+				if (tcvj && !tcvj->link){
+					tcvj->Echo();
+					ISSMERROR("problem inserting point in InsertNewPoints (tcvj=%p and tcvj->link=%i)",tcvj,tcvj->link);
+				}
+				quadtree->Add(vj);
+				AddVertex(vj,tcvj,dete);
+				NbSwap += vj.Optim(1);          
+				iv++;
+			}
+		} 
+		if (verbosity>3) {
+			printf("         number of new points: %i\n",iv);
+			printf("         number of to close (?) points: %i\n",nbv-iv);
+			printf("         number of swap after: %i\n",NbSwap);
+		}
+		nbv = iv;
+
+		for (i=nbvold;i<nbv;i++) NbSwap += vertices[i].Optim(1);  
+		if (verbosity>3) printf("   NbSwap=%i\n",NbSwap);
+
+		NbTSwap +=  NbSwap ;
+		return nbv-nbvold;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::MakeGeometricalEdgeToEdge{{{1*/
+	Edge** Triangles::MakeGeometricalEdgeToEdge() {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/MakeGeometricalEdgeToEdge)*/
+
+		if (!Gh.nbe){
+			ISSMERROR("!Gh.nbe");
+		}
+		Edge **e= new (Edge* [Gh.nbe]);
+
+		long i;
+		for ( i=0;i<Gh.nbe ; i++)
+		 e[i]=NULL;
+		for ( i=0;i<nbe ; i++) 
+		  { 
+			Edge * ei = edges+i;
+			GeometricalEdge *onGeometry = ei->onGeometry; 
+			e[Gh.Number(onGeometry)] = ei;    
+		  }
+		for ( i=0;i<nbe ; i++) 
+		 for (int ii=0;ii<2;ii++) { 
+			 Edge * ei = edges+i;
+			 GeometricalEdge *onGeometry = ei->onGeometry;
+			 int j= ii;
+			 while (!(*onGeometry)[j].Required()) { 
+				 Adj(onGeometry,j); // next geom edge
+				 j=1-j;
+				 if (e[Gh.Number(onGeometry)])  break; // optimisation
+				 e[Gh.Number(onGeometry)] = ei; 
+			 }
+		 }
+
+		int kk=0;
+		for ( i=0;i<Gh.nbe ; i++){
+			if (!e[i]){
+				kk++;
+				if(kk<10) printf("BUG: the geometrical edge %i is on no edge curve\n",i);
+			}
+		}
+		if(kk) ISSMERROR("See above");
+
+		return e;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::MakeQuadrangles{{{1*/
+	void Triangles::MakeQuadrangles(double costheta){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/MakeQuadrangles)*/
+
+		long int verbosity=0;
+
+		if (verbosity>2) printf("MakeQuadrangles costheta = %g\n",costheta);
+
+		if (costheta >1) {
+			if (verbosity>5) printf("   do nothing: costheta > 1\n");
+		}
+
+
+			long nbqq = (nbt*3)/2;
+			DoubleAndInt *qq = new DoubleAndInt[nbqq];
+
+			long i,ij;
+			int j;
+			long k=0;
+			for (i=0;i<nbt;i++)
+			 for (j=0;j<3;j++)
+			  if ((qq[k].q=triangles[i].QualityQuad(j))>=costheta)
+				qq[k++].i3j=i*3+j;
+			//  sort  qq
+			HeapSort(qq,k);
+
+			long kk=0;
+			for (ij=0;ij<k;ij++) { 
+				i=qq[ij].i3j/3;
+				j=(int) (qq[ij].i3j%3);
+				// optisamition no float computation  
+				if (triangles[i].QualityQuad(j,0) >=costheta) 
+				 triangles[i].SetHidden(j),kk++;
+			  }
+			NbOfQuad = kk;
+			if (verbosity>2){
+				printf("   number of quadrilaterals    = %i\n",NbOfQuad);
+				printf("   number of triangles         = %i\n",nbt-NbOutT- NbOfQuad*2);
+				printf("   number of outside triangles = %i\n",NbOutT);
+			}
+			delete [] qq;
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::MakeQuadTree{{{1*/
+	void Triangles::MakeQuadTree() {  
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/MakeQuadTree)*/
+
+		long int verbosity=0;
+		if (  !quadtree )  quadtree = new QuadTree(this);
+
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::MaxSubDivision{{{1*/
+	void  Triangles::MaxSubDivision(double maxsubdiv) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/MaxSubDivision)*/
+
+		long int verbosity=0;
+
+		const  double maxsubdiv2 = maxsubdiv*maxsubdiv;
+		if(verbosity>1) printf("   Limit the subdivision of a edges in the new mesh by %g\n",maxsubdiv);
+		// for all the edges 
+		// if the len of the edge is to long 
+		long it,nbchange=0;    
+		double lmax=0;
+		for (it=0;it<nbt;it++){
+			Triangle &t=triangles[it];
+			for (int j=0;j<3;j++){
+				Triangle &tt = *t.TriangleAdj(j);
+				if ( ! &tt ||  it < Number(tt) && ( tt.link || t.link)){
+					MeshVertex &v0 = t[VerticesOfTriangularEdge[j][0]];
+					MeshVertex &v1 = t[VerticesOfTriangularEdge[j][1]];
+					R2 AB= (R2) v1-(R2) v0;
+					Metric M = v0;
+					double l = M(AB,AB);
+					lmax = Max(lmax,l);
+					if(l> maxsubdiv2){
+					  R2 AC = M.Orthogonal(AB);// the ortogonal vector of AB in M
+						double lc = M(AC,AC);
+						D2xD2 Rt(AB,AC);// Rt.x = AB , Rt.y = AC;
+						D2xD2 Rt1(Rt.inv());
+						D2xD2 D(maxsubdiv2,0,0,lc);
+						D2xD2 MM = Rt1*D*Rt1.t();
+						v0.m =  M = Metric(MM.x.x,MM.y.x,MM.y.y);
+						nbchange++;
+					}
+					M = v1;
+					l = M(AB,AB);
+					lmax = Max(lmax,l);
+					if(l> maxsubdiv2){
+					  R2 AC = M.Orthogonal(AB);// the ortogonal vector of AB in M
+						double lc = M(AC,AC);
+						D2xD2 Rt(AB,AC);// Rt.x = AB , Rt.y = AC;
+						D2xD2 Rt1(Rt.inv());
+						D2xD2 D(maxsubdiv2,0,0,lc);
+						D2xD2  MM = Rt1*D*Rt1.t();
+						v1.m =  M = Metric(MM.x.x,MM.y.x,MM.y.y);
+						nbchange++;
+					}
+				}
+			}
+		}
+		if(verbosity>3){
+			printf("      number of metric changes = %i, maximum number of subdivision of a edges before change = %g\n",nbchange,pow(lmax,0.5));
+		}
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::MetricAt{{{1*/
+	Metric Triangles::MetricAt(const R2 & A) const { 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/MetricAt)*/
+
+		I2 a = toI2(A);
+		Icoor2 deta[3];
+		Triangle * t =FindTriangleContaining(a,deta);
+		if (t->det <0) { // outside
+			double ba,bb;
+			TriangleAdjacent edge= CloseBoundaryEdge(a,t,ba,bb) ;
+			return Metric(ba,*edge.EdgeVertex(0),bb,*edge.EdgeVertex(1));}
+		else { // inside
+			double   aa[3];
+			double s = deta[0]+deta[1]+deta[2];
+			aa[0]=deta[0]/s;
+			aa[1]=deta[1]/s;
+			aa[2]=deta[2]/s;
+			return Metric(aa,(*t)[0],(*t)[1],(*t)[2]);
+		}
+	}
+	/*}}}1*/
+/*FUNCTION Triangles::NearestVertex{{{1*/
+MeshVertex* Triangles::NearestVertex(Icoor1 i,Icoor1 j) {
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/NearestVertex)*/
+	return  quadtree->NearestVertex(i,j); 
+} 
+/*}}}1*/
+	/*FUNCTION Triangles::NewPoints{{{1*/
+	void  Triangles::NewPoints(Triangles & Bh,BamgOpts* bamgopts,int KeepVertices){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/NewPoints)*/
+
+		int i,j,k;
+		long NbTSwap=0;
+		long nbtold=nbt;
+		long nbvold=nbv;
+		long Headt=0;
+		long next_t;
+		long* first_np_or_next_t=new long[nbtx];
+		Triangle* t=NULL;
+
+		/*Recover options*/
+		int verbosity=bamgopts->verbose;
+
+		/*First, insert old points if requested*/
+		if (KeepVertices && (&Bh != this) && (nbv+Bh.nbv< nbvx)){
+			if (verbosity>5) printf("         Inserting initial mesh points\n");
+			for (i=0;i<Bh.nbv;i++){ 
+				MeshVertex &bv=Bh[i];
+				if (!bv.onGeometry){
+					vertices[nbv].r   = bv.r;
+					vertices[nbv++].m = bv.m;
+				}
+			}
+			Bh.ReMakeTriangleContainingTheVertex();     
+			InsertNewPoints(nbvold,NbTSwap)   ;            
+		}  
+		else Bh.ReMakeTriangleContainingTheVertex();     
+
+		// generation of the list of next Triangle 
+		for(i=0;i<nbt;i++) first_np_or_next_t[i]=-(i+1);
+		// the next traingle of i is -first_np_or_next_t[i]
+
+		// Big loop (most time consuming)
+		int iter=0;
+		if (verbosity>5) printf("         Big loop\n");
+		do {
+			/*Update variables*/
+			iter++;
+			nbtold=nbt;
+			nbvold=nbv;
+
+			/*We test all triangles*/
+			i=Headt;
+			next_t=-first_np_or_next_t[i];
+			for(t=&triangles[i];i<nbt;t=&triangles[i=next_t],next_t=-first_np_or_next_t[i]){
+
+				//check i
+				if (i<0 || i>=nbt ){
+					ISSMERROR("Index problem in NewPoints (i=%i not in [0 %i])",i,nbt-1);
+				}
+				//change first_np_or_next_t[i]
+				first_np_or_next_t[i] = iter; 
+
+				//Loop over the edges of t
+				for(j=0;j<3;j++){
+					TriangleAdjacent tj(t,j);
+					MeshVertex &vA = *tj.EdgeVertex(0);
+					MeshVertex &vB = *tj.EdgeVertex(1);
+
+					//if t is a boundary triangle, or tj locked, continue
+					if (!t->link)     continue;
+					if (t->det <0)    continue;
+					if (t->Locked(j)) continue;
+
+					TriangleAdjacent tadjj = t->Adj(j);	  
+					Triangle* ta=tadjj;
+
+					//if the adjacent triangle is a boundary triangle, continur
+					if (ta->det<0) continue;	  
+
+					R2 A=vA;
+					R2 B=vB;
+					k=Number(ta);
+
+					//if this edge has already been done, go to next edge of triangle
+					if(first_np_or_next_t[k]==iter) continue;
+
+					lIntTria.SplitEdge(Bh,A,B);
+					lIntTria.NewPoints(vertices,nbv,nbvx);
+				  } // end loop for each edge 
+			  }// for triangle   
+
+			if (!InsertNewPoints(nbvold,NbTSwap)) break;
+			for (i=nbtold;i<nbt;i++) first_np_or_next_t[i]=iter;
+			Headt = nbt; // empty list 
+
+			// for all the triangle containing the vertex i
+			for (i=nbvold;i<nbv;i++){ 
+				MeshVertex*          s  = vertices + i;
+				TriangleAdjacent ta(s->t, EdgesVertexTriangle[s->vint][1]);
+				Triangle*        tbegin= (Triangle*) ta;
+				long kt;
+				do { 
+					kt = Number((Triangle*) ta);
+					if (first_np_or_next_t[kt]>0){
+						first_np_or_next_t[kt]=-Headt;
+						Headt=kt;
+					}
+					if (ta.EdgeVertex(0)!=s){
+						ISSMERROR("ta.EdgeVertex(0)!=s");
+					}
+					ta = Next(Adj(ta));
+				} while ( (tbegin != (Triangle*) ta)); 
+			}
+
+		} while (nbv!=nbvold);
+
+		delete []  first_np_or_next_t;
+
+		long NbSwapf =0,NbSwp;
+
+		NbSwp = NbSwapf;
+		for (i=0;i<nbv;i++)
+		 NbSwapf += vertices[i].Optim(0);
+		NbTSwap +=  NbSwapf ;
+	}
+	/*}}}1*/
+/*FUNCTION Triangles::PreInit{{{1*/
+void Triangles::PreInit(long inbvx) {
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/PreInit)*/
+
+	long int verbosity=0;
+
+	srand(19999999);
+	NbRef=0;
+	//  allocGeometry=0;
+	NbOfTriangleSearchFind =0;
+	NbOfSwapTriangle =0;
+	nbiv=0;
+	nbv=0;
+	nbvx=inbvx;
+	nbt=0;
+	NbOfQuad = 0;
+	nbtx=2*inbvx-2;
+	NbSubDomains=0;
+	NbVertexOnBThVertex=0;
+	NbVertexOnBThEdge=0;
+	VertexOnBThVertex=NULL;
+	VertexOnBThEdge=NULL;
+
+	NbCrackedVertices=0;
+	CrackedVertices  =NULL;  
+	NbCrackedEdges   =0;
+	CrackedEdges     =NULL;  
+	nbe = 0; 
+
+	if (inbvx) {
+		vertices=new MeshVertex[nbvx];
+		if (!vertices){
+			ISSMERROR("!vertices");
+		}
+		ordre=new (MeshVertex* [nbvx]);
+		if (!ordre){
+			ISSMERROR("!ordre");
+		}
+		triangles=new Triangle[nbtx];
+		if (!triangles){
+			ISSMERROR("!triangles");
+		}
+	}
+	else {
+		vertices=NULL;
+		ordre=NULL;
+		triangles=NULL;
+		nbtx=0;
+	} 
+
+	quadtree=NULL;
+	edges=NULL;
+	VerticesOnGeomVertex=NULL;
+	VerticesOnGeomEdge=NULL;
+	NbVerticesOnGeomVertex=0;
+	NbVerticesOnGeomEdge=0;
+	subdomains=NULL;
+	NbSubDomains=0;
+}
+/*}}}1*/
+	/*FUNCTION Triangles::ProjectOnCurve{{{1*/
+	GeometricalEdge*   Triangles::ProjectOnCurve( Edge & BhAB, MeshVertex &  vA, MeshVertex & vB,
+				double theta,MeshVertex & R,VertexOnEdge &  BR,VertexOnGeom & GR) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshQuad.cpp/ProjectOnCurve)*/
+
+		void *pA=0,*pB=0;
+		double tA=0,tB=0;
+		R2 A=vA,B=vB;
+		MeshVertex * pvA=&vA, * pvB=&vB;
+		if (vA.vint == IsVertexOnVertex){
+			pA=vA.onBackgroundVertex;
+		}
+		else if (vA.vint == IsVertexOnEdge){
+			pA=vA.onBackgroundEdge->be;
+			tA=vA.onBackgroundEdge->abcisse;
+		}
+		else {
+			ISSMERROR("ProjectOnCurve On MeshVertex %i forget call to SetVertexFieldOnBTh",BTh.Number(vA));
+		} 
+
+		if (vB.vint == IsVertexOnVertex){
+			pB=vB.onBackgroundVertex;
+		}
+		else if(vB.vint == IsVertexOnEdge){
+			pB=vB.onBackgroundEdge->be;
+			tB=vB.onBackgroundEdge->abcisse;
+		}
+		else {
+			ISSMERROR("ProjectOnCurve On MeshVertex %i forget call to SetVertexFieldOnBTh",BTh.Number(vB));
+		} 
+		Edge * e = &BhAB;
+		if (!pA || !pB || !e){
+			ISSMERROR("!pA || !pB || !e");
+		}
+		// be carefull the back ground edge e is on same geom edge 
+		// of the initiale edge def by the 2 vertex A B;
+		//check Is a background Mesh;   
+		if (e<BTh.edges || e>=BTh.edges+BTh.nbe){
+			ISSMERROR("e<BTh.edges || e>=BTh.edges+BTh.nbe");
+		}
+		// walk on BTh edge 
+		//not finish ProjectOnCurve with BackGround Mesh);
+		// 1 first find a back ground edge contening the vertex A
+		// 2 walk n back gound boundary to find the final vertex B
+
+		if( vA.vint == IsVertexOnEdge) 
+		  { // find the start edge 
+			e = vA.onBackgroundEdge->be;	 
+
+		  } 
+		else if (vB.vint == IsVertexOnEdge) 
+		  {
+			theta = 1-theta;
+			Exchange(tA,tB);
+			Exchange(pA,pB);
+			Exchange(pvA,pvB);
+			Exchange(A,B);
+			e =  vB.onBackgroundEdge->be;
+
+		  } 
+		else{ // do the search by walking 
+			ISSMERROR("case not supported yet");
+		  }
+
+		// find the direction of walking with sens of edge and pA,PB;
+		R2 AB=B-A;
+
+		double cosE01AB = (( (R2) (*e)[1] - (R2) (*e)[0] ) , AB);
+		int kkk=0;
+		int sens = (cosE01AB>0) ? 1 : 0;
+
+		//   double l=0; // length of the edge AB
+		double abscisse = -1;
+
+		for (int cas=0;cas<2;cas++){
+			// 2 times algo:
+			//    1 for computing the length l
+			//    2 for find the vertex 
+			int  iii;
+			MeshVertex  *v0=pvA,*v1; 
+			Edge *neee,*eee;
+			double lg =0; // length of the curve 
+			double te0;
+			// we suppose take the curve's abcisse 
+			for ( eee=e,iii=sens,te0=tA;
+						eee && ((( void*) eee) != pB) && (( void*) (v1=&((*eee)[iii]))) != pB ;
+						neee = eee->adj[iii],iii = 1-neee->Intersection(*eee),eee = neee,v0=v1,te0=1-iii ) { 
+
+				kkk=kkk+1;
+				if (kkk>=100){
+					ISSMERROR("kkk>=100");
+				}
+				if (!eee){
+					ISSMERROR("!eee");
+				}
+				double lg0 = lg;
+				double dp = LengthInterpole(v0->m,v1->m,(R2) *v1 - (R2) *v0);
+				lg += dp;
+				if (cas && abscisse <= lg) { // ok we find the geom edge 
+					double sss  =   (abscisse-lg0)/dp;
+					double thetab = te0*(1-sss)+ sss*iii;
+					if (thetab<0 || thetab>1){
+						ISSMERROR("thetab<0 || thetab>1");
+					}
+					BR = VertexOnEdge(&R,eee,thetab);
+					return  Gh.ProjectOnCurve(*eee,thetab,R,GR);
+				  }
+			  }
+			// we find the end 
+			if (v1 != pvB){
+				if (( void*) v1 == pB)
+				 tB = iii;
+
+				double lg0 = lg;
+				if (!eee){
+					ISSMERROR("!eee");
+				}
+				v1 = pvB;
+				double dp = LengthInterpole(v0->m,v1->m,(R2) *v1 - (R2) *v0);
+				lg += dp;	
+				abscisse = lg*theta;
+				if (abscisse <= lg && abscisse >= lg0 ) // small optimisation we know the lenght because end
+				  { // ok we find the geom edge 
+					double sss  =   (abscisse-lg0)/dp;
+					double thetab = te0*(1-sss)+ sss*tB;
+					if (thetab<0 || thetab>1){
+						ISSMERROR("thetab<0 || thetab>1");
+					}
+					BR = VertexOnEdge(&R,eee,thetab);
+					return  Gh.ProjectOnCurve(*eee,thetab,R,GR);
+				  }
+			  }
+			abscisse = lg*theta;
+
+		  }
+		ISSMERROR("Big bug...");
+		return 0; // just for the compiler 
+	}                  
+	/*}}}1*/
+/*FUNCTION Triangles::ReconstructExistingMesh{{{1*/
+void Triangles::ReconstructExistingMesh(){
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/FillHoleInMesh)*/
+
+	/*This routine reconstruct an existing mesh to make it CONVEX:
+	 * -all the holes are filled
+	 * -concave boundaries are filled
+	 * A convex mesh is required for a lot of operations. This is why every mesh
+	 * goes through this process.
+	 * This routine also generates mesh properties such as adjencies,...
+	 */
+
+	/*Intermediary*/
+	int verbosity=0;
+
+	// generation of the integer coordinate
+
+	// find extrema coordinates of vertices pmin,pmax
+	long i;
+	if(verbosity>2) printf("      Reconstruct mesh of %i vertices\n",nbv); 
+
+	//initialize ordre
+	ISSMASSERT(ordre);
+	for (i=0;i<nbv;i++) ordre[i]=0;
+
+	//Initialize NbSubDomains
+	NbSubDomains =0;
+
+	/* generation of triangles adjacency*/
+
+	//First add existing edges
+	long kk =0;
+	SetOfEdges4* edge4= new SetOfEdges4(nbt*3,nbv);
+	for (i=0;i<nbe;i++){
+		kk=kk+(i==edge4->SortAndAdd(Number(edges[i][0]),Number(edges[i][1])));
+	}
+	if (kk != nbe){ 
+		ISSMERROR("There are %i double edges in the mesh",kk-nbe);
+	}
+
+	//Add edges of all triangles in existing mesh
+	long* st = new long[nbt*3];
+	for (i=0;i<nbt*3;i++) st[i]=-1;
+	for (i=0;i<nbt;i++){
+		for (int j=0;j<3;j++){
+
+			//Add current triangle edge to edge4
+			long k =edge4->SortAndAdd(Number(triangles[i][VerticesOfTriangularEdge[j][0]]),Number(triangles[i][VerticesOfTriangularEdge[j][1]]));
+
+			long invisible=triangles[i].Hidden(j);
+
+			//If the edge has not been added to st, add it
+			if(st[k]==-1) st[k]=3*i+j;
+
+			//If the edge already exists, add adjacency
+			else if(st[k]>=0) {
+				ISSMASSERT(!triangles[i].TriangleAdj(j));
+				ISSMASSERT(!triangles[st[k]/3].TriangleAdj((int) (st[k]%3)));
+
+				triangles[i].SetAdj2(j,triangles+st[k]/3,(int)(st[k]%3));
+				if (invisible) triangles[i].SetHidden(j);
+				if (k<nbe)     triangles[i].SetLocked(j);
+
+				//Make st[k] negative so that it will throw an error message if it is found again
+				st[k]=-2-st[k]; 
+			}
+
+			//An edge belongs to 2 triangles
+			else {
+				ISSMERROR("The edge (%i , %i) belongs to more than 2 triangles",Number(triangles[i][VerticesOfTriangularEdge[j][0]]),Number(triangles[i][VerticesOfTriangularEdge[j][1]]));
+			}
+		}
+	}
+
+	//Display info if required
+	if(verbosity>5) {
+		printf("         info of Mesh:\n");
+		printf("            - number of vertices    = %i \n",nbv); 
+		printf("            - number of triangles   = %i \n",nbt); 
+		printf("            - number of given edges = %i \n",nbe); 
+		printf("            - number of all edges   = %i \n"  ,edge4->nb()); 
+		printf("            - Euler number 1 - nb of holes = %i \n"  ,nbt-edge4->nb()+nbv); 
+	}
+
+	//check the consistency of edge[].adj and the geometrical required vertex
+	long k=0;
+	for (i=0;i<edge4->nb();i++){
+		if (st[i]>=0){ // edge alone 
+			if (i<nbe){
+				long i0=edge4->i(i);
+				ordre[i0] = vertices+i0;
+				long i1=edge4->j(i);
+				ordre[i1] = vertices+i1;
+			}
+			else {
+				k=k+1;
+				if (k<10) {
+					//print only 10 edges
+					printf("Lost boundary edges %i : %i %i\n",i,edge4->i(i),edge4->j(i));
+				}
+				else if (k==10){
+					printf("Other lost boundary edges not shown...\n");
+				}
+			}
+		}
+	}
+	if(k) {
+		ISSMERROR("%i boundary edges (from the geometry) are not defined as mesh edges",k);
+	}
+
+	/* mesh generation with boundary points*/
+	long nbvb=0;
+	for (i=0;i<nbv;i++){ 
+		vertices[i].t=0;
+		vertices[i].vint=0;
+		if (ordre[i]) ordre[nbvb++]=ordre[i];
+	}
+
+	Triangle* savetriangles=triangles;
+	long savenbt=nbt;
+	long savenbtx=nbtx;
+	SubDomain* savesubdomains=subdomains;
+	subdomains=0;
+
+	long  Nbtriafillhole=2*nbvb;
+	Triangle* triafillhole=new Triangle[Nbtriafillhole];
+	triangles = triafillhole;
+
+	nbt=2;
+	nbtx= Nbtriafillhole;
+
+	//Find a vertex that is not aligned with vertices 0 and 1
+	for (i=2;det(ordre[0]->i,ordre[1]->i,ordre[i]->i)==0;) 
+	 if  (++i>=nbvb) {
+		 ISSMERROR("ReconstructExistingMesh: All the vertices are aligned");
+	 }
+	//Move this vertex (i) to the 2d position in ordre
+	Exchange(ordre[2], ordre[i]);
+
+	/*Reconstruct mesh beginning with 2 triangles*/
+	MeshVertex *  v0=ordre[0], *v1=ordre[1];
+
+	triangles[0](0) = NULL; // Infinite vertex
+	triangles[0](1) = v0;
+	triangles[0](2) = v1;
+
+	triangles[1](0) = NULL;// Infinite vertex
+	triangles[1](2) = v0;
+	triangles[1](1) = v1;
+	const int e0 = OppositeEdge[0];
+	const int e1 = NextEdge[e0];
+	const int e2 = PreviousEdge[e0];
+	triangles[0].SetAdj2(e0, &triangles[1] ,e0);
+	triangles[0].SetAdj2(e1, &triangles[1] ,e2);
+	triangles[0].SetAdj2(e2, &triangles[1] ,e1);
+
+	triangles[0].det = -1;  // boundary triangles
+	triangles[1].det = -1;  // boundary triangles
+
+	triangles[0].SetTriangleContainingTheVertex();
+	triangles[1].SetTriangleContainingTheVertex();
+
+	triangles[0].link=&triangles[1];
+	triangles[1].link=&triangles[0];
+
+	if (!quadtree) delete quadtree; //ReInitialise;
+	quadtree = new QuadTree(this,0);
+	quadtree->Add(*v0);
+	quadtree->Add(*v1);
+
+	// vertices are added one by one
+	long NbSwap=0;
+	for (int icount=2; icount<nbvb; icount++) {
+		MeshVertex *vi  = ordre[icount];
+		Icoor2 dete[3];
+		Triangle *tcvi = FindTriangleContaining(vi->i,dete);
+		quadtree->Add(*vi); 
+		AddVertex(*vi,tcvi,dete);
+		NbSwap += vi->Optim(1,1);
+	}
+
+	//enforce the boundary 
+	TriangleAdjacent ta(0,0);
+	long nbloss = 0,knbe=0;
+	for ( i = 0; i < nbe; i++){
+		if (st[i] >=0){ //edge alone => on border
+			MeshVertex &a=edges[i][0], &b=edges[i][1];
+			if (a.t && b.t){
+				knbe++;
+				if (ForceEdge(a,b,ta)<0) nbloss++;
+			}
+		}
+	}
+	if(nbloss) {
+		ISSMERROR("we lost %i existing edges other %i",nbloss,knbe);
+	}
+
+	FindSubDomain(1);
+	// remove all the hole 
+	// remove all the good sub domain
+	long krm =0;
+	for (i=0;i<nbt;i++){
+		if (triangles[i].link){ // remove triangles
+			krm++;
+			for (int j=0;j<3;j++){
+				TriangleAdjacent ta =  triangles[i].Adj(j);
+				Triangle &tta = *(Triangle*)ta;
+				//if edge between remove and not remove 
+				if(! tta.link){ 
+					// change the link of ta;
+					int ja = ta;
+					MeshVertex *v0= ta.EdgeVertex(0);
+					MeshVertex *v1= ta.EdgeVertex(1);
+					long k =edge4->SortAndAdd(v0?Number(v0):nbv,v1? Number(v1):nbv);
+
+					ISSMASSERT(st[k]>=0);
+					tta.SetAdj2(ja,savetriangles + st[k] / 3,(int) (st[k]%3));
+					ta.SetLock();
+					st[k]=-2-st[k]; 
+				}
+			}
+		}
+	}
+	long NbTfillHoll =0;
+	for (i=0;i<nbt;i++){
+		if (triangles[i].link) {
+			triangles[i]=Triangle((MeshVertex *) NULL,(MeshVertex *) NULL,(MeshVertex *) NULL);
+			triangles[i].color=-1;
+		}
+		else{
+			triangles[i].color= savenbt+ NbTfillHoll++;
+		}
+	}
+	ISSMASSERT(savenbt+NbTfillHoll<=savenbtx);
+
+	// copy of the outside triangles in saveTriangles 
+	for (i=0;i<nbt;i++){
+		if(triangles[i].color>=0) {
+			savetriangles[savenbt]=triangles[i];
+			savetriangles[savenbt].link=0;
+			savenbt++;
+		}
+	}
+	// gestion of the adj
+	k =0;
+	Triangle * tmax = triangles + nbt;
+	for (i=0;i<savenbt;i++) { 
+		Triangle & ti = savetriangles[i];
+		for (int j=0;j<3;j++){
+			Triangle * ta = ti.TriangleAdj(j);
+			int aa = ti.NuEdgeTriangleAdj(j);
+			int lck = ti.Locked(j);
+			if (!ta) k++; // bug 
+			else if ( ta >= triangles && ta < tmax){
+				ta= savetriangles + ta->color;
+				ti.SetAdj2(j,ta,aa);
+				if(lck) ti.SetLocked(j);
+			}
+		}
+	}
+
+	// restore triangles;
+	nbt=savenbt;
+	nbtx=savenbtx;
+	delete [] triangles;
+	delete [] subdomains;
+	triangles = savetriangles;
+	subdomains = savesubdomains;
+	if (k) {
+		ISSMERROR("number of triangles edges alone = %i",k);
+	}
+	FindSubDomain();
+
+	delete edge4;
+	delete [] st;
+	for (i=0;i<nbv;i++) quadtree->Add(vertices[i]);
+
+	SetVertexFieldOn();
+
+	/*Check requirements consistency*/
+	for (i=0;i<nbe;i++){
+ 	/*If the current mesh edge is on Geometry*/
+		if(edges[i].onGeometry){
+			for(int j=0;j<2;j++){
+				/*Go through the edges adjacent to current edge (if on the same curve)*/
+				if (!edges[i].adj[j]){
+					/*The edge is on Geometry and does not have 2 adjacent edges... (not on a closed curve)*/
+					/*Check that the 2 vertices are on geometry AND required*/
+					if(!edges[i][j].onGeometry->IsRequiredVertex()){
+						printf("ReconstructExistingMesh error message: problem with the edge number %i: [%i %i]\n",i+1,Number(edges[i][0])+1,Number(edges[i][1])+1);
+						printf("This edge is on geometrical edge number %i\n",Gh.Number(edges[i].onGeometry)+1);
+						if (edges[i][j].onGeometry->OnGeomVertex())
+						 printf("the vertex number %i of this edge is a geometric MeshVertex number %i\n",Gh.Number(edges[i][j].onGeometry->gv)+1);
+						else if (edges[i][j].onGeometry->OnGeomEdge())
+						 printf("the vertex number %i of this edge is a geometric Edge number %i\n",Gh.Number(edges[i][j].onGeometry->ge)+1);
+						else
+						 printf("Its pointer is %p\n",edges[i][j].onGeometry);
+
+						printf("This edge is on geometry and has no adjacent edge (open curve) and one of the tip is not required\n");
+						ISSMERROR("See above (might be cryptic...)");
+					}
+				}
+			}
+		}
+	}
+}
+/*}}}1*/
+	/*FUNCTION Triangles::ReNumberingTheTriangleBySubDomain{{{1*/
+	void Triangles::ReNumberingTheTriangleBySubDomain(bool justcompress){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ReNumberingTheTriangleBySubDomain)*/
+
+		long int verbosity=0;
+		long *renu= new long[nbt];
+		register Triangle *t0,*t,*te=triangles+nbt;
+		register long k=0,it,i,j;
+
+		for ( it=0;it<nbt;it++) 
+		 renu[it]=-1; // outside triangle 
+		for ( i=0;i<NbSubDomains;i++)
+		  { 
+			t=t0=subdomains[i].head;
+			if (!t0){ // not empty sub domain
+				ISSMERROR("!t0");
+			}
+			do { 
+				long kt = Number(t);
+				if (kt<0 || kt >= nbt ){
+					ISSMERROR("kt<0 || kt >= nbt");
+				}
+				if (renu[kt]!=-1){
+					ISSMERROR("renu[kt]!=-1");
+				}
+				renu[kt]=k++;
+			}
+			while (t0 != (t=t->link));
+		  }
+		// take is same numbering if possible    
+		if(justcompress)
+		 for ( k=0,it=0;it<nbt;it++) 
+		  if(renu[it] >=0 ) 
+			renu[it]=k++;
+
+		// put the outside triangles at the end
+		for ( it=0;it<nbt;it++){
+			if (renu[it]==-1) renu[it]=k++;
+		}
+		if (k != nbt){
+			ISSMERROR("k != nbt");
+		}
+		// do the change on all the pointeur 
+		for ( it=0;it<nbt;it++)
+		 triangles[it].ReNumbering(triangles,te,renu);
+
+		for ( i=0;i<NbSubDomains;i++)
+		 subdomains[i].head=triangles+renu[Number(subdomains[i].head)];
+
+		// move the Triangles  without a copy of the array 
+		// be carefull not trivial code 
+		for ( it=0;it<nbt;it++) // for all sub cycles of the permutation renu
+		 if (renu[it] >= 0) // a new sub cycle
+			{ 
+			 i=it;
+			 Triangle ti=triangles[i],tj;
+			 while ( (j=renu[i]) >= 0) 
+				{ // i is old, and j is new 
+				 renu[i] = -1; // mark 
+				 tj = triangles[j]; // save new
+				 triangles[j]= ti; // new <- old
+				 i=j;     // next 
+				 ti = tj;
+				}  
+			}
+		delete [] renu;
+		nt = nbt - NbOutT;
+
+	}
+	/*}}}1*/
+	/*FUNCTION Triangles::ReNumberingVertex{{{1*/
+	void Triangles::ReNumberingVertex(long * renu) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ReNumberingVertex)*/
+
+		// warning be carfull because pointer
+		// from on mesh to over mesh 
+		//  --  so do ReNumbering at the beginning
+		MeshVertex * ve = vertices+nbv;
+		long it,ie,i;
+
+		printf("renumbering triangles\n");
+		for ( it=0;it<nbt;it++) 
+		 triangles[it].ReNumbering(vertices,ve,renu);
+
+		printf("renumbering edges\n");
+		for ( ie=0;ie<nbe;ie++) 
+		 edges[ie].ReNumbering(vertices,ve,renu);
+
+		printf("renumbering vertices on geom\n");
+		for (i=0;i< NbVerticesOnGeomVertex;i++)
+		  {
+			MeshVertex *v = VerticesOnGeomVertex[i].mv;
+			if (v>=vertices && v < ve)
+			 VerticesOnGeomVertex[i].mv=vertices+renu[Number(v)];
+		  }
+
+		printf("renumbering vertices on edge\n");
+		for (i=0;i< NbVerticesOnGeomEdge;i++)
+		  {
+			MeshVertex *v =VerticesOnGeomEdge[i].mv;
+			if (v>=vertices && v < ve)
+			 VerticesOnGeomEdge[i].mv=vertices+renu[Number(v)];
+		  }
+
+		printf("renumbering vertices on Bth vertex\n");
+		for (i=0;i< NbVertexOnBThVertex;i++)
+		  {
+			MeshVertex *v=VertexOnBThVertex[i].v;
+			if (v>=vertices && v < ve)
+			 VertexOnBThVertex[i].v=vertices+renu[Number(v)];
+		  }
+
+		for (i=0;i< NbVertexOnBThEdge;i++)
+		  {
+			MeshVertex *v=VertexOnBThEdge[i].v;
+			if (v>=vertices && v < ve)
+			 VertexOnBThEdge[i].v=vertices+renu[Number(v)];
+		  }
+
+		// move the Vertices without a copy of the array 
+		// be carefull not trivial code 
+		long j;
+		for ( it=0;it<nbv;it++) // for all sub cycles of the permutation renu
+		 if (renu[it] >= 0) // a new sub cycle
+			{ 
+			 i=it;
+			 MeshVertex ti=vertices[i],tj;
+			 while ( (j=renu[i]) >= 0){
+				 // i is old, and j is new 
+				 renu[i] = -1-renu[i]; // mark 
+				 tj = vertices[j];     // save new
+				 vertices[j]= ti;      // new <- old
+				 i=j;     // next 
+				 ti = tj;
+				}  
+			}
+		if (quadtree){
+			delete quadtree;
+			quadtree = new QuadTree(this);
+		}
+
+		for ( it=0;it<nbv;it++) renu[i]= -renu[i]-1;
+	}
+	/*}}}1*/
+/*FUNCTION Triangles::SetIntCoor{{{1*/
+void Triangles::SetIntCoor(const char * strfrom) {
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/SetIntCoor)*/
+
+	/*Set integer coordinate for existing vertices*/
+
+	//Get extrema coordinates of the existing vertices
+	pmin =  vertices[0].r;
+	pmax =  vertices[0].r;
+	long i;
+	for (i=0;i<nbv;i++) {
+		pmin.x = Min(pmin.x,vertices[i].r.x);
+		pmin.y = Min(pmin.y,vertices[i].r.y);
+		pmax.x = Max(pmax.x,vertices[i].r.x);
+		pmax.y = Max(pmax.y,vertices[i].r.y);
+	}
+	R2 DD = (pmax-pmin)*0.05;
+	pmin = pmin-DD;
+	pmax = pmax+DD; 
+
+	//Compute coefIcoor
+	coefIcoor= (MaxICoor)/(Max(pmax.x-pmin.x,pmax.y-pmin.y));
+	if (coefIcoor<=0){
+		ISSMERROR("coefIcoor should be positive, a problem in the geometry is likely");
+	}
+
+	// generation of integer coord  
+	for (i=0;i<nbv;i++) {
+		vertices[i].i = toI2(vertices[i].r);    
+	}
+
+	// computation of the det 
+	int Nberr=0;
+	for (i=0;i<nbt;i++) {
+		MeshVertex & v0 = triangles[i][0];
+		MeshVertex & v1 = triangles[i][1];
+		MeshVertex & v2 = triangles[i][2];
+
+		//If this is not a boundary triangle
+		if ( &v0 && &v1 &&  &v2 ){
+			triangles[i].det= det(v0,v1,v2);
+			if (triangles[i].det <=0 && Nberr++ <10){
+				if(Nberr==1)
+				 if (strfrom){
+					 ISSMERROR("Fatal error %s (SetInCoor) : area of Triangle %i < 0",strfrom,i);
+				 }
+				 else{
+					 ISSMERROR("Fatal error (SetInCoor) : area of Triangle %i < 0",i);
+				 }
+			}
+		}
+
+		//else, set as -1
+		else triangles[i].det=-1;
+	}
+}
+/*}}}1*/
+/*FUNCTION Triangles::ShowRegulaty{{{1*/
+void  Triangles::ShowRegulaty() const {
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr>*/
+
+	const  double  sqrt32=sqrt(3.)*0.5; 
+	const double  aireKh=sqrt32*0.5;
+	D2  Beq(1,0),Heq(0.5,sqrt32);
+	D2xD2 Br(D2xD2(Beq,Heq).t());
+	D2xD2 B1r(Br.inv());
+	double gammamn=1e100,hmin=1e100;
+	double gammamx=0,hmax=0;
+	double beta=1e100;
+	double beta0=0;
+	double  alpha2=0;
+	double area=0,Marea=0;
+	// double cf= double(coefIcoor);
+	// double cf2= 6.*cf*cf;
+	int nt=0;
+	for (int it=0;it<nbt;it++)
+	 if ( triangles[it].link) 
+		{
+		 nt++;
+		 Triangle &K=triangles[it];
+		 double  area3= Area2((R2) K[0],(R2) K[1],(R2) K[2])/6.;
+		 area+= area3;
+		 D2xD2 B_Kt(K[0],K[1],K[2]);
+		 D2xD2 B_K(B_Kt.t());
+		 D2xD2 B1K = Br*B_K.inv();
+		 D2xD2 BK =  B_K*B1r;
+		 D2xD2 B1B1 = B1K.t()*B1K;
+		 Metric MK(B1B1.x.x,B1B1.x.y,B1B1.y.y);
+		 MatVVP2x2 VMK(MK);
+		 alpha2 = Max(alpha2,Max(VMK.lambda1/VMK.lambda2,VMK.lambda2/VMK.lambda1));
+		 double betaK=0;
+
+		 for (int j=0;j<3;j++)
+			{
+			 double he= Norme2(R2(K[j],K[(j+1)%3]));
+			 hmin=Min(hmin,he);
+			 hmax=Max(hmax,he);
+			 MeshVertex & v=K[j];
+			 D2xD2 M((Metric)v);
+			 betaK += sqrt(M.det());
+
+			 D2xD2 BMB = BK.t()*M*BK;
+			 Metric M1(BMB.x.x,BMB.x.y,BMB.y.y);
+			 MatVVP2x2 VM1(M1);
+			 gammamn=Min3(gammamn,VM1.lambda1,VM1.lambda2);
+			 gammamx=Max3(gammamx,VM1.lambda1,VM1.lambda2);		
+			}
+		 betaK *= area3;//  1/2 (somme sqrt(det))* area(K)
+		 Marea+= betaK;
+		 beta=min(beta,betaK);
+		 beta0=max(beta0,betaK);
+		}   
+	area*=3; 
+	gammamn=sqrt(gammamn);
+	gammamx=sqrt(gammamx);    
+	printf("   Adaptmesh info:\n");
+	printf("      number of triangles = %i\n",nt);
+	printf("      hmin = %g, hmax=%g\n",hmin,hmax);
+	printf("      area = %g, M area = %g, M area/( |Khat| nt) = %g\n",area,Marea, Marea/(aireKh*nt));
+	printf("      infinite-regularity(?): min = %g, max = %g\n",gammamn,gammamx);
+	printf("      anisomax = %g, beta max = %g, min = %g\n",pow(alpha2,0.5),1./pow(beta/aireKh,0.5), 1./pow(beta0/aireKh,0.5));
+}
+/*}}}1*/
+/*FUNCTION Triangles::ShowHistogram{{{1*/
+void  Triangles::ShowHistogram() const {
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ShowHistogram)*/
+
+	const long kmax=10;
+	const double llmin = 0.5,llmax=2;
+	const double lmin=log(llmin),lmax=log(llmax),delta= kmax/(lmax-lmin);
+	long histo[kmax+1];
+	long i,it,k, nbedges =0;
+	for (i=0;i<=kmax;i++) histo[i]=0;
+	for (it=0;it<nbt;it++)
+	 if ( triangles[it].link) 
+		{
+
+		 for (int j=0;j<3;j++)
+			{
+			 Triangle *ta = triangles[it].TriangleAdj(j);
+			 if ( !ta || !ta->link || Number(ta) >= it) 
+				{ 
+				 MeshVertex & vP = triangles[it][VerticesOfTriangularEdge[j][0]];
+				 MeshVertex & vQ = triangles[it][VerticesOfTriangularEdge[j][1]];
+				 if ( !& vP || !&vQ) continue;
+				 R2 PQ = vQ.r - vP.r;
+				 double l = log(LengthInterpole(vP,vQ,PQ));
+				 nbedges++;
+				 k = (int) ((l - lmin)*delta);
+				 k = Min(Max(k,0L),kmax);
+				 histo[k]++;
+				}
+			}
+		}  
+	printf(" --- Histogram of the unit mesh,  nb of edges = %i\n",nbedges);
+	printf("      length of edge in   | %% of edge  | Nb of edges \n"); 
+	printf("      --------------------+-------------+-------------\n"); 
+	for   (i=0;i<=kmax;i++){ 
+		if (i==0) printf("      %10i",0);
+		else      printf("      %10g",exp(lmin+i/delta));
+		if (i==kmax) printf("          +inf   ");
+		else printf("      %10g",exp(lmin+(i+1)/delta));
+		printf("|  %10g |\n",((long)  ((10000.0 * histo[i])/ nbedges))/100.0);
+		printf("  %g\n",histo[i]);
+	}
+	printf("      --------------------+-------------+-------------\n"); 
+}
+/*}}}1*/
+/*FUNCTION Triangles::SmoothingVertex{{{1*/
+void Triangles::SmoothingVertex(int nbiter,double omega ) { 
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/SmoothingVertex)*/
+
+	long int verbosity=0;
+	//  if quatree exist remove it end reconstruct
+	if (quadtree) delete quadtree;
+	quadtree=0;
+	ReMakeTriangleContainingTheVertex();
+	Triangle vide; // a triangle to mark the boundary vertex
+	Triangle   ** tstart= new Triangle* [nbv];
+	long i,j,k;
+	//   attention si Background == Triangle alors on ne peut pas utiliser la rechech rapide 
+	if ( this == & BTh)
+	 for ( i=0;i<nbv;i++)
+	  tstart[i]=vertices[i].t;     
+	else 
+	 for ( i=0;i<nbv;i++)
+	  tstart[i]=0;
+	for ( j=0;j<NbVerticesOnGeomVertex;j++ ) 
+	 tstart[ Number(VerticesOnGeomVertex[j].mv)]=&vide;
+	for ( k=0;k<NbVerticesOnGeomEdge;k++ ) 
+	 tstart[ Number(VerticesOnGeomEdge[k].mv)]=&vide;
+	if(verbosity>2) printf("   SmoothingVertex: nb Iteration = %i, Omega=%g\n",nbiter,omega);
+	for (k=0;k<nbiter;k++)
+	  {
+		long i,NbSwap =0;
+		double delta =0;
+		for ( i=0;i<nbv;i++)
+		 if (tstart[i] != &vide) // not a boundary vertex 
+		  delta=Max(delta,vertices[i].Smoothing(*this,BTh,tstart[i],omega));
+		if (!NbOfQuad)
+		 for ( i=0;i<nbv;i++)
+		  if (tstart[i] != &vide) // not a boundary vertex 
+			NbSwap += vertices[i].Optim(1);
+		if (verbosity>3) printf("      move max = %g, iteration = %i, nb of swap = %i\n",pow(delta,0.5),k,NbSwap);
+	  }
+
+	delete [] tstart;
+	if (quadtree) quadtree= new QuadTree(this);
+}
+/*}}}1*/
+/*FUNCTION Triangles::SmoothMetric{{{1*/
+void Triangles::SmoothMetric(double raisonmax) { 
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Metric.cpp/SmoothMetric)*/
+
+	long int verbosity=0;
+
+	if(raisonmax<1.1) return;
+	if(verbosity > 1) printf("   Triangles::SmoothMetric raisonmax = %g\n",raisonmax);
+	ReMakeTriangleContainingTheVertex();
+	long i,j,kch,kk,ip;
+	long *first_np_or_next_t0 = new long[nbv];
+	long *first_np_or_next_t1 = new long[nbv];
+	long Head0 =0,Head1=-1;
+	double logseuil= log(raisonmax);
+
+	for(i=0;i<nbv-1;i++)
+	 first_np_or_next_t0[i]=i+1; 
+	first_np_or_next_t0[nbv-1]=-1;// end;
+	for(i=0;i<nbv;i++)
+	 first_np_or_next_t1[i]=-1;
+	kk=0;
+	while (Head0>=0&& kk++<100) {
+		kch=0;
+		for (i=Head0;i>=0;i=first_np_or_next_t0[ip=i],first_np_or_next_t0[ip]=-1) {
+			//  pour tous les triangles autour du sommet s
+			register Triangle* t= vertices[i].t;
+			if (!t){
+				ISSMERROR("!t");
+			}
+			MeshVertex & vi = vertices[i];
+			TriangleAdjacent ta(t,EdgesVertexTriangle[vertices[i].vint][0]);
+			MeshVertex *pvj0 = ta.EdgeVertex(0);
+			while (1) {
+				ta=Previous(Adj(ta));
+				if (vertices+i != ta.EdgeVertex(1)){
+					ISSMERROR("vertices+i != ta.EdgeVertex(1)");
+				}
+				MeshVertex & vj = *(ta.EdgeVertex(0));
+				if ( &vj ) {
+					j= &vj-vertices;
+					if (j<0 || j >= nbv){
+						ISSMERROR("j<0 || j >= nbv");
+					}
+					R2 Aij = (R2) vj - (R2) vi;
+					double ll =  Norme2(Aij);
+					if (0) {  
+						double hi = ll/vi.m(Aij);
+						double hj = ll/vj.m(Aij);
+						if(hi < hj)
+						  {
+							double dh=(hj-hi)/ll;
+							if (dh>logseuil) {
+								vj.m.IntersectWith(vi.m/(1 +logseuil*ll/hi));
+								if(first_np_or_next_t1[j]<0)
+								 kch++,first_np_or_next_t1[j]=Head1,Head1=j;
+							}
+						  }
+					} 
+					else
+					  {
+						double li = vi.m(Aij);
+						if( vj.m.IntersectWith(vi.m/(1 +logseuil*li)) )
+						 if(first_np_or_next_t1[j]<0) // if the metrix change 
+						  kch++,first_np_or_next_t1[j]=Head1,Head1=j;
+					  }
+				}
+				if  ( &vj ==  pvj0 ) break;
+			}
+		}
+		Head0 = Head1;
+		Head1 = -1;
+		Exchange(first_np_or_next_t0,first_np_or_next_t1);
+	}
+	if(verbosity>2) printf("      number of iterations = %i\n",kch); 
+	delete [] first_np_or_next_t0;
+	delete [] first_np_or_next_t1;
+}
+/*}}}1*/
+	/*FUNCTION Triangles::SplitElement{{{1*/
+	int  Triangles::SplitElement(int choice){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshQuad.cpp/SplitElement)*/
+
+		long int verbosity=0;
+
+		Direction NoDirOfSearch;
+		const  int withBackground = &BTh != this && &BTh;
+
+		ReNumberingTheTriangleBySubDomain();
+		//int nswap =0;
+		const long nfortria( choice ? 4 : 6);
+		if(withBackground) 
+		  {
+			BTh.SetVertexFieldOn();
+			SetVertexFieldOnBTh();
+		  }
+		else
+		 BTh.SetVertexFieldOn();
+
+		long newnbt=0,newnbv=0;
+		long * kedge = 0;
+		long newNbOfQuad=NbOfQuad;
+		long * ksplit= 0, * ksplitarray=0;
+		long kkk=0;
+		int ret =0;
+		if (nbvx<nbv+nbe) return 1;//   
+		// 1) create  the new points by spliting the internal edges 
+		// set the 
+		long nbvold = nbv;
+		long nbtold = nbt;
+		long NbOutTold  = NbOutT;
+		long  NbEdgeOnGeom=0;
+		long i;
+
+		nbt = nbt - NbOutT; // remove all the  the ouside triangles 
+		long nbtsave = nbt;
+		Triangle * lastT = triangles + nbt;
+		for (i=0;i<nbe;i++)
+		 if(edges[i].onGeometry) NbEdgeOnGeom++;
+		long newnbe=nbe+nbe;
+		//  long newNbVerticesOnGeomVertex=NbVerticesOnGeomVertex;
+		long newNbVerticesOnGeomEdge=NbVerticesOnGeomEdge+NbEdgeOnGeom;
+		// long newNbVertexOnBThVertex=NbVertexOnBThVertex;
+		long newNbVertexOnBThEdge=withBackground ? NbVertexOnBThEdge+NbEdgeOnGeom:0;
+
+		// do allocation for pointeur to the geometry and background
+		VertexOnGeom * newVerticesOnGeomEdge = new VertexOnGeom[newNbVerticesOnGeomEdge];
+		VertexOnEdge *newVertexOnBThEdge = newNbVertexOnBThEdge ?  new VertexOnEdge[newNbVertexOnBThEdge]:0;
+		if (NbVerticesOnGeomEdge)
+		 memcpy(newVerticesOnGeomEdge,VerticesOnGeomEdge,sizeof(VertexOnGeom)*NbVerticesOnGeomEdge);
+		if (NbVertexOnBThEdge)
+		 memcpy(newVertexOnBThEdge,VertexOnBThEdge,sizeof(VertexOnEdge)*NbVertexOnBThEdge);
+		Edge *newedges = new Edge [newnbe];
+		//  memcpy(newedges,edges,sizeof(Edge)*nbe);
+		SetOfEdges4 * edge4= new SetOfEdges4(nbe,nbv);
+		long k=nbv;
+		long kk=0;
+		long kvb = NbVertexOnBThEdge;
+		long kvg = NbVerticesOnGeomEdge;
+		long ie =0;
+		Edge ** edgesGtoB=0;
+		if (withBackground)
+		 edgesGtoB= BTh.MakeGeometricalEdgeToEdge();
+		long ferr=0;
+		for (i=0;i<nbe;i++)
+		 newedges[ie].onGeometry=0;
+
+		for (i=0;i<nbe;i++)
+		  {
+			GeometricalEdge *ong =  edges[i].onGeometry;
+
+			newedges[ie]=edges[i];
+			newedges[ie].adj[0]=newedges+(edges[i].adj[0]-edges) ;
+			newedges[ie].adj[1]=newedges + ie +1;
+			R2 A = edges[i][0],B = edges[i][1];
+
+
+			kk += (i == edge4->SortAndAdd(Number(edges[i][0]),Number(edges[i][1])));
+			if (ong) // a geometrical edges 
+			  { 
+				if (withBackground){
+					// walk on back ground mesh 
+					//  newVertexOnBThEdge[ibe++] = VertexOnEdge(vertices[k],bedge,absicsseonBedge); 
+					// a faire -- difficile 
+					// the first PB is to now a background edge between the 2 vertices
+					if (!edgesGtoB){
+						ISSMERROR("!edgesGtoB");
+					}
+					ong= ProjectOnCurve(*edgesGtoB[Gh.Number(edges[i].onGeometry)],
+								edges[i][0],edges[i][1],0.5,vertices[k],
+								newVertexOnBThEdge[kvb],
+								newVerticesOnGeomEdge[kvg++]);
+					vertices[k].ReferenceNumber= edges[i].ref;
+					vertices[k].DirOfSearch =   NoDirOfSearch;        
+					;
+					// get the Info on background mesh 
+					double s =        newVertexOnBThEdge[kvb];
+					MeshVertex &  bv0  = newVertexOnBThEdge[kvb][0];
+					MeshVertex &  bv1  = newVertexOnBThEdge[kvb][1];
+					// compute the metrix of the new points 
+					vertices[k].m =  Metric(1-s,bv0,s,bv1); 
+					kvb++;
+				  }
+				else 
+				  {
+					ong=Gh.ProjectOnCurve(edges[i],
+								0.5,vertices[k],newVerticesOnGeomEdge[kvg++]);
+					// vertices[k].i = toI2( vertices[k].r);
+					vertices[k].ReferenceNumber = edges[i].ref;
+					vertices[k].DirOfSearch = NoDirOfSearch;
+					vertices[k].m =  Metric(0.5,edges[i][0],0.5,edges[i][1]);	      
+				  }  
+			  }
+			else // straigth line edge ---
+			  { 
+				vertices[k].r = ((R2) edges[i][0] + (R2)  edges[i][1] )*0.5;
+				vertices[k].m =  Metric(0.5,edges[i][0],0.5,edges[i][1]);
+				vertices[k].onGeometry = 0;
+			  }
+			//vertices[k].i = toI2( vertices[k].r);
+			R2 AB =  vertices[k].r;
+			R2 AA = (A+AB)*0.5;
+			R2 BB = (AB+B)*0.5;
+			vertices[k].ReferenceNumber = edges[i].ref;
+			vertices[k].DirOfSearch = NoDirOfSearch;
+
+			newedges[ie].onGeometry = Gh.Containing(AA,ong);
+			newedges[ie++].v[1]=vertices+k;
+
+			newedges[ie]=edges[i];
+			newedges[ie].adj[0]=newedges + ie -1;
+			newedges[ie].adj[1]=newedges+(edges[i].adj[1]-edges) ;
+			newedges[ie].onGeometry =  Gh.Containing(BB,ong);
+			newedges[ie++].v[0]=vertices+k;
+			k++;
+		  }
+		if (edgesGtoB) delete [] edgesGtoB;
+		edgesGtoB=0;
+
+		newnbv=k;
+		newNbVerticesOnGeomEdge=kvg;
+		if (newnbv> nbvx) goto Error;// bug 
+
+		nbv = k;
+
+
+		kedge = new long[3*nbt+1];
+		ksplitarray = new long[nbt+1];
+		ksplit = ksplitarray +1; // because ksplit[-1] == ksplitarray[0]
+
+		for (i=0;i<3*nbt;i++)
+		 kedge[i]=-1;
+
+		//  
+
+		for (i=0;i<nbt;i++) {
+			Triangle & t = triangles[i];
+			if (!t.link){
+				ISSMERROR("!t.link");
+			}
+			for(int j=0;j<3;j++)
+			  {
+				const TriangleAdjacent ta = t.Adj(j);
+				const Triangle & tt = ta;
+				if (&tt >= lastT)
+				 t.SetAdj2(j,0,0);// unset adj
+				const MeshVertex & v0 = t[VerticesOfTriangularEdge[j][0]];
+				const MeshVertex & v1 = t[VerticesOfTriangularEdge[j][1]];
+				long  ke =edge4->SortAndFind(Number(v0),Number(v1));
+				if (ke>0) 
+				  {
+					long ii = Number(tt);
+					int  jj = ta;
+					long ks = ke + nbvold;
+					kedge[3*i+j] = ks;
+					if (ii<nbt) // good triangle
+					 kedge[3*ii+jj] = ks;
+					MeshVertex &A=vertices[ks];
+					double aa,bb,cc,dd;
+					if ((dd=Area2(v0.r,v1.r,A.r)) >=0){
+						// warning PB roundoff error 
+						if (t.link && ( (aa=Area2( A.r    , t[1].r , t[2].r )) < 0.0 
+										||   (bb=Area2( t[0].r , A.r    , t[2].r )) < 0.0  
+										||   (cc=Area2( t[0].r , t[1].r , A.r    )) < 0.0)){
+							printf("%i not in triangle %i In= %i %i %i %i %i\n",ke + nbvold,i,!!t.link,aa,bb,cc,dd);
+							ISSMERROR("Number of triangles with P2 interpolation Problem");
+						}
+					}
+					else {
+						if (tt.link && ( (aa=Area2( A.r     , tt[1].r , tt[2].r )) < 0 
+										||   (bb=Area2( tt[0].r , A.r     , tt[2].r )) < 0 
+										||   (cc=Area2( tt[0].r , tt[1].r , A.r     )) < 0)){
+							printf("%i not in triangle %i In= %i %i %i %i %i\n",ke + nbvold,ii,!!tt.link,aa,bb,cc,dd);
+							ISSMERROR("Number of triangles with P2 interpolation Problem");
+						}
+					} 
+				  }
+			  }
+		}
+
+		for (i=0;i<nbt;i++){
+			ksplit[i]=1; // no split by default
+			const Triangle & t = triangles[ i];
+			int nbsplitedge =0;
+			int nbinvisible =0;
+			int invisibleedge=0;
+			int kkk[3];      
+			for (int j=0;j<3;j++)
+			  {
+				if (t.Hidden(j)) invisibleedge=j,nbinvisible++;
+
+				const TriangleAdjacent ta = t.Adj(j);
+				const Triangle & tt = ta;
+
+
+				const MeshVertex & v0 = t[VerticesOfTriangularEdge[j][0]];
+				const MeshVertex & v1 = t[VerticesOfTriangularEdge[j][1]];
+				if ( kedge[3*i+j] < 0) 
+				  {
+					long  ke =edge4->SortAndFind(Number(v0),Number(v1));
+					if (ke<0) // new 
+					  {
+						if (&tt) // internal triangles all the boundary 
+						  { // new internal edges 
+							long ii = Number(tt);
+							int  jj = ta;
+
+							kedge[3*i+j]=k;// save the vertex number 
+							kedge[3*ii+jj]=k;
+							if (k<nbvx) 
+							  {
+								vertices[k].r = ((R2) v0+(R2) v1 )/2;
+								//vertices[k].i = toI2( vertices[k].r);
+								vertices[k].ReferenceNumber=0;
+								vertices[k].DirOfSearch =NoDirOfSearch;
+								vertices[k].m =  Metric(0.5,v0,0.5,v1);
+							  }
+							k++;
+							kkk[nbsplitedge++]=j;		      
+						  } // tt 
+						else
+						 ISSMERROR("Bug...");
+					  } // ke<0	       
+					else
+					  { // ke >=0
+						kedge[3*i+j]=nbvold+ke;
+						kkk[nbsplitedge++]=j;// previously splited
+					  }
+				  }
+				else 
+				 kkk[nbsplitedge++]=j;// previously splited
+
+			  } 
+			if (nbinvisible>=2){
+				ISSMERROR("nbinvisible>=2");
+			}
+			switch (nbsplitedge) {
+				case 0: ksplit[i]=10; newnbt++; break;   // nosplit
+				case 1: ksplit[i]=20+kkk[0];newnbt += 2; break; // split in 2 
+				case 2: ksplit[i]=30+3-kkk[0]-kkk[1];newnbt += 3; break; // split in 3 
+				case 3:
+						  if (nbinvisible) ksplit[i]=40+invisibleedge,newnbt += 4;
+						  else   ksplit[i]=10*nfortria,newnbt+=nfortria;
+						  break;
+			} 
+			if (ksplit[i]<40){
+				ISSMERROR("ksplit[i]<40");
+			}
+		  }
+		//  now do the element split
+		newNbOfQuad = 4*NbOfQuad;
+		nbv = k;
+		kkk = nbt;
+		ksplit[-1] = nbt;
+		// look on  old true  triangles 
+
+		for (i=0;i<nbtsave;i++){
+			int  nbmkadj=0;
+			long mkadj [100];
+			mkadj[0]=i;
+			long kk=ksplit[i]/10;
+			int  ke=(int) (ksplit[i]%10);
+			if (kk>=7 || kk<=0){
+				ISSMERROR("kk>=7 || kk<=0");
+			}
+
+			// def the numbering   k (edge) i vertex 
+			int k0 = ke;
+			int k1 = NextEdge[k0];
+			int k2 = PreviousEdge[k0];
+			int i0 = OppositeVertex[k0];
+			int i1 = OppositeVertex[k1];
+			int i2 = OppositeVertex[k2];
+
+			Triangle &t0=triangles[i];
+			MeshVertex * v0=t0(i0);           
+			MeshVertex * v1=t0(i1);           
+			MeshVertex * v2=t0(i2);
+
+			if (nbmkadj>=10){
+				ISSMERROR("nbmkadj>=10");
+			}
+			// --------------------------
+			TriangleAdjacent ta0(t0.Adj(i0)),ta1(t0.Adj(i1)),ta2(t0.Adj(i2));
+			// save the flag Hidden
+			int hid[]={t0.Hidden(0),t0.Hidden(1),t0.Hidden(2)};
+			// un set all adj -- save Hidden flag --
+			t0.SetAdj2(0,0,hid[0]);
+			t0.SetAdj2(1,0,hid[1]);
+			t0.SetAdj2(2,0,hid[2]);
+			// --  remake 
+			switch  (kk) {
+				case 1: break;// nothing 
+				case 2: // 
+						  {
+							Triangle &t1=triangles[kkk++];
+							t1=t0;
+							if (kedge[3*i+i0]<0){
+								ISSMERROR("kedge[3*i+i0]<0");
+							}
+							MeshVertex * v3 = vertices + kedge[3*i+k0];
+
+							t0(i2) = v3;
+							t1(i1) = v3;
+							t0.SetAllFlag(k2,0);
+							t1.SetAllFlag(k1,0);
+						  } 
+						break; 
+				case 3: //
+						  {
+							Triangle &t1=triangles[kkk++];
+							Triangle &t2=triangles[kkk++];
+							t2=t1=t0;
+							if (kedge[3*i+k1]<0){
+								ISSMERROR("kedge[3*i+k1]<0");
+							}
+							if (kedge[3*i+k2]<0){
+								ISSMERROR("kedge[3*i+k2]<0");
+							}
+
+							MeshVertex * v01 = vertices + kedge[3*i+k2];
+							MeshVertex * v02 = vertices + kedge[3*i+k1]; 
+							t0(i1) = v01; 
+							t0(i2) = v02; 
+							t1(i2) = v02;
+							t1(i0) = v01; 
+							t2(i0) = v02; 
+							t0.SetAllFlag(k0,0);
+							t1.SetAllFlag(k1,0);
+							t1.SetAllFlag(k0,0);
+							t2.SetAllFlag(k2,0);
+						  } 
+						break;
+				case 4: // 
+				case 6: // split in 4 
+						  {
+							Triangle &t1=triangles[kkk++];
+							Triangle &t2=triangles[kkk++];
+							Triangle &t3=triangles[kkk++];
+							t3=t2=t1=t0;
+							if (kedge[3*i+k0] <0 || kedge[3*i+k1]<0 || kedge[3*i+k2]<0){
+								ISSMERROR("kedge[3*i+k0] <0 || kedge[3*i+k1]<0 || kedge[3*i+k2]<0");
+							}
+							MeshVertex * v12 = vertices + kedge[3*i+k0];
+							MeshVertex * v02 = vertices + kedge[3*i+k1]; 
+							MeshVertex * v01 = vertices + kedge[3*i+k2];
+							t0(i1) = v01;
+							t0(i2) = v02;
+							t0.SetAllFlag(k0,hid[k0]);
+
+							t1(i0) = v01;
+							t1(i2) = v12;
+							t0.SetAllFlag(k1,hid[k1]);
+
+							t2(i0) = v02;
+							t2(i1) = v12;
+							t2.SetAllFlag(k2,hid[k2]);
+
+							t3(i0) = v12;
+							t3(i1) = v02;
+							t3(i2) = v01;
+
+							t3.SetAllFlag(0,hid[0]);	   
+							t3.SetAllFlag(1,hid[1]);	   
+							t3.SetAllFlag(2,hid[2]);
+
+							if ( kk == 6)
+							  {
+
+								Triangle &t4=triangles[kkk++];
+								Triangle &t5=triangles[kkk++];
+
+								t4 = t3;
+								t5 = t3;
+
+								t0.SetHidden(k0);
+								t1.SetHidden(k1);
+								t2.SetHidden(k2);
+								t3.SetHidden(0);
+								t4.SetHidden(1);
+								t5.SetHidden(2);
+
+								if (nbv < nbvx ) 
+								  {
+									vertices[nbv].r = ((R2) *v01 + (R2) *v12  + (R2) *v02 ) / 3.0;
+									vertices[nbv].ReferenceNumber =0;
+									vertices[nbv].DirOfSearch =NoDirOfSearch;
+									//vertices[nbv].i = toI2(vertices[nbv].r);
+									double a3[]={1./3.,1./3.,1./3.};
+									vertices[nbv].m = Metric(a3,v0->m,v1->m,v2->m);
+									MeshVertex * vc =  vertices +nbv++;
+									t3(i0) = vc;
+									t4(i1) = vc;
+									t5(i2) = vc;
+
+								  }
+								else
+								 goto Error; 
+							  }
+
+						  } 
+						break;         
+			}
+
+			// save all the new triangles
+			mkadj[nbmkadj++]=i;
+			long jj;
+			if (t0.link) 
+			 for (jj=nbt;jj<kkk;jj++)
+				{
+				 triangles[jj].link=t0.link;
+				 t0.link= triangles+jj;
+				 mkadj[nbmkadj++]=jj;
+				}
+			if (nbmkadj>13){// 13 = 6 + 4 +
+				ISSMERROR("nbmkadj>13");
+			}
+
+			if (kk==6)  newNbOfQuad+=3;
+			for (jj=ksplit[i-1];jj<kkk;jj++) nbt = kkk;
+			ksplit[i]= nbt; // save last adresse of the new triangles
+			kkk = nbt;
+		  }
+
+		for (i=0;i<nbv;i++) vertices[i].m = vertices[i].m*2.;
+
+		if(withBackground)
+		 for (i=0;i<BTh.nbv;i++)
+		  BTh.vertices[i].m =  BTh.vertices[i].m*2.;
+
+
+		ret = 2;
+		if (nbt>= nbtx) goto Error; // bug 
+		if (nbv>= nbvx) goto Error; // bug 
+		// generation of the new triangles 
+
+		SetIntCoor("In SplitElement"); 
+
+		ReMakeTriangleContainingTheVertex();
+		if(withBackground)
+		 BTh.ReMakeTriangleContainingTheVertex();
+
+		delete [] edges;
+		edges = newedges;
+		nbe = newnbe;
+		NbOfQuad = newNbOfQuad;
+
+		for (i=0;i<NbSubDomains;i++)
+		  { 
+			long k = subdomains[i].edge- edges;
+			subdomains[i].edge =  edges+2*k; // spilt all edge in 2 
+		  }
+
+		if (ksplitarray) delete [] ksplitarray;
+		if (kedge) delete [] kedge;
+		if (edge4) delete edge4;
+		if (VerticesOnGeomEdge) delete [] VerticesOnGeomEdge;
+		VerticesOnGeomEdge= newVerticesOnGeomEdge;
+		if(VertexOnBThEdge) delete []  VertexOnBThEdge;
+		VertexOnBThEdge = newVertexOnBThEdge;
+		NbVerticesOnGeomEdge = newNbVerticesOnGeomEdge;
+		NbVertexOnBThEdge=newNbVertexOnBThEdge;
+		//  ReMakeTriangleContainingTheVertex();
+
+		ReconstructExistingMesh();
+
+		if (verbosity>2){
+			printf("   number of quadrilaterals    = %i\n",NbOfQuad);
+			printf("   number of triangles         = %i\n",nbt-NbOutT- NbOfQuad*2);
+			printf("   number of outside triangles = %i\n",NbOutT);
+		}
+
+		return 0; //ok
+
+Error:
+		nbv = nbvold;
+		nbt = nbtold;
+		NbOutT = NbOutTold;
+		// cleaning memory ---
+		delete newedges;
+		if (ksplitarray) delete [] ksplitarray;
+		if (kedge) delete [] kedge;
+		if (newVerticesOnGeomEdge) delete [] newVerticesOnGeomEdge;
+		if (edge4) delete edge4;
+		if(newVertexOnBThEdge) delete []  newVertexOnBThEdge;
+
+		return ret; // ok 
+	}
+	/*}}}1*/
+/*FUNCTION Triangles::SplitInternalEdgeWithBorderVertices{{{1*/
+long  Triangles::SplitInternalEdgeWithBorderVertices(){
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/SplitInternalEdgeWithBorderVertices)*/
+
+	long NbSplitEdge=0;
+	SetVertexFieldOn();  
+	long it;
+	long nbvold=nbv;
+	long int verbosity=2;
+	for (it=0;it<nbt;it++){
+		Triangle &t=triangles[it];
+		if (t.link)
+		 for (int j=0;j<3;j++)
+		  if(!t.Locked(j) && !t.Hidden(j)){
+			  Triangle &tt = *t.TriangleAdj(j);
+			  if ( &tt && tt.link && it < Number(tt)) 
+				 { // an internal edge 
+				  MeshVertex &v0 = t[VerticesOfTriangularEdge[j][0]];
+				  MeshVertex &v1 = t[VerticesOfTriangularEdge[j][1]];
+				  if (v0.onGeometry && v1.onGeometry){
+					  R2 P= ((R2) v0 + (R2) v1)*0.5;
+					  if ( nbv<nbvx) {
+						  vertices[nbv].r = P;
+						  vertices[nbv++].m = Metric(0.5,v0.m,0.5,v1.m);
+						  vertices[nbv].ReferenceNumber=0;
+						  vertices[nbv].DirOfSearch = NoDirOfSearch ;
+					  }
+					  NbSplitEdge++;
+				  }
+				 }
+		  }
+	}
+	ReMakeTriangleContainingTheVertex();    
+	if (nbvold!=nbv){
+		long  iv = nbvold;
+		long NbSwap = 0;
+		Icoor2 dete[3];  
+		for (int i=nbvold;i<nbv;i++) {// for all the new point
+			MeshVertex & vi = vertices[i];
+			vi.i = toI2(vi.r);
+			vi.r = toR2(vi.i);
+
+			// a good new point 
+			vi.ReferenceNumber=0; 
+			vi.DirOfSearch =NoDirOfSearch;
+			Triangle *tcvi = FindTriangleContaining(vi.i,dete);
+			if (tcvi && !tcvi->link) {
+				printf("problem inserting point in SplitInternalEdgeWithBorderVertices (tcvj && !tcvj->link)\n");
+			}
+
+			quadtree->Add(vi);
+			if (!tcvi || tcvi->det<0){// internal
+				ISSMERROR("!tcvi || tcvi->det < 0");
+			}
+			AddVertex(vi,tcvi,dete);
+			NbSwap += vi.Optim(1);          
+			iv++;
+			//      }
+	}
+	if (verbosity>3) {
+		printf("   number of points: %i\n",iv);
+		printf("   number of swap to  split internal edges with border vertices: %i\n",NbSwap);
+		nbv = iv;
+	}
+}
+if (NbSplitEdge>nbv-nbvold) printf("WARNING: not enough vertices  to split all internal edges, we lost %i edges...\n",NbSplitEdge - ( nbv-nbvold));
+if (verbosity>2) printf("SplitInternalEdgeWithBorderVertices: Number of splited edge %i\n",NbSplitEdge);
+
+return  NbSplitEdge;
+}
+/*}}}1*/
+/*FUNCTION Triangles::TriangleReferenceList{{{1*/
+long  Triangles::TriangleReferenceList(long* reft) const {
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ConsRefTriangle)*/
+
+	long int verbosity=0;
+	register Triangle *t0,*t;
+	register long k=0, num;   
+
+	//initialize all triangles as -1 (outside)
+	for (int it=0;it<nbt;it++) reft[it]=-1;
+
+	//loop over all subdomains
+	for (int i=0;i<NbSubDomains;i++){ 
+
+		//first triangle of the subdomain i
+		t=t0=subdomains[i].head;
+
+		//check that the subdomain is not empty
+		if (!t0){ ISSMERROR("At least one subdomain is empty");}
+
+		//loop
+		do{
+			k++;
+
+			//get current triangle number
+			num = Number(t);
+
+			//check that num is in [0 nbt[
+			if (num<0 || num>=nbt){ ISSMERROR("num<0 || num>=nbt");}
+
+			//reft of this triangle is the subdomain number
+			reft[num]=i;
+
+		} while (t0 != (t=t->link));
+		//stop when all triangles of subdomains have been tagged
+
+	}
+	return k;   
+}
+/*}}}1*/
+/*FUNCTION Triangles::TriangleIntNumbering{{{1*/
+void Triangles::TriangleIntNumbering(long* renumbering){
+
+	long num=0;
+	for (int i=0;i<nbt;i++){
+		if (triangles[i].det>0) renumbering[i]=num++;
+		else renumbering[i]=-1;
+	}
+	return;   
+}
+/*}}}1*/
+
+	/*Intermediary*/
+	/*FUNCTION CloseBoundaryEdge{{{1*/
+	TriangleAdjacent CloseBoundaryEdge(I2 A,Triangle *t, double &a,double &b) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/CloseBoundaryEdge)*/
+
+		int k=(*t)(0) ?  ((  (*t)(1) ? ( (*t)(2) ? -1 : 2) : 1  )) : 0;
+		int dir=0;
+		if (k<0){
+			ISSMERROR("k<0");
+		}
+		int kkk=0;  
+		Icoor2 IJ_IA,IJ_AJ;
+		TriangleAdjacent edge(t,OppositeEdge[k]);          
+		for (;;edge = dir >0 ? Next(Adj(Next(edge))) : Previous(Adj(Previous(edge)))) {  
+			kkk++;
+			if (kkk>=1000){
+				ISSMERROR("kkk>=1000");
+			}
+			MeshVertex  &vI =  *edge.EdgeVertex(0);
+			MeshVertex  &vJ =  *edge.EdgeVertex(1);
+			I2 I=vI, J=vJ, IJ= J-I;
+			IJ_IA = (IJ ,(A-I));
+			if (IJ_IA<0) {
+				if (dir>0) {a=1;b=0;return edge;}// change of signe => I
+				else {dir=-1;
+					continue;}};// go in direction i 
+					IJ_AJ = (IJ ,(J-A));
+					if (IJ_AJ<0) {
+						if(dir<0)  {a=0;b=1;return edge;}            
+						else {dir = 1;
+							continue;}}// go in direction j
+							double IJ2 = IJ_IA + IJ_AJ;
+							if (IJ2==0){
+								ISSMERROR("IJ2==0");
+							}
+							a= IJ_AJ/IJ2;
+							b= IJ_IA/IJ2;
+							return edge;
+		  } 
+	}
+	/*}}}1*/
+	/*FUNCTION CloseBoundaryEdgeV2{{{1*/
+	TriangleAdjacent CloseBoundaryEdgeV2(I2 C,Triangle *t, double &a,double &b) { 
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/CloseBoundaryEdgeV2)*/
+		// walk around the vertex 
+		// version 2 for remove the probleme if we fill the hole
+		//int bug=1;
+		//  Triangle *torigine = t;
+		// restart:
+		//   int dir=0;
+		if (t->link != 0){
+			ISSMERROR("t->link != 0");
+		}
+		// to have a starting edges 
+		// try the 3 edge bourna-- in case of internal hole 
+		// and choice  the best 
+		// 
+		// the probleme is in case of  the fine and long internal hole
+		// for exemple neart the training edge of a wing
+		MeshVertex * s=0,*s1=0, *s0=0;
+		Icoor2 imax = MaxICoor22;
+		Icoor2 l0 = imax,l1 = imax;
+		double dd2 =  imax;// infinity
+		TriangleAdjacent er; 
+		int  cas=-2;
+		for (int j=0;j<3;j++)
+		  { 
+			TriangleAdjacent ta=t->FindBoundaryEdge(j);
+			if  (! (Triangle *) ta) continue;
+			s0 = ta.EdgeVertex(0);
+			s1 = ta.EdgeVertex(1);
+			I2 A = * s0;
+			I2 B = *ta.EdgeVertex(1);
+			I2 AB = B-A,AC=C-A,BC=B-C;
+			Icoor2  ACAC = (AC,AC), BCBC = (BC,BC);
+			Icoor2  AB2  =   Norme2_2(AB); //  ||AB||^2
+			Icoor2  ABAC  =   (AB,AC);         //  AB.AC|
+
+			double d2;
+			if ( ABAC < 0 )   // DIST A
+			  {
+				if ( (d2=(double) ACAC)  <  dd2) 
+				  {
+					er = ta;
+					l0 = ACAC;
+					l1 = BCBC;
+					cas = 0;
+					s = s0;
+				  }
+			  }
+			else if (ABAC > AB2)  // DIST B
+			  {
+				if ( (d2=(double) BCBC)  <  dd2) 
+				  {
+					dd2 = d2;
+					er = Adj(ta); // other direction
+					l0 = BCBC;
+					l1 = ACAC;
+					cas = 1;
+					s = s1;
+				  }
+			  }
+			else  // DIST AB
+			  { 
+
+				double det_2 =  (double) Det(AB,AC); 
+				det_2 *= det_2; // square of area*2 of triangle ABC
+				d2 = det_2/ (double) AB2; // hauteur^2 in C of of triangle ABC      
+
+				if (d2 < dd2) 
+				  {
+					dd2 = d2;
+					er = ta;
+					l0 = (AC,AC);
+					l1 = (BC,BC);
+					s = 0;
+					cas = -1;
+					b = ((double) ABAC/(double) AB2);
+					a = 1 - b;
+				  }
+			  }
+		  }
+		if (cas ==-2){
+			ISSMERROR("cas==-2");
+		}
+		// l1 = ||C s1||  , l0 = ||C s0||
+		// where s0,s1 are the vertex of the edge er
+
+		if ( s) 
+		  { 
+			t=er;
+			TriangleAdjacent edge(er); 
+
+			int kkk=0;  
+			int linkp = t->link == 0;
+
+			Triangle * tt=t=edge=Adj(Previous(edge));
+			do  {  // loop over vertex s
+				kkk++;
+				if (edge.EdgeVertex(0)!=s && kkk>=10000){
+					ISSMERROR("edge.EdgeVertex(0)!=s && kkk>=10000");
+				}
+
+				int link = tt->link == 0;
+				if ((link + linkp) == 1) 
+				  { // a boundary edge 
+					MeshVertex * st = edge.EdgeVertex(1);
+					I2 I=*st;
+					Icoor2  ll = Norme2_2 (C-I);
+					if (ll < l1) {  // the other vertex is neart 
+						s1=st;
+						l1=ll;
+						er = edge;
+						if(ll<l0) { // change of direction --
+							s1=s;
+							l1=l0;
+							s=st;
+							l0=ll;
+							t=tt;
+							edge=Adj(edge);
+							link=linkp;
+							er = edge;
+						}
+					}
+				  }
+
+				linkp=link;
+				edge=Adj(Previous(edge));
+				tt = edge;
+			} while (t!=tt);
+
+			if (!(Triangle *) er){
+				ISSMERROR("!(Triangle *) er");
+			}
+			I2 A((I2)*er.EdgeVertex(0));
+			I2 B((I2)*er.EdgeVertex(1));
+			I2 AB=B-A,AC=C-A,CB=B-C;
+			double aa =  (double) (AB,AC);
+			double bb =  (double) (AB,CB);
+			if (aa<0)       a=1,b=0;
+			else if(bb<0)   a=0,b=1;
+			else  
+			  {
+				a  = bb/(aa+bb);
+				b  = aa/(aa+bb);
+			  }
+		  }
+		return er;
+	} 
+	/*}}}1*/
+/*FUNCTION ForceEdge{{{1*/
+int ForceEdge(MeshVertex &a, MeshVertex & b,TriangleAdjacent & taret)  { 
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/ForceEdge)*/
+
+	int NbSwap =0;
+	if (!a.t || !b.t){ // the 2 vertex is in a mesh
+		ISSMERROR("!a.t || !b.t");
+	}
+	int k=0;
+	taret=TriangleAdjacent(0,0); // erreur 
+
+	TriangleAdjacent tta(a.t,EdgesVertexTriangle[a.vint][0]);
+	MeshVertex   *v1, *v2 = tta.EdgeVertex(0),*vbegin =v2;
+	// we turn around a in the  direct sens  
+
+	Icoor2 det2 = v2 ? det(*v2,a,b): -1 , det1;
+	if(v2) // normal case 
+	 det2 = det(*v2,a,b);
+	else { // no chance infini vertex try the next
+		tta= Previous(Adj(tta));
+		v2 = tta.EdgeVertex(0);
+		vbegin =v2;
+		if (!v2){
+			ISSMERROR("!v2");
+		}
+		det2 = det(*v2,a,b);
+	}
+
+	while (v2 != &b) {
+		TriangleAdjacent tc = Previous(Adj(tta));    
+		v1 = v2; 
+		v2 = tc.EdgeVertex(0);
+		det1 = det2;
+		det2 =  v2 ? det(*v2,a,b): det2; 
+
+		if((det1 < 0) && (det2 >0)) { 
+			// try to force the edge 
+			MeshVertex * va = &a, *vb = &b;
+			tc = Previous(tc);
+			if (!v1 || !v2){
+				ISSMERROR("!v1 || !v2");
+			}
+			Icoor2 detss = 0,l=0,ks;
+			while ((ks=SwapForForcingEdge(  va,  vb, tc, detss, det1,det2,NbSwap)))
+			 if(l++ > 10000000) {
+				 ISSMERROR("Loop in forcing Egde, nb de swap=%i, nb of try swap (%i) too big",NbSwap,l);
+			 }
+			MeshVertex *aa = tc.EdgeVertex(0), *bb = tc.EdgeVertex(1);
+			if (( aa == &a ) && (bb == &b) ||  (bb ==  &a ) && (aa == &b)) {
+				tc.SetLock();
+				a.Optim(1,0);
+				b.Optim(1,0);
+				taret = tc;
+				return NbSwap;
+			}
+			else 
+			  {
+				taret = tc;
+				return -2; // error  boundary is crossing
+			  }
+		}
+		tta = tc;
+		k++;
+		if (k>=2000){
+			ISSMERROR("k>=2000");
+		}
+		if ( vbegin == v2 ) return -1;// error 
+	}
+
+	tta.SetLock();
+	taret=tta;
+	a.Optim(1,0);
+	b.Optim(1,0);
+	return NbSwap; 
+}
+/*}}}1*/
+/*FUNCTION swap{{{1*/
+void  swap(Triangle *t1,short a1, Triangle *t2,short a2, MeshVertex *s1,MeshVertex *s2,Icoor2 det1,Icoor2 det2){ 
+	/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/swap)*/
+	// --------------------------------------------------------------
+	// short a2=aa[a];// les 2 numero de l arete dans les 2 triangles
+	//                               
+	//               sb                     sb    
+	//             / | \                   /   \                      !
+	//         as1/  |  \                 /a2   \                     !
+	//           /   |   \               /    t2 \                    !
+	//       s1 /t1  | t2 \s2  -->   s1 /___as2___\s2                 !
+	//          \  a1|a2  /             \   as1   /  
+	//           \   |   /               \ t1    /   
+	//            \  |  / as2             \   a1/    
+	//             \ | /                   \   /     
+	//              sa                       sa   
+	//  -------------------------------------------------------------
+	int as1 = NextEdge[a1];
+	int as2 = NextEdge[a2];
+	int ap1 = PreviousEdge[a1];
+	int ap2 = PreviousEdge[a2];
+	(*t1)(VerticesOfTriangularEdge[a1][1]) = s2 ; // avant sb
+	(*t2)(VerticesOfTriangularEdge[a2][1]) = s1  ; // avant sa
+	// mise a jour des 2 adjacences externes 
+	TriangleAdjacent taas1 = t1->Adj(as1),
+						  taas2 = t2->Adj(as2),
+						  tas1(t1,as1), tas2(t2,as2),
+						  ta1(t1,a1),ta2(t2,a2);
+	// externe haut gauche
+	taas1.SetAdj2(ta2, taas1.GetAllFlag_UnSwap());
+	// externe bas droite
+	taas2.SetAdj2(ta1, taas2.GetAllFlag_UnSwap());
+	// remove the Mark  UnMarkSwap 
+	t1->SetUnMarkUnSwap(ap1);
+	t2->SetUnMarkUnSwap(ap2);
+	// interne 
+	tas1.SetAdj2(tas2);
+
+	t1->det = det1;
+	t2->det = det2;
+
+	t1->SetTriangleContainingTheVertex();
+	t2->SetTriangleContainingTheVertex();
+} // end swap 
+/*}}}1*/
+	/*FUNCTION SwapForForcingEdge{{{1*/
+	int SwapForForcingEdge(MeshVertex   *  & pva ,MeshVertex  * &   pvb ,TriangleAdjacent & tt1,Icoor2 & dets1, Icoor2 & detsa,Icoor2 & detsb, int & NbSwap) {
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/SwapForForcingEdge)*/
+		// l'arete ta coupe l'arete pva pvb
+		// de cas apres le swap sa coupe toujours
+		// on cherche l'arete suivante 
+		// on suppose que detsa >0 et detsb <0
+		// attention la routine echange pva et pvb 
+
+		if(tt1.Locked()) return 0; // frontiere croise 
+
+		TriangleAdjacent tt2 = Adj(tt1);
+		Triangle *t1=tt1,*t2=tt2;// les 2 triangles adjacent
+		short a1=tt1,a2=tt2;// les 2 numero de l arete dans les 2 triangles
+		if ( a1<0 || a1>=3 ){
+			ISSMERROR("a1<0 || a1>=3");
+		}
+
+		MeshVertex & sa= (* t1)[VerticesOfTriangularEdge[a1][0]];
+		MeshVertex & s1= (*t1)[OppositeVertex[a1]];
+		MeshVertex & s2= (*t2)[OppositeVertex[a2]];
+
+
+		Icoor2 dets2 = det(*pva,*pvb,s2);
+		Icoor2 det1=t1->det , det2=t2->det ;
+		Icoor2 detT = det1+det2;
+		if ((det1<=0 ) || (det2<=0)){
+			ISSMERROR("(det1<=0 ) || (det2<=0)");
+		}
+		if ( (detsa>=0) || (detsb<=0) ){ // [a,b] cut infinite line va,bb
+			ISSMERROR("(detsa>=0) || (detsb<=0)");
+		}
+		Icoor2 ndet1 = bamg::det(s1,sa,s2);
+		Icoor2 ndet2 = detT - ndet1;
+
+		int ToSwap =0; //pas de swap
+		if ((ndet1 >0) && (ndet2 >0)) 
+		  { // on peut swaper  
+			if ((dets1 <=0 && dets2 <=0) || (dets2 >=0 && detsb >=0))
+			 ToSwap =1; 
+			else // swap alleatoire 
+			 if (BinaryRand()) 
+			  ToSwap =2; 
+		  }
+		if (ToSwap) NbSwap++,
+		 bamg::swap(t1,a1,t2,a2,&s1,&s2,ndet1,ndet2);
+
+		int ret=1;
+
+		if (dets2 < 0) {// haut
+			dets1 = ToSwap ? dets1 : detsa ;
+			detsa = dets2; 
+			tt1 =  Previous(tt2) ;}
+		else if (dets2 > 0){// bas 
+			dets1 = ToSwap ? dets1 : detsb ;
+			detsb = dets2;
+			//xxxx tt1 = ToSwap ? tt1 : Next(tt2);
+			if(!ToSwap) tt1 =  Next(tt2);
+		}
+		else { // changement de sens 
+			ret = -1;
+			Exchange(pva,pvb);
+			Exchange(detsa,detsb);
+			Exchange(dets1,dets2);
+			Exchange(tt1,tt2);
+			dets1=-dets1;
+			dets2=-dets2;
+			detsa=-detsa;
+			detsb=-detsb;
+
+			if (ToSwap) 
+			 if (dets2 < 0) {// haut
+				 dets1 = (ToSwap ? dets1 : detsa) ;
+				 detsa = dets2; 
+				 tt1 =  Previous(tt2) ;}
+			 else if (dets2 > 0){// bas 
+				 dets1 = (ToSwap ? dets1 : detsb) ;
+				 detsb =  dets2;
+				 if(!ToSwap) tt1 =  Next(tt2);
+			 }
+			 else {// on a fin ???
+				 tt1 = Next(tt2);
+				 ret =0;}
+
+		}
+		return ret;
+	}
+	/*}}}1*/
+
+}
Index: issm/trunk/src/c/objects/Bamg/Triangles.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/Triangles.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/Triangles.h	(revision 3913)
@@ -0,0 +1,203 @@
+#ifndef _TRIANGLES_H_
+#define _TRIANGLES_H_
+
+#include "./include.h"
+#include "./BamgOpts.h"
+#include "./BamgMesh.h"
+#include "./BamgGeom.h"
+#include "./Triangle.h"
+#include "./VertexOnGeom.h"
+#include "./VertexOnVertex.h"
+#include "./VertexOnEdge.h"
+#include "./ListofIntersectionTriangles.h"
+
+
+namespace bamg {
+
+	//classes
+	class Geometry;
+	class CrackedEdge;
+	class QuadTree;
+	class SubDomain;
+
+	class Triangles {
+		public:
+
+			Geometry & Gh;   // Geometry
+			Triangles & BTh; // Background Mesh Bth==*this =>no  background 
+			long NbRef;      // counter of ref on the this class if 0 we can delete
+			long nbvx,nbtx;  // nombre max  de sommets , de  triangles
+			long nt,nbv,nbt,nbiv,nbe; // nb of legal triangles, nb of vertex, of triangles, of initial vertices, of edges with reference,
+			long NbOfQuad;  // nb of quadrangle 
+			long NbSubDomains;
+			long NbOutT;    // Nb of oudeside triangle
+			long NbOfTriangleSearchFind;
+			long NbOfSwapTriangle;
+			MeshVertex* vertices;
+			long NbVerticesOnGeomVertex;
+			VertexOnGeom * VerticesOnGeomVertex;
+			long NbVerticesOnGeomEdge;
+			VertexOnGeom * VerticesOnGeomEdge;
+			long NbVertexOnBThVertex;
+			VertexOnVertex *VertexOnBThVertex;
+			long NbVertexOnBThEdge;
+			VertexOnEdge *VertexOnBThEdge;
+			long NbCrackedVertices;
+			long* CrackedVertices;
+			long NbCrackedEdges;
+			CrackedEdge* CrackedEdges;
+			R2 pmin,pmax;    // extrema
+			double coefIcoor; // coef to integer Icoor1;
+			Triangle* triangles;
+			Edge* edges; 
+			QuadTree* quadtree;
+			MeshVertex** ordre;
+			SubDomain* subdomains;
+			ListofIntersectionTriangles lIntTria;
+
+			//Constructors/Destructors
+			Triangles(BamgGeom* bamggeom,BamgMesh* bamgmesh,BamgOpts* bamgopts);
+			Triangles(double* index,double* x,double* y,int nods,int nels);
+			Triangles(Triangles &,Geometry * pGh=0,Triangles* pBTh=0,long nbvxx=0 ); //copy operator
+			Triangles(const Triangles &,const int *flag,const int *bb,BamgOpts* bamgopts); // truncature
+			Triangles(long nbvx,Triangles & BT,BamgOpts* bamgopts,int keepBackVertices=1) :Gh(BT.Gh),BTh(BT) {
+				try {GeomToTriangles1(nbvx,bamgopts,keepBackVertices);}
+				catch(...) { this->~Triangles(); throw; }
+			}
+			Triangles(long nbvx,Geometry & G,BamgOpts* bamgopts) :Gh(G),BTh(*this){
+				try { GeomToTriangles0(nbvx,bamgopts);}
+				catch(...) { this->~Triangles(); throw; }
+			}
+			~Triangles(); 
+
+			//Operators
+			const MeshVertex & operator[]  (long i) const { return vertices[i];};
+			MeshVertex & operator[](long i) { return vertices[i];};
+			const Triangle & operator()  (long i) const { return triangles[i];};
+			Triangle & operator()(long i) { return triangles[i];};
+
+			//Methods
+			void SetIntCoor(const char * from =0);
+			double MinimalHmin() {return 2.0/coefIcoor;}
+			double MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
+			I2 toI2(const R2 & P) const {
+				return  I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
+							,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
+			R2 toR2(const I2 & P) const {
+				return  R2( (double) P.x/coefIcoor+pmin.x, (double) P.y/coefIcoor+pmin.y);
+			}
+			void AddVertex(MeshVertex & s,Triangle * t,Icoor2 *  =0) ;
+			void Insert();
+			void ForceBoundary();
+			void FindSubDomain(int OutSide=0);
+			long TriangleReferenceList(long*) const;
+			void TriangleIntNumbering(long* renumbering);
+			void ShowHistogram() const;
+			void CrackMesh(BamgOpts* bamgopts);
+			void ShowRegulaty() const;
+			void SmoothMetric(double raisonmax) ;
+			void BoundAnisotropy(double anisomax,double hminaniso= 1e-100) ;
+			void MaxSubDivision(double maxsubdiv);
+			Edge** MakeGeometricalEdgeToEdge();
+			long SplitInternalEdgeWithBorderVertices();
+			void MakeQuadrangles(double costheta);
+			int  SplitElement(int choice);
+			void MakeQuadTree();
+			void NewPoints(Triangles &,BamgOpts* bamgopts,int KeepVertices=1);
+			long InsertNewPoints(long nbvold,long & NbTSwap) ; 
+			void ReNumberingTheTriangleBySubDomain(bool justcompress=false);
+			void ReNumberingVertex(long * renu);
+			void SmoothingVertex(int =3,double=0.3);
+			Metric MetricAt (const R2 &) const;
+			GeometricalEdge* ProjectOnCurve( Edge & AB, MeshVertex &  A, MeshVertex & B,double theta, MeshVertex & R,VertexOnEdge & BR,VertexOnGeom & GR);
+			long Number(const Triangle & t) const  { return &t - triangles;}
+			long Number(const Triangle * t) const  { return t - triangles;}
+			long Number(const MeshVertex & t) const  { return &t - vertices;}
+			long Number(const MeshVertex * t) const  { return t - vertices;}
+			long Number(const Edge & t) const  { return &t - edges;}
+			long Number(const Edge * t) const  { return t - edges;}
+			long Number2(const Triangle * t) const  { return t - triangles; }
+			MeshVertex* NearestVertex(Icoor1 i,Icoor1 j) ;
+			Triangle* FindTriangleContaining(const I2 & ,Icoor2 [3],Triangle *tstart=0) const;
+			void ReadMesh(double* index,double* x,double* y,int nods,int nels);
+			void ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);
+			void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts);
+			void ReadMetric(const BamgOpts* bamgopts);
+			void WriteMetric(BamgOpts* bamgopts);
+			void AddMetric(BamgOpts* bamgopts);
+			void BuildMetric0(BamgOpts* bamgopts);
+			void BuildMetric1(BamgOpts* bamgopts);
+			void AddGeometryMetric(BamgOpts* bamgopts);
+			int  isCracked() const {return NbCrackedVertices != 0;}
+			void BuildGeometryFromMesh(BamgOpts* bamgopts=NULL);
+			void ReconstructExistingMesh();
+
+			//Inline methods
+			inline  void ReMakeTriangleContainingTheVertex(){
+				for (int i=0;i<nbv;i++) vertices[i].vint=0, vertices[i].t=NULL;
+				for (int i=0;i<nbt;i++) triangles[i].SetTriangleContainingTheVertex();
+			}
+			inline  void  UnMarkUnSwapTriangle(){
+				for (int i=0;i<nbt;i++)
+				 for(int j=0;j<3;j++)
+				  triangles[i].SetUnMarkUnSwap(j);
+			  }
+			inline  void  SetVertexFieldOn(){
+				for (int i=0;i<nbv;i++)                    vertices[i].onGeometry=NULL;
+				for (int j=0;j<NbVerticesOnGeomVertex;j++) VerticesOnGeomVertex[j].SetOn();
+				for (int k=0;k<NbVerticesOnGeomEdge;k++ )  VerticesOnGeomEdge[k].SetOn();
+			}	       
+			inline  void   SetVertexFieldOnBTh(){
+				for (int i=0;i<nbv;i++)                 vertices[i].onGeometry=NULL;
+				for (int j=0;j<NbVertexOnBThVertex;j++) VertexOnBThVertex[j].SetOnBTh();
+				for (int k=0;k<NbVertexOnBThEdge;k++ )  VertexOnBThEdge[k].SetOnBTh();
+			}
+
+		private:
+			void GeomToTriangles1(long nbvx,BamgOpts* bamgopts,int KeepVertices=1);// the real constructor mesh adaption
+			void GeomToTriangles0(long nbvx,BamgOpts* bamgopts);// the real constructor mesh generator
+			void PreInit(long);
+
+	};
+
+	/*Intermediary*/
+	TriangleAdjacent CloseBoundaryEdge(I2 ,Triangle *, double &,double &) ;
+	TriangleAdjacent CloseBoundaryEdgeV2(I2 A,Triangle *t, double &a,double &b);
+	void  swap(Triangle *t1,short a1,
+				Triangle *t2,short a2,
+				MeshVertex *s1,MeshVertex *s2,Icoor2 det1,Icoor2 det2);
+	int SwapForForcingEdge(MeshVertex   *  & pva ,MeshVertex  * &   pvb ,
+				TriangleAdjacent & tt1,Icoor2 & dets1,
+				Icoor2 & detsa,Icoor2 & detsb, int & nbswap);
+	int ForceEdge(MeshVertex &a, MeshVertex & b,TriangleAdjacent & taret) ;
+	inline TriangleAdjacent Previous(const TriangleAdjacent & ta){
+		return TriangleAdjacent(ta.t,PreviousEdge[ta.a]);
+	}
+	inline TriangleAdjacent Next(const TriangleAdjacent & ta){
+		return TriangleAdjacent(ta.t,NextEdge[ta.a]);
+	}
+	inline  TriangleAdjacent Adj(const TriangleAdjacent & a){
+		return  a.Adj();
+	}
+	inline void Adj(GeometricalEdge * & on,int &i){
+		int j=i;i=on->DirAdj[i];on=on->Adj[j];
+	}
+	inline double qualite(const MeshVertex &va,const MeshVertex &vb,const MeshVertex &vc){
+		double ret; 
+		I2 ia=va,ib=vb,ic=vc;
+		I2 ab=ib-ia,bc=ic-ib,ac=ic-ia;
+		Icoor2 deta=Det(ab,ac);
+		if (deta <=0) ret = -1;
+		else {
+			double a = sqrt((double) (ac,ac)),
+					 b = sqrt((double) (bc,bc)),
+					 c = sqrt((double) (ab,ab)),
+					 p = a+b+c;
+			double h= Max(Max(a,b),c),ro=deta/p;
+			ret = ro/h;
+		}
+		return ret;
+	}
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/VertexOnEdge.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/VertexOnEdge.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/VertexOnEdge.cpp	(revision 3913)
@@ -0,0 +1,21 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "VertexOnEdge.h"
+#include "Triangles.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION VertexOnEdge::Set {{{1*/
+	void VertexOnEdge::Set(const Triangles & Th ,long i,Triangles & ThNew){
+		*this = Th.VertexOnBThEdge[i];  
+		v = ThNew.vertices + Th.Number(v);
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/VertexOnEdge.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/VertexOnEdge.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/VertexOnEdge.h	(revision 3913)
@@ -0,0 +1,36 @@
+#ifndef _VERTEXONEDGE_H_
+#define _VERTEXONEDGE_H_
+
+#include "./include.h"
+#include "./Edge.h"
+
+namespace bamg {
+
+	//classes
+	class Triangles;
+	class MeshVertex;
+
+	class VertexOnEdge {
+
+		public:
+			MeshVertex* v;
+			Edge*   be;
+			double abcisse;
+
+			//Constructors
+			VertexOnEdge( MeshVertex * w, Edge *bw,double s) :v(w),be(bw),abcisse(s) {}
+			VertexOnEdge(){}
+
+			//Operators
+			operator double () const { return abcisse;}
+			operator MeshVertex* () const { return v;}  
+			operator Edge* () const { return be;}  
+			MeshVertex & operator[](int i) const { return (*be)[i];}
+
+			//Methods
+			void SetOnBTh(){v->onBackgroundEdge=this;v->vint=IsVertexOnEdge;}  
+			void Set(const Triangles &,long,Triangles &);  
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/VertexOnGeom.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/VertexOnGeom.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/VertexOnGeom.cpp	(revision 3913)
@@ -0,0 +1,28 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "VertexOnGeom.h"
+#include "Triangles.h"
+#include "Geometry.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION VertexOnGeom::Set {{{1*/
+	void VertexOnGeom::Set(const VertexOnGeom & rec,const Triangles & Th ,Triangles & ThNew){
+		*this = rec;  
+		mv = ThNew.vertices + Th.Number(mv);
+		if (gv)
+		 if (abscisse < 0 )
+		  gv = ThNew.Gh.vertices + Th.Gh.Number(gv);
+		 else
+		  ge = ThNew.Gh.edges + Th.Gh.Number(ge);
+
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/VertexOnGeom.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/VertexOnGeom.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/VertexOnGeom.h	(revision 3913)
@@ -0,0 +1,48 @@
+#ifndef _VERTEXONGEOM_H_
+#define _VERTEXONGEOM_H_
+
+#include "./include.h"
+#include "./GeometricalVertex.h"
+
+namespace bamg {
+
+	//classes
+	class Triangles;
+	class MeshVertex;
+	class GeometricalEdge;
+
+	class VertexOnGeom{
+
+		public:
+
+			MeshVertex* mv;
+			double abscisse;  
+			union{ 
+				GeometricalVertex* gv; // if abscisse <0; 
+				GeometricalEdge*   ge; // if abscisse in [0..1]
+			};
+
+			//Constructors/Destructors
+			VertexOnGeom(): mv(0),abscisse(0){gv=0;} 
+			VertexOnGeom(MeshVertex & m,GeometricalVertex &g) : mv(&m),abscisse(-1){gv=&g;}
+			VertexOnGeom(MeshVertex & m,GeometricalEdge &g,double s) : mv(&m),abscisse(s){ge=&g;}
+
+			//Operators
+			operator MeshVertex*() const  {return mv;}
+			operator GeometricalVertex * () const  {return gv;}
+			operator GeometricalEdge * () const  {return ge;}
+			operator const double & () const {return abscisse;}
+
+			//Methods
+			int  OnGeomVertex()const{return this? abscisse <0 :0;}
+			int  OnGeomEdge() const {return this? abscisse >=0 :0;}
+			int  IsRequiredVertex() {return this? ((abscisse<0 ? (gv?gv->Required():0):0 )) : 0;}
+			void SetOn(){mv->onGeometry=this;mv->vint=IsVertexOnGeom;}
+
+			//Inline methods
+			void Set(const VertexOnGeom&,const Triangles &,Triangles &);  
+
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/VertexOnVertex.cpp
===================================================================
--- issm/trunk/src/c/objects/Bamg/VertexOnVertex.cpp	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/VertexOnVertex.cpp	(revision 3913)
@@ -0,0 +1,21 @@
+#include <cstdio>
+#include <cstring>
+#include <cmath>
+#include <ctime>
+
+#include "VertexOnVertex.h"
+#include "Triangles.h"
+
+namespace bamg {
+
+	/*Constructors/Destructors*/
+
+	/*Methods*/
+	/*FUNCTION VertexOnVertex::Set{{{1*/
+	void VertexOnVertex::Set(const Triangles &Th ,long i,Triangles &ThNew) { 
+		*this = Th.VertexOnBThVertex[i];  
+		v     = ThNew.vertices + Th.Number(v);
+	}
+	/*}}}*/
+
+} 
Index: issm/trunk/src/c/objects/Bamg/VertexOnVertex.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/VertexOnVertex.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/VertexOnVertex.h	(revision 3913)
@@ -0,0 +1,28 @@
+#ifndef _VERTEXONVERTEX_H_
+#define _VERTEXONVERTEX_H_
+
+#include "./include.h"
+#include "./MeshVertex.h"
+
+namespace bamg {
+
+	//classes
+	class Triangles;
+
+	class VertexOnVertex {
+
+		public:
+			MeshVertex* v;
+			MeshVertex* bv;
+
+			//Constructors
+			VertexOnVertex(MeshVertex * w,MeshVertex *bw) :v(w),bv(bw){}
+			VertexOnVertex() {};
+
+			//Methods
+			void SetOnBTh(){v->onBackgroundVertex=bv;v->vint=IsVertexOnVertex;}
+			void Set(const Triangles &,long,Triangles &);
+	};
+
+}
+#endif
Index: issm/trunk/src/c/objects/Bamg/include.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/include.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/include.h	(revision 3913)
@@ -0,0 +1,14 @@
+/*!\file: include.h
+ * \brief prototypes for include.h
+ */ 
+
+#ifndef _INCLUDE2_H_
+#define  _INCLUDE2_H_
+
+
+#include "./macros.h"
+#include "./typedefs.h"
+
+
+#endif //ifndef _INCLUDE2_H_
+
Index: issm/trunk/src/c/objects/Bamg/macros.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/macros.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/macros.h	(revision 3913)
@@ -0,0 +1,29 @@
+#ifndef _BAMGMACROS_H
+#define _BAMGMACROS_H
+
+#include "./typedefs.h"
+
+namespace bamg {
+
+	const double Pi =3.141592653589793238462643383279502884197169399375105820974944592308;
+	const float  fPi=3.141592653589793238462643383279502884197169399375105820974944592308;
+	const  int   IsVertexOnGeom = 8;
+	const  int   IsVertexOnVertex = 16;
+	const  int   IsVertexOnEdge = 32;
+	static const short VerticesOfTriangularEdge[3][2] = {{1,2},{2,0},{0,1}};
+	static const short EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
+	static const short OppositeVertex[3] = {0,1,2};
+	static const short OppositeEdge[3] =  {0,1,2};
+	static const short NextEdge[3] = {1,2,0};
+	static const short PreviousEdge[3] = {2,0,1};
+	static const short NextVertex[3] = {1,2,0};
+	static const short PreviousVertex[3] = {2,0,1};
+#if LONG_BIT > 63
+	const  Icoor1 MaxICoor   = 1073741823; // 2^30-1 =111...111 (29 times)
+#else
+	const  Icoor1 MaxICoor   = 8388608;    // 2^23
+#endif
+	const  Icoor2 MaxICoor22 = Icoor2(2)*Icoor2(MaxICoor) * Icoor2(MaxICoor) ;
+}
+
+#endif
Index: issm/trunk/src/c/objects/Bamg/typedefs.h
===================================================================
--- issm/trunk/src/c/objects/Bamg/typedefs.h	(revision 3913)
+++ issm/trunk/src/c/objects/Bamg/typedefs.h	(revision 3913)
@@ -0,0 +1,20 @@
+#ifndef _BAMGTYPEDEFS_H
+#define _BAMGTYPEDEFS_H
+
+#include "./R2.h"
+
+namespace bamg {
+
+	typedef int  Icoor1;  
+#if LONG_BIT > 63 //64 bits or more
+	typedef long Icoor2;
+#else //32 bits
+	typedef double Icoor2;
+#endif
+	typedef P2<Icoor1,Icoor2>  I2;
+	typedef P2xP2<short,long>  I2xI2;
+	typedef P2<double,double>  R2;
+	typedef P2<double,double>  R2xR2;
+}
+
+#endif
Index: issm/trunk/src/c/objects/DakotaPlugin.cpp
===================================================================
--- issm/trunk/src/c/objects/DakotaPlugin.cpp	(revision 3912)
+++ issm/trunk/src/c/objects/DakotaPlugin.cpp	(revision 3913)
@@ -26,5 +26,5 @@
 #include "../include/include.h"
 #include "../objects/objects.h"
-#include "../Qmux/Qmux.h"
+#include "../modules/Qmux/Qmux.h"
 
 /*Standard includes: */
Index: issm/trunk/src/c/objects/Loads/Riftfront.cpp
===================================================================
--- issm/trunk/src/c/objects/Loads/Riftfront.cpp	(revision 3912)
+++ issm/trunk/src/c/objects/Loads/Riftfront.cpp	(revision 3913)
@@ -16,5 +16,5 @@
 #include "../../shared/shared.h"
 #include "../../include/include.h"
-#include "../../ModelProcessorx/ModelProcessorx.h"
+#include "../../modules/ModelProcessorx/ModelProcessorx.h"
 #include "../objects.h"
 /*}}}*/
Index: issm/trunk/src/c/objects/Model.cpp
===================================================================
--- issm/trunk/src/c/objects/Model.cpp	(revision 3912)
+++ issm/trunk/src/c/objects/Model.cpp	(revision 3913)
@@ -12,9 +12,9 @@
 #include "stdio.h"
 #include "../DataSet/DataSet.h"
-#include "../ModelProcessorx/ModelProcessorx.h"
+#include "../modules/ModelProcessorx/ModelProcessorx.h"
 #include "./objects.h"
 #include "../include/include.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 
Index: issm/trunk/src/c/objects/objects.h
===================================================================
--- issm/trunk/src/c/objects/objects.h	(revision 3912)
+++ issm/trunk/src/c/objects/objects.h	(revision 3913)
@@ -79,7 +79,29 @@
 
 /*Bamg: */
+#include "./Bamg/BamgOpts.h"
 #include "./Bamg/BamgGeom.h"
 #include "./Bamg/BamgMesh.h"
-#include "./Bamg/BamgOpts.h"
+#include "./Bamg/Metric.h"
+#include "./Bamg/DoubleAndInt.h"
+#include "./Bamg/Direction.h"
+#include "./Bamg/MeshVertex.h"
+#include "./Bamg/TriangleAdjacent.h"
+#include "./Bamg/Edge.h"
+#include "./Bamg/GeometricalVertex.h"
+#include "./Bamg/GeometricalEdge.h"
+#include "./Bamg/Curve.h"
+#include "./Bamg/Triangle.h"
+#include "./Bamg/ListofIntersectionTriangles.h"
+#include "./Bamg/GeometricalSubDomain.h"
+#include "./Bamg/SubDomain.h"
+#include "./Bamg/VertexOnGeom.h"
+#include "./Bamg/VertexOnVertex.h"
+#include "./Bamg/VertexOnEdge.h"
+#include "./Bamg/CrackedEdge.h"
+#include "./Bamg/Triangles.h"
+#include "./Bamg/Geometry.h"
+#include "./Bamg/QuadTree.h"
+#include "./Bamg/SetOfE4.h"
+
 
 #endif
Index: issm/trunk/src/c/shared/Bamg/Abs.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/Abs.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/Abs.h	(revision 3913)
@@ -0,0 +1,9 @@
+#ifndef _BAMGABS_H_
+#define _BAMGABS_H_
+
+namespace bamg {
+
+	template<class T> inline T Abs (const T &a){return a <0 ? -a : a;}
+
+}
+#endif
Index: issm/trunk/src/c/shared/Bamg/BigPrimeNumber.cpp
===================================================================
--- issm/trunk/src/c/shared/Bamg/BigPrimeNumber.cpp	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/BigPrimeNumber.cpp	(revision 3913)
@@ -0,0 +1,33 @@
+#include "./BigPrimeNumber.h"
+
+namespace bamg {
+
+	long BigPrimeNumber(long n){
+		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/AGoodNumberPrimeWith)*/
+
+		//list of big prime numbers
+		const long BigPrimeNumber[] ={ 567890359L,
+			567890431L,  567890437L,  567890461L,  567890471L,
+			567890483L,  567890489L,  567890497L,  567890507L,
+			567890591L,  567890599L,  567890621L,  567890629L , 0};
+
+		//initialize o and pi
+		long o =0;
+		long pi=BigPrimeNumber[1];
+
+		//loop until BigPrimeNumber[i]==0 (end of BigPrimeNumber)
+		for (int i=0; BigPrimeNumber[i]; i++){
+
+			//compute r, rest of the remainder of the division of BigPrimeNumber[i] by n
+			long r = BigPrimeNumber[i] % n;
+
+			/*compute oo = min ( r , n-r , |n - 2r|, |n-3r|)*/
+			long oo =Min(Min(r,n-r),Min(Abs(n-2*r),Abs(n-3*r)));
+			if ( o < oo){
+				o=oo;
+				pi=BigPrimeNumber[i];
+			}
+		}
+		return pi; 
+	}
+}
Index: issm/trunk/src/c/shared/Bamg/BigPrimeNumber.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/BigPrimeNumber.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/BigPrimeNumber.h	(revision 3913)
@@ -0,0 +1,12 @@
+#ifndef _BIGPRIMENUMBER_H_
+#define _BIGPRIMENUMBER_H_
+
+#include "./Abs.h"
+#include "./extrema.h"
+
+namespace bamg {
+
+	long BigPrimeNumber(long n);
+
+}
+#endif
Index: issm/trunk/src/c/shared/Bamg/BinaryRand.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/BinaryRand.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/BinaryRand.h	(revision 3913)
@@ -0,0 +1,18 @@
+#ifndef _BINARYRAND_H_
+#define _BINARYRAND_H_
+
+#include <cstdlib>
+
+/*Return 1 or 0 randomly*/
+inline int BinaryRand(){
+	#ifdef RAND_MAX
+		/*RAND_MAX is defined by stdlib.h and is usually 32767*/
+		const long HalfRandMax = RAND_MAX/2;
+		return rand() < HalfRandMax;
+	#else
+		/*For sun machines, RAND_MAX is not defined, use 2^24*/
+		return rand() & 16384;
+	#endif
+} 
+
+#endif
Index: issm/trunk/src/c/shared/Bamg/Exchange.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/Exchange.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/Exchange.h	(revision 3913)
@@ -0,0 +1,6 @@
+#ifndef _EXCHANGE_H_
+#define _EXCHANGE_H_
+
+template<class T> inline void Exchange (T &a,T &b) {T c=a;a=b;b=c;}
+
+#endif
Index: issm/trunk/src/c/shared/Bamg/HeapSort.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/HeapSort.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/HeapSort.h	(revision 3913)
@@ -0,0 +1,67 @@
+#ifndef _HEAPSORT_H_
+#define _HEAPSORT_H_
+
+/*Sort a list of size n*/
+template<class T> inline void  HeapSort(T *c,long n){
+	int l,j,r,i;
+	T   crit;
+	c--;                    //the array must starts at 1 and not 0 
+	if(n<=1) return;        //return if size <=1
+	l=n/2+1;                //initialize l and r
+	r=n;
+	for(;;){
+		if(l<=1){
+			crit  =c[r];
+			c[r--]=c[1];
+			if (r==1){c[1]=crit; return;}
+		}
+		else  crit = c[--l]; 
+		j=l;
+		for(;;){
+			i=j;
+			j=2*j;
+			if  (j>r) {c[i]=crit;break;}
+			if ((j<r) && (c[j] < c[j+1])) j++;//c[j+1]> c[j] -> take j+1 instead of j (larger value)
+			if (crit < c[j]) c[i]=c[j];       //c[j]  > crit -> stock this large value in i(<j)
+			else{c[i]=crit;break;}            //c[j]  < crit -> stock crit in i (<j)
+		}
+	}
+}
+
+/*Sort a list of size n and returns ordering*/
+template<class T> inline void  HeapSort(int** porder,T* c,int n){
+	int  l,j,r,i;
+	T    crit;
+	int  pos;
+	int* order = new int[n];
+	for(i=0;i<n;i++) order[i]=i+1;
+	c--;                    //the array must starts at 1 and not 0 
+	order--;
+	if(n<=1) return;        //return if size <=1
+	l=n/2+1;                //initialize l and r
+	r=n;
+	for(;;){
+		if(l<=1){
+			crit  =c[r]; pos=order[r];
+			c[r--]=c[1]; order[r+1]=order[1];
+			if (r==1){
+				c[1]=crit; order[1]=pos;
+				order++;
+				*porder=order;
+				return;
+			}
+		}
+		else  {crit=c[--l]; pos=order[l];}
+		j=l;
+		for(;;){
+			i=j;
+			j=2*j;
+			if  (j>r) {c[i]=crit;order[i]=pos;break;}
+			if ((j<r) && (c[j] < c[j+1]))j++;
+			if (crit < c[j]) {c[i]=c[j];order[i]=order[j];}
+			else{c[i]=crit;order[i]=pos;break;}
+		}
+	}
+}
+
+#endif
Index: issm/trunk/src/c/shared/Bamg/Norm.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/Norm.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/Norm.h	(revision 3913)
@@ -0,0 +1,8 @@
+#ifndef _BAMGNORM_H_
+#define _BAMGNORM_H_
+
+#include <math.h>
+
+template<class T> inline double Norm(const T &a){return sqrt(a*a);}
+
+#endif
Index: issm/trunk/src/c/shared/Bamg/OppositeAngle.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/OppositeAngle.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/OppositeAngle.h	(revision 3913)
@@ -0,0 +1,12 @@
+#ifndef _OPPOSITEANGLE_H_
+#define _OPPOSITEANGLE_H_
+
+#include "../../objects/Bamg/include.h"
+
+/*Return the opposite angle modulo 2 Pi*/
+namespace bamg {
+	inline float  OppositeAngle(float  a){return a<0 ? fPi+a:a-fPi;}
+	inline double OppositeAngle(double a){return a<0 ?  Pi+a:a- Pi;}
+}
+
+#endif
Index: issm/trunk/src/c/shared/Bamg/det.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/det.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/det.h	(revision 3913)
@@ -0,0 +1,15 @@
+#ifndef _BAMGDET_H_
+#define _BAMGDET_H_
+
+#include "../../objects/Bamg/include.h"
+
+namespace bamg {
+
+	Icoor2 inline det(const I2 &a,const I2 & b,const I2 &c){
+		register  Icoor2 bax = b.x - a.x ,bay = b.y - a.y; 
+		register  Icoor2 cax = c.x - a.x ,cay = c.y - a.y; 
+		return  bax*cay - bay*cax;
+	}
+
+}
+#endif
Index: issm/trunk/src/c/shared/Bamg/extrema.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/extrema.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/extrema.h	(revision 3913)
@@ -0,0 +1,13 @@
+#ifndef _EXTREMA_H_
+#define _EXTREMA_H_
+
+namespace bamg {
+
+	template<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}
+	template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}
+	template<class T> inline T Max3 (const T &a,const T & b,const T & c){return Max(Max(a,b),c);}
+	template<class T> inline T Min3 (const T &a,const T & b,const T & c){return Min(Min(a,b),c);}
+
+}
+
+#endif
Index: issm/trunk/src/c/shared/Bamg/shared.h
===================================================================
--- issm/trunk/src/c/shared/Bamg/shared.h	(revision 3913)
+++ issm/trunk/src/c/shared/Bamg/shared.h	(revision 3913)
@@ -0,0 +1,18 @@
+/* \file shared.h
+ * \brief: header file for all shared  routines.
+ */
+
+
+#ifndef _SHAREDBamg_H_
+#define _SHAREDBamg_H_
+
+#include "Abs.h"
+#include "BigPrimeNumber.h"
+#include "BinaryRand.h"
+#include "det.h"
+#include "Exchange.h"
+#include "extrema.h"
+#include "HeapSort.h"
+#include "OppositeAngle.h"
+
+#endif
Index: issm/trunk/src/c/shared/shared.h
===================================================================
--- issm/trunk/src/c/shared/shared.h	(revision 3912)
+++ issm/trunk/src/c/shared/shared.h	(revision 3913)
@@ -19,4 +19,5 @@
 #include "String/sharedstring.h" //to avoid confusion with <string.h> standard header file
 #include "Threads/issm_threads.h"
+#include "Bamg/shared.h"
 
 
Index: issm/trunk/src/c/solutions/ControlInitialization.cpp
===================================================================
--- issm/trunk/src/c/solutions/ControlInitialization.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/ControlInitialization.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 void ControlInitialization(Model* model){
Index: issm/trunk/src/c/solutions/ControlRestart.cpp
===================================================================
--- issm/trunk/src/c/solutions/ControlRestart.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/ControlRestart.cpp	(revision 3913)
@@ -5,5 +5,5 @@
 
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
 
Index: issm/trunk/src/c/solutions/balancedthickness.cpp
===================================================================
--- issm/trunk/src/c/solutions/balancedthickness.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/balancedthickness.cpp	(revision 3913)
@@ -13,5 +13,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/balancedthickness2.cpp
===================================================================
--- issm/trunk/src/c/solutions/balancedthickness2.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/balancedthickness2.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/balancedthickness2_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/balancedthickness2_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/balancedthickness2_core.cpp	(revision 3913)
@@ -9,5 +9,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* balancedthickness2_core(Model* model){
Index: issm/trunk/src/c/solutions/balancedthickness_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/balancedthickness_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/balancedthickness_core.cpp	(revision 3913)
@@ -9,5 +9,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* balancedthickness_core(Model* model){
Index: issm/trunk/src/c/solutions/balancedvelocities.cpp
===================================================================
--- issm/trunk/src/c/solutions/balancedvelocities.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/balancedvelocities.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/balancedvelocities_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/balancedvelocities_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/balancedvelocities_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* balancedvelocities_core(Model* model){
Index: issm/trunk/src/c/solutions/control_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/control_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/control_core.cpp	(revision 3913)
@@ -4,5 +4,5 @@
 
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
 
Index: issm/trunk/src/c/solutions/convergence.cpp
===================================================================
--- issm/trunk/src/c/solutions/convergence.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/convergence.cpp	(revision 3913)
@@ -4,5 +4,5 @@
 
 #include "../objects/objects.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
 
Index: issm/trunk/src/c/solutions/diagnostic.cpp
===================================================================
--- issm/trunk/src/c/solutions/diagnostic.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/diagnostic.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/diagnostic_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/diagnostic_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/diagnostic_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "../include/include.h"
 
Index: issm/trunk/src/c/solutions/diagnostic_core_linear.cpp
===================================================================
--- issm/trunk/src/c/solutions/diagnostic_core_linear.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/diagnostic_core_linear.cpp	(revision 3913)
@@ -6,5 +6,5 @@
 #include "../objects/objects.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 void diagnostic_core_linear(Vec* pug,FemModel* fem,int analysis_type,int sub_analysis_type){
Index: issm/trunk/src/c/solutions/diagnostic_core_nonlinear.cpp
===================================================================
--- issm/trunk/src/c/solutions/diagnostic_core_nonlinear.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/diagnostic_core_nonlinear.cpp	(revision 3913)
@@ -6,5 +6,5 @@
 #include "../objects/objects.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/gradjcompute_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/gradjcompute_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/gradjcompute_core.cpp	(revision 3913)
@@ -3,5 +3,5 @@
  */ 
 
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
Index: issm/trunk/src/c/solutions/objectivefunctionC.cpp
===================================================================
--- issm/trunk/src/c/solutions/objectivefunctionC.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/objectivefunctionC.cpp	(revision 3913)
@@ -3,5 +3,5 @@
  */ 
 
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
Index: issm/trunk/src/c/solutions/prognostic.cpp
===================================================================
--- issm/trunk/src/c/solutions/prognostic.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/prognostic.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/prognostic2.cpp
===================================================================
--- issm/trunk/src/c/solutions/prognostic2.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/prognostic2.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/prognostic2_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/prognostic2_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/prognostic2_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* prognostic2_core(Model* model){
Index: issm/trunk/src/c/solutions/prognostic_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/prognostic_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/prognostic_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* prognostic_core(Model* model){
Index: issm/trunk/src/c/solutions/slope_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/slope_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/slope_core.cpp	(revision 3913)
@@ -7,5 +7,5 @@
 #include "../objects/objects.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 void slope_core(Vec* pslopex,Vec* pslopey,FemModel* fem, int AnalysisEnum){
Index: issm/trunk/src/c/solutions/slopecompute_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/slopecompute_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/slopecompute_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* slopecompute_core(Model* model){
Index: issm/trunk/src/c/solutions/steadystate.cpp
===================================================================
--- issm/trunk/src/c/solutions/steadystate.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/steadystate.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/steadystate_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/steadystate_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/steadystate_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* steadystate_core(Model* model){
Index: issm/trunk/src/c/solutions/thermal.cpp
===================================================================
--- issm/trunk/src/c/solutions/thermal.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/thermal.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/thermal_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/thermal_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/thermal_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* thermal_core(Model* model){
Index: issm/trunk/src/c/solutions/thermal_core_nonlinear.cpp
===================================================================
--- issm/trunk/src/c/solutions/thermal_core_nonlinear.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/thermal_core_nonlinear.cpp	(revision 3913)
@@ -6,5 +6,5 @@
 #include "../objects/objects.h"
 #include "../EnumDefinitions/EnumDefinitions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 void thermal_core_nonlinear(Vec* ptg,double* pmelting_offset,FemModel* fem,int analysis_type,int sub_analysis_type){
Index: issm/trunk/src/c/solutions/transient.cpp
===================================================================
--- issm/trunk/src/c/solutions/transient.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/transient.cpp	(revision 3913)
@@ -14,5 +14,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "../include/include.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 #include "./solutions.h"
 
Index: issm/trunk/src/c/solutions/transient_core.cpp
===================================================================
--- issm/trunk/src/c/solutions/transient_core.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/transient_core.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* transient_core(Model* model){
Index: issm/trunk/src/c/solutions/transient_core_2d.cpp
===================================================================
--- issm/trunk/src/c/solutions/transient_core_2d.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/transient_core_2d.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* transient_core_2d(Model* model){
Index: issm/trunk/src/c/solutions/transient_core_3d.cpp
===================================================================
--- issm/trunk/src/c/solutions/transient_core_3d.cpp	(revision 3912)
+++ issm/trunk/src/c/solutions/transient_core_3d.cpp	(revision 3913)
@@ -8,5 +8,5 @@
 #include "../EnumDefinitions/EnumDefinitions.h"
 #include "./solutions.h"
-#include "../modules.h"
+#include "../modules/modules.h"
 
 DataSet* transient_core_3d(Model* model){
Index: issm/trunk/src/mex/AverageFilter/AverageFilter.h
===================================================================
--- issm/trunk/src/mex/AverageFilter/AverageFilter.h	(revision 3912)
+++ issm/trunk/src/mex/AverageFilter/AverageFilter.h	(revision 3913)
@@ -11,5 +11,5 @@
 void AverageFilterUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Bamg/Bamg.h
===================================================================
--- issm/trunk/src/mex/Bamg/Bamg.h	(revision 3912)
+++ issm/trunk/src/mex/Bamg/Bamg.h	(revision 3913)
@@ -9,5 +9,5 @@
 void BamgUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.h
===================================================================
--- issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.h	(revision 3912)
+++ issm/trunk/src/mex/BamgConvertMesh/BamgConvertMesh.h	(revision 3913)
@@ -9,5 +9,5 @@
 void BamgConvertMeshUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/BuildNodeSets/BuildNodeSets.h
===================================================================
--- issm/trunk/src/mex/BuildNodeSets/BuildNodeSets.h	(revision 3912)
+++ issm/trunk/src/mex/BuildNodeSets/BuildNodeSets.h	(revision 3913)
@@ -11,5 +11,5 @@
 void BuildNodeSetsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ComputeBasalStress/ComputeBasalStress.h
===================================================================
--- issm/trunk/src/mex/ComputeBasalStress/ComputeBasalStress.h	(revision 3912)
+++ issm/trunk/src/mex/ComputeBasalStress/ComputeBasalStress.h	(revision 3913)
@@ -9,5 +9,5 @@
 void ComputeBasalStressUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ComputePressure/ComputePressure.h
===================================================================
--- issm/trunk/src/mex/ComputePressure/ComputePressure.h	(revision 3912)
+++ issm/trunk/src/mex/ComputePressure/ComputePressure.h	(revision 3913)
@@ -9,5 +9,5 @@
 void ComputePressureUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ConfigureObjects/ConfigureObjects.h
===================================================================
--- issm/trunk/src/mex/ConfigureObjects/ConfigureObjects.h	(revision 3912)
+++ issm/trunk/src/mex/ConfigureObjects/ConfigureObjects.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ConfigureObjectsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ContourToMesh/ContourToMesh.h
===================================================================
--- issm/trunk/src/mex/ContourToMesh/ContourToMesh.h	(revision 3912)
+++ issm/trunk/src/mex/ContourToMesh/ContourToMesh.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ContourToMeshUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ContourToNodes/ContourToNodes.h
===================================================================
--- issm/trunk/src/mex/ContourToNodes/ContourToNodes.h	(revision 3912)
+++ issm/trunk/src/mex/ContourToNodes/ContourToNodes.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ContourToNodesUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ControlConstrain/ControlConstrain.h
===================================================================
--- issm/trunk/src/mex/ControlConstrain/ControlConstrain.h	(revision 3912)
+++ issm/trunk/src/mex/ControlConstrain/ControlConstrain.h	(revision 3913)
@@ -10,5 +10,5 @@
 void ControlConstrainUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ControlOptimization/ControlOptimization.h
===================================================================
--- issm/trunk/src/mex/ControlOptimization/ControlOptimization.h	(revision 3912)
+++ issm/trunk/src/mex/ControlOptimization/ControlOptimization.h	(revision 3913)
@@ -9,5 +9,5 @@
 void ControlOptimizationUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/CostFunction/CostFunction.h
===================================================================
--- issm/trunk/src/mex/CostFunction/CostFunction.h	(revision 3912)
+++ issm/trunk/src/mex/CostFunction/CostFunction.h	(revision 3913)
@@ -9,5 +9,5 @@
 void CostFunctionUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/DepthAverageInput/DepthAverageInput.h
===================================================================
--- issm/trunk/src/mex/DepthAverageInput/DepthAverageInput.h	(revision 3912)
+++ issm/trunk/src/mex/DepthAverageInput/DepthAverageInput.h	(revision 3913)
@@ -9,5 +9,5 @@
 void DepthAverageInputUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Dof/Dof.h
===================================================================
--- issm/trunk/src/mex/Dof/Dof.h	(revision 3912)
+++ issm/trunk/src/mex/Dof/Dof.h	(revision 3913)
@@ -11,5 +11,5 @@
 void DofUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Du/Du.h
===================================================================
--- issm/trunk/src/mex/Du/Du.h	(revision 3912)
+++ issm/trunk/src/mex/Du/Du.h	(revision 3913)
@@ -9,5 +9,5 @@
 void DuUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Echo/Echo.h
===================================================================
--- issm/trunk/src/mex/Echo/Echo.h	(revision 3912)
+++ issm/trunk/src/mex/Echo/Echo.h	(revision 3913)
@@ -9,5 +9,5 @@
 void EchoUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.h
===================================================================
--- issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.h	(revision 3912)
+++ issm/trunk/src/mex/ElementConnectivity/ElementConnectivity.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ElementConnectivityUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ExtrudeInput/ExtrudeInput.h
===================================================================
--- issm/trunk/src/mex/ExtrudeInput/ExtrudeInput.h	(revision 3912)
+++ issm/trunk/src/mex/ExtrudeInput/ExtrudeInput.h	(revision 3913)
@@ -9,5 +9,5 @@
 void ExtrudeInputUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/FieldAverageOntoVertices/FieldAverageOntoVertices.h
===================================================================
--- issm/trunk/src/mex/FieldAverageOntoVertices/FieldAverageOntoVertices.h	(revision 3912)
+++ issm/trunk/src/mex/FieldAverageOntoVertices/FieldAverageOntoVertices.h	(revision 3913)
@@ -11,5 +11,5 @@
 void FieldAverageOntoVerticesUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/FieldDepthAverage/FieldDepthAverage.h
===================================================================
--- issm/trunk/src/mex/FieldDepthAverage/FieldDepthAverage.h	(revision 3912)
+++ issm/trunk/src/mex/FieldDepthAverage/FieldDepthAverage.h	(revision 3913)
@@ -11,5 +11,5 @@
 void FieldDepthAverageUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/FieldExtrude/FieldExtrude.h
===================================================================
--- issm/trunk/src/mex/FieldExtrude/FieldExtrude.h	(revision 3912)
+++ issm/trunk/src/mex/FieldExtrude/FieldExtrude.h	(revision 3913)
@@ -11,5 +11,5 @@
 void FieldExtrudeUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/GetSolutionFromInputs/GetSolutionFromInputs.h
===================================================================
--- issm/trunk/src/mex/GetSolutionFromInputs/GetSolutionFromInputs.h	(revision 3912)
+++ issm/trunk/src/mex/GetSolutionFromInputs/GetSolutionFromInputs.h	(revision 3913)
@@ -9,5 +9,5 @@
 void GetSolutionFromInputsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Gradj/Gradj.h
===================================================================
--- issm/trunk/src/mex/Gradj/Gradj.h	(revision 3912)
+++ issm/trunk/src/mex/Gradj/Gradj.h	(revision 3913)
@@ -9,5 +9,5 @@
 void GradjUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/HoleFiller/HoleFiller.h
===================================================================
--- issm/trunk/src/mex/HoleFiller/HoleFiller.h	(revision 3912)
+++ issm/trunk/src/mex/HoleFiller/HoleFiller.h	(revision 3913)
@@ -11,5 +11,5 @@
 void HoleFillerUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/InterpFromGridToMesh/InterpFromGridToMesh.h
===================================================================
--- issm/trunk/src/mex/InterpFromGridToMesh/InterpFromGridToMesh.h	(revision 3912)
+++ issm/trunk/src/mex/InterpFromGridToMesh/InterpFromGridToMesh.h	(revision 3913)
@@ -9,5 +9,5 @@
 void InterpFromGridToMeshUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/InterpFromMeshToGrid/InterpFromMeshToGrid.h
===================================================================
--- issm/trunk/src/mex/InterpFromMeshToGrid/InterpFromMeshToGrid.h	(revision 3912)
+++ issm/trunk/src/mex/InterpFromMeshToGrid/InterpFromMeshToGrid.h	(revision 3913)
@@ -11,5 +11,5 @@
 void InterpFromMeshToGridUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
===================================================================
--- issm/trunk/src/mex/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h	(revision 3912)
+++ issm/trunk/src/mex/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h	(revision 3913)
@@ -9,5 +9,5 @@
 void InterpFromMeshToMesh2dUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h
===================================================================
--- issm/trunk/src/mex/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h	(revision 3912)
+++ issm/trunk/src/mex/InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h	(revision 3913)
@@ -9,5 +9,5 @@
 void InterpFromMeshToMesh3dUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/MassFlux/MassFlux.h
===================================================================
--- issm/trunk/src/mex/MassFlux/MassFlux.h	(revision 3912)
+++ issm/trunk/src/mex/MassFlux/MassFlux.h	(revision 3913)
@@ -11,5 +11,5 @@
 void MassFluxUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Mergesolutionfromftog/Mergesolutionfromftog.h
===================================================================
--- issm/trunk/src/mex/Mergesolutionfromftog/Mergesolutionfromftog.h	(revision 3912)
+++ issm/trunk/src/mex/Mergesolutionfromftog/Mergesolutionfromftog.h	(revision 3913)
@@ -11,5 +11,5 @@
 void MergesolutionfromftogUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/MeshPartition/MeshPartition.h
===================================================================
--- issm/trunk/src/mex/MeshPartition/MeshPartition.h	(revision 3912)
+++ issm/trunk/src/mex/MeshPartition/MeshPartition.h	(revision 3913)
@@ -11,5 +11,5 @@
 void MeshPartitionUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Misfit/Misfit.h
===================================================================
--- issm/trunk/src/mex/Misfit/Misfit.h	(revision 3912)
+++ issm/trunk/src/mex/Misfit/Misfit.h	(revision 3913)
@@ -9,5 +9,5 @@
 void MisfitUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ModelProcessor/ModelProcessor.h
===================================================================
--- issm/trunk/src/mex/ModelProcessor/ModelProcessor.h	(revision 3912)
+++ issm/trunk/src/mex/ModelProcessor/ModelProcessor.h	(revision 3913)
@@ -9,5 +9,5 @@
 void ModelProcessorUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/MpcNodes/MpcNodes.h
===================================================================
--- issm/trunk/src/mex/MpcNodes/MpcNodes.h	(revision 3912)
+++ issm/trunk/src/mex/MpcNodes/MpcNodes.h	(revision 3913)
@@ -11,5 +11,5 @@
 void MpcNodesUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.h
===================================================================
--- issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.h	(revision 3912)
+++ issm/trunk/src/mex/NodeConnectivity/NodeConnectivity.h	(revision 3913)
@@ -11,5 +11,5 @@
 void NodeConnectivityUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/NormalizeConstraints/NormalizeConstraints.h
===================================================================
--- issm/trunk/src/mex/NormalizeConstraints/NormalizeConstraints.h	(revision 3912)
+++ issm/trunk/src/mex/NormalizeConstraints/NormalizeConstraints.h	(revision 3913)
@@ -9,5 +9,5 @@
 void NormalizeConstraintsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Orth/Orth.h
===================================================================
--- issm/trunk/src/mex/Orth/Orth.h	(revision 3912)
+++ issm/trunk/src/mex/Orth/Orth.h	(revision 3913)
@@ -11,5 +11,5 @@
 void OrthUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/OutputRifts/OutputRifts.h
===================================================================
--- issm/trunk/src/mex/OutputRifts/OutputRifts.h	(revision 3912)
+++ issm/trunk/src/mex/OutputRifts/OutputRifts.h	(revision 3913)
@@ -11,5 +11,5 @@
 void OutputRiftsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ParameterOutput/ParameterOutput.h
===================================================================
--- issm/trunk/src/mex/ParameterOutput/ParameterOutput.h	(revision 3912)
+++ issm/trunk/src/mex/ParameterOutput/ParameterOutput.h	(revision 3913)
@@ -9,5 +9,5 @@
 void ParameterOutputUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/PenaltyConstraints/PenaltyConstraints.h
===================================================================
--- issm/trunk/src/mex/PenaltyConstraints/PenaltyConstraints.h	(revision 3912)
+++ issm/trunk/src/mex/PenaltyConstraints/PenaltyConstraints.h	(revision 3913)
@@ -9,5 +9,5 @@
 void PenaltyConstraintsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/PenaltySystemMatrices/PenaltySystemMatrices.h
===================================================================
--- issm/trunk/src/mex/PenaltySystemMatrices/PenaltySystemMatrices.h	(revision 3912)
+++ issm/trunk/src/mex/PenaltySystemMatrices/PenaltySystemMatrices.h	(revision 3913)
@@ -9,5 +9,5 @@
 void PenaltySystemMatricesUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/ProcessParams/ProcessParams.h
===================================================================
--- issm/trunk/src/mex/ProcessParams/ProcessParams.h	(revision 3912)
+++ issm/trunk/src/mex/ProcessParams/ProcessParams.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ProcessParamsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h
===================================================================
--- issm/trunk/src/mex/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h	(revision 3912)
+++ issm/trunk/src/mex/PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h	(revision 3913)
@@ -11,5 +11,5 @@
 void PropagateFlagsFromConnectivityUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Qmu/Qmu.h
===================================================================
--- issm/trunk/src/mex/Qmu/Qmu.h	(revision 3912)
+++ issm/trunk/src/mex/Qmu/Qmu.h	(revision 3913)
@@ -11,5 +11,5 @@
 void QmuUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Reduceloadfromgtof/Reduceloadfromgtof.h
===================================================================
--- issm/trunk/src/mex/Reduceloadfromgtof/Reduceloadfromgtof.h	(revision 3912)
+++ issm/trunk/src/mex/Reduceloadfromgtof/Reduceloadfromgtof.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ReduceloadfromgtofUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Reducematrixfromgtof/Reducematrixfromgtof.h
===================================================================
--- issm/trunk/src/mex/Reducematrixfromgtof/Reducematrixfromgtof.h	(revision 3912)
+++ issm/trunk/src/mex/Reducematrixfromgtof/Reducematrixfromgtof.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ReducematrixfromgtofUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.h
===================================================================
--- issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.h	(revision 3912)
+++ issm/trunk/src/mex/Reducevectorgtof/Reducevectorgtof.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ReducevectorgtofUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Reducevectorgtos/Reducevectorgtos.h
===================================================================
--- issm/trunk/src/mex/Reducevectorgtos/Reducevectorgtos.h	(revision 3912)
+++ issm/trunk/src/mex/Reducevectorgtos/Reducevectorgtos.h	(revision 3913)
@@ -11,5 +11,5 @@
 void ReducevectorgtosUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/SetStructureField/SetStructureField.h
===================================================================
--- issm/trunk/src/mex/SetStructureField/SetStructureField.h	(revision 3912)
+++ issm/trunk/src/mex/SetStructureField/SetStructureField.h	(revision 3913)
@@ -13,5 +13,5 @@
 #define OUTPUTHANDLE plhs[0]
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Solver/Solver.h
===================================================================
--- issm/trunk/src/mex/Solver/Solver.h	(revision 3912)
+++ issm/trunk/src/mex/Solver/Solver.h	(revision 3913)
@@ -11,5 +11,5 @@
 void SolverUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/SpcNodes/SpcNodes.h
===================================================================
--- issm/trunk/src/mex/SpcNodes/SpcNodes.h	(revision 3912)
+++ issm/trunk/src/mex/SpcNodes/SpcNodes.h	(revision 3913)
@@ -11,5 +11,5 @@
 void SpcNodesUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/SplitSolutionVector/SplitSolutionVector.h
===================================================================
--- issm/trunk/src/mex/SplitSolutionVector/SplitSolutionVector.h	(revision 3912)
+++ issm/trunk/src/mex/SplitSolutionVector/SplitSolutionVector.h	(revision 3913)
@@ -11,5 +11,5 @@
 void SplitSolutionVectorUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/shared/shared.h"
 
Index: issm/trunk/src/mex/SystemMatrices/SystemMatrices.h
===================================================================
--- issm/trunk/src/mex/SystemMatrices/SystemMatrices.h	(revision 3912)
+++ issm/trunk/src/mex/SystemMatrices/SystemMatrices.h	(revision 3913)
@@ -9,5 +9,5 @@
 void SystemMatricesUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/Test/Test.h
===================================================================
--- issm/trunk/src/mex/Test/Test.h	(revision 3912)
+++ issm/trunk/src/mex/Test/Test.h	(revision 3913)
@@ -9,5 +9,5 @@
 void TestUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/TriMesh/TriMesh.h
===================================================================
--- issm/trunk/src/mex/TriMesh/TriMesh.h	(revision 3912)
+++ issm/trunk/src/mex/TriMesh/TriMesh.h	(revision 3913)
@@ -10,5 +10,5 @@
 #include "string.h"
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.h
===================================================================
--- issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.h	(revision 3912)
+++ issm/trunk/src/mex/TriMeshNoDensity/TriMeshNoDensity.h	(revision 3913)
@@ -10,5 +10,5 @@
 #include "string.h"
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/TriMeshProcessRifts/TriMeshProcessRifts.h
===================================================================
--- issm/trunk/src/mex/TriMeshProcessRifts/TriMeshProcessRifts.h	(revision 3912)
+++ issm/trunk/src/mex/TriMeshProcessRifts/TriMeshProcessRifts.h	(revision 3913)
@@ -10,5 +10,5 @@
 #include "string.h"
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/TriMeshRefine/TriMeshRefine.h
===================================================================
--- issm/trunk/src/mex/TriMeshRefine/TriMeshRefine.h	(revision 3912)
+++ issm/trunk/src/mex/TriMeshRefine/TriMeshRefine.h	(revision 3913)
@@ -10,5 +10,5 @@
 #include "string.h"
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/UpdateGeometry/UpdateGeometry.h
===================================================================
--- issm/trunk/src/mex/UpdateGeometry/UpdateGeometry.h	(revision 3912)
+++ issm/trunk/src/mex/UpdateGeometry/UpdateGeometry.h	(revision 3913)
@@ -11,5 +11,5 @@
 void UpdateGeometryUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/UpdateInputsFromConstant/UpdateInputsFromConstant.h
===================================================================
--- issm/trunk/src/mex/UpdateInputsFromConstant/UpdateInputsFromConstant.h	(revision 3912)
+++ issm/trunk/src/mex/UpdateInputsFromConstant/UpdateInputsFromConstant.h	(revision 3913)
@@ -9,5 +9,5 @@
 void UpdateInputsFromConstantUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/UpdateInputsFromSolution/UpdateInputsFromSolution.h
===================================================================
--- issm/trunk/src/mex/UpdateInputsFromSolution/UpdateInputsFromSolution.h	(revision 3912)
+++ issm/trunk/src/mex/UpdateInputsFromSolution/UpdateInputsFromSolution.h	(revision 3913)
@@ -9,5 +9,5 @@
 void UpdateInputsFromSolutionUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/UpdateInputsFromVector/UpdateInputsFromVector.h
===================================================================
--- issm/trunk/src/mex/UpdateInputsFromVector/UpdateInputsFromVector.h	(revision 3912)
+++ issm/trunk/src/mex/UpdateInputsFromVector/UpdateInputsFromVector.h	(revision 3913)
@@ -11,5 +11,5 @@
 void UpdateInputsFromVectorUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
Index: issm/trunk/src/mex/UpdateVertexPositions/UpdateVertexPositions.h
===================================================================
--- issm/trunk/src/mex/UpdateVertexPositions/UpdateVertexPositions.h	(revision 3912)
+++ issm/trunk/src/mex/UpdateVertexPositions/UpdateVertexPositions.h	(revision 3913)
@@ -11,5 +11,5 @@
 void UpdateVertexPositionsUsage(void);
 
-#include "../../c/modules.h"
+#include "../../c/modules/modules.h"
 #include "../../c/DataSet/DataSet.h"
 #include "../../c/shared/shared.h"
