GEOSX
FieldSpecificationOps.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_MANAGERS_FIELDSPECIFICATION_FIELDSPECIFICATIONOPS_HPP
20 #define GEOSX_MANAGERS_FIELDSPECIFICATION_FIELDSPECIFICATIONOPS_HPP
21 
22 #include "common/DataTypes.hpp"
23 
24 namespace geosx
25 {
26 
30 struct OpEqual
31 {
39  template< typename T, typename U >
40  GEOSX_HOST_DEVICE static inline
41  void apply( T & lhs, U const & rhs )
42  {
43  lhs = static_cast< T >( rhs );
44  }
45 };
46 
50 struct OpAdd
51 {
59  template< typename T, typename U >
60  GEOSX_HOST_DEVICE static inline
61  void apply( T & lhs, U const & rhs )
62  {
63  lhs += static_cast< T >( rhs );
64  }
65 };
66 
70 template< typename OP >
72 {
74  using OpType = OP;
75 
87  template< typename T >
89  static inline typename std::enable_if< !traits::is_tensorT< T >, void >::type
91  localIndex const index,
92  integer const component,
93  real64 const value )
94  {
95  GEOSX_UNUSED_VAR( component );
96  OP::template apply( field( index ), value );
97  }
98 
111  template< typename T >
113  static inline typename std::enable_if< traits::is_tensorT< T >, void >::type
115  localIndex const index,
116  integer const component,
117  real64 const value )
118  {
119  OP::template apply( field( index )[component], value );
120  }
121 
133  template< typename T >
135  static inline typename std::enable_if< !traits::is_tensorT< T >, void >::type
137  localIndex const index,
138  integer const component,
139  real64 & value )
140  {
141  GEOSX_UNUSED_VAR( component );
142  OP::template apply( value, field( index ) );
143  }
144 
156  template< typename T >
158  static inline typename std::enable_if< traits::is_tensorT< T >, void >::type
160  localIndex const index,
161  integer const component,
162  real64 & value )
163  {
164  OP::template apply( value, field( index )[component] );
165  }
166 
179  template< typename T, int USD >
181  static inline typename std::enable_if< !traits::is_tensorT< T >, void >::type
183  localIndex const index,
184  integer const component,
185  real64 const value )
186  {
187  if( component >= 0 )
188  {
189  OP::template apply( field( index, component ), value );
190  }
191  else
192  {
193  for( localIndex a = 0; a < field.size( 1 ); ++a )
194  {
195  OP::template apply( field( index, a ), value );
196  }
197  }
198  }
199 
213  template< typename T, int USD >
215  static inline typename std::enable_if< traits::is_tensorT< T >, void >::type
217  localIndex const index,
218  integer const component,
219  real64 const value )
220  {
221  if( component >= 0 )
222  {
223  for( localIndex a = 0; a < field.size( 1 ); ++a )
224  {
225  OP::template apply( field( index, a )[component], value );
226  }
227  }
228  else
229  {
230  for( localIndex a = 0; a < field.size( 1 ); ++a )
231  {
232  for( localIndex c = 0; c < T::SIZE; ++c )
233  {
234  OP::template apply( field( index, a )[c], value );
235  }
236  }
237  }
238  }
239 
252  template< typename T, int USD >
254  static inline typename std::enable_if< !traits::is_tensorT< T >, void >::type
256  localIndex const index,
257  integer const component,
258  real64 & value )
259  {
260  GEOSX_ASSERT( component >= 0 );
261  OP::template apply( value, field( index, component ) );
262  }
263 
274  template< typename T, int USD >
276  static inline typename std::enable_if< traits::is_tensorT< T >, void >::type
278  localIndex const index,
279  integer const component,
280  real64 & value )
281  {
282  GEOSX_UNUSED_VAR( field );
283  GEOSX_UNUSED_VAR( index );
284  GEOSX_UNUSED_VAR( component );
285  GEOSX_UNUSED_VAR( value );
286  GEOSX_ERROR( "ReadFieldValue: unsupported operation" );
287  }
288 
301  template< typename T, int USD >
303  static inline typename std::enable_if< !traits::is_tensorT< T >, void >::type
305  localIndex const index,
306  integer const component,
307  real64 const value )
308  {
309  if( component >= 0 )
310  {
311  for( localIndex a = 0; a < field.size( 1 ); ++a )
312  {
313  OP::template apply( field( index, a, component ), value );
314  }
315  }
316  else
317  {
318  for( localIndex a = 0; a < field.size( 1 ); ++a )
319  {
320  for( localIndex b = 0; b < field.size( 2 ); ++b )
321  {
322  OP::template apply( field( index, a, b ), value );
323  }
324  }
325  }
326  }
327 
341  template< typename T, int USD >
343  static inline typename std::enable_if< traits::is_tensorT< T >, void >::type
345  localIndex const index,
346  integer const component,
347  real64 const value )
348  {
349  if( component >= 0 )
350  {
351  for( localIndex a = 0; a < field.size( 1 ); ++a )
352  {
353  for( localIndex b = 0; b < field.size( 2 ); ++b )
354  {
355  OP::template apply( field( index, a, b )[component], value );
356  }
357  }
358  }
359  else
360  {
361  for( localIndex a = 0; a < field.size( 1 ); ++a )
362  {
363  for( localIndex b = 0; b < field.size( 2 ); ++b )
364  {
365  for( localIndex c = 0; c < T::size(); ++c )
366  {
367  OP::template apply( field( index, a, b )[c], value );
368  }
369  }
370  }
371  }
372  }
373 
383  template< typename T, int USD >
385  static inline void
387  localIndex const index,
388  integer const component,
389  real64 & value )
390  {
391  GEOSX_UNUSED_VAR( field );
392  GEOSX_UNUSED_VAR( index );
393  GEOSX_UNUSED_VAR( component );
394  GEOSX_UNUSED_VAR( value );
395  GEOSX_ERROR( "ReadFieldValue: unsupported operation" );
396  }
397 
398 };
399 
406 {
409  using base_type::SpecifyFieldValue;
410 
428  template< typename LAI >
429  static inline void SpecifyFieldValue( globalIndex const dof,
430  typename LAI::ParallelMatrix & matrix,
431  real64 & rhs,
432  real64 const bcValue,
433  real64 const fieldValue )
434  {
435  if( matrix.getLocalRowID( dof ) >= 0 )
436  {
437  real64 const diag = matrix.clearRow( dof, true );
438  rhs = -diag * (bcValue - fieldValue);
439  }
440  else
441  {
442  rhs = 0.0;
443  }
444  }
445 
465  static inline void
467  globalIndex const dofRankOffset,
469  real64 & rhs,
470  real64 const bcValue,
471  real64 const fieldValue )
472  {
473  globalIndex const localRow = dof - dofRankOffset;
474  if( localRow >= 0 && localRow < matrix.numRows() )
475  {
476  arraySlice1d< globalIndex const > const columns = matrix.getColumns( localRow );
477  arraySlice1d< real64 > const entries = matrix.getEntries( localRow );
478  localIndex const numEntries = matrix.numNonZeros( localRow );
479 
480  real64 diagonal = 0;
481  for( localIndex j = 0; j < numEntries; ++j )
482  {
483  if( columns[ j ] == dof )
484  { diagonal = entries[ j ]; }
485  else
486  { entries[ j ] = 0; }
487  }
488 
489  rhs = -diagonal * (bcValue - fieldValue);
490  }
491  else
492  {
493  rhs = 0.0;
494  }
495  }
496 
504  template< typename LAI >
505  static inline void PrescribeRhsValues( typename LAI::ParallelVector & rhs,
506  localIndex const num,
507  globalIndex * const dof,
508  real64 * const values )
509  {
510  for( localIndex a = 0; a < num; ++a )
511  {
512  if( rhs.getLocalRowID( dof[a] ) >= 0 )
513  {
514  rhs.set( dof[a], values[a] );
515  }
516  }
517  }
518 
527  template< typename POLICY >
528  static inline void PrescribeRhsValues( arrayView1d< real64 > const & rhs,
530  globalIndex const dofRankOffset,
531  arrayView1d< real64 const > const & values )
532  {
533  GEOSX_ASSERT_EQ( dof.size(), values.size() );
534  forAll< POLICY >( dof.size(), [rhs, dof, dofRankOffset, values] GEOSX_HOST_DEVICE ( localIndex const a )
535  {
536  globalIndex const localRow = dof[ a ] - dofRankOffset;
537  if( localRow >= 0 && localRow < rhs.size() )
538  { rhs[ localRow ] = values[ a ]; }
539  } );
540  }
541 };
542 
549 {
552  using base_type::SpecifyFieldValue;
553 
565  static inline void
567  globalIndex const dofRankOffset,
569  real64 & rhs,
570  real64 const bcValue,
571  real64 const fieldValue )
572  {
573  GEOSX_UNUSED_VAR( dof );
574  GEOSX_UNUSED_VAR( dofRankOffset );
575  GEOSX_UNUSED_VAR( matrix );
576  GEOSX_UNUSED_VAR( fieldValue );
577  rhs += bcValue;
578  }
579 
587  template< typename LAI >
588  static inline void PrescribeRhsValues( typename LAI::ParallelVector & rhs,
589  localIndex const num,
590  globalIndex * const dof,
591  real64 * const values )
592  {
593  rhs.add( dof, values, num );
594  }
595 
604  template< typename POLICY >
605  static inline void PrescribeRhsValues( arrayView1d< real64 > const & rhs,
607  globalIndex const dofRankOffset,
608  arrayView1d< real64 const > const & values )
609  {
610  GEOSX_ASSERT_EQ( dof.size(), values.size() );
611  forAll< POLICY >( dof.size(), [rhs, dof, dofRankOffset, values] GEOSX_HOST_DEVICE ( localIndex const a )
612  {
613  globalIndex const localRow = dof[ a ] - dofRankOffset;
614  if( localRow >= 0 && localRow < rhs.size() )
615  { rhs[ localRow ] += values[ a ]; }
616  } );
617  }
618 
619 };
620 
621 } //namespace geosx
622 
623 #endif //GEOSX_MANAGERS_FIELDSPECIFICATION_FIELDSPECIFICATIONOPS_HPP
#define GEOSX_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:48
static GEOSX_HOST_DEVICE std::enable_if< !traits::is_tensorT< T >, void >::type SpecifyFieldValue(arrayView3d< T, USD > const &field, localIndex const index, integer const component, real64 const value)
Pointwise application of a value to a field variable.
static GEOSX_HOST_DEVICE void ReadFieldValue(arrayView3d< T const, USD > const &field, localIndex const index, integer const component, real64 &value)
This function is not meaningful. It exists for generic purposes, but will result in an error if calle...
static GEOSX_HOST_DEVICE void apply(T &lhs, U const &rhs)
Pointwise set of a value.
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
INDEX_TYPE size() const noexcept
Definition: ArrayView.hpp:361
LAInterface::ParallelVector ParallelVector
Alias for ParallelVector.
OpAdd Operator that adds a value.
static void PrescribeRhsValues(typename LAI::ParallelVector &rhs, localIndex const num, globalIndex *const dof, real64 *const values)
Function to add some values of a vector.
static GEOSX_HOST_DEVICE std::enable_if< !traits::is_tensorT< T >, void >::type ReadFieldValue(arrayView2d< T const, USD > const &field, localIndex const index, integer const component, real64 &value)
Read value from a 2d field.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
constexpr INDEX_TYPE_NC numRows() const
static GEOSX_HOST_DEVICE std::enable_if< traits::is_tensorT< T >, void >::type SpecifyFieldValue(arrayView3d< T, USD > const &field, localIndex const index, integer const component, real64 const value)
Pointwise application of a value to a field variable.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
#define GEOSX_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
Definition: Logger.hpp:254
static GEOSX_HOST_DEVICE std::enable_if< traits::is_tensorT< T >, void >::type ReadFieldValue(arrayView2d< T const, USD > const &field, localIndex const index, integer const component, real64 &value)
This function is not meaningful. It exists for generic purposes, but will result in an error if calle...
constexpr ArraySlice< COL_TYPE const, 1, 0, INDEX_TYPE_NC > getColumns(INDEX_TYPE const row) const
ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
OpEqual Operator that sets a value.
static void PrescribeRhsValues(typename LAI::ParallelVector &rhs, localIndex const num, globalIndex *const dof, real64 *const values)
Function to add some values of a vector.
static GEOSX_HOST_DEVICE void apply(T &lhs, U const &rhs)
Pointwise update of a value.
static GEOSX_HOST_DEVICE void SpecifyFieldValue(globalIndex const dof, globalIndex const dofRankOffset, CRSMatrixView< real64, globalIndex const > const &matrix, real64 &rhs, real64 const bcValue, real64 const fieldValue)
Function to apply a value to a vector field for a single dof.
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:110
static GEOSX_HOST_DEVICE std::enable_if< !traits::is_tensorT< T >, void >::type ReadFieldValue(arrayView1d< T const > const &field, localIndex const index, integer const component, real64 &value)
Read a field value.
static GEOSX_HOST_DEVICE std::enable_if< !traits::is_tensorT< T >, void >::type SpecifyFieldValue(arrayView2d< T, USD > const &field, localIndex const index, integer const component, real64 const value)
Pointwise application of a value to a field variable.
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
static GEOSX_HOST_DEVICE std::enable_if< !traits::is_tensorT< T >, void >::type SpecifyFieldValue(arrayView1d< T > const &field, localIndex const index, integer const component, real64 const value)
Pointwise application of a value to a field.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
#define GEOSX_ASSERT(EXP)
Assert a condition in debug builds.
Definition: Logger.hpp:123
static void SpecifyFieldValue(globalIndex const dof, typename LAI::ParallelMatrix &matrix, real64 &rhs, real64 const bcValue, real64 const fieldValue)
Function to apply a Dirichlet like boundary condition to a single dof in a system of equations...
LAInterface::ParallelMatrix ParallelMatrix
Alias for ParallelMatrix.
static GEOSX_HOST_DEVICE std::enable_if< traits::is_tensorT< T >, void >::type ReadFieldValue(arrayView1d< T const > const &field, localIndex const index, integer const component, real64 &value)
Read a field value.
static GEOSX_HOST_DEVICE std::enable_if< traits::is_tensorT< T >, void >::type SpecifyFieldValue(arrayView2d< T, USD > const &field, localIndex const index, integer const component, real64 const value)
Pointwise application of a value to a field variable.
static void PrescribeRhsValues(arrayView1d< real64 > const &rhs, arrayView1d< globalIndex const > const &dof, globalIndex const dofRankOffset, arrayView1d< real64 const > const &values)
Function to add some values of a vector.
static GEOSX_HOST_DEVICE void SpecifyFieldValue(globalIndex const dof, globalIndex const dofRankOffset, CRSMatrixView< real64, globalIndex const > const &matrix, real64 &rhs, real64 const bcValue, real64 const fieldValue)
Function to apply a Dirichlet like boundary condition to a single dof in a system of equations...
static GEOSX_HOST_DEVICE std::enable_if< traits::is_tensorT< T >, void >::type SpecifyFieldValue(arrayView1d< T > const &field, localIndex const index, integer const component, real64 const value)
Pointwise application of value to a field variable.
static void PrescribeRhsValues(arrayView1d< real64 > const &rhs, arrayView1d< globalIndex const > const &dof, globalIndex const dofRankOffset, arrayView1d< real64 const > const &values)
Function to add some values of a vector.