Giter Site home page Giter Site logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 2, 2024

One way to compute fields derived from a solution is to define a special
sub-class of the Coefficient class and then project it on a given GridFunction.
Here is an example:

class MyCoefficient : public Coefficient
{
private:
   GridFunction &u;
   Coefficient &lambda, μ
   DenseMatrix eps, sigma;

public:
   MyCoefficient(GridFunction &_u, Coefficient &_lambda, Coefficient &_mu)
      : u(_u), lambda(_lambda), mu(_mu) { }
   virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
   {
      u.GetVectorGradient(T, eps);  // eps = grad(u)
      eps.Symmetrize();             // eps = (1/2)*(grad(u) + grad(u)^t)
      double l = lambda.Eval(T, ip);
      double m = mu.Eval(T, ip);
      sigma.Diag(l*eps.Trace(), eps.Size()); // sigma = lambda*trace(eps)*I
      sigma.Add(2*m, eps);          // sigma += 2*mu*eps

      return sigma(0,0); // return sigma_xx
   }
   virtual void Read(istream &in) { }
   virtual ~MyCoefficient() { }
};

Then inside the main function in ex2.cpp we can project this coefficient to a
GridFunction and save it to a file:

   {
      // A. Define a finite element space for post-processing the solution. We
      //    use a discontinuous space of the same order as the solution.
      L2_FECollection pp_fec(p, dim);
      FiniteElementSpace pp_fespace(mesh, &pp_fec);
      GridFunction pp_field(&pp_fespace);

      // B. Project the post-processing coefficient defined above to the
      //    'pp_field' GridFunction.
      MyCoefficient pp_coeff(x, lambda_func, mu_func);
      pp_field.ProjectCoefficient(pp_coeff);

      // C. Save the 'pp_field'.
      ofstream pp_ofs("postproc.gf");
      pp_ofs.precision(8);
      pp_field.Save(pp_ofs);
   }


Element-wise strain energies can be computed using a similar approach: in this
case the coefficient can be used to define a LinearForm (on a piece-wise
constant FE space) with one DomainLFIntegrator using a strain energy density
coefficient. After assembling, the LinearForm will give you the element-wise
energies.


Regarding a point load, one way to achieve this is by using a sub-class of
VectorCoefficient, something like this:

class PointLoadCoefficient : public VectorCoefficient
{
private:
   Vector center, force, point;

public:
   PointLoadCoefficient(const Vector &_center, const Vector &_force)
      : VectorCoefficient(_center.Size()), center(_center), force(_force) { }
   virtual void Eval(Vector &V, ElementTransformation &T,
                     const IntegrationPoint &ip)
   {
      T.Transform(ip, point);
      V.SetSize(vdim);
      if (point.DistanceTo(center) < 1e-12)
         V = force;
      else
         V = 0.0; // set all components to zero
   }
   virtual ~PointLoadCoefficient() { }
};

Projecting this coefficient on a GridFunction (defined on 'fespace' in ex2.cpp)
and adding it to the load vector should do the job.

Original comment by [email protected] on 22 Mar 2014 at 8:58

from mfem.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 2, 2024
Thank you!

Original comment by [email protected] on 23 Apr 2014 at 10:09

from mfem.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 2, 2024

Original comment by tzanio on 8 Dec 2014 at 10:00

  • Changed state: Fixed

from mfem.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.