Skip to content
Open
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
2 changes: 1 addition & 1 deletion opm/grid/cpgrid/CpGridData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ struct CellGeometryHandle
buffer.read(pos[i]);

buffer.read(vol);
scatterCont_[t] = Geom(pos, vol, pointGeom_, cell2Points_[t.index()].data());
scatterCont_[t] = Geom(pos, vol, pointGeom_.get(), cell2Points_[t.index()].data());
double isAquifer;
buffer.read(isAquifer);
if (isAquifer == 1.0)
Expand Down
42 changes: 10 additions & 32 deletions opm/grid/cpgrid/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <dune/common/version.hh>
#include <dune/geometry/type.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/geometry/axisalignedcubegeometry.hh>
#include <dune/grid/common/gridenums.hh>

#include "PartitionTypeIndicator.hpp"
Expand Down Expand Up @@ -130,8 +131,8 @@ class Entity : public EntityRep<codim>
template <int cd>
using Codim = typename Impl::CodimTraits<cd>;

typedef cpgrid::Geometry<3-codim,3> Geometry;
typedef Geometry LocalGeometry;
using Geometry = cpgrid::Geometry<3-codim,3>;
using LocalGeometry = Dune::AxisAlignedCubeGeometry<double,3,3>;

typedef cpgrid::IntersectionIterator LeafIntersectionIterator;
typedef cpgrid::IntersectionIterator LevelIntersectionIterator;
Expand Down Expand Up @@ -193,7 +194,7 @@ class Entity : public EntityRep<codim>
}

/// @brief Return the geometry of the entity (does not depend on its orientation).
const Geometry& geometry() const;
Geometry geometry() const;

/// @brief Return the level of the entity in the grid hierarchy. Level = 0 represents the coarsest grid.
int level() const;
Expand Down Expand Up @@ -284,7 +285,7 @@ class Entity : public EntityRep<codim>
/// Currently, LGR is built via refinement of a block-shaped patch from the coarse grid. So the LocalGeometry
/// of an entity coming from the LGR is one of the refined cells of the unit cube, with suitable amount of cells
/// in each direction.
Dune::cpgrid::Geometry<3,3> geometryInFather() const;
Dune::AxisAlignedCubeGeometry<double,3,3> geometryInFather() const;

/// Returns true if any of my intersections are on the boundary.
/// Implementation note:
Expand Down Expand Up @@ -422,7 +423,7 @@ unsigned int Entity<codim>::subEntities ( const unsigned int cc ) const
}

template <int codim>
const typename Entity<codim>::Geometry& Entity<codim>::geometry() const
typename Entity<codim>::Geometry Entity<codim>::geometry() const
{
return pgrid_->geomVector<codim>()[*this];
}
Expand Down Expand Up @@ -559,41 +560,18 @@ int Dune::cpgrid::Entity<codim>::getIdxInParentCell() const


template<int codim>
Dune::cpgrid::Geometry<3,3> Dune::cpgrid::Entity<codim>::geometryInFather() const
Dune::AxisAlignedCubeGeometry<double,3,3> Dune::cpgrid::Entity<codim>::geometryInFather() const
{
if (!(this->hasFather())){
OPM_THROW(std::logic_error, "Entity has no father.");
}

// Indices of corners in entity's geometry in father reference element.
static constexpr std::array<int,8> in_father_reference_elem_corner_indices = {0,1,2,3,4,5,6,7};
// 'static': The returned object Geometry<3,3> stores a pointer to in_father_reference_elem_corner_indices. Therefore,
// this variable is declared static to prolongate its lifetime beyond this function (static storage duration).

auto idx_in_parent_cell = pgrid_ -> cell_to_idxInParentCell_[this->index()];
if (idx_in_parent_cell !=-1) {
const auto& cells_per_dim = (*(pgrid_ -> level_data_ptr_))[this->level()] -> cells_per_dim_;
const auto& auxArr = pgrid_ -> getReferenceRefinedCorners(idx_in_parent_cell, cells_per_dim);
FieldVector<double, 3> corners_in_father_reference_elem_temp[8] =
{ auxArr[0], auxArr[1], auxArr[2], auxArr[3], auxArr[4], auxArr[5], auxArr[6], auxArr[7]};
auto in_father_reference_elem_corners = std::make_shared<EntityVariable<cpgrid::Geometry<0, 3>, 3>>();
EntityVariableBase<cpgrid::Geometry<0, 3>>& mutable_in_father_reference_elem_corners = *in_father_reference_elem_corners;
// Assign the corners. Make use of the fact that pointers behave like iterators.
mutable_in_father_reference_elem_corners.assign(corners_in_father_reference_elem_temp,
corners_in_father_reference_elem_temp + 8);
// Compute the center of the 'local-entity'.
Dune::FieldVector<double, 3> center_in_father_reference_elem = {0., 0.,0.};
for (int corn = 0; corn < 8; ++corn) {
for (int c = 0; c < 3; ++c)
{
center_in_father_reference_elem[c] += corners_in_father_reference_elem_temp[corn][c]/8.;
}
}
// Compute the volume of the 'local-entity'.
double volume_in_father_reference_elem = double(1)/(cells_per_dim[0]*cells_per_dim[1]*cells_per_dim[2]);
// Construct (and return) the Geometry<3,3> of 'child-cell in the reference element of its father (unit cube)'.
return Dune::cpgrid::Geometry<3,3>(center_in_father_reference_elem, volume_in_father_reference_elem,
in_father_reference_elem_corners, in_father_reference_elem_corner_indices.data());
const auto& corners = pgrid_ -> getReferenceRefinedCorners(idx_in_parent_cell, cells_per_dim);
// Create new geometry from lower left and upper right corners of the refined cell in the reference element of the father cell.
return {corners[0], corners[7]};
}
else {
OPM_THROW(std::logic_error, "Entity has no father.");
Expand Down
14 changes: 9 additions & 5 deletions opm/grid/cpgrid/Geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ namespace Dune

/// @brief Construct from center, volume (1- and 0-moments) and
/// corners.
/// @warning This constructor does not own the corners or indices,
/// thus, the pointers must remain valid for the lifetime of
/// the Geometry object.
///
/// @param pos the centroid of the entity
/// @param vol the volume(area) of the entity
/// @param allcorners_ptr pointer of all corner positions in the grid
Expand All @@ -414,17 +418,17 @@ namespace Dune
/// by (kji), i.e. i running fastest.
Geometry(const GlobalCoordinate& pos,
ctype vol,
std::shared_ptr<const EntityVariable<cpgrid::Geometry<0, 3>, 3>> allcorners_ptr,
EntityVariable<cpgrid::Geometry<0, 3>, 3> const * allcorners_ptr,
const int* corner_indices)
: pos_(pos), vol_(vol),
allcorners_(allcorners_ptr), cor_idx_(corner_indices)
{
assert(allcorners_ && corner_indices);
assert(allcorners_ptr && corner_indices);
}

/// Default constructor, giving a non-valid geometry.
Geometry()
: pos_(0.0), vol_(0.0), allcorners_(0), cor_idx_(0)
: pos_(0.0), vol_(0.0), allcorners_(nullptr), cor_idx_(nullptr)
{
}

Expand Down Expand Up @@ -1023,7 +1027,7 @@ namespace Dune
refined_cells[refined_cell_idx] =
Geometry<3,cdim>(refined_cell_center,
refined_cell_volume,
all_geom.geomVector(std::integral_constant<int,3>()),
all_geom.geomVector(std::integral_constant<int,3>()).get(),
indices_storage_ptr);
} // end i-for-loop
} // end j-for-loop
Expand All @@ -1044,7 +1048,7 @@ namespace Dune
private:
GlobalCoordinate pos_;
double vol_;
std::shared_ptr<const EntityVariable<Geometry<0, 3>,3>> allcorners_; // For dimension 3 only
const EntityVariable<Geometry<0, 3>,3>* allcorners_; // store non-owning pointer of the 8 corners
const int* cor_idx_; // For dimension 3 only

/// @brief
Expand Down
4 changes: 2 additions & 2 deletions opm/grid/cpgrid/Intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Dune
/// @brief
/// @todo Doc me!
/// @return
[[noreturn]] const LocalGeometry& geometryInInside() const
[[noreturn]] LocalGeometry geometryInInside() const
{
OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside().");
__builtin_unreachable();
Expand All @@ -169,7 +169,7 @@ namespace Dune
/// @brief
/// @todo Doc me!
/// @return
[[noreturn]] const LocalGeometry& geometryInOutside() const
[[noreturn]] LocalGeometry geometryInOutside() const
{
if (boundary()) {
OPM_THROW(std::runtime_error, "Cannot access geometryInOutside(), intersection is at a boundary.");
Expand Down
6 changes: 3 additions & 3 deletions opm/grid/cpgrid/LgrHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,

// Create a pointer to the first element of "refined_cell_to_point" (required as the fourth argement to construct a Geometry<3,3> type object).
int* indices_storage_ptr = refined_cell_to_point_vec[shiftedLevel][cell].data();
refined_cells_vec[shiftedLevel][cell] = Dune::cpgrid::Geometry<3,3>(elemLgrGeom.center(), elemLgrGeom.volume(), allLevelCorners, indices_storage_ptr);
refined_cells_vec[shiftedLevel][cell] = Dune::cpgrid::Geometry<3,3>(elemLgrGeom.center(), elemLgrGeom.volume(), allLevelCorners.get(), indices_storage_ptr);
} // refined_cells
// Refined face to cell.
refined_cell_to_face_vec[shiftedLevel].makeInverseRelation(refined_face_to_cell_vec[shiftedLevel]);
Expand Down Expand Up @@ -1722,7 +1722,7 @@ void populateLeafGridCells(const Dune::cpgrid::CpGridData& current_data,

// Create a pointer to the first element of "adapted_cell_to_point" (required as the fourth argement to construct a Geometry<3,3> type object).
int* indices_storage_ptr = adapted_cell_to_point[cell].data();
adapted_cells[cell] = Dune::cpgrid::Geometry<3,3>(cellGeom.center(), cellGeom.volume(), allCorners, indices_storage_ptr);
adapted_cells[cell] = Dune::cpgrid::Geometry<3,3>(cellGeom.center(), cellGeom.volume(), allCorners.get(), indices_storage_ptr);
} // adapted_cells

// Adapted/Leaf-grid-view face to cell.
Expand Down Expand Up @@ -2287,7 +2287,7 @@ void filterMarkedAquiferCellsAndConnections(Dune::CpGrid& grid,
} else {
grid.mark(0, elem);
}
}
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion opm/grid/cpgrid/processEclipseFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ namespace cpgrid
double vol,
const std::array<int,8>& corner_indices)
{
return cpgrid::Geometry<3, 3>(pos, vol, allcorners_, &corner_indices[0]);
return cpgrid::Geometry<3, 3>(pos, vol, allcorners_.get(), &corner_indices[0]);
}
};

Expand Down
8 changes: 4 additions & 4 deletions tests/cpgrid/geometry_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(cellgeom)
}

int cor_idx[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
Geometry g(c, v, pg, cor_idx);
Geometry g(c, v, pg.get(), cor_idx);

// Verification of properties.
BOOST_CHECK(g.type().isCube());
Expand Down Expand Up @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(cellgeom)
{
(*pg1).push_back(cpgrid::Geometry<0, 3>(crn));
}
g = Geometry(c, v, pg1, cor_idx);
g = Geometry(c, v, pg1.get(), cor_idx);

// Verification of properties.
BOOST_CHECK(g.type().isCube());
Expand Down Expand Up @@ -524,7 +524,7 @@ BOOST_AUTO_TEST_CASE(refine_simple_cube)
}

int cor_idx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
Geometry g(c, v, pg, cor_idx);
Geometry g(c, v, pg.get(), cor_idx);

refine_and_check(g, {1, 1, 1}, true);
refine_and_check(g, {2, 3, 4}, true);
Expand Down Expand Up @@ -566,7 +566,7 @@ BOOST_AUTO_TEST_CASE(refine_distorted_cube)
}

int cor_idx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
Geometry g(center, v, pg, cor_idx);
Geometry g(center, v, pg.get(), cor_idx);
refine_and_check(g, {1, 1, 1});
refine_and_check(g, {2, 3, 4});

Expand Down