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() :
mType(XdmfAttributeType::NoAttributeType()),
mItemType(""),
mElementDegree(0),
mElementFamily("")
mElementFamily(""),
mElementCell("")
{
}
//-----------------------------------------------------------------------------
......@@ -53,7 +54,8 @@ XdmfAttribute::XdmfAttribute(XdmfAttribute & refAttribute) :
mType(refAttribute.mType),
mItemType(refAttribute.mItemType),
mElementDegree(refAttribute.mElementDegree),
mElementFamily(refAttribute.mElementFamily)
mElementFamily(refAttribute.mElementFamily),
mElementCell(refAttribute.mElementCell)
{
}
//-----------------------------------------------------------------------------
......@@ -80,6 +82,7 @@ XdmfAttribute::getItemProperties() const
attributeProperties.insert(std::make_pair("ElementDegree",
std::to_string(mElementDegree)));
attributeProperties.insert(std::make_pair("ElementFamily", mElementFamily));
attributeProperties.insert(std::make_pair("ElementCell", mElementCell));
return attributeProperties;
}
//-----------------------------------------------------------------------------
......@@ -116,6 +119,11 @@ std::string XdmfAttribute::getElementFamily() const
return mElementFamily;
}
//-----------------------------------------------------------------------------
std::string XdmfAttribute::getElementCell() const
{
return mElementCell;
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::populateItem(
const std::map<std::string, std::string> & itemProperties,
......@@ -150,6 +158,12 @@ XdmfAttribute::populateItem(
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 =
itemProperties.find("ItemType");
if(item_type != itemProperties.end()) {
......@@ -200,15 +214,24 @@ XdmfAttribute::populateItem(
{
cell_order_array = array;
// Ignore other (third, etc.) children
// Ignore other (fifth, etc.) children
break;
}
}
}
std::vector<unsigned int> scalar_triangle_map = {0, 1, 2};
std::vector<unsigned int> scalar_quadratic_triangle_map =
// Number of components
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};
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;
// Prepare new array
......@@ -217,6 +240,8 @@ XdmfAttribute::populateItem(
indices_array->getSize());
unsigned long index = 0;
unsigned long padded_index = 0;
// For each cell
for (unsigned long cell = 0; cell < cell_order_array->getSize(); ++cell)
{
......@@ -224,38 +249,83 @@ XdmfAttribute::populateItem(
unsigned long ordered_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
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);
if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 2
and number_dofs_in_cell == 6)
and mElementDegree == 2 and mElementCell == "triangle"
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 = scalar_quadratic_triangle_map;
dof_to_vtk_map = quadratic_triangle_map;
dofs_per_component = 6;
} else if ((mElementFamily == "CG" or mElementFamily == "DG")
and mElementDegree == 1
and number_dofs_in_cell == 3)
and mElementDegree == 1 and mElementCell == "triangle"
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
dof_to_vtk_map = scalar_triangle_map;
padded_comps = 3 - ncomp;
}
// For each degree of freedom in this cell
for (unsigned int dof_in_cell = 0;
dof_in_cell < number_dofs_in_cell; ++dof_in_cell)
// For each degree of freedom per component in this 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
unsigned long dof_index =
for (unsigned int comp = 0; comp < ncomp; ++comp)
{
// Get global reordered index for degree of freedom
unsigned long dof_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
parsed_array->insert(index + dof_in_cell,
values_array->getValue<double>(dof_index));
for (unsigned int padded_comp = 0; padded_comp < padded_comps;
++padded_comp)
{
parsed_array->insert(padded_index + padded_dof_in_cell++,
0.0);
}
}
index = index + number_dofs_in_cell;
padded_index = padded_index + padded_dof_in_cell;
}
// And set the data to parent
......@@ -326,6 +396,13 @@ XdmfAttribute::setElementFamily(std::string family)
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setElementCell(std::string cell)
{
mElementCell = cell;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
// C Wrappers
//-----------------------------------------------------------------------------
XDMFATTRIBUTE * XdmfAttributeNew()
......
......@@ -184,6 +184,8 @@ public:
*/
unsigned int getElementDegree() const;
std::string getElementCell() const;
/**
* Set the XdmfAttributeCenter associated with this attribute.
*
......@@ -280,6 +282,8 @@ public:
*/
void setElementDegree(unsigned int degree);
void setElementCell(std::string cell);
XdmfAttribute(XdmfAttribute &);
protected:
......@@ -302,6 +306,7 @@ private:
std::string mItemType;
unsigned int mElementDegree;
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