Index: /issm/trunk/src/c/objects/Pengrid.cpp
===================================================================
--- /issm/trunk/src/c/objects/Pengrid.cpp	(revision 3622)
+++ /issm/trunk/src/c/objects/Pengrid.cpp	(revision 3623)
@@ -34,6 +34,7 @@
 /*}}}1*/
 /*FUNCTION Pengrid::Pengrid(int id, int node_ids int matpar_id){{{1*/
-Pengrid::Pengrid(int pengrid_id,int pengrid_node_id, int pengrid_matpar_id): 
-	hnode(pengrid_node_ids,1),
+Pengrid::Pengrid(int pengrid_id,int pengrid_node_id, int pengrid_element_id,int pengrid_matpar_id): 
+	hnode(pengrid_node_id,1),
+	helement(pengrid_element_id,1),
 	hmatice(&pengrid_matice_id,1),
 	hmatpar(&pengrid_matpar_id,1)
@@ -52,6 +53,7 @@
 /*}}}*/
 /*FUNCTION Pengrid::Pengrid(int id, Hook* hnodes, Hook* hmatice, Hook* hmatpar, DataSet* parameters, Inputs* pengrid_inputs) {{{1*/
-Pengrid::Pengrid(int pengrid_id,Hook* pengrid_hnode, Hook* pengrid_hmatpar, Parameters* pengrid_parameters, Inputs* pengrid_inputs):
+Pengrid::Pengrid(int pengrid_id,Hook* pengrid_hnode, Hook* pengrid_helement,Hook* pengrid_hmatpar, Parameters* pengrid_parameters, Inputs* pengrid_inputs):
 	hnode(pengrid_hnode),
+	helement(pengrid_helement),
 	hmatpar(pengrid_hmatpar)
 {
@@ -94,82 +96,33 @@
 }
 /*}}}1*/
-/*FUNCTION Pengrid::Pengrid(int i, IoModel* iomodel){{{1*/
-Pengrid::Pengrid(int index, IoModel* iomodel){ //i is the element index
+/*FUNCTION Pengrid::Pengrid(int index, int id, IoModel* iomodel){{{1*/
+Pengrid::Pengrid(int id, int index, IoModel* iomodel){ //i is the element index
 
 	int i,j;
-	int tria_node_ids[3];
-	int tria_matice_id;
-	int tria_matpar_id;
-	double nodeinputs[3];
+	int pengrid_node_id;
+	int pengrid_matpar_id;
+	int pengrid_element_id;
 
 	/*id: */
-	this->id=index+1;
+	this->id=id;
 	
 	/*hooks: */
-	//go recover node ids, needed to initialize the node hook.
-	if (iomodel->analysis_type==Prognostic2AnalysisEnum || iomodel->analysis_type==Balancedthickness2AnalysisEnum){
-		/*Discontinuous Galerkin*/
-		tria_node_ids[0]=3*index+1;
-		tria_node_ids[1]=3*index+2;
-		tria_node_ids[2]=3*index+3;
-	}
-	else{
-		/*Continuous Galerkin*/
-		for(i=0;i<3;i++){ 
-			tria_node_ids[i]=(int)*(iomodel->elements+3*index+i); //ids for vertices are in the elements array from Matlab
-		}
-	}
-	tria_matice_id=index+1; //refers to the corresponding ice material object
-	tria_matpar_id=iomodel->numberofelements+1; //refers to the constant material parameters object
-
-	this->hnodes.Init(tria_node_ids,3);
-	this->hmatice.Init(&tria_matice_id,1);
-	this->hmatpar.Init(&tria_matpar_id,1);
-
-	//intialize inputs, and add as many inputs per element as requested: 
+	pengrid_node_id=index+1;
+	pengrid_element_id=iomodel->singlenodetoelementconnectivity[index];
+	pengrid_matpar_id=iomodel->numberofelements+1; //refers to the constant material parameters object
+
+	this->hnode.Init(pengrid_node_ids,1);
+	this->helement.Init(pengrid_element_id,1);
+	this->hmatpar.Init(&pengrid_matpar_id,1);
+
+	//initialize inputs: none needed
 	this->inputs=new Inputs();
-	
-	if (iomodel->thickness) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->thickness[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(ThicknessEnum,nodeinputs));
-	}
-	if (iomodel->surface) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->surface[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(SurfaceEnum,nodeinputs));
-	}
-	if (iomodel->bed) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->bed[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(BedEnum,nodeinputs));
-	}
-	if (iomodel->drag_coefficient) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->drag_coefficient[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(DragCoefficientEnum,nodeinputs));
-
-		if (iomodel->drag_p) this->inputs->AddInput(new DoubleInput(DragPEnum,iomodel->drag_p[index]));
-		if (iomodel->drag_q) this->inputs->AddInput(new DoubleInput(DragQEnum,iomodel->drag_q[index]));
-		this->inputs->AddInput(new IntInput(DragTypeEnum,iomodel->drag_type));
-
-	}
-	if (iomodel->melting_rate) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->melting_rate[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(MeltingRateEnum,nodeinputs));
-	}
-	if (iomodel->accumulation_rate) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->accumulation_rate[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(AccumulationRateEnum,nodeinputs));
-	}
-	if (iomodel->geothermalflux) {
-		for(i=0;i<3;i++)nodeinputs[i]=iomodel->geothermalflux[tria_node_ids[i]-1];
-		this->inputs->AddInput(new PengridVertexInput(GeothermalFluxEnum,nodeinputs));
-	}	
-
-	if (iomodel->elementoniceshelf) this->inputs->AddInput(new BoolInput(ElementOnIceShelfEnum,(IssmBool)iomodel->elementoniceshelf[index]));
-	if (iomodel->elementonbed) this->inputs->AddInput(new BoolInput(ElementOnBedEnum,(IssmBool)iomodel->elementonbed[index]));
-	if (iomodel->elementonwater) this->inputs->AddInput(new BoolInput(ElementOnWaterEnum,(IssmBool)iomodel->elementonwater[index]));
-	if (iomodel->elementonsurface) this->inputs->AddInput(new BoolInput(ElementOnSurfaceEnum,(IssmBool)iomodel->elementonsurface[index]));
 
 	//this->parameters: we still can't point to it, it may not even exist. Configure will handle this.
 	this->parameters=NULL;
 
+	//let's not forget internals
+	this->active=0;
+	this->zigzag_counter=0;
 
 }
@@ -181,82 +134,65 @@
 /*}}}1*/
 		
-/*Object marshall*/
-/*FUNCTION Pengrid::Marshall {{{1*/
-void  Pengrid::Marshall(char** pmarshalled_dataset){
+/*Object management*/
+/*FUNCTION Pengrid::Configure {{{1*/
+void  Pengrid::Configure(DataSet* elementsin, DataSet* nodesin, DataSet* materialsin, Parameters* parametersin){
+
+	/*Take care of hooking up all objects for this load, ie links the objects in the hooks to their respective 
+	 * datasets, using internal ids and offsets hidden in hooks: */
+	hnode.configure(nodesin);
+	helement.configure(elementsin);
+	hmatpar.configure(materialsin);
+
+	/*point parameters to real dataset: */
+	this->parameters=parametersin;
+}
+/*}}}1*/
+/*FUNCTION Pengrid::copy {{{1*/
+Object* Pengrid::copy() {
+	return new Pengrid(this->id,&this->hnode,&this->helement,&this->hmatpar,this->parameters,this->inputs);
+}
+/*}}}1*/
+/*FUNCTION Pengrid::DeepEcho{{{1*/
+void Pengrid::DeepEcho(void){
+
+	printf("Pengrid:\n");
+	printf("   id: %i\n",id);
+	hnode.DeepEcho();
+	helement.DeepEcho();
+	hmatpar.DeepEcho();
+	printf("   active %i\n",this->active);
+	printf("   zigzag_counter %i\n",this->zigzag_counter);
+	printf("   parameters\n");
+	parameters->DeepEcho();
+	printf("   inputs\n");
+	inputs->DeepEcho();
+}
+/*}}}*/
+/*FUNCTION Pengrid::Demarshall {{{1*/
+void  Pengrid::Demarshall(char** pmarshalled_dataset){
 
 	char* marshalled_dataset=NULL;
-	int   enum_type=0;
+	int   i;
 
 	/*recover marshalled_dataset: */
 	marshalled_dataset=*pmarshalled_dataset;
 
-	/*get enum type of Pengrid: */
-	enum_type=PengridEnum;
-	
-	/*marshall enum: */
-	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
-	
-	/*marshall Pengrid data: */
-	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(marshalled_dataset,&mparid,sizeof(mparid));marshalled_dataset+=sizeof(mparid);
-	memcpy(marshalled_dataset,&dof,sizeof(dof));marshalled_dataset+=sizeof(dof);
-	memcpy(marshalled_dataset,&active,sizeof(active));marshalled_dataset+=sizeof(active);
-	memcpy(marshalled_dataset,&penalty_offset,sizeof(penalty_offset));marshalled_dataset+=sizeof(penalty_offset);
-	memcpy(marshalled_dataset,&thermal_steadystate,sizeof(thermal_steadystate));marshalled_dataset+=sizeof(thermal_steadystate);
-	memcpy(marshalled_dataset,&node_id,sizeof(node_id));marshalled_dataset+=sizeof(node_id);
-	memcpy(marshalled_dataset,&node_offset,sizeof(node_offset));marshalled_dataset+=sizeof(node_offset);
-	memcpy(marshalled_dataset,&matpar,sizeof(matpar));marshalled_dataset+=sizeof(matpar);
-	memcpy(marshalled_dataset,&matpar_offset,sizeof(matpar_offset));marshalled_dataset+=sizeof(matpar_offset);
-	memcpy(marshalled_dataset,&stabilize_constraints,sizeof(stabilize_constraints));marshalled_dataset+=sizeof(stabilize_constraints);
-	memcpy(marshalled_dataset,&zigzag_counter,sizeof(zigzag_counter));marshalled_dataset+=sizeof(zigzag_counter);
-
-	*pmarshalled_dataset=marshalled_dataset;
-	return;
-}
-/*}}}1*/
-/*FUNCTION Pengrid::MarshallSize {{{1*/
-int   Pengrid::MarshallSize(){
-
-	return sizeof(id)+
-		sizeof(mparid)+
-		sizeof(dof)+
-		sizeof(active)+
-		sizeof(penalty_offset)+
-		sizeof(thermal_steadystate)+
-		sizeof(node_id)+
-		sizeof(node_offset)+
-		sizeof(matpar)+
-		sizeof(matpar_offset)+
-		sizeof(stabilize_constraints)+
-		sizeof(zigzag_counter)+
-		sizeof(int); //sizeof(int) for enum type
-}
-/*}}}1*/
-/*FUNCTION Pengrid::Demarshall {{{1*/
-void  Pengrid::Demarshall(char** pmarshalled_dataset){
-
-	char* marshalled_dataset=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(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
-	memcpy(&mparid,marshalled_dataset,sizeof(mparid));marshalled_dataset+=sizeof(mparid);
-	memcpy(&dof,marshalled_dataset,sizeof(dof));marshalled_dataset+=sizeof(dof);
 	memcpy(&active,marshalled_dataset,sizeof(active));marshalled_dataset+=sizeof(active);
-	memcpy(&penalty_offset,marshalled_dataset,sizeof(penalty_offset));marshalled_dataset+=sizeof(penalty_offset);
-	memcpy(&thermal_steadystate,marshalled_dataset,sizeof(thermal_steadystate));marshalled_dataset+=sizeof(thermal_steadystate);
-	memcpy(&node_id,marshalled_dataset,sizeof(node_id));marshalled_dataset+=sizeof(node_id);
-	memcpy(&node_offset,marshalled_dataset,sizeof(node_offset));marshalled_dataset+=sizeof(node_offset);
-	memcpy(&matpar,marshalled_dataset,sizeof(matpar));marshalled_dataset+=sizeof(matpar);
-	memcpy(&matpar_offset,marshalled_dataset,sizeof(matpar_offset));marshalled_dataset+=sizeof(matpar_offset);
-	memcpy(&stabilize_constraints,marshalled_dataset,sizeof(stabilize_constraints));marshalled_dataset+=sizeof(stabilize_constraints);
 	memcpy(&zigzag_counter,marshalled_dataset,sizeof(zigzag_counter));marshalled_dataset+=sizeof(zigzag_counter);
 
-	node=NULL;
-	matpar=NULL;
+	/*demarshall hooks: */
+	hnode.Demarshall(&marshalled_dataset);
+	helement.Demarshall(&marshalled_dataset);
+	hmatpar.Demarshall(&marshalled_dataset);
+	
+	/*demarshall inputs: */
+	inputs=(Inputs*)DataSetDemarshallRaw(&marshalled_dataset); 
+
+	/*parameters: may not exist even yet, so let Configure handle it: */
+	this->parameters=NULL;
 
 	/*return: */
@@ -264,82 +200,8 @@
 	return;
 }
-/*}}}1*/
-
-/*Object functions*/
-/*FUNCTION Pengrid::copy {{{1*/
-Object* Pengrid::copy() {
-	return new Pengrid(*this); 
-}
-/*}}}1*/
-/*FUNCTION Pengrid::Configure {{{1*/
-
-void  Pengrid::Configure(void* pelementsin,void* pnodesin,void* pmaterialsin){
-
-	DataSet* nodesin=NULL;
-	DataSet* materialsin=NULL;
-
-	/*Recover pointers :*/
-	nodesin=(DataSet*)pnodesin;
-	materialsin=(DataSet*)pmaterialsin;
-
-	/*Link this load with its nodes: */
-	ResolvePointers((Object**)&node,&node_id,&node_offset,1,nodesin);
-	ResolvePointers((Object**)&matpar,&mparid,&matpar_offset,1,materialsin);
-}
-/*}}}1*/
-/*FUNCTION Pengrid::CreateKMatrix {{{1*/
-
-void  Pengrid::CreateKMatrix(Mat Kgg,int analysis_type,int sub_analysis_type){
-
-	/*No loads applied, do nothing: */
-	return;
-
-}
-/*}}}1*/
-/*FUNCTION Pengrid::CreatePVector {{{1*/
-void  Pengrid::CreatePVector(Vec pg,  int analysis_type,int sub_analysis_type){
-
-	/*No loads applied, do nothing: */
-	return;
-
-}
-/*}}}1*/
-/*FUNCTION Pengrid::DeepEcho {{{1*/
-void Pengrid::DeepEcho(void){
-
-	printf("Pengrid:\n");
-	printf("   id: %i\n",id);
-	printf("   mparid: %i\n",mparid);
-	printf("   dof: %i\n",dof);
-	printf("   active: %i\n",active);
-	printf("   penalty_offset: %g\n",penalty_offset);
-	printf("   thermal_steadystate: %i\n",thermal_steadystate);
-	printf("   node_id: [%i]\n",node_id);
-	printf("   node_offset: [%i]\n",node_offset);
-	printf("   matpar_offset=%i\n",matpar_offset);
-	
-	if(node)node->Echo();
-	if(matpar)matpar->Echo();
-	return;
-}		
-/*}}}1*/
-/*FUNCTION Pengrid::DistributenumDofs {{{1*/
-void  Pengrid::DistributeNumDofs(int* numdofpernode,int analysis_type,int sub_analysis_type){return;}
-/*}}}1*/
+/*}}}*/
 /*FUNCTION Pengrid::Echo {{{1*/
 void Pengrid::Echo(void){
-
-	printf("Pengrid:\n");
-	printf("   id: %i\n",id);
-	printf("   mparid: %i\n",mparid);
-	printf("   dof: %i\n",dof);
-	printf("   active: %i\n",active);
-	printf("   penalty_offset: %g\n",penalty_offset);
-	printf("   thermal_steadystate: %i\n",thermal_steadystate);
-	printf("   node_id: [%i]\n",node_id);
-	printf("   node_offset: [%i]\n",node_offset);
-	printf("   matpar_offset=%i\n",matpar_offset);
-	
-	return;
+	this->DeepEcho();
 }
 /*}}}1*/
@@ -348,20 +210,4 @@
 
 	return PengridEnum;
-}
-/*}}}1*/
-/*FUNCTION Pengrid::GetDofList {{{1*/
-void  Pengrid::GetDofList(int* doflist,int* pnumberofdofspernode){
-
-	int j;
-	int doflist_per_node[MAXDOFSPERNODE];
-	int numberofdofspernode;
-	
-	node->GetDofList(&doflist_per_node[0],&numberofdofspernode);
-	for(j=0;j<numberofdofspernode;j++){
-		doflist[j]=doflist_per_node[j];
-	}
-
-	/*Assign output pointers:*/
-	*pnumberofdofspernode=numberofdofspernode;
 }
 /*}}}1*/
@@ -374,4 +220,58 @@
 }
 /*}}}1*/
+/*FUNCTION Pengrid::Marshall {{{1*/
+void  Pengrid::Marshall(char** pmarshalled_dataset){
+
+	char* marshalled_dataset=NULL;
+	int   enum_type=0;
+	char* marshalled_inputs=NULL;
+	int   marshalled_inputs_size;
+
+	/*recover marshalled_dataset: */
+	marshalled_dataset=*pmarshalled_dataset;
+
+	/*get enum type of Tria: */
+	enum_type=PengridEnum;
+
+	/*marshall enum: */
+	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
+
+	/*marshall Tria data: */
+	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
+	memcpy(marshalled_dataset,&active,sizeof(active));marshalled_dataset+=sizeof(active);
+	memcpy(marshalled_dataset,&zigzag_counter,sizeof(zigzag_counter));marshalled_dataset+=sizeof(zigzag_counter);
+
+	/*Marshall hooks: */
+	hnode.Marshall(&marshalled_dataset);
+	helement.Marshall(&marshalled_dataset);
+	hmatpar.Marshall(&marshalled_dataset);
+
+	/*Marshall inputs: */
+	marshalled_inputs_size=inputs->MarshallSize();
+	marshalled_inputs=inputs->Marshall();
+	memcpy(marshalled_dataset,marshalled_inputs,marshalled_inputs_size*sizeof(char));
+	marshalled_dataset+=marshalled_inputs_size;
+
+	/*parameters: don't do anything about it. parameters are marshalled somewhere else!*/
+
+	xfree((void**)&marshalled_inputs);
+
+	*pmarshalled_dataset=marshalled_dataset;
+	return;
+}
+/*}}}*/
+/*FUNCTION Pengrid::MarshallSize {{{1*/
+int   Pengrid::MarshallSize(){
+	
+	return sizeof(id)
+		+sizeof(active)
+		+sizeof(zigzag_counter)
+		+hnode.MarshallSize()
+		+helement.MarshallSize()
+		+hmatpar.MarshallSize()
+		+inputs->MarshallSize()
+		+sizeof(int); //sizeof(int) for enum type
+}
+/*}}}*/
 /*FUNCTION Pengrid::MyRank {{{1*/
 int    Pengrid::MyRank(void){ 
@@ -380,4 +280,49 @@
 }
 /*}}}1*/
+
+/*Object functions*/
+/*FUNCTION Pengrid::CreateKMatrix {{{1*/
+
+void  Pengrid::CreateKMatrix(Mat Kgg,int analysis_type,int sub_analysis_type){
+
+	/*No loads applied, do nothing: */
+	return;
+
+}
+/*}}}1*/
+/*FUNCTION Pengrid::CreatePVector {{{1*/
+void  Pengrid::CreatePVector(Vec pg,  int analysis_type,int sub_analysis_type){
+
+	/*No loads applied, do nothing: */
+	return;
+
+}
+/*}}}1*/
+/*FUNCTION Pengrid::DistributenumDofs {{{1*/
+void  Pengrid::DistributeNumDofs(int* numdofpernode,int analysis_type,int sub_analysis_type){return;}
+/*}}}1*/
+/*FUNCTION Pengrid::GetDofList {{{1*/
+void  Pengrid::GetDofList(int* doflist,int* pnumberofdofspernode){
+
+	int i,j;
+	int doflist_per_node[MAXDOFSPERNODE];
+	int numberofdofspernode;
+
+	/*dynamic objects pointed to by hooks: */
+	Node node=NULL;
+
+	/*recover objects from hooks: */
+	node=(Node**)hnode.deliverp();
+	
+	node->GetDofList(&doflist_per_node[0],&numberofdofspernode);
+	for(j=0;j<numberofdofspernode;j++){
+		doflist[j]=doflist_per_node[j];
+	}
+
+	/*Assign output pointers:*/
+	*pnumberofdofspernode=numberofdofspernode;
+
+}
+/*}}}*/
 /*FUNCTION Pengrid::PenaltyConstrain {{{1*/
 void  Pengrid::PenaltyConstrain(int* punstable,int analysis_type,int sub_analysis_type){
@@ -432,7 +377,4 @@
 		return;
 	}
-
-	/*recover pointers: */
-	inputs=(ParameterInputs*)vinputs;
 
 	//First recover beta, pressure and temperature vectors;
@@ -764,7 +706,14 @@
 }
 /*}}}1*/
-/*FUNCTION Pengrid::UpdateFromInputs {{{1*/
-void  Pengrid::UpdateFromInputs(void* inputs){
-	
-}
-/*}}}1*/
+
+/*Updates: */
+/*FUNCTION Pengrid::UpdateFromDakota {{{1*/
+void  Pengrid::UpdateFromDakota(void* inputs){
+	ISSMERROR("not supported yet!");
+}
+/*}}}1*/
+/*FUNCTION Pengrid::UpdateInputs {{{1*/
+void  Pengrid::UpdateInputs(double* solution, int analysis_type, int sub_analysis_type){
+	ISSMERROR("not supported yet!");
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/Pengrid.h
===================================================================
--- /issm/trunk/src/c/objects/Pengrid.h	(revision 3622)
+++ /issm/trunk/src/c/objects/Pengrid.h	(revision 3623)
@@ -18,4 +18,5 @@
 		
 		Hook hnode;  //hook to 1 node
+		Hook helement;  //hook to 1 element
 		Hook hmatpar; //hook to 1 matpar
 
@@ -31,7 +32,7 @@
 		/*FUNCTION constructors, destructors {{{1*/
 		Pengrid();
-		Pengrid(int pengrid_id,int pengrid_node_id int pengrid_matpar_id);
-		Pengrid(int pengrid_id,Hook* pengrid_hnode, Hook* pengrid_hmatpar, Parameters* pengrid_parameters, Inputs* pengrid_inputs);
-		Pengrid(int i, IoModel* iomodel);
+		Pengrid(int pengrid_id,int pengrid_node_id, int pengrid_element_id,int pengrid_matpar_id);
+		Pengrid(int pengrid_id,Hook* pengrid_hnode, Hook* pengrid_helement,Hook* pengrid_hmatpar, Parameters* pengrid_parameters, Inputs* pengrid_inputs);
+		Pengrid(int index, int id, IoModel* iomodel);
 		~Pengrid();
 		/*}}}*/
