Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python extension #25

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
12b0329
Add untracked files
remontel Jun 25, 2024
798b125
Add untracked files
remontel Jun 25, 2024
8c5d6ba
Update settings and remove plot_heat.py
remontel Jun 25, 2024
7fcd85c
Renamed source file to helloPy.c and recompiled helloPy.so, removed r…
remontel Jun 26, 2024
cacc9ab
removed unused IDE files
remontel Jun 26, 2024
ca61e59
renamed file for clarity
remontel Jul 1, 2024
72c6bd8
renamed file for clarity
remontel Jul 1, 2024
d64470f
changes made to vscode settings
remontel Jul 16, 2024
29c5846
Merge branch 'mcm86-temp-remove-number-type'
remontel Jul 16, 2024
da5c9e0
Add intial Python extension: Removed old files and add pyheat.c (sour…
remontel Jul 17, 2024
0da2b73
Updated file list in vscode settings
remontel Jul 17, 2024
e819221
removed unnecessary includes
remontel Jul 18, 2024
6ff2758
Refactor pyheat.c and update heat.py for Python extension
remontel Jul 20, 2024
149b76c
Remove VS Code configuration files from tracking
remontel Jul 20, 2024
64fe517
Add .gitignore file
remontel Jul 20, 2024
24b6b57
Remove VS Code configuration files from tracking
remontel Jul 20, 2024
1689a79
Updated .gitignore file
remontel Jul 20, 2024
2a8055c
Added .gitignore file
remontel Jul 22, 2024
3fe2d21
Refactor pyheat.c and update test_heat.py for Python extension
remontel Jul 22, 2024
4dc18ce
Renamed test_pyheat.py to heat.py
remontel Jul 25, 2024
0d32864
Refactor pyheat.c for Python extension
remontel Jul 25, 2024
f5c29ae
Refactor pyheat.c for Python extension
remontel Jul 25, 2024
d901fde
Fix Segmentation Fault and AttributeError in pyheat.c
remontel Jul 25, 2024
19bf165
Fix Segmentation Fault and AttributeError in pyheat.c
remontel Jul 25, 2024
8b4ef35
**Description:** This commit includes multiple updates and enhancemen…
remontel Jul 30, 2024
0e02f5c
'help' Targets has been updated to include pyheat.so. 'make pyheat.so…
remontel Jul 30, 2024
6973eb0
Updates to return heats results stored in array. Currently return_sim…
remontel Aug 2, 2024
5be4cef
In set_initial_condition commented out in order for set_initial_cond…
remontel Aug 5, 2024
aa20e8e
Added comment for debugger to ignore pyheat. Removes error before mak…
remontel Aug 5, 2024
e87b2b0
Debugged issues with returning no or garbage data.
remontel Aug 5, 2024
0834043
minor edits to pyheat.c for code clarity. heat.py updated to run exam…
remontel Aug 6, 2024
754810e
renamed function names for simplicity. Added help() docstring for pro…
remontel Aug 7, 2024
8ce7bab
Added help documentation. This can be called with help(pyheat).
remontel Aug 8, 2024
98e651a
Minor changes to documentation structure
remontel Aug 8, 2024
1abaf6b
Minor changes to code structure
remontel Aug 8, 2024
f72936a
Minor changes to documentation structure
remontel Aug 8, 2024
b6e7bf2
Added an option for user to select either the ftcs or dufrank algorit…
remontel Aug 14, 2024
0a7f545
fixed bug with running the dufrank algorithm
remontel Aug 16, 2024
2e32538
Created new test script for comparing ftcs and dufrank algorithms
remontel Aug 16, 2024
792bf55
Updated documentation to reflect changes in example scripts
remontel Aug 16, 2024
8970626
Removed placeholder hold
remontel Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.vscode/.DS_Store
.vscode/c_cpp_properties.json
.vscode/settings.json
Binary file removed .vscode/.DS_Store
Binary file not shown.
22 changes: 0 additions & 22 deletions .vscode/c_cpp_properties.json

This file was deleted.

48 changes: 0 additions & 48 deletions .vscode/settings.json

This file was deleted.

52 changes: 52 additions & 0 deletions heat_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pyheat # type: ignore
import sys
import matplotlib.pyplot as plt

# Example of using the pyheat module to run a heat transfer simulation with two different numerical models.
# The simulation is run for a 1D heat transfer problem with a constant heat source and no heat loss.
# Run with the FTCS and Dufrank numerical models.
# The results are plotted to compare the temperature profiles predicted by the two.

# Initialize the problem with material properties and boundary conditions
prob_index = pyheat.problem(1, 0.2, 0, 0, "const(3)")
print(f"Initialized Problem Index: {prob_index}")

# Initialize the solution for the problem with numerical model parameters
ftcs_index = pyheat.solution(prob_index, 0.01, 0.00004, 0.04, 100, "ftcs")
print(f"Initialized Solution Index: {ftcs_index}")

# Initialize the solution for the problem with numerical model parameters
dufrank_index = pyheat.solution(prob_index, 0.01, 0.00004, 0.04, 100, "dufrank")
print(f"Initialized Solution Index: {dufrank_index}")

# Run the simulation with the initialized solution and save settings
ftcs_run_index = pyheat.run(ftcs_index, "heat_results", 100, 100)
if ftcs_run_index < 0:
print("Problem running simulation")
sys.exit(1)

dufrank_run_index = pyheat.run(dufrank_index, "heat_results", 100, 100)
if dufrank_run_index < 0:
print("Problem running simulation")
sys.exit(1)

# Return the simulation results
ftcs_results = pyheat.results(ftcs_run_index)
dufrank_results = pyheat.results(dufrank_run_index)
print(f"Simulation results: {ftcs_results[4]}") # Temperature values at 4th index in array
print(f"Simulation results: {dufrank_results[4]}") # Temperature values at 4th index in array

# Plot the results
x = [] # x values are the distance values
for i in range (0,100):
x.append(i*0.01) # iterates through the x values
y1 = ftcs_results[4] # y values are the temperature values
y2 = dufrank_results[4] # y values are the temperature values

plt.xlabel('Distance (meters)')
plt.ylabel('Temperature (Kelvin)')
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
sys.exit(0)

53 changes: 53 additions & 0 deletions heat_ftcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pyheat # type: ignore
import sys
import matplotlib.pyplot as plt

# Example of using the pyheat module to run a heat transfer simulation
# CLI command that would be used in C application:
# ./heat dx=0.01 dt=0.00004 bc1=0 ic="spikes(0,100,50)" maxt=0.04 outi=100 savi=100

# Initialize the problem with material properties and boundary conditions
prob_index = pyheat.problem(1, 0.2, 0, 0, "spikes(0,100,50)")
print(f"Initialized Problem Index: {prob_index}")

# Initialize the solution for the problem with numerical model parameters
ftcs_index = pyheat.solution(prob_index, 0.01, 0.00004, 0.04, 100, "ftcs")
print(f"Initialized Solution Index: {ftcs_index}")

# Initialize the solution for the problem with numerical model parameters
dufrank_index = pyheat.solution(prob_index, 0.01, 0.00004, 0.04, 100, "dufrank")
print(f"Initialized Solution Index: {dufrank_index}")

# Run the simulation with the initialized solution and save settings
ftcs_run_index = pyheat.run(ftcs_index, "heat_results", 100, 100)
if ftcs_run_index < 0:
print("Problem running simulation")
sys.exit(1)

dufrank_run_index = pyheat.run(dufrank_index, "heat_results", 100, 100)
if dufrank_run_index < 0:
print("Problem running simulation")
sys.exit(1)

# Return the simulation results
ftcs_results = pyheat.results(ftcs_run_index)
dufrank_results = pyheat.results(dufrank_run_index)
print(f"Simulation results: {ftcs_results[4]}") # Temperature values at 4th index in array
print(f"Simulation results: {dufrank_results[4]}") # Temperature values at 4th index in array



# Plot the results
x = [] # x values are the distance values
for i in range (0,100):
x.append(i*0.01) # iterates through the x values
y1 = ftcs_results[4] # y values are the temperature values
y2 = dufrank_results[4] # y values are the temperature values

plt.xlabel('Distance (meters)')
plt.ylabel('Temperature (Kelvin)')
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
sys.exit(0)

144 changes: 0 additions & 144 deletions helloPy.C

This file was deleted.

21 changes: 20 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ RM = rm
HDR = Number.h heat.h
# Source Files
SRC = heat.c utils.c args.c exact.c ftcs.c crankn.c dufrank.c
# Python Source Files
pySRC = pyheat.c
# Object Files
OBJ = $(SRC:.c=.o)
# Python Object Files
pyOBJ = $(pySRC:.c=.o)
pySO = $(pySRC:.c=.so)
# Coverage Files
GCOV = $(SRC:.c=.c.gcov) $(SRC:.c=.gcda) $(SRC:.c=.gcno) $(HDR:.h=.h.gcov)
# Executable
Expand All @@ -34,10 +39,12 @@ help:
@echo " heat-single: makes the heat application with single precision"
@echo " heat-double: makes the heat application with double precision"
@echo " heat-long-double: makes the heat application with long-double precision"
@echo " pyheat.so: makes the python-extension of the heat application"
@echo " PTOOL=[gnuplot,matplotlib,visit] RUNAME=<run-dir-name> plot: plots results"
@echo " check: runs various tests confirming steady-state is linear"



# Linking the final heat app
heat: $(OBJ)
$(CC) -o heat $(OBJ) $(LDFLAGS) -lm
Expand Down Expand Up @@ -89,7 +96,8 @@ check_clean:
$(RM) -rf heat heat-omp heat-half heat-single heat-double heat-long-double

clean: check_clean
$(RM) -f $(OBJ) $(EXE) $(GCOV)
$(RM) -f $(OBJ) $(EXE) $(GCOV) $(pyOBJ) $(pySO)
# added Python shared library [rene]

#
# Run for a long time with random initial condition
Expand Down Expand Up @@ -135,3 +143,14 @@ check_dufrank: heat check_dufrank/check_dufrank_soln_final.curve
./python_testing/check_lss.py check_dufrank/check_dufrank_soln_final.curve $(ERRBND)

check_all: check_ftcs check_crankn check_dufrank

PYTHON_INCLUDES := $(shell python3-config --includes)
PYTHON_LDFLAGS := $(shell python3-config --ldflags) -lpython3.12

# Target to build the Python extension module
pyheat.so: $(pyOBJ) $(OBJ)
cc -shared -o $(pySO) $(pyOBJ) $(OBJ) -lm $(PYTHON_LDFLAGS)

# Compile pyheat.c into pyheat.o
pyheat.o: $(pySRC)
cc -c -fPIC $(pySRC) -o $(pyOBJ) -I. $(PYTHON_INCLUDES)
Loading
Loading