Skip to content

Commit

Permalink
Removing Problem::get_mesh
Browse files Browse the repository at this point in the history
- this API was removed in favor of `DiscreteProblemInterface::get_mesh` which
  is used more often in the child classes and gives back the UnstructiredMesh,
  which is what the application code uses.
- VTKOutput and TecplotOutput were updated so they match what is going on in
  the ExodusIIOutput.
  • Loading branch information
andrsd committed Jan 20, 2025
1 parent ae3b384 commit 3de30ff
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 63 deletions.
6 changes: 5 additions & 1 deletion include/godzilla/DiscreteProblemInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BoundaryCondition;
class AuxiliaryField;
class EssentialBC;
class NaturalBC;
class MeshObject;

/// Interface for discrete problems
///
Expand Down Expand Up @@ -62,7 +63,7 @@ class DiscreteProblemInterface {
virtual ~DiscreteProblemInterface();

/// Get unstructured mesh associated with this problem
UnstructuredMesh * get_unstr_mesh() const;
UnstructuredMesh * get_mesh() const;

/// Get problem
///
Expand Down Expand Up @@ -448,6 +449,9 @@ class DiscreteProblemInterface {
/// Problem this interface is part of
Problem * problem;

/// Mesh object
MeshObject * mesh_obj;

/// Unstructured mesh
UnstructuredMesh * unstr_mesh;

Expand Down
3 changes: 0 additions & 3 deletions include/godzilla/Problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ class Problem : public Object, public PrintInterface {
const Vector & get_solution_vector() const;
Vector & get_solution_vector();

/// Get mesh this problem is using
virtual Mesh * get_mesh() const;

/// Get problem spatial dimension
Int get_dimension() const;

Expand Down
2 changes: 1 addition & 1 deletion src/AuxiliaryField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void
AuxiliaryField::create()
{
CALL_STACK_MSG();
this->mesh = this->dpi->get_unstr_mesh();
this->mesh = this->dpi->get_mesh();
if (!this->region.empty()) {
if (this->mesh->has_label(this->region)) {
this->label = this->mesh->get_label(this->region);
Expand Down
20 changes: 10 additions & 10 deletions src/DGProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DGProblemInterface::init()
create_fe(it.second);
DiscreteProblemInterface::init();

auto dm = get_unstr_mesh()->get_dm();
auto dm = get_mesh()->get_dm();

Check warning on line 45 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L45

Added line #L45 was not covered by tests
DM cdm = dm;
while (cdm) {
set_up_auxiliary_dm(cdm);
Expand Down Expand Up @@ -362,7 +362,7 @@ DGProblemInterface::set_aux_field(Int id,
Int
DGProblemInterface::get_num_nodes_per_elem(Int c) const
{
auto unstr_mesh = get_unstr_mesh();
auto unstr_mesh = get_mesh();

Check warning on line 365 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L365

Added line #L365 was not covered by tests
auto ct = unstr_mesh->get_cell_type(c);
auto n_nodes = UnstructuredMesh::get_num_cell_nodes(ct);
return n_nodes;
Expand Down Expand Up @@ -397,23 +397,23 @@ DGProblemInterface::create()
CALL_STACK_MSG();
set_up_fields();
DiscreteProblemInterface::create();
get_unstr_mesh()->localize_coordinates();
get_mesh()->localize_coordinates();

Check warning on line 400 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L400

Added line #L400 was not covered by tests
}

void
DGProblemInterface::set_up_ds()
{
CALL_STACK_MSG();
create_section();
PETSC_CHECK(DMSetAdjacency(get_unstr_mesh()->get_dm(), 0, PETSC_TRUE, PETSC_FALSE));
PETSC_CHECK(DMSetAdjacency(get_mesh()->get_dm(), 0, PETSC_TRUE, PETSC_FALSE));

Check warning on line 408 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L408

Added line #L408 was not covered by tests
}

void
DGProblemInterface::create_section()
{
CALL_STACK_MSG();
auto comm = get_problem()->get_comm();
auto unstr_mesh = get_unstr_mesh();
auto unstr_mesh = get_mesh();

Check warning on line 416 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L416

Added line #L416 was not covered by tests
auto dm = unstr_mesh->get_dm();
PETSC_CHECK(DMSetNumFields(dm, 1));
Section section;
Expand Down Expand Up @@ -446,7 +446,7 @@ void
DGProblemInterface::set_up_section_constraint_dofs(Section & section)
{
CALL_STACK_MSG();
auto unstr_mesh = get_unstr_mesh();
auto unstr_mesh = get_mesh();

Check warning on line 449 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L449

Added line #L449 was not covered by tests

auto depth_label = unstr_mesh->get_depth_label();
auto dim = unstr_mesh->get_dimension();
Expand Down Expand Up @@ -481,7 +481,7 @@ void
DGProblemInterface::set_up_section_constraint_indicies(Section & section)
{
CALL_STACK_MSG();
auto unstr_mesh = get_unstr_mesh();
auto unstr_mesh = get_mesh();

Check warning on line 484 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L484

Added line #L484 was not covered by tests

auto depth_label = unstr_mesh->get_depth_label();
Int dim = unstr_mesh->get_dimension();
Expand Down Expand Up @@ -538,7 +538,7 @@ DGProblemInterface::create_aux_fields()
section_aux.set_num_field_components(fi.id, fi.nc);
}

auto unstr_mesh = get_unstr_mesh();
auto unstr_mesh = get_mesh();

Check warning on line 541 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L541

Added line #L541 was not covered by tests
auto cell_range = unstr_mesh->get_cell_range();
section_aux.set_chart(cell_range.first(), cell_range.last());
for (Int c = cell_range.first(); c < cell_range.last(); c++) {
Expand Down Expand Up @@ -573,9 +573,9 @@ void
DGProblemInterface::create_fe(FieldInfo & fi)
{
CALL_STACK_MSG();
auto comm = get_unstr_mesh()->get_comm();
auto comm = get_mesh()->get_comm();

Check warning on line 576 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L576

Added line #L576 was not covered by tests
Int dim = get_problem()->get_dimension();
PetscBool is_simplex = get_unstr_mesh()->is_simplex() ? PETSC_TRUE : PETSC_FALSE;
PetscBool is_simplex = get_mesh()->is_simplex() ? PETSC_TRUE : PETSC_FALSE;

Check warning on line 578 in src/DGProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DGProblemInterface.cpp#L578

Added line #L578 was not covered by tests
PETSC_CHECK(PetscFECreateLagrange(comm, dim, fi.nc, is_simplex, fi.k, this->qorder, &fi.fe));
}

Expand Down
18 changes: 11 additions & 7 deletions src/DiscreteProblemInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 David Andrs <[email protected]>
// SPDX-License-Identifier: MIT

#include "godzilla/MeshObject.h"
#include "godzilla/Parameters.h"
#include "godzilla/CallStack.h"
#include "godzilla/App.h"
Expand All @@ -12,6 +13,7 @@
#include "godzilla/AuxiliaryField.h"
#include "godzilla/NaturalBC.h"
#include "godzilla/Exception.h"
#include "godzilla/UnstructuredMesh.h"
#include <set>
#include <cassert>

Expand Down Expand Up @@ -61,6 +63,7 @@ DiscreteProblemInterface::invoke_natural_riemann_bc_delegate(Real time,

DiscreteProblemInterface::DiscreteProblemInterface(Problem * problem, const Parameters & params) :
problem(problem),
mesh_obj(params.get<MeshObject *>("_mesh_obj")),
unstr_mesh(nullptr),
logger(params.get<App *>("_app")->get_logger()),
ds(nullptr),
Expand Down Expand Up @@ -182,7 +185,7 @@ DiscreteProblemInterface::get_aux(const std::string & name) const
}

UnstructuredMesh *
DiscreteProblemInterface::get_unstr_mesh() const
DiscreteProblemInterface::get_mesh() const
{
CALL_STACK_MSG();
return this->unstr_mesh;
Expand Down Expand Up @@ -230,10 +233,11 @@ DiscreteProblemInterface::distribute()
auto part = this->problem->get_partitioner();
part.set_up();

// cannot use `get_unstr_mesh`, since this may be called before the `create` calls
auto unstr_mesh = dynamic_cast<UnstructuredMesh *>(this->problem->get_mesh());
unstr_mesh->set_partitioner(part);
unstr_mesh->distribute(this->problem->get_partition_overlap());
// cannot use `get_mesh`, since this may be called before the `create` calls
auto mesh = this->mesh_obj->get_mesh<UnstructuredMesh>();
assert(mesh != nullptr);
mesh->set_partitioner(part);
mesh->distribute(this->problem->get_partition_overlap());

Check warning on line 240 in src/DiscreteProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DiscreteProblemInterface.cpp#L237-L240

Added lines #L237 - L240 were not covered by tests
}

void
Expand All @@ -250,7 +254,7 @@ DiscreteProblemInterface::create()
{
CALL_STACK_MSG();
assert(this->problem != nullptr);
this->unstr_mesh = dynamic_cast<UnstructuredMesh *>(problem->get_mesh());
this->unstr_mesh = this->mesh_obj->get_mesh<UnstructuredMesh>();
assert(this->unstr_mesh != nullptr);

for (auto & ic : this->all_ics)
Expand Down Expand Up @@ -506,7 +510,7 @@ DiscreteProblemInterface::compute_aux_fields()
const std::vector<AuxiliaryField *> & auxs = it.second;
Label label;
if (!region_name.empty())
label = get_unstr_mesh()->get_label(region_name);
label = get_mesh()->get_label(region_name);

Check warning on line 513 in src/DiscreteProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/DiscreteProblemInterface.cpp#L513

Added line #L513 was not covered by tests

if (label.is_null())
compute_global_aux_fields(this->dm_aux, auxs, this->a);
Expand Down
5 changes: 3 additions & 2 deletions src/ExodusIIOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "godzilla/Postprocessor.h"
#include "godzilla/IndexSet.h"
#include "godzilla/Exception.h"
#include "godzilla/MeshObject.h"
#include "exodusIIcpp/exodusIIcpp.h"
#include "fmt/format.h"
#include "fmt/chrono.h"
Expand Down Expand Up @@ -143,8 +144,8 @@ ExodusIIOutput::create()
CALL_STACK_MSG();
FileOutput::create();

this->mesh = get_problem() ? dynamic_cast<UnstructuredMesh *>(get_problem()->get_mesh())
: get_param<UnstructuredMesh *>("_mesh");
this->mesh = this->dpi ? this->dpi->get_mesh()
: get_param<MeshObject *>("_mesh_obj")->get_mesh<UnstructuredMesh>();
if (this->mesh == nullptr)
log_error("ExodusII output can be only used with unstructured meshes.");

Expand Down
2 changes: 1 addition & 1 deletion src/ExplicitFELinearProblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ExplicitFELinearProblem::compute_rhs_function_fem(Real time, const Vector & loc_
{
// this is based on DMPlexTSComputeRHSFunctionFEM()
CALL_STACK_MSG();
IndexSet all_cells = get_unstr_mesh()->get_all_cells();
auto all_cells = get_mesh()->get_all_cells();

for (auto region : get_weak_form()->get_residual_regions()) {
IndexSet cells;
Expand Down
12 changes: 6 additions & 6 deletions src/FENonlinearProblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ FENonlinearProblem::compute_residual_local(const Vector & x, Vector & f)
{
CALL_STACK_MSG();
// this is based on DMSNESComputeResidual()
IndexSet all_cells = get_unstr_mesh()->get_all_cells();
auto all_cells = get_mesh()->get_all_cells();

for (auto & region : get_weak_form()->get_residual_regions()) {
IndexSet cells;
Expand Down Expand Up @@ -374,8 +374,8 @@ FENonlinearProblem::compute_bnd_residual_internal(DM dm, Vec loc_x, Vec loc_x_t,

PetscDS prob;
PETSC_CHECK(DMGetDS(dm, &prob));
auto depth_label = get_unstr_mesh()->get_depth_label();
Int dim = get_unstr_mesh()->get_dimension();
auto depth_label = get_mesh()->get_depth_label();
Int dim = get_dimension();
auto facets = depth_label.get_stratum(dim - 1);
Int n_bnd;
PETSC_CHECK(PetscDSGetNumBoundary(prob, &n_bnd));
Expand Down Expand Up @@ -580,7 +580,7 @@ FENonlinearProblem::compute_jacobian_local(const Vector & x, Matrix & J, Matrix
{
CALL_STACK_MSG();
// based on DMPlexSNESComputeJacobianFEM and DMSNESComputeJacobianAction
IndexSet all_cells = get_unstr_mesh()->get_all_cells();
auto all_cells = get_mesh()->get_all_cells();

auto wf = get_weak_form();
auto has_jac = wf->has_jacobian();
Expand Down Expand Up @@ -879,8 +879,8 @@ FENonlinearProblem::compute_bnd_jacobian_internal(DM dm,
CALL_STACK_MSG();
PetscDS prob;
PETSC_CHECK(DMGetDS(dm, &prob));
auto depth_label = get_unstr_mesh()->get_depth_label();
Int dim = get_unstr_mesh()->get_dimension();
auto depth_label = get_mesh()->get_depth_label();
Int dim = get_dimension();
auto facets = depth_label.get_stratum(dim - 1);
Int n_bnd;
PETSC_CHECK(PetscDSGetNumBoundary(prob, &n_bnd));
Expand Down
20 changes: 10 additions & 10 deletions src/FEProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ FEProblemInterface::create()
this->asmbl = new AssemblyData(dim);
set_up_fields();
DiscreteProblemInterface::create();
get_unstr_mesh()->localize_coordinates();
get_mesh()->localize_coordinates();
}

void
Expand All @@ -105,7 +105,7 @@ FEProblemInterface::init()

DiscreteProblemInterface::init();

auto dm = get_unstr_mesh()->get_dm();
auto dm = get_mesh()->get_dm();
DM cdm = dm;
while (cdm) {
set_up_auxiliary_dm(cdm);
Expand Down Expand Up @@ -447,17 +447,17 @@ void
FEProblemInterface::create_fe(FieldInfo & fi)
{
CALL_STACK_MSG();
auto comm = get_unstr_mesh()->get_comm();
auto comm = get_mesh()->get_comm();
Int dim = get_problem()->get_dimension();
PetscBool is_simplex = get_unstr_mesh()->is_simplex() ? PETSC_TRUE : PETSC_FALSE;
PetscBool is_simplex = get_mesh()->is_simplex() ? PETSC_TRUE : PETSC_FALSE;
PETSC_CHECK(PetscFECreateLagrange(comm, dim, fi.nc, is_simplex, fi.k, this->qorder, &fi.fe));
}

void
FEProblemInterface::set_up_ds()
{
CALL_STACK_MSG();
auto dm = get_unstr_mesh()->get_dm();
auto dm = get_mesh()->get_dm();
for (auto & it : this->fields) {
FieldInfo & fi = it.second;
PETSC_CHECK(DMSetField(dm, fi.id, fi.block, (PetscObject) fi.fe));
Expand Down Expand Up @@ -717,7 +717,7 @@ FEProblemInterface::add_residual_block(Int field_id,
add_weak_form_residual_block(WeakForm::F1, field_id, f1);
}
else {
auto label = get_unstr_mesh()->get_label(region);
auto label = get_mesh()->get_label(region);

Check warning on line 720 in src/FEProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/FEProblemInterface.cpp#L720

Added line #L720 was not covered by tests
auto ids = label.get_values();
for (auto & val : ids) {
add_weak_form_residual_block(WeakForm::F0, field_id, f0, label, val, 0);
Expand All @@ -735,7 +735,7 @@ FEProblemInterface::add_boundary_residual_block(Int field_id,
CALL_STACK_MSG();
assert(!boundary.empty());

auto label = get_unstr_mesh()->get_label(boundary);
auto label = get_mesh()->get_label(boundary);
auto ids = label.get_values();
for (auto & val : ids) {
add_weak_form_residual_block(WeakForm::BND_F0, field_id, f0, label, val, 0);
Expand All @@ -760,7 +760,7 @@ FEProblemInterface::add_jacobian_block(Int fid,
add_weak_form_jacobian_block(WeakForm::G3, fid, gid, g3);
}
else {
auto label = get_unstr_mesh()->get_label(region);
auto label = get_mesh()->get_label(region);

Check warning on line 763 in src/FEProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/FEProblemInterface.cpp#L763

Added line #L763 was not covered by tests
auto ids = label.get_values();
for (auto & val : ids) {
add_weak_form_jacobian_block(WeakForm::G0, fid, gid, g0, label, val, 0);
Expand Down Expand Up @@ -788,7 +788,7 @@ FEProblemInterface::add_jacobian_preconditioner_block(Int fid,
add_weak_form_jacobian_block(WeakForm::GP3, fid, gid, g3);
}
else {
auto label = get_unstr_mesh()->get_label(region);
auto label = get_mesh()->get_label(region);

Check warning on line 791 in src/FEProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/FEProblemInterface.cpp#L791

Added line #L791 was not covered by tests
auto ids = label.get_values();
for (auto & val : ids) {
add_weak_form_jacobian_block(WeakForm::GP0, fid, gid, g0, label, val, 0);
Expand All @@ -811,7 +811,7 @@ FEProblemInterface::add_boundary_jacobian_block(Int fid,
CALL_STACK_MSG();
assert(!region.empty());

auto label = get_unstr_mesh()->get_label(region);
auto label = get_mesh()->get_label(region);
auto ids = label.get_values();
for (auto & val : ids) {
add_weak_form_jacobian_block(WeakForm::BND_G0, fid, gid, g0, label, val, 0);
Expand Down
Loading

0 comments on commit 3de30ff

Please sign in to comment.