/[escript]/trunk/modellib/py_src/crustal/mines.py
ViewVC logotype

Diff of /trunk/modellib/py_src/crustal/mines.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 977 by gross, Fri Feb 16 06:34:21 2007 UTC revision 981 by gross, Mon Feb 19 06:52:25 2007 UTC
# Line 92  def unitConverter(val,val_unit,out_unit) Line 92  def unitConverter(val,val_unit,out_unit)
92            out=float(val)            out=float(val)
93         elif VAL_UNIT == "KM":         elif VAL_UNIT == "KM":
94            out=float(val)*1000.            out=float(val)*1000.
95        elif OUT_UNIT == "KG":
96            if VAL_UNIT == "MT":
97                out=float(val)*1e9
98      if out == None:      if out == None:
99            raise ValueError("cannot convert from unit %s to %s."%(val_unit,out_unit))            raise ValueError("cannot convert from unit %s to %s."%(val_unit,out_unit))
100      return out      return out
# Line 143  class MiningArea(BoxInTheCrust): Line 146  class MiningArea(BoxInTheCrust):
146       def __init__(self, longitude_length, latitude_length, depth, location=LocationOnEarth(), name="unknown", tilt=0., mines=[]):       def __init__(self, longitude_length, latitude_length, depth, location=LocationOnEarth(), name="unknown", tilt=0., mines=[]):
147          super(MiningArea, self).__init__(longitude_length, latitude_length, depth, location, name, tilt)          super(MiningArea, self).__init__(longitude_length, latitude_length, depth, location, name, tilt)
148          self.__mines=mines          self.__mines=mines
149         def getStartOfRecords(self):
150             return min([ m.getStartOfRecords() for m in self.__mines ])
151       def fillDesign(self,design):       def fillDesign(self,design):
152           """           """
153           this puts the mining area and all the mines into the given design           this puts the mining area and all the mines into the given design
# Line 243  class MiningArea(BoxInTheCrust): Line 248  class MiningArea(BoxInTheCrust):
248           dom=SurfaceLoop(bottom,top,front,back,left,right,-bb_bottom,-bb_front,-bb_back,-bb_left,-bb_right)           dom=SurfaceLoop(bottom,top,front,back,left,right,-bb_bottom,-bb_front,-bb_back,-bb_left,-bb_right)
249           design.addItems(Volume(dom))           design.addItems(Volume(dom))
250           return           return
          1/0  
                 
                 
          print msh_factor  
          pnts=[]  
          min_fac=1.  
          for m in self.__mines:  
                mb=m.createSurfaceLoop()  
                fac=m.getDiameter()/self.getDiameter()  
                min_fac=min(min_fac, fac)  
                mb.setLocalScale(fac)  
                mb+=m.getCenter().getRelativeXYZ(self.getCenter())  
                mboxes.append(mb)  
                s=m.getCenter().getRelativeXYZ(self.getCenter())  
   
          print min_fac  
          # for p in box.getConstructionPoints():  
          #     if p.getCoordinates()[2] == 0. : p.setLocalScale(min_fac)  
          # design.addItems(Volume(box, holes=mboxes))  
          design.addItems(Volume(box), *tuple(pnts))  
251    
252  class Mine(BoxInTheCrust):  class Mine(BoxInTheCrust):
253       """       """
# Line 270  class Mine(BoxInTheCrust): Line 255  class Mine(BoxInTheCrust):
255       """       """
256       def __init__(self, longitude_length, latitude_length, depth, location=LocationOnEarth(), name="unknown", tilt=0.):       def __init__(self, longitude_length, latitude_length, depth, location=LocationOnEarth(), name="unknown", tilt=0.):
257          super(Mine, self).__init__(longitude_length, latitude_length, depth, location, name, tilt)          super(Mine, self).__init__(longitude_length, latitude_length, depth, location, name, tilt)
258            self.__record=[]
259    
260         def addRecord(self, material, year, extraction):
261            TYPE=material.upper()
262            for y, e in self.__record:
263               if y == year:
264                   if e.has_key(TYPE):
265                      e[TYPE]+=extraction
266                   else:
267                      e[TYPE]=extraction
268                   return
269               if y>year:
270                   self.__record.insert(self.__record.index((y,e)), { TYPE : extraction} )
271                   return
272            self.__record.append((year, { TYPE : extraction} ))
273            return
274         def getStartOfRecords(self):
275              if len(self.__record)>0:
276                 return self.__record[0][0]
277              else:
278                 raise ValueError("empty record of %s mine."%self.getName())
279    
280    
281  def _parse(root):  def _parse(root):
# Line 302  def _parse(root): Line 308  def _parse(root):
308                   DEPTH=0.                   DEPTH=0.
309                   LONGLENGTH=0.                   LONGLENGTH=0.
310                   LATLENGTH=0.                   LATLENGTH=0.
311                     RECORD=[]
312                   for node in root.childNodes:                   for node in root.childNodes:
313                         if isinstance(node, minidom.Element):                         if isinstance(node, minidom.Element):
314                            if node.tagName == 'Name': NAME=_parse(node)                            if node.tagName == 'Name': NAME=_parse(node)
# Line 310  def _parse(root): Line 317  def _parse(root):
317                            if node.tagName == 'Depth': DEPTH=_parse(node)                            if node.tagName == 'Depth': DEPTH=_parse(node)
318                            if node.tagName == 'LongitudeLength': LONGLENGTH=_parse(node)                            if node.tagName == 'LongitudeLength': LONGLENGTH=_parse(node)
319                            if node.tagName == 'LatitudeLength': LATLENGTH=_parse(node)                            if node.tagName == 'LatitudeLength': LATLENGTH=_parse(node)
320                   return Mine(location=LOC, tilt=TILT,name=NAME, longitude_length=LONGLENGTH, latitude_length=LATLENGTH, depth=DEPTH)                            if node.tagName == 'Record': RECORD.append(_parse(node))
321                     m=Mine(location=LOC, tilt=TILT,name=NAME, longitude_length=LONGLENGTH, latitude_length=LATLENGTH, depth=DEPTH)
322                     for r in RECORD:
323                        m.addRecord(material=r[0],year=r[1],extraction=r[2])
324                     return m
325          elif root.tagName == 'LocationOnEarth':          elif root.tagName == 'LocationOnEarth':
326                      long=0.                      long=0.
327                      lat=0.                      lat=0.
# Line 321  def _parse(root): Line 332  def _parse(root):
332                            if node.tagName == 'Latitude': lat=_parse(node)                            if node.tagName == 'Latitude': lat=_parse(node)
333                            if node.tagName == 'Altitude': alt=_parse(node)                            if node.tagName == 'Altitude': alt=_parse(node)
334                      return LocationOnEarth(longitude=long, latitude=lat, altitude=alt)                      return LocationOnEarth(longitude=long, latitude=lat, altitude=alt)
335            elif root.tagName == 'Record':
336                        year=0
337                        mat="unknown"
338                        ext=0.
339                        for node in  root.childNodes:
340                           if isinstance(node, minidom.Element):
341                              if node.tagName == 'Year': year=_parse(node)
342                              if node.tagName == 'Material': mat=_parse(node)
343                              if node.tagName == 'Extraction': ext=_parse(node)
344                        return (mat,year,ext)
345          elif root.tagName == 'SouthWest':          elif root.tagName == 'SouthWest':
346                    return _parse(root.getElementsByTagName('LocationOnEarth')[0])                    return _parse(root.getElementsByTagName('LocationOnEarth')[0])
347          elif root.tagName == 'NorthEast':          elif root.tagName == 'NorthEast':
# Line 350  def _parse(root): Line 371  def _parse(root):
371                         unit="M"                         unit="M"
372                     for node in root.childNodes:                     for node in root.childNodes:
373                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
374                          return unitConverter(root.firstChild.nodeValue, unit, LocationOnEarth.LENGTH_UNIT)                          return unitConverter(node.nodeValue.strip(), unit, LocationOnEarth.LENGTH_UNIT)
375                     return 0.                     return 0.
376          elif root.tagName == 'LongitudeLength':          elif root.tagName == 'LongitudeLength':
377                     if root.hasAttribute("unit"):                     if root.hasAttribute("unit"):
# Line 359  def _parse(root): Line 380  def _parse(root):
380                         unit="M"                         unit="M"
381                     for node in root.childNodes:                     for node in root.childNodes:
382                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
383                          return unitConverter(root.firstChild.nodeValue, unit, LocationOnEarth.LENGTH_UNIT)                          return unitConverter(node.nodeValue.strip(), unit, LocationOnEarth.LENGTH_UNIT)
384                     return 0.                     return 0.
385          elif root.tagName == 'LatitudeLength':          elif root.tagName == 'LatitudeLength':
386                     if root.hasAttribute("unit"):                     if root.hasAttribute("unit"):
# Line 368  def _parse(root): Line 389  def _parse(root):
389                         unit="M"                         unit="M"
390                     for node in root.childNodes:                     for node in root.childNodes:
391                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
392                          return unitConverter(root.firstChild.nodeValue, unit, LocationOnEarth.LENGTH_UNIT)                          return unitConverter(node.nodeValue.strip(), unit, LocationOnEarth.LENGTH_UNIT)
393                     return 0.                     return 0.
394          elif root.tagName == 'Depth':          elif root.tagName == 'Depth':
395                     if root.hasAttribute("unit"):                     if root.hasAttribute("unit"):
# Line 377  def _parse(root): Line 398  def _parse(root):
398                         unit="M"                         unit="M"
399                     for node in root.childNodes:                     for node in root.childNodes:
400                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
401                          return unitConverter(root.firstChild.nodeValue, unit, LocationOnEarth.LENGTH_UNIT)                          return unitConverter(node.nodeValue.strip(), unit, LocationOnEarth.LENGTH_UNIT)
402                     return 0.                     return 0.
403          elif root.tagName == 'LongitudeLength':          elif root.tagName == 'LongitudeLength':
404                     if root.hasAttribute("unit"):                     if root.hasAttribute("unit"):
# Line 386  def _parse(root): Line 407  def _parse(root):
407                         unit="M"                         unit="M"
408                     for node in root.childNodes:                     for node in root.childNodes:
409                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
410                          return unitConverter(root.firstChild.nodeValue, unit, LocationOnEarth.LENGTH_UNIT)                          return unitConverter(node.nodeValue.strip(), unit, LocationOnEarth.LENGTH_UNIT)
411                     return 0.                     return 0.
412          elif root.tagName == 'Tilt':          elif root.tagName == 'Tilt':
413                     if root.hasAttribute("unit"):                     if root.hasAttribute("unit"):
# Line 395  def _parse(root): Line 416  def _parse(root):
416                         unit="D.MM"                         unit="D.MM"
417                     for node in root.childNodes:                     for node in root.childNodes:
418                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
419                          return unitConverter(root.firstChild.nodeValue, unit, LocationOnEarth.DEG_UNIT)                          return unitConverter(node.nodeValue.strip(), unit, LocationOnEarth.DEG_UNIT)
420                     return 0.                     return 0.
421          elif root.tagName == 'Name':          elif root.tagName == 'Name':
422                     for node in root.childNodes:                     for node in root.childNodes:
423                        if isinstance(node, minidom.Text):                        if isinstance(node, minidom.Text):
424                          return node.nodeValue.strip()                          return node.nodeValue.strip()
425                     return "unknown"                     return "unknown"
426            elif root.tagName == 'Year':
427                      for node in root.childNodes:
428                          if isinstance(node, minidom.Text):
429                              return int(node.nodeValue.strip())
430                      return 0
431            elif root.tagName == 'Material':
432                       for node in root.childNodes:
433                          if isinstance(node, minidom.Text):
434                            return node.nodeValue.strip()
435                       return "unknown"
436            elif root.tagName == 'Extraction':
437                       if root.hasAttribute("unit"):
438                           unit=root.getAttribute("unit")
439                       else:
440                           unit="MT"
441                       for node in root.childNodes:
442                          if isinstance(node, minidom.Text):
443                            return unitConverter(node.nodeValue.strip(), unit, "kg")
444                       return 0.
445       for node in root.childNodes:       for node in root.childNodes:
446             if isinstance(node, minidom.Element): return _parse(node)             if isinstance(node, minidom.Element): return _parse(node)
447        
# Line 424  if __name__ == "__main__": Line 464  if __name__ == "__main__":
464      dsgn.setScriptFileName("newcastle_mines.geo")      dsgn.setScriptFileName("newcastle_mines.geo")
465      dsgn.setMeshFileName("newcastle_mines.msh")      dsgn.setMeshFileName("newcastle_mines.msh")
466      print dsgn.getCommandString()      print dsgn.getCommandString()
467        print "start of records = ",mine.getStartOfRecords()
468      dsgn.getMeshHandler()      dsgn.getMeshHandler()

Legend:
Removed from v.977  
changed lines
  Added in v.981

  ViewVC Help
Powered by ViewVC 1.1.26