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 with CUDA support.
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.cuse import CUDA_RAISE_ON_FAIL, CuseSolver, CuseCase
79
103
110 from numpy import sqrt
111 wvec = kw['wvec']
112 ctr = kw['ctr']
113 amp = kw['amp']
114 assert len(wvec) == len(ctr)
115
116 evl, evc = self._calc_eigen(**kw)
117
118 self.amp = evc * (amp / sqrt((evc**2).sum()))
119 self.ctr = ctr
120 self.wvec = wvec
121 self.afreq = evl * sqrt((wvec**2).sum())
122 self.wsp = evl
124 """
125 Calculate eigenvalues and eigenvectors.
126
127 @return: eigenvalues and eigenvectors.
128 @rtype: tuple
129 """
130 raise NotImplementedError
132 from ctypes import byref, c_double
133 svr._clib_lincuse_c.calc_planewave(
134 byref(svr.exd),
135 asol.ctypes._as_parameter_,
136 adsol.ctypes._as_parameter_,
137 self.amp.ctypes._as_parameter_,
138 self.ctr.ctypes._as_parameter_,
139 self.wvec.ctypes._as_parameter_,
140 c_double(self.afreq),
141 )
142
148 for pw in self.planewaves:
149 pw(self.svr, asol, self.adsol)
151 from numpy import empty
152 ngstcell = self.svr.ngstcell
153 nacell = self.svr.ncell + ngstcell
154
155 asol = self.svr.der['analytical'] = empty(
156 (nacell, self.svr.neq), dtype=self.svr.fpdtype)
157 adsol = self.adsol = empty(
158 (nacell, self.svr.neq, self.svr.ndim),
159 dtype=self.svr.fpdtype)
160 asol.fill(0.0)
161 self._calculate(asol)
162 self.svr.soln[ngstcell:,:] = asol[ngstcell:,:]
163 self.svr.dsoln[ngstcell:,:,:] = adsol[ngstcell:,:,:]
164
165 diff = self.svr.der['difference'] = empty(
166 (nacell, self.svr.neq), dtype=self.svr.fpdtype)
167 diff[ngstcell:,:] = self.svr.soln[ngstcell:,:] - asol[ngstcell:,:]
168 - def postfull(self):
169 ngstcell = self.svr.ngstcell
170
171 asol = self.svr.der['analytical']
172 asol.fill(0.0)
173 self._calculate(asol)
174
175 diff = self.svr.der['difference']
176 diff[ngstcell:,:] = self.svr.soln[ngstcell:,:] - asol[ngstcell:,:]
177
180 self.planewaves = kw.pop('planewaves')
181 self.norm = dict()
182 super(PlaneWaveHook, self).__init__(svr, **kw)
188 from numpy import empty, sqrt, abs
189 neq = self.cse.execution.neq
190 var = self.cse.execution.var
191 asol = self._collect_interior(
192 'analytical', inder=True, consider_ghost=True)
193 diff = self._collect_interior(
194 'difference', inder=True, consider_ghost=True)
195 norm_Linf = empty(neq, dtype='float64')
196 norm_L2 = empty(neq, dtype='float64')
197 clvol = self.blk.clvol
198 for it in range(neq):
199 norm_Linf[it] = abs(diff[:,it]).max()
200 norm_L2[it] = sqrt((diff[:,it]**2*clvol).sum())
201 self.norm['Linf'] = norm_Linf
202 self.norm['L2'] = norm_L2
204 from numpy import pi
205 self.postmarch()
206 for ipw in range(len(self.planewaves)):
207 pw = self.planewaves[ipw]
208 self.info("planewave[%d]:\n" % ipw)
209 self.info(" c = %g, omega = %g, T = %.15e\n" % (
210 pw.wsp, pw.afreq, 2*pi/pw.afreq))
211 - def postmarch(self):
212 psteps = self.psteps
213 istep = self.cse.execution.step_current
214 if istep%psteps == 0:
215 self._calculate()
216 - def postloop(self):
217 import os
218 from cPickle import dump
219 fname = '%s_norm.pickle' % self.cse.io.basefn
220 fname = os.path.join(self.cse.io.basedir, fname)
221 dump(self.norm, open(fname, 'wb'), -1)
222 self.info('Linf norm in velocity:\n')
223 self.info(' %e, %e, %e\n' % tuple(self.norm['Linf'][:3]))
224 self.info('L2 norm in velocity:\n')
225 self.info(' %e, %e, %e\n' % tuple(self.norm['L2'][:3]))
226