Exemplo n.º 1
0
    def get_basis_functions(
            self,
            fs):  # TODO: Implement radial basis functions other than Gaussians
        """
        Assemble an array of radial basis functions, rotated by specified angle.
        """
        from adapt_utils.misc import gaussian
        from adapt_utils.linalg import rotation_matrix

        # Gather parameters
        x0, y0 = self.centre_x, self.centre_y  # Centre of basis region
        nx, ny = self.nx, self.ny  # Number of basis functions along each axis
        N = nx * ny  # Total number of basis functions
        rx, ry = self.radius_x, self.radius_y  # Radius of each basis function in each direction
        dx, dy = self.extent_x, self.extent_y  # Extent of basis region in each direction
        angle = self.strike_angle  # Angle by which to rotate axis / basis array

        # Setup array coordinates
        X = np.array([0.0]) if nx == 1 else np.linspace(
            -0.5 * dx, 0.5 * dx, nx)
        Y = np.array([0.0]) if ny == 1 else np.linspace(
            -0.5 * dy, 0.5 * dy, ny)

        # Assemble array
        self.print_debug(
            "INIT: Assembling rotated radial basis function array...")
        self.basis_functions = [Function(fs) for i in range(N)]
        R = rotation_matrix(-angle)
        self._array = []
        for j, y in enumerate(Y):
            for i, x in enumerate(X):
                phi = self.basis_functions[i + j * nx]
                x_rot, y_rot = tuple(
                    np.array([x0, y0]) + np.dot(R, np.array([x, y])))
                self._array.append([x_rot, y_rot])
                phi.interpolate(
                    gaussian([(x_rot, y_rot, rx, ry)],
                             fs.mesh(),
                             rotation=angle))
Exemplo n.º 2
0
    "pc_fieldsplit_type": "multiplicative",
}
bcs = None if 'dg' in family else DirichletBC(V.sub(1), 0, 100)
problem = LinearVariationalProblem(a, L, q, bcs=bcs)
solver = LinearVariationalSolver(problem, solver_parameters=params)

# Define basis
R = FunctionSpace(mesh, "R", 0)
optimum = 5.0
m = Function(R).assign(optimum)
basis_function = Function(V)
psi, phi = basis_function.split()
loc = (0.7e+06, 4.2e+06)
radii = (48e+03, 96e+03)
angle = pi / 12
phi.interpolate(gaussian([loc + radii], mesh, rotation=angle))

# Define gauge indicators
radius = 20.0e+03 * pow(
    0.5, level)  # The finer the mesh, the more precise the indicator region
P0 = FunctionSpace(mesh, "DG", 0)
for gauge in gauges:
    loc = op.gauges[gauge]["coords"]
    op.gauges[gauge]['indicator'] = interpolate(
        ellipse([loc + (radius, )], mesh), P0)
    area = assemble(op.gauges[gauge]['indicator'] * dx)
    op.gauges[gauge]['indicator'].assign(op.gauges[gauge]['indicator'] / area)


def solve_forward(control, store=False):
    """