/usr/include/libmesh/dof_object.h is in libmesh-dev 0.7.1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | // $Id: dof_object.h 4356 2011-04-15 15:28:29Z jwpeterson $
// The libMesh Finite Element Library.
// Copyright (C) 2002-2008 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef __dof_object_h__
#define __dof_object_h__
// C++ includes
// Local includes
#include "libmesh_config.h"
#include "libmesh_common.h"
#include "libmesh.h" // libMesh::invalid_uint
#include "reference_counted_object.h"
namespace libMesh
{
// Forward declarations
class DofObject;
/**
* The \p DofObject defines an abstract base class for objects that
* have degrees of freedom associated with them. Examples of such
* objects are the \p Node and \p Elem classes. This class can
* not be instantiated, only derived from.
*
* This class is intended to be extremely lightweight. To help acheive
* this goal no \p std::vector<> or anything else that might be heavy
* is used to store the degree of freedom indices.
*
* \author Benjamin S. Kirk
* \date 2003
* \version $Revision: 4356 $
*/
class DofObject : public ReferenceCountedObject<DofObject>
{
protected:
/**
* Constructor. Protected so that you can't instantiate one of these.
*/
DofObject ();
public:
/**
* Copy-constructor.
*/
DofObject (const DofObject&);
/**
* Destructor.
*/
virtual ~DofObject ();
/**
* Deep-copying assignment operator
*/
DofObject& operator= (const DofObject& dof_obj);
#ifdef LIBMESH_ENABLE_AMR
/**
* This object on the last mesh. Useful for projecting
* solutions from one mesh to another.
*/
DofObject* old_dof_object;
/**
* Sets the \p old_dof_object to NULL
*/
void clear_old_dof_object ();
/**
* Sets the \p old_dof_object to a copy of \p this
*/
void set_old_dof_object ();
#endif
/**
* Clear the \p DofMap data structures and return to
* a pristine state.
*/
void clear_dofs ();
/**
* Sets all degree of freedom numbers to \p invalid_id
*/
void invalidate_dofs (const unsigned int sys_num = libMesh::invalid_uint);
/**
* Sets the id to \p invalid_id
*/
void invalidate_id ();
/**
* Sets the processor id to \p invalid_processor_id
*/
void invalidate_processor_id ();
/**
* Invalidates all the indices for this \p DofObject
*/
void invalidate ();
/**
* @returns the number of degrees of freedom associated with
* system \p s for this object. Optionally only counts degrees
* of freedom for variable number \p var
*/
unsigned int n_dofs (const unsigned int s,
const unsigned int var =
libMesh::invalid_uint) const;
/**
* \returns the \p id for this \p DofObject
*/
unsigned int id () const;
/**
* \returns the \p id for this \p DofObject as a writeable reference.
*/
unsigned int & set_id ();
/**
* Sets the \p id for this \p DofObject
*/
void set_id (const unsigned int id)
{ this->set_id() = id; }
/**
* @returns \p true if this \p DofObject has a valid \p id set,
* \p false otherwise.
*/
bool valid_id () const;
/**
* @returns the processor that this element belongs to.
* To conserve space this is stored as a short integer.
*/
unsigned short int processor_id () const;
/**
* @returns the processor that this element belongs to as a
* writeable reference.
*/
unsigned short int & processor_id ();
/**
* Sets the \p processor_id for this \p DofObject.
*/
void processor_id (const unsigned int id);
/**
* @returns \p true if this \p DofObject has a valid \p id set,
* \p false otherwise.
*/
bool valid_processor_id () const;
/**
* @returns the number of systems associated with this
* \p DofObject
*/
unsigned int n_systems() const;
/**
* Sets the number of systems for this \p DofObject
*/
void set_n_systems (const unsigned int s);
/**
* Adds an additional system to the \p DofObject
*/
void add_system ();
/**
* @returns the number of variables associated with system \p s
* for this \p DofObject
*/
unsigned int n_vars(const unsigned int s) const;
/**
* Sets number of variables associated with system \p s for this
* \p DofObject
*/
void set_n_vars(const unsigned int s,
const unsigned int nvars);
/**
* @returns the number of components for variable \p var
* of system \p s associated with this \p DofObject.
* For example, the \p HIERARCHIC shape functions may
* have @e multiple dof's associated with @e one node. Another
* example is the \p MONOMIALs, where only the elements
* hold the dof's, but for the different spatial directions,
* and orders, see \p FE.
*/
unsigned int n_comp(const unsigned int s,
const unsigned int var) const;
/**
* Sets the number of components for variable \p var
* of system \p s associated with this \p DofObject
*/
void set_n_comp(const unsigned int s,
const unsigned int var,
const unsigned int ncomp);
/**
* @returns the global degree of freedom number variable \p var,
* component \p comp for system \p s associated with this \p DofObject
*/
unsigned int dof_number(const unsigned int s,
const unsigned int var,
const unsigned int comp) const;
/**
* Sets the global degree of freedom number variable \p var,
* component \p comp for system \p s associated with this \p DofObject
*/
void set_dof_number(const unsigned int s,
const unsigned int var,
const unsigned int comp,
const unsigned int dn);
/**
* @returns true if any system has variables which have been assigned,
* false otherwise
*/
bool has_dofs(const unsigned int s=libMesh::invalid_uint) const;
/**
* Implemented in Elem and Node.
*/
// virtual bool operator==(const DofObject& ) const
// { libmesh_error(); return false; }
/**
* An invaild \p id to distinguish an uninitialized \p DofObject
*/
static const unsigned int invalid_id = libMesh::invalid_uint;
/**
* An invalid \p processor_id to distinguish DOFs that have
* not been assigned to a processor.
*/
static const unsigned short int invalid_processor_id = static_cast<unsigned short int>(-1);
private:
/**
* The \p id of the \p DofObject
*/
unsigned int _id;
/**
* The \p processor_id of the \p DofObject.
* Degrees of freedom are wholly owned by processors,
* however they may be duplicated on other processors.
*
* This is stored as an unsigned short int since we cannot
* expect to be solving on 65000+ processors any time soon,
* can we??
*/
unsigned short int _processor_id;
/**
* The number of systems.
*/
unsigned char _n_systems;
/**
* The number of variables and components for each variable of each system
* associated with this \p DofObject. This is stored as an
* unsigned char for storage efficiency.
*
* _n_v_comp[s][0] = # of variables in system s
* _n_v_comp[s][v+1] = # of components for variable v in system s.
*/
unsigned char **_n_v_comp;
/**
* The first global degree of freedom number
* for each variable of each system.
*/
unsigned int **_dof_ids;
};
//------------------------------------------------------
// Inline functions
inline
DofObject::DofObject () :
#ifdef LIBMESH_ENABLE_AMR
old_dof_object(NULL),
#endif
_id (invalid_id),
_processor_id (invalid_processor_id),
_n_systems (0),
_n_v_comp (NULL),
_dof_ids (NULL)
{
this->invalidate();
}
inline
DofObject::~DofObject ()
{
// Free all memory.
#ifdef LIBMESH_ENABLE_AMR
this->clear_old_dof_object ();
#endif
this->clear_dofs ();
}
inline
void DofObject::invalidate_dofs (const unsigned int sys_num)
{
// If the user does not specify the system number...
if (sys_num >= this->n_systems())
{
for (unsigned int s=0; s<this->n_systems(); s++)
for (unsigned int v=0; v<this->n_vars(s); v++)
if (this->n_comp(s,v))
this->set_dof_number(s,v,0,invalid_id);
}
// ...otherwise invalidate the dofs for all systems
else
for (unsigned int v=0; v<n_vars(sys_num); v++)
if (this->n_comp(sys_num,v))
this->set_dof_number(sys_num,v,0,invalid_id);
}
inline
void DofObject::invalidate_id ()
{
this->set_id (invalid_id);
}
inline
void DofObject::invalidate_processor_id ()
{
this->processor_id (invalid_processor_id);
}
inline
void DofObject::invalidate ()
{
this->invalidate_dofs ();
this->invalidate_id ();
this->invalidate_processor_id ();
}
inline
void DofObject::clear_dofs ()
{
// Only clear if there is data
if (this->n_systems() != 0)
{
libmesh_assert (_n_v_comp != NULL);
libmesh_assert (_dof_ids != NULL);
for (unsigned int s=0; s<this->n_systems(); s++)
{
if (_dof_ids[s] != NULL) // This has only been allocated if
{ // variables were declared
delete [] _dof_ids[s]; _dof_ids[s] = NULL;
}
if (_n_v_comp[s] != NULL) // it is possible the number of variables is 0,
{ // but this was allocated (_n_v_comp[s][0] == 0)
delete [] _n_v_comp[s]; _n_v_comp[s] = NULL;
}
}
delete [] _n_v_comp; _n_v_comp = NULL;
delete [] _dof_ids; _dof_ids = NULL;
}
// Make sure we cleaned up
// (or there was nothing there)
libmesh_assert (_n_v_comp == NULL);
libmesh_assert (_dof_ids == NULL);
// No systems now.
_n_systems = 0;
}
inline
unsigned int DofObject::n_dofs (const unsigned int s,
const unsigned int var) const
{
libmesh_assert (s < this->n_systems());
unsigned int num = 0;
// Count all variables
if (var == libMesh::invalid_uint)
for (unsigned int v=0; v<this->n_vars(s); v++)
num += this->n_comp(s,v);
// Only count specified variable
else
{
num = this->n_comp(s,var);
}
return num;
}
inline
unsigned int DofObject::id () const
{
libmesh_assert (this->valid_id());
return _id;
}
inline
unsigned int & DofObject::set_id ()
{
return _id;
}
inline
bool DofObject::valid_id () const
{
return (DofObject::invalid_id != _id);
}
inline
unsigned short int DofObject::processor_id () const
{
return _processor_id;
}
inline
unsigned short int & DofObject::processor_id ()
{
return _processor_id;
}
inline
void DofObject::processor_id (const unsigned int id)
{
#ifdef DEBUG
if (id != static_cast<unsigned int>(static_cast<unsigned short int>(id)))
{
libMesh::err << "ERROR: id too large for unsigned short int!" << std::endl
<< "Recompile with DofObject::_processor_id larger!" << std::endl;
libmesh_error();
}
#endif
this->processor_id() = id;
}
inline
bool DofObject::valid_processor_id () const
{
return (DofObject::invalid_processor_id != _processor_id);
}
inline
unsigned int DofObject::n_systems () const
{
return static_cast<unsigned int>(_n_systems);
}
inline
unsigned int DofObject::n_vars(const unsigned int s) const
{
libmesh_assert (s < this->n_systems());
libmesh_assert (_n_v_comp != NULL);
if (_n_v_comp[s] == NULL)
return 0;
return static_cast<unsigned int>(_n_v_comp[s][0]);
}
inline
unsigned int DofObject::n_comp(const unsigned int s,
const unsigned int var) const
{
libmesh_assert (s < this->n_systems());
libmesh_assert (_dof_ids != NULL);
libmesh_assert (_dof_ids[s] != NULL);
libmesh_assert (_n_v_comp != NULL);
libmesh_assert (_n_v_comp[s] != NULL);
# ifdef DEBUG
// Does this ever happen? I doubt it... 3/7/2003 (BSK)
if (var >= this->n_vars(s))
{
libMesh::err << "s=" << s << ", var=" << var << std::endl
<< "this->n_vars(s)=" << this->n_vars(s) << std::endl
<< "this->n_systems()=" << this->n_systems() << std::endl;
libmesh_error();
}
# endif
return static_cast<unsigned int>(_n_v_comp[s][var+1]);
}
inline
unsigned int DofObject::dof_number(const unsigned int s,
const unsigned int var,
const unsigned int comp) const
{
libmesh_assert (s < this->n_systems());
libmesh_assert (var < this->n_vars(s));
libmesh_assert (_dof_ids != NULL);
libmesh_assert (_dof_ids[s] != NULL);
libmesh_assert (comp < this->n_comp(s,var));
if (_dof_ids[s][var] == invalid_id)
return invalid_id;
else
return (_dof_ids[s][var] + comp);
}
inline
bool DofObject::has_dofs (const unsigned int sys) const
{
if (sys == libMesh::invalid_uint)
{
for (unsigned int s=0; s<this->n_systems(); s++)
if (this->n_vars(s))
return true;
}
else
{
libmesh_assert (sys < this->n_systems());
if (this->n_vars(sys))
return true;
}
return false;
}
} // namespace libMesh
#endif // #ifndef __dof_object_h__
|