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

Decouple compilation of 2D and 3D mprans classes #1140

Merged
merged 27 commits into from
Apr 24, 2020
Merged

Conversation

cekees
Copy link
Member

@cekees cekees commented Apr 20, 2020

I merged master back into a testing branch I made recently. This is in response to the discussion #1139 . I don't find that this compiles significantly faster, but the design is simpler in my opinion. In this version the 2D and 3D extension modules don't depend on one another, so when you're developing on say, RANS3P2D, it doesn't force recompilation of RANS3P.

Mandatory Checklist

Please ensure that the following criteria are met:

  • Title of pull request describes the changes/features
  • Request at least 2 reviewers
  • If new files are being added, the files are no larger than 100kB. Post the file sizes.
  • Code coverage did not decrease. If this is a bug fix, a test should cover that bug fix. If a new feature is added, a test should be made to cover that feature.
  • New features have appropriate documentation strings (readable by sphinx)
  • Contributor has read and agreed with CONTRIBUTING.md and has added themselves to CONTRIBUTORS.md

As a general rule of thumb, try to follow PEP8 guidelines.

Description

@cekees cekees requested a review from zhang-alvin April 20, 2020 13:45
Copy link
Contributor

@zhang-alvin zhang-alvin left a comment

Choose a reason for hiding this comment

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

Looks reasonable.

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
@cekees
Copy link
Member Author

cekees commented Apr 22, 2020

@JohanMabille can you take a look at this PR. I'm thinking I'd like to go ahead and split the RANS* classes to have separate modules following the same pattern. Mainly just to prevent confusion in the future. The compile times appeared to be slightly faster on my laptop, but the difference was marginal. This is mainly just for consistency/simplicity.

@cekees
Copy link
Member Author

cekees commented Apr 22, 2020

Also @JohanMabille can you explain why #define FORCE_IMPORT_ARRAY is necessary?

Copy link
Member

@JohanMabille JohanMabille left a comment

Choose a reason for hiding this comment

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

I will give detail about the FORCE_IMPORT_ARRAY preprocessor token in a dedicated message to avoid getting it lost in a resolved conversation.

@@ -10,6 +10,9 @@
#include "ModelFactory.h"
#include "SedClosure.h"
#include "equivalent_polynomials.h"
const double DM=0.0;//1-mesh conservation and divergence, 0 - weak div(v) only
const double DM2=0.0;//1-point-wise mesh volume strong-residual, 0 - div(v) only
const double DM3=1.0;//1-point-wise divergence, 0-point-wise rate of volume change
Copy link
Member

@JohanMabille JohanMabille Apr 22, 2020

Choose a reason for hiding this comment

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

I think these variables could be static to avoid multiple symbols definitions if this header is included in many cpp files in the same library. This is just a precaution.

Copy link
Member Author

Choose a reason for hiding this comment

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

These headers really shouldn't be used in more than one compilation unit, and the point here is to make the symbols local constants. They're just switches that are specific to this file (could also be macros).

proteus/mprans/RANS3PSed2D.h Show resolved Hide resolved
.def("calculateResidual", &cppRANS3PSed_base::calculateResidual)
.def("calculateJacobian", &cppRANS3PSed_base::calculateJacobian)
.def("calculateVelocityAverage", &cppRANS3PSed_base::calculateVelocityAverage);

Copy link
Member

Choose a reason for hiding this comment

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

This file looks like a duplicata of RANS3PSed.cpp or am I missing something? If this is a duplicate, this defines the module twice. Also I would be in favor of keeping the name of the implementation file consistent with that of the header file. The 'c' prefix makes me think of a file generated by cython while it is not.

.def("calculateResidual", &cppRANS3PSed2D_base::calculateResidual)
.def("calculateJacobian", &cppRANS3PSed2D_base::calculateJacobian)
.def("calculateVelocityAverage", &cppRANS3PSed2D_base::calculateVelocityAverage);
}
Copy link
Member

Choose a reason for hiding this comment

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

Same comment w.r.t. RANS3PSed2D.cpp

extra_compile_args=PROTEUS_OPT+['-std=c++14'],
language='c++'),
Extension(
'mprans.cRANS3PSed2D',
Copy link
Member

Choose a reason for hiding this comment

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

Ah you replaced RANS3PSed.cpp with cRANS3PSed.cpp here (same for the 2D file) so the modules are not defined twice. Therefore, the RANS3PSed.cpp and RANS3PSed2D.cpp are not used anymore and could be deleted. However I would be in favor of doing the contrary to keep naming consistency with other modules.

@JohanMabille
Copy link
Member

JohanMabille commented Apr 22, 2020

Regarding the FORCE_IMPORT_ARRAY token, first you should be aware of this.

To summarize, the import_array function must be called only once in the initialization routine of the extension module. Besides, each compilation unit that does not contain the initialization routine must define NO_IMPORT_ARRAY before including numpy headers, otherwise you end up with link errors.

Now, when you include a header from xtensore-python, you indirectly include a header form numpy. Requiring the user to define NO_IMPORT_ARRAY in every cpp module is a bit cumbersome, therefore we took the opposite approach: by default, NO_IMPORT_ARRAY is defined except if you define FORCE_IMPORT_ARRAY before including a header from xtensor_python.

This way, extension authors only have to be careful when they write the module that contains the initialization routine. Besides, when FORCE_IMPORT_ARRAY is not defined, the import_numpy function does nothing, preventing accidental calls to it in other cpp files.

@JohanMabille
Copy link
Member

LGTM!

@cekees cekees merged commit ff9eabe into erdc:master Apr 24, 2020
@cekees cekees deleted the split_rans branch April 24, 2020 03:46
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.

3 participants