Page MenuHomec4science

dumper_1d.cc
No OneTemporary

File Metadata

Created
Tue, Oct 15, 05:43

dumper_1d.cc

/**
* @file dumper_1d.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
* @author Srinivasa Babu Ramisetti <srinivasa.ramisetti@epfl.ch>
*
* @date Wed Jul 09 21:59:47 2014
*
* @brief Dumps the per point information for 1D domains
*
* @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 "dumper_1d.hh"
#include "lib_md.hh"
#include "lib_dd.hh"
#include "lib_continuum.hh"
#include "filter.hh"
#include "compute.hh"
#include "filter_manager.hh"
#include <iomanip>
#include "ref_point_data.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont>
void Dumper1D<Cont>::dump(Cont & cont){
static const UInt Dim = Cont::Dim;
if (Dim != 1)
LM_FATAL("cannot apply this dumper to model of dimension greater than 1 " << Dim);
if (!file.is_open()){
std::stringstream str;
str << this->getBaseName() << "-" << lm_my_proc_id << ".plot";
file.open(str.str().c_str());
}
ComputeInterface * ptr = NULL;
if (filter != invalidFilter){
ptr =
dynamic_cast<ComputeInterface *>(FilterManager::getManager().getObject(filter));
if (!ptr) LM_FATAL("filter provided is invalid");
if (!do_not_rebuild_flag)
ptr->build();
if (ptr->nbElem()/ptr->getDim() != cont.nbElem())
LM_FATAL("compute and container mismatch of number of components "
<< ptr->nbElem()/ptr->getDim() << " " << cont.nbElem());
dumpCompute<Dim>(*ptr,cont);
}
else
switch (field_type){
case _displacement: dumpField<_displacement,Dim>(cont);break;
case _position: dumpField<_position,Dim>(cont);break;
case _velocity: dumpField<_velocity,Dim>(cont);break;
case _force: dumpField<_force,Dim>(cont);break;
default: LM_FATAL("field not eligible " << field_type);
}
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
template <UInt Dim, typename ContCompute>
void Dumper1D<Cont>::dumpCompute(ContCompute & contCompute, Cont & cont){
if (contCompute.getDim() > 2)
LM_FATAL("result of compute must have < 3 columns " << contCompute.getDim());
if (contCompute.getDim() == 1){
for (UInt i = 0; i < contCompute.nbElem(); ++i) {
file << std::scientific << std::setprecision(precision)
<< contCompute.get(i) << "\t" << cont.get(i).position0(0) << "\t";
}
}
else if (contCompute.getDim() == 2){
for (UInt i = 0; i < contCompute.nbElem()/2; ++i) {
file << std::scientific << std::setprecision(precision)
<< contCompute.get(2*i) << "\t" << contCompute.get(2*i+1) << "\t";
}
}
file << std::endl;
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
template <FieldType ftype, UInt Dim>
void Dumper1D<Cont>::dumpField(Cont & cont){
typename Cont::iterator it = cont.getIterator();
typedef typename Cont::Ref RefPoint;
for (RefPoint at = it.getFirst();!it.end();at = it.getNext()){
Real f = at.template field<ftype>(0);
file << std::scientific << std::setprecision(precision)
<< f << "\t" << at.position0(0) << "\t";
}
file << std::endl;
}
/* -------------------------------------------------------------------------- */
/* LMDESC DUMPER1D
Dumps the per point information such as position,displacement,velocity and force
for 1D domains.
*/
/* LMEXAMPLE DUMPER dmd1d DUMPER1D INPUT md FREQ 100 PREFIX ./ FIELD position */
/* LMHERITANCE dumper */
template <typename Cont>
void Dumper1D<Cont>::declareParams(){
Dumper<Cont>::declareParams();
/* LMKEYWORD FIELD
Specify the field to extract
*/
this->parseKeyword("FIELD",field_type);
/* LMKEYWORD FILTER
specify what to put with positions
*/
this->parseKeyword("FILTER",filter,invalidFilter);
/* LMKEYWORD PRECISION
The generated file will use the provided precision.
*/
this->parseKeyword("PRECISION",precision,15u);
/* LMKEYWORD DONOTREBUILD
the default is to recompute
You can ask not to recompute the attached filter so that
when another instance ask for the compute at another time the release
number will be ignored
*/
this->parseTag("DONOTREBUILD",do_not_rebuild_flag,false);
}
/* -------------------------------------------------------------------------- */
DECLARE_DUMPER_REF(Dumper1D,LIST_ATOM_MODEL);
DECLARE_DUMPER_REF(Dumper1D,LIST_CONTINUUM_MODEL);
DECLARE_DUMPER_REF(Dumper1D,LIST_DD_MODEL);
DECLARE_DUMPER_REFPOINT(Dumper1D);
DECLARE_DUMPER_GENERIC_MESH(Dumper1D);
__END_LIBMULTISCALE__

Event Timeline