ExaDG
Loading...
Searching...
No Matches
exadg_coupling.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2022 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_PRECICE_EXADG_COUPLING_H_
23#define INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_PRECICE_EXADG_COUPLING_H_
24
25// ExaDG
26#include <exadg/fluid_structure_interaction/precice/coupling_base.h>
27#include <exadg/functions_and_boundary_conditions/interface_coupling.h>
28#include <exadg/utilities/tensor_utilities.h>
29
30namespace ExaDG
31{
32namespace preCICE
33{
39template<int dim, int data_dim, typename VectorizedArrayType>
40class ExaDGCoupling : public CouplingBase<dim, data_dim, VectorizedArrayType>
41{
42public:
43 static unsigned int const rank = n_components_to_rank<data_dim, dim>();
44
46 dealii::MatrixFree<dim, double, VectorizedArrayType> const & data,
47#ifdef EXADG_WITH_PRECICE
48 std::shared_ptr<precice::SolverInterface> precice,
49#endif
50 std::string const mesh_name,
51 std::shared_ptr<ContainerInterfaceData<rank, dim, double>> interface_data_,
52 dealii::types::boundary_id const surface_id = dealii::numbers::invalid_unsigned_int);
53
58 virtual void
59 define_coupling_mesh() override;
60
69 virtual void
70 write_data(dealii::LinearAlgebra::distributed::Vector<double> const & data_vector,
71 std::string const & data_name) override;
72
73 virtual void
74 read_block_data(std::string const & data_name) const override;
75
76private:
78 std::shared_ptr<ContainerInterfaceData<rank, dim, double>> interface_data;
79
81 std::vector<int> coupling_nodes_ids;
82
83 virtual std::string
84 get_surface_type() const override;
85};
86
87
88
89template<int dim, int data_dim, typename VectorizedArrayType>
91 dealii::MatrixFree<dim, double, VectorizedArrayType> const & data,
92#ifdef EXADG_WITH_PRECICE
93 std::shared_ptr<precice::SolverInterface> precice,
94#endif
95 std::string const mesh_name,
96 std::shared_ptr<ContainerInterfaceData<rank, dim, double>> interface_data_,
97 dealii::types::boundary_id const surface_id)
98 : CouplingBase<dim, data_dim, VectorizedArrayType>(data,
99#ifdef EXADG_WITH_PRECICE
100 precice,
101#endif
102 mesh_name,
103 surface_id),
104 interface_data(interface_data_)
105{
106}
107
108
109
110template<int dim, int data_dim, typename VectorizedArrayType>
111void
113{
114 Assert(this->mesh_id != -1, dealii::ExcNotInitialized());
115 Assert(interface_data.get() != nullptr, dealii::ExcNotInitialized());
116
117 // In order to avoid that we define the surface multiple times when reader
118 // and writer refer to the same object
119 if(coupling_nodes_ids.size() > 0)
120 return;
121
122 for(auto quad_index : interface_data->get_quad_indices())
123 {
124 // returns std::vector<dealii::Point<dim>>
125 auto const & points = interface_data->get_array_q_points(quad_index);
126
127 // Get current size of our interface
128 auto const start_index = coupling_nodes_ids.size();
129
130 // Allocate memory for new interface nodes
131 coupling_nodes_ids.resize(start_index + points.size());
132
133 // Set the vertices
134#ifdef EXADG_WITH_PRECICE
135 this->precice->setMeshVertices(this->mesh_id,
136 points.size(),
137 &points[0][0],
138 &coupling_nodes_ids[start_index]);
139#endif
140 }
141
142#ifdef EXADG_WITH_PRECICE
143 if(this->read_data_map.size() > 0)
144 this->print_info(true, this->precice->getMeshVertexSize(this->mesh_id));
145 if(this->write_data_map.size() > 0)
146 this->print_info(false, this->precice->getMeshVertexSize(this->mesh_id));
147#endif
148}
149
150
151template<int dim, int data_dim, typename VectorizedArrayType>
152void
154 std::string const & data_name) const
155{
156 Assert(interface_data.get() != nullptr, dealii::ExcNotInitialized());
157
158 int const read_data_id = this->read_data_map.at(data_name);
159
160 // summarizing the IDs already read
161 unsigned int start_index = 0;
162 // extract values of each quadrature rule
163 for(auto quad_index : interface_data->get_quad_indices())
164 {
165 if constexpr(data_dim > 1)
166 {
167 auto & array_solution = interface_data->get_array_solution(quad_index);
168 auto const array_size = array_solution.size();
169
170 AssertIndexRange(start_index, coupling_nodes_ids.size());
171#ifdef EXADG_WITH_PRECICE
172 this->precice->readBlockVectorData(read_data_id,
173 array_size,
174 &coupling_nodes_ids[start_index],
175 &array_solution[0][0]);
176#else
177 (void)read_data_id;
178#endif
179 start_index += array_size;
180 }
181 else
182 {
183 AssertThrow(false, dealii::ExcNotImplemented());
184 }
185 }
186}
187
188
189
190template<int dim, int data_dim, typename VectorizedArrayType>
191void
193 dealii::LinearAlgebra::distributed::Vector<double> const &,
194 std::string const &)
195{
196 AssertThrow(false, dealii::ExcNotImplemented());
197}
198
199
200template<int dim, int data_dim, typename VectorizedArrayType>
201std::string
203{
204 return "exadg shallow wrapper";
205}
206
207} // namespace preCICE
208} // namespace ExaDG
209
210#endif
Definition container_interface_data.h:45
Definition coupling_base.h:66
std::string const mesh_name
public precice solverinterface
Definition coupling_base.h:152
Definition exadg_coupling.h:41
virtual void define_coupling_mesh() override
define_mesh_vertices Define a vertex coupling mesh for preCICE coupling the classical preCICE way
Definition exadg_coupling.h:112
virtual void write_data(dealii::LinearAlgebra::distributed::Vector< double > const &data_vector, std::string const &data_name) override
write_data
Definition exadg_coupling.h:192
Definition driver.cpp:33