#define RCSID "$Id: Get_ElementSource.c,v 1.13 2006/02/26 00:42:54 geuzaine Exp $"
/*
 * Copyright (C) 1997-2006 P. Dular, C. Geuzaine
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 *
 * Please report all bugs and problems to <getdp@geuz.org>.
 */

#include "GetDP.h"
#include "Treatment_Formulation.h"
#include "GeoData.h"
#include "ExtendedGroup.h"
#include "Get_Geometry.h"
#include "CurrentData.h"
#include "Tools.h"

static int     Nbr_ElementSource, i_ElementSource ;
static List_T *RegionSource_L ;
static struct  Element  ElementSource , ElementTrace;

/* ------------------------------------------------------------------------ */
/*  G e t _ I n i t E l e m e n t S o u r c e                               */
/* ------------------------------------------------------------------------ */

void  Get_InitElementSource(struct Element *Element, int InIndex) {

  GetDP_Begin("Get_InitElementSource");

  Element->ElementSource = &ElementSource ;

  Nbr_ElementSource = Geo_GetNbrGeoElements() ;
  i_ElementSource = -1 ;

  if(InIndex<0){
    Msg(GERROR, "Missing support (Region Group) in Integral Quantity");
  }
  else{
    RegionSource_L = ((struct Group*)
		      List_Pointer(Problem_S.Group, InIndex))->InitialList ;
    Current.SourceIntegrationSupportIndex = InIndex ;
  }

  GetDP_End ;
}

/* ------------------------------------------------------------------------ */
/*  G e t _ N e x t E l e m e n t S o u r c e                               */
/* ------------------------------------------------------------------------ */

int  Get_NextElementSource(struct Element *ElementSource) {
  
  GetDP_Begin("Get_NextElementSource");

  while (++i_ElementSource < Nbr_ElementSource) {

    ElementSource->GeoElement = Geo_GetGeoElement(i_ElementSource) ;
    ElementSource->Region = ElementSource->GeoElement->Region ;

    if (List_Search(RegionSource_L, &ElementSource->Region, fcmp_int)) {
      ElementSource->Num  = ElementSource->GeoElement->Num ;
      ElementSource->Type = ElementSource->GeoElement->Type ;
      ElementSource->FMMGroup = ElementSource->GeoElement->FMMGroup ;
      GetDP_Return(1) ;
    }
  }
  GetDP_Return(0) ;
}


/* ------------------------------------------------------------------------ */
/*  G e t _ E l e m e n t S o u r c e I n t e r p o l a t i o n             */
/* ------------------------------------------------------------------------ */

int  Get_ElementSourceInterpolation(struct Element *ElementSource, 
				    struct PostSubOperation *PostSubOperation) {

  GetDP_Begin("Get_ElementSourceInterpolation");

  GetDP_Return(0) ;

}



/* ------------------------------------------------------------------------ */
/*  G e t _ E l e m e n t T r a c e                                         */
/* ------------------------------------------------------------------------ */

void  Get_ElementTrace(struct Element *Element, int InIndex) {
  struct Group   * Group_P ;
  struct TwoInt  * Pair_P ;

  GetDP_Begin("Get_ElementTrace");

  Element->ElementTrace = &ElementTrace ;

  Group_P = (struct Group*)List_Pointer(Problem_S.Group, InIndex) ;
  
  if (!Group_P->ExtendedList) Generate_ExtendedGroup(Group_P) ;
  
  if(!(Pair_P = (struct TwoInt*)List_PQuery(Group_P->ExtendedList, 
					    &Element->Num, fcmp_int)))
    Msg(GERROR, "No Element connected to Element %d: check Group for Trace", 
	Element->Num) ;

  Element->ElementTrace = &ElementTrace ;
  Element->ElementTrace->GeoElement = Geo_GetGeoElement(Pair_P->Int2) ;
  Element->ElementTrace->Region = Element->ElementTrace->GeoElement->Region ;
  Element->ElementTrace->Num    = Element->ElementTrace->GeoElement->Num ;
  Element->ElementTrace->Type   = Element->ElementTrace->GeoElement->Type ;

  Get_NodesCoordinatesOfElement(Element->ElementTrace) ;

  Msg(INFO, "Element %d -> Trace %d", Element->Num, Element->ElementTrace->Num);

  GetDP_End ;
}


syntax highlighted by Code2HTML, v. 0.9.1