[19895] | 1 | import numpy
|
---|
| 2 | from fielddisplay import fielddisplay
|
---|
| 3 | from project3d import project3d
|
---|
| 4 | from EnumDefinitions import *
|
---|
| 5 | from checkfield import checkfield
|
---|
| 6 | from WriteData import WriteData
|
---|
| 7 | import MatlabFuncs as m
|
---|
| 8 |
|
---|
| 9 | class mask(object):
|
---|
| 10 | """
|
---|
| 11 | MASK class definition
|
---|
| 12 |
|
---|
| 13 | Usage:
|
---|
| 14 | mask=mask();
|
---|
| 15 | """
|
---|
| 16 |
|
---|
| 17 | def __init__(self): # {{{
|
---|
| 18 | self.ice_levelset = float('NaN')
|
---|
| 19 | self.groundedice_levelset = float('NaN')
|
---|
| 20 |
|
---|
| 21 | #set defaults
|
---|
| 22 | self.setdefaultparameters()
|
---|
| 23 |
|
---|
| 24 | #}}}
|
---|
| 25 | def __repr__(self): # {{{
|
---|
| 26 | string=" masks:"
|
---|
| 27 |
|
---|
| 28 | string="%s\n%s"%(string,fielddisplay(self,"groundedice_levelset","is ice grounded ? grounded ice if > 0, grounding line position if = 0, floating ice if < 0"))
|
---|
| 29 | string="%s\n%s"%(string,fielddisplay(self,"ice_levelset","presence of ice if < 0, icefront position if = 0, no ice if > 0"))
|
---|
| 30 | return string
|
---|
| 31 | #}}}
|
---|
| 32 | def extrude(self,md): # {{{
|
---|
| 33 | self.ice_levelset=project3d(md,'vector',self.ice_levelset,'type','node')
|
---|
| 34 | self.groundedice_levelset=project3d(md,'vector',self.groundedice_levelset,'type','node')
|
---|
| 35 | return self
|
---|
| 36 | #}}}
|
---|
| 37 | def setdefaultparameters(self): # {{{
|
---|
| 38 | return self
|
---|
| 39 | #}}}
|
---|
| 40 | def checkconsistency(self,md,solution,analyses): # {{{
|
---|
| 41 |
|
---|
| 42 | md = checkfield(md,'fieldname','mask.ice_levelset' ,'size',[md.mesh.numberofvertices])
|
---|
| 43 | isice=numpy.array(md.mask.ice_levelset<=0,int)
|
---|
| 44 | if numpy.sum(isice)==0:
|
---|
| 45 | raise TypeError("no ice present in the domain")
|
---|
| 46 |
|
---|
| 47 | icefront=numpy.sum(md.mask.ice_levelset[md.mesh.elements-1]==0,axis=1)
|
---|
| 48 | if (max(icefront)==3 and m.strcmp(md.mesh.elementtype(),'Tria')) or (max(icefront==6) and m.strcmp(md.mesh.elementtype(),'Penta')):
|
---|
| 49 | raise TypeError("At least one element has all nodes on ice front, change md.mask.ice_levelset to fix it")
|
---|
| 50 |
|
---|
| 51 | return md
|
---|
| 52 | # }}}
|
---|
| 53 | def marshall(self,md,fid): # {{{
|
---|
| 54 | WriteData(fid,'object',self,'fieldname','groundedice_levelset','format','DoubleMat','mattype',1)
|
---|
| 55 | WriteData(fid,'object',self,'fieldname','ice_levelset','format','DoubleMat','mattype',1)
|
---|
| 56 |
|
---|
| 57 | # get mask of vertices of elements with ice
|
---|
| 58 | isice=numpy.array(md.mask.ice_levelset<0.,int)
|
---|
| 59 | vlist = numpy.zeros((md.mesh.numberofvertices,1), dtype=int)
|
---|
| 60 | pos=numpy.nonzero(numpy.sum(isice[md.mesh.elements-1],axis=1))[0]
|
---|
| 61 | vlist[md.mesh.elements[pos,:]-1]=1
|
---|
| 62 | WriteData(fid,'data',vlist,'enum',IceMaskNodeActivationEnum(),'format','DoubleMat','mattype',1);
|
---|
| 63 | # }}}
|
---|