Index: issm/trunk/src/c/Makefile.am
===================================================================
--- issm/trunk/src/c/Makefile.am	(revision 11527)
+++ issm/trunk/src/c/Makefile.am	(revision 11995)
@@ -1,3 +1,4 @@
-INCLUDES = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @MATLABINCL@  @METISINCL@  @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@  @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@  @TRIANGLEINCL@ @HYPREINCL@ @MLINCL@ @TAOINCL@
+INCLUDES = @DAKOTAINCL@ @SHAPELIBINCL@ @PETSCINCL@ @SLEPCINCL@ @MPIINCL@ @MATLABINCL@ @METISINCL@ @CHACOINCL@ @SCOTCHINCL@ @PLAPACKINCL@ @BLASLAPACKINCL@ @MKLINCL@ @MUMPSINCL@ @TRIANGLEINCL@ @HYPREINCL@ @MLINCL@ @TAOINCL@ @ADIC2INCL@ @ADOLCINCL@ @GSLINCL@ @BOOSTINCL@ @PYTHONINCL@ @PYTHON_NUMPYINCL@
+
 EXEEXT=$(ISSMEXT)
 
@@ -12,5 +13,5 @@
 else
 if NOPARALLEL
-lib_LIBRARIES = libISSM.a  libOverload.a
+lib_LIBRARIES = libISSM.a libOverload.a
 else
 lib_LIBRARIES = libISSM.a libpISSM.a libOverload.a
@@ -21,5 +22,5 @@
 #sources
 #Core sources{{{1
-core_sources   = ./include/macros.h\
+core_sources = ./include/macros.h\
 					./include/typedefs.h\
 					./include/types.h\
@@ -79,6 +80,4 @@
 					./objects/ExternalResults/StringExternalResult.h\
 					./objects/ExternalResults/StringExternalResult.cpp\
-					./objects/ExternalResults/PetscVecExternalResult.h\
-					./objects/ExternalResults/PetscVecExternalResult.cpp\
 					./objects/Elements/Tria.h\
 					./objects/Elements/Tria.cpp\
@@ -120,4 +119,8 @@
 					./objects/Numerics/ElementVector.h\
 					./objects/Numerics/ElementVector.cpp\
+					./objects/Numerics/Matrix.h\
+					./objects/Numerics/Matrix.cpp\
+					./objects/Numerics/Vector.h\
+					./objects/Numerics/Vector.cpp\
 					./objects/Params/Param.h\
 					./objects/Params/BoolParam.cpp\
@@ -133,6 +136,4 @@
 					./objects/Params/FileParam.cpp\
 					./objects/Params/FileParam.h\
-					./objects/Params/PetscMatParam.cpp\
-					./objects/Params/PetscMatParam.h\
 					./objects/Params/StringArrayParam.cpp\
 					./objects/Params/StringArrayParam.h\
@@ -145,8 +146,10 @@
 					./objects/Params/DoubleVecParam.cpp\
 					./objects/Params/DoubleVecParam.h\
-					./objects/Params/PetscVecParam.cpp\
-					./objects/Params/PetscVecParam.h\
 					./objects/Params/StringParam.cpp\
 					./objects/Params/StringParam.h\
+					./objects/Params/MatrixParam.h\
+					./objects/Params/MatrixParam.cpp\
+					./objects/Params/VectorParam.h\
+					./objects/Params/VectorParam.cpp\
 					./Container/Container.h\
 					./Container/Constraints.h\
@@ -191,5 +194,5 @@
 					./shared/Numerics/XZvectorsToCoordinateSystem.cpp\
 					./shared/Numerics/UnitConversion.cpp\
-					./shared/Numerics/PetscOptionsFromAnalysis.cpp\
+					./shared/Numerics/OptionsFromAnalysis.cpp\
 					./shared/Exceptions/exceptions.h\
 					./shared/Exceptions/Exceptions.cpp\
@@ -204,46 +207,24 @@
 					./shared/Elements/GetGlobalDofList.cpp\
 					./shared/Elements/GetNumberOfDofs.cpp\
-					./shared/Elements/CoordinateSystemTransform.cpp\
 					./shared/String/sharedstring.h\
-					./toolkits/petsc\
-					./toolkits/petsc/patches\
-					./toolkits/petsc/patches/SolverEnum.h\
-					./toolkits/petsc/patches/petscpatches.h\
-					./toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp\
-					./toolkits/petsc/patches/MatlabVectorToPetscVector.cpp\
-					./toolkits/petsc/patches/PetscMatrixToMatlabMatrix.cpp\
-					./toolkits/petsc/patches/PetscVectorToMatlabVector.cpp\
-					./toolkits/petsc/patches/MatlabMatrixToDoubleMatrix.cpp\
-					./toolkits/petsc/patches/MatlabVectorToDoubleVector.cpp\
-					./toolkits/petsc/patches/PetscDetermineLocalSize.cpp\
-					./toolkits/petsc/patches/VecTranspose.cpp\
-					./toolkits/petsc/patches/VecToMPISerial.cpp\
-					./toolkits/petsc/patches/MatToSerial.cpp\
-					./toolkits/petsc/patches/VecMerge.cpp\
-					./toolkits/petsc/patches/NewVec.cpp\
-					./toolkits/petsc/patches/PetscOptionsDetermineSolverType.cpp\
-					./toolkits/petsc/patches/PetscOptionsInsertMultipleString.cpp\
-					./toolkits/petsc/patches/NewMat.cpp\
-					./toolkits/petsc/patches/SerialToVec.cpp\
-					./toolkits/petsc/patches/VecFree.cpp\
-					./toolkits/petsc/patches/VecDuplicatePatch.cpp\
-					./toolkits/petsc/patches/KSPFree.cpp\
-					./toolkits/petsc/patches/ISFree.cpp\
-					./toolkits/petsc/patches/MatFree.cpp\
-					./toolkits/petsc/patches/GetOwnershipBoundariesFromRange.cpp\
-					./toolkits/petsc/patches/VecPartition.cpp\
-					./toolkits/petsc/patches/MatPartition.cpp\
-					./toolkits/petsc/patches/MatInvert.cpp\
-					./toolkits/petsc/patches/MatMultPatch.cpp\
-					./toolkits/petsc/petscincludes.h\
+					./shared/Wrapper/wrappershared.h\
+					./shared/Wrapper/ModuleBoot.cpp\
+					./shared/Wrapper/ModuleEnd.cpp\
 					./toolkits/mpi/mpiincludes.h\
 					./toolkits/mpi/patches/mpipatches.h\
+					./toolkits/mpi/patches/DetermineLocalSize.cpp\
 					./toolkits/mpi/patches/MPI_Upperrow.cpp\
 					./toolkits/mpi/patches/MPI_Lowerrow.cpp\
 					./toolkits/mpi/patches/MPI_Boundariesfromrange.cpp\
 					./toolkits/metis/metisincludes.h\
+					./toolkits/issm/issmtoolkit.h\
+					./toolkits/issm/SeqVec.h\
+					./toolkits/issm/SeqVec.cpp\
+					./toolkits/issm/SeqMat.h\
+					./toolkits/issm/SeqMat.cpp\
 					./toolkits/metis/patches/metispatches.h\
 					./toolkits/metis/patches/METIS_PartMeshNodalPatch.cpp\
 					./toolkits/triangle/triangleincludes.h\
+					./toolkitsenums.h\
 					./toolkits.h\
 					./io/io.h\
@@ -253,5 +234,4 @@
 					./io/PrintfFunction.cpp\
 					./EnumDefinitions/EnumDefinitions.h\
-					./EnumDefinitions/EnumToModelField.cpp\
 					./modules/ModelProcessorx/ModelProcessorx.h\
 					./modules/ModelProcessorx/ModelProcessorx.cpp\
@@ -343,5 +323,4 @@
 					./modules/Solverx/Solverx.cpp\
 					./modules/Solverx/Solverx.h\
-					./modules/Solverx/DofTypesToIndexSet.cpp\
 					./modules/VecMergex/VecMergex.cpp\
 					./modules/VecMergex/VecMergex.h\
@@ -419,7 +398,5 @@
 
 thermal_psources = ./solutions/thermal_core.cpp\
-					    ./solutions/thermal_core_step.cpp\
 					    ./solutions/enthalpy_core.cpp\
-					    ./solutions/enthalpy_core_step.cpp\
 					    ./solvers/solver_thermal_nonlinear.cpp
 #}}}
@@ -473,5 +450,5 @@
 					  ./solutions/controlrestart.cpp\
 					  ./solutions/controlconvergence.cpp\
-					  ./solutions/objectivefunctionC.cpp\
+					  ./solutions/objectivefunction.cpp\
 					  ./solutions/gradient_core.cpp\
 					  ./solutions/adjointdiagnostic_core.cpp\
@@ -503,4 +480,5 @@
 					      ./modules/ModelProcessorx/DiagnosticHutter/CreateConstraintsDiagnosticHutter.cpp \
 					      ./modules/ModelProcessorx/DiagnosticHutter/CreateLoadsDiagnosticHutter.cpp \
+							./shared/Elements/CoordinateSystemTransform.cpp\
 							./shared/Elements/TransformLoadVectorCoord.cpp \
 							./shared/Elements/TransformStiffnessMatrixCoord.cpp \
@@ -717,16 +695,62 @@
 #}}}
 #Matlab sources  {{{1
-matlab_sources= ./shared/Matlab/matlabshared.h\
-				    ./shared/Matlab/ModuleBoot.cpp\
-				    ./shared/Matlab/ModuleEnd.cpp\
-				    ./shared/Matlab/mxGetAssignedField.cpp\
-				    ./shared/Matlab/mxGetField.cpp\
-				    ./shared/Matlab/CheckNumMatlabArguments.cpp\
-				    ./toolkits/matlab/matlabincludes.h\
+matlab_sources= ./toolkits/matlab/matlabincludes.h\
 				    ./toolkits/matlab/MatlabNArrayToNArray.cpp\
+				    ./toolkits/double/MatlabVectorToDoubleVector.cpp\
+				    ./toolkits/double/double.h\
+				    ./toolkits/double/MatlabMatrixToDoubleMatrix.cpp\
 				    ./io/Matlab/matlabio.h\
+				    ./io/Matlab/CheckNumMatlabArguments.cpp\
+				    ./io/Matlab/mxGetAssignedField.cpp\
 				    ./io/Matlab/WriteMatlabData.cpp\
 				    ./io/Matlab/FetchMatlabData.cpp\
 				    ./io/Matlab/OptionParse.cpp
+#}}}
+#Python sources  {{{1
+python_sources=     ./io/Python/pythonio.h\
+				    ./io/Python/WritePythonData.cpp\
+				    ./io/Python/CheckNumPythonArguments.cpp\
+				    ./io/Python/FetchPythonData.cpp
+#}}}
+#Petsc sources  {{{1
+petsc_sources= ./toolkits/petsc\
+					./toolkits/petsc/patches\
+					./toolkits/petsc/patches/SolverEnum.h\
+					./toolkits/petsc/patches/petscpatches.h\
+					./toolkits/petsc/patches/MatlabMatrixToPetscMatrix.cpp\
+					./toolkits/petsc/patches/MatlabVectorToPetscVector.cpp\
+					./toolkits/petsc/patches/PetscMatrixToMatlabMatrix.cpp\
+					./toolkits/petsc/patches/PetscVectorToMatlabVector.cpp\
+					./toolkits/petsc/patches/VecTranspose.cpp\
+					./toolkits/petsc/patches/VecToMPISerial.cpp\
+					./toolkits/petsc/patches/MatToSerial.cpp\
+					./toolkits/petsc/patches/VecMerge.cpp\
+					./toolkits/petsc/patches/NewVec.cpp\
+					./toolkits/petsc/patches/PetscOptionsDetermineSolverType.cpp\
+					./toolkits/petsc/patches/PetscOptionsInsertMultipleString.cpp\
+					./toolkits/petsc/patches/NewMat.cpp\
+					./toolkits/petsc/patches/SerialToVec.cpp\
+					./toolkits/petsc/patches/VecFree.cpp\
+					./toolkits/petsc/patches/VecDuplicatePatch.cpp\
+					./toolkits/petsc/patches/KSPFree.cpp\
+					./toolkits/petsc/patches/ISFree.cpp\
+					./toolkits/petsc/patches/MatFree.cpp\
+					./toolkits/petsc/patches/GetOwnershipBoundariesFromRange.cpp\
+					./toolkits/petsc/patches/VecPartition.cpp\
+					./toolkits/petsc/patches/MatPartition.cpp\
+					./toolkits/petsc/patches/MatInvert.cpp\
+					./toolkits/petsc/patches/MatMultPatch.cpp\
+					./toolkits/petsc/patches/ISSMToPetscMatrixType.cpp\
+					./toolkits/petsc/patches/ISSMToPetscInsertMode.cpp\
+					./toolkits/petsc/patches/ISSMToPetscNormMode.cpp\
+					./toolkits/petsc/petscincludes.h\
+					./shared/Numerics/PetscOptionsFromAnalysis.cpp\
+					./modules/Solverx/SolverxPetsc.cpp\
+					./modules/Solverx/DofTypesToIndexSet.cpp
+
+#}}}
+#Gsl sources  {{{1
+gsl_sources= ./modules/Solverx/SolverxGsl.cpp
+
 #}}}
 #Serialsources  {{{1
@@ -769,4 +793,6 @@
 			./modules/TriaSearchx/TriaSearchx.h\
 			./modules/TriaSearchx/TriaSearchx.cpp\
+			./modules/TriMeshx/TriMeshx.h\
+			./modules/TriMeshx/TriMeshx.cpp\
 			./modules/PointCloudFindNeighborsx/PointCloudFindNeighborsx.h\
 			./modules/PointCloudFindNeighborsx/PointCloudFindNeighborsx.cpp\
@@ -816,5 +842,6 @@
 
 #ISSM sources are a combination of core sources and sources related to specific capabilities (which can 
-#be activated by autotools conditionals {{{1
+#be activated by autotools conditionals 
+#{{{1
 
 #First the core
@@ -828,4 +855,15 @@
 endif
 
+if PETSC
+issm_sources  +=  $(petsc_sources)
+issm_psources +=  $(petsc_psources)
+endif
+
+if GSL
+issm_sources  +=  $(gsl_sources)
+issm_psources +=  $(gsl_psources)
+endif
+
+
 if TRANSIENT
 issm_sources  +=  $(transient_sources)
@@ -891,21 +929,29 @@
 
 #ISSM serial library {{{1
+if SERIAL
 libISSM_a_SOURCES  = $(issm_sources)
 libISSM_a_SOURCES += $(serial_sources)
 libISSM_a_SOURCES += $(bamg_sources)
 libISSM_a_SOURCES += $(kml_sources)
+libISSM_a_CXXFLAGS = -fPIC -D_SERIAL_ -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXFLAGS) $(CXXOPTFLAGS) 
+#libISSM_a_CXXFLAGS = -D_SERIAL_ -DTRILIBRARY -DANSI_DECLARATORS -DNO_TIMER   $(CXXFLAGS) $(CXXOPTFLAGS) 
+
+if PYTHON
+libISSM_a_CXXFLAGS+=  -DNPY_NO_DEPRECATED_API 
+libISSM_a_SOURCES += $(python_sources)
+endif
+
+if MATLAB
 libISSM_a_SOURCES += $(matlab_sources)
-
-libISSM_a_CXXFLAGS = -fPIC -DMATLAB -D_SERIAL_ -D_GNU_SOURCE -fno-omit-frame-pointer -pthread -D_CPP_  $(CXXFLAGS) $(CXXOPTFLAGS) 
-if LARGEARRAYS
-libISSM_a_CXXFLAGS += -D__GCC4BUILD__  
-else
-libISSM_a_CXXFLAGS += -DMX_COMPAT_32 
+endif
+
 endif
 #}}}
 #ISSM parallel library {{{1
+if PARALLEL
 libpISSM_a_SOURCES  = $(issm_sources)
 libpISSM_a_SOURCES += $(issm_psources)
 libpISSM_a_CXXFLAGS = -fPIC -D_PARALLEL_   -D_C_ $(CXXFLAGS) $(CXXOPTFLAGS) 
+endif
 #}}}
 #Overload library, to overload any non-standard symbols. {{{1
@@ -918,14 +964,47 @@
 bin_PROGRAMS = 
 else 
-bin_PROGRAMS = issm
+bin_PROGRAMS = issm 
 endif
 
 #Standard libraries
-LDADD =      ./libpISSM.a ./libOverload.a
+LDADD = ./libpISSM.a ./libOverload.a
 
 #External packages
-LDADD += $(PETSCLIB) $(TAOLIB) $(FLIBS) $(PLAPACKLIB)  $(MUMPSLIB) $(SCALAPACKLIB)  $(BLACSLIB) $(HYPRELIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB)  $(MKLLIB) $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(ADIC2LIB)  $(OSLIBS)
+LDADD += $(PETSCLIB) $(TAOLIB) $(FLIBS) $(PLAPACKLIB) $(MUMPSLIB) $(SCALAPACKLIB) $(BLACSLIB) $(HYPRELIB) $(MLLIB) $(DAKOTALIB) $(METISLIB) $(CHACOLIB) $(SCOTCHLIB) $(BLASLAPACKLIB) $(MKLLIB) $(MPILIB) $(MATHLIB) $(FORTRANLIB) $(GRAPHICSLIB) $(MULTITHREADINGLIB) $(OSLIBS) $(GSLLIB)
 
 issm_SOURCES = solutions/issm.cpp
-issm_CXXFLAGS= -fPIC -D_PARALLEL_  $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) 
-#}}}
+issm_CXXFLAGS= -fPIC -D_PARALLEL_ $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) 
+#}}}
+#Automatic differentiation: append this fold to the end of the src/c/Makefile.am to get this Makefile.am {{{
+if ADIC2 
+lib_LIBRARIES += libAD.a libpISSMRose.a
+
+#ADIC2 library, for automatic differentiation 
+#libAD_a_SOURCES = ./mini1.ad.c
+libAD_a_SOURCES = 
+libAD_a_CFLAGS = -fPIC -D_PARALLEL_   -D_C_ $(COPTFLAGS)
+
+
+
+#test rose preprocessing 
+%.r2cpp.cpp : %.cpp
+	testTranslator -rose:o $@ -rose:skipfinalCompileStep -DHAVE_CONFIG_H -D_PARALLEL_ -D_C_ -I. -I../.. $(INCLUDES) $<
+libpISSMRose_a_SOURCES = $(libpISSM_a_SOURCES:.cpp=.r2cpp.cpp)
+libpISSMRose_a_CXXFLAGS= -fPIC -D_PARALLEL_ -D_C_ $(CXXOPTFLAGS)
+
+
+
+#Automatic differentiation rules: 
+%.ad.c: %.c
+	adic2 -mforward  $< --nary
+
+
+
+#Executable
+bin_PROGRAMS +=  issmRose.exe
+issmRose_exe_LDADD = ./libpISSMRose.a $(LDADD)
+issmRose_exe_SOURCES = solutions/issm.cpp
+issmRose_exe_CXXFLAGS= -fPIC -D_PARALLEL_  $(CXXOPTFLAGS) $(COPTFLAGS) 
+LDADD +=  $(ADIC2LIB) 
+
+endif #}}}
