Fluid structure interaction suite
dof_plotter.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
28 #include <deal.II/dofs/dof_tools.h>
29 
30 #include <deal.II/fe/mapping_fe.h>
31 
33 
40 #include <deal.II/lac/vector.h>
41 
43 
45 #include "parsed_tools/data_out.h"
48 #include "parsed_tools/grid_info.h"
49 
50 using namespace dealii;
51 
52 int
53 main(int argc, char **argv)
54 {
55  try
56  {
57  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
58  std::string par_name = "dof_plotter.prm";
59  if (argc > 1)
60  par_name = argv[1];
61 
62  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
64  else
66 
70  unsigned int n_basis_functions = 3;
71  unsigned int info_level = 0;
72  unsigned int mapping_degree = 1;
73 
74 
76  "Maximum number of basis functions to plot", n_basis_functions);
77  ParameterAcceptor::prm.add_parameter("Mapping degree", mapping_degree);
78  ParameterAcceptor::prm.add_parameter("Verbosity of grid info",
79  info_level);
80 
81  ParameterAcceptor::initialize(par_name, "used_" + par_name);
82 
83  Triangulation<2> tria;
84  pgg.generate(tria);
85  ParsedTools::GridInfo info(tria, info_level);
86  pgg.write(tria);
87  info.print_info(deallog);
88 
89  DoFHandler<2> dh(tria);
90  dh.distribute_dofs(pfe);
91  std::unique_ptr<Mapping<2>> mapping;
93  mapping = std::make_unique<MappingQ<2>>(mapping_degree);
94  else
95  {
96  mapping =
97  std::make_unique<MappingFE<2>>(FE_SimplexP<2>(mapping_degree));
98  // tria.set_all_manifold_ids(1);
99  }
100 
101  auto quad =
103  pfe().tensor_degree() + 1);
104 
105 
106  DynamicSparsityPattern dsp(dh.n_dofs(), dh.n_dofs());
108  dsp.compress();
109  SparsityPattern sparsity_pattern;
110  sparsity_pattern.copy_from(dsp);
111  sparsity_pattern.compress();
112  SparseMatrix<double> mass_matrix(sparsity_pattern);
113 
114  MatrixCreator::create_mass_matrix(*mapping, dh, quad, mass_matrix);
115 
116  SparseDirectUMFPACK mass_matrix_solver;
117  mass_matrix_solver.initialize(mass_matrix);
118 
119  std::vector<Vector<double>> basis_functions(n_basis_functions,
120  Vector<double>(dh.n_dofs()));
121  std::vector<Vector<double>> reciprocal_basis_functions(
122  n_basis_functions, Vector<double>(dh.n_dofs()));
123 
124  pdo.attach_dof_handler(dh);
125  n_basis_functions = std::min(n_basis_functions, dh.n_dofs());
126 
127  for (unsigned int i = 0; i < n_basis_functions; ++i)
128  {
129  basis_functions[i][i] = 1.0;
130  mass_matrix_solver.vmult(reciprocal_basis_functions[i],
131  basis_functions[i]);
132  pdo.add_data_vector(basis_functions[i],
133  "basis_function_" + std::to_string(i));
134  pdo.add_data_vector(reciprocal_basis_functions[i],
135  "reciprocal_basis_function_" + std::to_string(i));
136  }
137  pdo.write_data_and_clear(*mapping);
138  }
139  catch (std::exception &exc)
140  {
141  std::cerr << std::endl
142  << std::endl
143  << "----------------------------------------------------"
144  << std::endl;
145  std::cerr << "Exception on processing: " << std::endl
146  << exc.what() << std::endl
147  << "Aborting!" << std::endl
148  << "----------------------------------------------------"
149  << std::endl;
150 
151  return 1;
152  }
153  catch (...)
154  {
155  std::cerr << std::endl
156  << std::endl
157  << "----------------------------------------------------"
158  << std::endl;
159  std::cerr << "Unknown exception!" << std::endl
160  << "Aborting!" << std::endl
161  << "----------------------------------------------------"
162  << std::endl;
163  return 1;
164  }
165 
166  return 0;
167 }
void distribute_dofs(const FiniteElement< dim, spacedim > &fe)
types::global_dof_index n_dofs() const
unsigned int depth_console(const unsigned int n)
static void initialize(const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle)
static ParameterHandler prm
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation="", const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern(), const bool has_to_be_set=false)
void initialize(const SparsityPattern &sparsity_pattern)
void vmult(Vector< double > &dst, const Vector< double > &src) const
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
bool all_reference_cells_are_hyper_cube() const
void write_data_and_clear(const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim, spacedim >::mapping)
Actually write the file.
Definition: data_out.cc:194
void add_data_vector(const VECTOR &data_vector, const std::string &desc, const typename DataOut< dim, spacedim >::DataVectorType &type=DataOut< dim, spacedim >::type_automatic)
Add the given vector to the output file.
Definition: data_out.h:183
void attach_dof_handler(const DoFHandler< dim, spacedim > &dh, const std::string &suffix="")
Prepare to output data on the given file.
Definition: data_out.cc:119
Parsed FiniteElement.
GridGenerator class.
void generate(Triangulation< dim, spacedim > &tria) const
Fill a triangulation according to the parsed parameters.
void write(const Triangulation< dim, spacedim > &tria, const std::string &filename="") const
Write the given Triangulation to the output file specified in Output file name, or in the optional fi...
int main(int argc, char **argv)
Definition: dof_plotter.cc:53
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
LogStream deallog
void create_mass_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim > &q, MatrixType &matrix, const Function< spacedim, typename MatrixType::value_type > *const a=nullptr, const AffineConstraints< typename MatrixType::value_type > &constraints=AffineConstraints< typename MatrixType::value_type >())
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
Quadrature< dim > get_cell_quadrature(const Triangulation< dim, spacedim > &tria, const unsigned int degree)
Return a Quadrature object that can be used on the given Triangulation cells.
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
Gather information about a Triangulation.
Definition: grid_info.h:149
void print_info(StreamType &out)
Print all gathered information about the Triangulation.
Definition: grid_info.h:251