KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
skyline_lu_custom_scalar_solver.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Michael Andre, https://github.com/msandre
11 //
12 //
13 
14 // System includes
15 #include <iostream>
16 #include <complex>
17 #include <vector>
18 #include <algorithm>
19 
20 // External includes
21 #include <memory>
22 #include <amgcl/backend/builtin.hpp>
23 #include <amgcl/adapter/zero_copy.hpp>
24 #include <amgcl/value_type/complex.hpp>
25 #include <amgcl/solver/skyline_lu.hpp>
26 
27 // Project includes
28 #include "includes/define.h"
32 
33 #if !defined(KRATOS_SKYLINE_LU_CUSTOM_SCALAR_SOLVER_H_INCLUDED)
34 #define KRATOS_SKYLINE_LU_CUSTOM_SCALAR_SOLVER_H_INCLUDED
35 
36 namespace Kratos {
37 
40 
41 template <class TSparseSpaceType, class TDenseSpaceType, class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType>>
43  : public DirectSolver<TSparseSpaceType, TDenseSpaceType, TReordererType>
44 {
45 public:
47 
49 
51 
53 
54  typedef typename TSparseSpaceType::DataType DataType;
55 
56  typedef typename amgcl::backend::builtin<DataType>::matrix BuiltinMatrixType;
57 
58  typedef amgcl::solver::skyline_lu<DataType> SolverType;
59 
61  : DirectSolver<TSparseSpaceType, TDenseSpaceType, TReordererType>()
62  {
63  }
64 
66  : DirectSolver<TSparseSpaceType, TDenseSpaceType, TReordererType>(rParam)
67  {
68  }
69 
71  {
72  Clear();
73  }
74 
76  {
77  Clear();
78 
79  pBuiltinMatrix = amgcl::adapter::zero_copy(
80  rA.size1(),
81  rA.index1_data().begin(),
82  rA.index2_data().begin(),
83  rA.value_data().begin());
84 
85  pSolver = Kratos::make_shared<SolverType>(*pBuiltinMatrix);
86  }
87 
89  {
90  std::vector<DataType> x(rX.size());
91  std::vector<DataType> b(rB.size());
92 
93  std::copy(std::begin(rB), std::end(rB), std::begin(b));
94 
95  (*pSolver)(b, x);
96 
97  std::copy(std::begin(x), std::end(x), std::begin(rX));
98  }
99 
100  bool Solve(SparseMatrixType& rA, VectorType& rX, VectorType& rB) override
101  {
102  InitializeSolutionStep(rA, rX, rB);
103  PerformSolutionStep(rA, rX, rB);
104  FinalizeSolutionStep(rA, rX, rB);
105 
106  return true;
107  }
108 
110  {
111  Clear();
112  }
113 
114  void Clear() override
115  {
116  pSolver.reset();
117  pBuiltinMatrix.reset();
118  }
119 
120  void PrintInfo(std::ostream& rOStream) const override
121  {
122  rOStream << "Skyline LU custom scalar solver";
123  }
124 
125 private:
126 
128 
130 };
131 
133 
136 
138 template<class TSparseSpaceType, class TDenseSpaceType, class TReordererType>
139 inline std::istream& operator >>(std::istream& rIStream,
141  return rIStream;
142 }
143 
145 template<class TSparseSpaceType, class TDenseSpaceType, class TReordererType>
146 inline std::ostream& operator <<(std::ostream& rOStream,
148  rThis.PrintInfo(rOStream);
149  rOStream << std::endl;
150  rThis.PrintData(rOStream);
151 
152  return rOStream;
153 }
155 
156 }// namespace Kratos.
157 
158 #endif // KRATOS_SKYLINE_LU_CUSTOM_SCALAR_SOLVER_H_INCLUDED defined
Definition: direct_solver.h:48
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: direct_solver.h:79
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
Definition: skyline_lu_custom_scalar_solver.h:44
SkylineLUCustomScalarSolver()
Definition: skyline_lu_custom_scalar_solver.h:60
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: skyline_lu_custom_scalar_solver.h:120
TSparseSpaceType::DataType DataType
Definition: skyline_lu_custom_scalar_solver.h:54
~SkylineLUCustomScalarSolver() override
Definition: skyline_lu_custom_scalar_solver.h:70
void Clear() override
Definition: skyline_lu_custom_scalar_solver.h:114
KRATOS_CLASS_POINTER_DEFINITION(SkylineLUCustomScalarSolver)
bool Solve(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: skyline_lu_custom_scalar_solver.h:100
amgcl::solver::skyline_lu< DataType > SolverType
Definition: skyline_lu_custom_scalar_solver.h:58
SkylineLUCustomScalarSolver(Parameters &rParam)
Definition: skyline_lu_custom_scalar_solver.h:65
void FinalizeSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: skyline_lu_custom_scalar_solver.h:109
void InitializeSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: skyline_lu_custom_scalar_solver.h:75
TDenseSpaceType::MatrixType DenseMatrixType
Definition: skyline_lu_custom_scalar_solver.h:52
void PerformSolutionStep(SparseMatrixType &rA, VectorType &rX, VectorType &rB) override
Definition: skyline_lu_custom_scalar_solver.h:88
amgcl::backend::builtin< DataType >::matrix BuiltinMatrixType
Definition: skyline_lu_custom_scalar_solver.h:56
TSparseSpaceType::VectorType VectorType
Definition: skyline_lu_custom_scalar_solver.h:50
TSparseSpaceType::MatrixType SparseMatrixType
Definition: skyline_lu_custom_scalar_solver.h:48
end
Definition: DEM_benchmarks.py:180
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
x
Definition: sensitivityMatrix.py:49