Skip to content

Commit

Permalink
Merge pull request #225 from kent0/cyl-update
Browse files Browse the repository at this point in the history
Update cylinder example with new run_rom and run_fom scripts
  • Loading branch information
Ping-Hsuan authored Jul 29, 2024
2 parents 0d42807 + 64fa95d commit e99a70d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/cyl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ A unit-diameter cylinder is centered at (0,0) in a box on [-2.5,17] x [-5,5].
With unit inflow velocity at x=-2.5, the Reynolds number is given by Re =
1/viscosity

For the current case, we have Re=100. The drag and lift coefficients are also
computed by calls in userchk. To see the drag vs. time:

grep drag logfile
Run (with NekROM/bin and Nek5000/bin in $PATH and $MOR_DIR set to NekROM) `./run_fom` to generate the FOM fields and drag/lift data.

## ROM: Flow past a cylinder in 2D

To obtain the ROM solution, run

```
mkdir snaps && cp cyl0.f* snaps && ls snaps/*0.f* > file.list
makerom cyl_rom
nekbmpi cyl 1
```

```
grep dragx logfile | sed 's/dragx//g' > rom.dragx.dat
grep dragy logfile | sed 's/dragy//g' > rom.dragy.dat
```

The usr file for the ROM, cyl_rom.usr, mimics the FOM user file. In particular the rom_userchk subroutine is only a slight modification of the FOM userchk subroutine to accomodate variable name conflicts.

To see the drag vs. time:
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/cyl/cyl_rom.usr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ c-----------------------------------------------------------------------
include 'TOTAL'
include 'MOR'

param(170) = -1
nsteps = 25 * 1e3 ! reduce to 100 CTUs

call rom_update

call exitt0
Expand Down Expand Up @@ -198,6 +201,11 @@ c-----------------------------------------------------------------------
include 'TOTAL'
include 'MOR'

if (ad_step.eq.0) then
isnap = 100 ! restart from 401 CTU snapshot
call copy(u,uk(1+(isnap-1)*(nb+1)),nb+1)
endif

return
end
c-----------------------------------------------------------------------
Expand Down
28 changes: 28 additions & 0 deletions examples/cyl/post.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
% read fom and rom data
fx=dlmread('fom.dragx.dat');
fy=dlmread('fom.dragy.dat');
rx=dlmread('rom.dragx.dat');
ry=dlmread('rom.dragy.dat');

% plot fom result:

tstart=401;
tend=500;

figure;
plot(fx(:,2),fx(:,3)); xlim([tstart tend]);
title('Drag result');
xlabel('Time');
ylabel('Drag');

% plot rom result:
%figure;
hold on
rx(:,1)=rx(:,1)+tstart; % restart from t=400
%plot(rx(:,1),rx(:,4)); xlim([400 500]);
plot(rx(:,1),rx(:,4),'--');
legend('FOM','ROM');
%title('ROM drag result');
xlabel('Time');
ylabel('Drag');

21 changes: 21 additions & 0 deletions examples/cyl/run_fom
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

np=8 # number of processors to use for FOM calculation
makerom cyl_fom # `makerom` can be replaced with `makenek`

# generate mesh connectivity information
genmap << EOF
cyl
0.1
EOF

echo 'running Nek5000 FOM calculation...'
neklmpi cyl $np
logfile=cyl.log.$np
mkdir snaps && mv *cyl0.f* $logfile snaps && ls -r snaps/cyl0.f* > file.list

# For the current case, we have Re=100. The drag and lift coefficients are also computed by calls in userchk. The following lines extract the data to .dat files
grep dragx snaps/$logfile | sed 's/1dragx//g' > fom.dragx.dat
grep dragy snaps/$logfile | sed 's/1dragy//g' > fom.dragy.dat

echo 'done with FOM, exiting...'
11 changes: 11 additions & 0 deletions examples/cyl/run_rom
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

makerom cyl_rom
neklmpi cyl 1

logfile=cyl.log.1

# The detail computation of drag in the ROM is in Kento Kaneko An Augmented Basis Method for Reduced Order Models of Turbulent Flow. Ph.D. thesis (2022).
grep dragx $logfile | sed 's/dragx//' > rom.dragx.dat
grep dragy $logfile | sed 's/dragy//' > rom.dragy.dat

0 comments on commit e99a70d

Please sign in to comment.