Init_Solution_mult (initialize on subdomains) + finer mesh

This commit is contained in:
dino.celebic 2026-01-23 17:43:13 +01:00
commit bd4477f062
7 changed files with 46889 additions and 2124 deletions

View file

@ -34,7 +34,7 @@ g=[2 -diam_bottom/2 diam_bottom/2 floor_level floor_level 1 0; % #vert
]';
[p,e,t] = initmesh(g,'hmax',10);
[p,e,t] = initmesh(g,'hmax',1.5);
pdemesh(p,e,t)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -67,6 +67,30 @@ void Mesh::SetValues(std::vector<double> &vvec,
}
}
void Mesh::Init_Solution_mult(std::vector<double> &v,
int target_sd,
const function<double(double, double)> &func) const
{
assert(2==Ndims());
int const nnode = Nnodes(); // number of vertices in mesh
assert( nnode == static_cast<int>(v.size()) );
for (int e = 0; e < Nelems(); ++e) // loop over all elements
{
int sd = ElementSubdomains[e]; // get subdomain of element e
if (sd == target_sd) // if is target subdomain then
{
int base = e * _nvert_e; // get starting index of element in coordinate vector
for (int k = 0; k < _nvert_e; ++k) // loop over vertices of element
{
int node = _ia[base + k]; // global index of vertex
v[node] = func( _xc[2 * node], _xc[2 * node + 1] ); // set function
}
}
}
}
void Mesh::Debug() const
{
@ -958,10 +982,6 @@ Mesh::Mesh(std::string const &fname)
//cout << " P E R M U T E D !" << endl;
}
vector<int> ElementSubdomains;
Mesh::Mesh(std::string const &filename, std::string const &subdomain_filename) : Mesh(filename)
{
ElementSubdomains = ReadElementSubdomains(subdomain_filename);

View file

@ -199,6 +199,17 @@ public:
const std::function<double(double, double, double)> &func1,
const std::function<double(double, double, double)> &func2 ) const;
/**
* Initialize values in vector valued vector @p v via functions @p func?(x,y) only
* on elements (all their vertices) that belong to subdomain @p target_sd
* @param[in] v vector
* @param[in] target_sd integer of target subdomain.
* @param[in] func function of (x,y) returning a double value.
*/
void Init_Solution_mult(std::vector<double> &v,
int target_sd,
const std::function<double(double, double)> &func) const;
/**
* Prints the information for a finite element mesh
*/

View file

@ -57,8 +57,9 @@ int main(int argc, char **argv )
// Initialize temperature
vector<double> uv(SK.Nrows(), 0.0); // temperature
mesh.SetValues(uv, [](double x, double y) -> double { return 18; } ); // initial temperature of every domain
mesh.Init_Solution_mult(uv, 0, [](double x, double y) -> double { return 18; }); // mug
mesh.Init_Solution_mult(uv, 1, [](double x, double y) -> double { return 80; }); // fluid
mesh.Init_Solution_mult(uv, 2, [](double x, double y) -> double { return 18; }); // air
// Apply BC
SK.ApplyDirichletBC(uv, fv);
@ -70,7 +71,7 @@ int main(int argc, char **argv )
auto t3 = system_clock::now(); // start timer
JacobiSolve(SK, fv, uv ); // solve the system of equations
// JacobiSolve(SK, fv, uv ); // solve the system of equations
auto t4 = system_clock::now(); // stop timer
auto duration = duration_cast<microseconds>(t4 - t3); // duration in microseconds

File diff suppressed because it is too large Load diff