Ejemplo n.º 1
0
 int compare_string(Left const &l,Char const *begin)
 {
     Char const *end = begin;
     while(*end!=0)
         end++;
     return compare_text(l.begin(),l.end(),begin,end);
 }
Ejemplo n.º 2
0
inline void assign(Left& old, Right&& value, bool& changes){
    if(old.top()){
        changes = !value.top();
    } else if(old.values().size() != value.values().size()){
        changes = true;
    }

    old = value;
}
Ejemplo n.º 3
0
 void operator ()(Left &left, Right &right) const
 {
     BOOST_ASSERT(left.size() == right.size());
     for(std::size_t i = 0, size = left.size(); i != size; ++i)
     {
         if(numeric::greater(right[i], left[i]))
         {
             left[i] = right[i];
         }
     }
 }
	void simple_inheritance_dynamic_down_cast() {
		Mock<A, Left, TopLeft> aMock;
		Fake(Method(aMock,l));
		A& a = aMock.get();
		Left* left = &a;
		TopLeft* topLeft = &a;

		A* aPtr = dynamic_cast<A*>(left);
 		ASSERT_EQUAL(0, aPtr->l());

 		aPtr = dynamic_cast<A*>(topLeft);
  		ASSERT_EQUAL(0, aPtr->l());
 
  		left = dynamic_cast<Left*>(topLeft);
  		ASSERT_EQUAL(0, left->l());
	}
 result_type
 operator ()(Left & left, Right & right) const
 {
     std::size_t left_size = left.size();
     std::size_t right_size = right.size();
     result_type result(left_size, right_size);
     for (std::size_t i = 0; i < left_size; ++i)
         for (std::size_t j = 0; j < right_size; ++j)
             result(i,j) = numeric::multiplies(left[i], right[j]);
     return result;
 }
Ejemplo n.º 6
0
    bool parse_sequence(
        Left const& left, Right const& right
      , Iterator& first, Iterator const& last
      , Context const& context, Attribute& attr, traits::plain_attribute)
    {
        typedef typename traits::attribute_of<Left>::type l_attr_type;
        typedef typename traits::attribute_of<Right>::type r_attr_type;
        typedef traits::make_attribute<l_attr_type, Attribute> l_make_attribute;
        typedef traits::make_attribute<r_attr_type, Attribute> r_make_attribute;

        typename l_make_attribute::type l_attr = l_make_attribute::call(attr);
        typename r_make_attribute::type r_attr = r_make_attribute::call(attr);

        Iterator save = first;
        if (left.parse(first, last, context, l_attr)
            && right.parse(first, last, context, r_attr))
            return true;
        first = save;
        return false;
    }
Ejemplo n.º 7
0
    bool parse_sequence(
        Left const& left, Right const& right
      , Iterator& first, Iterator const& last
      , Context const& context, Attribute& attr, traits::tuple_attribute)
    {
        typedef detail::partition_attribute<Left, Right, Attribute> partition;
        typedef typename partition::l_pass l_pass;
        typedef typename partition::r_pass r_pass;

        typename partition::l_part l_part = partition::left(attr);
        typename partition::r_part r_part = partition::right(attr);
        typename l_pass::type l_attr = l_pass::call(l_part);
        typename r_pass::type r_attr = r_pass::call(r_part);

        Iterator save = first;
        if (left.parse(first, last, context, l_attr)
            && right.parse(first, last, context, r_attr))
            return true;
        first = save;
        return false;
    }
Ejemplo n.º 8
0
 int compare_text(Left const &l,Right const &r)
 {
     return compare_text(l.begin(),l.end(),r.begin(),r.end());
 }
Ejemplo n.º 9
0
int main()
{
  // Dirichlet boundary condition for clamp at left end
  class Clamp : public Expression
  {
  public:

    Clamp() : Expression(3) {}

    void eval(Array<double>& values, const Array<double>& x) const
    {
      values[0] = 0.0;
      values[1] = 0.0;
      values[2] = 0.0;
    }

  };

  // Sub domain for clamp at left end
  class Left : public SubDomain
  {
    bool inside(const Array<double>& x, bool on_boundary) const
    {
      return x[0] < 0.5 && on_boundary;
    }
  };

  // Dirichlet boundary condition for rotation at right end
  class Rotation : public Expression
  {
  public:

    Rotation() : Expression(3) {}

    void eval(Array<double>& values, const Array<double>& x) const
    {
      // Center of rotation
      const double y0 = 0.5;
      const double z0 = 0.219;

      // Angle of rotation (30 degrees)
      const double theta = 0.5236;

      // New coordinates
      const double y = y0 + (x[1] - y0)*cos(theta) - (x[2] - z0)*sin(theta);
      const double z = z0 + (x[1] - y0)*sin(theta) + (x[2] - z0)*cos(theta);

      // Clamp at right end
      values[0] = 0.0;
      values[1] = y - x[1];
      values[2] = z - x[2];
    }

  };

  // Sub domain for rotation at right end
  class Right : public SubDomain
  {
    bool inside(const Array<double>& x, bool on_boundary) const
    {
      return x[0] > 0.9 && on_boundary;
    }
  };

  // Read mesh and create function space
  Mesh mesh("gear.xml.gz");
  Elasticity::Form_a::TestSpace V(mesh);

  // Create right-hand side
  Constant f(0.0, 0.0, 0.0);

  // Set up boundary condition at left end
  Clamp c;
  Left left;
  DirichletBC bcl(V, c, left);

  // Set up boundary condition at right end
  Rotation r;
  Right right;
  DirichletBC bcr(V, r, right);

  // Collect boundary conditions
  std::vector<const BoundaryCondition*> bcs;
  bcs.push_back(&bcl);
  bcs.push_back(&bcr);

  std::vector<const DirichletBC*> _bcs;
  _bcs.push_back(&bcl);
  _bcs.push_back(&bcr);

  // Set elasticity parameters
  double E  = 10.0;
  double nu = 0.3;
  Constant mu(E / (2*(1 + nu)));
  Constant lambda(E*nu / ((1 + nu)*(1 - 2*nu)));

  // Define variational problem
  Elasticity::Form_a a(V, V);
  a.mu = mu; a.lmbda = lambda;
  Elasticity::Form_L L(V);
  L.f = f;
  Function u(V);
  LinearVariationalProblem problem(a, L, u, bcs);

  // Compute solution
  LinearVariationalSolver solver(problem);
  solver.parameters["symmetric"] = true;
  solver.parameters["linear_solver"] = "direct";
  solver.solve();

  // Extract solution components (deep copy)
  Function ux = u[0];
  Function uy = u[1];
  Function uz = u[2];
  std::cout << "Norm (u): " << u.vector()->norm("l2") << std::endl;
  std::cout << "Norm (ux, uy, uz): " << ux.vector()->norm("l2") << "  "
            << uy.vector()->norm("l2") << "  "
            << uz.vector()->norm("l2") << std::endl;

  // Save solution in VTK format
  File vtk_file("elasticity.pvd", "compressed");
  vtk_file << u;

  // Extract stress and write in VTK format
  Elasticity::Form_a_s::TestSpace W(mesh);
  Elasticity::Form_a_s a_s(W, W);
  Elasticity::Form_L_s L_s(W);
  L_s.mu = mu;
  L_s.lmbda = lambda;
  L_s.disp = u;

  Function stress(W);
  LocalSolver local_solver;
  local_solver.solve(*stress.vector(), a_s, L_s);

  File file_stress("stress.pvd");
  file_stress << stress;

  // Save colored mesh paritions in VTK format if running in parallel
  if (dolfin::MPI::num_processes() > 1)
  {
    CellFunction<std::size_t> partitions(mesh, dolfin::MPI::process_number());
    File file("partitions.pvd");
    file << partitions;
  }

  // Write boundary condition facets markers to VTK format
  MeshFunction<std::size_t> facet_markers(mesh, 2, 0);
  left.mark(facet_markers, 1);
  right.mark(facet_markers, 2);
  File facet_file("facet_markers.pvd");
  facet_file << facet_markers;

  // Plot solution
  plot(u, "Displacement", "displacement");

  // Displace mesh and plot displaced mesh
  mesh.move(u);
  plot(mesh, "Deformed mesh");

  // Make plot windows interactive
  interactive();

 return 0;
}