コード例 #1
0
ファイル: neighbor.cpp プロジェクト: tqleow2/hermes
    bool NeighborSearch<Scalar>::is_inter_edge(const int& edge, const Hermes::vector<unsigned int>& transformations)
    {
      _F_;
      // No subelements => of course this edge is an inter-element one.
      if(transformations.size() == 0)
        return true;

      // Triangles.
      for(unsigned int i = 0; i < transformations.size(); i++)
        if(central_el->get_mode() == HERMES_MODE_TRIANGLE)
        {
          if ((edge == 0 && (transformations[i] == 2 || transformations[i] == 3)) ||
            (edge == 1 && (transformations[i] == 0 || transformations[i] == 3)) ||
            (edge == 2 && (transformations[i] == 1 || transformations[i] == 3)))
            return false;
        }
        // Quads.
        else
        {
          if ((edge == 0 && (transformations[i] == 2 || transformations[i] == 3 || transformations[i] == 5)) ||
            (edge == 1 && (transformations[i] == 0 || transformations[i] == 3 || transformations[i] == 6)) ||
            (edge == 2 && (transformations[i] == 0 || transformations[i] == 1 || transformations[i] == 4)) ||
            (edge == 3 && (transformations[i] == 1 || transformations[i] == 2 || transformations[i] == 7)))
            return false;
        }
        return true;
    }
コード例 #2
0
ファイル: ogprojection.cpp プロジェクト: Amuthan/hermes-dev
    void OGProjection<Scalar>::project_internal(Hermes::vector<Space<Scalar>*> spaces, WeakForm<Scalar>* wf,
      Scalar* target_vec, Hermes::MatrixSolverType matrix_solver_type)
    {
      _F_;
      // Instantiate a class with global functions.
      Global<Scalar> hermes2d;

      unsigned int n = spaces.size();

      // sanity checks
      if (n <= 0 || n > 10) error("Wrong number of projected functions in project_internal().");
      for (unsigned int i = 0; i < n; i++) if(spaces[i] == NULL) error("this->spaces[%d] == NULL in project_internal().", i);
      if (spaces.size() != n) error("Number of spaces must match number of projected functions in project_internal().");

      // this is needed since spaces may have their DOFs enumerated only locally.
      int ndof = Space<Scalar>::assign_dofs(spaces);

      // Initialize DiscreteProblem.
      DiscreteProblem<Scalar> dp(wf, spaces);

      // Initial coefficient vector for the Newton's method.  
      Scalar* coeff_vec = new Scalar[ndof];
      memset(coeff_vec, 0, ndof*sizeof(Scalar));

      // Perform Newton's iteration.
      NewtonSolver<Scalar> newton(&dp, matrix_solver_type);
      if (!newton.solve(coeff_vec)) 
        error("Newton's iteration failed.");

      delete [] coeff_vec;

      if (target_vec != NULL)
        for (int i = 0; i < ndof; i++) 
          target_vec[i] = newton.get_sln_vector()[i];
    }
コード例 #3
0
ファイル: ogprojection.cpp プロジェクト: Amuthan/hermes-dev
    void OGProjection<Scalar>::project_global(Hermes::vector<Space<Scalar>*> spaces,
      Hermes::vector<MatrixFormVol<Scalar> *> mfvol,
      Hermes::vector<VectorFormVol<Scalar> *> vfvol,
      Hermes::vector<MeshFunction<Scalar>*> source_meshfns,
      Scalar* target_vec, Hermes::MatrixSolverType matrix_solver_type)
    {
      _F_;
      unsigned int n = spaces.size();
      unsigned int n_biforms = mfvol.size();
      if (n_biforms == 0)
        error("Please use the simpler version of project_global with the argument Hermes::vector<ProjNormType> proj_norms if you do not provide your own projection norm.");
      if (n_biforms != vfvol.size())
        error("Mismatched numbers of projection forms in project_global().");
      if (n != n_biforms)
        error("Mismatched numbers of projected functions and projection forms in project_global().");

      // This is needed since spaces may have their DOFs enumerated only locally
      // when they come here.
      int ndof = Space<Scalar>::assign_dofs(spaces);

      // Define projection weak form.
      WeakForm<Scalar>* proj_wf = new WeakForm<Scalar>(n);
      for (unsigned int i = 0; i < n; i++) 
      {
        proj_wf->add_matrix_form(mfvol[i]);
        // FIXME
        // proj_wf->add_vector_form(i, proj_liforms[i].first, proj_liforms[i].second, HERMES_ANY, source_meshfns[i]);
      }

      project_internal(spaces, proj_wf, target_vec, matrix_solver_type);
    }
コード例 #4
0
    Hermes::vector<Space<Scalar>*> CalculationContinuity<Scalar>::Record::load_spaces(Hermes::vector<Mesh*> meshes, Hermes::vector<Shapeset*> shapesets)
    {
			Hermes::vector<Space<Scalar>*> spaces;

      if(shapesets == Hermes::vector<Shapeset*>())
        for(unsigned int i = 0; i < meshes.size(); i++)
          shapesets.push_back(NULL);

      for(unsigned int i = 0; i < meshes.size(); i++)
      {
        std::stringstream filename;
        filename << CalculationContinuity<Scalar>::space_file_name << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";

        try
        {
          spaces.push_back(Space<Scalar>::load(filename.str().c_str(), meshes[i], false, NULL, shapesets[i]));
        }
        catch(Hermes::Exceptions::SpaceLoadFailureException& e)
        {
          throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
        }
        catch(std::exception& e)
        {
          throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
        }
      }
    }
コード例 #5
0
    void Continuity<Scalar>::Record::load_spaces(Hermes::vector<Space<Scalar>*> spaces, Hermes::vector<SpaceType> space_types, Hermes::vector<Mesh*> meshes, Hermes::vector<Shapeset*> shapesets)
    {
      if(shapesets == Hermes::vector<Shapeset*>())
        for(unsigned int i = 0; i < spaces.size(); i++)
          shapesets.push_back(NULL);

      for(unsigned int i = 0; i < spaces.size(); i++)
      {
        std::stringstream filename;
        filename << Continuity<Scalar>::spaceFileName << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";

        spaces[i]->free();

        switch(space_types[i])
        {
        case HERMES_H1_SPACE:
          dynamic_cast<H1Space<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
          break;
        case HERMES_HCURL_SPACE:
          dynamic_cast<HcurlSpace<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
          break;
        case HERMES_HDIV_SPACE:
          dynamic_cast<HdivSpace<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
          break;
        case HERMES_L2_SPACE:
          dynamic_cast<L2Space<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
          break;
        }
      }
    }
コード例 #6
0
ファイル: adapt.cpp プロジェクト: panek50/hermes-dev
    Adapt<Scalar>::Adapt(Hermes::vector<Space<Scalar>*> spaces,
      Hermes::vector<ProjNormType> proj_norms) :
    spaces(spaces),
      num_act_elems(-1),
      have_errors(false),
      have_coarse_solutions(false),
      have_reference_solutions(false)
    {
      // sanity check
      if (proj_norms.size() > 0 && spaces.size() != proj_norms.size())
        error("Mismatched numbers of spaces and projection types in Adapt<Scalar>::Adapt().");

      this->num = spaces.size();

      // sanity checks
      error_if(this->num <= 0, "Too few components (%d), only %d supported.", this->num, H2D_MAX_COMPONENTS);
      error_if(this->num > H2D_MAX_COMPONENTS, "Too many components (%d), only %d supported.", this->num, H2D_MAX_COMPONENTS);

      // reset values
      memset(errors, 0, sizeof(errors));
      memset(sln, 0, sizeof(sln));
      memset(rsln, 0, sizeof(rsln));

      // if norms were not set by the user, set them to defaults
      // according to spaces
      if (proj_norms.size() == 0) 
      {
        for (int i = 0; i < this->num; i++) 
        {
          switch (spaces[i]->get_type()) 
          {
          case HERMES_H1_SPACE: proj_norms.push_back(HERMES_H1_NORM); break;
          case HERMES_HCURL_SPACE: proj_norms.push_back(HERMES_HCURL_NORM); break;
          case HERMES_HDIV_SPACE: proj_norms.push_back(HERMES_HDIV_NORM); break;
          case HERMES_L2_SPACE: proj_norms.push_back(HERMES_L2_NORM); break;
          default: error("Unknown space type in Adapt<Scalar>::Adapt().");
          }
        }
      }

      // assign norm weak forms  according to norms selection
      for (int i = 0; i < this->num; i++)
        for (int j = 0; j < this->num; j++)
        {
          error_form[i][j] = NULL;
          norm_form[i][j] = NULL;
        }

      for (int i = 0; i < this->num; i++)
      {
        error_form[i][i] = new MatrixFormVolError(proj_norms[i]);
        norm_form[i][i] = error_form[i][i];
      }
    }
コード例 #7
0
ファイル: basic.cpp プロジェクト: sajedi/hermes
// Set Dirichlet boundary values.
void ModuleBasic::set_dirichlet_values(const std::vector<int> &bdy_markers_dirichlet,
                                       const std::vector<double> &bdy_values_dirichlet)
{
  Hermes::vector<int> tm;
  for (unsigned int i = 0; i < bdy_markers_dirichlet.size(); i++) {
    tm.push_back(bdy_markers_dirichlet[i]);
  }
  Hermes::vector<double> tv;
  for (unsigned int i = 0; i < bdy_values_dirichlet.size(); i++) {
    tv.push_back(bdy_values_dirichlet[i]);
  }
  if (tm.size() != tv.size()) error("Mismatched numbers of Dirichlet boundary markers and values.");
  for (unsigned int i = 0; i < tm.size(); i++) this->bc_values.add_const(tm[i], tv[i]);
}
コード例 #8
0
 void Continuity<Scalar>::Record::load_solutions(Hermes::vector<Solution<Scalar>*> solutions, Hermes::vector<Space<Scalar>*> spaces)
 {
   if(solutions.size() != spaces.size())
     throw Exceptions::LengthException(1, 2, solutions.size(), spaces.size());
   for(unsigned int i = 0; i < solutions.size(); i++)
   {
     std::stringstream filename;
     filename << Continuity<Scalar>::solutionFileName << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
     solutions[i]->load(filename.str().c_str(), spaces[i]->get_mesh());
     solutions[i]->space = spaces[i];
     solutions[i]->space_type = spaces[i]->get_type();
     solutions[i]->space_seq = spaces[i]->get_seq();
   }
 }
コード例 #9
0
ファイル: neighbor.cpp プロジェクト: tqleow2/hermes
    void NeighborSearch<Scalar>::clear_initial_sub_idx()
    {
      _F_;
      if(neighborhood_type != H2D_DG_GO_DOWN)
        return;
      // Obtain the transformations sequence.
      Hermes::vector<unsigned int> transformations = get_transforms(original_central_el_transform);
      // Test for active element.
      if(transformations.empty())
        return;

      for(unsigned int i = 0; i < n_neighbors; i++)
      {
        // Find the index where the additional subelement mapping (on top of the initial one from assembling) starts.
        unsigned int j = 0;
        // Note that we do not have to test if central_transformations is empty or how long it is, because it has to be
        // longer than transformations (and that is tested).
        // Also the function compatible_transformations() does not have to be used, as now the array central_transformations
        // has been adjusted so that it contains the array transformations.
        while(central_transformations.get(i)->transf[j] == transformations[j])
          if(++j > transformations.size() - 1)
            break;
        central_transformations.get(i)->strip_initial_transformations(j);
      }
    }
コード例 #10
0
    void DiscreteProblemIntegrationOrderCalculator<Scalar>::deinit_ext_orders(Hermes::vector<MeshFunctionSharedPtr<Scalar> >& ext, Hermes::vector<UExtFunctionSharedPtr<Scalar> >& u_ext_fns, Func<Hermes::Ord>** ext_func)
    {
      if (ext_func)
      {
        for (int ext_i = 0; ext_i < u_ext_fns.size(); ext_i++)
          delete ext_func[ext_i];

        for (int ext_i = 0; ext_i < ext.size(); ext_i++)
        {
          if (ext[ext_i] && ext[ext_i]->get_active_element())
            delete ext_func[u_ext_fns.size() + ext_i];
        }

        delete[] ext_func;
      }
    }
コード例 #11
0
ファイル: space.cpp プロジェクト: ChanyMetal/hermes
 int Space<Scalar>::get_num_dofs(Hermes::vector<Space<Scalar>*> spaces)
 {
   int ndof = 0;
   for (unsigned int i = 0; i<spaces.size(); i++)
     ndof += spaces[i]->get_num_dofs();
   return ndof;
 }
コード例 #12
0
ファイル: neighbor.cpp プロジェクト: tqleow2/hermes
    void NeighborSearch<Scalar>::update_according_to_sub_idx(const Hermes::vector<unsigned int>& transformations)
    {
      _F_;
      if(neighborhood_type == H2D_DG_NO_TRANSF || neighborhood_type == H2D_DG_GO_UP)
      {
        if (!neighbor_transformations.present(0)) // in case of neighborhood_type == H2D_DG_NO_TRANSF
          neighbor_transformations.add(new Transformations, 0);
        Transformations *tr = neighbor_transformations.get(0);

        for(unsigned int i = 0; i < transformations.size(); i++)
          // Triangles.
          if(central_el->get_mode() == HERMES_MODE_TRIANGLE)
            if ((active_edge == 0 && transformations[i] == 0) ||
              (active_edge == 1 && transformations[i] == 1) ||
              (active_edge == 2 && transformations[i] == 2))
              tr->transf[tr->num_levels++] = (!neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 3);
            else
              tr->transf[tr->num_levels++] = (neighbor_edges[0].orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 3);
        // Quads.
          else
            if ((active_edge == 0 && (transformations[i] == 0 || transformations[i] == 6)) ||
              (active_edge == 1 && (transformations[i] == 1 || transformations[i] == 4)) ||
              (active_edge == 2 && (transformations[i] == 2 || transformations[i] == 7)) ||
              (active_edge == 3 && (transformations[i] == 3 || transformations[i] == 5)))
              tr->transf[tr->num_levels++] = (!neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 4);
            else if ((active_edge == 0 && (transformations[i] == 1 || transformations[i] == 7)) ||
              (active_edge == 1 && (transformations[i] == 2 || transformations[i] == 5)) ||
              (active_edge == 2 && (transformations[i] == 3 || transformations[i] == 6)) ||
              (active_edge == 3 && (transformations[i] == 0 || transformations[i] == 4)))
              tr->transf[tr->num_levels++] = (neighbor_edge.orientation ? neighbor_edge.local_num_of_edge : (neighbor_edge.local_num_of_edge + 1) % 4);
      }
      else handle_sub_idx_way_down(transformations);
    }
コード例 #13
0
ファイル: ogprojection.cpp プロジェクト: Amuthan/hermes-dev
 void OGProjection<Scalar>::project_global(Hermes::vector<Space<Scalar>*> spaces, Hermes::vector<Solution<Scalar>*> source_sols,
   Scalar* target_vec, Hermes::MatrixSolverType matrix_solver_type, Hermes::vector<ProjNormType> proj_norms)
 {
   Hermes::vector<MeshFunction<Scalar>*> mesh_fns;
   for(unsigned int i = 0; i < source_sols.size(); i++)
     mesh_fns.push_back(source_sols[i]);
   project_global(spaces, mesh_fns, target_vec, matrix_solver_type, proj_norms);
 }
コード例 #14
0
ファイル: definitions.cpp プロジェクト: Amuthan/hermes
 void filter_fn(int n, Hermes::vector<scalar*> values, scalar* result)
 {
   for (int i = 0; i < n; i++) {
     result[i] = 0;
     for (unsigned int j = 0; j < values.size(); j++)
       result[i] += nu[j] * Sigma_f[j] * values.at(j)[i];
   }
 } 
コード例 #15
0
ファイル: ogprojection.cpp プロジェクト: julywater/hermes
    void OGProjection<Scalar>::project_global(const Hermes::vector<SpaceSharedPtr<Scalar> >& spaces,
      const Hermes::vector<MatrixFormVol<Scalar>*>& custom_projection_jacobians,
      const Hermes::vector<VectorFormVol<Scalar>*>& custom_projection_residuals,
      const Hermes::vector<MeshFunctionSharedPtr<Scalar> >& target_slns)
    {
      int n = spaces.size();

      // Sanity checks.
      if (n != target_slns.size()) throw Exceptions::LengthException(1, 2, n, target_slns.size());
      if (n != custom_projection_jacobians.size()) throw Exceptions::LengthException(1, 2, n, custom_projection_residuals.size());
      if (n != custom_projection_residuals.size()) throw Exceptions::LengthException(1, 2, n, custom_projection_residuals.size());

      for (int i = 0; i < n; i++) 
      {
        project_global(spaces[i], custom_projection_jacobians[i], custom_projection_residuals[i], target_slns[i]);
      }
    }
コード例 #16
0
ファイル: filter.cpp プロジェクト: ChanyMetal/hermes
 void Filter<Scalar>::init(const Hermes::vector<MeshFunction<Scalar>*>& solutions)
 {
   this->num = solutions.size();
   if(num > 10)
     throw Hermes::Exceptions::Exception("Attempt to create an instance of Filter with more than 10 MeshFunctions.");
   for(int i = 0; i < this->num; i++)
     this->sln[i] = solutions.at(i);
   this->init();
 }
コード例 #17
0
 void Continuity<Scalar>::Record::save_solutions(Hermes::vector<Solution<Scalar>*> solutions)
 {
   for(unsigned int i = 0; i < solutions.size(); i++)
   {
     std::stringstream filename;
     filename << Continuity<Scalar>::solutionFileName << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
     solutions[i]->save(filename.str().c_str());
   }
 }
コード例 #18
0
ファイル: filter.cpp プロジェクト: qsnake/hermes
void Filter::init(Hermes::vector<MeshFunction*> solutions)
{
	this->num = solutions.size();
	if(num > 10)
		error("Attempt to create an instance of Filter with more than 10 MeshFunctions.");
	for(int i = 0; i < this->num; i++)
		this->sln[i] = solutions.at(i);
  this->init();
}
コード例 #19
0
ファイル: filter.cpp プロジェクト: Manguydudebro/hermes
 void Filter<Scalar>::init(Hermes::vector<MeshFunctionSharedPtr<Scalar> > solutions)
 {
   this->num = solutions.size();
   if(num > H2D_MAX_COMPONENTS)
     throw Hermes::Exceptions::Exception("Attempt to create an instance of Filter with more than 10 MeshFunctions.");
   for(int i = 0; i < this->num; i++)
     this->sln[i] = solutions.at(i);
   this->init();
 }
コード例 #20
0
 void Continuity<Scalar>::Record::load_meshes(Hermes::vector<Mesh*> meshes)
 {
   MeshReaderH2DXML reader;
   for(unsigned int i = 0; i < meshes.size(); i++)
   {
     std::stringstream filename;
     filename << Continuity<Scalar>::meshFileName << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";
     reader.load(filename.str().c_str(), meshes[i]);
   }
 }
コード例 #21
0
KrivodonovaDiscontinuityDetector::KrivodonovaDiscontinuityDetector(Hermes::vector<const Space<double>*> spaces, 
  Hermes::vector<Solution<double>*> solutions) : DiscontinuityDetector(spaces, solutions)
{
  // A check that all meshes are the same in the spaces.
  unsigned int mesh0_seq = spaces[0]->get_mesh()->get_seq();
  for(unsigned int i = 0; i < spaces.size(); i++)
    if(spaces[i]->get_mesh()->get_seq() != mesh0_seq)
      error("So far DiscontinuityDetector works only for single mesh.");
  mesh = spaces[0]->get_mesh();
};
コード例 #22
0
ファイル: space.cpp プロジェクト: ChanyMetal/hermes
 void Space<Scalar>::update_essential_bc_values(Hermes::vector<Space<Scalar>*> spaces, double time)
 {
   int n = spaces.size();
   for (int i = 0; i < n; i++)
   {
     if(spaces[i]->get_essential_bcs() != NULL)
       spaces[i]->get_essential_bcs()->set_current_time(time);
     spaces[i]->update_essential_bc_values();
   }
 }
コード例 #23
0
ファイル: euler-util.cpp プロジェクト: mmru/hermes
DiscontinuityDetector::DiscontinuityDetector(Hermes::vector<Space *> spaces, 
                        Hermes::vector<Solution *> solutions) : spaces(spaces), solutions(solutions)
{
  // A check that all meshes are the same in the spaces.
  Mesh* mesh0 = spaces[0]->get_mesh();
  for(unsigned int i = 0; i < spaces.size(); i++)
    if(spaces[i]->get_mesh() != mesh0)
      error("So far DiscontinuityDetector works only for single mesh.");
  mesh = mesh0;
};
コード例 #24
0
ファイル: space.cpp プロジェクト: ChanyMetal/hermes
    int Space<Scalar>::assign_dofs(Hermes::vector<Space<Scalar>*> spaces)
    {
      int n = spaces.size();

      int ndof = 0;
      for (int i = 0; i < n; i++) {
        ndof += spaces[i]->assign_dofs(ndof);
      }

      return ndof;
    }
コード例 #25
0
ファイル: filter.cpp プロジェクト: nbachela/hermes
    SimpleFilter<Scalar>::SimpleFilter(const Hermes::vector<Solution<Scalar>*>& solutions, const Hermes::vector<int>& items)
    {
      this->num = solutions.size();
      if(this->num > 10)
        error("Attempt to create an instance of Filter with more than 10 MeshFunctions.");
      if(items.size() != (unsigned) this->num)
        if(items.size() > 0)
          error("Attempt to create an instance of SimpleFilter with different supplied number of MeshFunctions than the number of types of data used from them.");

      for(int i = 0; i < this->num; i++)
      {
        this->sln[i] = solutions.at(i);
        if(items.size() > 0)
          this->item[i] = items.at(i);
        else
          this->item[i] = H2D_FN_VAL;
      }
      this->init();
      init_components();
    }
コード例 #26
0
void FilterVectorPotential::filter_fn(int n, Hermes::vector<double*> values, double* result, Geom<double> *e)
{
  for (int i = 0; i < n; i++)
  {
    result[i] = 0;
    for(unsigned int j = 0; j < values.size(); j++)
      result[i] += sqr(values[j][i]);

    result[i] = std::sqrt(result[i]) * e->x[i];
  }
}
コード例 #27
0
    void CalculationContinuity<Scalar>::Record::load_spaces(Hermes::vector<Space<Scalar>*> spaces, Hermes::vector<SpaceType> space_types, Hermes::vector<Mesh*> meshes, Hermes::vector<Shapeset*> shapesets)
    {
      if(shapesets == Hermes::vector<Shapeset*>())
        for(unsigned int i = 0; i < spaces.size(); i++)
          shapesets.push_back(NULL);

      for(unsigned int i = 0; i < spaces.size(); i++)
      {
        std::stringstream filename;
        filename << CalculationContinuity<Scalar>::spaceFileName << i << '_' << (std::string)"t = " << this->time << (std::string)"n = " << this->number << (std::string)".h2d";

        spaces[i]->free();

        try
        {
          switch(space_types[i])
          {
          case HERMES_H1_SPACE:
            dynamic_cast<H1Space<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
            break;
          case HERMES_HCURL_SPACE:
            dynamic_cast<HcurlSpace<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
            break;
          case HERMES_HDIV_SPACE:
            dynamic_cast<HdivSpace<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
            break;
          case HERMES_L2_SPACE:
            dynamic_cast<L2Space<Scalar>*>(spaces[i])->load(filename.str().c_str(), meshes[i], shapesets[i]);
            break;
          }
        }
        catch(Hermes::Exceptions::SpaceLoadFailureException& e)
        {
          throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
        }
        catch(std::exception& e)
        {
          throw IOCalculationContinuityException(CalculationContinuityException::spaces, IOCalculationContinuityException::input, filename.str().c_str(), e.what());
        }
      }
    }
コード例 #28
0
ファイル: ogprojection.cpp プロジェクト: julywater/hermes
    void OGProjection<Scalar>::project_global(const Hermes::vector<SpaceSharedPtr<Scalar> >& spaces,
      const Hermes::vector<MatrixFormVol<Scalar>*>& custom_projection_jacobians,
      const Hermes::vector<VectorFormVol<Scalar>*>& custom_projection_residuals,
      Scalar* target_vec)
    {
      int n = spaces.size();

      // Sanity checks.
      if(target_vec == nullptr) throw Exceptions::NullException(3);
      if (n != custom_projection_jacobians.size()) throw Exceptions::LengthException(1, 2, n, custom_projection_residuals.size());
      if (n != custom_projection_residuals.size()) throw Exceptions::LengthException(1, 2, n, custom_projection_residuals.size());

      int start_index = 0;
      for (int i = 0; i < n; i++) 
      {

        project_global(spaces[i], custom_projection_jacobians[i], custom_projection_residuals[i], target_vec + start_index);

        start_index += spaces[i]->get_num_dofs();                       
      }
    }
コード例 #29
0
ファイル: filter.cpp プロジェクト: qsnake/hermes
SimpleFilter::SimpleFilter(void (*filter_fn)(int n, Hermes::vector<scalar*> values, scalar* result),
		Hermes::vector<MeshFunction*> solutions, Hermes::vector<int> items) : filter_fn(filter_fn)
{
	this->num = solutions.size();
	if(num > 10)
		error("Attempt to create an instance of Filter with more than 10 MeshFunctions.");
	if(items.size() != (unsigned) num)
		if(items.size() > 0)
			error("Attempt to create an instance of SimpleFilter with different supplied number of MeshFunctions than the number of types of data used from them.");

	for(int i = 0; i < this->num; i++)
	{
		this->sln[i] = solutions.at(i);
		if(items.size() > 0)
			this->item[i] = items.at(i);
		else
			this->item[i] =	H2D_FN_VAL;
	}
	this->init();
	init_components();
}
コード例 #30
0
    void OGProjectionNOX<Scalar>::project_global(Hermes::vector<SpaceSharedPtr<Scalar> > spaces, Hermes::vector<MeshFunctionSharedPtr<Scalar> > source_slns,
      Scalar* target_vec, Hermes::vector<NormType> proj_norms,
      double newton_tol, int newton_max_iter)
    {
      int n = spaces.size();

      // Sanity checks.
      if(n != source_slns.size()) throw Exceptions::LengthException(1, 2, n, source_slns.size());
      if(target_vec == nullptr) throw Exceptions::NullException(3);
      if(!proj_norms.empty() && n != proj_norms.size()) throw Exceptions::LengthException(1, 5, n, proj_norms.size());

      int start_index = 0;
      for (int i = 0; i < n; i++)
      {
        if(proj_norms.empty())
          project_global(spaces[i], source_slns[i], target_vec + start_index, HERMES_UNSET_NORM, newton_tol, newton_max_iter);
        else
          project_global(spaces[i], source_slns[i], target_vec + start_index, proj_norms[i], newton_tol, newton_max_iter);
        start_index += spaces[i]->get_num_dofs();
      }
    }