Commit e025ca18 authored by Michal Habera's avatar Michal Habera

Add vector component handling, elementCell to attribute

parent c4a1c5aa
...@@ -42,7 +42,8 @@ XdmfAttribute::XdmfAttribute() : ...@@ -42,7 +42,8 @@ XdmfAttribute::XdmfAttribute() :
mType(XdmfAttributeType::NoAttributeType()), mType(XdmfAttributeType::NoAttributeType()),
mItemType(""), mItemType(""),
mElementDegree(0), mElementDegree(0),
mElementFamily("") mElementFamily(""),
mElementCell("")
{ {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -53,7 +54,8 @@ XdmfAttribute::XdmfAttribute(XdmfAttribute & refAttribute) : ...@@ -53,7 +54,8 @@ XdmfAttribute::XdmfAttribute(XdmfAttribute & refAttribute) :
mType(refAttribute.mType), mType(refAttribute.mType),
mItemType(refAttribute.mItemType), mItemType(refAttribute.mItemType),
mElementDegree(refAttribute.mElementDegree), mElementDegree(refAttribute.mElementDegree),
mElementFamily(refAttribute.mElementFamily) mElementFamily(refAttribute.mElementFamily),
mElementCell(refAttribute.mElementCell)
{ {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -80,6 +82,7 @@ XdmfAttribute::getItemProperties() const ...@@ -80,6 +82,7 @@ XdmfAttribute::getItemProperties() const
attributeProperties.insert(std::make_pair("ElementDegree", attributeProperties.insert(std::make_pair("ElementDegree",
std::to_string(mElementDegree))); std::to_string(mElementDegree)));
attributeProperties.insert(std::make_pair("ElementFamily", mElementFamily)); attributeProperties.insert(std::make_pair("ElementFamily", mElementFamily));
attributeProperties.insert(std::make_pair("ElementCell", mElementCell));
return attributeProperties; return attributeProperties;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -116,6 +119,11 @@ std::string XdmfAttribute::getElementFamily() const ...@@ -116,6 +119,11 @@ std::string XdmfAttribute::getElementFamily() const
return mElementFamily; return mElementFamily;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string XdmfAttribute::getElementCell() const
{
return mElementCell;
}
//-----------------------------------------------------------------------------
void void
XdmfAttribute::populateItem( XdmfAttribute::populateItem(
const std::map<std::string, std::string> & itemProperties, const std::map<std::string, std::string> & itemProperties,
...@@ -150,6 +158,12 @@ XdmfAttribute::populateItem( ...@@ -150,6 +158,12 @@ XdmfAttribute::populateItem(
mElementFamily = element_family->second; mElementFamily = element_family->second;
} }
std::map<std::string, std::string>::const_iterator element_cell =
itemProperties.find("ElementCell");
if(element_cell != itemProperties.end()) {
mElementCell = element_cell->second;
}
std::map<std::string, std::string>::const_iterator item_type = std::map<std::string, std::string>::const_iterator item_type =
itemProperties.find("ItemType"); itemProperties.find("ItemType");
if(item_type != itemProperties.end()) { if(item_type != itemProperties.end()) {
...@@ -200,15 +214,24 @@ XdmfAttribute::populateItem( ...@@ -200,15 +214,24 @@ XdmfAttribute::populateItem(
{ {
cell_order_array = array; cell_order_array = array;
// Ignore other (third, etc.) children // Ignore other (fifth, etc.) children
break; break;
} }
} }
} }
std::vector<unsigned int> scalar_triangle_map = {0, 1, 2}; // Number of components
std::vector<unsigned int> scalar_quadratic_triangle_map = unsigned int ncomp = 1;
// Number of dofs per component
unsigned int dofs_per_component;
// Mapping of dofs per component to the correct VTK order
std::vector<unsigned int> triangle_map = {0, 1, 2};
std::vector<unsigned int> quadratic_triangle_map =
{0, 1, 2, 5, 3, 4}; {0, 1, 2, 5, 3, 4};
std::vector<unsigned int> tetrahedron_map = {0, 1, 2, 3, 4};
std::vector<unsigned int> quadratic_tetrahedron_map =
{0, 1, 2, 3, 9, 6, 8, 7, 5, 4};
std::vector<unsigned int> quadrilateral_map = {0, 1, 2, 3};
std::vector<unsigned int> dof_to_vtk_map; std::vector<unsigned int> dof_to_vtk_map;
// Prepare new array // Prepare new array
...@@ -217,6 +240,8 @@ XdmfAttribute::populateItem( ...@@ -217,6 +240,8 @@ XdmfAttribute::populateItem(
indices_array->getSize()); indices_array->getSize());
unsigned long index = 0; unsigned long index = 0;
unsigned long padded_index = 0;
// For each cell // For each cell
for (unsigned long cell = 0; cell < cell_order_array->getSize(); ++cell) for (unsigned long cell = 0; cell < cell_order_array->getSize(); ++cell)
{ {
...@@ -224,38 +249,83 @@ XdmfAttribute::populateItem( ...@@ -224,38 +249,83 @@ XdmfAttribute::populateItem(
unsigned long ordered_cell = unsigned long ordered_cell =
cell_order_array->getValue<unsigned long>(cell); cell_order_array->getValue<unsigned long>(cell);
// This number iterates through dofs in cell
unsigned int padded_dof_in_cell = 0;
// Compute number of degrees of freedom // Compute number of degrees of freedom
unsigned int number_dofs_in_cell = unsigned int number_dofs_in_cell =
number_of_dofs_array->getValue<unsigned int>(ordered_cell + 1) - number_of_dofs_array->getValue<unsigned int>(ordered_cell + 1) -
number_of_dofs_array->getValue<unsigned int>(ordered_cell); number_of_dofs_array->getValue<unsigned int>(ordered_cell);
if ((mElementFamily == "CG" or mElementFamily == "DG") if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 2 and mElementDegree == 2 and mElementCell == "triangle"
and number_dofs_in_cell == 6) and (number_dofs_in_cell % 6) == 0)
{ {
// If the cell is CG/DG2 with 6 dofs then it is quadratic_triangle dof_to_vtk_map = quadratic_triangle_map;
dof_to_vtk_map = scalar_quadratic_triangle_map; dofs_per_component = 6;
} else if ((mElementFamily == "CG" or mElementFamily == "DG") } else if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 1 and mElementDegree == 1 and mElementCell == "triangle"
and number_dofs_in_cell == 3) and (number_dofs_in_cell % 3) == 0)
{
dof_to_vtk_map = triangle_map;
dofs_per_component = 3;
} else if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 1 and mElementCell == "tetrahedron"
and (number_dofs_in_cell % 4) == 0)
{
dof_to_vtk_map = tetrahedron_map;
dofs_per_component = 4;
} else if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 2 and mElementCell == "tetrahedron"
and (number_dofs_in_cell % 10) == 0)
{
dof_to_vtk_map = quadratic_tetrahedron_map;
dofs_per_component = 10;
} else if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 1 and mElementCell == "quadrilateral"
and (number_dofs_in_cell % 4) == 0)
{
dof_to_vtk_map = quadrilateral_map;
dofs_per_component = 4;
} else {
XdmfError(XdmfError::FATAL, "Unsupported FiniteElementFunction type.");
}
ncomp = number_dofs_in_cell / dofs_per_component;
unsigned int padded_comps = 0;
if (mType == XdmfAttributeType::Vector())
{ {
// If CG/DG1 and 3 dofs then it is linear triangle padded_comps = 3 - ncomp;
dof_to_vtk_map = scalar_triangle_map;
} }
// For each degree of freedom in this cell
for (unsigned int dof_in_cell = 0; // For each degree of freedom per component in this cell
dof_in_cell < number_dofs_in_cell; ++dof_in_cell) for (unsigned int dof_per_component_in_cell = 0;
dof_per_component_in_cell < dofs_per_component;
++dof_per_component_in_cell)
{ {
// Get global reordered index for degree of freedom for (unsigned int comp = 0; comp < ncomp; ++comp)
unsigned long dof_index = {
// Get global reordered index for degree of freedom
unsigned long dof_index =
indices_array->getValue<unsigned long>(index + indices_array->getValue<unsigned long>(index +
dof_to_vtk_map[dof_in_cell]); dof_to_vtk_map[dof_per_component_in_cell] +
comp * dofs_per_component);
// Insert the value of degree of freedom
parsed_array->insert(padded_index + padded_dof_in_cell++,
values_array->getValue<double>(dof_index));
}
// Insert the value of degree of freedom for (unsigned int padded_comp = 0; padded_comp < padded_comps;
parsed_array->insert(index + dof_in_cell, ++padded_comp)
values_array->getValue<double>(dof_index)); {
parsed_array->insert(padded_index + padded_dof_in_cell++,
0.0);
}
} }
index = index + number_dofs_in_cell; index = index + number_dofs_in_cell;
padded_index = padded_index + padded_dof_in_cell;
} }
// And set the data to parent // And set the data to parent
...@@ -326,6 +396,13 @@ XdmfAttribute::setElementFamily(std::string family) ...@@ -326,6 +396,13 @@ XdmfAttribute::setElementFamily(std::string family)
this->setIsChanged(true); this->setIsChanged(true);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void
XdmfAttribute::setElementCell(std::string cell)
{
mElementCell = cell;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
// C Wrappers // C Wrappers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
XDMFATTRIBUTE * XdmfAttributeNew() XDMFATTRIBUTE * XdmfAttributeNew()
......
...@@ -184,6 +184,8 @@ public: ...@@ -184,6 +184,8 @@ public:
*/ */
unsigned int getElementDegree() const; unsigned int getElementDegree() const;
std::string getElementCell() const;
/** /**
* Set the XdmfAttributeCenter associated with this attribute. * Set the XdmfAttributeCenter associated with this attribute.
* *
...@@ -280,6 +282,8 @@ public: ...@@ -280,6 +282,8 @@ public:
*/ */
void setElementDegree(unsigned int degree); void setElementDegree(unsigned int degree);
void setElementCell(std::string cell);
XdmfAttribute(XdmfAttribute &); XdmfAttribute(XdmfAttribute &);
protected: protected:
...@@ -302,6 +306,7 @@ private: ...@@ -302,6 +306,7 @@ private:
std::string mItemType; std::string mItemType;
unsigned int mElementDegree; unsigned int mElementDegree;
std::string mElementFamily; std::string mElementFamily;
std::string mElementCell;
}; };
......
Markdown is supported
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