24 #include "utilities/geometry_utilities.h"
50 template<
unsigned int TDim>
58 static constexpr std::size_t
NumNodes = TDim + 1;
61 static constexpr std::size_t
NumEdges = TDim == 2 ? 3 : 6;
125 mAEC = AntidiffusiveEedgeContribution;
135 mMij += Weight * Ni * Nj;
136 for (std::size_t
d = 0;
d < TDim; ++
d) {
137 mLij += Weight * rDNiDX[
d] * rDNjDX[
d];
138 mNiDNj[
d] += Weight * Ni * rDNjDX[
d];
139 mDNiNj[
d] += Weight * rDNiDX[
d] * Nj;
150 for (std::size_t
d = 0;
d < TDim; ++
d) {
151 mNiNjNormal[
d] += Weight * Ni * Nj * rUnitNormal[
d];
160 bool mIsBoundary =
false;
161 double mLength = 0.0;
222 CheckGeometryTypes(rModelPart);
227 FillEdgesSparseGraph(rModelPart, edges_graph);
231 CalculateEdgeDataValues(rModelPart, edges_graph);
240 mMassMatrixDiagonal.clear();
241 mLumpedMassMatrixDiagonal.clear();
265 return mMassMatrixDiagonal;
270 return mMassMatrixDiagonal[I-1];
275 return mBoundaryMassMatrixDiagonal;
280 return mBoundaryMassMatrixDiagonal[I-1];
285 return mLumpedMassMatrixDiagonal;
290 return mLumpedMassMatrixDiagonal[I-1];
302 const IndexType ij_col_vect_index = GetColumVectorIndex(I,
J);
303 return *(mEdgeData[ij_col_vect_index]);
310 const IndexType ij_col_vect_index = GetColumVectorIndex(I,
J);
311 return *(mEdgeData[ij_col_vect_index]);
326 std::stringstream buffer;
327 buffer <<
"EdgeBasedDataStructure";
334 rOStream <<
"EdgeBasedDataStructure" << std::endl;
412 void CheckGeometryTypes(
const ModelPart&)
417 void FillEdgesSparseGraph(
418 const ModelPart& rModelPart,
424 for (
auto& r_node : rModelPart.Nodes()) {
427 std::vector<IndexType> col_ids;
430 auto& r_node_neighs = r_node.GetValue(NEIGHBOUR_NODES);
431 for (
auto& r_neigh : r_node_neighs) {
435 col_ids.push_back(j_id);
440 if (col_ids.size() != 0) {
441 rEdgesSparseGraph.AddEntries(i_id, col_ids);
446 rEdgesSparseGraph.Finalize();
449 void CalculateEdgeDataValues(
450 const ModelPart& rModelPart,
454 KRATOS_ERROR_IF(mNumEdges == 0) <<
"No edges in model part '" << rModelPart.FullName() <<
"'." << std::endl;
455 mEdgeData.resize(mNumEdges);
456 mMassMatrixDiagonal.resize(rModelPart.NumberOfNodes());
457 mLumpedMassMatrixDiagonal.resize(rModelPart.NumberOfNodes());
458 mBoundaryMassMatrixDiagonal.resize(rModelPart.NumberOfNodes());
461 std::fill(mMassMatrixDiagonal.begin(), mMassMatrixDiagonal.end(), 0.0);
462 std::fill(mLumpedMassMatrixDiagonal.begin(), mLumpedMassMatrixDiagonal.end(), 0.0);
463 std::fill(mBoundaryMassMatrixDiagonal.begin(), mBoundaryMassMatrixDiagonal.end(),
ZeroVector(TDim));
467 array_1d<double, NumNodes> fake_N;
468 BoundedMatrix<double, NumNodes, TDim> DNDX;
469 BoundedMatrix<double, NumEdges, NumNodes>
N;
470 BoundedMatrix<double, NumEdgesFace, NumNodesFace> N_face;
473 for (
auto& r_element : rModelPart.Elements()) {
475 GetEdgeShapeFunctionsValues(
N);
476 const auto& r_geom = r_element.GetGeometry();
484 const auto& r_N =
row(
N, g);
503 const IndexType aux_i_id = r_geom[aux_i].Id();
504 const IndexType aux_j_id = r_geom[aux_j].Id();
509 auto& rp_edge_data = pGetEdgeData(aux_i_id, aux_j_id);
510 if (rp_edge_data ==
nullptr) {
511 rp_edge_data = std::move(Kratos::make_unique<EdgeData>());
512 rp_edge_data->SetLength(
norm_2(r_geom[aux_i].Coordinates()-r_geom[aux_j].Coordinates()));
516 rp_edge_data->AddOffDiagonalValues(
w_gauss, r_N[aux_i], r_N[aux_j],
row(DNDX, aux_i),
row(DNDX, aux_j));
524 const double aux_mass =
w_gauss * r_N[
i] * r_N[
i];
525 mMassMatrixDiagonal[i_row] += aux_mass;
526 mLumpedMassMatrixDiagonal[i_row] += 2.0 * aux_mass;
533 KRATOS_ERROR_IF(rModelPart.GetCommunicator().GlobalNumberOfConditions() == 0) <<
"No conditions found in model part '" << rModelPart.FullName() <<
"'." << std::endl;
534 array_1d<double,TDim> unit_normal;
535 for (
auto& r_condition : rModelPart.Conditions()) {
537 const auto& r_geom = r_condition.GetGeometry();
538 GetEdgeFaceShapeFunctionsValues(N_face);
539 CalculateUnitNormal(r_geom, unit_normal);
547 const auto& r_N_face =
row(N_face, g);
566 const IndexType aux_i_id = r_geom[aux_i].Id();
567 const IndexType aux_j_id = r_geom[aux_j].Id();
570 auto& rp_edge_data = pGetEdgeData(aux_i_id, aux_j_id);
571 KRATOS_ERROR_IF(rp_edge_data ==
nullptr) <<
"Boundary edge " << aux_i_id <<
"-" << aux_j_id <<
" data structure is not present." << std::endl;
572 rp_edge_data->AddConvectiveBoundaryValue(
w_gauss, r_N_face[aux_i], r_N_face[aux_j], unit_normal);
581 const double aux_mass =
w_gauss * r_N_face[
i] * r_N_face[
i];
582 noalias(mBoundaryMassMatrixDiagonal[i_row]) += aux_mass * unit_normal;
588 void CalculateUnitNormal(
589 const Geometry<Node>& rGeometry,
590 array_1d<double, TDim>& rUnitNormal)
const
592 if constexpr (TDim == 2) {
593 rUnitNormal[0] = rGeometry[1].Y() - rGeometry[0].Y();
594 rUnitNormal[1] = -(rGeometry[1].X() - rGeometry[0].X());
596 array_1d<double, 3> v1, v2;
597 v1[0] = rGeometry[1].X() - rGeometry[0].X();
598 v1[1] = rGeometry[1].Y() - rGeometry[0].Y();
599 v1[2] = rGeometry[1].Z() - rGeometry[0].Z();
601 v2[0] = rGeometry[2].X() - rGeometry[0].X();
602 v2[1] = rGeometry[2].Y() - rGeometry[0].Y();
603 v2[2] = rGeometry[2].Z() - rGeometry[0].Z();
609 const double n_norm =
norm_2(rUnitNormal);
610 KRATOS_WARNING_IF(
"EdgeBasedDataStructure", n_norm < 1.0e-12) <<
"Normal is close to zero." << std::endl;
611 rUnitNormal /= n_norm;
614 void GetEdgeShapeFunctionsValues(BoundedMatrix<double, NumEdges, NumNodes>& rN)
const
616 if constexpr (TDim == 2) {
617 rN(0,0) = 0.5; rN(0,1) = 0.5; rN(0,2) = 0.0;
618 rN(1,0) = 0.0; rN(1,1) = 0.5; rN(1,2) = 0.5;
619 rN(2,0) = 0.5; rN(2,1) = 0.0; rN(2,2) = 0.5;
621 rN(0,0) = 0.5; rN(0,1) = 0.5; rN(0,2) = 0.0; rN(0,3) = 0.0;
622 rN(1,0) = 0.0; rN(1,1) = 0.5; rN(1,2) = 0.5; rN(1,3) = 0.0;
623 rN(2,0) = 0.0; rN(2,1) = 0.0; rN(2,2) = 0.5; rN(2,3) = 0.5;
624 rN(3,0) = 0.5; rN(3,1) = 0.0; rN(3,2) = 0.5; rN(3,3) = 0.0;
625 rN(4,0) = 0.5; rN(4,1) = 0.0; rN(4,2) = 0.0; rN(4,3) = 0.5;
626 rN(5,0) = 0.0; rN(5,1) = 0.5; rN(5,2) = 0.0; rN(5,3) = 0.5;
630 void GetEdgeFaceShapeFunctionsValues(BoundedMatrix<double, NumEdgesFace, NumNodesFace>& rN)
const
632 if constexpr (TDim == 2) {
633 rN(0,0) = 0.5; rN(0,1) = 0.5;
635 rN(0,0) = 0.5; rN(0,1) = 0.5; rN(0,2) = 0.0;
636 rN(1,0) = 0.0; rN(1,1) = 0.5; rN(1,2) = 0.5;
637 rN(2,0) = 0.5; rN(2,1) = 0.0; rN(2,2) = 0.5;
660 const IndexType i_row_index = mRowIndices[I];
661 for (
auto it = mColIndices.begin() + i_row_index; it != mColIndices.end(); ++it) {
663 j_col_index = std::distance(mColIndices.begin(), it);
679 const IndexType ij_col_index = GetColumVectorIndex(aux_i_id, aux_j_id);
680 KRATOS_ERROR_IF(ij_col_index < 0) <<
"Column index cannot be found for ij-edge " << GlobalIdI <<
"-" << GlobalIdJ <<
"." << std::endl;
682 return mEdgeData[ij_col_index];
708 template <
unsigned int TDim>
710 std::istream &rIStream,
717 template <
unsigned int TDim>
719 std::ostream &rOStream,
723 rOStream << std::endl;
Definition: edge_based_data_structure.h:71
void AddOffDiagonalValues(const double Weight, const double Ni, const double Nj, const array_1d< double, TDim > &rDNiDX, const array_1d< double, TDim > &rDNjDX)
Definition: edge_based_data_structure.h:128
double GetLength() const
Definition: edge_based_data_structure.h:83
const array_1d< double, TDim > & GetOffDiagonalConvectiveBoundary() const
Definition: edge_based_data_structure.h:113
double GetOffDiagonalLaplacian() const
Definition: edge_based_data_structure.h:93
const array_1d< double, TDim > & GetOffDiagonalConvectiveTranspose() const
Definition: edge_based_data_structure.h:108
double GetOffDiagonalConsistentMass() const
Definition: edge_based_data_structure.h:88
void SetLength(const double Length)
Definition: edge_based_data_structure.h:118
const array_1d< double, TDim > & GetOffDiagonalConvective() const
Definition: edge_based_data_structure.h:103
bool IsBoundary() const
Definition: edge_based_data_structure.h:78
double GetAntidiffusiveEdgeContribution() const
Definition: edge_based_data_structure.h:98
EdgeData(const EdgeData &rOther)=delete
void AddConvectiveBoundaryValue(const double Weight, const double Ni, const double Nj, const array_1d< double, TDim > &rUnitNormal)
Definition: edge_based_data_structure.h:143
void SetAntidiffusiveEdgeContribution(const double AntidiffusiveEedgeContribution)
Definition: edge_based_data_structure.h:123
Definition: edge_based_data_structure.h:52
void CalculateEdgeDataStructure(const ModelPart &rModelPart)
Definition: edge_based_data_structure.h:219
static constexpr std::size_t NumEdges
Definition: edge_based_data_structure.h:61
std::string Info() const
Turn back information as a string.
Definition: edge_based_data_structure.h:324
std::size_t SizeType
Size type definition.
Definition: edge_based_data_structure.h:174
std::vector< double > MassMatrixVectorType
CSR storage mass matrices vector definition.
Definition: edge_based_data_structure.h:189
const IndicesVectorType & GetRowIndices() const
Definition: edge_based_data_structure.h:253
const MassMatrixVectorType & GetMassMatrixDiagonal() const
Definition: edge_based_data_structure.h:263
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: edge_based_data_structure.h:339
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: edge_based_data_structure.h:332
static constexpr std::size_t NumEdgesFace
Definition: edge_based_data_structure.h:64
std::size_t IndexType
Index type definition.
Definition: edge_based_data_structure.h:171
const IndicesVectorType & GetColIndices() const
Definition: edge_based_data_structure.h:258
static constexpr std::size_t NumNodesFace
Definition: edge_based_data_structure.h:67
std::vector< IndexType > IndicesVectorType
CSR storage indices vector definition.
Definition: edge_based_data_structure.h:183
std::vector< array_1d< double, TDim > > BoundaryMassMatrixVectorType
CSR storage boundary mass matrices vector definition.
Definition: edge_based_data_structure.h:192
SparseGraph< IndexType > SparseGraphType
Sparse graph definition.
Definition: edge_based_data_structure.h:180
const EdgeData & GetEdgeData(IndexType I, IndexType J) const
Definition: edge_based_data_structure.h:306
const BoundaryMassMatrixVectorType & GetBoundaryMassMatrixDiagonal() const
Definition: edge_based_data_structure.h:273
EdgeBasedDataStructure & operator=(const EdgeBasedDataStructure &rOther)=delete
Assignment operator.
SizeType NumberOfEdges() const
Definition: edge_based_data_structure.h:248
static constexpr std::size_t NumNodes
Definition: edge_based_data_structure.h:58
const MassMatrixVectorType & GetLumpedMassMatrixDiagonal() const
Definition: edge_based_data_structure.h:283
EdgeData & GetEdgeData(IndexType I, IndexType J)
Definition: edge_based_data_structure.h:298
~EdgeBasedDataStructure()=default
Destructor.
void Clear()
Definition: edge_based_data_structure.h:234
const EdgeDataVectorType & GetEdgeData() const
Definition: edge_based_data_structure.h:293
std::unique_ptr< EdgeData > EdgeDataPointerType
Edge data container pointer type.
Definition: edge_based_data_structure.h:177
std::vector< EdgeDataPointerType > EdgeDataVectorType
CSR storage off-diagonal values vector definition.
Definition: edge_based_data_structure.h:186
const array_1d< double, TDim > & GetBoundaryMassMatrixDiagonal(IndexType I) const
Definition: edge_based_data_structure.h:278
KRATOS_CLASS_POINTER_DEFINITION(EdgeBasedDataStructure)
Pointer definition of EdgeBasedDataStructure.
EdgeBasedDataStructure()=default
Constructor.
double GetMassMatrixDiagonal(IndexType I) const
Definition: edge_based_data_structure.h:268
double GetLumpedMassMatrixDiagonal(IndexType I) const
Definition: edge_based_data_structure.h:288
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
Short class definition.
Definition: sparse_graph.h:66
IndexType ExportCSRArrays(TVectorType &rRowIndices, TVectorType &rColIndices) const
Definition: sparse_graph.h:215
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int domain_size
Definition: face_heat.py:4
w_gauss
Definition: generate_convection_diffusion_explicit_element.py:136
def load(f)
Definition: ode_solve.py:307
int d
Definition: ode_solve.py:397
int j
Definition: quadrature.py:648
J
Definition: sensitivityMatrix.py:58
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17