MOAB: Mesh Oriented datABase
(version 5.2.1)
|
#include <TargetWriter.hpp>
Public Member Functions | |
MESQUITE_EXPORT | TargetWriter (TargetCalculator *tc, WeightCalculator *wc=0, std::string target_base_name="MSQ_TARGET_MATRIX", std::string weight_base_name="MSQ_TARGET_WEIGHT") |
virtual MESQUITE_EXPORT | ~TargetWriter () |
MESQUITE_EXPORT double | loop_over_mesh (MeshDomainAssoc *mesh_and_domain, const Settings *, MsqError &) |
MESQUITE_EXPORT void | initialize_queue (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err) |
MESQUITE_EXPORT std::string | get_name () const |
Get string name for use in diagnostic and status output. | |
Private Member Functions | |
TagHandle | get_target_tag (unsigned dimension, unsigned count, Mesh *mesh, MsqError &err) |
TagHandle | get_weight_tag (unsigned count, Mesh *mesh, MsqError &err) |
TagHandle | get_tag_handle (const std::string &base_name, unsigned num_dbl, Mesh *mesh, MsqError &err) |
Private Attributes | |
TargetCalculator * | targetCalc |
WeightCalculator * | weightCalc |
std::string | targetName |
std::string | weightName |
std::vector< TagHandle > | targetTags |
std::vector< TagHandle > | weightTags |
Save target matrices in tag data
Store element target matrices in tag data. The stored target matrices may be retreived using the TargetReader class.
Definition at line 50 of file TargetWriter.hpp.
MBMesquite::TargetWriter::TargetWriter | ( | TargetCalculator * | tc, |
WeightCalculator * | wc = 0 , |
||
std::string | target_base_name = "MSQ_TARGET_MATRIX" , |
||
std::string | weight_base_name = "MSQ_TARGET_WEIGHT" |
||
) |
Definition at line 48 of file TargetWriter.cpp.
: targetCalc( tc ), weightCalc( wc ), targetName( target_base_name ), weightName( weight_base_name ) { }
MBMesquite::TargetWriter::~TargetWriter | ( | ) | [virtual] |
Definition at line 54 of file TargetWriter.cpp.
{}
std::string MBMesquite::TargetWriter::get_name | ( | ) | const [virtual] |
Get string name for use in diagnostic and status output.
Implements MBMesquite::Instruction.
Definition at line 56 of file TargetWriter.cpp.
{ return "TargetWriter"; }
TagHandle MBMesquite::TargetWriter::get_tag_handle | ( | const std::string & | base_name, |
unsigned | num_dbl, | ||
Mesh * | mesh, | ||
MsqError & | err | ||
) | [private] |
Definition at line 220 of file TargetWriter.cpp.
References MBMesquite::MsqError::clear(), MBMesquite::Mesh::DOUBLE, MBMesquite::MsqError::error_code(), MSQ_CHKERR, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::MsqError::TAG_ALREADY_EXISTS, MBMesquite::Mesh::tag_create(), MBMesquite::Mesh::tag_get(), MBMesquite::MsqError::TAG_NOT_FOUND, and MBMesquite::Mesh::tag_properties().
Referenced by get_target_tag(), and get_weight_tag().
{ std::ostringstream sstr; sstr << base_name << num_dbl; TagHandle handle = mesh->tag_get( sstr.str().c_str(), err ); if( !MSQ_CHKERR( err ) ) { std::string temp_name; Mesh::TagType temp_type; unsigned temp_length; mesh->tag_properties( handle, temp_name, temp_type, temp_length, err ); MSQ_ERRZERO( err ); if( temp_type != Mesh::DOUBLE || temp_length != num_dbl ) { MSQ_SETERR( err ) ( MsqError::TAG_ALREADY_EXISTS, "Mismatched type or length for existing tag \"%s\"", sstr.str().c_str() ); } } else if( err.error_code() == MsqError::TAG_NOT_FOUND ) { err.clear(); handle = mesh->tag_create( sstr.str().c_str(), Mesh::DOUBLE, num_dbl, 0, err ); MSQ_ERRZERO( err ); } return handle; }
TagHandle MBMesquite::TargetWriter::get_target_tag | ( | unsigned | dimension, |
unsigned | count, | ||
Mesh * | mesh, | ||
MsqError & | err | ||
) | [private] |
Definition at line 186 of file TargetWriter.cpp.
References dim, get_tag_handle(), MBMesquite::TargetCalculator::have_surface_orient(), MSQ_CHKERR, targetCalc, targetName, and targetTags.
Referenced by loop_over_mesh().
{ if( dim == 2 && !targetCalc->have_surface_orient() ) count *= 4; else count *= 3 * dim; // num doubles if( targetTags.size() <= count ) targetTags.resize( count + 1, 0 ); if( !targetTags[count] ) { targetTags[count] = get_tag_handle( targetName, count, mesh, err ); if( MSQ_CHKERR( err ) ) { targetTags[count] = 0; return 0; } } return targetTags[count]; }
TagHandle MBMesquite::TargetWriter::get_weight_tag | ( | unsigned | count, |
Mesh * | mesh, | ||
MsqError & | err | ||
) | [private] |
Definition at line 205 of file TargetWriter.cpp.
References get_tag_handle(), MSQ_CHKERR, weightName, and weightTags.
Referenced by loop_over_mesh().
{ if( weightTags.size() <= count ) weightTags.resize( count + 1, 0 ); if( !weightTags[count] ) { weightTags[count] = get_tag_handle( weightName, count, mesh, err ); if( MSQ_CHKERR( err ) ) { weightTags[count] = 0; return 0; } } return weightTags[count]; }
void MBMesquite::TargetWriter::initialize_queue | ( | MeshDomainAssoc * | mesh_and_domain, |
const Settings * | settings, | ||
MsqError & | err | ||
) | [virtual] |
Called for all instructions in queue before loop_over_mesh is called for any insetruction in queue. Default behavior is to do nothing.
Implements MBMesquite::Instruction.
Definition at line 249 of file TargetWriter.cpp.
{}
double MBMesquite::TargetWriter::loop_over_mesh | ( | MeshDomainAssoc * | mesh_and_domain, |
const Settings * | settings, | ||
MsqError & | err | ||
) | [virtual] |
Virtual fuction implementing primary functionaliy of instruction instance.
Implements MBMesquite::Instruction.
Definition at line 61 of file TargetWriter.cpp.
References MBMesquite::arrptr(), MBMesquite::PatchData::attach_settings(), moab::cross(), MBMesquite::det(), dim, MBMesquite::PatchData::element_by_index(), MBMesquite::TargetCalculator::get_2D_target(), MBMesquite::TargetCalculator::get_3D_target(), MBMesquite::MeshDomainAssoc::get_domain(), MBMesquite::PatchData::get_element_handles_array(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::MeshDomainAssoc::get_mesh(), MBMesquite::ElementPatches::get_patch(), MBMesquite::ElementPatches::get_patch_handles(), MBMesquite::PatchData::get_samples(), MBMesquite::TargetCalculator::get_surface_target(), get_target_tag(), MBMesquite::WeightCalculator::get_weight(), get_weight_tag(), MBMesquite::TargetCalculator::have_surface_orient(), MBMesquite::MsqError::INVALID_ARG, mesh, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::PatchData::num_elements(), MBMesquite::PatchData::set_domain(), MBMesquite::PatchSet::set_mesh(), MBMesquite::PatchData::set_mesh(), MBMesquite::PatchData::set_mesh_entities(), MBMesquite::Mesh::tag_set_element_data(), targetCalc, and weightCalc.
Referenced by TargetReadWriteTest::read_write_2D_targets(), TargetReadWriteTest::read_write_3D_targets(), TargetReadWriteTest::read_write_surface_targets(), and TargetReadWriteTest::read_write_weights().
{ Mesh* mesh = mesh_and_domain->get_mesh(); MeshDomain* domain = mesh_and_domain->get_domain(); PatchData patch; patch.set_mesh( mesh ); patch.set_domain( domain ); if( settings ) patch.attach_settings( settings ); ElementPatches patch_set; patch_set.set_mesh( mesh ); std::vector< PatchSet::PatchHandle > patches; std::vector< PatchSet::PatchHandle >::iterator p; std::vector< Mesh::VertexHandle > patch_verts; std::vector< Mesh::ElementHandle > patch_elems; patch_set.get_patch_handles( patches, err ); MSQ_ERRZERO( err ); std::vector< MsqMatrix< 3, 3 > > targets3d; std::vector< MsqMatrix< 3, 2 > > targets2dorient; std::vector< MsqMatrix< 2, 2 > > targets2d; std::vector< double > weights; std::vector< Sample > samples; for( p = patches.begin(); p != patches.end(); ++p ) { patch_verts.clear(); patch_elems.clear(); patch_set.get_patch( *p, patch_elems, patch_verts, err ); MSQ_ERRZERO( err ); patch.set_mesh_entities( patch_elems, patch_verts, err ); MSQ_ERRZERO( err ); assert( patch.num_elements() == 1 ); MsqMeshEntity& elem = patch.element_by_index( 0 ); EntityTopology type = elem.get_element_type(); patch.get_samples( 0, samples, err ); MSQ_ERRZERO( err ); if( samples.empty() ) continue; if( targetCalc ) { const unsigned dim = TopologyInfo::dimension( type ); if( dim == 3 ) { targets3d.resize( samples.size() ); for( unsigned i = 0; i < samples.size(); ++i ) { targetCalc->get_3D_target( patch, 0, samples[i], targets3d[i], err ); MSQ_ERRZERO( err ); if( DBL_EPSILON > det( targets3d[i] ) ) { MSQ_SETERR( err )( "Inverted 3D target", MsqError::INVALID_ARG ); return 0.0; } } TagHandle tag = get_target_tag( 3, samples.size(), mesh, err ); MSQ_ERRZERO( err ); mesh->tag_set_element_data( tag, 1, patch.get_element_handles_array(), arrptr( targets3d ), err ); MSQ_ERRZERO( err ); } else if( targetCalc->have_surface_orient() ) { targets2dorient.resize( samples.size() ); for( unsigned i = 0; i < samples.size(); ++i ) { targetCalc->get_surface_target( patch, 0, samples[i], targets2dorient[i], err ); MSQ_ERRZERO( err ); MsqMatrix< 3, 1 > cross = targets2dorient[i].column( 0 ) * targets2dorient[i].column( 1 ); if( DBL_EPSILON > ( cross % cross ) ) { MSQ_SETERR( err )( "Degenerate 2D target", MsqError::INVALID_ARG ); return 0.0; } } TagHandle tag = get_target_tag( 2, samples.size(), mesh, err ); MSQ_ERRZERO( err ); mesh->tag_set_element_data( tag, 1, patch.get_element_handles_array(), arrptr( targets2dorient ), err ); MSQ_ERRZERO( err ); } else { targets2d.resize( samples.size() ); for( unsigned i = 0; i < samples.size(); ++i ) { targetCalc->get_2D_target( patch, 0, samples[i], targets2d[i], err ); MSQ_ERRZERO( err ); if( DBL_EPSILON > det( targets2d[i] ) ) { MSQ_SETERR( err )( "Degenerate/Inverted 2D target", MsqError::INVALID_ARG ); return 0.0; } } TagHandle tag = get_target_tag( 2, samples.size(), mesh, err ); MSQ_ERRZERO( err ); mesh->tag_set_element_data( tag, 1, patch.get_element_handles_array(), arrptr( targets2d ), err ); MSQ_ERRZERO( err ); } } if( weightCalc ) { weights.resize( samples.size() ); for( unsigned i = 0; i < samples.size(); ++i ) { weights[i] = weightCalc->get_weight( patch, 0, samples[i], err ); MSQ_ERRZERO( err ); } TagHandle tag = get_weight_tag( samples.size(), mesh, err ); MSQ_ERRZERO( err ); mesh->tag_set_element_data( tag, 1, patch.get_element_handles_array(), arrptr( weights ), err ); MSQ_ERRZERO( err ); } } return 0.0; }
Definition at line 73 of file TargetWriter.hpp.
Referenced by get_target_tag(), and loop_over_mesh().
std::string MBMesquite::TargetWriter::targetName [private] |
Definition at line 76 of file TargetWriter.hpp.
Referenced by get_target_tag().
std::vector< TagHandle > MBMesquite::TargetWriter::targetTags [private] |
Definition at line 77 of file TargetWriter.hpp.
Referenced by get_target_tag().
Definition at line 74 of file TargetWriter.hpp.
Referenced by loop_over_mesh().
std::string MBMesquite::TargetWriter::weightName [private] |
Definition at line 76 of file TargetWriter.hpp.
Referenced by get_weight_tag().
std::vector< TagHandle > MBMesquite::TargetWriter::weightTags [private] |
Definition at line 77 of file TargetWriter.hpp.
Referenced by get_weight_tag().