Skip to content

Commit

Permalink
dvec set vec ptr added
Browse files Browse the repository at this point in the history
  • Loading branch information
milindasf committed Jul 11, 2023
1 parent 7726cbc commit 5dbcfa6
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions include/dvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ namespace ot
*/
void create_vector(const ot::Mesh* pMesh, DVEC_TYPE type, DVEC_LOC loc, unsigned int dof=1, bool allocate_ghost=true);

/**
* @brief initialize a DVector object from already allocated ptr
*
* @param ptr allocated ptr
* @param pMesh Mesh associated with the allocation
* @param type DVector type
* @param loc DVector location
* @param dof DVector dof
* @param allocate_ghost DVector allocated ghost
*/
void set_vec_ptr(T*& ptr, const ot::Mesh* pMesh, DVEC_TYPE type, DVEC_LOC loc, unsigned int dof, bool allocate_ghost);

/**@brief creates a similar vector as dvec*/
void create_vector(const ot::DVector<T,I>& dvec);

Expand Down Expand Up @@ -143,16 +155,16 @@ namespace ot
template<typename T,typename I>
void DVector<T,I>::create_vector(const ot::Mesh* pMesh, DVEC_TYPE type, DVEC_LOC loc, unsigned int dof, bool allocate_ghost)
{
if(!(pMesh->isActive()))
return;

m_dof = dof;
m_comm = pMesh->getMPICommunicator();
m_vec_type = type;
m_vec_loc = loc;
m_ghost_allocated = allocate_ghost;
m_size = 0;

if(!(pMesh->isActive()))
return;

if(m_vec_type == DVEC_TYPE::OCT_SHARED_NODES)
(allocate_ghost) ? m_size = pMesh->getDegOfFreedom() * m_dof : m_size = pMesh->getNumLocalMeshNodes() * m_dof;
else if (m_vec_type == DVEC_TYPE::OCT_LOCAL_NODES)
Expand Down Expand Up @@ -189,6 +201,37 @@ namespace ot
}

}

template<typename T,typename I>
void DVector<T,I>::set_vec_ptr(T*& ptr, const ot::Mesh* pMesh, DVEC_TYPE type, DVEC_LOC loc, unsigned int dof, bool allocate_ghost)
{
if(!(pMesh->isActive()))
return;

m_dof = dof;
m_comm = pMesh->getMPICommunicator();
m_vec_type = type;
m_vec_loc = loc;
m_ghost_allocated = allocate_ghost;
m_size = 0;

if(m_vec_type == DVEC_TYPE::OCT_SHARED_NODES)
(allocate_ghost) ? m_size = pMesh->getDegOfFreedom() * m_dof : m_size = pMesh->getNumLocalMeshNodes() * m_dof;
else if (m_vec_type == DVEC_TYPE::OCT_LOCAL_NODES)
(allocate_ghost) ? m_size = pMesh->getDegOfFreedomDG() * m_dof : m_size = pMesh->getNumLocalMeshElements() * pMesh->getNumNodesPerElement() * m_dof;
else if (m_vec_type == DVEC_TYPE::OCT_LOCAL_WITH_PADDING)
(allocate_ghost) ? m_size = pMesh->getDegOfFreedomUnZip() * m_dof : m_size = pMesh->getDegOfFreedomUnZip() * m_dof;
else if (m_vec_type == DVEC_TYPE::OCT_CELL_CENTERED)
(allocate_ghost) ? m_size = pMesh->getAllElements().size() * m_dof : m_size = pMesh->getNumLocalMeshElements() * m_dof;
else
{
dendro_log(" unknown type in DVector");
MPI_Abort(m_comm,0);
}

m_data_ptr = ptr;
return;
}

template<typename T,typename I>
void DVector<T,I>::destroy_vector()
Expand Down

0 comments on commit 5dbcfa6

Please sign in to comment.