Giter Site home page Giter Site logo

Implement own bilinear form about mfem HOT 6 CLOSED

AIBSCT80 avatar AIBSCT80 commented on June 19, 2024
Implement own bilinear form

from mfem.

Comments (6)

atallah727 avatar atallah727 commented on June 19, 2024

Hello @YHDAUT, you can check the shifted miniapp as an example. There we define our own integrators over the boundary. But the main idea is to create a class that inherits from BilinearFormIntegrator (or LinearFormIntegrator ) and then you would overload the assemble function. For integrals on the domain, as in your case, you would need to overload the AssembleElementMatrix function.

from mfem.

AIBSCT80 avatar AIBSCT80 commented on June 19, 2024

Hello @atallah727 . Many thanks. May I ask where I can see this shifted miniapp example. Are there any example defining own integrators over the domain? Your comments help me a lot. Thanks..

from mfem.

atallah727 avatar atallah727 commented on June 19, 2024

You can find the shifted miniapp in the miniapps directory. For more details on writing domain integrators you can refer to this documentation page: https://mfem.org/integration/. Look for the section titled: Writing Custom Integrators .

from mfem.

AIBSCT80 avatar AIBSCT80 commented on June 19, 2024

Hi @atallah727 . Many thanks for your comments. This is really a great help to me. :)

from mfem.

atallah727 avatar atallah727 commented on June 19, 2024

Great. I will go ahead and close this issue. But please feel free to reopen it.

from mfem.

AIBSCT80 avatar AIBSCT80 commented on June 19, 2024

Hi @atallah727 it seems to me not trivial to implement the mixed bilinear form :

\partial_x u \partial_x v + \partial_y u \partial_y v - \partial_z u \partial_z v

I am trying to make this new bilinear form from the standard
diffusion integrator in MFEM.

However, is there any way/example to show how to
select derivative in each direction x, y, z

\partial_x u \partial_x v
\partial_y u \partial_y v
\partial_z u \partial_z v

Then perform summation or subtraction of these terms.

Thanks

void MyDiffusionIntegrator::AssembleElementMatrix2(
const FiniteElement &trial_fe, const FiniteElement &test_fe,
ElementTransformation &Trans, DenseMatrix &elmat)
{
int tr_nd = trial_fe.GetDof();
int te_nd = test_fe.GetDof();
dim = trial_fe.GetDim();
int spaceDim = Trans.GetSpaceDim();
bool square = (dim == spaceDim);
double w;

if (VQ)
{
MFEM_VERIFY(VQ->GetVDim() == spaceDim,
"Unexpected dimension for VectorCoefficient");
}
if (MQ)
{
MFEM_VERIFY(MQ->GetWidth() == spaceDim,
"Unexpected width for MatrixCoefficient");
MFEM_VERIFY(MQ->GetHeight() == spaceDim,
"Unexpected height for MatrixCoefficient");
}

#ifdef MFEM_THREAD_SAFE
DenseMatrix dshape(tr_nd, dim), dshapedxt(tr_nd, spaceDim);
DenseMatrix te_dshape(te_nd, dim), te_dshapedxt(te_nd, spaceDim);
DenseMatrix invdfdx(dim, spaceDim);
DenseMatrix dshapedxt_m(te_nd, MQ ? spaceDim : 0);
DenseMatrix M(MQ ? spaceDim : 0);
Vector D(VQ ? VQ->GetVDim() : 0);
#else
dshape.SetSize(tr_nd, dim);
dshapedxt.SetSize(tr_nd, spaceDim);
te_dshape.SetSize(te_nd, dim);
te_dshapedxt.SetSize(te_nd, spaceDim);
invdfdx.SetSize(dim, spaceDim);
dshapedxt_m.SetSize(te_nd, MQ ? spaceDim : 0);
M.SetSize(MQ ? spaceDim : 0);
D.SetSize(VQ ? VQ->GetVDim() : 0);
#endif
elmat.SetSize(te_nd, tr_nd);

const IntegrationRule *ir = IntRule ? IntRule : &GetRule(trial_fe, test_fe);

elmat = 0.0;
for (int i = 0; i < ir->GetNPoints(); i++)
{
const IntegrationPoint &ip = ir->IntPoint(i);
trial_fe.CalcDShape(ip, dshape);
test_fe.CalcDShape(ip, te_dshape);

  Trans.SetIntPoint(&ip);
  CalcAdjugate(Trans.Jacobian(), invdfdx);
  w = Trans.Weight();
  w = ip.weight / (square ? w : w*w*w);
  Mult(dshape, invdfdx, dshapedxt);
  Mult(te_dshape, invdfdx, te_dshapedxt);
  // invdfdx, dshape, and te_dshape no longer needed
  if (MQ)
  {
     MQ->Eval(M, Trans, ip);
     M *= w;
     Mult(te_dshapedxt, M, dshapedxt_m);
     AddMultABt(dshapedxt_m, dshapedxt, elmat);
  }
  else if (VQ)
  {
     VQ->Eval(D, Trans, ip);
     D *= w;
     AddMultADAt(dshapedxt, D, elmat);
  }
  else
  {
     if (Q)
     {
        w *= Q->Eval(Trans, ip);
     }
     dshapedxt *= w;
     AddMultABt(te_dshapedxt, dshapedxt, elmat);
  }

}
}

from mfem.

Related Issues (20)

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.