#module imports
from fielddisplay import fielddisplay
from EnumDefinitions import *
from checkfield import *
from WriteData import *

class balancethickness(object):
	"""
	BALANCETHICKNESS class definition

	   Usage:
	      balancethickness=balancethickness();
	"""

	#properties
	def __init__(self):
		# {{{ Properties
		self.spcthickness      = float('NaN')
		self.thickening_rate   = float('NaN')
		self.stabilization     = 0

		#set defaults
		self.setdefaultparameters()

		#}}}
	def __repr__(self):
		# {{{ Display
		
		string='   balance thickness solution parameters:' 
		
		string="%s\n%s"%(string,fielddisplay(self,'spcthickness','thickness constraints (NaN means no constraint)'))
		string="%s\n%s"%(string,fielddisplay(self,'thickening_rate','ice thickening rate used in the mass conservation (dh/dt)'))
		string="%s\n%s"%(string,fielddisplay(self,'stabilization',"0: None, 1: SU, 2: MacAyeal's artificial diffusivity, 3:DG"))
		return string
		#}}}
	def setdefaultparameters(self):
		# {{{setdefaultparameters
		
		#Type of stabilization used
		self.stabilization=1

		return self
	#}}}

	def checkconsistency(self,md,solution,analyses):    # {{{
		#Early return
		if not solution==BalancethicknessSolutionEnum():
			return md

		md = checkfield(md,'balancethickness.spcthickness','forcing',1)
		md = checkfield(md,'balancethickness.thickening_rate','size',[md.mesh.numberofvertices],'NaN',1)
		md = checkfield(md,'balancethickness.stabilization','size',[1],'values',[0,1,2,3])

		return md
	# }}}

	def marshall(self,fid):    # {{{
		WriteData(fid,'object',self,'fieldname','spcthickness','format','DoubleMat','mattype',1)
		WriteData(fid,'object',self,'fieldname','thickening_rate','format','DoubleMat','mattype',1)
		WriteData(fid,'object',self,'fieldname','stabilization','format','Integer')
	# }}}

