Example #1
0
def test_map_flag_section_data():
    # basic 4 element SHELL181 result files
    shell181_2020r2 = os.path.join(testfiles_path, 'shell181_2020R2.rst')
    shell181_2021r1 = os.path.join(testfiles_path, 'shell181_2021R1.rst')

    rst_2020r2 = pymapdl_reader.read_binary(shell181_2020r2)
    rst_2021r1 = pymapdl_reader.read_binary(shell181_2021r1)

    for key in rst_2020r2.section_data:
        assert np.allclose(rst_2020r2.section_data[key],
                           rst_2021r1.section_data[key])
Example #2
0
def test_element_stress_v182_non_cyclic():
    """
    Generated ansys results with:
    ansys.Post1()
    ansys.Set(1, 1)
    ansys.Header('OFF', 'OFF', 'OFF', 'OFF', 'OFF', 'OFF')
    ansys.Format('', 'E', 80, 20)
    ansys.Page(1E9, '', -1)

    msg = ansys.Presol('S').splitlines()
    ansys_element_stress = []
    for line in msg:
        if len(line) == 201:
            ansys_element_stress.append(line)
    ansys_element_stress = np.genfromtxt(ansys_element_stress)
    ansys_enode = ansys_element_stress[:, 0].astype(np.int)
    ansys_element_stress = ansys_element_stress[:, 1:]

    """
    ansys_result_file = os.path.join(cyclic_testfiles_path, 'cyclic_v182.rst')
    result = pymapdl_reader.read_binary(ansys_result_file)

    elemnum, element_stress, enode = result.element_stress(0, False, False)
    assert np.allclose(np.sort(elemnum), elemnum), 'elemnum must be sorted'

    element_stress = np.vstack(element_stress)
    enode = np.hstack(enode)

    # cyclic model will only output the master sector
    from_ansys = np.load(os.path.join(cyclic_testfiles_path,
                                      'v182_presol.npz'))
    assert np.allclose(from_ansys['enode'], enode)
    assert np.allclose(from_ansys['element_stress'], element_stress)
Example #3
0
def SaveDefHistory(rstfile, outFile, wdir='', factor=1, readFromFile=True):
    if (readFromFile):
        if (os.path.exists(rstfile) == False):
            ShowMsg('File does NOT exist.')
            return None
        # Create result object by loading the result file
        # Working with result after simulation
        result = Reader.read_binary(rstfile)  # Using Reader
    else:
        result = rstfile

    rsetMax = result.nsets

    loads = range(0, rsetMax - 1, 10)

    for ld in loads:
        SaveNodalInfo(rstfile, outFile, wdir, factor, readFromFile, ld, True)
        ShowMsg('Step %i of %i written.' % (ld, rsetMax - 1), 1)

    # Export the Final solution
    if ((rsetMax - ld) > 1):
        SaveNodalInfo(rstfile, outFile, wdir, factor, readFromFile,
                      rsetMax - 1, True)
        ShowMsg('Step %i of %i written.' % (rsetMax - 1, rsetMax - 1), 1)

    return None
Example #4
0
def test_read_temperature():
    temp_rst = pymapdl_reader.read_binary(temperature_rst)
    nnum, temp = temp_rst.nodal_temperature(0)

    npz_rst = np.load(temperature_known_result)
    assert np.allclose(nnum, npz_rst['nnum'])
    assert np.allclose(temp, npz_rst['temp'])
Example #5
0
def test_overwrite_dict(tmpdir):
    tmp_path = str(tmpdir.mkdir("tmpdir"))
    rst = pymapdl_reader.read_binary(copy(examples.rstfile, tmp_path))

    # get the data
    solution_type = 'EEL'
    enum, esol_old, _ = rst.element_solution_data(0, solution_type)

    indices = (10, 20)
    old_records = [esol_old[index] for index in indices]

    element_data = {
        enum[indices[0]]: np.random.random(old_records[0].size),
        enum[indices[1]]: np.random.random(old_records[1].size)
    }

    rst.overwrite_element_solution_records(element_data, 0, solution_type)

    # verify data has been written
    new_record = rst.element_solution_data(0, solution_type)[1]

    for i, index in enumerate(indices):
        assert not np.allclose(old_records[i],
                               new_record[index]), "nothing overwritten"
        assert np.allclose(element_data[enum[indices[i]]], new_record[index])
def test_beam44():
    result = pymapdl_reader.read_binary(BEAM44_RST)
    assert result.grid.n_cells
    assert result.grid.n_points
    nnum, disp = result.nodal_solution(0)
    assert nnum.size == result.grid.n_points
    assert disp.any()
Example #7
0
def test_file_close(tmpdir):
    tmpfile = str(tmpdir.mkdir("tmpdir").join('tmp.rst'))
    shutil.copy(examples.rstfile, tmpfile)
    rst = pymapdl_reader.read_binary(tmpfile)
    nnum, stress = rst.nodal_stress(0)
    del rst
    os.remove(tmpfile)  # tests file has been correctly closed
Example #8
0
def test_not_all_found(thermal_solution, mapdl, tmpdir):
    filename = os.path.join(mapdl.directory, 'file0.rth')

    tmp_file = os.path.join(mapdl.directory, 'tmp0.rth')
    shutil.copy(filename, tmp_file)
    with pytest.raises(FileNotFoundError):
        dist_rst = pymapdl_reader.read_binary(tmp_file)
Example #9
0
def test_shell_stress_element_cs():
    result = pymapdl_reader.read_binary(result_file_name)
    enum, stress, enode = result.element_stress(0, in_element_coord_sys=True)

    idx = np.where(enum == 118223)[0][0]
    assert np.allclose(KNOWN_RESULT_ENODE, enode[idx][:4])
    assert np.allclose(KNOWN_RESULT_STRESS, stress[idx], rtol=1E-4)
Example #10
0
def test_plot_temperature(thermal_solution, mapdl):
    if not mapdl._distributed:
        return

    dist_rst = pymapdl_reader.read_binary(
        os.path.join(mapdl.directory, 'file0.rth'))
    cpos = dist_rst.plot_nodal_temperature(0)
    assert isinstance(cpos, CameraPosition)
Example #11
0
def test_rst_beam4_shell63():
    filename = os.path.join(testfiles_path, 'shell63_beam4.rst')

    # check geometry can load
    rst = pymapdl_reader.read_binary(filename)
    assert isinstance(rst.grid.points, np.ndarray)
    assert isinstance(rst.grid.cells, np.ndarray)
    assert (rst.grid.cells >= 0).all()
    assert (rst.grid.cells <= 50).all()

    # not a great test, but verifies results load
    assert np.any(rst.nodal_displacement(0)[1] > 0)
Example #12
0
def test_temperature(thermal_solution, mapdl, tmpdir):
    ans_temp = mapdl.post_processing.nodal_temperature
    dist_rst = pymapdl_reader.read_binary(os.path.join(mapdl.directory, 'file0.rth'))

    # normal result should match
    rst = mapdl.result  # normally not distributed
    nnum, rst_temp = rst.nodal_temperature(0)
    assert np.allclose(rst_temp, ans_temp)

    # distributed result should match
    dist_nnum, dist_temp = dist_rst.nodal_temperature(0)
    assert np.allclose(dist_temp, ans_temp)
    assert np.allclose(dist_nnum, nnum)
Example #13
0
def test_plot_component():
    """
    # create example file for component plotting
    ansys = launch_mapdl()
    ansys.Cdread('db', examples.hexarchivefile)
    # ansys.open_gui()
    ansys.Esel('S', 'ELEM', vmin=1, vmax=20)
    ansys.Nsle('S', 1)
    ansys.Cm('MY_COMPONENT', 'NODE')

    ansys.Nsel('S', 'NODE', '', 1, 40)
    ansys.Cm('MY_OTHER_COMPONENT', 'NODE')

    ansys.Allsel()

    # Aluminum properties (or something)
    ansys.Prep7()
    ansys.Mp('ex', 1, 10e6)
    ansys.Mp('nuxy', 1, 0.3)
    ansys.Mp('dens', 1, 0.1/386.1)
    ansys.Mp('dens', 2, 0)

    ansys.Run("/SOLU")
    ansys.Antype(2, "NEW")
    ansys.Run("BCSOPT,,INCORE")
    ansys.Modopt("LANB", 1)
    ansys.Mxpand(elcalc='YES')
    ansys.Run("/GOPR")
    ansys.Solve()
    ansys.Finish()
    ansys.exit()
    """

    filename = os.path.join(testfiles_path, 'comp_hex_beam.rst')
    result = pymapdl_reader.read_binary(filename)

    components = ['MY_COMPONENT', 'MY_OTHER_COMPONENT']
    result.plot_nodal_solution(0,
                               node_components=components,
                               off_screen=True,
                               sel_type_all=False)
    result.plot_nodal_stress(0,
                             'x',
                             node_components=components,
                             off_screen=True)
    result.plot_principal_nodal_stress(0,
                                       'SEQV',
                                       node_components=components,
                                       off_screen=True)
Example #14
0
def test_overwrite(tmpdir):
    tmp_path = str(tmpdir.mkdir("tmpdir"))
    rst = pymapdl_reader.read_binary(copy(examples.rstfile, tmp_path))

    # get the data
    solution_type = 'EEL'
    enum, esol_old, _ = rst.element_solution_data(0, solution_type)

    index = 10
    element_id = enum[index]
    old_record = esol_old[index]
    ovr_record = np.random.random(old_record.size)

    rst.overwrite_element_solution_record(ovr_record, 0, solution_type, element_id)

    # verify data has been written
    new_record = rst.element_solution_data(0, solution_type)[1][index]
    assert not np.allclose(new_record, old_record), "nothing overwritten"
    assert np.allclose(ovr_record, new_record)
Example #15
0
def PlotNodalSolution(rstfile, step=-1, readFromFile=True):
    '''
    

    Parameters
    ----------
    rstfile : TYPE
        Either filepath of 'rst' or the result object variable.
    step : TYPE, optional
        DESCRIPTION. The default is -1.
    readFromFile : bool, optional
        If set to False, rstfile is 'mapdl.result' object. The default is True.

    Returns
    -------
    result : PyVista.pyplot
        Plot of nodal deformation.

    '''
    if (readFromFile):
        # Create result object by loading the result file
        # Working with result after simulation
        result = Reader.read_binary(rstfile)  # Using Reader
    else:
        result = rstfile

    if (step < 0):
        rsetMax = result.nsets - 1
    else:
        rsetMax = step

    # Plot nodal solution
    result.plot_nodal_solution(rsetMax,
                               background='w',
                               show_edges=True,
                               show_displacement=True,
                               notebook=False,
                               window_size=[512, 384])
    return result
Example #16
0
def GetNodalInfoFromRST(rstfile, step=-1, readFromFile=True):
    '''
    

    Parameters
    ----------
    rstfile : TYPE
        Either filepath of 'rst' or the result object variable.
    step : TYPE, optional
        DESCRIPTION. The default is -1.
    readFromFile : bool, optional
        If set to False, rstfile is 'mapdl.result' object. The default is True.

    Returns
    -------
    result : [nodeNum, nodeDisp]  
        List of nodes and nodal displacements.

    '''
    if (readFromFile):
        # Create result object by loading the result file
        # Working with result after simulation
        result = Reader.read_binary(rstfile)  # Using Reader
    else:
        result = rstfile

    if (step < 0):
        rsetMax = result.nsets - 1
    else:
        rsetMax = step

    # Get nodal solutions, along with nodal numbers
    rslt = GetNodalData_Result(result, 1.0, step)

    return rslt
    pass
Example #17
0
def test_loadbeam():
    linkresult_path = os.path.join(testfiles_path, 'link1.rst')
    linkresult = pymapdl_reader.read_binary(linkresult_path)
    assert np.any(linkresult.grid.cells)
Example #18
0
def result():
    return pymapdl_reader.read_binary(examples.rstfile)
Example #19
0
def SaveNodalInfo(rstfile,
                  outFile,
                  wdir='',
                  factor=1,
                  readFromFile=True,
                  step=-1,
                  appendTimeStamp=False,
                  doCombined=True):

    if (readFromFile):
        # Create result object by loading the result file
        # Working with result after simulation
        result = Reader.read_binary(rstfile)  # Using Reader
    else:
        result = rstfile

    if (step < 0):
        rsetMax = result.nsets - 1
    else:
        rsetMax = step

    # Get nodal displacements
    nnum, ndisp = result.nodal_displacement(rsetMax)

    # Plot nodal solution
    # result.plot_nodal_solution(rsetMax,background='w',show_edges=True,show_displacement=True)

    # Get nodes original position
    nodes = result.mesh.nodes

    nodeCnt = len(nodes)

    # doCombined = True
    compFactor = factor  # To get deformed shape, use +1.
    rset = rsetMax
    tStep = result.solution_info(rset)['timfrq']

    tStepStr = "%08.1f" % (tStep)

    # Get nodal solutions, along with nodal numbers
    nodeNum, nodeDisp = result.nodal_displacement(rset)  # first set
    nodeNum, nodeTemp = result.nodal_temperature(rset)
    isothermTemp = nodeTemp[1]  # Nodal temp

    if (appendTimeStamp):
        filePref, fileExt = SplitFileName(outFile)
        outFile = filePref + '_T_' + tStepStr + '.' + fileExt

    # Using info https://www.w3schools.com/python/python_file_write.asp
    fullname = FullPath(outFile, wdir)
    f = open(fullname, "w")
    try:

        print("%s %68s" % ('!', "Nodal Information Dump"), file=f)
        print("%s %58s%10i" % ('!', "Total Nodes =", nodeCnt), file=f)
        if (doCombined):
            print("%s%9s%20s%20s%20s" % ('!', "Node", "X", "Y", "Z"), file=f)
            print("nblock,3,,%i" % (nodeCnt), file=f)
            print("(1i9,3e20.9e3)", file=f)

        else:
            print("%s%9s%20s%20s%20s%20s%20s%20s" %
                  ('!', "Node", "X", "Y", "Z", "UX", "UY", "UZ"),
                  file=f)
            print("nblock,3,,%i" % (nodeCnt), file=f)
            print("(1i9,6e20.9e3)", file=f)

        for j in nodeNum:
            if (doCombined):
                print("%9i%20.9E%20.9E%20.9E" %
                      (j, nodes[j - 1, 0] + compFactor * nodeDisp[j - 1, 0],
                       nodes[j - 1, 1] + compFactor * nodeDisp[j - 1, 1],
                       nodes[j - 1, 2] + compFactor * nodeDisp[j - 1, 2]),
                      file=f)
            else:
                print("%9i%20.9E%20.9E%20.9E%20.9E%20.9E%20.9E" %
                      (j, nodes[j - 1, 0], nodes[j - 1, 1], nodes[j - 1, 2],
                       nodeDisp[j - 1, 0], nodeDisp[j - 1, 1], nodeDisp[j - 1,
                                                                        2]),
                      file=f)

        print("-1", file=f)
        print(
            "! ====================================================================",
            file=f)
    except:
        pass

    f.close()
    return True
Example #20
0
def volume_rst():
    rst_file = os.path.join(testfiles_path, 'vol_test.rst')
    return pymapdl_reader.read_binary(rst_file)
Example #21
0
def thermal_rst():
    filename = os.path.join(testfiles_path, 'file.rth')
    return pymapdl_reader.read_binary(filename)
Example #22
0
def test_file_not_found():
    with pytest.raises(FileNotFoundError):
        pymapdl_reader.read_binary('not_a_file.rst')
Example #23
0
def test_reaction_forces():
    rst = pymapdl_reader.read_binary(os.path.join(testfiles_path, 'vm1.rst'))
    nnum, forces = rst.nodal_static_forces(0)
    assert np.allclose(nnum, [1, 2, 3, 4])
    assert np.allclose(forces[:, 1], [-600, 250, 500, -900])
Example #24
0
def _download_and_read(filename):
    saved_file, _ = _download_file(filename)
    if saved_file[-3:] == 'cdb':
        return pymapdl_reader.Archive(saved_file)
    else:
        return pymapdl_reader.read_binary(saved_file)
Example #25
0
def static_canteliver_bc():
    filename = os.path.join(testfiles_path, 'rst', 'beam_static_bc.rst')
    return pymapdl_reader.read_binary(filename)
Example #26
0
def beam_blade():
    filename = os.path.join(testfiles_path, 'dist_rst', 'blade_stations',
                            'beam3_0.rst')
    return pymapdl_reader.read_binary(filename)
Example #27
0
def test_file_not_supported():
    with pytest.raises(RuntimeError):
        pymapdl_reader.read_binary(os.path.join(testfiles_path, 'file.esav'))
Example #28
0
def static_rst():
    filename = os.path.join(testfiles_path, 'dist_rst', 'static', 'file.rst')
    return pymapdl_reader.read_binary(filename)
def rst():
    rst_file = os.path.join(path, 'file.rst')
    return pymapdl_reader.read_binary(rst_file)
Example #30
0
outputDir = "D:\\Basil\\OneDrive - University of Pittsburgh\\Shared\\Hao\\BinderJet Distortion Data\\SimulationTimeHistory\\"
outputDir = "D:\\Basil\\OneDrive - University of Pittsburgh\\Shared\\Hao\\BinderJet Distortion Data\\IT0_Results\\"
outputDir = "D:\\Basil\\Deformation_Comp\\Hao\\CD1\\IT0_1\\"
try:
    if (os.path.exists(outputDir) == False):
        os.mkdir(outputDir)
except OSError as error:
    print('Error Creating folder')

# mapdl = launch_mapdl("True", loglevel="WARNING")
# Sample result file
rstfile = fullnameInput

# Create result object by loading the result file
# Working with result after simulation
result = Reader.read_binary(rstfile)  # Using Reader

# Get result using dpf
#mdl = Model(rstfile)
##rslt = mdl.results
#disp = rslt.displacement()
#fldC = disp.outputs.fields_container()
#fld = fldC[0]
#result = mdl.results

rsetMax = result.nsets - 1

# Get nodal displacements
nnum, ndisp = result.nodal_displacement(rsetMax)

# Plot nodal solution