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

Add an input consistency check. #5209

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Particle/ParticleIO/XMLParticleIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@
}

if (ntot > 0 && num_non_zero_group != nat_group.size())
throw UniformCommunicateError("Some 'group' XML element node doesn't contain a 'size' attribute! 'size = 0' is not allowed in the input. Make appropriate adjustments to the input or converter.");
throw UniformCommunicateError(

Check warning on line 181 in src/Particle/ParticleIO/XMLParticleIO.cpp

View check run for this annotation

Codecov / codecov/patch

src/Particle/ParticleIO/XMLParticleIO.cpp#L181

Added line #L181 was not covered by tests
"Some 'group' XML element node doesn't contain a 'size' attribute! 'size = 0' is not allowed in the input. "
"Make appropriate adjustments to the input or converter.");
}

{ // parse all the 'attrib's to obtain or verify the total number of particles
Expand Down Expand Up @@ -441,13 +443,19 @@
pAttrib.add(utype, condition_tag); //condition
pAttrib.add(size_in, "size"); //size
pAttrib.put(cur);

if (oname.empty() || otype.empty())
{
app_error() << " Missing attrib/@name or attrib/@datatype " << std::endl;
app_error() << R"( <attrib name="aname" datatype="atype"/>)" << std::endl;
return;
}
int t_id = ref_AttribList.getAttribType(otype);

if (utype == 1 && !ref_.getLattice().explicitly_defined)
throw UniformCommunicateError(
"Fractional coordinates cannot be used without an explicit lattice in the <simulationcell/>!");

const int t_id = ref_AttribList.getAttribType(otype);

if (oname == ionid_tag)
throw UniformCommunicateError("'ionid' should not be parsed by getPtclAttrib.");
Expand Down
23 changes: 21 additions & 2 deletions src/Particle/ParticleIO/tests/test_xml_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ namespace qmcplusplus
{
TEST_CASE("read_particleset_xml", "[particle_io][xml]")
{
const char* particles_frac = R"(
<particleset name="ion0" size="1">
<group name="He">
<parameter name="charge">2</parameter>
</group>
<attrib name="position" datatype="posArray" condition="1">
0.1 0.2 0.3
</attrib>
</particleset>
)";
Libxml2Document doc_frac;
REQUIRE(doc_frac.parseFromString(particles_frac));

const SimulationCell simulation_cell;
ParticleSet ions_bad(simulation_cell);

XMLParticleParser parse_ions_bad(ions_bad);
REQUIRE_THROWS_WITH(parse_ions_bad.readXML(doc_frac.getRoot()),
"Fractional coordinates cannot be used without an explicit lattice in the <simulationcell/>!");

const char* particles = R"(<tmp>
<particleset name="ion0" size="1">
<group name="He">
Expand Down Expand Up @@ -57,12 +77,11 @@ TEST_CASE("read_particleset_xml", "[particle_io][xml]")
REQUIRE(okay);

xmlNodePtr root = doc.getRoot();
xmlNodePtr part1 = xmlFirstElementChild(root);

const SimulationCell simulation_cell;
ParticleSet ions(simulation_cell), electrons(simulation_cell);

XMLParticleParser parse_ions(ions);
xmlNodePtr part1 = xmlFirstElementChild(root);
parse_ions.readXML(part1);

REQUIRE(ions.groups() == 1);
Expand Down
Loading