Skip to content

Commit

Permalink
Debug ci fix (chaos-polymtl#1247)
Browse files Browse the repository at this point in the history
Description
There were some asserts being thrown in debug mode. These asserts were all warrented.
They were cuased by the following:
1- std::shared_ptr cannot be created from a nullptr. Since the sharp edge in the tracer relies on this mechanism to assess if there is or not a shape, this was highly problematic. @oguevremont we will need to look more into this and refactor this more cleanly in the next month. I have made a solution using regular pointers which is fine, but relying on nullptr is not very nice in my opinion
2- There was an std::vector that was not used correctly in the find cell around flat mechanism
3- In the restart for sharp edge, the order of the checks was not done in the right order which violated the size issue.

Solution
Fixed all of those bugs.

Testing
Debug tests should pass now.

Former-commit-id: b255a9e
  • Loading branch information
blaisb authored Aug 18, 2024
1 parent 18d34a5 commit 190b5b1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 51 deletions.
8 changes: 5 additions & 3 deletions include/solvers/multiphysics_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,16 @@ class MultiphysicsInterface
/**
* @brief Request immersed solid signed distance function
*/
std::shared_ptr<Function<dim>>
Function<dim> *
get_immersed_solid_signed_distance_function();

/**
* @brief Share immersed solid signed distance function
*
* @param function The immersed solid signed distance function
*/
void
set_immersed_solid_signed_distance_function(std::shared_ptr<Function<dim>>);
set_immersed_solid_signed_distance_function(Function<dim> *function);

/**
* @brief Request the previous solutions of a given physics
Expand Down Expand Up @@ -921,7 +923,7 @@ class MultiphysicsInterface
GlobalVectorType *reynolds_stress_solutions;

// Immersed solid signed distance function to be used by auxiliary physics
std::shared_ptr<Function<dim>> immersed_solid_signed_distance_function;
Function<dim> *immersed_solid_signed_distance_function;

// past (minus 1) solution
std::map<PhysicsID, GlobalVectorType *> physics_solutions_m1;
Expand Down
3 changes: 0 additions & 3 deletions include/solvers/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,6 @@ class Tracer : public AuxiliaryPhysics<dim, GlobalVectorType>
AffineConstraints<double> zero_constraints;
TrilinosWrappers::SparseMatrix system_matrix;

// Immersed solid signed distance function with immersed solid solver
std::shared_ptr<Function<dim>> immersed_solid_signed_distance_function;

// Previous solutions vectors
std::vector<GlobalVectorType> previous_solutions;

Expand Down
10 changes: 9 additions & 1 deletion include/solvers/tracer_scratch_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,16 @@ class TracerScratchData
auto &fe_tracer = this->fe_values_tracer.get_fe();

source_function->value_list(quadrature_points, source);

if (properties_manager.field_is_required(field::levelset))
levelset_function->value_list(quadrature_points, sdf_values);
{
Assert(
levelset_function != nullptr,
ExcMessage(
"Levelset function is required for tracer assembly, but the level set function is a nullptr"));

levelset_function->value_list(quadrature_points, sdf_values);
}

if (dim == 2)
this->cell_size =
Expand Down
1 change: 0 additions & 1 deletion source/core/lethe_grid_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,6 @@ LetheGridTools::cell_cut_by_flat(
if (condition_B2)
{
bool condition_C2 = false;
manifold_points.clear();
for (const auto face : cell->face_indices())
{
auto face_iter = cell->face(face);
Expand Down
12 changes: 6 additions & 6 deletions source/fem-dem/fluid_dynamics_sharp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ FluidDynamicsSharp<dim>::define_particles()
combined_shapes =
std::make_shared<CompositeShape<dim>>(all_shapes, Point<dim>(), Point<3>());
this->multiphysics->set_immersed_solid_signed_distance_function(
combined_shapes);
&(*combined_shapes));
}


Expand Down Expand Up @@ -4341,15 +4341,15 @@ FluidDynamicsSharp<dim>::read_checkpoint()
std::map<std::string, std::vector<double>> restart_data;
fill_vectors_from_file(restart_data, filename);

// Implement the data in the particles.
// Implement the data in the particles.
if constexpr (dim == 2)
{
unsigned int row = 0;
for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
{
unsigned int j = 0;
while (restart_data["ID"][row] == p_i and
row < restart_data["ID"].size())
while (row < restart_data["ID"].size() &&
restart_data["ID"][row] == p_i)
{
if (j == 0)
{
Expand Down Expand Up @@ -4415,8 +4415,8 @@ FluidDynamicsSharp<dim>::read_checkpoint()
for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
{
unsigned int j = 0;
while (restart_data["ID"][row] == p_i and
row < restart_data["ID"].size())
while (row < restart_data["ID"].size() &&
restart_data["ID"][row] == p_i)
{
if (j == 0)
{
Expand Down
8 changes: 4 additions & 4 deletions source/solvers/multiphysics_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,20 @@ MultiphysicsInterface<dim>::get_projected_phase_fraction_gradient_dof_handler()
}

template <int dim>
std::shared_ptr<Function<dim>>
Function<dim> *
MultiphysicsInterface<dim>::get_immersed_solid_signed_distance_function()
{
// This pointer is also used to check if an immersed boundary solid method is
// being used, depending on whether the pointer is assigned.
return this->immersed_solid_signed_distance_function;
return immersed_solid_signed_distance_function;
}

template <int dim>
void
MultiphysicsInterface<dim>::set_immersed_solid_signed_distance_function(
std::shared_ptr<Function<dim>> function)
Function<dim> *function)
{
this->immersed_solid_signed_distance_function = function;
immersed_solid_signed_distance_function = function;
}

template <int dim>
Expand Down
46 changes: 21 additions & 25 deletions source/solvers/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ Tracer<dim>::assemble_system_matrix()
this->system_matrix = 0;
setup_assemblers();

// We get the immersed function, which is null when no immersed solids are
// involved.
immersed_solid_signed_distance_function =
this->multiphysics->get_immersed_solid_signed_distance_function();
// Update the source term time
simulation_parameters.source_term.tracer_source->set_time(
simulation_control->get_current_time());

const DoFHandler<dim> *dof_handler_fluid =
multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
Expand Down Expand Up @@ -89,14 +88,13 @@ Tracer<dim>::assemble_local_system_matrix(
if (!cell->is_locally_owned())
return;

auto source_term = simulation_parameters.source_term.tracer_source;
source_term->set_time(simulation_control->get_current_time());

scratch_data.reinit(cell,
this->evaluation_point,
this->previous_solutions,
&(*source_term),
&(*immersed_solid_signed_distance_function));
scratch_data.reinit(
cell,
this->evaluation_point,
this->previous_solutions,
&(*simulation_parameters.source_term.tracer_source),
&(*this->multiphysics->get_immersed_solid_signed_distance_function()));

const DoFHandler<dim> *dof_handler_fluid =
multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
Expand Down Expand Up @@ -193,10 +191,9 @@ Tracer<dim>::assemble_system_rhs()
this->system_rhs = 0;
setup_assemblers();

// We get the immersed function, which is null when no immersed solids are
// involved
immersed_solid_signed_distance_function =
this->multiphysics->get_immersed_solid_signed_distance_function();
// Update the source term time
simulation_parameters.source_term.tracer_source->set_time(
simulation_control->get_current_time());

const DoFHandler<dim> *dof_handler_fluid =
multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
Expand Down Expand Up @@ -234,11 +231,12 @@ Tracer<dim>::assemble_local_system_rhs(
auto source_term = simulation_parameters.source_term.tracer_source;
source_term->set_time(simulation_control->get_current_time());

scratch_data.reinit(cell,
this->evaluation_point,
this->previous_solutions,
&(*source_term),
&(*immersed_solid_signed_distance_function));
scratch_data.reinit(
cell,
this->evaluation_point,
this->previous_solutions,
&(*source_term),
(this->multiphysics->get_immersed_solid_signed_distance_function()));

const DoFHandler<dim> *dof_handler_fluid =
multiphysics->get_dof_handler(PhysicsID::fluid_dynamics);
Expand Down Expand Up @@ -650,11 +648,9 @@ Tracer<dim>::postprocess_tracer_flow_rate(const VectorType &current_solution_fd)
n_q_points_face));
face_quadrature_points =
fe_face_values_tracer.get_quadrature_points();
immersed_solid_signed_distance_function =
this->multiphysics
->get_immersed_solid_signed_distance_function();
this->immersed_solid_signed_distance_function->value_list(
face_quadrature_points, levelset_values);
this->multiphysics
->get_immersed_solid_signed_distance_function()
->value_list(face_quadrature_points, levelset_values);
set_field_vector(field::levelset,
levelset_values,
fields);
Expand Down
9 changes: 2 additions & 7 deletions tests/core/lethe_grid_tool_mesh_cut_by_flat_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,10 @@ test()
<< std::endl;
}

// Printing the final position for all the vertices

#if (DEAL_II_VERSION_MAJOR < 10 && DEAL_II_VERSION_MINOR < 4)
Legacy::DataOut<2> data_out;
Legacy::DataOut<1, DoFHandler<1, 2>> flat_data_out;
#else
// Printing the final position for all the vertices
DataOut<2> data_out;
DataOut<1, 2> flat_data_out;
#endif

data_out.attach_dof_handler(dof_handler);
data_out.add_data_vector(subdomain, "subdomain");
data_out.build_patches();
Expand Down
1 change: 0 additions & 1 deletion tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <deal.II/base/config.h>

#include <deal.II/base/cuda.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/job_identifier.h>
#include <deal.II/base/logstream.h>
Expand Down

0 comments on commit 190b5b1

Please sign in to comment.