Beispiel #1
0
    void ParsedDRICmd::SetParams(const QStringList &params)
    {
        if (CDebugMode) std::cout << "params: " << params.join(";").toStdString() << std::endl;

        m_params.clear(); // ?!

        // check and set params
        for (int i = 0; i < params.size(); ++i)
        {
            QString pm( params.at(i) );

            if ( pm.isEmpty() )
            {
                ThrowErrorMsg( "Missing method's parameter", params.join(CParamSep) );
            }

            // pm can also be unquoted path: obj1.obj11
            if ( (!ValidateObjName(pm) ) 
                 &&( ContainsUnquotedSystemSymbols(pm) ) )
            {
                QString err = "Parameter contains unquoted system symbol \'" + pm + "\'";
                ThrowErrorMsg(err, params.join(CParamSep));
            }

            pm = DriUtils::UnquoteString(pm, CStringChar);

            m_params.push_back(pm);
        }
    }
Beispiel #2
0
    void ParsedDRICmd::FillNameAndPath(const QString &data)
    {
        if (CDebugMode) std::cout << "FillNameAndPath" << std::endl;
        
        QString tmp(data);

        if ( tmp.startsWith(CPathSep) )
        {
            m_isRelativePath = true;
            tmp = tmp.remove(0, 1);
        }

        // check name validation
        if ( ( tmp.isEmpty() ) || ( tmp.endsWith(CPathSep) ) ) 
        {
            ThrowErrorMsg("No method's or property's name found", tmp);
        }

        QStringList nameAndPath = tmp.split(CPathSep, QString::KeepEmptyParts);
        // check syntax
        for (int i = 0; i < nameAndPath.size(); ++i)
        {
            QString name( nameAndPath.at(i) );
            if ( ( name.isEmpty() ) || ( !ValidateObjName(name) ) )
            {
                ThrowErrorMsg("Invalid method's or property's name or path", tmp);
            }
        }
        
        m_methodOrPropertyName = nameAndPath.last();
        nameAndPath.removeLast();
        m_fullObjectName = nameAndPath;
    }
Beispiel #3
0
bool field_data_valid( const FieldBase & f ,
                       const Bucket & k ,
                       unsigned ord ,
                       const char * required_by )
{
  const MetaData * const k_mesh_meta_data = & MetaData::get(k);
  const MetaData * const f_mesh_meta_data = & MetaData::get(f);
  const bool ok_mesh_meta_data  = k_mesh_meta_data == f_mesh_meta_data ;
  const bool ok_ord     = ord < k.size() ;
  const bool exists     = ok_mesh_meta_data && ok_ord &&
                          NULL != field_data( f , k.begin() );

  if ( required_by && ! exists ) {
    std::ostringstream msg_begin ;
    msg_begin << "For args: " ;
    msg_begin << f << " , " ;
    msg_begin << k << " , " ;
    msg_begin << ord << " , " ;
    msg_begin << required_by ;
    msg_begin << "; operation FAILED with " ;
    ThrowErrorMsgIf( ! ok_mesh_meta_data,
                     msg_begin.str() << " different MetaData");
    ThrowErrorMsgIf( ! ok_ord, msg_begin.str() <<
                     " Ordinal " <<  ord << " >= " << " size " << k.size());
    ThrowErrorMsg( msg_begin.str() << " no data");
  }

  return exists ;
}
Beispiel #4
0
    void ParsedDRICmd::CutNameAndPath()
    {
        QStringList res;

        if (CDebugMode) std::cout << "CutNameAndPath" << std::endl;
        
        // 1) try split using CMethodInitBegin
        SplitWithQuotesConsideration(m_cmd, CMethodInitBegin, res);
        if (res.size() > 2) ThrowSepErrorMsg("Extra", CMethodInitBegin);
        if (res.size() == 1) 
        {
            // 2) try split using COptInit
            SplitWithQuotesConsideration(m_cmd, COptInit, res);
            if (res.size() > 2) ThrowSepErrorMsg("Extra", COptInit);
            if (res.size() == 1)
            {
                // 3) try split using CSep
                SplitWithQuotesConsideration(m_cmd, CSep, res);
            }
        }

        // fill fields
        if (res.size() < 1) ThrowErrorMsg("No method's or property's name found", m_cmd);
        QString nameAndPath = res.at(0).trimmed();
        FillNameAndPath(nameAndPath);

        // cut
        m_cmd = m_cmd.remove( 0, nameAndPath.size() );
    }
Beispiel #5
0
    void ParsedDRICmd::MakeParamList()
    {
        // [ ][(]param[,] param2[)]
        // [ ][=]param
         
        if (CDebugMode) std::cout << "MakeParamList" << std::endl;

        m_cmd = m_cmd.trimmed();

        QStringList params;
       
        // if it's option's parameter, which starts with COptInit
        if ( m_cmd.startsWith(COptInit) )
        {
            m_cmd = m_cmd.remove(0, 1).trimmed();
            if ( m_cmd.isEmpty() ) ThrowSepErrorMsg("Missing property's parameter after", 
                                                        COptInit);
            // even is there is too many params will be syntax exception
            SetParams( QStringList(m_cmd) );
            m_actType = PropertyWrite;
            return;
        }

        // if there are method's parameters, 
        // which start with CMethodInitBegin and end with CMethodInitEnd
        if ( m_cmd.startsWith(CMethodInitBegin) )
        {
            if ( !m_cmd.endsWith(CMethodInitEnd) )
            {
                ThrowSepErrorMsg("Parameter's list does not end with", CMethodInitEnd);
            }
            // remove separators
            m_cmd = m_cmd.mid(1, m_cmd.size() - 2);
            m_actType = MethodCall;
        }

        // try split with using CParamSep
        if ( m_cmd.trimmed().endsWith(CParamSep) )
        {
            ThrowErrorMsg("Missing property's parameter after", CParamSep);
        }
        SplitWithQuotesConsideration(m_cmd, CParamSep, params, false);
        if (params.size() > 1) 
        {
            SetParams(params);
            m_actType = MethodCall;
            return;
        }

        // try split with using CSep
        SplitWithQuotesConsideration(m_cmd, CSep, params);
        SetParams(params);
        if (params.size() > 1) m_actType = MethodCall;
    }
Beispiel #6
0
void FieldBaseImpl::insert_restriction(
  const char     * arg_method ,
  EntityRank       arg_entity_rank ,
  const Selector & arg_selector ,
  const unsigned * arg_stride,
  const void*      arg_init_value )
{
  TraceIfWatching("stk::mesh::impl::FieldBaseImpl::insert_restriction", LOG_FIELD, m_ordinal);

  FieldRestriction tmp( arg_entity_rank , arg_selector );

  {
    unsigned i = 0 ;
    if ( m_field_rank ) {
      for ( i = 0 ; i < m_field_rank ; ++i ) { tmp.stride(i) = arg_stride[i] ; }
    }
    else { // Scalar field is 0 == m_field_rank
      i = 1 ;
      tmp.stride(0) = 1 ;
    }
    // Remaining dimensions are 1, no change to stride
    for ( ; i < MaximumFieldDimension ; ++i ) {
      tmp.stride(i) = tmp.stride(i-1) ;
    }

    for ( i = 1 ; i < m_field_rank ; ++i ) {
      const bool bad_stride = 0 == tmp.stride(i) ||
                              0 != tmp.stride(i) % tmp.stride(i-1);
      ThrowErrorMsgIf( bad_stride,
          arg_method << " FAILED for " << *this <<
          " WITH BAD STRIDE!");
    }
  }

  if (arg_init_value != NULL) {
    //insert_restriction can be called multiple times for the same field, giving
    //the field different lengths on different mesh-parts.
    //We will only store one initial-value array, we need to store the one with
    //maximum length for this field so that it can be used to initialize data
    //for all field-restrictions. For the parts on which the field is shorter,
    //a subset of the initial-value array will be used.
    //
    //We want to end up storing the longest arg_init_value array for this field.
    //
    //Thus, we call set_initial_value only if the current length is longer
    //than what's already been stored.

    //length in bytes is num-scalars X sizeof-scalar:

    size_t num_scalars = 1;
    //if rank > 0, then field is not a scalar field, so num-scalars is
    //obtained from the stride array:
    if (m_field_rank > 0) num_scalars = tmp.stride(m_field_rank-1);

    size_t sizeof_scalar = m_data_traits.size_of;
    size_t nbytes = sizeof_scalar * num_scalars;

    size_t old_nbytes = 0;
    if (get_initial_value() != NULL) {
      old_nbytes = get_initial_value_num_bytes();
    }

    if (nbytes > old_nbytes) {
      set_initial_value(arg_init_value, num_scalars, nbytes);
    }
  }

  {
    FieldRestrictionVector & srvec = selector_restrictions();

    bool restriction_already_exists = false;
    for(FieldRestrictionVector::const_iterator it=srvec.begin(), it_end=srvec.end();
        it!=it_end; ++it) {
      if (tmp == *it) {
        restriction_already_exists = true;
        if (tmp.not_equal_stride(*it)) {
          ThrowErrorMsg("Incompatible selector field-restrictions!");
        }
      }
    }

    if ( !restriction_already_exists ) {
      // New field restriction, verify we are not committed:
      ThrowRequireMsg(!m_meta_data->is_commit(), "mesh MetaData has been committed.");
      srvec.push_back( tmp );
    }
  }
}
Beispiel #7
0
void compute_memory_usage(const BulkData& bulk, MemoryUsage& mem_usage)
{
  mem_usage.entity_rank_names = bulk.mesh_meta_data().entity_rank_names();

  const FieldVector& fields = bulk.mesh_meta_data().get_fields();
  mem_usage.num_fields = fields.size();
  mem_usage.field_bytes = fields.size()*sizeof(FieldBase);
  for(size_t i=0; i<fields.size(); ++i) {
    mem_usage.field_bytes += fields[i]->name().length();
    mem_usage.field_bytes += sizeof(FieldRestriction)*fields[i]->restrictions().size();
  }

  const PartVector& parts = bulk.mesh_meta_data().get_parts();
  mem_usage.num_parts = parts.size();
  mem_usage.part_bytes = parts.size()*sizeof(Part);
  for(size_t i=0; i<parts.size(); ++i) {
    mem_usage.part_bytes += parts[i]->name().length();
    mem_usage.part_bytes += sizeof(Part*)        * parts[i]->supersets().size();
    mem_usage.part_bytes += sizeof(Part*)        * parts[i]->subsets().size();
  }

  size_t total_bytes = mem_usage.field_bytes + mem_usage.part_bytes;

  mem_usage.entity_counts.clear();
  mem_usage.downward_relation_counts.clear();
  mem_usage.upward_relation_counts.clear();
  mem_usage.bucket_counts.clear();
  mem_usage.bucket_bytes.clear();

  Selector all = bulk.mesh_meta_data().universal_part();
  count_entities(all, bulk, mem_usage.entity_counts);

  size_t nranks = mem_usage.entity_counts.size();
  mem_usage.downward_relation_counts.resize(nranks, 0);
  mem_usage.upward_relation_counts.resize(nranks, 0);
  mem_usage.bucket_counts.resize(nranks, 0);
  mem_usage.bucket_bytes.resize(nranks, 0);

  std::vector<Entity> entities;
  for(size_t i=0; i<nranks; ++i) {
    EntityRank rank_i = static_cast<EntityRank>(i);
    total_bytes += mem_usage.entity_counts[rank_i]*sizeof(Entity);

    get_entities(bulk, rank_i, entities);

    for(size_t n=0; n<entities.size(); ++n) {
      Entity entity = entities[n];
      for(EntityRank r=stk::topology::NODE_RANK; r<rank_i; ++r) {
        unsigned num_rels = bulk.num_connectivity(entity, r);
        mem_usage.downward_relation_counts[r] += num_rels;
        ThrowErrorMsg("stk::mesh::compute_memory_usage need to be largely re-written for the new Connectivity scheme but is not needed for this 4.27.7.");
      }
      for(EntityRank r=static_cast<EntityRank>(rank_i+1); r<nranks; ++r) {
        unsigned num_rels = bulk.num_connectivity(entity, r);
        mem_usage.upward_relation_counts[r] += num_rels;
        ThrowErrorMsg("stk::mesh::compute_memory_usage need to be largely re-written for the new Connectivity scheme but is not needed for this 4.27.7.");
      }
    }

    const BucketVector& buckets = bulk.buckets(rank_i);
    mem_usage.bucket_counts[rank_i] = buckets.size();
    for(size_t b=0; b<buckets.size(); ++b) {
      Bucket& bucket = *buckets[b];
      mem_usage.bucket_bytes[rank_i] += bucket.allocation_size();
      total_bytes += bucket.allocation_size();
    }
  }

  mem_usage.total_bytes = total_bytes;
}
STKUNIT_UNIT_TEST(UnitTestingOfThrowMacros, testUnit)
{
  // Setting assert handler to NULL should cause exception
  STKUNIT_ASSERT_THROW(stk::set_assert_handler(0), std::runtime_error);

  // Check that Throw*Msg works
  STKUNIT_ASSERT_THROW(force_throw_require_trigger(), std::logic_error);
  STKUNIT_ASSERT_THROW(force_throw_error_trigger(), std::runtime_error);
  STKUNIT_ASSERT_THROW(force_throw_invarg_trigger(), std::invalid_argument);

  // Check that Throw* works
  STKUNIT_ASSERT_THROW(force_throw_require_trigger(false), std::logic_error);
  STKUNIT_ASSERT_THROW(force_throw_error_trigger(false), std::runtime_error);
  STKUNIT_ASSERT_THROW(force_throw_invarg_trigger(false), std::invalid_argument);

  // Check that macro interacts appropriately with if statements
  STKUNIT_ASSERT_THROW(check_interaction_with_if(), std::logic_error);
  STKUNIT_ASSERT_THROW(check_interaction_with_if(false), std::logic_error);

  // Check that usage of ThrowRequireMsg/ThrowAssertMsg does not change program
  // semantics. Code blocks that are not contained within braces seem to be
  // the most likely to be problematic.

  bool expected_execution_path = false;
  if (false)
    ThrowRequireMsg(false, "test");
  else
    expected_execution_path = true;
  STKUNIT_ASSERT(expected_execution_path);

  expected_execution_path = false;
  if (false)
    ThrowAssertMsg(false, "test");
  else
    expected_execution_path = true;
  STKUNIT_ASSERT(expected_execution_path);

  expected_execution_path = false;
  if (false)
    ThrowErrorMsg("test");
  else
    expected_execution_path = true;
  STKUNIT_ASSERT(expected_execution_path);

  // These next four statements are to check compilation success

  if (false)
    ThrowRequireMsg(false, "test");

  if (false)
    ThrowAssertMsg(false, "test");

  if (false)
    ThrowRequire(false);

  if (false)
    ThrowAssert(false);

  // Check that do-while still works, again, we are mostly checking compilation
  // success here.

  do ThrowRequireMsg(true, "test");
  while (false);

  do ThrowAssertMsg(true, "test");
  while (false);

  // Check that message with put-tos compiles

  int temp = 0;
  ThrowRequireMsg(true, "test: " << temp << " blah");
  ThrowAssertMsg(true, "test: " << temp << " blah");

  // Check that assert behaves as expected (throws in debug, not in opt)
#ifdef NDEBUG
  force_throw_assert();
#else
  STKUNIT_ASSERT_THROW(force_throw_assert(), std::logic_error);
#endif

  // Check that ThrowErrorMsg works

  STKUNIT_ASSERT_THROW(test_no_expr_error(), std::runtime_error);
  
  // Check that setting handler for asserts works.

  stk::ErrorHandler orig = stk::set_assert_handler(test_assert_handler);

  ThrowRequireMsg(false, "test");

  STKUNIT_ASSERT(test_assert_handler_called);

  stk::set_assert_handler(orig);

  STKUNIT_ASSERT_THROW(force_throw_require_trigger(), std::logic_error);

  // Check that setting handler for errors works.

  orig = stk::set_error_handler(test_error_handler);

  ThrowErrorMsgIf(true, "test");

  STKUNIT_ASSERT(test_error_handler_called);

  stk::set_error_handler(orig);

  STKUNIT_ASSERT_THROW(force_throw_error_trigger(), std::runtime_error);

  // Check that setting handler for invalid args works.

  orig = stk::set_invalid_arg_handler(test_invarg_handler);

  ThrowInvalidArgMsgIf(true, "test");

  STKUNIT_ASSERT(test_invarg_handler_called);

  stk::set_invalid_arg_handler(orig);

  STKUNIT_ASSERT_THROW(force_throw_invarg_trigger(), std::invalid_argument);
}