Skip to content

[Obsolete] A new composition parser for all features#926

Closed
alanjyu wants to merge 3 commits into
GeodynamicWorldBuilder:mainfrom
alanjyu:composition_name_parse
Closed

[Obsolete] A new composition parser for all features#926
alanjyu wants to merge 3 commits into
GeodynamicWorldBuilder:mainfrom
alanjyu:composition_name_parse

Conversation

@alanjyu
Copy link
Copy Markdown
Contributor

@alanjyu alanjyu commented Mar 30, 2026

WARNING: "Parameter::composition_properties" (struct) has been renamed to "composition_property" (storing index, name, density, etc. for one composition), while the global composition_properties (vector) indicates the user defined table. These two were named the same in the previous push request.

Users now can assign a composition field using a name (string) that they define in the composition_properties table. The name will be parsed and linked to the corresponding composition index (and default properties). The name output function (what you see in ParaView) has not been updated yet.

@alanjyu alanjyu force-pushed the composition_name_parse branch from 2be23d5 to e468287 Compare March 30, 2026 21:37
Copy link
Copy Markdown
Contributor

@danieldouglas92 danieldouglas92 left a comment

Choose a reason for hiding this comment

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

Hey @alanjyu thanks for this! If I'm understanding correctly, a lot of these changes here are just renaming what you added in PR #909, and then the new get_vector() function you added in parameters.cc is the new feature here? I didn't get a chance to look at #909, but I think being able to set compositions in the world builder file with a string will be a very nice quality of life improvement. I've forgotten so many times what index number N in some of my large world builder files is actually supposed to correspond to.

Anyway, if what I said above is correct and it's not too much of a hassle, I would just open up a very quick PR that only renames Parameters::composition_properties to Parameters::composition_property.

I think the new parser function looks good, I only had a clarification comment about the modification you made to the existing get_vector parser.

Comment thread doc/world_builder_declarations.tex Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You'll have to delete this file (hopefully now that #927 has been merged it will never be an issue🤞)

Comment on lines +1996 to +2045
template<>
std::vector<unsigned int>
Parameters::get_vector(const std::string &name,
const std::vector<Parameters::composition_property> &composition_properties)
{
std::vector<unsigned int> vector;
const std::string strict_base = this->get_full_json_path();
if (Pointer((strict_base + "/" + name).c_str()).Get(parameters) != nullptr)
{
Value *array = Pointer((strict_base + "/" + name).c_str()).Get(parameters);

for (size_t i = 0; i < array->Size(); ++i )
{
const std::string base = (strict_base + "/").append(name).append("/").append(std::to_string(i));
Value *entry = Pointer(base.c_str()).Get(parameters);

// user can define either an index (usigned int)
// or a compositon name (string)
// if latter, assign the corresponding index in the composition properties
if (entry->IsUint())
{
vector.push_back(entry->GetUint());
}
else if (entry->IsString())
{
const std::string feature_composition_name = entry->GetString();
bool isFoundInCompositionProperties = false;

for (const Parameters::composition_property &global_composition : composition_properties)
{
// compare globally defined composition name
// with feature-defined composition name
// and assign the corresponding index if found
if (global_composition.name == feature_composition_name)
{
vector.push_back(global_composition.index);
isFoundInCompositionProperties = true;
break;
}
}
WBAssertThrow(isFoundInCompositionProperties,
"internal error: could not find the value \"" << feature_composition_name << "\" in the composition properties at: "
<< this->get_full_json_schema_path() + "/" + name + "/items/enum");
}
else
{
WBAssertThrow(false,
"internal error: expected an unsigned int or a string for the value at: "
<< base);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function that you've added is how you handle the case for the composition being entered as a string instead of an integer. But I'm not sure what you added to the other get_vector function above. Can you add some documentation in that function that describes what the else statement is meant to handle in the function above?

@github-actions
Copy link
Copy Markdown

Benchmark Main Feature Difference (99.9% CI)
Slab interpolation simple none 1.171 ± 0.006 (s=390) 1.176 ± 0.005 (s=379) +0.4% .. +0.6%
Slab interpolation curved simple none 1.308 ± 0.009 (s=356) 1.322 ± 0.007 (s=331) +0.9% .. +1.2%
Spherical slab interpolation simple none 1.280 ± 0.008 (s=363) 1.291 ± 0.007 (s=340) +0.7% .. +0.9%
Slab interpolation simple curved CMS 1.351 ± 0.007 (s=337) 1.368 ± 0.007 (s=328) +1.2% .. +1.4%
Spherical slab interpolation simple CMS 1.516 ± 0.012 (s=279) 1.520 ± 0.010 (s=316) +0.1% .. +0.5%
Spherical fault interpolation simple none 1.301 ± 0.007 (s=357) 1.314 ± 0.008 (s=334) +0.9% .. +1.1%
Cartesian min max surface 3.094 ± 0.012 (s=131) 3.114 ± 0.012 (s=161) +0.5% .. +0.8%
Spherical min max surface 8.607 ± 0.090 (s=54) 8.691 ± 0.095 (s=53) +0.3% .. +1.7%

@MFraters
Copy link
Copy Markdown
Member

Please let us know when it is ready for another round of reviews. Also, I think it would be good to rebase onto the newest main and regenerated the declarations (by running make test).

@alanjyu alanjyu changed the title A new composition parser for all features [Obsolete] A new composition parser for all features Mar 31, 2026
@alanjyu
Copy link
Copy Markdown
Contributor Author

alanjyu commented Mar 31, 2026

Changes are re-applied in a new pull request #934.

@alanjyu alanjyu closed this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants