Skip to content

Commit a291924

Browse files
authored
Merge pull request #4400 from roystgnr/get_uninitialized_info
Fix System::get_info() on uninitialized systems
2 parents 4822278 + b4a4189 commit a291924

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/systems/system.C

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,18 +1881,23 @@ std::string System::get_info() const
18811881

18821882
oss << '\n';
18831883

1884-
oss << " n_dofs()=" << this->n_dofs() << '\n';
1885-
dof_id_type local_dofs = this->n_local_dofs();
1886-
oss << " n_local_dofs()=" << local_dofs << '\n';
1887-
this->comm().max(local_dofs);
1888-
oss << " max(n_local_dofs())=" << local_dofs << '\n';
1884+
if (this->is_initialized())
1885+
{
1886+
oss << " n_dofs()=" << this->n_dofs() << '\n';
1887+
dof_id_type local_dofs = this->n_local_dofs();
1888+
oss << " n_local_dofs()=" << local_dofs << '\n';
1889+
this->comm().max(local_dofs);
1890+
oss << " max(n_local_dofs())=" << local_dofs << '\n';
18891891
#ifdef LIBMESH_ENABLE_CONSTRAINTS
1890-
oss << " n_constrained_dofs()=" << this->n_constrained_dofs() << '\n';
1891-
oss << " n_local_constrained_dofs()=" << this->n_local_constrained_dofs() << '\n';
1892-
dof_id_type local_unconstrained_dofs = this->n_local_dofs() - this->n_local_constrained_dofs();
1893-
this->comm().max(local_unconstrained_dofs);
1894-
oss << " max(local unconstrained dofs)=" << local_unconstrained_dofs << '\n';
1892+
oss << " n_constrained_dofs()=" << this->n_constrained_dofs() << '\n';
1893+
oss << " n_local_constrained_dofs()=" << this->n_local_constrained_dofs() << '\n';
1894+
dof_id_type local_unconstrained_dofs = this->n_local_dofs() - this->n_local_constrained_dofs();
1895+
this->comm().max(local_unconstrained_dofs);
1896+
oss << " max(local unconstrained dofs)=" << local_unconstrained_dofs << '\n';
18951897
#endif
1898+
}
1899+
else
1900+
oss << " (still uninitialized)\n";
18961901

18971902
oss << " " << "n_vectors()=" << this->n_vectors() << '\n';
18981903
oss << " " << "n_matrices()=" << this->n_matrices() << '\n';

tests/systems/systems_test.C

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ public:
445445

446446
CPPUNIT_TEST( test100KVariables );
447447

448+
CPPUNIT_TEST( testUninitializedInfo );
449+
448450
CPPUNIT_TEST( testPostInitAddVector );
449451
CPPUNIT_TEST( testAddVectorProjChange );
450452
CPPUNIT_TEST( testAddVectorTypeChange );
@@ -661,6 +663,17 @@ public:
661663
CPPUNIT_ASSERT_EQUAL(sys.get_dof_map().n_dofs(888), dof_id_type(5));
662664
}
663665

666+
void testUninitializedInfo()
667+
{
668+
Mesh mesh(*TestCommWorld);
669+
EquationSystems es(mesh);
670+
ExplicitSystem & sys = simpleSetup(mesh, es);
671+
672+
auto info = sys.get_info();
673+
674+
CPPUNIT_ASSERT (info.find("uninitialized") != std::string::npos);
675+
}
676+
664677

665678
void testPostInitAddVector()
666679
{

0 commit comments

Comments
 (0)