Exemplo n.º 1
0
 def _upsample_check(self):
     if self.check_upsample_factor != 1.0:
         un = 2 * int(self.check.N * self.check_upsample_factor * 0.5)
         self.upcheck = GSB(c=resample(self.check.c, un))
         self.upbdy = GSB(c=resample(self.bdy.c, un))
         self.cu.build(self.check.N, un)
     else:
         self.upcheck = self.check
         self.upbdy = self.bdy
         self.cu = QFS_Null_Check_Upsampler()
Exemplo n.º 2
0
 def _place_shfited_bdy(self, M, sign, upsample):
     # assess distance between first-try and maximum_distance
     if self.maximum_distance is not None:
         sbdy = self._get_shifted_bdy(MH)
         sep = np.abs(bdy.c - sbdy.c).max()
         if sep > self.maximum_distance:
             OS = sep / self.maximum_distance
             MH = sign * M / OS
         else:
             OS = 1.0
             MH = sign * M
     else:
         OS = 1.0
         MH = sign * M
     # okay, now we have our first guess for M and oversampling required
     # try it out, if it fails, move closer and refine
     valid = False
     while not valid:
         sbdyc = self._get_shifted_bdy(MH)
         if upsample:
             sbdyc = get_upsampled_bdyc(sbdyc, OS)
         sbdyp = polygon_from_bdyc(sbdyc)
         sbdys = speed_from_bdyc(sbdyc)
         valid = sbdyp.is_valid and sbdys.min() > self.bdy.speed.min() * 0.5
         if not valid:
             OS *= 1.1
             MH /= 1.1
             if OS > 10:
                 raise Exception(
                     'Source oversampling factor > 10; QFS cannot be efficiently generated; refine boundary.'
                 )
     return GSB(c=sbdyc), MH
Exemplo n.º 3
0
 def __init__(self, src, trg):
     self.N = trg.N
     # upsample the target point to the number of source points
     trg = GSB(c=resample(trg.c, src.N))
     ssrc = src.Generate_1pt_Circulant_Boundary()
     m = func(ssrc, trg)[:, 0]
     self.mh = np.fft.fft(m)
Exemplo n.º 4
0
 def build(self, bdy, fine_N=None, check=None):
     self.bdy = bdy
     if self.singular:
         self.resampler = lambda f: f
     else:
         if fine_N is None:
             raise Exception(
                 'If QFS_B2C is not singular, you must provide a fine_N.')
         if check is None:
             raise Exception(
                 'If QFS_B2C is not singular, you must provide a check surface.'
             )
         self.fine_N = fine_N
         func = vector_resample if self.vector else resample
         self.resampler = lambda f: func(f, self.fine_N)
         self.fine = GSB(c=resample(self.bdy.c, self.fine_N))
         self.check = check
     if self.singular:
         self.mats = [func(self.bdy) for func in self.funcs]
     else:
         self.mats = [func(self.fine, self.check) for func in self.funcs]
     if self.form_b2c_mats:
         if self.vector:
             self.resampling_matrix = vector_resampling_matrix(
                 self.bdy.N, self.fine_N)
         else:
             self.resampling_matrix = resampling_matrix(
                 self.bdy.N, self.fine_N)
         self.b2c_mats = [
             mat.dot(self.resampling_matrix) for mat in self.mats
         ]
Exemplo n.º 5
0
    def _generate_pressure_target(self):
        sign = 1 if self.interior else -1
        bdy = self.bdy
        h = bdy.speed[0] * bdy.dt

        dist = 6 * sign
        pN = bdy.N
        self.bdy_path = shg.Polygon(zip(bdy.x, bdy.y))
        pressure_pt = self._get_shifted_bdy(dist)[0]
        sep = np.abs(pressure_pt - bdy.c[0])
        check = self._check_pressure_pt(pressure_pt.real, pressure_pt.imag,
                                        sep)

        while not check:
            dist /= 2
            pN = pN * 2
            pressure_pt = self._get_shifted_bdy(dist)[0]
            sep = np.abs(pressure_pt - bdy.c[0])
            check = self._check_pressure_pt(pressure_pt.real, pressure_pt.imag,
                                            sep)
        self.pressure_x = pressure_pt.real
        self.pressure_y = pressure_pt.imag
        self.pressure_fine_bdy = GSB(c=resample(self.bdy.c, pN))
        self.pressure_targ = PointSet(x=np.array(self.pressure_x),
                                      y=np.array(self.pressure_y))
Exemplo n.º 6
0
 def build(self, source, check, tol):
     super().build(source, check, tol)
     self.source0 = self.source.Generate_1pt_Circulant_Boundary()
     if self.sN != self.cN:
         self.fine_check = GSB(c=resample(check.c, self.sN))
         self.mat = self.func(self.source0, self.fine_check)
         self.resampled = True
     else:
         self.mat = self.func(self.source0, self.check)
         self.resampled = False
     if self.vector:
         a = self.mat[:self.sN, 0]
         b = self.mat[:self.sN, 1]
         c = self.mat[self.sN:, 0]
         d = self.mat[self.sN:, 1]
         theta = self.source.t
         self.Inverter = PolarBlockCirculant2x2_solver(
             a, b, c, d, theta, tol)
     else:
         self.Inverter = Circulant_Solver(self.mat[:, 0], self.tol)
Exemplo n.º 7
0
    return Tx, Ty


############################################################################
# Generate options dictionary

options = {
    'b2c_type': b2c_type,
    's2c_type': s2c_type,
    'singular': singular,
}

################################################################################
# Setup boundary

bdy = GSB(c=star(n, f=5, a=0.0 if use_circle else 0.2))

################################################################################
# Run test

print('')
print('Running QFS Tests for Stokes Equation')
print('    options are:')
for key, value in options.items():
    print('        ', (key + ':').ljust(15), value)

for interior in [True, False]:

    print('\n    Testing', 'interior' if interior else 'exterior',
          'evaluation.')
Exemplo n.º 8
0
 def _upsample_source(self):
     if self.source_upsample_factor != 1.0:
         un = 2 * int(self.source.N * self.source_upsample_factor * 0.5)
         self.source = GSB(c=resample(self.source.c, un))
Exemplo n.º 9
0
    'singular': singular,
}

qfs_kwargs = {
    'tol': tol,
    'shift_type': shift_type,
    'source_upsample_factor': source_upsample_factor,
    'check_upsample_factor': check_upsample_factor,
    'closer_source': move_source_closer,
}

############################################################################
# Setup boundary

use_circle = s2c_type == 'Circulant' or b2c_type == 'Circulant'
bdy = GSB(c=star(n, f=5, a=0.0 if use_circle else 0.2))

############################################################################
# Run test

print('')
print('Running QFS Tests for Modified Helmholtz Equation')
print('    options are:')
for key, value in options.items():
    print('        ', (key + ':').ljust(15), value)

for interior in [True, False]:

    print('\n    Testing', 'interior' if interior else 'exterior',
          'evaluation.')