Project: s41467-024-47831-2 | Function: homogenized_elasticity_matrix_2d (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Numerical homogenization algorithm for computing effective constitutive properties of irregular architected materials by solving unit cell boundary value problems and deriving homogenized elasticity tensor from microstructural stiffness matrices

**KEY TERMS:** {
  "K_uc": "unit cell global stiffness matrix",
  "B_0": "topology matrix relating independent and slave nodes",
  "B_a": "matrix handling periodic boundary conditions",
  "B_eps": "strain-displacement matrix for homogenization",
  "V": "unit cell volume",
  "D_0": "displacement correction matrix",
  "K_eps": "homogenized elasticity tensor"
}

**CONTEXT CODE:**     assert (master_nodes.size + slave_nodes.size + interior_nodes.size == nodes.shape[1])

    # Compute B_0 matrix
    independent_nodes = np.hstack((master_nodes, interior_nodes))
    B_0 = np.zeros((all_nodes.size, independent_nodes.size), dtype=int)
    B_0[independent_nodes, np.arange(independent_nodes.size).astype(int)] = 1

    left_coords = nodes.T[left_master_nodes]
    left_coords[:, 0] += lx
    right_coords = nodes.T[right_slave_nodes]
    indices = find_indices(independent_nodes, left_master_nodes)
    args = compare_matrices(left_coords, right_coords, precision=6)
    cols = indices[args]
    B_0[right_slave_nodes, cols] = 1

    bottom_coords = nodes.T[bottom_master_nodes]
    bottom_coords[:, 1] += ly
    top_coords = nodes.T[top_slave_nodes]
    indices = find_indices(independent_nodes, bottom_master_nodes)
    args = compare_matrices(bottom_coords, top_coords, precision=6)
    cols = indices[args]
    B_0[top_slave_nodes, cols] = 1

    assert np.allclose(np.sum(B_0, axis=1), 1)
    B_0 = np.kron(B_0, np.eye(2, dtype=int))
    assert B_0.shape == (2*all_nodes.size, 2*independent_nodes.size)

    # Compute B_a matrix
    B_a = np.zeros((all_nodes.size, 2), dtype=int)
    B_a[right_slave_nodes, 0] = 1
    B_a[top_slave_nodes, 1] = 1
    B_a = np.kron(B_a, np.eye(2, dtype=int))
    assert B_a.shape == (2*all_nodes.size, 4)

    a_1x, a_1y = lx, 0.0
    a_2x, a_2y = 0.0, ly
    B_eps = np.array([
        [a_1x, 0.0, a_1y/2],
        [0.0, a_1y, a_1x/2],
        [a_2x, 0.0, a_2y/2],
        [0.0, a_2y, a_2x/2],
    ])

    V = np.linalg.det(np.array([
        [a_1x, a_1y],
        [a_2x, a_2y],
    ]))  # Volume
    return B_0, B_a, B_eps, V


def homogenized_elasticity_matrix_2d(nodes, elements, mat_table):
    """Compute the homogenized constitutive matrix."""
    raise NotImplementedError("Function has been masked for testing purposes")


Complete the function implementation replacing "raise NotImplementedError".