# Contents of /trunk/modellib/py_src/temperature.py

Revision 4821 - (show annotations)
Tue Apr 1 04:58:33 2014 UTC (5 years, 2 months ago) by sshaw
File MIME type: text/x-python
File size: 3668 byte(s)
moved SolverOptions to c++, split into SolverOptions for the options and SolverBuddy as the state as a precursor to per-pde solving... does break some use cases (e.g. pde.getSolverOptions().DIRECT will now fail, new value access is with SolverOptions.DIRECT), examples and documentation updated to match

 1 2 ############################################################################## 3 # 4 # Copyright (c) 2003-2014 by University of Queensland 5 6 # 7 # Primary Business: Queensland, Australia 8 # Licensed under the Open Software License version 3.0 9 10 # 11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC) 12 # Development 2012-2013 by School of Earth Sciences 13 # Development from 2014 by Centre for Geoscience Computing (GeoComp) 14 # 15 ############################################################################## 16 17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland 18 http://www.uq.edu.au 19 Primary Business: Queensland, Australia""" 20 __license__="""Licensed under the Open Software License version 3.0 21 22 __url__= 23 24 from esys.escript import Data, inf, sup, length, grad, inner 25 from esys.escript.modelframe import Model,IterationDivergenceError 26 from esys.escript.linearPDEs import LinearPDE, SolverOptions 27 import numpy 28 29 30 class TemperatureAdvection(Model): 31 """ 32 33 The conservation of internal heat energy is given by 34 35 *rho c_p ( dT/dt+v[j] * grad(T)[j])-grad(\kappa grad(T)_{,i}=Q* 36 37 *n_i \kappa T_{,i}=0* 38 39 it is assummed that *\rho c_p* is constant in time. 40 41 solved by Taylor Galerkin method 42 43 """ 44 def __init__(self,**kwargs): 45 super(TemperatureAdvection, self).__init__(**kwargs) 46 self.declareParameter(domain=None, \ 47 temperature=1., \ 48 velocity=numpy.zeros([3]), 49 density=1., \ 50 heat_capacity=1., \ 51 thermal_permabilty=1., \ 52 # reference_temperature=0., \ 53 # radiation_coefficient=0., \ 54 thermal_source=0., \ 55 fixed_temperature=0., 56 location_fixed_temperature=Data(), 57 safety_factor=0.1) 58 59 def doInitialization(self): 60 self.__pde=LinearPDE(self.domain) 61 self.__pde.setSymmetryOn() 62 self.__pde.setReducedOrderOn() 63 self.__pde.getSolverOptions().setSolverMethod(SolverOptions.LUMPING) 64 self.__pde.setValue(D=self.heat_capacity*self.density) 65 66 def getSafeTimeStepSize(self,dt): 67 """ 68 returns new step size 69 """ 70 h=self.domain.getSize() 71 return self.safety_factor*inf(h**2/(h*abs(self.heat_capacity*self.density)*length(self.velocity)+self.thermal_permabilty)) 72 73 def G(self,T,alpha): 74 """ 75 tangential operator for taylor galerikin 76 """ 77 g=grad(T) 78 self.__pde.setValue(X=-self.thermal_permabilty*g, \ 79 Y=self.thermal_source-self.__rhocp*inner(self.velocity,g), \ 80 r=(self.__fixed_T-self.temperature)*alpha,\ 81 q=self.location_fixed_temperature) 82 return self.__pde.getSolution() 83 84 85 def doStepPostprocessing(self,dt): 86 """ 87 perform taylor galerkin step 88 """ 89 T=self.temperature 90 self.__rhocp=self.heat_capacity*self.density 91 self.__fixed_T=self.fixed_temperature 92 self.temperature=dt*self.G(dt/2*self.G(T,1./dt)+T,1./dt)+T 93 self.trace("Temperature range is %e %e"%(inf(self.temperature),sup(self.temperature)))

## Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision