translate python grad(u).trans code to C++

More
3 years 1 month ago #4017 by Kai
Hi all :),
i try to translate the following piece of python code
Code:
self.u = self.fes.TrialFunction() self.v = self.fes.TestFunction() # StiffnessMatrix depending on material type: if (self.material.type == "linear"): self.A = BilinearForm(self.fes) self.A += 2 * self.material.mu * InnerProduct(1 / 2 * (grad(self.u) + grad(self.u).trans), 1 / 2 * (grad(self.v) + grad(self.v).trans)) * dx

into corresponding C++ code so far i have
Code:
ngcomp::ProxyNode u = fes->GetTrialFunction(); ngcomp::ProxyNode v = fes->GetTestFunction(); Flags flags_bfa; std::shared_ptr<T_BilinearFormSymmetric<double>> bfa = make_shared<T_BilinearFormSymmetric<double>> (fes, "a", flags_bfa); bfa->AddIntegrator(make_shared<SymbolicBilinearFormIntegrator>( material.mu * InnerProduct( 0.5f*(u->Deriv() + TransposeCF(u->Deriv())), 0.5f*(v->Deriv() + TransposeCF(v->Deriv()))), VOL, VOL));

but the TransposeCF leads to
Code:
terminate called after throwing an instance of 'ngcore::Exception' what(): Transpose of non-matrix called 00:46:50: Das Programm ist abgestürzt.

So my question is how can i transpose v->Deriv() and u->Deriv() ?

Thank you for any help :)
More
3 years 1 month ago #4019 by joachim
Hi Kai,

can you show us how you created the finite element space fes ? Is it really vector-valued ?

For debugging, you can insert a
Code:
cout << *(u->Deriv()) << endl;

before the exception is thrown.

Joachim
More
3 years 1 month ago #4020 by Kai
Hi Joachim,
thanks for quick response, i used the wrong FESpace. Now iam using VectorH1FESpace but the next problem follows : the SymbolicBilinearFormIntegrator does not work with Vector valued Coefficient functions ...

hope this is ok to attach my new qustion here in this thread ?
More
3 years 1 month ago #4021 by joachim
yes, at the end you need a scalar-valued function for the SymbolicBilinearFormIntegrator.

You get it, for example, by taking InnerProduct(grad(u), grad(v)).
grad(u) and grad(v) are matrix-valued.
More
3 years 1 month ago #4022 by Kai
But i do already the InnerProduct like InnerProdukt(grad(u) + Transpose(grad(u)), grad(v) + Transpose(grad(v)))
Code:
bfa->AddIntegrator(make_shared<SymbolicBilinearFormIntegrator>( material.mu * InnerProduct( 0.5f*(u->Deriv() + TransposeCF(u->Deriv())), 0.5f*(v->Deriv() + TransposeCF(v->Deriv()))), VOL, VOL));

but this returns a coef innerproduct, fix size = 9, real ... i do not see whats wrong here ... mathematically this should work ?
More
3 years 1 month ago #4023 by joachim
can you do a
Code:
auto func = material.mu * InnerProduct( 0.5f*(u->Deriv() + TransposeCF(u->Deriv())), 0.5f*(v->Deriv() + TransposeCF(v->Deriv()))); cout << *func << endl;

and send the output ?

If this does not help, you may send the complete example.
Time to create page: 0.117 seconds