Skip to content

Adding geimFoam python module#15

Open
mahmudulh-tamim wants to merge 8 commits intomainfrom
add-geimFoam
Open

Adding geimFoam python module#15
mahmudulh-tamim wants to merge 8 commits intomainfrom
add-geimFoam

Conversation

@mahmudulh-tamim
Copy link
Copy Markdown
Collaborator

@mahmudulh-tamim mahmudulh-tamim commented Jun 18, 2025

This pull request adds the geimFOAM module. It should be noted that it's based on #13. Hence, please check src/python/geimFOAM.py. The geimFOAM module has two Python classes - one for the offline phase of the algorithm and another for the online phase. The classes can be imported by:

from geimFOAM import GeimFOAM_offline, GeimFOAM_online 

GeimFOAM_offline takes a rank, an instance of the Snapshot_manager, a list of observable fields, and a list of non-observable fields as inputs. It should be noted that the user has been given the option for choosing the non-observable fields because some fields might be of lesser interest, e.g., constant fields.

Therefore, the instantiation of GeimFOAM_offline would be of the following form:

gf_offline = GeimFOAM_offline(rank=rank, snapshot_manager_object=snapshot_manager_object, observable_fields=list_observable_fields, non_observable_fields=list_non_observable_fields)

Then, the GeimFOAM_offline.run_geim() method must be called to start the algorithm. This can be done the following way:

gf_offline.run_geim()

After the completion of this method, the instance of the object is matured and can now be used to run the online phase of the algorithm.

To run the online phase of the algorithm, we have to create an instance of the GeimFOAM_online class. It takes an instance of the GeimFOAM_offline class, a list of snapshots that we intend to reconstruct, and the rank of reconstruction. It can be instantiated the following way:

gf_online = GeimFOAM_online(geim_offline_object=gf_offline, snaps=snapshot_list, rank_reconstruct=rank_reconstruct)

After the instantiation of the object, one must run the GeimFOAM_online.reconstruct_snaps() method to complete the reconstruction process.

@mahmudulh-tamim mahmudulh-tamim self-assigned this Jun 18, 2025
@mahmudulh-tamim mahmudulh-tamim linked an issue Jun 18, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@rokkrpan rokkrpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, avoid using linAlg4Foam inside loops.

sensor_field_i = self.list_sensor_to_field[i]
for j in range(count_basis + 1):
sensor_basis_j = self.list_sensor_to_basis_paths[j]
sensoring_results = linAlg4Foam.readFromPoints(self.virtual_openFoam_directory, [sensor_basis_j], [sensor_field_i], [sensor_point_i])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each time you call linAlg4Foam it will start from scratch (without compiling). Try to avoid using these functionalities in a loop. You can provide a list of snaps, fields and points all at once, and then extract the needed data from the generated dictionary.

for i in range(n_rows):
sensor_point = self.list_points[i]
sensor_field = self.list_sensor_to_field[i]
sensoring_results = linAlg4Foam.readFromPoints(self.virtual_openFoam_directory, self.list_chosen_snaps, [sensor_field], [sensor_point])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, avoid using in a loop.

reconstructed_snap = self.list_reconstructed_snaps[i]
for field in self.all_fields:
region, field_name = split_on_slash(field)
linAlg4Foam.linearCombination(self.virtual_openFoam_directory, [self.list_sensor_to_basis_paths], [field], [coeffs_list], [os.path.join("../symlinked_cases", reconstructed_snap, region)])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, avoid using in a loop. If looping cannot be omitted, then some upgrading of the function is needed.

residual_snap = self.list_residual_snaps[i]
for field in self.all_fields:
region, field_name = split_on_slash(field)
linAlg4Foam.linearCombination(self.virtual_openFoam_directory, [[snap, reconstructed_snap]], [field], [[1, -1]], [os.path.join("../symlinked_cases", residual_snap, region)])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering multiple fields at once is needed?

for i in range(self.rank_reconstruct):
sensor_point = self.list_points[i]
sensor_field = self.list_sensor_to_field[i]
sensoring_results = linAlg4Foam.readFromPoints(self.virtual_openFoam_directory, self.snaps, [sensor_field], [sensor_point])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, avoid using it in a loop.

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.

Add geimFoam

2 participants