<commit_before>import numpy as np
import subprocess


def read_vector(filename):
    v = []
    with open(filename, "r") as fd:
        for line in fd:
            v.append(float(line))
    return np.array(v)


def check_vectors(filea="elimination.vector",
                  fileb="schur.vector"):
    veca = read_vector(filea)
    vecb = read_vector(fileb)
    return np.linalg.norm(veca - vecb) / np.linalg.norm(vecb)


def run(fd, t, mesh="../data/square-disc-p3.mesh", diffusion=False):
    commandline = ["./ex-normal",
                   "--reltol", "1.e-10",
                   "--mesh", mesh]
    if diffusion:
        commandline.append("--diffusion")
    if t[0] == "p":
        commandline = commandline + ["--penalty", t[1:]]
    elif t == "elimination":
        commandline = commandline + ["--elimination"]
    p = subprocess.Popen(commandline, stdout=fd, stderr=fd)
    p.communicate()


def main():
    with open("normalcheck.log", "w") as fd:
        for mesh in ["../data/square-disc-p3.mesh",
                     "icf.mesh",
                     "sphere_hex27.mesh"]:
            print(mesh)
            for d in [False]:
                print("  diffusion:", d)
                run(fd, "schur", mesh=mesh, diffusion=d)
                run(fd, "elimination", mesh=mesh, diffusion=d)
                print("    ", check_vectors())


def penalty(diffusion=False):
    print("Check penalty sanity, error should scale like 1/penalty:")
    with open("penalty.log", "w") as fd:
        run(fd, "schur")
        # run(fd, "elimination")
        for penalty in [1.0, 1.e+2, 1.e+4, 1.e+6]:
            run(fd, "p" + str(penalty), diffusion=diffusion)
            print("  penalty parameter:", penalty, ", error:",
                  check_vectors(filea="penalty.vector"))


if __name__ == "__main__":
    main()
    penalty()
    # penalty(True)<commit_msg>Test --diffusion with boundary conditions, works reasonably well<commit_after>import numpy as np
import subprocess


def read_vector(filename):
    v = []
    with open(filename, "r") as fd:
        for line in fd:
            v.append(float(line))
    return np.array(v)


def check_vectors(filea="elimination.vector",
                  fileb="schur.vector"):
    veca = read_vector(filea)
    vecb = read_vector(fileb)
    return np.linalg.norm(veca - vecb) / np.linalg.norm(vecb)


def run(fd, t, mesh="../data/square-disc-p3.mesh", diffusion=False):
    commandline = ["./ex-normal",
                   "--reltol", "1.e-10",
                   "--mesh", mesh]
    if diffusion:
        commandline.append("--diffusion")
        commandline = commandline + ["--boundary-attribute", "1"]
    if t[0] == "p":
        commandline = commandline + ["--penalty", t[1:]]
    elif t == "elimination":
        commandline = commandline + ["--elimination"]
    p = subprocess.Popen(commandline, stdout=fd, stderr=fd)
    p.communicate()


def main():
    with open("normalcheck.log", "w") as fd:
        for mesh in ["../data/square-disc-p3.mesh",
                     "icf.mesh",
                     "sphere_hex27.mesh"]:
            print(mesh)
            ds = [False]
            if mesh == "../data/square-disc-p3.mesh":
                ds = [False, True]
            for d in ds:
                print("  diffusion:", d)
                run(fd, "schur", mesh=mesh, diffusion=d)
                run(fd, "elimination", mesh=mesh, diffusion=d)
                print("    ", check_vectors())


def penalty(diffusion=False):
    print("Check penalty sanity, error should scale like 1/penalty:")
    with open("penalty.log", "w") as fd:
        run(fd, "schur", diffusion=diffusion)
        for penalty in [1.0, 1.e+2, 1.e+4, 1.e+6]:
            run(fd, "p" + str(penalty), diffusion=diffusion)
            print("  penalty parameter:", penalty, ", error:",
                  check_vectors(filea="penalty.vector"))


if __name__ == "__main__":
    main()
    penalty()
    penalty(True)
{'fraction_non_alphanumeric': 0.15678824721377912, 'fraction_numerical': 0.009625126646403243, 'mean_word_length': 2.0948275862068964, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5074415', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1259, 'n_words': 291}