Skip to content
Snippets Groups Projects
Commit c75f4390 authored by Michael Kuron's avatar Michael Kuron :mortar_board:
Browse files

addFlattenedShallowCopyToStorage

parent 711dc8e1
No related merge requests found
......@@ -246,6 +246,36 @@ BlockDataID addCloneToStorage( const shared_ptr< BlockStorage_T > & blocks,
//**********************************************************************************************************************
/*! Adds a flattened shallow copy of an existing field to BlockStorage
*
* Template parameters:
* Field_T the type of the field that should be cloned and flattened
* BlockStorage_T the type of the BlockStorage ( will be deduced automatically )
*
* Parameters:
* \param blocks BlockStorage where the original field is stored and the new one is created
* \param fieldToClone BlockDataID of the Field that is cloned
* \param identifier name for new the field ( displayed in GUI and debugging functions )
*/
//**********************************************************************************************************************
template< typename Field_T, typename BlockStorage_T >
BlockDataID addFlattenedShallowCopyToStorage( const shared_ptr< BlockStorage_T > & blocks,
ConstBlockDataID fieldToClone,
const std::string & identifier,
const Set<SUID> & requiredSelectors = Set<SUID>::emptySet(),
const Set<SUID> & incompatibleSelectors = Set<SUID>::emptySet() )
{
return blocks->addBlockData( make_shared< field::FlattenedShallowCopyBlockDataHandling< Field_T > >( fieldToClone ),
identifier, requiredSelectors, incompatibleSelectors );
}
//**********************************************************************************************************************
/*! BlockDataCreator for fields
*
......
......@@ -538,5 +538,31 @@ private:
template< typename Field_T >
class FlattenedShallowCopyBlockDataHandling : public blockforest::AlwaysInitializeBlockDataHandling< typename Field_T::FlattenedGhostLayerField >
{
public:
FlattenedShallowCopyBlockDataHandling( const ConstBlockDataID & fieldToClone ) :
fieldToClone_( fieldToClone )
{}
typename Field_T::FlattenedGhostLayerField * initialize( IBlock * const block )
{
const Field_T * toClone = block->template getData< Field_T >( fieldToClone_ );
return toClone->flattenedShallowCopy();
}
private:
ConstBlockDataID fieldToClone_;
}; // class FlattenedShallowCopyBlockDataHandling
} // namespace field
} // namespace walberla
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla 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 General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file CollectTest.h
//! \author Martin Bauer <martin.bauer@fau.de>
//
//======================================================================================================================
#include "core/debug/TestSubsystem.h"
#include "core/Environment.h"
#include "blockforest/Initialization.h"
#include "field/AddToStorage.h"
namespace walberla {
int main( int argc, char ** argv )
{
debug::enterTestMode();
walberla::Environment walberlaEnv( argc, argv );
auto blocks = blockforest::createUniformBlockGrid( 2, 2, 2, // blocks in x,y,z
4, 4, 4, // nr of cells per block
1.0, // dx
false
);
typedef GhostLayerField<Vector3<uint_t>,1> VectorField;
typedef GhostLayerField<uint_t, 3> FlattenedField;
BlockDataID fieldID = field::addToStorage<VectorField>( blocks, "Field" );
BlockDataID flattenedID = field::addFlattenedShallowCopyToStorage<VectorField>( blocks, fieldID, "flattened Field");
for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt )
{
VectorField * field = blockIt->getData<VectorField>( fieldID );
for( auto cellIt = field->beginXYZ(); cellIt != field->end(); ++cellIt )
{
for( uint_t f = 0; f < 3; ++f)
{
uint_t val = uint_t(&(*cellIt)[f]);
(*cellIt)[f] = val;
}
}
}
BlockDataID copyID = field::addCloneToStorage<VectorField>( blocks, fieldID, "copied Field");
for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt )
{
VectorField * field = blockIt->getData<VectorField>( fieldID );
FlattenedField * flattened = blockIt->getData<FlattenedField>( flattenedID );
VectorField * copy = blockIt->getData<VectorField>( copyID );
for( auto cellIt = field->beginXYZ(); cellIt != field->end(); ++cellIt )
{
for( uint_t f = 0; f < 3; ++f)
{
WALBERLA_CHECK_EQUAL((*cellIt)[f], copy->get(cellIt.x(), cellIt.y(), cellIt.z())[f]);
WALBERLA_CHECK_UNEQUAL(&(*cellIt)[f], &(copy->get(cellIt.x(), cellIt.y(), cellIt.z())[f]));
WALBERLA_CHECK_EQUAL(&(*cellIt)[f], &(flattened->get(cellIt.x(), cellIt.y(), cellIt.z(), f)));
}
}
}
return 0;
}
}
int main( int argc, char ** argv )
{
return walberla::main(argc,argv);
}
......@@ -7,6 +7,9 @@
waLBerla_compile_test( FILES AccuracyEvaluationTest.cpp DEPENDS blockforest )
waLBerla_execute_test( NAME AccuracyEvaluationTest4 COMMAND $<TARGET_FILE:AccuracyEvaluationTest> PROCESSES 4 )
waLBerla_compile_test( FILES AddToStorageTest.cpp DEPENDS blockforest )
waLBerla_execute_test( NAME AddToStorageTest )
waLBerla_compile_test( FILES communication/FieldPackInfoTest.cpp DEPENDS blockforest )
waLBerla_execute_test( NAME FieldPackInfoTest )
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment