Author Topic: how to use maximum shear strain in SelectExpressionModifier  (Read 1671 times)

giocj

  • Newbie
  • *
  • Posts: 3
Dear all,

I have calculated shear strain using atomic strain modifier in Python script.
Now I want to use Select Expression Modifier to do some more analysis by using the maximum shear strain value. 

Is there any way to find the maximum value and use it in the script?

Here is what I want to do.

modifer = SelectExpressionModifer( expression = 'ShearStrain > x*Maximum Shear Strain')

Thank you in advance.
 

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Re: how to use maximum shear strain in SelectExpressionModifier
« Reply #1 on: May 27, 2017, 03:47:25 PM »
Hi,

You can insert a PythonScriptModifier into the data pipeline in between the shear strain calculation and your SelectExpressionModifier. The Python function determines maximum value of the atomic shear strain property and stores it as a global attribute that is injected into the pipeline. This attribute can then be referenced by the SelectExpressionModifier down the pipeline.

Code: [Select]
import numpy as np

...

def determine_max_strain(time, input, output):
    output.attributes['MaxShearStrain'] = np.max(input.particle_attributes['Shear Strain'].array)

node.modifiers.append(PythonScriptModifier(function = determine_max_strain))

...

giocj

  • Newbie
  • *
  • Posts: 3
Re: how to use maximum shear strain in SelectExpressionModifier
« Reply #2 on: May 27, 2017, 09:11:12 PM »
Thank you for your response.

I have added the code right after my shear calculation. So, my code looks like this:

...
atomic strain modifier
export file for shear calculation.

def determine_max_strain(time, input, output):
    output.attributes['MaxShearStrain'] = np.max(input.particle_attributes['Shear Strain'].array)

node.modifiers.append(PythonScriptModifier(function = determine_max_strain))

modifier = SelectExpressionModifier( expression = 'ShearStrain > MaxShearStrain*0.1' )
node.modifiers.append(modifier)
node.modifiers.append(InvertSelectionModifier())
node.modifiers.append(DeleteSelectedParticlesModifier())
output = node.compute()
export_file(node, "file.dat", "lammps_data", atom_style = "atomic")


When I run this code, it is working right before the line that starts to append the modifier. I mean the code is exited with errors when I added the line "node.modifiers.append(modifier)".
I do not know why this code has an error because I have used this pattern of the code without errors so far.

I would appreciate if you can help me out on this problem.

Thank you so much.

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Re: how to use maximum shear strain in SelectExpressionModifier
« Reply #3 on: May 28, 2017, 03:39:45 PM »
Excuse me, I am on a holiday trip right now and couldn't test the code I posted. After taking a second look, I spotted at least one mistake:

...np.max(input.particle_attributes['Shear Strain'].array)

This should be "input.particle_properties", not particle_attributes.


giocj

  • Newbie
  • *
  • Posts: 3
Re: how to use maximum shear strain in SelectExpressionModifier
« Reply #4 on: May 29, 2017, 03:21:29 PM »
It is working now.
Thank you so much!!