Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

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

More
2 years 6 months ago #4024 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.
More
2 years 6 months ago - 2 years 6 months ago #4025 by Kai
This lines give me the output :
Code:
2.59398e+07*(coef innerproduct, fix size = 9, real coef scale 0.5, real, dims = 3 x 3 coef binary operation '+', real, dims = 3 x 3 coef trial-function diffop = grad, real, dims = 3 x 3 coef Matrix transpose, real, dims = 3 x 3 coef trial-function diffop = grad, real, dims = 3 x 3 coef scale 0.5, real, dims = 3 x 3 coef binary operation '+', real, dims = 3 x 3 coef test-function diffop = grad, real, dims = 3 x 3 coef Matrix transpose, real, dims = 3 x 3 coef test-function diffop = grad, real, dims = 3 x 3 )

Hope this say's somthing to you ...

EDIT :

the python line
Code:
print(InnerProduct(1 / 2 * (grad(self.u) + grad(self.u).trans), 1 / 2 * (grad(self.v) + grad(self.v).trans)))

gives me :
Code:
coef innerproduct, fix size = 9, real coef scale 0.5, real, dims = 3 x 3 coef binary operation '+', real, dims = 3 x 3 coef trial-function diffop = grad, real, dims = 3 x 3 coef Matrix transpose, real, dims = 3 x 3 coef trial-function diffop = grad, real, dims = 3 x 3 coef scale 0.5, real, dims = 3 x 3 coef binary operation '+', real, dims = 3 x 3 coef test-function diffop = grad, real, dims = 3 x 3 coef Matrix transpose, real, dims = 3 x 3 coef test-function diffop = grad, real, dims = 3 x 3

so this seems to be very similar ... but in python there is DifferentialSymbol dx doted with the result of the InnerProdukt ... the dx seems to be defined as DifferentialSymbol(VOL) ... should i dot with this in C++ ?

I can not find where it is defined ...
Last edit: 2 years 6 months ago by Kai.
More
2 years 6 months ago #4043 by joachim
I can't see anything strange in the output, pls send me the complete example and I will have a look.
More
2 years 6 months ago - 2 years 6 months ago #4046 by Kai
I have managed to implement the C++ code such that i now get same results on stdout with C++ and Python, but only for free boundary conditions. In Python i set dirichlet boundary conditions with
Code:
dirichlet = [4, 27, 9, 21, 28, 1, 33, 205, 277, 192, 3, 5, 18, 328] fes = VectorH1(mesh, order=2, dirichlet=dirichlet, complex=True)
the integer list "dirichlet" i got with clicking on mesh faces in netgen ui. In C++ i do
Code:
Flags flags_fes; flags_fes.SetFlag("order", 2); flags_fes.SetFlag("complex", true); flags_fes.SetFlag("dirichlet", "4, 27, 9, 21, 28, 1, 33, 205, 277, 192, 3, 5, 18, 328"); auto fes = make_shared<VectorH1FESpace>(ma, flags_fes); BitArray dirichlet({4, 27, 9, 21, 28, 1, 33, 205, 277, 192, 3, 5, 18, 328}); fes->SetDirichletBoundaries(dirichlet); fes->Update(); fes->FinalizeUpdate(); fes->UpdateDofTables(); fes->PrintReport(std::cout);
But the results are the same as if i do computation without setting boundary conditions.

So is there some thing special to call in C++ to apply boundary conditions ?
Last edit: 2 years 6 months ago by Kai.
More
2 years 6 months ago #4047 by Kai
Fixed !

Code:
Flags flags_fes; flags_fes.SetFlag("order", 2); flags_fes.SetFlag("complex", true); //dirichlet(4, 27, 9, 21, 28, 1, 33, 205, 277, 192, 3, 5, 18, 328, 188, 154, 126); Array<double> dirbnd = {4, 27, 9, 21, 28, 1, 33, 205, 277, 192, 3, 5, 18, 328, 188, 154, 126}; flags_fes.SetFlag("dirichlet", dirbnd); auto fes = make_shared<VectorH1FESpace>(ma, flags_fes);
Time to create page: 0.136 seconds