ExaDG
Loading...
Searching...
No Matches
coupling_base.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_COUPLING_BASE_H_
23#define INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_PRECICE_COUPLING_BASE_H_
24
25// deal.II
26#include <deal.II/base/conditional_ostream.h>
27#include <deal.II/base/vectorization.h>
28
29#include <deal.II/matrix_free/matrix_free.h>
30
31// ExaDG
32#include <exadg/matrix_free/integrators.h>
33
34// preCICE
35#ifdef EXADG_WITH_PRECICE
36# include <precice/SolverInterface.hpp>
37#endif
38
39namespace ExaDG
40{
41namespace preCICE
42{
46enum class WriteDataType
47{
48 undefined,
49 values_on_dofs,
50 values_on_other_mesh,
51 gradients_on_other_mesh,
52 values_on_q_points,
53 normal_gradients_on_q_points
54};
55
64template<int dim, int data_dim, typename VectorizedArrayType>
66{
67public:
68 CouplingBase(dealii::MatrixFree<dim, double, VectorizedArrayType> const & data,
69#ifdef EXADG_WITH_PRECICE
70 std::shared_ptr<precice::SolverInterface> precice,
71#endif
72 std::string const mesh_name,
73 dealii::types::boundary_id const surface_id);
74
75 virtual ~CouplingBase() = default;
76
78 using FEFaceIntegrator = FaceIntegrator<dim, data_dim, double, VectorizedArrayType>;
79 using value_type = typename FEFaceIntegrator::value_type;
84 virtual void
86
93 virtual void
95
103 virtual void
104 write_data(dealii::LinearAlgebra::distributed::Vector<double> const & data_vector,
105 std::string const & data_name) = 0;
106
107
108 virtual void
109 read_block_data(std::string const & data_name) const;
110
115 void
116 add_read_data(std::string const & read_data_name);
117
122 void
123 add_write_data(std::string const & write_data_name);
124
129 void
130 set_write_data_type(WriteDataType write_data_specification);
131
132protected:
140 void
141 print_info(bool const reader, unsigned int const local_size) const;
142
144 dealii::MatrixFree<dim, double, VectorizedArrayType> const & matrix_free;
145
147#ifdef EXADG_WITH_PRECICE
148 std::shared_ptr<precice::SolverInterface> precice;
149#endif
150
152 std::string const mesh_name;
153 int mesh_id;
154 // Map between data ID (preCICE) and the data name
155 std::map<std::string, int> read_data_map;
156 std::map<std::string, int> write_data_map;
157
158 dealii::types::boundary_id const dealii_boundary_surface_id;
159
160 WriteDataType write_data_type;
161
162 virtual std::string
163 get_surface_type() const = 0;
164};
165
166
167
168template<int dim, int data_dim, typename VectorizedArrayType>
170 dealii::MatrixFree<dim, double, VectorizedArrayType> const & matrix_free_,
171#ifdef EXADG_WITH_PRECICE
172 std::shared_ptr<precice::SolverInterface> precice,
173#endif
174 std::string const mesh_name,
175 dealii::types::boundary_id const surface_id)
176 : matrix_free(matrix_free_),
177#ifdef EXADG_WITH_PRECICE
178 precice(precice),
179#endif
180 mesh_name(mesh_name),
181 dealii_boundary_surface_id(surface_id),
182 write_data_type(WriteDataType::undefined)
183{
184#ifdef EXADG_WITH_PRECICE
185 Assert(precice.get() != nullptr, dealii::ExcNotInitialized());
186
187 // Ask preCICE already in the constructor for the IDs
188 mesh_id = precice->getMeshID(mesh_name);
189#else
190 AssertThrow(false,
191 dealii::ExcMessage("EXADG_WITH_PRECICE has to be activated to use this code."));
192 mesh_id = 0;
193#endif
194}
195
196
197template<int dim, int data_dim, typename VectorizedArrayType>
198void
200{
201 Assert(mesh_id != -1, dealii::ExcNotInitialized());
202#ifdef EXADG_WITH_PRECICE
203 int const read_data_id = precice->getDataID(read_data_name, mesh_id);
204#else
205 int const read_data_id = 0;
206#endif
207 read_data_map.insert({read_data_name, read_data_id});
208}
209
210
211
212template<int dim, int data_dim, typename VectorizedArrayType>
213void
215 std::string const & write_data_name)
216{
217 Assert(mesh_id != -1, dealii::ExcNotInitialized());
218#ifdef EXADG_WITH_PRECICE
219 int const write_data_id = precice->getDataID(write_data_name, mesh_id);
220#else
221 int const write_data_id = 0;
222#endif
223 write_data_map.insert({write_data_name, write_data_id});
224}
225
226
227template<int dim, int data_dim, typename VectorizedArrayType>
228void
230 WriteDataType write_data_specification)
231{
232 write_data_type = write_data_specification;
233}
234
235
236
237template<int dim, int data_dim, typename VectorizedArrayType>
238void
243
244
245
246template<int dim, int data_dim, typename VectorizedArrayType>
247void
249{
250 AssertThrow(false, dealii::ExcNotImplemented());
251}
252
253
254template<int dim, int data_dim, typename VectorizedArrayType>
255void
257 unsigned int const local_size) const
258{
259 dealii::ConditionalOStream pcout(std::cout,
260 dealii::Utilities::MPI::this_mpi_process(
261 matrix_free.get_dof_handler().get_communicator()) == 0);
262 auto const map = (reader ? read_data_map : write_data_map);
263
264 auto names = map.begin();
265 std::string data_names = names->first;
266 ++names;
267 for(; names != map.end(); ++names)
268 data_names += std::string(", ") + names->first;
269
270 pcout << "-- Data " << (reader ? "reading" : "writing") << ":\n"
271 << "-- . data name(s): " << data_names << "\n"
272 << "-- . associated mesh: " << mesh_name << "\n"
273 << "-- . Number of coupling nodes: "
274 << dealii::Utilities::MPI::sum(local_size, matrix_free.get_dof_handler().get_communicator())
275 << "\n"
276 << "-- . Node location: " << get_surface_type() << "\n"
277 << std::endl;
278}
279
280} // namespace preCICE
281} // namespace ExaDG
282
283#endif
Definition coupling_base.h:66
void add_write_data(std::string const &write_data_name)
Queries data IDs from preCICE for the given write data name.
Definition coupling_base.h:214
std::string const mesh_name
public precice solverinterface
Definition coupling_base.h:152
virtual void process_coupling_mesh()
process_coupling_mesh (optional) Handle post-preCICE-initialization steps, e.g. do computations on re...
Definition coupling_base.h:239
FaceIntegrator< dim, data_dim, double, VectorizedArrayType > FEFaceIntegrator
Alias for the face integrator.
Definition coupling_base.h:78
virtual void write_data(dealii::LinearAlgebra::distributed::Vector< double > const &data_vector, std::string const &data_name)=0
write_data Write the data associated to the defined vertices to preCICE
dealii::MatrixFree< dim, double, VectorizedArrayType > const & matrix_free
The dealii::MatrixFree object (preCICE can only handle double precision)
Definition coupling_base.h:144
void set_write_data_type(WriteDataType write_data_specification)
Set the WriteDataType in this class which determines the location of the write data (e....
Definition coupling_base.h:229
virtual void define_coupling_mesh()=0
define_coupling_mesh Define the coupling mesh associated to the data points
void add_read_data(std::string const &read_data_name)
Queries data IDs from preCICE for the given read data name.
Definition coupling_base.h:199
void print_info(bool const reader, unsigned int const local_size) const
Print information of the current setup.
Definition coupling_base.h:256
Definition driver.cpp:33