Skip to content

Commit

Permalink
Merge commit 'd21b9d834d4cd61012c9cef4559cdd301835d58d' into feature-…
Browse files Browse the repository at this point in the history
…pybind11

* commit 'd21b9d834d4cd61012c9cef4559cdd301835d58d':
  Enhancements in the composite_user_data.h
  Arte 2D ready for use
  Revert "Merge pull request #96 from UG4/95-avoid-slicing"
  Member variable  m_passOnBehaviour now moved to abstract base. Menat to avoid slicing.
  NULL => nullptr
  Some cosmetics to the previous bug fix. Note that the bug fix is due to Shuai Lu.
  Bug fix: The bug prevented the subset handlers to be registered in the domain.

# Conflicts:
#	ugbase/bridge/disc_bridges/user_data_bridge.cpp
  • Loading branch information
anaegel committed Nov 5, 2024
2 parents ced0830 + d21b9d8 commit b74f0b0
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 134 deletions.
10 changes: 7 additions & 3 deletions ugbase/bridge/disc_bridges/user_data_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ static void Dimension(TRegistry& reg, string grp)
typedef CompositeUserData<number, dim, void> T;
reg.template add_class_<T,typename T::base_type>(name, grp)
.template add_constructor<void (*)(bool) >("")
.add_method("add", &T::add)
.template add_constructor<void (*)(bool)>("continuous")
.add_method("add", static_cast<void (T::*)(int, typename T::ref_type)>(&T::add), "assign a user data object to a subset index", "si#userdata")
.add_method("add", static_cast<void (T::*)(ConstSmartPtr<ISubsetHandler>, const char *, typename T::ref_type)>(&T::add), "assign a user data object to subsets by names", "names#userdata")
.add_method("has", &T::has)
.add_method("get", &T::get)
.add_method("is_coupled", &T::is_coupled)
Expand All @@ -473,8 +475,10 @@ static void Dimension(TRegistry& reg, string grp)
string name = string("CompositeUserVector").append(dimSuffix);
typedef CompositeUserData<MathVector<dim>, dim, void> T;
reg.template add_class_<T,typename T::base_type>(name, grp)
.template add_constructor<void (*)(bool) >("")
.add_method("add", &T::add)
.template add_constructor<void (*)()>()
.template add_constructor<void (*)(bool)>("continuous")
.add_method("add", static_cast<void (T::*)(int, typename T::ref_type)>(&T::add), "assign a user data object to a subset index", "si#userdata")
.add_method("add", static_cast<void (T::*)(ConstSmartPtr<ISubsetHandler>, const char *, typename T::ref_type)>(&T::add), "assign a user data object to subsets by names", "names#userdata")
.add_method("has", &T::has)
.add_method("get", &T::get)
.add_method("is_coupled", &T::is_coupled)
Expand Down
26 changes: 7 additions & 19 deletions ugbase/lib_disc/domain_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,19 @@ void LoadDomain(TDomain& domain, const char* filename, int procId)
//domain.create_additional_subset_handler("markSH");
vector<string> additionalSHNames = domain.additional_subset_handler_names();
SPProjectionHandler ph = make_sp(new ProjectionHandler(domain.geometry3d(), domain.subset_handler()));
vector<SmartPtr<ISubsetHandler> > ash(additionalSHNames.size());

if(additionalSHNames.size()>0){
SmartPtr<ISubsetHandler> sh;
vector<SmartPtr<ISubsetHandler>> ash(additionalSHNames.size());
for(size_t i_name = 0; i_name < additionalSHNames.size(); ++i_name){
SmartPtr<ISubsetHandler> sh = domain.additional_subset_handler(additionalSHNames[i_name]);
ash[i_name]= sh;
}

if(!LoadGridFromFile(*domain.grid(), ph, num_ph, *domain.subset_handler(), additionalSHNames, ash,
filename, domain.position_attachment(), procId))
{
UG_THROW("LoadDomain: Could not load file: "<<filename);
}
}
else if(!LoadGridFromFile(*domain.grid(), *domain.subset_handler(),
filename, domain.position_attachment(), procId))
for(size_t i_name = 0; i_name < additionalSHNames.size(); ++i_name)
ash[i_name] = domain.additional_subset_handler(additionalSHNames[i_name]);

if(!LoadGridFromFile(*domain.grid(), ph, num_ph, *domain.subset_handler(), additionalSHNames, ash,
filename, domain.position_attachment(), procId))
{
UG_THROW("LoadDomain: Could not load file: "<<filename);
}

if(num_ph > 0)
{
if(num_ph != 0)
domain.set_refinement_projector(ph);
}
}


Expand Down
30 changes: 15 additions & 15 deletions ugbase/lib_disc/spatial_disc/disc_util/conv_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ update(const TFVGeom* geo,
const MathMatrix<dim, dim>* DiffDisp,
bool computeDeriv)
{
UG_ASSERT(geo != NULL, "Null pointer");
UG_ASSERT(Velocity != NULL, "Null pointer");
UG_ASSERT(geo != nullptr, "Null pointer");
UG_ASSERT(Velocity != nullptr, "Null pointer");

// \todo: think about: this should be something like scvf.num_sh()
const size_t numSH = geo->num_sh();
Expand Down Expand Up @@ -280,8 +280,8 @@ update(const TFVGeom* geo,
const MathMatrix<dim, dim>* DiffDisp,
bool computeDeriv)
{
UG_ASSERT(geo != NULL, "Null pointer");
UG_ASSERT(Velocity != NULL, "Null pointer");
UG_ASSERT(geo != nullptr, "Null pointer");
UG_ASSERT(Velocity != nullptr, "Null pointer");

// \todo: think about: this should be something like scvf.num_sh()
const size_t numSH = geo->num_sh();
Expand Down Expand Up @@ -456,8 +456,8 @@ update(const TFVGeom* geo,
const MathMatrix<dim, dim>* DiffDisp,
bool computeDeriv)
{
UG_ASSERT(geo != NULL, "Null pointer");
UG_ASSERT(Velocity != NULL, "Null pointer");
UG_ASSERT(geo != nullptr, "Null pointer");
UG_ASSERT(Velocity != nullptr, "Null pointer");

// \todo: think about: this should be something like scvf.num_sh()
const size_t numSH = geo->num_sh();
Expand Down Expand Up @@ -618,9 +618,9 @@ update(const TFVGeom* geo,
const MathMatrix<dim, dim>* DiffDisp,
bool computeDeriv)
{
UG_ASSERT(geo != NULL, "Null pointer");
UG_ASSERT(Velocity != NULL, "Null pointer");
// UG_ASSERT(DiffDisp != NULL, "Null pointer");
UG_ASSERT(geo != nullptr, "Null pointer");
UG_ASSERT(Velocity != nullptr, "Null pointer");
// UG_ASSERT(DiffDisp != nullptr, "Null pointer");

// Compute Volume of Element
// typedef typename TFVGeom::ref_elem_type ref_elem_type;
Expand All @@ -644,7 +644,7 @@ update(const TFVGeom* geo,
number lambda = -1;

// if DiffDisp-Tensor passed, compute lambda
if(DiffDisp != NULL)
if(DiffDisp != nullptr)
{
// Get Gradients
MathVector<dim> DiffGrad;
Expand Down Expand Up @@ -679,7 +679,7 @@ update(const TFVGeom* geo,
// Case 1:
// full upwind is used
///////////////////////////////////////////////////////////////////
if(lambda <= 0 || DiffDisp == NULL)
if(lambda <= 0 || DiffDisp == nullptr)
{
// Choose Upwind corner
const size_t up = (flux >= 0) ? scvf.from() : scvf.to();
Expand Down Expand Up @@ -902,8 +902,8 @@ bool ConvectionShapesSkewedUpwind<TDim>::
const MathMatrix<dim, dim> *DiffDisp,
bool computeDeriv)
{
UG_ASSERT(geo != NULL, "Null pointer");
UG_ASSERT(Velocity != NULL, "Null pointer");
UG_ASSERT(geo != nullptr, "Null pointer");
UG_ASSERT(Velocity != nullptr, "Null pointer");

// \todo: think about: this should be something like scvf.num_sh()
const size_t numSH = geo->num_sh();
Expand Down Expand Up @@ -1071,8 +1071,8 @@ bool ConvectionShapesLinearProfileSkewedUpwind<TDim>::
const MathMatrix<dim, dim> *DiffDisp,
bool computeDeriv)
{
UG_ASSERT(geo != NULL, "Null pointer");
UG_ASSERT(Velocity != NULL, "Null pointer");
UG_ASSERT(geo != nullptr, "Null pointer");
UG_ASSERT(Velocity != nullptr, "Null pointer");

// \todo: think about: this should be something like scvf.num_sh()
const size_t numSH = geo->num_sh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,61 +33,95 @@
#ifndef __LIB_DISC__COMPOSITE_USER_DATA_H_
#define __LIB_DISC__COMPOSITE_USER_DATA_H_

// UG4
#include <vector>
#include <string>

// UG4 headers
#include "lib_grid/tools/subset_group.h"
#include "lib_disc/spatial_disc/user_data/linker/linker.h"

namespace ug{

//! This is a compositum for user data from different subsets.
/*! This is handy, but the implementation is rather slow. */
/// This is a compositum for user data defined on different subsets
/**
* This combines user data objects defined on several subsets which is handy,
* but may be slow.
*/
template <typename TData, int dim, typename TRet = void>
class CompositeUserData : public UserData<TData, dim, TRet>
{
protected:
typedef CplUserData<TData, dim, TRet> TCplUserData;
public:
typedef UserData<TData, dim, TRet> base_type;
typedef SmartPtr<base_type> ref_type;
typedef std::map<int, ref_type> map_type;
typedef SmartPtr<base_type> ref_type; ///< the attached UserData objects should have the same type as this class (i.e. they are "remapped")

CompositeUserData(bool continuous) : m_continuous(continuous), m_bRequiresGridFunction(false)
{}
CompositeUserData() : m_bContinuous(true), m_bRequiresGridFunction(false) {}

CompositeUserData(bool continuous) : m_bContinuous(continuous), m_bRequiresGridFunction(false) {}

virtual ~CompositeUserData(){}

///! Add 'UserData' for given subset index.
void add(int si, ref_type ref)

/// Add 'UserData' object for given subset index.
void add
(
int si, ///< the subset index
ref_type ref ///< pointer to the user-data object
)
{
// UG_ASSERT(ref->continuous() == m_continuous, "ERROR: Mixing continuous and discontinuous data!");
m_map[si] = ref;
m_continuous = m_continuous && ref->continuous();
UG_ASSERT (si >= 0, "CompositeUserData: Non-existing subset index!");

if ((size_t) si >= m_vData.size ())
m_vData.resize (si + 1);
m_vData[si] = ref;

// UG_ASSERT(ref->continuous() == m_continuous, "CompositeUserData: Mixing continuous and discontinuous data!");
m_bContinuous = m_bContinuous && ref->continuous();
m_bRequiresGridFunction = m_bRequiresGridFunction || ref->requires_grid_fct();
}

/// Add 'UserData' object for all subsets in a given group
void add
(
const SubsetGroup & ssg, ///< the subset group
ref_type ref ///< pointer to the user-data object
)
{
for (size_t i = 0; i < ssg.size (); i++) add (ssg[i], ref);
}

/// Add 'UserData' object for all subsets by their names
void add
(
ConstSmartPtr<ISubsetHandler> ssh, ///< subset handler of the domain
const char * ss_names, ///< names of the subdomains
ref_type ref ///< pointer to the user-data object
)
{
std::vector<std::string> v_ss_names;
SubsetGroup ssg;

TokenizeTrimString (std::string (ss_names), v_ss_names);
ssg.add (v_ss_names);
add (ssg, ref);
}

ref_type get(int si)
{ return (find(si)->second); }

bool has(int si)
{ return find(si) != m_map.end();}


bool is_coupled(int si)
{ return (has(si) && find(si)->second.template is_of_type<TCplUserData>()); }
/// Returns the value assigned to a subset index
ref_type get (int si) const { return find(si); }

SmartPtr<TCplUserData> get_coupled(int si)
{ return find(si)->second.template cast_dynamic<TCplUserData>(); }
/// Checks if anything is assigned to a given subset index
bool has(int si) const { return si >= 0 && (size_t) si < m_vData.size () && find(si).valid ();}


bool is_coupled(int si) { return has(si) && find(si).template is_of_type<TCplUserData>(); }

SmartPtr<TCplUserData> get_coupled(int si) { return find(si).template cast_dynamic<TCplUserData>(); }

// Implementing virtual functions

virtual bool continuous() const
{return m_continuous;}

virtual bool continuous() const {return m_bContinuous;}

//! returns true, if at least one of the underlying UserData requires grid functions.
/// returns true, if at least one of the underlying UserData requires grid functions.
virtual bool requires_grid_fct() const
{
return m_bRequiresGridFunction;
Expand All @@ -97,66 +131,71 @@ class CompositeUserData : public UserData<TData, dim, TRet>
virtual TRet operator() (TData& value,
const MathVector<dim>& globIP,
number time, int si) const
{ return (*find(si)->second)(value, globIP, time, si); }
{ return (*find(si)) (value, globIP, time, si); }

/// returns values for global positions
virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si, const size_t nip) const
{ return (*find(si)) (vValue, vGlobIP, time, si, nip); }

/// returns values for global positions
virtual void operator()(TData vValue[],

virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si, const size_t nip) const
{ return (*find(si)->second)(vValue, vGlobIP, time, si, nip); }


virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si,
GridObject* elem,
const MathVector<dim> vCornerCoords[],
const MathVector<1> vLocIP[],
const size_t nip,
LocalVector* u,
const MathMatrix<1, dim>* vJT = NULL) const
{
return (*find(si)->second)(vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
}

virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si,
GridObject* elem,
const MathVector<dim> vCornerCoords[],
const MathVector<2> vLocIP[],
const size_t nip,
LocalVector* u,
const MathMatrix<2, dim>* vJT = NULL) const
{
return (*find(si)->second)(vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
}

virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si,
GridObject* elem,
const MathVector<dim> vCornerCoords[],
const MathVector<3> vLocIP[],
const size_t nip,
LocalVector* u,
const MathMatrix<3, dim>* vJT = NULL) const
{
return (*find(si)->second)(vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
}
number time, int si,
GridObject* elem,
const MathVector<dim> vCornerCoords[],
const MathVector<1> vLocIP[],
const size_t nip,
LocalVector* u,
const MathMatrix<1, dim>* vJT = NULL) const
{
return (*find(si)) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
}

virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si,
GridObject* elem,
const MathVector<dim> vCornerCoords[],
const MathVector<2> vLocIP[],
const size_t nip,
LocalVector* u,
const MathMatrix<2, dim>* vJT = NULL) const
{
return (*find(si)) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
}

virtual void operator()(TData vValue[],
const MathVector<dim> vGlobIP[],
number time, int si,
GridObject* elem,
const MathVector<dim> vCornerCoords[],
const MathVector<3> vLocIP[],
const size_t nip,
LocalVector* u,
const MathMatrix<3, dim>* vJT = NULL) const
{
return (*find(si)) (vValue, vGlobIP, time, si, elem, vCornerCoords, vLocIP, nip, u, vJT);
}

protected:
typename map_type::const_iterator find(int si) const
private:

// returns the reference to the user data in the given subset
const ref_type & find (int si) const
{
typename map_type::const_iterator it = m_map.find(si);
UG_ASSERT(it != m_map.end(), "ERROR: Subset not found!");
return it;
if (si < 0 || (size_t) si >= m_vData.size ())
{
UG_THROW ("CompositeUserData: No data for subset " << si);
}

return m_vData [si];
}

map_type m_map;
bool m_continuous;
private:

std::vector<ref_type> m_vData;
bool m_bContinuous;
bool m_bRequiresGridFunction;
};

Expand Down
Loading

0 comments on commit b74f0b0

Please sign in to comment.