Page MenuHomec4science

stimulation_field_point.cc
No OneTemporary

File Metadata

Created
Mon, May 27, 20:40

stimulation_field_point.cc

/**
* @file stimulation_field_point.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
* @author Till Junge <till.junge@epfl.ch>
* @author Jaehyun Cho <jaehyun.cho@epfl.ch>
*
* @date Thu Sep 18 16:13:19 2014
*
* @brief Impose a field to a set of degree of freedom
*
* @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 "stimulation_field.hh"
#include "lib_md.hh"
#include "lib_dd.hh"
#include "lib_continuum.hh"
#include "filter_manager.hh"
#include "compute.hh"
#include "filter.hh"
#include "ref_point_data.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont>
void StimulationField<Cont>::stimulate(Cont & cont, UInt stage) {
static const UInt Dim = Cont::Dim;
switch (ftype){
case _position0: stimulateField<Dim,_position0>(cont);break;
case _position: stimulateField<Dim,_position>(cont);break;
case _displacement: stimulateField<Dim,_displacement>(cont);break;
case _velocity: stimulateField<Dim,_velocity>(cont);break;
case _force: stimulateField<Dim,_force>(cont);break;
case ft_uninitialised:
LM_FATAL("You forgot to set the field type for the stimulator \""
<< this->getID() << "\"");break;
default: LM_FATAL("cannot treat field type \"" << ftype << "\"" << std::endl);
}
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
template <UInt Dim,FieldType type>
void StimulationField<Cont>::stimulateField(Cont & cont){
if (cont.size() == 0) return;
ComputeInterface * ptr =
dynamic_cast<ComputeInterface *>(FilterManager::getManager().getObject(compute_id));
if (!ptr) LM_FATAL("invalid compute id: " << compute_id);
ptr->build();
UInt dim_compute = ptr->getDim();
// CommGroup group = cont.getCommGroup();
// Communicator & comm = Communicator::getCommunicator();
// UInt my_rank = comm.groupRank(lm_my_proc_id, group);
// UInt globalSize = ptr->getTotalNbData(ptr->gather_root_proc);
// if (ptr->gather_flag){
// // if (dim_compute != Dim)
// // LM_FATAL("incompatible dimensions " << dim_compute << " != " << Dim);
// if(my_rank == ptr->gather_root_proc) {
// if (ptr->nbElem()/dim_compute != globalSize/dim_compute)
// LM_FATAL("compute or filter contains " << globalSize/dim_compute << " entries"
// << " while container have " << globalSize/dim_compute << " : incompatible match");}
// else {return;}
// }
// else {
if (dim_compute != Dim)
LM_FATAL(this->getID() << ": incompatible dimensions " << dim_compute << " != " << Dim
<< " cont size: " << cont.size() << " compute size: " << ptr->size());
if (ptr->nbElem()/dim_compute != cont.nbElem())
LM_FATAL(this->getID() << ": compute or filter contains " << ptr->nbElem()/dim_compute << " entries"
<< " while container have " << cont.nbElem() << " : incompatible match");
ComputeInterface & comp = *ptr;
typedef typename Cont::Ref RefDof;
typename Cont::iterator it = cont.getIterator();
typename ComputeInterface::iterator itCompute = comp.getIterator();
Real val = itCompute.getFirst();
if (this->additive_flag) {
for(RefDof at = it.getFirst(); !it.end(); at = it.getNext()) {
for (UInt i = 0; i < Dim; ++i){
at.template field<type>(i) += val;
val = itCompute.getNext();
}
}
} else {
for(RefDof at = it.getFirst(); !it.end(); at = it.getNext()) {
for (UInt i = 0; i < Dim; ++i){
at.template field<type>(i) = val;
val = itCompute.getNext();
}
}
}
}
/* -------------------------------------------------------------------------- */
DECLARE_STIMULATION(StimulationField,LIST_ATOM_MODEL)
DECLARE_STIMULATION(StimulationField,LIST_DD_MODEL)
DECLARE_STIMULATION_REFPOINT(StimulationField)
DECLARE_STIMULATION_GENERIC_MESH(StimulationField)
__END_LIBMULTISCALE__

Event Timeline