idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.75k stars 1.05k forks source link

SamplerData VPP doesn't return samples using FINAL option #14044

Closed somu15 closed 2 years ago

somu15 commented 5 years ago

BUG DESCRIPTION

SamplerData vector postprocessor doesn't seem to return the samples drawn for a Monte Carlo simulation (SamplerTransientMultiApp) when using the FINAL option. I'm trying to run an analysis by randomizing a few material parameters.

However, when I use the INITIAL option for SamplerData, the drawn samples of the material params are returned (although at every time step).

STEPS TO REPRODUCE

To demonstrate the issue, let's consider a Timoshenko beam problem with one end fixed and subjected to a point load at the other end. The Young's modulus of the beam is randomized.

sub_Timoshenko.i (which needs to be executed) defines the distribution for Young's modulus, sets the number of samples (3 presently considered), sets up the MonteCarlo sampler using the SamplerTransientMultiApp. Note that sub_Timoshenko.i works with a dummy mesh. This input file is presented below:

[Mesh]
  type = GeneratedMesh
  dim = 1
  nx = 10
  xmin = 0.0
  xmax = 4.0
  displacements = 'disp_x disp_y disp_z'
[]

[Variables]
  [./disp_x]
  [../]
  [./disp_y]
  [../]
  [./disp_z]
  [../]
  [./rot_x]
  [../]
  [./rot_y]
  [../]
  [./rot_z]
  [../]
[]

[Problem]
  solve = false
  kernel_coverage_check = false
[]

[Distributions]
 [./uniform_E1]
   type = UniformDistribution
   lower_bound = 1e04
   upper_bound = 8e04
 [../]
[]

[Samplers]
  [./sample]
    type = MonteCarloSampler
    n_samples = 3
    distributions = 'uniform_E1'
    execute_on = INITIAL # create random numbers on initial and use them for each timestep
  [../]
[]

[MultiApps]
  [./sub]
    # creates sub files for each monte carlo sample and each scaled ground motion
    # Total number of simulations = number_of_bins * num_gms * n_samples
    type = SamplerTransientMultiApp
    input_files = 'sub_sub_Timoshenko.i'
    sampler = sample
    execute_on = TIMESTEP_BEGIN
  [../]
[]

[Transfers]
  [./sub]
    # transfers monte carlo samples to multiapp
    type = SamplerTransfer
    multi_app = sub
    parameters = 'AuxKernels/youngs_modulus1/value'
    to_control = 'stochastic'
    execute_on = INITIAL
    check_multiapp_execute_on = false
  [../]
[]

[Functions]
  [./force]
    type = ConstantFunction
    value = 0.01
  [../]
[]

[Executioner]
  type = Transient
  solve_type = 'PJFNK'
  petsc_options = '-snes_ksp_ew'
  petsc_options_iname = '-ksp_gmres_restart -pc_type -pc_hypre_type -pc_hypre_boomeramg_max_iter'
  petsc_options_value = '201                hypre    boomeramg      4'
  end_time = 0.3
  dt = 0.1
  dtmin = 0.01
  nl_abs_tol = 1e-3
    nl_rel_tol = 1e-03
  l_tol = 1e-3
  l_max_its = 20
  timestep_tolerance = 1e-3
[]

[VectorPostprocessors]
  [./data]
    type = SamplerData
    sampler = sample
    execute_on = 'INITIAL'
  [../]
[]

[Outputs]
  csv = true
[]

sub_sub_Timoshenko.i creates the required mesh and assigns material params etc. This input file is presented below. Note that the previous code depends on the below code:

[Mesh]
  type = GeneratedMesh
  dim = 1
  nx = 10
  xmin = 0.0
  xmax = 4.0
  displacements = 'disp_x disp_y disp_z'
[]

[AuxVariables]
  [./youngs_modulus1]
    order = CONSTANT
    family = MONOMIAL
  [../]
[]

[BCs]
  [./fixx1]
    type = DirichletBC
    variable = disp_x
    boundary = left
    value = 0.0
  [../]
  [./fixy1]
    type = DirichletBC
    variable = disp_y
    boundary = left
    value = 0.0
  [../]
  [./fixz1]
    type = DirichletBC
    variable = disp_z
    boundary = left
    value = 0.0
  [../]
  [./fixr1]
    type = DirichletBC
    variable = rot_x
    boundary = left
    value = 0.0
  [../]
  [./fixr2]
    type = DirichletBC
    variable = rot_y
    boundary = left
    value = 0.0
  [../]
  [./fixr3]
    type = DirichletBC
    variable = rot_z
    boundary = left
    value = 0.0
  [../]
[]

[NodalKernels]
  [./force_y2]
    type = UserForcingFunctionNodalKernel
    variable = disp_y
    boundary = right
    function = force
  [../]
[]

[AuxKernels]
  [./accel_x]
    type = NewmarkAccelAux
    variable = accel_x
    displacement = disp_x
    velocity = vel_x
    beta = 0.25
    execute_on = 'timestep_end'
  [../]
  [./vel_x]
    type = NewmarkVelAux
    variable = vel_x
    acceleration = accel_x
    gamma = 0.5
    execute_on = 'timestep_end'
  [../]
  [./accel_y]
    type = NewmarkAccelAux
    variable = accel_y
    displacement = disp_y
    velocity = vel_y
    beta = 0.25
    execute_on = 'timestep_end'
  [../]
  [./vel_y]
    type = NewmarkVelAux
    variable = vel_y
    acceleration = accel_y
    gamma = 0.5
    execute_on = 'timestep_end'
  [../]
  [./accel_z]
    type = NewmarkAccelAux
    variable = accel_z
    displacement = disp_z
    velocity = vel_z
    beta = 0.25
    execute_on = 'timestep_end'
  [../]
  [./vel_z]
    type = NewmarkVelAux
    variable = vel_z
    acceleration = accel_z
    gamma = 0.5
    execute_on = 'timestep_end'
  [../]
  [./youngs_modulus1]
    type = ConstantAux
    variable = youngs_modulus1
    value = 1e04
  [../]
[]

[Functions]
  # [./force]
  #   type = PiecewiseLinear
  #   x = '0.0 0.1 0.2 10.0'
  #   y = '0.0 1e-2  0.0  0.0'
  # [../]
  [./force]
    type = ConstantFunction
    value = 0.01
  [../]
  # [./accel_x]
  #   type = PiecewiseLinear
  #   data_file = 'GM_00.csv'
  #   format = columns
  #   scale_factor = 1.0
  #   xy_in_file_only = false
  # [../]
[]

[Preconditioning]
  [./smp]
    type = SMP
    full = true
  [../]
[]

[Executioner]
  type = Transient
  solve_type = 'PJFNK'
  petsc_options = '-snes_ksp_ew'
  petsc_options_iname = '-ksp_gmres_restart -pc_type -pc_hypre_type -pc_hypre_boomeramg_max_iter'
  petsc_options_value = '201                hypre    boomeramg      4'
  end_time = 0.3
  dt = 0.1
  dtmin = 0.01
  nl_abs_tol = 1e-3
    nl_rel_tol = 1e-03
  l_tol = 1e-3
  l_max_its = 20
  timestep_tolerance = 1e-3
[]

[Modules/TensorMechanics/LineElementMaster]
  [./all]
    add_variables = true
    displacements = 'disp_x disp_y disp_z'
    rotations = 'rot_x rot_y rot_z'

    # Geometry parameters
    area = 0.01
    Iy = 1e-4
    Iz = 1e-4
    y_orientation = '0.0 1.0 0.0'

    # dynamic simulation using consistent mass/inertia matrix
    dynamic_nodal_translational_inertia = true
    nodal_mass = 18.99772

    dynamic_nodal_rotational_inertia = true
    nodal_Ixx = 2e-1
    nodal_Iyy = 1e-1
    nodal_Izz = 1e-1

    velocities = 'vel_x vel_y vel_z'
    accelerations = 'accel_x accel_y accel_z'
    rotational_velocities = 'rot_vel_x rot_vel_y rot_vel_z'
    rotational_accelerations = 'rot_accel_x rot_accel_y rot_accel_z'

    beta = 0.25 # Newmark time integration parameter
    gamma = 0.5 # Newmark time integration parameter

    boundary = right # Node set where nodal mass and nodal inertia are applied

    # parameters for 5% Rayleigh damping
    zeta = 0.0005438894818 # stiffness proportional damping
    eta = 3.26645357034 # Mass proportional Rayleigh damping
  [../]
[]

[Materials]
  [./elasticity]
    type = ComputeElasticityBeam
    youngs_modulus = youngs_modulus1
    poissons_ratio = -0.999875
    shear_coefficient = 1.0
    block = 0
  [../]
  [./stress]
    type = ComputeBeamResultants
    block = 0
  [../]
[]

[Controls]
  [./stochastic]
    type = SamplerReceiver
  [../]
[]

[Postprocessors]
  [./disp_x]
    type = PointValue
    point = '4.0 0.0 0.0'
    variable = disp_x
  [../]
  [./disp_y]
    type = PointValue
    point = '4.0 0.0 0.0'
    variable = disp_y
  [../]
  [./vel_y]
    type = PointValue
    point = '4.0 0.0 0.0'
    variable = vel_y
  [../]
  [./accel_y]
    type = PointValue
    point = '4.0 0.0 0.0'
    variable = accel_y
  [../]
[]

[Outputs]
  file_base = 'dyn_euler_small_added_mass_inertia_damping_out'
  exodus = true
  csv = true

  perf_graph = true
[]

The VectorPostprocessors block in sub_Timoshenko.i is the one that should return the sampled values.

IMPACT

The values of the sampled material params are required to conduct analysis of the beam response data. While the INITIAL option does return the sampled values, it does so at every time step. For example, if I have 1000 time steps, I will end up with 1000 output files containing the same sampled values (my material params don't vary with time). This is why the FINAL option in SamplerData VPP is convenient as it's supposed to return the sampled values only once.

@somu15 - Please don't delete the issue template. That could result in an audit finding for our NQA-1 compliance. Also, this ticket doesn't provide enough information to reproduce the result. What kind of Monte Carlo simulation? Are you talking about a multiapp? Please correct these deficiencies.

permcody commented 5 years ago

@somu15 - Awesome!

somu15 commented 4 years ago

@aeslaughter This solution you suggested works! I can close this issue if that's okay.

GiudGiud commented 2 years ago

Someone should document Andrew's solution here