Fluid structure interaction suite
finite_element.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 
16 
17 
19 
20 #include <deal.II/base/patterns.h>
21 
24 #include <deal.II/fe/fe_tools.templates.h>
25 
26 #include <algorithm> // std::find
27 
28 using namespace dealii;
29 
30 namespace ParsedTools
31 {
32  template <int dim, int spacedim>
34  const std::string &section_name,
35  const std::string &_component_names,
36  const std::string &fe_name)
37  : ParameterAcceptor(section_name)
38  , joint_component_names(_component_names)
39  , component_names(Utilities::split_string_list(_component_names))
40  , fe_name(fe_name)
41  {
42  component_blocks.resize(component_names.size());
43  block_names.resize(component_names.size());
44  unsigned int j = 0;
45  for (unsigned int i = 0; i < component_names.size(); ++i)
46  {
47  if ((i > 0) && (component_names[i - 1] != component_names[i]))
48  j++;
49  component_blocks[i] = j;
51  }
52  block_names.resize(j + 1);
53 
54  add_parameter("Finite element space (" + joint_component_names + ")",
55  this->fe_name);
56  enter_my_subsection(this->prm);
57  this->prm.add_action(
58  "Finite element space (" + joint_component_names + ")",
59  [&](const std::string &value) {
60  fe = FETools::get_fe_by_name<dim, spacedim>(value);
61  // Check that the number of components is correct
62  Assert(fe->n_components() == component_names.size(),
63  ExcMessage("The number of components in the finite element "
64  "space does not match the number of components "
65  "for the FiniteElement."));
66  });
67  leave_my_subsection(this->prm);
68 
69  // // Add some of the deal.II new FE classes.
70  // static bool fe_simplex_p_added = false;
71  // if (dim > 1 && fe_simplex_p_added == false)
72  // {
73  // FETools::add_fe_name<dim, spacedim>(
74  // "FE_SimplexP", new FETools::FEFactory<FE_SimplexP<dim,
75  // spacedim>>());
76  // FETools::add_fe_name<dim, spacedim>(
77  // "FE_SimplexDGP",
78  // new FETools::FEFactory<FE_SimplexDGP<dim, spacedim>>());
79  // FETools::add_fe_name<dim, spacedim>(
80  // "FE_SimplexP_Bubbles",
81  // new FETools::FEFactory<FE_SimplexP_Bubbles<dim, spacedim>>());
82  // fe_simplex_p_added = true;
83  // }
84  }
85 
86 
87 
88  template <int dim, int spacedim>
89  FiniteElement<dim, spacedim>::operator dealii::FiniteElement<dim,
90  spacedim> &()
91  {
93  return *fe;
94  }
95 
96 
97 
98  template <int dim, int spacedim>
100  FiniteElement<dim, spacedim> &() const
101  {
103  return *fe;
104  }
105 
106 
107 
108  template <int dim, int spacedim>
109  dealii::FiniteElement<dim, spacedim> &
111  {
113  return *fe;
114  }
115 
116 
117 
118  template <int dim, int spacedim>
119  const dealii::FiniteElement<dim, spacedim> &
121  {
123  return *fe;
124  }
125 
126 
127 
128  template <int dim, int spacedim>
129  unsigned int
131  {
132  return component_names.size();
133  }
134 
135 
136  template <int dim, int spacedim>
137  unsigned int
139  {
140  return block_names.size();
141  }
142 
143 
144  template <int dim, int spacedim>
145  const std::string &
147  {
148  return joint_component_names;
149  }
150 
151 
152  template <int dim, int spacedim>
153  const std::vector<std::string> &
155  {
156  return component_names;
157  }
158 
159 
160  template <int dim, int spacedim>
161  std::string
163  {
164  return Patterns::Tools::to_string(block_names);
165  }
166 
167 
168  template <int dim, int spacedim>
169  std::vector<unsigned int>
171  {
172  return component_blocks;
173  }
174 
175  template <int dim, int spacedim>
176  unsigned int
178  const std::string &var) const
179  {
180  auto pos_it =
181  std::find(component_names.begin(), component_names.end(), var);
182  Assert(pos_it != component_names.end(),
183  ExcInternalError("Component not found!"));
184  return pos_it - component_names.begin();
185  }
186 
187  template <int dim, int spacedim>
188  bool
189  FiniteElement<dim, spacedim>::is_vector(const std::string &var) const
190  {
191  auto pos_it =
192  std::find(component_names.begin(), component_names.end(), var);
193  Assert(pos_it != component_names.end(),
194  ExcInternalError("Component not found!"));
195  pos_it++;
196  if (pos_it == component_names.end())
197  return false;
198  return (*pos_it == var);
199  }
200 
201 
202  template class FiniteElement<1, 1>;
203  template class FiniteElement<1, 2>;
204  template class FiniteElement<1, 3>;
205  template class FiniteElement<2, 2>;
206  template class FiniteElement<2, 3>;
207  template class FiniteElement<3, 3>;
208 
209 } // namespace ParsedTools
FiniteElement(const FiniteElementData< dim > &fe_data, const std::vector< bool > &restriction_is_additive_flags, const std::vector< ComponentMask > &nonzero_components)
static ParameterHandler prm
void leave_my_subsection(ParameterHandler &prm)
void enter_my_subsection(ParameterHandler &prm)
void add_parameter(const std::string &entry, ParameterType &parameter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action, const bool execute_action=true)
Parsed FiniteElement.
const std::vector< std::string > & get_component_names() const
Return the component names for this Finite Element.
const std::string joint_component_names
Component names as a single comma separated string.
unsigned int n_blocks() const
Return the number of blocks of the Finite Element, i.e., the number of variables.
std::vector< unsigned int > component_blocks
The subdivision, in terms of component indices.
std::unique_ptr< FiniteElement< dim, spacedim > > fe
The actual FiniteElement object.
std::vector< std::string > block_names
The subdivision, in terms of block names.
std::string get_block_names() const
Return the block names for this Finite Element.
std::vector< unsigned int > get_component_blocks() const
Return the blocking of the components for this finite element.
unsigned int n_components() const
Return the number of components of the Finite Element.
FiniteElement< dim, spacedim > & operator()()
Return a reference to the Finite Element.
unsigned int get_first_occurence(const std::string &var) const
Return the first occurence of var in default_component_names.
const std::vector< std::string > component_names
Component names.
const std::string & get_joint_component_names() const
Return the component names for this Finite Element.
bool is_vector(const std::string &var) const
Return true if var is vector, false otherwise.
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::string to_string(const T &t)
We collect in this namespace some wrappers around commonly used deal.II classes, derived from the Par...