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

Pull request: Add functions into "ITHACAstream" to read the converged fields in parallel. #559

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

Ruansh233
Copy link
Contributor

@Ruansh233 Ruansh233 commented Jun 21, 2024

1-Add two functions, read_last_fields and readLastFields, to the ITHACAstream. The two functions allow parallel reading of the converged fields in the subfolders.
2-The solver, 18simpleTurbNS, is also modified.
3-Declear as const for those immutable variables in the read_last_fields function.
4-Use pointers to improve the code's efficiency, following Dr. Mark Olesen's suggestions.
5-Add #if defined(OFVER) && (OFVER >= 2212)_ to activate emplace_back function for the new OF version.
6-Use Info instead of std::cout in the getTurbRBF function to reduce repeating print.

…CAstream. The two functions allow to parallel read the converged fields in the subfolders. 2-The solver, 18simpleTurbNS, is also modified.
@Ruansh233 Ruansh233 changed the title Add two functions to "ITHACAstream", which can parallel read the converged fields. Pull request: Add two functions to "ITHACAstream", which can parallel read the converged fields. Jun 21, 2024
Foam::Time runTime2(Foam::Time::controlDictName, rootpath, casename);
int last_s (runTime2.times().size());

GeometricField<Type, PatchField, GeoMesh> tmp_field(
Copy link
Contributor

@olesenm olesenm Jun 21, 2024

Choose a reason for hiding this comment

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

This is really wasteful. There is no reason to read the field from disk and then make a full (deep) copy if it, which is what the clone() will do. At least wrap it as a pointer to allow the append to steal the contents. Eg,

auto tfld =
    autoPtr<GeometricField<Type, PatchField, GeoMesh>>::New
    (
        IOobject
        (
            field.name(),
            casename + runTime2.times()[last_s-1].name(),
            field.mesh(),
            IOobject::MUST_READ
        ),
        field.mesh()
    );

Lfield.append(std::move(tfld));

Copy link
Contributor

Choose a reason for hiding this comment

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

Starting with OpenFOAM-v2212, you can also use the emplace_back() method. For example,

#if (OPENFOAM >= 2212)
Lfield.emplace_back
(
    IOobject
    (
        field.name(),
        casename + runTime2.times()[last_s-1].name(),
        field.mesh(),
        IOobject::MUST_READ
    ),
    field.mesh()
);
#else 
...
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good morning, Dr. Olesen. Thanks for your contributive suggestions. I will modify the code and submit it later today. As a new guy in OpenFOAM, I still need to learn lots of such programming skills.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries, you just need to be "paranoid" about clean code and memory use and most things will work out fine...

void readLastFields(PtrList<GeometricField<Type, PatchField, GeoMesh>>&
Lfield,
GeometricField<Type, PatchField, GeoMesh>& field,
fileName casename);
Copy link
Contributor

Choose a reason for hiding this comment

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

consider passing as const fileName& casename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will modify it as const fileName& casename.

…fields_ function; 2-Use pointer to improve the efficiency of the code; 3-Add to activate _emplace_back_ function for new OF version; 4-Use instead of in the function to reduce repeating print.
@Ruansh233 Ruansh233 changed the title Pull request: Add two functions to "ITHACAstream", which can parallel read the converged fields. Pull request: Add functions into "ITHACAstream" to read the converged fields in parallel. Jun 24, 2024
@giovastabile giovastabile merged commit cc881c0 into ITHACA-FV:master Jun 26, 2024
2 checks passed
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.

None yet

3 participants