Commit 440d6dd1 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'feature/entitynetwork-use-id-class' into 'master'

Feature/entitynetwork use id class

See merge request DennisGlaeser/frackit!20
parents 2966c1f7 61775850
......@@ -213,13 +213,13 @@ int main(int argc, char** argv)
ContainedEntityNetworkBuilder containedConfinedBuilder;
// define sub-domains
containedConfinedBuilder.addSubDomain(solids[0], /*subDomainIndex*/1);
containedConfinedBuilder.addSubDomain(networkDomain, /*subDomainIndex*/2);
containedConfinedBuilder.addSubDomain(solids[2], /*subDomainIndex*/3);
containedConfinedBuilder.addConfiningSubDomain(solids[0], Id(1));
containedConfinedBuilder.addConfiningSubDomain(networkDomain, Id(2));
containedConfinedBuilder.addConfiningSubDomain(solids[2], Id(3));
// define entity network for sub-domain 2
containedConfinedBuilder.addSubDomainEntities(diskSet1, 2);
containedConfinedBuilder.addSubDomainEntities(diskSet2, 2);
containedConfinedBuilder.addSubDomainEntities(diskSet1, Id(2));
containedConfinedBuilder.addSubDomainEntities(diskSet2, Id(2));
// build network
const auto containedConfinedNetwork = containedConfinedBuilder.build();
......@@ -230,15 +230,13 @@ int main(int argc, char** argv)
ContainedEntityNetworkBuilder containedUnconfinedBuilder;
// define sub-domains
containedUnconfinedBuilder.addSubDomain(solids[0], /*subDomainIndex*/1);
containedUnconfinedBuilder.addSubDomain(solids[2], /*subDomainIndex*/3);
containedUnconfinedBuilder.addSubDomain(networkDomain,
/*subDomainIndex*/2,
/*confineEmbeddedNetwork*/false);
containedUnconfinedBuilder.addSubDomain(solids[0], Id(1));
containedUnconfinedBuilder.addSubDomain(solids[2], Id(3));
containedUnconfinedBuilder.addSubDomain(networkDomain, Id(2));
// define entity network for sub-domain 2
containedUnconfinedBuilder.addSubDomainEntities(diskSet1, 2);
containedUnconfinedBuilder.addSubDomainEntities(diskSet2, 2);
containedUnconfinedBuilder.addSubDomainEntities(diskSet1, Id(2));
containedUnconfinedBuilder.addSubDomainEntities(diskSet2, Id(2));
// build network
const auto containedUnconfinedNetwork = containedUnconfinedBuilder.build();
......@@ -251,13 +249,11 @@ int main(int argc, char** argv)
EntityNetworkBuilder uncontainedConfinedBuilder;
// define sub-domains
uncontainedConfinedBuilder.addSubDomain(networkDomain,
/*subDomainIndex*/1,
/*confineEmbeddedNetwork*/true);
uncontainedConfinedBuilder.addConfiningSubDomain(networkDomain, Id(1));
// define entity network for sub-domain 2
uncontainedConfinedBuilder.addSubDomainEntities(diskSet1, 1);
uncontainedConfinedBuilder.addSubDomainEntities(diskSet2, 1);
uncontainedConfinedBuilder.addSubDomainEntities(diskSet1, Id(1));
uncontainedConfinedBuilder.addSubDomainEntities(diskSet2, Id(1));
// build network
const auto uncontainedConfinedNetwork = uncontainedConfinedBuilder.build();
......
......@@ -32,6 +32,7 @@
#include <TopTools_ListOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <frackit/common/id.hh>
#include "containedentitynetworkinterface.hh"
namespace Frackit {
......@@ -67,43 +68,43 @@ public:
, subDomainEntityFragments_(std::move(entityFragments))
, subDomainEntityFragmentIndexMap_(std::move(entityFragmentMaps))
{
subDomainIndices_.reserve(subDomainFragments_.size());
subDomainIds_.reserve(subDomainFragments_.size());
for (const auto& sdDataPair : subDomainFragments_)
subDomainIndices_.push_back(sdDataPair.first);
subDomainIds_.emplace_back(sdDataPair.first);
}
/*!
* \brief Returns the indices of defined the sub-domains
* \brief Returns the ids of defined the sub-domains
*/
const std::vector<std::size_t>& subDomainIndices() const override
{ return subDomainIndices_; }
const std::vector<Id>& subDomainIds() const override
{ return subDomainIds_; }
/*!
* \brief Returns the fragments of a sub-domain
* \param subDomainIdx The index of the sub-domain
*/
const TopTools_ListOfShape& subDomainFragments(std::size_t subDomainIdx) const override
{ return subDomainFragments_.at(subDomainIdx); }
const TopTools_ListOfShape& subDomainFragments(Id subDomainId) const override
{ return subDomainFragments_.at(subDomainId.get()); }
/*!
* \brief Returns the entity fragments of the network defined for a sub-domain
* \param subDomainIdx The index of the sub-domain
*/
const TopTools_ListOfShape& subDomainEntityFragments(std::size_t subDomainIdx) const override
{ return subDomainEntityFragments_.at(subDomainIdx); }
const TopTools_ListOfShape& subDomainEntityFragments(Id subDomainId) const override
{ return subDomainEntityFragments_.at(subDomainId.get()); }
/*!
* \brief Returns the map which maps each fragment the network of a sub-domain to its primary entity index.
* \param subDomainIdx The index of the sub-domain
*/
const TopTools_DataMapOfShapeInteger& subDomainEntityFragmentsIndexMap(std::size_t subDomainIdx) const override
{ return subDomainEntityFragmentIndexMap_.at(subDomainIdx); }
const TopTools_DataMapOfShapeInteger& subDomainEntityFragmentsIndexMap(Id subDomainId) const override
{ return subDomainEntityFragmentIndexMap_.at(subDomainId.get()); }
private:
std::unordered_map<std::size_t, TopTools_ListOfShape> subDomainFragments_;
std::unordered_map<std::size_t, TopTools_ListOfShape> subDomainEntityFragments_;
std::unordered_map<std::size_t, TopTools_DataMapOfShapeInteger> subDomainEntityFragmentIndexMap_;
std::vector<std::size_t> subDomainIndices_;
std::vector<Id> subDomainIds_;
};
} // end namespace Frackit
......
......@@ -30,6 +30,8 @@
#include <TopTools_ListOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <frackit/common/id.hh>
namespace Frackit {
/*!
......@@ -65,27 +67,27 @@ public:
{ return domainDimension_; }
/*!
* \brief Returns the indices of defined the sub-domains
* \brief Returns the ids of defined the sub-domains
*/
virtual const std::vector<std::size_t>& subDomainIndices() const = 0;
virtual const std::vector<Id>& subDomainIds() const = 0;
/*!
* \brief Returns the fragments of a sub-domain
* \param subDomainIdx The index of the sub-domain
*/
virtual const TopTools_ListOfShape& subDomainFragments(std::size_t subDomainIdx) const = 0;
virtual const TopTools_ListOfShape& subDomainFragments(Id subDomainId) const = 0;
/*!
* \brief Returns the entity fragments of the network defined for a sub-domain
* \param subDomainIdx The index of the sub-domain
*/
virtual const TopTools_ListOfShape& subDomainEntityFragments(std::size_t subDomainIdx) const = 0;
virtual const TopTools_ListOfShape& subDomainEntityFragments(Id subDomainId) const = 0;
/*!
* \brief Returns the map which maps each fragment the network of a sub-domain to its primary entity index.
* \param subDomainIdx The index of the sub-domain
*/
virtual const TopTools_DataMapOfShapeInteger& subDomainEntityFragmentsIndexMap(std::size_t subDomainIdx) const = 0;
virtual const TopTools_DataMapOfShapeInteger& subDomainEntityFragmentsIndexMap(Id subDomainId) const = 0;
private:
int entityDimension_;
......
......@@ -18,7 +18,7 @@
*****************************************************************************/
/*!
* \file
* \brief TODO
* \brief Contains builder classes for entity networks.
*/
#ifndef FRACKIT_ENTITY_NETWORK_BUILDER_HH
#define FRACKIT_ENTITY_NETWORK_BUILDER_HH
......@@ -33,10 +33,12 @@
#include <TopTools_ListOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <frackit/occ/breputilities.hh>
#include <frackit/common/id.hh>
#include <frackit/common/extractdimension.hh>
#include <frackit/precision/defaultepsilon.hh>
#include <frackit/precision/precision.hh>
#include <frackit/occ/breputilities.hh>
#include "entitynetwork.hh"
#include "containedentitynetwork.hh"
......@@ -108,38 +110,53 @@ public:
/*!
* \brief Defines a sub-domain which potentially
* contains an embedded entity network.
* Networks defined for this sub-domain
* will not be confined by the sub-domain's
* boundary.
* \param domain The sub-domain geometry
* \param index The index to be used for this sub-domain
* \param boundsNetwork If set to true, the entity network
* defined for this sub-domain will be
* confined to it, cutting away entities
* or those parts of entities that lie outside.
* \param subDomainId The identifier (index) to be used for this sub-domain
*/
template<class Domain>
void addSubDomain(const Domain& domain, std::size_t index, bool boundsNetwork = true)
void addSubDomain(const Domain& domain, Id subDomainId)
{
const auto domainDim = getDimension(domain);
if (!networks_.empty() && domainDim <= entityDimension_)
throw std::runtime_error("Sub-domain dimension must be greater than entity dimension");
if (!subDomains_.empty() && domainDim != domainDimension_)
throw std::runtime_error("Sub-domain dimension does not match to previously added");
if (subDomains_.find(index) != subDomains_.end())
throw std::runtime_error("Sub-domain index already taken!");
if (subDomains_.find(subDomainId.get()) != subDomains_.end())
throw std::runtime_error("Sub-domain id already taken!");
domainDimension_ = domainDim;
subDomains_[index] = OCCUtilities::getShape(domain);
subDomainBoundsNetwork_[index] = boundsNetwork;
subDomains_[subDomainId.get()] = OCCUtilities::getShape(domain);
subDomainBoundsNetwork_[subDomainId.get()] = false;
}
/*!
* \brief Defines a sub-domain which potentially
* contains an embedded entity network.
* Using this interface, the sub-domain is
* defined as confining, that is, the
* network embedded in it will be confined
* by the sub-domain's boundary.
* \param domain The sub-domain geometry
* \param subDomainId The identifier (index) to be used for this sub-domain
*/
template<class Domain>
void addConfiningSubDomain(const Domain& domain, Id subDomainId)
{
addSubDomain(domain, subDomainId);
subDomainBoundsNetwork_[subDomainId.get()] = true;
}
/*!
* \brief Adds an entity to the network embedded in
* the sub-domain with index subDomainIndex.
* \param entity The entity geometry
* \param subDomainIndex The index of the sub-domain
* this entity is embedded in
* \param subDomainId The identifier (index) to be used for this sub-domain
*/
template<class Entity>
void addSubDomainEntity(const Entity& entity, std::size_t subDomainIndex)
void addSubDomainEntity(const Entity& entity, Id subDomainId)
{
const auto entityDim = getDimension(entity);
if (!networks_.empty() && getDimension(entity) != entityDimension_)
......@@ -148,21 +165,20 @@ public:
throw std::runtime_error("Entity dimension must be smaller than domain dimension");
entityDimension_ = entityDim;
networks_[subDomainIndex].Append(OCCUtilities::getShape(entity));
networks_[subDomainId.get()].Append(OCCUtilities::getShape(entity));
}
/*!
* \brief Adds a set of entities to the network
* embedded in sub-domain with index subDomainIndex.
* \param entities The set of entities
* \param subDomainIndex The index of the sub-domain in which
* the given entities are embedded.
* \param subDomainId The identifier (index) to be used for this sub-domain
*/
template<class EntityNetwork>
void addSubDomainEntities(const EntityNetwork& entities, std::size_t subDomainIndex)
void addSubDomainEntities(const EntityNetwork& entities, Id subDomainId)
{
for (const auto& entity : entities)
addSubDomainEntity(entity, subDomainIndex);
addSubDomainEntity(entity, subDomainId);
}
/*!
......
......@@ -127,12 +127,12 @@ private:
void makeEntityMap_(const ContainedEntityNetwork& network)
{
std::size_t subNetworkOffset = 0;
for (auto idx : network.subDomainIndices())
for (const auto& id : network.subDomainIds())
{
// the map maps to the entity index within the sub-domain network
// Therefore, we add the offset in order to ensure that we don't add
// entities from another network to the same primary entity index
const auto& map = network.subDomainEntityFragmentsIndexMap(idx);
const auto& map = network.subDomainEntityFragmentsIndexMap(id);
for (TopTools_DataMapIteratorOfDataMapOfShapeInteger it(map); it.More(); it.Next())
{
allEntities_.Append(it.Key());
......@@ -198,16 +198,16 @@ private:
*/
void makeSubShapeMaps_(const ContainedEntityNetwork& network)
{
for (auto idx : network.subDomainIndices())
for (auto id : network.subDomainIds())
{
const auto& sdFragments = network.subDomainFragments(idx);
const auto& sdFragments = network.subDomainFragments(id);
for (TopTools_ListIteratorOfListOfShape it(sdFragments); it.More(); it.Next())
addSolids_(it.Value(), idx);
addSolids_(it.Value(), id.get());
}
for (auto idx : network.subDomainIndices())
for (auto id : network.subDomainIds())
{
const auto& sdEntityFragments = network.subDomainEntityFragments(idx);
const auto& sdEntityFragments = network.subDomainEntityFragments(id);
for (TopTools_ListIteratorOfListOfShape it(sdEntityFragments); it.More(); it.Next())
addFaces_(it.Value());
}
......
......@@ -13,10 +13,13 @@
#include <frackit/geometry/cylinder.hh>
#include <frackit/geometry/disk.hh>
#include <frackit/precision/precision.hh>
#include <frackit/magnitude/magnitude.hh>
#include <frackit/magnitude/containedmagnitude.hh>
#include <frackit/common/id.hh>
#include <frackit/occ/breputilities.hh>
#include <frackit/precision/precision.hh>
#include <frackit/sampling/pointsampling.hh>
#include <frackit/sampling/geometrysampling.hh>
......@@ -28,9 +31,10 @@
//! create 3 disk-shaped fractures and write geo (gmsh file format) file
int main(int argc, char** argv)
{
using namespace Frackit;
using ctype = double;
using Domain = Frackit::Cylinder<ctype>;
using Disk = Frackit::Disk<ctype>;
using Domain = Cylinder<ctype>;
using Disk = Disk<ctype>;
using Point = typename Disk::Point;
using Direction = typename Disk::Direction;
using Vector = typename Direction::Vector;
......@@ -43,18 +47,18 @@ int main(int argc, char** argv)
Domain domain(0.5, 1.0);
Domain domain2(Disk(Point(0.0, 0.0, 1.0), e1, e2, 1.0, 1.0), 1.0);
Frackit::ContainedEntityNetworkBuilder builder;
builder.addSubDomain(domain, 1);
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 0.1), e1, e2, 1.0, 1.0), 1);
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 0.5), e1, e3, 2.0, 2.0), 1);
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 0.75), e1, e2, 1.0, 1.0), 1);
ContainedEntityNetworkBuilder builder;
builder.addSubDomain(domain, Id(1));
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 0.1), e1, e2, 1.0, 1.0), Id(1));
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 0.5), e1, e3, 2.0, 2.0), Id(1));
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 0.75), e1, e2, 1.0, 1.0), Id(1));
builder.addSubDomain(domain2, 2);
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 1.1), e1, e2, 1.0, 1.0),2);
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 1.5), e1, e3, 2.0, 2.0),2);
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 1.75), e1, e2, 1.0, 1.0),2);
builder.addSubDomain(domain2, Id(2));
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 1.1), e1, e2, 1.0, 1.0), Id(2));
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 1.5), e1, e3, 2.0, 2.0), Id(2));
builder.addSubDomainEntity(Disk(Point(0.0, 0.0, 1.75), e1, e2, 1.0, 1.0), Id(2));
Frackit::GmshWriter writer(builder.build());
GmshWriter writer(builder.build());
writer.write("final", 1.0, 1.0);
std::cout << "All tests passed" << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment