Example #1
0
def generate_random_3graph(size_H, K=3):
  H = numpy.empty(shape=(size_H, K), dtype=numpy.int32)   # Generate H, empty adjacency list matrix
  H[:] = -1     # Initialize it with all elements -1

  nodes = numpy.arange(0, size_H)   # Generate list of nodes from 0 to size_H - 1

  randomized_nodes = numpy.random.permutation(nodes)  # Randomize their positions so that we construct random K-regular

  splits = numpy.array_split(randomized_nodes, 2)   # Split the nodes into two halves

  first   = splits[0]   # First half
  second  = splits[1]   # Second half

  for i, node1 in enumerate(first):

    node1_1 = second[ (i-1) % numpy.size(second) ]
    node1_2 = second[ i ]
    node1_3 = second[ (i+1) % numpy.size(second) ]

    H[node1][0]                               = node1_1   # Create the edge (node1, node1_1)
    H[node1_1][helpers.get_rank(node1_1, H)]  = node1   # Create the edge (node1_1, node1)

    H[node1][1]                               = node1_2   # Create the edge (node1, node1_2)
    H[node1_2][helpers.get_rank(node1_2, H)]  = node1   # Create the edge (node1_2, node1)

    H[node1][2]                               = node1_3   # Create the edge (node1, node1_3)
    H[node1_3][helpers.get_rank(node1_3, H)]  = node1   # Create the edge (node1_3, node1)

  return H
Example #2
0
def generate_random_3graph(size_H, K=3):
    H = numpy.empty(
        shape=(size_H, K),
        dtype=numpy.int32)  # Generate H, empty adjacency list matrix
    H[:] = -1  # Initialize it with all elements -1

    nodes = numpy.arange(0,
                         size_H)  # Generate list of nodes from 0 to size_H - 1

    randomized_nodes = numpy.random.permutation(
        nodes
    )  # Randomize their positions so that we construct random K-regular

    splits = numpy.array_split(randomized_nodes,
                               2)  # Split the nodes into two halves

    first = splits[0]  # First half
    second = splits[1]  # Second half

    for i, node1 in enumerate(first):

        node1_1 = second[(i - 1) % numpy.size(second)]
        node1_2 = second[i]
        node1_3 = second[(i + 1) % numpy.size(second)]

        H[node1][0] = node1_1  # Create the edge (node1, node1_1)
        H[node1_1][helpers.get_rank(
            node1_1, H)] = node1  # Create the edge (node1_1, node1)

        H[node1][1] = node1_2  # Create the edge (node1, node1_2)
        H[node1_2][helpers.get_rank(
            node1_2, H)] = node1  # Create the edge (node1_2, node1)

        H[node1][2] = node1_3  # Create the edge (node1, node1_3)
        H[node1_3][helpers.get_rank(
            node1_3, H)] = node1  # Create the edge (node1_3, node1)

    return H
Example #3
0
    def info(self):
        if dolfin.__version__ >= '1.3.0+':
          # I *hate* unannounced and intrusive API changes with no support for a transition.
          comm = mpi_comm_world() # self.domain.mesh.mpi_comm() when it works
          hmin = MPI.min(comm, self.domain.mesh.hmin())
          hmax = MPI.max(comm, self.domain.mesh.hmax())
          num_cells = MPI.sum(comm, self.domain.mesh.num_cells())
          rank = get_rank()
        else:
          hmin = MPI.min(self.domain.mesh.hmin())
          hmax = MPI.max(self.domain.mesh.hmax())
          num_cells = MPI.sum(self.domain.mesh.num_cells())
          rank = MPI.process_number()

        if rank == 0:
            # Physical parameters
            print "\n=== Physical parameters ==="
            if isinstance(self.params["depth"], float):
                print "Water depth: %f m" % self.params["depth"]
            print "Gravity constant: %f m/s^2" % self.params["g"]
            print "Viscosity constant: %f m^2/s" % self.params["diffusion_coef"]
            print "Water density: %f kg/m^3" % self.params["rho"]
            if isinstance(self.params["friction"], dolfin.functions.constant.Constant):
                print "Bottom friction: %s" % (self.params["friction"](0))
            else:
                print "Bottom fruction: %f - %f" %\
                    (self.params["friction"].vector().array().min(),
                     self.params["friction"].vector().array().max())
            print "Advection term: %s" % self.params["include_advection"]
            print "Diffusion term: %s" % self.params["include_diffusion"]
            print "Steady state: %s" % self.params["steady_state"]

            # Turbine settings 
            print "\n=== Turbine settings ==="
            print "Number of turbines: %i" % len(self.params["turbine_pos"])
            print "Turbines parametrisation: %s" % self.params["turbine_parametrisation"]
            if self.params["turbine_parametrisation"] == "individual":
                print "Turbines dimensions: %f x %f" % (self.params["turbine_x"], self.params["turbine_y"])
            print "Control parameters: %s" % ', '.join(self.params["controls"])
            if len(self.params["turbine_friction"]) > 0:
                print "Turbines frictions: %f - %f" % (min(self.params["turbine_friction"]), max(self.params["turbine_friction"]))

            # Discretisation settings
            print "\n=== Discretisation settings ==="
            print "Finite element pair: ", self.finite_element.func_name
            print "Steady state: ", self.params["steady_state"]
            if not self.params["steady_state"]:
                print "Theta: %f" % self.params["theta"]
                print "Start time: %f s" % self.params["start_time"]
                print "Finish time: %f s" % self.params["finish_time"]
                print "Time step: %f s" % self.params["dt"]
            print "Number of mesh elements: %i" % num_cells
            print "Mesh element size: %f - %f" % (hmin, hmax)

            # Optimisation settings
            print "\n=== Optimisation settings ==="
            print "Automatic functional rescaling: %s" % self.params["automatic_scaling"]
            if self.params["automatic_scaling"]:
                print "Automatic functional rescaling multiplier: %s" % self.params["automatic_scaling_multiplier"]
            print "Automatic checkpoint generation: %s" % self.params["save_checkpoints"]
            print ""

            # Solver settings
            print "\n=== Solver settings ==="
            print "Nonlinear solver: %s" % ("Newton" if self.params["newton_solver"] else "Picard")

            # Other 
            print "\n=== Other ==="
            print "Dolfin version: %s" % dolfin.__version__
            print "Cache forward solution for initial solver guess: %s" % self.params["cache_forward_state"]
            print ""