22#ifndef INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_PRECICE_COUPLING_BASE_H_
23#define INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_PRECICE_COUPLING_BASE_H_
26#include <deal.II/base/conditional_ostream.h>
27#include <deal.II/base/vectorization.h>
29#include <deal.II/matrix_free/matrix_free.h>
32#include <exadg/matrix_free/integrators.h>
35#ifdef EXADG_WITH_PRECICE
36# include <precice/SolverInterface.hpp>
46enum class WriteDataType
51 gradients_on_other_mesh,
53 normal_gradients_on_q_points
64template<
int dim,
int data_dim,
typename VectorizedArrayType>
68 CouplingBase(dealii::MatrixFree<dim, double, VectorizedArrayType>
const & data,
69#ifdef EXADG_WITH_PRECICE
70 std::shared_ptr<precice::SolverInterface> precice,
73 dealii::types::boundary_id
const surface_id);
75 virtual ~CouplingBase() =
default;
79 using value_type =
typename FEFaceIntegrator::value_type;
104 write_data(dealii::LinearAlgebra::distributed::Vector<double>
const & data_vector,
105 std::string
const & data_name) = 0;
109 read_block_data(std::string
const & data_name)
const;
141 print_info(
bool const reader,
unsigned int const local_size)
const;
144 dealii::MatrixFree<dim, double, VectorizedArrayType>
const &
matrix_free;
147#ifdef EXADG_WITH_PRECICE
148 std::shared_ptr<precice::SolverInterface> precice;
155 std::map<std::string, int> read_data_map;
156 std::map<std::string, int> write_data_map;
158 dealii::types::boundary_id
const dealii_boundary_surface_id;
160 WriteDataType write_data_type;
163 get_surface_type()
const = 0;
168template<
int dim,
int data_dim,
typename VectorizedArrayType>
169CouplingBase<dim, data_dim, VectorizedArrayType>::CouplingBase(
170 dealii::MatrixFree<dim, double, VectorizedArrayType>
const & matrix_free_,
171#ifdef EXADG_WITH_PRECICE
172 std::shared_ptr<precice::SolverInterface> precice,
174 std::string
const mesh_name,
175 dealii::types::boundary_id
const surface_id)
176 : matrix_free(matrix_free_),
177#ifdef EXADG_WITH_PRECICE
180 mesh_name(mesh_name),
181 dealii_boundary_surface_id(surface_id),
182 write_data_type(WriteDataType::undefined)
184#ifdef EXADG_WITH_PRECICE
185 Assert(precice.get() !=
nullptr, dealii::ExcNotInitialized());
191 dealii::ExcMessage(
"EXADG_WITH_PRECICE has to be activated to use this code."));
197template<
int dim,
int data_dim,
typename VectorizedArrayType>
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);
205 int const read_data_id = 0;
207 read_data_map.insert({read_data_name, read_data_id});
212template<
int dim,
int data_dim,
typename VectorizedArrayType>
215 std::string
const & write_data_name)
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);
221 int const write_data_id = 0;
223 write_data_map.insert({write_data_name, write_data_id});
227template<
int dim,
int data_dim,
typename VectorizedArrayType>
230 WriteDataType write_data_specification)
232 write_data_type = write_data_specification;
237template<
int dim,
int data_dim,
typename VectorizedArrayType>
246template<
int dim,
int data_dim,
typename VectorizedArrayType>
248CouplingBase<dim, data_dim, VectorizedArrayType>::read_block_data(std::string
const &)
const
250 AssertThrow(
false, dealii::ExcNotImplemented());
254template<
int dim,
int data_dim,
typename VectorizedArrayType>
257 unsigned int const local_size)
const
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);
264 auto names = map.begin();
265 std::string data_names = names->first;
267 for(; names != map.end(); ++names)
268 data_names += std::string(
", ") + names->first;
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())
276 <<
"-- . Node location: " << get_surface_type() <<
"\n"
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