Index: /issm/trunk/src/c/objects/DofVec.cpp
===================================================================
--- /issm/trunk/src/c/objects/DofVec.cpp	(revision 2310)
+++ /issm/trunk/src/c/objects/DofVec.cpp	(revision 2310)
@@ -0,0 +1,429 @@
+/*!\file DofVec.c
+ * \brief: implementation of the DofVec object
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./DofVec.h"
+#include "../shared/shared.h"
+#include "../EnumDefinitions/EnumDefinitions.h"
+
+DofVec::DofVec(){
+	return;
+}
+
+DofVec::~DofVec(){
+	VecFree(&this->vector);
+}
+
+DofVec::DofVec(int total_size,char* name){
+
+	strcpy(this->name,name);
+	this->numdofs=1;
+	this->numentries=total_size;
+	this->vector=NewVec(total_size);
+}
+		
+DofVec::DofVec(int total_size,double default_value,char* name){
+
+	strcpy(this->name,name);
+	this->numdofs=1;
+	this->numentries=total_size;
+	this->vector=NewVec(total_size);
+	VecSet(this->vector,default_value);
+}
+		
+DofVec::DofVec(int dofvec_numdofs,int dofvec_numentries,char* name){
+
+	strcpy(this->name,name);
+	this->numdofs=dofvec_numdofs;
+	this->numentries=dofvec_numentries;
+	this->vector=NewVec(dofvec_numdofs*dofvec_numentries);
+}
+		
+DofVec::DofVec(int dofvec_numdofs,int dofvec_numentries,double default_value,char* name){
+
+	strcpy(this->name,name);
+	this->numdofs=dofvec_numdofs;
+	this->numentries=dofvec_numentries;
+	this->vector=NewVec(dofvec_numdofs*dofvec_numentries);
+	VecSet(this->vector,default_value);
+
+}
+		
+DofVec::DofVec(double* serial_vector,int total_size,char* name){
+	
+	strcpy(this->name,name);
+	this->numdofs=1;
+	this->numentries=total_size;
+	this->vector=SerialToVec(serial_vector,total_size);
+}
+		
+DofVec::DofVec(double* serial_vector,int dofvec_numdofs,int dofvec_numentries,char* name){
+	
+	strcpy(this->name,name);
+	this->numdofs=dofvec_numdofs;
+	this->numentries=dofvec_numentries;
+	this->vector=SerialToVec(serial_vector,dofvec_numdofs*dofvec_numentries);
+}
+		
+DofVec::DofVec(Vec vec,char* name){
+
+	strcpy(this->name,name);
+	this->numdofs=1;
+	VecGetSize(vec,&this->numentries);
+	VecDuplicatePatch(&this->vector,vec);
+	
+}
+		
+DofVec::DofVec(Vec vec,int dofvec_numdofs,int dofvec_numentries,char* name){
+
+	strcpy(this->name,name);
+	this->numdofs=dofvec_numdofs;
+	this->numentries=dofvec_numentries;
+	VecDuplicatePatch(&this->vector,vec);
+}
+	
+#undef __FUNCT__
+#define __FUNCT__ "DofVec::Echo"
+void DofVec::Echo(void){
+
+	printf("DofVec:\n");
+	printf("   name: %s\n",this->name);
+	printf("   numdofs: %i\n",this->numdofs);
+	printf("   numentries: %i\n",this->numentries);
+	printf("   totalsize: %i\n",this->numentries*this->numdofs);
+	printf("   vector: %p\n",this->vector);
+
+}
+
+#undef __FUNCT__
+#define __FUNCT__ "DofVec::DeepEcho"
+void DofVec::DeepEcho(void){
+
+	printf("DofVec:\n");
+	printf("   name: %s\n",this->name);
+	printf("   numdofs: %i\n",this->numdofs);
+	printf("   numentries: %i\n",this->numentries);
+	printf("   totalsize: %i\n",this->numdofs*this->numentries);
+	if(this->vector)VecView(this->vector,PETSC_VIEWER_STDOUT_WORLD);
+}
+
+void  DofVec::Marshall(char** pmarshalled_dataset){
+
+	char* marshalled_dataset=NULL;
+	int   enum_type=0;
+	double* serial_vector=NULL;
+
+	/*recover marshalled_dataset: */
+	marshalled_dataset=*pmarshalled_dataset;
+
+	/*get enum type of DofVec: */
+	enum_type=DofVecEnum();
+	
+	/*marshall enum: */
+	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
+	
+	/*marshall DofVec data: */
+	memcpy(marshalled_dataset,&name,sizeof(name));marshalled_dataset+=sizeof(name);
+	memcpy(marshalled_dataset,&numdofs,sizeof(numdofs));marshalled_dataset+=sizeof(numdofs);
+	memcpy(marshalled_dataset,&numentries,sizeof(numentries));marshalled_dataset+=sizeof(numentries);
+
+	/*Serialize vector before marshalling it: */
+	VecToMPISerial(&serial_vector,this->vector);
+	
+	memcpy(marshalled_dataset,serial_vector,this->numentries*this->numdofs*sizeof(double));marshalled_dataset+=this->numentries*this->numdofs*sizeof(double);
+
+	/*Free ressources: */
+	xfree((void**)&serial_vector);
+	
+	*pmarshalled_dataset=marshalled_dataset;
+	return;
+}
+		
+int   DofVec::MarshallSize(){
+	return sizeof(name)
+		+sizeof(numdofs)
+		+sizeof(numentries)
+		+this->numentries*this->numdofs*sizeof(double)
+		+sizeof(int); //sizeof(int) for enum type
+}
+
+char* DofVec::GetName(void){
+	char* string=NULL;
+	string=(char*)xmalloc((strlen(this->name)+1)*sizeof(char));
+	strcpy(string,this->name);
+	return string;
+}
+
+void  DofVec::Demarshall(char** pmarshalled_dataset){
+
+	char* marshalled_dataset=NULL;
+	int   i;
+	double* serial_vector=NULL;
+
+	/*recover marshalled_dataset: */
+	marshalled_dataset=*pmarshalled_dataset;
+
+	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
+	 *object data (thanks to DataSet::Demarshall):*/
+
+	memcpy(&name,marshalled_dataset,sizeof(name));marshalled_dataset+=sizeof(name);
+	memcpy(&numdofs,marshalled_dataset,sizeof(numdofs));marshalled_dataset+=sizeof(numdofs);
+	memcpy(&numentries,marshalled_dataset,sizeof(numentries));marshalled_dataset+=sizeof(numentries);
+
+	serial_vector=(double*)xmalloc(this->numentries*this->numdofs*sizeof(double));
+	memcpy(serial_vector,marshalled_dataset,this->numentries*this->numdofs*sizeof(double));marshalled_dataset+=this->numentries*this->numdofs*sizeof(double);
+
+	this->vector=SerialToVec(serial_vector,this->numentries*this->numdofs);
+
+	/*Free ressources:*/
+	xfree((void**)&serial_vector);
+
+	/*return: */
+	*pmarshalled_dataset=marshalled_dataset;
+	return;
+}
+
+
+int DofVec::Enum(void){
+
+	return DofVecEnum();
+
+}
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::GetId"
+int DofVec::GetId(void){ 
+	throw ErrorException(__FUNCT__," no id function for DofVec class");
+}
+
+int    DofVec::MyRank(void){ 
+
+	extern int my_rank;
+	return my_rank; 
+}
+
+Object* DofVec::copy() {
+
+	DofVec* dofvec=NULL;
+
+	dofvec=new DofVec(*this); 
+	
+	/*do the dynamic allocation copy: */
+	VecDuplicatePatch(&dofvec->vector,this->vector);
+
+	return (Object*)dofvec;
+
+}
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::GetVecFromDof"
+void DofVec::GetVecFromDof(double** pvector,int dof){
+
+	double* dofset=NULL;
+	double* serial_vector=NULL;
+	Vec     vector=NULL;
+
+	
+	/*check we are not out of bounds: */
+	if (dof>=numdofs){
+		throw ErrorException(__FUNCT__,exprintf("%s%i%s%i\n"," error message: dof ",dof," requested is out of bounds for vector with number of dofs",this->numdofs));
+	}
+
+	dofset=dofsetgen(1,&dof,this->numdofs,this->numdofs*this->numentries);
+	VecPartition(&vector, this->vector, dofset, this->numdofs*this->numentries);
+
+	VecToMPISerial(&serial_vector,vector);
+
+	/*Free ressources:*/
+	VecFree(&vector);
+	xfree((void**)&dofset);
+
+	/*Assign output pointers:*/
+	*pvector=serial_vector;
+}
+
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::GetVecFromDof"
+void DofVec::GetVecFromDof(Vec* pvector, int dof){
+
+	double* dofset=NULL;
+	Vec     vector=NULL;
+
+	
+	/*check we are not out of bounds: */
+	if (dof>=numdofs){
+		throw ErrorException(__FUNCT__,exprintf("%s%i%s%i\n"," error message: dof ",dof," requested is out of bounds for vector with number of dofs",this->numdofs));
+	}
+
+	dofset=dofsetgen(1,&dof,this->numdofs,this->numdofs*this->numentries);
+	VecPartition(&vector, this->vector, dofset, this->numdofs*this->numentries);
+
+	/*Free ressources:*/
+	xfree((void**)&dofset);
+
+	/*Assign output pointers:*/
+	*pvector=vector;
+}
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::GetVecFromDofList"
+void DofVec::GetVecFromDofList(double** pvector, int requested_numdofs,int* requested_doflist){
+
+	int i;
+	double* dofset=NULL;
+	double* serial_vector=NULL;
+	Vec     vector=NULL;
+	
+	/*check we are not out of bounds: */
+	if (requested_numdofs>=this->numdofs) throw ErrorException(__FUNCT__,exprintf("%s%i%s%i\n"," error message: requested dof list has size  ",requested_numdofs," which is out of bounds for vector with number of dofs",this->numdofs));
+
+	for(i=0;i<requested_numdofs;i++){
+		if (requested_doflist[i]>=this->numdofs)throw ErrorException(__FUNCT__,exprintf("%s%i%s%i\n"," error message: requested dof   ",requested_doflist[i]," in list, is out of bounds for vector with number of dofs",this->numdofs));
+	}
+
+	
+	dofset=dofsetgen(requested_numdofs,requested_doflist,this->numdofs,this->numdofs*this->numentries);
+	VecPartition(&vector, this->vector, dofset, this->numdofs*this->numentries);
+
+	VecToMPISerial(&serial_vector,vector);
+
+	/*Free ressources:*/
+	VecFree(&vector);
+	xfree((void**)&dofset);
+
+
+	/*Assign output pointers:*/
+	*pvector=serial_vector;
+}
+
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::GetVecFromDofList"
+void DofVec::GetVecFromDofList(Vec* pvector, int requested_numdofs,int* requested_doflist){
+
+	int i;
+	double* dofset=NULL;
+	Vec     vector=NULL;
+	
+	/*check we are not out of bounds: */
+	if (requested_numdofs>=this->numdofs) throw ErrorException(__FUNCT__,exprintf("%s%i%s%i\n"," error message: requested dof list has size  ",requested_numdofs," which is out of bounds for vector with number of dofs",this->numdofs));
+
+	for(i=0;i<requested_numdofs;i++){
+		if (requested_doflist[i]>=this->numdofs)throw ErrorException(__FUNCT__,exprintf("%s%i%s%i\n"," error message: requested dof   ",requested_doflist[i]," in list, is out of bounds for vector with number of dofs",this->numdofs));
+	}
+
+	
+	dofset=dofsetgen(requested_numdofs,requested_doflist,this->numdofs,this->numdofs*this->numentries);
+	VecPartition(&vector, this->vector, dofset, this->numdofs*this->numentries);
+
+
+	/*Free ressources:*/
+	xfree((void**)&dofset);
+
+	/*Assign output pointers:*/
+	*pvector=vector;
+}
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::SetValuesFromVecAndDofList"
+void DofVec::SetValuesFromVecAndDofList(double* serial_vector,int vector_size,int requested_numdofs,int* requested_doflist){
+
+	double* dofset=NULL;
+	Vec     vector=NULL;
+
+	/*First thing, is the vector of the right size? :*/
+	if (vector_size!=requested_numdofs*this->numentries)throw ErrorException(__FUNCT__,exprintf("%s%i%s%i"," error message: input vector size ",vector_size," is not equal to the expected numdofs*numentries",requested_numdofs*this->numentries));
+
+	/*Create dofset: */
+	dofset=dofsetgen(requested_numdofs,requested_doflist,this->numdofs,this->numdofs*this->numentries);
+
+	/*Make a parallel vector out of the serial input vector: */
+	vector=SerialToVec(serial_vector,vector_size);
+	
+	/*Merge vector into this->vector: */
+	VecMerge(this->vector,vector,dofset,vector_size);
+
+	/*Free ressources:*/
+	xfree((void**)&dofset);
+	VecFree(&vector);
+}
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::SetValuesFromVecAndDofList"
+void DofVec::SetValuesFromVecAndDofList(Vec vector,int requested_numdofs,int* requested_doflist){
+
+	double* dofset=NULL;
+	int    vector_size;
+
+	VecGetSize(vector,&vector_size);
+
+	/*First thing, is the vector of the right size? :*/
+	if (vector_size!=requested_numdofs*this->numentries)throw ErrorException(__FUNCT__,exprintf("%s%i%s%i"," error message: input vector size ",vector_size," is not equal to the expected numdofs*numentries",requested_numdofs*this->numentries));
+
+	/*Create dofset: */
+	dofset=dofsetgen(requested_numdofs,requested_doflist,this->numdofs,this->numdofs*this->numentries);
+
+	/*Merge vector into this->vector: */
+	VecMerge(this->vector,vector,dofset,vector_size);
+
+	/*Free ressources:*/
+	xfree((void**)&dofset);
+}
+
+#undef __FUNCT__ 
+#define __FUNCT__ "DofVec::SetValuesFromVecAndDofList"
+void DofVec::SetValuesFromVecAndDofList(DofVec* vector,int requested_numdofs,int* requested_doflist){
+
+	double* dofset=NULL;
+	int    vector_size;
+
+	vector_size=vector->Size();
+
+	/*First thing, is the vector of the right size? :*/
+	if (vector_size!=requested_numdofs*this->numentries)throw ErrorException(__FUNCT__,exprintf("%s%i%s%i"," error message: input vector size ",vector_size," is not equal to the expected numdofs*numentries",requested_numdofs*this->numentries));
+
+	/*Create dofset: */
+	dofset=dofsetgen(requested_numdofs,requested_doflist,this->numdofs,this->numdofs*this->numentries);
+
+	/*Merge vector into this->vector: */
+	VecMerge(this->vector,vector->GetVec(),dofset,vector_size);
+
+	/*Free ressources:*/
+	xfree((void**)&dofset);
+}
+
+double* DofVec::GetValuesFromIndex(int index_size,int* index){
+
+	double* values=NULL;
+	double* serial_vector=NULL;
+	int i;
+
+	/*Serialize vector first, then allocate a buffer and fill it with the correct 
+	 * values: */
+	VecToMPISerial(&serial_vector,this->vector);
+
+	values=(double*)xmalloc(index_size*sizeof(double));
+	for(i=0;i<index_size;i++){
+		values[i]=serial_vector[index[i]];
+	}
+
+	/*Free ressources:*/
+	xfree((void**)&serial_vector);
+
+	return values;
+}
+
+int DofVec::Size(){
+	return this->numdofs*this->numentries;
+}
+
+Vec     DofVec::GetVec(void){
+	return vector;
+}
Index: /issm/trunk/src/c/objects/DofVec.h
===================================================================
--- /issm/trunk/src/c/objects/DofVec.h	(revision 2310)
+++ /issm/trunk/src/c/objects/DofVec.h	(revision 2310)
@@ -0,0 +1,64 @@
+/*! \file DovVec.h 
+ *  \brief: header file for dofvec object
+ */
+
+#ifndef _DOFVEC_H_
+#define _DOFVEC_H_
+
+
+#include "./Object.h"
+#include "../toolkits/toolkits.h"
+
+#define DOFVECNAMESIZE 20
+
+class DofVec: public Object{
+
+	private: 
+
+		char name[DOFVECNAMESIZE];
+		int numdofs; //number  of dofs per entry.
+		int numentries; //number of entries
+		Vec vector; //vector itself.
+
+	public:
+
+		DofVec();
+		DofVec(int total_size,char* name); //default numdofs=1, numentries=total_size, default_value=0;
+		DofVec(int total_size,double default_value,char* name); //default numdofs=1, numentries=total_size
+		DofVec(int numdofs,int numentries,char* name);  //default_value=0;
+		DofVec(int numdofs,int numentries,double default_value,char* name); 
+		DofVec(double* serial_vector,int size,char* name); //default numdofs=1;
+		DofVec(double* serial_vector,int numdofs,int numentries,char* name);
+		DofVec(Vec vec,char* name); //default numdofs=1;
+		DofVec(Vec vec,int numdofs,int numentries,char* name); 
+
+		~DofVec();
+
+		void  Echo();
+		void  DeepEcho();
+		void  Marshall(char** pmarshalled_dataset);
+		int   MarshallSize();
+		char* GetName();
+		void  Demarshall(char** pmarshalled_dataset);
+		int   Enum();
+		int   GetId(); 
+		int   MyRank();
+		int   Size();
+
+		Object* copy();
+
+		Vec     GetVec(void);
+		void    GetVecFromDof(double** pvector,int dof);
+		void    GetVecFromDof(Vec* vector,int dof);
+		void    GetVecFromDofList(double** pvector, int numdofs,int* doflist);
+		void    GetVecFromDofList(Vec* pvector, int numdofs,int* doflist);
+		
+		void    SetValuesFromVecAndDofList(double* vector,int vector_size,int numdofs,int* doflist);
+		void    SetValuesFromVecAndDofList(Vec vector,int numdofs,int* doflist);
+		void    SetValuesFromVecAndDofList(DofVec* vector,int numdofs,int* doflist);
+		
+		double* GetValuesFromIndex(int index_size,int* index);
+		
+
+};
+#endif  /* _DOFVEC_H */
