idaholab / moose

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

Add way for AdvancedExtruderGenerator (and other ExtruderGenerators) to report extrusion layering scheme #27985

Open lewisgross1296 opened 1 week ago

lewisgross1296 commented 1 week ago

Motivation

I'm currently experimenting with non-uniform z-layering in my mesh, and I want to be able to make plots of my VPPs as a function of z. Here's an example of my z-layering scheme using the AdvancedExtruderGenerator

  [extrude]
    type = AdvancedExtruderGenerator
    input = 'bundle'
    heights    = '0.1 0.1 0.1 1.4 0.1 0.1 0.1'
    num_layers = '3    6    6     36 6     6    3'
    direction = '0 0 1'
    subdomain_swaps = '1 6 2 6;
                       1 6 2 6;
                      ;
                      ;
                      ;
                      1 6 2 6; 
                      1 6 2 6'
  []

I'm currently trying to use an AuxVariable + ParsedAux to compute the z of each element with an ElementValueSampler VPP to generate a CSV of z-heights, but it's kind of clunky -- and requiring me to do more post processing to delete the duplicates from each element.

It would be nice to have a way to take the information from the mesh generator and generate a layering scheme (in my case in the z-direction), but it could be arbitrary for the direction parameter for the x,y, and z unit vectors.

Design

Here's the python code I wrote to do this, which accepts heights and num_layers (just as is used in AdvancedExtruderGenerator)

def compute_mesh_z_positions(layers, heights, z_min = 0):
    try:
        len(layers) == len(heights)
    except ValueError:
        print(f"The length of layers ({len(layers)}) and heights ({len(heights)}) must be the same")

    z_bounds = [z_min]
    for layer,height in zip(layers,heights):
        for i in range(layer):
            z_bounds.append(z_bounds[-1] + height)

    z_centers = [0.5*(z_bounds[i+1]+z_bounds[i]) for i in range(len(z_bounds)-1)]

    return z_bounds, z_centers

Impact

While I'm pretty sure my python code works, it would be great from a QC standpoint to have MOOSE output the z corresponding to each VPP value in a way that doesn't require removing duplicates (like w ElementValueSampler)

lewisgross1296 commented 1 week ago

Oh a note about my python code. I define my heights a little differently than the AdvancedExtruderGenerator, but converting between them isn't too bad.

E.g., where I specify (0.1, 3) for the first (height, num_layers) pair in my list of heights and layers in the mesh generation script, the python would actually want (0.1/3, 3)