From 2137bb38fcba7b2e6fe0ce9fa08f1d11d3d2149e Mon Sep 17 00:00:00 2001 From: Kento Kaneko Date: Fri, 19 Jul 2024 13:58:00 -0400 Subject: [PATCH 1/2] updated files --- examples/cyl/README.md | 18 ++++++++++++++---- examples/cyl/{cyl.usr => cyl_fom.usr} | 0 examples/cyl/cyl_rom.usr | 10 ++++++++++ examples/cyl/post.m | 20 ++++++++++++++++++++ examples/cyl/run_fom | 21 +++++++++++++++++++++ examples/cyl/run_rom | 11 +++++++++++ 6 files changed, 76 insertions(+), 4 deletions(-) rename examples/cyl/{cyl.usr => cyl_fom.usr} (100%) create mode 100644 examples/cyl/post.m create mode 100755 examples/cyl/run_fom create mode 100755 examples/cyl/run_rom diff --git a/examples/cyl/README.md b/examples/cyl/README.md index eaedd5be..5a5b1b3d 100644 --- a/examples/cyl/README.md +++ b/examples/cyl/README.md @@ -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: diff --git a/examples/cyl/cyl.usr b/examples/cyl/cyl_fom.usr similarity index 100% rename from examples/cyl/cyl.usr rename to examples/cyl/cyl_fom.usr diff --git a/examples/cyl/cyl_rom.usr b/examples/cyl/cyl_rom.usr index e53fb2d5..8c4c382d 100644 --- a/examples/cyl/cyl_rom.usr +++ b/examples/cyl/cyl_rom.usr @@ -52,6 +52,8 @@ c----------------------------------------------------------------------- include 'TOTAL' include 'MOR' + param(170) = -1 + call rom_update call exitt0 @@ -198,6 +200,14 @@ c----------------------------------------------------------------------- include 'TOTAL' include 'MOR' + if (ad_step.eq.0) then + call copy(u,uk,nb+1) +c call rzero(u,nb+1) +c if (nid.eq.0) call copy(u,uk,nb+1) + +c call gop(u,ut,'+ ',nb+1) + endif + return end c----------------------------------------------------------------------- diff --git a/examples/cyl/post.m b/examples/cyl/post.m new file mode 100644 index 00000000..64c60cc5 --- /dev/null +++ b/examples/cyl/post.m @@ -0,0 +1,20 @@ +% 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: +figure; +plot(fx(:,2),fx(:,3)); xlim([400 500]); +title('FOM drag result'); +xlabel('Time'); +ylabel('Drag'); + +% plot rom result: +figure; +plot(rx(:,1),rx(:,4)); xlim([400 500]); +title('ROM drag result'); +xlabel('Time'); +ylabel('Drag'); + diff --git a/examples/cyl/run_fom b/examples/cyl/run_fom new file mode 100755 index 00000000..fb3044ef --- /dev/null +++ b/examples/cyl/run_fom @@ -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...' diff --git a/examples/cyl/run_rom b/examples/cyl/run_rom new file mode 100755 index 00000000..3ee5fcd9 --- /dev/null +++ b/examples/cyl/run_rom @@ -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 + From 64fa95d9990c4a037e2d3c2e6f59e805a2e4573d Mon Sep 17 00:00:00 2001 From: Kento Kaneko Date: Thu, 25 Jul 2024 12:01:39 -0400 Subject: [PATCH 2/2] updated restart and post-processing to show reconstructed drag --- examples/cyl/cyl_rom.usr | 8 +++----- examples/cyl/post.m | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/cyl/cyl_rom.usr b/examples/cyl/cyl_rom.usr index 8c4c382d..f9f01ec4 100644 --- a/examples/cyl/cyl_rom.usr +++ b/examples/cyl/cyl_rom.usr @@ -53,6 +53,7 @@ c----------------------------------------------------------------------- include 'MOR' param(170) = -1 + nsteps = 25 * 1e3 ! reduce to 100 CTUs call rom_update @@ -201,11 +202,8 @@ c----------------------------------------------------------------------- include 'MOR' if (ad_step.eq.0) then - call copy(u,uk,nb+1) -c call rzero(u,nb+1) -c if (nid.eq.0) call copy(u,uk,nb+1) - -c call gop(u,ut,'+ ',nb+1) + isnap = 100 ! restart from 401 CTU snapshot + call copy(u,uk(1+(isnap-1)*(nb+1)),nb+1) endif return diff --git a/examples/cyl/post.m b/examples/cyl/post.m index 64c60cc5..a14de17e 100644 --- a/examples/cyl/post.m +++ b/examples/cyl/post.m @@ -5,16 +5,24 @@ ry=dlmread('rom.dragy.dat'); % plot fom result: + +tstart=401; +tend=500; + figure; -plot(fx(:,2),fx(:,3)); xlim([400 500]); -title('FOM drag result'); +plot(fx(:,2),fx(:,3)); xlim([tstart tend]); +title('Drag result'); xlabel('Time'); ylabel('Drag'); % plot rom result: -figure; -plot(rx(:,1),rx(:,4)); xlim([400 500]); -title('ROM drag 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');