Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82106685
dumper_grid.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
Mon, Sep 9, 15:21
Size
6 KB
Mime Type
text/x-c++
Expires
Wed, Sep 11, 15:21 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
20652762
Attached To
rLIBMULTISCALE LibMultiScale
dumper_grid.cc
View Options
/**
* @file dumper_grid.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Jul 09 21:59:47 2014
*
* @brief This dumper allows to use a grid so as to reduce on a per-cell basis
*
* @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_grid.hh"
#include "cube.hh"
#include "lib_md.hh"
#include "lib_dd.hh"
#include "lib_continuum.hh"
#include "filter.hh"
#include "lm_file.hh"
#include "ref_point_data.hh"
#include <iomanip>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template <typename Cont>
void DumperGrid<Cont>::dump(Cont & cont){
static const UInt Dim = Cont::Dim;
switch (field){
case _displacement: FillGrid<_displacement>(cont,Dim);break;
case _velocity : FillGrid<_velocity>(cont,Dim);break;
case _force : FillGrid<_force>(cont,Dim);break;
default: LM_FATAL("cannot treat this field");
}
std::stringstream fname;
fname << this->getBaseName() << "_grid." << std::setfill('0') << std::setw(4)
<< this->action_step << ".txt";
LMFile file(fname.str());
std::vector<std::vector<Tensor> *> & blocks = grid->getBlocks();
Real x=0,y=0,z=0;
std::vector<Real> force_x;
for (UInt i = 0; i < grid->getSize();++i)
if (blocks[i]) {
grid->index2Coordinates(i,x,y,z);
Tensor t;
t = grid->extractBoxValue(i,op);
file.printf("%d\t%.15e\t%.15e\t%.15e\t%.15e\t%.15e\t%.15e\t%.15e\t%.15e\t%.15e\n",
i,x,y,z,t(0),t(1),t(2),t(3),t(4),t(5));
}
file.close();
delete (grid);
grid = NULL;
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
template <FieldType type>
void DumperGrid<Cont>::FillGrid(Cont & cont, const UInt & Dim){
if (cont.nbElem() == 0) return;
Cube & cube = cont.getBoundingBox();
for (UInt i = 0; i < Dim; ++i) {
if (gridspace[i] == -1 && griddivision[i] == UINT_MAX)
LM_FATAL("GRIDSPACE or GRIDDIVISION keyword should be used for direction " << i);
}
Real gridspace2[3] = {0,0,0};
for (UInt i = 0; i < Dim; ++i) gridspace2[i] = gridspace[i];
grid = new SpatialGridPoint<Tensor,3>(cube,gridspace2,griddivision);
typedef typename Cont::Ref RefPoint;
typename Cont::iterator it = cont.getIterator();
for (RefPoint at = it.getFirst();!it.end();at = it.getNext())
{
Real x[Dim];
at.getPositions0(x);
if (current_flag) at.getPositions(x);
Real tmp[Dim];
at.template getField<type>(tmp);
Tensor t;
for (UInt i = 0; i < Dim; ++i) t(i) = tmp[i];
grid->addElement(t,x);
}
DUMP("we have as average " << grid->getAverageEltByBlock() << " points per block",DBG_MESSAGE);
}
/* -------------------------------------------------------------------------- */
/* LMDESC GRID
This dumper allows to use a grid so as to reduce on a per-cell basis.
A point/nodes based sorting into a spatial grid is used.
It admits several options that could be model dependent.
*/
/* LMEXAMPLE DUMPER GRID GRIDSPACE 10 10 10 PREFIX /home/titeuf */
/* LMHERITANCE dumper */
template <typename _Input>
inline void DumperGrid<_Input>::declareParams(){
Dumper<_Input>::declareParams();
/* LMKEYWORD GRID_DIVISIONX
Set the number of grid cells in x direction
*/
this->parseKeyword("GRID_DIVISIONX",griddivision[0]);
/* LMKEYWORD GRID_DIVISIONY
Set the number of grid cells in y direction
*/
this->parseKeyword("GRID_DIVISIONY",griddivision[1]);
/* LMKEYWORD GRID_DIVISIONZ
Set the number of grid cells in x direction
*/
this->parseKeyword("GRID_DIVISIONZ",griddivision[2]);
/* LMKEYWORD GRID_DIVISION
Allows to set the number of grid cells in all directions of
space, see GRID\_DIVISION\_X/Y/Z
*/
this->parseVectorKeyword("GRID_DIVISION",3,griddivision);
/* LMKEYWORD GRIDSPACEX
Set the cell size in the X direction for the grid generation
*/
this->parseKeyword("GRIDSPACEX",gridspace[0]);
/* LMKEYWORD GRIDSPACEY
Set the cell size in the Y direction for the grid generation
*/
this->parseKeyword("GRIDSPACEY",gridspace[1]);
/* LMKEYWORD GRIDSPACEZ
Set the cell size in the Z direction for the grid generation
*/
this->parseKeyword("GRIDSPACEZ",gridspace[2]);
/* LMKEYWORD GRIDSPACE
The implementation of the Bridging domain method needs a match
between elements and atoms to be made at initialisation of the
bridging zones. This could be a very costful operation. \\
In order to break the complexity of such a stage, the
elements are first stored in a grid for which
number of cells (in each direction) are specified by this keyword.
*/
this->parseVectorKeyword("GRIDSPACE",3,gridspace);
/* LMKEYWORD OPERATOR
Specify the operator to reduce the information per cell \\
The possible operators are for now:
\begin{itemize}
\item SUM: perform a sum per cell $\sum_{i \in cell} v_i$
\item AVERAGE: perform an average per cell $\frac{1}{\#cell}\sum_{i \in cell} v_i$
\item DENSITY: perform the volumetric average $\overline{v} = \frac{1}{vol(cell)}\sum_{i \in cell} v_i$
\item DEVIATION: compute the standard deviation $\frac{1}{\#cell}\sum_{i \in cell} (v_i - \overline{v} )^2$
\item MAX: compute the max value
\item MIN: compute the min value
\end{itemize}
*/
this->parseKeyword("OPERATOR",op);
/* LMKEYWORD CURRENT_POSITION
All the points/atoms/nodes are sorted in a spatial grid. By default the initial position of
these points/atoms/nodes are considered. This flag allows to consider current positions instead.
*/
this->parseTag("CURRENT_POSITION",current_flag);
/* LMKEYWORD FIELD
Request to perform the grid reduction on the provided field
*/
this->parseKeyword("FIELD",field);
}
/* -------------------------------------------------------------------------- */
DECLARE_DUMPER_REF(DumperGrid,LIST_ATOM_MODEL)
DECLARE_DUMPER_REF(DumperGrid,LIST_CONTINUUM_MODEL)
DECLARE_DUMPER_REF(DumperGrid,LIST_DD_MODEL)
DECLARE_DUMPER_REFPOINT(DumperGrid)
DECLARE_DUMPER_GENERIC_MESH(DumperGrid)
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment