예제 #1
0
def test_check_fields_label():
    # setup
    f1 = multifield.Field(label='ab', rightBC=1.3)
    f2 = multifield.Field(label='de', rightBC=1.4)
    f3 = multifield.Field(label='ions', rightBC=np.ones(2))
    f4 = multifield.Field(label='ions', rightBC=1.5)
    fields = [f1, f2, f3]
    fields2 = [f1, f2, f3, f4]

    # check
    assert multifield.check_fields_label(fields)
    assert not multifield.check_fields_label(fields2)
예제 #2
0
def test_get_field_by_label():
    """Test get_field_by_label() function."""
    # create a list of fields with labels
    f1 = multifield.Field(label='ab')
    f2 = multifield.Field(label='de')
    f3 = multifield.Field(label='ions')
    f4 = multifield.Field(label='electrons')
    fields = [f1, f2, f3, f4]

    # check
    assert multifield.get_field_by_label(fields, 'ab') is f1
    assert multifield.get_field_by_label(fields, 'de') is f2
    assert multifield.get_field_by_label(fields, 'ions') is f3
    assert multifield.get_field_by_label(fields, 'electrons') is f4
예제 #3
0
def test_check_fields_profile_mminus1():
    # setup
    f1 = multifield.Field(label='ab', profile_mminus1=np.zeros(3))
    f2 = multifield.Field(label='de', profile_mminus1=np.zeros(3))
    f3 = multifield.Field(label='ions', profile_mminus1=np.ones(4))
    f4 = multifield.Field(label='elecs')
    fields = [f1, f2]
    fields2 = [f1, f2, f3]
    fields3 = [f1, f2, f4]

    # check
    assert multifield.check_fields_profile_mminus1(fields)
    assert not multifield.check_fields_profile_mminus1(fields2)
    assert not multifield.check_fields_profile_mminus1(fields3)
예제 #4
0
def test_check_fields_coupled_to():
    # setup
    f1 = multifield.Field(label='ab')
    f2 = multifield.Field(label='de')
    f3 = multifield.Field(label='ions', coupledTo='elecs')
    f4 = multifield.Field(label='elecs', coupledTo='ions')
    f5 = multifield.Field(label='elecs', coupledTo='aa')
    f6 = multifield.Field(label='elecs')

    # check
    assert multifield.check_fields_coupled_to([f1, f2, f3, f4])
    assert not multifield.check_fields_coupled_to([f1, f2, f3, f5])
    assert not multifield.check_fields_coupled_to([f1, f2, f3, f6])
    # check with a different order
    assert multifield.check_fields_coupled_to([f1, f2, f4, f3])
    assert not multifield.check_fields_coupled_to([f1, f2, f5, f3])
    assert not multifield.check_fields_coupled_to([f1, f2, f6, f3])
예제 #5
0
def test_solve_multiple_fieldgroups():
    """Test the chain of functions for solving multiple fieldgroups."""
    # ----Setup----
    (dt, dx, nL, n_initial, H1, H2, H7, n_ss_analytic,
     rtol) = one_field_polar_setup()
    label0 = 'field0'

    (dt, dx, rightBC, psi_mminus1, J1, J2, J3, J6, J7, J8, K1, K2, K3, K6, K7,
     K8, psiAnalytic, rtol) = two_field_equation_setup()
    label1 = 'field1'
    label2 = 'field2'

    # create the fields
    field0 = multifield.Field(label0, nL, n_initial, coupledTo=None)
    field1 = multifield.Field(label1,
                              rightBC[0],
                              psi_mminus1[0],
                              coupledTo='field2')
    field2 = multifield.Field(label2,
                              rightBC[1],
                              psi_mminus1[1],
                              coupledTo='field1')
    fields = [field0, field1, field2]

    # create the HCoeffsAllFields
    HCoeffsAllFields = {}
    HCoeffs0 = multifield.HCoefficients(H1=H1, H2=H2, H7=H7)
    HCoeffs1 = multifield.HCoefficients(H1=J1,
                                        H2=J2,
                                        H3=J3,
                                        H6=J6,
                                        H7=J7,
                                        H8=J8)
    HCoeffs2 = multifield.HCoefficients(H1=K1,
                                        H2=K2,
                                        H3=K3,
                                        H6=K6,
                                        H7=K7,
                                        H8=K8)
    HCoeffsAllFields[field0.label] = HCoeffs0
    HCoeffsAllFields[field1.label] = HCoeffs1
    HCoeffsAllFields[field2.label] = HCoeffs2

    # ----Run through the solve steps----
    # create fieldGroups from fields
    fieldGroups = fieldgroups.fields_to_fieldgroups(fields, HCoeffsAllFields)

    # discretize to create matrix equation
    for fieldGroup in fieldGroups:
        fieldGroup.matrixEqn = fieldGroup.Hcoeffs_to_matrix_eqn(
            dt, dx, fieldGroup.rightBC, fieldGroup.psi_mminus1,
            fieldGroup.HCoeffs)

    # solve the matrix equations [iterating over groups]
    for fieldGroup in fieldGroups:
        fieldGroup.profileSolution = fieldGroup.solve_matrix_eqn(
            fieldGroup.matrixEqn)

    # get the profiles for the fields out of the fieldGroups, put into a dict of profiles
    profiles = fieldgroups.fieldgroups_to_profiles(fieldGroups)

    # ----Check----
    assert np.allclose(profiles[label0], n_ss_analytic, rtol)
    assert np.allclose(profiles[label1], psiAnalytic[0], rtol)
    assert np.allclose(profiles[label2], psiAnalytic[1], rtol)
예제 #6
0
def test_fields_to_fieldgroups():
    """Test the fields_to_fieldgroups() function."""
    # setup
    (dt, dx, nL, n_initial, H1, H2, H7, n_ss_analytic,
     rtol) = one_field_polar_setup()
    label0 = 'field0'

    (dt, dx, rightBC, psi_mminus1, J1, J2, J3, J6, J7, J8, K1, K2, K3, K6, K7,
     K8, psiAnalytic, rtol) = two_field_equation_setup()
    label1 = 'field1'
    label2 = 'field2'

    # create the fields
    field0 = multifield.Field(label0, nL, n_initial, coupledTo=None)
    field1 = multifield.Field(label1,
                              rightBC[0],
                              psi_mminus1[0],
                              coupledTo='field2')
    field2 = multifield.Field(label2,
                              rightBC[1],
                              psi_mminus1[1],
                              coupledTo='field1')
    fields = [field0, field1, field2]

    # create the HCoeffsAllFields
    HCoeffsAllFields = {}
    HCoeffs0 = multifield.HCoefficients(H1=H1, H2=H2, H7=H7)
    HCoeffs1 = multifield.HCoefficients(H1=J1,
                                        H2=J2,
                                        H3=J3,
                                        H6=J6,
                                        H7=J7,
                                        H8=J8)
    HCoeffs2 = multifield.HCoefficients(H1=K1,
                                        H2=K2,
                                        H3=K3,
                                        H6=K6,
                                        H7=K7,
                                        H8=K8)
    HCoeffsAllFields[field0.label] = HCoeffs0
    HCoeffsAllFields[field1.label] = HCoeffs1
    HCoeffsAllFields[field2.label] = HCoeffs2

    # run the function
    fieldGroups = fieldgroups.fields_to_fieldgroups(fields, HCoeffsAllFields)

    # check that fieldGroups was created properly
    assert len(fieldGroups) == 2
    fg0 = fieldGroups[0]
    # label, Hcoeffs, rightBC, psi_mminus1
    assert fg0.label == label0
    assert fg0.HCoeffs == HCoeffs0
    assert fg0.rightBC == nL
    assert np.allclose(fg0.psi_mminus1, n_initial)

    fg1 = fieldGroups[1]
    assert fg1.label0 == label1
    assert fg1.label1 == label2
    assert np.allclose(fg1.HCoeffs.J1, HCoeffs1.H1) and np.allclose(
        fg1.HCoeffs.J2, HCoeffs1.H2) and np.allclose(
            fg1.HCoeffs.J3, HCoeffs1.H3) and np.allclose(
                fg1.HCoeffs.J6, HCoeffs1.H6)
    assert np.allclose(fg1.HCoeffs.J7, HCoeffs1.H7) and np.allclose(
        fg1.HCoeffs.J8, HCoeffs1.H8)
    assert np.allclose(fg1.HCoeffs.K1, HCoeffs2.H1) and np.allclose(
        fg1.HCoeffs.K2, HCoeffs2.H2) and np.allclose(
            fg1.HCoeffs.K3, HCoeffs2.H3) and np.allclose(
                fg1.HCoeffs.K6, HCoeffs2.H6)
    assert np.allclose(fg1.HCoeffs.K7, HCoeffs2.H7) and np.allclose(
        fg1.HCoeffs.K8, HCoeffs2.H8)
    assert np.allclose(fg1.rightBC, rightBC)
    assert np.allclose(fg1.psi_mminus1[0], psi_mminus1[0])
    assert np.allclose(fg1.psi_mminus1[1], psi_mminus1[1])