Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82312847
compute_combine.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Sep 10, 17:20
Size
4 KB
Mime Type
text/x-c++
Expires
Thu, Sep 12, 17:20 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20679359
Attached To
rLIBMULTISCALE LibMultiScale
compute_combine.cc
View Options
/**
* @file compute_combine.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Oct 28 19:23:14 2013
*
* @brief This is a compute made from other computes and a provided operator
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale 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.
*
* LibMultiScale 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 LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "lm_common.hh"
#include "lib_md.hh"
#include "lib_dd.hh"
#include "lib_continuum.hh"
#include "compute_combine.hh"
#include "factory_multiscale.hh"
#include "math_tools.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont>
void ComputeCombine<Cont>::build(Cont & cont){
const UInt Dim = cont.getDim();
this->empty();
this->name_computed.clear();
for (UInt i = 0; i < list_columns.size(); ++i) {
if (list_columns[i] >= Dim) {
DUMP("wrong column number " << list_columns[i]
<< " columns can range from 0 to " << Dim
<< " and are ",DBG_MESSAGE);
for (UInt k = 0; k < Dim; ++k)
DUMP("col(" << k << ") => " << cont.name_computed[k] << " ",DBG_MESSAGE);
LM_FATAL("exit");
}
}
switch (op){
case OP_MAX :
this->makeName<OP_MAX>(cont);
this->combine<MathTools::MaxOperator<Real> >(cont);break;
case OP_MIN :
this->makeName<OP_MIN>(cont);
this->combine<MathTools::MinOperator<Real> >(cont);break;
case OP_SUM :
this->makeName<OP_SUM>(cont);
this->combine<MathTools::SumOperator<Real> >(cont);break;
case OP_AVERAGE :
this->makeName<OP_AVERAGE>(cont);
this->combine<MathTools::AverageOperator<Real> >(cont);break;
default: LM_FATAL("Operator " << op << " not handled");
}
this->setDim(this->name_computed.size());
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
template <typename Op>
void ComputeCombine<Cont>::combine(Cont & cont){
const UInt Dim = cont.getDim();
UInt nb_lines = cont.nbElem()/Dim;
UInt n_col = list_columns.size();
UInt * cols = &list_columns[0];
for (UInt i = 0; i < nb_lines; ++i) {
Op op;
op.init();
for (UInt j = 0; j < n_col; ++j) {
UInt col = cols[j];
op.account(cont[i*Dim+col]);
}
this->add(op.result());
}
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
template <Operator op>
void ComputeCombine<Cont>::makeName(Cont & cont){
if (this->name_col != ""){
this->name_computed.push_back(name_col);
return;
}
UInt n_col = list_columns.size();
UInt * cols = &list_columns[0];
std::stringstream sstr_name_col;
sstr_name_col << op << "(";
for (UInt i = 0; i < n_col; ++i) {
sstr_name_col << cont.name_computed[cols[i]];
if (i < n_col -1) sstr_name_col << ",";
}
sstr_name_col << ")";
this->name_computed.push_back(sstr_name_col.str());
}
/* -------------------------------------------------------------------------- */
/* LMDESC COMBINE
This computes makes a compute providing a single column
as the result of an operator applied to a sequence of columns
from the input.
*/
/* LMEXAMPLE COMPUTE combine COMBINE INPUT ekin OPERATOR SUM COL 1 COL 2 */
template <typename _Input>
inline void ComputeCombine<_Input>::declareParams(){
/* LMKEYWORD OPERATOR
Provides an operator to be used when combining the columns
*/
this->parseKeyword("OPERATOR",op);
/* LMKEYWORD COL
provides the columns that are to be combined by the operator
*/
this->parseKeyword("COL",list_columns);
/* LMKEYWORD NAME
provides the columns name that is going to be computed
The default is a constructed information of the compute
*/
this->parseKeyword("NAME",name_col,"");
};
/* -------------------------------------------------------------------------- */
DECLARE_COMPUTE_REAL(ComputeCombine);
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment