def add_circle(
        self,
        x0,
        radius,
        lcar=None,
        R=None,
        compound=False,
        num_sections=3,
        holes=None,
        make_surface=True,
    ):
        """Add circle in the :math:`x`-:math:`y`-plane.
        """
        if holes is None:
            holes = []
        else:
            assert make_surface

        # Define points that make the circle (midpoint and the four cardinal
        # directions).
        X = numpy.zeros((num_sections + 1, len(x0)))
        if num_sections == 4:
            # For accuracy, the points are provided explicitly.
            X[1:, [0, 1]] = numpy.array(
                [[radius, 0.0], [0.0, radius], [-radius, 0.0], [0.0, -radius]]
            )
        else:
            X[1:, [0, 1]] = numpy.array(
                [
                    [
                        radius * numpy.cos(2 * numpy.pi * k / num_sections),
                        radius * numpy.sin(2 * numpy.pi * k / num_sections),
                    ]
                    for k in range(num_sections)
                ]
            )

        if R is not None:
            assert numpy.allclose(
                abs(numpy.linalg.eigvals(R)), numpy.ones(X.shape[1])
            ), "The transformation matrix doesn't preserve circles; at least one eigenvalue lies off the unit circle."
            X = numpy.dot(X, R.T)

        X += x0

        # Add Gmsh Points.
        p = [self.add_point(x, lcar=lcar) for x in X]

        # Define the circle arcs.
        arcs = [self.add_circle_arc(p[k], p[0], p[k + 1]) for k in range(1, len(p) - 1)]
        arcs.append(self.add_circle_arc(p[-1], p[0], p[1]))

        if compound:
            if self._gmsh_major() == 3:
                arcs = [self.add_compound_line(arcs)]
            elif self._gmsh_major() == 4:
                self.add_raw_code(
                    "Compound Curve{{{}}};".format(",".join([arc.id for arc in arcs]))
                )

        line_loop = self.add_line_loop(arcs)

        if make_surface:
            plane_surface = self.add_plane_surface(line_loop, holes)
            if compound and self._gmsh_major() == 4:
                self.add_raw_code("Compound Surface{{{}}};".format(plane_surface.id))
        else:
            plane_surface = None

        class Circle(object):
            def __init__(
                self,
                x0,
                radius,
                R,
                compound,
                num_sections,
                holes,
                line_loop,
                plane_surface,
                lcar=None,
            ):
                self.x0 = x0
                self.radius = radius
                self.lcar = lcar
                self.R = R
                self.compound = compound
                self.num_sections = num_sections
                self.holes = holes
                self.line_loop = line_loop
                self.plane_surface = plane_surface
                return

        return Circle(
            x0,
            radius,
            R,
            compound,
            num_sections,
            holes,
            line_loop,
            plane_surface,
            lcar=lcar,
        )
def add_circle ( self , x0 , radius , lcar = None , R = None , compound = False , num_sections = 3 , holes = None , make_surface = True , ) : if holes is None : holes = [ ] else : assert make_surface X = numpy . zeros ( ( num_sections + 1 , len ( x0 ) ) ) if num_sections == 4 : X [ 1 : , [ 0 , 1 ] ] = numpy . array ( [ [ radius , 0.0 ] , [ 0.0 , radius ] , [ - radius , 0.0 ] , [ 0.0 , - radius ] ] ) else : X [ 1 : , [ 0 , 1 ] ] = numpy . array ( [ [ radius * numpy . cos ( 2 * numpy . pi * k / num_sections ) , radius * numpy . sin ( 2 * numpy . pi * k / num_sections ) , ] for k in range ( num_sections ) ] ) if R is not None : assert numpy . allclose ( abs ( numpy . linalg . eigvals ( R ) ) , numpy . ones ( X . shape [ 1 ] ) ) , "The transformation matrix doesn't preserve circles; at least one eigenvalue lies off the unit circle." X = numpy . dot ( X , R . T ) X += x0 p = [ self . add_point ( x , lcar = lcar ) for x in X ] arcs = [ self . add_circle_arc ( p [ k ] , p [ 0 ] , p [ k + 1 ] ) for k in range ( 1 , len ( p ) - 1 ) ] arcs . append ( self . add_circle_arc ( p [ - 1 ] , p [ 0 ] , p [ 1 ] ) ) if compound : if self . _gmsh_major ( ) == 3 : arcs = [ self . add_compound_line ( arcs ) ] elif self . _gmsh_major ( ) == 4 : self . add_raw_code ( "Compound Curve{{{}}};" . format ( "," . join ( [ arc . id for arc in arcs ] ) ) ) line_loop = self . add_line_loop ( arcs ) if make_surface : plane_surface = self . add_plane_surface ( line_loop , holes ) if compound and self . _gmsh_major ( ) == 4 : self . add_raw_code ( "Compound Surface{{{}}};" . format ( plane_surface . id ) ) else : plane_surface = None class Circle ( object ) : def __init__ ( self , x0 , radius , R , compound , num_sections , holes , line_loop , plane_surface , lcar = None , ) : self . x0 = x0 self . radius = radius self . lcar = lcar self . R = R self . compound = compound self . num_sections = num_sections self . holes = holes self . line_loop = line_loop self . plane_surface = plane_surface return return Circle ( x0 , radius , R , compound , num_sections , holes , line_loop , plane_surface , lcar = lcar , )
Add circle in the :math:`x`-:math:`y`-plane.