Script example of extrusion/interpolation of 2D solution to 3D

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Script example of extrusion/interpolation of 2D solution to 3D

Precise Simulation
Administrator
FEATool Multiphysics script example for extruding/interpolating a 2D solution to a 3D domain.

featool 2d to 3d solution extrusion

Note! This will only work as is for 1st order/linear shape functions. For higher order shape functions interpolation order is more complicated due to degrees of freedom corresponding to cell center and edge mid points.

% Define and solve Poisson problem on 2x1 2D rectangle.
fea.sdim = {'x', 'y'};
fea.geom.objects = {gobj_rectangle(0, 2, 0, 1)};
fea.grid = gridgen(fea ,' hmax', 0.1);
fea = addphys(fea, @poisson);
fea = parsephys(fea);
fea = parseprob(fea);
fea.sol.u = solvestat(fea);
postplot(fea, 'surfexpr', 'u')


% Option 1. Direct extrusion of 2D mesh to 3D.

% Define 3D data struct and extrude 2D mesh.
fea2.sdim = {'x', 'y', 'z'};
n_layers = 5;
len = 0.5;
iaxis = 3;   % z-axis
fea2.grid = gridextrude(fea.grid, n_layers, len, iaxis);
figure
subplot(3,1,1)
plotgrid(fea2)

% Create "mock" 3D solution variable, and repeat 2D solution n+1 layers.
fea2 = addphys(fea2, @poisson, 'u_extruded');
fea2.phys.poi.prop.active = 0;   % Deactivate physics mode (will not be solved for).
fea2 = parsephys(fea2);
fea2 = parseprob(fea2);

% Assign repeated solution vector.
fea2.sol.u = repmat(fea.sol.u, n_layers+1, 1);

% Plot 3D extruded solution.
subplot(3,1,2)
postplot(fea2, 'sliceexpr', 'u_extruded')
title('u\_extruded')
subplot(3,1,3)
postplot(fea2, 'sliceexpr', 'u_extrudedx')
title('x-derivative')


% Option 2. Interpolate 2D solution to arbitrary 3D mesh.

% Create 3D geometry and mesh.
fea3.sdim = {'x', 'y', 'z'};
fea3.geom.objects = {gobj_block(0, 2, 0, 1, 0, 0.5)};
fea3.grid = gridgen(fea3, 'hmax', 0.1, 'dprim', false);
figure
subplot(3,1,1)
plotgrid(fea3)

fea3 = addphys(fea3, @poisson, 'u_interpolated');
fea3.phys.poi.prop.active = 0;   % Deactivate physics mode (will not be solved for).
fea3 = parsephys(fea3);
fea3 = parseprob(fea3);

p_interpolate = fea3.grid.p(1:2,:);
fea3.sol.u = evalexpr('u', p_interpolate, fea);

% Plot 3D interpolated solution.
subplot(3,1,2)
postplot(fea3, 'sliceexpr', 'u_interpolated')
title('u\_interpolated')
subplot(3,1,3)
postplot(fea3, 'sliceexpr', 'u_interpolatedx')
title('x-derivative')

https://gist.github.com/precise-simulation/a1dbcdfedca35b2870026d67a1969748