Tutorial example demonstrating how to use StabFem for a time-stepping calculation (BASIC)
This tutorial script is designed as a support for chapter 4 of the StabFem manual available here
We show how to compute the solution of a time-dependant through time-stepping and how to import, plot, and organise the results in a database.
This example is based on the "Thermal Conduction" example in the FreeFem manual. The mesh generator is Mesh_ThermalConduction.edp and the freefem solver is TimeStepper_ThermalConduction.edp
In this example the database management is disabled so that the steps of the computation can be followed easily. On the other hand in this mode only one computation can be launched, if you launch a new on the previous results will not be kept.
After studying this example it is recommended to go to the next example SCRIPT_ThermalConduction_Advanced.m which shows how to manage several simulations using the database.
Contents
Initialization
close all; addpath('../../SOURCES_MATLAB'); SF_Start('verbosity',4); SF_DataBase('disable'); % this is to disable the database management for this simple tutorial.
NOTICE - Initialization already done WARNING - Detected verbosity = 4 in Publish mode ; not recommended ! switching to 2 instead WARNING - Disabling database management. Some advanced functionalities may not work properly
Chapter 1 : creating mesh
As usual, a mesh is created by calling a FreeFem++ mesh-creator program.
ffmesh = SF_Mesh('Mesh_ThermalConduction.edp');
Plot this mesh
figure; SF_Plot(ffmesh);
Chapter 2 : Launching a simple time-stepping simulation
This is done in two steps : a/ launching the code
Run1 = SF_TS_Launch('TimeStepper_ThermalConduction.edp','Mesh',ffmesh,'Options',{'Niter',100,'alpha',.1});
WARNING - DataBase management disabled ; some advanced functionalities may not work WARNING - MoveDataFile : DID NOT FIND auxiliary file ./mesh.ff2m
Before importing the results let's check the content of the working directory to see the files created:
ls
autorun.m Snapshot_00000040.ff2m freefem++.pref Snapshot_00000040.txt freefemwarning.txt Snapshot_00000050.ff2m html Snapshot_00000050.txt LaunchSingleComputation_Example.bash Snapshot_00000060.ff2m mesh.msh Snapshot_00000060.txt Mesh_ThermalConduction.edp Snapshot_00000070.ff2m SCRIPT_ThermalConduction_Advanced.m Snapshot_00000070.txt SCRIPT_ThermalConduction_Basic.m Snapshot_00000080.ff2m SCRIPT_ThermalConduction_ForManual.m Snapshot_00000080.txt SF_AutoInclude.idp Snapshot_00000090.ff2m SF_Custom.idp Snapshot_00000090.txt SF_Geom.edp Snapshot_00000100.ff2m Simulation.log Snapshot_00000100.txt Snapshot_00000010.ff2m TimeStats.ff2m Snapshot_00000010.txt TimeStats.txt Snapshot_00000020.ff2m TimeStepper_ThermalConduction.edp Snapshot_00000020.txt TimeStepper_ThermalConduction_short.edp Snapshot_00000030.ff2m TS.status Snapshot_00000030.txt WORK
Note that the FreeFem++ solver will create a series of files 'Snapshot_#######.txt / .ff2m' corresponding to the snapshots plus a couple of file 'TimeStats.txt/.ff2m' corresponding to time-statistics.
Note that in the no-database mode, all output files are written in working directory './'
b/ Checking the contents
[stats,snapshots] = SF_TS_Check(Run1)
################################################################################# .... CONTENT OF ./ : Simulation completed Time-stepping simulation started 23-Mar-2023 12:15:25 Solver : TimeStepper_ThermalConduction.edp Mesh file name : ./mesh.msh Initial condition file name : Argument string : -Niter 100 -alpha 0.1 -> Found time series spaning from iter = 1 to 100 ; time = 0.1 to 10 -> Found 10 Snapshots in this folder. Importing them.... Simulation completed stats = struct with fields: filename: './TimeStats.txt' DataDescription: 'Time-series of a Thermal insteady problem ' datatype: 'TimeStatistics' datastoragemode: 'columns' datadescriptors: 't,u3,u6,iter' t: [100x1 double] u3: [100x1 double] u6: [100x1 double] iter: [100x1 double] status: 'completed' snapshots = 1x10 struct array with fields: mesh filename DataDescription datatype datastoragemode datadescriptors meshfilename alpha INDEXING t it T status
The results are imported as object which can be used simply for plotting and postprocessing.
Plotting a few snapshots;
figure; subplot(3,1,1); SF_Plot(snapshots(1),'T','title','Field at t=1','contour','on'); subplot(3,1,2); SF_Plot(snapshots(2),'T','title','Field at t=2','contour','on'); subplot(3,1,3); SF_Plot(snapshots(4),'T','title','Field at t=4','contour','on');
WARNING - FUNCTION SFcore_ImportMesh.m : DO NOT FIND COMPLEMENTARY FILE ././mesh.ff2m WARNING - Launching "Generate_Aux_Files_for_Mesh.edp" to generate it WARNING - MoveDataFile : DID NOT FIND auxiliary file ./././mesh.ff2m
Plotting time-series of T(0.5,3)
figure; plot(stats.t,stats.u3);xlabel('t');ylabel('T(3,.5)');
[[PUBLISH]] -> this tag is here to tell gitlab to automatically generate a web page from this script
% fclose(fopen('SCRIPT_ThermalConduction_Basic.success','w+'));