Skip to content

Commit a1137b5

Browse files
committed
Code keeps filling up my computer! I've implemented a compressed binary output transiant output
Added a new input flag _CompressedOutput to param.in to enable binary 'stream' output in mod_output.f90. Also added a USER_MANUAL.md to docs/.
1 parent 2799327 commit a1137b5

4 files changed

Lines changed: 186 additions & 22 deletions

File tree

docs/USER_MANUAL.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# HeatFlow User Manual
2+
3+
This manual provides a concise guide to configuring and running simulations using the **HeatFlow** software. The software simulates heat transport using finite difference methods, primarily focusing on the Cattaneo (hyperbolic heat equation) and Fourier models.
4+
5+
## Input Files
6+
7+
The simulation is controlled by three main input files located in the `inputs/` directory:
8+
1. **`param.in`**: Simulation parameters (time steps, flags, boundary conditions).
9+
2. **`mat.in`**: Material properties.
10+
3. **`system.in`**: Geometry and grid definition.
11+
12+
### 1. `param.in` (Simulation Parameters)
13+
14+
This file uses a `KEYWORD = VALUE` format. Comments can be added using `!`.
15+
16+
#### General Settings
17+
| Keyword | Type | Default | Description |
18+
| :--- | :--- | :--- | :--- |
19+
| `_RunName` | String | `default` | Name of the simulation run. |
20+
| `IVERB` | Integer | `1` | Verbosity level (higher = more output). |
21+
| `ntime` | Integer | `10` | Total number of time steps. |
22+
| `time_step` | Double | `1.0` | Time step size. |
23+
| `freq` | Double | `1.0` | Frequency of the heater. |
24+
| `icattaneo` | Integer | `1` | Switch for Cattaneo term (`1` = On, `0` = Off/Fourier). |
25+
| `isteady` | Integer | `0` | Steady state switch (`1` = Steady state, `0` = Transient). |
26+
| `heattime` | Integer | `0` | Number of steps for which heating is applied (case 2). |
27+
| `TempDepProp`| Integer | `0` | Flag for temperature dependent properties. |
28+
29+
#### Boundary & Conditions
30+
| Keyword | Type | Default | Description |
31+
| :--- | :--- | :--- | :--- |
32+
| `iboundary` | Integer | `1` | Boundary condition type. |
33+
| `Periodic` | String | `''` | Periodic boundaries. Contains 'x', 'y', or 'z' (e.g., `'xy'`). |
34+
| `kappaBound` | Double | `0.0` | Global boundary thermal conductivity (sets all planes). |
35+
| `kappaBoundx1`...`z2` | Double | `0.0` | Specific boundary conductivity (e.g., `kappaBoundx1` for x=1 plane). |
36+
| `T_System` | Double | `300.0` | Initial system temperature. |
37+
| `T_Bath` | Double | - | Global bath temperature (sets all boundaries boundaries). |
38+
| `T_Bathx1`...`z2` | Double | `T_Bath` | Specific boundary temperatures. |
39+
| `T_BathCG` | Double | `0.0` | Constant gradient bath temperature. |
40+
| `CG_dir` | String | `' '` | Direction for constant gradient (e.g., `'+x'`, `'-y'`). |
41+
| `T_BathCC` | Logical| `F` | Scale constant gradient with DeltaT. |
42+
| `BR` | Double | `1.0` | Bath Ratio (scaling factor). |
43+
44+
#### Power
45+
| Keyword | Type | Default | Description |
46+
| :--- | :--- | :--- | :--- |
47+
| `power_in` | Double | `0.0` | Power input for the heater. |
48+
49+
#### Flags (Logical)
50+
All flags default to `.False.`. Set to `.True.` (or `T`) to enable.
51+
- `_Check_Sparse_Full`: Check if simulation is sparse or full.
52+
- `_Check_Stability`: Perform stability check.
53+
- `_Check_Steady_State`: Check for steady state convergence.
54+
- `_WriteToTxt`: Enable writing output to text files.
55+
- `_Percentage_Completion`: Show progress % in output.
56+
- `_Test_Run`: Flag for test runs.
57+
- `_InputTempDis`: Load initial temperature distribution from file.
58+
- `_FullRestart`: Perform a full restart.
59+
60+
#### Output Control
61+
Defines the region of the grid to write to output.
62+
| Keyword | Type | Default | Description |
63+
| :--- | :--- | :--- | :--- |
64+
| `write_every` | Integer | `1` | Write output every N steps. |
65+
| `start_ix`, `end_ix` | Integer | `1`..`Nx` | X-range for output. |
66+
| `start_iy`, `end_iy` | Integer | `1`..`Ny` | Y-range for output. |
67+
| `start_iz`, `end_iz` | Integer | `1`..`Nz` | Z-range for output. |
68+
69+
---
70+
71+
### 2. `mat.in` (Material Properties)
72+
73+
Defines the physical properties for each material index used in the system. The file ends with a line containing `0`.
74+
75+
**Format:**
76+
```
77+
<Material_Index>
78+
keyword = value
79+
...
80+
0
81+
```
82+
83+
| Keyword | Description |
84+
| :--- | :--- |
85+
| `heat_capacity` | Specific heat capacity. |
86+
| `kappa` | Thermal conductivity. |
87+
| `rho` | Density. |
88+
| `tau` | Relaxation time (for Cattaneo). |
89+
| `em` | Emissivity / Parameter (usage depends on physics context). |
90+
| `vel` | Velocity vector (3 components, e.g., `vel = 1.0 0.0 0.0`). |
91+
92+
**Example:**
93+
```
94+
1
95+
heat_capacity = 4200
96+
kappa = 0.541
97+
rho = 997
98+
tau = 1e-12
99+
vel = 0.0 0.0 0.0
100+
0
101+
```
102+
103+
---
104+
105+
### 3. `system.in` (Geometry/Mesh)
106+
107+
Defines the simulation grid and the material distribution.
108+
109+
**Structure:**
110+
1. **Grid Dimensions**: `nx ny nz`
111+
2. **Physical Dimensions**: `Lx Ly Lz`
112+
3. **Grid Data**: A list of `MaterialID:HeaterID` for every cell.
113+
114+
The file is read in the order: Z-planes, then Y-rows, then X-columns.
115+
Each line in the file (after header) corresponds to one row (X-direction).
116+
117+
**Example:**
118+
```
119+
10 10 1
120+
0.01 0.01 0.001
121+
122+
! Z=1, Y=1 Row
123+
1:0 1:0 1:0 1:0 1:0 1:0 1:0 1:0 1:0 1:0
124+
! Z=1, Y=2 Row
125+
1:0 1:0 ...
126+
```
127+
- `1:0` means Material ID 1, Heater ID 0 (no heater).
128+
- `1:1` means Material ID 1, Heater ID 1 (active heater).
129+
130+
## Execution
131+
132+
Ensure the `inputs/` directory exists with the three required files. Run the executable from the directory containing `inputs/`.
133+
134+
```bash
135+
./ThermalFlow.x
136+
```
137+
or via `fpm`:
138+
```bash
139+
fpm run --profile release
140+
```

src/heatflow/mod_inputs.f90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module inputs
9191
integer(int12) :: start_ix, end_ix, start_iy, end_iy, start_iz, end_iz, TempDepProp, heated_steps
9292
! flags
9393
logical :: Check_Sparse_Full, Check_Stability, Check_Steady_State
94-
logical :: WriteToTxt, LPercentage, InputTempDis
94+
logical :: WriteToTxt, LPercentage, InputTempDis, CompressedOutput
9595
logical :: Test_Run = .FALSE., FullRestart = .FALSE.
9696

9797
! Name of simiulation run
@@ -204,7 +204,7 @@ end subroutine read_all_files
204204
subroutine read_param(unit)
205205
implicit none
206206
integer:: unit, Reason
207-
integer,dimension(45)::readvar
207+
integer,dimension(46)::readvar
208208
character(1024)::buffer
209209

210210
readvar(:)=0
@@ -221,6 +221,7 @@ subroutine read_param(unit)
221221
RunName = 'default'
222222
RunName = trim(adjustl(RunName))
223223
WriteToTxt = .FALSE.
224+
CompressedOutput = .FALSE.
224225
ntime = 10
225226
heated_steps = 0
226227
write_every = 1
@@ -325,6 +326,7 @@ subroutine read_param(unit)
325326
CALL assignD(buffer,"BR",BR,readvar(43))
326327
CALL assignL(buffer,"T_BathCC",T_BathCC,readvar(44))
327328
CALL assignS(buffer,"CG_dir",CG_dir,readvar(45))
329+
CALL assignL(buffer,"_CompressedOutput",CompressedOutput,readvar(46))
328330
!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
329331

330332
end do
@@ -520,6 +522,10 @@ subroutine check_param(readvar,n)
520522
readvar(39) = 1
521523
end if
522524

525+
if (readvar(46) .eq. 0) then
526+
readvar(46) = 1
527+
end if
528+
523529
if (any(readvar.eq.0)) then
524530
write(6,*)
525531
write(6,'(A43)') '###############################'
@@ -554,6 +560,7 @@ subroutine check_param(readvar,n)
554560
write(6,'(A35,L1)') ' _FullRestart = ', FullRestart
555561
write(6,'(A35,A)') ' _RunName = ', trim(RunName)
556562
write(6,'(A35,L1)') ' _WriteToTxt = ', WriteToTxt
563+
write(6,'(A35,L1)') ' _CompressedOutput = ', CompressedOutput
557564
write(6,'(A35,I12)') ' ntime = ', ntime
558565
write(6,'(A35,I12)') ' heattime = ', heated_steps
559566
write(6,'(A35,I12)') ' write_every = ', write_every

src/heatflow/mod_output.f90

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
module output
4545
use constants, only: real12, int12, TINY, fields
4646
use inputs, only: nx,ny,nz, time_step, grid, NA, Check_Steady_State, ntime, WriteToTxt
47-
use inputs, only: Test_Run, freq, RunName, FullRestart, IVERB, write_every
47+
use inputs, only: Test_Run, freq, RunName, FullRestart, IVERB, write_every, CompressedOutput
4848
use inputs, only: start_ix, end_ix, start_iy, end_iy, start_iz, end_iz
4949
use globe_data, only: Temp_p,Temp_pp, heat, heated_volume, logname
5050
implicit none
@@ -92,11 +92,17 @@ subroutine data_write(itime)
9292
! find most recent log file and open it
9393
!---------------------------------------
9494
CALL last_log(logname,outdir)
95-
open(logunit,file=logname)
96-
! print*, logunit
97-
! print*, logname
98-
write(logunit,*) real((itime-1)*(time_step)), &
99-
(Temp_cur(start_ix:end_ix, start_iy:end_iy, start_iz:end_iz))
95+
if (CompressedOutput) then
96+
open(logunit,file=logname, status='unknown', access='stream', position='append')
97+
write(logunit) real((itime-1)*(time_step), kind=real12)
98+
write(logunit) (Temp_cur(start_ix:end_ix, start_iy:end_iy, start_iz:end_iz))
99+
else
100+
open(logunit,file=logname)
101+
! print*, logunit
102+
! print*, logname
103+
write(logunit,*) real((itime-1)*(time_step)), &
104+
(Temp_cur(start_ix:end_ix, start_iy:end_iy, start_iz:end_iz))
105+
end if
100106
close(logunit)
101107
!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102108
end if
@@ -110,17 +116,23 @@ subroutine data_write(itime)
110116
! write out to log file
111117
!---------------------------------------
112118
if (.not. Test_run) then
113-
if (WriteToTxt) then
114-
if (mod(itime, write_every) .eq. 0) then
115-
write(*, *) 'Writing Temperature difference to file'
116-
! print*, logunit
117-
! print*, logname
118-
open(logunit,file=logname, status='old', position='append')
119-
write(logunit,*) real((itime-1)*(time_step)), &
120-
(Temp_cur(start_ix:end_ix, start_iy:end_iy, start_iz:end_iz))
121-
close(logunit)
122-
end if
123-
endif
119+
if (mod(itime, write_every) .eq. 0) then
120+
if (CompressedOutput) then
121+
write(*, *) 'Writing Temperature (Compressed) to file'
122+
open(logunit,file=logname, status='unknown', access='stream', position='append')
123+
write(logunit) real((itime-1)*(time_step), kind=real12)
124+
write(logunit) (Temp_cur(start_ix:end_ix, start_iy:end_iy, start_iz:end_iz))
125+
close(logunit)
126+
elseif (WriteToTxt) then
127+
write(*, *) 'Writing Temperature difference to file'
128+
! print*, logunit
129+
! print*, logname
130+
open(logunit,file=logname, status='old', position='append')
131+
write(logunit,*) real((itime-1)*(time_step)), &
132+
(Temp_cur(start_ix:end_ix, start_iy:end_iy, start_iz:end_iz))
133+
close(logunit)
134+
end if
135+
end if
124136
end if
125137
!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126138

@@ -202,8 +214,13 @@ subroutine last_log(logname,outdir)
202214
i = 0
203215
flag=.true.
204216
do while (flag)
205-
write(logname, '(A,A,I2.2)') trim(adjustl(outdir)) // 'output_' // &
206-
trim(adjustl(RunName)),'_', i
217+
if (CompressedOutput) then
218+
write(logname, '(A,A,I2.2,A)') trim(adjustl(outdir)) // 'output_' // &
219+
trim(adjustl(RunName)),'_', i, '.bin'
220+
else
221+
write(logname, '(A,A,I2.2)') trim(adjustl(outdir)) // 'output_' // &
222+
trim(adjustl(RunName)),'_', i
223+
endif
207224
inquire(file=logname, exist=flag)
208225
i = i+1
209226
end do

src/heatflow/mod_petsc_solver.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module petsc_solver
1212
! 'GAMG' = Algebraic Multigrid (best for elliptic PDEs, 10-20x faster)
1313
! 'ILU' = Incomplete LU (good general purpose, robust)
1414
! 'LU' = Direct solver (most robust, uses more memory)
15-
character(len=10), parameter :: PRECONDITIONER = 'GAMG' ! <-- Change here!
15+
character(len=10), parameter :: PRECONDITIONER = 'ILU' ! <-- Change here!
1616
! ====================================
1717

1818
! Persistent PETSc objects (reused across timesteps for memory efficiency)

0 commit comments

Comments
 (0)