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

Conversation

markcmiller86
Copy link
Owner

Create initial PR for merging @remontel python extension module work to main

remontel added 30 commits June 24, 2024 19:53
…ce code for shared library), test_pyheat.py (test script), and updated makefile to build shared libary
- Separated HeatProblem, HeatSolution, and HeatRun structures for clarity
- Refactored global arrays to hold instances of problem, solution, and run data
- Updated init_problem and init_solution functions to initialize respective structures
- Modified solve_heat_equation to correctly parse arguments and match expected types
- Updated heat.py to test the new implementation with correct argument types
- Separated HeatProblem, HeatSolution, and HeatRun structures for clarity
- Refactored global arrays to hold instances of problem, solution, and run data
- Updated init_problem and init_solution functions to initialize respective structures
- Modified solve_heat_equation to correctly parse arguments and match expected types
- Updated test_heat.py to test the new implementation with correct argument types

Merge branch 'main' into python-extension
1. Static Arrays and Index Management:
   • Static arrays problems, solutions, and runs are used to hold the data for each type of object.
   • Indices problemIndex, solutionIndex, and runIndex track the next available slot in each array.

2. Initialization Functions:
   • init_problem: Initializes a HeatProblem structure and returns its index.
   • init_solution: Initializes a HeatSolution structure and returns its index.

3. Simulation Function:
   • run_simulation: Runs the heat simulation using the initialized problem and solution, and stores run-specific settings.

- Removed dynamic memory allocation (malloc) from pyheat.c
- Included update_solution_ftcs function declaration
- Added detailed comments to explain the code
1. Static Arrays and Index Management:
   • Static arrays problems, solutions, and runs are used to hold the data for each type of object.
   • Indices problemIndex, solutionIndex, and runIndex track the next available slot in each array.

2. Initialization Functions:
   • init_problem: Initializes a HeatProblem structure and returns its index.
   • init_solution: Initializes a HeatSolution structure and returns its index.

3. Simulation Function:
   • run_simulation: Runs the heat simulation using the initialized problem and solution, and stores run-specific settings.

- Removed dynamic memory allocation (malloc) from pyheat.c
- Included update_solution_ftcs function declaration
- Added detailed comments to explain the code
1. Added Problem Index to HeatSolution:
   - Updated  structure to include  to reference the associated problem.

2. Corrected init_solution Function:
   - Modified  function to set the  when initializing a solution.

3. Corrected run_simulation Function:
   - Updated  function to retrieve the  structure using  from .
   - Ensured proper memory access and stability during simulation runs.

4. Added return_simulation_results Function:
   - Implemented  function to return simulation results.
   - Added a placeholder implementation that returns a sample result for testing purposes.

These changes correct the segmentation fault by properly referencing the associated problem for each solution and add the missing  function to resolve the AttributeError.
1. Added Problem Index to HeatSolution:
   - Updated HeatSolution structure to include probIndex to reference the associated problem.

2. Corrected init_solution Function:
   - Modified init_solution function to set the probIndex when initializing a solution.

3. Corrected run_simulation Function:
   - Updated run_simulation function to retrieve the HeatProblem structure using probIndex from HeatSolution.
   - Ensured proper memory access and stability during simulation runs.

4. Added return_simulation_results Function:
   - Implemented return_simulation_results function to return simulation results.
   - Added a placeholder implementation that returns a sample result for testing purposes.

5. Updated heat.py to reflect changes made to pyheat.c
…ts to pyheat.c to improve initialization, simulation, and result retrieval functions. The code has been refactored to store simulation results in arrays, replicating the functionality of the curve files in the original heat application. This allows the user to interact with the results data (e.g., graph in gnuplot). Changes have also been made to ensure better error handling, memory management, and code consistency.

**Detailed Changes**

1. **Initialization Functions**:
   - **init_problem**:
     - Added a check to ensure the number of problems does not exceed MAX_PROBLEMS.
     - Refactored to allow for storing of results in array
     - Improved error handling and documentation.
   - **init_solution**:
     - Added a check to ensure the number of solutions does not exceed MAX_SOLUTIONS.
     - Refactored to allow for storing of results in array
     - Improved error handling and documentation.

2. **Simulation Function**:
   - **run_simulation**:
     - Added error handling to check for valid solution and run indices.
     - Included memory allocation for times and t_results.
     - Utilized the copy function from utils.c to store results periodically.
     - Ensured the function checks for solution stability and raises an error if the solution becomes unstable.
     - Ensured the solIndex is correctly set in the HeatRun structure.

3. **Result Retrieval Function**:
   - **return_simulation_results**:
     - Added condition to check if runIndex is within valid limits by comparing it against MAX_RUNS
     - Ensured the function correctly references the HeatSolution associated with the given HeatRun.
     - Created nested lists to store and return simulation results, with each inner list representing the temperature results for a specific time step.
…ulation_results does not correctly return results
1.  now uses strdup to allocate memory for
2.  now uses  from utils.c to set initial conditions
3.  now checks if the time index is empty and iterates before continuing.
4. Added notes to print error message letting user know to use correct arguments when passing data
5. Minor editing to improve readability of code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants