コード例 #1
0
ファイル: models.py プロジェクト: lcharleux/compmod-doc
 def RunPostProc(self):
   """
   Runs the post processing script.
   """
   t0 = time.time()
   p = subprocess.Popen( "{0} viewer -noGUI {1}".format(self.abqlauncher, self.label + '_abqpostproc.py'), cwd = self.workdir,stdout = subprocess.PIPE, shell=True)
   trash = p.communicate()
   print trash[0]
   t1 = time.time()
   print '< Post Processed {0} in Abaqus: duration {1:.2f}s>'.format(self.label, t1 - t0) 
   self.outputs = load(self.workdir + self.label + ".pckl")
コード例 #2
0
def compute_C(E=1.,
              nu=0.3,
              sy=0.01,
              abqlauncher='/opt/Abaqus/6.9/Commands/abaqus',
              workdir='workdir',
              name='indentation_axi_fancier',
              frames=50):
    '''
  Computes the load prefactor C using Abaqus.
  
  Inputs:
  * E: sample's Young modulus.
  * nu: samples's Poisson's ratio
  * sy: sample's yield stress (von Mises yield criterion).
  * abqlauncher: absolute path to abaqus launcher.
  * wordir: path to working directory, can be relative.
  * name: name of simulation files.
  * frames: number of frames per step, increase if the simulation does not complete.
  
  Returns:
  * Load prefactor C (float)
  '''
    import time, subprocess, os
    t0 = time.time()  # Starting time recording
    path = workdir + '/' + name
    # Reading the INP target file
    f = open('indentation_axi_target.inp', 'r')
    inp = f.read()
    f.close()
    # Replace the targets in the file
    inp = inp.replace('#E', '{0}'.format(E))
    inp = inp.replace('#NU', '{0}'.format(nu))
    inp = inp.replace('#SY', '{0}'.format(sy))
    inp = inp.replace('#FRAME', '{0}'.format(1. / frames))
    # Creating a new inp file
    f = open(path + '.inp', 'w')
    f.write(inp)
    f.close()
    print 'Created INP file: {0}.inp'.format(path)
    # Then we run the simulation
    print 'Running simulation in Abaqus'
    p = subprocess.Popen(
        '{0} job={1} input={1}.inp interactive ask_delete=OFF'.format(
            abqlauncher, name),
        cwd=workdir,
        shell=True,
        stdout=subprocess.PIPE)
    trash = p.communicate()

    # Now we test run the post processing script
    print 'Post processing the simulation in Abaqus/Python'
    p = subprocess.Popen(
        [abqlauncher, 'viewer', 'noGUI=fancier_example_abq.py'],
        cwd='.',
        stdout=subprocess.PIPE)
    trash = p.communicate()
    # Getting back raw data
    data = load(workdir + '/' + name + '.pckl')
    # Post processing
    print 'Post processing the simulation in Python'
    if data['completed']:
        ref_node_label = data['ref_node_label']
        force_hist = -data['RF2']['Node I_INDENTER.{0}'.format(ref_node_label)]
        disp_hist = -data['U2']['Node I_INDENTER.{0}'.format(ref_node_label)]
        trash, force_l = force_hist[
            0, 1].plotable()  # Getting back force  during loading
        trash, disp_l = disp_hist[
            0, 1].plotable()  # Getting backdisplacement during loading
        trash, force_u = force_hist[2].plotable(
        )  # Getting back force  during unloading
        trash, disp_u = disp_hist[2].plotable(
        )  # Getting backdisplacement during unloading
        C_factor = (force_hist[1] / disp_hist[1]**2).average()

    else:
        print 'Simulation aborted, probably because frame number is to low'
        C_factor = None
    t1 = time.time()
    print 'Time used: {0:.2e} s'.format(t1 - t0)
    return C_factor
コード例 #3
0
def odb_postproc(workdir, name, iteration_count, H, n, E, nu, iteration_number, P10_test):
    import os
    from abapy.misc import load
    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    from prettytable import PrettyTable

    strain_hardening_exponent = n

    # Extracting the raw data from the .pck1 file
    os.chdir(workdir)
    data = load(name + '.pckl')
    ref_node_label = data['ref_node_label']
    force_hist = -data['RF2']['Node I_INDENTER.{0}'.format(ref_node_label)]
    disp_hist = -data['U2']['Node I_INDENTER.{0}'.format(ref_node_label)]

    # Getting back force & displacemt during loading and scaling units:
    displacement_loading = [1000*x for x in (disp_hist[0,0.5].toArray()[1])]
    force_loading = [1000*x for x in (force_hist[0,0.5].toArray()[1])]

    # Getting back force & displacemt during unloading and scaling units:
    disp_long = [1000*x for x in (disp_hist[1].toArray()[1])]
    force_long = [1000*x for x in (force_hist[1].toArray()[1])]

    # Trimming the trailing zeroes from the unloading dataset
    force_unloading = [i for n, i in enumerate(force_long) if i not in force_long[:n]]
    displacement_unloading = disp_long[:len(force_unloading)]

    # Parabolic Curve fit (E. Buckingham. Physical review, 4, 1914.) shows that the loading curve must be parabolic of the form P=C*h^2
    Parray = force_loading
    h = displacement_loading
    hsquared = [x**2 for x in h]
    C_factor_array = np.divide(Parray[100:], hsquared[100:])
    C_factor = np.mean(C_factor_array)
    disaplacement_loading_fit = displacement_loading
    force_loading_fit = C_factor*np.power(h,2)

    # Modify the loading curve to start at the same point at the curve fit:
    unload_dispstart = disaplacement_loading_fit[-1]
    Pmax = force_loading_fit[-1]
    if Pmax >= force_unloading[0]:
      force_unloading_mod = [Pmax]+force_unloading
      displacement_unloading_mod = [unload_dispstart]+displacement_unloading
    else:
      force_unloading_mod = np.minimum(force_unloading, Pmax)
      displacement_unloading_mod = displacement_unloading

    # Extracting all properties of interest for table
    ITERATION_Pmax  = np.amax(force_loading)

    z = -0.001*np.concatenate([force_loading, force_unloading])
    z = z[::-1]
    z = z.astype(np.float)
    z = -1000*z
    mZ = np.amax(z)
    mZ_index = np.where(z == mZ)
    iteration_force_unloading = z[:mZ_index[0][0]]
 
    w = -0.001*np.concatenate([displacement_loading, displacement_unloading])
    w = w[::-1]
    w = w.astype(np.float)
    w = -1000*w
    iteration_displacment_unloading = w[:mZ_index[0][0]]

    if P10_test == 0:
        P10 = 0.1*ITERATION_Pmax
        point_type = "test"
    elif P10_test == 1:
        P10 = 0.1*ITERATION_Pmax
        #P10 = P10_test
        point_type  = "train"
    else:
        print("ERROR in calculation of P10 location")

    hf1  = np.interp(1*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf2  = np.interp(2*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf3  = np.interp(3*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf4  = np.interp(4*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf5  = np.interp(5*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf6  = np.interp(6*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf7  = np.interp(7*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf8  = np.interp(8*P10, iteration_force_unloading, iteration_displacment_unloading)
    hf9  = np.interp(9*P10, iteration_force_unloading, iteration_displacment_unloading)

    # Creation of dataframe row:
    df = pd.DataFrame([[
        point_type,
        iteration_number,
        round(float(H), 10),
        round(float(strain_hardening_exponent), 10),
        E,
        nu,
        round(ITERATION_Pmax, 10),
        round(hf1, 10),
        round(hf2, 10),
        round(hf3, 10),
        round(hf4, 10),
        round(hf5, 10),
        round(hf6, 10),
        round(hf7, 10),
        round(hf8, 10),
        round(hf9, 10),
        round(P10, 10),
        round(C_factor, 10)]],
        columns = [
            'point_type',
            'i',
            'H',
            'n',
            'E',
            'nu',
            'Pmax',
            'hf1',
            'hf2',
            'hf3',
            'hf4',
            'hf5',
            'hf6',
            'hf7',
            'hf8',
            'hf9',
            'P10',
            'C'])
    
    return df
コード例 #4
0
  elType = elType,
  abqlauncher = abqlauncher,
  cpus = cpus,
  is_3D = is_3D,
  compart = compart)

# SIMULATION
m.MakeMesh()
if run_sim:
  m.MakeInp()
  m.Run()
  m.PostProc()

# SOME PLOTS
mesh = m.mesh
outputs = load(workdir + label + '.pckl')

if outputs['completed']:
  # Fields
  if export_fields == True :
      def field_func(outputs, step):
        """
        A function that defines the scalar field you want to plot
        """
        return outputs['field']['S'][step].vonmises()
      
      def plot_mesh(ax, mesh, outputs, step, field_func =None, zone = 'upper right', cbar = True, cbar_label = 'Z', cbar_orientation = 'horizontal', disp = True):
        """
        A function that plots the deformed mesh with a given field on it.
        """
        mesh2 = copy.deepcopy(mesh)
コード例 #5
0
from abapy.misc import load
import numpy as np
from matplotlib import pyplot as plt

# In this case, a 3D FEM simulation has beed performed and the results are stored in the file ``ContactData_berk.pckl``.
# See ``Get_ContactData`` to understand how this data has been extracted from an Abaqus odb file.

out = load('ContactData_berk.pckl')
cd0 = out[1][-1]  # First step data: loading
cd1 = out[2][-1]  # Second step data: unloading
hmax = -cd0.min_altitude()

p2, p1, p0 = cd0.contact_contour()
x0, y0 = p0[:, 0], p0[:, 1]
x1, y1 = p1[:, 0], p1[:, 1]
x2, y2 = p2[:, 0], p2[:, 1]

plt.figure()
plt.clf()
plt.title('Contact area contour')
plt.plot(x0, y0, label='upper bound')
plt.plot(x1, y1, label='middle')
plt.plot(x2, y2, label='lower bound')
plt.grid()
plt.legend()
plt.show()
コード例 #6
0
from abapy.misc import load
from matplotlib import pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib import mpl
import numpy as np

path_to_odb = '../../../../testing/'
title0 = 'title0'
title1 = 'title1'
title2 = 'title2'
N_levels = 10  # Number os isovalues
levels = np.linspace(0., 0.3, N_levels)

S = load(path_to_odb + 'indentation_S.pckl')
mesh0 = load(path_to_odb + 'indentation_mesh.pckl')
#mesh0 = mesh0['core_1']
point = (0., 0., 0.)
normal = (1., 0., 0.)
mesh1 = mesh0.apply_reflection(normal=normal, point=point)
S = S[mesh0.nodes.labels.tolist()]
x0, y0, z0, tri0 = mesh0.dump2triplot()
xe0, ye0, ze0 = mesh0.get_edges()
xb0, yb0, zb0 = mesh0.get_border()
xlim0, ylim0, zlim0 = mesh0.nodes.boundingBox()
x1, y1, z1, tri1 = mesh1.dump2triplot()
xe1, ye1, ze1 = mesh1.get_edges()
xb1, yb1, zb1 = mesh1.get_border()
xlim2, ylim1, zlim1 = mesh1.nodes.boundingBox()

field0 = S.get_component(12)  # What to plot ?
field1 = field0  # What other field to plot ?
コード例 #7
0
from abapy.misc import load
import numpy as np
from matplotlib import pyplot as plt


# In this case, a 3D FEM simulation has beed performed and the results are stored in the file ``ContactData_berk.pckl``. See ``Get_ContactData`` to understand how this data has been extracted from an Abaqus odb file.


out = load('ContactData_berk.pckl')
cd0 = out[1][-1] # First step data: loading
cd1 = out[2][-1] # Second step data: unloading
hmax = -cd0.min_altitude()

# First let's map altitude and pressure on cartesian grids.
x = np.linspace(-2., 2., 256)
X, Y = np.meshgrid(x, x)

Alt0, Press0 = cd0.interpolate(X, Y, method ='linear')
Alt1, Press1 = cd1.interpolate(X, Y, method ='linear')
Alt0 = Alt0 / hmax
Alt1 = Alt1 / hmax

# Now we wan to get some sections of the imprint
s = np.linspace(0., 2., 256)
s = np.append((-s)[::-1], s)
theta0 = np.radians(0.01)
theta1 = np.radians(15.)
xs0 = np.cos(theta0) * s 
ys0 = np.sin(theta0) * s
xs1 = np.cos(theta1) * s 
ys1 = np.sin(theta1) * s
コード例 #8
0
# PYTHON POST PROCESSING SCRIPT
# Run using python

# Packages
from abapy.misc import load
import matplotlib.pyplot as plt
import numpy as np

# Setting up some pathes
workdir = 'workdir'
name = 'indentation_axi'

# Getting back raw data
data = load(workdir + '/' + name + '.pckl')

# Post processing
ref_node_label = data['ref_node_label']
force_hist = -data['RF2']['Node I_INDENTER.{0}'.format(ref_node_label)]
disp_hist = -data['U2']['Node I_INDENTER.{0}'.format(ref_node_label)]

# Getting back force  during loading
time, force_l = force_hist[0, 1].plotable()
# Getting backdisplacement during loading
time, disp_l = disp_hist[0, 1].plotable()
# Getting back force  during unloading
time, force_u = force_hist[2].plotable()
# Getting backdisplacement during unloading
time, disp_u = disp_hist[2].plotable()

# Dimensional analysis (E. Buckingham. Physical review, 4, 1914.) shows that the loading curve must be parabolic, let's build a parabolic fit
コード例 #9
0
ファイル: first_example.py プロジェクト: DavidMercier/abapy
# PYTHON POST PROCESSING SCRIPT
# Run using python

# Packages
from abapy.misc import load
import matplotlib.pyplot as plt
import numpy as np

# Setting up some pathes
workdir = 'workdir'
name = 'indentation_axi'

# Getting back raw data
data = load(workdir + '/' + name + '.pckl')

# Post processing
ref_node_label = data['ref_node_label']
force_hist = -data['RF2']['Node I_INDENTER.{0}'.format(ref_node_label)]
disp_hist = -data['U2']['Node I_INDENTER.{0}'.format(ref_node_label)]

time, force_l = force_hist[0,1].plotable() # Getting back force  during loading
time, disp_l = disp_hist[0,1].plotable()   # Getting backdisplacement during loading
time, force_u = force_hist[2].plotable() # Getting back force  during unloading
time, disp_u = disp_hist[2].plotable()   # Getting backdisplacement during unloading

# Dimensional analysis (E. Buckingham. Physical review, 4, 1914.) shows that the loading curve must be parabolic, let's build a parabolic fit 


C_factor = (force_hist[1] / disp_hist[1]**2).average()
disp_fit = np.array(disp_hist[0,1].toArray()[1])
force_fit = C_factor * disp_fit**2
コード例 #10
0
ファイル: fancier_example.py プロジェクト: DavidMercier/abapy
def compute_C(E = 1. , nu = 0.3, sy = 0.01, abqlauncher = '/opt/Abaqus/6.9/Commands/abaqus', workdir = 'workdir', name = 'indentation_axi_fancier', frames = 50):
  '''
  Computes the load prefactor C using Abaqus.
  
  Inputs:
  * E: sample's Young modulus.
  * nu: samples's Poisson's ratio
  * sy: sample's yield stress (von Mises yield criterion).
  * abqlauncher: absolute path to abaqus launcher.
  * wordir: path to working directory, can be relative.
  * name: name of simulation files.
  * frames: number of frames per step, increase if the simulation does not complete.
  
  Returns:
  * Load prefactor C (float)
  '''
  import time, subprocess, os
  t0 = time.time() # Starting time recording
  path = workdir + '/' + name
  # Reading the INP target file
  f = open('indentation_axi_target.inp', 'r')
  inp = f.read()
  f.close()
  # Replace the targets in the file
  inp = inp.replace('#E', '{0}'.format(E))
  inp = inp.replace('#NU', '{0}'.format(nu))
  inp = inp.replace('#SY', '{0}'.format(sy))
  inp = inp.replace('#FRAME', '{0}'.format(1./frames))
  # Creating a new inp file
  f = open(path  + '.inp', 'w')
  f.write(inp)
  f.close()
  print 'Created INP file: {0}.inp'.format(path)
  # Then we run the simulation
  print 'Running simulation in Abaqus'
  p = subprocess.Popen( '{0} job={1} input={1}.inp interactive ask_delete=OFF'.format(abqlauncher, name), cwd = workdir, shell=True, stdout = subprocess.PIPE)
  trash = p.communicate()
  
  # Now we test run the post processing script
  print 'Post processing the simulation in Abaqus/Python'
  p = subprocess.Popen( [abqlauncher,  'viewer', 'noGUI=fancier_example_abq.py'], cwd = '.',stdout = subprocess.PIPE )
  trash = p.communicate()
  # Getting back raw data
  data = load(workdir + '/' + name + '.pckl')
  # Post processing
  print 'Post processing the simulation in Python'
  if data['completed']:
    ref_node_label = data['ref_node_label']
    force_hist = -data['RF2']['Node I_INDENTER.{0}'.format(ref_node_label)]
    disp_hist = -data['U2']['Node I_INDENTER.{0}'.format(ref_node_label)]
    trash, force_l = force_hist[0,1].plotable() # Getting back force  during loading
    trash, disp_l = disp_hist[0,1].plotable()   # Getting backdisplacement during loading
    trash, force_u = force_hist[2].plotable() # Getting back force  during unloading
    trash, disp_u = disp_hist[2].plotable()   # Getting backdisplacement during unloading
    C_factor = (force_hist[1] / disp_hist[1]**2).average()
    
  else:
    print 'Simulation aborted, probably because frame number is to low'
    C_factor = None  
  t1 = time.time()
  print 'Time used: {0:.2e} s'.format(t1-t0)
  return C_factor
コード例 #11
0
ファイル: MakeInp_plot.py プロジェクト: DavidMercier/abapy
from abapy.misc import load
from matplotlib import pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib import mpl
import numpy as np

path_to_odb = '../../../../testing/'
title0 = 'title0'
title1 = 'title1'
title2 = 'title2'
N_levels = 10 # Number os isovalues
levels = np.linspace(0., 0.3, N_levels)

S = load(path_to_odb + 'indentation_S.pckl')
mesh0 = load(path_to_odb + 'indentation_mesh.pckl')
#mesh0 = mesh0['core_1']
point  = (0., 0., 0.)
normal = (1., 0., 0.)
mesh1 = mesh0.apply_reflection(normal = normal, point = point)
S = S[mesh0.nodes.labels.tolist()]
x0, y0, z0, tri0 = mesh0.dump2triplot()
xe0, ye0, ze0 = mesh0.get_edges()
xb0, yb0, zb0 = mesh0.get_border()
xlim0, ylim0, zlim0 = mesh0.nodes.boundingBox()
x1, y1, z1, tri1 = mesh1.dump2triplot()
xe1, ye1, ze1 = mesh1.get_edges()
xb1, yb1, zb1 = mesh1.get_border()
xlim2, ylim1, zlim1 = mesh1.nodes.boundingBox()


field0 = S.get_component(12) # What to plot ?