1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """
20 CESE solver specialized for general linear equations.
21 """
22
23 from solvcon.gendata import SingleAssignDict, AttributeDict
24 from solvcon.anchor import Anchor
25 from solvcon.hook import BlockHook
26 from solvcon.kerpak.cese import CeseSolver, CeseCase
33 """
34 Basic linear CESE solver.
35
36 @ivar cfldt: the time_increment for CFL calculation at boundcond.
37 @itype cfldt: float
38 @ivar cflmax: the maximum CFL number.
39 @itype cflmax: float
40 """
41 from solvcon.dependency import getcdll
42 __clib_lincese = {
43 2: getcdll('lincese2d'),
44 3: getcdll('lincese3d'),
45 }
46 del getcdll
47 @property
50 @property
54 self.cfldt = kw.pop('cfldt', None)
55 self.cflmax = 0.0
56 super(LinceseSolver, self).__init__(*args, **kw)
58 raise NotImplementedError
71 self.marchret.setdefault('cfl', [0.0, 0.0, 0, 0])
72 self.marchret['cfl'][0] = self.cflmax
73 self.marchret['cfl'][1] = self.cflmax
74 self.marchret['cfl'][2] = 0
75 self.marchret['cfl'][3] = 0
76 return self.marchret
77
101
108 from numpy import sqrt
109 wvec = kw['wvec']
110 ctr = kw['ctr']
111 amp = kw['amp']
112 assert len(wvec) == len(ctr)
113
114 evl, evc = self._calc_eigen(**kw)
115
116 self.amp = evc * (amp / sqrt((evc**2).sum()))
117 self.ctr = ctr
118 self.wvec = wvec
119 self.afreq = evl * sqrt((wvec**2).sum())
120 self.wsp = evl
122 """
123 Calculate eigenvalues and eigenvectors.
124
125 @return: eigenvalues and eigenvectors.
126 @rtype: tuple
127 """
128 raise NotImplementedError
130 from ctypes import byref, c_double
131 svr._clib_lincese.calc_planewave(
132 byref(svr.exd),
133 asol.ctypes._as_parameter_,
134 adsol.ctypes._as_parameter_,
135 self.amp.ctypes._as_parameter_,
136 self.ctr.ctypes._as_parameter_,
137 self.wvec.ctypes._as_parameter_,
138 c_double(self.afreq),
139 )
140
146 for pw in self.planewaves:
147 pw(self.svr, asol, self.adsol)
149 from numpy import empty
150 ngstcell = self.svr.ngstcell
151 nacell = self.svr.ncell + ngstcell
152
153 asol = self.svr.der['analytical'] = empty(
154 (nacell, self.svr.neq), dtype=self.svr.fpdtype)
155 adsol = self.adsol = empty(
156 (nacell, self.svr.neq, self.svr.ndim),
157 dtype=self.svr.fpdtype)
158 asol.fill(0.0)
159 self._calculate(asol)
160 self.svr.soln[ngstcell:,:] = asol[ngstcell:,:]
161 self.svr.dsoln[ngstcell:,:,:] = adsol[ngstcell:,:,:]
162
163 diff = self.svr.der['difference'] = empty(
164 (nacell, self.svr.neq), dtype=self.svr.fpdtype)
165 diff[ngstcell:,:] = self.svr.soln[ngstcell:,:] - asol[ngstcell:,:]
166 - def postfull(self):
167 ngstcell = self.svr.ngstcell
168
169 asol = self.svr.der['analytical']
170 asol.fill(0.0)
171 self._calculate(asol)
172
173 diff = self.svr.der['difference']
174 diff[ngstcell:,:] = self.svr.soln[ngstcell:,:] - asol[ngstcell:,:]
175
178 self.planewaves = kw.pop('planewaves')
179 self.norm = dict()
180 super(PlaneWaveHook, self).__init__(svr, **kw)
186 from numpy import empty, sqrt, abs
187 neq = self.cse.execution.neq
188 var = self.cse.execution.var
189 asol = self._collect_interior(
190 'analytical', inder=True, consider_ghost=True)
191 diff = self._collect_interior(
192 'difference', inder=True, consider_ghost=True)
193 norm_Linf = empty(neq, dtype='float64')
194 norm_L2 = empty(neq, dtype='float64')
195 clvol = self.blk.clvol
196 for it in range(neq):
197 norm_Linf[it] = abs(diff[:,it]).max()
198 norm_L2[it] = sqrt((diff[:,it]**2*clvol).sum())
199 self.norm['Linf'] = norm_Linf
200 self.norm['L2'] = norm_L2
202 from numpy import pi
203 self.postmarch()
204 for ipw in range(len(self.planewaves)):
205 pw = self.planewaves[ipw]
206 self.info("planewave[%d]:\n" % ipw)
207 self.info(" c = %g, omega = %g, T = %.15e\n" % (
208 pw.wsp, pw.afreq, 2*pi/pw.afreq))
209 - def postmarch(self):
210 psteps = self.psteps
211 istep = self.cse.execution.step_current
212 if istep%psteps == 0:
213 self._calculate()
214 - def postloop(self):
215 import os
216 from cPickle import dump
217 fname = '%s_norm.pickle' % self.cse.io.basefn
218 fname = os.path.join(self.cse.io.basedir, fname)
219 dump(self.norm, open(fname, 'wb'), -1)
220 self.info('Linf norm in velocity:\n')
221 self.info(' %e, %e, %e\n' % tuple(self.norm['Linf'][:3]))
222 self.info('L2 norm in velocity:\n')
223 self.info(' %e, %e, %e\n' % tuple(self.norm['L2'][:3]))
224