Add 3D-1D coupling interface APIs - #131
Conversation
|
@taeoukkim This PR does not build on MacOS. This is a CMake issue I think; I'll have a look. |
|
@taeoukkim The compiler used to build svOneDSolver/Code/Source/interface/interface.cpp was set to I added after the |
ktbolt
left a comment
There was a problem hiding this comment.
@taeoukkim You've done a great job here adding an interface to an old and confusing code !
A couple of important things to clean up
-
Only use print statements for debugging; they should not be active for release
-
Use a consistent error handing; really everything should use
cvExceptionI'm guessing; writing to cerr is not very useful should throw I think
svOneDSolver writes out lots of .dat files and prints a simulation history to stdout I think. How is this managed for the 3D interface ?
Thank you for identifying the issue and suggesting the fix!! I added the C++20 settings to the top-level CMakeLists.txt and confirmed that the interface library builds successfully on my Mac. |
|
@ktbolt Thank you very much for the thorough review and helpful suggestions. I have addressed all of the comments. I also clarified that accepted coupled solutions are written to VTK and text files at the requested output interval. Both the standalone OneDSolver and svoned_interface build successfully on macOS, and I confirmed that the standalone solver still runs correctly. |
ktbolt
left a comment
There was a problem hiding this comment.
@taeoukkim Fine work here, nice clean up !
Please add any necessary comments to the non-API functions in interface.cpp.
I want to confirm that if the 1D solver fails then the failure is reported by the 3D solver.
| #else | ||
| #define SVONED_DEBUG_LOG(message) \ | ||
| do { } while (false) | ||
| #endif |
| if(argc == 2) { | ||
| string inputFile{removeQuotesIfPresent(argv[1])}; | ||
| return readLegacyOptions(inputFile); | ||
| if (errorCode == CV_ERROR) { |
There was a problem hiding this comment.
@taeoukkim It is not good to cast away a const qualifier; better to change the signature of CreateNode.
CreateNode always returns CV_OK.
| for (int jointIndex = 0; jointIndex < totalJoints; ++jointIndex) { | ||
| const std::string& inletName = opts.jointInletName[jointIndex]; | ||
| const std::string& outletName = opts.jointOutletName[jointIndex]; | ||
|
|
There was a problem hiding this comment.
@taeoukkim You can use const auto& inletName = opts.jointInletName[jointIndex];
|
|
||
| const int totalInlets = opts.jointInletListNumber[inletID]; | ||
| const int totalOutlets = opts.jointOutletListNumber[outletID]; | ||
|
|
There was a problem hiding this comment.
@taeoukkim All of this use of const just really adds noise in my opinion but maybe this is your style; no problem with that.
You can also use auto errMsg = ERROR: Cannot Find JOINTOUTLET for key " + outletName;
| for (int i = 0; i < totalInlets; ++i) { | ||
| inletSegments.push_back(opts.jointInletList[inletID][i]); | ||
| } | ||
|
|
There was a problem hiding this comment.
@taeoukkim You can replace all this (111-115) with
std::vector<int> inletSegments(opts.jointInletList[inletID].begin(), opts.jointInletList[inletID].end());
| cvOneDGlobal::outputType = OutputTypeScope::OUTPUT_BOTH; | ||
| } else { | ||
| throw cvException("ERROR: Invalid OUTPUT Type.\n"); | ||
| } |
There was a problem hiding this comment.
@taeoukkim Include in the exception message what the invalid type was.
|
|
||
| if (cvOneDGlobal::vtkOutputType > 1) { | ||
| throw cvException("ERROR: Invalid OUTPUT VTK Type.\n"); | ||
| } |
There was a problem hiding this comment.
@taeoukkim What does it mean to have cvOneDGlobal::vtkOutputType > 1 ?
| } | ||
|
|
||
| int getDataTableIDFromStringKey(std::string key) { | ||
| std::size_t count = 0; |
| upper_string(cvOneDGlobal::gDataTables[count]->getName())) { | ||
| return static_cast<int>(count); | ||
| } | ||
|
|
There was a problem hiding this comment.
@taeoukkim Maybe cleaner to use a for loop or iterators; while loops are typically not used for a known range.
auto ukey = upper_string(key);
for (auto& entry : cvOneDGlobal::gDataTables) {
if (ukey == upper_string(entry->getName())) {
return count;
}
count += 1;
}
| if (str.size() >= 2 && str.front() == '"' && str.back() == '"') { | ||
| return str.substr(1, str.size() - 2); | ||
| } | ||
|
|
There was a problem hiding this comment.
@taeoukkim It would be perhaps cleaner to use
auto mstr = str;
mstr.erase(std::remove(mstr.begin(), mstr.end(), '"'), mstr.end());
return mstr;
Current situation
resolves #129
Release Notes
Update 1D solver for 3D-1D coupling.
Functions are stored in "interface.cpp" file.
Main functions are: initialize_1d, set_external_step_size_1d, return_1d_solution, update_1d_solution, run_1d_simulation_step_1d, and extract_coupled_dof.
Now, when you compile the code, it will create a shared library for coupling at ".../svOneDSolver/build/lib/libsvoned_interface.dylib"
The API functions can be accessed through this shared library.
Documentation
I will update document.
Testing
3D-1D testing done
Code of Conduct & Contributing Guidelines