libMesh
Public Member Functions | Protected Attributes | List of all members
libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction Class Reference

This object is passed to MeshTools::Modification::redistribute() to redistribute the points on a uniform grid into the Gauss-Lobatto points on the actual grid. More...

Inheritance diagram for libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction:
[legend]

Public Member Functions

 GaussLobattoRedistributionFunction (unsigned int nx, Real xmin, Real xmax, unsigned int ny=0, Real ymin=0, Real ymax=0, unsigned int nz=0, Real zmin=0, Real zmax=0)
 Constructor. More...
 
 GaussLobattoRedistributionFunction (GaussLobattoRedistributionFunction &&)=default
 The 5 special functions can be defaulted for this class. More...
 
 GaussLobattoRedistributionFunction (const GaussLobattoRedistributionFunction &)=default
 
GaussLobattoRedistributionFunctionoperator= (const GaussLobattoRedistributionFunction &)=default
 
GaussLobattoRedistributionFunctionoperator= (GaussLobattoRedistributionFunction &&)=default
 
virtual ~GaussLobattoRedistributionFunction ()=default
 
virtual std::unique_ptr< FunctionBase< Real > > clone () const override
 We must provide a way to clone ourselves to satisfy the pure virtual interface. More...
 
virtual void operator() (const Point &p, const Real, DenseVector< Real > &output) override
 This is the actual function that MeshTools::Modification::redistribute() calls. More...
 
virtual Real operator() (const Point &, const Real) override
 We must also override operator() which returns a Real, but this function should never be called, so it's left unimplemented. More...
 
virtual void init ()
 The actual initialization process. More...
 
virtual void clear ()
 Clears the function. More...
 
void operator() (const Point &p, DenseVector< Real > &output)
 Evaluation function for time-independent vector-valued functions. More...
 
virtual Real component (unsigned int i, const Point &p, Real time=0.)
 
bool initialized () const
 
void set_is_time_dependent (bool is_time_dependent)
 Function to set whether this is a time-dependent function or not. More...
 
bool is_time_dependent () const
 

Protected Attributes

std::vector< Real_mins
 
std::vector< unsigned int_nelem
 
std::vector< Real_widths
 
std::vector< std::vector< Real > > _cosines
 
const FunctionBase_master
 Const pointer to our master, initialized to nullptr. More...
 
bool _initialized
 When init() was called so that everything is ready for calls to operator() (...), then this bool is true. More...
 
bool _is_time_dependent
 Cache whether or not this function is actually time-dependent. More...
 

Detailed Description

This object is passed to MeshTools::Modification::redistribute() to redistribute the points on a uniform grid into the Gauss-Lobatto points on the actual grid.

Definition at line 146 of file mesh_generation.C.

Constructor & Destructor Documentation

◆ GaussLobattoRedistributionFunction() [1/3]

libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::GaussLobattoRedistributionFunction ( unsigned int  nx,
Real  xmin,
Real  xmax,
unsigned int  ny = 0,
Real  ymin = 0,
Real  ymax = 0,
unsigned int  nz = 0,
Real  zmin = 0,
Real  zmax = 0 
)
inline

Constructor.

Definition at line 152 of file mesh_generation.C.

160  :
161  FunctionBase<Real>(nullptr)
162  {
163  _nelem.resize(3);
164  _nelem[0] = nx;
165  _nelem[1] = ny;
166  _nelem[2] = nz;
167 
168  _mins.resize(3);
169  _mins[0] = xmin;
170  _mins[1] = ymin;
171  _mins[2] = zmin;
172 
173  _widths.resize(3);
174  _widths[0] = xmax - xmin;
175  _widths[1] = ymax - ymin;
176  _widths[2] = zmax - zmin;
177 
178  // Precompute the cosine values.
179  _cosines.resize(3);
180  for (unsigned dir=0; dir<3; ++dir)
181  if (_nelem[dir] != 0)
182  {
183  _cosines[dir].resize(_nelem[dir]+1);
184  for (auto i : index_range(_cosines[dir]))
185  _cosines[dir][i] = std::cos(libMesh::pi * Real(i) / _nelem[dir]);
186  }
187  }

References _cosines, _mins, _nelem, _widths, libMesh::index_range(), libMesh::pi, and libMesh::Real.

◆ GaussLobattoRedistributionFunction() [2/3]

libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::GaussLobattoRedistributionFunction ( GaussLobattoRedistributionFunction &&  )
default

The 5 special functions can be defaulted for this class.

◆ GaussLobattoRedistributionFunction() [3/3]

libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::GaussLobattoRedistributionFunction ( const GaussLobattoRedistributionFunction )
default

◆ ~GaussLobattoRedistributionFunction()

virtual libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::~GaussLobattoRedistributionFunction ( )
virtualdefault

Member Function Documentation

◆ clear()

virtual void libMesh::FunctionBase< Real >::clear ( )
inlinevirtualinherited

Clears the function.

Definition at line 91 of file function_base.h.

91 {}

◆ clone()

virtual std::unique_ptr<FunctionBase<Real> > libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::clone ( ) const
inlineoverridevirtual

We must provide a way to clone ourselves to satisfy the pure virtual interface.

We use the autogenerated copy constructor.

Implements libMesh::FunctionBase< Real >.

Definition at line 202 of file mesh_generation.C.

203  {
204  return libmesh_make_unique<GaussLobattoRedistributionFunction>(*this);
205  }

◆ component()

Real libMesh::FunctionBase< Real >::component ( unsigned int  i,
const Point p,
Real  time = 0. 
)
inlinevirtualinherited
Returns
The vector component i at coordinate p and time time.
Note
Subclasses aren't required to override this, since the default implementation is based on the full vector evaluation, which is often correct.
Subclasses are recommended to override this, since the default implementation is based on a vector evaluation, which is usually unnecessarily inefficient.

Definition at line 227 of file function_base.h.

230 {
231  DenseVector<Output> outvec(i+1);
232  (*this)(p, time, outvec);
233  return outvec(i);
234 }

◆ init()

virtual void libMesh::FunctionBase< Real >::init ( )
inlinevirtualinherited

The actual initialization process.

Definition at line 86 of file function_base.h.

86 {}

◆ initialized()

bool libMesh::FunctionBase< Real >::initialized ( ) const
inlineinherited
Returns
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 205 of file function_base.h.

206 {
207  return (this->_initialized);
208 }

◆ is_time_dependent()

bool libMesh::FunctionBase< Real >::is_time_dependent ( ) const
inlineinherited
Returns
true when the function this object represents is actually time-dependent, false otherwise.

Definition at line 219 of file function_base.h.

220 {
221  return (this->_is_time_dependent);
222 }

◆ operator()() [1/3]

virtual Real libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::operator() ( const Point ,
const  Real 
)
inlineoverridevirtual

We must also override operator() which returns a Real, but this function should never be called, so it's left unimplemented.

Implements libMesh::FunctionBase< Real >.

Definition at line 275 of file mesh_generation.C.

277  {
278  libmesh_not_implemented();
279  }

◆ operator()() [2/3]

virtual void libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::operator() ( const Point p,
const  Real,
DenseVector< Real > &  output 
)
inlineoverridevirtual

This is the actual function that MeshTools::Modification::redistribute() calls.

Moves the points of the grid to the Gauss-Lobatto points.

Implements libMesh::FunctionBase< Real >.

Definition at line 212 of file mesh_generation.C.

215  {
216  output.resize(3);
217 
218  for (unsigned dir=0; dir<3; ++dir)
219  if (_nelem[dir] != 0)
220  {
221  // Figure out the index of the current point.
222  Real float_index = (p(dir) - _mins[dir]) * _nelem[dir] / _widths[dir];
223 
224  // std::modf separates the fractional and integer parts of the index.
225  Real integer_part_f = 0;
226  const Real fractional_part = std::modf(float_index, &integer_part_f);
227 
228  const int integer_part = int(integer_part_f);
229 
230  // Vertex node?
231  if (std::abs(fractional_part) < TOLERANCE || std::abs(fractional_part - 1.0) < TOLERANCE)
232  {
233  int index = int(round(float_index));
234 
235  // Move node to the Gauss-Lobatto position.
236  output(dir) = _mins[dir] + _widths[dir] * 0.5 * (1.0 - _cosines[dir][index]);
237  }
238 
239  // Mid-edge (quadratic) node?
240  else if (std::abs(fractional_part - 0.5) < TOLERANCE)
241  {
242  // Move node to the Gauss-Lobatto position, which is the average of
243  // the node to the left and the node to the right.
244  output(dir) = _mins[dir] + _widths[dir] * 0.5 *
245  (1.0 - 0.5*(_cosines[dir][integer_part] + _cosines[dir][integer_part+1]));
246  }
247 
248  // 1D only: Left interior (cubic) node?
249  else if (std::abs(fractional_part - 1./3.) < TOLERANCE)
250  {
251  // Move node to the Gauss-Lobatto position, which is
252  // 2/3*left_vertex + 1/3*right_vertex.
253  output(dir) = _mins[dir] + _widths[dir] * 0.5 *
254  (1.0 - 2./3.*_cosines[dir][integer_part] - 1./3.*_cosines[dir][integer_part+1]);
255  }
256 
257  // 1D only: Right interior (cubic) node?
258  else if (std::abs(fractional_part - 2./3.) < TOLERANCE)
259  {
260  // Move node to the Gauss-Lobatto position, which is
261  // 1/3*left_vertex + 2/3*right_vertex.
262  output(dir) = _mins[dir] + _widths[dir] * 0.5 *
263  (1.0 - 1./3.*_cosines[dir][integer_part] - 2./3.*_cosines[dir][integer_part+1]);
264  }
265 
266  else
267  libmesh_error_msg("Cannot redistribute node: " << p);
268  }
269  }

References _cosines, _mins, _nelem, _widths, std::abs(), int, libMesh::Real, libMesh::DenseVector< T >::resize(), and libMesh::TOLERANCE.

◆ operator()() [3/3]

void libMesh::FunctionBase< Real >::operator() ( const Point p,
DenseVector< Real > &  output 
)
inlineinherited

Evaluation function for time-independent vector-valued functions.

Sets output values in the passed-in output DenseVector.

Definition at line 240 of file function_base.h.

242 {
243  // Call the time-dependent function with t=0.
244  this->operator()(p, 0., output);
245 }

◆ operator=() [1/2]

GaussLobattoRedistributionFunction& libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::operator= ( const GaussLobattoRedistributionFunction )
default

◆ operator=() [2/2]

GaussLobattoRedistributionFunction& libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::operator= ( GaussLobattoRedistributionFunction &&  )
default

◆ set_is_time_dependent()

void libMesh::FunctionBase< Real >::set_is_time_dependent ( bool  is_time_dependent)
inlineinherited

Function to set whether this is a time-dependent function or not.

This is intended to be only used by subclasses who cannot natively determine time-dependence. In such a case, this function should be used immediately following construction.

Definition at line 212 of file function_base.h.

213 {
215 }

Member Data Documentation

◆ _cosines

std::vector<std::vector<Real> > libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_cosines
protected

Definition at line 288 of file mesh_generation.C.

Referenced by GaussLobattoRedistributionFunction(), and operator()().

◆ _initialized

bool libMesh::FunctionBase< Real >::_initialized
protectedinherited

When init() was called so that everything is ready for calls to operator() (...), then this bool is true.

Definition at line 179 of file function_base.h.

◆ _is_time_dependent

bool libMesh::FunctionBase< Real >::_is_time_dependent
protectedinherited

Cache whether or not this function is actually time-dependent.

Definition at line 184 of file function_base.h.

◆ _master

const FunctionBase* libMesh::FunctionBase< Real >::_master
protectedinherited

Const pointer to our master, initialized to nullptr.

There may be cases where multiple functions are required, but to save memory, one master handles some centralized data.

Definition at line 173 of file function_base.h.

◆ _mins

std::vector<Real> libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_mins
protected

Definition at line 283 of file mesh_generation.C.

Referenced by GaussLobattoRedistributionFunction(), and operator()().

◆ _nelem

std::vector<unsigned int> libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_nelem
protected

Definition at line 284 of file mesh_generation.C.

Referenced by GaussLobattoRedistributionFunction(), and operator()().

◆ _widths

std::vector<Real> libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_widths
protected

Definition at line 285 of file mesh_generation.C.

Referenced by GaussLobattoRedistributionFunction(), and operator()().


The documentation for this class was generated from the following file:
libMesh::pi
const Real pi
.
Definition: libmesh.h:237
libMesh::FunctionBase< Real >::is_time_dependent
bool is_time_dependent() const
Definition: function_base.h:219
libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_mins
std::vector< Real > _mins
Definition: mesh_generation.C:283
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::FunctionBase< Real >::_is_time_dependent
bool _is_time_dependent
Cache whether or not this function is actually time-dependent.
Definition: function_base.h:184
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::FunctionBase< Real >::_initialized
bool _initialized
When init() was called so that everything is ready for calls to operator() (...), then this bool is t...
Definition: function_base.h:179
libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_widths
std::vector< Real > _widths
Definition: mesh_generation.C:285
libMesh::FunctionBase< Real >::operator()
virtual Real operator()(const Point &p, const Real time=0.)=0
libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_nelem
std::vector< unsigned int > _nelem
Definition: mesh_generation.C:284
libMesh::MeshTools::Generation::Private::GaussLobattoRedistributionFunction::_cosines
std::vector< std::vector< Real > > _cosines
Definition: mesh_generation.C:288
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360