Page MenuHomec4science

elastic_functional.cpp
No OneTemporary

File Metadata

Created
Sat, Jun 1, 10:07

elastic_functional.cpp

/**
* @file
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas 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 3 of the License, or (at your option) any
* later version.
*
* Tamaas 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 Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "elastic_functional.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
namespace functional {
Real ElasticFunctionalPressure::computeF(GridBase<Real>& pressure,
GridBase<Real>& dual) const {
// This doesn't work if dual is multi-component
*buffer = dual;
// this can get large
unsigned long long n = dual.getNbPoints();
n *= n;
return (0.5 * pressure.dot(*buffer) - pressure.dot(surface)) / n;
}
/* -------------------------------------------------------------------------- */
void ElasticFunctionalPressure::computeGradF(GridBase<Real>& pressure,
GridBase<Real>& gradient) const {
this->op.apply(pressure, *buffer);
// This doesn't work if dual is multi-component
*buffer -= surface;
gradient += *buffer;
}
/* -------------------------------------------------------------------------- */
Real ElasticFunctionalGap::computeF(GridBase<Real>& gap,
GridBase<Real>& dual) const {
// This doesn't work if dual is multi-component
*buffer = gap;
*buffer += surface;
UInt n = dual.getNbPoints();
Real F = 0.5 * buffer->dot(dual);
return F / n / n; // avoid integer overflow
}
/* -------------------------------------------------------------------------- */
void ElasticFunctionalGap::computeGradF(GridBase<Real>& gap,
GridBase<Real>& gradient) const {
*buffer = gap;
*buffer += surface; // Now we have displacements
this->op.apply(*buffer, *buffer);
gradient += *buffer;
}
} // namespace functional
__END_TAMAAS__

Event Timeline