26 template <
typename QuadraticElement>
30 int const n_all_nodes = QuadraticElement::n_all_nodes;
31 int const n_base_nodes = QuadraticElement::n_base_nodes;
35 std::array<MeshLib::Node*, n_all_nodes> nodes{};
36 for (
int i = 0; i < n_base_nodes; i++)
43 for (
int i = 0; i < number_of_edges; i++)
49 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
52 return std::make_unique<QuadraticElement>(nodes, e.
getID());
57 std::unique_ptr<MeshLib::Quad9> convertLinearToQuadratic<MeshLib::Quad9>(
65 std::array<MeshLib::Node*, n_all_nodes> nodes{};
66 for (
int i = 0; i < n_base_nodes; i++)
73 for (
int i = 0; i < number_of_edges; i++)
79 (a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2);
84 for (
int i = 0; i < n_base_nodes; i++)
86 for (
int d = 0; d < 3; d++)
88 (*centre_node)[d] += (*nodes[i])[d] / n_base_nodes;
91 nodes[n_all_nodes - 1] = centre_node;
93 return std::make_unique<MeshLib::Quad9>(nodes, e.
getID());
102 return convertLinearToQuadratic<MeshLib::Line3>(e);
106 return convertLinearToQuadratic<MeshLib::Tri6>(e);
110 return convertLinearToQuadratic<MeshLib::Tet10>(e);
116 return convertLinearToQuadratic<MeshLib::Quad9>(e);
118 return convertLinearToQuadratic<MeshLib::Quad8>(e);
122 return convertLinearToQuadratic<MeshLib::Hex20>(e);
125 OGS_FATAL(
"Mesh element type {:s} is not supported",
140 bool const add_centre_node)
146 std::set<MeshLib::Node*, nodeByCoordinatesComparator> unique_nodes;
149 std::vector<MeshLib::Element*> quadratic_elements;
150 auto const& linear_mesh_elements = linear_mesh.
getElements();
156 int const number_base_nodes = quadratic_element->getNumberOfBaseNodes();
157 for (
int i = 0; i < number_base_nodes; ++i)
159 quadratic_element->setNode(
160 i, quadratic_mesh_nodes[
getNodeIndex(*quadratic_element, i)]);
164 int const number_all_nodes = quadratic_element->getNumberOfNodes();
165 for (
int i = number_base_nodes; i < number_all_nodes; ++i)
167 Node* original_node =
168 const_cast<Node*
>(quadratic_element->getNode(i));
170 auto it = unique_nodes.insert(original_node);
175 quadratic_element->setNode(i, *it.first);
177 delete original_node;
181 quadratic_elements.push_back(quadratic_element.release());
185 quadratic_mesh_nodes.reserve(linear_mesh.
getNodes().size() +
186 unique_nodes.size());
187 std::copy(unique_nodes.begin(), unique_nodes.end(),
188 std::back_inserter(quadratic_mesh_nodes));
190 return std::make_unique<MeshLib::Mesh>(
191 linear_mesh.
getName(), quadratic_mesh_nodes, quadratic_elements,
193 std::vector<MeshLib::MeshItemType>(1,
Definition of Duplicate functions.
Definition of the Element class.
Definition of the Hex class.
Definition of the Line class.
Definition of the Mesh class.
Definition of the Node class.
Definition of the Quad class.
std::unique_ptr< MeshLib::Element > createQuadraticElement(MeshLib::Element const &e, bool const add_centre_node)
Return a new quadratic element corresponding to the linear element's type.
std::unique_ptr< QuadraticElement > convertLinearToQuadratic(MeshLib::Element const &e)
Definition of the Tet class.
Definition of the Tri class.
virtual CellType getCellType() const =0
virtual const Node * getNode(unsigned idx) const =0
virtual unsigned getNumberOfBaseNodes() const =0
virtual Node * getEdgeNode(unsigned edge_id, unsigned node_id) const =0
Return a specific edge node.
virtual unsigned getNumberOfEdges() const =0
Get the number of edges for this element.
virtual std::size_t getID() const final
Returns the ID of the element.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
const std::string getName() const
Get name of the mesh.
Properties & getProperties()
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
static const unsigned n_all_nodes
Constant: The number of all nodes for this element.
static const unsigned n_base_nodes
Constant: The number of base nodes for this element.
void copy(PETScVector const &x, PETScVector &y)
std::vector< Node * > copyNodeVector(const std::vector< Node * > &nodes)
Creates a deep copy of a Node vector.
std::size_t getNodeIndex(Element const &element, unsigned const idx)
std::string CellType2String(const CellType t)
Given a MeshElemType this returns the appropriate string.
std::unique_ptr< Mesh > createQuadraticOrderMesh(Mesh const &linear_mesh, bool const add_centre_node)
bool operator()(MeshLib::Node *a, MeshLib::Node *b) const