-
Notifications
You must be signed in to change notification settings - Fork 244
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
[MedApp] Trim Whitespace in Group Names #12147
Changes from 2 commits
7bd6cc4
9df1fc1
cff095b
71e5877
4cad7b5
e6c89d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,10 +67,26 @@ void CheckMEDErrorCode(const int ierr, const std::string& MEDCallName) | |
KRATOS_ERROR_IF(ierr < 0) << MEDCallName << " failed with error code " << ierr << "." << std::endl; | ||
} | ||
|
||
bool IsNotPaddingCharacter(std::string::value_type character) noexcept | ||
{ | ||
return !(std::isspace(character) || character == '\0'); | ||
} | ||
|
||
// The names in the MED-file often have trailing null-chars, which need to be removed | ||
// this can otherwise make debugging very tricky | ||
void RemoveTrailingNullChars(std::string& rInput) | ||
void RemovePadding(std::string& rInput) | ||
{ | ||
// Trime left | ||
rInput.erase(rInput.begin(), | ||
std::find_if(rInput.begin(), | ||
rInput.end(), | ||
IsNotPaddingCharacter)); | ||
|
||
// Trim right | ||
rInput.erase(std::find_if(rInput.rbegin(), | ||
rInput.rend(), | ||
IsNotPaddingCharacter).base(), | ||
rInput.end()); | ||
rInput.erase(std::find(rInput.begin(), rInput.end(), '\0'), rInput.end()); | ||
} | ||
|
||
|
@@ -330,7 +346,7 @@ auto GetGroupsByFamily( | |
// split the goup names | ||
for (int i = 0; i < num_groups; i++) { | ||
group_names[i] = c_group_names.substr(i * MED_LNAME_SIZE, MED_LNAME_SIZE); | ||
RemoveTrailingNullChars(group_names[i]); | ||
RemovePadding(group_names[i]); | ||
} | ||
|
||
groups_by_family[family_number] = std::move(group_names); | ||
|
@@ -424,7 +440,7 @@ class MedModelPartIO::MedFileHandler | |
axis_unit.data()); | ||
CheckMEDErrorCode(err, "MEDmeshInfo"); | ||
|
||
RemoveTrailingNullChars(mMeshName); | ||
RemovePadding(mMeshName); | ||
mDimension = space_dim; | ||
} | ||
|
||
|
@@ -498,13 +514,14 @@ void MedModelPartIO::ReadModelPart(ModelPart& rThisModelPart) | |
const int dimension = mpFileHandler->GetDimension(); | ||
|
||
// read family info => Map from family number to group names aka SubModelPart names | ||
const auto groups_by_fam = GetGroupsByFamily( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it |
||
auto groups_by_fam = GetGroupsByFamily( | ||
mpFileHandler->GetFileHandle(), | ||
mpFileHandler->GetMeshName()); | ||
|
||
// create SubModelPart hierarchy | ||
for (const auto& r_map : groups_by_fam) { | ||
for (const auto& r_smp_name : r_map.second) { | ||
for (auto& r_map : groups_by_fam) { | ||
for (auto& r_smp_name : r_map.second) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftovers ... |
||
RemovePadding(r_smp_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think this is still necessary, since the group names are already cleaned in L349 (see above) |
||
if (!rThisModelPart.HasSubModelPart(r_smp_name)) { | ||
rThisModelPart.CreateSubModelPart(r_smp_name); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm this looks now like a pretty good addition to the StringUtilities
Could you please add it? I can review fast ;)
Not a blocker, we can also merge this one first.
Ideally this should have tests, but would not fit the current structure of the code, but once it is in the StringUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #12225