Пример #1
0
 /// extraction of data from the wrapped object, returned memory is a copy, not a view
 /// if nullptr is passed (also default parameter), memory is allocated.
 /// @return pointer to the newly allocated data which is of size size_of()*stride()*size()
 virtual const void* pack(void* buf=nullptr) const
 {
   if ( is_null(m_data) ) throw cf3::common::BadPointer(FromHere(),name()+": Data expired.");
   if (buf==nullptr) buf=new T[m_data->num_elements()*m_stride+1];
   if ( buf == nullptr ) throw cf3::common::NotEnoughMemory(FromHere(),name()+": Could not allocate temporary buffer.");
   T* ibuf=(T*)buf;
   for (int i=0; i<(const int)(m_data->num_elements()*m_stride); i++)
     *ibuf++=(*m_data)[i];
   return buf;
 }
Пример #2
0
 /// extraction of sub-data from data wrapped by the objectwrapper, pattern specified by map
 /// if nullptr is passed (also default parameter), memory is allocated.
 /// @param map vector of map
 /// @return pointer to the newly allocated data which is of size size_of()*stride()*map.size()
 virtual const void* pack(std::vector<int>& map, void* buf=nullptr) const
 {
   if ( is_null(m_data) ) throw cf3::common::BadPointer(FromHere(),name()+": Data expired.");
   if (buf==nullptr) buf=new T[map.size()*m_stride+1];
   if ( buf == nullptr ) throw cf3::common::NotEnoughMemory(FromHere(),name()+": Could not allocate temporary buffer.");
   T* ibuf=(T*)buf;
   boost_foreach( int local_idx, map)
     *ibuf++ = (*m_data)[local_idx];
   return buf;
 }
Пример #3
0
CLink& CLink::link_to ( Component::Ptr lnkto )
{
  if ( is_null(lnkto) )
    throw BadValue(FromHere(), "Cannot link to null component");

  if (lnkto->is_link())
    throw SetupError(FromHere(), "Cannot link a CLink to another CLink");

  m_link_component = lnkto;
  return *this;
}
Пример #4
0
void NLink::go_to_target(SignalArgs & )
{
  if ( is_null(m_target) )
    throw ValueNotFound (FromHere(), "Target of this link is not set or not valid");

  QModelIndex index = NTree::global()->index_from_path(m_target->uri());

  if(index.isValid())
    NTree::global()->set_current_index(index);
  else
    throw ValueNotFound (FromHere(), m_target->uri().string() + ": path does not exist");
}
Пример #5
0
RealVector ElementType::plane_jacobian_normal(const RealVector& mapped_coords,
                                              const RealMatrix& nodes,
                                              const CoordRef direction) const
{
  throw Common::NotImplemented(FromHere(),"jacobian not implemented for "+derived_type_name());
  return RealVector(1);
}
Пример #6
0
 inline void operator()(boost::any& to_set, const boost::any& new_value)
 {
   if(new_value.type() == to_set.type())
   {
     to_set = new_value;
   }
   else
   {
     try
     {
       std::vector<Uint> int_vals = boost::any_cast< std::vector<Uint> >(new_value);
       const Uint nb_vals = int_vals.size();
       std::vector<int> result(nb_vals);
       for(Uint i = 0; i != nb_vals; ++i)
       {
         result[i] = static_cast<int>(int_vals[i]);
       }
       to_set = result;
     }
     catch(boost::bad_any_cast& e)
     {
       throw CastingFailed(FromHere(), std::string("Failed to cast object of type ") + new_value.type().name() + " to type std::vector<int>");
     }
   }
 }
Пример #7
0
 inline void operator()(boost::any& to_set, const boost::any& new_value)
 {
   if(new_value.type() == to_set.type())
   {
     to_set = new_value;
   }
   else
   {
     try
     {
       const std::vector< Handle<Component> > generic_value = boost::any_cast< std::vector< Handle<Component> > >(new_value);
       const Uint nb_entries = generic_value.size();
       std::vector< Handle<ComponentT> > new_components(nb_entries);
       for(Uint i = 0; i != nb_entries; ++i)
       {
         new_components[i] = Handle<ComponentT>(generic_value[i]);
       }
       to_set = new_components;
     }
     catch(boost::bad_any_cast& e)
     {
       throw CastingFailed(FromHere(), std::string("Failed to cast object of type ") + new_value.type().name() + " to type " + class_name< std::vector< Handle<ComponentT> > >());
     }
   }
 }
Пример #8
0
TreeView::TreeView(CentralPanel * optionsPanel, QMainWindow * parent,
                   bool contextMenuAllowed)
: QTreeView(parent),
  m_context_menu_allowed(contextMenuAllowed)
{
  if(m_context_menu_allowed && optionsPanel == nullptr)
    throw BadValue(FromHere(), "Options panel is a nullptr pointer");

  // instantiate class attributes
  m_model_filter = new FilteringModel(this);
  m_central_panel = optionsPanel;
  m_signal_manager = new SignalManager(parent);

  m_model_filter->setSourceModel(NTree::global().get());
  m_model_filter->setDynamicSortFilter(true);

  this->setModel(m_model_filter);

  this->set_read_only(false);

  // when right clicking on the Client,
  // a "Context menu event" must be generated
  this->setContextMenuPolicy(Qt::CustomContextMenu);

  this->header()->setResizeMode(QHeaderView::ResizeToContents);
  this->header()->setStretchLastSection(true);

  if(m_context_menu_allowed)
  {
    connect(NTree::global().get(),
            SIGNAL(current_index_changed(QModelIndex, QModelIndex)),
            this,
            SLOT(current_index_changed(QModelIndex, QModelIndex)));
  }
}
Пример #9
0
  Common_API bool from_str<bool> (const std::string& str)
  {
    bool match = false;
    boost::algorithm::is_equal test_equal;

    if ( test_equal(str,"true") ||
         test_equal(str,"True") ||
         test_equal(str,"on")   ||
         test_equal(str,"1")     )
    {
      return true;
    }

    if ( test_equal(str,"false") ||
         test_equal(str,"False") ||
         test_equal(str,"off")   ||
         test_equal(str,"0")      )
    {
      return false;
    }

    if (!match)
      throw ParsingFailed (FromHere(), "Incorrect option conversion to bool of string [" + str + "]" );
    return true;
  }
Пример #10
0
const CF::Mesh::ElementType& Triag2DLagrangeP2B::face_type(const CF::Uint face) const
{
  throw Common::NotImplemented( FromHere(), "Line2DLagrangeP2 does not exist yet" );

  static const Line2DLagrangeP1 facetype;
  return facetype;
}
Пример #11
0
 /// setup of passing by reference
 /// @param std::vector of data
 /// @param stride number of array element grouping
 void setup(boost::multi_array<T,1>& data, const bool needs_update)
 {
   if (boost::is_pod<T>::value==false) throw cf3::common::BadValue(FromHere(),name()+": Data is not POD (plain old datatype).");
   m_data=&data;
   m_stride = 1;
   m_needs_update=needs_update;
 }
Пример #12
0
 /// returning back values into the data wrapped by objectwrapper
 /// @param pointer to the data to be committed back
 virtual void unpack(void* buf) const
 {
   if ( is_null(m_data) ) throw cf3::common::BadPointer(FromHere(),name()+": Data expired.");
   T* ibuf=(T*)buf;
   for (int i=0; i<(const int)(m_data->num_elements()*m_stride); i++)
     (*m_data)[i]=*ibuf++;
 }
Пример #13
0
 /// returning back values into the data wrapped by objectwrapper
 /// @param map vector of map
 /// @param pointer to the data to be committed back
 virtual void unpack(void* buf, std::vector<int>& map) const
 {
   if ( is_null(m_data) ) throw cf3::common::BadPointer(FromHere(),name()+": Data expired.");
   T* ibuf=(T*)buf;
   boost_foreach( int local_idx, map)
     (*m_data)[local_idx] = *ibuf++;
 }
Пример #14
0
  /// Create ElementCache if non-existant, else get the ElementCache and lock it through ElementCacheHandle constructor
  ElementCacheT& cache(const Handle<mesh::Entities const>& entities, const Uint elem)
  {
    typename value_type::iterator it = m_element_caches.find(entities.get());
    if(it != m_element_caches.end())
    {
      m_cache=it->second.get();

      if ( get().idx == elem ) // Nothing to be done
      {
        get().lock();
        return get();
      }

      if (get().locked()) throw common::IllegalCall(FromHere(),"cache "+uri().string()+" is locked to elem "+common::to_str(it->second->idx));

      set_cache(elem);
      return get();
    }
    boost::shared_ptr<ElementCacheT> element_cache ( new ElementCacheT );
    m_cache=element_cache.get();
    m_cache->cache = this->handle<Cache>();
    configure_cache(entities);
    set_cache(elem);
    m_element_caches[entities.get()]=element_cache;
    return get();
  }
Пример #15
0
double DerivativesType5::a2(Data::DataStorage& data_Q, Data::DataStorage& data_W, Data::DataStorage& data_MIX,  Data::DataStorage& dp, CHEM::SpeciesSet& species_set, int ND)
{
	double rho = data_MIX(0);

	double a2_rho = 0.0;

	for (int s= 0; s <= species_set.NS-1; s++)
	{
		a2_rho	+= data_Q(s)*dp(s);
	}

	for (int k = species_set.NS; k <= species_set.NS+ND-1; k++)
	{
		a2_rho += data_Q(k)*dp(k);
	}

	a2_rho	+= (data_Q(species_set.NS+ND) + data_W(species_set.NS+ND)) * dp(species_set.NS+ND);
	a2_rho	+= data_Q(species_set.NS+ND+1) * dp(species_set.NS+ND+1);

	if (a2_rho < 0.0 || a2_rho == std::numeric_limits<double>::infinity() || a2_rho != a2_rho)
	{
		throw Common::ExceptionNegativeValue (FromHere(), "Negative value of a2: Need to check dp_dQ.");
	}

	//Common::ErrorCheckNonNegative<double>(a2_rho, "DerivativesType5: rho_a2 cannot be negative");
	return (a2_rho / rho);
}
Пример #16
0
void CPlotXY::convergence_history( SignalArgs & args )
{
  if( is_not_null(m_data.get()) )
  {
    SignalFrame reply = args.create_reply( uri() );
    SignalFrame& options = reply.map( Protocol::Tags::key_options() );
//    std::vector<Real> data(8000);
    CTable<Real>& table = *m_data.get();
    std::vector<std::string> labels =
        list_of<std::string>("x")("y")("z")("u")("v")("w")("p")("t");

    add_multi_array_in(options.main_map, "Table", m_data->array(), ";", labels);

//    for(Uint row = 0 ; row < 1000 ; ++row)
//    {
//      for(Uint col = 0 ; col < 8 ; ++col)
//        data[ (row * 8) + col ] = table[row][col];
//    }

//    XmlNode node = options.add("Table", data, " ; ");

//    node.set_attribute("dimensions", "8");
  }
  else
    throw SetupError( FromHere(), "Data to plot not setup" );
}
Пример #17
0
  /// Return the wrapped component
  ComponentT& component()
  {
    if(is_null(m_component))
      throw common::SetupError(FromHere(), "ComponentWrapperImpl points to a null component");

    return **m_component;
  }
Пример #18
0
Field& Dictionary::create_field(const std::string &name, math::VariablesDescriptor& variables_descriptor)
{
  CFinfo << "Creating field " << uri()/name << CFendl;
  if (m_dim == 0) throw SetupError(FromHere(), "dimension not configured");
  Handle<Field> field = create_component<Field>(name);
  field->set_dict(*this);
  field->set_descriptor(variables_descriptor);
  if (variables_descriptor.options().option(common::Tags::dimension()).value<Uint>() == 0)
  {
    field->descriptor().options().set(common::Tags::dimension(),m_dim);
  }
  field->set_row_size(field->descriptor().size());
  field->resize(size());

  update_structures();

  CFinfo << "Created field " << field->uri() << " with variables \n";
  for (Uint var=0; var<field->descriptor().nb_vars(); ++var)
  {
    CFinfo << "    - " << field->descriptor().user_variable_name(var) << " [" << field->descriptor().var_length(var) << "]\n";
  }
  CFinfo << CFflush;


  return *field;
}
Пример #19
0
void Solve3x3eqn(std::vector< std::vector<double> >& A, std::vector<double> &b,  std::vector<double> &x)
{
	if (fabs<double>(b[0]) <= MATH_ZERO	&& fabs<double>(b[1]) <= MATH_ZERO && fabs<double>(b[2]) <= MATH_ZERO)
	{
		x.resize(3, 0.0);
	}
	else
	{
		x.resize(3, 0.0);
		double det = A[0][0]*(A[1][1]*A[2][2] - A[1][2]*A[2][1]) - A[0][1]*(A[1][0]*A[2][2] - A[1][2]*A[2][1]) + A[0][2]*(A[1][0]*A[2][1] - A[1][1]*A[2][0]);

		if( fabs<double>(det) < MATH_ZERO) throw Common::ExceptionDimensionMatch (FromHere(), "NO Solution (zero determinent)");

		double a11 = A[1][1]*A[2][2] - A[1][2]*A[2][1];
		double a12 = -(A[1][0]*A[2][2] - A[1][2]*A[2][0]);
		double a13 = A[1][0]*A[2][1] - A[1][1]*A[2][0];

		double a21 =-(A[0][1]*A[2][2] - A[0][2]*A[2][1]);
		double a22 = A[0][0]*A[2][2] - A[0][2]*A[2][0];
		double a23 =-(A[0][0]*A[2][1] - A[0][1]*A[2][0]);

		double a31 = A[2][1]*A[1][2] - A[0][2]*A[1][1];
		double a32 =-(A[0][0]*A[1][2] - A[0][2]*A[1][0]);
		double a33 = A[0][0]*A[1][1] - A[0][1]*A[1][0];

		x[0] =  (a11*b[0] + a12*b[1] + a13*b[2])/det;
		x[1] =  (a21*b[0] + a22*b[1] + a23*b[2])/det;
		x[2] =  (a31*b[0] + a32*b[1] + a33*b[2])/det;
	}
}
Пример #20
0
 Real solve_yplus(FunctorT&& f)
 {
   Real yp_low = 0.;
   Real yp_high = 1000.;
   Uint count = 1;
   Real yplus = 0.;
   while(((yp_high-yp_low) > 1e-4) && count < 1000)
   {
     yplus = (yp_low+yp_high)/2.;
     if (f(yplus) < yplus)
     {
       yp_high = yplus;
     }
     else
     {
       yp_low = yplus;
     }
     count += 1;
   }
   if(count == 1000)
   {
     throw common::FailedToConverge(FromHere(), "y+ computation did not converge");
   }
   return yplus;
 }
Пример #21
0
Uint CField::var_number ( const std::string& vname ) const
{
  const std::vector<std::string>::const_iterator var_loc_it = std::find(m_var_names.begin(), m_var_names.end(), vname);
  if(var_loc_it == m_var_names.end())
    throw Common::ValueNotFound(FromHere(), "Variable " + vname + " was not found in field " + name());
  return var_loc_it - m_var_names.begin();
}
Пример #22
0
    typename LIB::Ptr library ()
    {
      const std::string lname = LIB::library_namespace(); //instead of LIB::type_name();
      Component::Ptr clib = get_child_ptr(lname);

      typename LIB::Ptr lib;
      if ( is_null(clib) ) // doesnt exist so build it
      {
        CF::Common::TypeInfo::instance().regist< LIB >( lname );
        lib = create_component_ptr< LIB >(lname);
        cf_assert( is_not_null(lib) );
        return lib;
      }

      // try to convert existing ptr to LIB::Ptr and return it
      lib = clib->as_ptr<LIB>();

      if( is_null(lib) ) // conversion failed
        throw CastingFailed( FromHere(),
                            "Found component in CLibraries with name "
                            + lname
                            + " but is not the actual library "
                            + LIB::type_name() );
      return lib;
    }
Пример #23
0
  void read_data_block(char *data, const Uint count, const Uint block_idx)
  {
    static const std::string block_prefix("__CFDATA_BEGIN");
    
    XmlNode block_node = get_block_node(block_idx);
      
    const Uint block_begin = from_str<Uint>(block_node.attribute_value("begin"));
    const Uint block_end = from_str<Uint>(block_node.attribute_value("end"));
    const Uint compressed_size = block_end - block_begin - block_prefix.size();

    // Check the prefix
    binary_file.seekg(block_begin);
    std::vector<char> prefix_buf(block_prefix.size());
    binary_file.read(&prefix_buf[0], block_prefix.size());
    const std::string read_prefix(prefix_buf.begin(), prefix_buf.end());
    if(read_prefix != block_prefix)
      throw SetupError(FromHere(), "Bad block prefix for block " + to_str(block_idx));
   
    if(count != 0)
    {
      // Build a decompressing stream
      boost::iostreams::filtering_istream decompressing_stream;
      decompressing_stream.set_auto_close(false);
      decompressing_stream.push(boost::iostreams::zlib_decompressor());
      decompressing_stream.push(boost::iostreams::restrict(binary_file, 0, compressed_size));
      
      // Read the data
      decompressing_stream.read(data, count);
      decompressing_stream.pop();
    }
    
    cf3_assert(binary_file.tellg() == block_end);
  }
Пример #24
0
void BinaryDataReader::read_data_block(char *data, const Uint count, const Uint block_idx)
{
  if(is_null(m_implementation.get()))
    throw SetupError(FromHere(), "No open file for BinaryDataReader at " + uri().path());
  
  m_implementation->read_data_block(data, count, block_idx);
}
Пример #25
0
void VectorialFunction::parse()
{
  clear();

  for(Uint i = 0; i < m_functions.size(); ++i)
  {
    FunctionParser* ptr = new FunctionParser();
    ptr->AddConstant("pi", Consts::pi());
    m_parsers.push_back(ptr);

    // CFinfo << "Parsing Function: \'" << m_functions[i] << "\' Vars: \'" << m_vars << "\'\n" << CFendl;
    ptr->Parse(m_functions[i],m_vars);

    if ( ptr->GetParseErrorType() !=  FunctionParser::FP_NO_ERROR )
    {
      std::string msg("ParseError in VectorialFunction::parse(): ");
      msg += " Error [" +std::string(ptr->ErrorMsg()) + "]";
      msg += " Function [" + m_functions[i] + "]";
      msg += " Vars: ["    + m_vars + "]";
      throw common::ParsingFailed (FromHere(),msg);
    }
  }

  m_result.resize(m_functions.size());
  m_is_parsed = true;
}
Пример #26
0
  static void compute_properties ( const CV& coord,
                                   const SV& sol,
                                   const GM& grad_vars,
                                   MODEL::Properties& p )
  {
    p.coords    = coord;       // cache the coordiantes locally
    p.vars      = sol;         // cache the variables locally
    p.grad_vars = grad_vars;   // cache the gradient of variables locally

    p.rho = sol[Z0]*sol[Z0];
    p.u   = sol[Z1]/sol[Z0];
    p.v   = sol[Z2]/sol[Z0];
    p.w   = sol[Z3]/sol[Z0];
    p.H   = sol[Z4]/sol[Z0];

    p.uuvvww = p.u*p.u + p.v*p.v + p.w*p.w;
    p.P = p.gamma_minus_1/p.gamma * p.rho*(p.H - 0.5*p.uuvvww);

    p.rhou = p.rho * p.u;
    p.rhov = p.rho * p.v;
    p.rhow = p.rho * p.w;
    p.rhoE = p.rho * p.E;


    p.inv_rho = 1. / p.rho;

    if( p.P <= 0. )
    {
          std::cout << "rho    : " << p.rho  << std::endl;
          std::cout << "rhou   : " << p.rhou << std::endl;
          std::cout << "rhov   : " << p.rhov << std::endl;
          std::cout << "rhoE   : " << p.rhoE << std::endl;
          std::cout << "P      : " << p.P    << std::endl;
          std::cout << "u      : " << p.u    << std::endl;
          std::cout << "v      : " << p.v    << std::endl;
          std::cout << "w      : " << p.w    << std::endl;
          std::cout << "uuvvww : " << p.uuvvww << std::endl;


      throw common::FailedToConverge( FromHere(), "Pressure is negative at coordinates ["
                                   + common::to_str(coord[XX]) + ","
                                   + common::to_str(coord[YY]) + ","
                                   + common::to_str(coord[ZZ])
                                   + "]");
    }

    const Real RT = p.P * p.inv_rho;    // RT = p/rho

    p.E = p.rhoE * p.inv_rho;           // E = rhoE / rho

    p.a2 = p.gamma * RT;
    p.a = sqrt( p.a2 );

    p.Ma = sqrt( p.uuvvww / p.a2 );

    p.T = RT / p.R;

    p.half_gm1_v2 = 0.5 * p.gamma_minus_1 * p.uuvvww;
  }
Пример #27
0
  static void compute_properties ( const CV& coord,
                                   const SV& sol,
                                   const GM& grad_vars,
                                   MODEL::Properties& p )
  {
    p.coords    = coord;       // cache the coordiantes locally
    p.vars      = sol;         // cache the variables locally
    p.grad_vars = grad_vars;   // cache the gradient of variables locally

    p.R = 287.058;                 // air
    p.gamma = 1.4;                 // diatomic ideal gas
    p.gamma_minus_1 = p.gamma - 1.;

    p.rho = sol[Z0]*sol[Z0];
    p.u   = sol[Z1]/sol[Z0];
    p.v   = sol[Z2]/sol[Z0];
    p.H   = sol[Z3]/sol[Z0];

    p.uuvv = p.u*p.u + p.v*p.v;
    p.P = p.gamma_minus_1/p.gamma * p.rho*(p.H - 0.5*p.uuvv);

    p.rhou = p.rho * p.u;
    p.rhov = p.rho * p.v;
    p.rhoE = p.rho * p.E;


    p.inv_rho = 1. / p.rho;

    if( p.P <= 0. )
    {
          std::cout << "rho   : " << p.rho  << std::endl;
          std::cout << "rhou  : " << p.rhou << std::endl;
          std::cout << "rhov  : " << p.rhov << std::endl;
          std::cout << "rhoE  : " << p.rhoE << std::endl;
          std::cout << "P     : " << p.P    << std::endl;
          std::cout << "u     : " << p.u    << std::endl;
          std::cout << "v     : " << p.v    << std::endl;
          std::cout << "uuvv  : " << p.uuvv << std::endl;


      throw Common::BadValue( FromHere(), "Pressure is negative at coordinates ["
                                   + Common::to_str(coord[XX]) + ","
                                   + Common::to_str(coord[YY])
                                   + "]");
    }

    const Real RT = p.P * p.inv_rho;    // RT = p/rho

    p.E = p.rhoE * p.inv_rho;           // E = rhoE / rho

    p.a2 = p.gamma * RT;
    p.a = sqrt( p.a2 );

    p.Ma = sqrt( p.uuvv / p.a2 );

    p.T = RT / p.R;

    p.half_gm1_v2 = 0.5 * p.gamma_minus_1 * p.uuvv;
  }
Пример #28
0
solver::CSolver& ActionDirector::solver()
{
  Handle< solver::CSolver > s = m_solver;
  if( is_null(s) )
    throw common::SetupError( FromHere(),
                             "Solver not yet set for component " + uri().string() );
  return *s;
}
Пример #29
0
Mesh& ActionDirector::mesh()
{
  Handle< Mesh > m = m_mesh;
  if( is_null(m) )
    throw common::SetupError( FromHere(),
                             "Mesh not yet set for component " + uri().string() );
  return *m;
}
Пример #30
0
CTime& ActionDirector::time()
{
  Handle< CTime > t = m_time;
  if( is_null(t) )
    throw common::SetupError( FromHere(),
                             "Time not yet set for component " + uri().string() );
  return *t;
}