Line data Source code
1 : /*
2 : * Copyright (c) 2014: G-CSC, Goethe University Frankfurt
3 : * Author: Martin Rupp
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : // extern headers
34 : #include <iostream>
35 : #include <sstream>
36 : #include <string>
37 :
38 : // include bridge
39 : #include "bridge/bridge.h"
40 : #include "bridge/util.h"
41 : #include "bridge/util_algebra_dependent.h"
42 : #include "bridge/util_domain_algebra_dependent.h"
43 :
44 : // preconditioner
45 : #include "lib_algebra/lib_algebra.h"
46 : #include "lib_algebra/operator/interface/constrained_linear_iterator.h"
47 : #include "bridge/util_overloaded.h"
48 : #include "super_lu.h"
49 :
50 : using namespace std;
51 :
52 : namespace ug{
53 :
54 : namespace bridge{
55 : namespace SuperLUBridge{
56 :
57 :
58 : struct Functionality
59 : {
60 :
61 :
62 : /**
63 : * Function called for the registration of Algebra dependent parts.
64 : * All Functions and Classes depending on Algebra
65 : * are to be placed here when registering. The method is called for all
66 : * available Algebra types, based on the current build options.
67 : *
68 : * @param reg registry
69 : * @param parentGroup group for sorting of functionality
70 : */
71 : template <typename TAlgebra, typename TRegistry=ug::bridge::Registry>
72 3 : static void Algebra(TRegistry& reg, string grp)
73 : {
74 3 : string suffix = GetAlgebraSuffix<TAlgebra>();
75 3 : string tag = GetAlgebraTag<TAlgebra>();
76 :
77 : // typedefs for this algebra
78 : typedef typename TAlgebra::vector_type vector_type;
79 : typedef typename TAlgebra::matrix_type matrix_type;
80 :
81 : // SuperLU Solver
82 : {
83 : typedef SuperLUSolver<TAlgebra> T;
84 : typedef IExternalSolver<TAlgebra> TBase1;
85 : typedef ILinearOperatorInverse<vector_type> TBase2;
86 3 : string name = string("SuperLU").append(suffix);
87 9 : reg.template add_class_<T,TBase1,TBase2>(name, grp, "SuperLU")
88 3 : .add_constructor()
89 9 : .add_method("print_stat", &T::print_stat)
90 12 : .add_method("equil", &T::equil)
91 12 : .add_method("col_perm_natural", &T::col_perm_natural)
92 12 : .add_method("col_perm_mdo_ATA", &T::col_perm_mdo_ATA)
93 12 : .add_method("col_perm_mdo_AT_plus_A", &T::col_perm_mdo_AT_plus_A)
94 9 : .add_method("col_perm_approximate", &T::col_perm_approximate)
95 3 : .set_construct_as_smart_pointer(true);
96 9 : reg.add_class_to_group(name, "SuperLU", tag);
97 : }
98 3 : }
99 :
100 : template <typename TDomain, typename TAlgebra, typename TRegistry=ug::bridge::Registry>
101 9 : static void DomainAlgebra(TRegistry& reg, string grp)
102 : {
103 : string suffix = GetDomainAlgebraSuffix<TDomain,TAlgebra>();
104 : string tag = GetDomainAlgebraTag<TDomain,TAlgebra>();
105 :
106 : // constrained SuperLU
107 : {
108 : typedef ConstrainedLinearIterator<TDomain, TAlgebra, SuperLUSolver<TAlgebra> > T;
109 : typedef SuperLUSolver<TAlgebra> TBase;
110 9 : string name = string("SuperLU_c").append(suffix);
111 27 : reg.template add_class_<T,TBase>(name, grp, "SuperLU solver respecting constraints")
112 18 : .template add_constructor<void (*)(SmartPtr<IDomainDiscretization<TAlgebra> >)>("domain discretization")
113 18 : .add_method("set_time", &T::set_time, "", "time")
114 9 : .set_construct_as_smart_pointer(true);
115 27 : reg.add_class_to_group(name, "SuperLU_c", tag);
116 : }
117 9 : }
118 :
119 :
120 : }; // end Functionality
121 :
122 : // end group precond_bridge
123 : /// \}
124 :
125 : }// end Preconditioner
126 :
127 : /// \addtogroup precond_bridge
128 : template <typename TRegistry=ug::bridge::Registry>
129 1 : void RegisterBridge_SuperLU(TRegistry& reg, string grp)
130 : {
131 1 : grp.append("/Algebra/ExternalSolvers/");
132 : typedef SuperLUBridge::Functionality Functionality;
133 :
134 : try{
135 : #ifndef UG_USE_PYBIND11
136 2 : RegisterAlgebraDependent<Functionality>(reg,grp);
137 1 : RegisterDomainAlgebraDependent<Functionality>(reg,grp);
138 : #else
139 : RegisterAlgebraDependent<Functionality, TRegistry>(reg,grp);
140 : RegisterDomainAlgebraDependent<Functionality, TRegistry>(reg,grp);
141 : #endif
142 : }
143 0 : UG_REGISTRY_CATCH_THROW(grp);
144 1 : }
145 :
146 :
147 : // The following functions are the exported
148 : extern "C" void
149 1 : InitUGPlugin_SuperLU6(Registry* reg, string grp)
150 : {
151 1 : RegisterBridge_SuperLU(*reg, grp);
152 1 : }
153 :
154 :
155 : #ifdef UG_USE_PYBIND11 // Expose for pybind11.
156 : namespace SuperLUBridge{
157 : void InitUGPlugin(ug::pybind::Registry* reg, string grp)
158 : {
159 : RegisterBridge_SuperLU<ug::pybind::Registry>(*reg, grp);
160 : }
161 : }
162 : #endif
163 :
164 :
165 : } // namespace bridge
166 : } // namespace ug
|